summaryrefslogtreecommitdiffstats
path: root/nbd.c
Commit message (Collapse)AuthorAgeFilesLines
* nbd: Miscellaneous typo fixes.Hani Benhabiles2014-05-241-1/+1
| | | | | | | Signed-off-by: Hani Benhabiles <hani@linux.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
* nbd: move socket wrappers to qemu-nbdPaolo Bonzini2014-02-211-50/+0
| | | | | | | | | qemu-nbd is one of the few valid users of qerror_report_err. Move the error-reporting socket wrappers there. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: inline tcp_socket_incoming_spec into sole callerPaolo Bonzini2014-02-211-6/+2
| | | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: correctly propagate errorsPaolo Bonzini2014-02-211-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | Before: $ ./qemu-io-old qemu-io-old> open -r -o file.driver=nbd one of path and host must be specified. qemu-io-old: can't open device (null): Could not open image: Invalid argument $ ./qemu-io-old qemu-io-old> open -r -o file.driver=nbd,file.host=foo,file.path=bar path and host may not be used at the same time. qemu-io-old: can't open device (null): Could not open image: Invalid argument After: $ ./qemu-io qemu-io> open -r -o file.driver=nbd qemu-io: can't open device (null): one of path and host must be specified. $ ./qemu-io qemu-io> open -r -o file.driver=nbd,file.host=foo,file.path=bar qemu-io: can't open device (null): path and host may not be used at the same time. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: don't change socket block during negotiateMarc-André Lureau2013-12-161-2/+0
| | | | | | | | | The caller might handle non-blocking using coroutine. Leave the choice to the caller to use a blocking or non-blocking negotiate. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
* nbd: use BlockDriverState refcntFam Zheng2013-09-061-0/+5
| | | | | | | | | Previously, nbd calls drive_get_ref() on the drive of bs. A BDS doesn't always have associated dinfo, which nbd doesn't care either. We already have BDS ref count, so use it to make it safe for a BDS w/o blockdev. Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* aio / timers: Untangle include filesAlex Bligh2013-08-221-0/+1
| | | | | | | | | | include/qemu/timer.h has no need to include main-loop.h and doing so causes an issue for the next patch. Unfortunately various files assume including timers.h will pull in main-loop.h. Untangle this mess. Signed-off-by: Alex Bligh <alex@alex.org.uk> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* nbd: support large NBD requestsStefan Hajnoczi2013-05-031-6/+11
| | | | | | | | | | | | | | | | | | | | | | | The Linux nbd driver recently increased the maximum supported request size up to 32 MB: commit 078be02b80359a541928c899c2631f39628f56df Author: Michal Belczyk <belczyk@bsd.krakow.pl> Date: Tue Apr 30 15:28:28 2013 -0700 nbd: increase default and max request sizes Raise the default max request size for nbd to 128KB (from 127KB) to get it 4KB aligned. This patch also allows the max request size to be increased (via /sys/block/nbd<x>/queue/max_sectors_kb) to 32MB. QEMU's 1 MB buffers are too small to handle these requests. This patch allocates data buffers dynamically and allows up to 32 MB per request. Reported-by: Nick Thomas <nick@bytemark.co.uk> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* nbd: use g_slice_new() instead of a freelistStefan Hajnoczi2013-05-031-17/+6
| | | | | | | | | | Use GLib's efficient slice allocator instead of open-coding the request freelist. This patch simplifies the NBDRequest code. Now we qemu_blockalign() the req->data buffer each time but the next patch switches from a fixed size buffer to a dynamic size anyway. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* oslib-posix: rename socket_set_nonblock() to qemu_set_nonblock()Stefan Hajnoczi2013-04-021-4/+4
| | | | | | | | | The fcntl(fd, F_SETFL, O_NONBLOCK) flag is not specific to sockets. Rename to qemu_set_nonblock() just like qemu_set_cloexec(). Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
* nbd: Remove unused functionsKevin Wolf2013-03-221-19/+0
| | | | | Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
* nbd: Keep hostname and port separateKevin Wolf2013-03-221-0/+12
| | | | | | | | | | | | | | | The NBD block supports an URL syntax, for which a URL parser returns separate hostname and port fields. It also supports the traditional qemu syntax encoded in a filename. Until now, after parsing the URL to get each piece of information, a new string is built to be fed to socket functions. Instead of building a string in the URL case that is immediately parsed again, parse the string in both cases and use the QemuOpts interface to qemu-sockets.c. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
* misc: move include files to include/qemu/Paolo Bonzini2012-12-191-2/+2
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* block: move include files to include/block/Paolo Bonzini2012-12-191-3/+3
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: fix use of two uninitialized bytes when connecting to a named exportPaolo Bonzini2012-11-281-1/+1
| | | | | Reported-by: Michal Privoznik <mprivoznik@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: fixes to read-only handlingPaolo Bonzini2012-11-131-13/+12
| | | | | | | | | We do not need BLKROSET if the kernel supports setting flags. Also, always do BLKROSET even for a read-write export, otherwise the read-only state remains "sticky" after the invocation of "qemu-nbd -r". Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: ask and print error information from qemu-socketsPaolo Bonzini2012-10-231-8/+31
| | | | | | | | | | | | | | | | Before: $ qemu-system-x86_64 nbd:localhost:12345 inet_connect_opts: connect(ipv4,yakj.usersys.redhat.com,127.0.0.1,12345): Connection refused qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused After: $ x86_64-softmmu/qemu-system-x86_64 nbd:localhost:12345 qemu-system-x86_64: Failed to connect to socket: Connection refused qemu-system-x86_64: could not open disk image nbd:localhost:12345: Connection refused Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-sockets: add Error ** to all functionsPaolo Bonzini2012-10-231-2/+2
| | | | | | | | This lets me adjust the clients to do proper error propagation first, thus avoiding temporary regressions in the quality of the error messages. Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* Separate inet_connect into inet_connect (blocking) and inet_nonblocking_connectOrit Wasserman2012-09-251-1/+1
| | | | | | | | No need to add non blocking parameters to the blocking inet_connect add block parameter for inet_connect_opts instead of using QemuOpt "block". Signed-off-by: Orit Wasserman <owasserm@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* nbd: add nbd_export_get_blockdevPaolo Bonzini2012-09-191-1/+6
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: negotiate with named exportsPaolo Bonzini2012-09-191-19/+150
| | | | | | | | | Allow negotiation to receive the name of the requested export from the client. Passing a NULL export to nbd_client_new will cause the server to send the extended negotiation header. The exp field is then filled during negotiation. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: register named exportsPaolo Bonzini2012-09-191-0/+49
| | | | | | Add an API to register and find named exports. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: add notification for closing an NBDExportPaolo Bonzini2012-09-191-1/+9
| | | | | | | | In order to exit cleanly from qemu-nbd, add a callback that triggers when an NBDExport is closed. In the case of qemu-nbd it will exit the main loop. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: track clients into NBDExportPaolo Bonzini2012-09-191-2/+11
| | | | | | | Track the NBDClients of each NBDExport, and use it to implement nbd_export_close. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: add reference counting to NBDExportPaolo Bonzini2012-09-191-6/+31
| | | | | | | We will use a similar two-phase destruction for NBDExport, so we need each NBDClient to add a reference to NBDExport. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: do not leak nbd_trip coroutines when a connection is torn downPaolo Bonzini2012-09-191-6/+27
| | | | | | | | | | | | | | | | Because nbd_client_close removes the I/O handlers for the client socket, there is no way that any suspended coroutines are restarted. This will be a problem with the QEMU embedded NBD server, because we will have a QMP command to forcibly close all connections with the clients. Instead, we can exploit the reference counting of NBDClients; shutdown the client socket, which will make it readable and writeable. Also call the close callback, which will release the user's reference. The coroutines then will fail and exit cleanly, and release all remaining references, until the last refcount finally triggers the closure of the client. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: make refcount interface publicPaolo Bonzini2012-09-191-2/+2
| | | | | | | After the next patch, the close callback will have to release its reference. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: do not close BlockDriverState in nbd_export_closePaolo Bonzini2012-09-191-1/+0
| | | | | | | This is not desirable when embedding the NBD server inside QEMU. Move the bdrv_close to qemu-nbd. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: pass NBDClient to nbd_send_negotiatePaolo Bonzini2012-09-191-37/+41
| | | | | | | We will need the NBDClient in nbd_send_negotiate to store the export requested by the client. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: add more constantsPaolo Bonzini2012-09-181-7/+10
| | | | | | | Avoid magic numbers and magic size computations; hide them behind constants. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* net: inet_connect(), inet_connect_opts(): add in_progress argumentLuiz Capitulino2012-08-131-1/+1
| | | | | | | | | | | | It's used to indicate the special case where a valid file-descriptor is returned (ie. success) but the connection can't be completed w/o blocking. This is needed because QERR_SOCKET_CONNECT_IN_PROGRESS is not treated like an error and a future commit will drop it. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com>
* sockets: use error class to pass listen errorAmos Kong2012-05-101-1/+1
| | | | | | | | | | | | Add a new argument in inet_listen()/inet_listen_opts() to pass back listen error. Change nbd, qemu-char, vnc to use new interface. Signed-off-by: Amos Kong <akong@redhat.com> Reviewed-by: Orit Wasserman <owasserm@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* sockets: change inet_connect() to support nonblock socketAmos Kong2012-05-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | Add a bool argument to inet_connect() to assign if set socket to block/nonblock, and delete original argument 'socktype' that is unused. Add a new argument to inet_connect()/inet_connect_opts(), to pass back connect error by error class. Retry to connect when -EINTR is got. Connect's successful for nonblock socket when following errors are got, user should wait for connecting by select(): -EINPROGRESS -EWOULDBLOCK (win32) -WSAEALREADY (win32) Change nbd, vnc to use new interface. Signed-off-by: Amos Kong <akong@redhat.com> Reviewed-by: Orit Wasserman <owasserm@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* nbd: obey FUA on readsPaolo Bonzini2012-04-191-0/+9
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: do not include block_int.hPaolo Bonzini2012-04-191-2/+1
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: do not block in nbd_wr_sync if no data at all is availablePaolo Bonzini2012-04-191-6/+34
| | | | | | | | | | | | Right now, nbd_wr_sync will hang if no data at all is available on the socket and the other side is not going to provide any. Relax this by making it loop only for writes or partial reads. This fixes a race where one thread is executing qemu_aio_wait() and another is executing main_loop_wait(). Then, the select() call in main_loop_wait() can return stale data and call the "readable" callback with no data in the socket. Reported-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: consistently return negative errno valuesPaolo Bonzini2012-04-191-81/+78
| | | | | | | | In the next patch we need to look at the return code of nbd_wr_sync. To avoid percolating the socket_error() ugliness all around, let's handle errors by returning negative errno values. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: consistently check for <0 or >=0Paolo Bonzini2012-04-191-23/+25
| | | | | | | This prepares for the following patch, which changes -1 return values to negative errno. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: consistently use ssize_tPaolo Bonzini2012-04-191-12/+10
| | | | | | | | | GCC (pedantically, but correctly) considers that a negative ssize_t may become positive when casted to int. This may cause uninitialized variable warnings when a function returns such a negative ssize_t and is inlined. Propagate ssize_t return types to avoid this. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Fix compiler warning (w64)Stefan Weil2012-04-151-1/+1
| | | | | | Portable printing of dev_offset (data type off_t) needs a type cast. Signed-off-by: Stefan Weil <sw@weilnetz.de>
* qemu-nbd: throttle requestsPaolo Bonzini2011-12-221-3/+22
| | | | | | | | | | Limiting the number of in-flight requests is implemented very simply with a can_read callback. It does not require a semaphore, unlike the client side in block/nbd.c, because we can throttle directly the creation of coroutines. The client side can have a coroutine created at any time when an I/O request is made. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: asynchronous operationPaolo Bonzini2011-12-221-21/+53
| | | | | | | | | | | | | | | Using coroutines enable asynchronous operation on both the network and the block side. Network can be owned by two coroutines at the same time, one writing and one reading. On the send side, mutual exclusion is guaranteed by a CoMutex. On the receive side, mutual exclusion is guaranteed because new coroutines immediately start receiving data, and no new coroutines are created as long as the previous one is receiving. Between receive and send, qemu-nbd can have an arbitrary number of in-flight block transfers. Throttling is implemented by the next patch. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: add client pointer to NBDRequestPaolo Bonzini2011-12-221-21/+27
| | | | | | | | | | | By attaching a client to an NBDRequest, we can avoid passing around the socket descriptor and data buffer. Also, we can now manage the reference count for the client in nbd_request_get/put request instead of having to do it ourselved in nbd_read. This simplifies things when coroutines are used. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: move client handling to nbd.cPaolo Bonzini2011-12-221-3/+59
| | | | | | | | | This patch sets up the fd handler in nbd.c instead of qemu-nbd.c. It introduces NBDClient, which wraps the arguments to nbd_trip in a single structure, so that we can add a notifier to it. This way, qemu-nbd can know about disconnections. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: introduce NBDRequestPaolo Bonzini2011-12-221-14/+51
| | | | | | | | Move the buffer from NBDExport to a new structure, so that it will be possible to have multiple in-flight requests for the same export (and for the same client too---we get that for free). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: introduce NBDExportPaolo Bonzini2011-12-221-16/+48
| | | | | | | Wrap the common parameters of nbd_trip and nbd_negotiate in a single opaque struct. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: introduce nbd_do_receive_requestPaolo Bonzini2011-12-221-21/+47
| | | | | | Group the receiving of a response and the associated data into a new function. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: more robust handling of invalid requestsPaolo Bonzini2011-12-221-27/+30
| | | | | | | Fail invalid requests with EINVAL instead of dropping them into the void. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: introduce nbd_do_send_replyPaolo Bonzini2011-12-221-14/+32
| | | | | | | | | | | Group the sending of a reply and the associated data into a new function. Without corking, the caller would be forced to leave 12 free bytes at the beginning of the data pointer. Not too ugly, but still ugly. :) Using nbd_do_send_reply everywhere will help when the routine will set up the write handler that re-enters the send coroutine. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: simplify nbd_tripPaolo Bonzini2011-12-221-17/+8
| | | | | | | | | | Use TCP_CORK to remove a violation of encapsulation, that would later require nbd_trip to know too much about an NBD reply. We could also switch to sendmsg (qemu_co_sendv) later, it is even easier once coroutines are in. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
OpenPOWER on IntegriCloud