[PATCH 0/23] factor and const-correctness
by Jim Meyering
This started as a simple warning-elimination change.
I'll get back to that series shortly ;-)
It turned into a factorization and constification exercise
during which I got a taste of ocaml. Thanks to Rich Jones
for help with a few snippets in generator.ml.
The overall result is that many previously-manually-maintained
bits from daemon/*.c functions are now hoisted into the automatically-
generated (by generator.ml) file, stubs.c. Now, many of the
interfaces in daemon/*.c (with declarations in the autogenerated
file, daemon/actions.h) that were not const-correct are.
daemon/augeas.c | 25 +--
daemon/blockdev.c | 24 +--
daemon/checksum.c | 5
daemon/cmp.c | 8 -
daemon/command.c | 6
daemon/cpmv.c | 12 -
daemon/daemon.h | 22 +--
daemon/debug.c | 2
daemon/devsparts.c | 4
daemon/df.c | 4
daemon/dir.c | 50 +------
daemon/du.c | 5
daemon/ext2.c | 28 +---
daemon/fallocate.c | 5
daemon/file.c | 59 +-------
daemon/find.c | 5
daemon/fsck.c | 4
daemon/glob.c | 5
daemon/grep.c | 29 +---
daemon/grub.c | 6
daemon/guestfsd.c | 2
daemon/headtail.c | 13 -
daemon/hexdump.c | 5
daemon/initrd.c | 5
daemon/inotify.c | 6
daemon/link.c | 17 --
daemon/ls.c | 10 -
daemon/lvm.c | 30 +---
daemon/mknod.c | 11 -
daemon/mount.c | 54 +++----
daemon/ntfs.c | 4
daemon/readdir.c | 5
daemon/realpath.c | 5
daemon/scrub.c | 14 --
daemon/sfdisk.c | 24 +--
daemon/stat.c | 15 --
daemon/strings.c | 7 -
daemon/swap.c | 45 +-----
daemon/tar.c | 14 --
daemon/upload.c | 6
daemon/wc.c | 11 -
daemon/xattr.c | 39 ++---
daemon/zero.c | 4
daemon/zerofree.c | 4
src/generator.ml | 362 ++++++++++++++++++++++++++++++-----------------------
45 files changed, 430 insertions(+), 590 deletions(-)
15 years, 4 months
[PATCH] Don't assume grub is on a separate boot filesystem
by Matthew Booth
Paths in grub.conf are relative to the filesystem containing it. grub parsing
currently assumes that it is on /boot, and will fail if it isn't, for example
because a guest only has a single partition.
This patch makes grub parsing work harder to work out what grub paths are
relative to. Firstly, it looks for a previous detected 'linux-grub' filesystem.
If this isn't found, it tries to work out which filesystem contains
/boot/grub/menu.lst and uses that.
---
perl/lib/Sys/Guestfs/Lib.pm | 56 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm
index 72b0f7d..89f2aa6 100644
--- a/perl/lib/Sys/Guestfs/Lib.pm
+++ b/perl/lib/Sys/Guestfs/Lib.pm
@@ -1435,6 +1435,56 @@ sub _check_for_applications
$os->{apps} = \@apps;
}
+# Find the path which needs to be prepended to paths in grub.conf to make them
+# absolute
+sub _find_grub_prefix
+{
+ my ($g, $os) = @_;
+
+ my $fses = $os->{filesystems};
+ die("filesystems undefined") unless(defined($fses));
+
+ # Look for the filesystem which contains grub
+ my $grubdev;
+ foreach my $dev (keys(%$fses)) {
+ my $fsinfo = $fses->{$dev};
+ if(exists($fsinfo->{content}) && $fsinfo->{content} eq "linux-grub") {
+ $grubdev = $dev;
+ last;
+ }
+ }
+
+ my $mounts = $os->{mounts};
+ die("mounts undefined") unless(defined($mounts));
+
+ # Find where the filesystem is mounted
+ if(defined($grubdev)) {
+ foreach my $mount (keys(%$mounts)) {
+ if($mounts->{$mount} eq $grubdev) {
+ return "" if($mount eq '/');
+ return $mount;
+ }
+ }
+
+ die("$grubdev defined in filesystems, but not in mounts");
+ }
+
+ # If we didn't find it, look for /boot/grub/menu.lst, then try to work out
+ # what filesystem it's on. We use menu.lst rather than grub.conf because
+ # debian only uses menu.lst, and anaconda creates a symlink for it.
+ die(__"Can't find grub on guest") unless($g->exists('/boot/grub/menu.lst'));
+
+ # Look for the most specific mount point in mounts
+ foreach my $path qw(/boot/grub /boot /) {
+ if(exists($mounts->{$path})) {
+ return "" if($path eq '/');
+ return $path;
+ }
+ }
+
+ die("Couldn't determine which filesystem holds /boot/grub/menu.lst");
+}
+
sub _check_for_kernels
{
my ($g, $os) = @_;
@@ -1443,6 +1493,8 @@ sub _check_for_kernels
# Iterate over entries in grub.conf, populating $os->{boot}
# For every kernel we find, inspect it and add to $os->{kernels}
+ my $grub = _find_grub_prefix($g, $os);
+
my @boot_configs;
# We want
@@ -1474,7 +1526,7 @@ sub _check_for_kernels
# Check we've got a kernel entry
if(defined($grub_kernel)) {
- my $path = "/boot$grub_kernel";
+ my $path = "$grub$grub_kernel";
# Reconstruct the kernel command line
my @args = ();
@@ -1508,7 +1560,7 @@ sub _check_for_kernels
unless($@) {
$config{initrd} =
- _inspect_initrd($g, $os, "/boot$initrd",
+ _inspect_initrd($g, $os, "$grub$initrd",
$kernel->{version});
} else {
warn __x("Grub entry {title} does not specify an ".
--
1.6.2.5
15 years, 4 months
[PATCH] Add 'setcon', 'getcon' commands to set and get the SELinux context
by Richard W.M. Jones
These commands let you set and get the SELinux context of the daemon
and all operations in the API and processes run from the daemon:
$ ./fish/guestfish --ro -a /dev/mapper/vg_trick-F11x64 \
selinux 1 : \
run : \
mount /dev/vg_f11x64/lv_root / : \
sh "/usr/sbin/load_policy" : \
getcon : \
setcon "system_u:system_r:unconfined_t:s0" : \
getcon
system_u:system_r:kernel_t:s0
system_u:system_r:unconfined_t:s0
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
15 years, 4 months
[PATCH] Don't use cache=off if device is on tmpfs
by Richard W.M. Jones
[For a bug noted earlier by both Matt Booth and Jim Meyering]
If you use the guestfs_add_drive function, then currently it
generates a qemu command line element like:
-drive ...,cache=off,...
This causes qemu to try to open the device with O_DIRECT.
Unfortunately some filesystems don't support this flag, notably tmpfs,
which means you can't use libguestfs in conjunction with tmpfs. On
some systems /tmp is a tmpfs filesystem.
This patch fixes this so that if the filesystem doesn't support
O_DIRECT, then we omit the cache=off parameter. This seems reasonable
from a reliability point of view, because if you're using tmpfs then
you probably didn't expect reliability in the case where your system
suddenly powers off.
Tested using a tmpfs. Without:
$ guestfish alloc /mnt/tmp/test.img 10M : run
qemu: could not open disk image /mnt/tmp/test.img
libguestfs: error: connect: Connection refused
libguestfs: error: connect: Connection refused
libguestfs: error: connect: Connection refused
libguestfs: error: connect: Connection refused
With:
$ ./fish/guestfish
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help with commands
'quit' to quit the shell
><fs> alloc /mnt/tmp/test.img 10M
><fs> run
><fs>
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
15 years, 4 months
[PATCH libguestfs] fish: don't read freed memory
by Jim Meyering
Using the latest code, I was seeing a failure of the remote alloc part
of the test-remote.sh test:
i.e., this would fail:
make check -C regressions TESTS=test-remote.sh
Running valgrind on it, I got this:
$ libtool --mode=execute valgrind ../fish/guestfish --remote alloc test.img 10M
==11953== Memcheck, a memory error detector.
==11953== Copyright (C) 2002-2008, and GNU GPL'd, by Julian Seward et al.
==11953== Using LibVEX rev 1884, a library for dynamic binary translation.
==11953== Copyright (C) 2004-2008, and GNU GPL'd, by OpenWorks LLP.
==11953== Using valgrind-3.4.1, a dynamic binary instrumentation framework.
==11953== Copyright (C) 2000-2008, and GNU GPL'd, by Julian Seward et al.
==11953== For more details, rerun with: -v
==11953==
==11953== Invalid read of size 2
==11953== at 0x3E89C6653D: fflush (in /lib64/libc-2.10.1.so)
==11953== by 0x415E26: rc_remote (rc.c:269)
==11953== by 0x413C53: issue_command (fish.c:779)
==11953== by 0x414F81: main (fish.c:721)
==11953== Address 0x4e602e8 is 0 bytes inside a block of size 568 free'd
==11953== at 0x4A0633D: free (vg_replace_malloc.c:323)
==11953== by 0x3E89C660DC: fclose@(a)GLIBC_2.2.5 (in /lib64/libc-2.10.1.so)
==11953== by 0x415E10: rc_remote (rc.c:268)
==11953== by 0x413C53: issue_command (fish.c:779)
==11953== by 0x414F81: main (fish.c:721)
==11953==
==11953== Invalid read of size 8
==11953== at 0x3E89C66543: fflush (in /lib64/libc-2.10.1.so)
==11953== by 0x415E26: rc_remote (rc.c:269)
==11953== by 0x413C53: issue_command (fish.c:779)
==11953== by 0x414F81: main (fish.c:721)
==11953== Address 0x4e60370 is 136 bytes inside a block of size 568 free'd
==11953== at 0x4A0633D: free (vg_replace_malloc.c:323)
==11953== by 0x3E89C660DC: fclose@(a)GLIBC_2.2.5 (in /lib64/libc-2.10.1.so)
==11953== by 0x415E10: rc_remote (rc.c:268)
==11953== by 0x413C53: issue_command (fish.c:779)
==11953== by 0x414F81: main (fish.c:721)
==11953==
... (and many more) ...
The fix is to ensure that we close the file handle *after*,
not before calling xdr_destroy.
>From 99c1ef6b484866ec1e7bbd621096ea1a2294f31e Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Wed, 12 Aug 2009 14:44:14 +0200
Subject: [PATCH libguestfs] fish: don't read freed memory
* fish/rc.c (rc_remote): Close file handle only *after* xdr_destroy,
because that latter may flush its file handle (implicated via
xdrstdio_create).
---
fish/rc.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/fish/rc.c b/fish/rc.c
index e88716c..57f1c36 100644
--- a/fish/rc.c
+++ b/fish/rc.c
@@ -235,8 +235,8 @@ rc_remote (int pid, const char *cmd, int argc, char *argv[],
if (!xdr_guestfish_hello (&xdr, &hello)) {
fprintf (stderr, _("guestfish: protocol error: could not send initial greeting to server\n"));
- fclose (fp);
xdr_destroy (&xdr);
+ fclose (fp);
return -1;
}
@@ -249,8 +249,8 @@ rc_remote (int pid, const char *cmd, int argc, char *argv[],
call.exit_on_error = exit_on_error;
if (!xdr_guestfish_call (&xdr, &call)) {
fprintf (stderr, _("guestfish: protocol error: could not send initial greeting to server\n"));
- fclose (fp);
xdr_destroy (&xdr);
+ fclose (fp);
return -1;
}
xdr_destroy (&xdr);
@@ -260,13 +260,13 @@ rc_remote (int pid, const char *cmd, int argc, char *argv[],
if (!xdr_guestfish_reply (&xdr, &reply)) {
fprintf (stderr, _("guestfish: protocol error: could not decode reply from server\n"));
- fclose (fp);
xdr_destroy (&xdr);
+ fclose (fp);
return -1;
}
- fclose (fp);
xdr_destroy (&xdr);
+ fclose (fp);
return reply.r;
}
--
1.6.4.337.g5420e
15 years, 4 months
[PATCH libguestfs] build: enable automake's color-tests option
by Jim Meyering
Only marginally useful, but some like it...
This makes tests print "PASS" in green, and "FAIL" in red, when possible:
The autogen.sh snippet ensures that this automake-1.11 feature
is disabled when building-from-clone on a system with too-old automake.
This *does* modify a source file (and a version-controlled one at that),
but only when building from source on e.g. RHEL*
>From 897dab226d5d4ad5f83026d8baa730b072b1f6cd Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Mon, 10 Aug 2009 14:08:57 +0200
Subject: [PATCH libguestfs] build: enable automake's color-tests option
* configure.ac (AM_INIT_AUTOMAKE): Add color-tests.
* daemon/configure.ac: Likewise.
* autogen.sh: Detect a too-old version of automake, and if found,
dumb-down our usage of AM_INIT_AUTOMAKE to exclude the offending option.
---
autogen.sh | 9 +++++++++
configure.ac | 2 +-
daemon/configure.ac | 2 +-
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/autogen.sh b/autogen.sh
index 5179623..25cf94e 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -32,6 +32,15 @@ else
./bootstrap && echo "$t" > $curr_status
fi
+# In order to accommodate versions of automake that are older than 1.11
+# remove options that we find useful but that would otherwise not be recognized.
+v=$(automake --version | { read ver && echo ${ver#*) }; })
+case $v in
+ 1.1[1-9]*|[2-9]*) ;; # Good!
+ *) perl -pi -e 's/(AM_INIT_AUTOMAKE\(\[.*?)\s*color-tests\s*(.*)/$1 $2/'\
+ configure.ac daemon/configure.ac ;;
+esac
+
mkdir -p daemon/m4
autoreconf -i
diff --git a/configure.ac b/configure.ac
index a78ca51..27e5be9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,7 +24,7 @@ m4_define([libguestfs_extra], [])
AC_INIT([libguestfs],libguestfs_major.libguestfs_minor.libguestfs_release[]libguestfs_extra)
AC_CONFIG_AUX_DIR([build-aux])
-AM_INIT_AUTOMAKE([foreign])
+AM_INIT_AUTOMAKE([foreign color-tests])
m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
diff --git a/daemon/configure.ac b/daemon/configure.ac
index 43e331b..cd31fa8 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -17,7 +17,7 @@
AC_INIT([libguestfs-daemon],[1.0.0])
AC_CONFIG_AUX_DIR([build-aux])
-AM_INIT_AUTOMAKE([foreign])
+AM_INIT_AUTOMAKE([foreign color-tests])
m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
--
1.6.4.300.gc9df
15 years, 4 months