render / rpms / libvirt

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

BIOS bootloader

3ec523
+
3ec523
+    

Sometimes users might want to tweak some BIOS knobs or use

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

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

For the loader element, the following can occur:

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

Devices

3ec523
 
3ec523
     

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