]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: domain: Introduce helper to convert <loader> into virStorageSource
authorPeter Krempa <pkrempa@redhat.com>
Fri, 15 Nov 2019 15:25:26 +0000 (16:25 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 22 Nov 2019 07:32:25 +0000 (08:32 +0100)
Add a helper which will covert the PFLASH code file and variable file
into the virStorageSource objects stored in private data so that we can
use them with -blockdev while keeping the infrastructure to determine
the path to the loaders intact.

This is a temporary solution until we will want to do snapshots of the
pflash where we will be forced do track the full backing chain in the
XML.

In the meanwhile just convert it partially so that we can stop using
-drive.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index 174c780fed8efdf1203287ee2a64e5aab8b0f67e..c4d5f085416f6b8abdee777392174d351ddf6d2c 100644 (file)
@@ -15609,3 +15609,61 @@ qemuDomainSupportsCheckpointsBlockjobs(virDomainObjPtr vm)
 
     return 0;
 }
+
+/**
+ * qemuDomainInitializePflashStorageSource:
+ *
+ * This helper converts the specification of the source of the 'loader' in case
+ * PFLASH is required to virStorageSources in case QEMU_CAPS_BLOCKDEV is present.
+ *
+ * This helper is used in the intermediate state when we don't support full
+ * backing chains for pflash drives in the XML.
+ *
+ * The nodenames used here have a different prefix to allow for a later
+ * conversion. The prefixes are 'libvirt-pflash0-storage',
+ * 'libvirt-pflash0-format' for pflash0 and 'libvirt-pflash1-storage' and
+ * 'libvirt-pflash1-format' for pflash1.
+ */
+int
+qemuDomainInitializePflashStorageSource(virDomainObjPtr vm)
+{
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virDomainDefPtr def = vm->def;
+    g_autoptr(virStorageSource) pflash0 = NULL;
+    g_autoptr(virStorageSource) pflash1 = NULL;
+
+    if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
+        return 0;
+
+    if (!def->os.loader ||
+        def->os.loader->type != VIR_DOMAIN_LOADER_TYPE_PFLASH)
+        return 0;
+
+    if (!(pflash0 = virStorageSourceNew()))
+        return -1;
+
+    pflash0->type = VIR_STORAGE_TYPE_FILE;
+    pflash0->format = VIR_STORAGE_FILE_RAW;
+    pflash0->path = g_strdup(def->os.loader->path);
+    pflash0->readonly = def->os.loader->readonly;
+    pflash0->nodeformat = g_strdup("libvirt-pflash0-format");
+    pflash0->nodestorage = g_strdup("libvirt-pflash0-storage");
+
+
+    if (def->os.loader->nvram) {
+        if (!(pflash1 = virStorageSourceNew()))
+            return -1;
+
+        pflash1->type = VIR_STORAGE_TYPE_FILE;
+        pflash1->format = VIR_STORAGE_FILE_RAW;
+        pflash1->path = g_strdup(def->os.loader->nvram);
+        pflash1->readonly = false;
+        pflash1->nodeformat = g_strdup("libvirt-pflash1-format");
+        pflash1->nodestorage = g_strdup("libvirt-pflash1-storage");
+    }
+
+    priv->pflash0 = g_steal_pointer(&pflash0);
+    priv->pflash1 = g_steal_pointer(&pflash1);
+
+    return 0;
+}
index a545edb022debc3fb8a0b184b3d5a4e58c3b0455..db45a932dcbda98d5719809baf5dc4d772fa0f9b 100644 (file)
@@ -1235,3 +1235,6 @@ qemuDomainSupportsCheckpointsBlockjobs(virDomainObjPtr vm)
 
 int
 qemuDomainMakeCPUMigratable(virCPUDefPtr cpu);
+
+int
+qemuDomainInitializePflashStorageSource(virDomainObjPtr vm);