Commit Graph

600 Commits

Author SHA1 Message Date
Richard W.M. Jones
de5d416fc7 daemon: Move internal-autosync function to new file internal.c.
This is just code motion.
2012-01-21 21:31:50 +00:00
Richard W.M. Jones
a9c8123c72 daemon: Run udev_settle after pwrite-device finishes.
When you call close on any block device, udev kicks off a rule which
runs blkid to reexamine the device.  We need to wait for this rule to
finish running since it holds the device open and can cause other
operations to fail, notably BLKRRPART.
2012-01-19 15:47:19 +00:00
Richard W.M. Jones
61abcf71c0 daemon: pwrite/pread: Don't double close on error path.
In Linux, close (fd) closes the file descriptor even if it returns an
error.
2012-01-19 11:31:23 +00:00
Richard W.M. Jones
08840bab44 Tempus fugit.
Update all copyright dates to 2012.
2012-01-18 22:05:02 +00:00
Richard W.M. Jones
b1ea8a7808 resize2fs-M: fix double-free along error path (thanks Matthew Booth). 2012-01-16 10:15:02 +00:00
Wanlong Gao
4ac5e2d218 e2fsck-f: change the internal to use e2fsck
Since we implement the new api e2fsck, just change the
internal of e2fsck_f to use e2fsck now.
v1->v2: use optargs_bitmask

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2012-01-13 16:48:23 +00:00
Wanlong Gao
38a0966da8 NEW API: add a new api e2fsck
m: Wanlong Gao <gaowanlong@cn.fujitsu.com>

Add a new api e2fsck with two options:
correct: same as '-p' option of e2fsck
forceall: same as '-y' option of e2fsck

Thanks for Rich's idea.
v1->v2: use optargs_bitmask
v2->v3: change the optargs_bitmask check

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2012-01-13 16:48:22 +00:00
Wanlong Gao
0eaf06e673 ext2: tweak the error returned message of resize2fs-M(BZ755729)
Tweak the error message "e2fsck -f" and "e2fsck -fy".
Indicate the user to use the correct and/or forceall options.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2012-01-13 16:48:20 +00:00
Richard W.M. Jones
01e717b3c1 daemon: debug segv correct use of dereferencing NULL. 2012-01-09 16:55:49 +00:00
Wanlong Gao
2ac869bcc8 mkfs: optimization and code cleanup
v1->v2: fix a typo pointed by Matt

Optimizations by reducing the STREQ operations and do some
code cleanup.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>

RWMJ: Whitespace changes.
2011-12-23 08:19:47 +00:00
Richard W.M. Jones
498758faee tests: Split regressions -> various subdirectories of tests/ 2011-12-22 13:04:41 +00:00
Richard W.M. Jones
19e2f5aa4f daemon: Fix utimens so it doesn't hang on named pipes (RHBZ#761460).
This also adds comprehensive tests for utimens on regular files,
directories (RHBZ#761451), named pipes (RHBZ#761460), symbolic links,
block and char devices.

Note that there is a small change in the (previously undefined)
semantics of this call: It now sets the time on a symbolic link
itself, not on what the symbolic link points to.
2011-12-08 11:39:58 +00:00
Richard W.M. Jones
31fba8d803 daemon: Allow utimens to work for directories (RHBZ#761451).
You don't need to open the file O_WRONLY in order to call futimens on
the file descriptor.  Opening it O_WRONLY fails for directories.
Therefore open O_RDONLY instead.
2011-12-08 11:15:18 +00:00
Wanlong Gao
6c5f7c954c blkid: split the RHEL5 which can't support some options
RHEL5 shoult not support '-p', '-i' and '-o export' options.
But we just split it according to the '-p' option.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2011-12-05 10:15:12 +00:00
Richard W.M. Jones
e18058a5a5 Revert "blkid: Use -c /dev/null because RHEL 5 blkid doesn't have -p option."
This reverts commit 6533491b17.
2011-12-04 16:47:37 +00:00
Richard W.M. Jones
7f14c042eb Revert "blkid: Fix mistake in previous commit."
This reverts commit c48226a502.
2011-12-04 16:47:29 +00:00
Richard W.M. Jones
c48226a502 blkid: Fix mistake in previous commit.
This updates commit 6533491b17.
2011-12-03 23:16:00 +00:00
Richard W.M. Jones
6533491b17 blkid: Use -c /dev/null because RHEL 5 blkid doesn't have -p option. 2011-12-03 22:58:03 +00:00
Richard W.M. Jones
615924abaa daemon: Use pkg-config to locate Augeas CFLAGS / libraries.
Augeas 0.10 depends on libxml2, so this is now required in the
appliance (in fact, it was already present).

However this exposed two bugs:

(1) In libguestfs we use a home-brewed recipe for Augeas flags,
resulting in this error:
/usr/include/augeas.h:24:25: fatal error: libxml/tree.h: No such file or directory

(2) Augeas's own augeas.pc didn't include the libxml2 flags, so
it was broken.  This requires a patch to Augeas 0.10, see:
https://www.redhat.com/archives/augeas-devel/2011-December/msg00008.html

Change to using pkg-config to detect Augeas.  It is still an optional
library.
2011-12-03 14:34:52 +00:00
Wanlong Gao
fcb975a642 NEW API: add blkid command to print the attributes of the device
A NEW API blkid.
It can print the device attributes.
Use it after list-devices, we can list ower devices and the attributes
of each device.
Use it like:
blkid <device>
It's should be a usefull function.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2011-12-03 11:05:48 +00:00
Wanlong Gao
1970a14178 mkfs: enable to make xfs filesystems when the device already has a filesystem
Just add the -f option to mkfs.xfs to make sure we can
make a xfs filesystem when the device already has a
filesystem on it.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2011-12-02 14:01:28 +00:00
Hilko Bengen
1a35ca5908 libguestfs: Added gnulib includes from builddir, as suggested by the Gnulib documentation
Since some modules (`getopt', for example) may copy files
    into the build directory, `top_builddir/lib' is needed as well as
    `top_srcdir/lib'. -- GNU Gnulib manual, section 2.2 Initial import
2011-12-01 23:40:58 +00:00
Richard W.M. Jones
2d5841133a debian: Use mdadm -D --export instead of mdadm -DY.
For compatibility with mdadm on Debian Squeeze.
2011-11-24 16:27:36 +00:00
Richard W.M. Jones
c4381dba73 part-disk: Change default alignment of this to 64K (128 sectors).
This is the minimum alignment.  1MB would be better.

Note that the exact behaviour is not defined in the API.
2011-11-24 14:42:26 +00:00
Wanlong Gao
cbd1c45d95 New API: md-stop for stopping MD devices
This API is used to stop a md device.
When we want to move a device to another md array, we should
stop the md device which contained this device first.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2011-11-24 13:24:17 +00:00
Matthew Booth
182c25b2a4 Rename mdadm_ apis to md_
This change renames the following 2 apis:
* mdadm_create -> md_create
* mdadm_detail -> md_detail

This is more consistent with list_md_devices, and removes a reference to an
implementation detail from the api.
2011-11-24 13:22:42 +00:00
Matthew Booth
c4bd6bba8d New API: mdadm-detail. 2011-11-17 12:43:49 +00:00
Matthew Booth
00a0fab50b New API: list-md-devices.
Return a list of Linux MD devices detected in the guest.

This API complements list_devices, list_partitions, list_lvs and
list_dm_devices.
2011-11-11 22:52:31 +00:00
Richard W.M. Jones
c11a92751e New API: mdadm-create for creating MD devices. 2011-11-11 22:52:31 +00:00
Richard W.M. Jones
c81a16a4e2 New API: Bind the tune2fs command.
Previously we bound the 'tune2fs -l' command so that we could list out
the tunables of an ext2/3/4 filesystem.  Also commands like
set_e2label and set_e2uuid used tune2fs.

This commit binds many of the tunables that can be set using tune2fs.

The coverage is not complete, but we can add more later because this
uses optional parameters so the call is extensible without breaking
ABI.  The current change gives us enough for using libguestfs within
OpenStack.
2011-11-11 10:48:22 +00:00
Richard W.M. Jones
edd502543a daemon: Define safe ADD_ARG macro for constructing arg lists on the stack. 2011-11-11 10:48:16 +00:00
Matthew Booth
04ea1375c5 Update FSF address. 2011-11-08 14:43:07 +00:00
Richard W.M. Jones
9c299b64bb daemon: Use a private copy of /etc/lvm so we don't modify the real config.
In the libguestfs live case we need to be careful not to modify the
real /etc/lvm/lvm.conf file (when setting the filter rule).

When the daemon starts, make a complete copy of /etc/lvm in a
temporary directory, and adjust LVM_SYSTEM_DIR to point to the copy.
All changes are made in the temporary copy.
2011-11-04 16:37:12 +00:00
Richard W.M. Jones
6011b1f803 daemon: Don't use files with fixed names in /tmp (thanks Steve Kemp).
Although this doesn't matter for the ordinary (appliance) case, it
matters for the libguestfs live case.  In that case it could cause the
guest to be exploited by a tmp/symlink attack.
2011-11-04 15:30:12 +00:00
Matthew Booth
4e3a1205eb Fix debug help error message.
When given an invalid debug command, libguestfs responds with the
error message:

  libguestfs: error: debug: use 'debug help' to list the supported commands

However this command does not work, as debug requires two
arguments. This change updates the message to prompt the user to use
'debug help 0'.
2011-10-31 16:47:50 +00:00
Richard W.M. Jones
f223dfa29a New APIs: copy-{file,device}-to-{file,device}.
The four new APIs:
guestfs_copy_device_to_device,
guestfs_copy_device_to_file,
guestfs_copy_file_to_device, and
guestfs_copy_file_to_file
let you copy from a source to a destination, between files and
devices, optionally allowing source and destination offsets and size
to be specified.
2011-10-26 10:07:21 +01:00
Richard W.M. Jones
47412f137f New API: part-to-partnum
This converts a partition device name (eg. /dev/sda1) to a partition
number (eg. 1).  This is useful in conjunction with the parted APIs
that mostly take a disk device + partnum.
2011-10-25 12:46:05 +01:00
Richard W.M. Jones
35900223df Revert "out-of-tree build: daemon"
This reverts commit 025dba7f80.

If build and source directories are the same, you get this error:

make[3]: Leaving directory `/home/rjones/d/libguestfs/generator'
make[2]: Circular guestfs_protocol.c <- guestfs_protocol.c dependency dropped.
make[2]: Circular guestfs_protocol.h <- guestfs_protocol.h dependency dropped.
rm -f guestfs_protocol.h
ln  guestfs_protocol.h
ln: accessing `guestfs_protocol.h': No such file or directory
2011-10-24 15:47:57 +01:00
Hilko Bengen
025dba7f80 out-of-tree build: daemon 2011-10-21 16:41:22 +01:00
Richard W.M. Jones
5c2f1a2d94 mount: No longer implicitly add -o sync,noatime options. 2011-10-01 08:20:50 +01:00
Richard W.M. Jones
4e9ed01847 daemon: mkswap --help output changed, breaking linuxfsuuid group detection. 2011-09-29 16:08:20 +01:00
Richard W.M. Jones
8403f5a9d8 New APIs: compress-out, compress-device-out.
These APIs let you copy compressed files or devices out from the disk
image.

Compression is useful for large images which are mostly zeroes.  We
cannot currently do sparseness detection, and compression gives us a
form of zero detection for free.

Example usage:

$ guestfish --ro -a /dev/vg_pin/F16x64 -i \
    compress-out gzip /etc/passwd /tmp/passwd.gz
$ file -z /tmp/passwd.gz
/tmp/passwd.gz: ASCII text (gzip compressed data, was "passwd", from
Unix, last modified: Sun Aug 28 14:40:46 2011)
2011-09-28 14:52:56 +01:00
Richard W.M. Jones
ffc01285ee daemon: Move useful is_zero function to header file.
Code motion.
2011-09-28 14:52:56 +01:00
Richard W.M. Jones
99624d2922 Add an optional group ("grub") for the guestfs_grub_install API.
This also improves the documentation for this call, pointing out
several pitfalls in using it.

This unfortunately breaks existing callers that might use
guestfs_grub_install without checking for this new group.
2011-09-15 22:02:43 +01:00
Richard W.M. Jones
73be6db9bf daemon: Factor out name of virtio serial channel.
This is just code motion.
2011-09-01 13:00:25 +01:00
Richard W.M. Jones
e4cba8f2b1 protocol: Fix case where download can fail for small files.
There is another case where downloads of small files could fail if the
library side (writer) fails.  In this case the library would send back
a cancellation, but it would be received after the daemon had finished
sending the whole file (because the file is small enough).  The daemon
would reenter the main loop and immediately get an unexpected cancel
message, causing the daemon to die.

This commit also makes test-cancellation-download-librarycancels.sh
more robust.  We use Monte-Carlo testing with a range of file sizes.
Small file sizes should trigger the error case.
2011-08-18 20:02:30 +01:00
Richard W.M. Jones
5a50c04906 Improve zeroing and detection of zeroes.
This code modifies zero, zero-device, is-zero, is-zero-device.

zero and zero-device are modified so that if the blocks of the device
already contain zeroes, then we don't write zeroes.  The reason for
this is to avoid unnecessarily making the underlying storage
non-sparse or (in the qcow2 case) growing it.

is-zero and is-zero-device are modified so that zero detection is
faster.  This is a nice side effect of making the first change.

Since avoiding unnecessary zeroing involves reading the blocks before
writing them, whereas before we just blindly wrote, this can be
slower.  As you can see from the tests below, in the case where the
disk is sparse, it actually turns out to be faster, because we avoid
allocating the underlying blocks.

However in the case where the disk is non-sparse and full of existing
data, it is much slower.  There might be a case for an API flag to
adjust whether or not we perform the zero check.  I did not add this
flag because it is unlikely that the caller would have enough
information to be able to set the flag correctly.

                                (Elapsed time in seconds)
Format  Test case                 Before     After

Raw     Sparse                    16.4       5.3

        Preallocated zero         17.0       18.8

        Preallocated random       16.0       41.3

Qcow2   preallocation=off         18.7       5.6

        preallocation=metadata    17.4       5.8

The current code uses a fixed block size of 4K for reading and
writing.  I also tried the same tests with a block size of 64K but it
didn't make any significant difference.

(Thanks to Federico Simoncelli for suggesting this change)
2011-08-16 13:25:20 +01:00
Richard W.M. Jones
f133f1bb9d daemon: Don't include .gitignore in EXTRA_DIST.
This updates commit 60d5a50f4d.
2011-08-07 23:10:50 +01:00
Richard W.M. Jones
60d5a50f4d daemon: Remove separate configure of daemon subdirectory.
Combine the two Gnulib instances together.

Add checks from old daemon/configure.ac into configure.ac.

Fix daemon/Makefile.am so it is like a normal subdirectory
Makefile.am.

Because we are now using the replacement strerror_r function from
Gnulib (instead of the one from glibc directly), this requires a small
change to src/guestfs.c.
2011-08-05 12:34:11 +01:00
Richard W.M. Jones
d7356a2801 Add regression test to catch missing libraries in the appliance.
Related to RHBZ#727178.
2011-08-02 11:04:13 +01:00