Commit Graph

5657 Commits

Author SHA1 Message Date
Richard W.M. Jones
9e9d78ade1 launch: direct: Always use cache=unsafe for the appliance.
The code to select writeback was redundant, because current
qemu always supports cache=unsafe.

(cherry picked from commit 011c963926)
(cherry picked from commit 5be3a863c5)
2014-02-12 16:03:18 +00:00
Richard W.M. Jones
30d5ac37fa rescue: Use cachemode "unsafe" for the virt-rescue --scratch option.
(cherry picked from commit 3f0748f1fc)
(cherry picked from commit 1e421afa98)
2014-02-12 16:03:18 +00:00
Richard W.M. Jones
d58493e260 sparsify: Use cachemode "unsafe" for the overlay disk.
(cherry picked from commit f3a9c9f867)
(cherry picked from commit 322bf1dd40)
2014-02-12 16:03:18 +00:00
Richard W.M. Jones
ac0742b96f drives: Ensure all scratch drives use cachemode "unsafe".
They are _scratch_ drives so any data on them doesn't matter and can
be reconstructed in the event of a host system crash.

(cherry picked from commit 96cd7fcecb)
(cherry picked from commit 053061f66f)
2014-02-12 16:03:18 +00:00
Richard W.M. Jones
7042424ec2 add_drive: Introduce 'cachemode' parameter to control drive caching.
This commit adds an optional 'cachemode' parameter to the 'add_drive'
API to control caching.  This corresponds approximately to the
'-drive ...,cache=' parameter in qemu, but the choices are much more
restrictive, just 'writeback' or 'unsafe', for reasons outlined below.

The caching modes supported by recent QEMU are:

  writeback:
   - Reports data writes completed when data is present in the host
     page cache.
     Only safe provided guest correctly issues flush operations.

  writethrough:
   - Reports data writes completed only when each write has been
     flushed to disk.  Performance is reported as not good.

  none:
   - Uses O_DIRECT (avoids all interaction with host cache), but does
     not ensure every write is flushed to disk.
     Only safe provided guest correctly issues flush operations.

  directsync:
   - Uses O_DIRECT (avoids all interaction with host cache), and
     ensures every write has been flushed to disk.

  unsafe:
   - No special handling.

Since the libguestfs appliance kernel always issues flush operations
(eg. for filesystem journalling and for sync) the following modes can
be ignored: 'directsync', 'writethrough'.

That leaves 'writeback', 'none' and 'unsafe'.  However 'none' is both
a constant source of pain (RHBZ#994517), is inefficient because it
doesn't use the host cache, and does not give us any safety guarantees
over and above 'writeback'.  Therefore we should ignore 'none'.

This leaves 'writeback' (safe) and 'unsafe' (fast, useful for scratch
disks), which is what we implement in this patch.

Note that the previous behaviour was to use 'none' if possible, else
to use 'writeback'.  The new behaviour is to use 'writeback' only
which is (in safety terms) equivalent to 'none', and also faster and
less painful (RHBZ#994517).

This patch also allows you to specify a cache mode for network drives
which also previously defaulted to 'writeback'.

There is a considerable performance benefit to using unsafe (for
scratch disks only, of course).  The C API tests only use scratch
disks (since they are just tests, the final state of the disk doesn't
matter), and this decreases total run time from 202 seconds to 163
seconds, about 25% faster.

(cherry picked from commit 749e947bb0)
(cherry picked from commit c7304d0c8e)
2014-02-12 16:03:18 +00:00
Richard W.M. Jones
35c4270399 New API: add-drive-scratch.
This adds a temporary scratch drive to the handle.

(cherry picked from commit 1b11a83d52)
(cherry picked from commit eaffd8105f)
2014-02-12 16:03:18 +00:00
Richard W.M. Jones
8fb76be11e Version 1.22.9. 1.22.9 2014-02-12 15:28:54 +00:00
Richard W.M. Jones
0b4e648c3a 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.

(cherry picked from commit 59596810b0)
(cherry picked from commit 899d0af829)
2014-02-12 15:21:09 +00:00
Richard W.M. Jones
7c4aa0ede1 Version 1.22.8. 1.22.8 2014-02-12 14:49:27 +00:00
Richard W.M. Jones
353f72806a list-filesystems: Do not segfault if guestfs_btrfs_subvolume_list returns an error (RHBZ#1064008).
If calling guestfs_list_filesystems with a disk image containing a
corrupt btrfs volume, the library would segfault.  There was a missing
check for a NULL return from guestfs_btrfs_subvolume_list.

This adds a check, returning the real error up through the stack and
out of guestfs_list_filesystems.

This is potentially a denial of service if processing disk images from
untrusted sources, but is not exploitable.

Thanks: Jeff Bastian for reporting the bug.
(cherry picked from commit d70ceb4cbe)
2014-02-12 13:38:30 +00:00
Richard W.M. Jones
322f5242d9 lua: Don't redefine lua_objlen if already defined.
lua 5.2.2 seems to define this symbol already.

(cherry picked from commit 5ee193433a)
(cherry picked from commit 40e3823155)
2014-02-12 13:38:30 +00:00
Richard W.M. Jones
5ad4d2c2ec Revert "daemon: augeas: Enhance error reporting for aug_init failures."
This reverts commit 272cc56876.

See:
https://www.redhat.com/archives/libguestfs/2013-October/msg00035.html
2013-10-18 14:58:20 +01:00
Richard W.M. Jones
3a50219454 Revert "daemon: augeas: Don't test if AUG_NO_ERR_CLOSE is defined."
This reverts commit f59b87f7f1.

See:
https://www.redhat.com/archives/libguestfs/2013-October/msg00035.html
2013-10-18 14:57:34 +01:00
Richard W.M. Jones
dfdaab0fec Version 1.22.7. 1.22.7 2013-10-17 15:30:51 +01:00
Richard W.M. Jones
b23fca294e fish: CVE-2013-4419: Fix insecure temporary directory handling for remote guestfish (RHBZ#1016960).
When using the guestfish --remote or guestfish --listen options,
guestfish would create a socket in a known location
(/tmp/.guestfish-$UID/socket-$PID).

The location has to be a known one in order for both ends to
communicate.  However no checking was done that the containing
directory (/tmp/.guestfish-$UID) is owned by the user.  Thus another
user could create this directory and potentially modify sockets owned
by another user's guestfish client or server.

This commit fixes the issue by creating the directory unconditionally,
and then checking that the directory has the correct owner and
permissions, thus preventing another user from creating the directory
first.

If guestfish sees a suspicious socket directory it will print an error
like this and exit with an error status:

  guestfish: '/tmp/.guestfish-1000' is not a directory or has insecure owner or permissions

Thanks: Michael Scherer for discovering this issue.

Version 2:
 - Add assigned CVE number.
 - Update documentation.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 54fb09e052)
2013-10-17 13:18:29 +01:00
Richard W.M. Jones
9a86533362 FAQ: useradd -> usermod.
This fixes commit dd554d94ad.

(cherry picked from commit fc733cf943)
2013-10-17 13:18:14 +01:00
Richard W.M. Jones
f82ee97d87 sysprep: firstboot: Don't set `Created_files flag unless files are created.
(cherry picked from commit a3e5bc7bfa)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
2d8b5f59be firstboot: Add some debugging to the control script.
For reasons unknown, firstboot does not work on Debian 6 & 7.
https://bugzilla.redhat.com/show_bug.cgi?id=1019388

(cherry picked from commit 356a749bba)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
8c4dbe28f7 firstboot: Fix test for installing sysvinit scripts.
This fixes commit 9aa13e0574.

(cherry picked from commit 2bc223b6b2)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
60fffac0fe firstboot: Install both systemd and SysV init scripts.
This should be safe, and avoids the whole issue of whether a guest
uses systemd or not.  Also it is possible to switch init systems
(eg. by specifying init= on the command line) so it's not even clear
if a guest "is" systemd.

Thanks: Tom Gundersen on #systemd.

This updates/fixes commit 596de56a43.

(cherry picked from commit 9aa13e0574)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
a89c78a099 firstboot: Start service after network only.
Not necessary to wait for syslog since (a) we do our own logging
to a file and (b) syslog might not be installed.

(cherry picked from commit cff95392f5)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
509f5b3273 firstboot: Fix firstboot scripts so they work on Ubuntu.
Ubuntu 13.10 has /etc/systemd but uses Upstart.  This confuses the
script because it assumed that if you have /etc/systemd then you are
using systemd.  Ubuntu includes systemd services (inherited from
Debian) but they just don't run.

(cherry picked from commit 596de56a43)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
200a02514e FAQ: Clearer instructions for Debian and Ubuntu users.
(cherry picked from commit dd554d94ad)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
20ef9bb44f edit: Add virt-edit --edit as an alias for virt-edit -e.
This just adds the alias and does nothing else.

(cherry picked from commit 04041f23d0)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
4b0189850e appliance: Disable LD_PRELOAD libSegFault in virt-rescue shell.
Commit c598e14052 exports
LD_PRELOAD=/lib64/libSegFault.so so that guestfsd and processes that
it runs will produce descriptive stack traces.

However it exports it to everything including the virt-rescue shell.
But if we are chrooting into a guest which doesn't have this file (or
indeed any guest) we should not use LD_PRELOAD.

Therefore unset LD_PRELOAD in the rescue shell.

See also related commit 21e5fc811e.

(cherry picked from commit f7ca38b728)
2013-10-16 10:49:56 +01:00
John Eckersberg
caec4b24b8 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.

(cherry picked from commit da85de8a42)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
748c6bf70e daemon: xattr: Fix scope of cleanup buf to avoid memory leaks.
Found by ./configure --enable-valgrind-daemon.

(cherry picked from commit d8a8894cb2)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
bf3453015a daemon: parted: Fix memory leak of list of strings.
Found by ./configure --enable-valgrind-daemon.

(cherry picked from commit c245b55707)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
2d407dc6ff daemon: Fix scope of cleanup functions to avoid memory leaks.
Found by ./configure --enable-valgrind-daemon.

(cherry picked from commit db0307b7e3)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
f2eb68a3e5 daemon: Ignore memory leak in aug_setm.
(Found by ./configure --enable-valgrind-daemon)

(cherry picked from commit 237e1d41d7)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
bee0b7965b inspector: Allow the test to be skipped by setting an environment variable.
(cherry picked from commit 0f8db6185f)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
e42a6e5e54 fish: Use UNIX_PATH_MAX instead of hard-coded value for max length of socket buf.
(cherry picked from commit 9f1bcbca55)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
6f677ee9d3 generator: Change handling of C 'function(void)' to be simpler.
This also fixes an obscure case in daemon/optgroups.h.

The only difference in the generated output is:

--- daemon/optgroups.h.orig	     2013-10-09 20:42:02.479681861 +0100
+++ daemon/optgroups.h		     2013-10-09 20:42:10.563681858 +0100
@@ -149,7 +149,7 @@
   int optgroup_inotify_available (void) { return 0; }

 #define OPTGROUP_JOURNAL_NOT_AVAILABLE \
-  int __attribute__((noreturn)) do_internal_journal_get () { abort (); } \
+  int __attribute__((noreturn)) do_internal_journal_get (void) { abort (); } \
   int __attribute__((noreturn)) do_journal_close (void) { abort (); } \
   int64_t __attribute__((noreturn)) do_journal_get_data_threshold (void) { abort (); } \
   int __attribute__((noreturn)) do_journal_next (void) { abort (); } \

(cherry picked from commit b2baaa0029)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
fcb9d4dbaf df: parallel: Add a debug message when work function returns an error.
Further attempts to find out why this hangs under Koji.

(cherry picked from commit 74d9fdf56f)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
bae3ee0897 launch: libvirt: Clarify comment.
(cherry picked from commit 89b65b9779)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
984bcca384 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.

(cherry picked from commit 93793db049)
2013-10-16 10:49:56 +01:00
Richard W.M. Jones
9b6536f07f sysprep: Don't remove /var/cache/apt/archives/partial directory.
Removing this directory breaks Ubuntu guests.

This change adds a utility function which removes only files from a
directory.  This is a safer way to clean cache directories etc.

(cherry picked from commit dfa52c63b1)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
ecf73267b4 perl: valgrind: Renamed function requires different valgrind suppression.
Seems to be a difference in Perl 5.18.

(cherry picked from commit e79c99f58c)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
355699b4de tests/nbd: Avoid warning when tests are skipped.
Since END{} clause is always called,  might not be defined if
we exit early.  Move the whole clause to the top.

(cherry picked from commit a914889b1d)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
846b8379fc firstboot: Invoke firstboot.sh script with 'start' parameter.
.. else the systemd script does not run.

(cherry picked from commit da1d0da429)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
e2cc4382a5 resize, sparsify: Small argument parser refactoring.
Factor out a common string.

(cherry picked from commit e1d7fb406b)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
0100d12e1b 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.

(cherry picked from commit 21e5fc811e)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
adcdc44004 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.

(cherry picked from commit 8abd0a83b3)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
be481639ad appliance: Create /dev/loop-control and similar devices.
When 'mount -o loop' and similar commands are used, the loop module is
loaded automatically by the kernel when /dev/loop-control is accessed.

/dev/loop-control is created semi-statically by an unholy and
overcomplex combination of kmod static-nodes and systemd-tmpfiles
(instead of using, say, just udev or even just a simple series of
mknod commands).

(cherry picked from commit e2895b19bb)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
14337295d4 appliance: If --enable-valgrind-daemon then increase minimum memory to 768 MB.
tests/c-api would fail from time to time if --enable-valgrind-daemon
was configured.  There was no obvious memory leak.  It looks as if the
overhead of valgrind was sufficient to break long-running tests such
as this one.

(cherry picked from commit d0ef2ff9b6)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
d44c53dace sysprep: Fix option quoting in manual page.
This fixes commit b65c1c667b.

(cherry picked from commit 4cdb5bcc5e)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
75339d2573 virt-df: parallel: Send debugging messages to stderr.
Not stdout (ordinary program output) since that gets eaten by
the tests.

This fixes commit 67b9469754.

(cherry picked from commit 5971fb2a70)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
07a1c0a4b6 docs: Remove misleading / outdated section about other arches from README.
(cherry picked from commit ccc9a891df)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
a68ae78022 inspection: Don't print a warning if \Windows\explorer.exe does not exist.
guestfs_case_sensitive_path does not test for file existence.  We have
to test for it explicitly.

This updates commit 9ea6e97014.  See the
description of that commit for more details.

(cherry picked from commit bae6d5cc63)
2013-10-16 10:49:55 +01:00
Richard W.M. Jones
bccfef3e91 launch: direct: Set QEMU_AUDIO_DRV=none to stop qemu opening audio devices.
Libvirt does the same thing, and it definitely has an effect
on ARM at least.

(cherry picked from commit 2550971d72)
2013-10-16 10:49:55 +01:00