Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 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" |
Daniel P. Berrange | 064097d | 2016-02-10 18:41:01 +0000 | [diff] [blame] | 7 | #include "io/channel-socket.h" |
Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 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 | |
Eric Blake | 10676b8 | 2016-10-14 13:33:06 -0500 | [diff] [blame] | 20 | typedef struct NBDClientSession { |
Daniel P. Berrange | 064097d | 2016-02-10 18:41:01 +0000 | [diff] [blame] | 21 | QIOChannelSocket *sioc; /* The master data channel */ |
| 22 | QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */ |
Eric Blake | 004a89f | 2017-07-07 15:30:41 -0500 | [diff] [blame] | 23 | NBDExportInfo info; |
Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 24 | |
| 25 | CoMutex send_mutex; |
Changlong Xie | 9bc9732 | 2016-10-12 18:18:28 +0800 | [diff] [blame] | 26 | CoQueue free_sema; |
Paolo Bonzini | ff82911 | 2017-02-13 14:52:24 +0100 | [diff] [blame] | 27 | Coroutine *read_reply_co; |
Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 28 | int in_flight; |
| 29 | |
| 30 | Coroutine *recv_coroutine[MAX_NBD_REQUESTS]; |
Eric Blake | ed2dd91 | 2016-10-14 13:33:07 -0500 | [diff] [blame] | 31 | NBDReply reply; |
Eric Blake | 10676b8 | 2016-10-14 13:33:06 -0500 | [diff] [blame] | 32 | } NBDClientSession; |
Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 33 | |
Eric Blake | 10676b8 | 2016-10-14 13:33:06 -0500 | [diff] [blame] | 34 | NBDClientSession *nbd_get_client_session(BlockDriverState *bs); |
Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 35 | |
Daniel P. Berrange | 064097d | 2016-02-10 18:41:01 +0000 | [diff] [blame] | 36 | int nbd_client_init(BlockDriverState *bs, |
| 37 | QIOChannelSocket *sock, |
| 38 | const char *export_name, |
Daniel P. Berrange | 75822a1 | 2016-02-10 18:41:12 +0000 | [diff] [blame] | 39 | QCryptoTLSCreds *tlscreds, |
| 40 | const char *hostname, |
Max Reitz | f53a829 | 2015-02-06 16:06:16 -0500 | [diff] [blame] | 41 | Error **errp); |
| 42 | void nbd_client_close(BlockDriverState *bs); |
Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 43 | |
Manos Pitsidianakis | f5a5ca7 | 2017-06-09 13:18:08 +0300 | [diff] [blame] | 44 | int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes); |
Max Reitz | f53a829 | 2015-02-06 16:06:16 -0500 | [diff] [blame] | 45 | int nbd_client_co_flush(BlockDriverState *bs); |
Eric Blake | 70c4fb2 | 2016-07-15 17:23:07 -0600 | [diff] [blame] | 46 | int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, |
| 47 | uint64_t bytes, QEMUIOVector *qiov, int flags); |
Eric Blake | fa778ff | 2016-10-14 13:33:18 -0500 | [diff] [blame] | 48 | int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, |
Manos Pitsidianakis | f5a5ca7 | 2017-06-09 13:18:08 +0300 | [diff] [blame] | 49 | int bytes, BdrvRequestFlags flags); |
Eric Blake | 70c4fb2 | 2016-07-15 17:23:07 -0600 | [diff] [blame] | 50 | int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset, |
| 51 | uint64_t bytes, QEMUIOVector *qiov, int flags); |
Max Reitz | f53a829 | 2015-02-06 16:06:16 -0500 | [diff] [blame] | 52 | |
| 53 | void nbd_client_detach_aio_context(BlockDriverState *bs); |
| 54 | void nbd_client_attach_aio_context(BlockDriverState *bs, |
| 55 | AioContext *new_context); |
Stefan Hajnoczi | 69447cd | 2014-05-08 16:34:43 +0200 | [diff] [blame] | 56 | |
Marc-André Lureau | 2302c1c | 2013-12-01 22:23:41 +0100 | [diff] [blame] | 57 | #endif /* NBD_CLIENT_H */ |