Alas, the special handling of nformats == 0 means we can't use autogen.

* src/remote/remote_protocol.x (remote_domain_native_formats_args)
(remote_domain_native_formats_ret): New types.
* daemon/remote.c (remoteDispatchDomainNativeFormats): New function.
* src/remote/remote_driver.c (remoteDomainNativeFormats): Likewise.
(remote_driver): Register it.
* src/remote_protocol-structs: Regenerate.
---
 daemon/remote.c              |   56 ++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   64 +++++++++++++++++++++++++++++++++++++++++-
 src/remote/remote_protocol.x |   17 ++++++++++-
 src/remote_protocol-structs  |   12 ++++++++
 4 files changed, 146 insertions(+), 3 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index a28a754..3511158 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -1298,6 +1298,62 @@ cleanup:
 }

 static int
+remoteDispatchDomainNativeFormats(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                  virNetServerClientPtr client 
ATTRIBUTE_UNUSED,
+                                  virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                  virNetMessageErrorPtr rerr,
+                                  remote_domain_native_formats_args *args,
+                                  remote_domain_native_formats_ret *ret)
+{
+    char **formats = NULL;
+    unsigned int flags;
+    int rv = -1;
+    struct daemonClientPrivate *priv =
+        virNetServerClientGetPrivateData(client);
+
+    if (!priv->conn) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    flags = args->flags;
+
+    if (args->nformats > REMOTE_DOMAIN_NATIVE_FORMATS_MAX) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("nformats too large"));
+        goto cleanup;
+    }
+    if (args->nformats) {
+        if (VIR_ALLOC_N(formats, args->nformats) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+        ret->formats.formats_val = formats;
+    }
+
+    ret->nformats = virConnectDomainNativeFormats(priv->conn,
+                                                  ret->formats.formats_val,
+                                                  args->nformats, flags);
+    if (ret->nformats < 0)
+        goto cleanup;
+
+    /* In this case, we need to send back the number of formats supported
+     */
+    if (args->nformats == 0)
+        goto success;
+
+    ret->formats.formats_len = ret->nformats;
+success:
+    rv = 0;
+
+cleanup:
+    if (rv < 0) {
+        virNetMessageSaveError(rerr);
+        VIR_FREE(ret->formats.formats_val);
+    }
+    return rv;
+}
+
+static int
 remoteDispatchDomainGetVcpuPinInfo(virNetServerPtr server ATTRIBUTE_UNUSED,
                                    virNetServerClientPtr client 
ATTRIBUTE_UNUSED,
                                    virNetMessagePtr msg ATTRIBUTE_UNUSED,
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index e28840b..8b35c5f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2,7 +2,7 @@
  * remote_driver.c: driver to provide access to libvirtd running
  *   on a remote machine
  *
- * Copyright (C) 2007-2011 Red Hat, Inc.
+ * Copyright (C) 2007-2012 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1901,6 +1901,67 @@ done:
 }

 static int
+remoteDomainNativeFormats (virConnectPtr conn,
+                           char **formats, int nformats,
+                           unsigned int flags)
+{
+    int rv = -1;
+    remote_domain_native_formats_args args;
+    remote_domain_native_formats_ret ret;
+    int i = -1;
+    struct private_data *priv = conn->privateData;
+
+    remoteDriverLock(priv);
+
+    args.nformats = nformats;
+    args.flags = flags;
+
+    memset (&ret, 0, sizeof ret);
+    if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_NATIVE_FORMATS,
+              (xdrproc_t) xdr_remote_domain_native_formats_args, (char *) 
&args,
+              (xdrproc_t) xdr_remote_domain_native_formats_ret, (char *) &ret) 
== -1)
+        goto done;
+
+    /* Check the length of the returned list carefully. */
+    if (ret.formats.formats_len > REMOTE_DOMAIN_NATIVE_FORMATS_MAX ||
+        ret.formats.formats_len > nformats) {
+        remoteError(VIR_ERR_RPC, "%s",
+                    _("remoteDomainNativeFormats: "
+                      "returned number of formats exceeds limit"));
+        goto cleanup;
+    }
+    /* Handle the case when the caller does not know the number of formats
+     * and is asking for the number of formats supported
+     */
+    if (nformats == 0) {
+        rv = ret.nformats;
+        goto cleanup;
+    }
+
+    /* Deserialise the result. */
+    for (i = 0; i < ret.formats.formats_len; ++i) {
+        if ((formats[i] = strdup(ret.formats.formats_val[i])) == NULL) {
+            virReportOOMError();
+            goto cleanup;
+        }
+    }
+
+    rv = ret.formats.formats_len;
+
+cleanup:
+    if (rv < 0) {
+        int j;
+        for (j = 0; j < i; j++)
+            VIR_FREE(formats[j]);
+    }
+    xdr_free ((xdrproc_t) xdr_remote_domain_native_formats_ret,
+              (char *) &ret);
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
+static int
 remoteDomainMigratePrepare (virConnectPtr dconn,
                             char **cookie, int *cookielen,
                             const char *uri_in, char **uri_out,
@@ -4654,6 +4715,7 @@ static virDriver remote_driver = {
     .domainGetXMLDesc = remoteDomainGetXMLDesc, /* 0.3.0 */
     .domainXMLFromNative = remoteDomainXMLFromNative, /* 0.6.4 */
     .domainXMLToNative = remoteDomainXMLToNative, /* 0.6.4 */
+    .domainNativeFormats = remoteDomainNativeFormats, /* 0.9.10 */
     .listDefinedDomains = remoteListDefinedDomains, /* 0.3.0 */
     .numOfDefinedDomains = remoteNumOfDefinedDomains, /* 0.3.0 */
     .domainCreate = remoteDomainCreate, /* 0.3.0 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index ca739ff..cda7501 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -3,7 +3,7 @@
  *   remote_internal driver and libvirtd.  This protocol is
  *   internal and may change at any time.
  *
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -207,6 +207,9 @@ const REMOTE_DOMAIN_SEND_KEY_MAX = 16;
  */
 const REMOTE_DOMAIN_INTERFACE_PARAMETERS_MAX = 16;

+/* Upper limit on number of domain native formats */
+const REMOTE_DOMAIN_NATIVE_FORMATS_MAX = 16;
+
 /* UUID.  VIR_UUID_BUFLEN definition comes from libvirt.h */
 typedef opaque remote_uuid[VIR_UUID_BUFLEN];

@@ -1800,6 +1803,15 @@ struct remote_domain_xml_to_native_ret {
     remote_nonnull_string nativeConfig;
 };

+struct remote_domain_native_formats_args {
+    int nformats;
+    unsigned int flags;
+};
+
+struct remote_domain_native_formats_ret {
+    remote_nonnull_string formats<REMOTE_DOMAIN_NATIVE_FORMATS_MAX>;
+    int nformats;
+};

 struct remote_num_of_secrets_ret {
     int num;
@@ -2653,7 +2665,8 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_SET_NUMA_PARAMETERS = 254, /* autogen autogen */
     REMOTE_PROC_DOMAIN_GET_NUMA_PARAMETERS = 255, /* skipgen skipgen */
     REMOTE_PROC_DOMAIN_SET_INTERFACE_PARAMETERS = 256, /* autogen autogen */
-    REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257 /* skipgen skipgen */
+    REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257, /* skipgen skipgen */
+    REMOTE_PROC_DOMAIN_NATIVE_FORMATS = 258 /* skipgen skipgen priority:high */

     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 2758315..9dacbce 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1354,6 +1354,17 @@ struct remote_domain_xml_to_native_args {
 struct remote_domain_xml_to_native_ret {
         remote_nonnull_string      nativeConfig;
 };
+struct remote_domain_native_formats_args {
+        int                        nformats;
+        u_int                      flags;
+};
+struct remote_domain_native_formats_ret {
+        struct {
+                u_int              formats_len;
+                remote_nonnull_string * formats_val;
+        } formats;
+        int                        nformats;
+};
 struct remote_num_of_secrets_ret {
         int                        num;
 };
@@ -2090,4 +2101,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_GET_NUMA_PARAMETERS = 255,
         REMOTE_PROC_DOMAIN_SET_INTERFACE_PARAMETERS = 256,
         REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257,
+        REMOTE_PROC_DOMAIN_NATIVE_FORMATS = 258,
 };
-- 
1.7.7.5

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

Reply via email to