[PATCH 1/4] native: add virConnectNativeFormats API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make it easier to query what nativeFormat strings are valid in
the conversion between XML and native formats.

* include/libvirt/libvirt.h.in (virConnectDomainNativeFormats):
New declaration.
* src/libvirt.c (virConnectDomainNativeFormats): Implement it.
* src/driver.h (virDrvConnectDomainNativeFormats): New callback.
* src/libvirt_public.syms (LIBVIRT_0.9.10): Export it.
* python/generator.py (skip_function): Skip python binding for now.
---
 include/libvirt/libvirt.h.in |    4 +++
 python/generator.py          |    3 ++
 src/driver.h                 |    6 ++++
 src/libvirt.c                |   59 ++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |    5 +++
 5 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e436f3c..7d7f22a 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1432,6 +1432,10 @@ char *                  virConnectDomainXMLToNative(virConnectPtr conn,
                                                     const char *nativeFormat,
                                                     const char *domainXml,
                                                     unsigned int flags);
+int                     virConnectDomainNativeFormats(virConnectPtr conn,
+                                                      char **formats,
+                                                      int nformats,
+                                                      unsigned int flags);

 int                     virDomainBlockStats     (virDomainPtr dom,
                                                  const char *disk,
diff --git a/python/generator.py b/python/generator.py
index 6fee3a4..57615b8 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -477,6 +477,9 @@ skip_function = (
     "virNWFilterGetConnect",
     "virStoragePoolGetConnect",
     "virStorageVolGetConnect",
+
+    # Not implemented yet
+    "virConnectDomainNativeFormats",
 )

 qemu_skip_function = (
diff --git a/src/driver.h b/src/driver.h
index 24636a4..15e4f2c 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -243,6 +243,11 @@ typedef char *
                                            const char *domainXml,
                                            unsigned int flags);
 typedef int
+        (*virDrvConnectDomainNativeFormats) (virConnectPtr conn,
+                                             char **formats,
+                                             int nformats,
+                                             unsigned int flags);
+typedef int
         (*virDrvListDefinedDomains)	(virConnectPtr conn,
                                          char **const names,
                                          int maxnames);
@@ -868,6 +873,7 @@ struct _virDriver {
     virDrvDomainGetXMLDesc		domainGetXMLDesc;
     virDrvConnectDomainXMLFromNative domainXMLFromNative;
     virDrvConnectDomainXMLToNative domainXMLToNative;
+    virDrvConnectDomainNativeFormats domainNativeFormats;
     virDrvListDefinedDomains	listDefinedDomains;
     virDrvNumOfDefinedDomains	numOfDefinedDomains;
     virDrvDomainCreate		domainCreate;
diff --git a/src/libvirt.c b/src/libvirt.c
index a540424..2e9f773 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -4347,6 +4347,65 @@ error:
     return NULL;
 }

+/**
+ * virConnectDomainNativeFormats:
+ * @conn: pointer to the hypervisor connection.
+ * @formats: array for storing result
+ * @nformats: maximum size of array
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * This function provides a list of all supported formats used by
+ * virConnectDomainXMLToNative() and virConnectDomainXMLFromNative().
+ *
+ * As a special case, if @formats is NULL and @nformats is 0, the output
+ * will be the number of supported formats; the caller can use this to
+ * properly allocate the @formats array.  For example:
+ *
+ * nformats = virConnectNativeFormats(conn, NULL, 0, 0);
+ * if (nformats < 0 ||
+ *     (formats = calloc(nformats, sizeof(char *))) == NULL ||
+ *     (nformats = virConnectNativeFormats(conn, formats, nformats, 0)) < 0)
+ *     goto error;
+ *
+ * This function doesn't require privileged access to the hypervisor.
+ * This function expects the caller to allocate the @formats array,
+ * and to call free() on each returned array element.
+ *
+ * Returns -1 in case of error, or the count of returned elements.
+ */
+int
+virConnectDomainNativeFormats(virConnectPtr conn, char **formats, int nformats,
+                              unsigned int flags)
+{
+    VIR_DEBUG("conn=%p, formats=%p, nformats=%d, flags=%x",
+              conn, formats, nformats, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECT(conn)) {
+        virLibConnError(VIR_ERR_INVALID_CONN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (formats == NULL ? nformats != 0 : nformats < 1) {
+        virLibConnError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->domainNativeFormats) {
+        int ret;
+        ret = conn->driver->domainNativeFormats(conn, formats, nformats, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}

 /*
  * Sequence v1:
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 4ca7216..dde3c7a 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -516,4 +516,9 @@ LIBVIRT_0.9.9 {
         virDomainSetNumaParameters;
 } LIBVIRT_0.9.8;

+LIBVIRT_0.9.10 {
+    global:
+        virConnectDomainNativeFormats;
+} LIBVIRT_0.9.9;
+
 # .... define new API here using predicted next version number ....
-- 
1.7.7.5

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]