diff mbox series

[v7,29/47] blockdev: Use CAF in external_snapshot_prepare()

Message ID 20200625152215.941773-30-mreitz@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: Deal with filters | expand

Commit Message

Max Reitz June 25, 2020, 3:21 p.m. UTC
This allows us to differentiate between filters and nodes with COW
backing files: Filters cannot be used as overlays at all (for this
function).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 blockdev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Andrey Shinkevich July 20, 2020, 4:08 p.m. UTC | #1
On 25.06.2020 18:21, Max Reitz wrote:
> This allows us to differentiate between filters and nodes with COW
> backing files: Filters cannot be used as overlays at all (for this
> function).
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   blockdev.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/blockdev.c b/blockdev.c
> index 1eb0fcdea2..aabe51036d 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -1549,7 +1549,12 @@ static void external_snapshot_prepare(BlkActionState *common,
>           goto out;
>       }
>   
> -    if (state->new_bs->backing != NULL) {
> +    if (state->new_bs->drv->is_filter) {


Is there a chance to get a filter here? If so, is that when a user 
specifies the file name of such a kind “filter[filter-name]:foo.qcow2” 
or somehow else?

Andrey


> +        error_setg(errp, "Filters cannot be used as overlays");
> +        goto out;
> +    }
> +
> +    if (bdrv_cow_child(state->new_bs)) {
>           error_setg(errp, "The overlay already has a backing image");
>           goto out;
>       }


Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com>
Max Reitz July 24, 2020, 9:23 a.m. UTC | #2
On 20.07.20 18:08, Andrey Shinkevich wrote:
> On 25.06.2020 18:21, Max Reitz wrote:
>> This allows us to differentiate between filters and nodes with COW
>> backing files: Filters cannot be used as overlays at all (for this
>> function).
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>   blockdev.c | 7 ++++++-
>>   1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/blockdev.c b/blockdev.c
>> index 1eb0fcdea2..aabe51036d 100644
>> --- a/blockdev.c
>> +++ b/blockdev.c
>> @@ -1549,7 +1549,12 @@ static void
>> external_snapshot_prepare(BlkActionState *common,
>>           goto out;
>>       }
>>   -    if (state->new_bs->backing != NULL) {
>> +    if (state->new_bs->drv->is_filter) {
> 
> 
> Is there a chance to get a filter here? If so, is that when a user
> specifies the file name of such a kind “filter[filter-name]:foo.qcow2”
> or somehow else?

It would be with blockdev-snapshot and by specifying a filter for
@overlay.  Technically that’s already caught by the check whether the
overlay supports backing images (whether drv->supports_backing is true),
but we might as well give a nicer error message.

Example:

{"execute":"qmp_capabilities"}

{"execute":"blockdev-add","arguments":
 {"node-name":"overlay","driver":"copy-on-read",
  "file":{"driver":"null-co"}}}

{"execute":"blockdev-add","arguments":
 {"node-name":"base","driver":"null-co"}}

{"execute":"blockdev-snapshot","arguments":
 {"node":"base","overlay":"overlay"}}

Max
Andrey Shinkevich July 24, 2020, 10:37 a.m. UTC | #3
On 24.07.2020 12:23, Max Reitz wrote:
> On 20.07.20 18:08, Andrey Shinkevich wrote:
>> On 25.06.2020 18:21, Max Reitz wrote:
>>> This allows us to differentiate between filters and nodes with COW
>>> backing files: Filters cannot be used as overlays at all (for this
>>> function).
>>>
>>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>>> ---
>>>    blockdev.c | 7 ++++++-
>>>    1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/blockdev.c b/blockdev.c
>>> index 1eb0fcdea2..aabe51036d 100644
>>> --- a/blockdev.c
>>> +++ b/blockdev.c
>>> @@ -1549,7 +1549,12 @@ static void
>>> external_snapshot_prepare(BlkActionState *common,
>>>            goto out;
>>>        }
>>>    -    if (state->new_bs->backing != NULL) {
>>> +    if (state->new_bs->drv->is_filter) {
>>
>> Is there a chance to get a filter here? If so, is that when a user
>> specifies the file name of such a kind “filter[filter-name]:foo.qcow2”
>> or somehow else?
> It would be with blockdev-snapshot and by specifying a filter for
> @overlay.  Technically that’s already caught by the check whether the
> overlay supports backing images (whether drv->supports_backing is true),
> but we might as well give a nicer error message.
>
> Example:
>
> {"execute":"qmp_capabilities"}
>
> {"execute":"blockdev-add","arguments":
>   {"node-name":"overlay","driver":"copy-on-read",
>    "file":{"driver":"null-co"}}}
>
> {"execute":"blockdev-add","arguments":
>   {"node-name":"base","driver":"null-co"}}
>
> {"execute":"blockdev-snapshot","arguments":
>   {"node":"base","overlay":"overlay"}}
>
> Max
>

Thank you for the example.

Andrey
diff mbox series

Patch

diff --git a/blockdev.c b/blockdev.c
index 1eb0fcdea2..aabe51036d 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1549,7 +1549,12 @@  static void external_snapshot_prepare(BlkActionState *common,
         goto out;
     }
 
-    if (state->new_bs->backing != NULL) {
+    if (state->new_bs->drv->is_filter) {
+        error_setg(errp, "Filters cannot be used as overlays");
+        goto out;
+    }
+
+    if (bdrv_cow_child(state->new_bs)) {
         error_setg(errp, "The overlay already has a backing image");
         goto out;
     }