[sheepdog] [PATCH 3/3] add const where possible

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Oct 18 02:49:55 CEST 2012


Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/cluster.c          |    2 +-
 collie/collie.h           |    9 +++--
 collie/common.c           |    2 +-
 collie/node.c             |    4 +-
 collie/vdi.c              |   81 ++++++++++++++++++++++-------------------
 include/net.h             |    6 ++--
 include/sheep.h           |   31 ++++++++--------
 include/sheepdog_proto.h  |    5 ++-
 lib/net.c                 |    6 ++--
 sheep/cluster.h           |   26 +++++++------
 sheep/cluster/accord.c    |    2 +-
 sheep/cluster/corosync.c  |    4 +-
 sheep/cluster/local.c     |    2 +-
 sheep/cluster/zookeeper.c |    2 +-
 sheep/farm/farm.c         |   10 +++---
 sheep/gateway.c           |   18 +++++-----
 sheep/group.c             |   63 ++++++++++++++++++--------------
 sheep/object_cache.c      |   10 +++---
 sheep/ops.c               |   22 ++++++------
 sheep/plain_store.c       |   21 ++++++-----
 sheep/recovery.c          |   21 +++++------
 sheep/request.c           |    2 +-
 sheep/sheep_priv.h        |   89 +++++++++++++++++++++++----------------------
 sheep/sockfd_cache.c      |   28 +++++++-------
 sheep/vdi.c               |   28 ++++++++-------
 25 files changed, 258 insertions(+), 236 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index 5a64f17..642e4f2 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -177,7 +177,7 @@ again:
 	for (i = 0; i < nr_logs; i++) {
 		int j;
 		char name[128];
-		struct sd_node *entry;
+		const struct sd_node *entry;
 
 		ti = logs[i].time;
 		if (raw_output) {
diff --git a/collie/collie.h b/collie/collie.h
index 347e5a9..909a072 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -65,11 +65,12 @@ extern struct sd_vnode sd_vnodes[SD_MAX_VNODES];
 extern int sd_nodes_nr, sd_vnodes_nr;
 extern unsigned master_idx;
 
-bool is_current(struct sheepdog_inode *i);
+bool is_current(const struct sheepdog_inode *i);
 char *size_to_str(uint64_t _size, char *str, int str_size);
-typedef void (*vdi_parser_func_t)(uint32_t vid, char *name, char *tag,
-				  uint32_t snapid, uint32_t flags,
-				  struct sheepdog_inode *i, void *data);
+typedef void (*vdi_parser_func_t)(uint32_t vid, const char *name,
+				  const char *tag, uint32_t snapid,
+				  uint32_t flags,
+				  const struct sheepdog_inode *i, void *data);
 int parse_vdi(vdi_parser_func_t func, size_t size, void *data);
 int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 		   uint64_t offset, bool direct);
diff --git a/collie/common.c b/collie/common.c
index 227b045..3c4f753 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -11,7 +11,7 @@
 
 #include "collie.h"
 
-bool is_current(struct sheepdog_inode *i)
+bool is_current(const struct sheepdog_inode *i)
 {
 	return !i->snap_ctime;
 }
diff --git a/collie/node.c b/collie/node.c
index 5d75c31..ae204ad 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -11,9 +11,9 @@
 
 #include "collie.h"
 
-static void cal_total_vdi_size(uint32_t vid, char *name, char *tag,
+static void cal_total_vdi_size(uint32_t vid, const char *name, const char *tag,
 			       uint32_t snapid, uint32_t flags,
-			       struct sheepdog_inode *i, void *data)
+			       const struct sheepdog_inode *i, void *data)
 {
 	uint64_t *size = data;
 
diff --git a/collie/vdi.c b/collie/vdi.c
index 76238c7..e4503bf 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -45,8 +45,8 @@ static struct vdi_cmd_data {
 } vdi_cmd_data = { ~0, };
 
 struct get_vdi_info {
-	char *name;
-	char *tag;
+	const char *name;
+	const char *tag;
 	uint32_t vid;
 	uint32_t snapid;
 };
@@ -81,8 +81,9 @@ static int parse_option_size(const char *value, uint64_t *ret)
 	return 0;
 }
 
-static void print_vdi_list(uint32_t vid, char *name, char *tag, uint32_t snapid,
-			   uint32_t flags, struct sheepdog_inode *i, void *data)
+static void print_vdi_list(uint32_t vid, const char *name, const char *tag,
+			   uint32_t snapid, uint32_t flags,
+			   const struct sheepdog_inode *i, void *data)
 {
 	int idx;
 	bool is_clone = false;
@@ -141,8 +142,9 @@ static void print_vdi_list(uint32_t vid, char *name, char *tag, uint32_t snapid,
 	}
 }
 
-static void print_vdi_tree(uint32_t vid, char *name, char *tag, uint32_t snapid,
-			   uint32_t flags, struct sheepdog_inode *i, void *data)
+static void print_vdi_tree(uint32_t vid, const char *name, const char *tag,
+			   uint32_t snapid, uint32_t flags,
+			   const struct sheepdog_inode *i, void *data)
 {
 	time_t ti;
 	struct tm tm;
@@ -161,8 +163,9 @@ static void print_vdi_tree(uint32_t vid, char *name, char *tag, uint32_t snapid,
 	add_vdi_tree(name, buf, vid, i->parent_vdi_id, highlight && is_current(i));
 }
 
-static void print_vdi_graph(uint32_t vid, char *name, char *tag, uint32_t snapid,
-			    uint32_t flags, struct sheepdog_inode *i, void *data)
+static void print_vdi_graph(uint32_t vid, const char *name, const char *tag,
+			    uint32_t snapid, uint32_t flags,
+			    const struct sheepdog_inode *i, void *data)
 {
 	time_t ti;
 	struct tm tm;
@@ -194,8 +197,9 @@ static void print_vdi_graph(uint32_t vid, char *name, char *tag, uint32_t snapid
 
 }
 
-static void get_oid(uint32_t vid, char *name, char *tag, uint32_t snapid,
-		    uint32_t flags, struct sheepdog_inode *i, void *data)
+static void get_oid(uint32_t vid, const char *name, const char *tag,
+		    uint32_t snapid, uint32_t flags,
+		    const struct sheepdog_inode *i, void *data)
 {
 	struct get_vdi_info *info = data;
 
@@ -328,7 +332,7 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
 
 static int vdi_list(int argc, char **argv)
 {
-	char *vdiname = argv[optind];
+	const char *vdiname = argv[optind];
 
 	if (!raw_output)
 		printf("  Name        Id    Size    Used  Shared    Creation time   VDI id  Copies  Tag\n");
@@ -373,7 +377,7 @@ static int vdi_graph(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
-static int find_vdi_name(char *vdiname, uint32_t snapid, const char *tag,
+static int find_vdi_name(const char *vdiname, uint32_t snapid, const char *tag,
 			 uint32_t *vid, int for_snapshot)
 {
 	int ret, fd;
@@ -417,7 +421,7 @@ out:
 	return ret;
 }
 
-static int read_vdi_obj(char *vdiname, int snapid, const char *tag,
+static int read_vdi_obj(const char *vdiname, int snapid, const char *tag,
 			uint32_t *pvid, struct sheepdog_inode *inode,
 			size_t size)
 {
@@ -450,8 +454,9 @@ static int read_vdi_obj(char *vdiname, int snapid, const char *tag,
 	return EXIT_SUCCESS;
 }
 
-static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
-			 uint32_t *vdi_id, bool snapshot, int nr_copies)
+static int do_vdi_create(const char *vdiname, int64_t vdi_size,
+			 uint32_t base_vid, uint32_t *vdi_id, bool snapshot,
+			 int nr_copies)
 {
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
@@ -499,7 +504,7 @@ static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
 
 static int vdi_create(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	uint64_t size;
 	uint32_t vid;
 	uint64_t oid;
@@ -568,7 +573,7 @@ out:
 
 static int vdi_snapshot(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	uint32_t vid;
 	int ret;
 	char buf[SD_INODE_HEADER_SIZE];
@@ -597,7 +602,7 @@ static int vdi_snapshot(int argc, char **argv)
 
 static int vdi_clone(int argc, char **argv)
 {
-	char *src_vdi = argv[optind++], *dst_vdi;
+	const char *src_vdi = argv[optind++], *dst_vdi;
 	uint32_t base_vid, new_vid;
 	uint64_t oid;
 	int idx, max_idx, ret;
@@ -681,7 +686,7 @@ out:
 
 static int vdi_resize(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	uint64_t new_size;
 	uint32_t vid;
 	int ret;
@@ -770,7 +775,7 @@ static int vdi_delete(int argc, char **argv)
 
 static int vdi_rollback(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	uint32_t base_vid;
 	int ret;
 	char buf[SD_INODE_HEADER_SIZE];
@@ -799,7 +804,7 @@ static int vdi_rollback(int argc, char **argv)
 
 static int vdi_object(int argc, char **argv)
 {
-	char *vdiname = argv[optind];
+	const char *vdiname = argv[optind];
 	unsigned idx = vdi_cmd_data.index;
 	struct get_vdi_info info;
 	uint32_t vid;
@@ -859,7 +864,7 @@ static int print_obj_epoch(uint64_t oid)
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	struct sd_vnode vnodes[SD_MAX_VNODES];
-	struct sd_vnode *vnode_buf[SD_MAX_COPIES];
+	const struct sd_vnode *vnode_buf[SD_MAX_COPIES];
 	struct epoch_log *logs;
 	int vnodes_nr, nr_logs, log_length;
 	char host[128];
@@ -917,7 +922,7 @@ error:
 
 static int vdi_track(int argc, char **argv)
 {
-	char *vdiname = argv[optind];
+	const char *vdiname = argv[optind];
 	unsigned idx = vdi_cmd_data.index;
 	struct get_vdi_info info;
 	uint32_t vid;
@@ -973,8 +978,8 @@ static int vdi_track(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
-static int find_vdi_attr_oid(char *vdiname, char *tag, uint32_t snapid,
-			     char *key, void *value, unsigned int value_len,
+static int find_vdi_attr_oid(const char *vdiname, const char *tag, uint32_t snapid,
+			     const char *key, void *value, unsigned int value_len,
 			     uint32_t *vid, uint64_t *oid, unsigned int *nr_copies,
 			     bool create, bool excl, bool delete)
 {
@@ -1037,7 +1042,8 @@ static int vdi_setattr(int argc, char **argv)
 	int ret, value_len = 0;
 	uint64_t attr_oid = 0;
 	uint32_t vid = 0, nr_copies = 0;
-	char *vdiname = argv[optind++], *key, *value;
+	const char *vdiname = argv[optind++], *key;
+	char *value;
 	uint64_t offset;
 
 	key = argv[optind++];
@@ -1100,7 +1106,7 @@ static int vdi_getattr(int argc, char **argv)
 	int ret;
 	uint64_t oid, attr_oid = 0;
 	uint32_t vid = 0, nr_copies = 0;
-	char *vdiname = argv[optind++], *key;
+	const char *vdiname = argv[optind++], *key;
 	struct sheepdog_vdi_attr vattr;
 
 	key = argv[optind++];
@@ -1139,7 +1145,7 @@ static int vdi_getattr(int argc, char **argv)
 
 static int vdi_read(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	int ret, idx;
 	struct sheepdog_inode *inode = NULL;
 	uint64_t offset = 0, oid, done = 0, total = (uint64_t) -1;
@@ -1225,7 +1231,7 @@ out:
 
 static int vdi_write(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	uint32_t vid, flags;
 	int ret, idx;
 	struct sheepdog_inode *inode = NULL;
@@ -1342,7 +1348,7 @@ out:
 	return ret;
 }
 
-static void *read_object_from(struct sd_vnode *vnode, uint64_t oid)
+static void *read_object_from(const struct sd_vnode *vnode, uint64_t oid)
 {
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
@@ -1391,7 +1397,8 @@ static void *read_object_from(struct sd_vnode *vnode, uint64_t oid)
 	return buf;
 }
 
-static void write_object_to(struct sd_vnode *vnode, uint64_t oid, void *buf)
+static void write_object_to(const struct sd_vnode *vnode, uint64_t oid,
+			    void *buf)
 {
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
@@ -1436,7 +1443,7 @@ static void write_object_to(struct sd_vnode *vnode, uint64_t oid, void *buf)
  */
 static void do_check_repair(uint64_t oid, int nr_copies)
 {
-	struct sd_vnode *tgt_vnodes[SD_MAX_COPIES];
+	const struct sd_vnode *tgt_vnodes[SD_MAX_COPIES];
 	void *buf, *buf_cmp;
 	int i;
 
@@ -1462,7 +1469,7 @@ fix_consistency:
 
 static int vdi_check(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	int ret;
 	uint64_t total, done = 0, oid;
 	uint32_t idx = 0, vid;
@@ -1493,7 +1500,7 @@ out:
 
 static int vdi_flush(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	struct sd_req hdr;
 	uint32_t vid;
 	int ret = EXIT_SUCCESS;
@@ -1600,7 +1607,7 @@ static int get_obj_backup(int idx, uint32_t from_vid, uint32_t to_vid,
 
 static int vdi_backup(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	int ret = EXIT_SUCCESS, idx, nr_objs;
 	struct sheepdog_inode *from_inode = xzalloc(sizeof(*from_inode));
 	struct sheepdog_inode *to_inode = xzalloc(sizeof(*to_inode));
@@ -1712,7 +1719,7 @@ static int restore_obj(struct obj_backup *backup, uint32_t vid,
 			       0, parent_inode->nr_copies, false, true);
 }
 
-static uint32_t do_restore(char *vdiname, int snapid, const char *tag)
+static uint32_t do_restore(const char *vdiname, int snapid, const char *tag)
 {
 	int ret;
 	uint32_t vid;
@@ -1780,7 +1787,7 @@ out:
 
 static int vdi_restore(int argc, char **argv)
 {
-	char *vdiname = argv[optind++];
+	const char *vdiname = argv[optind++];
 	int ret;
 	char buf[SD_INODE_HEADER_SIZE] = {0};
 	struct sheepdog_inode *current_inode = xzalloc(sizeof(*current_inode));
diff --git a/include/net.h b/include/net.h
index 2966b2d..662e1ba 100644
--- a/include/net.h
+++ b/include/net.h
@@ -36,17 +36,17 @@ int conn_tx_off(struct connection *conn);
 int conn_tx_on(struct connection *conn);
 int conn_rx_off(struct connection *conn);
 int conn_rx_on(struct connection *conn);
-bool is_conn_dead(struct connection *conn);
+bool is_conn_dead(const struct connection *conn);
 int do_read(int sockfd, void *buf, int len);
 int rx(struct connection *conn, enum conn_state next_state);
 int tx(struct connection *conn, enum conn_state next_state, int flags);
 int connect_to(const 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 *len);
-int create_listen_ports(char *bindaddr, int port,
+int create_listen_ports(const char *bindaddr, int port,
 			int (*callback)(int fd, void *), void *data);
 
-char *addr_to_str(char *str, int size, uint8_t *addr, uint16_t port);
+char *addr_to_str(char *str, int size, const uint8_t *addr, uint16_t port);
 uint8_t *str_to_addr(int af, const char *ipstr, uint8_t *addr);
 int set_nonblocking(int fd);
 int set_nodelay(int fd);
diff --git a/include/sheep.h b/include/sheep.h
index ed85b98..5bedfa8 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -63,14 +63,14 @@ static inline void sd_init_req(struct sd_req *req, uint8_t opcode)
 	req->proto_ver = opcode < 0x80 ? SD_PROTO_VER : SD_SHEEP_PROTO_VER;
 }
 
-static inline int same_zone(struct sd_vnode *e, int n1, int n2)
+static inline int same_zone(const struct sd_vnode *e, int n1, int n2)
 {
 	return e[n1].zone == e[n2].zone;
 }
 
 /* Get the first vnode's index which is matching the OID */
-static inline int get_vnode_first_idx(struct sd_vnode *entries, int nr_entries,
-				      uint64_t oid)
+static inline int get_vnode_first_idx(const struct sd_vnode *entries,
+				      int nr_entries, uint64_t oid)
 {
 	uint64_t id = fnv_64a_buf(&oid, sizeof(oid), FNV1A_64_INIT);
 	int start, end, pos;
@@ -93,8 +93,9 @@ static inline int get_vnode_first_idx(struct sd_vnode *entries, int nr_entries,
 }
 
 /* Get next vnode's index according to the PREV_IDXS */
-static inline int get_vnode_next_idx(struct sd_vnode *entries, int nr_entries,
-				     int *prev_idxs, int nr_prev_idxs)
+static inline int get_vnode_next_idx(const struct sd_vnode *entries,
+				     int nr_entries, int *prev_idxs,
+				     int nr_prev_idxs)
 {
 	int i, idx, first_idx;
 	bool found;
@@ -119,7 +120,7 @@ static inline int get_vnode_next_idx(struct sd_vnode *entries, int nr_entries,
 }
 
 /* Get the n'th vnode's index which is matching the OID */
-static inline int get_vnode_nth_idx(struct sd_vnode *entries,
+static inline int get_vnode_nth_idx(const struct sd_vnode *entries,
 			int nr_entries, uint64_t oid, int nth)
 {
 	int nr_idxs = 0, idxs[SD_MAX_COPIES];
@@ -138,18 +139,18 @@ static inline int get_vnode_nth_idx(struct sd_vnode *entries,
 	return idxs[nth];
 }
 
-static inline struct sd_vnode *oid_to_vnode(struct sd_vnode *entries,
-					    int nr_entries, uint64_t oid,
-					    int copy_idx)
+static inline const struct sd_vnode *oid_to_vnode(const struct sd_vnode *entries,
+						  int nr_entries, uint64_t oid,
+						  int copy_idx)
 {
 	int idx = get_vnode_nth_idx(entries, nr_entries, oid, copy_idx);
 
 	return &entries[idx];
 }
 
-static inline void oid_to_vnodes(struct sd_vnode *entries, int nr_entries,
+static inline void oid_to_vnodes(const struct sd_vnode *entries, int nr_entries,
 				 uint64_t oid, int nr_copies,
-				 struct sd_vnode **vnodes)
+				 const struct sd_vnode **vnodes)
 {
 	int idx, idxs[SD_MAX_COPIES], i;
 
@@ -164,13 +165,13 @@ static inline void oid_to_vnodes(struct sd_vnode *entries, int nr_entries,
 	}
 }
 
-static inline void oid_to_nodes(struct sd_vnode *entries, int nr_entries,
+static inline void oid_to_nodes(const struct sd_vnode *entries, int nr_entries,
 				uint64_t oid, int nr_copies,
-				struct sd_node *all_nodes,
-				struct sd_node **nodes)
+				const struct sd_node *all_nodes,
+				const struct sd_node **nodes)
 {
 	int i;
-	struct sd_vnode *vnodes[SD_MAX_COPIES];
+	const struct sd_vnode *vnodes[SD_MAX_COPIES];
 
 	oid_to_vnodes(entries, nr_entries, oid, nr_copies, vnodes);
 	for (i = 0; i < nr_copies; i++)
diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 7d205dc..865f451 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -203,7 +203,7 @@ struct snap_log {
 /*
  * 64 bit Fowler/Noll/Vo FNV-1a hash code
  */
-static inline uint64_t fnv_64a_buf(void *buf, size_t len, uint64_t hval)
+static inline uint64_t fnv_64a_buf(const void *buf, size_t len, uint64_t hval)
 {
 	unsigned char *bp = (unsigned char *) buf;
 	unsigned char *be = bp + len;
@@ -222,7 +222,8 @@ static inline uint64_t hash_64(uint64_t val, unsigned int bits)
 	return hash & ((1 << bits) - 1);
 }
 
-static inline bool is_data_obj_writeable(struct sheepdog_inode *inode, int idx)
+static inline bool is_data_obj_writeable(const struct sheepdog_inode *inode,
+					 int idx)
 {
 	return inode->vdi_id == inode->data_vdi_id[idx];
 }
diff --git a/lib/net.c b/lib/net.c
index d2f0021..a61e535 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -60,7 +60,7 @@ int conn_rx_on(struct connection *conn)
 	return modify_event(conn->fd, conn->events);
 }
 
-notrace bool is_conn_dead(struct connection *conn)
+notrace bool is_conn_dead(const struct connection *conn)
 {
 	if (conn->c_rx_state == C_IO_CLOSED || conn->c_tx_state == C_IO_CLOSED)
 		return true;
@@ -113,7 +113,7 @@ notrace int tx(struct connection *conn, enum conn_state next_state, int flags)
 	return ret;
 }
 
-int create_listen_ports(char *bindaddr, int port,
+int create_listen_ports(const char *bindaddr, int port,
 		int (*callback)(int fd, void *), void *data)
 {
 	char servname[64];
@@ -391,7 +391,7 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *len)
 	return 0;
 }
 
-char *addr_to_str(char *str, int size, uint8_t *addr, uint16_t port)
+char *addr_to_str(char *str, int size, const uint8_t *addr, uint16_t port)
 {
 	int  af = AF_INET6;
 	int  addr_start_idx = 0;
diff --git a/sheep/cluster.h b/sheep/cluster.h
index 3e881d7..2679c19 100644
--- a/sheep/cluster.h
+++ b/sheep/cluster.h
@@ -70,7 +70,8 @@ struct cluster_driver {
 	 *
 	 * Returns zero on success, -1 on error
 	 */
-	int (*join)(struct sd_node *myself, void *opaque, size_t opaque_len);
+	int (*join)(const struct sd_node *myself, void *opaque,
+		    size_t opaque_len);
 
 	/*
 	 * Leave the cluster
@@ -141,7 +142,7 @@ static inline struct cluster_driver *find_cdrv(const char *name)
 	return NULL;
 }
 
-static inline const char *get_cdrv_option(struct cluster_driver *cdrv,
+static inline const char *get_cdrv_option(const struct cluster_driver *cdrv,
 					  const char *arg)
 {
 	int len = strlen(cdrv->name);
@@ -152,12 +153,12 @@ static inline const char *get_cdrv_option(struct cluster_driver *cdrv,
 		return NULL;
 }
 
-static inline char *node_to_str(struct sd_node *id)
+static inline char *node_to_str(const struct sd_node *id)
 {
 	static char str[256];
 	char name[256];
 	int af = AF_INET6;
-	uint8_t *addr = id->nid.addr;
+	const uint8_t *addr = id->nid.addr;
 
 	/* Find address family type */
 	if (addr[12]) {
@@ -193,14 +194,15 @@ static inline struct sd_node *str_to_node(const char *str, struct sd_node *id)
 }
 
 /* callbacks back into sheepdog from the cluster drivers */
-void sd_join_handler(struct sd_node *joined, struct sd_node *members,
-		size_t nr_members, enum cluster_join_result result,
-		void *opaque);
-void sd_leave_handler(struct sd_node *left, struct sd_node *members,
-		size_t nr_members);
-void sd_notify_handler(struct sd_node *sender, void *msg, size_t msg_len);
-bool sd_block_handler(struct sd_node *sender);
-enum cluster_join_result sd_check_join_cb(struct sd_node *joining,
+void sd_join_handler(const struct sd_node *joined,
+		     const struct sd_node *members,
+		     size_t nr_members, enum cluster_join_result result,
+		     const void *opaque);
+void sd_leave_handler(const struct sd_node *left, const struct sd_node *members,
+		      size_t nr_members);
+void sd_notify_handler(const struct sd_node *sender, void *msg, size_t msg_len);
+bool sd_block_handler(const struct sd_node *sender);
+enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
 		void *opaque);
 void recalculate_vnodes(struct sd_node *nodes, int nr_nodes);
 
diff --git a/sheep/cluster/accord.c b/sheep/cluster/accord.c
index a6edf2a..be0cf83 100644
--- a/sheep/cluster/accord.c
+++ b/sheep/cluster/accord.c
@@ -407,7 +407,7 @@ static void acrd_watch_fn(struct acrd_handle *ah, struct acrd_watch_info *info,
 	eventfd_write(efd, value);
 }
 
-static int accord_join(struct sd_node *myself,
+static int accord_join(const struct sd_node *myself,
 		       void *opaque, size_t opaque_len)
 {
 	this_node = *myself;
diff --git a/sheep/cluster/corosync.c b/sheep/cluster/corosync.c
index e238145..a607bae 100644
--- a/sheep/cluster/corosync.c
+++ b/sheep/cluster/corosync.c
@@ -263,7 +263,7 @@ eq_check:
 	return -1;
 }
 
-static void build_node_list(struct cpg_node *nodes, size_t nr_nodes,
+static void build_node_list(const struct cpg_node *nodes, size_t nr_nodes,
 			    struct sd_node *entries)
 {
 	int i;
@@ -681,7 +681,7 @@ static void cdrv_cpg_confchg(cpg_handle_t handle,
 	__corosync_dispatch();
 }
 
-static int corosync_join(struct sd_node *myself,
+static int corosync_join(const struct sd_node *myself,
 			 void *opaque, size_t opaque_len)
 {
 	int ret;
diff --git a/sheep/cluster/local.c b/sheep/cluster/local.c
index 27b3cfe..20ce325 100644
--- a/sheep/cluster/local.c
+++ b/sheep/cluster/local.c
@@ -325,7 +325,7 @@ static void check_pids(void *arg)
 
 /* Local driver APIs */
 
-static int local_join(struct sd_node *myself,
+static int local_join(const struct sd_node *myself,
 		      void *opaque, size_t opaque_len)
 {
 	this_node.node = *myself;
diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 9c87c89..388bebc 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -578,7 +578,7 @@ static void watcher(zhandle_t *zh, int type, int state, const char *path,
 	eventfd_write(efd, value);
 }
 
-static int zk_join(struct sd_node *myself,
+static int zk_join(const struct sd_node *myself,
 		   void *opaque, size_t opaque_len)
 {
 	int rc;
diff --git a/sheep/farm/farm.c b/sheep/farm/farm.c
index 58a26b6..6eee745 100644
--- a/sheep/farm/farm.c
+++ b/sheep/farm/farm.c
@@ -26,7 +26,7 @@
 char farm_obj_dir[PATH_MAX];
 char farm_dir[PATH_MAX];
 
-static int create_directory(char *p)
+static int create_directory(const char *p)
 {
 	int i, ret = 0;
 	struct strbuf buf = STRBUF_INIT;
@@ -99,7 +99,7 @@ out:
 	return ret;
 }
 
-static bool is_xattr_enabled(char *path)
+static bool is_xattr_enabled(const char *path)
 {
 	int ret, dummy;
 
@@ -108,7 +108,7 @@ static bool is_xattr_enabled(char *path)
 	return !(ret == -1 && errno == ENOTSUP);
 }
 
-static int farm_init(char *p)
+static int farm_init(const char *p)
 {
 	dprintf("use farm store driver\n");
 	if (create_directory(p) < 0)
@@ -130,7 +130,7 @@ err:
 	return SD_RES_EIO;
 }
 
-static int farm_snapshot(struct siocb *iocb)
+static int farm_snapshot(const struct siocb *iocb)
 {
 	unsigned char snap_sha1[SHA1_LEN];
 	unsigned char trunk_sha1[SHA1_LEN];
@@ -236,7 +236,7 @@ out:
 	return ret;
 }
 
-static int farm_restore(struct siocb *iocb)
+static int farm_restore(const struct siocb *iocb)
 {
 	int ret = SD_RES_EIO, epoch = iocb->epoch;
 
diff --git a/sheep/gateway.c b/sheep/gateway.c
index 1f25850..8a64710 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -33,8 +33,8 @@ int gateway_read_obj(struct request *req)
 	int i, ret = SD_RES_SUCCESS;
 	struct sd_req fwd_hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&fwd_hdr;
-	struct sd_vnode *v;
-	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
+	const struct sd_vnode *v;
+	const struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
 	uint64_t oid = req->rq.obj.oid;
 	int nr_copies, j;
 
@@ -97,7 +97,7 @@ out:
 
 struct write_info_entry {
 	struct pollfd pfd;
-	struct node_id *nid;
+	const struct node_id *nid;
 	struct sockfd *sfd;
 };
 
@@ -217,7 +217,7 @@ static inline void write_info_init(struct write_info *wi)
 }
 
 static inline void
-write_info_advance(struct write_info *wi, struct node_id *nid,
+write_info_advance(struct write_info *wi, const struct node_id *nid,
 		   struct sockfd *sfd)
 {
 	wi->ent[wi->nr_sent].nid = nid;
@@ -228,10 +228,10 @@ write_info_advance(struct write_info *wi, struct node_id *nid,
 }
 
 static int init_target_nodes(struct request *req, bool all_node,
-			uint64_t oid, struct sd_node **target_nodes)
+			     uint64_t oid, const struct sd_node **target_nodes)
 {
 	int i, nr_to_send;
-	struct vnode_info *vinfo = req->vinfo;
+	const struct vnode_info *vinfo = req->vinfo;
 
 	if (all_node) {
 		nr_to_send = vinfo->nr_nodes;
@@ -255,9 +255,9 @@ static int gateway_forward_request(struct request *req, bool all_node)
 	uint64_t oid = req->rq.obj.oid;
 	int nr_to_send;
 	struct write_info wi;
-	struct sd_op_template *op;
+	const struct sd_op_template *op;
 	struct sd_req hdr;
-	struct sd_node *target_nodes[SD_MAX_NODES];
+	const struct sd_node *target_nodes[SD_MAX_NODES];
 
 	dprintf("%"PRIx64"\n", oid);
 
@@ -270,7 +270,7 @@ static int gateway_forward_request(struct request *req, bool all_node)
 
 	for (i = 0; i < nr_to_send; i++) {
 		struct sockfd *sfd;
-		struct node_id *nid;
+		const struct node_id *nid;
 
 		if (node_is_local(target_nodes[i])) {
 			local = i;
diff --git a/sheep/group.c b/sheep/group.c
index 553c93b..049776d 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -55,7 +55,7 @@ static size_t get_join_message_size(struct join_message *jm)
 	return sizeof(*jm) + jm->nr_nodes * sizeof(jm->nodes[0]);
 }
 
-static int get_zones_nr_from(struct sd_node *nodes, int nr_nodes)
+static int get_zones_nr_from(const struct sd_node *nodes, int nr_nodes)
 {
 	int nr_zones = 0, i, j;
 	uint32_t zones[SD_MAX_COPIES];
@@ -162,7 +162,7 @@ void put_vnode_info(struct vnode_info *vnode_info)
 	}
 }
 
-static struct vnode_info *alloc_vnode_info(struct sd_node *nodes,
+static struct vnode_info *alloc_vnode_info(const struct sd_node *nodes,
 					   size_t nr_nodes)
 {
 	struct vnode_info *vnode_info;
@@ -283,7 +283,7 @@ static void cluster_op_done(struct work *work)
  * Must run in the main thread as it accesses unlocked state like
  * sys->pending_list.
  */
-bool sd_block_handler(struct sd_node *sender)
+bool sd_block_handler(const struct sd_node *sender)
 {
 	struct request *req;
 
@@ -351,8 +351,8 @@ static int get_nodes_nr_epoch(uint32_t epoch)
 	return epoch_log_read(epoch, nodes, sizeof(nodes));
 }
 
-static struct sd_node *find_entry_list(struct sd_node *entry,
-					struct list_head *head)
+static const struct sd_node *find_entry_list(const struct sd_node *entry,
+					     struct list_head *head)
 {
 	struct node *n;
 	list_for_each_entry(n, head, list)
@@ -363,8 +363,8 @@ static struct sd_node *find_entry_list(struct sd_node *entry,
 
 }
 
-static struct sd_node *find_entry_epoch(struct sd_node *entry,
-					uint32_t epoch)
+static const struct sd_node *find_entry_epoch(const struct sd_node *entry,
+					      uint32_t epoch)
 {
 	struct sd_node nodes[SD_MAX_NODES];
 	int nr, i;
@@ -387,7 +387,7 @@ static struct sd_node *find_entry_epoch(struct sd_node *entry,
  * an automated restart.  These nodes will become part of the cluster by
  * the time it does get restarted.
  */
-static bool add_delayed_node(uint32_t epoch, struct sd_node *node)
+static bool add_delayed_node(uint32_t epoch, const struct sd_node *node)
 {
 	struct node *n;
 
@@ -406,7 +406,7 @@ static bool add_delayed_node(uint32_t epoch, struct sd_node *node)
  * epoch, and if so add it to the list of node expected to be present
  * but failing to join.
  */
-static bool add_failed_node(uint32_t epoch, struct sd_node *node)
+static bool add_failed_node(uint32_t epoch, const struct sd_node *node)
 {
 	struct node *n;
 
@@ -425,7 +425,8 @@ static bool add_failed_node(uint32_t epoch, struct sd_node *node)
  * Add the failed and delayed nodes in a join message to the local
  * lists of such nodes.
  */
-static void update_exceptional_node_list(uint32_t epoch, struct join_message *jm)
+static void update_exceptional_node_list(uint32_t epoch,
+					 const struct join_message *jm)
 {
 	int i;
 
@@ -498,8 +499,8 @@ static int cluster_sanity_check(struct join_message *jm)
 	return CJ_RES_SUCCESS;
 }
 
-static int cluster_wait_for_join_check(struct sd_node *joined,
-		struct join_message *jm)
+static int cluster_wait_for_join_check(const struct sd_node *joined,
+				       struct join_message *jm)
 {
 	struct sd_node local_entries[SD_MAX_NODES];
 	int nr, nr_local_entries, nr_failed_entries, nr_delayed_nodes;
@@ -684,8 +685,9 @@ int log_current_epoch(void)
 				current_vnode_info->nr_nodes);
 }
 
-static struct vnode_info *alloc_old_vnode_info(struct sd_node *joined,
-		struct sd_node *nodes, size_t nr_nodes)
+static struct vnode_info *alloc_old_vnode_info(const struct sd_node *joined,
+					       const struct sd_node *nodes,
+					       size_t nr_nodes)
 {
 	struct sd_node old_nodes[SD_MAX_NODES];
 	size_t count = 0, i;
@@ -698,8 +700,9 @@ static struct vnode_info *alloc_old_vnode_info(struct sd_node *joined,
 	return alloc_vnode_info(old_nodes, count);
 }
 
-static void finish_join(struct join_message *msg, struct sd_node *joined,
-		struct sd_node *nodes, size_t nr_nodes)
+static void finish_join(const struct join_message *msg,
+			const struct sd_node *joined,
+			const struct sd_node *nodes, size_t nr_nodes)
 {
 	sys->join_finished = true;
 	sys->epoch = msg->epoch;
@@ -732,7 +735,7 @@ static void finish_join(struct join_message *msg, struct sd_node *joined,
 	sockfd_cache_add_group(nodes, nr_nodes);
 }
 
-static void get_vdis(struct sd_node *nodes, size_t nr_nodes)
+static void get_vdis(const struct sd_node *nodes, size_t nr_nodes)
 {
 	int array_len = nr_nodes * sizeof(struct sd_node);
 	struct get_vdis_work *w;
@@ -786,8 +789,9 @@ void recalculate_vnodes(struct sd_node *nodes, int nr_nodes)
 	}
 }
 
-static void update_cluster_info(struct join_message *msg,
-				struct sd_node *joined, struct sd_node *nodes,
+static void update_cluster_info(const struct join_message *msg,
+				const struct sd_node *joined,
+				const struct sd_node *nodes,
 				size_t nr_nodes)
 {
 	struct vnode_info *old_vnode_info;
@@ -855,10 +859,11 @@ static void update_cluster_info(struct join_message *msg,
  * Must run in the main thread as it accesses unlocked state like
  * sys->pending_list.
  */
-void sd_notify_handler(struct sd_node *sender, void *data, size_t data_len)
+void sd_notify_handler(const struct sd_node *sender, void *data,
+		       size_t data_len)
 {
 	struct vdi_op_message *msg = data;
-	struct sd_op_template *op = get_sd_op(msg->req.opcode);
+	const struct sd_op_template *op = get_sd_op(msg->req.opcode);
 	int ret = msg->rsp.result;
 	struct request *req = NULL;
 
@@ -889,7 +894,8 @@ void sd_notify_handler(struct sd_node *sender, void *data, size_t data_len)
 	}
 }
 
-enum cluster_join_result sd_check_join_cb(struct sd_node *joining, void *opaque)
+enum cluster_join_result sd_check_join_cb(const struct sd_node *joining,
+					  void *opaque)
 {
 	struct join_message *jm = opaque;
 	char str[256];
@@ -1013,13 +1019,14 @@ static int send_join_request(struct sd_node *ent)
 	return ret;
 }
 
-void sd_join_handler(struct sd_node *joined, struct sd_node *members,
-		size_t nr_members, enum cluster_join_result result,
-		void *opaque)
+void sd_join_handler(const struct sd_node *joined,
+		     const struct sd_node *members,
+		     size_t nr_members, enum cluster_join_result result,
+		     const void *opaque)
 {
 	int i;
 	int nr, nr_local, nr_failed, nr_delayed_nodes;
-	struct join_message *jm = opaque;
+	const struct join_message *jm = opaque;
 	uint32_t le = get_latest_epoch();
 
 	if (node_eq(joined, &sys->this_node)) {
@@ -1098,8 +1105,8 @@ void sd_join_handler(struct sd_node *joined, struct sd_node *members,
 	}
 }
 
-void sd_leave_handler(struct sd_node *left, struct sd_node *members,
-		size_t nr_members)
+void sd_leave_handler(const struct sd_node *left, const struct sd_node *members,
+		      size_t nr_members)
 {
 	struct vnode_info *old_vnode_info;
 	int i;
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index c6c479a..ab6499d 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -99,7 +99,7 @@ static inline int mark_cache_in_reclaim(void)
 	return uatomic_cmpxchg(&sys_cache.in_reclaim, 0, 1);
 }
 
-static inline bool entry_is_dirty(struct object_cache_entry *entry)
+static inline bool entry_is_dirty(const struct object_cache_entry *entry)
 {
 	return !!entry->bmap;
 }
@@ -110,7 +110,7 @@ static inline int hash(uint64_t vid)
 }
 
 /* We should always use this helper to get entry idx */
-static inline uint32_t entry_idx(struct object_cache_entry *entry)
+static inline uint32_t entry_idx(const struct object_cache_entry *entry)
 {
 	return entry->idx & ~CACHE_INDEX_MASK;
 }
@@ -951,7 +951,7 @@ out:
 	return ret;
 }
 
-bool bypass_object_cache(struct request *req)
+bool bypass_object_cache(const struct request *req)
 {
 	uint64_t oid = req->rq.obj.oid;
 
@@ -1096,7 +1096,7 @@ int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 	return ret;
 }
 
-int object_cache_flush_vdi(struct request *req)
+int object_cache_flush_vdi(const struct request *req)
 {
 	uint32_t vid = oid_to_vid(req->rq.obj.oid);
 	struct object_cache *cache;
@@ -1110,7 +1110,7 @@ int object_cache_flush_vdi(struct request *req)
 	return object_cache_push(cache);
 }
 
-int object_cache_flush_and_del(struct request *req)
+int object_cache_flush_and_del(const struct request *req)
 {
 	uint32_t vid = oid_to_vid(req->rq.obj.oid);
 	struct object_cache *cache;
diff --git a/sheep/ops.c b/sheep/ops.c
index 1e2539c..902de88 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -1172,7 +1172,7 @@ static struct sd_op_template sd_ops[] = {
 	},
 };
 
-struct sd_op_template *get_sd_op(uint8_t opcode)
+const struct sd_op_template *get_sd_op(uint8_t opcode)
 {
 	if (sd_ops[opcode].type == 0)
 		return NULL;
@@ -1180,42 +1180,42 @@ struct sd_op_template *get_sd_op(uint8_t opcode)
 	return sd_ops + opcode;
 }
 
-const char *op_name(struct sd_op_template *op)
+const char *op_name(const struct sd_op_template *op)
 {
 	return op->name;
 }
 
-bool is_cluster_op(struct sd_op_template *op)
+bool is_cluster_op(const struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_CLUSTER;
 }
 
-bool is_local_op(struct sd_op_template *op)
+bool is_local_op(const struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_LOCAL;
 }
 
-bool is_peer_op(struct sd_op_template *op)
+bool is_peer_op(const struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_PEER;
 }
 
-bool is_gateway_op(struct sd_op_template *op)
+bool is_gateway_op(const struct sd_op_template *op)
 {
 	return op->type == SD_OP_TYPE_GATEWAY;
 }
 
-bool is_force_op(struct sd_op_template *op)
+bool is_force_op(const struct sd_op_template *op)
 {
 	return !!op->force;
 }
 
-bool has_process_work(struct sd_op_template *op)
+bool has_process_work(const struct sd_op_template *op)
 {
 	return !!op->process_work;
 }
 
-bool has_process_main(struct sd_op_template *op)
+bool has_process_main(const struct sd_op_template *op)
 {
 	return !!op->process_main;
 }
@@ -1239,13 +1239,13 @@ void do_process_work(struct work *work)
 	req->rp.result = ret;
 }
 
-int do_process_main(struct sd_op_template *op, const struct sd_req *req,
+int do_process_main(const struct sd_op_template *op, const struct sd_req *req,
 		    struct sd_rsp *rsp, void *data)
 {
 	return op->process_main(req, rsp, data);
 }
 
-int sheep_do_op_work(struct sd_op_template *op, struct request *req)
+int sheep_do_op_work(const struct sd_op_template *op, struct request *req)
 {
 	return op->process_work(req);
 }
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 6716061..9ff2fc3 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -127,7 +127,7 @@ static int err_to_sderr(uint64_t oid, int err)
 	}
 }
 
-int default_write(uint64_t oid, struct siocb *iocb)
+int default_write(uint64_t oid, const struct siocb *iocb)
 {
 	int flags = get_open_flags(oid, false), fd, ret = SD_RES_SUCCESS;
 	char path[PATH_MAX];
@@ -214,7 +214,7 @@ static int init_objlist_and_vdi_bitmap(uint64_t oid, void *arg)
 	return SD_RES_SUCCESS;
 }
 
-int default_init(char *p)
+int default_init(const char *p)
 {
 	dprintf("use plain store driver\n");
 
@@ -230,8 +230,8 @@ int default_init(char *p)
 	return for_each_object_in_wd(init_objlist_and_vdi_bitmap, true, NULL);
 }
 
-static int default_read_from_path(uint64_t oid, char *path,
-				       struct siocb *iocb)
+static int default_read_from_path(uint64_t oid, const char *path,
+				  const struct siocb *iocb)
 {
 	int flags = get_open_flags(oid, false), fd, ret = SD_RES_SUCCESS;
 	ssize_t size;
@@ -254,7 +254,7 @@ static int default_read_from_path(uint64_t oid, char *path,
 	return ret;
 }
 
-int default_read(uint64_t oid, struct siocb *iocb)
+int default_read(uint64_t oid, const struct siocb *iocb)
 {
 	int ret;
 	char path[PATH_MAX];
@@ -292,7 +292,7 @@ int prealloc(int fd, uint32_t size)
 	return 0;
 }
 
-int default_create_and_write(uint64_t oid, struct siocb *iocb)
+int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 {
 	char path[PATH_MAX], tmp_path[PATH_MAX];
 	int flags = get_open_flags(oid, true);
@@ -351,7 +351,7 @@ out:
 	return ret;
 }
 
-int default_link(uint64_t oid, struct siocb *iocb, uint32_t tgt_epoch)
+int default_link(uint64_t oid, uint32_t tgt_epoch)
 {
 	char path[PATH_MAX], stale_path[PATH_MAX];
 
@@ -374,9 +374,9 @@ static bool oid_stale(uint64_t oid)
 {
 	int i, nr_copies;
 	struct vnode_info *vinfo;
-	struct sd_vnode *v;
+	const struct sd_vnode *v;
 	bool ret = true;
-	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
+	const struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
 
 	vinfo = get_vnode_info();
 	nr_copies = get_obj_copy_number(oid, vinfo->nr_zones);
@@ -425,7 +425,8 @@ static int check_stale_objects(uint64_t oid, void *arg)
 	return SD_RES_SUCCESS;
 }
 
-int default_end_recover(uint32_t old_epoch, struct vnode_info *old_vnode_info)
+int default_end_recover(uint32_t old_epoch,
+			const struct vnode_info *old_vnode_info)
 {
 	if (old_epoch == 0)
 		return SD_RES_SUCCESS;
diff --git a/sheep/recovery.c b/sheep/recovery.c
index f8e5b79..64b5b63 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -60,7 +60,8 @@ static int obj_cmp(const void *oid1, const void *oid2)
 	return 0;
 }
 
-static int recover_object_from_replica(uint64_t oid, struct sd_vnode *vnode,
+static int recover_object_from_replica(uint64_t oid,
+				       const struct sd_vnode *vnode,
 				       uint32_t epoch, uint32_t tgt_epoch)
 {
 	struct sd_req hdr;
@@ -70,14 +71,12 @@ static int recover_object_from_replica(uint64_t oid, struct sd_vnode *vnode,
 	void *buf = NULL;
 	struct siocb iocb = { 0 };
 
-	rlen = get_objsize(oid);
 	if (vnode_is_local(vnode)) {
-		iocb.epoch = epoch;
-		iocb.length = rlen;
-		ret = sd_store->link(oid, &iocb, tgt_epoch);
+		ret = sd_store->link(oid, tgt_epoch);
 		goto out;
 	}
 
+	rlen = get_objsize(oid);
 	buf = valloc(rlen);
 	if (!buf) {
 		eprintf("%m\n");
@@ -113,8 +112,8 @@ out:
  * A virtual node that does not match any node in current node list
  * means the node has left the cluster, then it's an invalid virtual node.
  */
-static bool is_invalid_vnode(struct sd_vnode *entry, struct sd_node *nodes,
-			     int nr_nodes)
+static bool is_invalid_vnode(const struct sd_vnode *entry,
+			     struct sd_node *nodes, int nr_nodes)
 {
 	if (bsearch(entry, nodes, nr_nodes, sizeof(struct sd_node),
 		    node_id_cmp))
@@ -143,9 +142,9 @@ again:
 	/* Let's do a breadth-first search */
 	nr_copies = get_obj_copy_number(oid, old->nr_zones);
 	for (i = 0; i < nr_copies; i++) {
-		struct sd_vnode *tgt_vnode = oid_to_vnode(old->vnodes,
-							  old->nr_vnodes,
-							  oid, i);
+		const struct sd_vnode *tgt_vnode;
+
+		tgt_vnode = oid_to_vnode(old->vnodes,old->nr_vnodes, oid, i);
 
 		if (is_invalid_vnode(tgt_vnode, rw->cur_vinfo->nodes,
 				     rw->cur_vinfo->nr_nodes))
@@ -534,7 +533,7 @@ static int fetch_object_list(struct sd_node *e, uint32_t epoch,
 static void screen_object_list(struct recovery_work *rw,
 			       uint64_t *oids, int nr_oids)
 {
-	struct sd_vnode *vnodes[SD_MAX_COPIES];
+	const struct sd_vnode *vnodes[SD_MAX_COPIES];
 	int old_count = rw->count;
 	int nr_objs;
 	int i, j;
diff --git a/sheep/request.c b/sheep/request.c
index 5922bed..1f9e335 100644
--- a/sheep/request.c
+++ b/sheep/request.c
@@ -26,7 +26,7 @@ static void requeue_request(struct request *req);
 
 static bool is_access_local(struct request *req, uint64_t oid)
 {
-	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
+	const struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
 	int nr_copies;
 	int i;
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 9c6f927..1f3fb97 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -41,7 +41,7 @@ struct request {
 	struct sd_req rq;
 	struct sd_rsp rp;
 
-	struct sd_op_template *op;
+	const struct sd_op_template *op;
 
 	void *data;
 	unsigned int data_length;
@@ -136,7 +136,7 @@ struct siocb {
 };
 
 struct vdi_iocb {
-	char *name;
+	const char *name;
 	uint32_t data_len;
 	uint64_t size;
 	uint32_t base_vid;
@@ -147,34 +147,36 @@ struct vdi_iocb {
 struct store_driver {
 	struct list_head list;
 	const char *name;
-	int (*init)(char *path);
+	int (*init)(const char *path);
 	bool (*exist)(uint64_t oid);
 	/* create_and_write must be an atomic operation*/
-	int (*create_and_write)(uint64_t oid, struct siocb *);
-	int (*write)(uint64_t oid, struct siocb *);
-	int (*read)(uint64_t oid, struct siocb *);
+	int (*create_and_write)(uint64_t oid, const struct siocb *);
+	int (*write)(uint64_t oid, const struct siocb *);
+	int (*read)(uint64_t oid, const struct siocb *);
 	int (*format)(void);
 	int (*remove_object)(uint64_t oid);
 	/* Operations in recovery */
-	int (*link)(uint64_t oid, struct siocb *, uint32_t tgt_epoch);
-	int (*begin_recover)(struct siocb *);
-	int (*end_recover)(uint32_t epoch, struct vnode_info *old_vnode_info);
+	int (*link)(uint64_t oid, uint32_t tgt_epoch);
+	int (*begin_recover)(const struct siocb *);
+	int (*end_recover)(uint32_t epoch,
+			   const struct vnode_info *old_vnode_info);
 	int (*purge_obj)(void);
 	/* Operations for snapshot */
-	int (*snapshot)(struct siocb *);
+	int (*snapshot)(const struct siocb *);
 	int (*cleanup)(void);
-	int (*restore)(struct siocb *);
+	int (*restore)(const struct siocb *);
 	int (*get_snap_file)(struct siocb *);
 	int (*flush)(void);
 };
 
-int default_init(char *p);
+int default_init(const char *p);
 bool default_exist(uint64_t oid);
-int default_create_and_write(uint64_t oid, struct siocb *iocb);
-int default_write(uint64_t oid, struct siocb *iocb);
-int default_read(uint64_t oid, struct siocb *iocb);
-int default_link(uint64_t oid, struct siocb *iocb, uint32_t tgt_epoch);
-int default_end_recover(uint32_t old_epoch, struct vnode_info *old_vnode_info);
+int default_create_and_write(uint64_t oid, const struct siocb *iocb);
+int default_write(uint64_t oid, const struct siocb *iocb);
+int default_read(uint64_t oid, const struct siocb *iocb);
+int default_link(uint64_t oid, uint32_t tgt_epoch);
+int default_end_recover(uint32_t old_epoch,
+			const struct vnode_info *old_vnode_info);
 int default_cleanup(void);
 int default_format(void);
 int default_remove_object(uint64_t oid);
@@ -231,8 +233,8 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid);
 int del_vdi(struct request *req, char *data, int data_len, uint32_t *vid,
 	    uint32_t snapid, unsigned int *nr_copies);
 
-int lookup_vdi(char *name, char *tag, uint32_t *vid, uint32_t snapid,
-	       unsigned int *nr_copies, uint64_t *ctime);
+int lookup_vdi(const char *name, const char *tag, uint32_t *vid,
+	       uint32_t snapid, unsigned int *nr_copies, uint64_t *ctime);
 
 int read_vdis(char *data, int len, unsigned int *rsp_len);
 
@@ -280,7 +282,6 @@ int get_cluster_space(uint64_t *space);
 
 int store_file_write(void *buffer, size_t len);
 void *store_file_read(void);
-int get_max_nr_copies_from(struct sd_node *entries, int nr);
 
 int epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len);
 int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len);
@@ -317,19 +318,19 @@ void put_request(struct request *req);
 
 /* Operations */
 
-struct sd_op_template *get_sd_op(uint8_t opcode);
-const char *op_name(struct sd_op_template *op);
-bool is_cluster_op(struct sd_op_template *op);
-bool is_local_op(struct sd_op_template *op);
-bool is_peer_op(struct sd_op_template *op);
-bool is_gateway_op(struct sd_op_template *op);
-bool is_force_op(struct sd_op_template *op);
-bool has_process_work(struct sd_op_template *op);
-bool has_process_main(struct sd_op_template *op);
+const struct sd_op_template *get_sd_op(uint8_t opcode);
+const char *op_name(const struct sd_op_template *op);
+bool is_cluster_op(const struct sd_op_template *op);
+bool is_local_op(const struct sd_op_template *op);
+bool is_peer_op(const struct sd_op_template *op);
+bool is_gateway_op(const struct sd_op_template *op);
+bool is_force_op(const struct sd_op_template *op);
+bool has_process_work(const struct sd_op_template *op);
+bool has_process_main(const struct sd_op_template *op);
 void do_process_work(struct work *work);
-int do_process_main(struct sd_op_template *op, const struct sd_req *req,
+int do_process_main(const struct sd_op_template *op, const struct sd_req *req,
 		    struct sd_rsp *rsp, void *data);
-int sheep_do_op_work(struct sd_op_template *op, struct request *req);
+int sheep_do_op_work(const struct sd_op_template *op, struct request *req);
 int gateway_to_peer_opcode(int opcode);
 
 /* Journal */
@@ -338,19 +339,19 @@ struct jrnl_descriptor *jrnl_begin(const void *buf, size_t count, off_t offset,
 int jrnl_end(struct jrnl_descriptor *jd);
 int jrnl_recover(const char *jrnl_dir);
 
-static inline bool is_myself(uint8_t *addr, uint16_t port)
+static inline bool is_myself(const uint8_t *addr, uint16_t port)
 {
 	return (memcmp(addr, sys->this_node.nid.addr,
 		       sizeof(sys->this_node.nid.addr)) == 0) &&
 		port == sys->this_node.nid.port;
 }
 
-static inline bool vnode_is_local(struct sd_vnode *v)
+static inline bool vnode_is_local(const struct sd_vnode *v)
 {
 	return is_myself(v->nid.addr, v->nid.port);
 }
 
-static inline bool node_is_local(struct sd_node *n)
+static inline bool node_is_local(const struct sd_node *n)
 {
 	return is_myself(n->nid.addr, n->nid.port);
 }
@@ -373,7 +374,7 @@ int default_flush(void);
 
 /* object_cache */
 
-bool bypass_object_cache(struct request *req);
+bool bypass_object_cache(const struct request *req);
 bool object_is_cached(uint64_t oid);
 
 void object_cache_try_to_reclaim(void);
@@ -382,8 +383,8 @@ int object_cache_write(uint64_t oid, char *data, unsigned int datalen,
 		       uint64_t offset, uint16_t flags, bool create);
 int object_cache_read(uint64_t oid, char *data, unsigned int datalen,
 		      uint64_t offset);
-int object_cache_flush_vdi(struct request *req);
-int object_cache_flush_and_del(struct request *req);
+int object_cache_flush_vdi(const struct request *req);
+int object_cache_flush_and_del(const struct request *req);
 void object_cache_delete(uint32_t vid);
 int object_cache_init(const char *p);
 void object_cache_remove(uint64_t oid);
@@ -397,14 +398,14 @@ struct sockfd {
 	int idx;
 };
 
-void sockfd_cache_del(struct node_id *);
-void sockfd_cache_add(struct node_id *);
-void sockfd_cache_add_group(struct sd_node *nodes, int nr);
+void sockfd_cache_del(const struct node_id *);
+void sockfd_cache_add(const struct node_id *);
+void sockfd_cache_add_group(const struct sd_node *nodes, int nr);
 
-struct sockfd *sheep_get_sockfd(struct node_id *);
-void sheep_put_sockfd(struct node_id *, struct sockfd *);
-void sheep_del_sockfd(struct node_id *, struct sockfd *);
-int sheep_exec_req(struct node_id *nid, struct sd_req *hdr, void *data,
+struct sockfd *sheep_get_sockfd(const struct node_id *);
+void sheep_put_sockfd(const struct node_id *, struct sockfd *);
+void sheep_del_sockfd(const struct node_id *, struct sockfd *);
+int sheep_exec_req(const struct node_id *nid, struct sd_req *hdr, void *data,
 		   unsigned int *rlen);
 
 static inline bool is_object_cache_enabled(void)
diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index 6f3da08..f2ccb40 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -101,7 +101,7 @@ sockfd_cache_insert(struct sockfd_cache_entry *new)
 	return NULL; /* insert successfully */
 }
 
-static struct sockfd_cache_entry *sockfd_cache_search(struct node_id *nid)
+static struct sockfd_cache_entry *sockfd_cache_search(const struct node_id *nid)
 {
 	struct rb_node *n = sockfd_cache.root.rb_node;
 	struct sockfd_cache_entry *t;
@@ -141,7 +141,7 @@ static inline int get_free_slot(struct sockfd_cache_entry *entry)
  *
  * If no free slot available, this typically means we should use short FD.
  */
-static struct sockfd_cache_entry *sockfd_cache_grab(struct node_id *nid,
+static struct sockfd_cache_entry *sockfd_cache_grab(const struct node_id *nid,
 						    char *name, int *ret_idx)
 {
 	struct sockfd_cache_entry *entry;
@@ -185,7 +185,7 @@ static inline void destroy_all_slots(struct sockfd_cache_entry *entry)
  * the victim node will finally find itself talking to a dead node and call
  * sheep_del_fd() to delete this node from the cache.
  */
-static bool sockfd_cache_destroy(struct node_id *nid)
+static bool sockfd_cache_destroy(const struct node_id *nid)
 {
 	struct sockfd_cache_entry *entry;
 
@@ -214,7 +214,7 @@ false_out:
 }
 
 /* When node craches, we should delete it from the cache */
-void sockfd_cache_del(struct node_id *nid)
+void sockfd_cache_del(const struct node_id *nid)
 {
 	char name[INET6_ADDRSTRLEN];
 	int n;
@@ -227,7 +227,7 @@ void sockfd_cache_del(struct node_id *nid)
 	dprintf("%s:%d, count %d\n", name, nid->port, n);
 }
 
-static void sockfd_cache_add_nolock(struct node_id *nid)
+static void sockfd_cache_add_nolock(const struct node_id *nid)
 {
 	struct sockfd_cache_entry *new = xmalloc(sizeof(*new));
 	int i;
@@ -245,9 +245,9 @@ static void sockfd_cache_add_nolock(struct node_id *nid)
 }
 
 /* Add group of nodes to the cache */
-void sockfd_cache_add_group(struct sd_node *nodes, int nr)
+void sockfd_cache_add_group(const struct sd_node *nodes, int nr)
 {
-	struct sd_node *p;
+	const struct sd_node *p;
 
 	dprintf("%d\n", nr);
 	pthread_rwlock_wrlock(&sockfd_cache.lock);
@@ -259,7 +259,7 @@ void sockfd_cache_add_group(struct sd_node *nodes, int nr)
 }
 
 /* Add one node to the cache means we can do caching tricks on this node */
-void sockfd_cache_add(struct node_id *nid)
+void sockfd_cache_add(const struct node_id *nid)
 {
 	struct sockfd_cache_entry *new;
 	char name[INET6_ADDRSTRLEN];
@@ -333,7 +333,7 @@ static inline void check_idx(int idx)
 	queue_work(sys->sockfd_wqueue, w);
 }
 
-static struct sockfd *sockfd_cache_get(struct node_id *nid, char *name)
+static struct sockfd *sockfd_cache_get(const struct node_id *nid, char *name)
 {
 	struct sockfd_cache_entry *entry;
 	struct sockfd *sfd;
@@ -366,7 +366,7 @@ out:
 	return sfd;
 }
 
-static void sockfd_cache_put(struct node_id *nid, int idx)
+static void sockfd_cache_put(const struct node_id *nid, int idx)
 {
 	struct sockfd_cache_entry *entry;
 	char name[INET6_ADDRSTRLEN];
@@ -393,7 +393,7 @@ static void sockfd_cache_put(struct node_id *nid, int idx)
  *
  * ret_idx is opaque to the caller, -1 indicates it is a short FD.
  */
-struct sockfd *sheep_get_sockfd(struct node_id *nid)
+struct sockfd *sheep_get_sockfd(const struct node_id *nid)
 {
 	char name[INET6_ADDRSTRLEN];
 	struct sockfd *sfd;
@@ -429,7 +429,7 @@ struct sockfd *sheep_get_sockfd(struct node_id *nid)
  * sheep_get_sockfd()
  */
 
-void sheep_put_sockfd(struct node_id *nid, struct sockfd *sfd)
+void sheep_put_sockfd(const struct node_id *nid, struct sockfd *sfd)
 {
 	if (sfd->idx == -1) {
 		dprintf("%d\n", sfd->fd);
@@ -449,7 +449,7 @@ void sheep_put_sockfd(struct node_id *nid, struct sockfd *sfd)
  * this vnode in the cache.
  * If it is a short FD, just close it.
  */
-void sheep_del_sockfd(struct node_id *nid, struct sockfd *sfd)
+void sheep_del_sockfd(const struct node_id *nid, struct sockfd *sfd)
 {
 	if (sfd->idx == -1) {
 		dprintf("%d\n", sfd->fd);
@@ -463,7 +463,7 @@ void sheep_del_sockfd(struct node_id *nid, struct sockfd *sfd)
 	free(sfd);
 }
 
-int sheep_exec_req(struct node_id *nid, struct sd_req *hdr, void *buf,
+int sheep_exec_req(const struct node_id *nid, struct sd_req *hdr, void *buf,
 		   unsigned int *rlen)
 {
 	struct sd_rsp *rsp = (struct sd_rsp *)hdr;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 45219ed..6613db8 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -201,7 +201,7 @@ static int create_vdi_obj(struct vdi_iocb *iocb, uint32_t new_vid,
 	struct timeval tv;
 	int ret = SD_RES_NO_MEM;
 	unsigned long block_size = SD_DATA_OBJ_SIZE;
-	char *name = iocb->name;
+	const char *name = iocb->name;
 
 	new = zalloc(sizeof(*new));
 	if (!new) {
@@ -314,10 +314,11 @@ out:
 	return ret;
 }
 
-static int find_first_vdi(unsigned long start, unsigned long end, char *name,
-			  char *tag, uint32_t snapid, uint32_t *vid,
-			  unsigned long *deleted_nr, uint32_t *next_snap,
-			  unsigned int *inode_nr_copies, uint64_t *create_time)
+static int find_first_vdi(unsigned long start, unsigned long end,
+			  const char *name, const char *tag, uint32_t snapid,
+			  uint32_t *vid, unsigned long *deleted_nr,
+			  uint32_t *next_snap, unsigned int *inode_nr_copies,
+			  uint64_t *create_time)
 {
 	struct sheepdog_inode *inode = NULL;
 	unsigned long i;
@@ -378,10 +379,11 @@ out:
 	return ret;
 }
 
-static int do_lookup_vdi(char *name, int namelen, uint32_t *vid, char *tag,
-		uint32_t snapid, uint32_t *next_snapid, unsigned long *right_nr,
-		unsigned long *deleted_nr, unsigned int *nr_copies,
-		uint64_t *create_time)
+static int do_lookup_vdi(const char *name, int namelen, uint32_t *vid,
+			 const char *tag, uint32_t snapid,
+			 uint32_t *next_snapid, unsigned long *right_nr,
+			 unsigned long *deleted_nr, unsigned int *nr_copies,
+			 uint64_t *create_time)
 {
 	int ret;
 	unsigned long nr, start_nr;
@@ -425,8 +427,8 @@ right_side:
 	}
 }
 
-int lookup_vdi(char *name, char *tag, uint32_t *vid, uint32_t snapid,
-	       unsigned int *nr_copies, uint64_t *create_time)
+int lookup_vdi(const char *name, const char *tag, uint32_t *vid,
+	       uint32_t snapid, unsigned int *nr_copies, uint64_t *create_time)
 {
 	uint32_t dummy0;
 	unsigned long dummy1, dummy2;
@@ -443,7 +445,7 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 	unsigned long nr, deleted_nr = SD_NR_VDIS, right_nr = SD_NR_VDIS;
 	unsigned int dummy;
 	int ret;
-	char *name;
+	const char *name;
 
 	if (iocb->data_len != SD_MAX_VDI_LEN)
 		return SD_RES_INVALID_PARMS;
@@ -490,7 +492,7 @@ static int start_deletion(struct request *req, uint32_t vid);
 int del_vdi(struct request *req, char *data, int data_len,
 	    uint32_t *vid, uint32_t snapid, unsigned int *nr_copies)
 {
-	char *name = data, *tag;
+	const char *name = data, *tag;
 	uint32_t dummy0;
 	unsigned long dummy1, dummy2;
 	int ret;
-- 
1.7.2.5




More information about the sheepdog mailing list