]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: block: Split up qemuBlockStorageSourceAttachApply
authorPeter Krempa <pkrempa@redhat.com>
Mon, 27 May 2019 15:30:12 +0000 (17:30 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 15 Jul 2019 08:26:23 +0000 (10:26 +0200)
Split up the addition of a storage source into the following sub-steps:
1) storage access dependencies (TLS transport, persistent reservation)
2) storage acccess node (file/gluster/nbd...)
3) format driver dependencies (encryption secret)
4) format driver node (qcow2, raw, ...)

The functions split out will be later reused when implementing support
for 'blockdev-create' as we'll need the dependencies plugged in first,
then blockdev-create will be called and after that successfully finishes
blockdev-add will be added.

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

index 0a6522577d5491d8afe4060b459e2ca343610b1c..8641e2011ccaf4365cff22e8fb40bc504063be77 100644 (file)
@@ -1450,25 +1450,10 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src)
 }
 
 
-/**
- * qemuBlockStorageSourceAttachApply:
- * @mon: monitor object
- * @data: structure holding data of block device to apply
- *
- * Attaches a virStorageSource definition converted to
- * qemuBlockStorageSourceAttachData to a running VM. This function expects being
- * called after the monitor was entered.
- *
- * Returns 0 on success and -1 on error with a libvirt error reported. If an
- * error occurred, changes which were already applied need to be rolled back by
- * calling qemuBlockStorageSourceAttachRollback.
- */
-int
-qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
-                                  qemuBlockStorageSourceAttachDataPtr data)
+static int
+qemuBlockStorageSourceAttachApplyStorageDeps(qemuMonitorPtr mon,
+                                             qemuBlockStorageSourceAttachDataPtr data)
 {
-    int rv;
-
     if (data->prmgrProps &&
         qemuMonitorAddObject(mon, &data->prmgrProps, &data->prmgrAlias) < 0)
         return -1;
@@ -1478,15 +1463,20 @@ qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
                              &data->authsecretAlias) < 0)
         return -1;
 
-    if (data->encryptsecretProps &&
-        qemuMonitorAddObject(mon, &data->encryptsecretProps,
-                             &data->encryptsecretAlias) < 0)
-        return -1;
-
     if (data->tlsProps &&
         qemuMonitorAddObject(mon, &data->tlsProps, &data->tlsAlias) < 0)
         return -1;
 
+    return 0;
+}
+
+
+static int
+qemuBlockStorageSourceAttachApplyStorage(qemuMonitorPtr mon,
+                                         qemuBlockStorageSourceAttachDataPtr data)
+{
+    int rv;
+
     if (data->storageProps) {
         rv = qemuMonitorBlockdevAdd(mon, data->storageProps);
         data->storageProps = NULL;
@@ -1497,6 +1487,29 @@ qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
         data->storageAttached = true;
     }
 
+    return 0;
+}
+
+
+static int
+qemuBlockStorageSourceAttachApplyFormatDeps(qemuMonitorPtr mon,
+                                            qemuBlockStorageSourceAttachDataPtr data)
+{
+    if (data->encryptsecretProps &&
+        qemuMonitorAddObject(mon, &data->encryptsecretProps,
+                             &data->encryptsecretAlias) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
+qemuBlockStorageSourceAttachApplyFormat(qemuMonitorPtr mon,
+                                        qemuBlockStorageSourceAttachDataPtr data)
+{
+    int rv;
+
     if (data->formatProps) {
         rv = qemuMonitorBlockdevAdd(mon, data->formatProps);
         data->formatProps = NULL;
@@ -1507,6 +1520,33 @@ qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
         data->formatAttached = true;
     }
 
+    return 0;
+}
+
+
+/**
+ * qemuBlockStorageSourceAttachApply:
+ * @mon: monitor object
+ * @data: structure holding data of block device to apply
+ *
+ * Attaches a virStorageSource definition converted to
+ * qemuBlockStorageSourceAttachData to a running VM. This function expects being
+ * called after the monitor was entered.
+ *
+ * Returns 0 on success and -1 on error with a libvirt error reported. If an
+ * error occurred, changes which were already applied need to be rolled back by
+ * calling qemuBlockStorageSourceAttachRollback.
+ */
+int
+qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
+                                  qemuBlockStorageSourceAttachDataPtr data)
+{
+    if (qemuBlockStorageSourceAttachApplyStorageDeps(mon, data) < 0 ||
+        qemuBlockStorageSourceAttachApplyStorage(mon, data) < 0 ||
+        qemuBlockStorageSourceAttachApplyFormatDeps(mon, data) < 0 ||
+        qemuBlockStorageSourceAttachApplyFormat(mon, data) < 0)
+        return -1;
+
     if (data->driveCmd) {
         if (qemuMonitorAddDrive(mon, data->driveCmd) < 0)
             return -1;