Statistics
| Branch: | Revision:

root / nbd.c @ f487b677

History | View | Annotate | Download (30.4 kB)

# Date Author Comment
e1adb27a 05/03/2013 02:05 pm Stefan Hajnoczi

nbd: use g_slice_new() instead of a freelist

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....

2d821488 05/03/2013 02:05 pm Stefan Hajnoczi

nbd: support large NBD requests

The Linux nbd driver recently increased the maximum supported request
size up to 32 MB:

commit 078be02b80359a541928c899c2631f39628f56df
Author: Michal Belczyk <>
Date: Tue Apr 30 15:28:28 2013 -0700...
f9e8cacc 04/02/2013 06:47 pm Stefan Hajnoczi

oslib-posix: rename socket_set_nonblock() to qemu_set_nonblock()

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 <>
Reviewed-by: Eric Blake <>...

197a4859 03/22/2013 06:51 pm Kevin Wolf

nbd: Remove unused functions

Signed-off-by: Kevin Wolf <>
Reviewed-by: Eric Blake <>

f17c90be 03/22/2013 06:51 pm Kevin Wolf

nbd: Keep hostname and port separate

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...

1de7afc9 12/19/2012 09:32 am Paolo Bonzini

misc: move include files to include/qemu/

Signed-off-by: Paolo Bonzini <>

737e150e 12/19/2012 09:31 am Paolo Bonzini

block: move include files to include/block/

Signed-off-by: Paolo Bonzini <>

8ffaaba0 11/28/2012 12:56 pm Paolo Bonzini

nbd: fix use of two uninitialized bytes when connecting to a named export

Reported-by: Michal Privoznik <>
Signed-off-by: Paolo Bonzini <>

c8969ede 11/13/2012 11:34 am Paolo Bonzini

nbd: fixes to read-only handling

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 <>

f8430e76 10/23/2012 02:54 pm Paolo Bonzini

nbd: ask and print error information from qemu-sockets

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...
7fc4e63e 10/23/2012 02:54 pm Paolo Bonzini

qemu-sockets: add Error ** to all functions

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 <>
Signed-off-by: Paolo Bonzini <>

5db5f44c 09/26/2012 03:05 am Orit Wasserman

Separate inet_connect into inet_connect (blocking) and inet_nonblocking_connect

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 <>...

125afda8 09/19/2012 04:26 pm Paolo Bonzini

nbd: add nbd_export_get_blockdev

Signed-off-by: Paolo Bonzini <>

ee0a19ec 09/19/2012 04:26 pm Paolo Bonzini

nbd: register named exports

Add an API to register and find named exports.

Signed-off-by: Paolo Bonzini <>

6b8c01e7 09/19/2012 04:26 pm Paolo Bonzini

nbd: negotiate with named exports

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....

4b9441f6 09/19/2012 04:26 pm Paolo Bonzini

nbd: track clients into NBDExport

Track the NBDClients of each NBDExport, and use it to implement
nbd_export_close.

Signed-off-by: Paolo Bonzini <>

0ddf08db 09/19/2012 04:26 pm Paolo Bonzini

nbd: add notification for closing an NBDExport

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 <>

ff2b68aa 09/19/2012 04:26 pm Paolo Bonzini

nbd: do not leak nbd_trip coroutines when a connection is torn down

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...

2c8d9f06 09/19/2012 04:26 pm Paolo Bonzini

nbd: add reference counting to NBDExport

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 <>

ce33967a 09/19/2012 04:26 pm Paolo Bonzini

nbd: make refcount interface public

After the next patch, the close callback will have to release its
reference.

Signed-off-by: Paolo Bonzini <>

a4aab7b4 09/19/2012 04:26 pm Paolo Bonzini

nbd: do not close BlockDriverState in nbd_export_close

This is not desirable when embedding the NBD server inside QEMU.
Move the bdrv_close to qemu-nbd.

Signed-off-by: Paolo Bonzini <>

9a304d29 09/19/2012 04:26 pm Paolo Bonzini

nbd: pass NBDClient to nbd_send_negotiate

We will need the NBDClient in nbd_send_negotiate to store the
export requested by the client.

Signed-off-by: Paolo Bonzini <>

fa26c26b 09/18/2012 01:35 pm Paolo Bonzini

nbd: add more constants

Avoid magic numbers and magic size computations; hide them behind
constants.

Signed-off-by: Paolo Bonzini <>

02a08fef 08/13/2012 07:20 pm Luiz Capitulino

net: inet_connect(), inet_connect_opts(): add in_progress argument

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...

a6ba35b3 05/10/2012 08:37 pm Amos Kong

sockets: change inet_connect() to support nonblock socket

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....

029409e5 05/10/2012 08:37 pm Amos Kong

sockets: use error class to pass listen error

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 <>
Reviewed-by: Orit Wasserman <>...

38ceff04 04/19/2012 06:19 pm Paolo Bonzini

nbd: do not include block_int.h

Signed-off-by: Paolo Bonzini <>

e25ceb76 04/19/2012 06:19 pm Paolo Bonzini

nbd: obey FUA on reads

Signed-off-by: Paolo Bonzini <>

94e7340b 04/19/2012 05:36 pm Paolo Bonzini

nbd: consistently use ssize_t

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....

fc19f8a0 04/19/2012 05:36 pm Paolo Bonzini

nbd: consistently check for <0 or >=0

This prepares for the following patch, which changes -1 return values
to negative errno.

Signed-off-by: Paolo Bonzini <>

185b4338 04/19/2012 05:36 pm Paolo Bonzini

nbd: consistently return negative errno values

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 <>

7fe7b68b 04/19/2012 05:36 pm Paolo Bonzini

nbd: do not block in nbd_wr_sync if no data at all is available

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...

0fee8f34 04/15/2012 10:25 pm Stefan Weil

nbd: Fix compiler warning (w64)

Portable printing of dev_offset (data type off_t) needs a type cast.

Signed-off-by: Stefan Weil <>

1743b515 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: move client handling to nbd.c

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....

72deddc5 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: add client pointer to NBDRequest

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...

262db388 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: asynchronous operation

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...

41996e38 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: throttle requests

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...

3e05c785 12/22/2011 12:53 pm Chunyan Liu

Update ioctl order in nbd_init() to detect EBUSY

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...

94607e7a 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: remove offset argument to nbd_trip

The argument is write-only.

Signed-off-by: Paolo Bonzini <>

3777b09f 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: remove data_size argument to nbd_trip

The size of the buffer is in practice part of the protocol.

Signed-off-by: Paolo Bonzini <>

a478f6e5 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: simplify nbd_trip

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 <>

22045592 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: introduce nbd_do_send_reply

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...

fae69416 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: more robust handling of invalid requests

Fail invalid requests with EINVAL instead of dropping them into
the void.

Signed-off-by: Paolo Bonzini <>

a030b347 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: introduce nbd_do_receive_request

Group the receiving of a response and the associated data into a new function.

Signed-off-by: Paolo Bonzini <>

af49bbbe 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: introduce NBDExport

Wrap the common parameters of nbd_trip and nbd_negotiate in a
single opaque struct.

Signed-off-by: Paolo Bonzini <>

d9a73806 12/22/2011 12:53 pm Paolo Bonzini

qemu-nbd: introduce NBDRequest

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 <>

ae255e52 12/22/2011 12:53 pm Paolo Bonzini

nbd: switch to asynchronous operation

Signed-off-by: Paolo Bonzini <>

adcf6302 12/22/2011 12:53 pm Paolo Bonzini

nbd: fix error handling in the server

bdrv_read and bdrv_write return negative errno values, not -1.

Signed-off-by: Paolo Bonzini <>

2c7989a9 12/22/2011 12:53 pm Paolo Bonzini

nbd: add support for NBD_CMD_FLAG_FUA

Signed-off-by: Paolo Bonzini <>

1486d04a 12/22/2011 12:53 pm Paolo Bonzini

nbd: add support for NBD_CMD_FLUSH

Signed-off-by: Paolo Bonzini <>

7a706633 12/22/2011 12:53 pm Paolo Bonzini

nbd: add support for NBD_CMD_TRIM

Signed-off-by: Paolo Bonzini <>

07f35073 12/02/2011 12:50 pm Dong Xu Wang

fix spelling in main directory

Signed-off-by: Dong Xu Wang <>
Signed-off-by: Stefan Hajnoczi <>

74624688 11/11/2011 03:02 pm Paolo Bonzini

nbd: treat EPIPE from NBD_DO_IT as success

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 <>
Signed-off-by: Kevin Wolf <>

8e72506e 09/21/2011 12:34 pm Paolo Bonzini

nbd: fix non-Linux build failure

Signed-off-by: Paolo Bonzini <>
Signed-off-by: Kevin Wolf <>

b90fb4b8 09/19/2011 12:34 pm Paolo Bonzini

nbd: support feature negotiation

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 <>
Signed-off-by: Kevin Wolf <>

bbb74edd 09/19/2011 12:34 pm Paolo Bonzini

nbd: sync API definitions with upstream

Signed-off-by: Paolo Bonzini <>
Signed-off-by: Kevin Wolf <>

973b3d0a 09/19/2011 12:34 pm Paolo Bonzini

nbd: support NBD_SET_FLAGS ioctl

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 <>...

ab359cd1 09/12/2011 04:17 pm Markus Armbruster

nbd: Clean up use of block_int.h

Signed-off-by: Markus Armbruster <>
Signed-off-by: Kevin Wolf <>

00aa0040 07/25/2011 05:38 pm Blue Swirl

Wrap recv to avoid warnings

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]...

b2e3d87f 04/07/2011 02:51 pm Nick Thomas

NBD library: whitespace changes

Signed-off-by: Nick Thomas <>
Signed-off-by: Kevin Wolf <>

c12504ce 04/07/2011 02:51 pm Nick Thomas

NBD: Use qemu_socket functions to open TCP and UNIX sockets

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...

5dc2eec9 10/03/2010 09:31 am Andreas Färber

nbd: Haiku has _IO() in its BSD compatibility layer

Signed-off-by: Andreas Färber <>
Signed-off-by: Blue Swirl <>

5fe16888 09/21/2010 04:39 pm Laurent Vivier

Improve qemu-nbd performance by 4400 %

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...

aab2e8f7 09/08/2010 10:26 pm Anthony Liguori

Merge remote branch 'kwolf/for-anthony' into staging

0a4eb864 09/04/2010 12:45 pm Jes Sorensen

Remove unused argument for nbd_client()

Signed-off-by: Jes Sorensen <>
Signed-off-by: Blue Swirl <>

1d45f8b5 08/30/2010 07:29 pm Laurent Vivier

nbd: Introduce NBD named exports.

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...

0bfcd599 05/22/2010 11:02 am Blue Swirl

Fix %lld or %llx printf format use

Signed-off-by: Blue Swirl <>

8167ee88 07/16/2009 11:47 pm Blue Swirl

Update to a hopefully more future proof FSF address

Signed-off-by: Blue Swirl <>

0a656f5f 05/21/2009 04:30 am malc

Cast pointer arguments of get/setsockopt, send to void * to keep GCC
from producing a warning about pointer type mismatches with Winsock

Signed-off-by: malc <>

b9e82a59 04/05/2009 09:03 pm blueswir1

Fix some win32 compile warnings

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6984 c046a42c-6fe2-441c-8c8c-71466251a162

fad6cb1a 01/05/2009 12:05 am aurel32

Update FSF address in GPL/LGPL boilerplate

The attached patch updates the FSF address in the GPL/LGPL boilerplate
in most GPL/LGPLed files, and also in COPYING.LIB.

Signed-off-by: Stuart Brady <>
Signed-off-by: Aurelien Jarno <>...

47398b9c 11/22/2008 10:04 pm blueswir1

Use qemu_isfoobar and qemu_towombat versions, based on patch by Christoph Egger

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5774 c046a42c-6fe2-441c-8c8c-71466251a162

03ff3ca3 09/15/2008 06:51 pm aliguori

Use common objects for qemu-img and qemu-nbd

Right now, we sprinkle #if defined(QEMU_IMG) && defined(QEMU_NBD) all over the
code. It's ugly and causes us to have to build multiple object files for
linking against qemu and the tools.

This patch introduces a new file, qemu-tool.c which contains enough for...

27982661 09/10/2008 06:23 pm aliguori

qemu-nbd: remove useless parameter from nbd_negotiate() (Laurent Vivier)

This patch removes "BlockDriverState *bs" from nbd_negotiate() because
it is not used.

Signed-off-by: Laurent Vivier <>
Signed-off-by: Anthony Liguori <>...

7e00eb9b 08/02/2008 04:57 am aliguori

Fix compilation of nbd on Solaris (Andreas Faerber)

Compilation of QEMU is currently broken on Solaris due to nbd's use of _IO and
due to network libraries not being linked into qemu-img.

The attached patch adds the appropriate libraries (copied from Makefile.target)...

d94888e3 07/04/2008 02:53 pm malc

Add missing return

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4846 c046a42c-6fe2-441c-8c8c-71466251a162

75818250 07/03/2008 04:41 pm ths

Allow QEMU to connect directly to an NBD server, by Laurent Vivier.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4838 c046a42c-6fe2-441c-8c8c-71466251a162

2f726488 07/03/2008 02:47 pm ths

Add a parameter to disable host cache, by Laurent Vivier.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4836 c046a42c-6fe2-441c-8c8c-71466251a162

cd831bd7 07/03/2008 01:23 pm ths

Merge NBD client/server, by Laurent Vivier.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4834 c046a42c-6fe2-441c-8c8c-71466251a162

975b092b 07/03/2008 12:18 am ths

Cleanup qemu-nbd related code, by Laurent Vivier.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4829 c046a42c-6fe2-441c-8c8c-71466251a162

dcf3a079 06/06/2008 04:03 am ths

Fix compiler warning.

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4676 c046a42c-6fe2-441c-8c8c-71466251a162

7a5ca864 05/28/2008 12:13 am bellard

qemu-nbd tool (Anthony Liguori)

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4596 c046a42c-6fe2-441c-8c8c-71466251a162