blob: df80771357c386a289099799fd1b2df83c040c35 [file] [log] [blame]
Marc-André Lureau2302c1c2013-12-01 22:23:41 +01001#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"
Daniel P. Berrange064097d2016-02-10 18:41:01 +00007#include "io/channel-socket.h"
Marc-André Lureau2302c1c2013-12-01 22:23:41 +01008
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
Eric Blake10676b82016-10-14 13:33:06 -050020typedef struct NBDClientSession {
Daniel P. Berrange064097d2016-02-10 18:41:01 +000021 QIOChannelSocket *sioc; /* The master data channel */
22 QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */
Eric Blake004a89f2017-07-07 15:30:41 -050023 NBDExportInfo info;
Marc-André Lureau2302c1c2013-12-01 22:23:41 +010024
25 CoMutex send_mutex;
Changlong Xie9bc97322016-10-12 18:18:28 +080026 CoQueue free_sema;
Paolo Bonziniff829112017-02-13 14:52:24 +010027 Coroutine *read_reply_co;
Marc-André Lureau2302c1c2013-12-01 22:23:41 +010028 int in_flight;
29
30 Coroutine *recv_coroutine[MAX_NBD_REQUESTS];
Eric Blakeed2dd912016-10-14 13:33:07 -050031 NBDReply reply;
Eric Blake10676b82016-10-14 13:33:06 -050032} NBDClientSession;
Marc-André Lureau2302c1c2013-12-01 22:23:41 +010033
Eric Blake10676b82016-10-14 13:33:06 -050034NBDClientSession *nbd_get_client_session(BlockDriverState *bs);
Marc-André Lureau2302c1c2013-12-01 22:23:41 +010035
Daniel P. Berrange064097d2016-02-10 18:41:01 +000036int nbd_client_init(BlockDriverState *bs,
37 QIOChannelSocket *sock,
38 const char *export_name,
Daniel P. Berrange75822a12016-02-10 18:41:12 +000039 QCryptoTLSCreds *tlscreds,
40 const char *hostname,
Max Reitzf53a8292015-02-06 16:06:16 -050041 Error **errp);
42void nbd_client_close(BlockDriverState *bs);
Marc-André Lureau2302c1c2013-12-01 22:23:41 +010043
Manos Pitsidianakisf5a5ca72017-06-09 13:18:08 +030044int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
Max Reitzf53a8292015-02-06 16:06:16 -050045int nbd_client_co_flush(BlockDriverState *bs);
Eric Blake70c4fb22016-07-15 17:23:07 -060046int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
47 uint64_t bytes, QEMUIOVector *qiov, int flags);
Eric Blakefa778ff2016-10-14 13:33:18 -050048int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
Manos Pitsidianakisf5a5ca72017-06-09 13:18:08 +030049 int bytes, BdrvRequestFlags flags);
Eric Blake70c4fb22016-07-15 17:23:07 -060050int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
51 uint64_t bytes, QEMUIOVector *qiov, int flags);
Max Reitzf53a8292015-02-06 16:06:16 -050052
53void nbd_client_detach_aio_context(BlockDriverState *bs);
54void nbd_client_attach_aio_context(BlockDriverState *bs,
55 AioContext *new_context);
Stefan Hajnoczi69447cd2014-05-08 16:34:43 +020056
Marc-André Lureau2302c1c2013-12-01 22:23:41 +010057#endif /* NBD_CLIENT_H */