diff mbox series

[1/3] block/blkdebug: add blocksize parameter

Message ID 20210525124753.528516-2-kit.westneat@gmail.com (mailing list archive)
State New, archived
Headers show
Series testing block device blocksizes | expand

Commit Message

Kit Westneat May 25, 2021, 12:47 p.m. UTC
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 | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Eric Blake May 25, 2021, 2:46 p.m. UTC | #1
On Tue, May 25, 2021 at 12:47:51PM +0000, Kit Westneat wrote:
> 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 | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)

Should this also be selectable when using QAPI to create a blkdebug
device over QMP?
Kit Westneat May 25, 2021, 5:59 p.m. UTC | #2
Makes sense. Sorry for the basic question, but is that just a matter of
adding it to qapi/block-core.json?

Thanks,
Kit

On Tue, May 25, 2021 at 10:46 AM Eric Blake <eblake@redhat.com> wrote:

> On Tue, May 25, 2021 at 12:47:51PM +0000, Kit Westneat wrote:
> > 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 | 27 +++++++++++++++++++++++++++
> >  1 file changed, 27 insertions(+)
>
> Should this also be selectable when using QAPI to create a blkdebug
> device over QMP?
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.           +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
>
>
diff mbox series

Patch

diff --git a/block/blkdebug.c b/block/blkdebug.c
index 2c0b9b0ee8..c7500746a8 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,13 @@  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 +997,18 @@  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 +1035,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 +1060,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,