[Sheepdog] [PATCH 1/2] journel: move data commiting out of jrnl_perform()

Liu Yuan namei.unix at gmail.com
Wed Nov 16 09:11:35 CET 2011


From: Liu Yuan <tailai.ly at taobao.com>

Let jrnl_perform just concentrate on journeling stuff, not intrude in store IO.
This would make store IO interface abstracting easier and cleaner.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/journal.c    |   24 +----------------
 sheep/sheep_priv.h |    2 +-
 sheep/store.c      |   72 ++++++++++++++++++++++++++++++++++------------------
 3 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/sheep/journal.c b/sheep/journal.c
index beff25c..3fb93f8 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -189,34 +189,16 @@ static int jrnl_apply_to_target_object(struct jrnl_descriptor *jd)
 	return res;
 }
 
-static int jrnl_commit_data(struct jrnl_descriptor *jd)
-{
-	int ret = 0;
-	ssize_t retsize;
-	struct jrnl_head *head = (struct jrnl_head *) &jd->head;
-
-	retsize = pwrite64(jd->target_fd, jd->data, head->size, head->offset);
-	if (retsize != head->size) {
-		if (errno == ENOSPC)
-			ret = SD_RES_NO_SPACE;
-		else
-			ret = SD_RES_EIO;
-	}
-
-	return ret;
-}
-
 /*
  * We cannot use this function for concurrent write operations
  */
-int jrnl_perform(int fd, void *buf, size_t count, off_t offset,
+int jrnl_perform(void *buf, size_t count, off_t offset,
 		 const char *path, const char *jrnl_dir)
 {
 	int ret;
 	struct jrnl_descriptor jd;
 
 	memset(&jd, 0, sizeof(jd));
-	jd.target_fd = fd;
 
 	jd.head.offset = offset;
 	jd.head.size = count;
@@ -240,10 +222,6 @@ int jrnl_perform(int fd, void *buf, size_t count, off_t offset,
 	if (ret)
 		goto out;
 
-	ret = jrnl_commit_data(&jd);
-	if (ret)
-		goto out;
-
 	ret = jrnl_close(&jd);
 	if (ret)
 		goto out;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 56bcbd1..ee4deb4 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -260,7 +260,7 @@ int do_process_main(struct sd_op_template *op, const struct sd_req *req,
 		    struct sd_rsp *rsp, void *data);
 
 /* Journal */
-int jrnl_perform(int fd, void *buf, size_t count, off_t offset,
+int jrnl_perform(void *buf, size_t count, off_t offset,
 		 const char *path, const char *jrnl_dir);
 int jrnl_recover(const char *jrnl_dir);
 
diff --git a/sheep/store.c b/sheep/store.c
index b04228e..3a04c34 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -638,18 +638,17 @@ static int store_write_obj_fd(int fd, struct request *req, uint32_t epoch)
 
 		snprintf(path, sizeof(path), "%s%08u/%016" PRIx64, obj_path,
 			 epoch, oid);
-		ret = jrnl_perform(fd, req->data, hdr->data_length,
+		ret = jrnl_perform(req->data, hdr->data_length,
 				   hdr->offset, path, jrnl_path);
 		if (ret)
 			return ret;
-	} else {
-		ret = pwrite64(fd, req->data, hdr->data_length, hdr->offset);
-		if (ret != hdr->data_length) {
-			if (errno == ENOSPC)
-				return SD_RES_NO_SPACE;
-			eprintf("%m\n");
-			return SD_RES_EIO;
-		}
+	}
+	ret = pwrite64(fd, req->data, hdr->data_length, hdr->offset);
+	if (ret != hdr->data_length) {
+		if (errno == ENOSPC)
+			return SD_RES_NO_SPACE;
+		eprintf("%m\n");
+		return SD_RES_EIO;
 	}
 
 	return SD_RES_SUCCESS;
@@ -1093,17 +1092,24 @@ int set_cluster_ctime(uint64_t ct)
 
 	fd = open(config_path, O_DSYNC | O_WRONLY);
 	if (fd < 0)
-		return -1;
+		return SD_RES_EIO;
 
-	ret = jrnl_perform(fd, &ct, sizeof(ct),
+	ret = jrnl_perform(&ct, sizeof(ct),
 			   offsetof(struct sheepdog_config, ctime),
 			   config_path, jrnl_path);
+	if (ret) {
+		ret = SD_RES_EIO;
+		goto err;
+	}
+	ret = pwrite64(fd, &ct, sizeof(ct), offsetof(struct sheepdog_config, ctime));
+	if (ret != sizeof(ct)) {
+		ret = SD_RES_EIO;
+		goto err;
+	}
+	ret = SD_RES_SUCCESS;
+err:
 	close(fd);
-
-	if (ret)
-		return -1;
-
-	return 0;
+	return ret;
 }
 
 uint64_t get_cluster_ctime(void)
@@ -2130,15 +2136,23 @@ int set_cluster_copies(uint8_t copies)
 	if (fd < 0)
 		return SD_RES_EIO;
 
-	ret = jrnl_perform(fd, &copies, sizeof(copies),
+	ret = jrnl_perform(&copies, sizeof(copies),
 			   offsetof(struct sheepdog_config, copies),
 			   config_path, jrnl_path);
-	close(fd);
-
-	if (ret != 0)
-		return SD_RES_EIO;
+	if (ret != 0) {
+		ret = SD_RES_EIO;
+		goto err;
+	}
 
-	return SD_RES_SUCCESS;
+	ret = pwrite64(fd, &copies, sizeof(copies), offsetof(struct sheepdog_config, copies));
+	if (ret != sizeof(copies)) {
+		ret = SD_RES_EIO;
+		goto err;
+	}
+	ret = SD_RES_SUCCESS;
+err:
+	close(fd);
+	return ret;
 }
 
 int get_cluster_copies(uint8_t *copies)
@@ -2167,12 +2181,20 @@ int set_cluster_flags(uint16_t flags)
 	if (fd < 0)
 		goto out;
 
-	ret = jrnl_perform(fd, &flags, sizeof(flags),
+	ret = jrnl_perform(&flags, sizeof(flags),
 			offsetof(struct sheepdog_config, flags),
 			config_path, jrnl_path);
-	if (ret != 0)
+	if (ret != 0) {
 		ret = SD_RES_EIO;
-
+		goto err;
+	}
+	ret = pwrite64(fd, &flags, sizeof(flags), offsetof(struct sheepdog_config, flags));
+	if (ret != sizeof(flags)) {
+		ret = SD_RES_EIO;
+		goto err;
+	}
+	ret = SD_RES_SUCCESS;
+err:
 	close(fd);
 out:
 	return ret;
-- 
1.7.6.1




More information about the sheepdog mailing list