]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: domain: Add infrastructure to generate block node names
authorPeter Krempa <pkrempa@redhat.com>
Fri, 7 Jul 2017 12:29:32 +0000 (14:29 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 21 Aug 2018 13:46:06 +0000 (15:46 +0200)
Node names for block objects in qemu need to be unique for an instance
of the qemu process. Add a counter to generate objects sequentially and
store it in the status XML so that we can restore it.

The helpers added allow to create new node names and reset the counter
after the VM process terminates.

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

index f570081e3a2d88b142419b6f8992bcc086f6a5fb..6e51f590cd9a291984e16486c1066dc94793c3e9 100644 (file)
@@ -2438,6 +2438,9 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf,
 
     qemuDomainObjPrivateXMLFormatPR(buf, priv);
 
+    if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
+        virBufferAsprintf(buf, "<nodename index='%llu'/>\n", priv->nodenameindex);
+
     if (qemuDomainObjPrivateXMLFormatBlockjobs(buf, vm) < 0)
         return -1;
 
@@ -2933,6 +2936,14 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
     if (qemuDomainObjPrivateXMLParseBlockjobs(priv, ctxt) < 0)
         goto error;
 
+    qemuDomainStorageIdReset(priv);
+    if (virXPathULongLong("string(./nodename/@index)", ctxt,
+                          &priv->nodenameindex) == -2) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("failed to parse node name index"));
+        goto error;
+    }
+
     return 0;
 
  error:
@@ -13179,3 +13190,30 @@ qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv)
 
     return ret;
 }
+
+
+/**
+ * qemuDomainStorageIdNew:
+ * @priv: qemu VM private data object.
+ *
+ * Generate a new unique id for a storage object. Useful for node name generation.
+ */
+unsigned int
+qemuDomainStorageIdNew(qemuDomainObjPrivatePtr priv)
+{
+    return ++priv->nodenameindex;
+}
+
+
+/**
+ * qemuDomainStorageIdReset:
+ * @priv: qemu VM private data object.
+ *
+ * Resets the data for the node name generator. The node names need to be unique
+ * for a single instance, so can be reset on VM shutdown.
+ */
+void
+qemuDomainStorageIdReset(qemuDomainObjPrivatePtr priv)
+{
+    priv->nodenameindex = 0;
+}
index 7b79d7725725be2686384494bd1e0f29d6e975c5..5dcbdfbbe158a0ec741f4e42916a3e6ea1f09181 100644 (file)
@@ -363,6 +363,9 @@ struct _qemuDomainObjPrivate {
 
     /* true if qemu-pr-helper process is running for the domain */
     bool prDaemonRunning;
+
+    /* counter for generating node names for qemu disks */
+    unsigned long long nodenameindex;
 };
 
 # define QEMU_DOMAIN_PRIVATE(vm) \
@@ -1063,4 +1066,7 @@ qemuDomainDiskCachemodeFlags(int cachemode,
 
 char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv);
 
+unsigned int qemuDomainStorageIdNew(qemuDomainObjPrivatePtr priv);
+void qemuDomainStorageIdReset(qemuDomainObjPrivatePtr priv);
+
 #endif /* __QEMU_DOMAIN_H__ */
index e1278db9d9af90355de3c8dc1692730584f1cd61..39716f91625f86bf22125a10230ff9b105cd6926 100644 (file)
@@ -7157,6 +7157,9 @@ void qemuProcessStop(virQEMUDriverPtr driver,
     /* clear all private data entries which are no longer needed */
     qemuDomainObjPrivateDataClear(priv);
 
+    /* reset node name allocator */
+    qemuDomainStorageIdReset(priv);
+
     /* The "release" hook cleans up additional resources */
     if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
         char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
index 4fb5f326c2e772a1a0eb8e327983174adc667c37..c9f5c4e76a072e7cbf0f2c7679377923cca2c665 100644 (file)
     <flag name='isa-serial'/>
     <flag name='dump-completed'/>
     <flag name='hda-output'/>
+    <flag name='blockdev'/>
   </qemuCaps>
   <devices>
     <device alias='rng0'/>
   <channelTargetDir path='/var/lib/libvirt/qemu/channel/target/domain-1-upstream'/>
   <chardevStdioLogd/>
   <allowReboot value='yes'/>
+  <nodename index='123'/>
   <blockjobs active='no'/>
   <domain type='kvm' id='1'>
     <name>upstream</name>