From nobody Tue May 7 07:52:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548865309980716.492554798479; Wed, 30 Jan 2019 08:21:49 -0800 (PST) Received: from localhost ([127.0.0.1]:40537 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goscV-0000jQ-OF for importer@patchew.org; Wed, 30 Jan 2019 11:21:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51751) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gosbV-0000NL-LG for qemu-devel@nongnu.org; Wed, 30 Jan 2019 11:20:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gosbU-0000R4-DG for qemu-devel@nongnu.org; Wed, 30 Jan 2019 11:20:45 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:37939) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gosbC-00008w-0a; Wed, 30 Jan 2019 11:20:26 -0500 X-IronPort-AV: E=Sophos;i="5.56,541,1539648000"; d="scan'208";a="76846046" From: Paul Durrant To: , , Date: Wed, 30 Jan 2019 16:19:48 +0000 Message-ID: <20190130161948.15888-1-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb6 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PATCH v2] xen-block: handle resize callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Stefano Stabellini , Max Reitz , Paul Durrant , Stefan Hajnoczi , Anthony Perard Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Some frontend drivers will handle dynamic resizing of PV disks, so set up the BlockDevOps resize_cb() method during xen_block_realize() to allow this to be done. Signed-off-by: Paul Durrant --- Cc: Stefan Hajnoczi Cc: Stefano Stabellini Cc: Anthony Perard Cc: Kevin Wolf Cc: Max Reitz v2: - re-write backend state after updating sectors --- hw/block/dataplane/xen-block.c | 4 +--- hw/block/trace-events | 1 + hw/block/xen-block.c | 40 ++++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index d0d8905a33..c6a15da024 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -50,7 +50,6 @@ struct XenBlockDataPlane { unsigned int nr_ring_ref; void *sring; int64_t file_blk; - int64_t file_size; int protocol; blkif_back_rings_t rings; int more_work; @@ -189,7 +188,7 @@ static int xen_block_parse_request(XenBlockRequest *req= uest) request->req.seg[i].first_sect + 1) * dataplane->file_blk; request->size +=3D len; } - if (request->start + request->size > dataplane->file_size) { + if (request->start + request->size > blk_getlength(dataplane->blk)) { error_report("error: access beyond end of file"); goto err; } @@ -638,7 +637,6 @@ XenBlockDataPlane *xen_block_dataplane_create(XenDevice= *xendev, dataplane->xendev =3D xendev; dataplane->file_blk =3D conf->logical_block_size; dataplane->blk =3D conf->blk; - dataplane->file_size =3D blk_getlength(dataplane->blk); =20 QLIST_INIT(&dataplane->inflight); QLIST_INIT(&dataplane->freelist); diff --git a/hw/block/trace-events b/hw/block/trace-events index d0851953c5..8020f9226a 100644 --- a/hw/block/trace-events +++ b/hw/block/trace-events @@ -126,6 +126,7 @@ xen_block_realize(const char *type, uint32_t disk, uint= 32_t partition) "%s d%up% xen_block_connect(const char *type, uint32_t disk, uint32_t partition) "%s= d%up%u" xen_block_disconnect(const char *type, uint32_t disk, uint32_t partition) = "%s d%up%u" xen_block_unrealize(const char *type, uint32_t disk, uint32_t partition) "= %s d%up%u" +xen_block_size(const char *type, uint32_t disk, uint32_t partition, int64_= t sectors) "%s d%up%u %"PRIi64 xen_disk_realize(void) "" xen_disk_unrealize(void) "" xen_cdrom_realize(void) "" diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index a636487b3e..0f0799e861 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -144,6 +144,38 @@ static void xen_block_unrealize(XenDevice *xendev, Err= or **errp) } } =20 +static void xen_block_set_size(XenBlockDevice *blockdev) +{ + const char *type =3D object_get_typename(OBJECT(blockdev)); + XenBlockVdev *vdev =3D &blockdev->props.vdev; + BlockConf *conf =3D &blockdev->props.conf; + int64_t sectors =3D blk_getlength(conf->blk) / conf->logical_block_siz= e; + XenDevice *xendev =3D XEN_DEVICE(blockdev); + + trace_xen_block_size(type, vdev->disk, vdev->partition, sectors); + + xen_device_backend_printf(xendev, "sectors", "%"PRIi64, sectors); +} + +static void xen_block_resize_cb(void *opaque) +{ + XenBlockDevice *blockdev =3D opaque; + XenDevice *xendev =3D XEN_DEVICE(blockdev); + enum xenbus_state backend_state =3D xen_device_backend_get_state(xende= v); + + xen_block_set_size(blockdev); + + /* + * Mimic the behaviour of Linux xen-blkback and re-write the state + * to trigger the frontend watch. + */ + xen_device_backend_set_state(xendev, backend_state); +} + +static const BlockDevOps xen_block_dev_ops =3D { + .resize_cb =3D xen_block_resize_cb, +}; + static void xen_block_realize(XenDevice *xendev, Error **errp) { XenBlockDevice *blockdev =3D XEN_BLOCK_DEVICE(xendev); @@ -180,7 +212,7 @@ static void xen_block_realize(XenDevice *xendev, Error = **errp) } =20 if (!blkconf_apply_backend_options(conf, blockdev->info & VDISK_READON= LY, - false, errp)) { + true, errp)) { return; } =20 @@ -197,6 +229,7 @@ static void xen_block_realize(XenDevice *xendev, Error = **errp) return; } =20 + blk_set_dev_ops(conf->blk, &xen_block_dev_ops, blockdev); blk_set_guest_block_size(conf->blk, conf->logical_block_size); =20 if (conf->discard_granularity > 0) { @@ -215,9 +248,8 @@ static void xen_block_realize(XenDevice *xendev, Error = **errp) =20 xen_device_backend_printf(xendev, "sector-size", "%u", conf->logical_block_size); - xen_device_backend_printf(xendev, "sectors", "%"PRIi64, - blk_getlength(conf->blk) / - conf->logical_block_size); + + xen_block_set_size(blockdev); =20 blockdev->dataplane =3D xen_block_dataplane_create(xendev, conf, blockdev->props.iothread); --=20 2.20.1.2.gb21ebb6