]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Add virStorageSource member for SCSI host device config data
authorPeter Krempa <pkrempa@redhat.com>
Wed, 9 Sep 2020 13:27:45 +0000 (15:27 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 15 Sep 2020 13:20:23 +0000 (15:20 +0200)
The backend for the SCSI host device is a storage source. While the
definition doesn't look like that it's converted to a storage source
when the VM is running.

Add the storage source to the definition object and also parse/format
its private data which will be used for internal state storage while
the VM is running.

Note that the virStorageSourcePtr may not be allocated all the time so
the private data parser allocates it if there is any private data
present.

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

index 1c802e8fae02421c7e85fb7f865a18fcaa2f5ad5..4d296f7bcb14ec364623a1d8394437e4d838b001 100644 (file)
@@ -3019,6 +3019,8 @@ virDomainHostdevSubsysSCSIClear(virDomainHostdevSubsysSCSIPtr scsisrc)
         scsisrc->u.iscsi.src = NULL;
     } else {
         VIR_FREE(scsisrc->u.host.adapter);
+        virObjectUnref(scsisrc->u.host.src);
+        scsisrc->u.host.src = NULL;
     }
 }
 
@@ -8263,7 +8265,9 @@ virDomainStorageNetworkParseHosts(xmlNodePtr node,
 static int
 virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
                                           xmlXPathContextPtr ctxt,
-                                          virDomainHostdevSubsysSCSIPtr scsisrc)
+                                          virDomainHostdevSubsysSCSIPtr scsisrc,
+                                          unsigned int flags,
+                                          virDomainXMLOptionPtr xmlopt)
 {
     virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
     g_autofree char *bus = NULL;
@@ -8313,6 +8317,16 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode,
         return -1;
     }
 
+    if (flags & VIR_DOMAIN_DEF_PARSE_STATUS &&
+        xmlopt && xmlopt->privateData.storageParse) {
+        if ((ctxt->node = virXPathNode("./privateData", ctxt))) {
+            if (!scsihostsrc->src &&
+                !(scsihostsrc->src = virStorageSourceNew()))
+                return -1;
+            if (xmlopt->privateData.storageParse(ctxt, scsihostsrc->src) < 0)
+                return -1;
+        }
+    }
     return 0;
 }
 
@@ -8413,7 +8427,8 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sourcenode,
 
     switch ((virDomainHostdevSCSIProtocolType) scsisrc->protocol) {
     case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_NONE:
-        return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, ctxt, scsisrc);
+        return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, ctxt, scsisrc,
+                                                         flags, xmlopt);
 
     case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI:
         return virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsisrc, ctxt,
@@ -26305,6 +26320,11 @@ virDomainHostdevDefFormatSubsysSCSI(virBufferPtr buf,
         virBufferAsprintf(&sourceChildBuf, " bus='%u' target='%u' unit='%llu'",
                           scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit);
         virBufferAddLit(&sourceChildBuf, "/>\n");
+
+        if (scsihostsrc->src &&
+            virDomainDiskSourceFormatPrivateData(&sourceChildBuf, scsihostsrc->src,
+                                                 flags, xmlopt) < 0)
+            return -1;
     }
 
     virXMLFormatElement(buf, "source", &sourceAttrBuf, &sourceChildBuf);
index 14a376350cb1bdde59de66ddf650c99080a1b152..cf76f340eefdcecf59189dcb3ef618e8f9ad7f65 100644 (file)
@@ -245,6 +245,7 @@ struct _virDomainHostdevSubsysSCSIHost {
     unsigned bus;
     unsigned target;
     unsigned long long unit;
+    virStorageSourcePtr src;
 };
 
 struct _virDomainHostdevSubsysSCSIiSCSI {