3e5111
From b452148f1570656d9b42efbdbff396cf5cafa9c7 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <b452148f1570656d9b42efbdbff396cf5cafa9c7@dist-git>
3e5111
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
3e5111
Date: Fri, 9 Jun 2017 12:49:05 +0200
3e5111
Subject: [PATCH] Add virtio-related options to rng devices
3e5111
MIME-Version: 1.0
3e5111
Content-Type: text/plain; charset=UTF-8
3e5111
Content-Transfer-Encoding: 8bit
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1283251
3e5111
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
(cherry picked from commit f65db1be1200b656094180ecfdb63f8bd0158cab)
3e5111
Signed-off-by: Ján Tomko <jtomko@redhat.com>
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 docs/formatdomain.html.in                             | 11 +++++++++++
3e5111
 docs/schemas/domaincommon.rng                         |  5 +++++
3e5111
 src/conf/domain_conf.c                                | 19 +++++++++++++++++++
3e5111
 src/conf/domain_conf.h                                |  1 +
3e5111
 .../qemuxml2argvdata/qemuxml2argv-virtio-options.xml  |  1 +
3e5111
 5 files changed, 37 insertions(+)
3e5111
3e5111
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
3e5111
index 8d3f916a19..2e5c669c4a 100644
3e5111
--- a/docs/formatdomain.html.in
3e5111
+++ b/docs/formatdomain.html.in
3e5111
@@ -7061,6 +7061,17 @@ qemu-kvm -net nic,model=? /dev/null
3e5111
           
3e5111
         
3e5111
       
3e5111
+      
driver
3e5111
+      
3e5111
+        The subelement driver can be used to tune the device:
3e5111
+        
3e5111
+          
virtio options
3e5111
+          
3e5111
+          Virtio-specific options can also be
3e5111
+          set. (Since 3.5.0)
3e5111
+          
3e5111
+        
3e5111
+      
3e5111
 
3e5111
     
3e5111
 
3e5111
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
3e5111
index 5e526b6100..7e80275029 100644
3e5111
--- a/docs/schemas/domaincommon.rng
3e5111
+++ b/docs/schemas/domaincommon.rng
3e5111
@@ -4912,6 +4912,11 @@
3e5111
       <interleave>
3e5111
         <ref name="rng-backend"/>
3e5111
         <optional>
3e5111
+          <element name="driver">
3e5111
+            <ref name="virtioOptions"/>
3e5111
+          </element>
3e5111
+        </optional>
3e5111
+        <optional>
3e5111
           <ref name="rng-rate"/>
3e5111
         </optional>
3e5111
         <optional>
3e5111
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
3e5111
index 5c7ffc0419..059c006b69 100644
3e5111
--- a/src/conf/domain_conf.c
3e5111
+++ b/src/conf/domain_conf.c
3e5111
@@ -12922,6 +12922,9 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlopt,
3e5111
     if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
3e5111
         goto error;
3e5111
 
3e5111
+    if (virDomainVirtioOptionsParseXML(ctxt, &def->virtio) < 0)
3e5111
+        goto error;
3e5111
+
3e5111
  cleanup:
3e5111
     VIR_FREE(model);
3e5111
     VIR_FREE(backend);
3e5111
@@ -19637,6 +19640,10 @@ virDomainRNGDefCheckABIStability(virDomainRNGDefPtr src,
3e5111
         return false;
3e5111
     }
3e5111
 
3e5111
+    if (src->virtio && dst->virtio &&
3e5111
+        !virDomainVirtioOptionsCheckABIStability(src->virtio, dst->virtio))
3e5111
+        return false;
3e5111
+
3e5111
     if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
3e5111
         return false;
3e5111
 
3e5111
@@ -23132,6 +23139,7 @@ virDomainRNGDefFormat(virBufferPtr buf,
3e5111
 {
3e5111
     const char *model = virDomainRNGModelTypeToString(def->model);
3e5111
     const char *backend = virDomainRNGBackendTypeToString(def->backend);
3e5111
+    virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
3e5111
 
3e5111
     virBufferAsprintf(buf, "<rng model='%s'>\n", model);
3e5111
     virBufferAdjustIndent(buf, 2);
3e5111
@@ -23160,6 +23168,16 @@ virDomainRNGDefFormat(virBufferPtr buf,
3e5111
         break;
3e5111
     }
3e5111
 
3e5111
+    virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
3e5111
+    if (virBufferCheckError(&driverBuf) < 0)
3e5111
+        return -1;
3e5111
+
3e5111
+    if (virBufferUse(&driverBuf)) {
3e5111
+        virBufferAddLit(buf, "
3e5111
+        virBufferAddBuffer(buf, &driverBuf);
3e5111
+        virBufferAddLit(buf, "/>\n");
3e5111
+    }
3e5111
+
3e5111
     if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) {
3e5111
         if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
3e5111
             return -1;
3e5111
@@ -23188,6 +23206,7 @@ virDomainRNGDefFree(virDomainRNGDefPtr def)
3e5111
     }
3e5111
 
3e5111
     virDomainDeviceInfoClear(&def->info);
3e5111
+    VIR_FREE(def->virtio);
3e5111
     VIR_FREE(def);
3e5111
 }
3e5111
 
3e5111
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
3e5111
index fdd852c29d..8cb9d5d0b1 100644
3e5111
--- a/src/conf/domain_conf.h
3e5111
+++ b/src/conf/domain_conf.h
3e5111
@@ -2020,6 +2020,7 @@ struct _virDomainRNGDef {
3e5111
     } source;
3e5111
 
3e5111
     virDomainDeviceInfo info;
3e5111
+    virDomainVirtioOptionsPtr virtio;
3e5111
 };
3e5111
 
3e5111
 typedef enum {
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.xml b/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.xml
3e5111
index 33da214611..b7b95014cd 100644
3e5111
--- a/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.xml
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-virtio-options.xml
3e5111
@@ -80,6 +80,7 @@
3e5111
     </memballoon>
3e5111
     <rng model='virtio'>
3e5111
       <backend model='random'>/dev/random</backend>
3e5111
+      <driver iommu='on' ats='on'/>
3e5111
       <address type='pci' domain='0x0000' bus='0x00' slot='0x0d' function='0x0'/>
3e5111
     </rng>
3e5111
   </devices>
3e5111
-- 
3e5111
2.13.1
3e5111