Skip to contentSkip to conversation

xen: add block resize infrastructure

PATCH In review Bruce Rogers 2 participants 5 messages Jun 12, 2018 – Jun 13, 2018 Block layer

lore
Share & tools
lore
#0 lore raw

cover xen: add block resize infrastructure

Resizing a disk on the fly is useful, including for Xen guests. Xen has this capability, except in the case of qdisks (Xen QEMU disks). This patch series intends to provide this capability. With these patches, the xl command "qemu-monitor-command" can be used in conjunction with the "info block" and "block_resize" commands to help identify and then resize a Xen qdisk. It is anticipated that Xen's libxl will be extended to handle qdisk resizing without resorting to using the human monitor in this way, with libvirt support eventually building on top of that.

Bruce Rogers (2):
xen: add xen disk naming for use in monitor
xen: add block resize support for xen disks

 block/block-backend.c          | 12 +++++++++++-
 blockdev.c                     |  8 ++++++++
 hw/block/xen_disk.c            | 24 ++++++++++++++++++++++++
 include/hw/xen/xen.h           |  4 ++++
 include/sysemu/block-backend.h |  2 ++
 stubs/xen-common.c             |  9 +++++++++
 6 files changed, 58 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 xen: add xen disk naming for use in monitor

Provide monitor naming of xen disks, including associating an attached dev_id for a BlockBackend which has legacy_dev set. Currently, only xen disks have legacy_dev set to true.

---
 block/block-backend.c |  5 ++++-
 hw/block/xen_disk.c   | 15 +++++++++++++++
 include/hw/xen/xen.h  |  2 ++
 stubs/xen-common.c    |  5 +++++
 4 files changed, 26 insertions(+), 1 deletion(-)
block/block-backend.c +4 -1
index d55c328736..db39dfe867 100644
@@ -23,6 +23,7 @@
 #include "qemu/option.h"
 #include "trace.h"
 #include "migration/misc.h"
+#include "hw/xen/xen.h"
 
 /* Number of coroutines to reserve per attached device model */
 #define COROUTINE_POOL_RESERVATION 64
@@ -895,7 +896,9 @@ char *blk_get_attached_dev_id(BlockBackend *blk)
 {
     DeviceState *dev;
 
-    assert(!blk->legacy_dev);
+    if (blk->legacy_dev) {
+        return xen_blk_get_attached_dev_id(blk->dev);
+    }
     dev = blk->dev;
 
     if (!dev) {
hw/block/xen_disk.c +15 -0
index 9fbc0cdb87..fca0597d36 100644
@@ -745,6 +745,7 @@ static int blk_connect(struct XenDevice *xendev)
     int order, ring_ref;
     unsigned int ring_size, max_grants;
     unsigned int i;
+    Error *errp = NULL;
 
     trace_xen_disk_connect(xendev->name);
 
@@ -801,6 +802,13 @@ static int blk_connect(struct XenDevice *xendev)
         blk_ref(blkdev->blk);
     }
     blk_attach_dev_legacy(blkdev->blk, blkdev);
+    if (!monitor_add_blk(blkdev->blk, g_strdup(blkdev->dev), &errp)) {
+        xen_pv_printf(&blkdev->xendev, 0, "error: %s\n",
+                      error_get_pretty(errp));
+        error_free(errp);
+        return -1;
+    }
+
     blkdev->file_size = blk_getlength(blkdev->blk);
     if (blkdev->file_size < 0) {
         BlockDriverState *bs = blk_bs(blkdev->blk);
@@ -951,6 +959,7 @@ static void blk_disconnect(struct XenDevice *xendev)
     if (blkdev->blk) {
         blk_set_aio_context(blkdev->blk, qemu_get_aio_context());
         blk_detach_dev(blkdev->blk, blkdev);
+        monitor_remove_blk(blkdev->blk);
         blk_unref(blkdev->blk);
         blkdev->blk = NULL;
     }
@@ -998,6 +1007,12 @@ static void blk_event(struct XenDevice *xendev)
     qemu_bh_schedule(blkdev->bh);
 }
 
+char *xen_blk_get_attached_dev_id(void *dev)
+{
+    struct XenBlkDev *blkdev = dev;
+    return g_strdup_printf("xen-qdisk-%i", blkdev->xendev.dev);
+}
+
 struct XenDevOps xen_blkdev_ops = {
     .flags      = DEVOPS_FLAG_NEED_GNTDEV,
     .size       = sizeof(struct XenBlkDev),
include/hw/xen/xen.h +2 -0
index 7efcdaa8fe..a201517675 100644
@@ -48,4 +48,6 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length);
 
 void xen_register_framebuffer(struct MemoryRegion *mr);
 
+char *xen_blk_get_attached_dev_id(void *dev);
+
 #endif /* QEMU_HW_XEN_H */
stubs/xen-common.c +5 -0
index 09fce2dd36..aeac0534ac 100644
@@ -12,3 +12,8 @@
 void xenstore_store_pv_console_info(int i, Chardev *chr)
 {
 }
+
+char *xen_blk_get_attached_dev_id(void *dev)
+{
+    return g_strdup("");
+}
Signature · 1 line
2.17.1
#4 lore raw

PATCH 2/2 xen: add block resize support for xen disks

In reply to Bruce Rogers

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.

---
 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(+)
block/block-backend.c +7 -0
index db39dfe867..e1b0db8363 100644
@@ -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;
blockdev.c +8 -0
index 4862323012..4dd34ad424 100644
@@ -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:
hw/block/xen_disk.c +9 -0
index fca0597d36..e69c7f590c 100644
@@ -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),
include/hw/xen/xen.h +2 -0
index a201517675..d923ae53f1 100644
@@ -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 */
include/sysemu/block-backend.h +2 -0
index 8d03d493c2..0ccaf5b035 100644
@@ -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
stubs/xen-common.c +4 -0
index aeac0534ac..c2cbf81a87 100644
@@ -17,3 +17,7 @@ char *xen_blk_get_attached_dev_id(void *dev)
 {
     return g_strdup("");
 }
+
+void xen_blk_resize_cb(void *dev)
+{
+}
Signature · 1 line
2.17.1
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] xen: add xen disk naming for use in monitor

In reply to Bruce Rogers
Quoted 25 lines · Bruce Rogers

Provide monitor naming of xen disks, including associating an attached dev_id for a BlockBackend which has legacy_dev set. Currently, only xen disks have legacy_dev set to true.

---
 block/block-backend.c |  5 ++++-
 hw/block/xen_disk.c   | 15 +++++++++++++++
 include/hw/xen/xen.h  |  2 ++
 stubs/xen-common.c    |  5 +++++
 4 files changed, 26 insertions(+), 1 deletion(-)
block/block-backend.c +1 -0
index d55c328736..db39dfe867 100644
@@ -23,6 +23,7 @@
 #include "qemu/option.h"
 #include "trace.h"
 #include "migration/misc.h"
+#include "hw/xen/xen.h"
 
 /* Number of coroutines to reserve per attached device model */
 #define COROUTINE_POOL_RESERVATION 64

block/block-backend.c char *blk_get_attached_dev_id(BlockBackend *blk) · line 904

Quoted 10 lines
block/block-backend.c +3 -1
@@ -895,7 +896,9 @@ char *blk_get_attached_dev_id(BlockBackend *blk)
 {
     DeviceState *dev;
 
-    assert(!blk->legacy_dev);
+    if (blk->legacy_dev) {
+        return xen_blk_get_attached_dev_id(blk->dev);
+    }
     dev = blk->dev;
 
     if (!dev) {

Hi Bruce,

Thanks for your patches!

But I don't think that the right way to go. We probably needs to qdevifie xen_disk instead. This is point out by the numerous TODO about "qdevified", and this very old mail:
https://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg07902.html

Thanks,

Signature · 1 line
Anthony PERARD
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] xen: add xen disk naming for use in monitor

Quoted 40 lines
Quoted 1 line
Quoted 1 line · Anthony PERARD
Quoted 29 lines · Bruce Rogers

Provide monitor naming of xen disks, including associating an attached dev_id for a BlockBackend which has legacy_dev set. Currently, only xen disks have legacy_dev set to true.

Signed‑off‑by: Bruce Rogers <[email protected]>
‑‑‑
block/block‑backend.c | 5 ++++‑

 hw/block/xen_disk.c   | 15 +++++++++++++++
 include/hw/xen/xen.h  |  2 ++
 stubs/xen‑common.c    |  5 +++++
 4 files changed, 26 insertions(+), 1 deletion(‑)

diff ‑‑git a/block/block‑backend.c b/block/block‑backend.c index d55c328736..db39dfe867 100644
‑‑‑ a/block/block‑backend.c
+++ b/block/block‑backend.c
@@ ‑23,6 +23,7 @@
#include "qemu/option.h"
#include "trace.h"
#include "migration/misc.h"
+#include "hw/xen/xen.h"

/* Number of coroutines to reserve per attached device model */ #define COROUTINE_POOL_RESERVATION 64
@@ ‑895,7 +896,9 @@ char *blk_get_attached_dev_id(BlockBackend *blk)

 {
     DeviceState *dev;

‑ assert(!blk‑>legacy_dev);

block/block-backend.c char *blk_get_attached_dev_id(BlockBackend *blk) · line 904

Quoted 6 lines
block/block-backend.c +3 -0
+    if (blk‑>legacy_dev) {
+        return xen_blk_get_attached_dev_id(blk‑>dev);
+    }
     dev = blk‑>dev;
 
     if (!dev) {

Hi Bruce,

Quoted 6 lines

Thanks for your patches!

But I don't think that the right way to go. We probably needs to qdevifie xen_disk instead. This is point out by the numerous TODO about "qdevified", and this very old mail:
https://lists.nongnu.org/archive/html/qemu‑devel/2016‑09/msg07902.html

Understood. These patches come from an effort to provide this functionality to older qemu releases that SUSE supports. I didn't try to work on a qdevify type solution, as I figured if the block experts hadn't done that yet, I would probably not be too successful myself.

Quoted 1 line

From what I can see, the xen support in qemu is not well integrated in general,

so my patches here are implemented in that "spirit" - not elegant, but getting the job done. I'd certainly rather see good integration of the xen model into qemu, and if that is the right way forward to get this type of functionality, I'd be happy with that approach as well.

Bruce