Turns out NBD is not so simple to do if you do it right. Anyway, this series adds blockdev-add support for NBD clients.
Patches 1 and 2 add one less and one more complicated QDict function, respectively, which I needed in later NBD patches: Patch 1 for handling legacy options (move "host" to "address.data.host" etc.) and patch 2 because I'd like to use the input visitor for transforming the NBD options into a SocketAddress. Unfortunately, the block layer uses flattened QDicts everywhere, so we'll have to unflatten (erect?) them before we can use that visitor. Patch 3 adds a test for qdict_unflatten(). Patches 4, 5, 6, and 7 are minor patches with no functional relation to this series, other than later patches will touch the code they touch, too. Patches 8 and 9 prepare the code for the addition of a new option prefix, which is "address.". Patch 10 makes the NBD client accept a SocketAddress under the "address" option (or rather, a flattened SocketAddress QDict with its keys prefixed by "address."). The old options "host", "port", and "path" are supported as legacy options and translated to the respective SocketAddress representation. Patch 11 drops usage of "host", "port", and "path" outside of nbd_has_filename_options_conflict(), nbd_process_legacy_socket_options(), and nbd_refresh_filename(), making those options nothing but legacy. Patch 12, the goal of this series, is again not very complicated. Patches 13, 14, and 15 are required for the iotest added in patch 16. It will invoke qemu-nbd, so patch 13 is required. Besides qemu-nbd, it will launch an NBD server VM concurrently to the client VM, which is why patch 14 is required. And finally, it will test whether we can add an NBD BDS by passing it a file descriptor, which patch 15 is needed for (so we use the socket_scm_helper to pass sockets to qemu). Patch 16 then adds the iotest for NBD's blockdev-add interface. Note on the relation to v1: As you can see, most of this series is completely new. Patch 5 was patch 1 in v1, and the only thing that has changed is that I removed the full stop at the end of the error message; consequently I kept Eric's R-b. Max Reitz (16): qdict: Add qdict_change_key() qdict: Add qdict_unflatten() check-qdict: Add a test for qdict_unflatten() block/nbd: Drop trailing "." in error messages block/nbd: Reject port parameter without host block/nbd: Default port in nbd_refresh_filename() block/nbd: Use qdict_put() block/nbd: Add nbd_has_filename_options_conflict() block/nbd: "address" in nbd_refresh_filename() block/nbd: Accept SocketAddress block/nbd: Use SocketAddress options qapi: Allow blockdev-add for NBD iotests.py: Add qemu_nbd function iotests.py: Allow concurrent qemu instances socket_scm_helper: Accept fd directly iotests: Add test for NBD's blockdev-add interface block/nbd.c | 231 +++++++++++++++++++--------- include/qapi/qmp/qdict.h | 2 + qapi/block-core.json | 23 ++- qobject/qdict.c | 212 ++++++++++++++++++++++++++ tests/check-qdict.c | 267 +++++++++++++++++++++++++++++++++ tests/qemu-iotests/051.out | 4 +- tests/qemu-iotests/051.pc.out | 4 +- tests/qemu-iotests/147 | 194 ++++++++++++++++++++++++ tests/qemu-iotests/147.out | 5 + tests/qemu-iotests/group | 1 + tests/qemu-iotests/iotests.py | 22 ++- tests/qemu-iotests/socket_scm_helper.c | 29 ++-- 12 files changed, 898 insertions(+), 96 deletions(-) create mode 100755 tests/qemu-iotests/147 create mode 100644 tests/qemu-iotests/147.out -- 2.7.1