File 0073-xen-add-block-resize-support-for-xe.patch of Package qemu-linux-user.12241
From c73609d44c01dee03523e047b08de17b93e15d2f Mon Sep 17 00:00:00 2001
From: Bruce Rogers <brogers@suse.com>
Date: Mon, 11 Jun 2018 13:53:40 -0600
Subject: [PATCH] xen: add block resize support for xen disks
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.
[BR: FATE#325467, BSC#1094725]
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
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 5288b67914..a9073760fc 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1900,6 +1900,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 56a6b24a0b..67339b475a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -2918,6 +2918,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;
@@ -2930,6 +2931,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);
@@ -2956,6 +2961,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 67f8464f6a..3556ceb6a2 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -1400,6 +1400,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 = {
.size = sizeof(struct XenBlkDev),
.alloc = blk_alloc,
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 c4e52a5fa3..46f45c4dc3 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -229,4 +229,6 @@ void blk_io_limits_enable(BlockBackend *blk, const char *group);
void blk_io_limits_update_group(BlockBackend *blk, const char *group);
void blk_set_force_allow_inactivate(BlockBackend *blk);
+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)
+{
+}