]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: process: Extract host setup of disk device into helpers
authorPeter Krempa <pkrempa@redhat.com>
Thu, 26 Oct 2023 13:05:41 +0000 (15:05 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 27 Oct 2023 13:04:20 +0000 (15:04 +0200)
Currently the code sets up only VDPA backends but will be used later in
hotplug code too.

This patch also uses normal forward iteration in the loop in
qemuProcessPrepareHostStorage as we don't need to remove disks from the
disk list at that point.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_process.c
src/qemu/qemu_process.h

index 63c0c62a46eee90370b81738470aac92da4ccd08..1ef032dbd2407b0c4c9c6936a0c71b3a20be654f 100644 (file)
@@ -6777,6 +6777,69 @@ qemuProcessPrepareHostStorageSourceVDPA(virStorageSource *src,
 }
 
 
+/**
+ * See qemuProcessPrepareHostStorageSourceChain
+ */
+int
+qemuProcessPrepareHostStorageSource(virDomainObj *vm,
+                                    virStorageSource *src)
+{
+    /* connect to any necessary vdpa block devices */
+    if (qemuProcessPrepareHostStorageSourceVDPA(src, vm->privateData) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+/**
+ * qemuProcessPrepareHostStorageSourceChain:
+ *
+ * @vm: domain object
+ * @chain: source chain
+ *
+ * Prepare the host side of a disk for use with the VM. Note that this function
+ * accesses host resources.
+ */
+int
+qemuProcessPrepareHostStorageSourceChain(virDomainObj *vm,
+                                         virStorageSource *chain)
+{
+    virStorageSource *n;
+
+    for (n = chain; virStorageSourceIsBacking(n); n = n->backingStore) {
+        if (qemuProcessPrepareHostStorageSource(vm, n) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+
+/**
+ * qemuProcessPrepareHostStorageDisk:
+ *
+ * @vm: domain object
+ * @disk: disk definition object
+ *
+ * Prepare the host side of a disk for use with the VM. Note that this function
+ * accesses host resources.
+ *
+ * Note that this function does not call qemuDomainDetermineDiskChain as that is
+ * needed in qemuProcessPrepareHostStorage to remove disks based on the startup
+ * policy, thus other callers need to call it explicitly.
+ */
+int
+qemuProcessPrepareHostStorageDisk(virDomainObj *vm,
+                                  virDomainDiskDef *disk)
+{
+    if (qemuProcessPrepareHostStorageSourceChain(vm, disk->src) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 static int
 qemuProcessPrepareHostStorage(virQEMUDriver *driver,
                               virDomainObj *vm,
@@ -6813,16 +6876,11 @@ qemuProcessPrepareHostStorage(virQEMUDriver *driver,
         return -1;
     }
 
-    /* connect to any necessary vdpa block devices */
-    for (i = vm->def->ndisks; i > 0; i--) {
-        size_t idx = i - 1;
-        virDomainDiskDef *disk = vm->def->disks[idx];
-        virStorageSource *src;
+    for (i = 0; i < vm->def->ndisks; i++) {
+        virDomainDiskDef *disk = vm->def->disks[i];
 
-        for (src = disk->src; virStorageSourceIsBacking(src); src = src->backingStore) {
-            if (qemuProcessPrepareHostStorageSourceVDPA(src, vm->privateData) < 0)
-                return -1;
-        }
+        if (qemuProcessPrepareHostStorageDisk(vm, disk) < 0)
+            return -1;
     }
 
     return 0;
index ef05b4689218eac5e89639881316c95734d09fca..c1ea9492151e51ed547cdade01e44965c79134cb 100644 (file)
@@ -133,6 +133,13 @@ int qemuProcessPrepareHost(virQEMUDriver *driver,
                            virDomainObj *vm,
                            unsigned int flags);
 
+int qemuProcessPrepareHostStorageSource(virDomainObj *vm,
+                                        virStorageSource *src);
+int qemuProcessPrepareHostStorageSourceChain(virDomainObj *vm,
+                                             virStorageSource *chain);
+int qemuProcessPrepareHostStorageDisk(virDomainObj *vm,
+                                  virDomainDiskDef *disk);
+
 int qemuProcessDeleteThreadContext(virDomainObj *vm);
 
 int qemuProcessLaunch(virConnectPtr conn,