This patch does a little refactoring of generational reference
counting. It also fixes trivial problems of pseudo code in
doc/object-reclaim.txt.

Signed-off-by: Hitoshi Mitake <[email protected]>
---
 doc/object-reclaim.txt |  6 +++++-
 sheep/vdi.c            | 21 ++++++++-------------
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/doc/object-reclaim.txt b/doc/object-reclaim.txt
index 4cef5f5..d9c8fca 100644
--- a/doc/object-reclaim.txt
+++ b/doc/object-reclaim.txt
@@ -43,6 +43,9 @@ Generational reference counting is performed as follows:
    reference B is initialized as follows:
 
        for (i = 0; i < MAX_DATA_OBJS; i++) {
+                  if (!A.data_vdi_id[i])
+              continue;
+
            B.gref[i].generation = A.gref[i].generation + 1;
            B.gref[i].count = 0;
        }
@@ -50,7 +53,8 @@ Generational reference counting is performed as follows:
    In addition, A.gref.count's are incremented:
 
        for (i = 0; i < MAX_DATA_OBJS; i++) {
-           A.gref[i].count++;
+                  if (A.data_vdi_id[i])
+              A.gref[i].count++;
        }
 
 3. When a object o is removed, a decrement message is sent to its
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 05cae7b..0adbea0 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -992,10 +992,8 @@ static int snapshot_vdi(const struct vdi_iocb *iocb, 
uint32_t new_snapid,
        base->snap_ctime = iocb->time;
 
        for (int i = 0; i < ARRAY_SIZE(base->gref); i++) {
-               if (!base->data_vdi_id[i])
-                       continue;
-
-               base->gref[i].count++;
+               if (base->data_vdi_id[i])
+                       base->gref[i].count++;
        }
 
        ret = sd_write_object(vid_to_vdi_oid(base_vid), (char *)base,
@@ -1007,13 +1005,8 @@ static int snapshot_vdi(const struct vdi_iocb *iocb, 
uint32_t new_snapid,
        }
 
        /* create a new vdi */
-       new = alloc_inode(iocb, new_snapid, new_vid, base->data_vdi_id, NULL);
-       for (int i = 0; i < ARRAY_SIZE(base->gref); i++) {
-               if (!base->data_vdi_id[i])
-                       continue;
-
-               new->gref[i].generation = base->gref[i].generation + 1;
-       }
+       new = alloc_inode(iocb, new_snapid, new_vid, base->data_vdi_id,
+                         base->gref);
        ret = sd_write_object(vid_to_vdi_oid(new_vid), (char *)new,
                              sizeof(*new), 0, true);
        if (ret != SD_RES_SUCCESS)
@@ -1073,8 +1066,10 @@ static int rebase_vdi(const struct vdi_iocb *iocb, 
uint32_t new_snapid,
                goto out;
        }
 
-       for (int i = 0; i < ARRAY_SIZE(base->gref); i++)
-               base->gref[i].count++;
+       for (int i = 0; i < ARRAY_SIZE(base->gref); i++) {
+               if (base->data_vdi_id[i])
+                       base->gref[i].count++;
+       }
        /* update current working vdi */
        ret = sd_write_object(vid_to_vdi_oid(base_vid), (char *)base->gref,
                              sizeof(base->gref),
-- 
1.8.3.2

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

Reply via email to