From: "Denis V. Lunev" <den@openvz.org>
To: andrey.drobyshev@virtuozzo.com
Cc: svt-core@virtuozzo.com, den@openvz.org
Subject: [PATCH hci-dev 4/6] tests/qtest/virtio-scsi: cover a replacement that changes the size #VSTOR-130961
Date: Wed, 4 Nov 2026 14:45:37 +0100 [thread overview]
Message-ID: <20261104134539.1519657-5-den@openvz.org> (raw)
In-Reply-To: <20261104134539.1519657-1-den@openvz.org>
From: Denis V. Lunev <den@openvz.org>
Realize a scsi-hd on a 1 MiB node, replace it with a 128 MiB one using
qom-set, and check that the device reports CAPACITY DATA HAS CHANGED and
then serves a read which only fits in the new node.
Both halves regress on their own. Without the notification from
bdrv_replace_child_bs() the first command after the replacement fails with
ILLEGAL REQUEST / LOGICAL BLOCK ADDRESS OUT OF RANGE instead of the unit
attention. Without the refresh in scsi_disk_resize_cb() the read after it
is refused the same way, since nothing here issues READ CAPACITY.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Message-ID: <20260812121500.1034178-4-den@openvz.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit e0856654911f3730cc71ab5c3a3a272cdbaff148)
---
tests/qtest/virtio-scsi-test.c | 63 ++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
diff --git a/tests/qtest/virtio-scsi-test.c b/tests/qtest/virtio-scsi-test.c
index db10d572d0f..f1aaeb31559 100644
--- a/tests/qtest/virtio-scsi-test.c
+++ b/tests/qtest/virtio-scsi-test.c
@@ -236,6 +236,53 @@ static void test_unmap_large_lba(void *obj, void *data,
qvirtio_scsi_pci_free(vs);
}
+/* Test replacing the backing node with one of a different size */
+static void test_replaced_node_size(void *obj, void *data,
+ QGuestAllocator *t_alloc)
+{
+ QVirtioSCSI *scsi = obj;
+ QVirtioSCSIQueues *vs;
+ uint8_t buf[512] = { 0 };
+ /* READ(10), LBA 0, transfer length 1 */
+ const uint8_t read_low_cdb[VIRTIO_SCSI_CDB_SIZE] = {
+ 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00
+ };
+ /* READ(10), LBA 0x1000 (2 MiB), transfer length 1 */
+ const uint8_t read_high_cdb[VIRTIO_SCSI_CDB_SIZE] = {
+ 0x28, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00
+ };
+ struct virtio_scsi_cmd_resp resp;
+
+ alloc = t_alloc;
+ vs = qvirtio_scsi_init(scsi->vdev);
+
+ /* LBA 0 is inside the 1 MiB node the device was realized with */
+ virtio_scsi_do_command(vs, read_low_cdb, buf, sizeof(buf), NULL, 0, &resp);
+ g_assert_cmphex(resp.response, ==, 0);
+ g_assert_cmphex(resp.status, ==, GOOD);
+
+ /* Swap in a 128 MiB node; the device is not reset by this */
+ qtest_qmp_assert_success(global_qtest,
+ "{'execute': 'qom-set', 'arguments': {"
+ " 'path': '/machine/peripheral/scsi-hd0',"
+ " 'property': 'drive', 'value': 'big'}}");
+
+ /* The guest has to be told that the capacity it knows is stale */
+ virtio_scsi_do_command(vs, read_high_cdb, buf, sizeof(buf), NULL, 0, &resp);
+ g_assert_cmphex(resp.response, ==, 0);
+ g_assert_cmphex(resp.status, ==, CHECK_CONDITION);
+ g_assert_cmphex(resp.sense[2], ==, UNIT_ATTENTION);
+ g_assert_cmphex(resp.sense[12], ==, 0x2a);
+ g_assert_cmphex(resp.sense[13], ==, 0x09); /* CAPACITY DATA HAS CHANGED */
+
+ /* LBA 0x1000 is past the old node but well inside the new one */
+ virtio_scsi_do_command(vs, read_high_cdb, buf, sizeof(buf), NULL, 0, &resp);
+ g_assert_cmphex(resp.response, ==, 0);
+ g_assert_cmphex(resp.status, ==, GOOD);
+
+ qvirtio_scsi_pci_free(vs);
+}
+
static void test_write_to_cdrom(void *obj, void *data,
QGuestAllocator *t_alloc)
{
@@ -340,6 +387,18 @@ static void *virtio_scsi_setup_4k(GString *cmd_line, void *arg)
return arg;
}
+static void *virtio_scsi_setup_replace(GString *cmd_line, void *arg)
+{
+ g_string_append(cmd_line,
+ " -blockdev driver=null-co,read-zeroes=on,"
+ "size=1048576,node-name=small"
+ " -blockdev driver=null-co,read-zeroes=on,"
+ "size=134217728,node-name=big"
+ " -device scsi-hd,id=scsi-hd0,drive=small,"
+ "lun=0,scsi-id=1");
+ return arg;
+}
+
static void *virtio_scsi_setup_cd(GString *cmd_line, void *arg)
{
g_string_append(cmd_line,
@@ -374,6 +433,10 @@ static void register_virtio_scsi_test(void)
qos_add_test("large-lba-unmap", "virtio-scsi",
test_unmap_large_lba, &opts);
+ opts.before = virtio_scsi_setup_replace;
+ qos_add_test("replaced-node-size", "virtio-scsi",
+ test_replaced_node_size, &opts);
+
opts.before = virtio_scsi_setup_cd;
qos_add_test("write-to-cdrom", "virtio-scsi", test_write_to_cdrom, &opts);
--
2.53.0
next prev parent reply other threads:[~2026-11-04 13:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 13:45 [PATCH hci-dev 0/6] block, scsi-disk: honour a size change on child replacement #VSTOR-130961 Denis V. Lunev
2026-11-04 13:45 ` [PATCH hci-dev 1/6] block: make bdrv_co_parent_cb_resize() a proper IO API function #VSTOR-130961 Denis V. Lunev
2026-11-04 13:47 ` no-reply
2026-11-04 13:45 ` [PATCH hci-dev 2/6] block: notify the parent when a replaced child has a different size #VSTOR-130961 Denis V. Lunev
2026-11-04 13:51 ` no-reply
2026-11-04 13:45 ` [PATCH hci-dev 3/6] scsi-disk: refresh the cached capacity from the resize callback #VSTOR-130961 Denis V. Lunev
2026-11-04 13:50 ` no-reply
2026-11-04 13:45 ` Denis V. Lunev [this message]
2026-11-04 13:54 ` [PATCH hci-dev 4/6] tests/qtest/virtio-scsi: cover a replacement that changes the size #VSTOR-130961 no-reply
2026-11-04 13:45 ` [PATCH hci-dev 5/6] tests/qemu-iotests/qom-set-drive: replace with a differently sized node #VSTOR-130961 Denis V. Lunev
2026-11-04 13:51 ` no-reply
2026-11-04 13:45 ` [PATCH hci-dev 6/6] tests/qtest/virtio-scsi: cover vz-x-blockdev-replace changing the size #VSTOR-130961 Denis V. Lunev
2026-11-04 13:53 ` no-reply
2026-11-04 14:00 ` [PATCH hci-dev 0/6] block, scsi-disk: honour a size change on child replacement #VSTOR-130961 Andrey Drobyshev
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=20261104134539.1519657-5-den@openvz.org \
--to=den@openvz.org \
--cc=andrey.drobyshev@virtuozzo.com \
--cc=svt-core@virtuozzo.com \
/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