mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 20:19:44 +00:00
7423f41782
Rather than asserting that nbdflags is within range, just give it the correct type to begin with :) nbdflags corresponds to the per-export portion of NBD Protocol "transmission flags", which is 16 bits in response to NBD_OPT_EXPORT_NAME and NBD_OPT_GO. Furthermore, upstream NBD has never passed the global flags to the kernel via ioctl(NBD_SET_FLAGS) (the ioctl was first introduced in NBD 2.9.22; then a latent bug in NBD 3.1 actually tried to OR the global flags with the transmission flags, with the disaster that the addition of NBD_FLAG_NO_ZEROES in 3.9 caused all earlier NBD 3.x clients to treat every export as read-only; NBD 3.10 and later intentionally clip things to 16 bits to pass only transmission flags). Qemu should follow suit, since the current two global flags (NBD_FLAG_FIXED_NEWSTYLE and NBD_FLAG_NO_ZEROES) have no impact on the kernel's behavior during transmission. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1469129688-22848-3-git-send-email-eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
59 lines
1.7 KiB
C
59 lines
1.7 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;
|
|
CoMutex free_sema;
|
|
Coroutine *send_coroutine;
|
|
int in_flight;
|
|
|
|
Coroutine *recv_coroutine[MAX_NBD_REQUESTS];
|
|
struct nbd_reply 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_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 */
|