Richard W.M. Jones
2010-Feb-12 12:40 UTC
[Libguestfs] [PATCH 0/4] Allow QEMU if=... (block device emulation) to be overridden
The background to this is that virt-v2v needs to boot the appliance with a specific block device emulation (eg. IDE, not virtio), because when it runs mkinitrd, mkinitrd will assume that the block devices available in the appliance are also the ones which apply at guest boot time. There's no way to override this assumption in mkinitrd (particularly in the old mkinitrd versions that shipped with RHEL3/4/5), so we have to change libguestfs to allow this instead. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Richard W.M. Jones
2010-Feb-12 12:44 UTC
[Libguestfs] [PATCH 1/4] generator: 'interface' is a reserved word in Java.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora -------------- next part -------------->From 48a9ff73319d0d065bff2b9374c84bcf6438cb20 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Fri, 12 Feb 2010 11:46:40 +0000 Subject: [PATCH 1/4] generator: 'interface' is a reserved word in Java. --- src/generator.ml | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 2cede47..7db58eb 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4787,6 +4787,7 @@ let check_functions () "for"; "forall"; "foreign"; "fun"; "function"; "functor"; "goto"; "hiding"; "if"; "import"; "in"; "include"; "infix"; "infixl"; "infixr"; "inherit"; "initializer"; "inline"; "instance"; "int"; + "interface"; "land"; "lazy"; "let"; "long"; "lor"; "lsl"; "lsr"; "lxor"; "match"; "mdo"; "method"; "mod"; "module"; "mutable"; "new"; "newtype"; "object"; "of"; "open"; "or"; "private"; "qualified"; -- 1.6.5.2
Richard W.M. Jones
2010-Feb-12 12:45 UTC
[Libguestfs] [PATCH 2/4] New APIs: add-drive{, -ro}-with-if allows you to set QEMU block emulation.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -------------- next part -------------->From 946dc06bb861a38cae959416362e4561c9e4829a Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Fri, 12 Feb 2010 11:47:18 +0000 Subject: [PATCH 2/4] New APIs: add-drive{,-ro}-with-if allows you to set QEMU block emulation. The default if=... comes from configure time (currently it defaults to if=virtio). This change allows you to set the QEMU block emulation. We don't think this will be used very often, but virt-v2v requires it in order to work around a subtle problem with running 'mkinitrd' in an appliance attached to a guest. --- src/generator.ml | 25 +++++++++++++++++++++++++ src/guestfs.c | 24 +++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 7db58eb..607b6d1 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -489,9 +489,15 @@ image). This is equivalent to the qemu parameter C<-drive file=filename,cache=off,if=...>. + C<cache=off> is omitted in cases where it is not supported by the underlying filesystem. +C<if=...> is set at compile time by the configuration option +C<./configure --with-drive-if=...>. In the rare case where you +might need to change this at run time, use C<guestfs_add_drive_with_if> +or C<guestfs_add_drive_ro_with_if>. + Note that this call checks for the existence of C<filename>. This stops you from specifying other types of drive which are supported by qemu such as C<nbd:> and C<http:> URLs. To specify those, use @@ -540,6 +546,11 @@ changes to be committed, although qemu can support this. This is equivalent to the qemu parameter C<-drive file=filename,snapshot=on,if=...>. +C<if=...> is set at compile time by the configuration option +C<./configure --with-drive-if=...>. In the rare case where you +might need to change this at run time, use C<guestfs_add_drive_with_if> +or C<guestfs_add_drive_ro_with_if>. + Note that this call checks for the existence of C<filename>. This stops you from specifying other types of drive which are supported by qemu such as C<nbd:> and C<http:> URLs. To specify those, use @@ -887,6 +898,20 @@ qemu, which is not very helpful."); "\ Return the recovery process enabled flag."); + ("add_drive_with_if", (RErr, [String "filename"; String "iface"]), -1, [], + [], + "add a drive specifying the QEMU block emulation to use", + "\ +This is the same as C<guestfs_add_drive> but it allows you +to specify the QEMU interface emulation to use at run time."); + + ("add_drive_ro_with_if", (RErr, [String "filename"; String "iface"]), -1, [], + [], + "add a drive read-only specifying the QEMU block emulation to use", + "\ +This is the same as C<guestfs_add_drive_ro> but it allows you +to specify the QEMU interface emulation to use at run time."); + ] (* daemon_functions are any functions which cause some action diff --git a/src/guestfs.c b/src/guestfs.c index 9908e7f..3c00114 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -748,7 +748,8 @@ guestfs__config (guestfs_h *g, } int -guestfs__add_drive (guestfs_h *g, const char *filename) +guestfs__add_drive_with_if (guestfs_h *g, const char *filename, + const char *drive_if) { size_t len = strlen (filename) + 64; char buf[len]; @@ -771,12 +772,12 @@ guestfs__add_drive (guestfs_h *g, const char *filename) int fd = open (filename, O_RDONLY|O_DIRECT); if (fd >= 0) { close (fd); - snprintf (buf, len, "file=%s,cache=off,if=" DRIVE_IF, filename); + snprintf (buf, len, "file=%s,cache=off,if=%s", filename, drive_if); } else { fd = open (filename, O_RDONLY); if (fd >= 0) { close (fd); - snprintf (buf, len, "file=%s,if=" DRIVE_IF, filename); + snprintf (buf, len, "file=%s,if=%s", filename, drive_if); } else { perrorf (g, "%s", filename); return -1; @@ -787,7 +788,8 @@ guestfs__add_drive (guestfs_h *g, const char *filename) } int -guestfs__add_drive_ro (guestfs_h *g, const char *filename) +guestfs__add_drive_ro_with_if (guestfs_h *g, const char *filename, + const char *drive_if) { size_t len = strlen (filename) + 64; char buf[len]; @@ -802,12 +804,24 @@ guestfs__add_drive_ro (guestfs_h *g, const char *filename) return -1; } - snprintf (buf, len, "file=%s,snapshot=on,if=%s", filename, DRIVE_IF); + snprintf (buf, len, "file=%s,snapshot=on,if=%s", filename, drive_if); return guestfs__config (g, "-drive", buf); } int +guestfs__add_drive (guestfs_h *g, const char *filename) +{ + return guestfs__add_drive_with_if (g, filename, DRIVE_IF); +} + +int +guestfs__add_drive_ro (guestfs_h *g, const char *filename) +{ + return guestfs__add_drive_ro_with_if (g, filename, DRIVE_IF); +} + +int guestfs__add_cdrom (guestfs_h *g, const char *filename) { if (strchr (filename, ',') != NULL) { -- 1.6.5.2
Richard W.M. Jones
2010-Feb-12 12:45 UTC
[Libguestfs] [PATCH 3/4] Sys::Guestfs::Lib::open_guest: Remove freeform parameters.
-- Richard Jones, Virtualization Group, Red Hat http://people.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 -------------- next part -------------->From 33b4b759afe58c959bdc8b904d618aa1d699a240 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Fri, 12 Feb 2010 12:08:58 +0000 Subject: [PATCH 3/4] Sys::Guestfs::Lib::open_guest: Remove freeform parameters. Remove the ability to pass freeform parameters to Sys::Virt->new. We don't use it, it makes the code more complex to modify, and indeed there are no other args that Sys::Virt->new supports so this would never be used. Also change $readwrite to $rw to match parameter name. --- perl/lib/Sys/Guestfs/Lib.pm | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm index 21c9a64..c9a3237 100644 --- a/perl/lib/Sys/Guestfs/Lib.pm +++ b/perl/lib/Sys/Guestfs/Lib.pm @@ -104,8 +104,7 @@ The handle is still in the config state when it is returned, so you have to call C<$g-E<gt>launch ()>. The optional C<address> parameter can be added to specify the libvirt -URI. In addition, L<Sys::Virt(3)> lists other parameters which are -passed through to C<Sys::Virt-E<gt>new> unchanged. +URI. The implicit libvirt handle is closed after this function, I<unless> you call the function in C<wantarray> context, in which case the @@ -126,7 +125,8 @@ sub open_guest my $first = shift; my %params = @_; - my $readwrite = $params{rw}; + my $rw = $params{rw}; + my $address = $params{address}; my @images = (); if (ref ($first) eq "ARRAY") { @@ -154,12 +154,15 @@ sub open_guest die __"open_guest: too many domains listed on command line" if @images > 1; - $conn = Sys::Virt->new (readonly => 1, @_); + my @libvirt_args = (); + push @libvirt_args, address => $address if defined $address; + + $conn = Sys::Virt->new (readonly => 1, @libvirt_args); die __"open_guest: cannot connect to libvirt" unless $conn; my @doms = $conn->list_defined_domains (); my $isitinactive = 1; - unless ($readwrite) { + unless ($rw) { # In the case where we want read-only access to a domain, # allow the user to specify an active domain too. push @doms, $conn->list_domains (); @@ -199,7 +202,7 @@ sub open_guest # We've now got the list of @images, so feed them to libguestfs. my $g = Sys::Guestfs->new (); foreach (@images) { - if ($readwrite) { + if ($rw) { $g->add_drive ($_); } else { $g->add_drive_ro ($_); -- 1.6.5.2
Richard W.M. Jones
2010-Feb-12 12:46 UTC
[Libguestfs] [PATCH 4/4] Sys::Guestfs::Lib::open_guest: Add interface parameter.
-- 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 -------------- next part -------------->From c03b7e4d756597f30415260a84a3caee3d9d6bde Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Fri, 12 Feb 2010 12:13:40 +0000 Subject: [PATCH 4/4] Sys::Guestfs::Lib::open_guest: Add interface parameter. This allows you to override the default QEMU block device emulation. --- perl/lib/Sys/Guestfs/Lib.pm | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm index c9a3237..e17728d 100644 --- a/perl/lib/Sys/Guestfs/Lib.pm +++ b/perl/lib/Sys/Guestfs/Lib.pm @@ -117,6 +117,10 @@ disk image, then C<$conn> and C<$dom> will be C<undef>. If the C<Sys::Virt> module is not available, then libvirt is bypassed, and this function can only open disk images. +The optional C<interface> parameter can be used to open devices with +C<add_drive{,_ro}_with_if>. See +L<Sys::Guestfs/guestfs_add_drive_with_if> for more details. + =cut sub open_guest @@ -127,6 +131,7 @@ sub open_guest my $rw = $params{rw}; my $address = $params{address}; + my $interface = $params{interface}; my @images = (); if (ref ($first) eq "ARRAY") { @@ -203,9 +208,17 @@ sub open_guest my $g = Sys::Guestfs->new (); foreach (@images) { if ($rw) { - $g->add_drive ($_); + if ($interface) { + $g->add_drive_with_if ($_, $interface); + } else { + $g->add_drive ($_); + } } else { - $g->add_drive_ro ($_); + if ($interface) { + $g->add_drive_ro_with_if ($_, $interface); + } else { + $g->add_drive_ro ($_); + } } } -- 1.6.5.2
Richard W.M. Jones
2010-Feb-12 12:50 UTC
[Libguestfs] [v2v PATCH] Force appliance to use IDE interface. (was: Re: [PATCH 0/4] Allow QEMU if=... (block device emulation) to be overridden)
The only changes that should be needed to virt-v2v are attached (untested). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -------------- next part -------------->From d4615e106772deaa635784fc33b26e9a8f3a79c4 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Fri, 12 Feb 2010 12:49:11 +0000 Subject: [PATCH] Force appliance to use IDE interface. --- v2v/virt-v2v.pl | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/v2v/virt-v2v.pl b/v2v/virt-v2v.pl index cd23514..9bc65be 100755 --- a/v2v/virt-v2v.pl +++ b/v2v/virt-v2v.pl @@ -330,10 +330,12 @@ exit(0); sub get_guestfs_handle { - my $g = open_guest(\@_, rw => 1); + my $interface = "ide"; + + my $g = open_guest(\@_, rw => 1, interface => $interface); # Add the transfer iso if there is one - $g->add_drive($transferiso) if(defined($transferiso)); + $g->add_drive_with_if($transferiso, $interface) if(defined($transferiso)); # Enable selinux in the guest $g->set_selinux(1); -- 1.6.5.2
Matthew Booth
2010-Feb-12 16:16 UTC
[Libguestfs] [PATCH 0/4] Allow QEMU if=... (block device emulation) to be overridden
On 12/02/10 12:40, Richard W.M. Jones wrote:> > The background to this is that virt-v2v needs to boot the appliance > with a specific block device emulation (eg. IDE, not virtio), because > when it runs mkinitrd, mkinitrd will assume that the block devices > available in the appliance are also the ones which apply at guest boot > time. There's no way to override this assumption in mkinitrd > (particularly in the old mkinitrd versions that shipped with > RHEL3/4/5), so we have to change libguestfs to allow this instead. > > Rich. >ACK to this whole series. Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team M: +44 (0)7977 267231 GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490