@@ -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
@@ -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_safe_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 ? "safe_remove" : "destroy");
return 1;
}
libxl_device_disk_dispose(&disk);
@@ -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,