* [Qemu-devel] [PATCH v2] xen-block: handle resize callback
@ 2019-01-30 16:19 Paul Durrant
2019-01-31 15:20 ` Anthony PERARD
0 siblings, 1 reply; 9+ messages in thread
From: Paul Durrant @ 2019-01-30 16:19 UTC (permalink / raw)
To: qemu-devel, qemu-block, xen-devel
Cc: Paul Durrant, Stefan Hajnoczi, Stefano Stabellini,
Anthony Perard, Kevin Wolf, Max Reitz
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>
---
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Max Reitz <mreitz@redhat.com>
v2:
- re-write backend state after updating sectors
---
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..0f0799e861 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 backend_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_set_state(xendev, backend_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);
--
2.20.1.2.gb21ebb6
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2] xen-block: handle resize callback
2019-01-30 16:19 [Qemu-devel] [PATCH v2] xen-block: handle resize callback Paul Durrant
@ 2019-01-31 15:20 ` Anthony PERARD
0 siblings, 0 replies; 9+ messages in thread
From: Anthony PERARD @ 2019-01-31 15:20 UTC (permalink / raw)
To: Paul Durrant
Cc: qemu-devel, qemu-block, xen-devel, Stefan Hajnoczi,
Stefano Stabellini, Kevin Wolf, Max Reitz
On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> 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>
> ---
> + /*
> + * Mimic the behaviour of Linux xen-blkback and re-write the state
> + * to trigger the frontend watch.
> + */
> + xen_device_backend_set_state(xendev, backend_state);
:(, that function doesn't write the state again if it hasn't changed.
So in my testing, Linux never did anything.
--
Anthony PERARD
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] xen-block: handle resize callback
@ 2019-01-31 15:20 ` Anthony PERARD
0 siblings, 0 replies; 9+ messages in thread
From: Anthony PERARD @ 2019-01-31 15:20 UTC (permalink / raw)
To: Paul Durrant
Cc: Kevin Wolf, Stefano Stabellini, qemu-block, qemu-devel,
Max Reitz, Stefan Hajnoczi, xen-devel
On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> 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>
> ---
> + /*
> + * Mimic the behaviour of Linux xen-blkback and re-write the state
> + * to trigger the frontend watch.
> + */
> + xen_device_backend_set_state(xendev, backend_state);
:(, that function doesn't write the state again if it hasn't changed.
So in my testing, Linux never did anything.
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2] xen-block: handle resize callback
2019-01-31 15:20 ` Anthony PERARD
(?)
(?)
@ 2019-01-31 15:22 ` Paul Durrant
2019-01-31 15:25 ` Anthony PERARD
-1 siblings, 1 reply; 9+ messages in thread
From: Paul Durrant @ 2019-01-31 15:22 UTC (permalink / raw)
To: Anthony Perard
Cc: qemu-devel, qemu-block, xen-devel, Stefan Hajnoczi,
Stefano Stabellini, Kevin Wolf, Max Reitz
> -----Original Message-----
> From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> Sent: 31 January 2019 15:21
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>; Stefano
> Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>; Max
> Reitz <mreitz@redhat.com>
> Subject: Re: [PATCH v2] xen-block: handle resize callback
>
> On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> > 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>
> > ---
>
>
> > + /*
> > + * Mimic the behaviour of Linux xen-blkback and re-write the state
> > + * to trigger the frontend watch.
> > + */
> > + xen_device_backend_set_state(xendev, backend_state);
>
> :(, that function doesn't write the state again if it hasn't changed.
> So in my testing, Linux never did anything.
Gah! I forgot about that. Alright, it's going to have to be a bit more crude.
Paul
>
> --
> Anthony PERARD
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] xen-block: handle resize callback
2019-01-31 15:20 ` Anthony PERARD
(?)
@ 2019-01-31 15:22 ` Paul Durrant
-1 siblings, 0 replies; 9+ messages in thread
From: Paul Durrant @ 2019-01-31 15:22 UTC (permalink / raw)
To: Anthony Perard
Cc: Kevin Wolf, Stefano Stabellini, qemu-block, qemu-devel,
Max Reitz, Stefan Hajnoczi, xen-devel
> -----Original Message-----
> From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> Sent: 31 January 2019 15:21
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>; Stefano
> Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>; Max
> Reitz <mreitz@redhat.com>
> Subject: Re: [PATCH v2] xen-block: handle resize callback
>
> On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> > 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>
> > ---
>
>
> > + /*
> > + * Mimic the behaviour of Linux xen-blkback and re-write the state
> > + * to trigger the frontend watch.
> > + */
> > + xen_device_backend_set_state(xendev, backend_state);
>
> :(, that function doesn't write the state again if it hasn't changed.
> So in my testing, Linux never did anything.
Gah! I forgot about that. Alright, it's going to have to be a bit more crude.
Paul
>
> --
> Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2] xen-block: handle resize callback
2019-01-31 15:22 ` [Qemu-devel] " Paul Durrant
@ 2019-01-31 15:25 ` Anthony PERARD
0 siblings, 0 replies; 9+ messages in thread
From: Anthony PERARD @ 2019-01-31 15:25 UTC (permalink / raw)
To: Paul Durrant
Cc: qemu-devel, qemu-block, xen-devel, Stefan Hajnoczi,
Stefano Stabellini, Kevin Wolf, Max Reitz
On Thu, Jan 31, 2019 at 03:22:18PM +0000, Paul Durrant wrote:
> > -----Original Message-----
> > From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> > Sent: 31 January 2019 15:21
> > To: Paul Durrant <Paul.Durrant@citrix.com>
> > Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> > devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>; Stefano
> > Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>; Max
> > Reitz <mreitz@redhat.com>
> > Subject: Re: [PATCH v2] xen-block: handle resize callback
> >
> > On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> > > 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>
> > > ---
> >
> >
> > > + /*
> > > + * Mimic the behaviour of Linux xen-blkback and re-write the state
> > > + * to trigger the frontend watch.
> > > + */
> > > + xen_device_backend_set_state(xendev, backend_state);
> >
> > :(, that function doesn't write the state again if it hasn't changed.
> > So in my testing, Linux never did anything.
>
> Gah! I forgot about that. Alright, it's going to have to be a bit more crude.
more crude > Yes, I tried to ignore the check in _set_state and end-up
with an infinit loop.
--
Anthony PERARD
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] xen-block: handle resize callback
@ 2019-01-31 15:25 ` Anthony PERARD
0 siblings, 0 replies; 9+ messages in thread
From: Anthony PERARD @ 2019-01-31 15:25 UTC (permalink / raw)
To: Paul Durrant
Cc: Kevin Wolf, Stefano Stabellini, qemu-block, qemu-devel,
Max Reitz, Stefan Hajnoczi, xen-devel
On Thu, Jan 31, 2019 at 03:22:18PM +0000, Paul Durrant wrote:
> > -----Original Message-----
> > From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> > Sent: 31 January 2019 15:21
> > To: Paul Durrant <Paul.Durrant@citrix.com>
> > Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> > devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>; Stefano
> > Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>; Max
> > Reitz <mreitz@redhat.com>
> > Subject: Re: [PATCH v2] xen-block: handle resize callback
> >
> > On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> > > 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>
> > > ---
> >
> >
> > > + /*
> > > + * Mimic the behaviour of Linux xen-blkback and re-write the state
> > > + * to trigger the frontend watch.
> > > + */
> > > + xen_device_backend_set_state(xendev, backend_state);
> >
> > :(, that function doesn't write the state again if it hasn't changed.
> > So in my testing, Linux never did anything.
>
> Gah! I forgot about that. Alright, it's going to have to be a bit more crude.
more crude > Yes, I tried to ignore the check in _set_state and end-up
with an infinit loop.
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2] xen-block: handle resize callback
2019-01-31 15:25 ` Anthony PERARD
(?)
@ 2019-01-31 15:26 ` Paul Durrant
-1 siblings, 0 replies; 9+ messages in thread
From: Paul Durrant @ 2019-01-31 15:26 UTC (permalink / raw)
To: Anthony Perard
Cc: qemu-devel, qemu-block, xen-devel, Stefan Hajnoczi,
Stefano Stabellini, Kevin Wolf, Max Reitz
> -----Original Message-----
> From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> Sent: 31 January 2019 15:25
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>; Stefano
> Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>; Max
> Reitz <mreitz@redhat.com>
> Subject: Re: [PATCH v2] xen-block: handle resize callback
>
> On Thu, Jan 31, 2019 at 03:22:18PM +0000, Paul Durrant wrote:
> > > -----Original Message-----
> > > From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> > > Sent: 31 January 2019 15:21
> > > To: Paul Durrant <Paul.Durrant@citrix.com>
> > > Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> > > devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>;
> Stefano
> > > Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>;
> Max
> > > Reitz <mreitz@redhat.com>
> > > Subject: Re: [PATCH v2] xen-block: handle resize callback
> > >
> > > On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> > > > 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>
> > > > ---
> > >
> > >
> > > > + /*
> > > > + * Mimic the behaviour of Linux xen-blkback and re-write the
> state
> > > > + * to trigger the frontend watch.
> > > > + */
> > > > + xen_device_backend_set_state(xendev, backend_state);
> > >
> > > :(, that function doesn't write the state again if it hasn't changed.
> > > So in my testing, Linux never did anything.
> >
> > Gah! I forgot about that. Alright, it's going to have to be a bit more
> crude.
>
> more crude > Yes, I tried to ignore the check in _set_state and end-up
> with an infinit loop.
Yes, you would. That check is there for a reason :-) I'll replace the call in xen-block.c with a call to xen_device_backend_printf().
Paul
>
> --
> Anthony PERARD
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] xen-block: handle resize callback
2019-01-31 15:25 ` Anthony PERARD
(?)
(?)
@ 2019-01-31 15:26 ` Paul Durrant
-1 siblings, 0 replies; 9+ messages in thread
From: Paul Durrant @ 2019-01-31 15:26 UTC (permalink / raw)
To: Anthony Perard
Cc: Kevin Wolf, Stefano Stabellini, qemu-block, qemu-devel,
Max Reitz, Stefan Hajnoczi, xen-devel
> -----Original Message-----
> From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> Sent: 31 January 2019 15:25
> To: Paul Durrant <Paul.Durrant@citrix.com>
> Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>; Stefano
> Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>; Max
> Reitz <mreitz@redhat.com>
> Subject: Re: [PATCH v2] xen-block: handle resize callback
>
> On Thu, Jan 31, 2019 at 03:22:18PM +0000, Paul Durrant wrote:
> > > -----Original Message-----
> > > From: Anthony PERARD [mailto:anthony.perard@citrix.com]
> > > Sent: 31 January 2019 15:21
> > > To: Paul Durrant <Paul.Durrant@citrix.com>
> > > Cc: qemu-devel@nongnu.org; qemu-block@nongnu.org; xen-
> > > devel@lists.xenproject.org; Stefan Hajnoczi <stefanha@redhat.com>;
> Stefano
> > > Stabellini <sstabellini@kernel.org>; Kevin Wolf <kwolf@redhat.com>;
> Max
> > > Reitz <mreitz@redhat.com>
> > > Subject: Re: [PATCH v2] xen-block: handle resize callback
> > >
> > > On Wed, Jan 30, 2019 at 04:19:48PM +0000, Paul Durrant wrote:
> > > > 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>
> > > > ---
> > >
> > >
> > > > + /*
> > > > + * Mimic the behaviour of Linux xen-blkback and re-write the
> state
> > > > + * to trigger the frontend watch.
> > > > + */
> > > > + xen_device_backend_set_state(xendev, backend_state);
> > >
> > > :(, that function doesn't write the state again if it hasn't changed.
> > > So in my testing, Linux never did anything.
> >
> > Gah! I forgot about that. Alright, it's going to have to be a bit more
> crude.
>
> more crude > Yes, I tried to ignore the check in _set_state and end-up
> with an infinit loop.
Yes, you would. That check is there for a reason :-) I'll replace the call in xen-block.c with a call to xen_device_backend_printf().
Paul
>
> --
> Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-01-31 15:48 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-30 16:19 [Qemu-devel] [PATCH v2] xen-block: handle resize callback Paul Durrant
2019-01-31 15:20 ` Anthony PERARD
2019-01-31 15:20 ` Anthony PERARD
2019-01-31 15:22 ` Paul Durrant
2019-01-31 15:22 ` [Qemu-devel] " Paul Durrant
2019-01-31 15:25 ` Anthony PERARD
2019-01-31 15:25 ` Anthony PERARD
2019-01-31 15:26 ` [Qemu-devel] " Paul Durrant
2019-01-31 15:26 ` Paul Durrant
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.