[Sheepdog] [PATCH 1/3] sheepdog: clean up definitions
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon May 10 00:44:26 CEST 2010
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
block/sheepdog.c | 194 +++++++++++++++++++++++++-----------------------------
1 files changed, 91 insertions(+), 103 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index bdb6270..043b215 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -14,24 +14,15 @@
#define SD_DEFAULT_ADDR "localhost:7000"
-#define SD_OP_NEW_VDI 0x11
-#define SD_OP_DEL_VDI 0x12
-#define SD_OP_LOCK_VDI 0x16
-#define SD_OP_RELEASE_VDI 0x17
-#define SD_OP_GET_VDI_INFO 0x18
-#define SD_OP_GET_NODE_LIST 0x19
-#define SD_OP_GET_VM_LIST 0x20
-#define SD_OP_MAKE_FS 0x21
-#define SD_OP_READ_VDIS 0x25
-
-#define SD_OP_DEBUG_INC_NVER 0xA0
-#define SD_OP_DEBUG_SET_NODE 0xA1
-
#define SD_OP_CREATE_AND_WRITE_OBJ 0x01
-#define SD_OP_REMOVE_OBJ 0x02
-#define SD_OP_READ_OBJ 0x03
-#define SD_OP_WRITE_OBJ 0x04
-#define SD_OP_SYNC_OBJ 0x05
+#define SD_OP_READ_OBJ 0x02
+#define SD_OP_WRITE_OBJ 0x03
+
+#define SD_OP_NEW_VDI 0x11
+#define SD_OP_LOCK_VDI 0x12
+#define SD_OP_RELEASE_VDI 0x13
+#define SD_OP_GET_VDI_INFO 0x14
+#define SD_OP_READ_VDIS 0x15
#define SD_FLAG_CMD_WRITE 0x01
#define SD_FLAG_CMD_COW 0x02
@@ -40,55 +31,45 @@
#define SD_RES_UNKNOWN 0x01 /* Unknown error */
#define SD_RES_NO_OBJ 0x02 /* No object found */
#define SD_RES_EIO 0x03 /* I/O error */
-#define SD_RES_OLD_NODE_VER 0x04 /* Remote node has an old epoch */
-#define SD_RES_NEW_NODE_VER 0x05 /* Remote node has a new epoch */
-#define SD_RES_VDI_EXIST 0x06 /* Vdi exists already */
-#define SD_RES_INVALID_PARMS 0x07 /* Invalid parameters */
-#define SD_RES_SYSTEM_ERROR 0x08 /* System error */
-#define SD_RES_VDI_LOCKED 0x09 /* Vdi is locked */
-#define SD_RES_NO_SUPER_OBJ 0x0A /* No super object found */
-#define SD_RES_NO_VDI 0x0B /* No vdi found */
-#define SD_RES_NO_BASE_VDI 0x0C /* No base vdi found */
-#define SD_RES_DIFFERENT_EPOCH 0x0D /* Epochs are different between nodes */
-#define SD_RES_DIR_READ 0x0E /* Cannot read directory */
-#define SD_RES_DIR_WRITE 0x0F /* Cannot write directory */
-#define SD_RES_VDI_READ 0x10 /* Cannot read requested vdi */
-#define SD_RES_VDI_WRITE 0x11 /* Cannot write requested vdi */
-#define SD_RES_BASE_VDI_READ 0x12 /* Cannot read base vdi */
-#define SD_RES_BASE_VDI_WRITE 0x13 /* Cannot write base vdi */
-#define SD_RES_NO_TAG 0x14 /* Requested tag is not found */
-#define SD_RES_STARTUP 0x15 /* Sheepdog is on starting up */
-#define SD_RES_NO_EPOCH 0x16 /* Requested epoch is not found */
-#define SD_RES_VDI_NOT_LOCKED 0x17 /* Vdi is not locked */
-#define SD_RES_SHUTDOWN 0x18 /* Sheepdog is shutting down */
+#define SD_RES_VDI_EXIST 0x04 /* Vdi exists already */
+#define SD_RES_INVALID_PARMS 0x05 /* Invalid parameters */
+#define SD_RES_SYSTEM_ERROR 0x06 /* System error */
+#define SD_RES_VDI_LOCKED 0x07 /* Vdi is locked */
+#define SD_RES_NO_VDI 0x08 /* No vdi found */
+#define SD_RES_NO_BASE_VDI 0x09 /* No base vdi found */
+#define SD_RES_VDI_READ 0x0A /* Cannot read requested vdi */
+#define SD_RES_VDI_WRITE 0x0B /* Cannot write requested vdi */
+#define SD_RES_BASE_VDI_READ 0x0C /* Cannot read base vdi */
+#define SD_RES_BASE_VDI_WRITE 0x0D /* Cannot write base vdi */
+#define SD_RES_NO_TAG 0x0E /* Requested tag is not found */
+#define SD_RES_STARTUP 0x0F /* Sheepdog is on starting up */
+#define SD_RES_VDI_NOT_LOCKED 0x10 /* Vdi is not locked */
+#define SD_RES_SHUTDOWN 0x11 /* Sheepdog is shutting down */
+#define SD_RES_NO_MEM 0x12 /* Cannot allocate memory */
+#define SD_RES_FULL_VDI 0x13 /* we already have the maximum vdis */
+
+/*
+ * Object ID rules
+ *
+ * 0 - 19 (20 bits): data object space
+ * 20 - 31 (12 bits): reserved data object space
+ * 32 - 55 (24 bits): vdi object space
+ * 56 - 59 ( 4 bits): reserved vdi object space
+ * 60 - 63 ( 4 bits): object type indentifier space
+ */
-#define SD_NR_VDIS (1U << 24)
#define VDI_SPACE_SHIFT 32
#define VDI_BIT (UINT64_C(1) << 63)
#define VMSTATE_BIT (UINT64_C(1) << 62)
-#define DEAFAULT_NR_COPIES 1
-#define SD_MAX_VDI_LEN 256
#define MAX_DATA_OBJS (1ULL << 20)
#define MAX_CHILDREN 1024
-#define SD_DATA_OBJ_SIZE (1UL << 22)
+#define SD_MAX_VDI_LEN 256
+#define SD_NR_VDIS (1U << 24)
+#define SD_DATA_OBJ_SIZE (UINT64_C(1) << 22)
#define SD_INODE_SIZE (sizeof(struct sd_inode))
#define CURRENT_VDI_ID 0
-#undef eprintf
-#define eprintf(fmt, args...) \
-do { \
- fprintf(stderr, "%s %d: " fmt, __func__, __LINE__, ##args); \
-} while (0)
-
-#undef dprintf
-#define dprintf(fmt, args...)
-
-#define min_t(type, x, y) ({ \
- type __min1 = (x); \
- type __min2 = (y); \
- __min1 < __min2 ? __min1: __min2; })
-
struct sd_req {
uint8_t proto_ver;
uint8_t opcode;
@@ -181,6 +162,60 @@ struct sd_inode {
uint32_t data_vdi_id[MAX_DATA_OBJS];
};
+/*
+ * 64 bit FNV-1a non-zero initial basis
+ */
+#define FNV1A_64_INIT ((uint64_t)0xcbf29ce484222325ULL)
+
+/*
+ * 64 bit Fowler/Noll/Vo FNV-1a hash code
+ */
+static inline uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
+{
+ unsigned char *bp = (unsigned char *) buf;
+ unsigned char *be = bp + len;
+ while (bp < be) {
+ hval ^= (uint64_t) *bp++;
+ hval += (hval << 1) + (hval << 4) + (hval << 5) +
+ (hval << 7) + (hval << 8) + (hval << 40);
+ }
+ return hval;
+}
+
+static inline int is_data_obj_writeable(struct sd_inode *inode, unsigned int idx)
+{
+ return inode->vdi_id == inode->data_vdi_id[idx];
+}
+
+static inline uint64_t vid_to_vdi_oid(uint32_t vid)
+{
+ return VDI_BIT | ((uint64_t)vid << VDI_SPACE_SHIFT);
+}
+
+static inline uint64_t vid_to_vmstate_oid(uint32_t vid, uint32_t idx)
+{
+ return VMSTATE_BIT | ((uint64_t)vid << VDI_SPACE_SHIFT) | idx;
+}
+
+static inline uint64_t vid_to_data_oid(uint32_t vid, uint32_t idx)
+{
+ return ((uint64_t)vid << VDI_SPACE_SHIFT) | idx;
+}
+
+#undef eprintf
+#define eprintf(fmt, args...) \
+do { \
+ fprintf(stderr, "%s %d: " fmt, __func__, __LINE__, ##args); \
+} while (0)
+
+#undef dprintf
+#define dprintf(fmt, args...)
+
+#define min_t(type, x, y) ({ \
+ type __min1 = (x); \
+ type __min2 = (y); \
+ __min1 < __min2 ? __min1: __min2; })
+
struct aio_req {
struct sd_aiocb *aiocb;
unsigned int iov_offset;
@@ -252,25 +287,18 @@ static const char * sd_strerror(int err)
{SD_RES_UNKNOWN, "Unknown error"},
{SD_RES_NO_OBJ, "No object found"},
{SD_RES_EIO, "I/O error"},
- {SD_RES_OLD_NODE_VER, "Remote node has an old epoch"},
- {SD_RES_NEW_NODE_VER, "Remote node has a new epoch"},
{SD_RES_VDI_EXIST, "VDI exists already"},
{SD_RES_INVALID_PARMS, "Invalid parameters"},
{SD_RES_SYSTEM_ERROR, "System error"},
{SD_RES_VDI_LOCKED, "VDI is already locked"},
- {SD_RES_NO_SUPER_OBJ, "No superblock found"},
{SD_RES_NO_VDI, "No vdi found"},
{SD_RES_NO_BASE_VDI, "No base VDI found"},
- {SD_RES_DIFFERENT_EPOCH, "Epochs are different between nodes"},
- {SD_RES_DIR_READ, "Failed to read the superblock"},
- {SD_RES_DIR_WRITE, "Failed to write the superblock"},
{SD_RES_VDI_READ, "Failed read the requested VDI"},
{SD_RES_VDI_WRITE, "Failed to write the requested VDI"},
{SD_RES_BASE_VDI_READ, "Failed to read the base VDI"},
{SD_RES_BASE_VDI_WRITE, "Failed to write the base VDI"},
{SD_RES_NO_TAG, "Failed to find the requested tag"},
{SD_RES_STARTUP, "The system is still booting"},
- {SD_RES_NO_EPOCH, "Requested epoch is not found"},
{SD_RES_VDI_NOT_LOCKED, "VDI isn't locked"},
{SD_RES_SHUTDOWN, "The system is shutting down"},
};
@@ -292,46 +320,6 @@ static inline int after(uint32_t seq1, uint32_t seq2)
return (int32_t)(seq2 - seq1) < 0;
}
-static inline int is_data_obj_writeable(struct sd_inode *inode, unsigned int idx)
-{
- return inode->vdi_id == inode->data_vdi_id[idx];
-}
-
-static inline uint64_t vid_to_vdi_oid(uint32_t vid)
-{
- return VDI_BIT | ((uint64_t)vid << VDI_SPACE_SHIFT);
-}
-
-static inline uint64_t vid_to_vmstate_oid(uint32_t vid, uint32_t idx)
-{
- return VMSTATE_BIT | ((uint64_t)vid << VDI_SPACE_SHIFT) | idx;
-}
-
-static inline uint64_t vid_to_data_oid(uint32_t vid, uint32_t idx)
-{
- return ((uint64_t)vid << VDI_SPACE_SHIFT) | idx;
-}
-
-/*
- * 64 bit FNV-1a non-zero initial basis
- */
-#define FNV1A_64_INIT ((uint64_t)0xcbf29ce484222325ULL)
-
-/*
- * 64 bit Fowler/Noll/Vo FNV-1a hash code
- */
-static inline uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
-{
- unsigned char *bp = (unsigned char *) buf;
- unsigned char *be = bp + len;
- while (bp < be) {
- hval ^= (uint64_t) *bp++;
- hval += (hval << 1) + (hval << 4) + (hval << 5) +
- (hval << 7) + (hval << 8) + (hval << 40);
- }
- return hval;
-}
-
static inline struct aio_req *alloc_aio_req(struct bdrv_sd_state *s,
struct sd_aiocb *acb,
uint64_t oid, unsigned int data_len,
--
1.5.6.5
More information about the sheepdog
mailing list