[Sheepdog] [PATCH 1/3] clean up header files

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Mon May 10 00:41:01 CEST 2010


Header files about sheepdog protocols are grouped into three.

include/sheepdog_proto.h - used between server and VM
include/collie.h         - used in the server (including shepherd)
collie/collie_priv.h     - internal to collie daemons

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/collie.c          |    2 +-
 collie/collie.h          |  173 ------------------------------
 collie/collie_priv.h     |  199 +++++++++++++++++++++++++++++++++++
 collie/group.c           |   28 ++++-
 collie/net.c             |  143 +++++++++++++++++++++++++-
 collie/store.c           |    3 +-
 collie/vdi.c             |    3 +-
 include/collie.h         |  175 +++++++++++++++++++++++++++++++
 include/meta.h           |   84 ---------------
 include/net.h            |   12 --
 include/sheepdog_proto.h |  260 +++++++++++++---------------------------------
 lib/net.c                |  139 ------------------------
 shepherd/shepherd.c      |   51 +++++----
 13 files changed, 642 insertions(+), 630 deletions(-)
 delete mode 100644 collie/collie.h
 create mode 100644 collie/collie_priv.h
 create mode 100644 include/collie.h
 delete mode 100644 include/meta.h

diff --git a/collie/collie.c b/collie/collie.c
index 8c31ff6..03cf990 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -16,7 +16,7 @@
 #include <linux/limits.h>
 #include <sys/syslog.h>
 
-#include "collie.h"
+#include "collie_priv.h"
 
 #define EPOLL_SIZE 4096
 #define DEFAULT_OBJECT_DIR "/tmp"
diff --git a/collie/collie.h b/collie/collie.h
deleted file mode 100644
index b52e457..0000000
--- a/collie/collie.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2009-2010 Nippon Telegraph and Telephone Corporation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef __COLLIE_H__
-#define __COLLIE_H__
-
-#include <inttypes.h>
-#include <corosync/cpg.h>
-
-#include "sheepdog_proto.h"
-#include "event.h"
-#include "logger.h"
-#include "work.h"
-#include "net.h"
-#include "meta.h"
-
-#define SD_MSG_JOIN             0x01
-#define SD_MSG_VDI_OP           0x02
-#define SD_MSG_MASTER_CHANGED   0x03
-
-enum cpg_event_type {
-	CPG_EVENT_CONCHG,
-	CPG_EVENT_DELIVER,
-	CPG_EVENT_REQUEST,
-};
-
-struct cpg_event {
-	enum cpg_event_type ctype;
-	struct list_head cpg_event_list;
-	unsigned int skip;
-};
-
-struct client_info {
-	struct connection conn;
-
-	struct request *rx_req;
-
-	struct request *tx_req;
-
-	struct list_head reqs;
-	struct list_head done_reqs;
-};
-
-struct request;
-
-typedef void (*req_end_t) (struct request *);
-
-struct request {
-	struct cpg_event cev;
-	struct sd_req rq;
-	struct sd_rsp rp;
-
-	void *data;
-
-	struct client_info *ci;
-	struct list_head r_siblings;
-	struct list_head r_wlist;
-	struct list_head pending_list;
-
-	uint64_t local_oid[2];
-
-	struct sheepdog_node_list_entry entry[SD_MAX_NODES];
-	int nr_nodes;
-
-	req_end_t done;
-	struct work work;
-};
-
-struct cluster_info {
-	cpg_handle_t handle;
-	/* set after finishing the JOIN procedure */
-	int join_finished;
-	uint32_t this_nodeid;
-	uint32_t this_pid;
-	struct sheepdog_node_list_entry this_node;
-
-	uint32_t epoch;
-	uint32_t status;
-
-	/*
-	 * we add a node to cpg_node_list in confchg then move it to
-	 * sd_node_list when the node joins sheepdog.
-	 */
-	struct list_head cpg_node_list;
-	struct list_head sd_node_list;
-
-	struct list_head vm_list;
-	struct list_head pending_list;
-
-	DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
-
-	struct list_head outstanding_req_list;
-	struct list_head req_wait_for_obj_list;
-
-	uint32_t nr_sobjs;
-
-	struct list_head cpg_event_siblings;
-	struct cpg_event *cur_cevent;
-	unsigned long cpg_event_work_flags;
-	int nr_outstanding_io;
-};
-
-extern struct cluster_info *sys;
-
-int create_listen_port(int port, void *data);
-
-int is_io_request(unsigned op);
-int init_store(char *dir);
-
-int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
-	    uint32_t *new_vid, uint32_t base_vid, uint32_t copies,
-	    int is_snapshot);
-
-int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t snapid);
-
-int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t snapid);
-
-int read_vdis(char *data, int len, unsigned int *rsp_len);
-
-int setup_ordered_sd_node_list(struct request *req);
-int get_ordered_sd_node_list(struct sheepdog_node_list_entry *entries);
-int is_access_to_busy_objects(uint64_t oid);
-
-void resume_pending_requests(void);
-
-int create_cluster(int port);
-
-void start_cpg_event_work(void);
-void store_queue_request(struct work *work, int idx);
-
-int read_epoch(uint32_t *epoch, uint64_t *ctime,
-	       struct sheepdog_node_list_entry *entries, int *nr_entries);
-void cluster_queue_request(struct work *work, int idx);
-
-int update_epoch_store(uint32_t epoch);
-
-int set_global_nr_copies(uint32_t copies);
-int get_global_nr_copies(uint32_t *copies);
-int set_nodeid(uint64_t nodeid);
-int get_nodeid(uint64_t *nodeid);
-
-#define NR_WORKER_THREAD 4
-
-int epoch_log_write(uint32_t epoch, char *buf, int len);
-int epoch_log_read(uint32_t epoch, char *buf, int len);
-int get_latest_epoch(void);
-int remove_epoch(int epoch);
-int set_cluster_ctime(uint64_t ctime);
-uint64_t get_cluster_ctime(void);
-
-int start_recovery(uint32_t epoch, uint32_t *failed_vdis, int nr_failed_vdis);
-void resume_recovery_work(void);
-int is_recoverying_oid(uint64_t oid);
-
-static inline int is_myself(struct sheepdog_node_list_entry *e)
-{
-	return e->id == sys->this_node.id;
-}
-
-#define panic(fmt, args...)			\
-({						\
-	vprintf(SDOG_EMERG fmt, ##args);	\
-	exit(1);				\
-})
-
-#endif
diff --git a/collie/collie_priv.h b/collie/collie_priv.h
new file mode 100644
index 0000000..35f0a54
--- /dev/null
+++ b/collie/collie_priv.h
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2009-2010 Nippon Telegraph and Telephone Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __COLLIE_PRIV_H__
+#define __COLLIE_PRIV_H__
+
+#include <inttypes.h>
+#include <corosync/cpg.h>
+
+#include "sheepdog_proto.h"
+#include "event.h"
+#include "logger.h"
+#include "work.h"
+#include "net.h"
+#include "collie.h"
+
+#define SD_MAX_REDUNDANCY 8
+
+#define SD_OP_REMOVE_OBJ     0x91
+#define SD_OP_SYNC_OBJ       0x92
+
+#define SD_OP_GET_OBJ_LIST   0xA1
+
+#define SD_MSG_JOIN             0x01
+#define SD_MSG_VDI_OP           0x02
+#define SD_MSG_MASTER_CHANGED   0x03
+
+#define SD_STATUS_OK                0x00
+#define SD_STATUS_WAIT_FOR_FORMAT   0x01
+#define SD_STATUS_WAIT_FOR_JOIN     0x02
+#define SD_STATUS_SHUTDOWN          0x03
+#define SD_STATUS_INCONSISTENT_EPOCHS   0x04
+#define SD_STATUS_JOIN_FAILED       0x05
+
+enum cpg_event_type {
+	CPG_EVENT_CONCHG,
+	CPG_EVENT_DELIVER,
+	CPG_EVENT_REQUEST,
+};
+
+struct cpg_event {
+	enum cpg_event_type ctype;
+	struct list_head cpg_event_list;
+	unsigned int skip;
+};
+
+struct client_info {
+	struct connection conn;
+
+	struct request *rx_req;
+
+	struct request *tx_req;
+
+	struct list_head reqs;
+	struct list_head done_reqs;
+};
+
+struct request;
+
+typedef void (*req_end_t) (struct request *);
+
+struct request {
+	struct cpg_event cev;
+	struct sd_req rq;
+	struct sd_rsp rp;
+
+	void *data;
+
+	struct client_info *ci;
+	struct list_head r_siblings;
+	struct list_head r_wlist;
+	struct list_head pending_list;
+
+	uint64_t local_oid[2];
+
+	struct sheepdog_node_list_entry entry[SD_MAX_NODES];
+	int nr_nodes;
+
+	req_end_t done;
+	struct work work;
+};
+
+struct cluster_info {
+	cpg_handle_t handle;
+	/* set after finishing the JOIN procedure */
+	int join_finished;
+	uint32_t this_nodeid;
+	uint32_t this_pid;
+	struct sheepdog_node_list_entry this_node;
+
+	uint32_t epoch;
+	uint32_t status;
+
+	/*
+	 * we add a node to cpg_node_list in confchg then move it to
+	 * sd_node_list when the node joins sheepdog.
+	 */
+	struct list_head cpg_node_list;
+	struct list_head sd_node_list;
+
+	struct list_head vm_list;
+	struct list_head pending_list;
+
+	DECLARE_BITMAP(vdi_inuse, SD_NR_VDIS);
+
+	struct list_head outstanding_req_list;
+	struct list_head req_wait_for_obj_list;
+
+	uint32_t nr_sobjs;
+
+	struct list_head cpg_event_siblings;
+	struct cpg_event *cur_cevent;
+	unsigned long cpg_event_work_flags;
+	int nr_outstanding_io;
+};
+
+extern struct cluster_info *sys;
+
+int create_listen_port(int port, void *data);
+
+int is_io_request(unsigned op);
+int init_store(char *dir);
+
+int add_vdi(uint32_t epoch, char *data, int data_len, uint64_t size,
+	    uint32_t *new_vid, uint32_t base_vid, uint32_t copies,
+	    int is_snapshot);
+
+int del_vdi(uint32_t epoch, char *data, int data_len, uint32_t snapid);
+
+int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid, uint32_t snapid);
+
+int read_vdis(char *data, int len, unsigned int *rsp_len);
+
+int setup_ordered_sd_node_list(struct request *req);
+int get_ordered_sd_node_list(struct sheepdog_node_list_entry *entries);
+int is_access_to_busy_objects(uint64_t oid);
+
+void resume_pending_requests(void);
+
+int create_cluster(int port);
+
+void start_cpg_event_work(void);
+void store_queue_request(struct work *work, int idx);
+
+int read_epoch(uint32_t *epoch, uint64_t *ctime,
+	       struct sheepdog_node_list_entry *entries, int *nr_entries);
+void cluster_queue_request(struct work *work, int idx);
+
+int update_epoch_store(uint32_t epoch);
+
+int set_global_nr_copies(uint32_t copies);
+int get_global_nr_copies(uint32_t *copies);
+int set_nodeid(uint64_t nodeid);
+int get_nodeid(uint64_t *nodeid);
+
+#define NR_WORKER_THREAD 4
+
+int epoch_log_write(uint32_t epoch, char *buf, int len);
+int epoch_log_read(uint32_t epoch, char *buf, int len);
+int get_latest_epoch(void);
+int remove_epoch(int epoch);
+int set_cluster_ctime(uint64_t ctime);
+uint64_t get_cluster_ctime(void);
+
+int start_recovery(uint32_t epoch, uint32_t *failed_vdis, int nr_failed_vdis);
+void resume_recovery_work(void);
+int is_recoverying_oid(uint64_t oid);
+
+int write_object(struct sheepdog_node_list_entry *e,
+		 int nodes, uint32_t node_version,
+		 uint64_t oid, char *data, unsigned int datalen,
+		 uint64_t offset, int nr, int create);
+int read_object(struct sheepdog_node_list_entry *e,
+		int nodes, uint32_t node_version,
+		uint64_t oid, char *data, unsigned int datalen,
+		uint64_t offset, int nr);
+int remove_object(struct sheepdog_node_list_entry *e,
+		  int nodes, uint32_t node_version,
+		  uint64_t oid, int nr);
+
+static inline int is_myself(struct sheepdog_node_list_entry *e)
+{
+	return e->id == sys->this_node.id;
+}
+
+#define panic(fmt, args...)			\
+({						\
+	vprintf(SDOG_EMERG fmt, ##args);	\
+	exit(1);				\
+})
+
+#endif
diff --git a/collie/group.c b/collie/group.c
index 9e57656..c41f918 100644
--- a/collie/group.c
+++ b/collie/group.c
@@ -18,10 +18,9 @@
 #include <corosync/cfg.h>
 
 #include "sheepdog_proto.h"
-#include "collie.h"
+#include "collie_priv.h"
 #include "list.h"
 #include "util.h"
-#include "meta.h"
 #include "logger.h"
 #include "work.h"
 
@@ -264,7 +263,6 @@ void cluster_queue_request(struct work *work, int idx)
 	case SD_OP_STAT_CLUSTER:
 		log = (struct epoch_log *)req->data;
 
-		((struct sd_vdi_rsp *)rsp)->rsvd = sys->status;
 		log->ctime = get_cluster_ctime();
 		log->epoch = get_latest_epoch();
 		log->nr_nodes = epoch_log_read(log->epoch, (char *)log->nodes,
@@ -277,7 +275,29 @@ void cluster_queue_request(struct work *work, int idx)
 			log->nr_nodes /= sizeof(log->nodes[0]);
 		}
 
-		rsp->result = SD_RES_SUCCESS;
+		switch (sys->status) {
+		case SD_STATUS_OK:
+			ret = SD_RES_SUCCESS;
+			break;
+		case SD_STATUS_WAIT_FOR_FORMAT:
+			ret = SD_RES_WAIT_FOR_FORMAT;
+			break;
+		case SD_STATUS_WAIT_FOR_JOIN:
+			ret = SD_RES_WAIT_FOR_JOIN;
+			break;
+		case SD_STATUS_SHUTDOWN:
+			ret = SD_RES_SHUTDOWN;
+			break;
+		case SD_STATUS_INCONSISTENT_EPOCHS:
+			ret = SD_RES_INCONSISTENT_EPOCHS;
+			break;
+		case SD_STATUS_JOIN_FAILED:
+			ret = SD_RES_JOIN_FAILED;
+			break;
+		default:
+			ret = SD_RES_SYSTEM_ERROR;
+			break;
+		}
 		break;
 	default:
 		/* forward request to group */
diff --git a/collie/net.c b/collie/net.c
index 9cc87b9..87c27da 100644
--- a/collie/net.c
+++ b/collie/net.c
@@ -14,7 +14,7 @@
 #include <netinet/tcp.h>
 #include <sys/epoll.h>
 
-#include "collie.h"
+#include "collie_priv.h"
 
 int is_io_request(unsigned op)
 {
@@ -150,7 +150,7 @@ static void queue_request(struct request *req)
 	struct sd_req *hdr = (struct sd_req *)&req->rq;
 	struct sd_rsp *rsp = (struct sd_rsp *)&req->rp;
 
-	if (hdr->opcode == SD_OP_DEBUG_KILL) {
+	if (hdr->opcode == SD_OP_KILL_NODE) {
 		log_close();
 		exit(1);
 	}
@@ -501,3 +501,142 @@ int create_listen_port(int port, void *data)
 {
 	return create_listen_ports(port, create_listen_port_fn, data);
 }
+
+int write_object(struct sheepdog_node_list_entry *e,
+		 int nodes, uint32_t node_version,
+		 uint64_t oid, char *data, unsigned int datalen,
+		 uint64_t offset, int nr, int create)
+{
+	struct sd_obj_req hdr;
+	int i, n, fd, ret, success = 0;
+	uint16_t vosts[3];
+	char name[128];
+
+	for (i = 0; i < nr; i++) {
+		unsigned rlen = 0, wlen = datalen;
+
+		n = obj_to_sheep(e, nodes, oid, i);
+
+		addr_to_str(name, sizeof(name), e[n].addr, 0);
+
+		fd = connect_to(name, e[n].port);
+		if (fd < 0) {
+			eprintf("can't connect to vost %u, %s\n", vosts[i], name);
+			continue;
+		}
+
+		memset(&hdr, 0, sizeof(hdr));
+		hdr.epoch = node_version;
+		if (create)
+			hdr.opcode = SD_OP_CREATE_AND_WRITE_OBJ;
+		else
+			hdr.opcode = SD_OP_WRITE_OBJ;
+
+		hdr.oid = oid;
+		hdr.copies = nr;
+
+		hdr.flags = SD_FLAG_CMD_WRITE | SD_FLAG_CMD_DIRECT;
+		hdr.data_length = wlen;
+		hdr.offset = offset;
+
+		ret = exec_req(fd, (struct sd_req *)&hdr, data, &wlen, &rlen);
+		close(fd);
+		if (ret)
+			eprintf("can't update vost %u, %s\n", vosts[i], name);
+		else
+			success++;
+	}
+
+	return !success;
+}
+
+int read_object(struct sheepdog_node_list_entry *e,
+		int nodes, uint32_t node_version,
+		uint64_t oid, char *data, unsigned int datalen,
+		uint64_t offset, int nr)
+{
+	struct sd_obj_req hdr;
+	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
+	char name[128];
+	int i = 0, n, fd, ret;
+
+	for (i = 0; i < nr; i++) {
+		unsigned wlen = 0, rlen = datalen;
+
+		n = obj_to_sheep(e, nodes, oid, i);
+
+		addr_to_str(name, sizeof(name), e[n].addr, 0);
+
+		fd = connect_to(name, e[n].port);
+		if (fd < 0) {
+			printf("%s(%d): %s, %m\n", __func__, __LINE__,
+			       name);
+			return -1;
+		}
+
+		memset(&hdr, 0, sizeof(hdr));
+		hdr.epoch = node_version;
+		hdr.opcode = SD_OP_READ_OBJ;
+		hdr.oid = oid;
+
+		hdr.flags =  SD_FLAG_CMD_DIRECT;
+		hdr.data_length = rlen;
+		hdr.offset = offset;
+
+		ret = exec_req(fd, (struct sd_req *)&hdr, data, &wlen, &rlen);
+		close(fd);
+
+		if (!ret) {
+			if (rsp->result == SD_RES_SUCCESS)
+				return rsp->data_length;
+		}
+	}
+
+	return -1;
+}
+
+int remove_object(struct sheepdog_node_list_entry *e,
+		  int nodes, uint32_t node_version,
+		  uint64_t oid, int nr)
+{
+	char name[128];
+	struct sd_obj_req hdr;
+	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
+	int i = 0, n, fd, ret;
+
+	if (nr > nodes)
+		nr = nodes;
+
+	for (i = 0; i < nr; i++) {
+		unsigned wlen = 0, rlen = 0;
+
+		n = obj_to_sheep(e, nodes, oid, i);
+
+		addr_to_str(name, sizeof(name), e[n].addr, 0);
+
+		fd = connect_to(name, e[n].port);
+		if (fd < 0) {
+			rsp->result = SD_RES_EIO;
+			return -1;
+		}
+
+		memset(&hdr, 0, sizeof(hdr));
+		hdr.epoch = node_version;
+		hdr.opcode = SD_OP_REMOVE_OBJ;
+		hdr.oid = oid;
+
+		hdr.flags = 0;
+		hdr.data_length = rlen;
+
+		ret = exec_req(fd, (struct sd_req *)&hdr, NULL, &wlen, &rlen);
+		close(fd);
+
+		if (ret)
+			return -1;
+	}
+
+	if (rsp->result != SD_RES_SUCCESS)
+		return -1;
+
+	return 0;
+}
diff --git a/collie/store.c b/collie/store.c
index 0e8340b..d4d3211 100644
--- a/collie/store.c
+++ b/collie/store.c
@@ -19,8 +19,7 @@
 #include <sys/xattr.h>
 #include <sys/statvfs.h>
 
-#include "collie.h"
-#include "meta.h"
+#include "collie_priv.h"
 
 #define ANAME_CTIME "user.sheepdog.ctime"
 #define ANAME_COPIES "user.sheepdog.copies"
diff --git a/collie/vdi.c b/collie/vdi.c
index 4798382..150af9e 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -13,8 +13,7 @@
 #include <sys/time.h>
 
 #include "sheepdog_proto.h"
-#include "meta.h"
-#include "collie.h"
+#include "collie_priv.h"
 
 
 /* TODO: should be performed atomically */
diff --git a/include/collie.h b/include/collie.h
new file mode 100644
index 0000000..b3c8264
--- /dev/null
+++ b/include/collie.h
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2009-2010 Nippon Telegraph and Telephone Corporation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __COLLIE_H__
+#define __COLLIE_H__
+
+#include <stdint.h>
+#include "util.h"
+#include "list.h"
+
+#define SD_MAX_NODES 1024
+#define SD_MAX_VMS   4096 /* FIXME: should be removed */
+
+#define SD_OP_DEL_VDI        0x81
+#define SD_OP_GET_NODE_LIST  0x82
+#define SD_OP_GET_VM_LIST    0x83
+#define SD_OP_MAKE_FS        0x84
+#define SD_OP_SHUTDOWN       0x85
+#define SD_OP_STAT_SHEEP     0x86
+#define SD_OP_STAT_CLUSTER   0x87
+#define SD_OP_KILL_NODE      0x88
+
+#define SD_FLAG_CMD_DIRECT   0x10
+#define SD_FLAG_CMD_RECOVERY 0x20
+
+#define SD_RES_OLD_NODE_VER  0x41 /* Remote node has an old epoch */
+#define SD_RES_NEW_NODE_VER  0x42 /* Remote node has a new epoch */
+#define SD_RES_WAIT_FOR_FORMAT      0x43 /* Sheepdog is waiting for a format operation */
+#define SD_RES_WAIT_FOR_JOIN        0x44 /* Sheepdog is waiting for other nodes joining */
+#define SD_RES_NOT_FORMATTED 0x45 /* Sheepdog is not formatted yet */
+#define SD_RES_INVALID_CTIME 0x46 /* Creation time of sheepdog is different */
+#define SD_RES_INVALID_EPOCH 0x47 /* Invalid epoch */
+#define SD_RES_INCONSISTENT_EPOCHS  0x48 /* There is inconsistency between epochs */
+#define SD_RES_JOIN_FAILED   0x49 /* Target node was failed to join sheepdog */
+
+struct sd_so_req {
+	uint8_t		proto_ver;
+	uint8_t		opcode;
+	uint16_t	flags;
+	uint32_t	epoch;
+	uint32_t        id;
+	uint32_t        data_length;
+	uint64_t	oid;
+	uint64_t	ctime;
+	uint32_t	copies;
+	uint32_t	tag;
+	uint32_t	opcode_specific[2];
+};
+
+struct sd_so_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	copies;
+	uint64_t	ctime;
+	uint64_t	oid;
+	uint32_t	opcode_specific[2];
+};
+
+struct sd_list_req {
+	uint8_t		proto_ver;
+	uint8_t		opcode;
+	uint16_t	flags;
+	uint32_t	epoch;
+	uint32_t        id;
+	uint32_t        data_length;
+	uint64_t        start;
+	uint64_t        end;
+	uint32_t        tgt_epoch;
+	uint32_t        pad[3];
+};
+
+struct sd_list_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        rsvd;
+	uint64_t        next;
+	uint32_t        pad[4];
+};
+
+struct sd_node_req {
+	uint8_t		proto_ver;
+	uint8_t		opcode;
+	uint16_t	flags;
+	uint32_t	epoch;
+	uint32_t        id;
+	uint32_t        data_length;
+	uint32_t	request_ver;
+	uint32_t	pad[7];
+};
+
+struct sd_node_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	nr_nodes;
+	uint32_t	local_idx;
+	uint32_t	master_idx;
+	uint64_t	store_size;
+	uint64_t	store_free;
+};
+
+struct sheepdog_vm_list_entry {
+	uint8_t         name[SD_MAX_VDI_LEN];
+	uint8_t         host_addr[16];
+	uint16_t        host_port;
+	uint8_t	        pad[6];
+};
+
+struct sheepdog_node_list_entry {
+	uint64_t        id;
+	uint8_t         addr[16];
+	uint16_t        port;
+	uint16_t	pad[3];
+};
+
+struct epoch_log {
+	uint64_t ctime;
+	uint32_t epoch;
+	uint32_t nr_nodes;
+	struct sheepdog_node_list_entry nodes[SD_MAX_NODES];
+};
+
+static inline int hval_to_sheep(struct sheepdog_node_list_entry *entries,
+				int nr_entries, uint64_t id, int idx)
+{
+	int i;
+	struct sheepdog_node_list_entry *e = entries, *n;
+
+	for (i = 0; i < nr_entries - 1; i++, e++) {
+		n = e + 1;
+		if (id > e->id && id <= n->id)
+			break;
+	}
+
+	return (i + 1 + idx) % nr_entries;
+}
+
+static inline int obj_to_sheep(struct sheepdog_node_list_entry *entries,
+			       int nr_entries, uint64_t oid, int idx)
+{
+	uint64_t id = fnv_64a_buf(&oid, sizeof(oid), FNV1A_64_INIT);
+
+	return hval_to_sheep(entries, nr_entries, id, idx);
+}
+
+static inline void print_node_list_entry(struct sheepdog_node_list_entry *e,
+					 char *str, size_t size)
+{
+	snprintf(str, size, "%016" PRIx64 " - %d.%d.%d.%d:%d",
+		 e->id, e->addr[12], e->addr[13],
+		 e->addr[14], e->addr[15], e->port);
+}
+
+#endif
diff --git a/include/meta.h b/include/meta.h
deleted file mode 100644
index 53fa085..0000000
--- a/include/meta.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2009-2010 Nippon Telegraph and Telephone Corporation.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#ifndef __META_H__
-#define __META_H__
-
-#include <stdint.h>
-#include "util.h"
-#include "list.h"
-
-#define SD_DATA_OBJ_SIZE (UINT64_C(1) << 22)
-
-/*
- * 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 bit ): object type indentifier space
- */
-
-#define VDI_SPACE   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 MAX_DATA_OBJS (1ULL << 20)
-#define MAX_CHILDREN 1024
-
-#define SD_NR_VDIS   (1U << 24)
-
-struct sheepdog_inode {
-	char name[SD_MAX_VDI_LEN];
-	uint64_t ctime;
-	uint64_t snap_ctime;
-	uint64_t vm_clock_nsec;
-	uint64_t vdi_size;
-	uint64_t vm_state_size;
-	uint16_t copy_policy;
-	uint8_t  nr_copies;
-	uint8_t  block_size_shift;
-	uint32_t snap_id;
-	uint32_t vdi_id;
-	uint32_t parent_vdi_id;
-	uint32_t child_vdi_id[MAX_CHILDREN];
-	uint32_t data_vdi_id[MAX_DATA_OBJS];
-};
-
-static inline int is_data_obj_writeable(struct sheepdog_inode *inode, int idx)
-{
-	return inode->vdi_id == inode->data_vdi_id[idx];
-}
-
-static inline int is_data_obj(uint64_t oid)
-{
-	return !(VDI_BIT & oid);
-}
-
-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_data_oid(uint32_t vid, uint32_t idx)
-{
-	return ((uint64_t)vid << VDI_SPACE_SHIFT) | idx;
-}
-
-static inline uint32_t oid_to_vid(uint64_t oid)
-{
-	return (~VDI_BIT & oid) >> VDI_SPACE_SHIFT;
-}
-
-#define NR_VDIS (1U << DATA_SPECE_SHIFT)
-
-#endif
diff --git a/include/net.h b/include/net.h
index 024276b..63ae469 100644
--- a/include/net.h
+++ b/include/net.h
@@ -35,18 +35,6 @@ int connect_to(char *name, int port);
 int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *wlen);
 int exec_req(int sockfd, struct sd_req *hdr, void *data,
 	     unsigned int *wlen, unsigned int *rlen);
-int write_object(struct sheepdog_node_list_entry *e,
-		 int nodes, uint32_t node_version,
-		 uint64_t oid, char *data, unsigned int datalen,
-		 uint64_t offset, int nr, int create);
-int read_object(struct sheepdog_node_list_entry *e,
-		int nodes, uint32_t node_version,
-		uint64_t oid, char *data, unsigned int datalen,
-		uint64_t offset, int nr);
-int remove_object(struct sheepdog_node_list_entry *e,
-		  int nodes, uint32_t node_version,
-		  uint64_t oid, int nr);
-
 int create_listen_ports(int port, int (*callback)(int fd, void *), void *data);
 
 char *addr_to_str(char *str, int size, uint8_t *addr, uint16_t port);
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 521432a..dc9152a 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -17,85 +17,61 @@
 
 #define SD_LISTEN_PORT 7000
 
-#define SD_MAX_NODES 1024
-#define SD_MAX_VMS   4096
-#define SD_MAX_VDI_LEN 256
-#define SD_MAX_REDUNDANCY 8
-
-/* -> vmon */
-
-#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_UPDATE_EPOCH   0x22
-#define SD_OP_GET_EPOCH      0x23
-#define SD_OP_SHUTDOWN       0x24
-#define SD_OP_READ_VDIS      0x25
-
-#define SD_OP_DEBUG_INC_NVER 0xA0
-#define SD_OP_DEBUG_SET_NODE 0xA1
-#define SD_OP_DEBUG_KILL     0xA2
-
 #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_GET_OBJ_LIST   0x06
+#define SD_OP_READ_OBJ       0x02
+#define SD_OP_WRITE_OBJ      0x03
 
-#define SD_OP_STAT_SHEEP     0xB0
-#define SD_OP_STAT_CLUSTER   0xB1
+#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
-#define SD_FLAG_CMD_DIRECT   0x04
-#define SD_FLAG_CMD_RECOVERY 0x08
-
-#define SD_STATUS_OK            0x00
-#define SD_STATUS_WAIT_FOR_FORMAT   0x01
-#define SD_STATUS_WAIT_FOR_JOIN     0x02
-#define SD_STATUS_SHUTDOWN          0x03
-#define SD_STATUS_INCONSISTENT_EPOCHS   0x04
-#define SD_STATUS_JOIN_FAILED   0x05
 
 #define SD_RES_SUCCESS       0x00 /* Success */
 #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_NO_MEM        0x19 /* Cannot allocate memory */
-#define SD_RES_INCONSISTENT_EPOCHS  0x1A /* There is inconsistency between epochs */
-#define SD_RES_FULL_VDI      0x1B /* we already have the maximum vdis */
-#define SD_RES_WAIT_FOR_FORMAT      0x1C /* Sheepdog is waiting for a format operation */
-#define SD_RES_WAIT_FOR_JOIN        0x1D /* Sheepdog is waiting for other nodes joining */
-#define SD_RES_NOT_FORMATTED 0x1E /* Sheepdog is not formatted yet */
-#define SD_RES_INVALID_CTIME 0x1F /* Creation time of sheepdog is different */
-#define SD_RES_INVALID_EPOCH 0x20 /* Invalid epoch */
+#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 VDI_SPACE_SHIFT   32
+#define VDI_BIT (UINT64_C(1) << 63)
+#define VMSTATE_BIT (UINT64_C(1) << 62)
+#define MAX_DATA_OBJS (1ULL << 20)
+#define MAX_CHILDREN 1024
+#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 sheepdog_inode))
+#define CURRENT_VDI_ID 0
 
 struct sd_req {
 	uint8_t		proto_ver;
@@ -118,34 +94,6 @@ struct sd_rsp {
 	uint32_t	opcode_specific[7];
 };
 
-struct sd_so_req {
-	uint8_t		proto_ver;
-	uint8_t		opcode;
-	uint16_t	flags;
-	uint32_t	epoch;
-	uint32_t        id;
-	uint32_t        data_length;
-	uint64_t	oid;
-	uint64_t	ctime;
-	uint32_t	copies;
-	uint32_t	tag;
-	uint32_t	opcode_specific[2];
-};
-
-struct sd_so_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	copies;
-	uint64_t	ctime;
-	uint64_t	oid;
-	uint32_t	opcode_specific[2];
-};
-
 struct sd_obj_req {
 	uint8_t		proto_ver;
 	uint8_t		opcode;
@@ -173,32 +121,6 @@ struct sd_obj_rsp {
 	uint32_t        pad[5];
 };
 
-struct sd_list_req {
-	uint8_t		proto_ver;
-	uint8_t		opcode;
-	uint16_t	flags;
-	uint32_t	epoch;
-	uint32_t        id;
-	uint32_t        data_length;
-	uint64_t        start;
-	uint64_t        end;
-	uint32_t        tgt_epoch;
-	uint32_t        pad[3];
-};
-
-struct sd_list_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        rsvd;
-	uint64_t        next;
-	uint32_t        pad[4];
-};
-
 struct sd_vdi_req {
 	uint8_t		proto_ver;
 	uint8_t		opcode;
@@ -227,51 +149,21 @@ struct sd_vdi_rsp {
 	uint32_t        pad[4];
 };
 
-struct sd_node_req {
-	uint8_t		proto_ver;
-	uint8_t		opcode;
-	uint16_t	flags;
-	uint32_t	epoch;
-	uint32_t        id;
-	uint32_t        data_length;
-	uint32_t	request_ver;
-	uint32_t	pad[7];
-};
-
-struct sd_node_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	nr_nodes;
-	uint32_t	local_idx;
-	uint32_t	master_idx;
-	uint64_t	store_size;
-	uint64_t	store_free;
-};
-
-struct sheepdog_vm_list_entry {
-	uint8_t         name[SD_MAX_VDI_LEN];
-	uint8_t         host_addr[16];
-	uint16_t        host_port;
-	uint8_t	        pad[6];
-};
-
-struct sheepdog_node_list_entry {
-	uint64_t        id;
-	uint8_t         addr[16];
-	uint16_t        port;
-	uint16_t	pad[3];
-};
-
-struct epoch_log {
+struct sheepdog_inode {
+	char name[SD_MAX_VDI_LEN];
 	uint64_t ctime;
-	uint32_t epoch;
-	uint32_t nr_nodes;
-	struct sheepdog_node_list_entry nodes[SD_MAX_NODES];
+	uint64_t snap_ctime;
+	uint64_t vm_clock_nsec;
+	uint64_t vdi_size;
+	uint64_t vm_state_size;
+	uint16_t copy_policy;
+	uint8_t  nr_copies;
+	uint8_t  block_size_shift;
+	uint32_t snap_id;
+	uint32_t vdi_id;
+	uint32_t parent_vdi_id;
+	uint32_t child_vdi_id[MAX_CHILDREN];
+	uint32_t data_vdi_id[MAX_DATA_OBJS];
 };
 
 /*
@@ -294,35 +186,29 @@ static inline uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
 	return hval;
 }
 
-static inline int hval_to_sheep(struct sheepdog_node_list_entry *entries,
-				int nr_entries, uint64_t id, int idx)
+static inline int is_data_obj_writeable(struct sheepdog_inode *inode, int idx)
 {
-	int i;
-	struct sheepdog_node_list_entry *e = entries, *n;
-
-	for (i = 0; i < nr_entries - 1; i++, e++) {
-		n = e + 1;
-		if (id > e->id && id <= n->id)
-			break;
-	}
+	return inode->vdi_id == inode->data_vdi_id[idx];
+}
 
-	return (i + 1 + idx) % nr_entries;
+static inline int is_data_obj(uint64_t oid)
+{
+	return !(VDI_BIT & oid);
 }
 
-static inline int obj_to_sheep(struct sheepdog_node_list_entry *entries,
-			       int nr_entries, uint64_t oid, int idx)
+static inline uint64_t vid_to_vdi_oid(uint32_t vid)
 {
-	uint64_t id = fnv_64a_buf(&oid, sizeof(oid), FNV1A_64_INIT);
+	return VDI_BIT | ((uint64_t)vid << VDI_SPACE_SHIFT);
+}
 
-	return hval_to_sheep(entries, nr_entries, id, idx);
+static inline uint64_t vid_to_data_oid(uint32_t vid, uint32_t idx)
+{
+	return ((uint64_t)vid << VDI_SPACE_SHIFT) | idx;
 }
 
-static inline void print_node_list_entry(struct sheepdog_node_list_entry *e,
-					 char *str, size_t size)
+static inline uint32_t oid_to_vid(uint64_t oid)
 {
-	snprintf(str, size, "%016" PRIx64 " - %d.%d.%d.%d:%d",
-		 e->id, e->addr[12], e->addr[13],
-		 e->addr[14], e->addr[15], e->port);
+	return (~VDI_BIT & oid) >> VDI_SPACE_SHIFT;
 }
 
 #endif
diff --git a/lib/net.c b/lib/net.c
index b7b5a4d..24c9bbf 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -346,145 +346,6 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
 	return 0;
 }
 
-int write_object(struct sheepdog_node_list_entry *e,
-		 int nodes, uint32_t node_version,
-		 uint64_t oid, char *data, unsigned int datalen,
-		 uint64_t offset, int nr, int create)
-{
-	struct sd_obj_req hdr;
-	int i, n, fd, ret, success = 0;
-	uint16_t vosts[3];
-	char name[128];
-
-	for (i = 0; i < nr; i++) {
-		unsigned rlen = 0, wlen = datalen;
-
-		n = obj_to_sheep(e, nodes, oid, i);
-
-		addr_to_str(name, sizeof(name), e[n].addr, 0);
-
-		fd = connect_to(name, e[n].port);
-		if (fd < 0) {
-			eprintf("can't connect to vost %u, %s\n", vosts[i], name);
-			continue;
-		}
-
-		memset(&hdr, 0, sizeof(hdr));
-		hdr.epoch = node_version;
-		if (create)
-			hdr.opcode = SD_OP_CREATE_AND_WRITE_OBJ;
-		else
-			hdr.opcode = SD_OP_WRITE_OBJ;
-
-		hdr.oid = oid;
-		hdr.copies = nr;
-
-		hdr.flags = SD_FLAG_CMD_WRITE | SD_FLAG_CMD_DIRECT;
-		hdr.data_length = wlen;
-		hdr.offset = offset;
-
-		ret = exec_req(fd, (struct sd_req *)&hdr, data, &wlen, &rlen);
-		close(fd);
-		if (ret)
-			eprintf("can't update vost %u, %s\n", vosts[i], name);
-		else
-			success++;
-	}
-
-	return !success;
-}
-
-int read_object(struct sheepdog_node_list_entry *e,
-		int nodes, uint32_t node_version,
-		uint64_t oid, char *data, unsigned int datalen,
-		uint64_t offset, int nr)
-{
-	struct sd_obj_req hdr;
-	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
-	char name[128];
-	int i = 0, n, fd, ret;
-
-	for (i = 0; i < nr; i++) {
-		unsigned wlen = 0, rlen = datalen;
-
-		n = obj_to_sheep(e, nodes, oid, i);
-
-		addr_to_str(name, sizeof(name), e[n].addr, 0);
-
-		fd = connect_to(name, e[n].port);
-		if (fd < 0) {
-			printf("%s(%d): %s, %m\n", __func__, __LINE__,
-			       name);
-			return -1;
-		}
-
-		memset(&hdr, 0, sizeof(hdr));
-		hdr.epoch = node_version;
-		hdr.opcode = SD_OP_READ_OBJ;
-		hdr.oid = oid;
-
-		hdr.flags =  SD_FLAG_CMD_DIRECT;
-		hdr.data_length = rlen;
-		hdr.offset = offset;
-
-		ret = exec_req(fd, (struct sd_req *)&hdr, data, &wlen, &rlen);
-		close(fd);
-
-		if (!ret) {
-			if (rsp->result == SD_RES_SUCCESS)
-				return rsp->data_length;
-		}
-	}
-
-	return -1;
-}
-
-int remove_object(struct sheepdog_node_list_entry *e,
-		  int nodes, uint32_t node_version,
-		  uint64_t oid, int nr)
-{
-	char name[128];
-	struct sd_obj_req hdr;
-	struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
-	int i = 0, n, fd, ret;
-
-	if (nr > nodes)
-		nr = nodes;
-
-	for (i = 0; i < nr; i++) {
-		unsigned wlen = 0, rlen = 0;
-
-		n = obj_to_sheep(e, nodes, oid, i);
-
-		addr_to_str(name, sizeof(name), e[n].addr, 0);
-
-		fd = connect_to(name, e[n].port);
-		if (fd < 0) {
-			rsp->result = SD_RES_EIO;
-			return -1;
-		}
-
-		memset(&hdr, 0, sizeof(hdr));
-		hdr.epoch = node_version;
-		hdr.opcode = SD_OP_REMOVE_OBJ;
-		hdr.oid = oid;
-
-		hdr.flags = 0;
-		hdr.data_length = rlen;
-
-		ret = exec_req(fd, (struct sd_req *)&hdr, NULL, &wlen, &rlen);
-		close(fd);
-
-		if (ret)
-			return -1;
-	}
-
-	if (rsp->result != SD_RES_SUCCESS)
-		return -1;
-
-	return 0;
-}
-
 /* TODO: support IPv6 */
 char *addr_to_str(char *str, int size, uint8_t *addr, uint16_t port)
 {
diff --git a/shepherd/shepherd.c b/shepherd/shepherd.c
index a63788e..db11fca 100644
--- a/shepherd/shepherd.c
+++ b/shepherd/shepherd.c
@@ -28,7 +28,7 @@
 #include <curses.h>
 
 #include "sheepdog_proto.h"
-#include "meta.h"
+#include "collie.h"
 #include "net.h"
 #include "treeview.h"
 
@@ -133,10 +133,6 @@ static int update_node_list(int max_nodes, int epoch)
 	switch (rsp->result) {
 	case SD_RES_SUCCESS:
 		break;
-	case SD_RES_DIR_READ:
-		fprintf(stderr, "cannot read directory object\n");
-		ret = -1;
-		goto out;
 	case SD_RES_WAIT_FOR_FORMAT:
 		fprintf(stderr, "sheepdog is not formatted yet\n");
 		ret = -1;
@@ -149,10 +145,6 @@ static int update_node_list(int max_nodes, int epoch)
 		fprintf(stderr, "sheepdog is shutting down\n");
 		ret = -1;
 		goto out;
-	case SD_RES_NO_EPOCH:
-		fprintf(stderr, "requested epoch is not found\n");
-		ret = -1;
-		goto out;
 	case SD_RES_INCONSISTENT_EPOCHS:
 		fprintf(stderr, "there is inconsistency betweeen epochs\n");
 		ret = -1;
@@ -306,20 +298,35 @@ static int parse_vdi(vdi_parser_func_t func, void *data)
 		return ret;
 
 	for (nr = 0; nr < SD_NR_VDIS; nr++) {
+		struct sd_obj_req hdr;
+		struct sd_obj_rsp *rsp = (struct sd_obj_rsp *)&hdr;
+
 		if (!test_bit(nr, vdi_inuse))
 			continue;
 
-		ret = read_object(node_list_entries, nr_nodes, node_list_version,
-				  vid_to_vdi_oid(nr), (void *)&i,
-				  sizeof(i), 0, nr_nodes);
+		wlen = 0;
+		rlen = sizeof(i);
+
+		fd = connect_to("localhost", sdport);
+		if (fd < 0) {
+			printf("failed to connect, %m\n");
+			return -1;
+		}
+
+		memset(&hdr, 0, sizeof(hdr));
+		hdr.opcode = SD_OP_READ_OBJ;
+		hdr.oid = vid_to_vdi_oid(nr);
+		hdr.data_length = rlen;
 
-		if (ret == sizeof(i)) {
+		ret = exec_req(fd, (struct sd_req *)&hdr, &i, &wlen, &rlen);
+		close(fd);
+
+		if (!ret && rsp->result == SD_RES_SUCCESS) {
 			if (i.name[0] == '\0') /* deleted */
 				continue;
 			func(i.vdi_id, i.name, i.snap_id, 0, &i, data);
 		} else
 			printf("error %lu, %d\n", nr, ret);
-
 	}
 
 	return 0;
@@ -968,24 +975,20 @@ static int cluster_info(int argc, char **argv)
 	if (ret != 0)
 		return 1;
 
-	if (rsp->result != SD_RES_SUCCESS) {
-		fprintf(stderr, "failed to get cluster status, %x\n", rsp->result);
-		return 1;
-	}
-	switch (rsp->rsvd) {
-	case SD_STATUS_OK:
+	switch (rsp->result) {
+	case SD_RES_SUCCESS:
 		printf("running\n");
 		break;
-	case SD_STATUS_WAIT_FOR_FORMAT:
+	case SD_RES_WAIT_FOR_FORMAT:
 		printf("sheepdog is not formatted yet\n");
 		break;
-	case SD_STATUS_WAIT_FOR_JOIN:
+	case SD_RES_WAIT_FOR_JOIN:
 		printf("sheepdog is waiting for other nodes joining\n");
 		break;
-	case SD_STATUS_INCONSISTENT_EPOCHS:
+	case SD_RES_INCONSISTENT_EPOCHS:
 		printf("there is inconsistency between epochs\n");
 		break;
-	case SD_STATUS_SHUTDOWN:
+	case SD_RES_SHUTDOWN:
 		printf("shutdown\n");
 		break;
 	default:
-- 
1.5.6.5




More information about the sheepdog mailing list