@@ -498,6 +498,13 @@ typedef struct BdrvAioNotifier {
QLIST_ENTRY(BdrvAioNotifier) list;
} BdrvAioNotifier;
+typedef struct BdrvDeletedStatus {
+ /* Set to true by bdrv_delete() */
+ bool deleted;
+
+ QLIST_ENTRY(BdrvDeletedStatus) next;
+} BdrvDeletedStatus;
+
struct BdrvChildRole {
/* If true, bdrv_replace_node() doesn't change the node this BdrvChild
* points to. */
@@ -706,6 +713,11 @@ struct BlockDriverState {
/* Only read/written by whoever has set active_flush_req to true. */
unsigned int flushed_gen; /* Flushed write generation */
+
+ /* When bdrv_delete() is invoked, it will walk through this list
+ * and set every entry's @deleted field to true. The entries will
+ * not be freed automatically. */
+ QLIST_HEAD(, BdrvDeletedStatus) deleted_status;
};
struct BlockBackendRootState {
@@ -3246,10 +3246,16 @@ out:
static void bdrv_delete(BlockDriverState *bs)
{
+ BdrvDeletedStatus *del_stat;
+
assert(!bs->job);
assert(bdrv_op_blocker_is_empty(bs));
assert(!bs->refcnt);
+ QLIST_FOREACH(del_stat, &bs->deleted_status, next) {
+ del_stat->deleted = true;
+ }
+
bdrv_close(bs);
/* remove from list, if necessary */
Sometimes an operation may delete a BDS. It may then not be trivial to determine this because the BDS object itself cannot be accessed afterwards. With this patch, one can attach a BdrvDeletedStatus object to a BDS which can be used to safely query whether the BDS still exists even after it has been deleted. Signed-off-by: Max Reitz <mreitz@redhat.com> --- include/block/block_int.h | 12 ++++++++++++ block.c | 6 ++++++ 2 files changed, 18 insertions(+)