Re: [Libguestfs] want to access the page file of VM from host on Xen platform using libguestfs
by Richard W.M. Jones
On Thu, Feb 09, 2012 at 03:17:22PM -0800, Irfan Ahmed wrote:
> I am using Xen and want to access the page file contents of windows
> XP SP2 virtual machine from dom0. Is it possible to read the page
> file of live Windows XP virtual machine using libguestfs. I have a C
> program and want to extend its functionality using
> libguestfs. Please help me how this can be done.
Yes; this can be done by reading the file through libguestfs, which is
what 'virt-cat' (a C program) does.
I would suggest you start with these two examples:
http://libguestfs.org/guestfs-examples.3.html
https://github.com/libguestfs/libguestfs/blob/6ca8a2db6d6f1028a35ece616af...
If you need to locate the page file (ie. it's not in a default
location) then you will have to read that from the registry, which
libguestfs can also do.
If the guest is live you won't simply be able to keep a handle open
and re-read the file. You might need to map the file to disk blocks
and read them directly. (This is a bit more experimental)
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
12 years, 8 months
[PATCH 0/3] Fix guestfish edit command.
by Richard W.M. Jones
This is a further, more comprehensive fix for
https://bugzilla.redhat.com/show_bug.cgi?id=788641
The guestfish 'edit' command (aka 'emacs', 'vi') suffered from the
same problems as virt-edit and more. It could have failed and left a
partially overwritten file, and it didn't preserve permissions etc
from the original file.
These three patches fix all this. The first is a code cleanup. The
second causes 'edit' to write to a temporary file which is atomically
moved over the original. The third copies permissions etc from the
original to the new file.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.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/
12 years, 8 months
[PATCH-v4 0/2] Add a new api wipefs
by Wanlong Gao
Hi Rich:
This is a latest patch. ;-P
Comments?
Thanks
-Wanlong Gao
Wanlong Gao (2):
NEW API: add a new api wipefs
virt-format: erase the filesystem signatures before erase partitions
TODO | 2 --
daemon/zero.c | 17 +++++++++++++++++
format/format.c | 19 ++++---------------
generator/generator_actions.ml | 14 ++++++++++++++
src/MAX_PROC_NR | 2 +-
5 files changed, 36 insertions(+), 18 deletions(-)
--
1.7.9
12 years, 8 months
want to access the page file of VM from host on Xen platform using libguestfs
by Irfan Ahmed
I am using Xen and want to access the page file contents of windows XP SP2 virtual machine from dom0. Is it possible to read the page file of live Windows XP virtual machine using libguestfs. I have a C program and want to extend its functionality using libguestfs. Any idea how this can be done using libguestfs.
--Irfan
12 years, 8 months
[PATCH v3 0/2] Add a new api wipefs
by Wanlong Gao
Hi Rich:
This is a alternative patch, if you like the api
name called wipefs ;-P
Thanks
-Wanlong Gao
Wanlong Gao (2):
NEW API: add a new api wipefs
virt-format: erase the filesystem signatures before erase partitions
TODO | 2 --
daemon/zero.c | 17 +++++++++++++++++
format/format.c | 19 ++++---------------
generator/generator_actions.ml | 14 ++++++++++++++
src/MAX_PROC_NR | 2 +-
5 files changed, 36 insertions(+), 18 deletions(-)
--
1.7.9
12 years, 8 months
Fix virt-edit so it preserves permissions (RHBZ#788641)
by Richard W.M. Jones
The first patch preserves file mode, UID, GID and SELinux context
across edited files.
The second patch adds a useful new command in guestfish ('llz') which
shows SELinux context (like 'ls -laZ') that was useful when debugging
this.
Rich.
12 years, 8 months
[PATCH 1/3] NEW API: add a new api zero_fs
by Wanlong Gao
Add the new api zero_fs to erase the filesystem signatures
on a device but now erase any data.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
daemon/zero.c | 17 +++++++++++++++++
generator/generator_actions.ml | 14 ++++++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 32 insertions(+), 1 deletions(-)
diff --git a/daemon/zero.c b/daemon/zero.c
index 398f844..348869f 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -73,6 +73,23 @@ do_zero (const char *device)
}
int
+do_zero_fs (const char *device)
+{
+ int r;
+ char *err = NULL;
+
+ const char *wipefs[] = {"wipefs", "-a", device, NULL};
+ r = commandv (NULL, &err, wipefs);
+ if (r == -1) {
+ reply_with_error ("%s", err);
+ free (err);
+ return -1;
+ }
+ free (err);
+ return 0;
+}
+
+int
do_zero_device (const char *device)
{
int64_t ssize = do_blockdev_getsize64 (device);
diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml
index 3a7be79..d27ef43 100644
--- a/generator/generator_actions.ml
+++ b/generator/generator_actions.ml
@@ -6651,6 +6651,20 @@ This option may not be specified at the same time as the C<correct> option.
=back");
+ ("zero_fs", (RErr, [Device "device"], []), 305, [Progress],
+ [InitBasicFSonLVM, Always, TestRun (
+ [["zero_fs"; "/dev/VG/LV"]])],
+ "wipe a filesystem signature from a device",
+ "\
+This command can erase filesystem or raid signatures (magic strings) from
+the specified C<device> to make the filesystem invisible for libblkid.
+This does not erase the filesystem itself nor any other data from the C<device>.
+Compare with C<guestfs_zero> which just zeroes the first few blocks of a
+device, contained the partitions on the device, but this C<guestfs_zero_fs>
+can't erase the partitions of a device.
+
+=back");
+
]
let all_functions = non_daemon_functions @ daemon_functions
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 873b744..67d04b9 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-304
+305
--
1.7.9
12 years, 9 months
[PATCH 1/2] Revert "daemon: Run udev_settle after pwrite-device finishes."
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
This reverts commit a9c8123c72db47bcab8dd738e8d5256a9ae87f11.
---
daemon/file.c | 18 +++---------------
daemon/parted.c | 3 +--
2 files changed, 4 insertions(+), 17 deletions(-)
diff --git a/daemon/file.c b/daemon/file.c
index 057e15d..91746e0 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -525,7 +525,7 @@ do_pread_device (const char *device, int count, int64_t offset, size_t *size_r)
static int
pwrite_fd (int fd, const char *content, size_t size, int64_t offset,
- const char *display_path, int settle)
+ const char *display_path)
{
ssize_t r;
@@ -541,18 +541,6 @@ pwrite_fd (int fd, const char *content, size_t size, int64_t offset,
return -1;
}
- /* 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. 'settle'
- * flag is only set on block devices.
- *
- * XXX We should be smarter about when we do this or should get rid
- * of the udev rules since we don't use blkid in cached mode.
- */
- if (settle)
- udev_settle ();
-
return r;
}
@@ -575,7 +563,7 @@ do_pwrite (const char *path, const char *content, size_t size, int64_t offset)
return -1;
}
- return pwrite_fd (fd, content, size, offset, path, 0);
+ return pwrite_fd (fd, content, size, offset, path);
}
int
@@ -593,7 +581,7 @@ do_pwrite_device (const char *device, const char *content, size_t size,
return -1;
}
- return pwrite_fd (fd, content, size, offset, device, 1);
+ return pwrite_fd (fd, content, size, offset, device);
}
/* This runs the 'file' command. */
diff --git a/daemon/parted.c b/daemon/parted.c
index 64a7d1d..16f0843 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -34,8 +34,7 @@
* COMMAND_FLAG_FOLD_STDOUT_ON_STDERR flag.
*
* parted occasionally fails to do ioctl(BLKRRPART) on the device,
- * probably because udev monitors all 'close' on block devices
- * and runs 'blkid' which opens and examines the device. We attempt
+ * apparently because of some internal race in the code. We attempt
* to detect and recover from this error if we can.
*/
static int
--
1.7.6
12 years, 9 months
[PATCH 0/2] Work-around blkid running from udev after device close.
by Richard W.M. Jones
This is a possibly better work-around for bug 769304, the bug where
blkid runs from udev whenever a device closes, causing the subsequent
operation to fail. For background to this change, see:
https://rwmj.wordpress.com/2012/01/19/udev-unexpectedness/#content
So far we have noticed this problem in two places (although I'm fairly
certain it affects many more):
- in virt-resize, after copy_device_to_device and before
part_set_bootable (which runs parted)
- in virt-format, after wiping the device (which writes zeroes then
closes it) and before blockdev_rereadpt
The fix is to run udev_settle *before* all blockdev, parted and sfdisk
commands. Note we do it before because at this point a blkid command
may be running which we have to wait for. None of these commands
should be performance sensitive (unlike pwrite_device, where I have
removed the udev_settle call).
In the parted and sfdisk cases we also have to run this command
afterwards, since parted itself will have closed the block device.
There may be alternatives to this patch:
- Add a udev rule (temporarily?) which causes udev to ignore devices
that libguestfs is using. However I feel this could be dangerous
since it may affect more than just the problematic blkid operation.
- Edit the udev rules so that the blkid rule doesn't run. This
requires complex and distro-specific edits to built-in udev rules.
- Get something into udev upstream which lessens the effect of the
blkid rule (eg. delaying it or disabling it in some circumstances)
Rich.
12 years, 9 months
[PATCH] build: Choose a virtual directory for the daemon which is not a symlink.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
Check /sbin, /usr/sbin, /bin and /usr/bin to ensure that neither the
directory nor the parent (eg. /usr) is a symlink, and use this
directory for the virtual directory used to store guestfsd in the
appliance.
---
appliance/Makefile.am | 9 +++++----
configure.ac | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/appliance/Makefile.am b/appliance/Makefile.am
index 99896be..fcf6422 100644
--- a/appliance/Makefile.am
+++ b/appliance/Makefile.am
@@ -67,10 +67,11 @@ stamp-supermin: make.sh packagelist excludelist
supermin.d/daemon.img: ../daemon/guestfsd
mkdir -p supermin.d
rm -f $@ $@-t
- mkdir sbin
- cd sbin && ln ../../daemon/guestfsd
- echo -e "sbin\nsbin/guestfsd" | cpio --quiet -o -H newc > $@-t
- rm -r sbin
+ rm -rf tmp
+ mkdir -p tmp/$(DAEMON_SUPERMIN_DIR)
+ cd tmp/$(DAEMON_SUPERMIN_DIR) && ln $(abs_top_builddir)/daemon/guestfsd
+ ( cd tmp && find | cpio --quiet -o -H newc ) > $@-t
+ rm -rf tmp
mv $@-t $@
supermin.d/init.img: init
diff --git a/configure.ac b/configure.ac
index 5caca32..019f7e4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -278,6 +278,28 @@ if test "x$enable_daemon" = "xyes"; then
AC_DEFINE([VALGRIND_DAEMON],[1],[Define to 1 to run the daemon under valgrind])
AC_DEFINE_UNQUOTED([VALGRIND_LOG_PATH],["$(pwd)"],[Path to save valgrind log files])
fi
+
+ dnl Which directory should we put the daemon in? NOTE: This
+ dnl is the "virtual" directory inside the appliance, not the
+ dnl install directory for libguestfs live. Since Fedora 17
+ dnl /sbin is a symlink to /usr/sbin. We have to put the
+ dnl daemon into a real (non-symlink) directory.
+ dirs="/sbin /usr/sbin /bin /usr/bin"
+ AC_MSG_CHECKING([which of $dirs is a real directory])
+ for dir in $dirs; do
+ parent=`dirname $dir`
+ if test \! -L $parent && test -d $parent \
+ && test \! -L $dir && test -d $dir
+ then
+ DAEMON_SUPERMIN_DIR=$dir
+ break
+ fi
+ done
+ if test "x$DAEMON_SUPERMIN_DIR" = "x"; then
+ AC_MSG_ERROR([non-symlink binary directory not found])
+ fi
+ AC_MSG_RESULT([$DAEMON_SUPERMIN_DIR])
+ AC_SUBST([DAEMON_SUPERMIN_DIR])
fi
AM_CONDITIONAL([INSTALL_DAEMON],[test "x$enable_install_daemon" = "xyes"])
AM_CONDITIONAL([VALGRIND_DAEMON],[test "x$enable_valgrind_daemon" = "xyes"])
--
1.7.6
12 years, 9 months