All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: andrey.drobyshev@virtuozzo.com
Cc: svt-core@virtuozzo.com, den@openvz.org
Subject: [PATCH hci-8.1] vhost-blk: pass full 20-byte serial to the guest
Date: Wed, 18 Nov 2026 18:08:45 +0300	[thread overview]
Message-ID: <20261118150845.216920-1-andrey.zhadchenko@virtuozzo.com> (raw)

vhost_blk_start() copies the serial with strncpy(..., VIRTIO_BLK_ID_BYTES - 1),
so a 20-character serial is truncated to 19 bytes before it is handed to
the kernel via VHOST_BLK_SET_SERIAL. The kernel already replies to
VIRTIO_BLK_T_GET_ID with min(strnlen + 1, 20) bytes, i.e. the same
convention as virtio-blk: NUL-terminated only when shorter than the
buffer.

Copy the whole serial zero-padded with strpadcpy() so the guest sees the
same ID as with virtio-blk. Print conf.serial in the error message, as the
buffer is no longer guaranteed to be NUL-terminated.

Found by hci-kubetest, which compares all 20 bytes of the serial.

https://virtuozzo.atlassian.net/browse/VSTOR-155058
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
---
 hw/block/vhost-blk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
index 4cebc91d33e..d8bbfcaff86 100644
--- a/hw/block/vhost-blk.c
+++ b/hw/block/vhost-blk.c
@@ -63,9 +63,10 @@ static int vhost_blk_start(VirtIODevice *vdev)
     }
 
     if (s->conf.serial) {
-        strncpy(serial, s->conf.serial, VIRTIO_BLK_ID_BYTES - 1);
+        strpadcpy(serial, sizeof(serial), s->conf.serial, '\0');
         if (ioctl(s->vhostfd, VHOST_BLK_SET_SERIAL, serial)) {
-            error_report("vhost-blk: unable to set drive serial %s", serial);
+            error_report("vhost-blk: unable to set drive serial %s",
+                         s->conf.serial);
             return -EINVAL;
         }
     }
-- 
2.43.5


             reply	other threads:[~2026-11-18 15:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 15:08 Andrey Zhadchenko [this message]
2026-11-18 15:23 ` 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=20261118150845.216920-1-andrey.zhadchenko@virtuozzo.com \
    --to=andrey.zhadchenko@virtuozzo.com \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=den@openvz.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.