Commit Graph

435 Commits

Author SHA1 Message Date
Richard Jones
65e9ac4595 New APIs: findfs-label and findfs-uuid
These two calls wrap up the /sbin/findfs command, allowing you
to find a filesystem by only knowing its label or UUID.

This is especially useful when resolving LABEL=... or UUID=...
entries in /etc/fstab.

Sample guestfish session:

><fs> vfs-uuid /dev/vda1
277dd61c-bf34-4253-a8dc-df500a05e7df
><fs> findfs-uuid 277dd61c-bf34-4253-a8dc-df500a05e7df
/dev/vda1
><fs> vfs-label /dev/vda1
/boot
><fs> findfs-label /boot
/dev/vda1
><fs> vfs-uuid /dev/VolGroup00/LogVol00
40ce7c36-82ce-4a12-a99d-48f5e054162c
><fs> findfs-uuid 40ce7c36-82ce-4a12-a99d-48f5e054162c
/dev/mapper/VolGroup00-LogVol00
><fs> findfs-uuid 12345678
libguestfs: error: findfs_uuid: findfs: unable to resolve 'UUID=12345678'
2010-08-17 14:09:25 +01:00
Richard Jones
6280ac9b98 New API: is-lv: check if a block device is a logical volume (RHBZ#619793)
This adds a new API, guestfs_is_lv (g, device), which returns true iff
the named device is an LVM2 logical volume.

A sample guestfish session:

><fs> lvs
/dev/vg_f13x64/lv_root
/dev/vg_f13x64/lv_swap
><fs> list-devices
/dev/vda
><fs> list-partitions
/dev/vda1
/dev/vda2
><fs> is-lv /dev/vg_f13x64/lv_root
true
><fs> is-lv /dev/vg_f13x64/lv_swap
true
><fs> is-lv /dev/vda
false
><fs> is-lv /dev/vda1
false
><fs> is-lv /dev/vda2
false
2010-07-30 16:32:35 +01:00
Richard Jones
945e569db6 New APIs: Support for creating LUKS and managing keys.
This commit adds four APIs for creating new LUKS devices
and key management.  These are:

  luks_format         Format a LUKS device with the default cipher.
  luks_format_cipher  Format with a chosen cipher.
  luks_add_key        Add another key to an existing device.
  luks_kill_slot      Delete a key from an existing device.

This enables all the significant functionality of the
cryptsetup luks* commands.

Note that you can obtain the UUID of a LUKS device already
by using vfs-uuid.

This also includes a regression test covering all the LUKS
functions.
2010-07-22 16:51:56 +01:00
Richard Jones
637f8df837 New APIs: Support for opening LUKS-encrypted disks.
This adds support for opening LUKS-encrypted disks, via
three new APIs:

  luks_open:    Create a mapping for an encrypted disk.
  luks_open_ro: Same, but read-only mapping.
  luks_close:   Close a mapping.

A typical guestfish session using this functionality looks
like this:

  $ guestfish --ro -a encrypted.img
  ><fs> run
  ><fs> list-devices
  /dev/vda
  ><fs> list-partitions
  /dev/vda1
  /dev/vda2
  ><fs> vfs-type /dev/vda2
  crypto_LUKS
  ><fs> luks-open /dev/vda2 luksdev
  Enter key or passphrase ("key"):
  ><fs> vgscan
  ><fs> vg-activate-all true
  ><fs> pvs
  /dev/dm-0
  ><fs> vgs
  vg_f13x64encrypted
  ><fs> lvs
  /dev/vg_f13x64encrypted/lv_root
  /dev/vg_f13x64encrypted/lv_swap
  ><fs> mount /dev/vg_f13x64encrypted/lv_root /
  ><fs> ll /
  total 132
  dr-xr-xr-x.  24 root root  4096 Jul 21 12:01 .
  dr-xr-xr-x   20 root root     0 Jul 21 20:06 ..
  drwx------.   3 root root  4096 Jul 21 11:59 .dbus
  drwx------.   2 root root  4096 Jul 21 12:00 .pulse
  -rw-------.   1 root root   256 Jul 21 12:00 .pulse-cookie
  dr-xr-xr-x.   2 root root  4096 May 13 03:03 bin

NOT included in this patch:

 - An easier way to use this from guestfish.
 - Ability to create LUKS devices.
 - Ability to change LUKS keys on existing devices.
 - Direct access to the /dev/mapper device (eg. if it contains
   anything apart from VGs).
2010-07-21 20:48:40 +01:00
Richard Jones
d2cf9a15a9 New APIs: lvm-set-filter and lvm-clear-filter.
These APIs allow you to change the device filter, the list of
block devices that LVM "sees".  Either you can set it to a fixed
list of devices / partitions, or you can clear it so that LVM sees
everything.
2010-07-16 15:49:50 +01:00
Richard Jones
ba39ced880 file: Fix file command on /dev/VG/LV paths (RHBZ#582484).
Previous commit 4df593496e broke the
"file" command on logical volume paths, since these are symbolic
links.  We *should* follow these (only).

This inadvertantly broke virt-inspector too, which indicates that
we need more regression testing in this area.  Since carrying whole
Fedora images around could make the distribution even larger than
now, I'm not sure at the moment how to do this.

Thanks to Matt Booth for diagnosing this bug.
2010-06-08 16:04:01 +01:00
Richard Jones
4df593496e file: Restrict to regular files (RHBZ#582484).
The file call can hang if called on char devices (because we are
using the file -s option).

This is hard to solve cleanly without adding another file API.

However this restricts file to regular files, unless called explicitly
with a /dev/ path.  For non-regular files, it will now return a
string like "directory".

There is a small semantic change for symbolic links.  Previously
it would not have worked at all on absolute links (or rather, the
results would have been undefined).  It would have treated relative
symlinks to regular files as the regular file itself.  Now it will
return the string "symbolic link" in both cases.

This commit also makes the API safe when called on untrusted
filesystems.  Previously a filesystem might have been set up so
that (eg) /etc/redhat-release was a char device, which would have
caused virt-inspector and virt-v2v to hang.  Now it will not hang.
2010-06-04 15:07:27 +01:00
Richard Jones
74958b0ad4 touch: Restrict touch to regular files only (RHBZ#582484). 2010-06-04 13:53:10 +01:00
Richard Jones
e3befe5a2e daemon: Rearrange code in 'file' command.
path = path to access file (/sysroot/.. or /dev/..)
  display_path = original path, saved so we can display it
  buf = optional buffer which is freed along return codepaths

There should be no change to the semantics of the code.
2010-06-04 11:23:01 +01:00
Richard Jones
00cc40a5f3 Update to latest gnulib. 2010-06-04 10:19:33 +01:00
Richard Jones
4d5c228002 mkfs-b: Map block size to cluster size for VFAT and NTFS partitions (RHBZ#599464).
This also adds a regression test for VFAT and (conditionally)
NTFS filesystems.
2010-06-03 14:33:59 +01:00
Richard Jones
0606cb5467 mkfs-b: Check that blocksize parameter is > 0 and a power of 2. 2010-06-03 14:33:59 +01:00
Richard Jones
cbb0260368 parted: Check partition number >= 1 in several calls. 2010-06-02 15:35:58 +01:00
Richard Jones
3ab2d089f3 daemon: Parse output of old parted which didn't support -m option (RHBZ#598309).
This fixes the following commands when run with RHEL 5-era parted:

  get-bootable
  get-parttype
  part-list
2010-06-02 15:33:03 +01:00
Richard Jones
aee7d55fcf daemon: count_strings function returns size_t 2010-06-02 15:33:02 +01:00
Richard Jones
50eed6d20d base64-in: Ignore garbage characters in input.
On RHEL 5 you have to specify the -i option to get the
external 'base64' command to ignore \n characters.  (The
Fedora version seems to ignore these characters anyway).

Add this option so the tests can pass on RHEL 5.
2010-06-02 15:33:02 +01:00
Richard Jones
9733d47469 daemon: write-file: Check range of size parameter (RHBZ#597135).
This also adds a regression test.
2010-06-02 13:38:00 +01:00
Richard Jones
52f9cd4882 daemon: Limit label lengths (RHBZ#597118). 2010-06-02 13:38:00 +01:00
Richard Jones
da4812ab6b Fix and deprecate get_e2label and get_e2uuid (RHBZ#597112).
Fix these calls (see description in RHBZ#597112), but also
deprecate them since the new calls vfs_label and vfs_uuid can
work on any filesystem type.

This also adds a regression test for the original bug reported
in RHBZ#597112.
2010-06-01 15:30:13 +01:00
Richard Jones
27b730a682 New APIs: vfs-label and vfs-uuid return label and uuid for many fs types.
These APIs generalize the existing 'get-e2label' and 'get-e2uuid'
calls, to provide calls which should be able to get the label
and UUID for most filesystem types.  These use 'blkid' to do the
work.

I have tested that the blkid commands themselves work on RHEL 5.

(Suggested by Yufang Zhang).
2010-06-01 15:30:08 +01:00
Richard Jones
21c42e9fab daemon: Kill blkid cache to improve reliability of blkid commands.
By killing the cache file, we make blkid work in situations such
as a just-created filesystem.
2010-06-01 15:29:09 +01:00
Richard Jones
85c71f8fff daemon: Generalize the implementation of vfs-type.
Note that there is no change to the semantics of the code.
2010-06-01 13:39:25 +01:00
Richard Jones
6b500f1b8e New API: fallocate64 (replaces fallocate).
guestfs_fallocate takes an integer for the length, effectively
limiting it to creating 1GB files.  This new call takes an int64_t
for the length, but is otherwise identical.
2010-05-27 09:48:22 +01:00
Richard Jones
1bd1f9b85f New API: available-all-groups to return list of all optional groups. 2010-05-25 11:27:49 +01:00
Richard Jones
7cb6fac307 New API: ntfsresize-size to allow shrinking NTFS (RHBZ#585223). 2010-05-21 14:51:57 +01:00
Richard Jones
9be89728f2 New API: pvresize-size to allow shrinking PVs (RHBZ#585222). 2010-05-21 14:51:57 +01:00
Richard Jones
71b02d6654 New API: resize2fs-size to allow shrinking ext2 filesystems (RHBZ#585221). 2010-05-21 14:51:54 +01:00
Richard Jones
53ca11ee44 generator: Make 'xz' into an optional group.
On Ubuntu <= Karmic, xz-utils was not packaged, and therefore
any xz-related tests would fail.  Thus make this an optional
group so that we can test for this and avoid running the tests
if xz utils are not present.
2010-05-20 10:42:21 +01:00
Richard Jones
1214b32162 New API: Implement pwrite system call (partial fix for RHBZ#592883). 2010-05-20 10:30:12 +01:00
Richard Jones
3920ad95f6 New API: write for creating files with fixed content (RHBZ#501889).
The guestfs_write call can be used to create small files with
arbitrary 8 bit content, including \0 bytes.

This replaces and deprecates write-file, which cannot be modified
to use BufferIn because of an unfortunate choice in the ABI: the
size parameter to write-file, if zero, means that the daemon tries
to calculate the length of the buffer using strlen.  However this
fails if we pass a zero-length buffer using BufferIn because then
the daemon tries to do strlen on a (really) zero length buffer, not
even containing a terminating \0 character, thus segfaulting.
2010-05-20 10:30:12 +01:00
Richard Jones
55748a94bc Improve errors from tar-in/tgz-in commands (RHBZ#591155 RHBZ#591250).
This commit improves the error messages from the tar-in, tgz-in (etc)
commands by capturing the stderr from the tar command in a file and
sending that back in the error message.

The method used for the error file is primitive, and there is a case
for a more generic error file mechanism, but this will do for now.

Sample error messages after this change:

$ virt-tar -u /tmp/test1.img /tmp/not.tar /
tar_in: tar subcommand failed on directory: /: tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors at /home/rjones/d/libguestfs/tools/virt-tar line 247.

$ virt-tar -u /tmp/test1.img /tmp/test.tar /
tar_in: tar subcommand failed on directory: /: tar: access.log: Cannot open: Read-only file system
tar: Exiting with failure status due to previous errors at /home/rjones/d/libguestfs/tools/virt-tar line 247.
2010-05-13 17:08:02 +01:00
Richard Jones
b76fd51e14 Combine common code in daemon/tar.c.
This commit shouldn't result in any change in the semantics
of the code.
2010-05-13 17:08:02 +01:00
Richard Jones
dc706a639e Fix FileIn cmds losing synch if both ends send cancel messages (RHBZ#576879).
During a FileIn command (eg. upload, tar-in) if both sides
experience errors, then both sides could send cancel messages,
the result being lost synchronization.

The reason for the lost synch was because the daemon was ignoring
this case and sending an error message back which the library side
(which had cancelled) was not expecting.

Fix this by checking in the daemon for the case where the library
also cancels during daemon cancellation, and not sending an error
messages.

This also includes an enhanced regression test which checks for this
case.

This extends the original fix in
commit 5922d7084d.

More details can be found here:
https://bugzilla.redhat.com/show_bug.cgi?id=576879#c5
2010-05-13 17:08:02 +01:00
Richard Jones
287f8957fe Fix error message in string-e command (RHBZ#588651). 2010-05-13 16:22:10 +01:00
Richard Jones
0c1e77219e New API: fill-pattern for creating files with predefined patterns. 2010-05-12 17:33:16 +01:00
Richard Jones
9d158c3ab1 Run udev_settle() after swapon/swapoff (RHBZ#516096). 2010-05-12 16:13:07 +01:00
Richard Jones
f606a79ed7 daemon: Use 'error' instead of 'perror' before calling 'abort'. 2010-05-07 22:51:20 +01:00
Richard Jones
b52ef0b021 daemon: gnulib module 'error' is used directly by the daemon. 2010-05-07 22:51:20 +01:00
Richard Jones
63882fb220 daemon: Use parens around code section for safety. 2010-05-07 22:51:20 +01:00
Richard Jones
42f59b28f1 daemon: Fix read-file so it fails gracefully for large files (RHBZ#589039).
Pengzhen Cao noticed that read-file would fail for files
larger than the protocol size; this is *not* the bug.  However
it would also lose protocol synchronization after this.

The reason was that functions which return RBufferOut in the
generator must not 'touch' the *size_r parameter along error
return paths.

I fixed read-file and initrd-cat, and I checked that pread was
doing the right thing.

This also adds regression tests for read-file with various categories
of large file.
2010-05-07 15:27:29 +01:00
Richard Jones
a84f136049 daemon: Fix wc* commands to work on absolute symbolic links (RHBZ#579608). 2010-05-07 15:27:28 +01:00
Richard Jones
26991ebb81 daemon: Fix strings to work on absolute symbolic links (RHBZ#579608). 2010-05-07 15:27:28 +01:00
Richard Jones
deee8e2b4e daemon: Fix head and tail commands to work on absolute symbolic links (RHBZ#579608). 2010-05-07 15:27:28 +01:00
Richard Jones
7d8e5886a6 daemon: Fix grep and related to work on absolute symbolic links (RHBZ#579608). 2010-05-07 15:27:28 +01:00
Richard Jones
00fae9fe88 daemon: Fix checksum to work on absolute symbolic links (RHBZ#579608). 2010-05-07 15:27:28 +01:00
Richard Jones
7a4ec57e54 daemon: Fix hexdump to work on absolute symbolic links (RHBZ#579608). 2010-05-07 15:27:28 +01:00
Richard Jones
07369cb77a daemon: Fix for commands working on absolute symbolic links (RHBZ#579608).
The original idea (suggested by Al Viro) was to fork and chroot
into the sysroot and read the file from there.  Because of the
separate process being chrooted, absolute links would be resolved
correctly.  The slightly modified idea is to open the file in the
daemon process (but temporarily chrooted, so symlinks resolve
correctly), fork, and have the subprocess just be responsible for
copying the file.  (Strictly speaking we don't need to fork, but
this implementation is simpler).

This commit just includes the changes needed to the command*()
functions in daemon/guestfsd.c and adds an absolute symlink to
the test ISO for testing it.  Later commits will fix the broken
daemon commands themselves.
2010-05-07 15:27:28 +01:00
Richard Jones
34067b5c36 daemon: Change command to abort() on resource problems.
The comment in the code describes it thus:

  /* Note: abort is used in a few places along the error paths early
   * in this function.  This is because (a) cleaning up correctly is
   * very complex at these places and (b) abort is used when a
   * resource problem is indicated which would be due to much more
   * serious issues - eg. memory or file descriptor leaks.  We
   * wouldn't expect fork(2) or pipe(2) to fail in normal
   * circumstances.
   */
2010-05-07 15:27:28 +01:00
Richard Jones
01c1d82823 Update to latest gnulib. 2010-05-06 18:57:25 +01:00
Richard Jones
8a9f2ca655 Change network configuration to use macros.
Change the network configuration so everything is set using
some macros at the top of src/guestfs.c.

Also, rename the macros used in the daemon so they are not the
same.  It was a very long time since these sets of macros had to
match the ones defined in src/guestfs.c, despite what the comment
said.

Note that this commit should not change the semantics of the
program at all.
2010-05-04 15:26:20 +01:00