[PATCH 1/6] qemu: block: Extract code for adding NBD exports to 'qemuBlockExportAddNBD'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Centralize the logic deciding which arguments to use when exporting a
block backend via NBD to a single place so that it can be centrally
fixed in upcoming commits to support the new export method via
'block-export-add'.

Additionally this allows simplification of the caller from migration as
the logic deciding which arguments to use is extracted too.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_backup.c    | 11 +++++------
 src/qemu/qemu_block.c     | 38 ++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_block.h     |  8 ++++++++
 src/qemu/qemu_migration.c | 12 +-----------
 4 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c
index 4e61a5e52b..5376d9485d 100644
--- a/src/qemu/qemu_backup.c
+++ b/src/qemu/qemu_backup.c
@@ -502,7 +502,6 @@ qemuBackupBeginPullExportDisks(virDomainObjPtr vm,
                                struct qemuBackupDiskData *disks,
                                size_t ndisks)
 {
-    qemuDomainObjPrivatePtr priv = vm->privateData;
     size_t i;

     for (i = 0; i < ndisks; i++) {
@@ -511,11 +510,11 @@ qemuBackupBeginPullExportDisks(virDomainObjPtr vm,
         if (!dd->backupdisk->exportname)
             dd->backupdisk->exportname = g_strdup(dd->domdisk->dst);

-        if (qemuMonitorNBDServerAdd(priv->mon,
-                                    dd->store->nodeformat,
-                                    dd->backupdisk->exportname,
-                                    false,
-                                    dd->incrementalBitmap) < 0)
+        if (qemuBlockExportAddNBD(vm, NULL,
+                                  dd->store,
+                                  dd->backupdisk->exportname,
+                                  false,
+                                  dd->incrementalBitmap) < 0)
             return -1;
     }

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 6bea21347a..0be612eb1f 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3363,3 +3363,41 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,

     return 0;
 }
+
+
+/**
+ * qemuBlockExportAddNBD:
+ * @vm: domain object
+ * @drivealias: (optional) alias of -drive to export in pre-blockdev configurations
+ * @src: disk source to export
+ * @exportname: name for the export
+ * @writable: whether the NBD export allows writes
+ * @bitmap: (optional) block dirty bitmap to export along
+ *
+ * This function automatically selects the proper invocation of exporting a
+ * block backend via NBD in qemu. This includes use of nodename for blockdev
+ * and proper configuration for the exportname for older qemus.
+ *
+ * This function must be called while in the monitor context.
+ */
+int
+qemuBlockExportAddNBD(virDomainObjPtr vm,
+                      const char *drivealias,
+                      virStorageSourcePtr src,
+                      const char *exportname,
+                      bool writable,
+                      const char *bitmap)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    const char *exportsrc = drivealias;
+
+    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+        exportsrc = src->nodeformat;
+    } else {
+        /* older qemu versions didn't support configuring the exportname and
+         * took the 'drivealias' as the export name */
+        exportname = NULL;
+    }
+
+    return qemuMonitorNBDServerAdd(priv->mon, exportsrc, exportname, writable, bitmap);
+}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 0701fc18d1..0fc95fa6f6 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -276,3 +276,11 @@ int
 qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
                                virStorageSourcePtr src,
                                virStorageSourcePtr topsrc);
+
+int
+qemuBlockExportAddNBD(virDomainObjPtr vm,
+                      const char *drivealias,
+                      virStorageSourcePtr src,
+                      const char *exportname,
+                      bool writable,
+                      const char *bitmap);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 4e959abebf..132545c99f 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -445,8 +445,6 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
     for (i = 0; i < vm->def->ndisks; i++) {
         virDomainDiskDefPtr disk = vm->def->disks[i];
         g_autofree char *diskAlias = NULL;
-        const char *exportname = NULL;
-        const char *devicename = NULL;

         /* check whether disk should be migrated */
         if (!qemuMigrationAnyCopyDisk(disk, nmigrate_disks, migrate_disks))
@@ -462,14 +460,6 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
         if (!(diskAlias = qemuAliasDiskDriveFromDisk(disk)))
             goto cleanup;

-        if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
-            exportname = diskAlias;
-            devicename = disk->src->nodeformat;
-        } else {
-            exportname = NULL;
-            devicename = diskAlias;
-        }
-
         if (!server_started &&
             server.transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
             if (server.port) {
@@ -493,7 +483,7 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver,
             qemuMonitorNBDServerStart(priv->mon, &server, tls_alias) < 0)
             goto exit_monitor;

-        if (qemuMonitorNBDServerAdd(priv->mon, devicename, exportname, true, NULL) < 0)
+        if (qemuBlockExportAddNBD(vm, diskAlias, disk->src, diskAlias, true, NULL) < 0)
             goto exit_monitor;
         if (qemuDomainObjExitMonitor(driver, vm) < 0)
             goto cleanup;
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux