[libvirt] [PATCH v2 2/2] domaincaps: Expose UEFI binary path, if it exists

2014-09-17 Thread Michal Privoznik
From: Cole Robinson crobi...@redhat.com

Check to see if the UEFI binary mentioned in qemu.conf actually
exists, and if so expose it in domcapabilities like

loader ...
  value/path/to/ovmf/value
/loader

We introduce some generic domcaps infrastructure for handling
a dynamic list of string values, it may be of use for future bits.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 docs/formatdomaincaps.html.in  |  6 +++
 docs/schemas/domaincaps.rng| 17 +---
 src/conf/domain_capabilities.c | 29 +
 src/conf/domain_capabilities.h |  8 
 src/qemu/qemu_capabilities.c   | 32 +++---
 src/qemu/qemu_capabilities.h   |  7 +++-
 src/qemu/qemu_driver.c |  6 ++-
 tests/domaincapsschemadata/domaincaps-full.xml |  2 +
 .../domaincaps-qemu_1.6.50-1.xml   |  1 +
 tests/domaincapstest.c | 49 +++---
 10 files changed, 140 insertions(+), 17 deletions(-)

diff --git a/docs/formatdomaincaps.html.in b/docs/formatdomaincaps.html.in
index 34d746d..6959dfe 100644
--- a/docs/formatdomaincaps.html.in
+++ b/docs/formatdomaincaps.html.in
@@ -105,6 +105,7 @@
   ...
   lt;os supported='yes'gt;
 lt;loader supported='yes'gt;
+  lt;valuegt;/usr/share/OVMF/OVMF_CODE.fdlt;/valuegt;
   lt;enum name='type'gt;
 lt;valuegt;romlt;/valuegt;
 lt;valuegt;pflashlt;/valuegt;
@@ -122,6 +123,11 @@
 pFor the codeloader/code element, the following can occur:/p
 
 dl
+  dtvalue/dt
+  ddList of known loader paths. Currently this is only used
+  to advertise known locations of OVMF binaries for qemu. Binaries
+  will only be listed if they actually exist on disk./dd
+
   dttype/dt
   ddWhether loader is a typical BIOS (coderom/code) or
   an UEFI binary (codepflash/code). This refers to
diff --git a/docs/schemas/domaincaps.rng b/docs/schemas/domaincaps.rng
index ad8d966..f4a555f 100644
--- a/docs/schemas/domaincaps.rng
+++ b/docs/schemas/domaincaps.rng
@@ -47,6 +47,9 @@
   define name='loader'
 element name='loader'
   ref name='supported'/
+  optional
+ref name='value'/
+  /optional
   ref name='enum'/
 /element
   /define
@@ -85,6 +88,14 @@
 /element
   /define
 
+  define name='value'
+zeroOrMore
+  element name='value'
+text/
+  /element
+/zeroOrMore
+  /define
+
   define name='supported'
 attribute name='supported'
   choice
@@ -100,11 +111,7 @@
 attribute name='name'
   text/
 /attribute
-zeroOrMore
-  element name='value'
-text/
-  /element
-/zeroOrMore
+ref name='value'/
   /element
 /zeroOrMore
   /define
diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 5a3c8e7..7c59912 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -48,12 +48,28 @@ VIR_ONCE_GLOBAL_INIT(virDomainCaps)
 
 
 static void
+virDomainCapsStringValuesFree(virDomainCapsStringValuesPtr values)
+{
+size_t i;
+
+if (!values || !values-values)
+return;
+
+for (i = 0; i  values-nvalues; i++)
+VIR_FREE(values-values[i]);
+VIR_FREE(values-values);
+}
+
+
+static void
 virDomainCapsDispose(void *obj)
 {
 virDomainCapsPtr caps = obj;
 
 VIR_FREE(caps-path);
 VIR_FREE(caps-machine);
+
+virDomainCapsStringValuesFree(caps-os.loader.values);
 }
 
 
@@ -156,6 +172,18 @@ virDomainCapsEnumFormat(virBufferPtr buf,
 return ret;
 }
 
+
+static void
+virDomainCapsStringValuesFormat(virBufferPtr buf,
+virDomainCapsStringValuesPtr values)
+{
+size_t i;
+
+for (i = 0; i  values-nvalues; i++)
+virBufferEscapeString(buf, value%s/value\n, values-values[i]);
+}
+
+
 #define FORMAT_PROLOGUE(item)   \
 do {\
 virBufferAsprintf(buf,  #item  supported='%s'%s\n, \
@@ -185,6 +213,7 @@ virDomainCapsLoaderFormat(virBufferPtr buf,
 {
 FORMAT_PROLOGUE(loader);
 
+virDomainCapsStringValuesFormat(buf, loader-values);
 ENUM_PROCESS(loader, type, virDomainLoaderTypeToString);
 ENUM_PROCESS(loader, readonly, virTristateBoolTypeToString);
 
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 768646b..597ac75 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -37,6 +37,13 @@ struct _virDomainCapsEnum {
 unsigned int values; /* Bitmask of values supported in the corresponding 
enum */
 };
 
+typedef struct _virDomainCapsStringValues virDomainCapsStringValues;
+typedef virDomainCapsStringValues *virDomainCapsStringValuesPtr;
+struct _virDomainCapsStringValues {
+char **values;  /* raw string values */
+

Re: [libvirt] [PATCH v2 2/2] domaincaps: Expose UEFI binary path, if it exists

2014-09-17 Thread Laszlo Ersek
On 09/17/14 14:15, Michal Privoznik wrote:

 diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
 index 0c4b09f..8543963 100644
 --- a/tests/domaincapstest.c
 +++ b/tests/domaincapstest.c
 @@ -34,6 +34,27 @@ typedef int (*virDomainCapsFill)(virDomainCapsPtr domCaps,
  #define SET_ALL_BITS(x) \
  memset((x.values), 0xff, sizeof(x.values))
  
 +static int ATTRIBUTE_SENTINEL
 +fillStringValues(virDomainCapsStringValuesPtr values, ...)
 +{
 +int ret = 0;
 +va_list list;
 +const char *str;
 +
 +va_start(list, values);
 +while ((str = va_arg(list, const char *))) {
 +if (VIR_REALLOC_N(values-values, values-nvalues + 1)  0 ||
 +VIR_STRDUP(values-values[values-nvalues], str)  0) {
 +ret = -1;
 +break;
 +}
 +values-nvalues++;
 +}
 +va_end(list);
 +
 +return ret;
 +}

Okay, you increment values-nvalues only after.

The rest too looks good to me.

Acked-by: Laszlo Ersek ler...@redhat.com

Thanks
Laszlo

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 2/2] domaincaps: Expose UEFI binary path, if it exists

2014-09-17 Thread Cole Robinson
On 09/17/2014 08:15 AM, Michal Privoznik wrote:
 From: Cole Robinson crobi...@redhat.com
 
 Check to see if the UEFI binary mentioned in qemu.conf actually
 exists, and if so expose it in domcapabilities like
 
 loader ...
   value/path/to/ovmf/value
 /loader
 
 We introduce some generic domcaps infrastructure for handling
 a dynamic list of string values, it may be of use for future bits.
 
 Signed-off-by: Michal Privoznik mpriv...@redhat.com


ACK, thanks for cleaning it up. But please change authorship since the patch
is reasonably altered, I won't be offended :)

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 2/2] domaincaps: Expose UEFI binary path, if it exists

2014-09-17 Thread Michal Privoznik

On 17.09.2014 14:57, Cole Robinson wrote:

On 09/17/2014 08:15 AM, Michal Privoznik wrote:

From: Cole Robinson crobi...@redhat.com

Check to see if the UEFI binary mentioned in qemu.conf actually
exists, and if so expose it in domcapabilities like

loader ...
   value/path/to/ovmf/value
/loader

We introduce some generic domcaps infrastructure for handling
a dynamic list of string values, it may be of use for future bits.

Signed-off-by: Michal Privoznik mpriv...@redhat.com



ACK, thanks for cleaning it up. But please change authorship since the patch
is reasonably altered, I won't be offended :)

- Cole



Thanks. Fixed and pushed.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list