This is a preparation patch.

Cc: Saeki Masaki <saeki.mas...@po.ntts.co.jp>
Cc: Yuka Kawasaki <kawasaki.y...@po.ntts.co.jp>
Signed-off-by: Hitoshi Mitake <mitake.hito...@lab.ntt.co.jp>
---
 include/internal_proto.h |  1 +
 sheep/group.c            |  3 ++-
 sheep/ops.c              |  7 ++++---
 sheep/plain_store.c      |  2 +-
 sheep/sheep_priv.h       |  2 +-
 sheep/vdi.c              | 15 ++++++++++++++-
 6 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/include/internal_proto.h b/include/internal_proto.h
index f6ba18e..c1ffe53 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -361,6 +361,7 @@ struct vdi_state {
        uint8_t copy_policy;
        uint8_t block_size_shift;
        uint8_t __pad[3];
+       uint32_t parent_vid;
 
        uint32_t lock_state;
 
diff --git a/sheep/group.c b/sheep/group.c
index af38b38..079d96d 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -510,7 +510,8 @@ retry:
                if (vs[i].deleted)
                        atomic_set_bit(vs[i].vid, sys->vdi_deleted);
                add_vdi_state(vs[i].vid, vs[i].nr_copies, vs[i].snapshot,
-                             vs[i].copy_policy, vs[i].block_size_shift);
+                             vs[i].copy_policy, vs[i].block_size_shift,
+                             vs[i].parent_vid);
        }
 out:
        free(vs);
diff --git a/sheep/ops.c b/sheep/ops.c
index 5d71dde..eec8ce3 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -664,14 +664,15 @@ static int cluster_notify_vdi_add(const struct sd_req 
*req, struct sd_rsp *rsp,
                add_vdi_state(req->vdi_state.old_vid,
                              get_vdi_copy_number(req->vdi_state.old_vid),
                              true, req->vdi_state.copy_policy,
-                             get_vdi_block_size_shift(req->vdi_state.old_vid));
+                             get_vdi_block_size_shift(req->vdi_state.old_vid),
+                             0);
 
        if (req->vdi_state.set_bitmap)
                atomic_set_bit(req->vdi_state.new_vid, sys->vdi_inuse);
 
        add_vdi_state(req->vdi_state.new_vid, req->vdi_state.copies, false,
                      req->vdi_state.copy_policy,
-                     req->vdi_state.block_size_shift);
+                     req->vdi_state.block_size_shift, req->vdi_state.old_vid);
 
        return SD_RES_SUCCESS;
 }
@@ -772,7 +773,7 @@ static int cluster_alter_vdi_copy(const struct sd_req *req, 
struct sd_rsp *rsp,
        uint32_t block_size_shift = req->vdi_state.block_size_shift;
        struct vnode_info *vinfo;
 
-       add_vdi_state(vid, nr_copies, false, 0, block_size_shift);
+       add_vdi_state(vid, nr_copies, false, 0, block_size_shift, 0);
 
        vinfo = get_vnode_info();
        start_recovery(vinfo, vinfo, false, NULL);
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index cb90e31..a7b0864 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -283,7 +283,7 @@ static int init_vdi_state(uint64_t oid, const char *wd, 
uint32_t epoch)
        }
        add_vdi_state(oid_to_vid(oid), inode->nr_copies,
                      vdi_is_snapshot(inode), inode->copy_policy,
-                     inode->block_size_shift);
+                     inode->block_size_shift, inode->parent_vdi_id);
 
        if (inode->name[0] == '\0')
                atomic_set_bit(oid_to_vid(oid), sys->vdi_deleted);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 9ad31a9..a798c50 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -334,7 +334,7 @@ uint8_t get_vdi_block_size_shift(uint32_t vid);
 int get_obj_copy_number(uint64_t oid, int nr_zones);
 int get_req_copy_number(struct request *req);
 int add_vdi_state(uint32_t vid, int nr_copies, bool snapshot,
-                 uint8_t, uint8_t block_size_shift);
+                 uint8_t, uint8_t block_size_shift, uint32_t parent_vid);
 int vdi_exist(uint32_t vid);
 int vdi_create(const struct vdi_iocb *iocb, uint32_t *new_vid);
 int vdi_snapshot(const struct vdi_iocb *iocb, uint32_t *new_vid);
diff --git a/sheep/vdi.c b/sheep/vdi.c
index dd01a20..982f587 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -18,6 +18,7 @@ struct vdi_state_entry {
        bool snapshot;
        bool deleted;
        uint8_t copy_policy;
+       uint32_t parent_vid;
        struct rb_node node;
 
        enum lock_state lock_state;
@@ -189,7 +190,7 @@ int get_req_copy_number(struct request *req)
 }
 
 int add_vdi_state(uint32_t vid, int nr_copies, bool snapshot,
-                 uint8_t cp, uint8_t block_size_shift)
+                 uint8_t cp, uint8_t block_size_shift, uint32_t parent_vid)
 {
        struct vdi_state_entry *entry, *old;
 
@@ -199,6 +200,7 @@ int add_vdi_state(uint32_t vid, int nr_copies, bool 
snapshot,
        entry->snapshot = snapshot;
        entry->copy_policy = cp;
        entry->block_size_shift = block_size_shift;
+       entry->parent_vid = parent_vid;
 
        entry->lock_state = LOCK_STATE_UNLOCKED;
        memset(&entry->owner, 0, sizeof(struct node_id));
@@ -226,6 +228,16 @@ int add_vdi_state(uint32_t vid, int nr_copies, bool 
snapshot,
                entry->snapshot = snapshot;
                entry->copy_policy = cp;
                entry->block_size_shift = block_size_shift;
+
+               if (parent_vid) {
+                       if (!snapshot)
+                               sd_warn("caution, updating parent VID of VID: %"
+                                       PRIx32 " (old parent VID: %" PRIx32
+                                       ", new parent VID: %"PRIx32 ")", vid,
+                                       entry->parent_vid, parent_vid);
+
+                       entry->parent_vid = parent_vid;
+               }
        }
 
        sd_rw_unlock(&vdi_state_lock);
@@ -256,6 +268,7 @@ int fill_vdi_state_list(const struct sd_req *hdr,
                vs[last].lock_state = entry->lock_state;
                vs[last].lock_owner = entry->owner;
                vs[last].nr_participants = entry->nr_participants;
+               vs[last].parent_vid = entry->parent_vid;
                for (int i = 0; i < vs[last].nr_participants; i++) {
                        vs[last].participants_state[i] =
                                entry->participants_state[i];
-- 
1.9.1

-- 
sheepdog mailing list
sheepdog@lists.wpkg.org
https://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to