From: Kit Westneat <kit.westneat@gmail.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, Kit Westneat <kit.westneat@gmail.com>
Subject: [PATCH v3 1/3] block/blkdebug: add blocksize parameter
Date: Tue, 25 May 2021 19:46:05 +0000 [thread overview]
Message-ID: <20210525194607.553291-2-kit.westneat@gmail.com> (raw)
In-Reply-To: <20210525194607.553291-1-kit.westneat@gmail.com>
Allow users to specify the block size of the qdev for testing purposes.
Signed-off-by: Kit Westneat <kit.westneat@gmail.com>
---
block/blkdebug.c | 29 +++++++++++++++++++++++++++++
qapi/block-core.json | 4 ++++
2 files changed, 33 insertions(+)
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 2c0b9b0ee8..d5f589920c 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -47,6 +47,7 @@ typedef struct BDRVBlkdebugState {
uint64_t max_write_zero;
uint64_t opt_discard;
uint64_t max_discard;
+ uint64_t blocksize;
uint64_t take_child_perms;
uint64_t unshare_child_perms;
@@ -455,6 +456,11 @@ static QemuOptsList runtime_opts = {
.type = QEMU_OPT_SIZE,
.help = "Maximum discard size in bytes",
},
+ {
+ .name = "blocksize",
+ .type = QEMU_OPT_SIZE,
+ .help = "Blocksize of device",
+ },
{ /* end of list */ }
},
};
@@ -562,6 +568,14 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
goto out;
}
+ s->blocksize = qemu_opt_get_size(opts, "blocksize", 512);
+ if (s->blocksize && (s->blocksize >= INT_MAX ||
+ !is_power_of_2(s->blocksize))) {
+ error_setg(errp, "Cannot meet constraints with blocksize %" PRIu64,
+ s->blocksize);
+ goto out;
+ }
+
bdrv_debug_event(bs, BLKDBG_NONE);
ret = 0;
@@ -984,6 +998,19 @@ static void blkdebug_refresh_limits(BlockDriverState *bs, Error **errp)
}
}
+static int blkdebug_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
+{
+ BDRVBlkdebugState *s = bs->opaque;
+
+ if (!s->blocksize) {
+ return 0;
+ }
+
+ bsz->phys = s->blocksize;
+ bsz->log = s->blocksize;
+ return 0;
+}
+
static int blkdebug_reopen_prepare(BDRVReopenState *reopen_state,
BlockReopenQueue *queue, Error **errp)
{
@@ -1010,6 +1037,7 @@ static const char *const blkdebug_strong_runtime_opts[] = {
"inject-error.",
"set-state.",
"align",
+ "blocksize",
"max-transfer",
"opt-write-zero",
"max-write-zero",
@@ -1034,6 +1062,7 @@ static BlockDriver bdrv_blkdebug = {
.bdrv_getlength = blkdebug_getlength,
.bdrv_refresh_filename = blkdebug_refresh_filename,
.bdrv_refresh_limits = blkdebug_refresh_limits,
+ .bdrv_probe_blocksizes = blkdebug_probe_blocksizes,
.bdrv_co_preadv = blkdebug_co_preadv,
.bdrv_co_pwritev = blkdebug_co_pwritev,
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 2ea294129e..1b1f2692ef 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3404,6 +3404,9 @@
# on how the blkdebug node is used). Defaults
# to none. (since 5.0)
#
+# @blocksize: blocksize of device in bytes, must be
+# positive power of 2 (since 6.1)
+#
# Since: 2.9
##
{ 'struct': 'BlockdevOptionsBlkdebug',
@@ -3412,6 +3415,7 @@
'*align': 'int', '*max-transfer': 'int32',
'*opt-write-zero': 'int32', '*max-write-zero': 'int32',
'*opt-discard': 'int32', '*max-discard': 'int32',
+ '*blocksize': 'int',
'*inject-error': ['BlkdebugInjectErrorOptions'],
'*set-state': ['BlkdebugSetStateOptions'],
'*take-child-perms': ['BlockPermission'],
--
2.26.3
next prev parent reply other threads:[~2021-05-25 19:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-25 19:46 [PATCH v3 0/3] testing block device blocksizes Kit Westneat
2021-05-25 19:46 ` Kit Westneat [this message]
2021-05-25 19:46 ` [PATCH v3 2/3] tests/qtest/virtio-scsi-test: add unmap large LBA with 4k blocks test Kit Westneat
2021-05-26 14:40 ` Paolo Bonzini
2021-05-25 19:46 ` [PATCH v3 3/3] block/blkdebug: add log-blocksize and phys-blocksize parameters Kit Westneat
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210525194607.553291-2-kit.westneat@gmail.com \
--to=kit.westneat@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).