cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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