@@ -901,6 +901,10 @@ static QemuOptsList bdrv_runtime_opts = {
.name = "node-name",
.type = QEMU_OPT_STRING,
.help = "Node name of the block device node",
+ },{
+ .name = "write-merging",
+ .type = QEMU_OPT_BOOL,
+ .help = "enable write merging (default: true)",
},
{ /* end of list */ }
},
@@ -1003,6 +1007,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
bs->opaque = g_malloc0(drv->instance_size);
bs->enable_write_cache = !!(flags & BDRV_O_CACHE_WB);
+ bs->write_merging = qemu_opt_get_bool(opts, "write-merging", true);
/* Open the image, either directly or using a protocol */
if (drv->bdrv_file_open) {
@@ -4559,6 +4564,10 @@ static int multiwrite_merge(BlockDriverState *bs, BlockRequest *reqs,
{
int i, outidx;
+ if (!bs->write_merging) {
+ return num_reqs;
+ }
+
// Sort requests by start sector
qsort(reqs, num_reqs, sizeof(*reqs), &multiwrite_req_compare);
@@ -58,6 +58,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs)
info->backing_file_depth = bdrv_get_backing_file_depth(bs);
info->detect_zeroes = bs->detect_zeroes;
+ info->write_merging = bs->write_merging;
if (bs->io_limits_enabled) {
ThrottleConfig cfg;
@@ -348,6 +348,10 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
BlockdevDetectZeroesOptions_lookup[info->value->inserted->detect_zeroes]);
}
+ if (!info->value->inserted->write_merging) {
+ monitor_printf(mon, " Write Merging: off\n");
+ }
+
if (info->value->inserted->bps
|| info->value->inserted->bps_rd
|| info->value->inserted->bps_wr
@@ -407,6 +407,7 @@ struct BlockDriverState {
QDict *options;
BlockdevDetectZeroesOptions detect_zeroes;
+ bool write_merging;
/* The error object in use for blocking operations on backing_hd */
Error *backing_blocker;
@@ -214,6 +214,8 @@
#
# @detect_zeroes: detect and optimize zero writes (Since 2.1)
#
+# @write_merging: true if write merging is enabled (Since 2.2)
+#
# @bps: total throughput limit in bytes per second is specified
#
# @bps_rd: read throughput limit in bytes per second is specified
@@ -250,6 +252,7 @@
'*backing_file': 'str', 'backing_file_depth': 'int',
'encrypted': 'bool', 'encryption_key_missing': 'bool',
'detect_zeroes': 'BlockdevDetectZeroesOptions',
+ 'write_merging': 'bool',
'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
'image': 'ImageInfo',
@@ -1187,6 +1190,10 @@
# (default: false)
# @detect-zeroes: #optional detect and optimize zero writes (Since 2.1)
# (default: off)
+# @write-merging: #optional enable the merging of write requests
+# also known as multiwrite_merge (Since 2.2)
+# (default: true, but this might change in the future
+# depending on format/protocol/features used)
#
# Since: 1.7
##
@@ -1200,7 +1207,8 @@
'*rerror': 'BlockdevOnError',
'*werror': 'BlockdevOnError',
'*read-only': 'bool',
- '*detect-zeroes': 'BlockdevDetectZeroesOptions' } }
+ '*detect-zeroes': 'BlockdevDetectZeroesOptions',
+ '*write-merging': 'bool' } }
##
# @BlockdevOptionsFile
@@ -432,6 +432,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive,
" [,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]\n"
" [,readonly=on|off][,copy-on-read=on|off]\n"
" [,discard=ignore|unmap][,detect-zeroes=on|off|unmap]\n"
+ " [,write-merging=on|off]\n"
" [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]]\n"
" [[,iops=i]|[[,iops_rd=r][,iops_wr=w]]]\n"
" [[,bps_max=bm]|[[,bps_rd_max=rm][,bps_wr_max=wm]]]\n"
@@ -2104,6 +2104,7 @@ 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_merging": enable merging of write requests (json-bool)
- "image": the detail of the image, it is a json-object containing
the following:
- "filename": image file name (json-string)
@@ -2181,6 +2182,7 @@ Example:
"iops_wr_max": 0,
"iops_size": 0,
"detect_zeroes": "on",
+ "write_merging": "true",
"image":{
"filename":"disks/test.qcow2",
"format":"qcow2",