fix 'xl block-detach'
cover fix 'xl block-detach'
From: Paul Durrant <[email protected]>
This series makes it behave as the documentation states it should
Paul Durrant (2):
xl: implement documented --force option for block-detach
libxl: do not automatically force detach of block devices
docs/man/xl.1.pod.in | 4 ++-- tools/libxl/libxl_device.c | 9 ++++++--- tools/xl/xl_block.c | 21 ++++++++++++++++----- tools/xl/xl_cmdtable.c | 3 ++- 4 files changed, 26 insertions(+), 11 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/2 xl: implement documented --force option for block-detach
From: Paul Durrant <[email protected]>
The manpage for 'xl' documents an option to force a block device to be released even if the domain to which it is attached does not co-operate. This option, however, is not implemented. This patch implements the option.
NOTE: The documentation is also adjusted since the normal positioning of
options is before compulsory parameters. It is also noted that use of the --force option may lead to a guest crash.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>
--- docs/man/xl.1.pod.in | 4 ++-- tools/xl/xl_block.c | 21 ++++++++++++++++----- tools/xl/xl_cmdtable.c | 3 ++- 3 files changed, 20 insertions(+), 8 deletions(-)
docs/man/xl.1.pod.in +2 -2
@@ -1389,7 +1389,7 @@ Note that only PV block devices are supported by block-attach. Requests to attach emulated devices (eg, vdev=hdc) will result in only the PV view being available to the guest. -=item B<block-detach> I<domain-id> I<devid> [I<OPTIONS>] +=item B<block-detach> [I<OPTIONS>] I<domain-id> I<devid> Detach a domain's virtual block device. I<devid> may be the symbolic name or the numeric device id given to the device by domain 0. You
@@ -1406,7 +1406,7 @@ B<OPTIONS> =item B<--force> If this parameter is specified the device will be forcefully detached, which -may cause IO errors in the domain. +may cause IO errors in the domain and possibly a guest crash =back
tools/xl/xl_block.c +16 -5
@@ -96,12 +96,21 @@ int main_blocklist(int argc, char **argv)int main_blockdetach (int argc,char **argv) { +static struct option opts[] = { + {"force" ,0 ,0 ,'f' }, +COMMON_LONG_OPTS + };uint32_t domid;int opt, rc =0 ;libxl_device_disk disk; - - SWITCH_FOREACH_OPT(opt, "", NULL, "block-detach", 2) { -/* No options */ +bool force = false; + + SWITCH_FOREACH_OPT(opt, "f", opts, "block-detach", 2) { +case 'f' : + force = true; +break ; +default : +break ; } domid =find_domain (argv[optind]);
@@ -110,9 +119,11 @@ int main_blockdetach(int argc, char **argv)fprintf (stderr,"Error: Device %s not connected.\n" , argv[optind+1 ]);return 1 ; } - rc =libxl_device_disk_remove (ctx, domid, &disk,0 ); + rc = !force ?libxl_device_disk_remove (ctx, domid, &disk,0 ) : +libxl_device_disk_destroy (ctx, domid, &disk,0 );if (rc) { -fprintf (stderr,"libxl_device_disk_remove failed.\n" ); +fprintf (stderr,"libxl_device_disk_%s failed.\n" , + !force ?"remove" :"destroy" );return 1 ; }libxl_device_disk_dispose (&disk);
tools/xl/xl_cmdtable.c +2 -1
@@ -368,7 +368,8 @@ struct cmd_spec cmd_table[] = { {"block-detach" , &main_blockdetach,0 ,1 ,"Destroy a domain's virtual block device" , -"<Domain> <DevId>" , +"[option] <Domain> <DevId>" , +"-f, --force do not wait for the domain to release the device" }, { "vtpm-attach", &main_vtpmattach, 1, 1,
Signature · 1 line
2.20.1
Re: [PATCH 1/2] xl: implement documented --force option for block-detach
Quoted 35 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The manpage for 'xl' documents an option to force a block device to be released even if the domain to which it is attached does not co-operate. This option, however, is not implemented. This patch implements the option.
NOTE: The documentation is also adjusted since the normal positioning of
options is before compulsory parameters. It is also noted that use of the --force option may lead to a guest crash.Signed-off-by Paul Durrant <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>--- docs/man/xl.1.pod.in | 4 ++-- tools/xl/xl_block.c | 21 ++++++++++++++++----- tools/xl/xl_cmdtable.c | 3 ++- 3 files changed, 20 insertions(+), 8 deletions(-)docs/man/xl.1.pod.in +1
-1@@ -1389,7 +1389,7 @@ Note that only PV block devices are supported by block-attach. Requests to attach emulated devices (eg, vdev=hdc) will result in only the PV view being available to the guest. -=item B<block-detach> I<domain-id> I<devid> [I<OPTIONS>] +=item B<block-detach> [I<OPTIONS>] I<domain-id> I<devid> Detach a domain's virtual block device. I<devid> may be the symbolic name or the numeric device id given to the device by domain 0. You
docs/man/xl.1.pod.in B<OPTIONS> · line 1409
Quoted 5 lines
docs/man/xl.1.pod.in +1
-1@@ -1406,7 +1406,7 @@ B<OPTIONS> =item B<--force> If this parameter is specified the device will be forcefully detached, which -may cause IO errors in the domain. +may cause IO errors in the domain and possibly a guest crash
Missing "." at the end. This can be fixed while committing.
PATCH 2/2 libxl: do not automatically force detach of block devices
In reply to Paul DurrantFrom: Paul Durrant <[email protected]>
The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour.
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>
--- tools/libxl/libxl_device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/libxl/libxl_device.c +6 -3
@@ -1092,7 +1092,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,if (rc ==ERROR_TIMEDOUT && aodev->action ==LIBXL__DEVICE_ACTION_REMOVE && - !aodev->force) { + !aodev->force && + aodev->dev->kind !=LIBXL__DEVICE_KIND_VBD ) {LOGD (DEBUG , aodev->dev->domid,"Timeout reached, initiating forced remove" ); aodev->force =1 ;libxl__initiate_device_generic_remove (egc, aodev);
@@ -1103,7 +1104,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,LOGD (ERROR , aodev->dev->domid,"unable to %s device with path %s" ,libxl__device_action_to_string (aodev->action),libxl__device_backend_path (gc, aodev->dev)); - goto out; +if (!aodev->force) + goto out; }device_hotplug (egc, aodev);
@@ -1319,7 +1321,8 @@ static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev)device_hotplug_clean (gc, aodev);/* Clean xenstore if it's a disconnection */ -if (aodev->action ==LIBXL__DEVICE_ACTION_REMOVE ) { +if (aodev->action ==LIBXL__DEVICE_ACTION_REMOVE && + (aodev->force || !aodev->rc)) { rc =libxl__device_destroy (gc, aodev->dev);if (!aodev->rc) aodev->rc = rc;
Signature · 1 line
2.20.1
Re: [PATCH 2/2] libxl: do not automatically force detach of block devices
Quoted 7 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour.
Won't this break cleanup on domain shutdown if the guest doesn't close the devices itself?
I think we need some special-casing on shutdown that keeps the current behavior on that case.
Quoted 15 lines
Signed-off-by Paul Durrant <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>--- tools/libxl/libxl_device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/libxl/libxl_device.c +0
-0
tools/libxl/libxl_device.c static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, · line 1096
Quoted 6 lines
tools/libxl/libxl_device.c +2
-1@@ -1092,7 +1092,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,if (rc ==ERROR_TIMEDOUT && aodev->action ==LIBXL__DEVICE_ACTION_REMOVE && - !aodev->force) { + !aodev->force && + aodev->dev->kind !=LIBXL__DEVICE_KIND_VBD ) {
Doing this differentiation for block only seems weird, we should treat all devices equally.
Thanks, Roger.
RE: [PATCH 2/2] libxl: do not automatically force detach of block devices
Quoted 11 lines
-----Original Message-----
From: Roger Pau Monné <[email protected]>
Sent: 04 September 2020 09:53
To: Paul Durrant <[email protected]>
Cc: [email protected]; Paul Durrant <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Anthony PERARD <[email protected]>
Subject: Re: [PATCH 2/2] libxl: do not automatically force detach of block devicesQuoted 2 lines · Paul Durrant
From: Paul Durrant <[email protected]>
Quoted 9 lines
Quoted 5 lines
The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour.
Won't this break cleanup on domain shutdown if the guest doesn't close the devices itself?
I don't think so... AFAIK that's a destroy i.e. it's always forced (since there's no way the guest can co-operate at the point).
Quoted 19 lines
I think we need some special-casing on shutdown that keeps the current behavior on that case.
Quoted 16 lines
Signed-off-by Paul Durrant <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>--- tools/libxl/libxl_device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/libxl/libxl_device.c +0
-0@@ -1092,7 +1092,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,
Quoted 9 lines
tools/libxl/libxl_device.c static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, · line 1096
Quoted 5 lines
tools/libxl/libxl_device.c +2
-1if (rc ==ERROR_TIMEDOUT && aodev->action ==LIBXL__DEVICE_ACTION_REMOVE && - !aodev->force) { + !aodev->force && + aodev->dev->kind !=LIBXL__DEVICE_KIND_VBD ) {Doing this differentiation for block only seems weird, we should treat all devices equally.
That is not how things are documented in the xl manpage though; block-detach is the only one to have a force option. I assume that was deliberate.
Paul
Quoted 1 line
Thanks, Roger.
Re: [PATCH 2/2] libxl: do not automatically force detach of block devices
Quoted 17 lines · Paul Durrant
Quoted 17 lines
-----Original Message-----
From: Roger Pau Monné <[email protected]>
Sent: 04 September 2020 09:53
To: Paul Durrant <[email protected]>
Cc: [email protected]; Paul Durrant <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Anthony PERARD <[email protected]>
Subject: Re: [PATCH 2/2] libxl: do not automatically force detach of block devicesQuoted 7 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour.
Quoted 5 lines
Quoted 3 lines
Won't this break cleanup on domain shutdown if the guest doesn't close the devices itself?
I don't think so... AFAIK that's a destroy i.e. it's always forced (since there's no way the guest can co-operate at the point).
Urgh, yes, sorry.
Quoted 29 lines
Quoted 19 lines
I think we need some special-casing on shutdown that keeps the current behavior on that case.
Quoted 16 lines
Signed-off-by Paul Durrant <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>--- tools/libxl/libxl_device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/libxl/libxl_device.c +0
-0@@ -1092,7 +1092,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,Quoted 9 lines
tools/libxl/libxl_device.c static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds, · line 1096
Quoted 5 lines
tools/libxl/libxl_device.c +2
-1if (rc ==ERROR_TIMEDOUT && aodev->action ==LIBXL__DEVICE_ACTION_REMOVE && - !aodev->force) { + !aodev->force && + aodev->dev->kind !=LIBXL__DEVICE_KIND_VBD ) {Doing this differentiation for block only seems weird, we should treat all devices equally.
Quoted 1 line
That is not how things are documented in the xl manpage though; block-detach is the only one to have a force option. I assume that was deliberate.
Oh right, that's weird. I guess removing a block device without guest cooperation will likely result in a guest crash, while the same it's not true for other devices.
Thanks, Roger.
Re: [PATCH 2/2] libxl: do not automatically force detach of block devices
In reply to Paul DurrantQuoted 9 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour.
Signed-off-by Paul Durrant <[email protected]>
I'm two-minded here.
On the one hand, special-casing VBD in libxl to conform to xl's behaviour seems wrong to me.
On the other hand, if we want to treat all devices the same in libxl, libxl should drop its force-removal behaviour all together, and the retry behaviour would need to be implemented in xl for all devices excepts for VBD. This requires a bit of code churn and, more importantly, changes how those device removal APIs behave. In the end this effort may not worth it.
If we go with the patch here, we should document this special case on libxl level somehow.
Anthony and Ian, do you have any opinion on this?
Wei.
Quoted 45 lines
---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Anthony PERARD <[email protected]>--- tools/libxl/libxl_device.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/libxl/libxl_device.c +6
-3@@ -1092,7 +1092,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,if (rc ==ERROR_TIMEDOUT && aodev->action ==LIBXL__DEVICE_ACTION_REMOVE && - !aodev->force) { + !aodev->force && + aodev->dev->kind !=LIBXL__DEVICE_KIND_VBD ) {LOGD (DEBUG , aodev->dev->domid,"Timeout reached, initiating forced remove" ); aodev->force =1 ;libxl__initiate_device_generic_remove (egc, aodev);@@ -1103,7 +1104,8 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,LOGD (ERROR , aodev->dev->domid,"unable to %s device with path %s" ,libxl__device_action_to_string (aodev->action),libxl__device_backend_path (gc, aodev->dev)); - goto out; +if (!aodev->force) + goto out; }device_hotplug (egc, aodev);@@ -1319,7 +1321,8 @@ static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev)device_hotplug_clean (gc, aodev);/* Clean xenstore if it's a disconnection */ -if (aodev->action ==LIBXL__DEVICE_ACTION_REMOVE ) { +if (aodev->action ==LIBXL__DEVICE_ACTION_REMOVE && + (aodev->force || !aodev->rc)) { rc =libxl__device_destroy (gc, aodev->dev);if (!aodev->rc) aodev->rc = rc;Signature · 1 line
2.20.1
Re: [PATCH 2/2] libxl: do not automatically force detach of block devices
Quoted 16 lines · Wei Liu
Quoted 9 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour.
Signed-off-by Paul Durrant <[email protected]>I'm two-minded here.
On the one hand, special-casing VBD in libxl to conform to xl's behaviour seems wrong to me.
Quoted 6 lines
On the other hand, if we want to treat all devices the same in libxl, libxl should drop its force-removal behaviour all together, and the retry behaviour would need to be implemented in xl for all devices excepts for VBD. This requires a bit of code churn and, more importantly, changes how those device removal APIs behave. In the end this effort may not worth it.
I would be worried about those changes, as we would likely have to also change libvirt or any other downstreams?
Quoted 4 lines
If we go with the patch here, we should document this special case on libxl level somehow.
Anthony and Ian, do you have any opinion on this?
Maybe a new function should be introduced instead, that attempts to remove a device gracefully and fail otherwise?
Then none of the current APIs would change, and xl could use this new function to handle VBD removal?
Roger.
Re: [PATCH 2/2] libxl: do not automatically force detach of block devices
Quoted 30 lines · Roger Pau Monné
Quoted 16 lines · Wei Liu
Quoted 9 lines · Paul Durrant
From: Paul Durrant <[email protected]>
The manpage for 'xl' documents that guest co-operation is required for a (non- forced) block-detach operation and that it may consequently fail. Currently, however, the implementation of generic device removal means that a time-out of a block-detach is being automatically re-tried with the force flag set rather than failing. This patch stops such behaviour.
Signed-off-by Paul Durrant <[email protected]>I'm two-minded here.
On the one hand, special-casing VBD in libxl to conform to xl's behaviour seems wrong to me.
Quoted 6 lines
On the other hand, if we want to treat all devices the same in libxl, libxl should drop its force-removal behaviour all together, and the retry behaviour would need to be implemented in xl for all devices excepts for VBD. This requires a bit of code churn and, more importantly, changes how those device removal APIs behave. In the end this effort may not worth it.
I would be worried about those changes, as we would likely have to also change libvirt or any other downstreams?
Quoted 3 lines
If we go with the patch here, we should document this special case on libxl level somehow.
Quoted 7 lines
Quoted 1 line
Anthony and Ian, do you have any opinion on this?
Maybe a new function should be introduced instead, that attempts to remove a device gracefully and fail otherwise?
Then none of the current APIs would change, and xl could use this new function to handle VBD removal?
This sounds fine to me.
Wei.
Quoted 2 lines
Roger.
Re: [PATCH 2/2] libxl: do not automatically force detach of block devices
Wei Liu writes ("Re: [PATCH 2/2] libxl: do not automatically force detach of block devices"):
Quoted 8 lines · Roger Pau Monné
Quoted 5 lines
Maybe a new function should be introduced instead, that attempts to remove a device gracefully and fail otherwise?
Then none of the current APIs would change, and xl could use this new function to handle VBD removal?
This sounds fine to me.
I agree.
If there is going to be different default policy for different devices it ought to be in xl, not libxl, but frankly I think this is an anomaly.
I suggest we have a new entrypoint that specifies the fallback behaviour explicitly. ISTM that there are three possible behaviours:
- fail if the guest does not cooperate
- fall back to force remove
- rip the device out immediately
The last of these would be useful only in rare situations. IDK if the length of the timeout (for the first two cases) ought to be a parameter too.
Ian.
Ping? Can I get a toolstack maintainer opinion on this?
Thanks,
Paul
Quoted 23 lines
-----Original Message-----
From: Paul Durrant <[email protected]>
Sent: 03 September 2020 11:06
To: [email protected]
Cc: Paul Durrant <[email protected]>
Subject: [PATCH 0/2] fix 'xl block-detach'From: Paul Durrant <[email protected]>
This series makes it behave as the documentation states it should
Paul Durrant (2):
xl: implement documented --force option for block-detach
libxl: do not automatically force detach of block devicesdocs/man/xl.1.pod.in | 4 ++-- tools/libxl/libxl_device.c | 9 ++++++--- tools/xl/xl_block.c | 21 ++++++++++++++++----- tools/xl/xl_cmdtable.c | 3 ++- 4 files changed, 26 insertions(+), 11 deletions(-)--
2.20.1
Quoted 1 line · Paul Durrant
Ping? Can I get a toolstack maintainer opinion on this?
This series landed in my @xen.org inbox just fine but I haven't got around reviewing it.
Wei.