summaryrefslogtreecommitdiffstats
path: root/nbd.c
Commit message (Collapse)AuthorAgeFilesLines
* qemu-nbd: only send a limited number of errno codes on the wirePaolo Bonzini2015-05-081-0/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Right now, NBD includes potentially platform-specific error values in the wire protocol. Luckily, most common error values are more or less universal: in particular, of all errno values <= 34 (up to ERANGE), they are all the same on supported platforms except for 11 (which is EAGAIN on Windows and Linux, but EDEADLK on Darwin and the *BSDs). So, in order to guarantee some portability, only keep a handful of possible error codes and squash everything else to EINVAL. This patch defines a limited set of errno values that are valid for the NBD protocol, and specifies recommendations for what error to return in specific corner cases. The set of errno values is roughly based on the errors listed in the read(2) and write(2) man pages, with some exceptions: - ENOMEM is added for servers that implement copy-on-write or other formats that require dynamic allocation. - EDQUOT is not part of the universal set of errors; it can be changed to ENOSPC on the wire format. - EFBIG is part of the universal set of errors, but it is also changed to ENOSPC because it is pretty similar to ENOSPC or EDQUOT. Incoming values will in general match system errno values, but not on the Hurd which has different errno values (they have a "subsystem code" equal to 0x10 in bits 24-31). The Hurd is probably not something to which QEMU has been ported, but still do the right thing and reverse-map the NBD errno values to the system errno values. The corresponding patch to the NBD protocol description can be found at http://article.gmane.org/gmane.linux.drivers.nbd.general/3154. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd/trivial: fix type cast for ioctlBogdan Purcareata2015-04-281-1/+1
| | | | | | | | | | | | | | | This fixes ioctl behavior on powerpc e6500 platforms with 64bit kernel and 32bit userspace. The current type cast has no effect there and the value passed to the kernel is still 0. Probably an issue related to the compiler, since I'm assuming the same configuration works on a similar setup on x86. Also ensure consistency with previous type cast in TRACE message. Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com> Message-Id: <1428058914-32050-1-git-send-email-bogdan.purcareata@freescale.com> Cc: qemu-stable@nongnu.org [Fix parens as noticed by Michael. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Drop unexpected data for NBD_OPT_LISTMax Reitz2015-03-181-0/+23
| | | | | | | | | | When requesting the list of exports, no data should be sent. If data is sent, the NBD server should not just inform the client of the invalid request, but also drop the data. Signed-off-by: Max Reitz <mreitz@redhat.com> Message-Id: <1424887718-10800-22-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Fix interpretation of the export flagsMax Reitz2015-03-181-1/+1
| | | | | | | | | | | | The export flags are a 16 bit value, so be16_to_cpu() has to be used to interpret them correctly. This makes discard and flush actually work for named NBD exports (they did not work before, because the client always assumed them to be unsupported because of the bug fixed by this patch). Signed-off-by: Max Reitz <mreitz@redhat.com> Message-Id: <1424887718-10800-20-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Fix nbd_receive_options()Max Reitz2015-03-181-20/+29
| | | | | | | | The client flags are sent exactly once overall, not once per option. Signed-off-by: Max Reitz <mreitz@redhat.com> Message-Id: <1424887718-10800-19-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Set block size to BDRV_SECTOR_SIZEMax Reitz2015-03-181-8/+7
| | | | | | Signed-off-by: Max Reitz <mreitz@redhat.com> Message-Id: <1424887718-10800-13-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Handle blk_getlength() failureMax Reitz2015-03-181-2/+14
| | | | | | Signed-off-by: Max Reitz <mreitz@redhat.com> Message-Id: <1424887718-10800-9-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Pass return value from nbd_handle_list()Max Reitz2015-03-181-3/+4
| | | | | | | | | | | While it does not make a difference in practice, nbd_receive_options() generally returns -errno, so it should do that here as well; and the easiest way to achieve this is by passing on the value returned by nbd_handle_list(). Signed-off-by: Max Reitz <mreitz@redhat.com> Message-Id: <1424887718-10800-7-git-send-email-mreitz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Fix overflow return valueYik Fang2015-03-181-1/+1
| | | | | | | | The value of reply.error should be the type unsigned int. Signed-off-by: Yik Fang <eric.fangyi@huawei.com> Message-Id: <1423722111-12902-1-git-send-email-eric.fangyi@huawei.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Drop BDS backpointerMax Reitz2015-02-161-4/+4
| | | | | | | | | | | | | | Before this patch, the "opaque" pointer in an NBD BDS points to a BDRVNBDState, which contains an NbdClientSession object, which in turn contains a pointer to the BDS. This pointer may become invalid due to bdrv_swap(), so drop it, and instead pass the BDS directly to the nbd-client.c functions which then retrieve the NbdClientSession object from there. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1423256778-3340-2-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* nbd: Improve error messagesMax Reitz2015-02-061-17/+25
| | | | | | | | | | | | | | | | | | | This patch makes use of the Error object for nbd_receive_negotiate() so that errors during negotiation look nicer. Furthermore, this patch adds an additional error message if the received magic was wrong, but would be correct for the other protocol version, respectively: So if an export name was specified, but the NBD server magic corresponds to an old handshake, this condition is explicitly signaled to the user, and vice versa. As these messages are now part of the "Could not open image" error message, additional filtering has to be employed in iotest 083, which this patch does as well. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: Use BlockBackend internallyMax Reitz2014-12-101-28/+28
| | | | | | | | | | | | | | With all externally visible functions changed to use BlockBackend, this patch makes nbd use BlockBackend for everything internally as well. While touching them, substitute 512 by BDRV_SECTOR_SIZE in the calls to blk_read(), blk_write() and blk_co_discard(). Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1416309679-333-6-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: Change external interface to BlockBackendMax Reitz2014-12-101-5/+6
| | | | | | | | | | | Substitute BlockDriverState by BlockBackend in every globally visible function provided by nbd. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 1416309679-333-5-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block/migration: Disable cache invalidate for incoming migrationAlexey Kardashevskiy2014-10-141-0/+6
| | | | | | | | | | | | | | | | | | When migrated using libvirt with "--copy-storage-all", at the end of migration there is race between NBD mirroring task trying to do flush and migration completion, both end up invalidating cache. Since qcow2 driver does not handle this situation very well, random crashes happen. This disables the BDRV_O_INCOMING flag for the block device being migrated once the cache has been invalidated. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> -- fixed parens by hand Signed-off-by: Juan Quintela <quintela@redhat.com>
* nbd: Follow the BDS' AIO contextMax Reitz2014-08-291-0/+31
| | | | | | | | | | Keep the NBD server always in the same AIO context as the exported BDS by calling bdrv_add_aio_context_notifier() and implementing the required callbacks. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* nbd: Drop nbd_can_read()Max Reitz2014-08-291-19/+53
| | | | | | | | | | | | | | | | There is no variant of aio_set_fd_handler() like qemu_set_fd_handler2(), so we cannot give a can_read() callback function. Instead, unregister the nbd_read() function whenever we cannot read and re-register it as soon as we can read again. All this is hidden behind the functions nbd_set_handlers() (which registers all handlers for the AIO context and file descriptor belonging to the given client), nbd_unset_handlers() (which unregisters them) and nbd_update_can_read() (which checks whether NBD can read for the given client and acts accordingly). Signed-off-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* qemu-coroutine-io: fix for Win32Paolo Bonzini2014-08-291-1/+1
| | | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* nbd: Handle NBD_OPT_LIST option.Hani Benhabiles2014-06-301-0/+65
| | | | | Signed-off-by: Hani Benhabiles <kroosec@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Handle fixed new-style clients.Hani Benhabiles2014-06-301-49/+102
| | | | | | | | | | | When this flag is set, the server tells the client that it can send another option if the server received a request with an option that it doesn't understand instead of directly closing the connection. Also add link to the most up-to-date documentation. Signed-off-by: Hani Benhabiles <kroosec@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: Don't validate from and len in NBD_CMD_DISC.Hani Benhabiles2014-06-271-3/+4
| | | | | | | | | | | | | | | | | | These values aren't used in this case. Currently, the from field in the request sent by the nbd kernel module leading to a false error message when ending the connection with the client. $ qemu-nbd some.img -v // After nbd-client -d /dev/nbd0 nbd.c:nbd_trip():L1031: From: 18446744073709551104, Len: 0, Size: 20971520, Offset: 0 nbd.c:nbd_trip():L1032: requested operation past EOF--bad client? nbd.c:nbd_receive_request():L638: read failed Signed-off-by: Hani Benhabiles <kroosec@gmail.com> Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* 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>
OpenPOWER on IntegriCloud