Commit 1919631e authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Stefan Hajnoczi
Browse files

block: explicitly acquire aiocontext in bottom halves that need it



Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: default avatarFam Zheng <famz@redhat.com>
Reviewed-by: default avatarDaniel P. Berrange <berrange@redhat.com>
Message-id: 20170213135235.12274-15-pbonzini@redhat.com
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent 9d456654
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -310,8 +310,11 @@ static void qemu_archipelago_complete_aio(void *opaque)
{
    AIORequestData *reqdata = (AIORequestData *) opaque;
    ArchipelagoAIOCB *aio_cb = (ArchipelagoAIOCB *) reqdata->aio_cb;
    AioContext *ctx = bdrv_get_aio_context(aio_cb->common.bs);

    aio_context_acquire(ctx);
    aio_cb->common.cb(aio_cb->common.opaque, aio_cb->ret);
    aio_context_release(ctx);
    aio_cb->status = 0;

    qemu_aio_unref(aio_cb);
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ static int64_t blkreplay_getlength(BlockDriverState *bs)
static void blkreplay_bh_cb(void *opaque)
{
    Request *req = opaque;
    qemu_coroutine_enter(req->co);
    aio_co_wake(req->co);
    qemu_bh_delete(req->bh);
    g_free(req);
}
+6 −0
Original line number Diff line number Diff line
@@ -939,9 +939,12 @@ int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags)
static void error_callback_bh(void *opaque)
{
    struct BlockBackendAIOCB *acb = opaque;
    AioContext *ctx = bdrv_get_aio_context(acb->common.bs);

    bdrv_dec_in_flight(acb->common.bs);
    aio_context_acquire(ctx);
    acb->common.cb(acb->common.opaque, acb->ret);
    aio_context_release(ctx);
    qemu_aio_unref(acb);
}

@@ -983,9 +986,12 @@ static void blk_aio_complete(BlkAioEmAIOCB *acb)
static void blk_aio_complete_bh(void *opaque)
{
    BlkAioEmAIOCB *acb = opaque;
    AioContext *ctx = bdrv_get_aio_context(acb->common.bs);

    assert(acb->has_returned);
    aio_context_acquire(ctx);
    blk_aio_complete(acb);
    aio_context_release(ctx);
}

static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, int64_t offset, int bytes,
+18 −8
Original line number Diff line number Diff line
@@ -796,13 +796,18 @@ static void curl_readv_bh_cb(void *p)
{
    CURLState *state;
    int running;
    int ret = -EINPROGRESS;

    CURLAIOCB *acb = p;
    BDRVCURLState *s = acb->common.bs->opaque;
    BlockDriverState *bs = acb->common.bs;
    BDRVCURLState *s = bs->opaque;
    AioContext *ctx = bdrv_get_aio_context(bs);

    size_t start = acb->sector_num * BDRV_SECTOR_SIZE;
    size_t end;

    aio_context_acquire(ctx);

    // In case we have the requested data already (e.g. read-ahead),
    // we can just call the callback and be done.
    switch (curl_find_buf(s, start, acb->nb_sectors * BDRV_SECTOR_SIZE, acb)) {
@@ -810,7 +815,7 @@ static void curl_readv_bh_cb(void *p)
            qemu_aio_unref(acb);
            // fall through
        case FIND_RET_WAIT:
            return;
            goto out;
        default:
            break;
    }
@@ -818,9 +823,8 @@ static void curl_readv_bh_cb(void *p)
    // No cache found, so let's start a new request
    state = curl_init_state(acb->common.bs, s);
    if (!state) {
        acb->common.cb(acb->common.opaque, -EIO);
        qemu_aio_unref(acb);
        return;
        ret = -EIO;
        goto out;
    }

    acb->start = 0;
@@ -834,9 +838,8 @@ static void curl_readv_bh_cb(void *p)
    state->orig_buf = g_try_malloc(state->buf_len);
    if (state->buf_len && state->orig_buf == NULL) {
        curl_clean_state(state);
        acb->common.cb(acb->common.opaque, -ENOMEM);
        qemu_aio_unref(acb);
        return;
        ret = -ENOMEM;
        goto out;
    }
    state->acb[0] = acb;

@@ -849,6 +852,13 @@ static void curl_readv_bh_cb(void *p)

    /* Tell curl it needs to kick things off */
    curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);

out:
    if (ret != -EINPROGRESS) {
        acb->common.cb(acb->common.opaque, ret);
        qemu_aio_unref(acb);
    }
    aio_context_release(ctx);
}

static BlockAIOCB *curl_aio_readv(BlockDriverState *bs,
+1 −8
Original line number Diff line number Diff line
@@ -698,13 +698,6 @@ static struct glfs *qemu_gluster_init(BlockdevOptionsGluster *gconf,
    return qemu_gluster_glfs_init(gconf, errp);
}

static void qemu_gluster_complete_aio(void *opaque)
{
    GlusterAIOCB *acb = (GlusterAIOCB *)opaque;

    qemu_coroutine_enter(acb->coroutine);
}

/*
 * AIO callback routine called from GlusterFS thread.
 */
@@ -720,7 +713,7 @@ static void gluster_finish_aiocb(struct glfs_fd *fd, ssize_t ret, void *arg)
        acb->ret = -EIO; /* Partial read/write - fail it */
    }

    aio_bh_schedule_oneshot(acb->aio_context, qemu_gluster_complete_aio, acb);
    aio_co_schedule(acb->aio_context, acb->coroutine);
}

static void qemu_gluster_parse_flags(int bdrv_flags, int *open_flags)
Loading