[sheepdog] [PATCH 3/5] sheep: make stale object erasure aware

Liu Yuan namei.unix at gmail.com
Fri Oct 11 11:17:13 CEST 2013


Replica with different ec_index should be considered stale.

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 sheep/plain_store.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 40a7aaf..c788b07 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -311,6 +311,15 @@ static int set_erasure_index(const char *path, uint8_t idx)
 	return 0;
 }
 
+static int get_erasure_index(const char *path, uint8_t *idx)
+{
+	if (getxattr(path, ECNAME, idx, ECSIZE) < 0) {
+		sd_err("failed to getxattr %s, %m", path);
+		return -1;
+	}
+	return 0;
+}
+
 int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 {
 	char path[PATH_MAX], tmp_path[PATH_MAX];
@@ -408,7 +417,7 @@ out:
 
 static bool oid_stale(uint64_t oid)
 {
-	int i, nr_copies;
+	uint32_t i, nr_copies;
 	struct vnode_info *vinfo;
 	const struct sd_vnode *v;
 	bool ret = true;
@@ -421,7 +430,18 @@ static bool oid_stale(uint64_t oid)
 	for (i = 0; i < nr_copies; i++) {
 		v = obj_vnodes[i];
 		if (vnode_is_local(v)) {
-			ret = false;
+			if (is_erasure_oid(oid)) {
+				char path[PATH_MAX];
+				uint8_t idx;
+
+				get_obj_path(oid, path, sizeof(path));
+				if (get_erasure_index(path, &idx) < 0)
+					break;
+				if (idx == i)
+					ret = false;
+			} else {
+				ret = false;
+			}
 			break;
 		}
 	}
-- 
1.7.9.5




More information about the sheepdog mailing list