block: add event when disk usage exceeds threshold
PATCH v5 1/1 block: add event when disk usage exceeds threshold
Managing applications, like oVirt (http://www.ovirt.org), make extensive use of thin-provisioned disk images.
To let the guest run smoothly and be not unnecessarily paused, oVirt sets a disk usage threshold (so called 'high water mark') based on the occupation of the device, and automatically extends the image once the threshold is reached or exceeded.
In order to detect the crossing of the threshold, oVirt has no choice but aggressively polling the QEMU monitor using the query-blockstats command. This lead to unnecessary system load, and is made even worse under scale:
deployments with hundreds of VMs are no longer rare.
To fix this, this patch adds:
* A new monitor command `block-set-write-threshold', to set a mark for a given block device.
* A new event `BLOCK_WRITE_THRESHOLD', to report if a block device usage exceeds the threshold.
* A new write_threshold' field into the BlockDeviceInfo' structure, to report the configured threshold.
This will allow the managing application to use smarter and more efficient monitoring, greatly reducing the need of polling.
--- block/Makefile.objs | 1 + block/qapi.c | 3 + block/write-threshold.c | 125 ++++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 4 ++ include/block/write-threshold.h | 64 ++++++++++++++++++++ qapi/block-core.json | 51 +++++++++++++++- qmp-commands.hx | 32 ++++++++++ tests/Makefile | 3 + tests/test-write-threshold.c | 119 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 block/write-threshold.c create mode 100644 include/block/write-threshold.h create mode 100644 tests/test-write-threshold.c
block/Makefile.objs +1 -0
@@ -20,6 +20,7 @@ block-obj-$(CONFIG_GLUSTERFS) += gluster.o block-obj-$(CONFIG_ARCHIPELAGO) += archipelago.o block-obj-$(CONFIG_LIBSSH2) += ssh.o block-obj-y += accounting.o +block-obj-y += write-threshold.o common-obj-y += stream.o common-obj-y += commit.o
block/qapi.c +3 -0
@@ -24,6 +24,7 @@#include "block/qapi.h" #include "block/block_int.h" +#include "block/write-threshold.h" #include "qmp-commands.h" #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h"
@@ -89,6 +90,8 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs) info->iops_size = cfg.op_size; } + info->write_threshold =bdrv_write_threshold_get (bs); +return info; }
block/write-threshold.c new file +125 -0
125 lines not on this page · raw message
include/block/block_int.h +4 -0
@@ -412,6 +412,10 @@ struct BlockDriverState {/* The error object in use for blocking operations on backing_hd */ Error *backing_blocker; + +/* threshold limit for writes, in bytes. "High water mark". */ +uint64_t write_threshold_offset; +NotifierWithReturn write_threshold_notifier; };
include/block/write-threshold.h new file +64 -0
64 lines not on this page · raw message
qapi/block-core.json +50 -1
66 lines not on this page · raw message
qmp-commands.hx +32 -0
@@ -2104,6 +2104,8 @@ Each json-object contain the following: - "iops_size": I/O size when limiting by iops (json-int) - "detect_zeroes": detect and optimize zero writing (json-string) - Possible values: "off", "on", "unmap" + - "write_threshold": write offset threshold in bytes, a event will be + emitted if crossed. Zero if disabled (json-int) - "image": the detail of the image, it is a json-object containing the following: - "filename": image file name (json-string)
@@ -2181,6 +2183,7 @@ Example: "iops_wr_max": 0, "iops_size": 0, "detect_zeroes": "on", + "write_threshold": 0, "image":{ "filename":"disks/test.qcow2", "format":"qcow2",
@@ -3624,6 +3627,7 @@ Example: "iops_rd_max": 0, "iops_wr_max": 0, "iops_size": 0, + "write_threshold": 0, "image":{ "filename":"disks/test.qcow2", "format":"qcow2",
@@ -3860,3 +3864,31 @@ Move mouse pointer to absolute coordinates (20000, 400). <- { "return": {} } EQMP + + { + .name = "block-set-write-threshold", + .args_type = "node-name:s,write-threshold:l", + .mhandler.cmd_new = qmp_marshal_input_block_set_write_threshold, + }, + +SQMP +block-set-write-threshold +------------ + +Change the write threshold for a block drive. The threshold is an offset, +thus must be non-negative. Default is no write threshold. +Setting the threshold to zero disables it. + +Arguments: + +- "node-name": the node name in the block driver state graph (json-string) +- "write-threshold": the write threshold in bytes (json-int) + +Example: + +-> { "execute": "block-set-write-threshold", + "arguments": { "node-name": "mydev", + "write-threshold": 17179869184 } } +<- { "return": {} } + +EQMP
tests/Makefile +3 -0
@@ -66,6 +66,8 @@ check-unit-y += tests/check-qom-interface$(EXESUF) gcov-files-check-qom-interface-y = qom/object.c check-unit-y += tests/test-qemu-opts$(EXESUF) gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c +check-unit-y += tests/test-write-threshold$(EXESUF) +gcov-files-test-write-threshold-y = block/write-threshold.c check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -354,6 +356,7 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y) tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a +tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(block-obj-y) libqemuutil.a libqemustub.a ifeq ($(CONFIG_POSIX),y) LIBS += -lutil
tests/test-write-threshold.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.1.0
Stefan Hajnoczi
AppliedQuoted 25 lines · Francesco Romani
Managing applications, like oVirt (http://www.ovirt.org), make extensive use of thin-provisioned disk images.
To let the guest run smoothly and be not unnecessarily paused, oVirt sets a disk usage threshold (so called 'high water mark') based on the occupation of the device, and automatically extends the image once the threshold is reached or exceeded.In order to detect the crossing of the threshold, oVirt has no choice but aggressively polling the QEMU monitor using the query-blockstats command. This lead to unnecessary system load, and is made even worse under scale:
deployments with hundreds of VMs are no longer rare.To fix this, this patch adds:
* A new monitor command `block-set-write-threshold', to set a mark for a given block device.
* A new event `BLOCK_WRITE_THRESHOLD', to report if a block device usage exceeds the threshold.
* A newwrite_threshold' field into theBlockDeviceInfo' structure, to report the configured threshold.This will allow the managing application to use smarter and more efficient monitoring, greatly reducing the need of polling.
Signed-off-by Francesco Romani <[email protected]>Reviewed-by Eric Blake <[email protected]>
Quoted 14 lines
--- block/Makefile.objs | 1 + block/qapi.c | 3 + block/write-threshold.c | 125 ++++++++++++++++++++++++++++++++++++++++ include/block/block_int.h | 4 ++ include/block/write-threshold.h | 64 ++++++++++++++++++++ qapi/block-core.json | 51 +++++++++++++++- qmp-commands.hx | 32 ++++++++++ tests/Makefile | 3 + tests/test-write-threshold.c | 119 ++++++++++++++++++++++++++++++++++++++ 9 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 block/write-threshold.c create mode 100644 include/block/write-threshold.h create mode 100644 tests/test-write-threshold.c
Thanks, applied to my block branch:
https://github.com/stefanha/qemu/tree/block
Stefan
----- Original Message -----
Quoted 8 lines
From: "Stefan Hajnoczi" <[email protected]>
To: "Francesco Romani" <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Sent: Tuesday, January 13, 2015 2:54:41 PM
Subject: Re: [PATCH v5] block: add event when disk usage exceeds thresholdThanks, applied to my block branch:
https://github.com/stefanha/qemu/tree/block
Thank you for the review and the merge!
Bests,
Signature · 4 lines
Francesco Romani RedHat Engineering Virtualization R & D Phone: 8261328 IRC: fromani