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

[libvirt] [PATCH 5/6] Remote protocol support for storage vol upload/download APIs



* daemon/remote.c, src/remote/remote_driver.c: Implementation
  of storage vol upload/download APIs
* src/remote/remote_protocol.x: Wire protocol definition for
  upload/download
* daemon/remote_dispatch_args.h, daemon/remote_dispatch_prototypes.h,
  daemon/remote_dispatch_table.h, src/remote/remote_protocol.h,
  src/remote/remote_protocol.c: Re-generate
---
 daemon/remote.c                     |   92 +++++++++++++++++++++++++++++++++++
 daemon/remote_dispatch_args.h       |    2 +
 daemon/remote_dispatch_prototypes.h |   16 ++++++
 daemon/remote_dispatch_table.h      |   10 ++++
 src/remote/remote_driver.c          |   87 +++++++++++++++++++++++++++++++++
 src/remote/remote_protocol.c        |   30 +++++++++++
 src/remote/remote_protocol.h        |   22 ++++++++
 src/remote/remote_protocol.x        |   19 +++++++-
 src/remote_protocol-structs         |   12 +++++
 9 files changed, 289 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index f410982..7e8103c 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -5816,7 +5816,99 @@ remoteDispatchNodeDeviceDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
     virNodeDeviceFree(dev);
     return 0;
 }
+static int remoteDispatchStorageVolUpload(struct qemud_server *server ATTRIBUTE_UNUSED,
+                                          struct qemud_client *client,
+                                          virConnectPtr conn,
+                                          remote_message_header *hdr,
+                                          remote_error *rerr,
+                                          remote_storage_vol_upload_args *args,
+                                          void *ret ATTRIBUTE_UNUSED)
+{
+    int rv = -1;
+    struct qemud_client_stream *stream = NULL;
+    virStorageVolPtr vol;
+
+    vol = get_nonnull_storage_vol(conn, args->vol);
+    if (vol == NULL) {
+        remoteDispatchConnError(rerr, conn);
+        goto cleanup;
+    }
+
+    stream = remoteCreateClientStream(conn, hdr);
+    if (!stream) {
+        remoteDispatchConnError(rerr, conn);
+        goto cleanup;
+    }
+
+    if (virStorageVolUpload(vol, stream->st,
+                            args->offset, args->length,
+                            args->flags) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        goto cleanup;
+    }
+
+    if (remoteAddClientStream(client, stream, 0) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        virStreamAbort(stream->st);
+        goto cleanup;
+    }
+
+    rv = 0;
+
+cleanup:
+    if (vol)
+        virStorageVolFree(vol);
+    if (stream && rv != 0)
+        remoteFreeClientStream(client, stream);
+    return rv;
+}
 
+static int remoteDispatchStorageVolDownload(struct qemud_server *server ATTRIBUTE_UNUSED,
+                                            struct qemud_client *client,
+                                            virConnectPtr conn,
+                                            remote_message_header *hdr,
+                                            remote_error *rerr,
+                                            remote_storage_vol_download_args *args,
+                                            void *ret ATTRIBUTE_UNUSED)
+{
+    int rv = -1;
+    struct qemud_client_stream *stream = NULL;
+    virStorageVolPtr vol;
+
+    vol = get_nonnull_storage_vol (conn, args->vol);
+    if (vol == NULL) {
+        remoteDispatchConnError(rerr, conn);
+        goto cleanup;
+    }
+
+    stream = remoteCreateClientStream(conn, hdr);
+    if (!stream) {
+        remoteDispatchConnError(rerr, conn);
+        goto cleanup;
+    }
+
+    if (virStorageVolDownload(vol, stream->st,
+                              args->offset, args->length,
+                              args->flags) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        goto cleanup;
+    }
+
+    if (remoteAddClientStream(client, stream, 1) < 0) {
+        remoteDispatchConnError(rerr, conn);
+        virStreamAbort(stream->st);
+        goto cleanup;
+    }
+
+    rv = 0;
+
+cleanup:
+    if (vol)
+        virStorageVolFree(vol);
+    if (stream && rv != 0)
+        remoteFreeClientStream(client, stream);
+    return rv;
+}
 
 
 /***************************
diff --git a/daemon/remote_dispatch_args.h b/daemon/remote_dispatch_args.h
index b32ae1f..da378c1 100644
--- a/daemon/remote_dispatch_args.h
+++ b/daemon/remote_dispatch_args.h
@@ -175,3 +175,5 @@
     remote_domain_set_memory_flags_args val_remote_domain_set_memory_flags_args;
     remote_domain_set_blkio_parameters_args val_remote_domain_set_blkio_parameters_args;
     remote_domain_get_blkio_parameters_args val_remote_domain_get_blkio_parameters_args;
+    remote_storage_vol_upload_args val_remote_storage_vol_upload_args;
+    remote_storage_vol_download_args val_remote_storage_vol_download_args;
diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h
index 4db6c76..65f7f8e 100644
--- a/daemon/remote_dispatch_prototypes.h
+++ b/daemon/remote_dispatch_prototypes.h
@@ -1530,6 +1530,14 @@ static int remoteDispatchStorageVolDelete(
     remote_error *err,
     remote_storage_vol_delete_args *args,
     void *ret);
+static int remoteDispatchStorageVolDownload(
+    struct qemud_server *server,
+    struct qemud_client *client,
+    virConnectPtr conn,
+    remote_message_header *hdr,
+    remote_error *err,
+    remote_storage_vol_download_args *args,
+    void *ret);
 static int remoteDispatchStorageVolDumpXml(
     struct qemud_server *server,
     struct qemud_client *client,
@@ -1578,6 +1586,14 @@ static int remoteDispatchStorageVolLookupByPath(
     remote_error *err,
     remote_storage_vol_lookup_by_path_args *args,
     remote_storage_vol_lookup_by_path_ret *ret);
+static int remoteDispatchStorageVolUpload(
+    struct qemud_server *server,
+    struct qemud_client *client,
+    virConnectPtr conn,
+    remote_message_header *hdr,
+    remote_error *err,
+    remote_storage_vol_upload_args *args,
+    void *ret);
 static int remoteDispatchStorageVolWipe(
     struct qemud_server *server,
     struct qemud_client *client,
diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h
index c50d038..06b083e 100644
--- a/daemon/remote_dispatch_table.h
+++ b/daemon/remote_dispatch_table.h
@@ -1037,3 +1037,13 @@
     .args_filter = (xdrproc_t) xdr_remote_domain_get_blkio_parameters_args,
     .ret_filter = (xdrproc_t) xdr_remote_domain_get_blkio_parameters_ret,
 },
+{   /* StorageVolUpload => 207 */
+    .fn = (dispatch_fn) remoteDispatchStorageVolUpload,
+    .args_filter = (xdrproc_t) xdr_remote_storage_vol_upload_args,
+    .ret_filter = (xdrproc_t) xdr_void,
+},
+{   /* StorageVolDownload => 208 */
+    .fn = (dispatch_fn) remoteDispatchStorageVolDownload,
+    .args_filter = (xdrproc_t) xdr_remote_storage_vol_download_args,
+    .ret_filter = (xdrproc_t) xdr_void,
+},
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 8aa8801..16db847 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -9563,6 +9563,91 @@ done:
     return rv;
 }
 
+static int
+remoteStorageVolUpload(virStorageVolPtr vol,
+                       virStreamPtr st,
+                       unsigned long long offset,
+                       unsigned long long length,
+                       unsigned int flags)
+{
+    struct private_data *priv = vol->conn->privateData;
+    struct private_stream_data *privst = NULL;
+    int rv = -1;
+    remote_storage_vol_upload_args args;
+
+    remoteDriverLock(priv);
+
+    if (!(privst = remoteStreamOpen(st, 1,
+                                    REMOTE_PROC_STORAGE_VOL_UPLOAD,
+                                    priv->counter)))
+        goto done;
+
+    st->driver = &remoteStreamDrv;
+    st->privateData = privst;
+
+    make_nonnull_storage_vol(&args.vol, vol);
+    args.offset = offset;
+    args.length = length;
+    args.flags = flags;
+
+    if (call (vol->conn, priv, 0, REMOTE_PROC_STORAGE_VOL_UPLOAD,
+              (xdrproc_t) xdr_remote_storage_vol_upload_args, (char *) &args,
+              (xdrproc_t) xdr_void, NULL) == -1) {
+        remoteStreamRelease(st);
+        goto done;
+    }
+
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+
+    return rv;
+}
+
+
+static int
+remoteStorageVolDownload(virStorageVolPtr vol,
+                         virStreamPtr st,
+                         unsigned long long offset,
+                         unsigned long long length,
+                         unsigned int flags)
+{
+    struct private_data *priv = vol->conn->privateData;
+    struct private_stream_data *privst = NULL;
+    int rv = -1;
+    remote_storage_vol_download_args args;
+
+    remoteDriverLock(priv);
+
+    if (!(privst = remoteStreamOpen(st, 1,
+                                    REMOTE_PROC_STORAGE_VOL_DOWNLOAD,
+                                    priv->counter)))
+        goto done;
+
+    st->driver = &remoteStreamDrv;
+    st->privateData = privst;
+
+    make_nonnull_storage_vol(&args.vol, vol);
+    args.offset = offset;
+    args.length = length;
+    args.flags = flags;
+
+    if (call (vol->conn, priv, 0, REMOTE_PROC_STORAGE_VOL_DOWNLOAD,
+              (xdrproc_t) xdr_remote_storage_vol_download_args, (char *) &args,
+              (xdrproc_t) xdr_void, NULL) == -1) {
+        remoteStreamRelease(st);
+        goto done;
+    }
+
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+
+    return rv;
+}
+
 
 static int
 remoteDomainOpenConsole(virDomainPtr dom,
@@ -11233,6 +11318,8 @@ static virStorageDriver storage_driver = {
     .volLookupByPath = remoteStorageVolLookupByPath,
     .volCreateXML = remoteStorageVolCreateXML,
     .volCreateXMLFrom = remoteStorageVolCreateXMLFrom,
+    .volDownload = remoteStorageVolDownload,
+    .volUpload = remoteStorageVolUpload,
     .volDelete = remoteStorageVolDelete,
     .volWipe = remoteStorageVolWipe,
     .volGetInfo = remoteStorageVolGetInfo,
diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c
index ea2bdf7..9cadcb7 100644
--- a/src/remote/remote_protocol.c
+++ b/src/remote/remote_protocol.c
@@ -3859,6 +3859,36 @@ xdr_remote_domain_open_console_args (XDR *xdrs, remote_domain_open_console_args
 }
 
 bool_t
+xdr_remote_storage_vol_upload_args (XDR *xdrs, remote_storage_vol_upload_args *objp)
+{
+
+         if (!xdr_remote_nonnull_storage_vol (xdrs, &objp->vol))
+                 return FALSE;
+         if (!xdr_uint64_t (xdrs, &objp->offset))
+                 return FALSE;
+         if (!xdr_uint64_t (xdrs, &objp->length))
+                 return FALSE;
+         if (!xdr_u_int (xdrs, &objp->flags))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
+xdr_remote_storage_vol_download_args (XDR *xdrs, remote_storage_vol_download_args *objp)
+{
+
+         if (!xdr_remote_nonnull_storage_vol (xdrs, &objp->vol))
+                 return FALSE;
+         if (!xdr_uint64_t (xdrs, &objp->offset))
+                 return FALSE;
+         if (!xdr_uint64_t (xdrs, &objp->length))
+                 return FALSE;
+         if (!xdr_u_int (xdrs, &objp->flags))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
 xdr_remote_procedure (XDR *xdrs, remote_procedure *objp)
 {
 
diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h
index a55f7c4..4bf2b0f 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -2177,6 +2177,22 @@ struct remote_domain_open_console_args {
         u_int flags;
 };
 typedef struct remote_domain_open_console_args remote_domain_open_console_args;
+
+struct remote_storage_vol_upload_args {
+        remote_nonnull_storage_vol vol;
+        uint64_t offset;
+        uint64_t length;
+        u_int flags;
+};
+typedef struct remote_storage_vol_upload_args remote_storage_vol_upload_args;
+
+struct remote_storage_vol_download_args {
+        remote_nonnull_storage_vol vol;
+        uint64_t offset;
+        uint64_t length;
+        u_int flags;
+};
+typedef struct remote_storage_vol_download_args remote_storage_vol_download_args;
 #define REMOTE_PROGRAM 0x20008086
 #define REMOTE_PROTOCOL_VERSION 1
 
@@ -2387,6 +2403,8 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_SET_MEMORY_FLAGS = 204,
         REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205,
         REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206,
+        REMOTE_PROC_STORAGE_VOL_UPLOAD = 207,
+        REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 208,
 };
 typedef enum remote_procedure remote_procedure;
 
@@ -2767,6 +2785,8 @@ extern  bool_t xdr_remote_domain_snapshot_current_ret (XDR *, remote_domain_snap
 extern  bool_t xdr_remote_domain_revert_to_snapshot_args (XDR *, remote_domain_revert_to_snapshot_args*);
 extern  bool_t xdr_remote_domain_snapshot_delete_args (XDR *, remote_domain_snapshot_delete_args*);
 extern  bool_t xdr_remote_domain_open_console_args (XDR *, remote_domain_open_console_args*);
+extern  bool_t xdr_remote_storage_vol_upload_args (XDR *, remote_storage_vol_upload_args*);
+extern  bool_t xdr_remote_storage_vol_download_args (XDR *, remote_storage_vol_download_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*);
@@ -3121,6 +3141,8 @@ extern bool_t xdr_remote_domain_snapshot_current_ret ();
 extern bool_t xdr_remote_domain_revert_to_snapshot_args ();
 extern bool_t xdr_remote_domain_snapshot_delete_args ();
 extern bool_t xdr_remote_domain_open_console_args ();
+extern bool_t xdr_remote_storage_vol_upload_args ();
+extern bool_t xdr_remote_storage_vol_download_args ();
 extern bool_t xdr_remote_procedure ();
 extern bool_t xdr_remote_message_type ();
 extern bool_t xdr_remote_message_status ();
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index aa710a4..4bcad65 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1920,6 +1920,21 @@ struct remote_domain_open_console_args {
     unsigned int flags;
 };
 
+struct remote_storage_vol_upload_args {
+    remote_nonnull_storage_vol vol;
+    unsigned hyper offset;
+    unsigned hyper length;
+    unsigned int flags;
+};
+
+struct remote_storage_vol_download_args {
+    remote_nonnull_storage_vol vol;
+    unsigned hyper offset;
+    unsigned hyper length;
+    unsigned int flags;
+};
+
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -2152,7 +2167,9 @@ enum remote_procedure {
     REMOTE_PROC_GET_SYSINFO = 203,
     REMOTE_PROC_DOMAIN_SET_MEMORY_FLAGS = 204,
     REMOTE_PROC_DOMAIN_SET_BLKIO_PARAMETERS = 205,
-    REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206
+    REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206,
+    REMOTE_PROC_STORAGE_VOL_UPLOAD = 207,
+    REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 208
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 35d0c1c..8a8fb0c 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1409,6 +1409,18 @@ struct remote_domain_open_console_args {
 	remote_string              devname;
 	u_int                      flags;
 };
+struct remote_storage_vol_upload_args {
+	remote_nonnull_storage_vol vol;
+	uint64_t                   offset;
+	uint64_t                   length;
+	u_int                      flags;
+};
+struct remote_storage_vol_download_args {
+	remote_nonnull_storage_vol vol;
+	uint64_t                   offset;
+	uint64_t                   length;
+	u_int                      flags;
+};
 struct remote_message_header {
 	u_int                      prog;
 	u_int                      vers;
-- 
1.7.4


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