Commit e5cd6952 authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging



# gpg: Signature made Tue 08 May 2018 16:18:22 BST
# gpg:                using RSA key BDBE7B27C0DE3057
# gpg: Good signature from "Jeffrey Cody <jcody@redhat.com>"
# gpg:                 aka "Jeffrey Cody <jeff@codyprime.org>"
# gpg:                 aka "Jeffrey Cody <codyprime@gmail.com>"
# Primary key fingerprint: 9957 4B4D 3474 90E7 9D98  D624 BDBE 7B27 C0DE 3057

* remotes/cody/tags/block-pull-request:
  sheepdog: Fix sd_co_create_opts() memory leaks
  iotests: Add test for cancelling a mirror job
  block/mirror: Make cancel always cancel pre-READY
  block/mirror: honor ratelimit again

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents cc8f8ba7 a2cb9239
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -868,12 +868,16 @@ static void coroutine_fn mirror_run(void *opaque)
        }

        ret = 0;
        trace_mirror_before_sleep(s, cnt, s->synced, delay_ns);
        if (block_job_is_cancelled(&s->common) && s->common.force) {
            break;
        } else if (!should_complete) {

        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->synced || s->common.force))
        {
            break;
        }
        s->last_pause_ns = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
    }
+3 −1
Original line number Diff line number Diff line
@@ -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;
}

+1 −1
Original line number Diff line number Diff line
@@ -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": {}}
{"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_READY", "data": {"device": "disk", "len": 4194304, "offset": 4194304, "speed": 65536, "type": "mirror"}}
{"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 ===

tests/qemu-iotests/218

0 → 100644
+138 −0
Original line number Diff line number Diff line
#!/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 <mreitz@redhat.com>

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])
+30 −0
Original line number Diff line number Diff line

=== 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'}
Loading