From: levin li <[email protected]>

Since vnode_info is only used for forward_*_obj_req() in the old
code, it's no need to keep it any more.

Signed-off-by: levin li <[email protected]>
---
 sheep/ops.c        |   10 +++---
 sheep/sheep_priv.h |   20 +++++------
 sheep/vdi.c        |   93 +++++++++++++++-------------------------------------
 3 files changed, 39 insertions(+), 84 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index 4ebd4d6..7dd1be8 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -112,7 +112,7 @@ static int cluster_new_vdi(struct request *req)
        uint32_t vid = 0, nr_copies = sys->nr_copies;
        int ret;
 
-       ret = add_vdi(req->vnodes, hdr->epoch, req->data, hdr->data_length,
+       ret = add_vdi(req->data, hdr->data_length,
                      hdr->vdi.vdi_size, &vid, hdr->vdi.base_vdi_id,
                      hdr->vdi.copies, hdr->vdi.snapid, &nr_copies);
 
@@ -141,7 +141,7 @@ static int cluster_del_vdi(struct request *req)
        uint32_t vid = 0, nr_copies = sys->nr_copies;
        int ret;
 
-       ret = del_vdi(req->vnodes, hdr->epoch, req->data, hdr->data_length,
+       ret = del_vdi(req->data, hdr->data_length,
                      &vid, hdr->vdi.snapid, &nr_copies);
 
        if (sys->enable_write_cache && ret == SD_RES_SUCCESS)
@@ -171,7 +171,7 @@ static int cluster_get_vdi_info(struct request *req)
        else
                return SD_RES_INVALID_PARMS;
 
-       ret = lookup_vdi(req->vnodes, hdr->epoch, req->data, tag, &vid,
+       ret = lookup_vdi(req->data, tag, &vid,
                         hdr->vdi.snapid, &nr_copies, NULL);
        if (ret != SD_RES_SUCCESS)
                return ret;
@@ -271,7 +271,7 @@ static int cluster_get_vdi_attr(struct request *req)
        struct sheepdog_vdi_attr *vattr;
 
        vattr = req->data;
-       ret = lookup_vdi(req->vnodes, hdr->epoch, vattr->name, vattr->tag,
+       ret = lookup_vdi(vattr->name, vattr->tag,
                         &vid, hdr->vdi.snapid, &nr_copies, &created_time);
        if (ret != SD_RES_SUCCESS)
                return ret;
@@ -280,7 +280,7 @@ static int cluster_get_vdi_attr(struct request *req)
           so we use the hash value of the VDI name as the VDI id */
        vid = fnv_64a_buf(vattr->name, strlen(vattr->name), FNV1A_64_INIT);
        vid &= SD_NR_VDIS - 1;
-       ret = get_vdi_attr(req->vnodes, hdr->epoch, req->data, hdr->data_length,
+       ret = get_vdi_attr(req->data, hdr->data_length,
                           vid, &attrid, nr_copies, created_time,
                           hdr->flags & SD_FLAG_CMD_CREAT,
                           hdr->flags & SD_FLAG_CMD_EXCL,
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 290ea82..0d80706 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -204,23 +204,19 @@ int create_listen_port(int port, void *data);
 int init_store(const char *dir, int enable_write_cache);
 int init_base_path(const char *dir);
 
-int add_vdi(struct vnode_info *vnode_info, uint32_t epoch, char *data,
-               int data_len, uint64_t size, uint32_t *new_vid,
-               uint32_t base_vid, uint32_t copies, int is_snapshot,
-               unsigned int *nr_copies);
+int add_vdi(char *data, int data_len, uint64_t size, uint32_t *new_vid,
+           uint32_t base_vid, uint32_t copies, int is_snapshot,
+           unsigned int *nr_copies);
 
-int del_vdi(struct vnode_info *vnode_info, uint32_t epoch, char *data,
-               int data_len, uint32_t *vid, uint32_t snapid,
-               unsigned int *nr_copies);
+int del_vdi(char *data, int data_len, uint32_t *vid, uint32_t snapid,
+           unsigned int *nr_copies);
 
-int lookup_vdi(struct vnode_info *vnode_info, uint32_t epoch, char *name,
-               char *tag, uint32_t *vid, uint32_t snapid,
-               unsigned int *nr_copies, uint64_t *ctime);
+int lookup_vdi(char *name, char *tag, uint32_t *vid, uint32_t snapid,
+              unsigned int *nr_copies, uint64_t *ctime);
 
 int read_vdis(char *data, int len, unsigned int *rsp_len);
 
-int get_vdi_attr(struct vnode_info *vnode_info, uint32_t epoch,
-               struct sheepdog_vdi_attr *vattr, int data_len, uint32_t vid,
+int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len, uint32_t vid,
                uint32_t *attrid, int copies, uint64_t ctime, int write,
                int excl, int delete);
 
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 300cf89..cee973a 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -17,17 +17,15 @@
 
 
 /* TODO: should be performed atomically */
-static int create_vdi_obj(struct vnode_info *vnode_info, uint32_t epoch,
-               char *name, uint32_t new_vid, uint64_t size, uint32_t base_vid,
-               uint32_t cur_vid, uint32_t copies, uint32_t snapid,
-               int is_snapshot)
+static int create_vdi_obj(char *name, uint32_t new_vid, uint64_t size,
+                         uint32_t base_vid, uint32_t cur_vid,
+                         uint32_t copies, uint32_t snapid, int is_snapshot)
 {
        /* we are not called concurrently */
        struct sheepdog_inode *new = NULL, *base = NULL, *cur = NULL;
        struct timeval tv;
        int ret = SD_RES_NO_MEM;
        unsigned long block_size = SD_DATA_OBJ_SIZE;
-       int nr_copies;
 
        new = zalloc(sizeof(*new));
        if (!new) {
@@ -51,10 +49,6 @@ static int create_vdi_obj(struct vnode_info *vnode_info, 
uint32_t epoch,
                }
        }
 
-       nr_copies = get_nr_copies(vnode_info);
-       if (nr_copies > copies)
-               nr_copies = copies;
-
        if (base_vid) {
                ret = read_object(vid_to_vdi_oid(base_vid), (char *)base,
                                  sizeof(*base), 0);
@@ -144,15 +138,14 @@ out:
        return ret;
 }
 
-static int find_first_vdi(struct vnode_info *vnode_info, uint32_t epoch,
-               unsigned long start, unsigned long end, char *name, char *tag,
-               uint32_t snapid, uint32_t *vid, unsigned long *deleted_nr,
-               uint32_t *next_snap, unsigned int *inode_nr_copies,
-               uint64_t *ctime)
+static int find_first_vdi(unsigned long start, unsigned long end,
+                         char *name, char *tag, uint32_t snapid,
+                         uint32_t *vid, unsigned long *deleted_nr,
+                         uint32_t *next_snap, unsigned int *inode_nr_copies,
+                         uint64_t *ctime)
 {
        struct sheepdog_inode *inode = NULL;
        unsigned long i;
-       int nr_copies;
        int ret = SD_RES_NO_MEM;
        int vdi_found = 0;
 
@@ -162,8 +155,6 @@ static int find_first_vdi(struct vnode_info *vnode_info, 
uint32_t epoch,
                goto out;
        }
 
-       nr_copies = get_nr_copies(vnode_info);
-
        for (i = start; i >= end; i--) {
                ret = read_object(vid_to_vdi_oid(i), (char *)inode,
                                  SD_INODE_HEADER_SIZE, 0);
@@ -206,8 +197,7 @@ out:
        return ret;
 }
 
-static int do_lookup_vdi(struct vnode_info *vnode_info, uint32_t epoch,
-               char *name, int namelen, uint32_t *vid, char *tag,
+static int do_lookup_vdi(char *name, int namelen, uint32_t *vid, char *tag,
                uint32_t snapid, uint32_t *next_snapid, unsigned long *right_nr,
                unsigned long *deleted_nr, unsigned int *nr_copies,
                uint64_t *ctime)
@@ -227,7 +217,7 @@ static int do_lookup_vdi(struct vnode_info *vnode_info, 
uint32_t epoch,
        } else if (nr < SD_NR_VDIS) {
        right_side:
                /* look up on the right side of the hash point */
-               ret = find_first_vdi(vnode_info, epoch, nr - 1, start_nr, name,
+               ret = find_first_vdi(nr - 1, start_nr, name,
                                     tag, snapid, vid, deleted_nr, next_snapid,
                                     nr_copies, ctime);
                return ret;
@@ -239,7 +229,7 @@ static int do_lookup_vdi(struct vnode_info *vnode_info, 
uint32_t epoch,
                        return SD_RES_FULL_VDI;
                else if (nr) {
                        /* look up on the left side of the hash point */
-                       ret = find_first_vdi(vnode_info, epoch, nr - 1, 0, name,
+                       ret = find_first_vdi(nr - 1, 0, name,
                                             tag, snapid, vid, deleted_nr,
                                             next_snapid, nr_copies, ctime);
                        if (ret == SD_RES_NO_VDI)
@@ -253,21 +243,20 @@ static int do_lookup_vdi(struct vnode_info *vnode_info, 
uint32_t epoch,
        }
 }
 
-int lookup_vdi(struct vnode_info *vnode_info, uint32_t epoch, char *name,
-               char *tag, uint32_t *vid, uint32_t snapid,
-               unsigned int *nr_copies, uint64_t *ctime)
+int lookup_vdi(char *name, char *tag, uint32_t *vid, uint32_t snapid,
+              unsigned int *nr_copies, uint64_t *ctime)
 {
        uint32_t dummy0;
        unsigned long dummy1, dummy2;
 
-       return do_lookup_vdi(vnode_info, epoch, name, strlen(name), vid, tag,
+       return do_lookup_vdi(name, strlen(name), vid, tag,
                             snapid, &dummy0, &dummy1, &dummy2, nr_copies,
                             ctime);
 }
 
-int add_vdi(struct vnode_info *vnode_info, uint32_t epoch, char *data,
-           int data_len, uint64_t size, uint32_t *new_vid, uint32_t base_vid,
-           uint32_t copies, int is_snapshot, unsigned int *nr_copies)
+int add_vdi(char *data, int data_len, uint64_t size, uint32_t *new_vid,
+           uint32_t base_vid, uint32_t copies, int is_snapshot,
+           unsigned int *nr_copies)
 {
        uint32_t cur_vid = 0;
        uint32_t next_snapid;
@@ -280,7 +269,7 @@ int add_vdi(struct vnode_info *vnode_info, uint32_t epoch, 
char *data,
 
        name = data;
 
-       ret = do_lookup_vdi(vnode_info, epoch, name, strlen(name), &cur_vid,
+       ret = do_lookup_vdi(name, strlen(name), &cur_vid,
                            NULL, 0, &next_snapid, &right_nr, &deleted_nr,
                            nr_copies, NULL);
 
@@ -321,17 +310,15 @@ int add_vdi(struct vnode_info *vnode_info, uint32_t 
epoch, char *data,
                copies = sys->nr_copies;
        }
 
-       return create_vdi_obj(vnode_info, epoch, name, *new_vid, size,
+       return create_vdi_obj(name, *new_vid, size,
                              base_vid, cur_vid, copies, next_snapid,
                              is_snapshot);
 }
 
-static int start_deletion(struct vnode_info *vnode_info, uint32_t vid,
-               uint32_t epoch);
+static int start_deletion(uint32_t vid);
 
-int del_vdi(struct vnode_info *vnode_info, uint32_t epoch, char *data,
-               int data_len, uint32_t *vid, uint32_t snapid,
-               unsigned int *nr_copies)
+int del_vdi(char *data,        int data_len, uint32_t *vid, uint32_t snapid,
+           unsigned int *nr_copies)
 {
        char *name = data, *tag;
        uint32_t dummy0;
@@ -347,12 +334,12 @@ int del_vdi(struct vnode_info *vnode_info, uint32_t 
epoch, char *data,
                goto out;
        }
 
-       ret = do_lookup_vdi(vnode_info, epoch, name, strlen(name), vid, tag,
+       ret = do_lookup_vdi(name, strlen(name), vid, tag,
                            snapid, &dummy0, &dummy1, &dummy2, nr_copies, NULL);
        if (ret != SD_RES_SUCCESS)
                goto out;
 
-       ret = start_deletion(vnode_info, *vid, epoch);
+       ret = start_deletion(*vid);
 out:
        return ret;
 }
@@ -370,7 +357,6 @@ int read_vdis(char *data, int len, unsigned int *rsp_len)
 
 struct deletion_work {
        uint32_t done;
-       uint32_t epoch;
 
        struct work work;
        struct list_head dw_siblings;
@@ -380,7 +366,6 @@ struct deletion_work {
        int count;
        uint32_t *buf;
 
-       struct vnode_info *vnodes;
        int delete_error;
 };
 
@@ -390,7 +375,6 @@ static int delete_inode(struct deletion_work *dw)
 {
        struct sheepdog_inode *inode = NULL;
        int ret = SD_RES_SUCCESS;
-       int nr_copies;
 
        inode = zalloc(sizeof(*inode));
        if (!inode) {
@@ -398,8 +382,6 @@ static int delete_inode(struct deletion_work *dw)
                goto out;
        }
 
-       nr_copies = get_nr_copies(dw->vnodes);
-
        ret = read_object(vid_to_vdi_oid(dw->vid), (char *)inode,
                          SD_INODE_HEADER_SIZE, 0);
        if (ret != SD_RES_SUCCESS) {
@@ -428,7 +410,6 @@ static void delete_one(struct work *work)
        uint32_t vdi_id = *(dw->buf + dw->count - dw->done - 1);
        int ret, i;
        struct sheepdog_inode *inode = NULL;
-       int nr_copies;
 
        eprintf("%d %d, %16x\n", dw->done, dw->count, vdi_id);
 
@@ -438,8 +419,6 @@ static void delete_one(struct work *work)
                goto out;
        }
 
-       nr_copies = get_nr_copies(dw->vnodes);
-
        ret = read_object(vid_to_vdi_oid(vdi_id),
                          (void *)inode, sizeof(*inode), 0);
 
@@ -494,7 +473,6 @@ static void delete_one_done(struct work *work)
 
        list_del(&dw->dw_siblings);
 
-       put_vnode_info(dw->vnodes);
        free(dw->buf);
        free(dw);
 
@@ -512,9 +490,6 @@ static int fill_vdi_list(struct deletion_work *dw, uint32_t 
root_vid)
        struct sheepdog_inode *inode = NULL;
        int done = dw->count;
        uint32_t vid;
-       int nr_copies;
-
-       nr_copies = get_nr_copies(dw->vnodes);
 
        inode = malloc(SD_INODE_HEADER_SIZE);
        if (!inode) {
@@ -596,8 +571,7 @@ out:
        return vid;
 }
 
-static int start_deletion(struct vnode_info *vnode_info, uint32_t vid,
-               uint32_t epoch)
+static int start_deletion(uint32_t vid)
 {
        struct deletion_work *dw = NULL;
        int ret = SD_RES_NO_MEM, cloned;
@@ -614,13 +588,10 @@ static int start_deletion(struct vnode_info *vnode_info, 
uint32_t vid,
 
        dw->count = 0;
        dw->vid = vid;
-       dw->epoch = epoch;
 
        dw->work.fn = delete_one;
        dw->work.done = delete_one_done;
 
-       dw->vnodes = vnode_info;
-
        root_vid = get_vdi_root(dw->vid, &cloned);
        if (!root_vid) {
                ret = SD_RES_EIO;
@@ -648,12 +619,6 @@ static int start_deletion(struct vnode_info *vnode_info, 
uint32_t vid,
        if (dw->count == 0)
                goto out;
 
-       /*
-        * Only grab the vnode_info reference once we know that we can't fail in
-        * this helper thread.
-        */
-       grab_vnode_info(dw->vnodes);
-
        if (!list_empty(&deletion_work_list)) {
                list_add_tail(&dw->dw_siblings, &deletion_work_list);
                goto out;
@@ -671,23 +636,17 @@ err:
        return ret;
 }
 
-int get_vdi_attr(struct vnode_info *vnode_info, uint32_t epoch,
-                struct sheepdog_vdi_attr *vattr, int data_len,
+int get_vdi_attr(struct sheepdog_vdi_attr *vattr, int data_len,
                 uint32_t vid, uint32_t *attrid, int copies, uint64_t ctime,
                 int wr, int excl, int delete)
 {
        struct sheepdog_vdi_attr tmp_attr;
        uint64_t oid, hval;
        uint32_t end;
-       int nr_copies;
        int ret;
 
        vattr->ctime = ctime;
 
-       nr_copies = get_nr_copies(vnode_info);
-       if (nr_copies > copies)
-               nr_copies = copies;
-
        /* we cannot include value_len for calculating the hash value */
        hval = fnv_64a_buf(vattr->name, sizeof(vattr->name), FNV1A_64_INIT);
        hval = fnv_64a_buf(vattr->tag, sizeof(vattr->tag), hval);
-- 
1.7.10

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to