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

Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging



Block layer patches:

- Add blockdev-create job
- qcow2: Silence Coverity false positive

# gpg: Signature made Wed 30 May 2018 16:55:31 BST
# gpg:                using RSA key 7F09B272C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74  56FE 7F09 B272 C88F 2FD6

* remotes/kevin/tags/for-upstream:
  block/create: Mark blockdev-create stable
  qemu-iotests: Rewrite 213 for blockdev-create job
  qemu-iotests: Rewrite 212 for blockdev-create job
  qemu-iotests: Rewrite 211 for blockdev-create job
  qemu-iotests: Rewrite 210 for blockdev-create job
  qemu-iotests: Rewrite 207 for blockdev-create job
  qemu-iotests: Rewrite 206 for blockdev-create job
  qemu-iotests: iotests.py helper for non-file protocols
  qemu-iotests: Add VM.run_job()
  qemu-iotests: Add iotests.img_info_log()
  qemu-iotests: Add VM.qmp_log()
  qemu-iotests: Add VM.get_qmp_events_filtered()
  block/create: Make x-blockdev-create a job
  job: Add error message for failing jobs
  vhdx: Fix vhdx_co_create() return value
  vdi: Fix vdi_co_do_create() return value
  qcow2: Fix Coverity warning when calculating the refcount cache size

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents b5725385 3fb588a0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -321,7 +321,7 @@ static void backup_complete(Job *job, void *opaque)
{
    BackupCompleteData *data = opaque;

    job_completed(job, data->ret);
    job_completed(job, data->ret, NULL);
    g_free(data);
}

+1 −1
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ static void commit_complete(Job *job, void *opaque)
     * bdrv_set_backing_hd() to fail. */
    block_job_remove_all_bdrv(bjob);

    job_completed(job, ret);
    job_completed(job, ret, NULL);
    g_free(data);

    /* If bdrv_drop_intermediate() didn't already do that, remove the commit
+46 −21
Original line number Diff line number Diff line
@@ -24,28 +24,51 @@

#include "qemu/osdep.h"
#include "block/block_int.h"
#include "qemu/job.h"
#include "qapi/qapi-commands-block-core.h"
#include "qapi/qapi-visit-block-core.h"
#include "qapi/clone-visitor.h"
#include "qapi/error.h"

typedef struct BlockdevCreateCo {
typedef struct BlockdevCreateJob {
    Job common;
    BlockDriver *drv;
    BlockdevCreateOptions *opts;
    int ret;
    Error **errp;
} BlockdevCreateCo;
    Error *err;
} BlockdevCreateJob;

static void coroutine_fn bdrv_co_create_co_entry(void *opaque)
static void blockdev_create_complete(Job *job, void *opaque)
{
    BlockdevCreateCo *cco = opaque;
    cco->ret = cco->drv->bdrv_co_create(cco->opts, cco->errp);
    BlockdevCreateJob *s = container_of(job, BlockdevCreateJob, common);

    job_completed(job, s->ret, s->err);
}

void qmp_x_blockdev_create(BlockdevCreateOptions *options, Error **errp)
static void coroutine_fn blockdev_create_run(void *opaque)
{
    BlockdevCreateJob *s = opaque;

    job_progress_set_remaining(&s->common, 1);
    s->ret = s->drv->bdrv_co_create(s->opts, &s->err);
    job_progress_update(&s->common, 1);

    qapi_free_BlockdevCreateOptions(s->opts);
    job_defer_to_main_loop(&s->common, blockdev_create_complete, NULL);
}

static const JobDriver blockdev_create_job_driver = {
    .instance_size = sizeof(BlockdevCreateJob),
    .job_type      = JOB_TYPE_CREATE,
    .start         = blockdev_create_run,
};

void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *options,
                         Error **errp)
{
    BlockdevCreateJob *s;
    const char *fmt = BlockdevDriver_str(options->driver);
    BlockDriver *drv = bdrv_find_format(fmt);
    Coroutine *co;
    BlockdevCreateCo cco;

    /* If the driver is in the schema, we know that it exists. But it may not
     * be whitelisted. */
@@ -55,22 +78,24 @@ void qmp_x_blockdev_create(BlockdevCreateOptions *options, Error **errp)
        return;
    }

    /* Call callback if it exists */
    /* Error out if the driver doesn't support .bdrv_co_create */
    if (!drv->bdrv_co_create) {
        error_setg(errp, "Driver does not support blockdev-create");
        return;
    }

    cco = (BlockdevCreateCo) {
        .drv = drv,
        .opts = options,
        .ret = -EINPROGRESS,
        .errp = errp,
    };

    co = qemu_coroutine_create(bdrv_co_create_co_entry, &cco);
    qemu_coroutine_enter(co);
    while (cco.ret == -EINPROGRESS) {
        aio_poll(qemu_get_aio_context(), true);
    /* Create the block job */
    /* TODO Running in the main context. Block drivers need to error out or add
     * locking when they use a BDS in a different AioContext. */
    s = job_create(job_id, &blockdev_create_job_driver, NULL,
                   qemu_get_aio_context(), JOB_DEFAULT | JOB_MANUAL_DISMISS,
                   NULL, NULL, errp);
    if (!s) {
        return;
    }

    s->drv = drv,
    s->opts = QAPI_CLONE(BlockdevCreateOptions, options),

    job_start(&s->common);
}
+1 −1
Original line number Diff line number Diff line
@@ -581,7 +581,7 @@ static void mirror_exit(Job *job, void *opaque)
    blk_set_perm(bjob->blk, 0, BLK_PERM_ALL, &error_abort);
    blk_insert_bs(bjob->blk, mirror_top_bs, &error_abort);

    job_completed(job, data->ret);
    job_completed(job, data->ret, NULL);

    g_free(data);
    bdrv_drained_end(src);
+2 −3
Original line number Diff line number Diff line
@@ -768,6 +768,7 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
    BDRVQcow2State *s = bs->opaque;
    uint64_t combined_cache_size;
    bool l2_cache_size_set, refcount_cache_size_set, combined_cache_size_set;
    int min_refcount_cache = MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;

    combined_cache_size_set = qemu_opt_get(opts, QCOW2_OPT_CACHE_SIZE);
    l2_cache_size_set = qemu_opt_get(opts, QCOW2_OPT_L2_CACHE_SIZE);
@@ -804,8 +805,6 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
        } else {
            uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE;
            uint64_t max_l2_cache = virtual_disk_size / (s->cluster_size / 8);
            uint64_t min_refcount_cache =
                (uint64_t) MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;

            /* Assign as much memory as possible to the L2 cache, and
             * use the remainder for the refcount cache */
@@ -825,7 +824,7 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts,
                                 * s->cluster_size);
        }
        if (!refcount_cache_size_set) {
            *refcount_cache_size = MIN_REFCOUNT_CACHE_SIZE * s->cluster_size;
            *refcount_cache_size = min_refcount_cache;
        }
    }

Loading