diff mbox

[3/6] sheepdog: use coroutine based socket functions in coroutine context

Message ID 1340749583-5292-4-git-send-email-morita.kazutaka@lab.ntt.co.jp
State New
Headers show

Commit Message

MORITA Kazutaka June 26, 2012, 10:26 p.m. UTC
This removes blocking network I/Os in coroutine context.

Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
---
 block/sheepdog.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

Comments

Kevin Wolf July 3, 2012, 1:15 p.m. UTC | #1
Am 27.06.2012 00:26, schrieb MORITA Kazutaka:
> This removes blocking network I/Os in coroutine context.
> 
> Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
> ---
>  block/sheepdog.c |   10 ++++++++--
>  1 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/block/sheepdog.c b/block/sheepdog.c
> index 0b49c6d..5dc1d7a 100644
> --- a/block/sheepdog.c
> +++ b/block/sheepdog.c
> @@ -541,11 +541,18 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
>      return ret;
>  }
>  
> +static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data,
> +                                  unsigned int *wlen, unsigned int *rlen);
> +
>  static int do_req(int sockfd, SheepdogReq *hdr, void *data,
>                    unsigned int *wlen, unsigned int *rlen)
>  {
>      int ret;
>  
> +    if (qemu_in_coroutine()) {
> +        return do_co_req(sockfd, hdr, data, wlen, rlen);
> +    }
> +
>      socket_set_block(sockfd);
>      ret = send_req(sockfd, hdr, data, wlen);
>      if (ret < 0) {

How about replacing the non-coroutine implementation by code that
creates a new coroutine and executes do_co_req() as well? This would
reduce some code duplication.

Kevin
Peter A. G. Crosthwaite July 4, 2012, 12:25 a.m. UTC | #2
On Tue, Jul 3, 2012 at 11:15 PM, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 27.06.2012 00:26, schrieb MORITA Kazutaka:
>> This removes blocking network I/Os in coroutine context.
>>
>> Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
>> ---
>>  block/sheepdog.c |   10 ++++++++--
>>  1 files changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/block/sheepdog.c b/block/sheepdog.c
>> index 0b49c6d..5dc1d7a 100644
>> --- a/block/sheepdog.c
>> +++ b/block/sheepdog.c
>> @@ -541,11 +541,18 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
>>      return ret;
>>  }
>>
>> +static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data,
>> +                                  unsigned int *wlen, unsigned int *rlen);
>> +
>>  static int do_req(int sockfd, SheepdogReq *hdr, void *data,
>>                    unsigned int *wlen, unsigned int *rlen)
>>  {
>>      int ret;
>>
>> +    if (qemu_in_coroutine()) {
>> +        return do_co_req(sockfd, hdr, data, wlen, rlen);
>> +    }
>> +
>>      socket_set_block(sockfd);
>>      ret = send_req(sockfd, hdr, data, wlen);
>>      if (ret < 0) {
>
> How about replacing the non-coroutine implementation by code that
> creates a new coroutine and executes do_co_req() as well? This would
> reduce some code duplication.
>

+1. I presume it can it be done such that there is no if
(qemu_in_coroutine()) logic that way?

Regards,
Peter

> Kevin
>
Kevin Wolf July 4, 2012, 8:37 a.m. UTC | #3
Am 04.07.2012 02:25, schrieb Peter Crosthwaite:
> On Tue, Jul 3, 2012 at 11:15 PM, Kevin Wolf <kwolf@redhat.com> wrote:
>> Am 27.06.2012 00:26, schrieb MORITA Kazutaka:
>>> This removes blocking network I/Os in coroutine context.
>>>
>>> Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
>>> ---
>>>  block/sheepdog.c |   10 ++++++++--
>>>  1 files changed, 8 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/block/sheepdog.c b/block/sheepdog.c
>>> index 0b49c6d..5dc1d7a 100644
>>> --- a/block/sheepdog.c
>>> +++ b/block/sheepdog.c
>>> @@ -541,11 +541,18 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
>>>      return ret;
>>>  }
>>>
>>> +static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data,
>>> +                                  unsigned int *wlen, unsigned int *rlen);
>>> +
>>>  static int do_req(int sockfd, SheepdogReq *hdr, void *data,
>>>                    unsigned int *wlen, unsigned int *rlen)
>>>  {
>>>      int ret;
>>>
>>> +    if (qemu_in_coroutine()) {
>>> +        return do_co_req(sockfd, hdr, data, wlen, rlen);
>>> +    }
>>> +
>>>      socket_set_block(sockfd);
>>>      ret = send_req(sockfd, hdr, data, wlen);
>>>      if (ret < 0) {
>>
>> How about replacing the non-coroutine implementation by code that
>> creates a new coroutine and executes do_co_req() as well? This would
>> reduce some code duplication.
>>
> 
> +1. I presume it can it be done such that there is no if
> (qemu_in_coroutine()) logic that way?

That was not my intention, and actually I don't think it would help your
case here because this is a function truly internal to the block layer
(or actually even a single block driver).

Kevin
MORITA Kazutaka July 4, 2012, 3:27 p.m. UTC | #4
At Tue, 03 Jul 2012 15:15:03 +0200,
Kevin Wolf wrote:
> 
> Am 27.06.2012 00:26, schrieb MORITA Kazutaka:
> > This removes blocking network I/Os in coroutine context.
> > 
> > Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
> > ---
> >  block/sheepdog.c |   10 ++++++++--
> >  1 files changed, 8 insertions(+), 2 deletions(-)
> > 
> > diff --git a/block/sheepdog.c b/block/sheepdog.c
> > index 0b49c6d..5dc1d7a 100644
> > --- a/block/sheepdog.c
> > +++ b/block/sheepdog.c
> > @@ -541,11 +541,18 @@ static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
> >      return ret;
> >  }
> >  
> > +static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data,
> > +                                  unsigned int *wlen, unsigned int *rlen);
> > +
> >  static int do_req(int sockfd, SheepdogReq *hdr, void *data,
> >                    unsigned int *wlen, unsigned int *rlen)
> >  {
> >      int ret;
> >  
> > +    if (qemu_in_coroutine()) {
> > +        return do_co_req(sockfd, hdr, data, wlen, rlen);
> > +    }
> > +
> >      socket_set_block(sockfd);
> >      ret = send_req(sockfd, hdr, data, wlen);
> >      if (ret < 0) {
> 
> How about replacing the non-coroutine implementation by code that
> creates a new coroutine and executes do_co_req() as well? This would
> reduce some code duplication.

Indeed.  I'll send a patch for it soon.

Thanks,

Kazutaka
diff mbox

Patch

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 0b49c6d..5dc1d7a 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -541,11 +541,18 @@  static coroutine_fn int send_co_req(int sockfd, SheepdogReq *hdr, void *data,
     return ret;
 }
 
+static coroutine_fn int do_co_req(int sockfd, SheepdogReq *hdr, void *data,
+                                  unsigned int *wlen, unsigned int *rlen);
+
 static int do_req(int sockfd, SheepdogReq *hdr, void *data,
                   unsigned int *wlen, unsigned int *rlen)
 {
     int ret;
 
+    if (qemu_in_coroutine()) {
+        return do_co_req(sockfd, hdr, data, wlen, rlen);
+    }
+
     socket_set_block(sockfd);
     ret = send_req(sockfd, hdr, data, wlen);
     if (ret < 0) {
@@ -1642,7 +1649,6 @@  static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num,
     int ret;
 
     if (bs->growable && sector_num + nb_sectors > bs->total_sectors) {
-        /* TODO: shouldn't block here */
         ret = sd_truncate(bs, (sector_num + nb_sectors) * SECTOR_SIZE);
         if (ret < 0) {
             return ret;
@@ -1710,7 +1716,7 @@  static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
     hdr.opcode = SD_OP_FLUSH_VDI;
     hdr.oid = vid_to_vdi_oid(inode->vdi_id);
 
-    ret = do_co_req(s->flush_fd, (SheepdogReq *)&hdr, NULL, &wlen, &rlen);
+    ret = do_req(s->flush_fd, (SheepdogReq *)&hdr, NULL, &wlen, &rlen);
     if (ret) {
         error_report("failed to send a request to the sheep");
         return ret;