Blame SOURCES/kvm-blockdev-unify-qmp_blockdev_backup-and-blockdev-back.patch

22c213
From 959955217f745f1ee6cbea97314efe69f2d7dc08 Mon Sep 17 00:00:00 2001
22c213
From: Sergio Lopez Pascual <slp@redhat.com>
22c213
Date: Fri, 7 Feb 2020 11:27:43 +0000
22c213
Subject: [PATCH 10/18] blockdev: unify qmp_blockdev_backup and blockdev-backup
22c213
 transaction paths
22c213
22c213
RH-Author: Sergio Lopez Pascual <slp@redhat.com>
22c213
Message-id: <20200207112749.25073-4-slp@redhat.com>
22c213
Patchwork-id: 93756
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 3/9] blockdev: unify qmp_blockdev_backup and blockdev-backup transaction paths
22c213
Bugzilla: 1745606 1746217 1773517 1779036 1782111 1782175 1783965
22c213
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
22c213
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
22c213
RH-Acked-by: Max Reitz <mreitz@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
22c213
Issuing a blockdev-backup from qmp_blockdev_backup takes a slightly
22c213
different path than when it's issued from a transaction. In the code,
22c213
this is manifested as some redundancy between do_blockdev_backup() and
22c213
blockdev_backup_prepare().
22c213
22c213
This change unifies both paths, merging do_blockdev_backup() and
22c213
blockdev_backup_prepare(), and changing qmp_blockdev_backup() to
22c213
create a transaction instead of calling do_backup_common() direcly.
22c213
22c213
As a side-effect, now qmp_blockdev_backup() is executed inside a
22c213
drained section, as it happens when creating a blockdev-backup
22c213
transaction. This change is visible from the user's perspective, as
22c213
the job gets paused and immediately resumed before starting the actual
22c213
work.
22c213
22c213
Signed-off-by: Sergio Lopez <slp@redhat.com>
22c213
Reviewed-by: Max Reitz <mreitz@redhat.com>
22c213
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
22c213
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
22c213
(cherry picked from commit 5b7bfe515ecbd584b40ff6e41d2fd8b37c7d5139)
22c213
Signed-off-by: Sergio Lopez <slp@redhat.com>
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 blockdev.c | 60 +++++++++++++-----------------------------------------------
22c213
 1 file changed, 13 insertions(+), 47 deletions(-)
22c213
22c213
diff --git a/blockdev.c b/blockdev.c
22c213
index 5e85fc0..152a0f7 100644
22c213
--- a/blockdev.c
22c213
+++ b/blockdev.c
22c213
@@ -1940,16 +1940,13 @@ typedef struct BlockdevBackupState {
22c213
     BlockJob *job;
22c213
 } BlockdevBackupState;
22c213
 
22c213
-static BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn,
22c213
-                                    Error **errp);
22c213
-
22c213
 static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
22c213
 {
22c213
     BlockdevBackupState *state = DO_UPCAST(BlockdevBackupState, common, common);
22c213
     BlockdevBackup *backup;
22c213
-    BlockDriverState *bs, *target;
22c213
+    BlockDriverState *bs;
22c213
+    BlockDriverState *target_bs;
22c213
     AioContext *aio_context;
22c213
-    Error *local_err = NULL;
22c213
 
22c213
     assert(common->action->type == TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP);
22c213
     backup = common->action->u.blockdev_backup.data;
22c213
@@ -1959,8 +1956,8 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
22c213
         return;
22c213
     }
22c213
 
22c213
-    target = bdrv_lookup_bs(backup->target, backup->target, errp);
22c213
-    if (!target) {
22c213
+    target_bs = bdrv_lookup_bs(backup->target, backup->target, errp);
22c213
+    if (!target_bs) {
22c213
         return;
22c213
     }
22c213
 
22c213
@@ -1971,13 +1968,10 @@ static void blockdev_backup_prepare(BlkActionState *common, Error **errp)
22c213
     /* Paired with .clean() */
22c213
     bdrv_drained_begin(state->bs);
22c213
 
22c213
-    state->job = do_blockdev_backup(backup, common->block_job_txn, &local_err);
22c213
-    if (local_err) {
22c213
-        error_propagate(errp, local_err);
22c213
-        goto out;
22c213
-    }
22c213
+    state->job = do_backup_common(qapi_BlockdevBackup_base(backup),
22c213
+                                  bs, target_bs, aio_context,
22c213
+                                  common->block_job_txn, errp);
22c213
 
22c213
-out:
22c213
     aio_context_release(aio_context);
22c213
 }
22c213
 
22c213
@@ -3695,41 +3689,13 @@ XDbgBlockGraph *qmp_x_debug_query_block_graph(Error **errp)
22c213
     return bdrv_get_xdbg_block_graph(errp);
22c213
 }
22c213
 
22c213
-BlockJob *do_blockdev_backup(BlockdevBackup *backup, JobTxn *txn,
22c213
-                             Error **errp)
22c213
+void qmp_blockdev_backup(BlockdevBackup *backup, Error **errp)
22c213
 {
22c213
-    BlockDriverState *bs;
22c213
-    BlockDriverState *target_bs;
22c213
-    AioContext *aio_context;
22c213
-    BlockJob *job;
22c213
-
22c213
-    bs = bdrv_lookup_bs(backup->device, backup->device, errp);
22c213
-    if (!bs) {
22c213
-        return NULL;
22c213
-    }
22c213
-
22c213
-    target_bs = bdrv_lookup_bs(backup->target, backup->target, errp);
22c213
-    if (!target_bs) {
22c213
-        return NULL;
22c213
-    }
22c213
-
22c213
-    aio_context = bdrv_get_aio_context(bs);
22c213
-    aio_context_acquire(aio_context);
22c213
-
22c213
-    job = do_backup_common(qapi_BlockdevBackup_base(backup),
22c213
-                           bs, target_bs, aio_context, txn, errp);
22c213
-
22c213
-    aio_context_release(aio_context);
22c213
-    return job;
22c213
-}
22c213
-
22c213
-void qmp_blockdev_backup(BlockdevBackup *arg, Error **errp)
22c213
-{
22c213
-    BlockJob *job;
22c213
-    job = do_blockdev_backup(arg, NULL, errp);
22c213
-    if (job) {
22c213
-        job_start(&job->job);
22c213
-    }
22c213
+    TransactionAction action = {
22c213
+        .type = TRANSACTION_ACTION_KIND_BLOCKDEV_BACKUP,
22c213
+        .u.blockdev_backup.data = backup,
22c213
+    };
22c213
+    blockdev_do_action(&action, errp);
22c213
 }
22c213
 
22c213
 /* Parameter check and block job starting for drive mirroring.
22c213
-- 
22c213
1.8.3.1
22c213