[PATCH] blockcommit: Reopen base image as RO after abort

Alexander Ivanov posted 1 patch 12 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231130101104.127356-1-alexander.ivanov@virtuozzo.com
Maintainers: John Snow <jsnow@redhat.com>, Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
There is a newer version of this series
block/mirror.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] blockcommit: Reopen base image as RO after abort
Posted by Alexander Ivanov 12 months ago
If a blockcommit is aborted the base image remains in RW mode, that leads
to a fail of subsequent live migration.

How to reproduce:
  $ virsh snapshot-create-as vm snp1 --disk-only

  *** write something to the disk ***

  $ virsh blockcommit vm vda --active --shallow && virsh blockjob vm vda --abort
  $ lsof /vzt/vm.qcow2
  COMMAND      PID USER   FD   TYPE DEVICE   SIZE/OFF NODE NAME
  qemu-syst 433203 root   45u   REG  253,0 1724776448  133 /vzt/vm.qcow2
  $ cat /proc/433203/fdinfo/45
  pos:    0
  flags:  02140002

Reopen the base image in RO mode in mirror_exit_common() if the blockjob
is aborted.

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 block/mirror.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/block/mirror.c b/block/mirror.c
index dcd88de2e3..50a2825b1c 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -789,6 +789,10 @@ static int mirror_exit_common(Job *job)
     block_job_remove_all_bdrv(bjob);
     bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_abort);
 
+    if (abort && !bdrv_is_read_only(target_bs)) {
+        bdrv_reopen_set_read_only(target_bs, true, NULL);
+    }
+
     bs_opaque->job = NULL;
 
     bdrv_drained_end(src);
-- 
2.39.2
Re: [PATCH] blockcommit: Reopen base image as RO after abort
Posted by Vladimir Sementsov-Ogievskiy 11 months ago
On 30.11.23 13:11, Alexander Ivanov wrote:
> If a blockcommit is aborted the base image remains in RW mode, that leads
> to a fail of subsequent live migration.
> 
> How to reproduce:
>    $ virsh snapshot-create-as vm snp1 --disk-only
> 
>    *** write something to the disk ***
> 
>    $ virsh blockcommit vm vda --active --shallow && virsh blockjob vm vda --abort
>    $ lsof /vzt/vm.qcow2
>    COMMAND      PID USER   FD   TYPE DEVICE   SIZE/OFF NODE NAME
>    qemu-syst 433203 root   45u   REG  253,0 1724776448  133 /vzt/vm.qcow2
>    $ cat /proc/433203/fdinfo/45
>    pos:    0
>    flags:  02140002
> 
> Reopen the base image in RO mode in mirror_exit_common() if the blockjob
> is aborted.
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>   block/mirror.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/block/mirror.c b/block/mirror.c
> index dcd88de2e3..50a2825b1c 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -789,6 +789,10 @@ static int mirror_exit_common(Job *job)
>       block_job_remove_all_bdrv(bjob);
>       bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_abort);
>   
> +    if (abort && !bdrv_is_read_only(target_bs)) {

I think, we also should check here, that we did bdrv_reopen_set_read_only(false) at job start (probably we didn't, or we are in mirror job)

> +        bdrv_reopen_set_read_only(target_bs, true, NULL);
> +    }
> +
>       bs_opaque->job = NULL;
>   
>       bdrv_drained_end(src);

-- 
Best regards,
Vladimir
Re: [PATCH] blockcommit: Reopen base image as RO after abort
Posted by Alexander Ivanov 11 months, 1 week ago
Ping. Could someone please review the code?

On 11/30/23 11:11, Alexander Ivanov wrote:
> If a blockcommit is aborted the base image remains in RW mode, that leads
> to a fail of subsequent live migration.
>
> How to reproduce:
>    $ virsh snapshot-create-as vm snp1 --disk-only
>
>    *** write something to the disk ***
>
>    $ virsh blockcommit vm vda --active --shallow && virsh blockjob vm vda --abort
>    $ lsof /vzt/vm.qcow2
>    COMMAND      PID USER   FD   TYPE DEVICE   SIZE/OFF NODE NAME
>    qemu-syst 433203 root   45u   REG  253,0 1724776448  133 /vzt/vm.qcow2
>    $ cat /proc/433203/fdinfo/45
>    pos:    0
>    flags:  02140002
>
> Reopen the base image in RO mode in mirror_exit_common() if the blockjob
> is aborted.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>   block/mirror.c | 4 ++++
>   1 file changed, 4 insertions(+)
>
> diff --git a/block/mirror.c b/block/mirror.c
> index dcd88de2e3..50a2825b1c 100644
> --- a/block/mirror.c
> +++ b/block/mirror.c
> @@ -789,6 +789,10 @@ static int mirror_exit_common(Job *job)
>       block_job_remove_all_bdrv(bjob);
>       bdrv_replace_node(mirror_top_bs, mirror_top_bs->backing->bs, &error_abort);
>   
> +    if (abort && !bdrv_is_read_only(target_bs)) {
> +        bdrv_reopen_set_read_only(target_bs, true, NULL);
> +    }
> +
>       bs_opaque->job = NULL;
>   
>       bdrv_drained_end(src);

-- 
Best regards,
Alexander Ivanov