summaryrefslogtreecommitdiffstats
path: root/nbd.c
Commit message (Collapse)AuthorAgeFilesLines
...
* 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>
* qemu-nbd: remove data_size argument to nbd_tripPaolo Bonzini2011-12-221-3/+3
| | | | | | The size of the buffer is in practice part of the protocol. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: remove offset argument to nbd_tripPaolo Bonzini2011-12-221-5/+3
| | | | | | The argument is write-only. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* Update ioctl order in nbd_init() to detect EBUSYChunyan Liu2011-12-221-18/+9
| | | | | | | | | | | | | | | Update ioctl(s) in nbd_init() to detect device busy early. Current nbd_init() issues NBD_CLEAR_SOCKET before NBD_SET_SOCKET, if issuing "qemu-nbd -c /dev/nbd0 disk.img" twice, the second time won't detect EBUSY in nbd_init(), but in nbd_client will report EBUSY and do clear socket (the 1st time command will be affacted too because of no socket any more.) No change to previous version. Signed-off-by: Chunyan Liu <cyliu@suse.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: add support for NBD_CMD_TRIMPaolo Bonzini2011-12-221-2/+13
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: add support for NBD_CMD_FLUSHPaolo Bonzini2011-12-221-1/+14
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: add support for NBD_CMD_FLAG_FUAPaolo Bonzini2011-12-221-2/+11
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: fix error handling in the serverPaolo Bonzini2011-12-221-9/+12
| | | | | | bdrv_read and bdrv_write return negative errno values, not -1. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: switch to asynchronous operationPaolo Bonzini2011-12-221-0/+8
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* fix spelling in main directoryDong Xu Wang2011-12-021-2/+2
| | | | | Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* nbd: treat EPIPE from NBD_DO_IT as successPaolo Bonzini2011-11-111-0/+7
| | | | | | | | This can be seen with "qemu-nbd -v -c", which returns 1 instead of 0 when you disconnect with "qemu-nbd -d". Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: fix non-Linux build failurePaolo Bonzini2011-09-211-1/+1
| | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: support NBD_SET_FLAGS ioctlPaolo Bonzini2011-09-191-0/+8
| | | | | | | | | The nbd kernel module cannot enable DISCARD requests unless it is informed about it. The flags field in the header is used for this, and this patch adds support for it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: sync API definitions with upstreamPaolo Bonzini2011-09-191-0/+2
| | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: support feature negotiationPaolo Bonzini2011-09-191-7/+25
| | | | | | | | | nbd supports writing flags in bytes 24...27 of the header, and uses that for the read-only flag. Add support for it in qemu-nbd. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: Clean up use of block_int.hMarkus Armbruster2011-09-121-0/+1
| | | | | Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Wrap recv to avoid warningsBlue Swirl2011-07-251-1/+1
| | | | | | | | | | | | | Avoid warnings like these by wrapping recv(): CC slirp/ip_icmp.o /src/qemu/slirp/ip_icmp.c: In function 'icmp_receive': /src/qemu/slirp/ip_icmp.c:418:5: error: passing argument 2 of 'recv' from incompatible pointer type [-Werror] /usr/local/lib/gcc/i686-mingw32msvc/4.6.0/../../../../i686-mingw32msvc/include/winsock2.h:547:32: note: expected 'char *' but argument is of type 'struct icmp *' Remove also casts used to avoid warnings. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* NBD: Use qemu_socket functions to open TCP and UNIX socketsNick Thomas2011-04-071-129/+29
| | | | | | | | | | | | | | | | | | This commit has the side-effect of making the qemu-nbd binary capable of binding to IPv6 addresses. ("-b ::1", for instance). block/nbd.c fails to parse IPv6 IP addresses correctly at this point, but will work over IPv6 when given a hostname. It still works over IPv4 as before. We move the qemu-sockets object from the 'common' to the 'block' list in the Makefile. The common list includes the block list, so this is effectively a no-op for the rest of the code. We also add 32-bit 'magic' attributes to nbd_(request|reply) to facilitate calculating maximum request/response sizes later. Signed-off-by: Nick Thomas <nick@bytemark.co.uk> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* NBD library: whitespace changesNick Thomas2011-04-071-417/+418
| | | | | Signed-off-by: Nick Thomas <nick@bytemark.co.uk> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: Haiku has _IO() in its BSD compatibility layerAndreas Färber2010-10-031-1/+1
| | | | | Signed-off-by: Andreas Färber <andreas.faerber@web.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Improve qemu-nbd performance by 4400 %Laurent Vivier2010-09-211-7/+18
| | | | | | | | | | | | | | | This patch allows to reduce the boot time from an NBD server from 225 seconds to 5 seconds (time between the "boot cd:0" and the kernel init) for the following command lines: ./qemu-nbd -t ../ISO/debian-500-powerpc-netinst.iso and ./ppc-softmmu/qemu-system-ppc -cdrom nbd:localhost:1024 This patch combines the reply header and payload send operation. Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Merge remote branch 'kwolf/for-anthony' into stagingAnthony Liguori2010-09-081-12/+106
|\
| * nbd: Introduce NBD named exports.Laurent Vivier2010-08-301-12/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch allows to connect Qemu using NBD protocol to an nbd-server using named exports. For instance, if on the host "isoserver", in /etc/nbd-server/config, you have: [generic] [debian-500-ppc-netinst] exportname = /ISO/debian-500-powerpc-netinst.iso [Fedora-10-ppc-netinst] exportname = /ISO/Fedora-10-ppc-netinst.iso You can connect to it, using: qemu -cdrom nbd:isoserver:exportname=debian-500-ppc-netinst qemu -cdrom nbd:isoserver:exportname=Fedora-10-ppc-netinst NOTE: you need at least nbd-server 2.9.18 Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* | Remove unused argument for nbd_client()Jes Sorensen2010-09-041-2/+2
|/ | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Fix %lld or %llx printf format useBlue Swirl2010-05-221-2/+1
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Update to a hopefully more future proof FSF addressBlue Swirl2009-07-161-2/+1
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
OpenPOWER on IntegriCloud