[PATCH 33/35] conf: Introduce 'shareBacking' for <transient> disks

Peter Krempa pkrempa at redhat.com
Fri May 21 12:47:33 UTC 2021


In case the user wants to share the disk image between multiple VMs the
qemu driver needs to hotplug such disks to instantiate the backends.
Since that doesn't work for all disk configs add a switch to force this
behaviour.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 docs/formatdomain.rst         |  6 ++++++
 docs/schemas/domaincommon.rng |  5 +++++
 src/conf/domain_conf.c        | 17 ++++++++++++++---
 src/conf/domain_conf.h        |  1 +
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index fa5c14febc..61fa520965 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -3135,6 +3135,12 @@ paravirtualized driver is specified via the ``disk`` element.
    disk transient prevents the domain from participating in migration,
    snapshots, or blockjobs. Only supported in vmx hypervisor
    (:since:`Since 0.9.5`) and ``qemu`` hypervisor (:since:`Since 6.9.0`).
+
+   In cases where the source image of the ``<transient/>`` disk is supposed to
+   be shared between multiple concurrently running VMs the optional
+   ``shareBacking`` attribute should be set to ``yes``. Note that hypervisor
+   drivers may need to hotplug such disk and thus it works only with
+   configurations supporting hotplug. :since:`Since 7.4.0`
 ``serial``
    If present, this specify serial number of virtual hard drive. For example, it
    may look like ``<serial>WD-WMAP9A966149</serial>``. Not supported for
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index a2e5c50c1d..e476eca250 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1429,6 +1429,11 @@
       </optional>
       <optional>
         <element name="transient">
+          <optional>
+            <attribute name="shareBacking">
+              <ref name='virYesNo'/>
+            </attribute>
+          </optional>
           <empty/>
         </element>
       </optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4ec6484b78..749c07b2c1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9038,6 +9038,7 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
     xmlNodePtr blockioNode;
     xmlNodePtr driverNode;
     xmlNodePtr mirrorNode;
+    xmlNodePtr transientNode;
     g_autoptr(virStorageSource) src = NULL;

     if (!(src = virDomainDiskDefParseSourceXML(xmlopt, node, ctxt, flags)))
@@ -9146,9 +9147,15 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt,
         }
     }

-    if (virXPathNode("./transient", ctxt))
+    if ((transientNode = virXPathNode("./transient", ctxt))) {
         def->transient = true;

+        if (virXMLPropTristateBool(transientNode, "shareBacking",
+                                   VIR_XML_PROP_NONE,
+                                   &def->transientShareBacking) < 0)
+            return NULL;
+    }
+
     if (virDomainDiskDefIotuneParse(def, ctxt) < 0)
         return NULL;

@@ -23540,8 +23547,12 @@ virDomainDiskDefFormat(virBuffer *buf,
         virBufferAddLit(buf, "<readonly/>\n");
     if (def->src->shared)
         virBufferAddLit(buf, "<shareable/>\n");
-    if (def->transient)
-        virBufferAddLit(buf, "<transient/>\n");
+    if (def->transient) {
+        virBufferAddLit(buf, "<transient");
+        if (def->transientShareBacking == VIR_TRISTATE_BOOL_YES)
+            virBufferAddLit(buf, " shareBacking='yes'");
+        virBufferAddLit(buf, "/>\n");
+    }
     virBufferEscapeString(buf, "<serial>%s</serial>\n", def->serial);
     virBufferEscapeString(buf, "<wwn>%s</wwn>\n", def->wwn);
     virBufferEscapeString(buf, "<vendor>%s</vendor>\n", def->vendor);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a0855d816e..34420f0a10 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -575,6 +575,7 @@ struct _virDomainDiskDef {
     unsigned int snapshot; /* virDomainSnapshotLocation, snapshot_conf.h */
     virDomainStartupPolicy startupPolicy;
     bool transient;
+    virTristateBool transientShareBacking;
     virDomainDeviceInfo info;
     virTristateBool rawio;
     virDomainDeviceSGIO sgio;
-- 
2.31.1




More information about the libvir-list mailing list