From nobody Sun May 5 14:41:25 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1679429697; cv=none; d=zohomail.com; s=zohoarc; b=Hz86HnbvRnYtRv3xw+ROW1uvF8lUP6ZPEuOSYCgUw8hV5KjO9IrJF9Mwkvz3DYar+PfDrWhdsijkRZm7Z8ZSZLyrZyl3lcCqVxWwSb9Hg2aoPt9YZJ/f0xCWr0TBCVaLns6NedGIQKrfwz6W5uhrn+wzMJJPRqF2p9wOolVkPVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679429697; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=350kmENVs4y4oRc6fDqn78MOAWx6tQ9idjyBULPH48w=; b=R4M5fIjekuKLL2gS6/L12Hnu9/eQHuPKvI9jmZ7SMf6Sb278BpV7qCxVT4VqMqYnd1f5YCv5HaLdaTC8Eei/s4N5O3BpgGKtAj/qEs/W9x+PSw96q4zBeXRujdcgZRpIrlVhVpfDo7stLULCNDmqzyxColFKAbcHhD3snX7LXFg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1679429696851287.27212943392726; Tue, 21 Mar 2023 13:14:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1peiMu-0002Zq-FJ; Tue, 21 Mar 2023 16:14:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1peiMr-0002YO-LO; Tue, 21 Mar 2023 16:14:02 -0400 Received: from forwardcorp1c.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1peiMp-0000t0-Aq; Tue, 21 Mar 2023 16:14:01 -0400 Received: from mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net [IPv6:2a02:6b8:c14:5708:0:640:5704:0]) by forwardcorp1c.mail.yandex.net (Yandex) with ESMTP id AAC845EA80; Tue, 21 Mar 2023 23:13:47 +0300 (MSK) Received: from vsementsov-win.yandex-team.ru (unknown [2a02:6b8:b081:1224::1:29]) by mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id fDwl040OnOs0-BxPhDACI; Tue, 21 Mar 2023 23:13:46 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1679429626; bh=350kmENVs4y4oRc6fDqn78MOAWx6tQ9idjyBULPH48w=; h=Message-Id:Date:Cc:Subject:To:From; b=IXL9j6Yy+wfaAE9ClMHm2wppqRl7ag64Pzv6SPlKoIi1JoqVIXiKnNsD2Vl41imTs rqqffxDu1JO10leTQlqwj5cxpE9a0J9SEGYksnYKlDkFHnbpj+fRoZgCf+8xsk2KGa lUAWvPMImxJIusFZ2fCE0CkECBGs//UMFX4ea0Hg= Authentication-Results: mail-nwsmtp-smtp-corp-canary-81.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mst@redhat.com, hreitz@redhat.com, kwolf@redhat.com, Coiby.Xu@gmail.com, yc-core@yandex-team.ru, Vladimir Sementsov-Ogievskiy Subject: [PATCH] vhost-user-blk-server: notify client about disk resize Date: Tue, 21 Mar 2023 23:13:23 +0300 Message-Id: <20230321201323.3695923-1-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=178.154.239.200; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1c.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1679429699283100003 Content-Type: text/plain; charset="utf-8" Currently block_resize qmp command is simply ignored by vhost-user-blk export. So, the block-node is successfully resized, but virtio config is unchanged and guest doesn't see that disk is resized. Let's handle the resize by modifying the config and notifying the guest appropriately. After this comment, lsblk in linux guest with attached vhost-user-blk-pci device shows new size immediately after block_resize QMP command on vhost-user exported block node. Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! Seems, we have everything except this tiny patch to support live disk resize for vhost-user export. How I test: ./build/storage-daemon/qemu-storage-daemon --blockdev file,filename=3Da,nod= e-name=3Df1 --export vhost-user-blk,node-name=3Df1,addr.type=3Dunix,addr.pa= th=3D/tmp/sock,writable=3Don,id=3Dgg --chardev socket,path=3Dqmp.sock,serve= r=3Don,wait=3Doff,id=3Dchar1 --monitor chardev=3Dchar1 In another terminal, connect to qmp interface by nc -U qmp.sock Launch QEMU: ./build/qemu-system-x86_64 -M q35,accel=3Dkvm,memory-backend=3Dmem -object = memory-backend-file,share=3Don,id=3Dmem,size=3D1G,mem-path=3D/dev/shm/qemu-= ram -drive file=3D/home/vsementsov/work/vms/ub -chardev socket,path=3D/tmp/= sock,id=3Dchar0 -device vhost-user-blk-pci,chardev=3Dchar0 Then, run in the guest lsblk command to check current size of vhost-user driven disk. Then in nc terminal: {'execute': 'qmp_capabilities'} {'execute': 'block_resize', 'arguments': {'node-name': 'f1', 'size': 628531= 200}} Then, check in the guest that lsblk shows new size. subprojects/libvhost-user/libvhost-user.h | 2 ++ block/export/vhost-user-blk-server.c | 24 +++++++++++++++++++++++ subprojects/libvhost-user/libvhost-user.c | 10 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index 8c5a2719e3..49208cceaa 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -585,6 +585,8 @@ bool vu_queue_empty(VuDev *dev, VuVirtq *vq); */ void vu_queue_notify(VuDev *dev, VuVirtq *vq); =20 +void vu_config_change_msg(VuDev *dev); + /** * vu_queue_notify_sync: * @dev: a VuDev context diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user= -blk-server.c index 3409d9e02e..e56b92f2e2 100644 --- a/block/export/vhost-user-blk-server.c +++ b/block/export/vhost-user-blk-server.c @@ -10,6 +10,7 @@ * later. See the COPYING file in the top-level directory. */ #include "qemu/osdep.h" +#include "qemu/error-report.h" #include "block/block.h" #include "subprojects/libvhost-user/libvhost-user.h" /* only for the type = definitions */ #include "standard-headers/linux/virtio_blk.h" @@ -251,6 +252,27 @@ static void vu_blk_exp_request_shutdown(BlockExport *e= xp) vhost_user_server_stop(&vexp->vu_server); } =20 +static void vu_blk_exp_resize(void *opaque) +{ + VuBlkExport *vexp =3D opaque; + BlockDriverState *bs =3D blk_bs(vexp->handler.blk); + int64_t new_size =3D bdrv_getlength(bs); + + if (new_size < 0) { + error_printf("Failed to get length of block node '%s'", + bdrv_get_node_name(bs)); + return; + } + + vexp->blkcfg.capacity =3D cpu_to_le64(new_size >> VIRTIO_BLK_SECTOR_BI= TS); + + vu_config_change_msg(&vexp->vu_server.vu_dev); +} + +static const BlockDevOps vu_blk_dev_ops =3D { + .resize_cb =3D vu_blk_exp_resize, +}; + static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts, Error **errp) { @@ -292,6 +314,8 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExp= ortOptions *opts, blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detac= h, vexp); =20 + blk_set_dev_ops(exp->blk, &vu_blk_dev_ops, vexp); + if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx, num_queues, &vu_blk_iface, errp)) { blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 0200b78e8e..0abd898a52 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -2455,6 +2455,16 @@ void vu_queue_notify_sync(VuDev *dev, VuVirtq *vq) _vu_queue_notify(dev, vq, true); } =20 +void vu_config_change_msg(VuDev *dev) +{ + VhostUserMsg vmsg =3D { + .request =3D VHOST_USER_BACKEND_CONFIG_CHANGE_MSG, + .flags =3D VHOST_USER_VERSION, + }; + + vu_message_write(dev, dev->slave_fd, &vmsg); +} + static inline void vring_used_flags_set_bit(VuVirtq *vq, int mask) { --=20 2.34.1