[sheepdog] [PATCH v1 4/5] sheep/md: change the method of generating vnodes in md
Robin Dong
robin.k.dong at gmail.com
Tue Apr 29 04:53:44 CEST 2014
From: Robin Dong <sanbai at taobao.com>
Because the method of generating vnodes in cluster is changed, the
method of generating vnodes in md should changed also.
After changing generate item from nodes to disks, adding new disk
or removing old disk should also cause whole cluster to do recovery.
Signed-off-by: Robin Dong <sanbai at taobao.com>
---
sheep/group.c | 25 ++++++++++++++++++++++++-
sheep/md.c | 27 +++++++++++++++++++++++++--
2 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/sheep/group.c b/sheep/group.c
index 5e2b198..91cc35a 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -645,6 +645,29 @@ void wait_get_vdis_done(void)
sd_debug("vdi list ready");
}
+static bool nodes_changed(const struct cluster_info *cinfo,
+ const struct rb_root *nroot,
+ size_t nr_nodes)
+{
+ const struct sd_node *key, *n;
+ int i, ret;
+
+ if (nr_nodes != cinfo->nr_nodes)
+ return true;
+
+ for (i = 0; i < cinfo->nr_nodes; i++) {
+ key = cinfo->nodes + i;
+ n = rb_search(nroot, key, rb, node_cmp);
+ if (!n)
+ continue;
+ ret = memcmp(n->disks, key->disks,
+ sizeof(struct disk_info) * DISK_MAX);
+ if (ret)
+ return true;
+ }
+ return false;
+}
+
static void update_cluster_info(const struct cluster_info *cinfo,
const struct sd_node *joined,
const struct rb_root *nroot,
@@ -677,7 +700,7 @@ static void update_cluster_info(const struct cluster_info *cinfo,
/* initialize config file */
set_cluster_config(&sys->cinfo);
- if (nr_nodes != cinfo->nr_nodes) {
+ if (nodes_changed(cinfo, nroot, nr_nodes)) {
int ret;
if (old_vnode_info)
put_vnode_info(old_vnode_info);
diff --git a/sheep/md.c b/sheep/md.c
index bec8853..7a90660 100644
--- a/sheep/md.c
+++ b/sheep/md.c
@@ -70,8 +70,17 @@ static struct vdisk *oid_to_vdisk(uint64_t oid)
static void create_vdisks(const struct disk *disk)
{
uint64_t hval = sd_hash(disk->path, strlen(disk->path));
+#ifdef HAVE_DISKVNODES
+ const struct sd_node *n = &sys->this_node;
+ uint64_t node_hval = sd_hash(&n->nid, offsetof(typeof(n->nid),
+ io_addr));
+ hval = fnv_64a_64(node_hval, hval);
+ int nr = disk->space / WEIGHT_MIN;
+ if (0 == n->nid.port)
+ return;
+#else
int nr = vdisk_number(disk);
-
+#endif
for (int i = 0; i < nr; i++) {
struct vdisk *v = xmalloc(sizeof(*v));
@@ -92,8 +101,15 @@ static inline void vdisk_free(struct vdisk *v)
static void remove_vdisks(const struct disk *disk)
{
uint64_t hval = sd_hash(disk->path, strlen(disk->path));
+#ifdef HAVE_DISKVNODES
+ const struct sd_node *n = &sys->this_node;
+ uint64_t node_hval = sd_hash(&n->nid, offsetof(typeof(n->nid),
+ io_addr));
+ hval = fnv_64a_64(node_hval, hval);
+ int nr = disk->space / WEIGHT_MIN;
+#else
int nr = vdisk_number(disk);
-
+#endif
for (int i = 0; i < nr; i++) {
struct vdisk *v;
@@ -486,6 +502,12 @@ struct md_work {
char path[PATH_MAX];
};
+#ifdef HAVE_DISKVNODES
+static inline void kick_recover(void)
+{
+ sys->cdrv->update_node(&sys->this_node);
+}
+#else
static inline void kick_recover(void)
{
struct vnode_info *vinfo = get_vnode_info();
@@ -493,6 +515,7 @@ static inline void kick_recover(void)
start_recovery(vinfo, vinfo, false);
put_vnode_info(vinfo);
}
+#endif
static void md_do_recover(struct work *work)
{
--
1.7.12.4
More information about the sheepdog
mailing list