[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/7] block: Parse 'detect-zeroes' in bdrv_open_commo
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 4/7] block: Parse 'detect-zeroes' in bdrv_open_common() |
Date: |
Tue, 20 Sep 2016 23:08:54 +0200 |
Amonst others, this means that you can now use the 'detect-zeroes'
option for non-top-level nodes in blockdev-add, like the QAPI schema
promises.
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 33 +++++++++++++++++++++++++++++++++
blockdev.c | 9 +--------
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/block.c b/block.c
index 1e9d66b..b9c780e 100644
--- a/block.c
+++ b/block.c
@@ -41,6 +41,7 @@
#include "qapi-event.h"
#include "qemu/cutils.h"
#include "qemu/id.h"
+#include "qapi/util.h"
#ifdef CONFIG_BSD
#include <sys/ioctl.h>
@@ -906,6 +907,11 @@ static QemuOptsList bdrv_runtime_opts = {
.type = QEMU_OPT_BOOL,
.help = "Node is opened in read-only mode",
},
+ {
+ .name = "detect-zeroes",
+ .type = QEMU_OPT_STRING,
+ .help = "try to optimize zero writes (off, on, unmap)",
+ },
{ /* end of list */ }
},
};
@@ -922,6 +928,7 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild
*file,
const char *filename;
const char *driver_name = NULL;
const char *node_name = NULL;
+ const char *detect_zeroes;
QemuOpts *opts;
BlockDriver *drv;
Error *local_err = NULL;
@@ -990,6 +997,32 @@ static int bdrv_open_common(BlockDriverState *bs,
BdrvChild *file,
}
}
+ detect_zeroes = qemu_opt_get(opts, "detect-zeroes");
+ if (detect_zeroes) {
+ BlockdevDetectZeroesOptions value =
+ qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
+ qemu_opt_get(opts, "detect-zeroes"),
+ BLOCKDEV_DETECT_ZEROES_OPTIONS__MAX,
+ BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
+ &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ ret = -EINVAL;
+ goto fail_opts;
+ }
+
+ if (value == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP &&
+ !(bs->open_flags & BDRV_O_UNMAP))
+ {
+ error_setg(errp, "setting detect-zeroes to unmap is not allowed "
+ "without setting discard operation to unmap");
+ ret = -EINVAL;
+ goto fail_opts;
+ }
+
+ bs->detect_zeroes = value;
+ }
+
if (filename != NULL) {
pstrcpy(bs->filename, sizeof(bs->filename), filename);
} else {
diff --git a/blockdev.c b/blockdev.c
index a611cc8..b847ee9 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -658,7 +658,6 @@ static BlockDriverState *bds_tree_init(QDict *bs_opts,
Error **errp)
BlockDriverState *bs;
QemuOpts *opts;
Error *local_error = NULL;
- BlockdevDetectZeroesOptions detect_zeroes;
int bdrv_flags = 0;
opts = qemu_opts_create(&qemu_root_bds_opts, NULL, 1, errp);
@@ -673,7 +672,7 @@ static BlockDriverState *bds_tree_init(QDict *bs_opts,
Error **errp)
}
extract_common_blockdev_options(opts, &bdrv_flags, NULL, NULL,
- &detect_zeroes, &local_error);
+ NULL, &local_error);
if (local_error) {
error_propagate(errp, local_error);
goto fail;
@@ -695,8 +694,6 @@ static BlockDriverState *bds_tree_init(QDict *bs_opts,
Error **errp)
goto fail_no_bs_opts;
}
- bs->detect_zeroes = detect_zeroes;
-
fail_no_bs_opts:
qemu_opts_del(opts);
return bs;
@@ -4140,10 +4137,6 @@ static QemuOptsList qemu_root_bds_opts = {
.name = "copy-on-read",
.type = QEMU_OPT_BOOL,
.help = "copy read data from backing file into image file",
- },{
- .name = "detect-zeroes",
- .type = QEMU_OPT_STRING,
- .help = "try to optimize zero writes (off, on, unmap)",
},
{ /* end of list */ }
},
--
1.8.3.1
- [Qemu-devel] [PATCH 0/7] block: Make more blockdev-add options work, Kevin Wolf, 2016/09/20
- [Qemu-devel] [PATCH 1/7] block: Drop aio/cache consistency check from qmp_blockdev_add(), Kevin Wolf, 2016/09/20
- [Qemu-devel] [PATCH 5/7] block: Use 'detect-zeroes' option for 'blockdev-change-medium', Kevin Wolf, 2016/09/20
- [Qemu-devel] [PATCH 4/7] block: Parse 'detect-zeroes' in bdrv_open_common(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 7/7] block: Remove qemu_root_bds_opts, Kevin Wolf, 2016/09/20
- [Qemu-devel] [PATCH 2/7] block/qapi: Use separate options type for curl driver, Kevin Wolf, 2016/09/20
- [Qemu-devel] [PATCH 3/7] block/qapi: Move 'aio' option to file driver, Kevin Wolf, 2016/09/20
- [Qemu-devel] [PATCH 6/7] block: Move 'discard' option to bdrv_open_common(), Kevin Wolf, 2016/09/20