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

[libvirt] [PATCH 11/11] DEMO: Implement get/put in remote driver client & libvirtd



* qemud/remote.c: Implement remoteDispatchPutFile and
  remoteDispatchGetFile API handlers
* qemud/remote_protocol.x: Define wire protocol for the
  virConnectGetFile/PutFile APIs
* qemud/remote_protocol.c, qemud/remote_protocol.h,
  qemud/remote_dispatch_table.h, qemud/remote_dispatch_prototypes.h,
  qemud/remote_dispatch_args.h: Re-generate
* src/remote_internal.c: Client side of get/put APIs
---
 qemud/remote.c                     |   64 ++++++++++++++++++++++++++++++
 qemud/remote_dispatch_args.h       |    2 +
 qemud/remote_dispatch_prototypes.h |   16 +++++++
 qemud/remote_dispatch_table.h      |   10 +++++
 qemud/remote_protocol.c            |   18 ++++++++
 qemud/remote_protocol.h            |   16 +++++++
 qemud/remote_protocol.x            |   13 +++++-
 src/remote_internal.c              |   77 ++++++++++++++++++++++++++++++++++--
 8 files changed, 210 insertions(+), 6 deletions(-)

diff --git a/qemud/remote.c b/qemud/remote.c
index 3034023..ff060b3 100644
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -55,6 +55,7 @@
 #include "datatypes.h"
 #include "memory.h"
 #include "util.h"
+#include "stream.h"
 
 #define VIR_FROM_THIS VIR_FROM_REMOTE
 #define REMOTE_DEBUG(fmt, ...) DEBUG(fmt, __VA_ARGS__)
@@ -4554,6 +4555,69 @@ remoteDispatchNodeDeviceDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
 
     return 0;
 }
+static int remoteDispatchPutFile(struct qemud_server *server ATTRIBUTE_UNUSED,
+                                 struct qemud_client *client,
+                                 virConnectPtr conn,
+                                 remote_message_header *hdr,
+                                 remote_error *rerr,
+                                 remote_put_file_args *args,
+                                 void *ret ATTRIBUTE_UNUSED)
+{
+    struct qemud_client_stream *stream;
+
+    stream = remoteCreateClientStream(conn, hdr);
+    if (!stream) {
+        remoteDispatchConnError(rerr, conn);
+        return -1;
+    }
+
+    if (virConnectPutFile(conn, args->name, stream->st) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        remoteFreeClientStream(client, stream);
+        return -1;
+    }
+
+    if (remoteAddClientStream(client, stream) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        virStreamAbort(stream->st);
+        remoteFreeClientStream(client, stream);
+        return -1;
+    }
+
+    return 0;
+}
+
+static int remoteDispatchGetFile(struct qemud_server *server ATTRIBUTE_UNUSED,
+                                 struct qemud_client *client,
+                                 virConnectPtr conn,
+                                 remote_message_header *hdr,
+                                 remote_error *rerr,
+                                 remote_get_file_args *args,
+                                 void *ret ATTRIBUTE_UNUSED)
+{
+    struct qemud_client_stream *stream;
+
+    stream = remoteCreateClientStream(conn, hdr);
+    if (!stream) {
+        remoteDispatchConnError(rerr, conn);
+        return -1;
+    }
+
+    if (virConnectGetFile(conn, args->name, stream->st) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        remoteFreeClientStream(client, stream);
+        return -1;
+    }
+
+    if (remoteAddClientStream(client, stream) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        virStreamAbort(stream->st);
+        remoteFreeClientStream(client, stream);
+        return -1;
+    }
+
+    return 0;
+}
 
 
 
diff --git a/qemud/remote_dispatch_args.h b/qemud/remote_dispatch_args.h
index 9dacfb8..e0415cb 100644
--- a/qemud/remote_dispatch_args.h
+++ b/qemud/remote_dispatch_args.h
@@ -117,3 +117,5 @@
     remote_domain_xml_from_native_args val_remote_domain_xml_from_native_args;
     remote_domain_xml_to_native_args val_remote_domain_xml_to_native_args;
     remote_list_defined_interfaces_args val_remote_list_defined_interfaces_args;
+    remote_put_file_args val_remote_put_file_args;
+    remote_get_file_args val_remote_get_file_args;
diff --git a/qemud/remote_dispatch_prototypes.h b/qemud/remote_dispatch_prototypes.h
index a25ea16..1814aba 100644
--- a/qemud/remote_dispatch_prototypes.h
+++ b/qemud/remote_dispatch_prototypes.h
@@ -434,6 +434,14 @@ static int remoteDispatchGetCapabilities(
     remote_error *err,
     void *args,
     remote_get_capabilities_ret *ret);
+static int remoteDispatchGetFile(
+    struct qemud_server *server,
+    struct qemud_client *client,
+    virConnectPtr conn,
+    remote_message_header *hdr,
+    remote_error *err,
+    remote_get_file_args *args,
+    void *ret);
 static int remoteDispatchGetHostname(
     struct qemud_server *server,
     struct qemud_client *client,
@@ -882,6 +890,14 @@ static int remoteDispatchOpen(
     remote_error *err,
     remote_open_args *args,
     void *ret);
+static int remoteDispatchPutFile(
+    struct qemud_server *server,
+    struct qemud_client *client,
+    virConnectPtr conn,
+    remote_message_header *hdr,
+    remote_error *err,
+    remote_put_file_args *args,
+    void *ret);
 static int remoteDispatchStoragePoolBuild(
     struct qemud_server *server,
     struct qemud_client *client,
diff --git a/qemud/remote_dispatch_table.h b/qemud/remote_dispatch_table.h
index 449786d..1325ac5 100644
--- a/qemud/remote_dispatch_table.h
+++ b/qemud/remote_dispatch_table.h
@@ -697,3 +697,13 @@
     .args_filter = (xdrproc_t) xdr_remote_list_defined_interfaces_args,
     .ret_filter = (xdrproc_t) xdr_remote_list_defined_interfaces_ret,
 },
+{   /* PutFile => 139 */
+    .fn = (dispatch_fn) remoteDispatchPutFile,
+    .args_filter = (xdrproc_t) xdr_remote_put_file_args,
+    .ret_filter = (xdrproc_t) xdr_void,
+},
+{   /* GetFile => 140 */
+    .fn = (dispatch_fn) remoteDispatchGetFile,
+    .args_filter = (xdrproc_t) xdr_remote_get_file_args,
+    .ret_filter = (xdrproc_t) xdr_void,
+},
diff --git a/qemud/remote_protocol.c b/qemud/remote_protocol.c
index 7b46096..279a590 100644
--- a/qemud/remote_protocol.c
+++ b/qemud/remote_protocol.c
@@ -2534,6 +2534,24 @@ xdr_remote_domain_xml_to_native_ret (XDR *xdrs, remote_domain_xml_to_native_ret
 }
 
 bool_t
+xdr_remote_put_file_args (XDR *xdrs, remote_put_file_args *objp)
+{
+
+         if (!xdr_remote_nonnull_string (xdrs, &objp->name))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
+xdr_remote_get_file_args (XDR *xdrs, remote_get_file_args *objp)
+{
+
+         if (!xdr_remote_nonnull_string (xdrs, &objp->name))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
 xdr_remote_procedure (XDR *xdrs, remote_procedure *objp)
 {
 
diff --git a/qemud/remote_protocol.h b/qemud/remote_protocol.h
index 2ff9075..394b982 100644
--- a/qemud/remote_protocol.h
+++ b/qemud/remote_protocol.h
@@ -1429,6 +1429,16 @@ struct remote_domain_xml_to_native_ret {
         remote_nonnull_string nativeConfig;
 };
 typedef struct remote_domain_xml_to_native_ret remote_domain_xml_to_native_ret;
+
+struct remote_put_file_args {
+        remote_nonnull_string name;
+};
+typedef struct remote_put_file_args remote_put_file_args;
+
+struct remote_get_file_args {
+        remote_nonnull_string name;
+};
+typedef struct remote_get_file_args remote_get_file_args;
 #define REMOTE_PROGRAM 0x20008086
 #define REMOTE_PROTOCOL_VERSION 1
 
@@ -1571,6 +1581,8 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_XML_TO_NATIVE = 136,
         REMOTE_PROC_NUM_OF_DEFINED_INTERFACES = 137,
         REMOTE_PROC_LIST_DEFINED_INTERFACES = 138,
+        REMOTE_PROC_PUT_FILE = 139,
+        REMOTE_PROC_GET_FILE = 140,
 };
 typedef enum remote_procedure remote_procedure;
 
@@ -1835,6 +1847,8 @@ extern  bool_t xdr_remote_domain_xml_from_native_args (XDR *, remote_domain_xml_
 extern  bool_t xdr_remote_domain_xml_from_native_ret (XDR *, remote_domain_xml_from_native_ret*);
 extern  bool_t xdr_remote_domain_xml_to_native_args (XDR *, remote_domain_xml_to_native_args*);
 extern  bool_t xdr_remote_domain_xml_to_native_ret (XDR *, remote_domain_xml_to_native_ret*);
+extern  bool_t xdr_remote_put_file_args (XDR *, remote_put_file_args*);
+extern  bool_t xdr_remote_get_file_args (XDR *, remote_get_file_args*);
 extern  bool_t xdr_remote_procedure (XDR *, remote_procedure*);
 extern  bool_t xdr_remote_message_type (XDR *, remote_message_type*);
 extern  bool_t xdr_remote_message_status (XDR *, remote_message_status*);
@@ -2073,6 +2087,8 @@ extern bool_t xdr_remote_domain_xml_from_native_args ();
 extern bool_t xdr_remote_domain_xml_from_native_ret ();
 extern bool_t xdr_remote_domain_xml_to_native_args ();
 extern bool_t xdr_remote_domain_xml_to_native_ret ();
+extern bool_t xdr_remote_put_file_args ();
+extern bool_t xdr_remote_get_file_args ();
 extern bool_t xdr_remote_procedure ();
 extern bool_t xdr_remote_message_type ();
 extern bool_t xdr_remote_message_status ();
diff --git a/qemud/remote_protocol.x b/qemud/remote_protocol.x
index e24c428..42c71ca 100644
--- a/qemud/remote_protocol.x
+++ b/qemud/remote_protocol.x
@@ -1272,6 +1272,14 @@ struct remote_domain_xml_to_native_ret {
 };
 
 
+struct remote_put_file_args {
+    remote_nonnull_string name;
+};
+
+struct remote_get_file_args {
+    remote_nonnull_string name;
+};
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -1428,9 +1436,10 @@ enum remote_procedure {
     REMOTE_PROC_INTERFACE_DESTROY = 134,
     REMOTE_PROC_DOMAIN_XML_FROM_NATIVE = 135,
     REMOTE_PROC_DOMAIN_XML_TO_NATIVE = 136,
-
     REMOTE_PROC_NUM_OF_DEFINED_INTERFACES = 137,
-    REMOTE_PROC_LIST_DEFINED_INTERFACES = 138
+    REMOTE_PROC_LIST_DEFINED_INTERFACES = 138,
+    REMOTE_PROC_PUT_FILE = 139,
+    REMOTE_PROC_GET_FILE = 140
 };
 
 
diff --git a/src/remote_internal.c b/src/remote_internal.c
index c8ea1a3..8b1d1c6 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -6348,7 +6348,6 @@ done:
 }
 
 
-#if 0
 static struct private_stream_data *
 remoteStreamOpen(virStreamPtr st,
                  int output ATTRIBUTE_UNUSED,
@@ -6699,7 +6698,77 @@ static virStreamDriver remoteStreamDrv = {
     .streamUpdateCallback = remoteStreamEventUpdateCallback,
     .streamRemoveCallback = remoteStreamEventRemoveCallback,
 };
-#endif
+
+static int
+remoteConnectPutFile(virConnectPtr conn,
+                     const char *name,
+                     virStreamPtr st)
+{
+    struct private_data *priv = conn->privateData;
+    struct private_stream_data *privst = NULL;
+    int rv = -1;
+    remote_put_file_args args;
+
+    remoteDriverLock(priv);
+
+    if (!(privst = remoteStreamOpen(st, 1, REMOTE_PROC_PUT_FILE, priv->counter)))
+        goto done;
+
+    st->driver = &remoteStreamDrv;
+    st->privateData = privst;
+
+    args.name = (char *) name;
+
+    if (call (conn, priv, 0, REMOTE_PROC_PUT_FILE,
+              (xdrproc_t) xdr_remote_put_file_args, (char *) &args,
+              (xdrproc_t) xdr_void, NULL) == -1) {
+        remoteStreamRelease(st);
+        goto done;
+    }
+
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+
+    return rv;
+}
+
+
+static int
+remoteConnectGetFile(virConnectPtr conn,
+                     const char *name,
+                     virStreamPtr st)
+{
+    struct private_data *priv = conn->privateData;
+    struct private_stream_data *privst = NULL;
+    int rv = -1;
+    remote_put_file_args args;
+
+    remoteDriverLock(priv);
+
+    if (!(privst = remoteStreamOpen(st, 1, REMOTE_PROC_GET_FILE, priv->counter)))
+        goto done;
+
+    st->driver = &remoteStreamDrv;
+    st->privateData = privst;
+
+    args.name = (char *) name;
+
+    if (call (conn, priv, 0, REMOTE_PROC_GET_FILE,
+              (xdrproc_t) xdr_remote_put_file_args, (char *) &args,
+              (xdrproc_t) xdr_void, NULL) == -1) {
+        remoteStreamRelease(st);
+        goto done;
+    }
+
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+
+    return rv;
+}
 
 
 /*----------------------------------------------------------------------*/
@@ -8047,8 +8116,8 @@ static virDriver remote_driver = {
     remoteNodeDeviceDettach, /* nodeDeviceDettach */
     remoteNodeDeviceReAttach, /* nodeDeviceReAttach */
     remoteNodeDeviceReset, /* nodeDeviceReset */
-    NULL,
-    NULL,
+    remoteConnectPutFile,
+    remoteConnectGetFile,
 };
 
 static virNetworkDriver network_driver = {
-- 
1.6.2.5


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