Skip to content

Commit

Permalink
nbd: BLOCK_STATUS constants
Browse files Browse the repository at this point in the history
Expose the new constants and structs that will be used by both
server and client implementations of NBD_CMD_BLOCK_STATUS (the
command is currently experimental at
https://github.com/NetworkBlockDevice/nbd/blob/extension-blockstatus/doc/proto.md
but will hopefully be stabilized soon).

Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
Message-Id: <[email protected]>
[eblake: split from larger patch on server implementation]
Signed-off-by: Eric Blake <[email protected]>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and ebblake committed Mar 1, 2018
1 parent 6bc8695 commit 25c1467
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
31 changes: 31 additions & 0 deletions include/block/nbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ struct NBDOptionReply {
} QEMU_PACKED;
typedef struct NBDOptionReply NBDOptionReply;

typedef struct NBDOptionReplyMetaContext {
NBDOptionReply h; /* h.type = NBD_REP_META_CONTEXT, h.length > 4 */
uint32_t context_id;
/* meta context name follows */
} QEMU_PACKED NBDOptionReplyMetaContext;

/* Transmission phase structs
*
* Note: these are _NOT_ the same as the network representation of an NBD
Expand Down Expand Up @@ -105,6 +111,19 @@ typedef struct NBDStructuredError {
uint16_t message_length;
} QEMU_PACKED NBDStructuredError;

/* Header of NBD_REPLY_TYPE_BLOCK_STATUS */
typedef struct NBDStructuredMeta {
NBDStructuredReplyChunk h; /* h.length >= 12 (at least one extent) */
uint32_t context_id;
/* extents follows */
} QEMU_PACKED NBDStructuredMeta;

/* Extent chunk for NBD_REPLY_TYPE_BLOCK_STATUS */
typedef struct NBDExtent {
uint32_t length;
uint32_t flags; /* NBD_STATE_* */
} QEMU_PACKED NBDExtent;

/* Transmission (export) flags: sent from server to client during handshake,
but describe what will happen during transmission */
#define NBD_FLAG_HAS_FLAGS (1 << 0) /* Flags are there */
Expand Down Expand Up @@ -136,13 +155,16 @@ typedef struct NBDStructuredError {
#define NBD_OPT_INFO (6)
#define NBD_OPT_GO (7)
#define NBD_OPT_STRUCTURED_REPLY (8)
#define NBD_OPT_LIST_META_CONTEXT (9)
#define NBD_OPT_SET_META_CONTEXT (10)

/* Option reply types. */
#define NBD_REP_ERR(value) ((UINT32_C(1) << 31) | (value))

#define NBD_REP_ACK (1) /* Data sending finished. */
#define NBD_REP_SERVER (2) /* Export description. */
#define NBD_REP_INFO (3) /* NBD_OPT_INFO/GO. */
#define NBD_REP_META_CONTEXT (4) /* NBD_OPT_{LIST,SET}_META_CONTEXT */

#define NBD_REP_ERR_UNSUP NBD_REP_ERR(1) /* Unknown option */
#define NBD_REP_ERR_POLICY NBD_REP_ERR(2) /* Server denied */
Expand All @@ -163,6 +185,8 @@ typedef struct NBDStructuredError {
#define NBD_CMD_FLAG_FUA (1 << 0) /* 'force unit access' during write */
#define NBD_CMD_FLAG_NO_HOLE (1 << 1) /* don't punch hole on zero run */
#define NBD_CMD_FLAG_DF (1 << 2) /* don't fragment structured read */
#define NBD_CMD_FLAG_REQ_ONE (1 << 3) /* only one extent in BLOCK_STATUS
* reply chunk */

/* Supported request types */
enum {
Expand All @@ -173,6 +197,7 @@ enum {
NBD_CMD_TRIM = 4,
/* 5 reserved for failed experiment NBD_CMD_CACHE */
NBD_CMD_WRITE_ZEROES = 6,
NBD_CMD_BLOCK_STATUS = 7,
};

#define NBD_DEFAULT_PORT 10809
Expand Down Expand Up @@ -200,9 +225,15 @@ enum {
#define NBD_REPLY_TYPE_NONE 0
#define NBD_REPLY_TYPE_OFFSET_DATA 1
#define NBD_REPLY_TYPE_OFFSET_HOLE 2
#define NBD_REPLY_TYPE_BLOCK_STATUS 5
#define NBD_REPLY_TYPE_ERROR NBD_REPLY_ERR(1)
#define NBD_REPLY_TYPE_ERROR_OFFSET NBD_REPLY_ERR(2)

/* Flags for extents (NBDExtent.flags) of NBD_REPLY_TYPE_BLOCK_STATUS,
* for base:allocation meta context */
#define NBD_STATE_HOLE (1 << 0)
#define NBD_STATE_ZERO (1 << 1)

static inline bool nbd_reply_type_is_error(int type)
{
return type & (1 << 15);
Expand Down
10 changes: 10 additions & 0 deletions nbd/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const char *nbd_opt_lookup(uint32_t opt)
return "go";
case NBD_OPT_STRUCTURED_REPLY:
return "structured reply";
case NBD_OPT_LIST_META_CONTEXT:
return "list meta context";
case NBD_OPT_SET_META_CONTEXT:
return "set meta context";
default:
return "<unknown>";
}
Expand All @@ -90,6 +94,8 @@ const char *nbd_rep_lookup(uint32_t rep)
return "server";
case NBD_REP_INFO:
return "info";
case NBD_REP_META_CONTEXT:
return "meta context";
case NBD_REP_ERR_UNSUP:
return "unsupported";
case NBD_REP_ERR_POLICY:
Expand Down Expand Up @@ -144,6 +150,8 @@ const char *nbd_cmd_lookup(uint16_t cmd)
return "trim";
case NBD_CMD_WRITE_ZEROES:
return "write zeroes";
case NBD_CMD_BLOCK_STATUS:
return "block status";
default:
return "<unknown>";
}
Expand All @@ -159,6 +167,8 @@ const char *nbd_reply_type_lookup(uint16_t type)
return "data";
case NBD_REPLY_TYPE_OFFSET_HOLE:
return "hole";
case NBD_REPLY_TYPE_BLOCK_STATUS:
return "block status";
case NBD_REPLY_TYPE_ERROR:
return "generic error";
case NBD_REPLY_TYPE_ERROR_OFFSET:
Expand Down

0 comments on commit 25c1467

Please sign in to comment.