qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] block/iscsi: use a bh to schedule co reentrance
@ 2013-12-14 16:31 Peter Lieven
  2013-12-16 10:26 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Lieven @ 2013-12-14 16:31 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, stefanha, Peter Lieven, qemu-stable, ronniesahlberg,
	anthony, pbonzini

this fixes a potential segfault and performance regression.

If the coroutine is reentered directly in the iscsi_co_generic_cb
iscsi_process_{read,write} are interrupted and reentered any
time later. One the one hand this could happen after an iscsi_close
where the iscsi context is already gone (segfault). On the
other hand this limits the number of processed callbacks
in each aio_dispatch to one (potential performance regression).

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index fa69408..b0e6eea 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -68,6 +68,7 @@ typedef struct IscsiTask {
     int do_retry;
     struct scsi_task *task;
     Coroutine *co;
+    QEMUBH *bh;
 } IscsiTask;
 
 typedef struct IscsiAIOCB {
@@ -123,6 +124,13 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
     qemu_bh_schedule(acb->bh);
 }
 
+static void iscsi_co_generic_bh_cb(void *opaque)
+{
+    struct IscsiTask *iTask = opaque;
+    qemu_bh_delete(iTask->bh);
+    qemu_coroutine_enter(iTask->co, NULL);
+}
+
 static void
 iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
                         void *command_data, void *opaque)
@@ -147,7 +155,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
 
 out:
     if (iTask->co) {
-        qemu_coroutine_enter(iTask->co, NULL);
+        iTask->bh = qemu_bh_new(iscsi_co_generic_bh_cb, iTask);
+        qemu_bh_schedule(iTask->bh);
     }
 }
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] block/iscsi: use a bh to schedule co reentrance
  2013-12-14 16:31 [Qemu-devel] [PATCH] block/iscsi: use a bh to schedule co reentrance Peter Lieven
@ 2013-12-16 10:26 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2013-12-16 10:26 UTC (permalink / raw)
  To: Peter Lieven
  Cc: kwolf, stefanha, qemu-devel, qemu-stable, ronniesahlberg, anthony

Il 14/12/2013 17:31, Peter Lieven ha scritto:
> this fixes a potential segfault and performance regression.
> 
> If the coroutine is reentered directly in the iscsi_co_generic_cb
> iscsi_process_{read,write} are interrupted and reentered any
> time later. One the one hand this could happen after an iscsi_close
> where the iscsi context is already gone (segfault). On the
> other hand this limits the number of processed callbacks
> in each aio_dispatch to one (potential performance regression).
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Peter Lieven <pl@kamp.de>
> ---
>  block/iscsi.c |   11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/block/iscsi.c b/block/iscsi.c
> index fa69408..b0e6eea 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -68,6 +68,7 @@ typedef struct IscsiTask {
>      int do_retry;
>      struct scsi_task *task;
>      Coroutine *co;
> +    QEMUBH *bh;
>  } IscsiTask;
>  
>  typedef struct IscsiAIOCB {
> @@ -123,6 +124,13 @@ iscsi_schedule_bh(IscsiAIOCB *acb)
>      qemu_bh_schedule(acb->bh);
>  }
>  
> +static void iscsi_co_generic_bh_cb(void *opaque)
> +{
> +    struct IscsiTask *iTask = opaque;
> +    qemu_bh_delete(iTask->bh);
> +    qemu_coroutine_enter(iTask->co, NULL);
> +}
> +
>  static void
>  iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
>                          void *command_data, void *opaque)
> @@ -147,7 +155,8 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
>  
>  out:
>      if (iTask->co) {
> -        qemu_coroutine_enter(iTask->co, NULL);
> +        iTask->bh = qemu_bh_new(iscsi_co_generic_bh_cb, iTask);
> +        qemu_bh_schedule(iTask->bh);
>      }
>  }
>  
> 

Applied to scsi-next branch, thanks.

Paolo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-12-16 10:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-14 16:31 [Qemu-devel] [PATCH] block/iscsi: use a bh to schedule co reentrance Peter Lieven
2013-12-16 10:26 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).