summaryrefslogtreecommitdiffstats
path: root/qemu-nbd.c
Commit message (Collapse)AuthorAgeFilesLines
* Add -f FMT / --format FMT arg to qemu-nbdDaniel P. Berrange2013-04-151-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently the qemu-nbd program will auto-detect the format of any disk it is given. This behaviour is known to be insecure. For example, if qemu-nbd initially exposes a 'raw' file to an unprivileged app, and that app runs 'qemu-img create -f qcow2 -o backing_file=/etc/shadow /dev/nbd0' then the next time the app is started, the qemu-nbd will now detect it as a 'qcow2' file and expose /etc/shadow to the unprivileged app. The only way to avoid this is to explicitly tell qemu-nbd what disk format to use on the command line, completely disabling auto-detection. This patch adds a '-f' / '--format' arg for this purpose, mirroring what is already available via qemu-img and qemu commands. qemu-nbd --format raw -p 9000 evil.img will now always use raw, regardless of what format 'evil.img' looks like it contains Signed-off-by: Daniel P. Berrange <berrange@redhat.com> [Use errx, not err. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* block: Add options QDict to bdrv_open() prototypeKevin Wolf2013-03-151-1/+1
| | | | | | | | | | It doesn't do anything yet except storing the options QDict in the BlockDriverState. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
* qemu-nbd: add --discard optionPaolo Bonzini2013-02-221-3/+15
| | | | | | | | Similar to --cache and --aio, this option mimics the discard suboption of "-drive". Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* block: move include files to include/block/Paolo Bonzini2012-12-191-2/+2
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: initialize main loop before block layerPaolo Bonzini2012-11-121-1/+1
| | | | | | | qemu-nbd was broken because they initialized the block layer while qemu_aio_context was still NULL. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: rewrite termination conditions to use a state machinePaolo Bonzini2012-09-191-10/+27
| | | | | | | | | | | | Use a simple state machine with the following states: - RUNNING => accepting connections - TERMINATE => main loop must call nbd_export_close/put, and not accept connections anymore - TERMINATING => waiting for pending requests to finish - TERMINATED => the NBDExport has been closed Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: add notification for closing an NBDExportPaolo Bonzini2012-09-191-1/+1
| | | | | | | | 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: add reference counting to NBDExportPaolo Bonzini2012-09-191-0/+2
| | | | | | | 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 close BlockDriverState in nbd_export_closePaolo Bonzini2012-09-191-0/+1
| | | | | | | 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>
* qemu-nbd: add --cache and --aio optionsPaolo Bonzini2012-07-241-2/+40
| | | | | | | Add two options to tune the I/O implementation of qemu-nbd, matching the possibilities given by the QEMU -drive option. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: reorganize help messagePaolo Bonzini2012-07-241-11/+22
| | | | | | | This patch separates qemu-nbd's options in logical groups, thus making the help message easier to read. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: do not include block_int.hPaolo Bonzini2012-04-191-2/+2
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* nbd: consistently return negative errno valuesPaolo Bonzini2012-04-191-7/+8
| | | | | | | | 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-13/+13
| | | | | | | This prepares for the following patch, which changes -1 return values to negative errno. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* open /dev/nbd in nbd_client_threadPaolo Bonzini2012-02-171-18/+16Star
| | | | Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* do not chdir(/) in qemu-nbd before opening all filesMichael Tokarev2012-02-171-1/+7
| | | | | | | | | | | | | | | | When qemu-nbd becomes a daemon it calls daemon(3) with nochdir=0, so daemon(3) changes current directory to /. But at this time, qemu-nbd did not open any user-specified files yet, so by changing current directory, all non-absolute paths becomes wrong. The solution is to pass nochdir=1 to daemon(3) function, and to chdir("/") after all init has been performed, before entering the main loop, -- just like a good daemon should do. This patch is applicable for -stable. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: drop loop which can never loopStefan Hajnoczi2012-01-061-6/+4Star
| | | | | | | | | | For some reason nbd_client_thread() has a do..while loop which can never loop, the condition is bogus because we would take a goto instead. Drop the loop. Reported-by: Dr David Alan Gilbert <davidagilbert@uk.ibm.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* qemu-nbd: move client handling to nbd.cPaolo Bonzini2011-12-221-10/+4Star
| | | | | | | | | 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: use common main loopPaolo Bonzini2011-12-221-67/+45Star
| | | | | | | Using a single main loop for sockets will help yielding from the socket coroutine back to the main loop, and later reentering it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: introduce NBDExportPaolo Bonzini2011-12-221-10/+5Star
| | | | | | | 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: remove data_size argument to nbd_tripPaolo Bonzini2011-12-221-3/+1Star
| | | | | | 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-2/+1Star
| | | | | | The argument is write-only. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* qemu-nbd: open the block device after starting the client threadPaolo Bonzini2011-11-111-17/+17
| | | | | | | | | | | | This is cleaner, because we do not need to close the block device when there is an error opening /dev/nbdX. It was done this way only to print errors before daemonizing. At the same time, use atexit to ensure that the block device is closed whenever we exit. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-nbd: fix socket creation racePaolo Bonzini2011-11-111-15/+15
| | | | | | | | | | | | | | Now that the client and server are in the same process, there is no need to race on the creation of the socket. We can open the listening socket before starting the client thread. This avoids that "qemu-nbd -v -c" prints this once before connecting successfully to the socket: connect(unix:/var/lock/qemu-nbd-nbd0): No such file or directory Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-nbd: print error messages from the daemon through a pipePaolo Bonzini2011-11-111-9/+59
| | | | | | | | | | | In order to get nice error messages, keep the qemu-nbd process running until before issuing NBD_DO_IT and connected to the daemon with a pipe. This lets the qemu-nbd process relay error messages from the daemon and exit with a nonzero status if appropriate. Suggested-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-nbd: move client to a threadPaolo Bonzini2011-11-111-80/+93
| | | | | | | | | | | | | | | | This avoids that qemu-nbd uses both forking and threads, which do not behave well together. qemu-nbd is already Unix only, and there is no qemu_thread_join, so for now use pthreads. Since the parent and child no longer have separate file descriptors, we can open the NBD device before daemonizing, instead of checking with access(2) and restricting the open to the client only. Reported-by: Pierre Riteau <pierre.riteau@irisa.fr> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-nbd: rename socket variablePaolo Bonzini2011-11-111-13/+12Star
| | | | | | | | It will be moved to a global variable by the next patch, and it would conflict with the socket function. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-nbd: trap SIGTERMPaolo Bonzini2011-11-111-5/+29
| | | | | | | | | | | The client process right now uses SIGTERM to interrupt the server side. This does not affect the exit status of "qemu-nbd -v -c" because the server is a child process. This will change when both sides will be in the same process, and anyway cleaning up things nicely upon SIGTERM is good practice. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: support feature negotiationPaolo Bonzini2011-09-191-7/+6Star
| | | | | | | | | 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>
* Fix include statements for qemu-common.hStefan Weil2011-09-091-1/+1
| | | | | | | | | | | | | | * qemu-common.h is not a system include file, so it should be included with "" instead of <>. Otherwise incremental builds might fail because only local include files are checked for changes. * linux-user/syscall.c included the file twice. Cc: Riku Voipio <riku.voipio@iki.fi> Cc: Jan Kiszka <jan.kiszka@siemens.com> Acked-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
* Use glib memory allocation and free functionsAnthony Liguori2011-08-211-2/+2
| | | | | | qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Darwin: Fix compilation warning regarding the deprecated daemon() functionAlexandre Raymond2011-06-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | Changes since v1: create a wrapper function named qemu_daemon() in oslib-posix.c instead of putting the OS specific workaround in qemu-nbd.c directly. On OSX >= 10.5, daemon() is deprecated, resulting in the following warning: ----8<---- qemu-nbd.c: In function ‘main’: qemu-nbd.c:371: warning: ‘daemon’ is deprecated (declared at /usr/include/stdlib.h:289) ----8<---- The following trick, used in mDNSResponder, takes care of this warning: http://www.opensource.apple.com/source/mDNSResponder/mDNSResponder-258.18/mDNSPosix/PosixDaemon.c On OSX, it temporarily renames the daemon() function before including stdlib.h and declares it manually as an extern function. This way, the compiler does not see the declaration from stdlib.h and thus does not display the warning. Signed-off-by: Alexandre Raymond <cerbere@gmail.com> Cc: Blue Swirl <blauwirbel@gmail.com> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
* block: clarify the meaning of BDRV_O_NOCACHEChristoph Hellwig2011-06-081-1/+1
| | | | | | | | | Change BDRV_O_NOCACHE to only imply bypassing the host OS file cache, but no writeback semantics. All existing callers are changed to also specify BDRV_O_CACHE_WB to give them writeback semantics. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Remove NULL checks for bdrv_new return valueKevin Wolf2010-12-171-2/+0Star
| | | | | | It's an indirect call to qemu_malloc, which never returns an error. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* nbd: correctly manage default portLaurent Vivier2010-09-211-3/+3
| | | | | | | | block/nbd.c: use default port number when none is specified qemu-nbd.c: use IANA-assigned port number: 10809 Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* use qemu_blockalign consistentlyChristoph Hellwig2010-09-211-1/+1
| | | | | | | | | Use qemu_blockalign for all allocations in the block layer. This allows increasing the required alignment, which is need to support O_DIRECT on devices with large block sizes. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Merge remote branch 'kwolf/for-anthony' into stagingAnthony Liguori2010-09-081-1/+3
|\
| * nbd: Introduce NBD named exports.Laurent Vivier2010-08-301-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Respect return value from nbd_client()Jes Sorensen2010-09-041-1/+4
| | | | | | | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* | Remove unused argument for nbd_client()Jes Sorensen2010-09-041-1/+1
|/ | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* qemu-nbd: Improve error reportingRyota Ozaki2010-05-171-10/+24
| | | | | | | | | | | | - use err(3) instead of errx(3) if errno is available to report why failed - let fail prior to daemon(3) if opening a nbd file is likely to fail after daemonizing to avoid silent failure exit - add missing 'ret = 1' when unix_socket_outgoing failed Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Replace calls of old bdrv_openKevin Wolf2010-04-231-1/+1
| | | | | | | | | What is known today as bdrv_open2 becomes the new bdrv_open. All remaining callers of the old function are converted to the new one. In some places they even know the right format, so they should have used bdrv_open2 from the beginning. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-nbd: Fix invalid usage of the first argument of errxRyota Ozaki2010-03-271-17/+17
| | | | | | | | | errx takes the exit status of a process as the first argument. Passing errno to it is wrong. Instead the patch lets errx take EXIT_FAILURE. Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* qemu-nbd: Fix return value handling of bdrv_openRyota Ozaki2010-03-271-1/+1
| | | | | | | | bdrv_open may return -errno so we have to check if the return value is '< 0', not '== -1'. Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
* read-only: minor cleanupNaphtali Sprei2010-03-171-0/+1
| | | | | | | Really use read-only flags for opening the file when asked for read-only Signed-off-by: Naphtali Sprei <nsprei@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* win32: pair qemu_memalign() with qemu_vfree()Herve Poussineau2010-01-261-1/+1
| | | | | | | | | | Win32 suffers from a very big memory leak when dealing with SCSI devices. Each read/write request allocates memory with qemu_memalign (ie VirtualAlloc) but frees it with qemu_free (ie free). Pair all qemu_memalign() calls with qemu_vfree() to prevent such leaks. Signed-off-by: Herve Poussineau <hpoussin@reactos.org> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* Clean-up a little bit the RW related bits of BDRV_O_FLAGS. BDRV_O_RDONLY ↵Naphtali Sprei2010-01-201-1/+1
| | | | | | | | | | gone (and so is BDRV_O_ACCESS). Default value for bdrv_flags (0/zero) is READ-ONLY. Need to explicitly request READ-WRITE. Instead of using the field 'readonly' of the BlockDriverState struct for passing the request, pass the request in the flags parameter to the function. Signed-off-by: Naphtali Sprei <nsprei@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* qemu-nbd: fix OpenBSD linker warningBlue Swirl2009-12-231-1/+2
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Compile qemu-nbd also on OpenBSD and SolarisBlue Swirl2009-12-231-0/+1
| | | | | | | | | basename() needs #include <libgen.h>. No prototype for daemon() is available on Solaris, but link succeeds. Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* Fix Sparse warnings: "Using plain integer as NULL pointer"Blue Swirl2009-07-311-16/+16
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>