[sheepdog] [PATCH 2/2] sheep: move read/write/remove_object to vdi.c

Christoph Hellwig hch at infradead.org
Thu May 31 10:47:10 CEST 2012


These helpers are only used by the VDI code to forward I/O requests, so move
them to vdi.c instead of store.c where they are misplaced.

Signed-off-by: Christoph Hellwig <hch at lst.de>

---
 sheep/sheep_priv.h |    8 ---
 sheep/store.c      |  132 -----------------------------------------------------
 sheep/vdi.c        |  131 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+), 140 deletions(-)

Index: sheepdog/sheep/sheep_priv.h
===================================================================
--- sheepdog.orig/sheep/sheep_priv.h	2012-05-31 10:32:35.275894444 +0200
+++ sheepdog/sheep/sheep_priv.h	2012-05-31 10:32:36.307894433 +0200
@@ -291,14 +291,6 @@ int is_recoverying_oid(uint64_t oid);
 int is_recovery_init(void);
 int node_in_recovery(void);
 
-int write_object(struct vnode_info *vnodes, uint32_t node_version,
-		 uint64_t oid, char *data, unsigned int datalen,
-		 uint64_t offset, uint16_t flags, int nr, int create);
-int read_object(struct vnode_info *vnodes, uint32_t node_version,
-		uint64_t oid, char *data, unsigned int datalen,
-		uint64_t offset, int nr);
-int remove_object(struct vnode_info *vnodes, uint32_t node_version,
-		  uint64_t oid, int nr);
 int merge_objlist(uint64_t *list1, int nr_list1, uint64_t *list2, int nr_list2);
 
 void del_sheep_fd(int fd);
Index: sheepdog/sheep/store.c
===================================================================
--- sheepdog.orig/sheep/store.c	2012-05-31 10:32:35.279894443 +0200
+++ sheepdog/sheep/store.c	2012-05-31 10:32:36.307894433 +0200
@@ -533,138 +533,6 @@ int read_epoch(uint32_t *epoch, uint64_t
 	return SD_RES_SUCCESS;
 }
 
-/*
- * Write data to both local object cache (if enabled) and backends
- */
-int write_object(struct vnode_info *vnodes, uint32_t epoch,
-		 uint64_t oid, char *data, unsigned int datalen,
-		 uint64_t offset, uint16_t flags, int nr_copies, int create)
-{
-	struct request write_req;
-	struct sd_req *hdr = &write_req.rq;
-	int ret;
-
-	if (sys->enable_write_cache && object_is_cached(oid)) {
-		ret = object_cache_write(oid, data, datalen, offset,
-			flags, nr_copies, epoch, create);
-		if (ret != 0) {
-			eprintf("write cache failed %"PRIx64" %"PRIx32"\n",
-				oid, ret);
-			return ret;
-		}
-	}
-
-	memset(&write_req, 0, sizeof(write_req));
-	hdr->opcode = create ? SD_OP_CREATE_AND_WRITE_OBJ : SD_OP_WRITE_OBJ;
-	hdr->flags = SD_FLAG_CMD_WRITE;
-	hdr->data_length = datalen;
-	hdr->epoch = epoch;
-
-	hdr->obj.oid = oid;
-	hdr->obj.offset = offset;
-	hdr->obj.copies = nr_copies;
-
-	write_req.data = data;
-	write_req.op = get_sd_op(hdr->opcode);
-	write_req.vnodes = vnodes;
-
-	ret = forward_write_obj_req(&write_req);
-	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to forward write object %x\n", ret);
-	return ret;
-}
-
-/*
- * Read data firstly from local object cache(if enabled), if fail,
- * try read backends
- */
-int read_object(struct vnode_info *vnodes, uint32_t epoch,
-		uint64_t oid, char *data, unsigned int datalen,
-		uint64_t offset, int nr_copies)
-{
-	struct request read_req;
-	struct sd_req *hdr = &read_req.rq;
-	int ret;
-
-	if (sys->enable_write_cache && object_is_cached(oid)) {
-		ret = object_cache_read(oid, data, datalen, offset,
-					nr_copies, epoch);
-		if (ret != SD_RES_SUCCESS) {
-			eprintf("try forward read %"PRIx64" %"PRIx32"\n",
-				oid, ret);
-			goto forward_read;
-		}
-		return ret;
-	}
-	memset(&read_req, 0, sizeof(read_req));
-forward_read:
-	hdr->opcode = SD_OP_READ_OBJ;
-	hdr->data_length = datalen;
-	hdr->epoch = epoch;
-
-	hdr->obj.oid = oid;
-	hdr->obj.offset = offset;
-	hdr->obj.copies = nr_copies;
-
-	read_req.data = data;
-	read_req.op = get_sd_op(hdr->opcode);
-	read_req.vnodes = vnodes;
-
-	ret = forward_read_obj_req(&read_req);
-	if (ret != SD_RES_SUCCESS)
-		eprintf("failed to forward read object %x\n", ret);
-
-	return ret;
-}
-
-int remove_object(struct vnode_info *vnodes, uint32_t epoch,
-		  uint64_t oid, int nr)
-{
-	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
-	int err = 0, i = 0;
-
-	oid_to_vnodes(vnodes, oid, nr, obj_vnodes);
-	for (i = 0; i < nr; i++) {
-		struct sd_req hdr;
-		struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-		struct sd_vnode *v;
-		unsigned wlen = 0, rlen = 0;
-		char name[128];
-		int fd, ret;
-
-		v = obj_vnodes[i];
-		addr_to_str(name, sizeof(name), v->addr, 0);
-
-		fd = connect_to(name, v->port);
-		if (fd < 0) {
-			rsp->result = SD_RES_EIO;
-			return -1;
-		}
-
-		memset(&hdr, 0, sizeof(hdr));
-		hdr.epoch = epoch;
-		hdr.opcode = SD_OP_REMOVE_OBJ;
-		hdr.flags = 0;
-		hdr.data_length = rlen;
-
-		hdr.obj.oid = oid;
-
-		ret = exec_req(fd, &hdr, NULL, &wlen, &rlen);
-		close(fd);
-
-		if (ret)
-			return -1;
-
-		if (rsp->result != SD_RES_SUCCESS)
-			err = 1;
-	}
-
-	if (err)
-		return -1;
-
-	return 0;
-}
-
 int set_cluster_copies(uint8_t copies)
 {
 	int fd, ret;
Index: sheepdog/sheep/vdi.c
===================================================================
--- sheepdog.orig/sheep/vdi.c	2012-05-31 10:32:30.871894485 +0200
+++ sheepdog/sheep/vdi.c	2012-05-31 10:32:36.307894433 +0200
@@ -16,6 +16,137 @@
 #include "sheep_priv.h"
 
 
+/*
+ * Write data to both local object cache (if enabled) and backends
+ */
+static int write_object(struct vnode_info *vnodes, uint32_t epoch, uint64_t oid,
+		char *data, unsigned int datalen, uint64_t offset,
+		uint16_t flags, int nr_copies, int create)
+{
+	struct request write_req;
+	struct sd_req *hdr = &write_req.rq;
+	int ret;
+
+	if (sys->enable_write_cache && object_is_cached(oid)) {
+		ret = object_cache_write(oid, data, datalen, offset,
+			flags, nr_copies, epoch, create);
+		if (ret != 0) {
+			eprintf("write cache failed %"PRIx64" %"PRIx32"\n",
+				oid, ret);
+			return ret;
+		}
+	}
+
+	memset(&write_req, 0, sizeof(write_req));
+	hdr->opcode = create ? SD_OP_CREATE_AND_WRITE_OBJ : SD_OP_WRITE_OBJ;
+	hdr->flags = SD_FLAG_CMD_WRITE;
+	hdr->data_length = datalen;
+	hdr->epoch = epoch;
+
+	hdr->obj.oid = oid;
+	hdr->obj.offset = offset;
+	hdr->obj.copies = nr_copies;
+
+	write_req.data = data;
+	write_req.op = get_sd_op(hdr->opcode);
+	write_req.vnodes = vnodes;
+
+	ret = forward_write_obj_req(&write_req);
+	if (ret != SD_RES_SUCCESS)
+		eprintf("failed to forward write object %x\n", ret);
+	return ret;
+}
+
+/*
+ * Read data firstly from local object cache(if enabled), if fail,
+ * try read backends
+ */
+static int read_object(struct vnode_info *vnodes, uint32_t epoch, uint64_t oid,
+		char *data, unsigned int datalen, uint64_t offset, int nr_copies)
+{
+	struct request read_req;
+	struct sd_req *hdr = &read_req.rq;
+	int ret;
+
+	if (sys->enable_write_cache && object_is_cached(oid)) {
+		ret = object_cache_read(oid, data, datalen, offset,
+					nr_copies, epoch);
+		if (ret != SD_RES_SUCCESS) {
+			eprintf("try forward read %"PRIx64" %"PRIx32"\n",
+				oid, ret);
+			goto forward_read;
+		}
+		return ret;
+	}
+	memset(&read_req, 0, sizeof(read_req));
+forward_read:
+	hdr->opcode = SD_OP_READ_OBJ;
+	hdr->data_length = datalen;
+	hdr->epoch = epoch;
+
+	hdr->obj.oid = oid;
+	hdr->obj.offset = offset;
+	hdr->obj.copies = nr_copies;
+
+	read_req.data = data;
+	read_req.op = get_sd_op(hdr->opcode);
+	read_req.vnodes = vnodes;
+
+	ret = forward_read_obj_req(&read_req);
+	if (ret != SD_RES_SUCCESS)
+		eprintf("failed to forward read object %x\n", ret);
+
+	return ret;
+}
+
+static int remove_object(struct vnode_info *vnodes, uint32_t epoch,
+		uint64_t oid, int nr)
+{
+	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
+	int err = 0, i = 0;
+
+	oid_to_vnodes(vnodes, oid, nr, obj_vnodes);
+	for (i = 0; i < nr; i++) {
+		struct sd_req hdr;
+		struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
+		struct sd_vnode *v;
+		unsigned wlen = 0, rlen = 0;
+		char name[128];
+		int fd, ret;
+
+		v = obj_vnodes[i];
+		addr_to_str(name, sizeof(name), v->addr, 0);
+
+		fd = connect_to(name, v->port);
+		if (fd < 0) {
+			rsp->result = SD_RES_EIO;
+			return -1;
+		}
+
+		memset(&hdr, 0, sizeof(hdr));
+		hdr.epoch = epoch;
+		hdr.opcode = SD_OP_REMOVE_OBJ;
+		hdr.flags = 0;
+		hdr.data_length = rlen;
+
+		hdr.obj.oid = oid;
+
+		ret = exec_req(fd, &hdr, NULL, &wlen, &rlen);
+		close(fd);
+
+		if (ret)
+			return -1;
+
+		if (rsp->result != SD_RES_SUCCESS)
+			err = 1;
+	}
+
+	if (err)
+		return -1;
+
+	return 0;
+}
+
 /* TODO: should be performed atomically */
 static int create_vdi_obj(struct vnode_info *vnode_info, uint32_t epoch,
 		char *name, uint32_t new_vid, uint64_t size, uint32_t base_vid,



More information about the sheepdog mailing list