Commit Graph

39 Commits

Author SHA1 Message Date
Matthew Booth
04ea1375c5 Update FSF address. 2011-11-08 14:43:07 +00: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
3135b8c378 Coverity: Don't leak error strings. 2011-06-09 10:53:23 +01:00
Richard W.M. Jones
7fae594df7 Coverity: Check return value of sysroot_path.
For some reason we were checking the parameter!
2011-06-09 10:53:22 +01:00
Richard W.M. Jones
9b945cfa78 daemon: Reimplement 'mounts' and 'mountpoints' commands.
Reimplement these so they read /proc/mounts instead of trying to parse
the output of the 'mount' external command.

One consequence of this is that these commands now work again for
ntfs-3g filesystems.
2011-04-05 20:01:15 +01:00
Richard W.M. Jones
4905604390 umount-all: Use /proc/mounts instead of output of 'mount' command.
The particular issue is that ntfs-3g (or FUSE?) no longer appears
to update /etc/mtab, which meant that umount-all was not unmounting
these partitions.  But parsing /proc/mounts is simpler and more
robust in any case.
2011-03-22 11:15:34 +00:00
Richard W.M. Jones
33b638109e proto: Fix FileIn ops that abort during the chunk upload stage.
As a previous, incorrect attempt to fix RHBZ#576879 we tried to
prevent the daemon from sending an error reply if the daemon had
cancelled the transfer.  This is wrong: the daemon should send an
error reply in these cases.

A simple test case is this:

  guestfish -N fs -m /dev/sda1 upload big-file /

(This fails because the target "/" is a directory, not a file.)
Prior to this commit, libguestfs would hang instead of printing an
error.  With this commit, libguestfs prints an error.

What is happening is:

  (1) Library is uploading
  a file                          (2) In the middle of the long
                                  upload, daemon detects an error.
                                  Daemon cancels.
  (3) Library detects cancel,
  sends cancel chunk, then waits
  for the error reply from the
  daemon.                         (4) Daemon is supposed to send
                                  an error reply message.

Because step (4) wasn't happening, uploads that failed like this would
hang in the library (waiting for the error message, while the daemon
was waiting for the next request).

This also adds a regression test.

This temporarily breaks the "both ends cancel" case (RHBZ#576879c5).
Therefore the test for that is disabled, and this is fixed in the next
patch in the series.

This partially reverts commit dc706a639e.
2011-03-18 17:56:45 +00:00
Richard W.M. Jones
61a1a2b71c daemon: Parse /proc/mounts instead of /etc/mtab
Since Fedora util-linux 2.19, the %post script does:

  rm -f /etc/mtab
  ln -s /proc/mounts /etc/mtab

We are no longer running %post scripts, so this means that /etc/mtab
is a plain file in the appliance.  Usual 'mount' still updates it, but
for some reason mount.ntfs does *not* update it in Fedora 15, meaning
that you couldn't mount and then operate on NTFS partitions.

It seems better to always parse /proc/mounts (ie. what the kernel
thinks is mounted) unconditionally, rather than relying on the
capriciousness of the external mount command.

Therefore, parse /proc/mounts instead of /etc/mtab, but add a note
saying that in future we should really be parsing
/proc/self/mountinfo, but that needs a custom parser, and the format
is rather tricky:

http://lxr.linux.no/#linux+v2.6.37/Documentation/filesystems/proc.txt#L1462
2011-02-03 09:47:48 +00:00
Richard W.M. Jones
77df7d6d53 daemon: Replace root_mounted global with intelligence.
We used to maintain a global flag 'root_mounted' which tells us if the
user has mounted something on root (ie. on the sysroot directory).

This flag caused a lot of trouble (eg. RHBZ#599503) because it's hard
to keep the flag updated correctly when the user can do arbitrary
mounts and also use mkmountpoint.

Remove this flag and replace it with a test to see if something is
mounted on *or under* the sysroot.  (It has to be *or under* because
of mkmountpoint and friends).

This also replaces a rather convoluted "have we mounted root yet"
check in the mount* APIs with a simpler check to see if the mountpoint
exists and is an ordinary directory.
2011-01-27 18:08:45 +00:00
Richard W.M. Jones
1c63d8239a Revert "umount-all: Add udev_settle after unmounting disks."
This reverts commit ad2abf89c3.

Ubuntu still has errors even with the addition of udev_settle
after umount-all.  Therefore this was just masking the problem.
2010-12-07 17:57:07 +00:00
Richard W.M. Jones
ad2abf89c3 umount-all: Add udev_settle after unmounting disks.
This helps avoid an error on Ubuntu, but it's not clear if this
is a real solution or just helps by adjusting the timing of some
race condition.
2010-12-07 16:24:34 +00:00
Richard W.M. Jones
fea2e61ac1 daemon: Fix /dev/mapper paths from mounts and mountpoints (RHBZ#646432).
Make the LV paths returned by these two commands canonical.
2010-10-28 15:16:14 +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
5922d7084d Fix upload losing synchronization if root not mounted (RHBZ#576879).
Modify the generator so that it can correctly handle early
cancellation for Pathname|Device|.. parameters.  This fixes
the upload command, but consequently we need to fix the
parameters for tar_in and t?z_in commands.  This should also
mean that 'win:' can now be used as the second argument of
tar_in and t?z_in commands in guestfish, whereas previously
this wouldn't have worked.

Adds a regression test for the original problem.
2010-04-17 15:22:29 +01:00
Richard Jones
e9c3711310 daemon: Don't need to prefix error messages with the command name.
The RPC stubs already prefix the command name to error messages.
The daemon doesn't have to do this.  As a (small) benefit this also
makes the daemon slightly smaller.

Code in the daemon such as:

  if (argv[0] == NULL) {
    reply_with_error ("passed an empty list");
    return NULL;
  }

now results in error messages like this:

  ><fs> command ""
  libguestfs: error: command: passed an empty list

(whereas previously you would have seen ..command: command:..)
2010-02-12 16:49:00 +00:00
Jim Meyering
9a8889e4d0 use STREQ, not strcmp: part 1
git grep -l 'strcmp *([^=]*== *0'|xargs \
  perl -pi -e 's/\bstrcmp( *\(.*?\)) *== *0/STREQ$1/g'
2009-11-09 22:34:16 +01:00
Jim Meyering
3e70b34eed change strncmp() == 0 to STREQLEN()
git grep -l 'strncmp *([^=]*== *0'|xargs \
  perl -pi -e 's/\bstrncmp( *\(.*?\)) *== *0\b/STREQLEN$1/g'
2009-11-09 22:34:16 +01:00
Richard Jones
4556fd64a8 umount: Enable device name translation for device parameter. 2009-08-13 16:41:37 +01:00
Richard Jones
40a0f25955 mount: Check mountpoints are absolute paths. 2009-08-13 16:19:25 +01:00
Richard Jones
dcd67e2c4e In rmmountpoint, have to explicitly check for ABS_PATH (*not* NEED_ROOT). 2009-08-13 14:41:05 +01:00
Jim Meyering
a0bb8e69de do_umount: don't use RESOLVE_DEVICE anymore
* daemon/mount.c (do_umount): Don't use RESOLVE_DEVICE here,
now that the caller always invokes REQUIRE_ROOT_OR_RESOLVE_DEVICE.
2009-08-13 14:45:34 +02:00
Jim Meyering
84fc760439 generator.ml: use new "Pathname" designation
Nearly every file-related function in daemons/*.c is affected:
Remove this pair of statements from each affected do_* function:
-  NEED_ROOT (return -1);
-  ABS_PATH (dir, return -1);
and change the type of the corresponding parameter to "const char *".
* src/generator.ml: Emit NEED_ROOT just once, even when there are two or
more Pathname args.
2009-08-13 14:45:34 +02:00
Jim Meyering
6bda071b5c update all NEED_ROOT uses
run this command:
  git grep -l -w NEED_ROOT|xargs perl -pi -e \
    's/(NEED_ROOT) \((.*?)\)/$1 (return $2)/'
2009-08-13 14:45:34 +02:00
Jim Meyering
0c07f0d236 * src/generator.ml: Change all String "device"' to Device "device"'.
Then update each affected function, removing each uses of RESOLVE_DEVICE,
now that it's generated in caller from stub.c.
* daemon/blockdev.c (call_blockdev): Remove use of RESOLVE_DEVICE.
* daemon/devsparts.c (do_mkfs): Likewise.
* daemon/ext2.c (do_e2fsck_f, do_get_e2label, do_get_e2uuid): Likewise.
(do_resize2fs, do_set_e2label, do_set_e2uuid, do_tune2fs_l): Likewise.
* daemon/fsck.c (do_fsck): Likewise.
* daemon/grub.c (do_grub_install): Likewise.
* daemon/lvm.c (do_lvremove, do_pvcreate, do_pvremove): Likewise.
(do_pvresize): Likewise.
* daemon/mount.c (do_mount_vfs): Likewise.
* daemon/ntfs.c (do_ntfs_3g_probe): Likewise.
* daemon/scrub.c (do_scrub_device): Likewise.
* daemon/sfdisk.c (sfdisk, sfdisk_flag): Likewise.
* daemon/swap.c (do_mkswap, do_mkswap_L, do_mkswap_U): Likewise.
(do_swapoff_device, do_swapon_device): Likewise.
* daemon/zero.c (do_zero): Likewise.
* daemon/zerofree.c (do_zerofree): Likewise.
2009-08-13 14:45:34 +02:00
Jim Meyering
0dd6c8c844 update all uses of ABS_PATH
run this command:
  git grep -l -w ABS_PATH|xargs perl -pi -e \
    's/(?:ABS_PATH)( \(.*?,) (.*?)\)/ABS_PATH$1 return $2)/'
2009-08-13 14:45:34 +02:00
Jim Meyering
1997858e90 change almost all uses: s/IS_DEVICE/RESOLVE_DEVICE/
Use this command:
  git grep -l -w IS_DEVICE|xargs perl -pi -e \
    's/\b(?:IS_DEVICE)\b( \(.*?,) (.*?)\)/RESOLVE_DEVICE$1 return $2)/'
2009-08-13 14:45:33 +02:00
Jim Meyering
2f1a50d816 Convert all TABs-as-indentation to spaces.
Do it by running this command:
[exempted files are matched via .x-sc_TAB_in_indentation]

  git ls-files \
    | pcregrep -vf .x-sc_TAB_in_indentation \
    | xargs pcregrep -l '^ *\t' \
    | xargs perl -MText::Tabs -ni -le \
      '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-08-03 17:17:57 +02:00
Richard Jones
78029b529a Make /sysroot path configurable.
Currently /sysroot is hard-coded throughout the daemon code.

This patch turns the path into a variable so that we can change
it in future, for example to allow standalone mode to be implemented.

This patch was tested by running all the C API tests successfully.
2009-07-18 10:43:52 +01:00
Richard W.M. Jones
7428b0a70c New commands: 'mkmountpoint' and 'rmmountpoint'
These specialized commands are used to create additional mountpoints
before mounting filesystems.  They are only used where you want to
mount several unrelated or read-only filesystems together, and need
additional care to use correctly.

Here is how to use these calls to unpack the "Russian doll" nest
of a Fedora 11 live CD:

 add-ro Fedora-11-i686-Live.iso
 run
 mkmountpoint /cd
 mkmountpoint /squash
 mkmountpoint /ext3
 mount /dev/sda /cd
 mount-loop /cd/LiveOS/squashfs.img /squash
 mount-loop /squash/LiveOS/ext3fs.img /ext3

The inner filesystem is now unpacked under the /ext3 mountpoint.
2009-07-15 23:12:02 +01:00
Richard W.M. Jones
7fc3faabc7 New command: 'mountpoints' which returns a hash of device -> mountpoint. 2009-07-15 22:25:51 +01:00
Jim Meyering
a7b73d4a1e remove trailing blanks 2009-07-03 17:04:21 +02:00
Richard W.M. Jones
a548d51b70 Add mount-loop command (RHBZ#508668).
Loop device mounts don't work for the generic 'mount' commands
because the first parameter should be a file not a device.

We want to separate out files parameters from device parameters
in the long term, so this adds a new mount-loop command for this
purpose.
2009-06-29 16:03:54 +01:00
Richard W.M. Jones
25ebdcd506 Fix memory leak in daemon/mount.c:do_mount_vfs. 2009-06-29 16:00:49 +01:00
Richard Jones
56bef498f4 In the daemon, change all const char * parameters to char *. 2009-06-10 14:16:47 +01:00
Richard Jones
2df2f2854e Add IS_DEVICE checks for all calls which take a device parameter. 2009-06-10 11:11:14 +01:00
Richard Jones
e4733575ef Fix umount_all command so it unmounts filesystems in the correct order. 2009-04-30 17:25:14 +01:00
Richard Jones
d7ffe439e8 Add mount_ro, mount_options, mount_vfs. Fix small bug in OCaml generator. 2009-04-22 21:02:15 +01:00
Richard Jones
b4d2a01828 Added test suite. 2009-04-11 17:04:35 +01:00
Richard Jones
99bd425a0a Implemented 'mount' and 'touch' commands. 2009-04-03 22:25:34 +01:00