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

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