diff mbox series

[v2,03/33] block: Add BdrvChildRole

Message ID 20200204170848.614480-4-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: Introduce real BdrvChildRole | expand

Commit Message

Max Reitz Feb. 4, 2020, 5:08 p.m. UTC
This enum will supplement BdrvChildClass when it comes to what role (or
combination of roles) a child takes for its parent.

Because empty enums are not allowed, let us just start with it filled.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 include/block/block.h | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

Comments

Eric Blake Feb. 5, 2020, 3:24 p.m. UTC | #1
On 2/4/20 11:08 AM, Max Reitz wrote:
> This enum will supplement BdrvChildClass when it comes to what role (or
> combination of roles) a child takes for its parent.
> 
> Because empty enums are not allowed, let us just start with it filled.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   include/block/block.h | 27 +++++++++++++++++++++++++++
>   1 file changed, 27 insertions(+)
> 
> diff --git a/include/block/block.h b/include/block/block.h
> index 38963ef203..0f7e8caa5b 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -279,6 +279,33 @@ enum {
>       DEFAULT_PERM_UNCHANGED      = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH,
>   };
>   
> +typedef enum BdrvChildRole {
> +    /* Child stores data */
> +    BDRV_CHILD_DATA         = (1 << 0),
> +
> +    /* Child stores metadata */
> +    BDRV_CHILD_METADATA     = (1 << 1),
> +
> +    /* Filtered child */
> +    BDRV_CHILD_FILTERED     = (1 << 2),

I'm not sure this comment does justice for what the flag represents, but 
am not sure of what longer comment to put in its place.

> +
> +    /* Child to COW from (backing child) */
> +    BDRV_CHILD_COW          = (1 << 3),
> +
> +    /*
> +     * The primary child.  For most drivers, this is the child whose
> +     * filename applies best to the parent node.
> +     * Each parent must give this flag to no more than one child at a
> +     * time.
> +     */
> +    BDRV_CHILD_PRIMARY      = (1 << 4),
> +
> +    /* Useful combination of flags */
> +    BDRV_CHILD_IMAGE        = BDRV_CHILD_DATA
> +                              | BDRV_CHILD_METADATA
> +                              | BDRV_CHILD_PRIMARY,
> +} BdrvChildRole;
> +
>   char *bdrv_perm_names(uint64_t perm);
>   uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm);
>   
> 

Whether or not you can improve the comment, the enum makes sense.

Reviewed-by: Eric Blake <eblake@redhat.com>
Max Reitz Feb. 6, 2020, 10:47 a.m. UTC | #2
On 05.02.20 16:24, Eric Blake wrote:
> On 2/4/20 11:08 AM, Max Reitz wrote:
>> This enum will supplement BdrvChildClass when it comes to what role (or
>> combination of roles) a child takes for its parent.
>>
>> Because empty enums are not allowed, let us just start with it filled.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>   include/block/block.h | 27 +++++++++++++++++++++++++++
>>   1 file changed, 27 insertions(+)
>>
>> diff --git a/include/block/block.h b/include/block/block.h
>> index 38963ef203..0f7e8caa5b 100644
>> --- a/include/block/block.h
>> +++ b/include/block/block.h
>> @@ -279,6 +279,33 @@ enum {
>>       DEFAULT_PERM_UNCHANGED      = BLK_PERM_ALL &
>> ~DEFAULT_PERM_PASSTHROUGH,
>>   };
>>   +typedef enum BdrvChildRole {
>> +    /* Child stores data */
>> +    BDRV_CHILD_DATA         = (1 << 0),
>> +
>> +    /* Child stores metadata */
>> +    BDRV_CHILD_METADATA     = (1 << 1),
>> +
>> +    /* Filtered child */
>> +    BDRV_CHILD_FILTERED     = (1 << 2),
> 
> I'm not sure this comment does justice for what the flag represents, but
> am not sure of what longer comment to put in its place.

You’re right.  I thought I could just rely on our .is_filter
documentation (at least after
https://lists.gnu.org/archive/html/qemu-devel/2019-08/msg01721.html),
but that doesn’t really apply here.

For example, this series makes raw (without further parameters) have a
CHILD_FILTERED child, without raw being a filter itself.

So there should indeed be some definition here.

Maybe:

A child to which the parent forwards all reads and writes.  Therefore,
this child presents exactly the same visible data as the parent.

Would that work?

Max
Max Reitz Feb. 6, 2020, 10:49 a.m. UTC | #3
On 06.02.20 11:47, Max Reitz wrote:
> On 05.02.20 16:24, Eric Blake wrote:
>> On 2/4/20 11:08 AM, Max Reitz wrote:
>>> This enum will supplement BdrvChildClass when it comes to what role (or
>>> combination of roles) a child takes for its parent.
>>>
>>> Because empty enums are not allowed, let us just start with it filled.
>>>
>>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>>> ---
>>>   include/block/block.h | 27 +++++++++++++++++++++++++++
>>>   1 file changed, 27 insertions(+)
>>>
>>> diff --git a/include/block/block.h b/include/block/block.h
>>> index 38963ef203..0f7e8caa5b 100644
>>> --- a/include/block/block.h
>>> +++ b/include/block/block.h
>>> @@ -279,6 +279,33 @@ enum {
>>>       DEFAULT_PERM_UNCHANGED      = BLK_PERM_ALL &
>>> ~DEFAULT_PERM_PASSTHROUGH,
>>>   };
>>>   +typedef enum BdrvChildRole {
>>> +    /* Child stores data */
>>> +    BDRV_CHILD_DATA         = (1 << 0),
>>> +
>>> +    /* Child stores metadata */
>>> +    BDRV_CHILD_METADATA     = (1 << 1),
>>> +
>>> +    /* Filtered child */
>>> +    BDRV_CHILD_FILTERED     = (1 << 2),
>>
>> I'm not sure this comment does justice for what the flag represents, but
>> am not sure of what longer comment to put in its place.
> 
> You’re right.  I thought I could just rely on our .is_filter
> documentation (at least after
> https://lists.gnu.org/archive/html/qemu-devel/2019-08/msg01721.html),
> but that doesn’t really apply here.
> 
> For example, this series makes raw (without further parameters) have a
> CHILD_FILTERED child, without raw being a filter itself.
> 
> So there should indeed be some definition here.
> 
> Maybe:
> 
> A child to which the parent forwards all reads and writes.  Therefore,
> this child presents exactly the same visible data as the parent.

On second thought, the “therefore” is wrong, because the first sentence
applies to quorum, but the logical conclusion does not.

So maybe rather:

A child to which the parent forwards all reads and writes.  It must
present exactly the same visible data as the parent.
Any node may have at most one filtered child at a time.

?

Max
Eric Blake Feb. 11, 2020, 3:35 p.m. UTC | #4
On 2/6/20 4:49 AM, Max Reitz wrote:

>>>> +
>>>> +    /* Filtered child */
>>>> +    BDRV_CHILD_FILTERED     = (1 << 2),
>>>
>>> I'm not sure this comment does justice for what the flag represents, but
>>> am not sure of what longer comment to put in its place.
>>
>> You’re right.  I thought I could just rely on our .is_filter
>> documentation (at least after
>> https://lists.gnu.org/archive/html/qemu-devel/2019-08/msg01721.html),
>> but that doesn’t really apply here.
>>
>> For example, this series makes raw (without further parameters) have a
>> CHILD_FILTERED child, without raw being a filter itself.
>>
>> So there should indeed be some definition here.
>>
>> Maybe:
>>
>> A child to which the parent forwards all reads and writes.  Therefore,
>> this child presents exactly the same visible data as the parent.
> 
> On second thought, the “therefore” is wrong, because the first sentence
> applies to quorum, but the logical conclusion does not.
> 
> So maybe rather:
> 
> A child to which the parent forwards all reads and writes.  It must
> present exactly the same visible data as the parent.
> Any node may have at most one filtered child at a time.

Yes, this works for me.
Alberto Garcia Feb. 11, 2020, 3:41 p.m. UTC | #5
On Tue 04 Feb 2020 06:08:18 PM CET, Max Reitz wrote:
> +    /* Child to COW from (backing child) */
> +    BDRV_CHILD_COW          = (1 << 3),

Without the comment in brackets I'm not sure that I would have
understood that this is meant for backing files.

This is the "child that contains the data that is not allocated in the
parent", or something like that, right?

Berto
Max Reitz Feb. 17, 2020, 2:40 p.m. UTC | #6
On 11.02.20 16:41, Alberto Garcia wrote:
> On Tue 04 Feb 2020 06:08:18 PM CET, Max Reitz wrote:
>> +    /* Child to COW from (backing child) */
>> +    BDRV_CHILD_COW          = (1 << 3),
> 
> Without the comment in brackets I'm not sure that I would have
> understood that this is meant for backing files.

I put it in brackets because bs->backing isn’t always such a child (for
filters it isn’t).  That’s also the reason why I prefer to stress the
COW aspect.

> This is the "child that contains the data that is not allocated in the
> parent", or something like that, right?

Hm, so I suppose the problem is that I didn’t describe in which event
the COW is to occur.  (I didn’t because we only have one kind of COW in
the block layer, namely for backing chains.)

So maybe “Child from which to read all data that isn’t allocated in the
parent (backing child); such data may be copied to the parent by means
of COW or COR”?

(The problem I see with this description is that it is kind of a
tautology, because “allocation” is in turn defined by differentiating
between layers of a backing chain, i.e. this layer and that backing/COW
child we’re talking about here.)

Max
diff mbox series

Patch

diff --git a/include/block/block.h b/include/block/block.h
index 38963ef203..0f7e8caa5b 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -279,6 +279,33 @@  enum {
     DEFAULT_PERM_UNCHANGED      = BLK_PERM_ALL & ~DEFAULT_PERM_PASSTHROUGH,
 };
 
+typedef enum BdrvChildRole {
+    /* Child stores data */
+    BDRV_CHILD_DATA         = (1 << 0),
+
+    /* Child stores metadata */
+    BDRV_CHILD_METADATA     = (1 << 1),
+
+    /* Filtered child */
+    BDRV_CHILD_FILTERED     = (1 << 2),
+
+    /* Child to COW from (backing child) */
+    BDRV_CHILD_COW          = (1 << 3),
+
+    /*
+     * The primary child.  For most drivers, this is the child whose
+     * filename applies best to the parent node.
+     * Each parent must give this flag to no more than one child at a
+     * time.
+     */
+    BDRV_CHILD_PRIMARY      = (1 << 4),
+
+    /* Useful combination of flags */
+    BDRV_CHILD_IMAGE        = BDRV_CHILD_DATA
+                              | BDRV_CHILD_METADATA
+                              | BDRV_CHILD_PRIMARY,
+} BdrvChildRole;
+
 char *bdrv_perm_names(uint64_t perm);
 uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm);