[Libguestfs] [PATCH] launch: direct: Use old-style file= and format= parameters when not disabling locking (RHBZ#1503497).

Richard W.M. Jones rjones at redhat.com
Wed Jan 17 10:23:51 UTC 2018


Ancient qemu 1.5 (in RHEL 7) does not understand the
file.file.filename= and file.driver= parameters.  Go back to using the
old-style file= and format= parameters when we're not trying to set
the file.backing.file.locking=off parameter.

Fixes commit 9fe592808ccfd9ed184b88ca9c6cad2e1798dee3.

Thanks: Yongkui Guo, Václav Kadlčík.
---
 lib/launch-direct.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/lib/launch-direct.c b/lib/launch-direct.c
index aa4139359..47e8f37de 100644
--- a/lib/launch-direct.c
+++ b/lib/launch-direct.c
@@ -255,17 +255,28 @@ add_drive_standard_params (guestfs_h *g, struct backend_direct_data *data,
   }
   else {
     /* Writable qcow2 overlay on top of read-only drive. */
-    append_list_format ("file.file.filename=%s", drv->overlay);
-    append_list ("file.driver=qcow2");
-    append_list ("cache=unsafe");
-    if (drv->disk_label)
-      append_list_format ("serial=%s", drv->disk_label);
-
-    /* Add the file-specific locking option only for files, as qemu
-     * won't accept options unknown to the block driver in use.
-     */
-    if (data->qemu_mandatory_locking && drv->src.protocol == drive_protocol_file)
+    if (data->qemu_mandatory_locking &&
+	/* Add the file-specific locking option only for files, as
+	 * qemu won't accept options unknown to the block driver in
+	 * use.
+	 */
+	drv->src.protocol == drive_protocol_file) {
+      append_list_format ("file.file.filename=%s", drv->overlay);
+      append_list ("file.driver=qcow2");
       append_list ("file.backing.file.locking=off");
+    }
+    else {
+      /* Ancient qemu (esp. qemu 1.5 in RHEL 7) didn't understand the
+       * file.file.filename= parameter, so use the safer old-style
+       * form of parameters unless we actually want to specify the
+       * locking flag above.
+       */
+      append_list_format ("file=%s", drv->overlay);
+      append_list ("format=qcow2");
+    }
+    append_list ("cache=unsafe");
+    if (drv->disk_label)
+      append_list_format ("serial=%s", drv->disk_label);
   }
 
   append_list_format ("id=hd%zu", i);
-- 
2.13.2




More information about the Libguestfs mailing list