If we're given a ISO image as the source of virtio windows drivers,
reuse the same guestfs handle that is open for accessing the guest being
inspected, rather than creating a new one. This is lighter-weight and
more convenient, and, given the support for hot-inserting/ejecting an
ISO image in libguestfs, appears no less reliable.
Signed-off-by: Roman Kagan <rkagan(a)virtuozzo.com>
---
v2v/convert_windows.ml | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
index b6e6c62..51bbd8c 100644
--- a/v2v/convert_windows.ml
+++ b/v2v/convert_windows.ml
@@ -254,18 +254,15 @@ echo uninstalling Xen PV driver
)
else if is_regular_file virtio_win then (
try
- let g2 = new Guestfs.guestfs () in
- if trace () then g2#set_trace true;
- if verbose () then g2#set_verbose true;
- g2#add_drive_opts virtio_win ~readonly:true;
- g2#launch ();
- let vio_root = "/" in
- g2#mount_ro "/dev/sda" vio_root;
- let paths = g2#find vio_root in
+ let label = "viowin" in
+ g#add_drive_opts virtio_win ~readonly:true ~label:label;
+ let vio_root = (g#mkdtemp (driverdir // "isoXXXXXX")) in
+ g#mount_ro ("/dev/disk/guestfs" // label) vio_root;
+ let paths = g#find vio_root in
Array.iter (
fun path ->
let source = vio_root // path in
- if ((g2#is_file source ~followsymlinks:false) &&
+ if ((g#is_file source ~followsymlinks:false) &&
(match_vio_path_with_os path inspect.i_arch
inspect.i_major_version inspect.i_minor_version
inspect.i_product_variant)) then
@@ -275,9 +272,11 @@ echo uninstalling Xen PV driver
printf "Copying virtio driver bits: '%s:%s' ->
'%s'\n"
virtio_win path target;
- g#write target (g2#read_file source)
+ g#cp source target
) paths;
- g2#close()
+ g#umount vio_root;
+ g#remove_drive label;
+ g#rmdir vio_root
with Guestfs.Error msg ->
error (f_"%s: cannot open virtio-win ISO file: %s") virtio_win msg
)
--
2.4.3