block: explicitly acquire aiocontext in callbacks that need it
This covers both file descriptor callbacks and polling callbacks, since they execute related code. Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Message-id: 20170213135235.12274-14-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
		
							parent
							
								
									2f47da5f7f
								
							
						
					
					
						commit
						9d45665448
					
				
							
								
								
									
										16
									
								
								block/curl.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								block/curl.c
									
									
									
									
									
								
							@ -386,9 +386,8 @@ static void curl_multi_check_completion(BDRVCURLState *s)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void curl_multi_do(void *arg)
 | 
					static void curl_multi_do_locked(CURLState *s)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    CURLState *s = (CURLState *)arg;
 | 
					 | 
				
			||||||
    CURLSocket *socket, *next_socket;
 | 
					    CURLSocket *socket, *next_socket;
 | 
				
			||||||
    int running;
 | 
					    int running;
 | 
				
			||||||
    int r;
 | 
					    int r;
 | 
				
			||||||
@ -406,12 +405,23 @@ static void curl_multi_do(void *arg)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void curl_multi_do(void *arg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CURLState *s = (CURLState *)arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(s->s->aio_context);
 | 
				
			||||||
 | 
					    curl_multi_do_locked(s);
 | 
				
			||||||
 | 
					    aio_context_release(s->s->aio_context);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void curl_multi_read(void *arg)
 | 
					static void curl_multi_read(void *arg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    CURLState *s = (CURLState *)arg;
 | 
					    CURLState *s = (CURLState *)arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    curl_multi_do(arg);
 | 
					    aio_context_acquire(s->s->aio_context);
 | 
				
			||||||
 | 
					    curl_multi_do_locked(s);
 | 
				
			||||||
    curl_multi_check_completion(s->s);
 | 
					    curl_multi_check_completion(s->s);
 | 
				
			||||||
 | 
					    aio_context_release(s->s->aio_context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void curl_multi_timeout_do(void *arg)
 | 
					static void curl_multi_timeout_do(void *arg)
 | 
				
			||||||
 | 
				
			|||||||
@ -394,8 +394,10 @@ iscsi_process_read(void *arg)
 | 
				
			|||||||
    IscsiLun *iscsilun = arg;
 | 
					    IscsiLun *iscsilun = arg;
 | 
				
			||||||
    struct iscsi_context *iscsi = iscsilun->iscsi;
 | 
					    struct iscsi_context *iscsi = iscsilun->iscsi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(iscsilun->aio_context);
 | 
				
			||||||
    iscsi_service(iscsi, POLLIN);
 | 
					    iscsi_service(iscsi, POLLIN);
 | 
				
			||||||
    iscsi_set_events(iscsilun);
 | 
					    iscsi_set_events(iscsilun);
 | 
				
			||||||
 | 
					    aio_context_release(iscsilun->aio_context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
@ -404,8 +406,10 @@ iscsi_process_write(void *arg)
 | 
				
			|||||||
    IscsiLun *iscsilun = arg;
 | 
					    IscsiLun *iscsilun = arg;
 | 
				
			||||||
    struct iscsi_context *iscsi = iscsilun->iscsi;
 | 
					    struct iscsi_context *iscsi = iscsilun->iscsi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(iscsilun->aio_context);
 | 
				
			||||||
    iscsi_service(iscsi, POLLOUT);
 | 
					    iscsi_service(iscsi, POLLOUT);
 | 
				
			||||||
    iscsi_set_events(iscsilun);
 | 
					    iscsi_set_events(iscsilun);
 | 
				
			||||||
 | 
					    aio_context_release(iscsilun->aio_context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int64_t sector_lun2qemu(int64_t sector, IscsiLun *iscsilun)
 | 
					static int64_t sector_lun2qemu(int64_t sector, IscsiLun *iscsilun)
 | 
				
			||||||
 | 
				
			|||||||
@ -251,7 +251,9 @@ static void qemu_laio_completion_cb(EventNotifier *e)
 | 
				
			|||||||
    LinuxAioState *s = container_of(e, LinuxAioState, e);
 | 
					    LinuxAioState *s = container_of(e, LinuxAioState, e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (event_notifier_test_and_clear(&s->e)) {
 | 
					    if (event_notifier_test_and_clear(&s->e)) {
 | 
				
			||||||
 | 
					        aio_context_acquire(s->aio_context);
 | 
				
			||||||
        qemu_laio_process_completions_and_submit(s);
 | 
					        qemu_laio_process_completions_and_submit(s);
 | 
				
			||||||
 | 
					        aio_context_release(s->aio_context);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -265,7 +267,9 @@ static bool qemu_laio_poll_cb(void *opaque)
 | 
				
			|||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(s->aio_context);
 | 
				
			||||||
    qemu_laio_process_completions_and_submit(s);
 | 
					    qemu_laio_process_completions_and_submit(s);
 | 
				
			||||||
 | 
					    aio_context_release(s->aio_context);
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -208,15 +208,21 @@ static void nfs_set_events(NFSClient *client)
 | 
				
			|||||||
static void nfs_process_read(void *arg)
 | 
					static void nfs_process_read(void *arg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    NFSClient *client = arg;
 | 
					    NFSClient *client = arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(client->aio_context);
 | 
				
			||||||
    nfs_service(client->context, POLLIN);
 | 
					    nfs_service(client->context, POLLIN);
 | 
				
			||||||
    nfs_set_events(client);
 | 
					    nfs_set_events(client);
 | 
				
			||||||
 | 
					    aio_context_release(client->aio_context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void nfs_process_write(void *arg)
 | 
					static void nfs_process_write(void *arg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    NFSClient *client = arg;
 | 
					    NFSClient *client = arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(client->aio_context);
 | 
				
			||||||
    nfs_service(client->context, POLLOUT);
 | 
					    nfs_service(client->context, POLLOUT);
 | 
				
			||||||
    nfs_set_events(client);
 | 
					    nfs_set_events(client);
 | 
				
			||||||
 | 
					    aio_context_release(client->aio_context);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void nfs_co_init_task(BlockDriverState *bs, NFSRPC *task)
 | 
					static void nfs_co_init_task(BlockDriverState *bs, NFSRPC *task)
 | 
				
			||||||
 | 
				
			|||||||
@ -575,13 +575,6 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
 | 
				
			|||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void restart_co_req(void *opaque)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    Coroutine *co = opaque;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    qemu_coroutine_enter(co);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
typedef struct SheepdogReqCo {
 | 
					typedef struct SheepdogReqCo {
 | 
				
			||||||
    int sockfd;
 | 
					    int sockfd;
 | 
				
			||||||
    BlockDriverState *bs;
 | 
					    BlockDriverState *bs;
 | 
				
			||||||
@ -592,12 +585,19 @@ typedef struct SheepdogReqCo {
 | 
				
			|||||||
    unsigned int *rlen;
 | 
					    unsigned int *rlen;
 | 
				
			||||||
    int ret;
 | 
					    int ret;
 | 
				
			||||||
    bool finished;
 | 
					    bool finished;
 | 
				
			||||||
 | 
					    Coroutine *co;
 | 
				
			||||||
} SheepdogReqCo;
 | 
					} SheepdogReqCo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void restart_co_req(void *opaque)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    SheepdogReqCo *srco = opaque;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_co_wake(srco->co);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static coroutine_fn void do_co_req(void *opaque)
 | 
					static coroutine_fn void do_co_req(void *opaque)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret;
 | 
					    int ret;
 | 
				
			||||||
    Coroutine *co;
 | 
					 | 
				
			||||||
    SheepdogReqCo *srco = opaque;
 | 
					    SheepdogReqCo *srco = opaque;
 | 
				
			||||||
    int sockfd = srco->sockfd;
 | 
					    int sockfd = srco->sockfd;
 | 
				
			||||||
    SheepdogReq *hdr = srco->hdr;
 | 
					    SheepdogReq *hdr = srco->hdr;
 | 
				
			||||||
@ -605,9 +605,9 @@ static coroutine_fn void do_co_req(void *opaque)
 | 
				
			|||||||
    unsigned int *wlen = srco->wlen;
 | 
					    unsigned int *wlen = srco->wlen;
 | 
				
			||||||
    unsigned int *rlen = srco->rlen;
 | 
					    unsigned int *rlen = srco->rlen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    co = qemu_coroutine_self();
 | 
					    srco->co = qemu_coroutine_self();
 | 
				
			||||||
    aio_set_fd_handler(srco->aio_context, sockfd, false,
 | 
					    aio_set_fd_handler(srco->aio_context, sockfd, false,
 | 
				
			||||||
                       NULL, restart_co_req, NULL, co);
 | 
					                       NULL, restart_co_req, NULL, srco);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = send_co_req(sockfd, hdr, data, wlen);
 | 
					    ret = send_co_req(sockfd, hdr, data, wlen);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
@ -615,7 +615,7 @@ static coroutine_fn void do_co_req(void *opaque)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    aio_set_fd_handler(srco->aio_context, sockfd, false,
 | 
					    aio_set_fd_handler(srco->aio_context, sockfd, false,
 | 
				
			||||||
                       restart_co_req, NULL, NULL, co);
 | 
					                       restart_co_req, NULL, NULL, srco);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = qemu_co_recv(sockfd, hdr, sizeof(*hdr));
 | 
					    ret = qemu_co_recv(sockfd, hdr, sizeof(*hdr));
 | 
				
			||||||
    if (ret != sizeof(*hdr)) {
 | 
					    if (ret != sizeof(*hdr)) {
 | 
				
			||||||
@ -643,6 +643,7 @@ out:
 | 
				
			|||||||
    aio_set_fd_handler(srco->aio_context, sockfd, false,
 | 
					    aio_set_fd_handler(srco->aio_context, sockfd, false,
 | 
				
			||||||
                       NULL, NULL, NULL, NULL);
 | 
					                       NULL, NULL, NULL, NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    srco->co = NULL;
 | 
				
			||||||
    srco->ret = ret;
 | 
					    srco->ret = ret;
 | 
				
			||||||
    srco->finished = true;
 | 
					    srco->finished = true;
 | 
				
			||||||
    if (srco->bs) {
 | 
					    if (srco->bs) {
 | 
				
			||||||
@ -866,7 +867,7 @@ static void coroutine_fn aio_read_response(void *opaque)
 | 
				
			|||||||
         * We've finished all requests which belong to the AIOCB, so
 | 
					         * We've finished all requests which belong to the AIOCB, so
 | 
				
			||||||
         * we can switch back to sd_co_readv/writev now.
 | 
					         * we can switch back to sd_co_readv/writev now.
 | 
				
			||||||
         */
 | 
					         */
 | 
				
			||||||
        qemu_coroutine_enter(acb->coroutine);
 | 
					        aio_co_wake(acb->coroutine);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
@ -883,14 +884,14 @@ static void co_read_response(void *opaque)
 | 
				
			|||||||
        s->co_recv = qemu_coroutine_create(aio_read_response, opaque);
 | 
					        s->co_recv = qemu_coroutine_create(aio_read_response, opaque);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qemu_coroutine_enter(s->co_recv);
 | 
					    aio_co_wake(s->co_recv);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void co_write_request(void *opaque)
 | 
					static void co_write_request(void *opaque)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    BDRVSheepdogState *s = opaque;
 | 
					    BDRVSheepdogState *s = opaque;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qemu_coroutine_enter(s->co_send);
 | 
					    aio_co_wake(s->co_send);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										29
									
								
								block/ssh.c
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								block/ssh.c
									
									
									
									
									
								
							@ -889,10 +889,14 @@ static void restart_coroutine(void *opaque)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    DPRINTF("co=%p", co);
 | 
					    DPRINTF("co=%p", co);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    qemu_coroutine_enter(co);
 | 
					    aio_co_wake(co);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static coroutine_fn void set_fd_handler(BDRVSSHState *s, BlockDriverState *bs)
 | 
					/* A non-blocking call returned EAGAIN, so yield, ensuring the
 | 
				
			||||||
 | 
					 * handlers are set up so that we'll be rescheduled when there is an
 | 
				
			||||||
 | 
					 * interesting event on the socket.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int r;
 | 
					    int r;
 | 
				
			||||||
    IOHandler *rd_handler = NULL, *wr_handler = NULL;
 | 
					    IOHandler *rd_handler = NULL, *wr_handler = NULL;
 | 
				
			||||||
@ -912,25 +916,10 @@ static coroutine_fn void set_fd_handler(BDRVSSHState *s, BlockDriverState *bs)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
 | 
					    aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
 | 
				
			||||||
                       false, rd_handler, wr_handler, NULL, co);
 | 
					                       false, rd_handler, wr_handler, NULL, co);
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static coroutine_fn void clear_fd_handler(BDRVSSHState *s,
 | 
					 | 
				
			||||||
                                          BlockDriverState *bs)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    DPRINTF("s->sock=%d", s->sock);
 | 
					 | 
				
			||||||
    aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock,
 | 
					 | 
				
			||||||
                       false, NULL, NULL, NULL, NULL);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* A non-blocking call returned EAGAIN, so yield, ensuring the
 | 
					 | 
				
			||||||
 * handlers are set up so that we'll be rescheduled when there is an
 | 
					 | 
				
			||||||
 * interesting event on the socket.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static coroutine_fn void co_yield(BDRVSSHState *s, BlockDriverState *bs)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    set_fd_handler(s, bs);
 | 
					 | 
				
			||||||
    qemu_coroutine_yield();
 | 
					    qemu_coroutine_yield();
 | 
				
			||||||
    clear_fd_handler(s, bs);
 | 
					    DPRINTF("s->sock=%d - back", s->sock);
 | 
				
			||||||
 | 
					    aio_set_fd_handler(bdrv_get_aio_context(bs), s->sock, false,
 | 
				
			||||||
 | 
					                       NULL, NULL, NULL, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* SFTP has a function `libssh2_sftp_seek64' which seeks to a position
 | 
					/* SFTP has a function `libssh2_sftp_seek64' which seeks to a position
 | 
				
			||||||
 | 
				
			|||||||
@ -41,7 +41,7 @@ struct QEMUWin32AIOState {
 | 
				
			|||||||
    HANDLE hIOCP;
 | 
					    HANDLE hIOCP;
 | 
				
			||||||
    EventNotifier e;
 | 
					    EventNotifier e;
 | 
				
			||||||
    int count;
 | 
					    int count;
 | 
				
			||||||
    bool is_aio_context_attached;
 | 
					    AioContext *aio_ctx;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct QEMUWin32AIOCB {
 | 
					typedef struct QEMUWin32AIOCB {
 | 
				
			||||||
@ -88,7 +88,9 @@ static void win32_aio_process_completion(QEMUWin32AIOState *s,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(s->aio_ctx);
 | 
				
			||||||
    waiocb->common.cb(waiocb->common.opaque, ret);
 | 
					    waiocb->common.cb(waiocb->common.opaque, ret);
 | 
				
			||||||
 | 
					    aio_context_release(s->aio_ctx);
 | 
				
			||||||
    qemu_aio_unref(waiocb);
 | 
					    qemu_aio_unref(waiocb);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -176,13 +178,13 @@ void win32_aio_detach_aio_context(QEMUWin32AIOState *aio,
 | 
				
			|||||||
                                  AioContext *old_context)
 | 
					                                  AioContext *old_context)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    aio_set_event_notifier(old_context, &aio->e, false, NULL, NULL);
 | 
					    aio_set_event_notifier(old_context, &aio->e, false, NULL, NULL);
 | 
				
			||||||
    aio->is_aio_context_attached = false;
 | 
					    aio->aio_ctx = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void win32_aio_attach_aio_context(QEMUWin32AIOState *aio,
 | 
					void win32_aio_attach_aio_context(QEMUWin32AIOState *aio,
 | 
				
			||||||
                                  AioContext *new_context)
 | 
					                                  AioContext *new_context)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    aio->is_aio_context_attached = true;
 | 
					    aio->aio_ctx = new_context;
 | 
				
			||||||
    aio_set_event_notifier(new_context, &aio->e, false,
 | 
					    aio_set_event_notifier(new_context, &aio->e, false,
 | 
				
			||||||
                           win32_aio_completion_cb, NULL);
 | 
					                           win32_aio_completion_cb, NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -212,7 +214,7 @@ out_free_state:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void win32_aio_cleanup(QEMUWin32AIOState *aio)
 | 
					void win32_aio_cleanup(QEMUWin32AIOState *aio)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    assert(!aio->is_aio_context_attached);
 | 
					    assert(!aio->aio_ctx);
 | 
				
			||||||
    CloseHandle(aio->hIOCP);
 | 
					    CloseHandle(aio->hIOCP);
 | 
				
			||||||
    event_notifier_cleanup(&aio->e);
 | 
					    event_notifier_cleanup(&aio->e);
 | 
				
			||||||
    g_free(aio);
 | 
					    g_free(aio);
 | 
				
			||||||
 | 
				
			|||||||
@ -150,7 +150,8 @@ static void virtio_blk_ioctl_complete(void *opaque, int status)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    VirtIOBlockIoctlReq *ioctl_req = opaque;
 | 
					    VirtIOBlockIoctlReq *ioctl_req = opaque;
 | 
				
			||||||
    VirtIOBlockReq *req = ioctl_req->req;
 | 
					    VirtIOBlockReq *req = ioctl_req->req;
 | 
				
			||||||
    VirtIODevice *vdev = VIRTIO_DEVICE(req->dev);
 | 
					    VirtIOBlock *s = req->dev;
 | 
				
			||||||
 | 
					    VirtIODevice *vdev = VIRTIO_DEVICE(s);
 | 
				
			||||||
    struct virtio_scsi_inhdr *scsi;
 | 
					    struct virtio_scsi_inhdr *scsi;
 | 
				
			||||||
    struct sg_io_hdr *hdr;
 | 
					    struct sg_io_hdr *hdr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -587,6 +588,7 @@ bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
 | 
				
			|||||||
    MultiReqBuffer mrb = {};
 | 
					    MultiReqBuffer mrb = {};
 | 
				
			||||||
    bool progress = false;
 | 
					    bool progress = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    aio_context_acquire(blk_get_aio_context(s->blk));
 | 
				
			||||||
    blk_io_plug(s->blk);
 | 
					    blk_io_plug(s->blk);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
@ -609,6 +611,7 @@ bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    blk_io_unplug(s->blk);
 | 
					    blk_io_unplug(s->blk);
 | 
				
			||||||
 | 
					    aio_context_release(blk_get_aio_context(s->blk));
 | 
				
			||||||
    return progress;
 | 
					    return progress;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -441,10 +441,12 @@ bool virtio_scsi_handle_ctrl_vq(VirtIOSCSI *s, VirtQueue *vq)
 | 
				
			|||||||
    VirtIOSCSIReq *req;
 | 
					    VirtIOSCSIReq *req;
 | 
				
			||||||
    bool progress = false;
 | 
					    bool progress = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    virtio_scsi_acquire(s);
 | 
				
			||||||
    while ((req = virtio_scsi_pop_req(s, vq))) {
 | 
					    while ((req = virtio_scsi_pop_req(s, vq))) {
 | 
				
			||||||
        progress = true;
 | 
					        progress = true;
 | 
				
			||||||
        virtio_scsi_handle_ctrl_req(s, req);
 | 
					        virtio_scsi_handle_ctrl_req(s, req);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    virtio_scsi_release(s);
 | 
				
			||||||
    return progress;
 | 
					    return progress;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -602,6 +604,7 @@ bool virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    QTAILQ_HEAD(, VirtIOSCSIReq) reqs = QTAILQ_HEAD_INITIALIZER(reqs);
 | 
					    QTAILQ_HEAD(, VirtIOSCSIReq) reqs = QTAILQ_HEAD_INITIALIZER(reqs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    virtio_scsi_acquire(s);
 | 
				
			||||||
    do {
 | 
					    do {
 | 
				
			||||||
        virtio_queue_set_notification(vq, 0);
 | 
					        virtio_queue_set_notification(vq, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -629,6 +632,7 @@ bool virtio_scsi_handle_cmd_vq(VirtIOSCSI *s, VirtQueue *vq)
 | 
				
			|||||||
    QTAILQ_FOREACH_SAFE(req, &reqs, next, next) {
 | 
					    QTAILQ_FOREACH_SAFE(req, &reqs, next, next) {
 | 
				
			||||||
        virtio_scsi_handle_cmd_req_submit(s, req);
 | 
					        virtio_scsi_handle_cmd_req_submit(s, req);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    virtio_scsi_release(s);
 | 
				
			||||||
    return progress;
 | 
					    return progress;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -760,10 +764,13 @@ out:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bool virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq)
 | 
					bool virtio_scsi_handle_event_vq(VirtIOSCSI *s, VirtQueue *vq)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    virtio_scsi_acquire(s);
 | 
				
			||||||
    if (s->events_dropped) {
 | 
					    if (s->events_dropped) {
 | 
				
			||||||
        virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
 | 
					        virtio_scsi_push_event(s, NULL, VIRTIO_SCSI_T_NO_EVENT, 0);
 | 
				
			||||||
 | 
					        virtio_scsi_release(s);
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    virtio_scsi_release(s);
 | 
				
			||||||
    return false;
 | 
					    return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -402,9 +402,7 @@ static bool aio_dispatch_handlers(AioContext *ctx)
 | 
				
			|||||||
            (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) &&
 | 
					            (revents & (G_IO_IN | G_IO_HUP | G_IO_ERR)) &&
 | 
				
			||||||
            aio_node_check(ctx, node->is_external) &&
 | 
					            aio_node_check(ctx, node->is_external) &&
 | 
				
			||||||
            node->io_read) {
 | 
					            node->io_read) {
 | 
				
			||||||
            aio_context_acquire(ctx);
 | 
					 | 
				
			||||||
            node->io_read(node->opaque);
 | 
					            node->io_read(node->opaque);
 | 
				
			||||||
            aio_context_release(ctx);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* aio_notify() does not count as progress */
 | 
					            /* aio_notify() does not count as progress */
 | 
				
			||||||
            if (node->opaque != &ctx->notifier) {
 | 
					            if (node->opaque != &ctx->notifier) {
 | 
				
			||||||
@ -415,9 +413,7 @@ static bool aio_dispatch_handlers(AioContext *ctx)
 | 
				
			|||||||
            (revents & (G_IO_OUT | G_IO_ERR)) &&
 | 
					            (revents & (G_IO_OUT | G_IO_ERR)) &&
 | 
				
			||||||
            aio_node_check(ctx, node->is_external) &&
 | 
					            aio_node_check(ctx, node->is_external) &&
 | 
				
			||||||
            node->io_write) {
 | 
					            node->io_write) {
 | 
				
			||||||
            aio_context_acquire(ctx);
 | 
					 | 
				
			||||||
            node->io_write(node->opaque);
 | 
					            node->io_write(node->opaque);
 | 
				
			||||||
            aio_context_release(ctx);
 | 
					 | 
				
			||||||
            progress = true;
 | 
					            progress = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -618,10 +614,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
 | 
				
			|||||||
        start = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
 | 
					        start = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    aio_context_acquire(ctx);
 | 
					 | 
				
			||||||
    progress = try_poll_mode(ctx, blocking);
 | 
					    progress = try_poll_mode(ctx, blocking);
 | 
				
			||||||
    aio_context_release(ctx);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (!progress) {
 | 
					    if (!progress) {
 | 
				
			||||||
        assert(npfd == 0);
 | 
					        assert(npfd == 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -266,9 +266,7 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
 | 
				
			|||||||
            (revents || event_notifier_get_handle(node->e) == event) &&
 | 
					            (revents || event_notifier_get_handle(node->e) == event) &&
 | 
				
			||||||
            node->io_notify) {
 | 
					            node->io_notify) {
 | 
				
			||||||
            node->pfd.revents = 0;
 | 
					            node->pfd.revents = 0;
 | 
				
			||||||
            aio_context_acquire(ctx);
 | 
					 | 
				
			||||||
            node->io_notify(node->e);
 | 
					            node->io_notify(node->e);
 | 
				
			||||||
            aio_context_release(ctx);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* aio_notify() does not count as progress */
 | 
					            /* aio_notify() does not count as progress */
 | 
				
			||||||
            if (node->e != &ctx->notifier) {
 | 
					            if (node->e != &ctx->notifier) {
 | 
				
			||||||
@ -280,15 +278,11 @@ static bool aio_dispatch_handlers(AioContext *ctx, HANDLE event)
 | 
				
			|||||||
            (node->io_read || node->io_write)) {
 | 
					            (node->io_read || node->io_write)) {
 | 
				
			||||||
            node->pfd.revents = 0;
 | 
					            node->pfd.revents = 0;
 | 
				
			||||||
            if ((revents & G_IO_IN) && node->io_read) {
 | 
					            if ((revents & G_IO_IN) && node->io_read) {
 | 
				
			||||||
                aio_context_acquire(ctx);
 | 
					 | 
				
			||||||
                node->io_read(node->opaque);
 | 
					                node->io_read(node->opaque);
 | 
				
			||||||
                aio_context_release(ctx);
 | 
					 | 
				
			||||||
                progress = true;
 | 
					                progress = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if ((revents & G_IO_OUT) && node->io_write) {
 | 
					            if ((revents & G_IO_OUT) && node->io_write) {
 | 
				
			||||||
                aio_context_acquire(ctx);
 | 
					 | 
				
			||||||
                node->io_write(node->opaque);
 | 
					                node->io_write(node->opaque);
 | 
				
			||||||
                aio_context_release(ctx);
 | 
					 | 
				
			||||||
                progress = true;
 | 
					                progress = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user