qemu/block/nbd-client.h
<<
>>
Prefs
   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"
   7#include "io/channel-socket.h"
   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
  20typedef struct {
  21    Coroutine *coroutine;
  22    uint64_t offset;        /* original offset of the request */
  23    bool receiving;         /* waiting for read_reply_co? */
  24} NBDClientRequest;
  25
  26typedef struct NBDClientSession {
  27    QIOChannelSocket *sioc; /* The master data channel */
  28    QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */
  29    NBDExportInfo info;
  30
  31    CoMutex send_mutex;
  32    CoQueue free_sema;
  33    Coroutine *read_reply_co;
  34    int in_flight;
  35
  36    NBDClientRequest requests[MAX_NBD_REQUESTS];
  37    NBDReply reply;
  38    bool quit;
  39} NBDClientSession;
  40
  41NBDClientSession *nbd_get_client_session(BlockDriverState *bs);
  42
  43int nbd_client_init(BlockDriverState *bs,
  44                    QIOChannelSocket *sock,
  45                    const char *export_name,
  46                    QCryptoTLSCreds *tlscreds,
  47                    const char *hostname,
  48                    Error **errp);
  49void nbd_client_close(BlockDriverState *bs);
  50
  51int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes);
  52int nbd_client_co_flush(BlockDriverState *bs);
  53int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
  54                          uint64_t bytes, QEMUIOVector *qiov, int flags);
  55int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
  56                                int bytes, BdrvRequestFlags flags);
  57int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
  58                         uint64_t bytes, QEMUIOVector *qiov, int flags);
  59
  60void nbd_client_detach_aio_context(BlockDriverState *bs);
  61void nbd_client_attach_aio_context(BlockDriverState *bs,
  62                                   AioContext *new_context);
  63
  64int coroutine_fn nbd_client_co_block_status(BlockDriverState *bs,
  65                                            bool want_zero,
  66                                            int64_t offset, int64_t bytes,
  67                                            int64_t *pnum, int64_t *map,
  68                                            BlockDriverState **file);
  69
  70#endif /* NBD_CLIENT_H */
  71