mirror of
https://github.com/qemu/qemu.git
synced 2024-12-11 12:43:55 +08:00
fa778fffdf
Upstream NBD protocol recently added the ability to efficiently write zeroes without having to send the zeroes over the wire, along with a flag to control whether the client wants a hole. The generic block code takes care of falling back to the obvious write of lots of zeroes if we return -ENOTSUP because the server does not have WRITE_ZEROES. Ideally, since NBD_CMD_WRITE_ZEROES does not involve any data over the wire, we want to support transactions that are much larger than the normal 32M limit imposed on NBD_CMD_WRITE. But the server may still have a limit smaller than UINT_MAX, so until experimental NBD protocol additions for advertising various command sizes is finalized (see [1], [2]), for now we just stick to the same limits as normal writes. [1] https://github.com/yoe/nbd/blob/extension-info/doc/proto.md [2] https://sourceforge.net/p/nbd/mailman/message/35081223/ Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1476469998-28592-17-git-send-email-eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
61 lines
1.9 KiB
C
61 lines
1.9 KiB
C
#ifndef NBD_CLIENT_H
|
|
#define NBD_CLIENT_H
|
|
|
|
#include "qemu-common.h"
|
|
#include "block/nbd.h"
|
|
#include "block/block_int.h"
|
|
#include "io/channel-socket.h"
|
|
|
|
/* #define DEBUG_NBD */
|
|
|
|
#if defined(DEBUG_NBD)
|
|
#define logout(fmt, ...) \
|
|
fprintf(stderr, "nbd\t%-24s" fmt, __func__, ##__VA_ARGS__)
|
|
#else
|
|
#define logout(fmt, ...) ((void)0)
|
|
#endif
|
|
|
|
#define MAX_NBD_REQUESTS 16
|
|
|
|
typedef struct NBDClientSession {
|
|
QIOChannelSocket *sioc; /* The master data channel */
|
|
QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */
|
|
uint16_t nbdflags;
|
|
off_t size;
|
|
|
|
CoMutex send_mutex;
|
|
CoQueue free_sema;
|
|
Coroutine *send_coroutine;
|
|
int in_flight;
|
|
|
|
Coroutine *recv_coroutine[MAX_NBD_REQUESTS];
|
|
NBDReply reply;
|
|
|
|
bool is_unix;
|
|
} NBDClientSession;
|
|
|
|
NBDClientSession *nbd_get_client_session(BlockDriverState *bs);
|
|
|
|
int nbd_client_init(BlockDriverState *bs,
|
|
QIOChannelSocket *sock,
|
|
const char *export_name,
|
|
QCryptoTLSCreds *tlscreds,
|
|
const char *hostname,
|
|
Error **errp);
|
|
void nbd_client_close(BlockDriverState *bs);
|
|
|
|
int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int count);
|
|
int nbd_client_co_flush(BlockDriverState *bs);
|
|
int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
|
|
uint64_t bytes, QEMUIOVector *qiov, int flags);
|
|
int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
|
|
int count, BdrvRequestFlags flags);
|
|
int nbd_client_co_preadv(BlockDriverState *bs, uint64_t offset,
|
|
uint64_t bytes, QEMUIOVector *qiov, int flags);
|
|
|
|
void nbd_client_detach_aio_context(BlockDriverState *bs);
|
|
void nbd_client_attach_aio_context(BlockDriverState *bs,
|
|
AioContext *new_context);
|
|
|
|
#endif /* NBD_CLIENT_H */
|