From f3930ed0bb1945b59da8e591072b5c79606d0760 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Wed, 8 Apr 2015 13:43:47 +0200 Subject: block: Move flag inheritance to bdrv_open_inherit() Instead of letting every caller of bdrv_open() determine the right flags for its child node manually and pass them to the function, pass the parent node and the role of the newly opened child (like backing file, protocol layer, etc.). Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- include/block/block_int.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include/block/block_int.h') diff --git a/include/block/block_int.h b/include/block/block_int.h index f004378d58..662dd56afe 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -330,6 +330,13 @@ typedef struct BdrvAioNotifier { QLIST_ENTRY(BdrvAioNotifier) list; } BdrvAioNotifier; +struct BdrvChildRole { + int (*inherit_flags)(int parent_flags); +}; + +extern const BdrvChildRole child_file; +extern const BdrvChildRole child_format; + /* * Note: the function bdrv_append() copies and swaps contents of * BlockDriverStates, so if you add new fields to this struct, please -- cgit v1.2.3 From 6e93e7c41fdfdee3068770cae79380e1d986b76a Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Wed, 8 Apr 2015 13:49:41 +0200 Subject: block: Add list of children to BlockDriverState This allows iterating over all children of a given BDS, not only including bs->file and bs->backing_hd, but also driver-specific ones like VMDK extents or Quorum children. For bdrv_swap(), the list of children of the swapped BDS stays at that BDS (because that's where the pointers stay as well). The list head moves and pointers to it must be fixed up therefore. The list of children in the parent of the swapped BDS is not affected by the swap. The contents of the BDS objects is swapped, so the existing pointer in the parent automatically points to the newly swapped in BDS. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- include/block/block_int.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include/block/block_int.h') diff --git a/include/block/block_int.h b/include/block/block_int.h index 662dd56afe..4ae58606a6 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -337,6 +337,12 @@ struct BdrvChildRole { extern const BdrvChildRole child_file; extern const BdrvChildRole child_format; +typedef struct BdrvChild { + BlockDriverState *bs; + const BdrvChildRole *role; + QLIST_ENTRY(BdrvChild) next; +} BdrvChild; + /* * Note: the function bdrv_append() copies and swaps contents of * BlockDriverStates, so if you add new fields to this struct, please @@ -431,6 +437,8 @@ struct BlockDriverState { /* long-running background operation */ BlockJob *job; + QLIST_HEAD(, BdrvChild) children; + QDict *options; BlockdevDetectZeroesOptions detect_zeroes; -- cgit v1.2.3 From bddcec3745b0220d4a7eda700950812a94398668 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 9 Apr 2015 18:47:50 +0200 Subject: block: Add BlockDriverState.inherits_from Currently, the block layer assumes that any block node can have only one parent, and if it has a parent, that it inherits some options/flags from this parent. This is not true any more: With references used in block device creation, a single node can be used by multiple parents, or it can be created separately and not inherit flags from any parent. To handle reopens correctly, a node must know from which parent it inherited options. This patch adds the information to BlockDriverState. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- include/block/block_int.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/block/block_int.h') diff --git a/include/block/block_int.h b/include/block/block_int.h index 4ae58606a6..2732ccdaae 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -437,6 +437,10 @@ struct BlockDriverState { /* long-running background operation */ BlockJob *job; + /* The node that this node inherited default options from (and a reopen on + * which can affect this node by changing these defaults). This is always a + * parent node of this node. */ + BlockDriverState *inherits_from; QLIST_HEAD(, BdrvChild) children; QDict *options; -- cgit v1.2.3