render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From dfe7fcd67e7c3cb13f6c2080ff5ce4829da5b4e5 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <dfe7fcd67e7c3cb13f6c2080ff5ce4829da5b4e5@dist-git>
9119d9
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
9119d9
Date: Wed, 24 Sep 2014 16:55:42 +0200
9119d9
Subject: [PATCH] conf: split out virtio net driver formatting
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1139364
9119d9
9119d9
Instead of checking upfront if the <driver> element will be needed
9119d9
in a big condition, just format all the attributes into a string
9119d9
and output the <driver> element if the string is not empty.
9119d9
9119d9
(cherry picked from commit fb78d1cee7ff6bafff80a58be3ff7710488d55ad)
9119d9
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/conf/domain_conf.c | 68 ++++++++++++++++++++++++++++++++------------------
9119d9
 1 file changed, 44 insertions(+), 24 deletions(-)
9119d9
9119d9
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
9119d9
index a5f3c1d..306843b 100644
9119d9
--- a/src/conf/domain_conf.c
9119d9
+++ b/src/conf/domain_conf.c
9119d9
@@ -16446,6 +16446,41 @@ virDomainActualNetDefFormat(virBufferPtr buf,
9119d9
     return 0;
9119d9
 }
9119d9
 
9119d9
+
9119d9
+static int
9119d9
+virDomainVirtioNetDriverFormat(char **outstr,
9119d9
+                               virDomainNetDefPtr def)
9119d9
+{
9119d9
+    virBuffer buf = VIR_BUFFER_INITIALIZER;
9119d9
+    if (def->driver.virtio.name) {
9119d9
+        virBufferAsprintf(&buf, "name='%s' ",
9119d9
+                          virDomainNetBackendTypeToString(def->driver.virtio.name));
9119d9
+    }
9119d9
+    if (def->driver.virtio.txmode) {
9119d9
+        virBufferAsprintf(&buf, "txmode='%s' ",
9119d9
+                          virDomainNetVirtioTxModeTypeToString(def->driver.virtio.txmode));
9119d9
+    }
9119d9
+    if (def->driver.virtio.ioeventfd) {
9119d9
+        virBufferAsprintf(&buf, "ioeventfd='%s' ",
9119d9
+                          virTristateSwitchTypeToString(def->driver.virtio.ioeventfd));
9119d9
+    }
9119d9
+    if (def->driver.virtio.event_idx) {
9119d9
+        virBufferAsprintf(&buf, "event_idx='%s' ",
9119d9
+                          virTristateSwitchTypeToString(def->driver.virtio.event_idx));
9119d9
+    }
9119d9
+    if (def->driver.virtio.queues)
9119d9
+        virBufferAsprintf(&buf, "queues='%u' ", def->driver.virtio.queues);
9119d9
+
9119d9
+    virBufferTrim(&buf, " ", -1);
9119d9
+
9119d9
+    if (virBufferCheckError(&buf) < 0)
9119d9
+        return -1;
9119d9
+
9119d9
+    *outstr = virBufferContentAndReset(&buf;;
9119d9
+    return 0;
9119d9
+}
9119d9
+
9119d9
+
9119d9
 int
9119d9
 virDomainNetDefFormat(virBufferPtr buf,
9119d9
                       virDomainNetDefPtr def,
9119d9
@@ -16621,30 +16656,15 @@ virDomainNetDefFormat(virBufferPtr buf,
9119d9
     if (def->model) {
9119d9
         virBufferEscapeString(buf, "<model type='%s'/>\n",
9119d9
                               def->model);
9119d9
-        if (STREQ(def->model, "virtio") &&
9119d9
-            (def->driver.virtio.name || def->driver.virtio.txmode ||
9119d9
-             def->driver.virtio.ioeventfd || def->driver.virtio.event_idx ||
9119d9
-             def->driver.virtio.queues)) {
9119d9
-            virBufferAddLit(buf, "
9119d9
-            if (def->driver.virtio.name) {
9119d9
-                virBufferAsprintf(buf, " name='%s'",
9119d9
-                                  virDomainNetBackendTypeToString(def->driver.virtio.name));
9119d9
-            }
9119d9
-            if (def->driver.virtio.txmode) {
9119d9
-                virBufferAsprintf(buf, " txmode='%s'",
9119d9
-                                  virDomainNetVirtioTxModeTypeToString(def->driver.virtio.txmode));
9119d9
-            }
9119d9
-            if (def->driver.virtio.ioeventfd) {
9119d9
-                virBufferAsprintf(buf, " ioeventfd='%s'",
9119d9
-                                  virTristateSwitchTypeToString(def->driver.virtio.ioeventfd));
9119d9
-            }
9119d9
-            if (def->driver.virtio.event_idx) {
9119d9
-                virBufferAsprintf(buf, " event_idx='%s'",
9119d9
-                                  virTristateSwitchTypeToString(def->driver.virtio.event_idx));
9119d9
-            }
9119d9
-            if (def->driver.virtio.queues)
9119d9
-                virBufferAsprintf(buf, " queues='%u'", def->driver.virtio.queues);
9119d9
-            virBufferAddLit(buf, "/>\n");
9119d9
+        if (STREQ(def->model, "virtio")) {
9119d9
+            char *str;
9119d9
+
9119d9
+            if (virDomainVirtioNetDriverFormat(&str, def) < 0)
9119d9
+                return -1;
9119d9
+
9119d9
+            if (str)
9119d9
+                virBufferAsprintf(buf, "<driver %s/>\n", str);
9119d9
+            VIR_FREE(str);
9119d9
         }
9119d9
     }
9119d9
     if (def->backend.tap || def->backend.vhost) {
9119d9
-- 
9119d9
2.1.1
9119d9