[libvirt PATCH 01/12] conf: refactor hostdev driver subelement format for simpler additions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This reorganizes with no functional change, to make it easier to see
what is added in an upcoming patch.

(Yes, the "backend != DEFAULT" clause is duplicated in the nested if -
the first is to check if *any* attributes of <driver> are present, the
second is checking for this specific attribute; this will be useful
when we add a second attribute).

Signed-off-by: Laine Stump <laine@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2a8a04cacb..0208d330c3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -25022,16 +25022,23 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 
     if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
         pcisrc->backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) {
-        const char *backend =
-            virDomainHostdevSubsysPCIBackendTypeToString(pcisrc->backend);
 
-        if (!backend) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("unexpected pci hostdev driver name type %d"),
-                           pcisrc->backend);
-            return -1;
+        virBufferAddLit(buf, "<driver");
+
+        if (pcisrc->backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) {
+            const char *backend =
+                virDomainHostdevSubsysPCIBackendTypeToString(pcisrc->backend);
+
+            if (!backend) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("unexpected pci hostdev driver name type %d"),
+                               pcisrc->backend);
+                return -1;
+            }
+            virBufferAsprintf(buf, " name='%s'", backend);
         }
-        virBufferAsprintf(buf, "<driver name='%s'/>\n", backend);
+
+        virBufferAddLit(buf, "/>\n");
     }
 
     virBufferAddLit(buf, "<source");
-- 
2.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux