v4 Decouple block device removal from device removal
PATCH 3/3 Add qmp version of drive_unplug
In reply to Ryan Harper--- qmp-commands.hx | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-)
qmp-commands.hx +26 -0
@@ -338,6 +338,32 @@ Example: EQMP { + .name = "drive_unplug", + .args_type = "id:s", + .params = "device", + .help = "unplug block device", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_drive_unplug, + }, + +SQMP +drive unplug +---------- + +Unplug a block device. + +Arguments: + +- "id": the device's ID (json-string) + +Example: + +-> { "execute": "drive_unplug", "arguments": { "id": "drive-virtio-blk1" } } +<- { "return": {} } + +EQMP + + { .name = "cpu", .args_type = "index:i", .params = "index",
Signature · 1 line
1.6.3.3
PATCH 2/3 v2 Fix Block Hotplug race with drive_unplug()
In reply to Ryan HarperBlock hot unplug is racy since the guest is required to acknowlege the ACPI unplug event; this may not happen synchronously with the device removal command
This series aims to close a gap where by mgmt applications that assume the block resource has been removed without confirming that the guest has acknowledged the removal may re-assign the underlying device to a second guest leading to data leakage.
This series introduces a new montor command to decouple asynchornous device removal from restricting guest access to a block device. We do this by creating a new monitor command drive_unplug which maps to a bdrv_unplug() command which does a qemu_aio_flush; bdrv_flush() and bdrv_close(). Once complete, subsequent IO is rejected from the device and the guest will get IO errors but continue to function.
A subsequent device removal command can be issued to remove the device, to which the guest may or maynot respond, but as long as the unplugged bit is set, no IO will be sumbitted.
Changes since v1:
- Added qemu_aio_flush() before bdrv_flush() to wait on pending io
--- block.c | 7 +++++++ block.h | 1 + blockdev.c | 26 ++++++++++++++++++++++++++ blockdev.h | 1 + hmp-commands.hx | 15 +++++++++++++++ 5 files changed, 50 insertions(+), 0 deletions(-)
block.c +7 -0
@@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } } +void bdrv_unplug (BlockDriverState *bs) +{ +qemu_aio_flush (); +bdrv_flush (bs); +bdrv_close (bs); +} +int bdrv_is_removable (BlockDriverState *bs) {return bs->removable;
block.h +1 -0
@@ -171,6 +171,7 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error);BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read);void bdrv_set_removable (BlockDriverState *bs,int removable); +void bdrv_unplug (BlockDriverState *bs);int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);
blockdev.c +26 -0
@@ -610,3 +610,29 @@ int do_change_block(Monitor *mon, const char *device, }return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); } + +int do_drive_unplug (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +DriveInfo *dinfo; +BlockDriverState *bs; +const char *id; + +if (!qdict_haskey (qdict,"id" )) { +qerror_report (QERR_MISSING_PARAMETER ,"id" ); +return -1 ; + } + + id =qdict_get_str (qdict,"id" ); + dinfo =drive_get_by_id (id); +if (!dinfo) { +qerror_report (QERR_DEVICE_NOT_FOUND , id); +return -1 ; + } + +/* mark block device unplugged */ + bs = dinfo->bdrv; +bdrv_unplug (bs); + +return 0 ; +} +
blockdev.h +1 -0
@@ -52,5 +52,6 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data);int do_block_set_passwd (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt); +int do_drive_unplug (Monitor *mon,const QDict *qdict,QObject **ret_data);#endif
hmp-commands.hx +15 -0
@@ -68,6 +68,21 @@ Eject a removable medium (use -f to force it). ETEXI { + .name = "drive_unplug", + .args_type = "id:s", + .params = "device", + .help = "unplug block device", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_drive_unplug, + }, + +STEXI +@item unplug @var{device} +@findex unplug +Unplug block device. +ETEXI + + { .name = "change", .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]",
Signature · 1 line
1.6.3.3
cover v4 Decouple block device removal from device removal
This patch series decouples the detachment of a block device from the removal of the backing pci-device. Removal of a hotplugged pci device requires the guest to respond before qemu tears down the block device. In some cases, the guest may not respond leaving the guest with continued access to the block device.
The new monitor command, drive_unplug, will revoke a guests access to the block device independently of the removal of the pci device.
The first patch adds a new drive find method, the second patch implements the monitor command and block layer changes.
Changes since v3:
- Moved QMP command for drive_unplug() to separate patch
Changes since v2:
- Added QMP command for drive_unplug()
Changes since v1:
- CodingStyle fixes
- Added qemu_aio_flush() to bdrv_unplug()
PATCH 1/3 v2 Add drive_get_by_id
Add a function to find a drive by id string.
Changes since v1:
-Coding Style fix
--- blockdev.c | 13 +++++++++++++ blockdev.h | 1 + 2 files changed, 14 insertions(+), 0 deletions(-)
blockdev.c +13 -0
@@ -75,6 +75,19 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)return NULL ; } +DriveInfo *drive_get_by_id (const char *id) +{ +DriveInfo *dinfo; + + QTAILQ_FOREACH(dinfo, &drives, next) { +if (strcmp (id, dinfo->id)) { +continue ; + } +return dinfo; + } +return NULL ; +} +int drive_get_max_bus (BlockInterfaceType type) {int max_bus;
blockdev.h +1 -0
@@ -38,6 +38,7 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);int drive_get_max_bus (BlockInterfaceType type);void drive_uninit (DriveInfo *dinfo);DriveInfo *drive_get_by_blockdev (BlockDriverState *bs); +DriveInfo *drive_get_by_id (const char *id);QemuOpts *drive_add (const char *file,const char *fmt, ...)GCC_FMT_ATTR (2 ,3 );DriveInfo *drive_init (QemuOpts *arg,int default_to_scsi,int *fatal_error);
Signature · 1 line
1.6.3.3
Re: [Qemu-devel] [PATCH 1/3] v2 Add drive_get_by_id
Quoted 4 lines · Ryan Harper
Add a function to find a drive by id string.
Changes since v1:
-Coding Style fix
Recommend to put patch history below the --- line, so it doesn't get included in the commit message.
Quoted 5 lines
Signed-off-by Ryan Harper <[email protected]>--- blockdev.c | 13 +++++++++++++ blockdev.h | 1 + 2 files changed, 14 insertions(+), 0 deletions(-)
[...]
This effectively reverts commit dfb0acd8, which cleans up after commit f8b6cc00:
qdev: Decouple qdev_prop_drive from DriveInfo
Make the property point to BlockDriverState, cutting out the DriveInfo middleman. This prepares the ground for block devices that don't have a DriveInfo.
Currently all user-defined ones have a DriveInfo, because the only way to define one is -drive & friends (they go through drive_init()). DriveInfo is closely tied to -drive, and like -drive, it mixes information about host and guest part of the block device. I'm working towards a new way to define block devices, with clean host/guest separation, and I need to get DriveInfo out of the way for that.
Fortunately, the device models are perfectly happy with BlockDriverState, except for two places: ide_drive_initfn() and scsi_disk_initfn() need to check the DriveInfo for a serial number set with legacy -drive serial=... Use drive_get_by_blockdev() there.
Device model code should now use DriveInfo only when explicitly dealing with drives defined the old way, i.e. without -device.
I think your do_drive_unplug() could use bdrv_find() instead. More on that in my review of your PATCH 2/3.
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
In reply to Ryan HarperQuoted 36 lines · Ryan Harper
Block hot unplug is racy since the guest is required to acknowlege the ACPI unplug event; this may not happen synchronously with the device removal command
This series aims to close a gap where by mgmt applications that assume the block resource has been removed without confirming that the guest has acknowledged the removal may re-assign the underlying device to a second guest leading to data leakage.
This series introduces a new montor command to decouple asynchornous device removal from restricting guest access to a block device. We do this by creating a new monitor command
drive_unplugwhich maps to abdrv_unplug()command which does aqemu_aio_flush;bdrv_flush()andbdrv_close(). Once complete, subsequent IO is rejected from the device and the guest will get IO errors but continue to function.A subsequent device removal command can be issued to remove the device, to which the guest may or maynot respond, but as long as the unplugged bit is set, no IO will be sumbitted.
Changes since v1:
- Addedqemu_aio_flush()beforebdrv_flush()to wait on pending ioSigned-off-by Ryan Harper <[email protected]>--- block.c | 7 +++++++ block.h | 1 + blockdev.c | 26 ++++++++++++++++++++++++++ blockdev.h | 1 + hmp-commands.hx | 15 +++++++++++++++ 5 files changed, 50 insertions(+), 0 deletions(-)block.c +0
-0
block.c void bdrv_set_removable(BlockDriverState *bs, int removable) · line 1336
Quoted 9 lines
block.c +6
-0@@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } } +void bdrv_unplug (BlockDriverState *bs) +{ +qemu_aio_flush (); +bdrv_flush (bs); +bdrv_close (bs); +}
Stupid question: why doesn't bdrv_close() flush automatically?
And why do we have to flush here, but not before other uses of bdrv_close(), such as eject_device()?
Quoted 25 lines
block.c +1
-0+int bdrv_is_removable (BlockDriverState *bs) {return bs->removable;block.h +1
-0@@ -171,6 +171,7 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error);BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read);void bdrv_set_removable (BlockDriverState *bs,int removable); +void bdrv_unplug (BlockDriverState *bs);int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);blockdev.c +1
-0@@ -610,3 +610,29 @@ int do_change_block(Monitor *mon, const char *device, }return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); } +
blockdev.c int do_change_block(Monitor *mon, const char *device, · line 623
Quoted 10 lines
blockdev.c +10
-0+int do_drive_unplug (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +DriveInfo *dinfo; +BlockDriverState *bs; +const char *id; + +if (!qdict_haskey (qdict,"id" )) { +qerror_report (QERR_MISSING_PARAMETER ,"id" ); +return -1 ; + }
As Luiz pointed out, this check is redundant.
Quoted 5 lines
blockdev.c +5
-0+ + id =qdict_get_str (qdict,"id" ); + dinfo =drive_get_by_id (id); +if (!dinfo) { +qerror_report (QERR_DEVICE_NOT_FOUND , id);
blockdev.c int do_change_block(Monitor *mon, const char *device, · line 638
Quoted 10 lines
blockdev.c +10
-0+return -1 ; + } + +/* mark block device unplugged */ + bs = dinfo->bdrv; +bdrv_unplug (bs); + +return 0 ; +} +
What about:
const char *id = qdict_get_str(qdict, "id");
BlockDriverState *bs;
bs = bdrv_find(id);
if (!bs) {
qerror_report(QERR_DEVICE_NOT_FOUND, id);
return -1;
}
bdrv_unplug(bs);
return 0;Precedence: commit f8b6cc00 replaced uses of drive_get_by_id() by bdrv_find().
Quoted 21 lines
blockdev.h +1
-0@@ -52,5 +52,6 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data);int do_block_set_passwd (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt); +int do_drive_unplug (Monitor *mon,const QDict *qdict,QObject **ret_data);#endif hmp-commands.hx +2
-0@@ -68,6 +68,21 @@ Eject a removable medium (use -f to force it). ETEXI { + .name = "drive_unplug", + .args_type = "id:s",
hmp-commands.hx Eject a removable medium (use -f to force it). · line 82
Quoted 10 lines
hmp-commands.hx +10
-0+ .params = "device", + .help = "unplug block device", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_drive_unplug, + }, + +STEXI +@item unplug @var{device} +@findex unplug +Unplug block device.
A bit terse, isn't it? What does it mean to unplug a block device? What's its observable effect on the guest? Does it look like disk gone completely south, perhaps?
Quoted 6 lines
hmp-commands.hx +3
-0+ETEXI + + { .name = "change", .args_type = "device:B,target:F,arg:s?", .params = "device filename [format]",
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
Quoted 42 lines · Markus Armbruster
Quoted 39 lines · Ryan Harper
Block hot unplug is racy since the guest is required to acknowlege the ACPI unplug event; this may not happen synchronously with the device removal command
This series aims to close a gap where by mgmt applications that assume the block resource has been removed without confirming that the guest has acknowledged the removal may re-assign the underlying device to a second guest leading to data leakage.
This series introduces a new montor command to decouple asynchornous device removal from restricting guest access to a block device. We do this by creating a new monitor command
drive_unplugwhich maps to abdrv_unplug()command which does aqemu_aio_flush;bdrv_flush()andbdrv_close(). Once complete, subsequent IO is rejected from the device and the guest will get IO errors but continue to function.A subsequent device removal command can be issued to remove the device, to which the guest may or maynot respond, but as long as the unplugged bit is set, no IO will be sumbitted.
Changes since v1:
- Addedqemu_aio_flush()beforebdrv_flush()to wait on pending ioSigned-off-by Ryan Harper<[email protected]>--- block.c | 7 +++++++ block.h | 1 + blockdev.c | 26 ++++++++++++++++++++++++++ blockdev.h | 1 + hmp-commands.hx | 15 +++++++++++++++ 5 files changed, 50 insertions(+), 0 deletions(-)block.c +0
-0@@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } }
Quoted 9 lines
block.c void bdrv_set_removable(BlockDriverState *bs, int removable)
Quoted 7 lines
block.c +6
-0+void bdrv_unplug (BlockDriverState *bs) +{ +qemu_aio_flush (); +bdrv_flush (bs); +bdrv_close (bs); +}Stupid question: why doesn't
bdrv_close()flush automatically?
I don't think it's a bad idea to do that but to the extent that the block API is designed after posix file I/O, close does not usually imply flush.
Quoted 3 lines
And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?
Good question. Kevin should also confirm, but looking at the code, I think flush() is needed before close. If there's a pending I/O event and you close before the I/O event is completed, you'll get a callback for completion against a bogus BlockDriverState.
I can't find anything in either raw-posix or the generic block layer that would mitigate this.
Regards,
Anthony Liguori
[Note cc: Michael]
Quoted 15 lines · Ryan Harper
This patch series decouples the detachment of a block device from the removal of the backing pci-device. Removal of a hotplugged pci device requires the guest to respond before qemu tears down the block device. In some cases, the guest may not respond leaving the guest with continued access to the block device.
The new monitor command,
drive_unplug, will revoke a guests access to the block device independently of the removal of the pci device.The first patch adds a new drive find method, the second patch implements the monitor command and block layer changes.
Changes since v3:
- Moved QMP command fordrive_unplug()to separate patch
Quoted 8 lines
Changes since v2:
- Added QMP command fordrive_unplug()Changes since v1:
- CodingStyle fixes
- Addedqemu_aio_flush()tobdrv_unplug()Signed-off-by Ryan Harper <[email protected]>
If I understand your patch correctly, the difference between your drive_unplug and my blockdev_del is as follows:
* drive_unplug forcefully severs the connection between the host part of the block device and its BlockDriverState. A shell of the host part remains, to be cleaned up later. You need forceful disconnect operation to be able to revoke access to an image whether the guest cooperates or not. Fair enough.
* blockdev_del deletes a host part. My current version fails when the host part is in use. I patterned that after netdev_del, which used to work that way, until commit 2ffcb18d:
Make netdev_del delete the netdev even when it's in use
To hot-unplug guest and host part of a network device, you do:
device_del NIC-ID
netdev_del NETDEV-ID
For PCI devices, device_del merely tells ACPI to unplug the device. The device goes away for real only after the guest processed the ACPI unplug event.
You have to wait until then (e.g. by polling info pci) before you can unplug the netdev. Not good.
Fix by removing the "in use" check from do_netdev_del(). Deleting a netdev while it's in use is safe; packets simply get routed to the bit bucket.
Isn't this the very same problem that's behind your drive_unplug?
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Even if your drive_unplug shouldn't fit in that set, we might want it as a stop-gap. Depends on how urgent the need for it is. Yet another special-purpose command to be deprecated later.
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
In reply to Anthony LiguoriAm 29.10.2010 16:15, schrieb Anthony Liguori:
Quoted 20 lines · Markus Armbruster
Quoted 9 lines
Quoted 8 lines · Ryan Harper
block.c +0
-0@@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } }Quoted 9 lines
block.c void bdrv_set_removable(BlockDriverState *bs, int removable)
Quoted 7 lines
block.c +6
-0+void bdrv_unplug (BlockDriverState *bs) +{ +qemu_aio_flush (); +bdrv_flush (bs); +bdrv_close (bs); +}Stupid question: why doesn't
bdrv_close()flush automatically?
Quoted 3 lines
I don't think it's a bad idea to do that but to the extent that the block API is designed after posix file I/O, close does not usually imply flush.
I don't think it really resembles POSIX. More or less the only thing they have in common is that both provide open, read, write and close, which is something that probably any API for file accesses provides.
The operation you're talking about here is bdrv_flush/fsync that is not implied by a POSIX close?
Quoted 11 lines
Quoted 3 lines
And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?Good question. Kevin should also confirm, but looking at the code, I think
flush()is needed before close. If there's a pending I/O event and you close before the I/O event is completed, you'll get a callback for completion against a bogus BlockDriverState.I can't find anything in either raw-posix or the generic block layer that would mitigate this.
I'm not aware of anything either. This is what qemu_aio_flush would do.
It seems reasonable to me to call both qemu_aio_flush and bdrv_flush in bdrv_close. We probably don't really need to call bdrv_flush to operate correctly, but it can't hurt and bdrv_close shouldn't happen that often anyway.
Kevin
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
Quoted 29 lines · Kevin Wolf
Am 29.10.2010 16:15, schrieb Anthony Liguori:
Quoted 23 lines · Markus Armbruster
Quoted 11 lines
Quoted 8 lines · Ryan Harper
block.c +0
-0@@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } }Quoted 11 lines
block.c void bdrv_set_removable(BlockDriverState *bs, int removable) · line 1338
Quoted 8 lines
block.c +6
-0+void bdrv_unplug (BlockDriverState *bs) +{ +qemu_aio_flush (); +bdrv_flush (bs); +bdrv_close (bs); +}Stupid question: why doesn't
bdrv_close()flush automatically?Quoted 4 lines
I don't think it's a bad idea to do that but to the extent that the block API is designed after posix file I/O, close does not usually imply flush.
Quoted 7 lines
I don't think it really resembles POSIX. More or less the only thing they have in common is that both provide open, read, write and close, which is something that probably any API for file accesses provides.
The operation you're talking about here is bdrv_flush/fsync that is not implied by a POSIX close?
Yes. But I think for the purposes of this patch, a bdrv_cancel_all() would be just as good. The intention is to eliminate pending I/O requests, the fsync is just a side effect.
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?Quoted 8 lines
Good question. Kevin should also confirm, but looking at the code, I think
flush()is needed before close. If there's a pending I/O event and you close before the I/O event is completed, you'll get a callback for completion against a bogus BlockDriverState.I can't find anything in either raw-posix or the generic block layer that would mitigate this.
Quoted 7 lines
I'm not aware of anything either. This is what
qemu_aio_flushwould do.It seems reasonable to me to call both
qemu_aio_flushandbdrv_flushinbdrv_close. We probably don't really need to callbdrv_flushto operate correctly, but it can't hurt andbdrv_closeshouldn't happen that often anyway.
I agree. Re: qemu_aio_flush, we have to wait for it to complete which gets a little complicated in bdrv_close(). I think it would be better to make bdrv_flush() call bdrv_aio_flush() if an explicit bdrv_flush method isn't provided. Something like the attached (still need to test).
Does that seem reasonable?
Regards,
Anthony Liguori
Quoted 4 lines
Kevin
From
86bf3c9eb5ce43280224f9271a4ad016b0dd3fb1Mon Sep 17 00:00:00 2001
From: Anthony Liguori <[email protected]>
Date: Fri, 29 Oct 2010 09:36:53 -0500
Subject: [PATCH 1/2] block: make bdrv_flush() fall back to bdrv_aio_flush
block.c +38 -1
@@ -1453,14 +1453,51 @@ const char *bdrv_get_device_name(BlockDriverState *bs)return bs->device_name; } +static void bdrv_flush_em_cb (void *opaque,int ret) +{ +int *pcomplete = opaque; + *pcomplete =1 ; +} + +static void bdrv_flush_em (BlockDriverState *bs) +{ +int complete =0 ; +BlockDriverAIOCB *acb; + +if (!bs->drv->bdrv_aio_flush) { +return ; + } + +async_context_push (); + + acb = bs->drv->bdrv_aio_flush (bs, bdrv_flush_em_cb, &complete); +if (!acb) { + goto out; + } + +while (!complete) { +qemu_aio_wait (); + } + +out: +async_context_pop (); +} +void bdrv_flush (BlockDriverState *bs) {if (bs->open_flags &BDRV_O_NO_FLUSH ) {return ; } -if (bs->drv && bs->drv->bdrv_flush) +if (!bs->drv) { +return ; + } + +if (bs->drv->bdrv_flush) { bs->drv->bdrv_flush (bs); + }else { +bdrv_flush_em (bs); + } }void bdrv_flush_all (void )
Signature · 1 line
1.7.0.4
Quoted 1 line
From
094049974796ddf78ee2f1541bffa40fe1176a1aMon Sep 17 00:00:00 2001
From: Anthony Liguori <[email protected]>
Date: Fri, 29 Oct 2010 09:37:25 -0500
Subject: [PATCH 2/2] block: add bdrv_flush to bdrv_close
To ensure that there are no pending completions before destroying a block device.
block.c +2 -0
@@ -644,6 +644,8 @@ unlink_and_fail:void bdrv_close (BlockDriverState *bs) {if (bs->drv) { +bdrv_flush (bs); +if (bs == bs_snapshots) { bs_snapshots =NULL ; }
Signature · 1 line
1.7.0.4
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
Am 29.10.2010 16:40, schrieb Anthony Liguori:
Quoted 10 lines · Kevin Wolf
Quoted 9 lines
Am 29.10.2010 16:15, schrieb Anthony Liguori:
Quoted 4 lines
I don't think it's a bad idea to do that but to the extent that the block API is designed after posix file I/O, close does not usually imply flush.
I don't think it really resembles POSIX. More or less the only thing they have in common is that both provide open, read, write and close, which is something that probably any API for file accesses provides.
Quoted 7 lines
Quoted 3 lines
The operation you're talking about here is bdrv_flush/fsync that is not implied by a POSIX close?
Yes. But I think for the purposes of this patch, a
bdrv_cancel_all()would be just as good. The intention is to eliminate pending I/O requests, the fsync is just a side effect.
Well, if I'm not mistaken, bdrv_flush would provide only this side effect and not the semantics that you're really looking for. This is why I suggested adding both bdrv_flush and qemu_aio_flush. We could probably introduce a qemu_aio_flush variant that flushes only one BlockDriverState - this is what you really want.
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?Quoted 8 lines
Good question. Kevin should also confirm, but looking at the code, I think
flush()is needed before close. If there's a pending I/O event and you close before the I/O event is completed, you'll get a callback for completion against a bogus BlockDriverState.I can't find anything in either raw-posix or the generic block layer that would mitigate this.
I'm not aware of anything either. This is what
qemu_aio_flushwould do.
Quoted 8 lines
Quoted 5 lines
It seems reasonable to me to call both
qemu_aio_flushandbdrv_flushinbdrv_close. We probably don't really need to callbdrv_flushto operate correctly, but it can't hurt andbdrv_closeshouldn't happen that often anyway.I agree. Re:
qemu_aio_flush, we have to wait for it to complete which gets a little complicated inbdrv_close().
qemu_aio_flush is the function that waits for requests to complete.
Quoted 5 lines
I think it would be better
to makebdrv_flush()callbdrv_aio_flush()if an explicitbdrv_flushmethod isn't provided. Something like the attached (still need to test).Does that seem reasonable?
I'm not sure why you want to introduce this emulation. Are there any drivers that implement bdrv_aio_flush, but not bdrv_flush? They are definitely broken.
Today, bdrv_aio_flush is emulated using bdrv_flush if the driver doesn't provide it explicitly.
I think this also means that your first patch would kill any drivers implementing neither bdrv_flush nor bdrv_aio_flush because they'd try to emulate the other function in an endless recursion.
And apart from that, as said above, bdrv_flush doesn't do the right thing anyway. ;-)
Kevin
Quoted 52 lines · Markus Armbruster
[Note cc: Michael]
Quoted 15 lines · Ryan Harper
This patch series decouples the detachment of a block device from the removal of the backing pci-device. Removal of a hotplugged pci device requires the guest to respond before qemu tears down the block device. In some cases, the guest may not respond leaving the guest with continued access to the block device.
The new monitor command,
drive_unplug, will revoke a guests access to the block device independently of the removal of the pci device.The first patch adds a new drive find method, the second patch implements the monitor command and block layer changes.
Changes since v3:
- Moved QMP command fordrive_unplug()to separate patchQuoted 8 lines
Changes since v2:
- Added QMP command fordrive_unplug()Changes since v1:
- CodingStyle fixes
- Addedqemu_aio_flush()tobdrv_unplug()Signed-off-by Ryan Harper <[email protected]>If I understand your patch correctly, the difference between your
drive_unplugand myblockdev_delis as follows:*
drive_unplugforcefully severs the connection between the host part of the block device and its BlockDriverState. A shell of the host part remains, to be cleaned up later. You need forceful disconnect operation to be able to revoke access to an image whether the guest cooperates or not. Fair enough.*
blockdev_deldeletes a host part. My current version fails when the host part is in use. I patterned that afternetdev_del, which used to work that way, until commit2ffcb18d:Make
netdev_deldelete the netdev even when it's in useTo hot-unplug guest and host part of a network device, you do:
device_delNIC-ID
netdev_delNETDEV-IDFor PCI devices,
device_delmerely tells ACPI to unplug the device. The device goes away for real only after the guest processed the ACPI unplug event.
Quoted 8 lines
You have to wait until then (e.g. by polling info pci) before you can unplug the netdev. Not good.
Fix by removing the "in use" check from
do_netdev_del(). Deleting a netdev while it's in use is safe; packets simply get routed to the bit bucket.Isn't this the very same problem that's behind your
drive_unplug?
Yes it is.
Quoted 4 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to device_del induced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do a blockdev_del() immediately after the device_del. What happens when we do:
device_del
ACPI to guestblockdev_del /* removes host-side device */ guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side block
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
Quoted 4 lines
Even if your
drive_unplugshouldn't fit in that set, we might want it as a stop-gap. Depends on how urgent the need for it is. Yet another special-purpose command to be deprecated later.
The fix is urgent; but I'm willing to spin a couple patches if it helps get this into better shape.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
In reply to Kevin WolfQuoted 52 lines · Kevin Wolf
Am 29.10.2010 16:40, schrieb Anthony Liguori:
Quoted 13 lines · Kevin Wolf
Quoted 12 lines
Am 29.10.2010 16:15, schrieb Anthony Liguori:
Quoted 5 lines
I don't think it's a bad idea to do that but to the extent that the block API is designed after posix file I/O, close does not usually imply flush.
I don't think it really resembles POSIX. More or less the only thing they have in common is that both provide open, read, write and close, which is something that probably any API for file accesses provides.
Quoted 8 lines
Quoted 4 lines
The operation you're talking about here is bdrv_flush/fsync that is not implied by a POSIX close?
Yes. But I think for the purposes of this patch, a
bdrv_cancel_all()would be just as good. The intention is to eliminate pending I/O requests, the fsync is just a side effect.Well, if I'm not mistaken,
bdrv_flushwould provide only this side effect and not the semantics that you're really looking for. This is why I suggested adding bothbdrv_flushandqemu_aio_flush. We could probably introduce aqemu_aio_flushvariant that flushes only one BlockDriverState - this is what you really want.Quoted 22 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?Quoted 9 lines
Good question. Kevin should also confirm, but looking at the code, I think
flush()is needed before close. If there's a pending I/O event and you close before the I/O event is completed, you'll get a callback for completion against a bogus BlockDriverState.I can't find anything in either raw-posix or the generic block layer that would mitigate this.
I'm not aware of anything either. This is what
qemu_aio_flushwould do.It seems reasonable to me to call both
qemu_aio_flushandbdrv_flushinbdrv_close. We probably don't really need to callbdrv_flushto operate correctly, but it can't hurt andbdrv_closeshouldn't happen that often anyway.
Quoted 5 lines
Quoted 3 lines
I agree. Re:
qemu_aio_flush, we have to wait for it to complete which gets a little complicated inbdrv_close().
qemu_aio_flushis the function that waits for requests to complete.
Please excuse me while my head explodes ;-)
I think we've got a bit of a problem.
We have:
1) bdrv_flush() - sends an fdatasync
2) bdrv_aio_flush() - sends an fdatasync using the thread pool
3) qemu_aio_flush() - waits for all pending aio requests to complete
But we use bdrv_aio_flush() to implement a barrier and we don't actually preserve those barrier semantics in the thread pool.
That is:
If I do:
bdrv_aio_write() -> Abdrv_aio_write() -> Bbdrv_aio_flush() -> C
This will get queued as three requests on the thread pool. (A) is a write, (B) is a write, and (C) is a fdatasync.
But if this gets picked up by three separate threads, the ordering isn't guaranteed. It might be C, B, A. So semantically, is bdrv_aio_flush() supposed to flush any *pending* writes or any *completed* writes? If it's the later, we're okay, but if it's the former, we're broken.
If it's supposed to flush any pending writes, then my patch series is correct in theory.
Regards,
Anthony Liguori
Quoted 22 lines
Quoted 6 lines
I think it would be better
to makebdrv_flush()callbdrv_aio_flush()if an explicitbdrv_flushmethod isn't provided. Something like the attached (still need to test).Does that seem reasonable?
I'm not sure why you want to introduce this emulation. Are there any drivers that implement
bdrv_aio_flush, but notbdrv_flush? They are definitely broken.Today,
bdrv_aio_flushis emulated usingbdrv_flushif the driver doesn't provide it explicitly.I think this also means that your first patch would kill any drivers implementing neither
bdrv_flushnorbdrv_aio_flushbecause they'd try to emulate the other function in an endless recursion.And apart from that, as said above,
bdrv_flushdoesn't do the right thing anyway. ;-)Kevin
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
In reply to Anthony LiguoriQuoted 53 lines · Anthony Liguori
Quoted 42 lines · Markus Armbruster
Quoted 39 lines · Ryan Harper
Block hot unplug is racy since the guest is required to acknowlege the ACPI unplug event; this may not happen synchronously with the device removal command
This series aims to close a gap where by mgmt applications that assume the block resource has been removed without confirming that the guest has acknowledged the removal may re-assign the underlying device to a second guest leading to data leakage.
This series introduces a new montor command to decouple asynchornous device removal from restricting guest access to a block device. We do this by creating a new monitor command
drive_unplugwhich maps to abdrv_unplug()command which does aqemu_aio_flush;bdrv_flush()andbdrv_close(). Once complete, subsequent IO is rejected from the device and the guest will get IO errors but continue to function.A subsequent device removal command can be issued to remove the device, to which the guest may or maynot respond, but as long as the unplugged bit is set, no IO will be sumbitted.
Changes since v1:
- Addedqemu_aio_flush()beforebdrv_flush()to wait on pending ioSigned-off-by Ryan Harper<[email protected]>--- block.c | 7 +++++++ block.h | 1 + blockdev.c | 26 ++++++++++++++++++++++++++ blockdev.h | 1 + hmp-commands.hx | 15 +++++++++++++++ 5 files changed, 50 insertions(+), 0 deletions(-)block.c +0
-0@@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } }Quoted 9 lines
block.c void bdrv_set_removable(BlockDriverState *bs, int removable)
Quoted 7 lines
block.c +6
-0+void bdrv_unplug (BlockDriverState *bs) +{ +qemu_aio_flush (); +bdrv_flush (bs); +bdrv_close (bs); +}Stupid question: why doesn't
bdrv_close()flush automatically?
Quoted 3 lines
I don't think it's a bad idea to do that but to the extent that the block API is designed after posix file I/O, close does not usually imply flush.
There is no flush() in POSIX file I/O. There is fsync().
There is fflush() in stdio. fclose() flushes automatically. Flushing only affects stdio buffers, it doesn't imply fsync().
Based on that, a reasonable programmer could be led to believe that bdrv_close() flushes automatically, and flushing doesn't fsync().
Quoted 11 lines
Quoted 3 lines
And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?Good question. Kevin should also confirm, but looking at the code, I think
flush()is needed before close. If there's a pending I/O event and you close before the I/O event is completed, you'll get a callback for completion against a bogus BlockDriverState.I can't find anything in either raw-posix or the generic block layer that would mitigate this.
Then bdrv_close() is too hard to use.
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
In reply to Anthony LiguoriAm 29.10.2010 17:28, schrieb Anthony Liguori:
Quoted 65 lines · Kevin Wolf
Quoted 52 lines
Am 29.10.2010 16:40, schrieb Anthony Liguori:
Quoted 13 lines · Kevin Wolf
Quoted 12 lines
Am 29.10.2010 16:15, schrieb Anthony Liguori:
Quoted 5 lines
I don't think it's a bad idea to do that but to the extent that the block API is designed after posix file I/O, close does not usually imply flush.
I don't think it really resembles POSIX. More or less the only thing they have in common is that both provide open, read, write and close, which is something that probably any API for file accesses provides.
Quoted 8 lines
Quoted 4 lines
The operation you're talking about here is bdrv_flush/fsync that is not implied by a POSIX close?
Yes. But I think for the purposes of this patch, a
bdrv_cancel_all()would be just as good. The intention is to eliminate pending I/O requests, the fsync is just a side effect.Well, if I'm not mistaken,
bdrv_flushwould provide only this side effect and not the semantics that you're really looking for. This is why I suggested adding bothbdrv_flushandqemu_aio_flush. We could probably introduce aqemu_aio_flushvariant that flushes only one BlockDriverState - this is what you really want.Quoted 22 lines
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?Quoted 9 lines
Good question. Kevin should also confirm, but looking at the code, I think
flush()is needed before close. If there's a pending I/O event and you close before the I/O event is completed, you'll get a callback for completion against a bogus BlockDriverState.I can't find anything in either raw-posix or the generic block layer that would mitigate this.
I'm not aware of anything either. This is what
qemu_aio_flushwould do.It seems reasonable to me to call both
qemu_aio_flushandbdrv_flushinbdrv_close. We probably don't really need to callbdrv_flushto operate correctly, but it can't hurt andbdrv_closeshouldn't happen that often anyway.Quoted 5 lines
Quoted 3 lines
I agree. Re:
qemu_aio_flush, we have to wait for it to complete which gets a little complicated inbdrv_close().
qemu_aio_flushis the function that waits for requests to complete.Please excuse me while my head explodes ;-)
I think we've got a bit of a problem.
We have:
Quoted 8 lines
1)
bdrv_flush()- sends an fdatasync2)
bdrv_aio_flush()- sends an fdatasync using the thread pool3)
qemu_aio_flush()- waits for all pending aio requests to completeBut we use
bdrv_aio_flush()to implement a barrier and we don't actually preserve those barrier semantics in the thread pool.
Not really. We use it to implement flush commands, which I think don't necessarily constitute a barrier by themselves.
Quoted 8 lines
That is:
If I do:
bdrv_aio_write()-> Abdrv_aio_write()-> Bbdrv_aio_flush()-> C
Quoted 7 lines
This will get queued as three requests on the thread pool. (A) is a write, (B) is a write, and (C) is a fdatasync.
But if this gets picked up by three separate threads, the ordering isn't guaranteed. It might be C, B, A. So semantically, is
bdrv_aio_flush()supposed to flush any *pending* writes or any *completed* writes? If it's the later, we're okay, but if it's the former, we're broken.
Right, so don't do that. ;-)
bdrv_aio_flush, as I understand it, is meant to flush only completed writes. We've had this discussion before and if I understood right, this is also how real hardware works generally. So to get barrier semantics you as an OS need to flush your queue, i.e. you wait for A and B to complete before you issue C.
Christoph should be able to detail on this.
Kevin
Quoted 75 lines · Ryan Harper
Quoted 52 lines · Markus Armbruster
[Note cc: Michael]
Quoted 15 lines · Ryan Harper
This patch series decouples the detachment of a block device from the removal of the backing pci-device. Removal of a hotplugged pci device requires the guest to respond before qemu tears down the block device. In some cases, the guest may not respond leaving the guest with continued access to the block device.
The new monitor command,
drive_unplug, will revoke a guests access to the block device independently of the removal of the pci device.The first patch adds a new drive find method, the second patch implements the monitor command and block layer changes.
Changes since v3:
- Moved QMP command fordrive_unplug()to separate patchQuoted 8 lines
Changes since v2:
- Added QMP command fordrive_unplug()Changes since v1:
- CodingStyle fixes
- Addedqemu_aio_flush()tobdrv_unplug()Signed-off-by Ryan Harper <[email protected]>If I understand your patch correctly, the difference between your
drive_unplugand myblockdev_delis as follows:*
drive_unplugforcefully severs the connection between the host part of the block device and its BlockDriverState. A shell of the host part remains, to be cleaned up later. You need forceful disconnect operation to be able to revoke access to an image whether the guest cooperates or not. Fair enough.*
blockdev_deldeletes a host part. My current version fails when the host part is in use. I patterned that afternetdev_del, which used to work that way, until commit2ffcb18d:Make
netdev_deldelete the netdev even when it's in useTo hot-unplug guest and host part of a network device, you do:
device_delNIC-ID
netdev_delNETDEV-IDFor PCI devices,
device_delmerely tells ACPI to unplug the device. The device goes away for real only after the guest processed the ACPI unplug event.Quoted 8 lines
You have to wait until then (e.g. by polling info pci) before you can unplug the netdev. Not good.
Fix by removing the "in use" check from
do_netdev_del(). Deleting a netdev while it's in use is safe; packets simply get routed to the bit bucket.Isn't this the very same problem that's behind your
drive_unplug?Yes it is.
Quoted 4 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:
Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */
Fails in my tree, because the blockdev's still in use. See below.
Quoted 6 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockThat may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part. device_del should undo device_add. {block,net,char}dev_{add,del} should be similarly paired.
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive with drive_add, it gets auto-deleted, but if you use blockdev_add, it stays around.
Quoted 6 lines
Quoted 3 lines
Even if your
drive_unplugshouldn't fit in that set, we might want it as a stop-gap. Depends on how urgent the need for it is. Yet another special-purpose command to be deprecated later.The fix is urgent; but I'm willing to spin a couple patches if it helps get this into better shape.
Can we agree on a common solution for block and net? That's why I cc'ed Michael.
Currently, we have two different ways:
* The netdev way: "del" always succeeds
How can it succeed if the host part is in use?
If all device models are prepared to deal with a missing host part, we can delete it right away.
Else, we need to replace it with a suitable zombie, which is auto-deleted when it goes out of use. Such zombies are not be visible elsewhere, in particular, the ID becomes available immediately.
* The unplug way: "del" fails while in use, "unplug" always succeeds
Feels a bit cleaner to me. But changing netdev_del might not be acceptable.
Either way works for me as an user interface. But I'd rather not have both.
Next, we need to consider how to integrate this with the automatic deletion of drives on qdev destruction. That's too late for unplug, we want that right in device_del. I'd leave the stupid automatic delete where it is now, in qdev destruction. The C API need unplug and delete separate for that.
Regardless of the way we choose, we need to think very clearly on how exactly device models should behave when their host part is missing or a zombie, and how that behavior appears in the guest.
For net, making it look exactly like a yanked out network cable would make sense to me.
What about block?
Quoted 64 lines · Markus Armbruster
Quoted 52 lines · Ryan Harper
Quoted 29 lines · Markus Armbruster
[Note cc: Michael]
Ryan Harper <[email protected]> writes:
If I understand your patch correctly, the difference between your
drive_unplugand myblockdev_delis as follows:*
drive_unplugforcefully severs the connection between the host part of the block device and its BlockDriverState. A shell of the host part remains, to be cleaned up later. You need forceful disconnect operation to be able to revoke access to an image whether the guest cooperates or not. Fair enough.*
blockdev_deldeletes a host part. My current version fails when the host part is in use. I patterned that afternetdev_del, which used to work that way, until commit2ffcb18d:Make
netdev_deldelete the netdev even when it's in useTo hot-unplug guest and host part of a network device, you do:
device_delNIC-ID
netdev_delNETDEV-IDFor PCI devices,
device_delmerely tells ACPI to unplug the device. The device goes away for real only after the guest processed the ACPI unplug event.Quoted 8 lines
You have to wait until then (e.g. by polling info pci) before you can unplug the netdev. Not good.
Fix by removing the "in use" check from
do_netdev_del(). Deleting a netdev while it's in use is safe; packets simply get routed to the bit bucket.Isn't this the very same problem that's behind your
drive_unplug?Yes it is.
Quoted 4 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side block
Quoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.
Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.
But what to do about the case where we're doing drive_add and then a device_del() That's the urgent situation that needs to be resolved.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Even if your
drive_unplugshouldn't fit in that set, we might want it as a stop-gap. Depends on how urgent the need for it is. Yet another special-purpose command to be deprecated later.The fix is urgent; but I'm willing to spin a couple patches if it helps get this into better shape.
Can we agree on a common solution for block and net? That's why I cc'ed Michael.
I didn't see a good way to have block behave the same as net; though I do agree that it would be good to have this be common, long term.
Quoted 29 lines
Currently, we have two different ways:
* The netdev way: "del" always succeeds
How can it succeed if the host part is in use?
If all device models are prepared to deal with a missing host part, we can delete it right away.
Else, we need to replace it with a suitable zombie, which is auto-deleted when it goes out of use. Such zombies are not be visible elsewhere, in particular, the ID becomes available immediately.
* The unplug way: "del" fails while in use, "unplug" always succeeds
Feels a bit cleaner to me. But changing
netdev_delmight not be acceptable.Either way works for me as an user interface. But I'd rather not have both.
Next, we need to consider how to integrate this with the automatic deletion of drives on qdev destruction. That's too late for unplug, we want that right in
device_del. I'd leave the stupid automatic delete where it is now, in qdev destruction. The C API need unplug and delete separate for that.
Quoted 8 lines
Regardless of the way we choose, we need to think very clearly on how exactly device models should behave when their host part is missing or a zombie, and how that behavior appears in the guest.
For net, making it look exactly like a yanked out network cable would make sense to me.
What about block?
It seems to me that for block it's like cdrom with no disk, floppy with no media, hard disk that's gone bad. I think we we throw EIO back; it's handled gracefully enough. This is what happens when you do a drive_unplug with my patch; the application using the device gets IO errors. That's expected if a drive were to suddently fail (which is what this looks like). And certainly there is some responsibility at the mgmt console to ensure you're not unplugging a drive that you are currently using.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
In reply to Kevin WolfQuoted 8 lines · Kevin Wolf
Quoted 8 lines
I think we've got a bit of a problem.
We have:
1)
bdrv_flush()- sends an fdatasync2)
bdrv_aio_flush()- sends an fdatasync using the thread pool
Quoted 7 lines
Quoted 4 lines
3)
qemu_aio_flush()- waits for all pending aio requests to completeBut we use
bdrv_aio_flush()to implement a barrier and we don't actually preserve those barrier semantics in the thread pool.Not really. We use it to implement flush commands, which I think don't necessarily constitute a barrier by themselves.
Yes. Just as with normal disks qemu has absolutely no concept of I/O barriers. I/O barriers is an abstraction inside the Linux kernel that we fortunately finally got rid of.
Qemu just gets a cache flush command from the guest and executes it. Usuaully asynchronously as synchronous block I/O with a single outstanding request is not very performant. The filesystem in the guest handles the ordering around it.
Quoted 2 lines
bdrv_aio_flush, as I understand it, is meant to flush only completed writes.
Exactly. The guest OS tracks writes and only issues a cache flush if all I/Os it wants to see flushes have been ACKed by the storage hardware / qemu.
Re: [Qemu-devel] [PATCH 2/3] v2 Fix Block Hotplug race with drive_unplug()
In reply to Markus ArmbrusterQuoted 122 lines · Markus Armbruster
Quoted 36 lines · Ryan Harper
Block hot unplug is racy since the guest is required to acknowlege the ACPI unplug event; this may not happen synchronously with the device removal command
This series aims to close a gap where by mgmt applications that assume the block resource has been removed without confirming that the guest has acknowledged the removal may re-assign the underlying device to a second guest leading to data leakage.
This series introduces a new montor command to decouple asynchornous device removal from restricting guest access to a block device. We do this by creating a new monitor command
drive_unplugwhich maps to abdrv_unplug()command which does aqemu_aio_flush;bdrv_flush()andbdrv_close(). Once complete, subsequent IO is rejected from the device and the guest will get IO errors but continue to function.A subsequent device removal command can be issued to remove the device, to which the guest may or maynot respond, but as long as the unplugged bit is set, no IO will be sumbitted.
Changes since v1:
- Addedqemu_aio_flush()beforebdrv_flush()to wait on pending ioSigned-off-by Ryan Harper <[email protected]>--- block.c | 7 +++++++ block.h | 1 + blockdev.c | 26 ++++++++++++++++++++++++++ blockdev.h | 1 + hmp-commands.hx | 15 +++++++++++++++ 5 files changed, 50 insertions(+), 0 deletions(-)block.c +0
-0block.c void bdrv_set_removable(BlockDriverState *bs, int removable) · line 1336
Quoted 9 lines
block.c +6
-0@@ -1328,6 +1328,13 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } } +void bdrv_unplug (BlockDriverState *bs) +{ +qemu_aio_flush (); +bdrv_flush (bs); +bdrv_close (bs); +}Stupid question: why doesn't
bdrv_close()flush automatically?And why do we have to flush here, but not before other uses of
bdrv_close(), such aseject_device()?Quoted 25 lines
block.c +1
-0+int bdrv_is_removable (BlockDriverState *bs) {return bs->removable;block.h +1
-0@@ -171,6 +171,7 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error);BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read);void bdrv_set_removable (BlockDriverState *bs,int removable); +void bdrv_unplug (BlockDriverState *bs);int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);blockdev.c +1
-0@@ -610,3 +610,29 @@ int do_change_block(Monitor *mon, const char *device, }return monitor_read_bdrv_key_start (mon, bs,NULL ,NULL ); } +blockdev.c int do_change_block(Monitor *mon, const char *device, · line 623
Quoted 10 lines
blockdev.c +10
-0+int do_drive_unplug (Monitor *mon,const QDict *qdict,QObject **ret_data) +{ +DriveInfo *dinfo; +BlockDriverState *bs; +const char *id; + +if (!qdict_haskey (qdict,"id" )) { +qerror_report (QERR_MISSING_PARAMETER ,"id" ); +return -1 ; + }As Luiz pointed out, this check is redundant.
Quoted 5 lines
blockdev.c +5
-0+ + id =qdict_get_str (qdict,"id" ); + dinfo =drive_get_by_id (id); +if (!dinfo) { +qerror_report (QERR_DEVICE_NOT_FOUND , id);blockdev.c int do_change_block(Monitor *mon, const char *device, · line 638
Quoted 10 lines
blockdev.c +10
-0+return -1 ; + } + +/* mark block device unplugged */ + bs = dinfo->bdrv; +bdrv_unplug (bs); + +return 0 ; +} +What about:
const char *id = qdict_get_str(qdict, "id"); BlockDriverState *bs; bs = bdrv_find(id); if (!bs) { qerror_report(QERR_DEVICE_NOT_FOUND, id); return -1; } bdrv_unplug(bs); return 0;
Quoted 2 lines
Precedence: commit
f8b6cc00replaced uses ofdrive_get_by_id()bybdrv_find().
That works out nicely; and I can drop the drive_get_by_id() patch as well. Thanks.
Quoted 28 lines
Quoted 28 lines
blockdev.h +1
-0@@ -52,5 +52,6 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data);int do_block_set_passwd (Monitor *mon,const QDict *qdict,QObject **ret_data);int do_change_block (Monitor *mon,const char *device,const char *filename,const char *fmt); +int do_drive_unplug (Monitor *mon,const QDict *qdict,QObject **ret_data);#endif hmp-commands.hx +8
-0@@ -68,6 +68,21 @@ Eject a removable medium (use -f to force it). ETEXI { + .name = "drive_unplug", + .args_type = "id:s", + .params = "device", + .help = "unplug block device", + .user_print = monitor_user_noop, + .mhandler.cmd_new = do_drive_unplug, + }, +
Quoted 8 lines
hmp-commands.hx Eject a removable medium (use -f to force it). · line 82
Quoted 4 lines
hmp-commands.hx +4
-0+STEXI +@item unplug @var{device} +@findex unplug +Unplug block device.A bit terse, isn't it? What does it mean to unplug a block device? What's its observable effect on the guest? Does it look like disk gone completely south, perhaps?
Well, most of the info in here is rather sparse as well, so there is clear precedence for it's terseness; I'll be a bit more verbose in the next version.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 10 lines · Markus Armbruster
C.
FOO_unplugYou got a patch for
drive_unplug.Need
netdev_unplug.By the way, I hate "unplug", because it suggests relation to hot unplug. What about "disconnect"?
Any preferences?
This implies that both parts stay on, just disconnected. This is really surprise removal. While we are at it, can we handle this generically as removal of devices?
Signature · 1 line
MST
Quoted 72 lines · Ryan Harper
Quoted 64 lines · Markus Armbruster
Quoted 52 lines · Ryan Harper
Quoted 29 lines · Markus Armbruster
[Note cc: Michael]
Ryan Harper <[email protected]> writes:
If I understand your patch correctly, the difference between your
drive_unplugand myblockdev_delis as follows:*
drive_unplugforcefully severs the connection between the host part of the block device and its BlockDriverState. A shell of the host part remains, to be cleaned up later. You need forceful disconnect operation to be able to revoke access to an image whether the guest cooperates or not. Fair enough.*
blockdev_deldeletes a host part. My current version fails when the host part is in use. I patterned that afternetdev_del, which used to work that way, until commit2ffcb18d:Make
netdev_deldelete the netdev even when it's in useTo hot-unplug guest and host part of a network device, you do:
device_delNIC-ID
netdev_delNETDEV-IDFor PCI devices,
device_delmerely tells ACPI to unplug the device. The device goes away for real only after the guest processed the ACPI unplug event.Quoted 8 lines
You have to wait until then (e.g. by polling info pci) before you can unplug the netdev. Not good.
Fix by removing the "in use" check from
do_netdev_del(). Deleting a netdev while it's in use is safe; packets simply get routed to the bit bucket.Isn't this the very same problem that's behind your
drive_unplug?Yes it is.
Quoted 4 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockQuoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.
Quoted 8 lines
Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.But what to do about the case where we're doing
drive_addand then adevice_del()That's the urgent situation that needs to be resolved.
What's the exact problem we need to solve urgently?
Is it "provide means to cut the connection to the host part immediately, even with an uncooperative guest"?
Does this need to be separate from device_del?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Even if your
drive_unplugshouldn't fit in that set, we might want it as a stop-gap. Depends on how urgent the need for it is. Yet another special-purpose command to be deprecated later.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The fix is urgent; but I'm willing to spin a couple patches if it helps get this into better shape.
Can we agree on a common solution for block and net? That's why I cc'ed Michael.
I didn't see a good way to have block behave the same as net; though I do agree that it would be good to have this be common, long term.
If we can't make them behave 100% the same, then the next best thing is to offer a preferred way to do things that works similarly enough to let users ignore the differences.
Possible preferred ways to revoke access to a host part:
A. device_del
Need to make device_del cut the connection right away instead of when the guest completes unplug.
device_del changes behavior. Any problems with that?
Not an option if we need "cut the connection" to be separate from device_del.
B. FOO_del
Got netdev_del.
Need drive_del. If drive is in use, replace it by a special "dead drive" without a device name (so the ID becomes available for new drives), then delete the original.
Wart: drive_del doesn't work reliably after device_del, because the drive is auto-deleted when the guest completes unplug. Not a problem for my blockdev_add/blockdev_del work-in-progress, because host parts created with blockdev_add don't auto-delete.
C. FOO_unplug
You got a patch for drive_unplug.
Need netdev_unplug.
By the way, I hate "unplug", because it suggests relation to hot unplug. What about "disconnect"?
Any preferences?
Quoted 37 lines
Quoted 28 lines
Currently, we have two different ways:
* The netdev way: "del" always succeeds
How can it succeed if the host part is in use?
If all device models are prepared to deal with a missing host part, we can delete it right away.
Else, we need to replace it with a suitable zombie, which is auto-deleted when it goes out of use. Such zombies are not be visible elsewhere, in particular, the ID becomes available immediately.
* The unplug way: "del" fails while in use, "unplug" always succeeds
Feels a bit cleaner to me. But changing
netdev_delmight not be acceptable.Either way works for me as an user interface. But I'd rather not have both.
Next, we need to consider how to integrate this with the automatic deletion of drives on qdev destruction. That's too late for unplug, we want that right in
device_del. I'd leave the stupid automatic delete where it is now, in qdev destruction. The C API need unplug and delete separate for that.Quoted 8 lines
Regardless of the way we choose, we need to think very clearly on how exactly device models should behave when their host part is missing or a zombie, and how that behavior appears in the guest.
For net, making it look exactly like a yanked out network cable would make sense to me.
What about block?
Quoted 8 lines
It seems to me that for block it's like cdrom with no disk, floppy with no media, hard disk that's gone bad. I think we we throw EIO back; it's handled gracefully enough. This is what happens when you do a
drive_unplugwith my patch; the application using the device gets IO errors. That's expected if a drive were to suddently fail (which is what this looks like). And certainly there is some responsibility at the mgmt console to ensure you're not unplugging a drive that you are currently using.
Total drive failure works for me.
"No media" is cute, but it's possible only for drives with removable media. I'd rather have all drives behave the same, whether their media is removable or not.
Am 02.11.2010 10:40, schrieb Markus Armbruster:
Quoted 23 lines
Quoted 12 lines · Ryan Harper
Quoted 10 lines · Markus Armbruster
Ryan Harper <[email protected]> writes:
Regardless of the way we choose, we need to think very clearly on how exactly device models should behave when their host part is missing or a zombie, and how that behavior appears in the guest.
For net, making it look exactly like a yanked out network cable would make sense to me.
What about block?
Quoted 8 lines
It seems to me that for block it's like cdrom with no disk, floppy with no media, hard disk that's gone bad. I think we we throw EIO back; it's handled gracefully enough. This is what happens when you do a
drive_unplugwith my patch; the application using the device gets IO errors. That's expected if a drive were to suddently fail (which is what this looks like). And certainly there is some responsibility at the mgmt console to ensure you're not unplugging a drive that you are currently using.
Quoted 5 lines
Total drive failure works for me.
"No media" is cute, but it's possible only for drives with removable media. I'd rather have all drives behave the same, whether their media is removable or not.
But I think we need some way to eject the medium without destroying the whole device. If you handle it as "device broken", you need another command for keeping the device, but ejecting the medium, unplugging the network cable, etc. We have "eject" for block today, but it needs a drive and not a blockdev (and I'm not even sure it really does what I'm thinking of, once again)
Kevin
Quoted 80 lines · Markus Armbruster
Quoted 78 lines · Ryan Harper
Quoted 64 lines · Markus Armbruster
Quoted 52 lines · Ryan Harper
Quoted 29 lines · Markus Armbruster
[Note cc: Michael]
Ryan Harper <[email protected]> writes:
If I understand your patch correctly, the difference between your
drive_unplugand myblockdev_delis as follows:*
drive_unplugforcefully severs the connection between the host part of the block device and its BlockDriverState. A shell of the host part remains, to be cleaned up later. You need forceful disconnect operation to be able to revoke access to an image whether the guest cooperates or not. Fair enough.*
blockdev_deldeletes a host part. My current version fails when the host part is in use. I patterned that afternetdev_del, which used to work that way, until commit2ffcb18d:Make
netdev_deldelete the netdev even when it's in useTo hot-unplug guest and host part of a network device, you do:
device_delNIC-ID
netdev_delNETDEV-IDFor PCI devices,
device_delmerely tells ACPI to unplug the device. The device goes away for real only after the guest processed the ACPI unplug event.Quoted 8 lines
You have to wait until then (e.g. by polling info pci) before you can unplug the netdev. Not good.
Fix by removing the "in use" check from
do_netdev_del(). Deleting a netdev while it's in use is safe; packets simply get routed to the bit bucket.Isn't this the very same problem that's behind your
drive_unplug?Yes it is.
Quoted 4 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockQuoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.
Quoted 7 lines
Quoted 2 lines
But what to do about the case where we're doing
drive_addand then adevice_del()That's the urgent situation that needs to be resolved.What's the exact problem we need to solve urgently?
Is it "provide means to cut the connection to the host part immediately, even with an uncooperative guest"?
Yes, need to ensure that if the mgmt layer (libvirt) has done what it believes should have disassociated the host block device from the guest, we want to ensure that the host block device is no longer accessible from the guest.
Quoted 2 lines
Does this need to be separate from
device_del?
no, it doesn't have to be. Honestly, I didn't see a clear way to do something like unplug early in the device_del because that's all pci device code which has no knowledge of host block devices; having it disconnect seemed like a layering violation.
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Even if your
drive_unplugshouldn't fit in that set, we might want it as a stop-gap. Depends on how urgent the need for it is. Yet another special-purpose command to be deprecated later.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The fix is urgent; but I'm willing to spin a couple patches if it helps get this into better shape.
Can we agree on a common solution for block and net? That's why I cc'ed Michael.
I didn't see a good way to have block behave the same as net; though I do agree that it would be good to have this be common, long term.
If we can't make them behave 100% the same, then the next best thing is to offer a preferred way to do things that works similarly enough to let users ignore the differences.
Quoted 8 lines
Possible preferred ways to revoke access to a host part:
A.
device_delNeed to make
device_delcut the connection right away instead of when the guest completes unplug.
device_delchanges behavior. Any problems with that?
I don't think so; current mgmt consumers assume a cooperative guest and don't handle an uncooperative one right now in the case where Selinux is disabled; so modifying this path to do a disconnect shouldn't be a problem.
Quoted 19 lines
Not an option if we need "cut the connection" to be separate from
device_del.B.
FOO_delGot
netdev_del.Need
drive_del. If drive is in use, replace it by a special "dead drive" without a device name (so the ID becomes available for new drives), then delete the original.Wart:
drive_deldoesn't work reliably afterdevice_del, because the drive is auto-deleted when the guest completes unplug. Not a problem for my blockdev_add/blockdev_del work-in-progress, because host parts created withblockdev_adddon't auto-delete.C.
FOO_unplug
Quoted 8 lines
You got a patch for
drive_unplug.Need
netdev_unplug.By the way, I hate "unplug", because it suggests relation to hot unplug. What about "disconnect"?
Any preferences?
disconnect is fine.
Quoted 47 lines
Quoted 38 lines
Quoted 29 lines
Currently, we have two different ways:
* The netdev way: "del" always succeeds
How can it succeed if the host part is in use?
If all device models are prepared to deal with a missing host part, we can delete it right away.
Else, we need to replace it with a suitable zombie, which is auto-deleted when it goes out of use. Such zombies are not be visible elsewhere, in particular, the ID becomes available immediately.
* The unplug way: "del" fails while in use, "unplug" always succeeds
Feels a bit cleaner to me. But changing
netdev_delmight not be acceptable.Either way works for me as an user interface. But I'd rather not have both.
Next, we need to consider how to integrate this with the automatic deletion of drives on qdev destruction. That's too late for unplug, we want that right in
device_del. I'd leave the stupid automatic delete where it is now, in qdev destruction. The C API need unplug and delete separate for that.Quoted 8 lines
Regardless of the way we choose, we need to think very clearly on how exactly device models should behave when their host part is missing or a zombie, and how that behavior appears in the guest.
For net, making it look exactly like a yanked out network cable would make sense to me.
What about block?
Quoted 8 lines
It seems to me that for block it's like cdrom with no disk, floppy with no media, hard disk that's gone bad. I think we we throw EIO back; it's handled gracefully enough. This is what happens when you do a
drive_unplugwith my patch; the application using the device gets IO errors. That's expected if a drive were to suddently fail (which is what this looks like). And certainly there is some responsibility at the mgmt console to ensure you're not unplugging a drive that you are currently using.
Quoted 1 line
Total drive failure works for me.
OK
Quoted 4 lines
"No media" is cute, but it's possible only for drives with removable media. I'd rather have all drives behave the same, whether their media is removable or not.
right, I don't think there is any "no media" for hard disks.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 95 lines · Ryan Harper
Quoted 80 lines · Markus Armbruster
Quoted 78 lines · Ryan Harper
Quoted 64 lines · Markus Armbruster
Quoted 52 lines · Ryan Harper
Quoted 29 lines · Markus Armbruster
[Note cc: Michael]
Ryan Harper <[email protected]> writes:
If I understand your patch correctly, the difference between your
drive_unplugand myblockdev_delis as follows:*
drive_unplugforcefully severs the connection between the host part of the block device and its BlockDriverState. A shell of the host part remains, to be cleaned up later. You need forceful disconnect operation to be able to revoke access to an image whether the guest cooperates or not. Fair enough.*
blockdev_deldeletes a host part. My current version fails when the host part is in use. I patterned that afternetdev_del, which used to work that way, until commit2ffcb18d:Make
netdev_deldelete the netdev even when it's in useTo hot-unplug guest and host part of a network device, you do:
device_delNIC-ID
netdev_delNETDEV-IDFor PCI devices,
device_delmerely tells ACPI to unplug the device. The device goes away for real only after the guest processed the ACPI unplug event.Quoted 8 lines
You have to wait until then (e.g. by polling info pci) before you can unplug the netdev. Not good.
Fix by removing the "in use" check from
do_netdev_del(). Deleting a netdev while it's in use is safe; packets simply get routed to the bit bucket.Isn't this the very same problem that's behind your
drive_unplug?Yes it is.
Quoted 4 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockQuoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.Quoted 7 lines
Quoted 2 lines
But what to do about the case where we're doing
drive_addand then adevice_del()That's the urgent situation that needs to be resolved.What's the exact problem we need to solve urgently?
Is it "provide means to cut the connection to the host part immediately, even with an uncooperative guest"?
Yes, need to ensure that if the mgmt layer (libvirt) has done what it believes should have disassociated the host block device from the guest, we want to ensure that the host block device is no longer accessible from the guest.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
Does this need to be separate from
device_del?no, it doesn't have to be. Honestly, I didn't see a clear way to do something like unplug early in the
device_delbecause that's all pci device code which has no knowledge of host block devices; having it disconnect seemed like a layering violation.
We invoke the cleanup callback, isn't that enough?
Quoted 126 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Even if your
drive_unplugshouldn't fit in that set, we might want it as a stop-gap. Depends on how urgent the need for it is. Yet another special-purpose command to be deprecated later.Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The fix is urgent; but I'm willing to spin a couple patches if it helps get this into better shape.
Can we agree on a common solution for block and net? That's why I cc'ed Michael.
I didn't see a good way to have block behave the same as net; though I do agree that it would be good to have this be common, long term.
If we can't make them behave 100% the same, then the next best thing is to offer a preferred way to do things that works similarly enough to let users ignore the differences.
Quoted 8 lines
Possible preferred ways to revoke access to a host part:
A.
device_delNeed to make
device_delcut the connection right away instead of when the guest completes unplug.
device_delchanges behavior. Any problems with that?I don't think so; current mgmt consumers assume a cooperative guest and don't handle an uncooperative one right now in the case where Selinux is disabled; so modifying this path to do a disconnect shouldn't be a problem.
Quoted 19 lines
Not an option if we need "cut the connection" to be separate from
device_del.B.
FOO_delGot
netdev_del.Need
drive_del. If drive is in use, replace it by a special "dead drive" without a device name (so the ID becomes available for new drives), then delete the original.Wart:
drive_deldoesn't work reliably afterdevice_del, because the drive is auto-deleted when the guest completes unplug. Not a problem for my blockdev_add/blockdev_del work-in-progress, because host parts created withblockdev_adddon't auto-delete.C.
FOO_unplugQuoted 8 lines
You got a patch for
drive_unplug.Need
netdev_unplug.By the way, I hate "unplug", because it suggests relation to hot unplug. What about "disconnect"?
Any preferences?
disconnect is fine.
Quoted 47 lines
Quoted 38 lines
Quoted 29 lines
Currently, we have two different ways:
* The netdev way: "del" always succeeds
How can it succeed if the host part is in use?
If all device models are prepared to deal with a missing host part, we can delete it right away.
Else, we need to replace it with a suitable zombie, which is auto-deleted when it goes out of use. Such zombies are not be visible elsewhere, in particular, the ID becomes available immediately.
* The unplug way: "del" fails while in use, "unplug" always succeeds
Feels a bit cleaner to me. But changing
netdev_delmight not be acceptable.Either way works for me as an user interface. But I'd rather not have both.
Next, we need to consider how to integrate this with the automatic deletion of drives on qdev destruction. That's too late for unplug, we want that right in
device_del. I'd leave the stupid automatic delete where it is now, in qdev destruction. The C API need unplug and delete separate for that.Quoted 8 lines
Regardless of the way we choose, we need to think very clearly on how exactly device models should behave when their host part is missing or a zombie, and how that behavior appears in the guest.
For net, making it look exactly like a yanked out network cable would make sense to me.
What about block?
Quoted 8 lines
It seems to me that for block it's like cdrom with no disk, floppy with no media, hard disk that's gone bad. I think we we throw EIO back; it's handled gracefully enough. This is what happens when you do a
drive_unplugwith my patch; the application using the device gets IO errors. That's expected if a drive were to suddently fail (which is what this looks like). And certainly there is some responsibility at the mgmt console to ensure you're not unplugging a drive that you are currently using.Quoted 1 line
Total drive failure works for me.
OK
Quoted 4 lines
"No media" is cute, but it's possible only for drives with removable media. I'd rather have all drives behave the same, whether their media is removable or not.
right, I don't think there is any "no media" for hard disks.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 50 lines · Michael S. Tsirkin
Quoted 49 lines · Ryan Harper
Quoted 33 lines · Markus Armbruster
Quoted 33 lines
Quoted 20 lines
Quoted 10 lines
Quoted 3 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockQuoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.Quoted 7 lines
Quoted 2 lines
But what to do about the case where we're doing
drive_addand then adevice_del()That's the urgent situation that needs to be resolved.What's the exact problem we need to solve urgently?
Is it "provide means to cut the connection to the host part immediately, even with an uncooperative guest"?
Yes, need to ensure that if the mgmt layer (libvirt) has done what it believes should have disassociated the host block device from the guest, we want to ensure that the host block device is no longer accessible from the guest.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Does this need to be separate from
device_del?no, it doesn't have to be. Honestly, I didn't see a clear way to do something like unplug early in the
device_delbecause that's all pci device code which has no knowledge of host block devices; having it disconnect seemed like a layering violation.We invoke the cleanup callback, isn't that enough?
Won't that look a bit strange? on device_del, call the cleanup callback first;, then notify the guest, if the guest responds, I suppose as long as the cleanup callback can handle being called a second time that'd work.
I like the idea of disconnect; if part of the device_del method was to invoke a disconnect method, we could implement that for block, net, etc;
I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 58 lines · Ryan Harper
Quoted 57 lines · Michael S. Tsirkin
Quoted 55 lines · Ryan Harper
Quoted 33 lines · Markus Armbruster
Quoted 33 lines
Quoted 20 lines
Quoted 10 lines
Quoted 3 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockQuoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.Quoted 7 lines
Quoted 2 lines
But what to do about the case where we're doing
drive_addand then adevice_del()That's the urgent situation that needs to be resolved.What's the exact problem we need to solve urgently?
Is it "provide means to cut the connection to the host part immediately, even with an uncooperative guest"?
Yes, need to ensure that if the mgmt layer (libvirt) has done what it believes should have disassociated the host block device from the guest, we want to ensure that the host block device is no longer accessible from the guest.
Quoted 2 lines
Does this need to be separate from
device_del?no, it doesn't have to be. Honestly, I didn't see a clear way to do something like unplug early in the
device_delbecause that's all pci device code which has no knowledge of host block devices; having it disconnect seemed like a layering violation.
Quoted 6 lines
Quoted 1 line
We invoke the cleanup callback, isn't that enough?
Won't that look a bit strange? on
device_del, call the cleanup callback first;, then notify the guest, if the guest responds, I suppose as long as the cleanup callback can handle being called a second time that'd work.
Well this is exactly what happens with surpise removal. If you yank a card out the slot, guest only gets notification afterwards.
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Signature · 1 line
MST
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Ryan Harper
Quoted 58 lines · Michael S. Tsirkin
Quoted 49 lines · Ryan Harper
Quoted 33 lines · Markus Armbruster
Quoted 33 lines
Quoted 20 lines
Quoted 10 lines
Quoted 3 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockQuoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.Quoted 7 lines
Quoted 2 lines
But what to do about the case where we're doing
drive_addand then adevice_del()That's the urgent situation that needs to be resolved.What's the exact problem we need to solve urgently?
Is it "provide means to cut the connection to the host part immediately, even with an uncooperative guest"?
Yes, need to ensure that if the mgmt layer (libvirt) has done what it believes should have disassociated the host block device from the guest, we want to ensure that the host block device is no longer accessible from the guest.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
Does this need to be separate from
device_del?no, it doesn't have to be. Honestly, I didn't see a clear way to do something like unplug early in the
device_delbecause that's all pci device code which has no knowledge of host block devices; having it disconnect seemed like a layering violation.We invoke the cleanup callback, isn't that enough?
Quoted 8 lines
Quoted 4 lines
Won't that look a bit strange? on
device_del, call the cleanup callback first;, then notify the guest, if the guest responds, I suppose as long as the cleanup callback can handle being called a second time that'd work.Well this is exactly what happens with surpise removal. If you yank a card out the slot, guest only gets notification afterwards.
Right, though the card ripper can (in some systems) press the removal button which would send notification. I think I'm fine with not bothering to notify; this was mgmt interface driven anyhow so who ever is doing it should have already ensured they weren't using the device.
Quoted 8 lines
Quoted 7 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
Quoted 7 lines
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Cc [email protected], he is working on hotplug for pci express.
Quoted 67 lines · Ryan Harper
Quoted 66 lines · Michael S. Tsirkin
Quoted 64 lines · Ryan Harper
Quoted 50 lines · Michael S. Tsirkin
Quoted 49 lines · Ryan Harper
Quoted 33 lines · Markus Armbruster
Quoted 33 lines
Quoted 20 lines
Quoted 10 lines
Quoted 3 lines
I'd like to have some consistency among net, block and char device commands, i.e. a common set of operations that work the same for all of them. Can we agree on such a set?
Yeah; the current trouble (or at least what I perceive to be trouble) is that in the case where the guest responds to
device_delinduced ACPI removal event; the current qdev code already does the host-side device tear down. Not sure if it is OK to do ablockdev_del()immediately after thedevice_del. What happens when we do:Quoted 3 lines
device_del
ACPI to guestblockdev_del/* removes host-side device */Fails in my tree, because the blockdev's still in use. See below.
Quoted 4 lines
guest responds to ACPI
qdev calls pci device removal code
qemu attempts to destroy the associated host-side blockQuoted 6 lines
Quoted 2 lines
That may just work today; and if not, it shouldn't be hard to fix up the code to check for NULLs
I hate the automatic deletion of host part along with the guest part.
device_delshould undodevice_add. {block,net,char}dev_{add,del} should be similarly paired.Agreed.
Quoted 4 lines
In my blockdev branch, I keep the automatic delete only for backwards
compatibility: if you create the drive withdrive_add, it gets auto-deleted, but if you useblockdev_add, it stays around.Quoted 7 lines
Quoted 2 lines
But what to do about the case where we're doing
drive_addand then adevice_del()That's the urgent situation that needs to be resolved.What's the exact problem we need to solve urgently?
Is it "provide means to cut the connection to the host part immediately, even with an uncooperative guest"?
Yes, need to ensure that if the mgmt layer (libvirt) has done what it believes should have disassociated the host block device from the guest, we want to ensure that the host block device is no longer accessible from the guest.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Does this need to be separate from
device_del?no, it doesn't have to be. Honestly, I didn't see a clear way to do something like unplug early in the
device_delbecause that's all pci device code which has no knowledge of host block devices; having it disconnect seemed like a layering violation.We invoke the cleanup callback, isn't that enough?
Won't that look a bit strange? on
device_del, call the cleanup callback first;, then notify the guest, if the guest responds, I suppose as long as the cleanup callback can handle being called a second time that'd work.
Quoted 7 lines
Quoted 3 lines
Well this is exactly what happens with surpise removal. If you yank a card out the slot, guest only gets notification afterwards.
Right, though the card ripper can (in some systems) press the removal button which would send notification. I think I'm fine with not bothering to notify;
I think at least for express the port would notice the event and notify guest anyway, it just happens after the fact, by necessity.
Quoted 2 lines
this was mgmt interface driven anyhow so who ever
is doing it should have already ensured they weren't using the device.
Right. However, I think two additional new interfaces that
1. just send the notification
2. report event on guest eject
would be a good idea. This might tie in well with pci express work where there's a standard interface for sending these events and for getting notified that guest is ready for device to be removed.
Guests also might have ways to lock the card so you can not yank it out, mechanically. This could translate to a failure to do surpise removal, management can then decide whether killing the guest makes sense.
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.
Signature · 1 line
MST
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.
Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what drive_unplug() implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.
Very specifically, what we're suggesting instead of the drive_unplug() command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.
What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 46 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
Quoted 5 lines
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove device
A twist is when guest disabled the device already. Then it would just want to remove the device.
Quoted 5 lines
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 53 lines · Michael S. Tsirkin
Quoted 46 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
Quoted 5 lines
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove device
Yes; but this argues for (1) being a separate command from (3) unless we require (3) to include (1) and (2) in the qemu implementation.
Currently we implement:
1. device_del (attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destruction
With my drive_unplug patch we do:
1. disconnect host resource from device
2. device_del (attempt to remove device)
3. notify guest
4. if guest responds, remove device
I think we're suggesting to instead do (if we keep disconnect as part of device_del)
1. device_del (attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 5 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
Quoted 8 lines
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionWith my
drive_unplugpatch we do:1. disconnect host resource from device
This is what drive_unplug does, right?
Quoted 11 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.
By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on eject
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Quoted 6 lines
Signature · 5 lines
-- Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destruction
Quoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?
Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)
Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.
I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the qdev_unplug() path which ultimately kills the device and the Drive and BlockState objects.
Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on eject
Quoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to device_del.
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having device_del always succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doing drive_unplug?
With at least two of these device types needing an explicit disconnect to sever the bond between host/guest makes me want a device-level interface for doing the disconnect that each device can implement differently.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 119 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Quoted 7 lines
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?
I'm not sure I parse this.
Quoted 4 lines
With at least two of these device types needing an explicit disconnect to sever the bond between host/guest makes me want a device-level interface for doing the disconnect that each device can implement differently.
I'm fine with having a separate command to forcibly disconnect a device from its host resources.
Typical use:
1. device_del
ask guest to give up device, via ACPI
2a. guest replies "done", delete device, free host resources
2b. timeout, device_disconnect (or however we call that)
Is this what you have in mind?
With qdev, device models are connected to host resources with special properties such as qdev_prop_netdev and qdev_prop_drive. Thus, generic qdev code can already find and disconnect them.
How can we make sure device models survive such a disconnect?
* Ask the device to disconnect itself (new DeviceInfo method).
Drawback: duplicates common functionality in every device model. More code, more bugs.
* Let qdev core disconnect and free host resources
- and replace them with dummies. I guess we'd need a dummy constructor method for that, in PropertyInfo. Done right, device models should be able to carry on unawares.
- and leave them null. Device models need to cope with that. NICs do for netdev.
We might need to notify the device model (new DeviceInfo method). Dunno.
Quoted 124 lines · Markus Armbruster
Quoted 122 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.
Quoted 6 lines
Quoted 4 lines
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have device_del() always succeed by replacing the device with a shell/zombie. The drive_unplug() patch doesn't do the same thing; it doesn't affect the device_del() path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.
Quoted 11 lines
Quoted 5 lines
With at least two of these device types needing an explicit disconnect to sever the bond between host/guest makes me want a device-level interface for doing the disconnect that each device can implement differently.
I'm fine with having a separate command to forcibly disconnect a device from its host resources.
Typical use:
Quoted 8 lines
1.
device_del
ask guest to give up device, via ACPI2a. guest replies "done", delete device, free host resources
2b. timeout,
device_disconnect(or however we call that)Is this what you have in mind?
Yeah, aboslutely. I think Michael was saying we should implement 2b in the mgmt stack. The current libvirt does the following
1. mgmt invokes detach-device
2. device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.
With drive_unplug in qemu and a patch to libvirt, it looks like:
1. mgmt invokes detach-device
2a. call drive_unplug, log warning if drive_unplug isn't available 2b. device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.
I can look at implementing the timeout before invoking the unplug (that's a bit tricky) in libvirt; but given the fact that the mgmt is invoking the removal I think it's reasonable to do forced disconnect (even if the guest hasn't responded).
Quoted 12 lines
With qdev, device models are connected to host resources with special properties such as
qdev_prop_netdevandqdev_prop_drive. Thus, generic qdev code can already find and disconnect them.How can we make sure device models survive such a disconnect?
* Ask the device to disconnect itself (new DeviceInfo method).
Drawback: duplicates common functionality in every device model. More code, more bugs.
Quoted 9 lines
* Let qdev core disconnect and free host resources
- and replace them with dummies. I guess we'd need a dummy constructor method for that, in PropertyInfo. Done right, device models should be able to carry on unawares.
- and leave them null. Device models need to cope with that. NICs do for netdev.
I like the latter here; the BlockDriverState handles nulls. I think netdev should be able to as well though I haven't looked very closely though so maybe Michael can confirm if that's a true statement.
Quoted 2 lines
We might need to notify the device model (new DeviceInfo method). Dunno.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 130 lines · Ryan Harper
Quoted 129 lines · Markus Armbruster
Quoted 126 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?
Quoted 8 lines
Quoted 1 line
I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.
Yes, the shell thing is just an implementation detail.
Quoted 30 lines
Quoted 11 lines
Quoted 5 lines
With at least two of these device types needing an explicit disconnect to sever the bond between host/guest makes me want a device-level interface for doing the disconnect that each device can implement differently.
I'm fine with having a separate command to forcibly disconnect a device from its host resources.
Typical use:
Quoted 8 lines
1.
device_del
ask guest to give up device, via ACPI2a. guest replies "done", delete device, free host resources
2b. timeout,
device_disconnect(or however we call that)Is this what you have in mind?
Yeah, aboslutely. I think Michael was saying we should implement 2b in the mgmt stack. The current libvirt does the following
1. mgmt invokes detach-device
2.device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.With
drive_unplugin qemu and a patch to libvirt, it looks like:
Quoted 8 lines
1. mgmt invokes detach-device
2a. calldrive_unplug, log warning ifdrive_unplugisn't available 2b.device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.I can look at implementing the timeout before invoking the unplug (that's a bit tricky) in libvirt;
So we'd
1. reorder 2a and 2b, and add a small timeout
2. teach libvirt not to reuse the PCI slot and device id until it is really free
Sounds good.
Quoted 3 lines
but given the fact that the mgmt is
invoking the removal I think it's reasonable to do forced disconnect (even if the guest hasn't responded).
This is really making an assumption about the user. Giving the guest a bit of time to respond with eject seems prudent. For disk we risk losing data otherwise.
The only reason we are pushing this out to management is so it can track state implement timeouts and interact with the user. If it doesn't, what's the point? Let's keep it all in qemu...
Quoted 18 lines
Quoted 18 lines
With qdev, device models are connected to host resources with special properties such as
qdev_prop_netdevandqdev_prop_drive. Thus, generic qdev code can already find and disconnect them.How can we make sure device models survive such a disconnect?
* Ask the device to disconnect itself (new DeviceInfo method).
Drawback: duplicates common functionality in every device model. More code, more bugs.* Let qdev core disconnect and free host resources
- and replace them with dummies. I guess we'd need a dummy constructor method for that, in PropertyInfo. Done right, device models should be able to carry on unawares.
Quoted 7 lines
Quoted 3 lines
- and leave them null. Device models need to cope with that. NICs do for netdev.
I like the latter here; the BlockDriverState handles nulls. I think netdev should be able to as well though I haven't looked very closely though so maybe Michael can confirm if that's a true statement.
Not at the moment: the issue is that NULL means legacy vlan setup there. We can rework the code to avoid that assumption but it's not on my priority list.
Quoted 10 lines
Quoted 2 lines
We might need to notify the device model (new DeviceInfo method). Dunno.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 133 lines · Michael S. Tsirkin
Quoted 132 lines · Ryan Harper
Quoted 130 lines · Markus Armbruster
Quoted 119 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the
device_delmethod was to invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect. Struggling with whether it's worth having some reasonable timeout between notification and disconnect.
The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Quoted 7 lines
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
Quoted 8 lines
Quoted 6 lines
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.Yes, the shell thing is just an implementation detail.
ok. What qemu monitor command do I call for net delete to do the "disconnect/unplug"?
Quoted 41 lines
Quoted 31 lines
Quoted 12 lines
Quoted 6 lines
With at least two of these device types needing an explicit disconnect to sever the bond between host/guest makes me want a device-level interface for doing the disconnect that each device can implement differently.
I'm fine with having a separate command to forcibly disconnect a device from its host resources.
Typical use:
Quoted 8 lines
1.
device_del
ask guest to give up device, via ACPI2a. guest replies "done", delete device, free host resources
2b. timeout,
device_disconnect(or however we call that)Is this what you have in mind?
Yeah, aboslutely. I think Michael was saying we should implement 2b in the mgmt stack. The current libvirt does the following
1. mgmt invokes detach-device
2.device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.With
drive_unplugin qemu and a patch to libvirt, it looks like:Quoted 8 lines
1. mgmt invokes detach-device
2a. calldrive_unplug, log warning ifdrive_unplugisn't available 2b.device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.I can look at implementing the timeout before invoking the unplug (that's a bit tricky) in libvirt;
Quoted 6 lines
So we'd
1. reorder 2a and 2b, and add a small timeout
2. teach libvirt not to reuse the PCI slot and device id until it is really freeSounds good.
We're talking libvirt code here; so we'll need to start up that thread there. (1) is probably reasonable. (2) is the harder part. We'll need some help in figuring out how to do that one. Maybe it can be done on the attach path (check if the slot is available in qemu). I know there is some code to allocte slots in a structure that libvirt maintains.
I'll start a thread over there.
Quoted 7 lines
Quoted 4 lines
but given the fact that the mgmt is
invoking the removal I think it's reasonable to do forced disconnect (even if the guest hasn't responded).This is really making an assumption about the user. Giving the guest a bit of time to respond with eject seems prudent.
I don't disagree that the notification is nice; but I'm not sure I see it as a requirement for correctness of behavior. The device is being deleted *explicitly* at the user's request. If the user invokes removal and it still using the device; the kernel doesn't do anything special here; it just responds to the interrupt and destroys the resource; this will result in the user app being hung on pending IO. The same thing happens if we disconnect the host side device.
Now, if we want to talk about nice; we'd need to do some improvements on the Linux acpi removal code where by we flush all pending io in the device before we respond to the device removal;
Quoted 1 line
For disk we risk losing data otherwise.
I don't think that's true at all. Even on suprise removal we complete pending io the device and return -EIO back to the guest. The app may or maynot be robust enough to handle it the errors but we're definitely not losing data.
Quoted 26 lines
The only reason we are pushing this out to management is so it can track state implement timeouts and interact with the user. If it doesn't, what's the point? Let's keep it all in qemu...
Quoted 22 lines
Quoted 21 lines
With qdev, device models are connected to host resources with special properties such as
qdev_prop_netdevandqdev_prop_drive. Thus, generic qdev code can already find and disconnect them.How can we make sure device models survive such a disconnect?
* Ask the device to disconnect itself (new DeviceInfo method).
Drawback: duplicates common functionality in every device model. More code, more bugs.* Let qdev core disconnect and free host resources
- and replace them with dummies. I guess we'd need a dummy constructor method for that, in PropertyInfo. Done right, device models should be able to carry on unawares.
- and leave them null. Device models need to cope with that. NICs do for netdev.
Quoted 7 lines
Quoted 3 lines
I like the latter here; the BlockDriverState handles nulls. I think netdev should be able to as well though I haven't looked very closely though so maybe Michael can confirm if that's a true statement.
Not at the moment: the issue is that NULL means legacy vlan setup there. We can rework the code to avoid that assumption but it's not on my priority list.
So, to move the ball forward so to speak we need:
1. have qdev code disconnect host resources and leave them null (or some that indicates that the device is disconnected from host resource)
2. update netdev code to have some way to distinquish between legacy vlan and disconnected
3. implement a device_disconnect monitor command which can disconnect at least block and net devices?
Does that look right?
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 141 lines · Ryan Harper
Quoted 140 lines · Michael S. Tsirkin
Quoted 138 lines · Ryan Harper
Quoted 124 lines · Markus Armbruster
Quoted 122 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
Quoted 6 lines
I like the idea of disconnect; if part of the device_del method was to
invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect.
Struggling with whether it's worth having some reasonable timeout
between notification and disconnect.The problem with this is that it has no analog in real world. In real world, you can send some notifications to the guest, and you can remove the card. Tying them together is what created the problem in the first place.
Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog being shown to the user.
Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Quoted 6 lines
Quoted 4 lines
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.
Quoted 4 lines
Quoted 1 line
Yes, the shell thing is just an implementation detail.
ok. What qemu monitor command do I call for net delete to do the "disconnect/unplug"?
netdev_del
Quoted 133 lines
Quoted 41 lines
Quoted 31 lines
Quoted 12 lines
Quoted 6 lines
With at least two of these device types needing an explicit disconnect to sever the bond between host/guest makes me want a device-level interface for doing the disconnect that each device can implement differently.
I'm fine with having a separate command to forcibly disconnect a device from its host resources.
Typical use:
Quoted 8 lines
1.
device_del
ask guest to give up device, via ACPI2a. guest replies "done", delete device, free host resources
2b. timeout,
device_disconnect(or however we call that)Is this what you have in mind?
Yeah, aboslutely. I think Michael was saying we should implement 2b in the mgmt stack. The current libvirt does the following
1. mgmt invokes detach-device
2.device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.With
drive_unplugin qemu and a patch to libvirt, it looks like:Quoted 8 lines
1. mgmt invokes detach-device
2a. calldrive_unplug, log warning ifdrive_unplugisn't available 2b.device_del
3. update mgmt view of resources, assumes guest has done it's part; does not confirm with qemu that device has been deleted.I can look at implementing the timeout before invoking the unplug (that's a bit tricky) in libvirt;
Quoted 6 lines
So we'd
1. reorder 2a and 2b, and add a small timeout
2. teach libvirt not to reuse the PCI slot and device id until it is really freeSounds good.
We're talking libvirt code here; so we'll need to start up that thread there. (1) is probably reasonable. (2) is the harder part. We'll need some help in figuring out how to do that one. Maybe it can be done on the attach path (check if the slot is available in qemu). I know there is some code to allocte slots in a structure that libvirt maintains.
I'll start a thread over there.
Quoted 7 lines
Quoted 4 lines
but given the fact that the mgmt is
invoking the removal I think it's reasonable to do forced disconnect (even if the guest hasn't responded).This is really making an assumption about the user. Giving the guest a bit of time to respond with eject seems prudent.
I don't disagree that the notification is nice; but I'm not sure I see it as a requirement for correctness of behavior. The device is being deleted *explicitly* at the user's request. If the user invokes removal and it still using the device; the kernel doesn't do anything special here; it just responds to the interrupt and destroys the resource; this will result in the user app being hung on pending IO. The same thing happens if we disconnect the host side device.
Now, if we want to talk about nice; we'd need to do some improvements on the Linux acpi removal code where by we flush all pending io in the device before we respond to the device removal;
Quoted 1 line
For disk we risk losing data otherwise.
I don't think that's true at all. Even on suprise removal we complete pending io the device and return
-EIOback to the guest. The app may or maynot be robust enough to handle it the errors but we're definitely not losing data.Quoted 26 lines
The only reason we are pushing this out to management is so it can track state implement timeouts and interact with the user. If it doesn't, what's the point? Let's keep it all in qemu...
Quoted 22 lines
Quoted 21 lines
With qdev, device models are connected to host resources with special properties such as
qdev_prop_netdevandqdev_prop_drive. Thus, generic qdev code can already find and disconnect them.How can we make sure device models survive such a disconnect?
* Ask the device to disconnect itself (new DeviceInfo method).
Drawback: duplicates common functionality in every device model. More code, more bugs.* Let qdev core disconnect and free host resources
- and replace them with dummies. I guess we'd need a dummy constructor method for that, in PropertyInfo. Done right, device models should be able to carry on unawares.
- and leave them null. Device models need to cope with that. NICs do for netdev.
Quoted 7 lines
Quoted 3 lines
I like the latter here; the BlockDriverState handles nulls. I think netdev should be able to as well though I haven't looked very closely though so maybe Michael can confirm if that's a true statement.
Not at the moment: the issue is that NULL means legacy vlan setup there. We can rework the code to avoid that assumption but it's not on my priority list.
So, to move the ball forward so to speak we need:
1. have qdev code disconnect host resources and leave them null (or some that indicates that the device is disconnected from host resource)
2. update netdev code to have some way to distinquish between legacy vlan and disconnected
3. implement adevice_disconnectmonitor command which can disconnect at least block and net devices?Does that look right?
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 142 lines · Michael S. Tsirkin
Quoted 141 lines · Ryan Harper
Quoted 140 lines · Michael S. Tsirkin
Quoted 138 lines · Ryan Harper
Quoted 124 lines · Markus Armbruster
Quoted 122 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
I like the idea of disconnect; if part of the device_del method was to
invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect.
Struggling with whether it's worth having some reasonable timeout
between notification and disconnect.The problem with this is that it has no analog in real world.
In real world, you can send some notifications to the guest, and you can
remove the card. Tying them together is what created the problem in the
first place.Quoted 7 lines
Quoted 2 lines
Timeouts can be implemented by management, maybe with a nice dialog
being shown to the user.Very true. I'm fine with forcing a disconnect during the removal path prior to notification. Do we want a new disconnect method at the device level (pci)? or just use the existing removal callback and call that during the initial hotremov event?
Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Quoted 6 lines
Quoted 4 lines
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Yes, the shell thing is just an implementation detail.
ok. What qemu monitor command do I call for net delete to do the "disconnect/unplug"?
netdev_del
OK. With netdev_del and drive_unplug commands (not sure if we care to change the names to be similar, maybe blockdev_del) in qemu, we can then implement the following in libvirt:
1) detach-device invocation
2) issue device_del to QEMU
2a) notification is sent)
3) issue netdev_del/blockdev_del as appropriate for the device type
4) update guest XML to indicate device has been removed
And a fancier version would look like:
1) detach-device invocation
2) issue device_del to QEMU
2a) notification is sent)
3) set a timeout for guest to respond
4) when timeout expires
4a) check if the pci device has been removed by quering QEMU
if it hasn't been removed, issue netdev_del/blockdev_del
5) update guest XML to indicate device has been removed
in both cases, I think we'll also want a patch that validates that the pci slot is available before handing it out again; this will handle the case where the guest doesn't respond to the device removal request; our net/blockdev_del command will break the host/guest association, but we don't want to attempt to attach a device to the same slot.
Marcus, do you think we're at a point where the mechanisms for explicitly revoking access to the host resource is consistent between net and block?
If so, then I suppose I might have a consmetic patch to fix up the monitor command name to line up with the netdev_del.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 11 lines · Ryan Harper
OK. With
netdev_delanddrive_unplugcommands (not sure if we care to change the names to be similar, maybeblockdev_del) in qemu, we can then implement the following in libvirt:1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) issue netdev_del/blockdev_del as appropriate for the device type
4) update guest XML to indicate device has been removed And a fancier version would look like:
Quoted 7 lines
1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) set a timeout for guest to respond
4) when timeout expires
4a) check if the pci device has been removed by quering QEMU
if it hasn't been removed, issue netdev_del/blockdev_del
I think it's easier to check the network device:
info network and whatever is appropriate for block
Quoted 8 lines
5) update guest XML to indicate device has been removed
in both cases, I think we'll also want a patch that validates that the pci slot is available before handing it out again; this will handle the case where the guest doesn't respond to the device removal request; our
net/blockdev_delcommand will break the host/guest association, but we don't want to attempt to attach a device to the same slot.
Yes, absolutely. And same for qdev device id.
Quoted 13 lines
Marcus, do you think we're at a point where the mechanisms for explicitly revoking access to the host resource is consistent between net and block?
If so, then I suppose I might have a consmetic patch to fix up the monitor command name to line up with the
netdev_del.Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 179 lines · Ryan Harper
Quoted 142 lines · Michael S. Tsirkin
Quoted 141 lines · Ryan Harper
Quoted 140 lines · Michael S. Tsirkin
Quoted 138 lines · Ryan Harper
Quoted 124 lines · Markus Armbruster
Quoted 122 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 20 lines
Quoted 19 lines
I like the idea of disconnect; if part of the device_del method was to
invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect.
Struggling with whether it's worth having some reasonable timeout
between notification and disconnect.The problem with this is that it has no analog in real world.
In real world, you can send some notifications to the guest, and you can
remove the card. Tying them together is what created the problem in the
first place.Timeouts can be implemented by management, maybe with a nice dialog
being shown to the user.Very true. I'm fine with forcing a disconnect during the removal path
prior to notification. Do we want a new disconnect method at the device
level (pci)? or just use the existing removal callback and call that
during the initial hotremov event?Quoted 5 lines
Not sure what you mean by that, but I don't see a device doing anything differently wrt surprise or ordered removal. So probably the existing callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Quoted 6 lines
Quoted 4 lines
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Yes, the shell thing is just an implementation detail.
ok. What qemu monitor command do I call for net delete to do the "disconnect/unplug"?
netdev_delOK. With
netdev_delanddrive_unplugcommands (not sure if we care to change the names to be similar, maybeblockdev_del) in qemu, we can then implement the following in libvirt:1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) issue netdev_del/blockdev_del as appropriate for the device type
4) update guest XML to indicate device has been removedAnd a fancier version would look like:
1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) set a timeout for guest to respond
4) when timeout expires
4a) check if the pci device has been removed by quering QEMU
if it hasn't been removed, issue netdev_del/blockdev_del
5) update guest XML to indicate device has been removedin both cases, I think we'll also want a patch that validates that the pci slot is available before handing it out again; this will handle the case where the guest doesn't respond to the device removal request; our
net/blockdev_delcommand will break the host/guest association, but we don't want to attempt to attach a device to the same slot.
Quoted 6 lines
Marcus, do you think we're at a point where the mechanisms for explicitly revoking access to the host resource is consistent between net and block?
If so, then I suppose I might have a consmetic patch to fix up the monitor command name to line up with the
netdev_del.
I'd be fine with any of these:
1. A new command "device_disconnet ID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.
2. New commands netdev_disconnect, drive_disconnect (or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.
3. A new command "drive_del ID" similar to existing netdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.
Do you need anything else from me to make progress?
Quoted 216 lines · Michael S. Tsirkin
Quoted 190 lines · Markus Armbruster
Quoted 179 lines · Ryan Harper
Quoted 142 lines · Michael S. Tsirkin
Quoted 141 lines · Ryan Harper
Quoted 140 lines · Michael S. Tsirkin
Quoted 138 lines · Ryan Harper
Quoted 124 lines · Markus Armbruster
Quoted 122 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
I like the idea of disconnect; if part of the device_del method was to
invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect.
Struggling with whether it's worth having some reasonable timeout
between notification and disconnect.The problem with this is that it has no analog in real world.
In real world, you can send some notifications to the guest, and you can
remove the card. Tying them together is what created the problem in the
first place.Timeouts can be implemented by management, maybe with a nice dialog
being shown to the user.Very true. I'm fine with forcing a disconnect during the removal path
prior to notification. Do we want a new disconnect method at the device
level (pci)? or just use the existing removal callback and call that
during the initial hotremov event?Not sure what you mean by that, but I don't see a device doing anything
differently wrt surprise or ordered removal. So probably the existing
callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it
just that.Because current the "removal" process depends on the guest actually
responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug() implements, is to disconnect the host block device from
the guest device to prevent any further access to it in the case the
guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the drive_unplug()
command so to complete the device removal operation without waiting for
the guest to respond; that's what's going to happen if we invoke the
response callback; it will appear as if the guest responded whether it
did or not.What I was suggesting above was to instead of calling the callback for
handing the guest response was to add a device function called
disconnect which would remove any association of host resources from
guest resources before we notified the guest. Thinking about it again
I'm not sure this is useful, but if we're going to remove the device
without the guests knowledge, I'm not sure how useful sending the
removal requests via ACPI is in the first place.My feeling is that I'd like to have explicit control over the disconnect
from host resources separate from the device removal *if* we're going to
retain the guest notification. If we don't care to notify the guest,
then we can just do device removal without notifying the guest
and be done with it.Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Quoted 6 lines
Quoted 4 lines
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Yes, the shell thing is just an implementation detail.
ok. What qemu monitor command do I call for net delete to do the "disconnect/unplug"?
netdev_delOK. With
netdev_delanddrive_unplugcommands (not sure if we care to change the names to be similar, maybeblockdev_del) in qemu, we can then implement the following in libvirt:1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) issue netdev_del/blockdev_del as appropriate for the device type
4) update guest XML to indicate device has been removedAnd a fancier version would look like:
1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) set a timeout for guest to respond
4) when timeout expires
4a) check if the pci device has been removed by quering QEMU
if it hasn't been removed, issue netdev_del/blockdev_del
5) update guest XML to indicate device has been removedin both cases, I think we'll also want a patch that validates that the pci slot is available before handing it out again; this will handle the case where the guest doesn't respond to the device removal request; our
net/blockdev_delcommand will break the host/guest association, but we don't want to attempt to attach a device to the same slot.Quoted 6 lines
Marcus, do you think we're at a point where the mechanisms for explicitly revoking access to the host resource is consistent between net and block?
If so, then I suppose I might have a consmetic patch to fix up the monitor command name to line up with the
netdev_del.I'd be fine with any of these:
Quoted 8 lines
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.I think it's cleaner not to introduce a concept of a disconnected backend.
One thing that we must be careful to explicitly disallow, is reconnecting guest to another host backend. The reason being that guest might rely on backend features and changing these would break this.
Given that, disconnecting without delete isn't helpful.
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.
Quoted 8 lines
I don't see how it's more dangerous than disconnecting. If guest can't access the backend it might not exist as far as guest is concerned.
Quoted 1 line
Do you need anything else from me to make progress?
Let's go for 3. Need for 1/2 seems dubious, and it's much harder to support.
Other than naming I thought (1) and (3) were the same; but if the current netdev_del() is considered (3), then I'm for renaming drive_unplug to blockdev_del (or drive_del).
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 188 lines · Markus Armbruster
Quoted 179 lines · Ryan Harper
Quoted 142 lines · Michael S. Tsirkin
Quoted 141 lines · Ryan Harper
Quoted 140 lines · Michael S. Tsirkin
Quoted 138 lines · Ryan Harper
Quoted 124 lines · Markus Armbruster
Quoted 122 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 25 lines
I like the idea of disconnect; if part of the device_del method was to
invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect.
Struggling with whether it's worth having some reasonable timeout
between notification and disconnect.The problem with this is that it has no analog in real world.
In real world, you can send some notifications to the guest, and you can
remove the card. Tying them together is what created the problem in the
first place.Timeouts can be implemented by management, maybe with a nice dialog
being shown to the user.Very true. I'm fine with forcing a disconnect during the removal path
prior to notification. Do we want a new disconnect method at the device
level (pci)? or just use the existing removal callback and call that
during the initial hotremov event?Not sure what you mean by that, but I don't see a device doing anything
differently wrt surprise or ordered removal. So probably the existing
callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it
just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Quoted 6 lines
Quoted 4 lines
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Yes, the shell thing is just an implementation detail.
ok. What qemu monitor command do I call for net delete to do the "disconnect/unplug"?
netdev_delOK. With
netdev_delanddrive_unplugcommands (not sure if we care to change the names to be similar, maybeblockdev_del) in qemu, we can then implement the following in libvirt:1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) issue netdev_del/blockdev_del as appropriate for the device type
4) update guest XML to indicate device has been removedAnd a fancier version would look like:
1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) set a timeout for guest to respond
4) when timeout expires
4a) check if the pci device has been removed by quering QEMU
if it hasn't been removed, issue netdev_del/blockdev_del
5) update guest XML to indicate device has been removedin both cases, I think we'll also want a patch that validates that the pci slot is available before handing it out again; this will handle the case where the guest doesn't respond to the device removal request; our
net/blockdev_delcommand will break the host/guest association, but we don't want to attempt to attach a device to the same slot.Quoted 6 lines
Marcus, do you think we're at a point where the mechanisms for explicitly revoking access to the host resource is consistent between net and block?
If so, then I suppose I might have a consmetic patch to fix up the monitor command name to line up with the
netdev_del.
Quoted 6 lines
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.
This is sort of what netdev_del() and drive_unplug() are today; we're just saying sever the connection of this device id.
I'd like to rename drive_unplug() to blockdev_del() and call it done. I was looking at libvirt and the right call to netdev_del is already in-place; I'd just need to re-spin my block patch to call blockdev_del() after invoking device_del() to match what is done for net.
Quoted 4 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.
What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
Quoted 6 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.
Hrm, I thought that's what (1) is. Well, either (1) or (3); I'd like to rename drive_unplug() to blockdev_del() since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).
Quoted 2 lines
Do you need anything else from me to make progress?
I think just an agreement on the approach; shouldn't take more than a few hours to respin the qemu and libvirt side.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 190 lines · Markus Armbruster
Quoted 179 lines · Ryan Harper
Quoted 142 lines · Michael S. Tsirkin
Quoted 141 lines · Ryan Harper
Quoted 140 lines · Michael S. Tsirkin
Quoted 138 lines · Ryan Harper
Quoted 124 lines · Markus Armbruster
Quoted 122 lines · Ryan Harper
Quoted 74 lines · Michael S. Tsirkin
Quoted 54 lines · Ryan Harper
Quoted 53 lines · Michael S. Tsirkin
Quoted 51 lines · Ryan Harper
Quoted 25 lines
I like the idea of disconnect; if part of the device_del method was to
invoke a disconnect method, we could implement that for block, net, etc;I'd think we'd want to send the notification, then disconnect.
Struggling with whether it's worth having some reasonable timeout
between notification and disconnect.The problem with this is that it has no analog in real world.
In real world, you can send some notifications to the guest, and you can
remove the card. Tying them together is what created the problem in the
first place.Timeouts can be implemented by management, maybe with a nice dialog
being shown to the user.Very true. I'm fine with forcing a disconnect during the removal path
prior to notification. Do we want a new disconnect method at the device
level (pci)? or just use the existing removal callback and call that
during the initial hotremov event?Not sure what you mean by that, but I don't see a device doing anything
differently wrt surprise or ordered removal. So probably the existing
callback should do. I don't think we need to talk about disconnect:
since we decided we are emulating device removal, let's call it
just that.Because current the "removal" process depends on the guest actually responding. What I'm suggesting is that, in Marcus's term, and what
drive_unplug()implements, is to disconnect the host block device from the guest device to prevent any further access to it in the case the guest doesn't respond to the removal request made via ACPI.Very specifically, what we're suggesting instead of the
drive_unplug()command so to complete the device removal operation without waiting for the guest to respond; that's what's going to happen if we invoke the response callback; it will appear as if the guest responded whether it did or not.What I was suggesting above was to instead of calling the callback for handing the guest response was to add a device function called disconnect which would remove any association of host resources from guest resources before we notified the guest. Thinking about it again I'm not sure this is useful, but if we're going to remove the device without the guests knowledge, I'm not sure how useful sending the removal requests via ACPI is in the first place.
My feeling is that I'd like to have explicit control over the disconnect from host resources separate from the device removal *if* we're going to retain the guest notification. If we don't care to notify the guest, then we can just do device removal without notifying the guest and be done with it.
Quoted 6 lines
Quoted 4 lines
I imagine management would typically want to do this:
1. notify guest
2. wait a bit
3. remove deviceYes; but this argues for (1) being a separate command from (3)
Yes. Long term I think we will want a way to do that.
Quoted 10 lines
unless we
require (3) to include (1) and (2) in the qemu implementation.Currently we implement:
1.
device_del(attempt to remove device)
2. notify guest
3. if guest responds, remove device
4. disconnect host resource from device on destructionQuoted 5 lines
Quoted 3 lines
With my
drive_unplugpatch we do:1. disconnect host resource from device
This is what
drive_unplugdoes, right?Correct.
Quoted 8 lines
Quoted 8 lines
2.
device_del(attempt to remove device)
3. notify guest
4. if guest responds, remove deviceI think we're suggesting to instead do (if we keep disconnect as part of
device_del)Quoted 8 lines
Quoted 4 lines
1.
device_del(attemp to remove device)
2. notify guest
3. invoke device destruction callback resulting in disconnect host resource from device
4. if guest responds, invoke device destruction path a second time.By response you mean eject? No, this is not what I was suggesting. I was really suggesting that your patch is fine :)
Sorry about confusion.I don't mean eject; I mean responding to the ACPI event by writing a response to the PCI chipset which QEMU then in turn will invoke the
qdev_unplug()path which ultimately kills the device and the Drive and BlockState objects.Quoted 9 lines
I was also saying that from what I hear, the pci express support will at some point need interfaces to
- notify guest about device removal/addition
- get eject from guest
- remove device without talking to guest
- add device without talking to guest
- suppress device deletion on ejectQuoted 4 lines
All this can be generic and can work through express configuration mechanisms or through acpi for pci. But this is completely separate from unplugging the host backend, which should be possible at any point.
Yes. I think we've worked out that we do want an independent unplug/disconnect mechanism rather than tying it to
device_del.Quoted 6 lines
Quoted 4 lines
Marcus, it sounds like then you wanted to see a net_unplug/disconnect and that instead of having
device_delalways succeed and replacing it with a shell, we'd need to provide an explicit command to do the disconnect in a similar fashion to how we're doingdrive_unplug?I'm not sure I parse this.
You were asking for net and block disconnect to have similar mechanisms. You mentioned the net fix for suprise removal was to have
device_del()always succeed by replacing the device with a shell/zombie. Thedrive_unplug()patch doesn't do the same thing; it doesn't affect thedevice_del()path at all, rather it provides mgmt apps a hook to directly disconnect host resource from guest resource.Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Yes, the shell thing is just an implementation detail.
ok. What qemu monitor command do I call for net delete to do the "disconnect/unplug"?
netdev_delOK. With
netdev_delanddrive_unplugcommands (not sure if we care to change the names to be similar, maybeblockdev_del) in qemu, we can then implement the following in libvirt:1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) issue netdev_del/blockdev_del as appropriate for the device type
4) update guest XML to indicate device has been removedAnd a fancier version would look like:
1) detach-device invocation
2) issuedevice_delto QEMU
2a) notification is sent)
3) set a timeout for guest to respond
4) when timeout expires
4a) check if the pci device has been removed by quering QEMU
if it hasn't been removed, issue netdev_del/blockdev_del
5) update guest XML to indicate device has been removedin both cases, I think we'll also want a patch that validates that the pci slot is available before handing it out again; this will handle the case where the guest doesn't respond to the device removal request; our
net/blockdev_delcommand will break the host/guest association, but we don't want to attempt to attach a device to the same slot.Quoted 6 lines
Marcus, do you think we're at a point where the mechanisms for explicitly revoking access to the host resource is consistent between net and block?
If so, then I suppose I might have a consmetic patch to fix up the monitor command name to line up with the
netdev_del.I'd be fine with any of these:
Quoted 8 lines
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.
I think it's cleaner not to introduce a concept of a disconnected backend.
One thing that we must be careful to explicitly disallow, is reconnecting guest to another host backend. The reason being that guest might rely on backend features and changing these would break this.
Given that, disconnecting without delete isn't helpful.
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.
I don't see how it's more dangerous than disconnecting. If guest can't access the backend it might not exist as far as guest is concerned.
Quoted 1 line
Do you need anything else from me to make progress?
Let's go for 3. Need for 1/2 seems dubious, and it's much harder to support.
Signature · 1 line
MST
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.I think it's cleaner not to introduce a concept of a disconnected backend.
Backends start disconnected, so the concept already exists.
Quoted 6 lines
One thing that we must be careful to explicitly disallow, is reconnecting guest to another host backend. The reason being that guest might rely on backend features and changing these would break this.
Given that, disconnecting without delete isn't helpful.
What about disconnect, hot plug new device, connect?
Quoted 9 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.I don't see how it's more dangerous than disconnecting. If guest can't access the backend it might not exist as far as guest is concerned.
If we keep disconnect and delete separate operations, we can make delete fail when still connected. Typo insurance.
Quoted 4 lines
Quoted 1 line
Do you need anything else from me to make progress?
Let's go for 3. Need for 1/2 seems dubious, and it's much harder to support.
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.
No, I have netdev_del as (3).
All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.
Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).
I'd call it drive_del for now, to match drive_add.
Quoted 4 lines
Quoted 1 line
Do you need anything else from me to make progress?
I think just an agreement on the approach; shouldn't take more than a few hours to respin the qemu and libvirt side.
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.
OK, drive_del() and as you mentioned, drive_unplug will take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll want drive_del to remove the dinfo object as well.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 61 lines · Ryan Harper
Quoted 60 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).
Quoted 6 lines
Quoted 1 line
I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.
Exactly.
a. bdrv_detach() to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c. drive_uninit() to dispose of the host part
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every HOSTDEV_del. Except for netdev_del, which is special because of VLANs.
To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use drive_uninit() for that then.
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
Quoted 70 lines · Markus Armbruster
Quoted 61 lines · Ryan Harper
Quoted 60 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).Quoted 6 lines
Quoted 1 line
I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host part
a-c need to be done to match netdev_del symmetry? How hard of a req is this?
Quoted 7 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.
Quoted 6 lines
To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug() works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the dinfo() object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 71 lines · Ryan Harper
Quoted 70 lines · Markus Armbruster
Quoted 67 lines · Ryan Harper
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.
Quoted 8 lines
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host parta-c need to be done to match
netdev_delsymmetry? How hard of a req is this?
Without (c), it's not a delete. And (c) without (b) leaves a dangling pointer. (c) without (a) fails an assertion in bdrv_delete().
Aside: (b) should probably be folded into bdrv_detach().
Quoted 10 lines
Quoted 10 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.
Quoted 6 lines
Quoted 2 lines
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug()works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.
Sometimes it takes a tough man to make a tender chicken.
Quoted 5 lines
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the
dinfo()object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.
Steps a, b, c are the result of my (admittedly quick) audit.
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo
|
| .bdrv
| .id == .bdrv->device_name
|
contains V
bdrv_states -----------> BlockDriverState
| ^
.peer | |
| | host part
-----------------------------|---|-----------------------------------
| | guest part
| | property "drive"
v |DeviceState
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
Quoted 131 lines · Markus Armbruster
Quoted 71 lines · Ryan Harper
Quoted 70 lines · Markus Armbruster
Quoted 67 lines · Ryan Harper
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.Quoted 8 lines
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host parta-c need to be done to match
netdev_delsymmetry? How hard of a req is this?Without (c), it's not a delete. And (c) without (b) leaves a dangling pointer. (c) without (a) fails an assertion in
bdrv_delete().Aside: (b) should probably be folded into
bdrv_detach().Quoted 10 lines
Quoted 10 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.Quoted 6 lines
Quoted 2 lines
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug()works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.Sometimes it takes a tough man to make a tender chicken.
Quoted 5 lines
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the
dinfo()object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.Steps a, b, c are the result of my (admittedly quick) audit.
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |
Quoted 5 lines
DeviceState
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
If we remove DriveInfo, how can management later detect that guest part was deleted? If you want symmetry with netdev, it's possible to keep a shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
Signature · 1 line
MST
Quoted 134 lines · Michael S. Tsirkin
Quoted 133 lines · Markus Armbruster
Quoted 71 lines · Ryan Harper
Quoted 70 lines · Markus Armbruster
Quoted 67 lines · Ryan Harper
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.Quoted 8 lines
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host parta-c need to be done to match
netdev_delsymmetry? How hard of a req is this?Without (c), it's not a delete. And (c) without (b) leaves a dangling pointer. (c) without (a) fails an assertion in
bdrv_delete().Aside: (b) should probably be folded into
bdrv_detach().Quoted 10 lines
Quoted 10 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.Quoted 6 lines
Quoted 2 lines
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug()works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.Sometimes it takes a tough man to make a tender chicken.
Quoted 5 lines
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the
dinfo()object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.Steps a, b, c are the result of my (admittedly quick) audit.
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |DeviceState
Quoted 7 lines
Quoted 3 lines
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
If we remove DriveInfo, how can management later detect that guest part was deleted?
Directly: check whether the qdev is gone.
I don't know how to check that indirectly, via DriveInfo.
Quoted 3 lines
If you want symmetry with netdev, it's possible to keep a
shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
netdev_del deletes the host network part:
(qemu) info network
Devices not on any VLAN:
net.0: net=10.0.2.0, restricted=n peer=nic.0
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
(qemu) netdev_del net.0
(qemu) info network
Devices not on any VLAN:
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
It leaves around the VLAN object. Since qdev property points to that, it doesn't dangle.
In my opinion, drive_del should make the drive vanish from "info block", just like netdev_del makes the netdev vanish from "info network". And that means deleting it from bdrv_states. Whether we delete it alltogether (which is what I sketched), or turn it into a zombie is a separate question. Both work for me.
Quoted 163 lines · Markus Armbruster
Quoted 134 lines · Michael S. Tsirkin
Quoted 133 lines · Markus Armbruster
Quoted 71 lines · Ryan Harper
Quoted 70 lines · Markus Armbruster
Quoted 67 lines · Ryan Harper
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.Quoted 8 lines
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host parta-c need to be done to match
netdev_delsymmetry? How hard of a req is this?Without (c), it's not a delete. And (c) without (b) leaves a dangling pointer. (c) without (a) fails an assertion in
bdrv_delete().Aside: (b) should probably be folded into
bdrv_detach().Quoted 10 lines
Quoted 10 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.Quoted 6 lines
Quoted 2 lines
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug()works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.Sometimes it takes a tough man to make a tender chicken.
Quoted 5 lines
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the
dinfo()object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.Steps a, b, c are the result of my (admittedly quick) audit.
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |DeviceState
Quoted 7 lines
Quoted 3 lines
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
If we remove DriveInfo, how can management later detect that guest part was deleted?
Directly: check whether the qdev is gone.
I don't know how to check that indirectly, via DriveInfo.
Quoted 3 lines
If you want symmetry with netdev, it's possible to keep a
shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
netdev_deldeletes the host network part:(qemu) info network
Devices not on any VLAN:
net.0: net=10.0.2.0, restricted=n peer=nic.0
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
(qemu)netdev_delnet.0
(qemu) info network
Devices not on any VLAN:
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
Quoted 4 lines
It leaves around the VLAN object. Since qdev property points to that, it doesn't dangle.
In my opinion,
drive_delshould make the drive vanish from "info block",
Yeah; that's the right thing to do here. Let me respin the patch with the name change and the additional work to fix up the pointers and ensure that we don't see the drive in info block.
Quoted 4 lines
just like
netdev_delmakes the netdev vanish from "info network". And that means deleting it frombdrv_states. Whether we delete it alltogether (which is what I sketched), or turn it into a zombie is a separate question. Both work for me.
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 141 lines · Markus Armbruster
Quoted 139 lines · Michael S. Tsirkin
Quoted 136 lines · Markus Armbruster
Quoted 71 lines · Ryan Harper
Quoted 70 lines · Markus Armbruster
Quoted 67 lines · Ryan Harper
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.Quoted 8 lines
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host parta-c need to be done to match
netdev_delsymmetry? How hard of a req is this?Without (c), it's not a delete. And (c) without (b) leaves a dangling pointer. (c) without (a) fails an assertion in
bdrv_delete().Aside: (b) should probably be folded into
bdrv_detach().Quoted 10 lines
Quoted 10 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.Quoted 6 lines
Quoted 2 lines
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug()works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.Sometimes it takes a tough man to make a tender chicken.
Quoted 5 lines
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the
dinfo()object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.Steps a, b, c are the result of my (admittedly quick) audit.
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |DeviceState
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
Quoted 4 lines
Quoted 2 lines
If we remove DriveInfo, how can management later detect that guest part was deleted?
Directly: check whether the qdev is gone.
With info qdev?
I am not at all sure we want management to do that, it'll require that we keep the output stable.
info block is already parsed, it's easier for management to look there.
Quoted 17 lines
I don't know how to check that indirectly, via DriveInfo.
Quoted 3 lines
If you want symmetry with netdev, it's possible to keep a
shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
netdev_deldeletes the host network part:(qemu) info network
Devices not on any VLAN:
net.0: net=10.0.2.0, restricted=n peer=nic.0
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
(qemu)netdev_delnet.0
(qemu) info network
Devices not on any VLAN:
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
Quoted 5 lines
It leaves around the VLAN object. Since qdev property points to that, it doesn't dangle.
In my opinion,
drive_delshould make the drive vanish from "info block", just likenetdev_delmakes the netdev vanish from "info network".
Yes but we need to have something left on info block IMO.
Quoted 4 lines
And
that means deleting it frombdrv_states. Whether we delete it alltogether (which is what I sketched), or turn it into a zombie is a separate question. Both work for me.
Quoted 164 lines · Ryan Harper
Quoted 163 lines · Markus Armbruster
Quoted 134 lines · Michael S. Tsirkin
Quoted 133 lines · Markus Armbruster
Quoted 71 lines · Ryan Harper
Quoted 70 lines · Markus Armbruster
Quoted 67 lines · Ryan Harper
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.Quoted 8 lines
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host parta-c need to be done to match
netdev_delsymmetry? How hard of a req is this?Without (c), it's not a delete. And (c) without (b) leaves a dangling pointer. (c) without (a) fails an assertion in
bdrv_delete().Aside: (b) should probably be folded into
bdrv_detach().Quoted 10 lines
Quoted 10 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.Quoted 6 lines
Quoted 2 lines
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug()works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.Sometimes it takes a tough man to make a tender chicken.
Quoted 5 lines
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the
dinfo()object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.Steps a, b, c are the result of my (admittedly quick) audit.
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |DeviceState
Quoted 7 lines
Quoted 3 lines
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
If we remove DriveInfo, how can management later detect that guest part was deleted?
Directly: check whether the qdev is gone.
I don't know how to check that indirectly, via DriveInfo.
Quoted 3 lines
If you want symmetry with netdev, it's possible to keep a
shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
netdev_deldeletes the host network part:(qemu) info network
Devices not on any VLAN:
net.0: net=10.0.2.0, restricted=n peer=nic.0
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
(qemu)netdev_delnet.0
(qemu) info network
Devices not on any VLAN:
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
Quoted 8 lines
Quoted 4 lines
It leaves around the VLAN object. Since qdev property points to that, it doesn't dangle.
In my opinion,
drive_delshould make the drive vanish from "info block",Yeah; that's the right thing to do here. Let me respin the patch with the name change and the additional work to fix up the pointers and ensure that we don't see the drive in info block.
Daniel, I'd like your input here: can you live with device diappearing from info block and parsing qdev tree info to figure out whether device is really gone?
Quoted 11 lines
Quoted 4 lines
just like
netdev_delmakes the netdev vanish from "info network". And that means deleting it frombdrv_states. Whether we delete it alltogether (which is what I sketched), or turn it into a zombie is a separate question. Both work for me.Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Ryan Harper
Quoted 51 lines · Markus Armbruster
Quoted 19 lines · Michael S. Tsirkin
Quoted 19 lines
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |DeviceState
Quoted 7 lines
Quoted 3 lines
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
If we remove DriveInfo, how can management later detect that guest part was deleted?
Directly: check whether the qdev is gone.
I don't know how to check that indirectly, via DriveInfo.
Quoted 3 lines
If you want symmetry with netdev, it's possible to keep a
shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
netdev_deldeletes the host network part:(qemu) info network
Devices not on any VLAN:
net.0: net=10.0.2.0, restricted=n peer=nic.0
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
(qemu)netdev_delnet.0
(qemu) info network
Devices not on any VLAN:
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0It leaves around the VLAN object. Since qdev property points to that, it doesn't dangle.
In my opinion,
drive_delshould make the drive vanish from "info block",
Quoted 7 lines
Quoted 3 lines
Yeah; that's the right thing to do here. Let me respin the patch with the name change and the additional work to fix up the pointers and ensure that we don't see the drive in info block.
Daniel, I'd like your input here: can you live with device diappearing from info block and parsing qdev tree info to figure out whether device is really gone?
We don't use info block for anything. Having to parse the full qdev tree to determine if a single device is gone seems rather tedious. It would be better if query-qdev took an optional argument, which is the name of the device to root the tree at. Then checking whether a device named 'foo' is gone just means running 'query-qdev foo' and seeing if that returns an error about the device not existing, then we know it has gone. No need to parse anything. Being able to query the qdev data for a single device, or sub-tree of devices seems useful in its own right.
Regards,
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 170 lines · Michael S. Tsirkin
Quoted 169 lines · Ryan Harper
Quoted 167 lines · Markus Armbruster
Quoted 134 lines · Michael S. Tsirkin
Quoted 133 lines · Markus Armbruster
Quoted 71 lines · Ryan Harper
Quoted 70 lines · Markus Armbruster
Quoted 67 lines · Ryan Harper
Quoted 54 lines · Markus Armbruster
Quoted 10 lines · Ryan Harper
Quoted 6 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.This is sort of what
netdev_del()anddrive_unplug()are today; we're just saying sever the connection of this device id.No, I have
netdev_delas (3).All three options are "sort of" the same, just different commands with a common purpose.
Quoted 4 lines
I'd like to rename
drive_unplug()toblockdev_del()and call it done. I was looking at libvirt and the right call tonetdev_delis already in-place; I'd just need to re-spin my block patch to callblockdev_del()after invokingdevice_del()to match what is done for net.Unless I'm missing something, you can't just rename: your unplug does not delete the host part.
Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.What's the advantage here? We need an additional piece of info (host part) in addition to the device id?
That's a disadvantage.
Possible advantage: implementation could be slightly easier than (1), because you don't have to find the host parts.
Quoted 7 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.Hrm, I thought that's what (1) is.
No.
With (1), the argument is a *device* ID, and we disconnect *all* host parts connected to this device (typically just one).
With (3), the argument is a netdev/drive ID, and disconnect *this* host part from the peer device.
Quoted 7 lines
Quoted 5 lines
Well, either (1) or (3); I'd like to
renamedrive_unplug()toblockdev_del()since they're similar function w.r.t removing access to the host resource. And we can invoke them in the same way from libvirt (after doing guest notification, remove access).I'd call it
drive_delfor now, to matchdrive_add.OK,
drive_del()and as you mentioned,drive_unplugwill take out the block driver, but doesn't remove the dinfo object; that ends up dying when we call the device destructor. I think for symmetry we'll wantdrive_delto remove the dinfo object as well.Quoted 8 lines
Quoted 5 lines
Exactly.
a.
bdrv_detach()to zap the pointer from bdrv to qdev b. zap the pointer from qdev to bdrv
c.drive_uninit()to dispose of the host parta-c need to be done to match
netdev_delsymmetry? How hard of a req is this?Without (c), it's not a delete. And (c) without (b) leaves a dangling pointer. (c) without (a) fails an assertion in
bdrv_delete().Aside: (b) should probably be folded into
bdrv_detach().Quoted 10 lines
Quoted 10 lines
Step b could be awkward with (3), because you don't know device details. I guess you have to search device properties for a drive property pointing to bdrv. I like (1) because it puts that loop in the one place where it belongs: qdev core. (3) duplicates it in every
HOSTDEV_del. Except fornetdev_del, which is special because of VLANs.To avoid step b, you could try to keep the bdrv around in a special zombie state. Still have to free the dinfo, but can't use
drive_uninit()for that then.Quoted 6 lines
Quoted 2 lines
If you think I'm overcomplicating this, feel free to prove me wrong with working code :)
drive_unplug()works as-is today; so it does feel very combursome at this point. Other than the name change and agreement on how mgmt should invoke the command, it's been a long ride to get here.Sometimes it takes a tough man to make a tender chicken.
Quoted 5 lines
I'll take my best shot at trying to clean up the other pointers and objects; though on one of my attempts when I took out the
dinfo()object that didn't go so well; going to have to audit who uses dinfo and where and what they check before calling it to have a proper cleanup that doesn't remove the whole device altogether.Steps a, b, c are the result of my (admittedly quick) audit.
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |DeviceState
Quoted 7 lines
Quoted 3 lines
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
If we remove DriveInfo, how can management later detect that guest part was deleted?
Directly: check whether the qdev is gone.
I don't know how to check that indirectly, via DriveInfo.
Quoted 3 lines
If you want symmetry with netdev, it's possible to keep a
shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
netdev_deldeletes the host network part:(qemu) info network
Devices not on any VLAN:
net.0: net=10.0.2.0, restricted=n peer=nic.0
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
(qemu)netdev_delnet.0
(qemu) info network
Devices not on any VLAN:
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0It leaves around the VLAN object. Since qdev property points to that, it doesn't dangle.
In my opinion,
drive_delshould make the drive vanish from "info block",
Quoted 7 lines
Quoted 3 lines
Yeah; that's the right thing to do here. Let me respin the patch with the name change and the additional work to fix up the pointers and ensure that we don't see the drive in info block.
Daniel, I'd like your input here: can you live with device diappearing from info block and parsing qdev tree info to figure out whether device is really gone?
AFAICT, libvirt doesn't look at or use info block at all.
I'd rather not have to add info block to libvirt; but currently I can't see how else we can determine if we should call drive_unplug if we do a device_del() and the guest removes it before we call drive_unplug().
What happens is that the guest removes the device and when we call drive_unplug() it fails to find the target device (since it was deleted by the guest). Then we fail the PCiDelDisk and libvirt keeps the device config around even though the guest has finished removing it.
The only way I see out of this is to either movethe severing of host/guest before doing the delete (and notification). Or adding some code to parse info block and don't bother calling unplug if the blockdevice is already deleted.
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
just like
netdev_delmakes the netdev vanish from "info network". And that means deleting it frombdrv_states. Whether we delete it alltogether (which is what I sketched), or turn it into a zombie is a separate question. Both work for me.Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 63 lines · Daniel P. Berrange
Quoted 54 lines · Michael S. Tsirkin
Quoted 53 lines · Ryan Harper
Quoted 51 lines · Markus Armbruster
Quoted 19 lines · Michael S. Tsirkin
Quoted 19 lines
Here's how the various objects are connected to each other:
contains
drivelist -----------> DriveInfo| | .bdrv | .id == .bdrv->device_name | contains V bdrv_states -----------> BlockDriverState | ^ .peer | | | | host part -----------------------------|---|----------------------------------- | | guest part | | property "drive" v |DeviceState
Quoted 7 lines
Quoted 3 lines
To disconnect host from guest part, you need to cut both pointers. To delete the host part, you need to delete both objects, BlockDriverState and DriveInfo.
If we remove DriveInfo, how can management later detect that guest part was deleted?
Directly: check whether the qdev is gone.
I don't know how to check that indirectly, via DriveInfo.
Quoted 3 lines
If you want symmetry with netdev, it's possible to keep a
shell of BlockDriverState/DriveInfo around (solving dangling pointer problems).
netdev_deldeletes the host network part:(qemu) info network
Devices not on any VLAN:
net.0: net=10.0.2.0, restricted=n peer=nic.0
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0
(qemu)netdev_delnet.0
(qemu) info network
Devices not on any VLAN:
nic.0: model=virtio-net-pci,macaddr=52:54:00:12:34:56 peer=net.0It leaves around the VLAN object. Since qdev property points to that, it doesn't dangle.
In my opinion,
drive_delshould make the drive vanish from "info block",Quoted 7 lines
Quoted 3 lines
Yeah; that's the right thing to do here. Let me respin the patch with the name change and the additional work to fix up the pointers and ensure that we don't see the drive in info block.
Daniel, I'd like your input here: can you live with device diappearing from info block and parsing qdev tree info to figure out whether device is really gone?
Quoted 9 lines
We don't use info block for anything. Having to parse the full qdev tree to determine if a single device is gone seems rather tedious. It would be better if query-qdev took an optional argument, which is the name of the device to root the tree at. Then checking whether a device named 'foo' is gone just means running 'query-qdev foo' and seeing if that returns an error about the device not existing, then we know it has gone. No need to parse anything. Being able to query the qdev data for a single device, or sub-tree of devices seems useful in its own right.
Since I'm not looking forward to parsing info block (easy) nor parsing all of qdev tree (much harder) I really like the query approach.
That makes it easy to put a query in the netdev_del/drive_del commands to skip invoking them if the guest has already responded.
Quoted 8 lines
Regards,
DanielSignature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Signature · 4 lines
Ryan Harper Software Engineer; Linux Technology Center IBM Corp., Austin, Tx [email protected]
Quoted 13 lines · Ryan Harper
Quoted 9 lines · Michael S. Tsirkin
Quoted 4 lines · Ryan Harper
Quoted 3 lines · Markus Armbruster
Quoted 1 line · Michael S. Tsirkin
On Mon, Nov 08, 2010 at 11:32:01AM +0100, Markus Armbruster wrote:
Daniel, I'd like your input here: can you live with device diappearing from info block and parsing qdev tree info to figure out whether device is really gone?
AFAICT, libvirt doesn't look at or use info block at all.
Quoted 8 lines
I'd rather not have to add info block to libvirt; but currently I can't see how else we can determine if we should call
drive_unplugif we do adevice_del()and the guest removes it before we calldrive_unplug().What happens is that the guest removes the device and when we call
drive_unplug()it fails to find the target device (since it was deleted by the guest). Then we fail the PCiDelDisk and libvirt keeps the device config around even though the guest has finished removing it.
This needs drive_unplug to return an explicitly identifiable 'no such device' error code, which libvirt can catch and ignore. Making the call to drive_unplug conditional on a check to query-block/query-qdev is really a bug, because it has an designed in race condition which means you need to check for a 'no such device' error code regardless. So it is better to just blindly call drive_unplug and handle the non-fatal failure conditions every time - this ensures that codepath gets exercised more frequently too :-)
Regards,
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
Quoted 19 lines · Markus Armbruster
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Markus Armbruster
I'd be fine with any of these:
1. A new command "
device_disconnetID" (or similar name) to disconnect device ID from any host parts. Nice touch: you don't have to know about the device's host part(s) to disconnect it. But it might be more work than the other two.Quoted 6 lines
Quoted 3 lines
2. New commands
netdev_disconnect,drive_disconnect(or similar names) to disconnect a host part from a guest device. Like (1), except you have to point to the other end of the connection to cut it.I think it's cleaner not to introduce a concept of a disconnected backend.
Backends start disconnected, so the concept already exists.
Quoted 8 lines
Quoted 6 lines
One thing that we must be careful to explicitly disallow, is reconnecting guest to another host backend. The reason being that guest might rely on backend features and changing these would break this.
Given that, disconnecting without delete isn't helpful.
What about disconnect, hot plug new device, connect?
Exactly. I don't think we want to support this. New device might not support all features that old one has. Or it may have more features.
Quoted 17 lines
Quoted 9 lines
Quoted 5 lines
3. A new command "
drive_delID" similar to existingnetdev_del. This is
(2) fused with delete. Conceptual wart: you can't disconnect and keep the host part around. Moreover, delete is slightly dangerous, because it renders any guest device still using the host part useless.I don't see how it's more dangerous than disconnecting. If guest can't access the backend it might not exist as far as guest is concerned.
If we keep disconnect and delete separate operations, we can make delete fail when still connected. Typo insurance.
Quoted 4 lines
Quoted 1 line
Do you need anything else from me to make progress?
Let's go for 3. Need for 1/2 seems dubious, and it's much harder to support.