xref: /openbmc/qemu/include/block/nbd.h (revision fb1c2aaa)
1 /*
2  *  Copyright Red Hat
3  *  Copyright (C) 2005  Anthony Liguori <anthony@codemonkey.ws>
4  *
5  *  Network Block Device
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; under version 2 of the License.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef NBD_H
21 #define NBD_H
22 
23 #include "block/export.h"
24 #include "io/channel-socket.h"
25 #include "crypto/tlscreds.h"
26 #include "qapi/error.h"
27 #include "qemu/bswap.h"
28 
29 typedef struct NBDExport NBDExport;
30 typedef struct NBDClient NBDClient;
31 typedef struct NBDClientConnection NBDClientConnection;
32 typedef struct NBDMetaContexts NBDMetaContexts;
33 
34 extern const BlockExportDriver blk_exp_nbd;
35 
36 /*
37  * NBD_DEFAULT_HANDSHAKE_MAX_SECS: Number of seconds in which client must
38  * succeed at NBD_OPT_GO before being forcefully dropped as too slow.
39  */
40 #define NBD_DEFAULT_HANDSHAKE_MAX_SECS 10
41 
42 /* Handshake phase structs - this struct is passed on the wire */
43 
44 typedef struct NBDOption {
45     uint64_t magic; /* NBD_OPTS_MAGIC */
46     uint32_t option; /* NBD_OPT_* */
47     uint32_t length;
48 } QEMU_PACKED NBDOption;
49 
50 typedef struct NBDOptionReply {
51     uint64_t magic; /* NBD_REP_MAGIC */
52     uint32_t option; /* NBD_OPT_* */
53     uint32_t type; /* NBD_REP_* */
54     uint32_t length;
55 } QEMU_PACKED NBDOptionReply;
56 
57 typedef struct NBDOptionReplyMetaContext {
58     NBDOptionReply h; /* h.type = NBD_REP_META_CONTEXT, h.length > 4 */
59     uint32_t context_id;
60     /* metadata context name follows */
61 } QEMU_PACKED NBDOptionReplyMetaContext;
62 
63 /* Track results of negotiation */
64 typedef enum NBDMode {
65     /* Keep this list in a continuum of increasing features. */
66     NBD_MODE_OLDSTYLE,     /* server lacks newstyle negotiation */
67     NBD_MODE_EXPORT_NAME,  /* newstyle but only OPT_EXPORT_NAME safe */
68     NBD_MODE_SIMPLE,       /* newstyle but only simple replies */
69     NBD_MODE_STRUCTURED,   /* newstyle, structured replies enabled */
70     NBD_MODE_EXTENDED,     /* newstyle, extended headers enabled */
71 } NBDMode;
72 
73 /* Transmission phase structs */
74 
75 /*
76  * Note: NBDRequest is _NOT_ the same as the network representation of an NBD
77  * request!
78  */
79 typedef struct NBDRequest {
80     uint64_t cookie;
81     uint64_t from;  /* Offset touched by the command */
82     uint64_t len;   /* Effect length; 32 bit limit without extended headers */
83     uint16_t flags; /* NBD_CMD_FLAG_* */
84     uint16_t type;  /* NBD_CMD_* */
85     NBDMode mode;   /* Determines which network representation to use */
86     NBDMetaContexts *contexts; /* Used by NBD_CMD_BLOCK_STATUS */
87 } NBDRequest;
88 
89 typedef struct NBDSimpleReply {
90     uint32_t magic;  /* NBD_SIMPLE_REPLY_MAGIC */
91     uint32_t error;
92     uint64_t cookie;
93 } QEMU_PACKED NBDSimpleReply;
94 
95 /* Header of all structured replies */
96 typedef struct NBDStructuredReplyChunk {
97     uint32_t magic;  /* NBD_STRUCTURED_REPLY_MAGIC */
98     uint16_t flags;  /* combination of NBD_REPLY_FLAG_* */
99     uint16_t type;   /* NBD_REPLY_TYPE_* */
100     uint64_t cookie; /* request handle */
101     uint32_t length; /* length of payload */
102 } QEMU_PACKED NBDStructuredReplyChunk;
103 
104 typedef struct NBDExtendedReplyChunk {
105     uint32_t magic;  /* NBD_EXTENDED_REPLY_MAGIC */
106     uint16_t flags;  /* combination of NBD_REPLY_FLAG_* */
107     uint16_t type;   /* NBD_REPLY_TYPE_* */
108     uint64_t cookie; /* request handle */
109     uint64_t offset; /* request offset */
110     uint64_t length; /* length of payload */
111 } QEMU_PACKED NBDExtendedReplyChunk;
112 
113 typedef union NBDReply {
114     NBDSimpleReply simple;
115     NBDStructuredReplyChunk structured;
116     NBDExtendedReplyChunk extended;
117     struct {
118         /*
119          * @magic and @cookie fields have the same offset and size in all
120          * forms of replies, so let them be accessible without ".simple.",
121          * ".structured.", or ".extended." specifications.
122          */
123         uint32_t magic;
124         uint32_t _skip;
125         uint64_t cookie;
126     };
127 } NBDReply;
128 QEMU_BUILD_BUG_ON(offsetof(NBDReply, simple.cookie) !=
129                   offsetof(NBDReply, cookie));
130 QEMU_BUILD_BUG_ON(offsetof(NBDReply, structured.cookie) !=
131                   offsetof(NBDReply, cookie));
132 QEMU_BUILD_BUG_ON(offsetof(NBDReply, extended.cookie) !=
133                   offsetof(NBDReply, cookie));
134 
135 /* Header of chunk for NBD_REPLY_TYPE_OFFSET_DATA */
136 typedef struct NBDStructuredReadData {
137     /* header's .length >= 9 */
138     uint64_t offset;
139     /* At least one byte of data payload follows, calculated from h.length */
140 } QEMU_PACKED NBDStructuredReadData;
141 
142 /* Complete chunk for NBD_REPLY_TYPE_OFFSET_HOLE */
143 typedef struct NBDStructuredReadHole {
144     /* header's length == 12 */
145     uint64_t offset;
146     uint32_t length;
147 } QEMU_PACKED NBDStructuredReadHole;
148 
149 /* Header of all NBD_REPLY_TYPE_ERROR* errors */
150 typedef struct NBDStructuredError {
151     /* header's length >= 6 */
152     uint32_t error;
153     uint16_t message_length;
154 } QEMU_PACKED NBDStructuredError;
155 
156 /* Header of NBD_REPLY_TYPE_BLOCK_STATUS */
157 typedef struct NBDStructuredMeta {
158     /* header's length >= 12 (at least one extent) */
159     uint32_t context_id;
160     /* NBDExtent32 extents[] follows, array length implied by header */
161 } QEMU_PACKED NBDStructuredMeta;
162 
163 /* Extent array element for NBD_REPLY_TYPE_BLOCK_STATUS */
164 typedef struct NBDExtent32 {
165     uint32_t length;
166     uint32_t flags; /* NBD_STATE_* */
167 } QEMU_PACKED NBDExtent32;
168 
169 /* Header of NBD_REPLY_TYPE_BLOCK_STATUS_EXT */
170 typedef struct NBDExtendedMeta {
171     /* header's length >= 24 (at least one extent) */
172     uint32_t context_id;
173     uint32_t count; /* header length must be count * 16 + 8 */
174     /* NBDExtent64 extents[count] follows */
175 } QEMU_PACKED NBDExtendedMeta;
176 
177 /* Extent array element for NBD_REPLY_TYPE_BLOCK_STATUS_EXT */
178 typedef struct NBDExtent64 {
179     uint64_t length;
180     uint64_t flags; /* NBD_STATE_* */
181 } QEMU_PACKED NBDExtent64;
182 
183 /* Client payload for limiting NBD_CMD_BLOCK_STATUS reply */
184 typedef struct NBDBlockStatusPayload {
185     uint64_t effect_length;
186     /* uint32_t ids[] follows, array length implied by header */
187 } QEMU_PACKED NBDBlockStatusPayload;
188 
189 /* Transmission (export) flags: sent from server to client during handshake,
190    but describe what will happen during transmission */
191 enum {
192     NBD_FLAG_HAS_FLAGS_BIT          =  0, /* Flags are there */
193     NBD_FLAG_READ_ONLY_BIT          =  1, /* Device is read-only */
194     NBD_FLAG_SEND_FLUSH_BIT         =  2, /* Send FLUSH */
195     NBD_FLAG_SEND_FUA_BIT           =  3, /* Send FUA (Force Unit Access) */
196     NBD_FLAG_ROTATIONAL_BIT         =  4, /* Use elevator algorithm -
197                                              rotational media */
198     NBD_FLAG_SEND_TRIM_BIT          =  5, /* Send TRIM (discard) */
199     NBD_FLAG_SEND_WRITE_ZEROES_BIT  =  6, /* Send WRITE_ZEROES */
200     NBD_FLAG_SEND_DF_BIT            =  7, /* Send DF (Do not Fragment) */
201     NBD_FLAG_CAN_MULTI_CONN_BIT     =  8, /* Multi-client cache consistent */
202     NBD_FLAG_SEND_RESIZE_BIT        =  9, /* Send resize */
203     NBD_FLAG_SEND_CACHE_BIT         = 10, /* Send CACHE (prefetch) */
204     NBD_FLAG_SEND_FAST_ZERO_BIT     = 11, /* FAST_ZERO flag for WRITE_ZEROES */
205     NBD_FLAG_BLOCK_STAT_PAYLOAD_BIT = 12, /* PAYLOAD flag for BLOCK_STATUS */
206 };
207 
208 #define NBD_FLAG_HAS_FLAGS          (1 << NBD_FLAG_HAS_FLAGS_BIT)
209 #define NBD_FLAG_READ_ONLY          (1 << NBD_FLAG_READ_ONLY_BIT)
210 #define NBD_FLAG_SEND_FLUSH         (1 << NBD_FLAG_SEND_FLUSH_BIT)
211 #define NBD_FLAG_SEND_FUA           (1 << NBD_FLAG_SEND_FUA_BIT)
212 #define NBD_FLAG_ROTATIONAL         (1 << NBD_FLAG_ROTATIONAL_BIT)
213 #define NBD_FLAG_SEND_TRIM          (1 << NBD_FLAG_SEND_TRIM_BIT)
214 #define NBD_FLAG_SEND_WRITE_ZEROES  (1 << NBD_FLAG_SEND_WRITE_ZEROES_BIT)
215 #define NBD_FLAG_SEND_DF            (1 << NBD_FLAG_SEND_DF_BIT)
216 #define NBD_FLAG_CAN_MULTI_CONN     (1 << NBD_FLAG_CAN_MULTI_CONN_BIT)
217 #define NBD_FLAG_SEND_RESIZE        (1 << NBD_FLAG_SEND_RESIZE_BIT)
218 #define NBD_FLAG_SEND_CACHE         (1 << NBD_FLAG_SEND_CACHE_BIT)
219 #define NBD_FLAG_SEND_FAST_ZERO     (1 << NBD_FLAG_SEND_FAST_ZERO_BIT)
220 #define NBD_FLAG_BLOCK_STAT_PAYLOAD (1 << NBD_FLAG_BLOCK_STAT_PAYLOAD_BIT)
221 
222 /* New-style handshake (global) flags, sent from server to client, and
223    control what will happen during handshake phase. */
224 #define NBD_FLAG_FIXED_NEWSTYLE   (1 << 0) /* Fixed newstyle protocol. */
225 #define NBD_FLAG_NO_ZEROES        (1 << 1) /* End handshake without zeroes. */
226 
227 /* New-style client flags, sent from client to server to control what happens
228    during handshake phase. */
229 #define NBD_FLAG_C_FIXED_NEWSTYLE (1 << 0) /* Fixed newstyle protocol. */
230 #define NBD_FLAG_C_NO_ZEROES      (1 << 1) /* End handshake without zeroes. */
231 
232 /* Option requests. */
233 #define NBD_OPT_EXPORT_NAME       (1)
234 #define NBD_OPT_ABORT             (2)
235 #define NBD_OPT_LIST              (3)
236 /* #define NBD_OPT_PEEK_EXPORT    (4) not in use */
237 #define NBD_OPT_STARTTLS          (5)
238 #define NBD_OPT_INFO              (6)
239 #define NBD_OPT_GO                (7)
240 #define NBD_OPT_STRUCTURED_REPLY  (8)
241 #define NBD_OPT_LIST_META_CONTEXT (9)
242 #define NBD_OPT_SET_META_CONTEXT  (10)
243 #define NBD_OPT_EXTENDED_HEADERS  (11)
244 
245 /* Option reply types. */
246 #define NBD_REP_ERR(value) ((UINT32_C(1) << 31) | (value))
247 
248 #define NBD_REP_ACK             (1)    /* Data sending finished. */
249 #define NBD_REP_SERVER          (2)    /* Export description. */
250 #define NBD_REP_INFO            (3)    /* NBD_OPT_INFO/GO. */
251 #define NBD_REP_META_CONTEXT    (4)    /* NBD_OPT_{LIST,SET}_META_CONTEXT */
252 
253 #define NBD_REP_ERR_UNSUP           NBD_REP_ERR(1)  /* Unknown option */
254 #define NBD_REP_ERR_POLICY          NBD_REP_ERR(2)  /* Server denied */
255 #define NBD_REP_ERR_INVALID         NBD_REP_ERR(3)  /* Invalid length */
256 #define NBD_REP_ERR_PLATFORM        NBD_REP_ERR(4)  /* Not compiled in */
257 #define NBD_REP_ERR_TLS_REQD        NBD_REP_ERR(5)  /* TLS required */
258 #define NBD_REP_ERR_UNKNOWN         NBD_REP_ERR(6)  /* Export unknown */
259 #define NBD_REP_ERR_SHUTDOWN        NBD_REP_ERR(7)  /* Server shutting down */
260 #define NBD_REP_ERR_BLOCK_SIZE_REQD NBD_REP_ERR(8)  /* Need INFO_BLOCK_SIZE */
261 #define NBD_REP_ERR_TOO_BIG         NBD_REP_ERR(9)  /* Payload size overflow */
262 #define NBD_REP_ERR_EXT_HEADER_REQD NBD_REP_ERR(10) /* Need extended headers */
263 
264 /* Info types, used during NBD_REP_INFO */
265 #define NBD_INFO_EXPORT         0
266 #define NBD_INFO_NAME           1
267 #define NBD_INFO_DESCRIPTION    2
268 #define NBD_INFO_BLOCK_SIZE     3
269 
270 /* Request flags, sent from client to server during transmission phase */
271 #define NBD_CMD_FLAG_FUA         (1 << 0) /* 'force unit access' during write */
272 #define NBD_CMD_FLAG_NO_HOLE     (1 << 1) /* don't punch hole on zero run */
273 #define NBD_CMD_FLAG_DF          (1 << 2) /* don't fragment structured read */
274 #define NBD_CMD_FLAG_REQ_ONE     (1 << 3) \
275     /* only one extent in BLOCK_STATUS reply chunk */
276 #define NBD_CMD_FLAG_FAST_ZERO   (1 << 4) /* fail if WRITE_ZEROES is not fast */
277 #define NBD_CMD_FLAG_PAYLOAD_LEN (1 << 5) \
278     /* length describes payload, not effect; only with ext header */
279 
280 /* Supported request types */
281 enum {
282     NBD_CMD_READ = 0,
283     NBD_CMD_WRITE = 1,
284     NBD_CMD_DISC = 2,
285     NBD_CMD_FLUSH = 3,
286     NBD_CMD_TRIM = 4,
287     NBD_CMD_CACHE = 5,
288     NBD_CMD_WRITE_ZEROES = 6,
289     NBD_CMD_BLOCK_STATUS = 7,
290 };
291 
292 #define NBD_DEFAULT_PORT	10809
293 
294 /* Maximum size of a single READ/WRITE data buffer */
295 #define NBD_MAX_BUFFER_SIZE (32 * 1024 * 1024)
296 
297 /*
298  * Maximum size of a protocol string (export name, metadata context name,
299  * etc.).  Use malloc rather than stack allocation for storage of a
300  * string.
301  */
302 #define NBD_MAX_STRING_SIZE 4096
303 
304 /* Two types of request structures, a given client will only use 1 */
305 #define NBD_REQUEST_MAGIC           0x25609513
306 #define NBD_EXTENDED_REQUEST_MAGIC  0x21e41c71
307 
308 /*
309  * Three types of reply structures, but what a client expects depends
310  * on NBD_OPT_STRUCTURED_REPLY and NBD_OPT_EXTENDED_HEADERS.
311  */
312 #define NBD_SIMPLE_REPLY_MAGIC      0x67446698
313 #define NBD_STRUCTURED_REPLY_MAGIC  0x668e33ef
314 #define NBD_EXTENDED_REPLY_MAGIC    0x6e8a278c
315 
316 /* Chunk reply flags (for structured and extended replies) */
317 #define NBD_REPLY_FLAG_DONE          (1 << 0) /* This reply-chunk is last */
318 
319 /* Chunk reply types */
320 #define NBD_REPLY_ERR(value)         ((1 << 15) | (value))
321 
322 #define NBD_REPLY_TYPE_NONE              0
323 #define NBD_REPLY_TYPE_OFFSET_DATA       1
324 #define NBD_REPLY_TYPE_OFFSET_HOLE       2
325 #define NBD_REPLY_TYPE_BLOCK_STATUS      5
326 #define NBD_REPLY_TYPE_BLOCK_STATUS_EXT  6
327 #define NBD_REPLY_TYPE_ERROR             NBD_REPLY_ERR(1)
328 #define NBD_REPLY_TYPE_ERROR_OFFSET      NBD_REPLY_ERR(2)
329 
330 /* Extent flags for base:allocation in NBD_REPLY_TYPE_BLOCK_STATUS */
331 #define NBD_STATE_HOLE (1 << 0)
332 #define NBD_STATE_ZERO (1 << 1)
333 
334 /* Extent flags for qemu:dirty-bitmap in NBD_REPLY_TYPE_BLOCK_STATUS */
335 #define NBD_STATE_DIRTY (1 << 0)
336 
337 /* No flags needed for qemu:allocation-depth in NBD_REPLY_TYPE_BLOCK_STATUS */
338 
339 static inline bool nbd_reply_type_is_error(int type)
340 {
341     return type & (1 << 15);
342 }
343 
344 /* NBD errors are based on errno numbers, so there is a 1:1 mapping,
345  * but only a limited set of errno values is specified in the protocol.
346  * Everything else is squashed to EINVAL.
347  */
348 #define NBD_SUCCESS    0
349 #define NBD_EPERM      1
350 #define NBD_EIO        5
351 #define NBD_ENOMEM     12
352 #define NBD_EINVAL     22
353 #define NBD_ENOSPC     28
354 #define NBD_EOVERFLOW  75
355 #define NBD_ENOTSUP    95
356 #define NBD_ESHUTDOWN  108
357 
358 /* Details collected by NBD_OPT_EXPORT_NAME and NBD_OPT_GO */
359 typedef struct NBDExportInfo {
360     /* Set by client before nbd_receive_negotiate() */
361     bool request_sizes;
362     char *x_dirty_bitmap;
363 
364     /* Set by client before nbd_receive_negotiate(), or by server results
365      * during nbd_receive_export_list() */
366     char *name; /* must be non-NULL */
367 
368     /* In-out fields, set by client before nbd_receive_negotiate() and
369      * updated by server results during nbd_receive_negotiate() */
370     NBDMode mode; /* input maximum mode tolerated; output actual mode chosen */
371     bool base_allocation; /* base:allocation context for NBD_CMD_BLOCK_STATUS */
372 
373     /* Set by server results during nbd_receive_negotiate() and
374      * nbd_receive_export_list() */
375     uint64_t size;
376     uint16_t flags;
377     uint32_t min_block;
378     uint32_t opt_block;
379     uint32_t max_block;
380 
381     uint32_t context_id;
382 
383     /* Set by server results during nbd_receive_export_list() */
384     char *description;
385     int n_contexts;
386     char **contexts;
387 } NBDExportInfo;
388 
389 int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
390                           const char *hostname, QIOChannel **outioc,
391                           NBDExportInfo *info, Error **errp);
392 void nbd_free_export_list(NBDExportInfo *info, int count);
393 int nbd_receive_export_list(QIOChannel *ioc, QCryptoTLSCreds *tlscreds,
394                             const char *hostname, NBDExportInfo **info,
395                             Error **errp);
396 int nbd_init(int fd, QIOChannelSocket *sioc, NBDExportInfo *info,
397              Error **errp);
398 int nbd_send_request(QIOChannel *ioc, NBDRequest *request);
399 int coroutine_fn nbd_receive_reply(BlockDriverState *bs, QIOChannel *ioc,
400                                    NBDReply *reply, NBDMode mode,
401                                    Error **errp);
402 int nbd_client(int fd);
403 int nbd_disconnect(int fd);
404 int nbd_errno_to_system_errno(int err);
405 
406 void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk);
407 
408 AioContext *nbd_export_aio_context(NBDExport *exp);
409 NBDExport *nbd_export_find(const char *name);
410 
411 void nbd_client_new(QIOChannelSocket *sioc,
412                     uint32_t handshake_max_secs,
413                     QCryptoTLSCreds *tlscreds,
414                     const char *tlsauthz,
415                     void (*close_fn)(NBDClient *, bool),
416                     void *owner);
417 void *nbd_client_owner(NBDClient *client);
418 void nbd_client_get(NBDClient *client);
419 void nbd_client_put(NBDClient *client);
420 
421 void nbd_server_is_qemu_nbd(int max_connections);
422 bool nbd_server_is_running(void);
423 int nbd_server_max_connections(void);
424 void nbd_server_start(SocketAddress *addr, const char *tls_creds,
425                       const char *tls_authz, uint32_t max_connections,
426                       Error **errp);
427 void nbd_server_start_options(NbdServerOptions *arg, Error **errp);
428 
429 /* nbd_read
430  * Reads @size bytes from @ioc. Returns 0 on success.
431  */
432 static inline int nbd_read(QIOChannel *ioc, void *buffer, size_t size,
433                            const char *desc, Error **errp)
434 {
435     ERRP_GUARD();
436     int ret = qio_channel_read_all(ioc, buffer, size, errp) < 0 ? -EIO : 0;
437 
438     if (ret < 0) {
439         if (desc) {
440             error_prepend(errp, "Failed to read %s: ", desc);
441         }
442         return ret;
443     }
444 
445     return 0;
446 }
447 
448 #define DEF_NBD_READ_N(bits)                                            \
449 static inline int nbd_read##bits(QIOChannel *ioc,                       \
450                                  uint##bits##_t *val,                   \
451                                  const char *desc, Error **errp)        \
452 {                                                                       \
453     int ret = nbd_read(ioc, val, sizeof(*val), desc, errp);             \
454     if (ret < 0) {                                                      \
455         return ret;                                                     \
456     }                                                                   \
457     *val = be##bits##_to_cpu(*val);                                     \
458     return 0;                                                           \
459 }
460 
461 DEF_NBD_READ_N(16) /* Defines nbd_read16(). */
462 DEF_NBD_READ_N(32) /* Defines nbd_read32(). */
463 DEF_NBD_READ_N(64) /* Defines nbd_read64(). */
464 
465 #undef DEF_NBD_READ_N
466 
467 static inline bool nbd_reply_is_simple(NBDReply *reply)
468 {
469     return reply->magic == NBD_SIMPLE_REPLY_MAGIC;
470 }
471 
472 static inline bool nbd_reply_is_structured(NBDReply *reply)
473 {
474     return reply->magic == NBD_STRUCTURED_REPLY_MAGIC;
475 }
476 
477 const char *nbd_reply_type_lookup(uint16_t type);
478 const char *nbd_opt_lookup(uint32_t opt);
479 const char *nbd_rep_lookup(uint32_t rep);
480 const char *nbd_info_lookup(uint16_t info);
481 const char *nbd_cmd_lookup(uint16_t info);
482 const char *nbd_err_lookup(int err);
483 const char *nbd_mode_lookup(NBDMode mode);
484 
485 /* nbd/client-connection.c */
486 void nbd_client_connection_enable_retry(NBDClientConnection *conn);
487 
488 NBDClientConnection *nbd_client_connection_new(const SocketAddress *saddr,
489                                                bool do_negotiation,
490                                                const char *export_name,
491                                                const char *x_dirty_bitmap,
492                                                QCryptoTLSCreds *tlscreds,
493                                                const char *tlshostname);
494 void nbd_client_connection_release(NBDClientConnection *conn);
495 
496 QIOChannel *coroutine_fn
497 nbd_co_establish_connection(NBDClientConnection *conn, NBDExportInfo *info,
498                             bool blocking, Error **errp);
499 
500 void nbd_co_establish_connection_cancel(NBDClientConnection *conn);
501 
502 #endif
503