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

[libvirt] [PATCH 2/6] Introduce remote protocol support for virDomainCreate{XML}WithFiles



From: "Daniel P. Berrange" <berrange redhat com>

Since they make use of file descriptor passing, the remote protocol
methods for virDomainCreate{XML}WithFiles must be written by hand.

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 daemon/remote.c              | 104 +++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |  71 +++++++++++++++++++++++++++++
 src/remote/remote_protocol.x |  32 ++++++++++++-
 src/remote_protocol-structs  |  16 +++++++
 4 files changed, 222 insertions(+), 1 deletion(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 5847e60..a1b571c 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4891,6 +4891,110 @@ cleanup:
 }
 
 
+static int remoteDispatchDomainCreateXMLWithFiles(
+    virNetServerPtr server ATTRIBUTE_UNUSED,
+    virNetServerClientPtr client,
+    virNetMessagePtr msg ATTRIBUTE_UNUSED,
+    virNetMessageErrorPtr rerr,
+    remote_domain_create_xml_with_files_args *args,
+    remote_domain_create_xml_with_files_ret *ret)
+{
+    int rv = -1;
+    virDomainPtr dom = NULL;
+    struct daemonClientPrivate *priv =
+        virNetServerClientGetPrivateData(client);
+    int *files = NULL;
+    unsigned int nfiles = 0;
+    size_t i;
+
+    if (!priv->conn) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(files, msg->nfds) < 0)
+        goto cleanup;
+    for (i = 0; i < msg->nfds; i++) {
+        if ((files[i] = virNetMessageDupFD(msg, i)) < 0)
+            goto cleanup;
+        nfiles++;
+    }
+
+    if ((dom = virDomainCreateXMLWithFiles(priv->conn, args->xml_desc,
+                                           nfiles, files,
+                                           args->flags)) == NULL)
+        goto cleanup;
+
+    make_nonnull_domain(&ret->dom, dom);
+    rv = 0;
+
+cleanup:
+    for (i = 0; i < nfiles; i++) {
+        VIR_FORCE_CLOSE(files[i]);
+    }
+    VIR_FREE(files);
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (dom)
+        virDomainFree(dom);
+    return rv;
+}
+
+
+static int remoteDispatchDomainCreateWithFiles(
+    virNetServerPtr server ATTRIBUTE_UNUSED,
+    virNetServerClientPtr client,
+    virNetMessagePtr msg ATTRIBUTE_UNUSED,
+    virNetMessageErrorPtr rerr,
+    remote_domain_create_with_files_args *args,
+    remote_domain_create_with_files_ret *ret)
+{
+    int rv = -1;
+    virDomainPtr dom = NULL;
+    struct daemonClientPrivate *priv =
+        virNetServerClientGetPrivateData(client);
+    int *files = NULL;
+    unsigned int nfiles = 0;
+    size_t i;
+
+    if (!priv->conn) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(files, msg->nfds) < 0)
+        goto cleanup;
+    for (i = 0; i < msg->nfds; i++) {
+        if ((files[i] = virNetMessageDupFD(msg, i)) < 0)
+            goto cleanup;
+        nfiles++;
+    }
+
+    if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
+        goto cleanup;
+
+    if (virDomainCreateWithFiles(dom,
+                                 nfiles, files,
+                                 args->flags) < 0)
+        goto cleanup;
+
+    make_nonnull_domain(&ret->dom, dom);
+    rv = 0;
+
+cleanup:
+    for (i = 0; i < nfiles; i++) {
+        VIR_FORCE_CLOSE(files[i]);
+    }
+    VIR_FREE(files);
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (dom)
+        virDomainFree(dom);
+    return rv;
+}
+
+
+
 /*----- Helpers. -----*/
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 81ecef1..e2764e2 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -6387,6 +6387,75 @@ cleanup:
 }
 
 
+static virDomainPtr
+remoteDomainCreateXMLWithFiles(virConnectPtr conn, const char *xml_desc,
+                               unsigned int nfiles, int *files, unsigned int flags)
+{
+    virDomainPtr rv = NULL;
+    struct private_data *priv = conn->privateData;
+    remote_domain_create_xml_with_files_args args;
+    remote_domain_create_xml_with_files_ret ret;
+
+    remoteDriverLock(priv);
+
+    args.xml_desc = (char *)xml_desc;
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+
+    if (callFull(conn, priv, 0,
+                 files, nfiles,
+                 NULL, NULL,
+                 REMOTE_PROC_DOMAIN_CREATE_XML_WITH_FILES,
+                 (xdrproc_t)xdr_remote_domain_create_xml_with_files_args, (char *)&args,
+                 (xdrproc_t)xdr_remote_domain_create_xml_with_files_ret, (char *)&ret) == -1) {
+        goto done;
+    }
+
+    rv = get_nonnull_domain(conn, ret.dom);
+    xdr_free((xdrproc_t)xdr_remote_domain_create_xml_with_files_ret, (char *)&ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
+
+static int
+remoteDomainCreateWithFiles(virDomainPtr dom,
+                            unsigned int nfiles, int *files,
+                            unsigned int flags)
+{
+    int rv = -1;
+    struct private_data *priv = dom->conn->privateData;
+    remote_domain_create_with_files_args args;
+    remote_domain_create_with_files_ret ret;
+
+    remoteDriverLock(priv);
+
+    make_nonnull_domain(&args.dom, dom);
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+
+    if (callFull(dom->conn, priv, 0,
+                 files, nfiles,
+                 NULL, NULL,
+                 REMOTE_PROC_DOMAIN_CREATE_WITH_FILES,
+                 (xdrproc_t)xdr_remote_domain_create_with_files_args, (char *)&args,
+                 (xdrproc_t)xdr_remote_domain_create_with_files_ret, (char *)&ret) == -1) {
+        goto done;
+    }
+
+    dom->id = ret.dom.id;
+    xdr_free((xdrproc_t) &xdr_remote_domain_create_with_files_ret, (char *) &ret);
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 static void
 remoteDomainEventQueue(struct private_data *priv, virDomainEventPtr event)
 {
@@ -6544,6 +6613,7 @@ static virDriver remote_driver = {
     .connectNumOfDomains = remoteConnectNumOfDomains, /* 0.3.0 */
     .connectListAllDomains = remoteConnectListAllDomains, /* 0.9.13 */
     .domainCreateXML = remoteDomainCreateXML, /* 0.3.0 */
+    .domainCreateXMLWithFiles = remoteDomainCreateXMLWithFiles, /* 1.1.1 */
     .domainLookupByID = remoteDomainLookupByID, /* 0.3.0 */
     .domainLookupByUUID = remoteDomainLookupByUUID, /* 0.3.0 */
     .domainLookupByName = remoteDomainLookupByName, /* 0.3.0 */
@@ -6597,6 +6667,7 @@ static virDriver remote_driver = {
     .connectNumOfDefinedDomains = remoteConnectNumOfDefinedDomains, /* 0.3.0 */
     .domainCreate = remoteDomainCreate, /* 0.3.0 */
     .domainCreateWithFlags = remoteDomainCreateWithFlags, /* 0.8.2 */
+    .domainCreateWithFiles = remoteDomainCreateWithFiles, /* 1.1.1 */
     .domainDefineXML = remoteDomainDefineXML, /* 0.3.0 */
     .domainUndefine = remoteDomainUndefine, /* 0.3.0 */
     .domainUndefineFlags = remoteDomainUndefineFlags, /* 0.9.4 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 2e9dc1d..e77dc4d 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -734,6 +734,15 @@ struct remote_domain_create_xml_ret {
     remote_nonnull_domain dom;
 };
 
+struct remote_domain_create_xml_with_files_args {
+    remote_nonnull_string xml_desc;
+    unsigned int flags;
+};
+
+struct remote_domain_create_xml_with_files_ret {
+    remote_nonnull_domain dom;
+};
+
 struct remote_domain_lookup_by_id_args {
     int id;
 };
@@ -989,6 +998,15 @@ struct remote_domain_create_with_flags_ret {
     remote_nonnull_domain dom;
 };
 
+struct remote_domain_create_with_files_args {
+    remote_nonnull_domain dom;
+    unsigned int flags;
+};
+
+struct remote_domain_create_with_files_ret {
+    remote_nonnull_domain dom;
+};
+
 struct remote_domain_define_xml_args {
     remote_nonnull_string xml;
 };
@@ -4944,6 +4962,18 @@ enum remote_procedure {
      * @generate: none
      * @acl: domain:migrate
      */
-    REMOTE_PROC_DOMAIN_MIGRATE_CONFIRM3_PARAMS = 307
+    REMOTE_PROC_DOMAIN_MIGRATE_CONFIRM3_PARAMS = 307,
+
+    /**
+     * @generate: none
+     * @acl: domain:write
+     * @acl: domain:start
+     */
+    REMOTE_PROC_DOMAIN_CREATE_XML_WITH_FILES = 308,
 
+    /**
+     * @generate: none
+     * @acl: domain:start
+     */
+    REMOTE_PROC_DOMAIN_CREATE_WITH_FILES = 309
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index e38d24a..a5d18fe 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -423,6 +423,13 @@ struct remote_domain_create_xml_args {
 struct remote_domain_create_xml_ret {
         remote_nonnull_domain      dom;
 };
+struct remote_domain_create_xml_with_files_args {
+        remote_nonnull_string      xml_desc;
+        u_int                      flags;
+};
+struct remote_domain_create_xml_with_files_ret {
+        remote_nonnull_domain      dom;
+};
 struct remote_domain_lookup_by_id_args {
         int                        id;
 };
@@ -645,6 +652,13 @@ struct remote_domain_create_with_flags_args {
 struct remote_domain_create_with_flags_ret {
         remote_nonnull_domain      dom;
 };
+struct remote_domain_create_with_files_args {
+        remote_nonnull_domain      dom;
+        u_int                      flags;
+};
+struct remote_domain_create_with_files_ret {
+        remote_nonnull_domain      dom;
+};
 struct remote_domain_define_xml_args {
         remote_nonnull_string      xml;
 };
@@ -2601,4 +2615,6 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_MIGRATE_PERFORM3_PARAMS = 305,
         REMOTE_PROC_DOMAIN_MIGRATE_FINISH3_PARAMS = 306,
         REMOTE_PROC_DOMAIN_MIGRATE_CONFIRM3_PARAMS = 307,
+        REMOTE_PROC_DOMAIN_CREATE_XML_WITH_FILES = 308,
+        REMOTE_PROC_DOMAIN_CREATE_WITH_FILES = 309,
 };
-- 
1.8.1.4


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