Skip to contentSkip to conversation

Block patches

GIT PULL Applied Jeff Cody 2 participants 6 messages May 8, 2018 Block layer

lore
Share & tools
lore

Jeff Cody

author
#0 lore raw

The following changes since commit d01beac177d44491d7db8747b79d94e1b53d173b:

Merge remote-tracking branch 'remotes/kraxel/tags/vga-20180507-pull-request' into staging (2018-05-08 14:23:02 +0100)

are available in the git repository at:

git://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request

for you to fetch changes up to a2cb9239b7610ffb00f9ced5cd7640d40b0e1ccf:

sheepdog: Fix sd_co_create_opts() memory leaks (2018-05-08 10:47:27 -0400)

----------------------------------------------------------------
Block patches
----------------------------------------------------------------

Kevin Wolf (1):
sheepdog: Fix sd_co_create_opts() memory leaks

Max Reitz (2):
block/mirror: Make cancel always cancel pre-READY
iotests: Add test for cancelling a mirror job

Stefan Hajnoczi (1):
block/mirror: honor ratelimit again

 block/mirror.c             |  14 +++--
 block/sheepdog.c           |   4 +-
 tests/qemu-iotests/185.out |   4 +-
 tests/qemu-iotests/218     | 138 +++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/218.out |  30 ++++++++++
 tests/qemu-iotests/group   |   1 +
 6 files changed, 183 insertions(+), 8 deletions(-)
 create mode 100644 tests/qemu-iotests/218
 create mode 100644 tests/qemu-iotests/218.out
Signature · 1 line
2.13.6
author
#1 lore raw

[Qemu-devel] [PULL 4/4] sheepdog: Fix sd_co_create_opts() memory leaks

From: Kevin Wolf <[email protected]>

Both the option string for the 'redundancy' option and the SheepdogRedundancy object that is created accordingly could be leaked in error paths. This fixes the memory leaks.

Reported by Coverity (CID 1390614 and 1390641).

Message-id: [email protected]

---
 block/sheepdog.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/sheepdog.c +3 -1
index 07529f4b1b..fed2a04797 100644
@@ -1987,6 +1987,7 @@ static SheepdogRedundancy *parse_redundancy_str(const char *opt)
     } else {
         ret = qemu_strtol(n2, NULL, 10, &parity);
         if (ret < 0) {
+            g_free(redundancy);
             return NULL;
         }
 
@@ -2183,7 +2184,7 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
     QDict *qdict, *location_qdict;
     QObject *crumpled;
     Visitor *v;
-    const char *redundancy;
+    char *redundancy;
     Error *local_err = NULL;
     int ret;
 
@@ -2253,6 +2254,7 @@ static int coroutine_fn sd_co_create_opts(const char *filename, QemuOpts *opts,
 fail:
     qapi_free_BlockdevCreateOptions(create_options);
     qobject_unref(qdict);
+    g_free(redundancy);
     return ret;
 }
 
Signature · 1 line
2.13.6
author
#2 lore raw

[Qemu-devel] [PULL 1/4] block/mirror: honor ratelimit again

In reply to Jeff Cody

From: Stefan Hajnoczi <[email protected]>

Commit b76e4458b1eb3c32e9824fe6aa51f67d2b251748 ("block/mirror: change the semantic of 'force' of block-job-cancel") accidentally removed the ratelimit in the mirror job.

Reintroduce the ratelimit but keep the block-job-cancel force=true behavior that was added in commit b76e4458b1eb3c32e9824fe6aa51f67d2b251748.

Note that block_job_sleep_ns() returns immediately when the job is cancelled. Therefore it's safe to unconditionally call block_job_sleep_ns() - a cancelled job does not sleep.

This commit fixes the non-deterministic qemu-iotests 185 output. The test relies on the ratelimit to make the job sleep until the 'quit' command is processed. Previously the job could complete before the 'quit' command was received since there was no ratelimit.

Message-id: [email protected]

---
 block/mirror.c             | 8 +++++---
 tests/qemu-iotests/185.out | 4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)
block/mirror.c +5 -3
index 820f512c7b..9436a8d5ee 100644
@@ -868,12 +868,14 @@ static void coroutine_fn mirror_run(void *opaque)
         }
 
         ret = 0;
+
+        if (s->synced && !should_complete) {
+            delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0);
+        }
         trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
+        block_job_sleep_ns(&s->common, delay_ns);
         if (block_job_is_cancelled(&s->common) && s->common.force) {
             break;
-        } else if (!should_complete) {
-            delay_ns = (s->in_flight == 0 && cnt == 0 ? SLICE_TIME : 0);
-            block_job_sleep_ns(&s->common, delay_ns);
         }
         s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
     }
tests/qemu-iotests/185.out +2 -2
index 2c4b04de73..992162f418 100644
@@ -36,9 +36,9 @@ Formatting 'TEST_DIR/t.qcow2', fmt=qcow2 size=67108864 backing_file=TEST_DIR/t.q
 {"return": {}}
 Formatting 'TEST_DIR/t.qcow2.copy', fmt=qcow2 size=67108864 cluster_size=65536 lazy_refcounts=off refcount_bits=16
 {"return": {}}
+{"return": {}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_READY", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
-{"return": {}}
-{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
 {"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "BLOCK_JOB_COMPLETED", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
 
 === Start backup job and exit qemu ===
Signature · 1 line
2.13.6
author
#3 lore raw

[Qemu-devel] [PULL 2/4] block/mirror: Make cancel always cancel pre-READY

In reply to Jeff Cody

From: Max Reitz <[email protected]>

Commit b76e4458b1eb3c32e9824fe6aa51f67d2b251748 made the mirror block job respect block-job-cancel's @force flag: With that flag set, it would now always really cancel, even post-READY.

Unfortunately, it had a side effect: Without that flag set, it would now never cancel, not even before READY. Considering that is an incompatible change and not noted anywhere in the commit or the description of block-job-cancel's @force parameter, this seems unintentional and we should revert to the previous behavior, which is to immediately cancel the job when block-job-cancel is called before source and target are in sync (i.e. before the READY event).

Message-id: [email protected]

---
 block/mirror.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/mirror.c +3 -1
index 9436a8d5ee..99da9c0858 100644
@@ -874,7 +874,9 @@ static void coroutine_fn mirror_run(void *opaque)
         }
         trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
         block_job_sleep_ns(&s->common, delay_ns);
-        if (block_job_is_cancelled(&s->common) && s->common.force) {
+        if (block_job_is_cancelled(&s->common) &&
+            (!s->synced || s->common.force))
+        {
             break;
         }
         s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
Signature · 1 line
2.13.6
author
#4 lore raw

[Qemu-devel] [PULL 3/4] iotests: Add test for cancelling a mirror job

In reply to Jeff Cody

From: Max Reitz <[email protected]>

We already have an extensive mirror test (041) which does cover cancelling a mirror job, especially after it has emitted the READY event. However, it does not check what exact events are emitted after block-job-cancel is executed. More importantly, it does not use throttling to ensure that it covers the case of block-job-cancel before READY.

It would be possible to add this case to 041, but considering it is already our largest test file, it makes sense to create a new file for these cases.

Message-id: [email protected]

---
 tests/qemu-iotests/218     | 138 +++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/218.out |  30 ++++++++++
 tests/qemu-iotests/group   |   1 +
 3 files changed, 169 insertions(+)
 create mode 100644 tests/qemu-iotests/218
 create mode 100644 tests/qemu-iotests/218.out
tests/qemu-iotests/218 new file +138 -0
new file mode 100644
index 0000000000..92c331b6fb
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+#
+# This test covers what happens when a mirror block job is cancelled
+# in various phases of its existence.
+#
+# Note that this test only checks the emitted events (i.e.
+# BLOCK_JOB_COMPLETED vs. BLOCK_JOB_CANCELLED), it does not compare
+# whether the target is in sync with the source when the
+# BLOCK_JOB_COMPLETED event occurs.  This is covered by other tests
+# (such as 041).
+#
+# Copyright (C) 2018 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Creator/Owner: Max Reitz <[email protected]>
+
+import iotests
+from iotests import log
+
+iotests.verify_platform(['linux'])
+
+
+# Launches the VM, adds two null-co nodes (source and target), and
+# starts a blockdev-mirror job on them.
+#
+# Either both or none of speed and buf_size must be given.
+
+def start_mirror(vm, speed=None, buf_size=None):
+    vm.launch()
+
+    ret = vm.qmp('blockdev-add',
+                     node_name='source',
+                     driver='null-co',
+                     size=1048576)
+    assert ret['return'] == {}
+
+    ret = vm.qmp('blockdev-add',
+                     node_name='target',
+                     driver='null-co',
+                     size=1048576)
+    assert ret['return'] == {}
+
+    if speed is not None:
+        ret = vm.qmp('blockdev-mirror',
+                         job_id='mirror',
+                         device='source',
+                         target='target',
+                         sync='full',
+                         speed=speed,
+                         buf_size=buf_size)
+    else:
+        ret = vm.qmp('blockdev-mirror',
+                         job_id='mirror',
+                         device='source',
+                         target='target',
+                         sync='full')
+
+    assert ret['return'] == {}
+
+
+log('')
+log('=== Cancel mirror job before convergence ===')
+log('')
+
+log('--- force=false ---')
+log('')
+
+with iotests.VM() as vm:
+    # Low speed so it does not converge
+    start_mirror(vm, 65536, 65536)
+
+    log('Cancelling job')
+    log(vm.qmp('block-job-cancel', device='mirror', force=False))
+
+    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
+        filters=[iotests.filter_qmp_event])
+
+log('')
+log('--- force=true ---')
+log('')
+
+with iotests.VM() as vm:
+    # Low speed so it does not converge
+    start_mirror(vm, 65536, 65536)
+
+    log('Cancelling job')
+    log(vm.qmp('block-job-cancel', device='mirror', force=True))
+
+    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
+        filters=[iotests.filter_qmp_event])
+
+
+log('')
+log('=== Cancel mirror job after convergence ===')
+log('')
+
+log('--- force=false ---')
+log('')
+
+with iotests.VM() as vm:
+    start_mirror(vm)
+
+    log(vm.event_wait('BLOCK_JOB_READY'),
+        filters=[iotests.filter_qmp_event])
+
+    log('Cancelling job')
+    log(vm.qmp('block-job-cancel', device='mirror', force=False))
+
+    log(vm.event_wait('BLOCK_JOB_COMPLETED'),
+        filters=[iotests.filter_qmp_event])
+
+log('')
+log('--- force=true ---')
+log('')
+
+with iotests.VM() as vm:
+    start_mirror(vm)
+
+    log(vm.event_wait('BLOCK_JOB_READY'),
+        filters=[iotests.filter_qmp_event])
+
+    log('Cancelling job')
+    log(vm.qmp('block-job-cancel', device='mirror', force=True))
+
+    log(vm.event_wait('BLOCK_JOB_CANCELLED'),
+        filters=[iotests.filter_qmp_event])
tests/qemu-iotests/218.out new file +30 -0
new file mode 100644
index 0000000000..7dbf78e682
@@ -0,0 +1,30 @@
+
+=== Cancel mirror job before convergence ===
+
+--- force=false ---
+
+Cancelling job
+{u'return': {}}
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 65536, u'len': 1048576, u'offset': 65536}, u'event': u'BLOCK_JOB_CANCELLED'}
+
+--- force=true ---
+
+Cancelling job
+{u'return': {}}
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 65536, u'len': 1048576, u'offset': 65536}, u'event': u'BLOCK_JOB_CANCELLED'}
+
+=== Cancel mirror job after convergence ===
+
+--- force=false ---
+
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_READY'}
+Cancelling job
+{u'return': {}}
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_COMPLETED'}
+
+--- force=true ---
+
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_READY'}
+Cancelling job
+{u'return': {}}
+{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror', u'type': u'mirror', u'speed': 0, u'len': 1048576, u'offset': 1048576}, u'event': u'BLOCK_JOB_CANCELLED'}
tests/qemu-iotests/group +1 -0
index 52a80f3f9e..5daef24020 100644
@@ -212,3 +212,4 @@
 211 rw auto quick
 212 rw auto quick
 213 rw auto quick
+218 rw auto quick
Signature · 1 line
2.13.6
#5 lore raw
In reply to Jeff Cody
Quoted 8 lines · Jeff Cody

The following changes since commit d01beac177d44491d7db8747b79d94e1b53d173b:

Merge remote-tracking branch 'remotes/kraxel/tags/vga-20180507-pull-request' into staging (2018-05-08 14:23:02 +0100)

are available in the git repository at:

git://github.com/codyprime/qemu-kvm-jtc.git tags/block-pull-request

Quoted 8 lines

for you to fetch changes up to a2cb9239b7610ffb00f9ced5cd7640d40b0e1ccf:

sheepdog: Fix sd_co_create_opts() memory leaks (2018-05-08 10:47:27 -0400)

----------------------------------------------------------------
Block patches
----------------------------------------------------------------

Applied, thanks.

-- PMM