From fcd92f1c2f08e1ce15adcb115b0bae06c02c81d4 Mon Sep 17 00:00:00 2001 From: Conghui Date: Wed, 21 Sep 2022 11:07:04 +0800 Subject: [PATCH] dm: virtio-blk: fix parameter err Fix the truncate issue for virtio block parameter. Tracked-On: #8162 Signed-off-by: Conghui Acked-by: Wang, Yu1 --- devicemodel/hw/pci/virtio/virtio_block.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/devicemodel/hw/pci/virtio/virtio_block.c b/devicemodel/hw/pci/virtio/virtio_block.c index e499057ad..57eca75a2 100644 --- a/devicemodel/hw/pci/virtio/virtio_block.c +++ b/devicemodel/hw/pci/virtio/virtio_block.c @@ -500,13 +500,16 @@ virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) WPRINTF(("%s: strdup failed\n", __func__)); return -1; } - if (strstr(opts, "nodisk") != NULL) { - dummy_bctxt = true; - } else if ((opt = strsep(&opts_tmp, ",")) != NULL) { + if (strstr(opts, "nodisk") == NULL) { + opt = strsep(&opts_tmp, ","); if (strcmp("iothread", opt) == 0) { use_iothread = true; } else { - opts_tmp = opts_start; + /* The opts_start is truncated by strsep, opts_tmp is also + * changed by strsetp, so use opts which points to the + * original parameter string + */ + opts_tmp = opts; } bctxt = blockif_open(opts_tmp, bident); if (bctxt == NULL) { @@ -514,7 +517,10 @@ virtio_blk_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) free(opts_start); return -1; } + } else { + dummy_bctxt = true; } + free(opts_start);