NBD patches for 2.11
The following changes since commit 1ab5eb4efb91a3d4569b0df6e824cc08ab4bd8ec:
Update version for v2.10.0 release (2017-08-30 17:02:54 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/ericb.git tags/pull-nbd-2017-08-30
for you to fetch changes up to f35dff7e13b84d3fffe1103c2c69afd81df5e4f5:
block/nbd-client: refactor request send/receive (2017-08-30 13:00:38 -0500)
----------------------------------------------------------------
nbd patches for 2017-08-30
- Kashyap Chamarthy: qemu-iotests: Extend non-shared storage migration test (194)
- Stefan Hajnaczi: 0/3 nbd-client: enter read_reply_co during init to avoid crash
- Vladimir Sementsov-Ogievskiy: portions of 0/17 nbd client refactoring and fixing
----------------------------------------------------------------
Kashyap Chamarthy (1):
qemu-iotests: Extend non-shared storage migration test (194)
Stefan Hajnoczi (3):
nbd-client: avoid read_reply_co entry if send failed
qemu-iotests: improve nbd-fault-injector.py startup protocol
qemu-iotests: test NBD over UNIX domain sockets in 083
Vladimir Sementsov-Ogievskiy (7):
nbd/client: fix nbd_opt_go
nbd/client: refactor nbd_read_eof nbd/client: refactor nbd_receive_reply nbd/client: fix nbd_send_request to return int block/nbd-client: get rid of ssize_t block/nbd-client: rename nbd_recv_coroutines_enter_all block/nbd-client: refactor request send/receive
include/block/nbd.h | 4 +- nbd/nbd-internal.h | 33 +++++-- block/nbd-client.c | 102 ++++++++------------- nbd/client.c | 21 +++-- tests/qemu-iotests/common.filter | 4 +- tests/qemu-iotests/083 | 138 +++++++++++++++++----------- tests/qemu-iotests/083.out | 149 +++++++++++++++++++++++++++---- tests/qemu-iotests/194 | 23 +++-- tests/qemu-iotests/194.out | 11 ++- tests/qemu-iotests/nbd-fault-injector.py | 4 + 10 files changed, 319 insertions(+), 170 deletions(-)
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 01/11] qemu-iotests: Extend non-shared storage migration test (194)
From: Kashyap Chamarthy <[email protected]>
This is the follow-up patch that was discussed[*] as part of feedback to qemu-iotest 194.
Changes in this patch:
- Supply 'job-id' parameter to drive-mirror invocation.
- Once migration completes, issue QMP block-job-cancel command on the source QEMU to gracefully complete drive-mirror operation.
- Once the BLOCK_JOB_COMPLETED event is emitted, stop the NBD server on the destination QEMU.
- Check for both the events: MIGRATION and BLOCK_JOB_COMPLETED.
With the above, the test will also be (almost) in sync with the procedure outlined in the document 'live-block-operations.rst'[+] (section: "QMP invocation for live storage migration with ``drive-mirror`` + NBD").
[*] https://lists.nongnu.org/archive/html/qemu-devel/2017-08/msg04820.html
-- qemu-iotests: add 194 non-shared storage migration test
[+] https://git.qemu.org/gitweb.cgi?p=qemu.git;a=blob;f=docs/interop/live-block-operations.rst
Message-Id: <[email protected]>
--- tests/qemu-iotests/194 | 23 +++++++++++++++++------ tests/qemu-iotests/194.out | 11 ++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-)
tests/qemu-iotests/194 +17 -6
@@ -46,16 +46,17 @@ iotests.log('Launching NBD server on destination...') iotests.log(dest_vm.qmp('nbd-server-start', addr={'type': 'unix', 'data': {'path': nbd_sock_path}})) iotests.log(dest_vm.qmp('nbd-server-add', device='drive0', writable=True)) -iotests.log('Starting drive-mirror on source...') +iotests.log('Starting `drive-mirror` on source...') iotests.log(source_vm.qmp( 'drive-mirror', device='drive0', target='nbd+unix:///drive0?socket={0}'.format(nbd_sock_path), sync='full', format='raw', # always raw, the server handles the format - mode='existing')) + mode='existing', + job_id='mirror-job0')) -iotests.log('Waiting for drive-mirror to complete...') +iotests.log('Waiting for `drive-mirror` to complete...') iotests.log(source_vm.event_wait('BLOCK_JOB_READY'), filters=[iotests.filter_qmp_event])
@@ -67,7 +68,17 @@ dest_vm.qmp('migrate-set-capabilities', iotests.log(source_vm.qmp('migrate', uri='unix:{0}'.format(migration_sock_path))) while True: - event = source_vm.event_wait('MIGRATION') - iotests.log(event, filters=[iotests.filter_qmp_event]) - if event['data']['status'] in ('completed', 'failed'): + event1 = source_vm.event_wait('MIGRATION') + iotests.log(event1, filters=[iotests.filter_qmp_event]) + if event1['data']['status'] in ('completed', 'failed'): + iotests.log('Gracefully ending the `drive-mirror` job on source...') + iotests.log(source_vm.qmp('block-job-cancel', device='mirror-job0')) + break + +while True: + event2 = source_vm.event_wait('BLOCK_JOB_COMPLETED') + iotests.log(event2, filters=[iotests.filter_qmp_event]) + if event2['event'] == 'BLOCK_JOB_COMPLETED': + iotests.log('Stopping the NBD server on destination...') + iotests.log(dest_vm.qmp('nbd-server-stop')) break
tests/qemu-iotests/194.out +8 -3
@@ -2,12 +2,17 @@ Launching VMs... Launching NBD server on destination... {u'return': {}} {u'return': {}} -Starting drive-mirror on source... +Starting `drive-mirror` on source... {u'return': {}} -Waiting for drive-mirror to complete... -{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'drive0', u'type': u'mirror', u'speed': 0, u'len': 1073741824, u'offset': 1073741824}, u'event': u'BLOCK_JOB_READY'} +Waiting for `drive-mirror` to complete... +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror-job0', u'type': u'mirror', u'speed': 0, u'len': 1073741824, u'offset': 1073741824}, u'event': u'BLOCK_JOB_READY'} Starting migration... {u'return': {}} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'setup'}, u'event': u'MIGRATION'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'active'}, u'event': u'MIGRATION'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'completed'}, u'event': u'MIGRATION'} +Gracefully ending the `drive-mirror` job on source... +{u'return': {}} +{u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'device': u'mirror-job0', u'type': u'mirror', u'speed': 0, u'len': 1073741824, u'offset': 1073741824}, u'event': u'BLOCK_JOB_COMPLETED'} +Stopping the NBD server on destination... +{u'return': {}}
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 03/11] qemu-iotests: improve nbd-fault-injector.py startup protocol
In reply to Eric BlakeFrom: Stefan Hajnoczi <[email protected]>
Currently 083 waits for the nbd-fault-injector.py server to start up by looping until netstat shows the TCP listen socket.
The startup protocol can be simplified by passing a 0 port number to nbd-fault-injector.py. The kernel will allocate a port in bind(2) and the final port number can be printed by nbd-fault-injector.py.
This should make it slightly nicer and less TCP-specific to wait for server startup. This patch changes nbd-fault-injector.py, the next one will rewrite server startup in 083.
Message-Id: <[email protected]>
--- tests/qemu-iotests/nbd-fault-injector.py | 4 ++++ 1 file changed, 4 insertions(+)
tests/qemu-iotests/nbd-fault-injector.py +4 -0
@@ -235,11 +235,15 @@ def open_socket(path): sock = socket.socket() sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.bind((host, int(port))) + + # If given port was 0 the final port number is now available + path = '%s:%d' % sock.getsockname() else: sock = socket.socket(socket.AF_UNIX) sock.bind(path) sock.listen(0) print 'Listening on %s' % path + sys.stdout.flush() # another process may be waiting, show message now return sock def usage(args):
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 02/11] nbd-client: avoid read_reply_co entry if send failed
In reply to Eric BlakeFrom: Stefan Hajnoczi <[email protected]>
The following segfault is encountered if the NBD server closes the UNIX domain socket immediately after negotiation:
Program terminated with signal SIGSEGV, Segmentation fault. #0 aio_co_schedule (ctx=0x0, co=0xd3c0ff2ef0) at util/async.c:441
441 QSLIST_INSERT_HEAD_ATOMIC(&ctx->scheduled_coroutines,
(gdb) bt
#0 0x000000d3c01a50f8 in aio_co_schedule (ctx=0x0, co=0xd3c0ff2ef0) at util/async.c:441 #1 0x000000d3c012fa90 in nbd_coroutine_end (bs=bs@entry=0xd3c0fec650, request=<optimized out>) at block/nbd-client.c:207 #2 0x000000d3c012fb58 in nbd_client_co_preadv (bs=0xd3c0fec650, offset=0, bytes=<optimized out>, qiov=0x7ffc10a91b20, flags=0) at block/nbd-client.c:237 #3 0x000000d3c0128e63 in bdrv_driver_preadv (bs=bs@entry=0xd3c0fec650, offset=offset@entry=0, bytes=bytes@entry=512, qiov=qiov@entry=0x7ffc10a91b20, flags=0) at block/io.c:836 #4 0x000000d3c012c3e0 in bdrv_aligned_preadv (child=child@entry=0xd3c0ff51d0, req=req@entry=0x7f31885d6e90, offset=offset@entry=0, bytes=bytes@entry=512, align=align@entry=1, qiov=qiov@entry=0x7ffc10a91b20, f +lags=0) at block/io.c:1086 #5 0x000000d3c012c6b8 in bdrv_co_preadv (child=0xd3c0ff51d0, offset=offset@entry=0, bytes=bytes@entry=512, qiov=qiov@entry=0x7ffc10a91b20, flags=flags@entry=0) at block/io.c:1182 #6 0x000000d3c011cc17 in blk_co_preadv (blk=0xd3c0ff4f80, offset=0, bytes=512, qiov=0x7ffc10a91b20, flags=0) at block/block-backend.c:1032 #7 0x000000d3c011ccec in blk_read_entry (opaque=0x7ffc10a91b40) at block/block-backend.c:1079 #8 0x000000d3c01bbb96 in coroutine_trampoline (i0=<optimized out>, i1=<optimized out>) at util/coroutine-ucontext.c:79 #9 0x00007f3196cb8600 in __start_context () at /lib64/libc.so.6
The problem is that nbd_client_init() uses nbd_client_attach_aio_context() -> aio_co_schedule(new_context, client->read_reply_co). Execution of read_reply_co is deferred to a BH which doesn't run until later.
In the mean time blk_co_preadv() can be called and nbd_coroutine_end() calls aio_wake() on read_reply_co. At this point in time read_reply_co's ctx isn't set because it has never been entered yet.
This patch simplifies the nbd_co_send_request() -> nbd_co_receive_reply() -> nbd_coroutine_end() lifecycle to just nbd_co_send_request() -> nbd_co_receive_reply(). The request is "ended" if an error occurs at any point. Callers no longer have to invoke nbd_coroutine_end().
This cleanup also eliminates the segfault because we don't call aio_co_schedule() to wake up s->read_reply_co if sending the request failed. It is only necessary to wake up s->read_reply_co if a reply was received.
Note this only happens with UNIX domain sockets on Linux. It doesn't seem possible to reproduce this with TCP sockets.
Message-Id: <[email protected]>
--- block/nbd-client.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
block/nbd-client.c +9 -16
@@ -144,12 +144,12 @@ static int nbd_co_send_request(BlockDriverState *bs, request->handle =INDEX_TO_HANDLE (s, i);if (s->quit) { -qemu_co_mutex_unlock (&s->send_mutex); -return -EIO ; + rc = -EIO ; + goto err; }if (!s->ioc) { -qemu_co_mutex_unlock (&s->send_mutex); -return -EPIPE ; + rc = -EPIPE ; + goto err; }if (qiov) {
@@ -166,8 +166,13 @@ static int nbd_co_send_request(BlockDriverState *bs, }else { rc =nbd_send_request (s->ioc, request); } + +err:if (rc <0 ) { s->quit = true; + s->requests[i].coroutine =NULL ; + s->in_flight--; +qemu_co_queue_next (&s->free_sema); }qemu_co_mutex_unlock (&s->send_mutex);return rc;
@@ -201,13 +206,6 @@ static void nbd_co_receive_reply(NBDClientSession *s,/* Tell the read handler to read another header. */ s->reply.handle =0 ; } -} - -static void nbd_coroutine_end (BlockDriverState *bs, -NBDRequest *request) -{ -NBDClientSession *s =nbd_get_client_session (bs); -int i =HANDLE_TO_INDEX (s, request->handle); s->requests[i].coroutine =NULL ;
@@ -243,7 +241,6 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, }else {nbd_co_receive_reply (client, &request, &reply, qiov); } -nbd_coroutine_end (bs, &request);return -reply.error; }
@@ -272,7 +269,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, }else {nbd_co_receive_reply (client, &request, &reply,NULL ); } -nbd_coroutine_end (bs, &request);return -reply.error; }
@@ -306,7 +302,6 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, }else {nbd_co_receive_reply (client, &request, &reply,NULL ); } -nbd_coroutine_end (bs, &request);return -reply.error; }
@@ -330,7 +325,6 @@ int nbd_client_co_flush(BlockDriverState *bs) }else {nbd_co_receive_reply (client, &request, &reply,NULL ); } -nbd_coroutine_end (bs, &request);return -reply.error; }
@@ -355,7 +349,6 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) }else {nbd_co_receive_reply (client, &request, &reply,NULL ); } -nbd_coroutine_end (bs, &request);return -reply.error; }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 05/11] nbd/client: fix nbd_opt_go
In reply to Eric BlakeFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Do not send NBD_OPT_ABORT to the broken server. After sending NBD_REP_ACK on NBD_OPT_GO server is most probably in transmission phase, when option sending is finished.
Message-Id: <[email protected]>
--- nbd/client.c | 2 -- 1 file changed, 2 deletions(-)
nbd/client.c +0 -2
@@ -399,12 +399,10 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wantname,phase, but make sure it sent flags */ if (len) {error_setg (errp,"server sent invalid NBD_REP_ACK" ); -nbd_send_opt_abort (ioc);return -1 ; }if (!info->flags) {error_setg (errp,"broken server omitted NBD_INFO_EXPORT" ); -nbd_send_opt_abort (ioc);return -1 ; }trace_nbd_opt_go_success ();
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 04/11] qemu-iotests: test NBD over UNIX domain sockets in 083
In reply to Eric BlakeFrom: Stefan Hajnoczi <[email protected]>
083 only tests TCP. Some failures might be specific to UNIX domain sockets.
A few adjustments are necessary:
1. Generating a port number and waiting for server startup is TCP-specific. Use the new nbd-fault-injector.py startup protocol to fetch the address. This is a little more elegant because we don't need netstat anymore.
2. The NBD filter does not work for the UNIX domain sockets URIs we generate and must be extended.
3. Run all tests twice: once for TCP and once for UNIX domain sockets.
Message-Id: <[email protected]>
--- tests/qemu-iotests/common.filter | 4 +- tests/qemu-iotests/083 | 138 +++++++++++++++++++++++-------------- tests/qemu-iotests/083.out | 145 ++++++++++++++++++++++++++++++++++----- 3 files changed, 215 insertions(+), 72 deletions(-)
tests/qemu-iotests/common.filter +2 -2
@@ -170,9 +170,9 @@ _filter_nbd() # # Filter out the TCP port number since this changes between runs. sed -e '/nbd\/.*\.c:/d' \ - -e 's#nbd:\(//\)\?127\.0\.0\.1:[0-9]*#nbd:\1127.0.0.1:PORT#g' \ + -e 's#127\.0\.0\.1:[0-9]*#127.0.0.1:PORT#g' \ -e "s#?socket=$TEST_DIR#?socket=TEST_DIR#g" \ - -e 's#\(exportname=foo\|PORT\): Failed to .*$#\1#' + -e 's#\(foo\|PORT/\?\|.sock\): Failed to .*$#\1#' } # make sure this script returns success
tests/qemu-iotests/083 +85 -53
172 lines not on this page · raw message
tests/qemu-iotests/083.out +128 -17
205 lines not on this page · raw message
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 06/11] nbd/client: refactor nbd_read_eof
In reply to Eric BlakeFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Refactor nbd_read_eof to return 1 on success, 0 on eof, when no data was read and <0 for other cases, because returned size of read data is not actually used.
Message-Id: <[email protected]>
--- nbd/nbd-internal.h | 33 ++++++++++++++++++++++++--------- nbd/client.c | 5 ----- tests/qemu-iotests/083.out | 8 ++++---- 3 files changed, 28 insertions(+), 18 deletions(-)
nbd/nbd-internal.h +24 -9
@@ -77,21 +77,36 @@#define NBD_ESHUTDOWN 108/* nbd_read_eof -* Tries to read @size bytes from @ioc. Returns number of bytes actually read. -* May return a value >= 0 and < size only on EOF, i.e. when iteratively called -* qio_channel_readv() returns 0. So, there is no need to call nbd_read_eof -* iteratively. +* Tries to read @size bytes from @ioc. +* Returns 1 on success +* 0 on eof, when no data was read (errp is not set) +* negative errno on failure (errp is set) */ -static inline ssize_t nbd_read_eof (QIOChannel *ioc,void *buffer,size_t size, -Error **errp) +static inline int nbd_read_eof (QIOChannel *ioc,void *buffer,size_t size, +Error **errp) {struct iovec iov = { .iov_base = buffer, .iov_len = size }; +ssize_t ret; +/* Sockets are kept in blocking mode in the negotiation phase. After * that, a non-readable socket simply means that another thread stole * our request/reply. Synchronization is done with recv_coroutine, so * that this is coroutine-safe. */ -return nbd_rwv (ioc, &iov,1 , size, true, errp); + +assert (size); + + ret =nbd_rwv (ioc, &iov,1 , size, true, errp); +if (ret <=0 ) { +return ret; + } + +if (ret != size) { +error_setg (errp,"End of file" ); +return -EINVAL ; + } + +return 1 ; }/* nbd_read
@@ -100,9 +115,9 @@ static inline ssize_t nbd_read_eof(QIOChannel *ioc, void *buffer, size_t size,static inline int nbd_read (QIOChannel *ioc,void *buffer,size_t size,Error **errp) { -ssize_t ret =nbd_read_eof (ioc, buffer, size, errp); +int ret =nbd_read_eof (ioc, buffer, size, errp); -if (ret >=0 && ret != size) { +if (ret ==0 ) { ret = -EINVAL ;error_setg (errp,"End of file" ); }
nbd/client.c +0 -5
@@ -925,11 +925,6 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)return ret; } -if (ret !=sizeof (buf)) { -error_setg (errp,"read failed" ); -return -EINVAL ; - } -/* Reply [ 0 .. 3] magic (NBD_REPLY_MAGIC) [ 4 .. 7] error (0 == no error)
tests/qemu-iotests/083.out +4 -4
@@ -69,12 +69,12 @@ read failed: Input/output error === Check disconnect 4 reply === -read failed +End of file read failed: Input/output error === Check disconnect 8 reply === -read failed +End of file read failed: Input/output error === Check disconnect before data ===
@@ -180,12 +180,12 @@ read failed: Input/output error === Check disconnect 4 reply === -read failed +End of file read failed: Input/output error === Check disconnect 8 reply === -read failed +End of file read failed: Input/output error === Check disconnect before data ===
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 08/11] nbd/client: fix nbd_send_request to return int
In reply to Eric BlakeFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Fix nbd_send_request to return int, as it returns a return value of nbd_write (which is int), and the only user of nbd_send_request's return value (nbd_co_send_request) consider it as int too.
Message-Id: <[email protected]>
--- include/block/nbd.h | 2 +- nbd/client.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/block/nbd.h +1 -1
@@ -163,7 +163,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, Error **errp);int nbd_init (int fd,QIOChannelSocket *sioc,NBDExportInfo *info,Error **errp); -ssize_t nbd_send_request (QIOChannel *ioc,NBDRequest *request); +int nbd_send_request (QIOChannel *ioc,NBDRequest *request);int nbd_receive_reply (QIOChannel *ioc,NBDReply *reply,Error **errp);int nbd_client (int fd);int nbd_disconnect (int fd);
nbd/client.c +1 -1
@@ -896,7 +896,7 @@ int nbd_disconnect(int fd) }#endif -ssize_t nbd_send_request (QIOChannel *ioc,NBDRequest *request) +int nbd_send_request (QIOChannel *ioc,NBDRequest *request) {uint8_t buf[NBD_REQUEST_SIZE ];
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 09/11] block/nbd-client: get rid of ssize_t
In reply to Eric BlakeFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Use int variable for nbd_co_send_request return value (as nbd_co_send_request returns int).
Message-Id: <[email protected]>
--- block/nbd-client.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
block/nbd-client.c +5 -5
@@ -230,7 +230,7 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, .len = bytes, };NBDReply reply; -ssize_t ret; +int ret;assert (bytes <=NBD_MAX_BUFFER_SIZE );assert (!flags);
@@ -254,7 +254,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, .len = bytes, };NBDReply reply; -ssize_t ret; +int ret;if (flags &BDRV_REQ_FUA ) {assert (client->info.flags &NBD_FLAG_SEND_FUA );
@@ -275,7 +275,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,int nbd_client_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int bytes,BdrvRequestFlags flags) { -ssize_t ret; +int ret;NBDClientSession *client =nbd_get_client_session (bs);NBDRequest request = { .type =NBD_CMD_WRITE_ZEROES ,
@@ -310,7 +310,7 @@ int nbd_client_co_flush(BlockDriverState *bs)NBDClientSession *client =nbd_get_client_session (bs);NBDRequest request = { .type =NBD_CMD_FLUSH };NBDReply reply; -ssize_t ret; +int ret;if (!(client->info.flags &NBD_FLAG_SEND_FLUSH )) {return 0 ;
@@ -337,7 +337,7 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) .len = bytes, };NBDReply reply; -ssize_t ret; +int ret;if (!(client->info.flags &NBD_FLAG_SEND_TRIM )) {return 0 ;
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 10/11] block/nbd-client: rename nbd_recv_coroutines_enter_all
In reply to Eric BlakeFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Rename nbd_recv_coroutines_enter_all to nbd_recv_coroutines_wake_all, as it most probably just adds all recv coroutines into co_queue_wakeup, rather than directly enter them.
Message-Id: <[email protected]>
--- block/nbd-client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/nbd-client.c +2 -2
@@ -34,7 +34,7 @@#define HANDLE_TO_INDEX (bs, handle) ((handle) ^ ((uint64_t)(intptr_t)bs))#define INDEX_TO_HANDLE (bs, index) ((index) ^ ((uint64_t)(intptr_t)bs)) -static void nbd_recv_coroutines_enter_all (NBDClientSession *s) +static void nbd_recv_coroutines_wake_all (NBDClientSession *s) {int i;
@@ -112,7 +112,7 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque) } s->quit = true; -nbd_recv_coroutines_enter_all (s); +nbd_recv_coroutines_wake_all (s); s->read_reply_co =NULL ; }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 07/11] nbd/client: refactor nbd_receive_reply
In reply to Eric BlakeFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Refactor nbd_receive_reply to return 1 on success, 0 on eof, when no data was read and <0 for other cases, because returned size of read data is not actually used.
Message-Id: <[email protected]>
--- include/block/nbd.h | 2 +- nbd/client.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
include/block/nbd.h +1 -1
@@ -164,7 +164,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name,int nbd_init (int fd,QIOChannelSocket *sioc,NBDExportInfo *info,Error **errp);ssize_t nbd_send_request (QIOChannel *ioc,NBDRequest *request); -ssize_t nbd_receive_reply (QIOChannel *ioc,NBDReply *reply,Error **errp); +int nbd_receive_reply (QIOChannel *ioc,NBDReply *reply,Error **errp);int nbd_client (int fd);int nbd_disconnect (int fd);
nbd/client.c +9 -3
@@ -914,11 +914,16 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request)return nbd_write (ioc, buf,sizeof (buf),NULL ); } -ssize_t nbd_receive_reply (QIOChannel *ioc,NBDReply *reply,Error **errp) +/* nbd_receive_reply +* Returns 1 on success +* 0 on eof, when no data was read (errp is not set) +* negative errno on failure (errp is set) +*/ +int nbd_receive_reply (QIOChannel *ioc,NBDReply *reply,Error **errp) {uint8_t buf[NBD_REPLY_SIZE ];uint32_t magic; -ssize_t ret; +int ret; ret =nbd_read_eof (ioc, buf,sizeof (buf), errp);if (ret <=0 ) {
@@ -948,6 +953,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)error_setg (errp,"invalid magic (got 0x%" PRIx32")" , magic);return -EINVAL ; } -return sizeof (buf); + +return 1 ; }
Signature · 1 line
2.13.5
[Qemu-devel] [PULL 11/11] block/nbd-client: refactor request send/receive
In reply to Eric BlakeFrom: Vladimir Sementsov-Ogievskiy <[email protected]>
Add nbd_co_request, to remove code duplications in nbd_client_co_{pwrite,pread,...} functions. Also this is needed for further refactoring.
Message-Id: <[email protected]> [eblake: make nbd_co_request a wrapper, rather than merging two existing functions]
--- block/nbd-client.c | 73 +++++++++++++++++++----------------------------------- 1 file changed, 26 insertions(+), 47 deletions(-)
block/nbd-client.c +26 -47
@@ -220,28 +220,40 @@ static void nbd_co_receive_reply(NBDClientSession *s,qemu_co_mutex_unlock (&s->send_mutex); } +static int nbd_co_request (BlockDriverState *bs, +NBDRequest *request, +QEMUIOVector *qiov) +{ +NBDClientSession *client =nbd_get_client_session (bs); +NBDReply reply; +int ret; + +assert (!qiov || request->type ==NBD_CMD_WRITE || + request->type ==NBD_CMD_READ ); + ret =nbd_co_send_request (bs, request, + request->type ==NBD_CMD_WRITE ? qiov :NULL ); +if (ret <0 ) { + reply.error = -ret; + }else { +nbd_co_receive_reply (client, request, &reply, + request->type ==NBD_CMD_READ ? qiov :NULL ); + } +return -reply.error; +} +int nbd_client_co_preadv (BlockDriverState *bs,uint64_t offset,uint64_t bytes,QEMUIOVector *qiov,int flags) { -NBDClientSession *client =nbd_get_client_session (bs);NBDRequest request = { .type =NBD_CMD_READ , .from = offset, .len = bytes, }; -NBDReply reply; -int ret;assert (bytes <=NBD_MAX_BUFFER_SIZE );assert (!flags); - ret =nbd_co_send_request (bs, &request,NULL ); -if (ret <0 ) { - reply.error = -ret; - }else { -nbd_co_receive_reply (client, &request, &reply, qiov); - } -return -reply.error; +return nbd_co_request (bs, &request, qiov); } int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
@@ -253,8 +265,6 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, .from = offset, .len = bytes, }; -NBDReply reply; -int ret;if (flags &BDRV_REQ_FUA ) {assert (client->info.flags &NBD_FLAG_SEND_FUA );
@@ -263,26 +273,18 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,assert (bytes <=NBD_MAX_BUFFER_SIZE ); - ret =nbd_co_send_request (bs, &request, qiov); -if (ret <0 ) { - reply.error = -ret; - }else { -nbd_co_receive_reply (client, &request, &reply,NULL ); - } -return -reply.error; +return nbd_co_request (bs, &request, qiov); }int nbd_client_co_pwrite_zeroes (BlockDriverState *bs,int64_t offset,int bytes,BdrvRequestFlags flags) { -int ret;NBDClientSession *client =nbd_get_client_session (bs);NBDRequest request = { .type =NBD_CMD_WRITE_ZEROES , .from = offset, .len = bytes, }; -NBDReply reply;if (!(client->info.flags &NBD_FLAG_SEND_WRITE_ZEROES )) {return -ENOTSUP ;
@@ -296,21 +298,13 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, request.flags |=NBD_CMD_FLAG_NO_HOLE ; } - ret =nbd_co_send_request (bs, &request,NULL ); -if (ret <0 ) { - reply.error = -ret; - }else { -nbd_co_receive_reply (client, &request, &reply,NULL ); - } -return -reply.error; +return nbd_co_request (bs, &request,NULL ); }int nbd_client_co_flush (BlockDriverState *bs) {NBDClientSession *client =nbd_get_client_session (bs);NBDRequest request = { .type =NBD_CMD_FLUSH }; -NBDReply reply; -int ret;if (!(client->info.flags &NBD_FLAG_SEND_FLUSH )) {return 0 ;
@@ -319,13 +313,7 @@ int nbd_client_co_flush(BlockDriverState *bs) request.from =0 ; request.len =0 ; - ret =nbd_co_send_request (bs, &request,NULL ); -if (ret <0 ) { - reply.error = -ret; - }else { -nbd_co_receive_reply (client, &request, &reply,NULL ); - } -return -reply.error; +return nbd_co_request (bs, &request,NULL ); }int nbd_client_co_pdiscard (BlockDriverState *bs,int64_t offset,int bytes)
@@ -336,21 +324,12 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) .from = offset, .len = bytes, }; -NBDReply reply; -int ret;if (!(client->info.flags &NBD_FLAG_SEND_TRIM )) {return 0 ; } - ret =nbd_co_send_request (bs, &request,NULL ); -if (ret <0 ) { - reply.error = -ret; - }else { -nbd_co_receive_reply (client, &request, &reply,NULL ); - } -return -reply.error; - +return nbd_co_request (bs, &request,NULL ); }void nbd_client_detach_aio_context (BlockDriverState *bs)
Signature · 1 line
2.13.5
Peter Maydell
AppliedQuoted 12 lines · Eric Blake
The following changes since commit
1ab5eb4efb91a3d4569b0df6e824cc08ab4bd8ec:Update version for v2.10.0 release (2017-08-30 17:02:54 +0100)
are available in the git repository at:
git://repo.or.cz/qemu/ericb.gittags/pull-nbd-2017-08-30for you to fetch changes up to
f35dff7e13b84d3fffe1103c2c69afd81df5e4f5:
block/nbd-client: refactor request send/receive (2017-08-30 13:00:38 -0500)
Quoted 8 lines
----------------------------------------------------------------
nbd patches for 2017-08-30- Kashyap Chamarthy: qemu-iotests: Extend non-shared storage migration test (194)
- Stefan Hajnaczi: 0/3 nbd-client: enterread_reply_coduring init to avoid crash
- Vladimir Sementsov-Ogievskiy: portions of 0/17 nbd client refactoring and fixing----------------------------------------------------------------
Applied, thanks.
-- PMM