From patchwork Mon Feb 4 11:28:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 10795461 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E168922 for ; Mon, 4 Feb 2019 11:41:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DCB72AEF0 for ; Mon, 4 Feb 2019 11:41:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 723002B11E; Mon, 4 Feb 2019 11:41:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0858E2AF06 for ; Mon, 4 Feb 2019 11:41:02 +0000 (UTC) Received: from localhost ([127.0.0.1]:41099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqccY-0005f8-8q for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Feb 2019 06:41:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcQh-0006Au-Jt for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqcQf-0007MM-Vk for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:47 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:14928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqcQb-00076s-Ve for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:45 -0500 X-IronPort-AV: E=Sophos;i="5.56,560,1539648000"; d="scan'208";a="77210717" From: Anthony PERARD To: Date: Mon, 4 Feb 2019 11:28:00 +0000 Message-ID: <20190204112803.11645-2-anthony.perard@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204112803.11645-1-anthony.perard@citrix.com> References: <20190204112803.11645-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 1/4] configure: xen: Stop build-testing for xc_domain_create 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: Anthony PERARD , xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Its last uses was removed by: 6d7c06c213ddcfabcafdc178ccef81736f85a7c2 "Remove broken Xen PV domain builder". Signed-off-by: Anthony PERARD Reviewed-by: Paul Durrant --- configure | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/configure b/configure index f8176b3c40..ca1986125d 100755 --- a/configure +++ b/configure @@ -2474,7 +2474,6 @@ int main(void) { xenforeignmemory_handle *xfmem; xenevtchn_handle *xe; xengnttab_handle *xg; - xen_domain_handle_t handle; xengnttab_grant_copy_segment_t* seg = NULL; xs_daemon_open(); @@ -2484,7 +2483,6 @@ int main(void) { xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); - xc_domain_create(xc, 0, handle, 0, NULL, NULL); xfmem = xenforeignmemory_open(0, 0); xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); @@ -2526,7 +2524,6 @@ int main(void) { xenforeignmemory_handle *xfmem; xenevtchn_handle *xe; xengnttab_handle *xg; - xen_domain_handle_t handle; xs_daemon_open(); @@ -2535,7 +2532,6 @@ int main(void) { xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); xc_hvm_create_ioreq_server(xc, 0, HVM_IOREQSRV_BUFIOREQ_ATOMIC, NULL); - xc_domain_create(xc, 0, handle, 0, NULL, NULL); xfmem = xenforeignmemory_open(0, 0); xenforeignmemory_map(xfmem, 0, 0, 0, 0, 0); @@ -2553,21 +2549,6 @@ EOF then xen_ctrl_version=40701 xen=yes - elif - cat > $TMPC < -#include -int main(void) { - xc_interface *xc = NULL; - xen_domain_handle_t handle; - xc_domain_create(xc, 0, handle, 0, NULL, NULL); - return 0; -} -EOF - compile_prog "" "$xen_libs" - then - xen_ctrl_version=40700 - xen=yes # Xen 4.6 elif From patchwork Mon Feb 4 11:28:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 10795447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9ABD2746 for ; Mon, 4 Feb 2019 11:35:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8877C2AB5A for ; Mon, 4 Feb 2019 11:35:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D0872AF11; Mon, 4 Feb 2019 11:35:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1A43F2AB5A for ; Mon, 4 Feb 2019 11:35:48 +0000 (UTC) Received: from localhost ([127.0.0.1]:41035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcXT-0002qX-Cr for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Feb 2019 06:35:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcQQ-0005yZ-DV for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqcQO-00078o-Kk for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:30 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:14928) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqcQO-00076s-7j for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:28 -0500 X-IronPort-AV: E=Sophos;i="5.56,560,1539648000"; d="scan'208";a="77210713" From: Anthony PERARD To: Date: Mon, 4 Feb 2019 11:28:01 +0000 Message-ID: <20190204112803.11645-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204112803.11645-1-anthony.perard@citrix.com> References: <20190204112803.11645-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 2/4] configure: Don't add Xen's libs to LDFLAGS 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: Anthony PERARD , xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When Xen is detected via pkg-config, it isn't necessary to modify LDFLAGS as modifying libs_softmmu is enough. Reported-by: Peter Maydell Signed-off-by: Michael Tokarev Signed-off-by: Anthony PERARD Reviewed-by: Peter Maydell Reviewed-by: Michael Tokarev Reviewed-by: Philippe Mathieu-Daudé --- configure | 1 - 1 file changed, 1 deletion(-) diff --git a/configure b/configure index ca1986125d..3d89870d99 100755 --- a/configure +++ b/configure @@ -2359,7 +2359,6 @@ if test "$xen" != "no" ; then fi QEMU_CFLAGS="$QEMU_CFLAGS $($pkg_config --cflags $xen_pc)" libs_softmmu="$($pkg_config --libs $xen_pc) $libs_softmmu" - LDFLAGS="$($pkg_config --libs $xen_pc) $LDFLAGS" else xen_libs="-lxenstore -lxenctrl -lxenguest" From patchwork Mon Feb 4 11:28:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 10795463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5BBB922 for ; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 948942B092 for ; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 878792B117; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 200F02B092 for ; Mon, 4 Feb 2019 11:42:03 +0000 (UTC) Received: from localhost ([127.0.0.1]:41107 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcdW-0006Ju-BE for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Feb 2019 06:42:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcQh-0006Ax-KL for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqcQf-0007MS-VV for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:47 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:14941) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqcQb-00078u-UB for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:45 -0500 X-IronPort-AV: E=Sophos;i="5.56,560,1539648000"; d="scan'208";a="77210718" From: Anthony PERARD To: Date: Mon, 4 Feb 2019 11:28:02 +0000 Message-ID: <20190204112803.11645-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204112803.11645-1-anthony.perard@citrix.com> References: <20190204112803.11645-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 3/4] xen: fix xen-bus state model to allow frontend re-connection 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: Anthony PERARD , xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Durrant There is a flaw in the xen-bus state model. To allow a frontend to re- connect the backend state of an online XenDevice is transitioned from Closed to InitWait, but this is currently done unilaterally which is incorrect. The backend state should remain Closed until the frontend state transitions to Initialising. This patch removes the automatic backend state transition from xen_device_backend_state_changed() and, instead, adds an extra check in xen_device_frontend_state_changed() to determine whether a frontend is trying to re-connect to a previously Closed XenDevice. Only if this is found to be the case is the backend state transitioned from Closed to InitWait. Note that this transition will be common amongst all XenDevice classes and hence xen_device_frontend_state_changed() returns immediately afterwards without calling into the XenDeviceClass frontend_changed() method. Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Signed-off-by: Anthony PERARD --- hw/xen/xen-bus.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index 3aeccec69c..49a725e8c7 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -547,20 +547,15 @@ static void xen_device_backend_changed(void *opaque) } /* - * If a backend is still 'online' then its state should be cycled - * back round to InitWait in order for a new frontend instance to - * connect. This may happen when, for example, a frontend driver is - * re-installed or updated. - * If a backend is not 'online' then the device should be destroyed. + * If a backend is still 'online' then we should leave it alone but, + * if a backend is not 'online', then the device should be destroyed + * once the state is Closed. */ - if (xendev->backend_online && - xendev->backend_state == XenbusStateClosed) { - xen_device_backend_set_state(xendev, XenbusStateInitWait); - } else if (!xendev->backend_online && - (xendev->backend_state == XenbusStateClosed || - xendev->backend_state == XenbusStateInitialising || - xendev->backend_state == XenbusStateInitWait || - xendev->backend_state == XenbusStateUnknown)) { + if (!xendev->backend_online && + (xendev->backend_state == XenbusStateClosed || + xendev->backend_state == XenbusStateInitialising || + xendev->backend_state == XenbusStateInitWait || + xendev->backend_state == XenbusStateUnknown)) { Error *local_err = NULL; if (!xen_backend_try_device_destroy(xendev, &local_err)) { @@ -715,6 +710,17 @@ static void xen_device_frontend_changed(void *opaque) xen_device_frontend_set_state(xendev, state); + if (state == XenbusStateInitialising && + xendev->backend_state == XenbusStateClosed && + xendev->backend_online) { + /* + * The frontend is re-initializing so switch back to + * InitWait. + */ + xen_device_backend_set_state(xendev, XenbusStateInitWait); + return; + } + if (xendev_class->frontend_changed) { Error *local_err = NULL; From patchwork Mon Feb 4 11:28:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 10795459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FC05746 for ; Mon, 4 Feb 2019 11:39:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 397C42AEE9 for ; Mon, 4 Feb 2019 11:39:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D2AD2AEE8; Mon, 4 Feb 2019 11:39:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A62A92AEE8 for ; Mon, 4 Feb 2019 11:39:56 +0000 (UTC) Received: from localhost ([127.0.0.1]:41061 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcbU-0004wK-2r for patchwork-qemu-devel@patchwork.kernel.org; Mon, 04 Feb 2019 06:39:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52202) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqcQb-00066v-Pa for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqcQY-0007IW-3S for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:39 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:14941) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqcQW-00078u-4i for qemu-devel@nongnu.org; Mon, 04 Feb 2019 06:28:38 -0500 X-IronPort-AV: E=Sophos;i="5.56,560,1539648000"; d="scan'208";a="77210714" From: Anthony PERARD To: Date: Mon, 4 Feb 2019 11:28:03 +0000 Message-ID: <20190204112803.11645-5-anthony.perard@citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204112803.11645-1-anthony.perard@citrix.com> References: <20190204112803.11645-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 4/4] 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: Anthony PERARD , xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paul Durrant 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 Reviewed-by: Anthony PERARD Signed-off-by: Anthony PERARD --- 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 *request) request->req.seg[i].first_sect + 1) * dataplane->file_blk; request->size += 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 = xendev; dataplane->file_blk = conf->logical_block_size; dataplane->blk = conf->blk; - dataplane->file_size = blk_getlength(dataplane->blk); 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, uint32_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..5012af9cb6 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -144,6 +144,38 @@ static void xen_block_unrealize(XenDevice *xendev, Error **errp) } } +static void xen_block_set_size(XenBlockDevice *blockdev) +{ + const char *type = object_get_typename(OBJECT(blockdev)); + XenBlockVdev *vdev = &blockdev->props.vdev; + BlockConf *conf = &blockdev->props.conf; + int64_t sectors = blk_getlength(conf->blk) / conf->logical_block_size; + XenDevice *xendev = 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 = opaque; + XenDevice *xendev = XEN_DEVICE(blockdev); + enum xenbus_state state = xen_device_backend_get_state(xendev); + + 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_printf(xendev, "state", "%u", state); +} + +static const BlockDevOps xen_block_dev_ops = { + .resize_cb = xen_block_resize_cb, +}; + static void xen_block_realize(XenDevice *xendev, Error **errp) { XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev); @@ -180,7 +212,7 @@ static void xen_block_realize(XenDevice *xendev, Error **errp) } if (!blkconf_apply_backend_options(conf, blockdev->info & VDISK_READONLY, - false, errp)) { + true, errp)) { return; } @@ -197,6 +229,7 @@ static void xen_block_realize(XenDevice *xendev, Error **errp) return; } + blk_set_dev_ops(conf->blk, &xen_block_dev_ops, blockdev); blk_set_guest_block_size(conf->blk, conf->logical_block_size); if (conf->discard_granularity > 0) { @@ -215,9 +248,8 @@ static void xen_block_realize(XenDevice *xendev, Error **errp) 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); blockdev->dataplane = xen_block_dataplane_create(xendev, conf, blockdev->props.iothread);