Blame SOURCES/0015-nbdkit-qemuNBD-run_unix-formally-require-externally-.patch

7bddab
From 6d99469c696ea691a908ad8a65314475e43b7bd0 Mon Sep 17 00:00:00 2001
7bddab
From: Laszlo Ersek <lersek@redhat.com>
7bddab
Date: Wed, 23 Mar 2022 11:43:30 +0100
7bddab
Subject: [PATCH] nbdkit, qemuNBD: run_unix: formally require externally
7bddab
 provided socket
7bddab
7bddab
At this point, virt-v2v never relies on the Unix domain sockets created
7bddab
inside the "run_unix" implementations. Simplify the code by removing this
7bddab
option.
7bddab
7bddab
Consequently, the internally created temporary directory only holds the
7bddab
NBD server's PID file, and never its UNIX domain socket. Therefore:
7bddab
7bddab
(1) we no longer need the libguestfs socket dir to be our temp dir,
7bddab
7bddab
(2) we need not change the file mode bits on the temp dir,
7bddab
7bddab
(3) we can rename "tmpdir" to the more specific "piddir".
7bddab
7bddab
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2066773
7bddab
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
7bddab
Message-Id: <20220323104330.9667-1-lersek@redhat.com>
7bddab
Acked-by: Richard W.M. Jones <rjones@redhat.com>
7bddab
(cherry picked from commit 9788b06765af335b054aba03f41d1b829ed13092)
7bddab
---
7bddab
 input/input_disk.ml         |  4 ++--
7bddab
 input/input_libvirt.ml      |  8 ++++----
7bddab
 input/input_ova.ml          |  2 +-
7bddab
 input/input_vddk.ml         |  2 +-
7bddab
 input/input_vmx.ml          |  4 ++--
7bddab
 input/input_xen_ssh.ml      |  2 +-
7bddab
 input/vCenter.ml            |  2 +-
7bddab
 lib/nbdkit.ml               | 24 +++++-------------------
7bddab
 lib/nbdkit.mli              |  6 +-----
7bddab
 lib/qemuNBD.ml              | 25 +++++--------------------
7bddab
 lib/qemuNBD.mli             |  6 +-----
7bddab
 output/output.ml            |  4 ++--
7bddab
 output/output_null.ml       |  2 +-
7bddab
 output/output_rhv_upload.ml |  2 +-
7bddab
 14 files changed, 28 insertions(+), 65 deletions(-)
7bddab
7bddab
diff --git a/input/input_disk.ml b/input/input_disk.ml
7bddab
index dc3bed6f..c08548ee 100644
7bddab
--- a/input/input_disk.ml
7bddab
+++ b/input/input_disk.ml
7bddab
@@ -109,7 +109,7 @@ module Disk = struct
7bddab
            Nbdkit.add_arg cmd "file" disk;
7bddab
            if Nbdkit.version nbdkit_config >= (1, 22, 0) then
7bddab
              Nbdkit.add_arg cmd "cache" "none";
7bddab
-           let _, pid = Nbdkit.run_unix ~socket cmd in
7bddab
+           let _, pid = Nbdkit.run_unix socket cmd in
7bddab
 
7bddab
            (* --exit-with-parent should ensure nbdkit is cleaned
7bddab
             * up when we exit, but it's not supported everywhere.
7bddab
@@ -120,7 +120,7 @@ module Disk = struct
7bddab
            let cmd = QemuNBD.create disk in
7bddab
            QemuNBD.set_snapshot cmd true; (* protective overlay *)
7bddab
            QemuNBD.set_format cmd (Some format);
7bddab
-           let _, pid = QemuNBD.run_unix ~socket cmd in
7bddab
+           let _, pid = QemuNBD.run_unix socket cmd in
7bddab
            On_exit.kill pid
7bddab
     ) args;
7bddab
 
7bddab
diff --git a/input/input_libvirt.ml b/input/input_libvirt.ml
7bddab
index ee836aa0..ad7e20e8 100644
7bddab
--- a/input/input_libvirt.ml
7bddab
+++ b/input/input_libvirt.ml
7bddab
@@ -87,7 +87,7 @@ and setup_servers dir disks =
7bddab
          Nbdkit.add_arg cmd "hostname" hostname;
7bddab
          Nbdkit.add_arg cmd "port" (string_of_int port);
7bddab
          Nbdkit.add_arg cmd "shared" "true";
7bddab
-         let _, pid = Nbdkit.run_unix ~socket cmd in
7bddab
+         let _, pid = Nbdkit.run_unix socket cmd in
7bddab
 
7bddab
          (* --exit-with-parent should ensure nbdkit is cleaned
7bddab
           * up when we exit, but it's not supported everywhere.
7bddab
@@ -98,7 +98,7 @@ and setup_servers dir disks =
7bddab
       | HTTP url ->
7bddab
          let cor = dir // "convert" in
7bddab
          let cmd = Nbdkit_curl.create_curl ~cor url in
7bddab
-         let _, pid = Nbdkit.run_unix ~socket cmd in
7bddab
+         let _, pid = Nbdkit.run_unix socket cmd in
7bddab
 
7bddab
          (* --exit-with-parent should ensure nbdkit is cleaned
7bddab
           * up when we exit, but it's not supported everywhere.
7bddab
@@ -113,7 +113,7 @@ and setup_servers dir disks =
7bddab
             Nbdkit.add_arg cmd "file" filename;
7bddab
             if Nbdkit.version nbdkit_config >= (1, 22, 0) then
7bddab
               Nbdkit.add_arg cmd "cache" "none";
7bddab
-            let _, pid = Nbdkit.run_unix ~socket cmd in
7bddab
+            let _, pid = Nbdkit.run_unix socket cmd in
7bddab
 
7bddab
             (* --exit-with-parent should ensure nbdkit is cleaned
7bddab
              * up when we exit, but it's not supported everywhere.
7bddab
@@ -125,7 +125,7 @@ and setup_servers dir disks =
7bddab
             let cmd = QemuNBD.create filename in
7bddab
             QemuNBD.set_snapshot cmd true; (* protective overlay *)
7bddab
             QemuNBD.set_format cmd format;
7bddab
-            let _, pid = QemuNBD.run_unix ~socket cmd in
7bddab
+            let _, pid = QemuNBD.run_unix socket cmd in
7bddab
             On_exit.kill pid
7bddab
   ) disks
7bddab
 
7bddab
diff --git a/input/input_ova.ml b/input/input_ova.ml
7bddab
index c94ddc79..796cc3bc 100644
7bddab
--- a/input/input_ova.ml
7bddab
+++ b/input/input_ova.ml
7bddab
@@ -192,7 +192,7 @@ module OVA = struct
7bddab
         let cmd = QemuNBD.create qemu_uri in
7bddab
         QemuNBD.set_snapshot cmd true; (* protective overlay *)
7bddab
         QemuNBD.set_format cmd None; (* auto-detect format *)
7bddab
-        let _, pid = QemuNBD.run_unix ~socket cmd in
7bddab
+        let _, pid = QemuNBD.run_unix socket cmd in
7bddab
         On_exit.kill pid
7bddab
       ) qemu_uris;
7bddab
 
7bddab
diff --git a/input/input_vddk.ml b/input/input_vddk.ml
7bddab
index 29764095..f8bf3d28 100644
7bddab
--- a/input/input_vddk.ml
7bddab
+++ b/input/input_vddk.ml
7bddab
@@ -196,7 +196,7 @@ information on these settings.
7bddab
                ?nfchostport ?password_file:options.input_password ?port
7bddab
                ~server ?snapshot ~thumbprint ?transports ?user
7bddab
                path in
7bddab
-           let _, pid = Nbdkit.run_unix ~socket nbdkit in
7bddab
+           let _, pid = Nbdkit.run_unix socket nbdkit in
7bddab
            On_exit.kill pid
7bddab
     ) disks;
7bddab
 
7bddab
diff --git a/input/input_vmx.ml b/input/input_vmx.ml
7bddab
index 3aa49fa6..34ae99a3 100644
7bddab
--- a/input/input_vmx.ml
7bddab
+++ b/input/input_vmx.ml
7bddab
@@ -66,7 +66,7 @@ module VMX = struct
7bddab
                         (absolute_path_from_other_file vmx_filename filename) in
7bddab
             QemuNBD.set_snapshot cmd true; (* protective overlay *)
7bddab
             QemuNBD.set_format cmd (Some "vmdk");
7bddab
-            let _, pid = QemuNBD.run_unix ~socket cmd in
7bddab
+            let _, pid = QemuNBD.run_unix socket cmd in
7bddab
             On_exit.kill pid
7bddab
         ) filenames
7bddab
 
7bddab
@@ -108,7 +108,7 @@ module VMX = struct
7bddab
             let bandwidth = options.bandwidth in
7bddab
             let nbdkit = Nbdkit_ssh.create_ssh ?bandwidth ~cor ~password
7bddab
                            ~server ?port ?user abs_path in
7bddab
-            let _, pid = Nbdkit.run_unix ~socket nbdkit in
7bddab
+            let _, pid = Nbdkit.run_unix socket nbdkit in
7bddab
             On_exit.kill pid
7bddab
         ) filenames
7bddab
     );
7bddab
diff --git a/input/input_xen_ssh.ml b/input/input_xen_ssh.ml
7bddab
index 85e24bce..989a0cc7 100644
7bddab
--- a/input/input_xen_ssh.ml
7bddab
+++ b/input/input_xen_ssh.ml
7bddab
@@ -118,7 +118,7 @@ module XenSSH = struct
7bddab
            let bandwidth = options.bandwidth in
7bddab
            let nbdkit = Nbdkit_ssh.create_ssh ?bandwidth ~cor ~password
7bddab
                           ?port ~server ?user path in
7bddab
-           let _, pid = Nbdkit.run_unix ~socket nbdkit in
7bddab
+           let _, pid = Nbdkit.run_unix socket nbdkit in
7bddab
            On_exit.kill pid
7bddab
     ) disks;
7bddab
 
7bddab
diff --git a/input/vCenter.ml b/input/vCenter.ml
7bddab
index 40d594f0..8a1a5655 100644
7bddab
--- a/input/vCenter.ml
7bddab
+++ b/input/vCenter.ml
7bddab
@@ -117,7 +117,7 @@ let rec start_nbdkit_for_path ?bandwidth ?cor ?password_file
7bddab
     Nbdkit_curl.create_curl ?bandwidth ?cor
7bddab
       ~cookie_script ~cookie_script_renew
7bddab
       ~sslverify https_url in
7bddab
-  let _, pid = Nbdkit.run_unix ~socket nbdkit in
7bddab
+  let _, pid = Nbdkit.run_unix socket nbdkit in
7bddab
   pid
7bddab
 
7bddab
 and get_https_url dcPath uri server path =
7bddab
diff --git a/lib/nbdkit.ml b/lib/nbdkit.ml
7bddab
index 9ee6f39c..07896684 100644
7bddab
--- a/lib/nbdkit.ml
7bddab
+++ b/lib/nbdkit.ml
7bddab
@@ -102,27 +102,13 @@ let add_env cmd name value = cmd.env <- (name, value) :: cmd.env
7bddab
 let add_filter_if_available cmd filter =
7bddab
   if probe_filter filter then add_filter cmd filter
7bddab
 
7bddab
-let run_unix ?socket cmd =
7bddab
-  (* Create a temporary directory where we place the socket and PID file.
7bddab
-   * Use the libguestfs socket directory, so it is more likely the full path
7bddab
-   * of the UNIX sockets will fit in the (limited) socket pathname.
7bddab
-   *)
7bddab
-  let tmpdir =
7bddab
-    let base_dir = (open_guestfs ())#get_sockdir () in
7bddab
-    let t = Mkdtemp.temp_dir ~base_dir "v2vnbdkit." in
7bddab
-    (* tmpdir must be readable (but not writable) by "other" so that
7bddab
-     * qemu can open the sockets.
7bddab
-     *)
7bddab
-    chmod t 0o755;
7bddab
-    On_exit.rmdir t;
7bddab
-    t in
7bddab
+let run_unix socket cmd =
7bddab
+  (* Create a temporary directory where we place the PID file. *)
7bddab
+  let piddir = Mkdtemp.temp_dir "v2vnbdkit." in
7bddab
+  On_exit.rmdir piddir;
7bddab
 
7bddab
   let id = unique () in
7bddab
-  let pidfile = tmpdir // sprintf "nbdkit%d.pid" id in
7bddab
-  let socket =
7bddab
-    match socket with
7bddab
-    | None -> tmpdir // sprintf "nbdkit%d.sock" id
7bddab
-    | Some socket -> socket in
7bddab
+  let pidfile = piddir // sprintf "nbdkit%d.pid" id in
7bddab
 
7bddab
   (* Construct the final command line. *)
7bddab
   let add_arg, add_args_reversed, get_args =
7bddab
diff --git a/lib/nbdkit.mli b/lib/nbdkit.mli
7bddab
index dc2fd04b..5ba83ab0 100644
7bddab
--- a/lib/nbdkit.mli
7bddab
+++ b/lib/nbdkit.mli
7bddab
@@ -92,14 +92,10 @@ val add_args : cmd -> (string * string) list -> unit
7bddab
 val add_env : cmd -> string -> string -> unit
7bddab
 (** Add name=value environment variable. *)
7bddab
 
7bddab
-val run_unix : ?socket:string -> cmd -> string * int
7bddab
+val run_unix : string -> cmd -> string * int
7bddab
 (** Start nbdkit command listening on a Unix domain socket, waiting
7bddab
     for the process to start up.
7bddab
 
7bddab
-    If optional [?socket] parameter is omitted, then a temporary
7bddab
-    Unix domain socket name is created.  If [?socket] is present
7bddab
-    then this overrides the temporary name.
7bddab
-
7bddab
     Returns the Unix domain socket name and the nbdkit process ID.
7bddab
 
7bddab
     The --exit-with-parent, --foreground, --pidfile, --newstyle and
7bddab
diff --git a/lib/qemuNBD.ml b/lib/qemuNBD.ml
7bddab
index 2c999b9f..ae21b17c 100644
7bddab
--- a/lib/qemuNBD.ml
7bddab
+++ b/lib/qemuNBD.ml
7bddab
@@ -62,30 +62,15 @@ let create disk = { disk; snapshot = false; format = None }
7bddab
 let set_snapshot cmd snap = cmd.snapshot <- snap
7bddab
 let set_format cmd format = cmd.format <- format
7bddab
 
7bddab
-let run_unix ?socket { disk; snapshot; format } =
7bddab
+let run_unix socket { disk; snapshot; format } =
7bddab
   assert (disk <> "");
7bddab
 
7bddab
-  (* Create a temporary directory where we place the socket and PID file.
7bddab
-   * Use the libguestfs socket directory, so it is more likely the full path
7bddab
-   * of the UNIX sockets will fit in the (limited) socket pathname.
7bddab
-   *)
7bddab
-  let tmpdir =
7bddab
-    let base_dir = (open_guestfs ())#get_sockdir () in
7bddab
-    let t = Mkdtemp.temp_dir ~base_dir "v2vqemunbd." in
7bddab
-    (* tmpdir must be readable (but not writable) by "other" so that
7bddab
-     * qemu can open the sockets.
7bddab
-     *)
7bddab
-    chmod t 0o755;
7bddab
-    On_exit.rmdir t;
7bddab
-    t in
7bddab
+  (* Create a temporary directory where we place the PID file. *)
7bddab
+  let piddir = Mkdtemp.temp_dir "v2vqemunbd." in
7bddab
+  On_exit.rmdir piddir;
7bddab
 
7bddab
   let id = unique () in
7bddab
-  let pidfile = tmpdir // sprintf "qemunbd%d.pid" id in
7bddab
-
7bddab
-  let socket =
7bddab
-    match socket with
7bddab
-    | Some socket -> socket
7bddab
-    | None -> tmpdir // sprintf "qemunbd%d.sock" id in
7bddab
+  let pidfile = piddir // sprintf "qemunbd%d.pid" id in
7bddab
 
7bddab
   (* Construct the qemu-nbd command line. *)
7bddab
   let args = ref [] in
7bddab
diff --git a/lib/qemuNBD.mli b/lib/qemuNBD.mli
7bddab
index 83871c5b..e10d3106 100644
7bddab
--- a/lib/qemuNBD.mli
7bddab
+++ b/lib/qemuNBD.mli
7bddab
@@ -43,12 +43,8 @@ val set_snapshot : cmd -> bool -> unit
7bddab
 val set_format : cmd -> string option -> unit
7bddab
 (** Set the format [--format] parameter. *)
7bddab
 
7bddab
-val run_unix : ?socket:string -> cmd -> string * int
7bddab
+val run_unix : string -> cmd -> string * int
7bddab
 (** Start qemu-nbd command listening on a Unix domain socket,
7bddab
     waiting for the process to start up.
7bddab
 
7bddab
-    If optional [?socket] parameter is omitted, then a temporary
7bddab
-    Unix domain socket name is created.  If [?socket] is present
7bddab
-    then this overrides the temporary name.
7bddab
-
7bddab
     Returns the Unix domain socket name and the qemu-nbd process ID. *)
7bddab
diff --git a/output/output.ml b/output/output.ml
7bddab
index 7256b547..10e685c4 100644
7bddab
--- a/output/output.ml
7bddab
+++ b/output/output.ml
7bddab
@@ -90,7 +90,7 @@ let output_to_local_file ?(changeuid = fun f -> f ())
7bddab
        let cmd = Nbdkit.add_arg cmd "cache" "none" in
7bddab
        cmd
7bddab
      );
7bddab
-     let _, pid = Nbdkit.run_unix ~socket cmd in
7bddab
+     let _, pid = Nbdkit.run_unix socket cmd in
7bddab
 
7bddab
      (* --exit-with-parent should ensure nbdkit is cleaned
7bddab
       * up when we exit, but it's not supported everywhere.
7bddab
@@ -101,7 +101,7 @@ let output_to_local_file ?(changeuid = fun f -> f ())
7bddab
      let cmd = QemuNBD.create filename in
7bddab
      QemuNBD.set_snapshot cmd false;
7bddab
      QemuNBD.set_format cmd (Some "qcow2");
7bddab
-     let _, pid = QemuNBD.run_unix ~socket cmd in
7bddab
+     let _, pid = QemuNBD.run_unix socket cmd in
7bddab
      On_exit.kill pid
7bddab
 
7bddab
   | _ ->
7bddab
diff --git a/output/output_null.ml b/output/output_null.ml
7bddab
index 86d81eaa..c8e27c0b 100644
7bddab
--- a/output/output_null.ml
7bddab
+++ b/output/output_null.ml
7bddab
@@ -70,7 +70,7 @@ module Null = struct
7bddab
     let () =
7bddab
       let cmd = Nbdkit.create ~quiet:true "null" in
7bddab
       Nbdkit.add_arg cmd "size" "7E";
7bddab
-      let _, pid = Nbdkit.run_unix ~socket cmd in
7bddab
+      let _, pid = Nbdkit.run_unix socket cmd in
7bddab
 
7bddab
       (* --exit-with-parent should ensure nbdkit is cleaned
7bddab
        * up when we exit, but it's not supported everywhere.
7bddab
diff --git a/output/output_rhv_upload.ml b/output/output_rhv_upload.ml
7bddab
index 72463e57..828996b3 100644
7bddab
--- a/output/output_rhv_upload.ml
7bddab
+++ b/output/output_rhv_upload.ml
7bddab
@@ -398,7 +398,7 @@ e command line has to match the number of guest disk images (for this guest: %d)
7bddab
           Nbdkit.add_arg cmd "insecure" "true";
7bddab
         if is_ovirt_host then
7bddab
           Nbdkit.add_arg cmd "is_ovirt_host" "true";
7bddab
-        let _, pid = Nbdkit.run_unix ~socket cmd in
7bddab
+        let _, pid = Nbdkit.run_unix socket cmd in
7bddab
         List.push_front pid nbdkit_pids
7bddab
     ) (List.combine disks disk_uuids);
7bddab
 
7bddab
-- 
7bddab
2.31.1
7bddab