allow to set 'drive' property on a realized block device
cover allow to set 'drive' property on a realized block device
This allows to replace the file on a block device and is useful to workaround the cases (migration) when the VM image is placed on some shared storage with exclusive file opening model but the image should be open form more than one app.
The previous version of approaching the workaround was based on the "blockdev-change-medium" command modification but had some flaws:
* semantics: blockdev-change-medium is aimed to be used with removable devices only
* interface: it can't accept all possible combination of parameters for the "drive" replacement (creation).
More details here: http://patchwork.ozlabs.org/patch/1179329/
The current series suggests another approach:
1. blockdev-add
2. qom-set disk.drive = the blockdev added (this is what the series adds)
Denis Plotnikov (2):
qdev-properties-system: extend set_pionter for unrealized devices
block: allow to set 'drive' property on a realized block device
hw/core/qdev-properties-system.c | 117 +++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 21 deletions(-)
Signature · 1 line
2.17.0
PATCH 2/2 block: allow to set 'drive' property on a realized block device
This allows to change (replace) the file on a block device and is useful to workaround exclusive file access restrictions, e.g. to implement VM migration with a shared disk stored on some storage with the exclusive file opening model: a destination VM is started waiting for incomming migration with a fake image drive, and later, on the last migration phase, the fake image file is replaced with the real one.
--- hw/core/qdev-properties-system.c | 89 +++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-)
hw/core/qdev-properties-system.c +77 -12
@@ -79,8 +79,55 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,/* --- drive --- */ -static void do_parse_drive (DeviceState *dev,const char *str,void **ptr, -const char *propname,bool iothread,Error **errp) +static void do_parse_drive_realized (DeviceState *dev,const char *str, +void **ptr,const char *propname, +bool iothread,Error **errp) +{ +BlockBackend *blk = *ptr; +BlockDriverState *bs =bdrv_lookup_bs (NULL , str,NULL ); +int ret; +bool blk_created = false; + +if (!bs) { +error_setg (errp,"Can't find blockdev '%s'" , str); +return ; + } + +if (!blk) { +AioContext *ctx = iothread ?bdrv_get_aio_context (bs) : +qemu_get_aio_context (); + blk =blk_new (ctx,BLK_PERM_ALL ,BLK_PERM_ALL ); + blk_created = true; + }else { +if (blk_bs (blk)) { +blk_remove_bs (blk); + } + } + + ret =blk_insert_bs (blk, bs, errp); + +if (!ret && blk_created) { +if (blk_attach_dev (blk, dev) <0 ) { +/* +* Shouldn't be any errors here since we just created +* the new blk because the device doesn't have any. +* Leave the message here in case blk_attach_dev is changed +*/ +error_setg (errp,"Can't attach drive '%s' to device '%s'" , + str,object_get_typename (OBJECT (dev))); + }else { + *ptr = blk; + } + } + +if (blk_created) { +blk_unref (blk); + } +} + +static void do_parse_drive_unrealized (DeviceState *dev,const char *str, +void **ptr,const char *propname, +bool iothread,Error **errp) {BlockBackend *blk;bool blk_created = false;
@@ -137,18 +184,34 @@ fail: } } -static void parse_drive (DeviceState *dev,const char *str,void **ptr, -const char *propname,Error **errp) -{ -do_parse_drive (dev, str, ptr, propname, false, errp); -} - -static void parse_drive_iothread (DeviceState *dev,const char *str,void **ptr, +static void parse_drive_realized (DeviceState *dev,const char *str,void **ptr,const char *propname,Error **errp) { -do_parse_drive (dev, str, ptr, propname, true, errp); +do_parse_drive_realized (dev, str, ptr, propname, false, errp); } +static void parse_drive_realized_iothread (DeviceState *dev,const char *str, +void **ptr,const char *propname, +Error **errp) +{ +do_parse_drive_realized (dev, str, ptr, propname, true, errp); +} + +static void parse_drive_unrealized (DeviceState *dev,const char *str, +void **ptr,const char *propname, +Error **errp) +{ +do_parse_drive_unrealized (dev, str, ptr, propname, false, errp); +} + +static void parse_drive_unrealized_iothread (DeviceState *dev,const char *str, +void **ptr,const char *propname, +Error **errp) +{ +do_parse_drive_unrealized (dev, str, ptr, propname, true, errp); +} + +static void release_drive (Object *obj,const char *name,void *opaque) {DeviceState *dev =DEVICE (obj);
@@ -188,13 +251,15 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,static void set_drive (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque,NULL , parse_drive, name, errp); +set_pointer (obj, v, opaque, parse_drive_realized, parse_drive_unrealized, + name, errp); }static void set_drive_iothread (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque,NULL , parse_drive_iothread, name, errp); +set_pointer (obj, v, opaque, parse_drive_realized_iothread, + parse_drive_unrealized_iothread, name, errp); }const PropertyInfo qdev_prop_drive = {
Signature · 1 line
2.17.0
PATCH 1/2 qdev-properties-system: extend set_pionter for unrealized devices
In reply to Denis PlotnikovSome device's property can be changed if the device has been already realized. For example, it could be "drive" property of a scsi disk device.
So far, set_pointer could operate only on a relized device. The patch extends its interface for operation on an unrealized device.
--- hw/core/qdev-properties-system.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
hw/core/qdev-properties-system.c +21 -11
@@ -38,9 +38,14 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, }static void set_pointer (Object *obj,Visitor *v,Property *prop, -void (*parse)(DeviceState *dev,const char *str, -void **ptr,const char *propname, -Error **errp), +void (*parse_realized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp), +void (*parse_unrealized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp),const char *name,Error **errp) {DeviceState *dev =DEVICE (obj);
@@ -48,11 +53,6 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,void **ptr =qdev_get_prop_ptr (dev, prop);char *str; -if (dev->realized) { -qdev_prop_set_after_realize (dev, name, errp); -return ; - } -visit_type_str (v, name, &str, &local_err);if (local_err) {error_propagate (errp, local_err);
@@ -63,7 +63,17 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, *ptr =NULL ;return ; } -parse (dev, str, ptr, prop->name, errp); + +if (dev->realized) { +if (parse_realized) { +parse_realized (dev, str, ptr, prop->name, errp); + }else { +qdev_prop_set_after_realize (dev, name, errp); + } + }else { +parse_unrealized (dev, str, ptr, prop->name, errp); + } +g_free (str); }
@@ -178,13 +188,13 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,static void set_drive (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque, parse_drive, name, errp); +set_pointer (obj, v, opaque,NULL , parse_drive, name, errp); }static void set_drive_iothread (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque, parse_drive_iothread, name, errp); +set_pointer (obj, v, opaque,NULL , parse_drive_iothread, name, errp); }const PropertyInfo qdev_prop_drive = {
Signature · 1 line
2.17.0
Re: [PATCH v0 2/2] block: allow to set 'drive' property on a realized block device
In reply to Denis PlotnikovQuoted 31 lines · Denis Plotnikov
This allows to change (replace) the file on a block device and is useful to workaround exclusive file access restrictions, e.g. to implement VM migration with a shared disk stored on some storage with the exclusive file opening model: a destination VM is started waiting for incomming migration with a fake image drive, and later, on the last migration phase, the fake image file is replaced with the real one.
Signed-off-by Denis Plotnikov <[email protected]>--- hw/core/qdev-properties-system.c | 89 +++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-)hw/core/qdev-properties-system.c +9
-2@@ -79,8 +79,55 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,/* --- drive --- */ -static void do_parse_drive (DeviceState *dev,const char *str,void **ptr, -const char *propname,bool iothread,Error **errp) +static void do_parse_drive_realized (DeviceState *dev,const char *str, +void **ptr,const char *propname, +bool iothread,Error **errp) +{ +BlockBackend *blk = *ptr; +BlockDriverState *bs =bdrv_lookup_bs (NULL , str,NULL ); +int ret; +bool blk_created = false; +
hw/core/qdev-properties-system.c static void set_pointer(Object *obj, Visitor *v, Property *prop, · line 100
Quoted 10 lines
hw/core/qdev-properties-system.c +10
-0+if (!bs) { +error_setg (errp,"Can't find blockdev '%s'" , str); +return ; + } + +if (!blk) { +AioContext *ctx = iothread ?bdrv_get_aio_context (bs) : +qemu_get_aio_context (); + blk =blk_new (ctx,BLK_PERM_ALL ,BLK_PERM_ALL ); + blk_created = true;
Actually, I have concerns about situation where blk=null.
Is there any case when scsi-hd (or others) doesn't have a blk assigned and it's legal?
Quoted 94 lines
hw/core/qdev-properties-system.c +58
-10+ }else { +if (blk_bs (blk)) { +blk_remove_bs (blk); + } + } + + ret =blk_insert_bs (blk, bs, errp); + +if (!ret && blk_created) { +if (blk_attach_dev (blk, dev) <0 ) { +/* +* Shouldn't be any errors here since we just created +* the new blk because the device doesn't have any. +* Leave the message here in case blk_attach_dev is changed +*/ +error_setg (errp,"Can't attach drive '%s' to device '%s'" , + str,object_get_typename (OBJECT (dev))); + }else { + *ptr = blk; + } + } + +if (blk_created) { +blk_unref (blk); + } +} + +static void do_parse_drive_unrealized (DeviceState *dev,const char *str, +void **ptr,const char *propname, +bool iothread,Error **errp) {BlockBackend *blk;bool blk_created = false;@@ -137,18 +184,34 @@ fail: } } -static void parse_drive (DeviceState *dev,const char *str,void **ptr, -const char *propname,Error **errp) -{ -do_parse_drive (dev, str, ptr, propname, false, errp); -} - -static void parse_drive_iothread (DeviceState *dev,const char *str,void **ptr, +static void parse_drive_realized (DeviceState *dev,const char *str,void **ptr,const char *propname,Error **errp) { -do_parse_drive (dev, str, ptr, propname, true, errp); +do_parse_drive_realized (dev, str, ptr, propname, false, errp); } +static void parse_drive_realized_iothread (DeviceState *dev,const char *str, +void **ptr,const char *propname, +Error **errp) +{ +do_parse_drive_realized (dev, str, ptr, propname, true, errp); +} + +static void parse_drive_unrealized (DeviceState *dev,const char *str, +void **ptr,const char *propname, +Error **errp) +{ +do_parse_drive_unrealized (dev, str, ptr, propname, false, errp); +} + +static void parse_drive_unrealized_iothread (DeviceState *dev,const char *str, +void **ptr,const char *propname, +Error **errp) +{ +do_parse_drive_unrealized (dev, str, ptr, propname, true, errp); +} + +static void release_drive (Object *obj,const char *name,void *opaque) {DeviceState *dev =DEVICE (obj);@@ -188,13 +251,15 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,static void set_drive (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque,NULL , parse_drive, name, errp); +set_pointer (obj, v, opaque, parse_drive_realized, parse_drive_unrealized, + name, errp); }static void set_drive_iothread (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque,NULL , parse_drive_iothread, name, errp); +set_pointer (obj, v, opaque, parse_drive_realized_iothread, + parse_drive_unrealized_iothread, name, errp); }const PropertyInfo qdev_prop_drive = {
Ping!
Quoted 26 lines · Denis Plotnikov
This allows to replace the file on a block device and is useful to workaround the cases (migration) when the VM image is placed on some shared storage with exclusive file opening model but the image should be open form more than one app.
The previous version of approaching the workaround was based on the "blockdev-change-medium" command modification but had some flaws:
* semantics: blockdev-change-medium is aimed to be used with removable devices only
* interface: it can't accept all possible combination of parameters for the "drive" replacement (creation).More details here: http://patchwork.ozlabs.org/patch/1179329/
The current series suggests another approach:
1. blockdev-add
2. qom-set disk.drive = the blockdev added (this is what the series adds)Denis Plotnikov (2):
qdev-properties-system: extendset_pionterfor unrealized devices
block: allow to set 'drive' property on a realized block devicehw/core/qdev-properties-system.c | 117 +++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 21 deletions(-)
Re: [PATCH v0 2/2] block: allow to set 'drive' property on a realized block device
In reply to Denis PlotnikovQuoted 64 lines · Denis Plotnikov
Quoted 33 lines · Denis Plotnikov
This allows to change (replace) the file on a block device and is useful to workaround exclusive file access restrictions, e.g. to implement VM migration with a shared disk stored on some storage with the exclusive file opening model: a destination VM is started waiting for incomming migration with a fake image drive, and later, on the last migration phase, the fake image file is replaced with the real one.
Signed-off-by Denis Plotnikov <[email protected]>---
hw/core/qdev-properties-system.c| 89 +++++++++++++++++++++++++++-----1 file changed, 77 insertions(+), 12 deletions(-)hw/core/qdev-properties-system.c +0
-0@@ -79,8 +79,55 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, /* --- drive --- */-static void do_parse_drive(DeviceState *dev, const char *str, void **ptr,
- const char *propname, bool iothread, Error **errp)hw/core/qdev-properties-system.c +9
-0+static void do_parse_drive_realized (DeviceState *dev,const char *str, + void **ptr, const char *propname, + bool iothread, Error **errp) +{ + BlockBackend *blk = *ptr; + BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL); + int ret; + bool blk_created = false; +hw/core/qdev-properties-system.c static void set_pointer(Object *obj, Visitor *v, Property *prop, · line 100
Quoted 10 lines
hw/core/qdev-properties-system.c +10
-0+ if (!bs) { + error_setg(errp, "Can't find blockdev '%s'", str); + return; + } + + if (!blk) { + AioContext *ctx = iothread ? bdrv_get_aio_context(bs) : + qemu_get_aio_context(); + blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL); + blk_created = true;Actually, I have concerns about situation where blk=null.
Is there any case when scsi-hd (or others) doesn't have a blk assigned and it's legal?
Quoted 13 lines
+ } else {
+ if (blk_bs(blk)) {
+blk_remove_bs(blk);
+ }
+ }hw/core/qdev-properties-system.c +8
-0+ + ret = blk_insert_bs(blk, bs, errp); + + if (!ret && blk_created) { + if (blk_attach_dev(blk, dev) < 0) { + /* +* Shouldn't be any errors here since we just created +* the new blk because the device doesn't have any.
Quoted 8 lines
Quoted 8 lines
+ * Leave the message here in case
blk_attach_devis changed + */
+ error_setg(errp, "Can't attach drive '%s' to device '%s'", + str, object_get_typename(OBJECT(dev))); + } else {
+ *ptr = blk;
+ }
+ }
Another problem here, is that the "size" of the device dev may not match after setting a drive.
So, we should update it after the drive setting.
It was found, that it could be done by calling BlockDevOps.bdrv_parent_cb_resize.
But I have some concerns about doing it so. In the case of virtio scsi disk we have the following callstack
bdrv_parent_cb_resize calls() -> scsi_device_report_change(dev, SENSE_CODE(CAPACITY_CHANGED)) -> virtio_scsi_change ->
virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE, sense.asc |
(sense.ascq << 8));
virtio_scsi_change pushes the event to the guest to make the guest ask for size refreshing.
If I'm not mistaken, here we can get a race condition when some another request is processed with an unchanged
size and then the size changing request is processed.
I didn't find a better way to update device size so any comments are welcome.
Thanks!
Denis
Quoted 82 lines
Quoted 82 lines
hw/core/qdev-properties-system.c +7
-0+ + if (blk_created) { + blk_unref(blk); + } +} + +static void do_parse_drive_unrealized(DeviceState *dev, const char*str,
+ void **ptr, const char *propname, + bool iothread, Error **errp) {
BlockBackend *blk;
boolblk_created= false;hw/core/qdev-properties-system.c +0
-0@@ -137,18 +184,34 @@ fail: } }-static void parse_drive(DeviceState *dev, const char *str, void **ptr,
- const char *propname, Error **errp)hw/core/qdev-properties-system.c +0
-5-{ - do_parse_drive(dev, str, ptr, propname, false, errp); -} - -static void parse_drive_iothread(DeviceState *dev, const char *str,void **ptr,
+static void parse_drive_realized(DeviceState *dev, const char *str, void **ptr,
const char *propname, Error **errp) {
-do_parse_drive(dev, str, ptr, propname, true, errp);
+do_parse_drive_realized(dev, str, ptr, propname, false, errp); }
+static void parse_drive_realized_iothread(DeviceState *dev, const char *str,
+ void **ptr, const char *propname,
+ Error **errp)hw/core/qdev-properties-system.c +12
-0+{ + do_parse_drive_realized(dev, str, ptr, propname, true, errp); +} + +static void parse_drive_unrealized (DeviceState *dev,const char *str, + void **ptr, const char *propname, + Error **errp) +{ + do_parse_drive_unrealized(dev, str, ptr, propname, false, errp); +} + +static void parse_drive_unrealized_iothread(DeviceState *dev, constchar *str,
+ void **ptr, const char *propname,
+ Error **errp)hw/core/qdev-properties-system.c +5
-0+{ + do_parse_drive_unrealized(dev, str, ptr, propname, true, errp); +} + +static void
release_drive(Object *obj, const char *name, void *opaque){
DeviceState *dev = DEVICE(obj);hw/core/qdev-properties-system.c +2
-1@@ -188,13 +251,15 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque, static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - set_pointer(obj, v, opaque, NULL, parse_drive, name, errp); + set_pointer(obj, v, opaque, parse_drive_realized, parse_drive_unrealized, + name, errp); }static void set_drive_iothread(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp) {
-set_pointer(obj, v, opaque, NULL, parse_drive_iothread, name, errp);
+ set_pointer(obj, v, opaque,parse_drive_realized_iothread, +parse_drive_unrealized_iothread, name, errp); }
const PropertyInfoqdev_prop_drive= {
Re: [PATCH v0 1/2] qdev-properties-system: extend set_pionter for unrealized devices
In reply to Denis PlotnikovQuoted 21 lines · Denis Plotnikov
Some device's property can be changed if the device has been already realized. For example, it could be "drive" property of a scsi disk device.
So far,
set_pointercould operate only on a relized device. The patch extends its interface for operation on an unrealized device.Signed-off-by Denis Plotnikov <[email protected]>--- hw/core/qdev-properties-system.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)hw/core/qdev-properties-system.c +0
-2@@ -38,9 +38,14 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, } static void set_pointer(Object *obj, Visitor *v, Property *prop, - void (*parse)(DeviceState *dev, const char *str, - void **ptr, const char *propname,
hw/core/qdev-properties-system.c static void get_pointer(Object *obj, Visitor *v, Property *prop, · line 49
Quoted 10 lines
hw/core/qdev-properties-system.c +8
-1- Error **errp), +void (*parse_realized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp), + void (*parse_unrealized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp), const char *name, Error **errp)
Wouldn't it be simpler to just add a PropertyInfo::allow_set_after_realize bool field, and call the same setter function? Then you can simply change do_parse_drive() to check if realized is true.
Quoted 52 lines
hw/core/qdev-properties-system.c +13
-8{DeviceState *dev =DEVICE (obj);@@ -48,11 +53,6 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,void **ptr =qdev_get_prop_ptr (dev, prop);char *str; -if (dev->realized) { -qdev_prop_set_after_realize (dev, name, errp); -return ; - } -visit_type_str (v, name, &str, &local_err);if (local_err) {error_propagate (errp, local_err);@@ -63,7 +63,17 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, *ptr =NULL ;return ; } -parse (dev, str, ptr, prop->name, errp); + +if (dev->realized) { +if (parse_realized) { +parse_realized (dev, str, ptr, prop->name, errp); + }else { +qdev_prop_set_after_realize (dev, name, errp); + } + }else { +parse_unrealized (dev, str, ptr, prop->name, errp); + } +g_free (str); }@@ -178,13 +188,13 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,static void set_drive (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque, parse_drive, name, errp); +set_pointer (obj, v, opaque,NULL , parse_drive, name, errp); }static void set_drive_iothread (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque, parse_drive_iothread, name, errp); +set_pointer (obj, v, opaque,NULL , parse_drive_iothread, name, errp); }const PropertyInfo qdev_prop_drive = {Signature · 1 line
2.17.0
Signature · 1 line
Eduardo
Re: [PATCH v0 1/2] qdev-properties-system: extend set_pionter for unrealized devices
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Denis Plotnikov
Some device's property can be changed if the device has been already realized. For example, it could be "drive" property of a scsi disk device.
So far,
set_pointercould operate only on a relized device. The patch extends its interface for operation on an unrealized device.Signed-off-by Denis Plotnikov <[email protected]>--- hw/core/qdev-properties-system.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)hw/core/qdev-properties-system.c +0
-0@@ -38,9 +38,14 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, }
Quoted 16 lines
hw/core/qdev-properties-system.c static void get_pointer(Object *obj, Visitor *v, Property *prop, · line 49
Quoted 13 lines
hw/core/qdev-properties-system.c +8
-3static void set_pointer (Object *obj,Visitor *v,Property *prop, -void (*parse)(DeviceState *dev,const char *str, -void **ptr,const char *propname, -Error **errp), +void (*parse_realized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp), +void (*parse_unrealized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp),const char *name,Error **errp)Wouldn't it be simpler to just add a
PropertyInfo::allow_set_after_realizebool field, and call the same setter function? Then you can simply changedo_parse_drive()to check if realized is true.
May be, but I thought It would be more clear to have a separate callback for all the devices supporting the property setting when realized. Also the "drive" property setting on realized and non-realized device a little bit different: in the realized case the setter function expects to get
BlockDriverState only, when in the unrealized case the setter can accept both BlockBackend and BlockDriverState. Also, in the unrealized case the setter function doesn't expect to have a device with an empty BlockBackend. I decided that extending do_parse_drive would make it more complex for understanding. That's why I made two separate functions for both cases.
I'd like to mention that I have a few concerns about do_parse_drive_realized (please see the next patch from the series) and I'd like them to be reviewed as well. After that, may be it would be better to go the way you suggested.
Thanks for reviewing!
Denis
Quoted 53 lines
Quoted 53 lines
hw/core/qdev-properties-system.c +13
-8{DeviceState *dev =DEVICE (obj);@@ -48,11 +53,6 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,void **ptr =qdev_get_prop_ptr (dev, prop);char *str; -if (dev->realized) { -qdev_prop_set_after_realize (dev, name, errp); -return ; - } -visit_type_str (v, name, &str, &local_err);if (local_err) {error_propagate (errp, local_err);@@ -63,7 +63,17 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, *ptr =NULL ;return ; } -parse (dev, str, ptr, prop->name, errp); + +if (dev->realized) { +if (parse_realized) { +parse_realized (dev, str, ptr, prop->name, errp); + }else { +qdev_prop_set_after_realize (dev, name, errp); + } + }else { +parse_unrealized (dev, str, ptr, prop->name, errp); + } +g_free (str); }@@ -178,13 +188,13 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,static void set_drive (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque, parse_drive, name, errp); +set_pointer (obj, v, opaque,NULL , parse_drive, name, errp); }static void set_drive_iothread (Object *obj,Visitor *v,const char *name,void *opaque,Error **errp) { -set_pointer (obj, v, opaque, parse_drive_iothread, name, errp); +set_pointer (obj, v, opaque,NULL , parse_drive_iothread, name, errp); }const PropertyInfo qdev_prop_drive = {Signature · 1 line
2.17.0
Re: [PATCH v0 1/2] qdev-properties-system: extend set_pionter for unrealized devices
Quoted 38 lines · Denis Plotnikov
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Denis Plotnikov
Some device's property can be changed if the device has been already realized. For example, it could be "drive" property of a scsi disk device.
So far,
set_pointercould operate only on a relized device. The patch extends its interface for operation on an unrealized device.Signed-off-by Denis Plotnikov <[email protected]>--- hw/core/qdev-properties-system.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)hw/core/qdev-properties-system.c +0
-0@@ -38,9 +38,14 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, }Quoted 16 lines
hw/core/qdev-properties-system.c static void get_pointer(Object *obj, Visitor *v, Property *prop, · line 49
Quoted 13 lines
hw/core/qdev-properties-system.c +8
-3static void set_pointer (Object *obj,Visitor *v,Property *prop, -void (*parse)(DeviceState *dev,const char *str, -void **ptr,const char *propname, -Error **errp), +void (*parse_realized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp), +void (*parse_unrealized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp),const char *name,Error **errp)Wouldn't it be simpler to just add a
PropertyInfo::allow_set_after_realizebool field, and call the same setter function? Then you can simply changedo_parse_drive()to check if realized is true.
Quoted 10 lines
May be, but I thought It would be more clear to have a separate callback for all the devices supporting the property setting when realized. Also the "drive" property setting on realized and non-realized device a little bit different: in the realized case the setter function expects to get
BlockDriverState only, when in the unrealized case the setter can accept both BlockBackend and BlockDriverState. Also, in the unrealized case the setter function doesn't expect to have a device with an empty BlockBackend. I decided that extendingdo_parse_drivewould make it more complex for understanding. That's why I made two separate functions for both cases.
I understand you might want two separate functions in the specific case of drive. You can still call different functions after checking dev->realized inside do_parse_drive().
My point was that you don't need to make set_pointer() require two separate function pointers just to propagate 1 bit of information that is already available in DeviceState. In patch 2/2 you had to create 4 different copies of parse_drive*() because of this.
Quoted 5 lines
I'd like to mention that I have a few concerns about
do_parse_drive_realized(please see the next patch from the series) and I'd like them to be reviewed as well. After that, may be it would be better to go the way you suggested.
In the case if your questions in patch 2/2, I'm afraid I don't know the answers and we need help from the block maintainers.
Signature · 1 line
Eduardo
Re: [PATCH v0 1/2] qdev-properties-system: extend set_pionter for unrealized devices
Quoted 52 lines · Eduardo Habkost
Quoted 37 lines · Denis Plotnikov
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Denis Plotnikov
Some device's property can be changed if the device has been already realized. For example, it could be "drive" property of a scsi disk device.
So far,
set_pointercould operate only on a relized device. The patch extends its interface for operation on an unrealized device.Signed-off-by Denis Plotnikov <[email protected]>--- hw/core/qdev-properties-system.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)hw/core/qdev-properties-system.c +0
-0@@ -38,9 +38,14 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, }Quoted 16 lines
hw/core/qdev-properties-system.c static void get_pointer(Object *obj, Visitor *v, Property *prop, · line 49
Quoted 13 lines
hw/core/qdev-properties-system.c +8
-3static void set_pointer (Object *obj,Visitor *v,Property *prop, -void (*parse)(DeviceState *dev,const char *str, -void **ptr,const char *propname, -Error **errp), +void (*parse_realized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp), +void (*parse_unrealized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp),const char *name,Error **errp)Wouldn't it be simpler to just add a
PropertyInfo::allow_set_after_realizebool field, and call the same setter function? Then you can simply changedo_parse_drive()to check if realized is true.Quoted 10 lines
May be, but I thought It would be more clear to have a separate callback for all the devices supporting the property setting when realized. Also the "drive" property setting on realized and non-realized device a little bit different: in the realized case the setter function expects to get
BlockDriverState only, when in the unrealized case the setter can accept both BlockBackend and BlockDriverState. Also, in the unrealized case the setter function doesn't expect to have a device with an empty BlockBackend. I decided that extendingdo_parse_drivewould make it more complex for understanding. That's why I made two separate functions for both cases.I understand you might want two separate functions in the specific case of drive. You can still call different functions after checking
dev->realizedinsidedo_parse_drive().
Quoted 5 lines
My point was that you don't need to make
set_pointer()require two separate function pointers just to propagate 1 bit of information that is already available in DeviceState. In patch 2/2 you had to create 4 different copies of parse_drive*() because of this.
Yes, that's true. I wanted to suggest a more general way to deal with a device on realized and non-realized state.
I may be too much and not necessary. May be we should wait for a feedback from the block maintainers?
Quoted 8 lines
Quoted 6 lines
I'd like to mention that I have a few concerns about
do_parse_drive_realized(please see the next patch from the series) and I'd like them to be reviewed as well. After that, may be it would be better to go the way you suggested.In the case if your questions in patch 2/2, I'm afraid I don't know the answers and we need help from the block maintainers.
Anyway, thanks for taking a glance.
Quoted 1 line
Re: [PATCH v0 1/2] qdev-properties-system: extend set_pionter for unrealized devices
Am 26.11.2019 um 07:49 hat Denis Plotnikov geschrieben:
Quoted 60 lines · Eduardo Habkost
Quoted 52 lines · Denis Plotnikov
Quoted 37 lines · Eduardo Habkost
Quoted 19 lines · Denis Plotnikov
Quoted 18 lines
Some device's property can be changed if the device has been already realized. For example, it could be "drive" property of a scsi disk device.
So far,
set_pointercould operate only on a relized device. The patch extends its interface for operation on an unrealized device.Signed-off-by Denis Plotnikov <[email protected]>--- hw/core/qdev-properties-system.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)hw/core/qdev-properties-system.c +0
-0@@ -38,9 +38,14 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, }Quoted 16 lines
hw/core/qdev-properties-system.c static void get_pointer(Object *obj, Visitor *v, Property *prop, · line 49
Quoted 13 lines
hw/core/qdev-properties-system.c +8
-3static void set_pointer (Object *obj,Visitor *v,Property *prop, -void (*parse)(DeviceState *dev,const char *str, -void **ptr,const char *propname, -Error **errp), +void (*parse_realized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp), +void (*parse_unrealized)(DeviceState *dev, +const char *str,void **ptr, +const char *propname, +Error **errp),const char *name,Error **errp)Wouldn't it be simpler to just add a
PropertyInfo::allow_set_after_realizebool field, and call the same setter function? Then you can simply changedo_parse_drive()to check if realized is true.Quoted 10 lines
May be, but I thought It would be more clear to have a separate callback for all the devices supporting the property setting when realized. Also the "drive" property setting on realized and non-realized device a little bit different: in the realized case the setter function expects to get
BlockDriverState only, when in the unrealized case the setter can accept both BlockBackend and BlockDriverState. Also, in the unrealized case the setter function doesn't expect to have a device with an empty BlockBackend. I decided that extendingdo_parse_drivewould make it more complex for understanding. That's why I made two separate functions for both cases.I understand you might want two separate functions in the specific case of drive. You can still call different functions after checking
dev->realizedinsidedo_parse_drive().Quoted 5 lines
My point was that you don't need to make
set_pointer()require two separate function pointers just to propagate 1 bit of information that is already available in DeviceState. In patch 2/2 you had to create 4 different copies of parse_drive*() because of this.
Quoted 4 lines
Yes, that's true. I wanted to suggest a more general way to deal with a device on realized and non-realized state.
I may be too much and not necessary. May be we should wait for a feedback from the block maintainers?
I think I agree with Eduardo on this one. This is generic infrastructure and we already see that it may require lots of wrapper functions that call into the same function with different parameters. Checking dev->realized where necessary can do the same.
I haven't had a closer look at the specific functions, but maybe they can actually share the same implementation with just some if (dev->realized) blocks.
Kevin
[PING]Re: [PATCH v0 2/2] block: allow to set 'drive' property on a realized block device
In reply to Denis PlotnikovQuoted 194 lines · Denis Plotnikov
Quoted 68 lines · Denis Plotnikov
Quoted 35 lines · Denis Plotnikov
This allows to change (replace) the file on a block device and is useful
to workaround exclusive file access restrictions, e.g. to implement VM migration with a shared disk stored on some storage with the exclusive file opening model: a destination VM is started waiting for incomming migration with a fake image drive, and later, on the last migration phase, the fake image file is replaced with the real one.Signed-off-by Denis Plotnikov <[email protected]>---
hw/core/qdev-properties-system.c| 89
+++++++++++++++++++++++++++-----1 file changed, 77 insertions(+), 12 deletions(-)hw/core/qdev-properties-system.c +9
-1@@ -79,8 +79,55 @@ static void set_pointer(Object *obj, Visitor *v,Property *prop, /* --- drive --- */ -static void do_parse_drive(DeviceState *dev, const char *str, void **ptr, - const char *propname, bool iothread, Error **errp) +static void do_parse_drive_realized(DeviceState *dev, const char *str, + void **ptr, const char *propname, + bool iothread, Error **errp) +{ + BlockBackend *blk = *ptr; + BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL); + int ret; + bool blk_created = false; +hw/core/qdev-properties-system.c static void set_pointer(Object *obj, Visitor *v, · line 102
Quoted 10 lines
hw/core/qdev-properties-system.c +10
-0+ if (!bs) { + error_setg(errp, "Can't find blockdev '%s'", str); + return; + } + + if (!blk) { + AioContext *ctx = iothread ? bdrv_get_aio_context(bs) : + qemu_get_aio_context(); + blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL); + blk_created = true;Actually, I have concerns about situation where blk=null.
Is there any case when scsi-hd (or others) doesn't have a blk assigned and it's legal?
Quoted 15 lines
hw/core/qdev-properties-system.c +14
-0+ } else { + if (blk_bs(blk)) { + blk_remove_bs(blk); + } + } + + ret = blk_insert_bs(blk, bs, errp); + + if (!ret && blk_created) { + if (blk_attach_dev(blk, dev) < 0) { + /* +* Shouldn't be any errors here since we just created +* the new blk because the device doesn't have any. +* Leave the message here in case blk_attach_dev is changed
Quoted 8 lines
Quoted 8 lines
+ */
+ error_setg(errp, "Can't attach drive '%s' to device '%s'",
+ str, object_get_typename(OBJECT(dev))); + } else {
+ *ptr = blk;
+ }
+ }Another problem here, is that the "size" of the device dev may not match after setting a drive.
So, we should update it after the drive setting.
It was found, that it could be done by calling BlockDevOps.bdrv_parent_cb_resize.But I have some concerns about doing it so. In the case of virtio scsi disk we have the following callstack
bdrv_parent_cb_resizecalls()->scsi_device_report_change(dev, SENSE_CODE(CAPACITY_CHANGED))->virtio_scsi_change->
virtio_scsi_push_event(s, dev,VIRTIO_SCSI_T_PARAM_CHANGE,
sense.asc | (sense.ascq << 8));virtio_scsi_change pushes the event to the guest to make the guest ask for size refreshing.
If I'm not mistaken, here we can get a race condition when some another request is processed with an unchanged
size and then the size changing request is processed.I didn't find a better way to update device size so any comments are welcome.
Thanks!
Denis
Quoted 84 lines
Quoted 84 lines
hw/core/qdev-properties-system.c +7
-0+ + if (blk_created) { + blk_unref(blk); + } +} + +static void do_parse_drive_unrealized(DeviceState *dev, const char*str,
+ void **ptr, const char *propname,
+ bool iothread, Error **errp) {
BlockBackend *blk;
boolblk_created= false;hw/core/qdev-properties-system.c +0
-0@@ -137,18 +184,34 @@ fail: } }-static void parse_drive(DeviceState *dev, const char *str, void **ptr,
- const char *propname, Error **errp)hw/core/qdev-properties-system.c +0
-5-{ - do_parse_drive(dev, str, ptr, propname, false, errp); -} - -static void parse_drive_iothread(DeviceState *dev, const char *str,void **ptr,
+static void parse_drive_realized(DeviceState *dev, const char *str, void **ptr,
const char *propname, Error **errp) {
-do_parse_drive(dev, str, ptr, propname, true, errp);
+do_parse_drive_realized(dev, str, ptr, propname, false, errp); }
+static void parse_drive_realized_iothread(DeviceState *dev, const char *str,
+ void **ptr, const char *propname,
+ Error **errp)hw/core/qdev-properties-system.c +12
-0+{ + do_parse_drive_realized(dev, str, ptr, propname, true, errp); +} + +static void parse_drive_unrealized (DeviceState *dev,const char *str, + void **ptr, const char *propname, + Error **errp) +{ + do_parse_drive_unrealized(dev, str, ptr, propname, false, errp); +} + +static void parse_drive_unrealized_iothread(DeviceState *dev, constchar *str,
+ void **ptr, const char *propname,
+ Error **errp)hw/core/qdev-properties-system.c +5
-0+{ + do_parse_drive_unrealized(dev, str, ptr, propname, true, errp); +} + +static void
release_drive(Object *obj, const char *name, void *opaque)
{
DeviceState *dev = DEVICE(obj);hw/core/qdev-properties-system.c +2
-1@@ -188,13 +251,15 @@ static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque, static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { - set_pointer(obj, v, opaque, NULL, parse_drive, name, errp); + set_pointer(obj, v, opaque, parse_drive_realized, parse_drive_unrealized, + name, errp); }static void set_drive_iothread(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp) {
-set_pointer(obj, v, opaque, NULL, parse_drive_iothread, name, errp);
+ set_pointer(obj, v, opaque,parse_drive_realized_iothread, +parse_drive_unrealized_iothread, name, errp); }
const PropertyInfoqdev_prop_drive= {
Re: [PATCH v0 2/2] block: allow to set 'drive' property on a realized block device
In reply to Denis PlotnikovAm 18.11.2019 um 11:50 hat Denis Plotnikov geschrieben:
Quoted 51 lines · Denis Plotnikov
Quoted 48 lines · Denis Plotnikov
Quoted 33 lines
This allows to change (replace) the file on a block device and is useful to workaround exclusive file access restrictions, e.g. to implement VM migration with a shared disk stored on some storage with the exclusive file opening model: a destination VM is started waiting for incomming migration with a fake image drive, and later, on the last migration phase, the fake image file is replaced with the real one.
Signed-off-by Denis Plotnikov <[email protected]>---
hw/core/qdev-properties-system.c| 89 +++++++++++++++++++++++++++-----1 file changed, 77 insertions(+), 12 deletions(-)hw/core/qdev-properties-system.c +0
-0@@ -79,8 +79,55 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, /* --- drive --- */-static void do_parse_drive(DeviceState *dev, const char *str, void **ptr,
- const char *propname, bool iothread, Error **errp)hw/core/qdev-properties-system.c +9
-0+static void do_parse_drive_realized (DeviceState *dev,const char *str, + void **ptr, const char *propname, + bool iothread, Error **errp) +{ + BlockBackend *blk = *ptr; + BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL); + int ret; + bool blk_created = false; +hw/core/qdev-properties-system.c static void set_pointer(Object *obj, Visitor *v, Property *prop, · line 100
Quoted 10 lines
hw/core/qdev-properties-system.c +10
-0+ if (!bs) { + error_setg(errp, "Can't find blockdev '%s'", str); + return; + } + + if (!blk) { + AioContext *ctx = iothread ? bdrv_get_aio_context(bs) : + qemu_get_aio_context(); + blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL); + blk_created = true;Actually, I have concerns about situation where blk=null.
Quoted 2 lines
Quoted 2 lines
Is there any case when scsi-hd (or others) doesn't have a blk assigned and it's legal?
No, block devices will always have a BlockBackend, even if it doesn't have a root node inserted.
Quoted 30 lines
Quoted 13 lines
Quoted 13 lines
+ } else {
+ if (blk_bs(blk)) {
+blk_remove_bs(blk);
+ }
+ }hw/core/qdev-properties-system.c +8
-0+ + ret = blk_insert_bs(blk, bs, errp); + + if (!ret && blk_created) { + if (blk_attach_dev(blk, dev) < 0) { + /* +* Shouldn't be any errors here since we just created +* the new blk because the device doesn't have any. Quoted 8 lines
Quoted 8 lines
+ * Leave the message here in case
blk_attach_devis changed + */
+ error_setg(errp, "Can't attach drive '%s' to device '%s'", + str, object_get_typename(OBJECT(dev))); + } else {
+ *ptr = blk;
+ }
+ }Another problem here, is that the "size" of the device dev may not match after setting a drive.
So, we should update it after the drive setting.
It was found, that it could be done by calling BlockDevOps.bdrv_parent_cb_resize.But I have some concerns about doing it so. In the case of virtio scsi disk we have the following callstack
Quoted 6 lines
bdrv_parent_cb_resizecalls()->scsi_device_report_change(dev, SENSE_CODE(CAPACITY_CHANGED))->virtio_scsi_change->
virtio_scsi_push_event(s, dev,VIRTIO_SCSI_T_PARAM_CHANGE, sense.asc |
(sense.ascq << 8));
I think the safest option for now (and which should solve the case you want to address) is checking whether old and new size match and returning an error otherwise.
Quoted 4 lines
virtio_scsi_change pushes the event to the guest to make the guest ask for size refreshing. If I'm not mistaken, here we can get a race condition when some another request is processed with an unchanged size and then the size changing request is processed.
I think this is actually a problem even without resizing: We need to quiesce the device between removing the old root and inserting the new one. They way to achieve this is probably by splitting blk_drain() into a blk_drain_begin()/end() and then draining the BlockBackend here while we're working on it.
Kevin
Re: [PATCH v0 2/2] block: allow to set 'drive' property on a realized block device
Quoted 98 lines · Kevin Wolf
Am 18.11.2019 um 11:50 hat Denis Plotnikov geschrieben:
Quoted 48 lines · Denis Plotnikov
Quoted 46 lines · Denis Plotnikov
Quoted 33 lines
This allows to change (replace) the file on a block device and is useful to workaround exclusive file access restrictions, e.g. to implement VM migration with a shared disk stored on some storage with the exclusive file opening model: a destination VM is started waiting for incomming migration with a fake image drive, and later, on the last migration phase, the fake image file is replaced with the real one.
Signed-off-by Denis Plotnikov <[email protected]>--- hw/core/qdev-properties-system.c | 89 +++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-)hw/core/qdev-properties-system.c +9
-1@@ -79,8 +79,55 @@ static void set_pointer(Object *obj, Visitor *v,Property *prop, /* --- drive --- */ -static void do_parse_drive(DeviceState *dev, const char *str, void **ptr, - const char *propname, bool iothread, Error **errp) +static void do_parse_drive_realized(DeviceState *dev, const char *str, + void **ptr, const char *propname, + bool iothread, Error **errp) +{ + BlockBackend *blk = *ptr; + BlockDriverState *bs = bdrv_lookup_bs(NULL, str, NULL); + int ret; + bool blk_created = false; +hw/core/qdev-properties-system.c static void set_pointer(Object *obj, Visitor *v, · line 102
Quoted 10 lines
hw/core/qdev-properties-system.c +10
-0+ if (!bs) { + error_setg(errp, "Can't find blockdev '%s'", str); + return; + } + + if (!blk) { + AioContext *ctx = iothread ? bdrv_get_aio_context(bs) : + qemu_get_aio_context(); + blk = blk_new(ctx, BLK_PERM_ALL, BLK_PERM_ALL); + blk_created = true;Actually, I have concerns about situation where blk=null.
Quoted 2 lines
Quoted 2 lines
Is there any case when scsi-hd (or others) doesn't have a blk assigned and it's legal?
No, block devices will always have a BlockBackend, even if it doesn't have a root node inserted.
Quoted 30 lines
Quoted 13 lines
Quoted 13 lines
hw/core/qdev-properties-system.c +13
-0+ } else { + if (blk_bs(blk)) { + blk_remove_bs(blk); + } + } + + ret = blk_insert_bs(blk, bs, errp); + + if (!ret && blk_created) { + if (blk_attach_dev(blk, dev) < 0) { + /* +* Shouldn't be any errors here since we just created +* the new blk because the device doesn't have any. Quoted 8 lines
hw/core/qdev-properties-system.c static void set_pointer(Object *obj, Visitor *v, Property *prop, · line 121
Quoted 8 lines
hw/core/qdev-properties-system.c +8
-0+* Leave the message here in case blk_attach_dev is changed +*/ + error_setg(errp, "Can't attach drive '%s' to device '%s'", + str, object_get_typename(OBJECT(dev))); + } else { + *ptr = blk; + } + }Another problem here, is that the "size" of the device dev may not match after setting a drive.
So, we should update it after the drive setting.
It was found, that it could be done by calling BlockDevOps.bdrv_parent_cb_resize.But I have some concerns about doing it so. In the case of virtio scsi disk we have the following callstack
Quoted 6 lines
bdrv_parent_cb_resizecalls()->scsi_device_report_change(dev, SENSE_CODE(CAPACITY_CHANGED))->virtio_scsi_change->
virtio_scsi_push_event(s, dev,VIRTIO_SCSI_T_PARAM_CHANGE, sense.asc |
(sense.ascq << 8));I think the safest option for now (and which should solve the case you want to address) is checking whether old and new size match and returning an error otherwise.
Quoted 4 lines
virtio_scsi_change pushes the event to the guest to make the guest ask for size refreshing. If I'm not mistaken, here we can get a race condition when some another request is processed with an unchanged size and then the size changing request is processed.
Quoted 7 lines
I think this is actually a problem even without resizing: We need to quiesce the device between removing the old root and inserting the new one. They way to achieve this is probably by splitting
blk_drain()into a blk_drain_begin()/end() and then draining the BlockBackend here while we're working on it.Kevin
Why don't we use bdrv_drained_begin/end directly? This is what blk_drain does.
If we want to split blk_drain we must keep track if blk's brdv isn't change otherwise we can end up with drain_begin one and drain end another bdrv if we do remove/insert in between.
Another thing is should we really care about this if we have VM stopped and the sizes matched?
Denis
Quoted 1 line
Re: [PATCH v0 2/2] block: allow to set 'drive' property on a realized block device
Am 16.12.2019 um 15:51 hat Denis Plotnikov geschrieben:
Quoted 31 lines · Kevin Wolf
Quoted 30 lines
Am 18.11.2019 um 11:50 hat Denis Plotnikov geschrieben:
Quoted 9 lines
Another problem here, is that the "size" of the device dev may not match after setting a drive.
So, we should update it after the drive setting.
It was found, that it could be done by calling BlockDevOps.bdrv_parent_cb_resize.But I have some concerns about doing it so. In the case of virtio scsi disk we have the following callstack
Quoted 6 lines
bdrv_parent_cb_resizecalls()->scsi_device_report_change(dev, SENSE_CODE(CAPACITY_CHANGED))->virtio_scsi_change->
virtio_scsi_push_event(s, dev,VIRTIO_SCSI_T_PARAM_CHANGE, sense.asc |
(sense.ascq << 8));I think the safest option for now (and which should solve the case you want to address) is checking whether old and new size match and returning an error otherwise.
Quoted 4 lines
virtio_scsi_change pushes the event to the guest to make the guest ask for size refreshing. If I'm not mistaken, here we can get a race condition when some another request is processed with an unchanged size and then the size changing request is processed.
I think this is actually a problem even without resizing: We need to quiesce the device between removing the old root and inserting the new one. They way to achieve this is probably by splitting
blk_drain()into a blk_drain_begin()/end() and then draining the BlockBackend here while we're working on it.
Quoted 6 lines
Quoted 1 line
Kevin
Why don't we use bdrv_drained_begin/end directly? This is what
blk_draindoes.
If we want to splitblk_drainwe must keep track if blk's brdv isn't change otherwise we can end up withdrain_beginone and drain end another bdrv if we do remove/insert in between.
Hmm, true, we would have to keep track of draining at the BlockBackend level and consider it in blk_remove_bs() and blk_insert_bs(). Maybe that's not worth it.
If we use bdrv_drained_begin/end directly, I think we need to drain both the old and the new root node during the process.
Quoted 2 lines
Another thing is should we really care about this if we have VM stopped and the sizes matched?
How do we know that the VM is stopped? And why would we require this? Your patch doesn't implement or at least check this, and it seems a bit impractical for example when all you want is inserting a filter node.
Kevin
Re: [PATCH v0 2/2] block: allow to set 'drive' property on a realized block device
Quoted 42 lines · Kevin Wolf
Am 16.12.2019 um 15:51 hat Denis Plotnikov geschrieben:
Quoted 31 lines · Kevin Wolf
Quoted 30 lines
Am 18.11.2019 um 11:50 hat Denis Plotnikov geschrieben:
Quoted 9 lines
Another problem here, is that the "size" of the device dev may not match after setting a drive.
So, we should update it after the drive setting.
It was found, that it could be done by calling BlockDevOps.bdrv_parent_cb_resize.But I have some concerns about doing it so. In the case of virtio scsi disk we have the following callstack
Quoted 6 lines
bdrv_parent_cb_resize calls() -> scsi_device_report_change(dev, SENSE_CODE(CAPACITY_CHANGED)) -> virtio_scsi_change -> virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE, sense.asc |(sense.ascq << 8));
I think the safest option for now (and which should solve the case you want to address) is checking whether old and new size match and returning an error otherwise.
Quoted 4 lines
virtio_scsi_change pushes the event to the guest to make the guest ask for size refreshing. If I'm not mistaken, here we can get a race condition when some another request is processed with an unchanged size and then the size changing request is processed.
I think this is actually a problem even without resizing: We need to quiesce the device between removing the old root and inserting the new one. They way to achieve this is probably by splitting
blk_drain()into a blk_drain_begin()/end() and then draining the BlockBackend here while we're working on it.Quoted 6 lines
Quoted 1 line
Kevin
Why don't we use bdrv_drained_begin/end directly? This is what
blk_draindoes.
If we want to splitblk_drainwe must keep track if blk's brdv isn't change otherwise we can end up withdrain_beginone and drain end another bdrv if we do remove/insert in between.Hmm, true, we would have to keep track of draining at the BlockBackend level and consider it in
blk_remove_bs()andblk_insert_bs(). Maybe that's not worth it.
Quoted 6 lines
If we use bdrv_drained_begin/end directly, I think we need to drain both the old and the new root node during the process.
Quoted 2 lines
Another thing is should we really care about this if we have VM stopped and the sizes matched?
How do we know that the VM is stopped? And why would we require this?
I implied the scenario of VM migration over a shared storage with an exclusive file access model.
The VM is stopped on drive changing phase.
If there is no use to require it, than ok.
Denis
Quoted 4 lines
Your patch doesn't implement or at least check this, and it seems a bit impractical for example when all you want is inserting a filter node.
Kevin
Am 10.11.2019 um 20:03 hat Denis Plotnikov geschrieben:
Quoted 12 lines
This allows to replace the file on a block device and is useful to workaround the cases (migration) when the VM image is placed on some shared storage with exclusive file opening model but the image should be open form more than one app.
The previous version of approaching the workaround was based on the "blockdev-change-medium" command modification but had some flaws:
* semantics: blockdev-change-medium is aimed to be used with removable devices only
* interface: it can't accept all possible combination of parameters for the "drive" replacement (creation).
Quoted 5 lines
More details here: http://patchwork.ozlabs.org/patch/1179329/
The current series suggests another approach:
1. blockdev-add
2. qom-set disk.drive = the blockdev added (this is what the series adds)
Are you still planning to send another version?
Kevin
Quoted 13 lines · Kevin Wolf
Am 10.11.2019 um 20:03 hat Denis Plotnikov geschrieben:
Quoted 12 lines
This allows to replace the file on a block device and is useful to workaround the cases (migration) when the VM image is placed on some shared storage with exclusive file opening model but the image should be open form more than one app.
The previous version of approaching the workaround was based on the "blockdev-change-medium" command modification but had some flaws:
* semantics: blockdev-change-medium is aimed to be used with removable devices only
* interface: it can't accept all possible combination of parameters for the "drive" replacement (creation).
Quoted 8 lines
Quoted 5 lines
More details here: http://patchwork.ozlabs.org/patch/1179329/
The current series suggests another approach:
1. blockdev-add
2. qom-set disk.drive = the blockdev added (this is what the series adds)Are you still planning to send another version?
Kevin
Not in the near future :) There is an unresolved problem with bitmap-migration is case of block dev replacement. Still don't know how to do it in the proper way.
Denis
Quoted 1 line
Am 02.03.2020 um 14:55 hat Denis Plotnikov geschrieben:
Quoted 21 lines · Kevin Wolf
Quoted 18 lines
Am 10.11.2019 um 20:03 hat Denis Plotnikov geschrieben:
Quoted 17 lines
This allows to replace the file on a block device and is useful to workaround the cases (migration) when the VM image is placed on some shared storage with exclusive file opening model but the image should be open form more than one app.
The previous version of approaching the workaround was based on the "blockdev-change-medium" command modification but had some flaws:
* semantics: blockdev-change-medium is aimed to be used with removable devices only
* interface: it can't accept all possible combination of parameters for the "drive" replacement (creation).More details here: http://patchwork.ozlabs.org/patch/1179329/
The current series suggests another approach:
1. blockdev-add
2. qom-set disk.drive = the blockdev added (this is what the series adds)
Quoted 6 lines
Quoted 3 lines
Are you still planning to send another version?
Kevin
Not in the near future :) There is an unresolved problem with bitmap-migration is case of block dev replacement. Still don't know how to do it in the proper way.
I seem to remember that in some discussion a while ago we came to the conclusion that we need a way for the managemnt tool to provide a mapping from source node-names to destination node-names.
Or is the problem you mean unrelated to identifying the node to which a bitmap should belong?
Kevin
Quoted 24 lines · Kevin Wolf
Am 02.03.2020 um 14:55 hat Denis Plotnikov geschrieben:
Quoted 23 lines · Kevin Wolf
Quoted 20 lines
Am 10.11.2019 um 20:03 hat Denis Plotnikov geschrieben:
Quoted 12 lines
This allows to replace the file on a block device and is useful to workaround the cases (migration) when the VM image is placed on some shared storage with exclusive file opening model but the image should be open form more than one app.
The previous version of approaching the workaround was based on the "blockdev-change-medium" command modification but had some flaws:
* semantics: blockdev-change-medium is aimed to be used with removable devices only
* interface: it can't accept all possible combination of parameters for the "drive" replacement (creation).Quoted 5 lines
More details here: http://patchwork.ozlabs.org/patch/1179329/
The current series suggests another approach:
1. blockdev-add
2. qom-set disk.drive = the blockdev added (this is what the series adds)Are you still planning to send another version?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Kevin
Not in the near future :) There is an unresolved problem with bitmap-migration is case of block dev replacement. Still don't know how to do it in the proper way.
I seem to remember that in some discussion a while ago we came to the conclusion that we need a way for the managemnt tool to provide a mapping from source node-names to destination node-names.
Yes, it's planned solution for bitmaps migration, but it doesn't help here.
Quoted 4 lines
Or is the problem you mean unrelated to identifying the node to which a bitmap should belong?
The problem here is following:
We need to workaround migration on shared fs, which doesn't allow to open file on node A if it is opened RW on node B (and visa-versa).
So, we tried to start target with null-co stub instead of shared qcow2 and than switch to correct file at some moment. The problem with bitmaps migration is that we migrate bitmaps to null-co and than they are lost... So we need to implement some moving bitmaps from null-co to qcow2 node, keeping in mind that they are in progress of migration. We didn't try to implement such moving, it seemed too tricky.
I also had an idea of a flag for file-posix to close fd on inactivation.. But then we need to not open it when openining in inactive mode, and this needs support in qcow2, which doesn't seem better than null-co stub.
So, I see two ways of solving this:
1. Use null-co stub and deal with moving bitmaps during postcopy
2. Move to UNOPENED mode for bdrv, which is similar to INACTIVE, but doesn't allow to open any files on fs. We'll have to provide size as an option anyway.. Sounds bad.
Could you give an advice?
Signature · 2 lines
Best regards, Vladimir