[sheepdog] [PATCH RFC 3/4] sheep: notify the previous vid with copy number
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Thu Apr 25 12:23:26 CEST 2013
This sends the previous vid to all the nodes to notify which vid is a
snapshot one.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
include/internal_proto.h | 13 +++++++++++++
include/sheep.h | 4 +++-
sheep/group.c | 2 +-
sheep/ops.c | 10 +++++++---
sheep/plain_store.c | 3 ++-
sheep/sheep_priv.h | 2 +-
sheep/vdi.c | 33 ++++++++++++++++-----------------
7 files changed, 43 insertions(+), 24 deletions(-)
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 08958db..e41c75e 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -184,6 +184,19 @@ struct sd_node_rsp {
uint64_t store_free;
};
+struct sd_vdi_copy_req {
+ uint8_t proto_ver;
+ uint8_t opcode;
+ uint16_t flags;
+ uint32_t epoch;
+ uint32_t id;
+ uint32_t data_length;
+ uint32_t old_vid;
+ uint32_t new_vid;
+ uint32_t copies;
+ uint32_t pad[5];
+};
+
struct node_id {
uint8_t addr[16];
uint16_t port;
diff --git a/include/sheep.h b/include/sheep.h
index 26b9639..7ee22fd 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -38,7 +38,9 @@ struct vnode_info {
struct vdi_copy {
uint32_t vid;
- uint32_t nr_copies;
+ uint8_t nr_copies;
+ uint8_t snapshot;
+ uint16_t _pad;
};
#define TRACE_GRAPH_ENTRY 0x01
diff --git a/sheep/group.c b/sheep/group.c
index 3017164..be65bcd 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -668,7 +668,7 @@ static int get_vdis_from(struct sd_node *node)
count = rsp->data_length / sizeof(*vc);
for (i = 0; i < count; i++) {
set_bit(vc[i].vid, sys->vdi_inuse);
- add_vdi_copy_number(vc[i].vid, vc[i].nr_copies);
+ add_vdi_copy_number(vc[i].vid, vc[i].nr_copies, vc[i].snapshot);
}
out:
free(vc);
diff --git a/sheep/ops.c b/sheep/ops.c
index 96b25eb..5b74b1c 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -606,10 +606,14 @@ static int cluster_cleanup(const struct sd_req *req, struct sd_rsp *rsp,
static int cluster_notify_vdi_add(const struct sd_req *req, struct sd_rsp *rsp,
void *data)
{
- uint32_t vid = *(uint32_t *)data;
- uint32_t nr_copies = *(uint32_t *)((char *)data + sizeof(vid));
+ const struct sd_vdi_copy_req *hdr = (const struct sd_vdi_copy_req *)req;
+
+ if (hdr->old_vid)
+ /* make the existing vdi a new snapshot */
+ add_vdi_copy_number(hdr->old_vid,
+ get_vdi_copy_number(hdr->old_vid), true);
- add_vdi_copy_number(vid, nr_copies);
+ add_vdi_copy_number(hdr->new_vid, hdr->copies, false);
return SD_RES_SUCCESS;
}
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index adfd923..e47786a 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -183,7 +183,8 @@ static int init_vdi_copy_number(uint64_t oid, char *wd)
goto out;
}
- add_vdi_copy_number(oid_to_vid(oid), inode->nr_copies);
+ add_vdi_copy_number(oid_to_vid(oid), inode->nr_copies,
+ sd_is_snapshot(inode));
ret = SD_RES_SUCCESS;
out:
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 6434acf..048197b 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -248,7 +248,7 @@ int get_vdi_copy_number(uint32_t vid);
int get_obj_copy_number(uint64_t oid, int nr_zones);
int get_max_copy_number(void);
int get_req_copy_number(struct request *req);
-int add_vdi_copy_number(uint32_t vid, int nr_copies);
+int add_vdi_copy_number(uint32_t vid, int nr_copies, bool snapshot);
int vdi_exist(uint32_t vid);
int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid);
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 18dfef4..160f39b 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -19,6 +19,7 @@
struct vdi_copy_entry {
uint32_t vid;
unsigned int nr_copies;
+ bool snapshot;
struct rb_node node;
};
@@ -113,13 +114,14 @@ int get_max_copy_number(void)
return nr_copies;
}
-int add_vdi_copy_number(uint32_t vid, int nr_copies)
+int add_vdi_copy_number(uint32_t vid, int nr_copies, bool snapshot)
{
struct vdi_copy_entry *entry, *old;
entry = xzalloc(sizeof(*entry));
entry->vid = vid;
entry->nr_copies = nr_copies;
+ entry->snapshot = snapshot;
sd_dprintf("%" PRIx32 ", %d", vid, nr_copies);
@@ -129,6 +131,7 @@ int add_vdi_copy_number(uint32_t vid, int nr_copies)
free(entry);
entry = old;
entry->nr_copies = nr_copies;
+ entry->snapshot = snapshot;
}
if (uatomic_read(&max_copies) == 0 ||
@@ -149,8 +152,10 @@ int fill_vdi_copy_list(void *data)
pthread_rwlock_rdlock(&vdi_copy_lock);
for (n = rb_first(&vdi_copy_root); n; n = rb_next(n)) {
entry = rb_entry(n, struct vdi_copy_entry, node);
+ memset(vc, 0, sizeof(*vc));
vc->vid = entry->vid;
vc->nr_copies = entry->nr_copies;
+ vc->snapshot = entry->snapshot;
vc++;
nr++;
}
@@ -426,26 +431,20 @@ int lookup_vdi(const char *name, const char *tag, uint32_t *vid,
create_time);
}
-static int notify_vdi_add(uint32_t vdi_id, uint32_t nr_copies)
+static int notify_vdi_add(uint32_t vdi_id, uint32_t nr_copies, uint32_t old_vid)
{
- struct sd_req hdr;
+ struct sd_vdi_copy_req hdr;
int ret = SD_RES_SUCCESS;
- char *buf;
-
- sd_init_req(&hdr, SD_OP_NOTIFY_VDI_ADD);
- hdr.flags = SD_FLAG_CMD_WRITE;
- hdr.data_length = sizeof(vdi_id) + sizeof(nr_copies);
- buf = xmalloc(sizeof(vdi_id) + sizeof(nr_copies));
- memcpy(buf, &vdi_id, sizeof(vdi_id));
- memcpy(buf + sizeof(vdi_id), &nr_copies, sizeof(nr_copies));
+ sd_init_req((struct sd_req *)&hdr, SD_OP_NOTIFY_VDI_ADD);
+ hdr.old_vid = old_vid;
+ hdr.new_vid = vdi_id;
+ hdr.copies = nr_copies;
- ret = exec_local_req(&hdr, buf);
+ ret = exec_local_req((struct sd_req *)&hdr, NULL);
if (ret != SD_RES_SUCCESS)
- sd_eprintf("fail to notify vdi add event(%" PRIx32 ", %d)",
- vdi_id, nr_copies);
-
- free(buf);
+ sd_eprintf("fail to notify vdi add event(%" PRIx32 ", %d, %"
+ PRIx32 ")", vdi_id, nr_copies, old_vid);
return ret;
}
@@ -492,7 +491,7 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
*new_vid = nr;
- notify_vdi_add(nr, iocb->nr_copies);
+ notify_vdi_add(nr, iocb->nr_copies, cur_vid);
sd_iprintf("creating new %s %s: size %" PRIu64 ", vid %"
PRIx32 ", base %" PRIx32 ", cur %" PRIx32 ", copies %d",
--
1.7.2.5
More information about the sheepdog
mailing list