Richard W.M. Jones
2022-Jul-14 12:38 UTC
[Libguestfs] [PATCH virt-v2v 0/3] -o rhv: Try to avoid race condition when exiting
Requires: https://listman.redhat.com/archives/libguestfs/2022-July/029453.html This patch series tries to avoid a race condition when using -o rhv mode when virt-v2v exits after a successful conversion. The potential race is described in this bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1953286#c26 Rich.
Richard W.M. Jones
2022-Jul-14 12:38 UTC
[Libguestfs] [PATCH virt-v2v 1/3] common: Adapt to renamed function On_exit.rmdir -> On_exit.rm_rf
This function was renamed to make it clearer what it does (and that
it's potentially dangerous). The functionality is unchanged.
---
input/OVA.ml | 2 +-
input/parse_domain_from_vmx.ml | 2 +-
lib/nbdkit.ml | 2 +-
lib/qemuNBD.ml | 2 +-
lib/utils.ml | 2 +-
output/python_script.ml | 2 +-
common | 2 +-
7 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/input/OVA.ml b/input/OVA.ml
index 9e9c371285..09ceee98cb 100644
--- a/input/OVA.ml
+++ b/input/OVA.ml
@@ -78,7 +78,7 @@ let rec parse_ova ova else (
let tmpdir let t = Mkdtemp.temp_dir ~base_dir:large_tmpdir
"ova." in
- On_exit.rmdir t;
+ On_exit.rm_rf t;
t in
match detect_file_type ova with
diff --git a/input/parse_domain_from_vmx.ml b/input/parse_domain_from_vmx.ml
index 947ca41485..7aca2c2408 100644
--- a/input/parse_domain_from_vmx.ml
+++ b/input/parse_domain_from_vmx.ml
@@ -375,7 +375,7 @@ and find_nics vmx let parse_domain_from_vmx vmx_source
let tmpdir let t = Mkdtemp.temp_dir "vmx." in
- On_exit.rmdir t;
+ On_exit.rm_rf t;
t in
(* If the transport is SSH, fetch the file from remote, else
diff --git a/lib/nbdkit.ml b/lib/nbdkit.ml
index 07896684e8..1137b6bba2 100644
--- a/lib/nbdkit.ml
+++ b/lib/nbdkit.ml
@@ -105,7 +105,7 @@ let add_filter_if_available cmd filter let run_unix socket
cmd (* Create a temporary directory where we place the PID file. *)
let piddir = Mkdtemp.temp_dir "v2vnbdkit." in
- On_exit.rmdir piddir;
+ On_exit.rm_rf piddir;
let id = unique () in
let pidfile = piddir // sprintf "nbdkit%d.pid" id in
diff --git a/lib/qemuNBD.ml b/lib/qemuNBD.ml
index bbb65f4155..c3dd1666c4 100644
--- a/lib/qemuNBD.ml
+++ b/lib/qemuNBD.ml
@@ -69,7 +69,7 @@ let run_unix socket { disk; snapshot; format; imgopts }
(* Create a temporary directory where we place the PID file. *)
let piddir = Mkdtemp.temp_dir "v2vqemunbd." in
- On_exit.rmdir piddir;
+ On_exit.rm_rf piddir;
let id = unique () in
let pidfile = piddir // sprintf "qemunbd%d.pid" id in
diff --git a/lib/utils.ml b/lib/utils.ml
index 128bb69769..fd45769415 100644
--- a/lib/utils.ml
+++ b/lib/utils.ml
@@ -203,7 +203,7 @@ let error_if_no_ssh_agent () let create_v2v_directory ()
let d = Mkdtemp.temp_dir "v2v." in
chown_for_libvirt_rhbz_1045069 d;
- On_exit.rmdir d;
+ On_exit.rm_rf d;
d
(* Wait for a file to appear until a timeout. *)
diff --git a/output/python_script.ml b/output/python_script.ml
index 54ccd1b55f..ecf46c2d4b 100644
--- a/output/python_script.ml
+++ b/output/python_script.ml
@@ -33,7 +33,7 @@ type script = {
let create ?(name = "script.py") code let tmpdir =
Mkdtemp.temp_dir "v2v." in
- On_exit.rmdir tmpdir;
+ On_exit.rm_rf tmpdir;
let path = tmpdir // name in
with_open_out path (fun chan -> output_string chan code);
{ tmpdir; path }
diff --git a/common b/common
index 201632e4a7..c4c7d917b8 160000
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit 201632e4a78c1f591ea2d9038bd22f738642cf5c
+Subproject commit c4c7d917b89295ee26d1c276d9426f905b474227
--
2.37.0.rc2
Richard W.M. Jones
2022-Jul-14 12:38 UTC
[Libguestfs] [PATCH virt-v2v 2/3] -o rhv: Unmount the temporary NFS mountpoint as late as possible
To partially avoid a potential race against nbdkit or qemu-nbd
releasing files on the mountpoint before they exit, unmount as late as
we can.
See also https://bugzilla.redhat.com/show_bug.cgi?id=1953286#c26
---
output/output_rhv.ml | 4 ++--
common | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/output/output_rhv.ml b/output/output_rhv.ml
index 8571e07b0c..b3f03db760 100644
--- a/output/output_rhv.ml
+++ b/output/output_rhv.ml
@@ -204,8 +204,8 @@ module RHV = struct
if run_command cmd <> 0 then
error (f_"mount command failed, see earlier errors.\n\nThis
probably means you didn't specify the right %s path [-os %s], or else you
need to rerun virt-v2v as root.") domain_class os;
- (* Make sure it is unmounted at exit. *)
- On_exit.f (
+ (* Make sure it is unmounted at exit, as late as possible (prio=0) *)
+ On_exit.f ~prio:0 (
fun () ->
let cmd = [ "umount"; mp ] in
ignore (run_command cmd);
diff --git a/common b/common
index c4c7d917b8..a2446619e2 160000
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit c4c7d917b89295ee26d1c276d9426f905b474227
+Subproject commit a2446619e2ad668edbaab1decc999c518ae24615
--
2.37.0.rc2
Richard W.M. Jones
2022-Jul-14 12:38 UTC
[Libguestfs] [PATCH virt-v2v 3/3] output: Wait up to 5 seconds for nbdkit or qemu-nbd to exit
Before exiting virt-v2v, wait a few seconds for nbdkit or qemu-nbd
subprocesses to exit. We expect they will exit almost instaneously so
this won't have much effect. However in the -o rhv case it's helpful
to wait briefly to ensure that the NFS mountpoint is released before
we try to unmount it (also during shutdown).
https://bugzilla.redhat.com/show_bug.cgi?id=1953286#c26
---
output/output.ml | 4 ++--
common | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/output/output.ml b/output/output.ml
index 23c3932d1b..9754897fae 100644
--- a/output/output.ml
+++ b/output/output.ml
@@ -118,7 +118,7 @@ let output_to_local_file ?(changeuid = fun f -> f ())
?(compressed = false)
(* --exit-with-parent should ensure nbdkit is cleaned
* up when we exit, but it's not supported everywhere.
*)
- On_exit.kill pid
+ On_exit.kill ~wait:5 pid
| "qcow2" ->
let cmd @@ -140,7 +140,7 @@ let output_to_local_file ?(changeuid = fun f
-> f ()) ?(compressed = false)
) in
QemuNBD.set_snapshot cmd false;
let _, pid = QemuNBD.run_unix socket cmd in
- On_exit.kill pid
+ On_exit.kill ~wait:5 pid
| _ ->
error (f_"output mode only supports raw or qcow2 format (format:
%s)")
diff --git a/common b/common
index a2446619e2..f94f9eef4c 160000
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit a2446619e2ad668edbaab1decc999c518ae24615
+Subproject commit f94f9eef4c2fddabbc943ccb6b431e19ec5260c3
--
2.37.0.rc2