[sheepdog] [PATCH 1/2] sheep: add remove_vdisks to remove virtual disks

MORITA Kazutaka morita.kazutaka at gmail.com
Tue Sep 24 11:48:43 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

We don't need to iterate over all the vnodes to remove a disk.

This prepares for the next patch.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/md.c | 48 +++++++++++++++++++++++++++++++-----------------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/sheep/md.c b/sheep/md.c
index f49a78a..9fc1b6e 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -74,16 +74,19 @@ static struct vdisk *vdisk_insert(struct vdisk *new)
 	return rb_insert(&md.vroot, new, rb, vdisk_cmp);
 }
 
-/* If v1_hash < oid <= v2_hash, then oid is resident in v2 */
-static struct vdisk *oid_to_vdisk(uint64_t oid)
+/* If v1_hash < hval <= v2_hash, then oid is resident in v2 */
+static struct vdisk *hval_to_vdisk(uint64_t hval)
 {
-	struct vdisk dummy = {
-		.hash = sd_hash_oid(oid),
-	};
+	struct vdisk dummy = { .hash = hval };
 
 	return rb_nsearch(&md.vroot, &dummy, rb, vdisk_cmp);
 }
 
+static struct vdisk *oid_to_vdisk(uint64_t oid)
+{
+	return hval_to_vdisk(sd_hash_oid(oid));
+}
+
 static void create_vdisks(struct disk *disk)
 {
 	uint64_t hval = sd_hash(disk->path, strlen(disk->path));
@@ -100,6 +103,28 @@ static void create_vdisks(struct disk *disk)
 	}
 }
 
+static inline void vdisk_free(struct vdisk *v)
+{
+	rb_erase(&v->rb, &md.vroot);
+	free(v);
+}
+
+static void remove_vdisks(const struct disk *disk)
+{
+	uint64_t hval = sd_hash(disk->path, strlen(disk->path));
+	int nr = vdisk_number(disk);
+
+	for (int i = 0; i < nr; i++) {
+		struct vdisk *v;
+
+		hval = sd_hash_next(hval);
+		v = hval_to_vdisk(hval);
+		assert(v->hash == hval);
+
+		vdisk_free(v);
+	}
+}
+
 static inline void trim_last_slash(char *path)
 {
 	assert(path[0]);
@@ -286,23 +311,12 @@ bool md_add_disk(const char *path, bool purge)
 	return true;
 }
 
-static inline void vdisk_free(struct vdisk *v)
-{
-	rb_erase(&v->rb, &md.vroot);
-	free(v);
-}
-
 static inline void md_remove_disk(struct disk *disk)
 {
-	struct vdisk *v;
-
 	sd_info("%s from multi-disk array", disk->path);
 	rb_erase(&disk->rb, &md.root);
 	md.nr_disks--;
-	rb_for_each_entry(v, &md.vroot, rb) {
-		if (v->disk == disk)
-			vdisk_free(v);
-	}
+	remove_vdisks(disk);
 	free(disk);
 }
 
-- 
1.8.1.2




More information about the sheepdog mailing list