[sheepdog] [PATCH] Sheepdog, store: Update the get_store_temp_path function

Ziye Yang ziye.yang at intel.com
Thu Jul 9 07:58:59 CEST 2015


This function is nearly same with get_store_path, the
only difference is to add ".tmp" of the return string.
It can be optimized to reduce the duplicated code.

Signed-off-by: Ziye Yang <ziye.yang at intel.com>
---
 sheep/store/plain_store.c |   12 ++++--------
 sheep/store/tree_store.c  |   22 ++++------------------
 2 files changed, 8 insertions(+), 26 deletions(-)

diff --git a/sheep/store/plain_store.c b/sheep/store/plain_store.c
index db1a32c..2cc9479 100644
--- a/sheep/store/plain_store.c
+++ b/sheep/store/plain_store.c
@@ -28,15 +28,11 @@ static int get_store_path(uint64_t oid, uint8_t ec_index, char *path)
 
 static int get_store_tmp_path(uint64_t oid, uint8_t ec_index, char *path)
 {
-	if (is_erasure_oid(oid)) {
-		if (unlikely(ec_index >= SD_MAX_COPIES))
-			panic("invalid ec_index %d", ec_index);
-		return snprintf(path, PATH_MAX, "%s/%016"PRIx64"_%d.tmp",
-				md_get_object_dir(oid), oid, ec_index);
-	}
+	char tmp_path[PATH_MAX];
 
-	return snprintf(path, PATH_MAX, "%s/%016" PRIx64".tmp",
-			md_get_object_dir(oid), oid);
+	get_store_path(oid, ec_index, path);
+	memcpy(tmp_path, path, PATH_MAX);
+	return snprintf(path, PATH_MAX, "%s.tmp", tmp_path);
 }
 
 static int get_store_stale_path(uint64_t oid, uint32_t epoch, uint8_t ec_index,
diff --git a/sheep/store/tree_store.c b/sheep/store/tree_store.c
index b7fd8a5..31217e7 100644
--- a/sheep/store/tree_store.c
+++ b/sheep/store/tree_store.c
@@ -43,25 +43,11 @@ static int get_store_path(uint64_t oid, uint8_t ec_index, char *path)
 
 static int get_store_tmp_path(uint64_t oid, uint8_t ec_index, char *path)
 {
-	char tree_path[PATH_MAX];
-
-	if (is_vdi_obj(oid) || is_vmstate_obj(oid) || is_vdi_attr_obj(oid)) {
-		snprintf(tree_path, PATH_MAX, "%s/meta",
-			 md_get_object_dir(oid));
-	} else {
-		snprintf(tree_path, PATH_MAX, "%s/%02x",
-			 md_get_object_dir(oid), get_tree_directory(oid));
-	}
-
-	if (is_erasure_oid(oid)) {
-		if (unlikely(ec_index >= SD_MAX_COPIES))
-			panic("invalid ec_index %d", ec_index);
-		return snprintf(path, PATH_MAX, "%s/%016"PRIx64"_%d.tmp",
-				tree_path, oid, ec_index);
-	}
+	char tmp_path[PATH_MAX];
 
-	return snprintf(path, PATH_MAX, "%s/%016" PRIx64".tmp",
-			tree_path, oid);
+	get_store_path(oid, ec_index, path);
+	memcpy(tmp_path, path, PATH_MAX);
+	return snprintf(path, PATH_MAX, "%s.tmp", tmp_path);
 }
 
 static int get_store_stale_path(uint64_t oid, uint32_t epoch, uint8_t ec_index,



More information about the sheepdog mailing list