865 Commits

Author SHA1 Message Date
Richard W.M. Jones
acce28e887 lib: Make sure -lselinux is used when linking libguestfs.so.
If libselinux was detected, it was not added to the linker command
line.  This still worked (at least on Fedora) because some other
library pulls in the dependency implicitly, possibly libvirt.  However
this broke on Arch:

https://aur.archlinux.org/packages/libguestfs/

Reported by and thanks: Antoni Segura Puimedon.
2013-11-19 09:09:02 +00:00
Richard W.M. Jones
59596810b0 daemon: btrfs: Upstream 'btrfs device add' command now needs '--force' option to work.
However earlier versions didn't have the --force option, so we
have to detect it.
2013-11-15 09:05:43 +00:00
John Eckersberg
da85de8a42 btrfs: Fix improper memmove usage in do_btrfs_subvolume_list (RHBZ#1018149).
The third parameter (number of bytes to copy) was given as an offset
relative to dest, when it should be relative to src.  This fixes some
valgrind warnings I happened across.
2013-10-12 07:10:35 +01:00
Richard W.M. Jones
802c7f7376 daemon: Don't leak 'device' string in parse_btrfsvol.
Since 'device' is assigned repeatedly, and because
device_name_translation allocates a new string each time, we have to
free it in the loop and along error paths.

Found by ./configure --enable-valgrind-daemon.
2013-10-11 12:23:48 +01:00
Richard W.M. Jones
d8a8894cb2 daemon: xattr: Fix scope of cleanup buf to avoid memory leaks.
Found by ./configure --enable-valgrind-daemon.
2013-10-11 12:23:48 +01:00
Richard W.M. Jones
c245b55707 daemon: parted: Fix memory leak of list of strings.
Found by ./configure --enable-valgrind-daemon.
2013-10-11 11:12:57 +01:00
Richard W.M. Jones
db0307b7e3 daemon: Fix scope of cleanup functions to avoid memory leaks.
Found by ./configure --enable-valgrind-daemon.
2013-10-11 11:12:27 +01:00
Richard W.M. Jones
494c18802b daemon: When valgrinding the daemon, take steps to cleanly exit daemon.
This adds a new internal API: internal_exit

Only when valgrinding the daemon, have the library call internal_exit
along the close path, and close the sockets first.  This ensures we
will see normal valgrind messages (we were only seeing valgrind aborts
before).

Note this is not used in production builds.
2013-10-11 09:13:11 +01:00
Richard W.M. Jones
ae897e055a builder: Upload /etc/resolv.conf from the host when the network is enabled.
When the user has enabled the network (not the default) we upload
/etc/resolv.conf from the host to the appliance /etc/resolv.conf
so that programs in the appliance can contact nameservers.

Commit 9521422ce6 previously changed the
behaviour to copy /etc/resolv.conf into the sysroot when running
commands.
2013-10-08 12:33:16 +01:00
Richard W.M. Jones
4fc44a0157 blockdev: Deprecate blockdev_setbsz and make it do nothing (RHBZ#624334).
This call never did anything.  Don't use it.  Also I have submitted a
patch upstream to remove the corresponding option from blockdev.

See RHBZ#1002825 for an explanation of why this call was always
useless.

Thanks: Masayoshi Mizuma
2013-10-08 10:04:27 +01:00
Richard W.M. Jones
9521422ce6 daemon: command: Copy appliance /etc/resolv.conf in before running commands.
When you try to run commands for an Ubuntu guest, they fail because in
Ubuntu /etc/resolv.conf is a symlink to /run/...  and this turns out
to be a dangling symlink when the Ubuntu guest is mounted up under the
appliance.

Therefore even if the network is enabled, any command which tries to
do name resolution will fail.

Ideally we would like to bind-mount the appliance /etc/resolv.conf
into the sysroot.  However this is not possible because mount is buggy
(see comment).  So instead we use a complex hack to achieve the same
ends.

Note this is only done if the network is enabled and if /etc in the
guest actually exists.  The original /etc/resolv.conf is restored
as soon as the command has run.
2013-10-07 22:01:02 +01:00
Richard W.M. Jones
b8b1b0296b daemon: Refactor bind-mount code.
This is just code motion.
2013-10-07 21:51:29 +01:00
Richard W.M. Jones
93793db049 daemon: 'exists' API should not follow broken symlinks.
Using guestfs_exists on a symlink which existed but pointed to a
non-existent file was returning false.  However exists obviously
should not be following the symlink in the first place.
2013-10-07 17:10:14 +01:00
Richard W.M. Jones
21e5fc811e daemon: Don't set LD_PRELOAD for guestfsd children.
Commit c598e14052 exports
LD_PRELOAD=/lib64/libSegFault.so so that guestfsd and processes that
it runs will produce descriptive stack traces.

However if we chroot into /sysroot (ie. CHROOT_IN/CHROOT_OUT) and if
the libSegFault.so library does not exist inside the chroot (as is the
case on Debian guests) then we cannot run any processes.  In any case
we *don't* want to necessarily run this library from the guest.

The proper way to fix this is to confine all chrooting to a
subprocess, but that's a big change to guestfsd which we'll have to do
one day.  For now, unset LD_PRELOAD once guestfsd starts up.
2013-10-03 21:42:04 +01:00
Richard W.M. Jones
8abd0a83b3 daemon: Fix xfs_info parser because of new format.
The old parser had several problems: firstly it called the error path
sometimes without calling reply_with_error causing a protocol hang.
More seriously it had hard-coded line numbers, and since Fedora 21 the
output of xfs_info has changed, moving lines around.

Change the parser to be more robust against added fields by using the
first name on the line as the section name, thus 'bsize=' is
interpreted differently depending on whether it appears in the "data"
section or the "naming" section.

Ensure also that we don't call the error path without calling
reply_with_error, which is a side-effect of the above change.
2013-10-03 18:17:39 +01:00
Richard W.M. Jones
091eb07803 daemon: augeas: Don't test if AUG_NO_ERR_CLOSE is defined.
It's an enum, not a macro, and in any case it has been present in
augeas.h since 0.10.0, and the minimum version that libguestfs
requires is 1.0.0.

This fixes commit 3d132f2920.
2013-09-02 19:37:57 +01:00
Richard W.M. Jones
3d132f2920 daemon: augeas: Enhance error reporting for aug_init failures.
Thanks: Dominic Cleal.
2013-09-02 19:23:36 +01:00
Richard W.M. Jones
950afbb705 daemon: Add comment about how zero_free_space would be better if we could do cancellation. 2013-08-31 21:29:16 +01:00
Richard W.M. Jones
91c162586c daemon: tar: Use a temporary file to pass excludes to tar command (RHBZ#1001875).
Use tar -X option instead of tar --exclude=... option.
2013-08-29 13:27:40 +01:00
Richard W.M. Jones
a75ca610b8 daemon: Allow labels to be set on DOS filesystems using 'dosfslabel'.
You can now use virt-format or virt-make-fs --label option to set a
label for a DOS filesystem:

$ ./run ./format/virt-format -a /tmp/test.img --filesystem=vfat --label=BOOT
$ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  vfat  BOOT   -    1.0G  -
/dev/sda1  partition   -     -      0b   1.0G  /dev/sda
/dev/sda   device      -     -      -    1.0G  -

This also contains a small code refactoring.

Thanks: Gerd Hoffmann (kraxel)
2013-08-29 11:43:31 +01:00
Richard W.M. Jones
b1919066ca Initialize CLEANUP_* stack variables with NULL in various places.
Code like:

  CLEANUP_FREE char *buf;
  /* some code which might return early */
  buf = malloc (10);

is a potential bug because the free (*buf) might be called when buf is
an uninitialized pointer.  Initialize buf = NULL to avoid this.

Several of these are bugs, most are not bugs (because there is no
early return statement before the variable gets initialized).

However the compiler can elide the initialization, and even if it does
not the performance "penalty" is miniscule, and correctness is better.
2013-08-22 19:48:05 +01:00
Richard W.M. Jones
fc2947b112 daemon: sh: Fix missing initializer which caused segfault (RHBZ#1000121).
Thanks: Olaf Hering.
2013-08-22 19:39:25 +01:00
Richard W.M. Jones
d188594b11 daemon: hivex: Define empty hivex_finalize function in case !HAVE_HIVEX.
Thanks: Olaf Hering (see previous commit).
2013-08-20 18:28:25 +01:00
Olaf Hering
8590ec9b56 daemon: fix build without systemd-journal
Fix typo in OPTGROUP_JOURNAL_NOT_AVAILABLE
Define empty journal_finalize, called by mount.c

Signed-off-by: Olaf Hering <olaf@aepfle.de>
2013-08-20 18:28:02 +01:00
Richard W.M. Jones
c2232321b6 daemon: Document guestfs_verbose=1 and guestfs_channel=<PATH> in man page. 2013-08-20 11:42:18 +01:00
Richard W.M. Jones
08f605c073 tests: Add a test that console log messages make it up to events.
In Rawhide, the console was briefly broken although it "fixed itself"
when libvirtd was restarted.
2013-08-14 17:25:11 +01:00
Richard W.M. Jones
90cafed4c2 daemon: list-md-devices: Check if a /dev/md<X> device is valid before returning it.
For reasons not fully understood, if md is linked into the kernel (and
not a module), a /dev/md0 device node is created.  However this is not
a real RAID device.  For example running mdadm --detail /dev/md0 will
fail on it.

Check the /dev/md<X> devices are real RAID devices before returning
them from the list-md-devices API.
2013-08-13 15:46:54 +01:00
Richard W.M. Jones
52188f1ea3 daemon: md: Whitespace fixes. 2013-08-13 15:46:54 +01:00
Richard W.M. Jones
8ad634877c daemon: If /proc/modules doesn't exist, linuxmodules optgroup is disabled.
It likely means the kernel was compiled without modules support.
2013-08-13 15:46:54 +01:00
Richard W.M. Jones
e037f0d26b daemon: compare_device_names: Fix typo in this function.
This would have broken the function if we were comparing mixed
/dev/sda and /dev/ubda (ie different length) strings.  Which we never
normally do, luckily.
2013-08-12 13:40:24 +01:00
Richard W.M. Jones
9a6cc3c927 daemon: Recognize /dev/ubd[a-] as a valid device name. 2013-08-11 19:49:46 +01:00
Richard W.M. Jones
f55a1a1fe7 daemon: Allow guestfs_channel to override the virtio-serial channel.
Also if /dev/ttyS* is specified, make sure the serial port is set to
raw mode.
2013-08-11 19:49:45 +01:00
Richard W.M. Jones
2089f7a21a daemon: ldm: Don't return an error if /dev/mapper doesn't exist. 2013-08-11 17:41:09 +01:00
Richard W.M. Jones
1d7c3a2782 daemon: Device name translation now allocates a new string.
Previously device name translation worked on the string in-place.

This worked fine because the device strings always come from XDR where
they are dynamically allocated.  However it wouldn't work if the
translated name had to be longer than the original, specifically for
/dev/sd -> /dev/ubd (for User Mode Linux).

Therefore this commit changes the generator so that
device_name_translation and parse_btrfsvol (which depends on it)
allocate the new device name instead of overwriting it.
2013-08-11 17:39:57 +01:00
Richard W.M. Jones
89cf1c1163 daemon: Move all RESOLVE macros to daemon/stubs.c.
These macros are pretty horrible to use, with unexpected side-effects.
Move them exclusively into the generated code and rewrite the one
place in the general C code which used them.

There's no functional change in this code.
2013-08-11 17:39:57 +01:00
Richard W.M. Jones
7367729ec7 daemon: Remove unnecessary sysroot_path (selinux).
This fixes commit 72afcf450a.
2013-08-10 23:02:42 +01:00
Richard W.M. Jones
ce6e5738fc daemon: Close augeas, hivex, journal handles in unmount_all.
This is also called implicitly from internal_autosync, ensuring that
exit won't fail because of an open handle.

libguestfs: error: internal_autosync: umount: /sysroot: umount: /sysroot: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
2013-08-07 14:54:10 +01:00
Paul Mackerras
7c535c501b Fix parsing of boot flag in do_part_get_bootable()
The code in do_part_get_bootable() assumes that if a partition has the
bootable flag set, then that is the only flag.  It compares the entire
flags field with the string "boot".  However, the boot flag isn't
always the only flag.  For instance, POWER systems typically have a
bootable partition of type 0x41 (PPC PReP boot), which parted -m
displays as:

# parted -m -- f18.img unit b print
BYT;
/root/f18.img:16106127360B:file:512:512:msdos::;
1:1048576B:5242879B:4194304B:::boot, prep;

That is, the flags field contains "boot, prep", and thus libguestfs
fails to see that this partition is bootable.  Ultimately this causes
virt-resize to fail to set the bootable flag on the boot partition of
the destination image, resulting in an image that won't boot.

This patch fixes the problem by searching for the string "boot" within
the flags field, instead of comparing the whole flags field.
2013-08-07 12:28:10 +01:00
Richard W.M. Jones
c4a3e8112a New APIs: aug-setm and aug-label.
Bindings for the aug_setm and aug_label APIs in Augeas.
2013-08-06 11:47:21 +01:00
Richard W.M. Jones
f26a0407d2 augeas: Improve error reporting.
Display all the information from the handle about errors.
2013-08-06 11:47:21 +01:00
Richard W.M. Jones
a89675ee5c journal: Fix incorrect printf format specifier for 32-bit.
journal.c: In function 'do_journal_skip':
journal.c:134:5: error: format '%zd' expects argument of type 'signed size_t', but argument 3 has type 'int64_t' [-Werror=format=]
     reply_with_perror_errno (-r, "failed to skip %zd journal entries", skip);
     ^

This fixes commit 5cb7f294f6.
2013-07-31 22:37:57 +01:00
Richard W.M. Jones
c663ab3bb9 daemon: cap-get-file: Return empty string if no capability on file (RHBZ#989356).
Return an empty string (instead of an error) if no capabilities are
set on a file, and document that in the API.
2013-07-29 14:37:50 +01:00
Richard W.M. Jones
5cb7f294f6 New APIs: Add systemd journal support (RHBZ#988100).
This adds simple support for reading the journal files from guests
that use the systemd journal.

The new APIs are:

  journal-open
  journal-close
  journal-next
  journal-skip
  journal-get
  journal-get-data-threshold
  journal-set-data-threshold
  internal-journal-get

More complex journal support (eg. for seeking within the journal,
support for cursors) could be added later.
2013-07-28 19:16:03 +01:00
Richard W.M. Jones
8580ef7d0f New API: Implement set-uuid for ext2/3/4 and XFS (RHBZ#986877).
Also includes tests.
2013-07-22 13:52:23 +01:00
Richard W.M. Jones
091d22f49e daemon: Implement set-label for XFS and fix it for btrfs (RHBZ#986875).
Implement 'set-label' for XFS filesystems.

Fix the call for btrfs.  Previous
commit d5817537fa added some bogus
documentation implying this call would work for btrfs, but it did
not.

Add tests.
2013-07-22 13:52:23 +01:00
Richard W.M. Jones
3201e75564 mkfs: Use -b size=<size> for xfs (RHBZ#981715). 2013-07-18 14:36:25 +01:00
Richard W.M. Jones
c8f0a2eb76 daemon: hivex: Check that hivex_commit is passed an absolute path (RHBZ#981683).
You will now get an error like:

libguestfs: error: hivex_commit: do_hivex_commit: path must start with a / character
2013-07-05 14:27:38 +01:00
Richard W.M. Jones
fb0bd82dbe daemon: Verify ext2/3/4 filesystem name before passing to mke2fs (RHBZ#978302).
Add a utility function (fstype_is_extfs) to match ext2/3/4 filesystem
names.  This is used in a couple of places.

When passing the mke2fs -t parameter, verify that the request is for
an ext2/3/4 filesystem.  Previously we did not check this, and neither
did mke2fs when the -F flag was also used.
2013-06-26 14:37:26 +01:00
Richard W.M. Jones
2c4e7ad135 Augeas >= 1.0.0 is now required. 2013-06-18 15:34:01 +01:00
Richard W.M. Jones
ef107448e8 Add followsymlinks flag to is-file, is-dir, is-blockdev, is-chardev, is-fifo and is-socket APIs.
This adds an extra optional boolean 'followsymlinks' flag to those 6
is-* APIs.  If the flag is true, then symlinks are followed, ie. we
use stat instead of lstat in the test.

For the rationale behind this change, see:
https://bugzilla.redhat.com/show_bug.cgi?id=974489
2013-06-14 10:53:17 +01:00