Skip to contentSkip to conversation

block/mirror: change the semantic of 'force' of block-job-cancel

PATCH Liang Li 1 participant 1 message Feb 1, 2018

lore
Share & tools
lore

Liang Li

author
#0 lore raw
Quoted 19 lines · Eric Blake
Quoted 4 lines · Liang Li

When doing drive mirror to a low speed shared storage, if there was heavy BLK IO write workload in VM after the 'ready' event, drive mirror block job can't be canceled immediately, it would keep running until the heavy BLK IO workload stopped in the VM.

So far so good. But the grammar and explanation in the rest of the
commit is a bit hard to read; let me give a shot at an alternative wording:

Libvirt depends on the current block-job-cancel semantics, which is that when used without a flag after the 'ready' event, the command blocks until data is in sync. However, these semantics are awkward in other situations, for example, people may use drive mirror for realtime backups while still wanting to use block live migration. Libvirt cannot start a block live migration while another drive mirror is in progress, but the user would rather abandon the backup attempt as broken and proceed with the live migration than be stuck waiting for the current drive mirror backup to finish.

Quoted 8 lines

The drive-mirror command already includes a 'force' flag, which libvirt does not use, although it documented the flag as only being useful to quit a job which is paused. However, since quitting a paused job has the same effect as abandoning a backup in a non-paused job (namely, the destination file is not in sync, and the command completes immediately), we can just improve the documentation to make the force flag obviously useful.

much better, will include in the v2. Thanks!

Quoted 13 lines
Quoted 11 lines
Cc Paolo Bonzini <[email protected]>
Cc Jeff Cody <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Max Reitz <[email protected]>
Cc Eric Blake <[email protected]>
Cc John Snow <[email protected]>

---

Quoted 11 lines

Review ETEXI · line 110

Quoted 8 lines

+++ b/hmp-commands.hx

(quoted diff) +2 -1
@@ -106,7 +106,8 @@ ETEXI
        .args_type  = "force:-f,device:B",
        .params     = "[-f] device",
        .help       = "stop an active background block operation (use -f"
-                      "\n\t\t\t if the operation is currently paused)",
+                      "\n\t\t\t if you want to abort the operation immediately"
+                      "\n\t\t\t instead of keep running until data is in sync )",

s/sync )/sync)/

done

Quoted 10 lines
Quoted 10 lines
(quoted diff) +0 -0
        .cmd        = hmp_block_job_cancel,
    },
 
include/block/blockjob.h +0 -0
index 00403d9..4a96c42 100644
@@ -63,6 +63,12 @@ typedef struct BlockJob {
    bool cancelled;
 
Quoted 4 lines

include/block/blockjob.h typedef struct BlockJob { · line 66

Quoted 2 lines
include/block/blockjob.h +1 -0
    /**
+     * Set to true if the job should be abort immediately without waiting

s/be //

done

Quoted 5 lines

include/block/blockjob.h typedef struct BlockJob { · line 67

Quoted 2 lines
include/block/blockjob.h +1 -0
+     * for data is in sync.

s/is/to be/

done

Quoted 6 lines
Quoted 6 lines
include/block/blockjob.h +4 -0
+     */
+    bool force;
+
+    /**
     * Counter for pause request. If non-zero, the block job is either paused,
     * or if busy == true will pause itself as soon as possible.
Quoted 9 lines

include/block/blockjob.h void block_job_start(BlockJob *job); · line 227

Quoted 6 lines
include/block/blockjob.h +1 -0
     */
@@ -218,10 +224,11 @@ void block_job_start(BlockJob *job);
 /**
 * block_job_cancel:
 * @job: The job to be canceled.
+ * @force: Quit a job without waiting data is in sync.

s/data is/for data to be/

done

Quoted 17 lines

include/block/blockjob.h line 2101

Quoted 8 lines
include/block/blockjob.h +2 -2
+++ b/qapi/block-core.json
@@ -2098,8 +2098,10 @@
 #          the name of the parameter), but since QEMU 2.7 it can have
 #          other values.
 #
-# @force: whether to allow cancellation of a paused job (default
-#         false).  Since 1.3.
+# @force: #optional whether to allow cancellation a job without waiting data is

The '#optional' tag should no longer be added.

include/block/blockjob.h line 2104

Quoted 3 lines
include/block/blockjob.h +3 -0
+#         in sync, please not that since 2.12 it's semantic is not exactly the
+#         same as before, from 1.3 to 2.11 it means whether to allow cancellation
+#         of a paused job (default false).  Since 1.3.

Reads awkwardly. I suggest:

Quoted 5 lines

@force: If true, and the job has already emitted the event BLOCK_JOB_READY, abandon the job immediately (even if it is paused) instead of waiting for the destination to complete its final synchronization (since 1.3)

much more clear

Quoted 28 lines
Quoted 28 lines
include/block/blockjob.h +4 -3
+++ b/tests/test-blockjob-txn.c
@@ -125,7 +125,7 @@ static void test_single_job(int expected)
    block_job_start(job);
 
    if (expected == -ECANCELED) {
-        block_job_cancel(job);
+        block_job_cancel(job, false);
    }
 
    while (result == -EINPROGRESS) {
@@ -173,10 +173,10 @@ static void test_pair_jobs(int expected1, int expected2)
    block_job_txn_unref(txn);
 
    if (expected1 == -ECANCELED) {
-        block_job_cancel(job1);
+        block_job_cancel(job1, false);
    }
    if (expected2 == -ECANCELED) {
-        block_job_cancel(job2);
+        block_job_cancel(job2, false);
    }
 
    while (result1 == -EINPROGRESS || result2 == -EINPROGRESS) {
@@ -231,7 +231,7 @@ static void test_pair_jobs_fail_cancel_race(void)
    block_job_start(job1);
    block_job_start(job2);
 
Quoted 9 lines

include/block/blockjob.h static void test_pair_jobs_fail_cancel_race(void) · line 237

Quoted 6 lines
include/block/blockjob.h +1 -1
-    block_job_cancel(job1);
+    block_job_cancel(job1, false);
 
    /* Now make job2 finish before the main loop kicks jobs.  This simulates
     * the race between a pending kick and another job completing.

The testsuite should probably also test block_job_cancel(..., true).

will change in v2, thanks!

Liang

Quoted 4 lines
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org