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

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

 



* 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 +++++++-
 8 files changed, 277 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index c5509ad..c9b714f 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -5580,7 +5580,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 57962d1..2022cee 100644
--- a/daemon/remote_dispatch_args.h
+++ b/daemon/remote_dispatch_args.h
@@ -172,3 +172,5 @@
     remote_domain_open_console_args val_remote_domain_open_console_args;
     remote_domain_is_updated_args val_remote_domain_is_updated_args;
     remote_get_sysinfo_args val_remote_get_sysinfo_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 e59701a..b219cbd 100644
--- a/daemon/remote_dispatch_prototypes.h
+++ b/daemon/remote_dispatch_prototypes.h
@@ -1506,6 +1506,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,
@@ -1554,6 +1562,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 5d27390..de682cd 100644
--- a/daemon/remote_dispatch_table.h
+++ b/daemon/remote_dispatch_table.h
@@ -1022,3 +1022,13 @@
     .args_filter = (xdrproc_t) xdr_remote_get_sysinfo_args,
     .ret_filter = (xdrproc_t) xdr_remote_get_sysinfo_ret,
 },
+{   /* StorageVolUpload => 204 */
+    .fn = (dispatch_fn) remoteDispatchStorageVolUpload,
+    .args_filter = (xdrproc_t) xdr_remote_storage_vol_upload_args,
+    .ret_filter = (xdrproc_t) xdr_void,
+},
+{   /* StorageVolDownload => 205 */
+    .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 0be9c56..210e6ab 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -9358,6 +9358,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,
@@ -11021,6 +11106,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 bae92ca..bad3d69 100644
--- a/src/remote/remote_protocol.c
+++ b/src/remote/remote_protocol.c
@@ -3758,6 +3758,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 46d526a..aec6c13 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -2124,6 +2124,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
 
@@ -2331,6 +2347,8 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_OPEN_CONSOLE = 201,
         REMOTE_PROC_DOMAIN_IS_UPDATED = 202,
         REMOTE_PROC_GET_SYSINFO = 203,
+        REMOTE_PROC_STORAGE_VOL_UPLOAD = 204,
+        REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 205,
 };
 typedef enum remote_procedure remote_procedure;
 
@@ -2705,6 +2723,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*);
@@ -3053,6 +3073,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 e77aca1..21c469a 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1874,6 +1874,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. */
@@ -2103,7 +2118,9 @@ enum remote_procedure {
 
     REMOTE_PROC_DOMAIN_OPEN_CONSOLE = 201,
     REMOTE_PROC_DOMAIN_IS_UPDATED = 202,
-    REMOTE_PROC_GET_SYSINFO = 203
+    REMOTE_PROC_GET_SYSINFO = 203,
+    REMOTE_PROC_STORAGE_VOL_UPLOAD = 204,
+    REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 205
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
-- 
1.7.4

--
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]