[libvirt] [RFC PATCH 2/5] Add virDomainBlockIoThrottle support to the remote driver
Adam Litke
agl at us.ibm.com
Tue Oct 11 15:09:53 UTC 2011
On Mon, Oct 10, 2011 at 09:45:10PM +0800, Lei HH Li wrote:
Patch summary please.
>
> Signed-off-by: Zhi Yong Wu <wuzhy at linux.vnet.ibm.com>
> ---
> daemon/remote.c | 51 ++++++++++++++++++++++++++++++++++++++++
> src/remote/remote_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++
> src/remote/remote_protocol.x | 24 ++++++++++++++++++-
> src/remote_protocol-structs | 21 +++++++++++++++-
> 4 files changed, 147 insertions(+), 2 deletions(-)
>
> diff --git a/daemon/remote.c b/daemon/remote.c
> index 245d41c..2b277b3 100644
> --- a/daemon/remote.c
> +++ b/daemon/remote.c
> @@ -1796,6 +1796,57 @@ cleanup:
> return rv;
> }
>
> +static int
> +remoteDispatchDomainBlockIoThrottle(virNetServerPtr server ATTRIBUTE_UNUSED,
> + virNetServerClientPtr client ATTRIBUTE_UNUSED,
> + virNetMessageHeaderPtr hdr ATTRIBUTE_UNUSED,
> + virNetMessageErrorPtr rerr,
> + remote_domain_block_io_throttle_args *args,
> + remote_domain_block_io_throttle_ret *ret)
> +{
> + virDomainPtr dom = NULL;
> + virDomainBlockIoThrottleInfo tmp;
> + virDomainBlockIoThrottleInfo 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;
> +
> + if (args) {
> + tmp.bps = args->bps;
> + tmp.bps_rd = args->bps_rd;
> + tmp.bps_wr = args->bps_wr;
> + tmp.iops = args->iops;
> + tmp.iops_rd = args->iops_rd;
> + tmp.iops_wr = args->iops_wr;
> + }
> +
> + rv = virDomainBlockIoThrottle(dom, args->disk, &tmp, &reply, args->flags);
> + if (rv <= 0)
> + goto cleanup;
> +
> + ret->bps = reply.bps;
> + ret->bps_rd = reply.bps_rd;
> + ret->bps_wr = reply.bps_wr;
> + ret->iops = reply.iops;
> + ret->iops_rd = reply.iops_rd;
> + ret->iops_wr = reply.iops_wr;
> + rv = 0;
> +
> +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 2b2f41e..5dbc793 100644
> --- a/src/remote/remote_driver.c
> +++ b/src/remote/remote_driver.c
> @@ -2136,6 +2136,58 @@ done:
> return rv;
> }
>
> +static int remoteDomainBlockIoThrottle(virDomainPtr domain,
> + const char *disk,
> + virDomainBlockIoThrottleInfoPtr info,
> + virDomainBlockIoThrottleInfoPtr reply,
> + unsigned int flags)
> +{
> + int rv = -1;
> + remote_domain_block_io_throttle_args args;
> + remote_domain_block_io_throttle_ret ret;
> + struct private_data *priv = domain->conn->privateData;
> +
> + remoteDriverLock(priv);
> +
> + memset(&args, 0, sizeof(args));
> + memset(&ret, 0, sizeof(ret));
> +
> + make_nonnull_domain(&args.dom, domain);
> + args.disk = (char *)disk;
> + args.bps = info->bps;
> + args.bps_rd = info->bps_rd;
> + args.bps_wr = info->bps_wr;
> + args.iops = info->iops;
> + args.iops_rd = info->iops_rd;
> + args.iops_wr = info->iops_wr;
> + args.flags = flags;
> +
> + if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_BLOCK_IO_THROTTLE,
> + (xdrproc_t) xdr_remote_domain_block_io_throttle_args,
> + (char *) &args,
> + (xdrproc_t) xdr_remote_domain_block_io_throttle_ret,
> + (char *) &ret) == -1) {
> + goto done;
> + }
> +
> + if (ret.bps || ret.bps_rd || ret.bps_wr
> + || ret.iops || ret.iops_rd || ret.iops_wr) {
This is ugly. You are detecting whether the device is throttled by scanning all
attributes for a non-zero value. Why not change the return value of the API
itself to give you this information. virDomainBlockIoThrottle() returns < 0
on error, 0 on success (with no throttling active), and 1 on success (with
throttling information to report).
> + reply->bps = ret.bps;
> + reply->bps_rd = ret.bps_rd;
> + reply->bps_wr = ret.bps_wr;
> + reply->iops = ret.iops;
> + reply->iops_rd = ret.iops_rd;
> + reply->iops_wr = ret.iops_wr;
> + rv = 1;
> + } else {
> + rv = 0;
> + }
> +
> +done:
> + remoteDriverUnlock(priv);
> + return rv;
> +}
> +
> /*----------------------------------------------------------------------*/
>
> static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
> @@ -4431,6 +4483,7 @@ static virDriver remote_driver = {
> .domainGetBlockJobInfo = remoteDomainGetBlockJobInfo, /* 0.9.4 */
> .domainBlockJobSetSpeed = remoteDomainBlockJobSetSpeed, /* 0.9.4 */
> .domainBlockPull = remoteDomainBlockPull, /* 0.9.4 */
> + .domainBlockIoThrottle = remoteDomainBlockIoThrottle, /* 0.9.4 */
Use the next planned version number (as of today: 0.9.8).
> };
>
> static virNetworkDriver network_driver = {
> diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
> index c8a92fd..ab11a70 100644
> --- a/src/remote/remote_protocol.x
> +++ b/src/remote/remote_protocol.x
> @@ -1073,6 +1073,27 @@ struct remote_domain_block_pull_args {
> unsigned int flags;
> };
>
> +struct remote_domain_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_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;
> +};
> +
> /* Network calls: */
>
> struct remote_num_of_networks_ret {
> @@ -2525,7 +2546,8 @@ enum remote_procedure {
> REMOTE_PROC_DOMAIN_MIGRATE_GET_MAX_SPEED = 242, /* autogen autogen */
> REMOTE_PROC_DOMAIN_BLOCK_STATS_FLAGS = 243, /* skipgen skipgen */
> REMOTE_PROC_DOMAIN_SNAPSHOT_GET_PARENT = 244, /* autogen autogen */
> - REMOTE_PROC_DOMAIN_RESET = 245 /* autogen autogen */
> + REMOTE_PROC_DOMAIN_RESET = 245, /* autogen autogen */
> + REMOTE_PROC_DOMAIN_BLOCK_IO_THROTTLE = 246 /* 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 69175cc..8f0cfcd 100644
> --- a/src/remote_protocol-structs
> +++ b/src/remote_protocol-structs
> @@ -757,6 +757,25 @@ struct remote_domain_block_pull_args {
> uint64_t bandwidth;
> u_int flags;
> };
> +struct remote_domain_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_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;
> +};
> struct remote_num_of_networks_ret {
> int num;
> };
> @@ -1970,5 +1989,5 @@ enum remote_procedure {
> REMOTE_PROC_DOMAIN_MIGRATE_GET_MAX_SPEED = 242,
> REMOTE_PROC_DOMAIN_BLOCK_STATS_FLAGS = 243,
> REMOTE_PROC_DOMAIN_SNAPSHOT_GET_PARENT = 244,
> - REMOTE_PROC_DOMAIN_RESET = 245,
> + REMOTE_PROC_DOMAIN_BLOCK_IO_THROTTLE = 245,
Oops, you removed REMOTE_PROC_DOMAIN_RESET :). Just append your new rpc ID.
> };
> --
> 1.7.1
>
--
Adam Litke <agl at us.ibm.com>
IBM Linux Technology Center
More information about the libvir-list
mailing list