This supports getting epoch number list stored in the epoch directory. Start up routines use this feature. Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp> --- collie/collie.h | 3 +++ collie/net.c | 3 +++ collie/store.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ include/sheepdog_proto.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 0 deletions(-) diff --git a/collie/collie.h b/collie/collie.h index 89eb8f8..37e9dd1 100644 --- a/collie/collie.h +++ b/collie/collie.h @@ -96,6 +96,9 @@ void so_queue_request(struct work *work, int idx); void store_queue_request(struct work *work, int idx); +int get_epoch_list(uint32_t *epoch_list, int *size); +void epoch_queue_request(struct work *work, int idx); + void cluster_queue_request(struct work *work, int idx); int update_epoch_store(uint32_t epoch); diff --git a/collie/net.c b/collie/net.c index 84eecdc..70082ad 100644 --- a/collie/net.c +++ b/collie/net.c @@ -49,6 +49,9 @@ static void queue_request(struct request *req) case SD_OP_GET_OBJ_LIST: req->work.fn = store_queue_request; break; + case SD_OP_GET_EPOCH_LIST: + req->work.fn = epoch_queue_request; + break; case SD_OP_GET_NODE_LIST: case SD_OP_GET_VM_LIST: case SD_OP_NEW_VDI: diff --git a/collie/store.c b/collie/store.c index e46ca46..280fc4a 100644 --- a/collie/store.c +++ b/collie/store.c @@ -1574,3 +1574,49 @@ int init_store(char *d) return ret; } + +int get_epoch_list(uint32_t *epoch_list, int *size) +{ + struct dirent **dent; + int i, n; + + n = scandir(epoch_path, &dent, filter, alphasort); + if (n < 0) + return SD_RES_NO_MEM; + + /* FIXME: handle more epochs */ + if (n > *size) { + eprintf("too many epoch\n"); + n = *size; + } + + for (i = 0; i < n; i++) + epoch_list[i] = atoi(dent[i]->d_name); + + *size = n; + + free(dent); + + return SD_RES_SUCCESS; +} + +void epoch_queue_request(struct work *work, int idx) +{ + struct request *req = container_of(work, struct request, work); + int ret = SD_RES_SUCCESS, n; + struct sd_epoch_req *hdr = (struct sd_epoch_req *)&req->rq; + struct sd_epoch_rsp *rsp = (struct sd_epoch_rsp *)&req->rp; + uint32_t opcode = hdr->opcode; + + switch (opcode) { + case SD_OP_GET_EPOCH_LIST: + n = hdr->data_length / sizeof(uint32_t); + ret = get_epoch_list(req->data, &n); + rsp->data_length = n * sizeof(uint32_t); + break; + } + if (ret != SD_RES_SUCCESS) { + dprintf("failed, %d, %x, %x\n", idx, opcode, ret); + rsp->result = ret; + } +} diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h index cf803b7..64d0016 100644 --- a/include/sheepdog_proto.h +++ b/include/sheepdog_proto.h @@ -36,6 +36,8 @@ #define SD_OP_GET_EPOCH 0x23 #define SD_OP_SHUTDOWN 0x24 +#define SD_OP_GET_EPOCH_LIST 0x25 + #define SD_OP_DEBUG_INC_NVER 0xA0 #define SD_OP_DEBUG_SET_NODE 0xA1 @@ -87,6 +89,7 @@ #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_NO_MEM 0x19 /* Cannot allocate memory */ #define SD_VDI_RSP_FLAG_CURRENT 0x01 @@ -111,6 +114,31 @@ struct sd_rsp { uint32_t opcode_specific[7]; }; +struct sd_epoch_req { + uint8_t proto_ver; + uint8_t opcode; + uint16_t flags; + uint32_t epoch; + uint32_t id; + uint32_t data_length; + uint32_t request_epoch; + uint32_t pad[7]; +}; + +struct sd_epoch_rsp { + uint8_t proto_ver; + uint8_t opcode; + uint16_t flags; + uint32_t epoch; + uint32_t id; + uint32_t data_length; + uint32_t result; + uint32_t is_updated; + uint64_t ctime; + uint64_t hval; + uint32_t pad[2]; +}; + struct sd_so_req { uint8_t proto_ver; uint8_t opcode; -- 1.5.6.5 |