aboutsummaryrefslogtreecommitdiff
path: root/hw/block/xen-block.c
diff options
context:
space:
mode:
authorPaul Durrant <paul.durrant@citrix.com>2019-01-31 15:33:16 +0000
committerAnthony PERARD <anthony.perard@citrix.com>2019-02-04 11:04:49 +0000
commit3149f183d7ca448b1dc30fe3d4acb9e367de01bf (patch)
treec4e73f03d718d1f3fdaa97a67fa1f7aa7f201019 /hw/block/xen-block.c
parent67bc8e00f7c44b7ac35ee75e1716ad18baa77126 (diff)
xen-block: handle resize callback
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 <paul.durrant@citrix.com> Reviewed-by: Anthony PERARD <anthony.perard@citrix.com> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Diffstat (limited to 'hw/block/xen-block.c')
-rw-r--r--hw/block/xen-block.c40
1 files changed, 36 insertions, 4 deletions
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);