]> git.proxmox.com Git - mirror_qemu.git/blame - block/nbd-client.h
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
[mirror_qemu.git] / block / nbd-client.h
CommitLineData
2302c1ca
MAL
1#ifndef NBD_CLIENT_H
2#define NBD_CLIENT_H
3
4#include "qemu-common.h"
5#include "block/nbd.h"
6#include "block/block_int.h"
064097d9 7#include "io/channel-socket.h"
2302c1ca
MAL
8
9/* #define DEBUG_NBD */
10
11#if defined(DEBUG_NBD)
12#define logout(fmt, ...) \
13 fprintf(stderr, "nbd\t%-24s" fmt, __func__, ##__VA_ARGS__)
14#else
15#define logout(fmt, ...) ((void)0)
16#endif
17
18#define MAX_NBD_REQUESTS 16
19
40f4a218
SH
20typedef struct {
21 Coroutine *coroutine;
f140e300 22 uint64_t offset; /* original offset of the request */
bc5a0335 23 bool receiving; /* waiting for connection_co? */
40f4a218
SH
24} NBDClientRequest;
25
10676b81 26typedef struct NBDClientSession {
064097d9
DB
27 QIOChannelSocket *sioc; /* The master data channel */
28 QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */
004a89fc 29 NBDExportInfo info;
2302c1ca
MAL
30
31 CoMutex send_mutex;
9bc9732f 32 CoQueue free_sema;
bc5a0335 33 Coroutine *connection_co;
2302c1ca
MAL
34 int in_flight;
35
40f4a218 36 NBDClientRequest requests[MAX_NBD_REQUESTS];
ed2dd912 37 NBDReply reply;
5ad81b49 38 BlockDriverState *bs;
72b6ffc7 39 bool quit;
10676b81 40} NBDClientSession;
2302c1ca 41
10676b81 42NBDClientSession *nbd_get_client_session(BlockDriverState *bs);
f53a829b 43
064097d9 44int nbd_client_init(BlockDriverState *bs,
d42f78e9 45 SocketAddress *saddr,
064097d9 46 const char *export_name,
75822a12
DB
47 QCryptoTLSCreds *tlscreds,
48 const char *hostname,
216ee365 49 const char *x_dirty_bitmap,
f53a829b
HR
50 Error **errp);
51void nbd_client_close(BlockDriverState *bs);
52
f5a5ca79 53int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
f53a829b 54int nbd_client_co_flush(BlockDriverState *bs);
70c4fb26
EB
55int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
56 uint64_t bytes, QEMUIOVector *qiov, int flags);
fa778fff 57int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
f5a5ca79 58 int bytes, BdrvRequestFlags flags);
70c4fb26
EB
59int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
60 uint64_t bytes, QEMUIOVector *qiov, int flags);
f53a829b
HR
61
62void nbd_client_detach_aio_context(BlockDriverState *bs);
63void nbd_client_attach_aio_context(BlockDriverState *bs,
64 AioContext *new_context);
69447cd8 65
78a33ab5
VSO
66int coroutine_fn nbd_client_co_block_status(BlockDriverState *bs,
67 bool want_zero,
68 int64_t offset, int64_t bytes,
69 int64_t *pnum, int64_t *map,
70 BlockDriverState **file);
71
2302c1ca 72#endif /* NBD_CLIENT_H */