From patchwork Tue Jun 12 23:51:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Rogers X-Patchwork-Id: 10461361 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CAE460329 for ; Tue, 12 Jun 2018 23:54:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B4F728AE0 for ; Tue, 12 Jun 2018 23:54:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E67628AED; Tue, 12 Jun 2018 23:54:52 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E8FA828AE0 for ; Tue, 12 Jun 2018 23:54:51 +0000 (UTC) Received: from localhost ([::1]:58916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSt7j-0003Ts-96 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Jun 2018 19:54:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSt4Y-0001jL-Mj for qemu-devel@nongnu.org; Tue, 12 Jun 2018 19:51:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSt4X-0006YD-Jf for qemu-devel@nongnu.org; Tue, 12 Jun 2018 19:51:34 -0400 Received: from inet-orm.provo.novell.com ([137.65.248.124]:34843 helo=mail.novell.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSt4R-0006Vf-7t; Tue, 12 Jun 2018 19:51:27 -0400 Received: from brogers1.provo.novell.com (brogers1.dnsdhcp.provo.novell.com [137.65.133.7]) by mail.novell.com with ESMTP (NOT encrypted); Tue, 12 Jun 2018 17:51:09 -0600 From: Bruce Rogers To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Jun 2018 17:51:03 -0600 Message-Id: <20180612235103.12633-3-brogers@suse.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612235103.12633-1-brogers@suse.com> References: <20180612235103.12633-1-brogers@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 137.65.248.124 Subject: [Qemu-devel] [PATCH 2/2] xen: add block resize support for xen disks 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: kwolf@redhat.com, sstabellini@kernel.org, armbru@redhat.com, Bruce Rogers , anthony.perard@citrix.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In the context of a monitor based disk resize, provide notification of the new size to the front end xen block driver via a xenstore update. Signed-off-by: Bruce Rogers --- block/block-backend.c | 7 +++++++ blockdev.c | 8 ++++++++ hw/block/xen_disk.c | 9 +++++++++ include/hw/xen/xen.h | 2 ++ include/sysemu/block-backend.h | 2 ++ stubs/xen-common.c | 4 ++++ 6 files changed, 32 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index db39dfe867..e1b0db8363 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2003,6 +2003,13 @@ int blk_truncate(BlockBackend *blk, int64_t offset, PreallocMode prealloc, return bdrv_truncate(blk->root, offset, prealloc, errp); } +void blk_legacy_resize_cb(BlockBackend *blk) +{ + if (blk->legacy_dev) { + xen_blk_resize_cb(blk->dev); + } +} + static void blk_pdiscard_entry(void *opaque) { BlkRwCo *rwco = opaque; diff --git a/blockdev.c b/blockdev.c index 4862323012..4dd34ad424 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3174,6 +3174,7 @@ void qmp_block_resize(bool has_device, const char *device, { Error *local_err = NULL; BlockBackend *blk = NULL; + BlockBackend *cb_blk = NULL; BlockDriverState *bs; AioContext *aio_context; int ret; @@ -3186,6 +3187,10 @@ void qmp_block_resize(bool has_device, const char *device, return; } + if (has_device) { + cb_blk = blk_by_name(device); + } + aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); @@ -3212,6 +3217,9 @@ void qmp_block_resize(bool has_device, const char *device, bdrv_drained_begin(bs); ret = blk_truncate(blk, size, PREALLOC_MODE_OFF, errp); + if (!ret && cb_blk) { + blk_legacy_resize_cb(cb_blk); + } bdrv_drained_end(bs); out: diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index fca0597d36..e69c7f590c 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -1013,6 +1013,15 @@ char *xen_blk_get_attached_dev_id(void *dev) return g_strdup_printf("xen-qdisk-%i", blkdev->xendev.dev); } +void xen_blk_resize_cb(void *dev) +{ + struct XenBlkDev *blkdev = dev; + blkdev->file_size = blk_getlength(blkdev->blk); + xenstore_write_be_int64(&blkdev->xendev, "sectors", + blkdev->file_size / blkdev->file_blk); + xen_be_set_state(&blkdev->xendev, blkdev->xendev.be_state); +} + struct XenDevOps xen_blkdev_ops = { .flags = DEVOPS_FLAG_NEED_GNTDEV, .size = sizeof(struct XenBlkDev), diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h index a201517675..d923ae53f1 100644 --- a/include/hw/xen/xen.h +++ b/include/hw/xen/xen.h @@ -50,4 +50,6 @@ void xen_register_framebuffer(struct MemoryRegion *mr); char *xen_blk_get_attached_dev_id(void *dev); +void xen_blk_resize_cb(void *dev); + #endif /* QEMU_HW_XEN_H */ diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 8d03d493c2..0ccaf5b035 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -236,4 +236,6 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, BlockBackend *blk_out, int64_t off_out, int bytes, BdrvRequestFlags flags); +void blk_legacy_resize_cb(BlockBackend *blk); + #endif diff --git a/stubs/xen-common.c b/stubs/xen-common.c index aeac0534ac..c2cbf81a87 100644 --- a/stubs/xen-common.c +++ b/stubs/xen-common.c @@ -17,3 +17,7 @@ char *xen_blk_get_attached_dev_id(void *dev) { return g_strdup(""); } + +void xen_blk_resize_cb(void *dev) +{ +}