render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
9119d9
From 2136f434f55fa1bcdc4471e5a7bbd1da6eabb4ee Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <2136f434f55fa1bcdc4471e5a7bbd1da6eabb4ee@dist-git>
9119d9
From: Michal Privoznik <mprivozn@redhat.com>
9119d9
Date: Thu, 18 Sep 2014 11:45:37 +0200
9119d9
Subject: [PATCH] domaincaps: Expose UEFI capability
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1026772
9119d9
9119d9
As of 542899168c38 we learned libvirt to use UEFI for domains.
9119d9
However, management applications may firstly query if libvirt
9119d9
supports it. And this is where virConnectGetDomainCapabilities()
9119d9
API comes handy.
9119d9
9119d9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9119d9
(cherry picked from commit 4f76621c0edb895431a6fc30c026865dbf1c1316)
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 docs/formatdomaincaps.html.in                      | 40 ++++++++++++++++++++++
9119d9
 docs/schemas/domaincaps.rng                        | 21 ++++++++++++
9119d9
 src/conf/domain_capabilities.c                     | 28 +++++++++++++++
9119d9
 src/conf/domain_capabilities.h                     | 16 +++++++++
9119d9
 src/qemu/qemu_capabilities.c                       | 38 ++++++++++++++++++++
9119d9
 tests/domaincapsschemadata/domaincaps-basic.xml    |  1 +
9119d9
 tests/domaincapsschemadata/domaincaps-full.xml     | 13 +++++++
9119d9
 .../domaincaps-qemu_1.6.50-1.xml                   | 12 +++++++
9119d9
 tests/domaincapstest.c                             |  8 +++++
9119d9
 9 files changed, 177 insertions(+)
9119d9
9119d9
diff --git a/docs/formatdomaincaps.html.in b/docs/formatdomaincaps.html.in
9119d9
index 66b6017..34d746d 100644
9119d9
--- a/docs/formatdomaincaps.html.in
9119d9
+++ b/docs/formatdomaincaps.html.in
9119d9
@@ -93,6 +93,46 @@
9119d9
       
The maximum number of supported virtual CPUs
9119d9
     
9119d9
 
9119d9
+    

BIOS bootloader

9119d9
+
9119d9
+    

Sometimes users might want to tweak some BIOS knobs or use

9119d9
+    UEFI. For cases like that, 
9119d9
+    href="formatdomain.html#elementsOSBIOS">os
9119d9
+    element exposes what values can be passed to its children.

9119d9
+
9119d9
+
9119d9
+<domainCapabilities>
9119d9
+  ...
9119d9
+  <os supported='yes'>
9119d9
+    <loader supported='yes'>
9119d9
+      <enum name='type'>
9119d9
+        <value>rom</value>
9119d9
+        <value>pflash</value>
9119d9
+      </enum>
9119d9
+      <enum name='readonly'>
9119d9
+        <value>yes</value>
9119d9
+        <value>no</value>
9119d9
+      </enum>
9119d9
+    </loader>
9119d9
+  </os>
9119d9
+  ...
9119d9
+<domainCapabilities>
9119d9
+
9119d9
+
9119d9
+    

For the loader element, the following can occur:

9119d9
+
9119d9
+    
9119d9
+      
type
9119d9
+      
Whether loader is a typical BIOS (rom) or
9119d9
+      an UEFI binary (pflash). This refers to
9119d9
+      type attribute of the <loader/>
9119d9
+      element.
9119d9
+
9119d9
+      
readonly
9119d9
+      
Options for the readonly attribute of the
9119d9
+      <loader/> element.
9119d9
+    
9119d9
+
9119d9
     

Devices

9119d9
 
9119d9
     

9119d9
diff --git a/docs/schemas/domaincaps.rng b/docs/schemas/domaincaps.rng
9119d9
index 627b699..ad8d966 100644
9119d9
--- a/docs/schemas/domaincaps.rng
9119d9
+++ b/docs/schemas/domaincaps.rng
9119d9
@@ -26,6 +26,9 @@
9119d9
           <ref name='vcpu'/>
9119d9
         </optional>
9119d9
         <optional>
9119d9
+          <ref name='os'/>
9119d9
+        </optional>
9119d9
+        <optional>
9119d9
           <ref name='devices'/>
9119d9
         </optional>
9119d9
       </interleave>
9119d9
@@ -41,6 +44,24 @@
9119d9
     </element>
9119d9
   </define>
9119d9
 
9119d9
+  <define name='loader'>
9119d9
+    <element name='loader'>
9119d9
+      <ref name='supported'/>
9119d9
+      <ref name='enum'/>
9119d9
+    </element>
9119d9
+  </define>
9119d9
+
9119d9
+  <define name='os'>
9119d9
+    <element name='os'>
9119d9
+      <interleave>
9119d9
+        <ref name='supported'/>
9119d9
+        <optional>
9119d9
+          <ref name='loader'/>
9119d9
+        </optional>
9119d9
+      </interleave>
9119d9
+    </element>
9119d9
+  </define>
9119d9
+
9119d9
   <define name='devices'>
9119d9
     <element name='devices'>
9119d9
       <interleave>
9119d9
diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
9119d9
index df190eb..5a3c8e7 100644
9119d9
--- a/src/conf/domain_capabilities.c
9119d9
+++ b/src/conf/domain_capabilities.c
9119d9
@@ -178,6 +178,32 @@ virDomainCapsEnumFormat(virBufferPtr buf,
9119d9
                                 #capsEnum, valToStr);               \
9119d9
     } while (0)
9119d9
 
9119d9
+
9119d9
+static void
9119d9
+virDomainCapsLoaderFormat(virBufferPtr buf,
9119d9
+                          virDomainCapsLoaderPtr loader)
9119d9
+{
9119d9
+    FORMAT_PROLOGUE(loader);
9119d9
+
9119d9
+    ENUM_PROCESS(loader, type, virDomainLoaderTypeToString);
9119d9
+    ENUM_PROCESS(loader, readonly, virTristateBoolTypeToString);
9119d9
+
9119d9
+    FORMAT_EPILOGUE(loader);
9119d9
+}
9119d9
+
9119d9
+static void
9119d9
+virDomainCapsOSFormat(virBufferPtr buf,
9119d9
+                      virDomainCapsOSPtr os)
9119d9
+{
9119d9
+    virDomainCapsLoaderPtr loader = &os->loader;
9119d9
+
9119d9
+    FORMAT_PROLOGUE(os);
9119d9
+
9119d9
+    virDomainCapsLoaderFormat(buf, loader);
9119d9
+
9119d9
+    FORMAT_EPILOGUE(os);
9119d9
+}
9119d9
+
9119d9
 static void
9119d9
 virDomainCapsDeviceDiskFormat(virBufferPtr buf,
9119d9
                               virDomainCapsDeviceDiskPtr const disk)
9119d9
@@ -225,6 +251,8 @@ virDomainCapsFormatInternal(virBufferPtr buf,
9119d9
     if (caps->maxvcpus)
9119d9
         virBufferAsprintf(buf, "<vcpu max='%d'/>\n", caps->maxvcpus);
9119d9
 
9119d9
+    virDomainCapsOSFormat(buf, &caps->os);
9119d9
+
9119d9
     virBufferAddLit(buf, "<devices>\n");
9119d9
     virBufferAdjustIndent(buf, 2);
9119d9
 
9119d9
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
9119d9
index 731e66f..768646b 100644
9119d9
--- a/src/conf/domain_capabilities.h
9119d9
+++ b/src/conf/domain_capabilities.h
9119d9
@@ -43,6 +43,21 @@ struct _virDomainCapsDevice {
9119d9
     bool supported; /* true if <devtype> is supported by hypervisor */
9119d9
 };
9119d9
 
9119d9
+typedef struct _virDomainCapsLoader virDomainCapsLoader;
9119d9
+typedef virDomainCapsLoader *virDomainCapsLoaderPtr;
9119d9
+struct _virDomainCapsLoader {
9119d9
+    virDomainCapsDevice device;
9119d9
+    virDomainCapsEnum type;     /* Info about virDomainLoader */
9119d9
+    virDomainCapsEnum readonly; /* Info about readonly:virTristateBool */
9119d9
+};
9119d9
+
9119d9
+typedef struct _virDomainCapsOS virDomainCapsOS;
9119d9
+typedef virDomainCapsOS *virDomainCapsOSPtr;
9119d9
+struct _virDomainCapsOS {
9119d9
+    virDomainCapsDevice device;
9119d9
+    virDomainCapsLoader loader;     /* Info about virDomainLoaderDef */
9119d9
+};
9119d9
+
9119d9
 typedef struct _virDomainCapsDeviceDisk virDomainCapsDeviceDisk;
9119d9
 typedef virDomainCapsDeviceDisk *virDomainCapsDeviceDiskPtr;
9119d9
 struct _virDomainCapsDeviceDisk {
9119d9
@@ -75,6 +90,7 @@ struct _virDomainCaps {
9119d9
     /* Some machine specific info */
9119d9
     int maxvcpus;
9119d9
 
9119d9
+    virDomainCapsOS os;
9119d9
     virDomainCapsDeviceDisk disk;
9119d9
     virDomainCapsDeviceHostdev hostdev;
9119d9
     /* add new domain devices here */
9119d9
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
9119d9
index 4e7c435..65efe3e 100644
9119d9
--- a/src/qemu/qemu_capabilities.c
9119d9
+++ b/src/qemu/qemu_capabilities.c
9119d9
@@ -3609,6 +3609,42 @@ virQEMUCapsGetDefaultMachine(virQEMUCapsPtr qemuCaps)
9119d9
 
9119d9
 
9119d9
 static void
9119d9
+virQEMUCapsFillDomainLoaderCaps(virQEMUCapsPtr qemuCaps,
9119d9
+                                virDomainCapsLoaderPtr loader,
9119d9
+                                virArch arch)
9119d9
+{
9119d9
+    loader->device.supported = true;
9119d9
+
9119d9
+    VIR_DOMAIN_CAPS_ENUM_SET(loader->type,
9119d9
+                             VIR_DOMAIN_LOADER_TYPE_ROM);
9119d9
+
9119d9
+    if (arch == VIR_ARCH_X86_64 &&
9119d9
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE) &&
9119d9
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_FORMAT))
9119d9
+        VIR_DOMAIN_CAPS_ENUM_SET(loader->type,
9119d9
+                                 VIR_DOMAIN_LOADER_TYPE_PFLASH);
9119d9
+
9119d9
+
9119d9
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_READONLY))
9119d9
+        VIR_DOMAIN_CAPS_ENUM_SET(loader->readonly,
9119d9
+                                 VIR_TRISTATE_BOOL_YES,
9119d9
+                                 VIR_TRISTATE_BOOL_NO);
9119d9
+}
9119d9
+
9119d9
+
9119d9
+static void
9119d9
+virQEMUCapsFillDomainOSCaps(virQEMUCapsPtr qemuCaps,
9119d9
+                            virDomainCapsOSPtr os,
9119d9
+                            virArch arch)
9119d9
+{
9119d9
+    virDomainCapsLoaderPtr loader = &os->loader;
9119d9
+
9119d9
+    os->device.supported = true;
9119d9
+    virQEMUCapsFillDomainLoaderCaps(qemuCaps, loader, arch);
9119d9
+}
9119d9
+
9119d9
+
9119d9
+static void
9119d9
 virQEMUCapsFillDomainDeviceDiskCaps(virQEMUCapsPtr qemuCaps,
9119d9
                                     virDomainCapsDeviceDiskPtr disk)
9119d9
 {
9119d9
@@ -3686,12 +3722,14 @@ void
9119d9
 virQEMUCapsFillDomainCaps(virDomainCapsPtr domCaps,
9119d9
                           virQEMUCapsPtr qemuCaps)
9119d9
 {
9119d9
+    virDomainCapsOSPtr os = &domCaps->os;
9119d9
     virDomainCapsDeviceDiskPtr disk = &domCaps->disk;
9119d9
     virDomainCapsDeviceHostdevPtr hostdev = &domCaps->hostdev;
9119d9
     int maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, domCaps->machine);
9119d9
 
9119d9
     domCaps->maxvcpus = maxvcpus;
9119d9
 
9119d9
+    virQEMUCapsFillDomainOSCaps(qemuCaps, os, domCaps->arch);
9119d9
     virQEMUCapsFillDomainDeviceDiskCaps(qemuCaps, disk);
9119d9
     virQEMUCapsFillDomainDeviceHostdevCaps(qemuCaps, hostdev);
9119d9
 }
9119d9
diff --git a/tests/domaincapsschemadata/domaincaps-basic.xml b/tests/domaincapsschemadata/domaincaps-basic.xml
9119d9
index 9963519..6171393 100644
9119d9
--- a/tests/domaincapsschemadata/domaincaps-basic.xml
9119d9
+++ b/tests/domaincapsschemadata/domaincaps-basic.xml
9119d9
@@ -3,6 +3,7 @@
9119d9
   <domain>uml</domain>
9119d9
   <machine>my-machine-type</machine>
9119d9
   <arch>x86_64</arch>
9119d9
+  <os supported='no'/>
9119d9
   <devices>
9119d9
     <disk supported='no'/>
9119d9
     <hostdev supported='no'/>
9119d9
diff --git a/tests/domaincapsschemadata/domaincaps-full.xml b/tests/domaincapsschemadata/domaincaps-full.xml
9119d9
index 58dd4cb..9722772 100644
9119d9
--- a/tests/domaincapsschemadata/domaincaps-full.xml
9119d9
+++ b/tests/domaincapsschemadata/domaincaps-full.xml
9119d9
@@ -4,6 +4,19 @@
9119d9
   <machine>my-machine-type</machine>
9119d9
   <arch>x86_64</arch>
9119d9
   <vcpu max='255'/>
9119d9
+  <os supported='yes'>
9119d9
+    <loader supported='yes'>
9119d9
+      <enum name='type'>
9119d9
+        <value>rom</value>
9119d9
+        <value>pflash</value>
9119d9
+      </enum>
9119d9
+      <enum name='readonly'>
9119d9
+        <value>default</value>
9119d9
+        <value>yes</value>
9119d9
+        <value>no</value>
9119d9
+      </enum>
9119d9
+    </loader>
9119d9
+  </os>
9119d9
   <devices>
9119d9
     <disk supported='yes'>
9119d9
       <enum name='diskDevice'>
9119d9
diff --git a/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml b/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml
9119d9
index 8b63993..568cecb 100644
9119d9
--- a/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml
9119d9
+++ b/tests/domaincapsschemadata/domaincaps-qemu_1.6.50-1.xml
9119d9
@@ -3,6 +3,18 @@
9119d9
   <domain>kvm</domain>
9119d9
   <machine>pc-1.2</machine>
9119d9
   <arch>x86_64</arch>
9119d9
+  <os supported='yes'>
9119d9
+    <loader supported='yes'>
9119d9
+      <enum name='type'>
9119d9
+        <value>rom</value>
9119d9
+        <value>pflash</value>
9119d9
+      </enum>
9119d9
+      <enum name='readonly'>
9119d9
+        <value>yes</value>
9119d9
+        <value>no</value>
9119d9
+      </enum>
9119d9
+    </loader>
9119d9
+  </os>
9119d9
   <devices>
9119d9
     <disk supported='yes'>
9119d9
       <enum name='diskDevice'>
9119d9
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
9119d9
index 78197e2..f240643 100644
9119d9
--- a/tests/domaincapstest.c
9119d9
+++ b/tests/domaincapstest.c
9119d9
@@ -38,10 +38,18 @@ static void
9119d9
 fillAll(virDomainCapsPtr domCaps,
9119d9
         void *opaque ATTRIBUTE_UNUSED)
9119d9
 {
9119d9
+    virDomainCapsOSPtr os = &domCaps->os;
9119d9
+    virDomainCapsLoaderPtr loader = &os->loader;
9119d9
     virDomainCapsDeviceDiskPtr disk = &domCaps->disk;
9119d9
     virDomainCapsDeviceHostdevPtr hostdev = &domCaps->hostdev;
9119d9
     domCaps->maxvcpus = 255;
9119d9
 
9119d9
+    os->device.supported = true;
9119d9
+
9119d9
+    loader->device.supported = true;
9119d9
+    SET_ALL_BITS(loader->type);
9119d9
+    SET_ALL_BITS(loader->readonly);
9119d9
+
9119d9
     disk->device.supported = true;
9119d9
     SET_ALL_BITS(disk->diskDevice);
9119d9
     SET_ALL_BITS(disk->bus);
9119d9
-- 
9119d9
2.1.0
9119d9