mirror of https://github.com/proxmox/mirror_qemu
iscsi: implement .bdrv_detach/attach_aio_context()
Drop the assumption that we're using the main AioContext for Linux AIO. Convert qemu_aio_set_fd_handler() to aio_set_fd_handler() and timer_new_ms() to aio_timer_new(). The .bdrv_detach/attach_aio_context() interfaces also need to be implemented to move the fd and timer from the old to the new AioContext. Cc: Peter Lieven <pl@kamp.de> Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Peter Lieven <pl@kamp.de>master
parent
6ee50af24b
commit
80cf625766
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
typedef struct IscsiLun {
|
typedef struct IscsiLun {
|
||||||
struct iscsi_context *iscsi;
|
struct iscsi_context *iscsi;
|
||||||
|
AioContext *aio_context;
|
||||||
int lun;
|
int lun;
|
||||||
enum scsi_inquiry_peripheral_device_type type;
|
enum scsi_inquiry_peripheral_device_type type;
|
||||||
int block_size;
|
int block_size;
|
||||||
|
@ -73,6 +74,7 @@ typedef struct IscsiTask {
|
||||||
struct scsi_task *task;
|
struct scsi_task *task;
|
||||||
Coroutine *co;
|
Coroutine *co;
|
||||||
QEMUBH *bh;
|
QEMUBH *bh;
|
||||||
|
IscsiLun *iscsilun;
|
||||||
} IscsiTask;
|
} IscsiTask;
|
||||||
|
|
||||||
typedef struct IscsiAIOCB {
|
typedef struct IscsiAIOCB {
|
||||||
|
@ -133,7 +135,7 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
|
||||||
if (acb->bh) {
|
if (acb->bh) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
acb->bh = qemu_bh_new(iscsi_bh_cb, acb);
|
acb->bh = aio_bh_new(acb->iscsilun->aio_context, iscsi_bh_cb, acb);
|
||||||
qemu_bh_schedule(acb->bh);
|
qemu_bh_schedule(acb->bh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +171,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (iTask->co) {
|
if (iTask->co) {
|
||||||
iTask->bh = qemu_bh_new(iscsi_co_generic_bh_cb, iTask);
|
iTask->bh = aio_bh_new(iTask->iscsilun->aio_context,
|
||||||
|
iscsi_co_generic_bh_cb, iTask);
|
||||||
qemu_bh_schedule(iTask->bh);
|
qemu_bh_schedule(iTask->bh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,8 +180,9 @@ out:
|
||||||
static void iscsi_co_init_iscsitask(IscsiLun *iscsilun, struct IscsiTask *iTask)
|
static void iscsi_co_init_iscsitask(IscsiLun *iscsilun, struct IscsiTask *iTask)
|
||||||
{
|
{
|
||||||
*iTask = (struct IscsiTask) {
|
*iTask = (struct IscsiTask) {
|
||||||
.co = qemu_coroutine_self(),
|
.co = qemu_coroutine_self(),
|
||||||
.retries = ISCSI_CMD_RETRIES,
|
.retries = ISCSI_CMD_RETRIES,
|
||||||
|
.iscsilun = iscsilun,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +213,7 @@ iscsi_aio_cancel(BlockDriverAIOCB *blockacb)
|
||||||
iscsi_abort_task_cb, acb);
|
iscsi_abort_task_cb, acb);
|
||||||
|
|
||||||
while (acb->status == -EINPROGRESS) {
|
while (acb->status == -EINPROGRESS) {
|
||||||
qemu_aio_wait();
|
aio_poll(iscsilun->aio_context, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,10 +236,11 @@ iscsi_set_events(IscsiLun *iscsilun)
|
||||||
ev = POLLIN;
|
ev = POLLIN;
|
||||||
ev |= iscsi_which_events(iscsi);
|
ev |= iscsi_which_events(iscsi);
|
||||||
if (ev != iscsilun->events) {
|
if (ev != iscsilun->events) {
|
||||||
qemu_aio_set_fd_handler(iscsi_get_fd(iscsi),
|
aio_set_fd_handler(iscsilun->aio_context,
|
||||||
iscsi_process_read,
|
iscsi_get_fd(iscsi),
|
||||||
(ev & POLLOUT) ? iscsi_process_write : NULL,
|
iscsi_process_read,
|
||||||
iscsilun);
|
(ev & POLLOUT) ? iscsi_process_write : NULL,
|
||||||
|
iscsilun);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -791,7 +796,7 @@ static int iscsi_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
|
||||||
iscsi_aio_ioctl(bs, req, buf, ioctl_cb, &status);
|
iscsi_aio_ioctl(bs, req, buf, ioctl_cb, &status);
|
||||||
|
|
||||||
while (status == -EINPROGRESS) {
|
while (status == -EINPROGRESS) {
|
||||||
qemu_aio_wait();
|
aio_poll(iscsilun->aio_context, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1195,6 +1200,40 @@ fail_with_err:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void iscsi_detach_aio_context(BlockDriverState *bs)
|
||||||
|
{
|
||||||
|
IscsiLun *iscsilun = bs->opaque;
|
||||||
|
|
||||||
|
aio_set_fd_handler(iscsilun->aio_context,
|
||||||
|
iscsi_get_fd(iscsilun->iscsi),
|
||||||
|
NULL, NULL, NULL);
|
||||||
|
iscsilun->events = 0;
|
||||||
|
|
||||||
|
if (iscsilun->nop_timer) {
|
||||||
|
timer_del(iscsilun->nop_timer);
|
||||||
|
timer_free(iscsilun->nop_timer);
|
||||||
|
iscsilun->nop_timer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void iscsi_attach_aio_context(BlockDriverState *bs,
|
||||||
|
AioContext *new_context)
|
||||||
|
{
|
||||||
|
IscsiLun *iscsilun = bs->opaque;
|
||||||
|
|
||||||
|
iscsilun->aio_context = new_context;
|
||||||
|
iscsi_set_events(iscsilun);
|
||||||
|
|
||||||
|
#if defined(LIBISCSI_FEATURE_NOP_COUNTER)
|
||||||
|
/* Set up a timer for sending out iSCSI NOPs */
|
||||||
|
iscsilun->nop_timer = aio_timer_new(iscsilun->aio_context,
|
||||||
|
QEMU_CLOCK_REALTIME, SCALE_MS,
|
||||||
|
iscsi_nop_timed_event, iscsilun);
|
||||||
|
timer_mod(iscsilun->nop_timer,
|
||||||
|
qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + NOP_INTERVAL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We support iscsi url's on the form
|
* We support iscsi url's on the form
|
||||||
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
|
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
|
||||||
|
@ -1301,6 +1340,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
}
|
}
|
||||||
|
|
||||||
iscsilun->iscsi = iscsi;
|
iscsilun->iscsi = iscsi;
|
||||||
|
iscsilun->aio_context = bdrv_get_aio_context(bs);
|
||||||
iscsilun->lun = iscsi_url->lun;
|
iscsilun->lun = iscsi_url->lun;
|
||||||
iscsilun->has_write_same = true;
|
iscsilun->has_write_same = true;
|
||||||
|
|
||||||
|
@ -1374,11 +1414,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
|
||||||
scsi_free_scsi_task(task);
|
scsi_free_scsi_task(task);
|
||||||
task = NULL;
|
task = NULL;
|
||||||
|
|
||||||
#if defined(LIBISCSI_FEATURE_NOP_COUNTER)
|
iscsi_attach_aio_context(bs, iscsilun->aio_context);
|
||||||
/* Set up a timer for sending out iSCSI NOPs */
|
|
||||||
iscsilun->nop_timer = timer_new_ms(QEMU_CLOCK_REALTIME, iscsi_nop_timed_event, iscsilun);
|
|
||||||
timer_mod(iscsilun->nop_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + NOP_INTERVAL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Guess the internal cluster (page) size of the iscsi target by the means
|
/* Guess the internal cluster (page) size of the iscsi target by the means
|
||||||
* of opt_unmap_gran. Transfer the unmap granularity only if it has a
|
* of opt_unmap_gran. Transfer the unmap granularity only if it has a
|
||||||
|
@ -1422,11 +1458,7 @@ static void iscsi_close(BlockDriverState *bs)
|
||||||
IscsiLun *iscsilun = bs->opaque;
|
IscsiLun *iscsilun = bs->opaque;
|
||||||
struct iscsi_context *iscsi = iscsilun->iscsi;
|
struct iscsi_context *iscsi = iscsilun->iscsi;
|
||||||
|
|
||||||
if (iscsilun->nop_timer) {
|
iscsi_detach_aio_context(bs);
|
||||||
timer_del(iscsilun->nop_timer);
|
|
||||||
timer_free(iscsilun->nop_timer);
|
|
||||||
}
|
|
||||||
qemu_aio_set_fd_handler(iscsi_get_fd(iscsi), NULL, NULL, NULL);
|
|
||||||
iscsi_destroy_context(iscsi);
|
iscsi_destroy_context(iscsi);
|
||||||
g_free(iscsilun->zeroblock);
|
g_free(iscsilun->zeroblock);
|
||||||
g_free(iscsilun->allocationmap);
|
g_free(iscsilun->allocationmap);
|
||||||
|
@ -1530,10 +1562,7 @@ static int iscsi_create(const char *filename, QEMUOptionParameter *options,
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (iscsilun->nop_timer) {
|
iscsi_detach_aio_context(bs);
|
||||||
timer_del(iscsilun->nop_timer);
|
|
||||||
timer_free(iscsilun->nop_timer);
|
|
||||||
}
|
|
||||||
if (iscsilun->type != TYPE_DISK) {
|
if (iscsilun->type != TYPE_DISK) {
|
||||||
ret = -ENODEV;
|
ret = -ENODEV;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -1604,6 +1633,9 @@ static BlockDriver bdrv_iscsi = {
|
||||||
.bdrv_ioctl = iscsi_ioctl,
|
.bdrv_ioctl = iscsi_ioctl,
|
||||||
.bdrv_aio_ioctl = iscsi_aio_ioctl,
|
.bdrv_aio_ioctl = iscsi_aio_ioctl,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
.bdrv_detach_aio_context = iscsi_detach_aio_context,
|
||||||
|
.bdrv_attach_aio_context = iscsi_attach_aio_context,
|
||||||
};
|
};
|
||||||
|
|
||||||
static QemuOptsList qemu_iscsi_opts = {
|
static QemuOptsList qemu_iscsi_opts = {
|
||||||
|
|
Loading…
Reference in New Issue