[Libguestfs] [nbdkit PATCH 6/6] Add --threads option for supporting true parallel requests

2017-11-16 Thread Eric Blake
It's finally time to implement one of the TODO items: we want to support a thread pool of parallel readers from the client, in order to allow multiple in-flight operations with potential out-of-order completion. We also need at least one plugin that supports parallel processing for testing the opt

[Libguestfs] [nbdkit PATCH 4/6] connections: Add thread-safe status indicator

2017-11-16 Thread Eric Blake
Once we have multiple threads during parallel processing, we need to be sure that any I/O error flagged by one thread prevents the next thread from attempting I/O. Although we already have a separate lock for reads and writes, it's easier if status is shared by both actions, which needs yet anothe

[Libguestfs] [RFC nbdkit PATCH 0/6] Enable full parallel request handling

2017-11-16 Thread Eric Blake
I want to make my nbd forwarding plugin fully parallel - but to do that, I first need to make nbdkit itself fully parallel ;) With this series, I was finally able to demonstrate out-of-order responses when using qemu-io (which is great at sending back-to-back requests prior to waiting for response

[Libguestfs] [RFC nbdkit PATCH 5/6] connections: Set up thread pool for handling client requests

2017-11-16 Thread Eric Blake
Finish plumbing up everything we will need to process multiple client requests in parallel after handshake is complete. Since status is now global, and properly protected by a mutex, all of the threads will eventually quit as soon as any of them notices EOF or nbdkit detects a signal. For ease of

[Libguestfs] [nbdkit PATCH 3/6] connections: Add read/write lock over client I/O

2017-11-16 Thread Eric Blake
In preparation for parallel processing, we need to be sure that two threads belonging to the same connection cannot interleave their I/O except at message boundaries. Add a mutex around all reads and writes that must occur as a group (for now, there is no contention for either mutex). Signed-off-

[Libguestfs] [nbdkit PATCH 2/6] connections: Avoid plugin when shutdown is imminent

2017-11-16 Thread Eric Blake
If nbdkit receives SIGINT while we are reading from the client, it's better to avoid calling into the plugin for any work that will further stall our response to the signal, and instead just immediately give the client an ESHUTDOWN error. Signed-off-by: Eric Blake --- src/connections.c | 11

[Libguestfs] [nbdkit PATCH 1/6] connections: Simplify handle_request()

2017-11-16 Thread Eric Blake
_handle_request() was never returning anything but 0; and had to communicate the error value through a parameter by reference. As there is no return value that a plugin can use to declare the connection useless, we can consolidate this into just returning the error value. Meanwhile, we don't need

[Libguestfs] [nbdkit PATCH 4/4] sockets: Fix lifetime of thread_data

2017-11-16 Thread Eric Blake
It is never a wise idea to pass stack-allocated storage to another thread during pthread_create() unless you can guarantee that the new thread will complete prior to the calling thread returning and ending the lifetime of that storage. We were violating this, with the result in a SEGV in the detac

[Libguestfs] [nbdkit PATCH 0/4] thread-safety issues prior to parallel handling

2017-11-16 Thread Eric Blake
These patches should be ready to go in now; I will also post my work-in-progress for enabling full parallel handling that depends on these, but with that series, I was still getting crashes or hangs with test-socket-activation (I think I've nailed all the crashes I've seen, but the hang is rather i

[Libguestfs] [nbdkit PATCH 3/4] plugins: Make plugin_name() reliable past unload

2017-11-16 Thread Eric Blake
Directly returning storage in the module is risky, because it forces callers to strdup() if they aren't sure of the lifetime. Copying into the heap up front means that plugin_name() can now be safely used even if unload happens in the meantime. As long as we have only a single plugin in static sto

[Libguestfs] [nbdkit PATCH 2/4] threadlocal: Copy thread name

2017-11-16 Thread Eric Blake
We can't guarantee what storage duration the caller's request for a thread name has; and in fact, if the caller uses plugin_name() for their thread name, then the moment .unload is called, our threadlocal storage is pointing to la-la-land and we get a nice SEGV while trying to print any debug messa

[Libguestfs] [nbdkit PATCH 1/4] errors: Avoid interleaved errors from parallel threads

2017-11-16 Thread Eric Blake
Since we construct our error/debug messages via multiple calls to stdio primitives, we are at risk of multiple threads interleaving their output if they try to output at once. Add a mutex to group related outputs into an atomic chunk. Signed-off-by: Eric Blake --- src/errors.c | 30

Re: [Libguestfs] [nbdkit PATCH v2 0/2] add nbd plugin

2017-11-16 Thread Eric Blake
On 11/16/2017 05:53 AM, Richard W.M. Jones wrote: > > ACK series, with one minor change: > > Please add a reference to the new manual page in the ‘SEE ALSO’ > section at the bottom of the following two files: > > docs/nbdkit.pod This one is obvious; I also added: diff --git i/docs/nbdkit.pod

Re: [Libguestfs] [PATCH 0/3] Alternate way to avoid race conditions when nbdkit exits.

2017-11-16 Thread Eric Blake
On 11/14/2017 11:30 AM, Richard W.M. Jones wrote: > This fixes the race conditions for me, using the test described here: > > https://www.redhat.com/archives/libguestfs/2017-September/msg00226.html Running test-socket-activation in a loop, I've hit other races (some provoked a bit more easily wit

Re: [Libguestfs] [Qemu-devel] Effect of qemu-img convert -m and -W options

2017-11-16 Thread Stefan Hajnoczi
On Thu, Nov 16, 2017 at 3:10 PM, Richard W.M. Jones wrote: > On Thu, Nov 16, 2017 at 02:47:46PM +, Stefan Hajnoczi wrote: >> The threads you observed are the thread pool that performs >> preadv(2)/pwritev(2) syscalls. The Linux AIO API could be used instead >> and does not use threads for rea

Re: [Libguestfs] [Qemu-devel] Effect of qemu-img convert -m and -W options

2017-11-16 Thread Stefan Hajnoczi
On Thu, Nov 16, 2017 at 3:12 PM, Richard W.M. Jones wrote: > On Thu, Nov 16, 2017 at 03:51:29PM +0100, Peter Lieven wrote: >> Afaik all writes to the same QCOW2 serialize because of the s->lock that >> is held during the write. So its not suprising that there is no benefit from >> mutliple threads

Re: [Libguestfs] [Qemu-devel] Effect of qemu-img convert -m and -W options

2017-11-16 Thread Richard W.M. Jones
On Thu, Nov 16, 2017 at 05:30:48PM +, Stefan Hajnoczi wrote: > On Thu, Nov 16, 2017 at 3:10 PM, Richard W.M. Jones wrote: > > Both local filesystems, but on different SATA devices. > > Okay. I'm curious what the strace -f output looks like (only the > preadv(2)/pwritev(2) syscalls are intere

Re: [Libguestfs] [nbdkit PATCH] maint: Rebuild nbdkit if nbdkit.in changes

2017-11-16 Thread Eric Blake
On 11/16/2017 05:49 AM, Richard W.M. Jones wrote: > On Wed, Nov 15, 2017 at 10:50:06AM -0600, Eric Blake wrote: >> Tell automake that we want ./nbdkit to be kept up-to-date in the >> developer's tree. Otherwise, after touching nbdkit.in, you would >> have to remember to manually run 'make nbdkit'.

Re: [Libguestfs] [Qemu-devel] Effect of qemu-img convert -m and -W options

2017-11-16 Thread Richard W.M. Jones
On Thu, Nov 16, 2017 at 02:47:46PM +, Stefan Hajnoczi wrote: > The threads you observed are the thread pool that performs > preadv(2)/pwritev(2) syscalls. The Linux AIO API could be used instead > and does not use threads for read and write operations. I guess if I used AIO then I wouldn't ge

Re: [Libguestfs] [Qemu-devel] Effect of qemu-img convert -m and -W options

2017-11-16 Thread Richard W.M. Jones
On Thu, Nov 16, 2017 at 03:51:29PM +0100, Peter Lieven wrote: > Afaik all writes to the same QCOW2 serialize because of the s->lock that > is held during the write. So its not suprising that there is no benefit from > mutliple threads as long as reading from the RAW file involves no delay. > Which

Re: [Libguestfs] [Qemu-devel] Effect of qemu-img convert -m and -W options

2017-11-16 Thread Stefan Hajnoczi
On Wed, Nov 15, 2017 at 11:52:46AM +, Richard W.M. Jones wrote: > [CC to qemu-devel since I'm obviously doing something wrong here, > I'm just not sure what.] > > I was getting ready to add multiple threads to ‘qemu-img convert’ (the > longest part of v2v conversions) when I noticed that it ha

Re: [Libguestfs] [Qemu-devel] Effect of qemu-img convert -m and -W options

2017-11-16 Thread Peter Lieven
Am 16.11.2017 um 15:47 schrieb Stefan Hajnoczi: On Wed, Nov 15, 2017 at 11:52:46AM +, Richard W.M. Jones wrote: [CC to qemu-devel since I'm obviously doing something wrong here, I'm just not sure what.] I was getting ready to add multiple threads to ‘qemu-img convert’ (the longest part of v

Re: [Libguestfs] [nbdkit PATCH v2 0/2] add nbd plugin

2017-11-16 Thread Eric Blake
On 11/16/2017 05:53 AM, Richard W.M. Jones wrote: > > ACK series, with one minor change: > > Please add a reference to the new manual page in the ‘SEE ALSO’ > section at the bottom of the following two files: > > docs/nbdkit.pod > docs/nbdkit-plugin.pod > > It should be pretty clear what to

Re: [Libguestfs] [nbdkit PATCH v2 2/2] nbd: Split reading into separate thread

2017-11-16 Thread Eric Blake
On 11/14/2017 01:23 PM, Eric Blake wrote: > In preparation for allowing interleaved response, refactor the > nbd forwarder so that writes are still done from the thread > handling the original request from the client, but all reads are > done by a dedicated reader thread. Control between the two >

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Max Reitz
On 2017-11-16 11:08, Gandalf Corvotempesta wrote: > 2017-11-15 23:55 GMT+01:00 Max Reitz : >> https://xanclic.moe/convert-xva.rb -- does this work? >> (It seems to works on the two example images I found...) >> >> An example is in the code, you use it like this: >> >> $ ./convert-xva.rb ~/Downloads

Re: [Libguestfs] [nbdkit PATCH v2 1/2] nbd: Add new nbd forwarding plugin

2017-11-16 Thread Eric Blake
On 11/14/2017 01:23 PM, Eric Blake wrote: > This is a minimal implementation of an NBD forwarder; it lets us > convert between old and newstyle connections (great if a client > expects one style but the real server only provides the other), > or add TLS safety on top of a server without having to r

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Richard W.M. Jones
I think it's even possible to modify that shell script to pipe into nbdkit and from there to ‘qemu-img convert’. I'm too lazy to actually do that right now, but the basic idea is here: https://rwmj.wordpress.com/2014/10/14/streaming-nbd-server/ You'll probably have to add ‘-m 1’ to the qemu-im

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Tomáš Golembiovský
On Thu, 16 Nov 2017 13:56:16 +0100 Tomáš Golembiovský wrote: > On Wed, 15 Nov 2017 21:41:20 +0100 > Gandalf Corvotempesta wrote: > > > 2017-11-15 21:29 GMT+01:00 Richard W.M. Jones : > > > Gandalf, is there an XVA file publically available (pref. not > > > too big) that we can look at? > >

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Tomáš Golembiovský
On Wed, 15 Nov 2017 21:41:20 +0100 Gandalf Corvotempesta wrote: > 2017-11-15 21:29 GMT+01:00 Richard W.M. Jones : > > Gandalf, is there an XVA file publically available (pref. not > > too big) that we can look at? > > I can try to provide one, but it's simple: > > # tar tvf 20160630_124823_aa72

Re: [Libguestfs] [PATCH v2 1/2] lib: command: If command fails, exit with 126 or 127 as defined by POSIX.

2017-11-16 Thread Pino Toscano
On Friday, 6 October 2017 15:52:16 CET Richard W.M. Jones wrote: > If running the external command fails in "argv mode" (ie. when > not using the shell), then exit with either 126 or 127 as defined > by POSIX. > > This is mostly the same as what bash does, see > execute_cmd.c:shell_execve in the b

Re: [Libguestfs] [PATCH 2/2] common/mlstdutils: Add with_openfile function.

2017-11-16 Thread Pino Toscano
On Sunday, 5 November 2017 20:42:41 CET Richard W.M. Jones wrote: > This safe wrapper around Unix.openfile ensures that exceptions > escaping cannot leave unclosed files. > > There are only a few places in the code where this wrapper can be used > currently. There are other occurences of Unix.ope

Re: [Libguestfs] [PATCH 1/2] common/mlstdutils: Add with_open_in and with_open_out functions.

2017-11-16 Thread Pino Toscano
On Sunday, 5 November 2017 20:42:40 CET Richard W.M. Jones wrote: > These safe wrappers around Pervasives.open_in and Pervasives.open_out > ensure that exceptions escaping cannot leave unclosed files. > --- Mostly LGTM, just one note/improvement. > diff --git a/v2v/input_libvirt_vddk.ml b/v2v/inp

Re: [Libguestfs] [nbdkit PATCH v2 0/2] add nbd plugin

2017-11-16 Thread Richard W.M. Jones
ACK series, with one minor change: Please add a reference to the new manual page in the ‘SEE ALSO’ section at the bottom of the following two files: docs/nbdkit.pod docs/nbdkit-plugin.pod It should be pretty clear what to change if you look at those files. Thanks, Rich. -- Richard Jones

Re: [Libguestfs] [nbdkit PATCH] maint: Rebuild nbdkit if nbdkit.in changes

2017-11-16 Thread Richard W.M. Jones
On Wed, Nov 15, 2017 at 10:50:06AM -0600, Eric Blake wrote: > Tell automake that we want ./nbdkit to be kept up-to-date in the > developer's tree. Otherwise, after touching nbdkit.in, you would > have to remember to manually run 'make nbdkit'. > > Signed-off-by: Eric Blake > --- > Makefile.am |

Re: [Libguestfs] [nbdkit PATCH] connections: Extract common export flag computation code

2017-11-16 Thread Richard W.M. Jones
On Wed, Nov 15, 2017 at 04:52:37PM -0600, Eric Blake wrote: > No need to duplicate maintenance of export flag computation between > old and new style handshakes. > > Signed-off-by: Eric Blake > --- > src/connections.c | 120 > +- > 1 file chan

Re: [Libguestfs] [nbdkit PATCH] connections: Improve error responses

2017-11-16 Thread Richard W.M. Jones
On Wed, Nov 15, 2017 at 04:16:49PM -0600, Eric Blake wrote: > We had several inconsistencies from the NBD spec when diagnosing > bad client messages: > - FLUSH is not generally forbidden on a read-only export (so failing > with EPERM is wrong) [meanwhile, if we don't advertise flush because > plugi

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Richard W.M. Jones
On Thu, Nov 16, 2017 at 11:07:10AM +0100, Gandalf Corvotempesta wrote: > 2017-11-16 11:01 GMT+01:00 Richard W.M. Jones : > > As mentioned before you can use this to do a qemu-img convert using > > captive nbdkit: > > > > $ nbdkit -U - \ > > perl script=./xva-reader.pl file=./debian8cloud.xv

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Gandalf Corvotempesta
2017-11-15 23:55 GMT+01:00 Max Reitz : > https://xanclic.moe/convert-xva.rb -- does this work? > (It seems to works on the two example images I found...) > > An example is in the code, you use it like this: > > $ ./convert-xva.rb ~/Downloads/stats-appliance-2.36.020502.xva Ref:73 It doesn't work

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Gandalf Corvotempesta
2017-11-16 11:01 GMT+01:00 Richard W.M. Jones : > As mentioned before you can use this to do a qemu-img convert using > captive nbdkit: > > $ nbdkit -U - \ > perl script=./xva-reader.pl file=./debian8cloud.xva size=4294967296 \ > --run 'qemu-img convert -f raw $nbd -O qcow2 /var/tmp/o

Re: [Libguestfs] [Qemu-devel] [qemu-img] support for XVA

2017-11-16 Thread Richard W.M. Jones
Here's my solution, as a nbdkit plugin written in Perl. As with Max's solution I don't bother to parse the virtual size out of the XML file, so you need to specify that on the command line otherwise the disk will be truncated to the largest extent stored in the file. Also the ‘.xva’ file must not