]>
git.proxmox.com Git - qemu.git/blob - nbd.c
2 * Copyright (C) 2005 Anthony Liguori <anthony@codemonkey.ws>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "qemu-coroutine.h"
27 #include <sys/ioctl.h>
29 #if defined(__sun__) || defined(__HAIKU__)
30 #include <sys/ioccom.h>
39 #include "qemu_socket.h"
40 #include "qemu-queue.h"
45 #define TRACE(msg, ...) do { \
46 LOG(msg, ## __VA_ARGS__); \
49 #define TRACE(msg, ...) \
53 #define LOG(msg, ...) do { \
54 fprintf(stderr, "%s:%s():L%d: " msg "\n", \
55 __FILE__, __FUNCTION__, __LINE__, ## __VA_ARGS__); \
58 /* This is all part of the "official" NBD API */
60 #define NBD_REQUEST_SIZE (4 + 4 + 8 + 8 + 4)
61 #define NBD_REPLY_SIZE (4 + 4 + 8)
62 #define NBD_REQUEST_MAGIC 0x25609513
63 #define NBD_REPLY_MAGIC 0x67446698
64 #define NBD_OPTS_MAGIC 0x49484156454F5054LL
65 #define NBD_CLIENT_MAGIC 0x0000420281861253LL
67 #define NBD_SET_SOCK _IO(0xab, 0)
68 #define NBD_SET_BLKSIZE _IO(0xab, 1)
69 #define NBD_SET_SIZE _IO(0xab, 2)
70 #define NBD_DO_IT _IO(0xab, 3)
71 #define NBD_CLEAR_SOCK _IO(0xab, 4)
72 #define NBD_CLEAR_QUE _IO(0xab, 5)
73 #define NBD_PRINT_DEBUG _IO(0xab, 6)
74 #define NBD_SET_SIZE_BLOCKS _IO(0xab, 7)
75 #define NBD_DISCONNECT _IO(0xab, 8)
76 #define NBD_SET_TIMEOUT _IO(0xab, 9)
77 #define NBD_SET_FLAGS _IO(0xab, 10)
79 #define NBD_OPT_EXPORT_NAME (1 << 0)
81 /* Definitions for opaque data types */
83 typedef struct NBDRequest NBDRequest
;
86 QSIMPLEQ_ENTRY(NBDRequest
) entry
;
96 QSIMPLEQ_HEAD(, NBDRequest
) requests
;
101 void (*close
)(NBDClient
*client
);
106 Coroutine
*recv_coroutine
;
109 Coroutine
*send_coroutine
;
115 /* That's all folks */
117 ssize_t
nbd_wr_sync(int fd
, void *buffer
, size_t size
, bool do_read
)
122 if (qemu_in_coroutine()) {
124 return qemu_co_recv(fd
, buffer
, size
);
126 return qemu_co_send(fd
, buffer
, size
);
130 while (offset
< size
) {
134 len
= qemu_recv(fd
, buffer
+ offset
, size
- offset
, 0);
136 len
= send(fd
, buffer
+ offset
, size
- offset
, 0);
140 err
= socket_error();
142 /* recoverable error */
143 if (err
== EINTR
|| (offset
> 0 && err
== EAGAIN
)) {
147 /* unrecoverable error */
162 static ssize_t
read_sync(int fd
, void *buffer
, size_t size
)
164 /* Sockets are kept in blocking mode in the negotiation phase. After
165 * that, a non-readable socket simply means that another thread stole
166 * our request/reply. Synchronization is done with recv_coroutine, so
167 * that this is coroutine-safe.
169 return nbd_wr_sync(fd
, buffer
, size
, true);
172 static ssize_t
write_sync(int fd
, void *buffer
, size_t size
)
176 /* For writes, we do expect the socket to be writable. */
177 ret
= nbd_wr_sync(fd
, buffer
, size
, false);
178 } while (ret
== -EAGAIN
);
182 static void combine_addr(char *buf
, size_t len
, const char* address
,
185 /* If the address-part contains a colon, it's an IPv6 IP so needs [] */
186 if (strstr(address
, ":")) {
187 snprintf(buf
, len
, "[%s]:%u", address
, port
);
189 snprintf(buf
, len
, "%s:%u", address
, port
);
193 int tcp_socket_outgoing(const char *address
, uint16_t port
)
195 char address_and_port
[128];
196 combine_addr(address_and_port
, 128, address
, port
);
197 return tcp_socket_outgoing_spec(address_and_port
);
200 int tcp_socket_outgoing_spec(const char *address_and_port
)
202 return inet_connect(address_and_port
, true, NULL
, NULL
);
205 int tcp_socket_incoming(const char *address
, uint16_t port
)
207 char address_and_port
[128];
208 combine_addr(address_and_port
, 128, address
, port
);
209 return tcp_socket_incoming_spec(address_and_port
);
212 int tcp_socket_incoming_spec(const char *address_and_port
)
216 return inet_listen(address_and_port
, ostr
, olen
, SOCK_STREAM
, 0, NULL
);
219 int unix_socket_incoming(const char *path
)
224 return unix_listen(path
, ostr
, olen
);
227 int unix_socket_outgoing(const char *path
)
229 return unix_connect(path
);
246 static int nbd_send_negotiate(NBDClient
*client
)
248 int csock
= client
->sock
;
249 char buf
[8 + 8 + 8 + 128];
253 [ 0 .. 7] passwd ("NBDMAGIC")
254 [ 8 .. 15] magic (NBD_CLIENT_MAGIC)
257 [28 .. 151] reserved (0)
260 socket_set_block(csock
);
263 TRACE("Beginning negotiation.");
264 memcpy(buf
, "NBDMAGIC", 8);
265 cpu_to_be64w((uint64_t*)(buf
+ 8), NBD_CLIENT_MAGIC
);
266 cpu_to_be64w((uint64_t*)(buf
+ 16), client
->exp
->size
);
267 cpu_to_be32w((uint32_t*)(buf
+ 24),
268 client
->exp
->nbdflags
| NBD_FLAG_HAS_FLAGS
| NBD_FLAG_SEND_TRIM
|
269 NBD_FLAG_SEND_FLUSH
| NBD_FLAG_SEND_FUA
);
270 memset(buf
+ 28, 0, 124);
272 if (write_sync(csock
, buf
, sizeof(buf
)) != sizeof(buf
)) {
277 TRACE("Negotiation succeeded.");
280 socket_set_nonblock(csock
);
284 int nbd_receive_negotiate(int csock
, const char *name
, uint32_t *flags
,
285 off_t
*size
, size_t *blocksize
)
292 TRACE("Receiving negotiation.");
294 socket_set_block(csock
);
297 if (read_sync(csock
, buf
, 8) != 8) {
303 if (strlen(buf
) == 0) {
304 LOG("server connection closed");
308 TRACE("Magic is %c%c%c%c%c%c%c%c",
309 qemu_isprint(buf
[0]) ? buf
[0] : '.',
310 qemu_isprint(buf
[1]) ? buf
[1] : '.',
311 qemu_isprint(buf
[2]) ? buf
[2] : '.',
312 qemu_isprint(buf
[3]) ? buf
[3] : '.',
313 qemu_isprint(buf
[4]) ? buf
[4] : '.',
314 qemu_isprint(buf
[5]) ? buf
[5] : '.',
315 qemu_isprint(buf
[6]) ? buf
[6] : '.',
316 qemu_isprint(buf
[7]) ? buf
[7] : '.');
318 if (memcmp(buf
, "NBDMAGIC", 8) != 0) {
319 LOG("Invalid magic received");
323 if (read_sync(csock
, &magic
, sizeof(magic
)) != sizeof(magic
)) {
327 magic
= be64_to_cpu(magic
);
328 TRACE("Magic is 0x%" PRIx64
, magic
);
331 uint32_t reserved
= 0;
335 TRACE("Checking magic (opts_magic)");
336 if (magic
!= NBD_OPTS_MAGIC
) {
337 LOG("Bad magic received");
340 if (read_sync(csock
, &tmp
, sizeof(tmp
)) != sizeof(tmp
)) {
341 LOG("flags read failed");
344 *flags
= be16_to_cpu(tmp
) << 16;
345 /* reserved for future use */
346 if (write_sync(csock
, &reserved
, sizeof(reserved
)) !=
348 LOG("write failed (reserved)");
351 /* write the export name */
352 magic
= cpu_to_be64(magic
);
353 if (write_sync(csock
, &magic
, sizeof(magic
)) != sizeof(magic
)) {
354 LOG("write failed (magic)");
357 opt
= cpu_to_be32(NBD_OPT_EXPORT_NAME
);
358 if (write_sync(csock
, &opt
, sizeof(opt
)) != sizeof(opt
)) {
359 LOG("write failed (opt)");
362 namesize
= cpu_to_be32(strlen(name
));
363 if (write_sync(csock
, &namesize
, sizeof(namesize
)) !=
365 LOG("write failed (namesize)");
368 if (write_sync(csock
, (char*)name
, strlen(name
)) != strlen(name
)) {
369 LOG("write failed (name)");
373 TRACE("Checking magic (cli_magic)");
375 if (magic
!= NBD_CLIENT_MAGIC
) {
376 LOG("Bad magic received");
381 if (read_sync(csock
, &s
, sizeof(s
)) != sizeof(s
)) {
385 *size
= be64_to_cpu(s
);
387 TRACE("Size is %" PRIu64
, *size
);
390 if (read_sync(csock
, flags
, sizeof(*flags
)) != sizeof(*flags
)) {
391 LOG("read failed (flags)");
394 *flags
= be32_to_cpup(flags
);
396 if (read_sync(csock
, &tmp
, sizeof(tmp
)) != sizeof(tmp
)) {
397 LOG("read failed (tmp)");
400 *flags
|= be32_to_cpu(tmp
);
402 if (read_sync(csock
, &buf
, 124) != 124) {
403 LOG("read failed (buf)");
409 socket_set_nonblock(csock
);
414 int nbd_init(int fd
, int csock
, uint32_t flags
, off_t size
, size_t blocksize
)
416 TRACE("Setting NBD socket");
418 if (ioctl(fd
, NBD_SET_SOCK
, csock
) < 0) {
420 LOG("Failed to set NBD socket");
424 TRACE("Setting block size to %lu", (unsigned long)blocksize
);
426 if (ioctl(fd
, NBD_SET_BLKSIZE
, blocksize
) < 0) {
428 LOG("Failed setting NBD block size");
432 TRACE("Setting size to %zd block(s)", (size_t)(size
/ blocksize
));
434 if (ioctl(fd
, NBD_SET_SIZE_BLOCKS
, size
/ blocksize
) < 0) {
436 LOG("Failed setting size (in blocks)");
440 if (flags
& NBD_FLAG_READ_ONLY
) {
442 TRACE("Setting readonly attribute");
444 if (ioctl(fd
, BLKROSET
, (unsigned long) &read_only
) < 0) {
446 LOG("Failed setting read-only attribute");
451 if (ioctl(fd
, NBD_SET_FLAGS
, flags
) < 0
452 && errno
!= ENOTTY
) {
454 LOG("Failed setting flags");
458 TRACE("Negotiation ended");
463 int nbd_disconnect(int fd
)
465 ioctl(fd
, NBD_CLEAR_QUE
);
466 ioctl(fd
, NBD_DISCONNECT
);
467 ioctl(fd
, NBD_CLEAR_SOCK
);
471 int nbd_client(int fd
)
476 TRACE("Doing NBD loop");
478 ret
= ioctl(fd
, NBD_DO_IT
);
479 if (ret
< 0 && errno
== EPIPE
) {
480 /* NBD_DO_IT normally returns EPIPE when someone has disconnected
481 * the socket via NBD_DISCONNECT. We do not want to return 1 in
488 TRACE("NBD loop returned %d: %s", ret
, strerror(serrno
));
490 TRACE("Clearing NBD queue");
491 ioctl(fd
, NBD_CLEAR_QUE
);
493 TRACE("Clearing NBD socket");
494 ioctl(fd
, NBD_CLEAR_SOCK
);
500 int nbd_init(int fd
, int csock
, uint32_t flags
, off_t size
, size_t blocksize
)
505 int nbd_disconnect(int fd
)
510 int nbd_client(int fd
)
516 ssize_t
nbd_send_request(int csock
, struct nbd_request
*request
)
518 uint8_t buf
[NBD_REQUEST_SIZE
];
521 cpu_to_be32w((uint32_t*)buf
, NBD_REQUEST_MAGIC
);
522 cpu_to_be32w((uint32_t*)(buf
+ 4), request
->type
);
523 cpu_to_be64w((uint64_t*)(buf
+ 8), request
->handle
);
524 cpu_to_be64w((uint64_t*)(buf
+ 16), request
->from
);
525 cpu_to_be32w((uint32_t*)(buf
+ 24), request
->len
);
527 TRACE("Sending request to client: "
528 "{ .from = %" PRIu64
", .len = %u, .handle = %" PRIu64
", .type=%i}",
529 request
->from
, request
->len
, request
->handle
, request
->type
);
531 ret
= write_sync(csock
, buf
, sizeof(buf
));
536 if (ret
!= sizeof(buf
)) {
537 LOG("writing to socket failed");
543 static ssize_t
nbd_receive_request(int csock
, struct nbd_request
*request
)
545 uint8_t buf
[NBD_REQUEST_SIZE
];
549 ret
= read_sync(csock
, buf
, sizeof(buf
));
554 if (ret
!= sizeof(buf
)) {
560 [ 0 .. 3] magic (NBD_REQUEST_MAGIC)
561 [ 4 .. 7] type (0 == READ, 1 == WRITE)
567 magic
= be32_to_cpup((uint32_t*)buf
);
568 request
->type
= be32_to_cpup((uint32_t*)(buf
+ 4));
569 request
->handle
= be64_to_cpup((uint64_t*)(buf
+ 8));
570 request
->from
= be64_to_cpup((uint64_t*)(buf
+ 16));
571 request
->len
= be32_to_cpup((uint32_t*)(buf
+ 24));
573 TRACE("Got request: "
574 "{ magic = 0x%x, .type = %d, from = %" PRIu64
" , len = %u }",
575 magic
, request
->type
, request
->from
, request
->len
);
577 if (magic
!= NBD_REQUEST_MAGIC
) {
578 LOG("invalid magic (got 0x%x)", magic
);
584 ssize_t
nbd_receive_reply(int csock
, struct nbd_reply
*reply
)
586 uint8_t buf
[NBD_REPLY_SIZE
];
590 ret
= read_sync(csock
, buf
, sizeof(buf
));
595 if (ret
!= sizeof(buf
)) {
601 [ 0 .. 3] magic (NBD_REPLY_MAGIC)
602 [ 4 .. 7] error (0 == no error)
606 magic
= be32_to_cpup((uint32_t*)buf
);
607 reply
->error
= be32_to_cpup((uint32_t*)(buf
+ 4));
608 reply
->handle
= be64_to_cpup((uint64_t*)(buf
+ 8));
611 "{ magic = 0x%x, .error = %d, handle = %" PRIu64
" }",
612 magic
, reply
->error
, reply
->handle
);
614 if (magic
!= NBD_REPLY_MAGIC
) {
615 LOG("invalid magic (got 0x%x)", magic
);
621 static ssize_t
nbd_send_reply(int csock
, struct nbd_reply
*reply
)
623 uint8_t buf
[NBD_REPLY_SIZE
];
627 [ 0 .. 3] magic (NBD_REPLY_MAGIC)
628 [ 4 .. 7] error (0 == no error)
631 cpu_to_be32w((uint32_t*)buf
, NBD_REPLY_MAGIC
);
632 cpu_to_be32w((uint32_t*)(buf
+ 4), reply
->error
);
633 cpu_to_be64w((uint64_t*)(buf
+ 8), reply
->handle
);
635 TRACE("Sending response to client");
637 ret
= write_sync(csock
, buf
, sizeof(buf
));
642 if (ret
!= sizeof(buf
)) {
643 LOG("writing to socket failed");
649 #define MAX_NBD_REQUESTS 16
651 void nbd_client_get(NBDClient
*client
)
656 void nbd_client_put(NBDClient
*client
)
658 if (--client
->refcount
== 0) {
659 /* The last reference should be dropped by client->close,
660 * which is called by nbd_client_close.
662 assert(client
->closing
);
664 qemu_set_fd_handler2(client
->sock
, NULL
, NULL
, NULL
, NULL
);
671 void nbd_client_close(NBDClient
*client
)
673 if (client
->closing
) {
677 client
->closing
= true;
679 /* Force requests to finish. They will drop their own references,
680 * then we'll close the socket and free the NBDClient.
682 shutdown(client
->sock
, 2);
684 /* Also tell the client, so that they release their reference. */
686 client
->close(client
);
690 static NBDRequest
*nbd_request_get(NBDClient
*client
)
693 NBDExport
*exp
= client
->exp
;
695 assert(client
->nb_requests
<= MAX_NBD_REQUESTS
- 1);
696 client
->nb_requests
++;
698 if (QSIMPLEQ_EMPTY(&exp
->requests
)) {
699 req
= g_malloc0(sizeof(NBDRequest
));
700 req
->data
= qemu_blockalign(exp
->bs
, NBD_BUFFER_SIZE
);
702 req
= QSIMPLEQ_FIRST(&exp
->requests
);
703 QSIMPLEQ_REMOVE_HEAD(&exp
->requests
, entry
);
705 nbd_client_get(client
);
706 req
->client
= client
;
710 static void nbd_request_put(NBDRequest
*req
)
712 NBDClient
*client
= req
->client
;
713 QSIMPLEQ_INSERT_HEAD(&client
->exp
->requests
, req
, entry
);
714 if (client
->nb_requests
-- == MAX_NBD_REQUESTS
) {
717 nbd_client_put(client
);
720 NBDExport
*nbd_export_new(BlockDriverState
*bs
, off_t dev_offset
,
721 off_t size
, uint32_t nbdflags
)
723 NBDExport
*exp
= g_malloc0(sizeof(NBDExport
));
724 QSIMPLEQ_INIT(&exp
->requests
);
726 exp
->dev_offset
= dev_offset
;
727 exp
->nbdflags
= nbdflags
;
728 exp
->size
= size
== -1 ? bdrv_getlength(bs
) : size
;
732 void nbd_export_close(NBDExport
*exp
)
734 while (!QSIMPLEQ_EMPTY(&exp
->requests
)) {
735 NBDRequest
*first
= QSIMPLEQ_FIRST(&exp
->requests
);
736 QSIMPLEQ_REMOVE_HEAD(&exp
->requests
, entry
);
737 qemu_vfree(first
->data
);
744 static int nbd_can_read(void *opaque
);
745 static void nbd_read(void *opaque
);
746 static void nbd_restart_write(void *opaque
);
748 static ssize_t
nbd_co_send_reply(NBDRequest
*req
, struct nbd_reply
*reply
,
751 NBDClient
*client
= req
->client
;
752 int csock
= client
->sock
;
755 qemu_co_mutex_lock(&client
->send_lock
);
756 qemu_set_fd_handler2(csock
, nbd_can_read
, nbd_read
,
757 nbd_restart_write
, client
);
758 client
->send_coroutine
= qemu_coroutine_self();
761 rc
= nbd_send_reply(csock
, reply
);
763 socket_set_cork(csock
, 1);
764 rc
= nbd_send_reply(csock
, reply
);
766 ret
= qemu_co_send(csock
, req
->data
, len
);
771 socket_set_cork(csock
, 0);
774 client
->send_coroutine
= NULL
;
775 qemu_set_fd_handler2(csock
, nbd_can_read
, nbd_read
, NULL
, client
);
776 qemu_co_mutex_unlock(&client
->send_lock
);
780 static ssize_t
nbd_co_receive_request(NBDRequest
*req
, struct nbd_request
*request
)
782 NBDClient
*client
= req
->client
;
783 int csock
= client
->sock
;
786 client
->recv_coroutine
= qemu_coroutine_self();
787 rc
= nbd_receive_request(csock
, request
);
795 if (request
->len
> NBD_BUFFER_SIZE
) {
796 LOG("len (%u) is larger than max len (%u)",
797 request
->len
, NBD_BUFFER_SIZE
);
802 if ((request
->from
+ request
->len
) < request
->from
) {
803 LOG("integer overflow detected! "
804 "you're probably being attacked");
809 TRACE("Decoding type");
811 if ((request
->type
& NBD_CMD_MASK_COMMAND
) == NBD_CMD_WRITE
) {
812 TRACE("Reading %u byte(s)", request
->len
);
814 if (qemu_co_recv(csock
, req
->data
, request
->len
) != request
->len
) {
815 LOG("reading from socket failed");
823 client
->recv_coroutine
= NULL
;
827 static void nbd_trip(void *opaque
)
829 NBDClient
*client
= opaque
;
830 NBDExport
*exp
= client
->exp
;
832 struct nbd_request request
;
833 struct nbd_reply reply
;
836 TRACE("Reading request.");
837 if (client
->closing
) {
841 req
= nbd_request_get(client
);
842 ret
= nbd_co_receive_request(req
, &request
);
843 if (ret
== -EAGAIN
) {
850 reply
.handle
= request
.handle
;
858 if ((request
.from
+ request
.len
) > exp
->size
) {
859 LOG("From: %" PRIu64
", Len: %u, Size: %" PRIu64
860 ", Offset: %" PRIu64
"\n",
861 request
.from
, request
.len
,
862 (uint64_t)exp
->size
, (uint64_t)exp
->dev_offset
);
863 LOG("requested operation past EOF--bad client?");
864 goto invalid_request
;
867 switch (request
.type
& NBD_CMD_MASK_COMMAND
) {
869 TRACE("Request type is READ");
871 if (request
.type
& NBD_CMD_FLAG_FUA
) {
872 ret
= bdrv_co_flush(exp
->bs
);
880 ret
= bdrv_read(exp
->bs
, (request
.from
+ exp
->dev_offset
) / 512,
881 req
->data
, request
.len
/ 512);
883 LOG("reading from file failed");
888 TRACE("Read %u byte(s)", request
.len
);
889 if (nbd_co_send_reply(req
, &reply
, request
.len
) < 0)
893 TRACE("Request type is WRITE");
895 if (exp
->nbdflags
& NBD_FLAG_READ_ONLY
) {
896 TRACE("Server is read-only, return error");
901 TRACE("Writing to device");
903 ret
= bdrv_write(exp
->bs
, (request
.from
+ exp
->dev_offset
) / 512,
904 req
->data
, request
.len
/ 512);
906 LOG("writing to file failed");
911 if (request
.type
& NBD_CMD_FLAG_FUA
) {
912 ret
= bdrv_co_flush(exp
->bs
);
920 if (nbd_co_send_reply(req
, &reply
, 0) < 0) {
925 TRACE("Request type is DISCONNECT");
929 TRACE("Request type is FLUSH");
931 ret
= bdrv_co_flush(exp
->bs
);
936 if (nbd_co_send_reply(req
, &reply
, 0) < 0) {
941 TRACE("Request type is TRIM");
942 ret
= bdrv_co_discard(exp
->bs
, (request
.from
+ exp
->dev_offset
) / 512,
945 LOG("discard failed");
948 if (nbd_co_send_reply(req
, &reply
, 0) < 0) {
953 LOG("invalid request type (%u) received", request
.type
);
955 reply
.error
= -EINVAL
;
957 if (nbd_co_send_reply(req
, &reply
, 0) < 0) {
963 TRACE("Request/Reply complete");
966 nbd_request_put(req
);
970 nbd_request_put(req
);
971 nbd_client_close(client
);
974 static int nbd_can_read(void *opaque
)
976 NBDClient
*client
= opaque
;
978 return client
->recv_coroutine
|| client
->nb_requests
< MAX_NBD_REQUESTS
;
981 static void nbd_read(void *opaque
)
983 NBDClient
*client
= opaque
;
985 if (client
->recv_coroutine
) {
986 qemu_coroutine_enter(client
->recv_coroutine
, NULL
);
988 qemu_coroutine_enter(qemu_coroutine_create(nbd_trip
), client
);
992 static void nbd_restart_write(void *opaque
)
994 NBDClient
*client
= opaque
;
996 qemu_coroutine_enter(client
->send_coroutine
, NULL
);
999 NBDClient
*nbd_client_new(NBDExport
*exp
, int csock
,
1000 void (*close
)(NBDClient
*))
1003 client
= g_malloc0(sizeof(NBDClient
));
1004 client
->refcount
= 1;
1006 client
->sock
= csock
;
1007 if (nbd_send_negotiate(client
) < 0) {
1011 client
->close
= close
;
1012 qemu_co_mutex_init(&client
->send_lock
);
1013 qemu_set_fd_handler2(csock
, nbd_can_read
, nbd_read
, NULL
, client
);