Re: [libvirt] [PATCH v2 15/21] utils: Write a maximum of MAX_PIPE_FEED_BYTES into a pipe
On 7/10/19 4:07 PM, Marc-André Lureau wrote: On Wed, Jul 10, 2019 at 10:12 PM Stefan Berger wrote: To avoid blocking on a write on a pipe that the receiving process does not read from, write only MAX_PIPE_FEED_BYTES into the pipe so that we can serve other pipes as well. why not simply use non-blocking write? I had thought I would use non-blocking write, but... If we now have a large buffer and a pipe with less capacity and O_NONBLOCK is set, would we ever be able to make write progress or always get EAGAIN or EWOULDBLOCK? Probably what we would need is O_NONBLOCK combined with a small amount of bytes to write, like in this patch. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 15/21] utils: Write a maximum of MAX_PIPE_FEED_BYTES into a pipe
On Wed, Jul 10, 2019 at 10:12 PM Stefan Berger wrote: > > To avoid blocking on a write on a pipe that the receiving process > does not read from, write only MAX_PIPE_FEED_BYTES into the pipe > so that we can serve other pipes as well. why not simply use non-blocking write? > > Signed-off-by: Stefan Berger > --- > src/util/vircommand.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/src/util/vircommand.c b/src/util/vircommand.c > index 898ee0df45..0e367eeeab 100644 > --- a/src/util/vircommand.c > +++ b/src/util/vircommand.c > @@ -86,6 +86,8 @@ struct _virCommandSendBuffer { > size_t buflen; > off_t offset; > }; > +/* max. number of bytes we write to pipe to avoid blocking on it */ > +#define MAX_PIPE_FEED_BYTES 1024 > > struct _virCommand { > int has_error; /* ENOMEM on allocation failure, -1 for anything else. */ > @@ -2237,7 +2239,7 @@ virCommandProcessIO(virCommandPtr cmd) > int done; > > done = write(cmd->inpipe, cmd->inbuf + inoff, > - inlen - inoff); > + MIN(inlen - inoff, MAX_PIPE_FEED_BYTES)); > if (done < 0) { > if (errno == EPIPE) { > VIR_DEBUG("child closed stdin early, ignoring EPIPE " > -- > 2.20.1 > -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 15/21] utils: Write a maximum of MAX_PIPE_FEED_BYTES into a pipe
To avoid blocking on a write on a pipe that the receiving process does not read from, write only MAX_PIPE_FEED_BYTES into the pipe so that we can serve other pipes as well. Signed-off-by: Stefan Berger --- src/util/vircommand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 898ee0df45..0e367eeeab 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -86,6 +86,8 @@ struct _virCommandSendBuffer { size_t buflen; off_t offset; }; +/* max. number of bytes we write to pipe to avoid blocking on it */ +#define MAX_PIPE_FEED_BYTES 1024 struct _virCommand { int has_error; /* ENOMEM on allocation failure, -1 for anything else. */ @@ -2237,7 +2239,7 @@ virCommandProcessIO(virCommandPtr cmd) int done; done = write(cmd->inpipe, cmd->inbuf + inoff, - inlen - inoff); + MIN(inlen - inoff, MAX_PIPE_FEED_BYTES)); if (done < 0) { if (errno == EPIPE) { VIR_DEBUG("child closed stdin early, ignoring EPIPE " -- 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list