[libvirt] [PATCH 2/8] Add virDomain{Set, Get}BlockIoTune support to the remote driver

Lei Li lilei at linux.vnet.ibm.com
Wed Nov 9 20:32:52 UTC 2011


Support Block I/O Throttle setting and query to remote driver.

Signed-off-by: Zhi Yong Wu <wuzhy at linux.vnet.ibm.com>
Signed-off-by: Lei Li <lilei at linux.vnet.ibm.com>
---
 daemon/remote.c              |   87 ++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   80 ++++++++++++++++++++++++++++++++++++++
 src/remote/remote_protocol.x |   38 ++++++++++++++++++-
 src/remote_protocol-structs  |   33 ++++++++++++++++
 4 files changed, 237 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index bd0c3e3..070ca65 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -1850,6 +1850,93 @@ cleanup:
     return rv;
 }
 
+static int
+remoteDispatchDomainSetBlockIoThrottle(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                       virNetServerClientPtr client ATTRIBUTE_UNUSED,
+                                       virNetMessagePtr hdr ATTRIBUTE_UNUSED,
+                                       virNetMessageErrorPtr rerr,
+                                       remote_domain_set_block_io_throttle_args *args)
+{
+    virDomainPtr dom = NULL;
+    virDomainBlockIoTuneInfo tmp;
+    int rv = -1;
+    struct daemonClientPrivate *priv =
+        virNetServerClientGetPrivateData(client);
+
+    if (!priv->conn) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
+        goto cleanup;
+
+    if (args) {
+        tmp.total_bytes_sec = args->bps;
+        tmp.read_bytes_sec = args->bps_rd;
+        tmp.write_bytes_sec = args->bps_wr;
+        tmp.total_iops_sec = args->iops;
+        tmp.read_iops_sec = args->iops_rd;
+        tmp.write_iops_sec = args->iops_wr;
+    }
+
+    rv = virDomainSetBlockIoTune(dom, args->disk, &tmp, args->flags);
+
+    if (rv < 0)
+        goto cleanup;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (dom)
+        virDomainFree(dom);
+    return rv;
+}
+
+static int
+remoteDispatchDomainGetBlockIoThrottle(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                       virNetServerClientPtr client ATTRIBUTE_UNUSED,
+                                       virNetMessagePtr hdr ATTRIBUTE_UNUSED,
+                                       virNetMessageErrorPtr rerr,
+                                       remote_domain_get_block_io_throttle_args *args,
+                                       remote_domain_get_block_io_throttle_ret *ret)
+{
+    virDomainPtr dom = NULL;
+    virDomainBlockIoTuneInfo reply;
+    int rv = -1;
+    struct daemonClientPrivate *priv =
+        virNetServerClientGetPrivateData(client);
+
+    if (!priv->conn) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
+        goto cleanup;
+
+    rv = virDomainGetBlockIoTune(dom, args->disk, &reply, args->flags);
+
+    if (rv < 0) {
+        ret->found = 0;
+        goto cleanup;
+    }
+
+    ret->bps     = reply.total_bytes_sec;
+    ret->bps_rd  = reply.read_bytes_sec;
+    ret->bps_wr  = reply.write_bytes_sec;
+    ret->iops    = reply.total_iops_sec;
+    ret->iops_rd = reply.read_iops_sec;
+    ret->iops_wr = reply.write_iops_sec;
+    ret->found = 1;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (dom)
+        virDomainFree(dom);
+    return rv;
+}
 
 /*-------------------------------------------------------------*/
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index f3b8ad5..0900231 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2154,6 +2154,84 @@ done:
     return rv;
 }
 
+static int remoteDomainSetBlockIoTune(virDomainPtr domain,
+                                      const char *disk,
+                                      virDomainBlockIoTuneInfoPtr info,
+                                      unsigned int flags)
+{
+    int rv = -1;
+    remote_domain_set_block_io_throttle_args args;
+    struct private_data *priv = domain->conn->privateData;
+
+    remoteDriverLock(priv);
+
+    memset(&args, 0, sizeof(args));
+
+    make_nonnull_domain(&args.dom, domain);
+    args.disk = (char *)disk;
+    args.bps = info->total_bytes_sec;
+    args.bps_rd = info->read_bytes_sec;
+    args.bps_wr = info->write_bytes_sec;
+    args.iops = info->total_iops_sec;
+    args.iops_rd = info->read_iops_sec;
+    args.iops_wr = info->write_iops_sec;
+    args.flags = flags;
+
+    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_BLOCK_IO_THROTTLE,
+             (xdrproc_t) xdr_remote_domain_set_block_io_throttle_args,
+               (char *) &args,
+             (xdrproc_t) xdr_void,
+               (char *) NULL) == -1) {
+        goto done;
+    }
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
+static int remoteDomainGetBlockIoTune(virDomainPtr domain,
+                                      const char *disk,
+                                      virDomainBlockIoTuneInfoPtr reply,
+                                      unsigned int flags)
+{
+    int rv = -1;
+    remote_domain_get_block_io_throttle_args args;
+    remote_domain_get_block_io_throttle_ret ret;
+    struct private_data *priv = domain->conn->privateData;
+
+    remoteDriverLock(priv);
+
+    make_nonnull_domain(&args.dom, domain);
+    args.disk = (char *)disk;
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+
+    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_BLOCK_IO_THROTTLE,
+             (xdrproc_t) xdr_remote_domain_get_block_io_throttle_args,
+               (char *) &args,
+             (xdrproc_t) xdr_remote_domain_get_block_io_throttle_ret,
+               (char *) &ret) == -1) {
+        goto done;
+    }
+
+    if (ret.found) {
+        reply->total_bytes_sec = ret.bps;
+        reply->read_bytes_sec = ret.bps_rd;
+        reply->write_bytes_sec = ret.bps_wr;
+        reply->total_iops_sec = ret.iops;
+        reply->read_iops_sec = ret.iops_rd;
+        reply->write_iops_sec = ret.iops_wr;
+    }
+    rv = 0;
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 /*----------------------------------------------------------------------*/
 
 static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
@@ -4526,6 +4604,8 @@ static virDriver remote_driver = {
     .domainGetBlockJobInfo = remoteDomainGetBlockJobInfo, /* 0.9.4 */
     .domainBlockJobSetSpeed = remoteDomainBlockJobSetSpeed, /* 0.9.4 */
     .domainBlockPull = remoteDomainBlockPull, /* 0.9.4 */
+    .domainSetBlockIoTune = remoteDomainSetBlockIoTune, /* 0.9.8 */
+    .domainGetBlockIoTune = remoteDomainGetBlockIoTune, /* 0.9.8 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index a174af8..ccc77b5 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1073,6 +1073,40 @@ struct remote_domain_block_pull_args {
     unsigned int flags;
 };
 
+struct remote_domain_set_block_io_throttle_args {
+    remote_nonnull_domain dom;
+    remote_nonnull_string disk;
+    unsigned hyper bps;
+    unsigned hyper bps_rd;
+    unsigned hyper bps_wr;
+    unsigned hyper iops;
+    unsigned hyper iops_rd;
+    unsigned hyper iops_wr;
+    unsigned int flags;
+};
+
+struct remote_domain_get_block_io_throttle_args {
+    remote_nonnull_domain dom;
+    remote_nonnull_string disk;
+    unsigned hyper bps;
+    unsigned hyper bps_rd;
+    unsigned hyper bps_wr;
+    unsigned hyper iops;
+    unsigned hyper iops_rd;
+    unsigned hyper iops_wr;
+    unsigned int flags;
+};
+
+struct remote_domain_get_block_io_throttle_ret {
+    unsigned hyper bps;
+    unsigned hyper bps_rd;
+    unsigned hyper bps_wr;
+    unsigned hyper iops;
+    unsigned hyper iops_rd;
+    unsigned hyper iops_wr;
+    unsigned int found;
+};
+
 /* Network calls: */
 
 struct remote_num_of_networks_ret {
@@ -2562,7 +2596,9 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_SNAPSHOT_NUM_CHILDREN = 246, /* autogen autogen priority:high */
     REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_CHILDREN_NAMES = 247, /* autogen autogen priority:high */
     REMOTE_PROC_DOMAIN_EVENT_DISK_CHANGE = 248, /* skipgen skipgen */
-    REMOTE_PROC_DOMAIN_OPEN_GRAPHICS = 249 /* skipgen skipgen */
+    REMOTE_PROC_DOMAIN_OPEN_GRAPHICS = 249, /* skipgen skipgen */
+    REMOTE_PROC_DOMAIN_SET_BLOCK_IO_THROTTLE = 250, /* skipgen skipgen */
+    REMOTE_PROC_DOMAIN_GET_BLOCK_IO_THROTTLE = 251 /* skipgen skipgen */
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 12cedef..4a813e0 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -757,6 +757,37 @@ struct remote_domain_block_pull_args {
         uint64_t                   bandwidth;
         u_int                      flags;
 };
+struct remote_domain_set_block_io_throttle_args {
+        remote_nonnull_domain      dom;
+        remote_nonnull_string      disk;
+        uint64_t                   bps;
+        uint64_t                   bps_rd;
+        uint64_t                   bps_wr;
+        uint64_t                   iops;
+        uint64_t                   iops_rd;
+        uint64_t                   iops_wr;
+        u_int                      flags;
+};
+struct remote_domain_get_block_io_throttle_args {
+        remote_nonnull_domain      dom;
+        remote_nonnull_string      disk;
+        uint64_t                   bps;
+        uint64_t                   bps_rd;
+        uint64_t                   bps_wr;
+        uint64_t                   iops;
+        uint64_t                   iops_rd;
+        uint64_t                   iops_wr;
+        u_int                      flags;
+};
+struct remote_domain_get_block_io_throttle_ret {
+        uint64_t                   bps;
+        uint64_t                   bps_rd;
+        uint64_t                   bps_wr;
+        uint64_t                   iops;
+        uint64_t                   iops_rd;
+        uint64_t                   iops_wr;
+        u_int                      found;
+};
 struct remote_num_of_networks_ret {
         int                        num;
 };
@@ -2005,4 +2036,6 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_SNAPSHOT_LIST_CHILDREN_NAMES = 247,
         REMOTE_PROC_DOMAIN_EVENT_DISK_CHANGE = 248,
         REMOTE_PROC_DOMAIN_OPEN_GRAPHICS = 249,
+        REMOTE_PROC_DOMAIN_SET_BLOCK_IO_THROTTLE = 250,
+        REMOTE_PROC_DOMAIN_GET_BLOCK_IO_THROTTLE = 251,
 };
-- 
1.7.1




More information about the libvir-list mailing list