]> git.neil.brown.name Git - LaFS.git/commitdiff
cluster.c - various tidy-ups.
authorNeil Brown <neilb@nbeee.brown>
Mon, 11 Oct 2010 07:12:15 +0000 (18:12 +1100)
committerNeil Brown <neilb@nbeee.brown>
Mon, 11 Oct 2010 07:13:05 +0000 (18:13 +1100)
factor some common code,
remove some 'inline' defnitions
general cleanup

cluster.c

index 168426f385653c646e86e156dc2262d68ea96e72..c06b3a245e0f7fbc41d5216a31e6228fb8017b27 100644 (file)
--- a/cluster.c
+++ b/cluster.c
@@ -280,7 +280,7 @@ static void seg_step(struct fs *fs, struct segpos *seg)
        seg->st_table = seg->nxt_table;
        seg->st_row = seg->nxt_row;
        seg->table = seg->st_table;
-       seg->row = seg->nxt_row;
+       seg->row = seg->st_row;
        seg->col = 0;
 }
 
@@ -328,18 +328,33 @@ static void seg_setpos(struct fs *fs, struct segpos *seg, u64 addr)
        seg->col = 0;
 }
 
-static u64 seg_next(struct fs *fs, struct segpos *seg)
+static u64 seg_addr(struct fs *fs, struct segpos *seg)
 {
-       /* step forward one block, returning the address of
-        * the block stepped over
+       /* Return the virtual address of the blocks pointed
+        * to by 'seg'.
         */
        struct fs_dev *dv = &fs->devs[seg->dev];
+       u64 addr;
 
-       u64 addr = seg->col * dv->stride;
+       if (seg->dev < 0)
+               /* Setting 'next' address for last cluster in
+                * a cleaner segment */
+               return 0;
+       addr = seg->col * dv->stride;
        addr += seg->row;
-       addr += seg->table * (dv->stride);  /* FIXME */
+       addr += seg->table * dv->rows_per_table;
        addr += seg->num * dv->segment_stride;
        addr += dv->start;
+       return addr;
+}
+
+static u64 seg_next(struct fs *fs, struct segpos *seg)
+{
+       /* step forward one block, returning the address of
+        * the block stepped over
+        */
+       struct fs_dev *dv = &fs->devs[seg->dev];
+       u64 addr = seg_addr(fs, seg);
 
        /* now step forward in column or table or seg */
        seg->col++;
@@ -354,29 +369,8 @@ static u64 seg_next(struct fs *fs, struct segpos *seg)
        return addr;
 }
 
-static u64 seg_addr(struct fs *fs, struct segpos *seg)
-{
-       /* step forward one block, returning the address of
-        * the block stepped over. FIXME this comment is wrong.
-        */
-       struct fs_dev *dv = &fs->devs[seg->dev];
-       u64 addr;
-
-       if (seg->dev < 0)
-               /* Setting 'next' address for last cluster in
-                * a cleaner segment */
-               return 0;
-       addr = seg->col * dv->stride;
-       addr += seg->row;
-       addr += seg->table * (dv->stride);  /* FIXME */
-       addr += seg->num * dv->segment_stride;
-       addr += dv->start;
-       return addr;
-}
-
 static void cluster_reset(struct fs *fs, struct wc *wc)
 {
-       int blocksize = fs->blocksize;
        if (wc->seg.dev < 0) {
                wc->remaining = 0;
                wc->chead_size = 0;
@@ -385,7 +379,7 @@ static void cluster_reset(struct fs *fs, struct wc *wc)
        wc->remaining = seg_remainder(fs, &wc->seg);
        wc->chead_blocks = 1;
        wc->remaining--;
-       wc->cluster_space = blocksize - sizeof(struct cluster_head);
+       wc->cluster_space = fs->blocksize - sizeof(struct cluster_head);
        wc->chead = page_address(wc->page[wc->pending_next]);
        wc->chead_size = sizeof(struct cluster_head);
 }
@@ -844,8 +838,8 @@ int lafs_cluster_allocate(struct block *b, int cnum)
  * in the list.  These routines help.
  */
 
-static inline void cluster_addhead(struct wc *wc, struct inode *ino,
-                                  struct group_head **headstart)
+static void cluster_addhead(struct wc *wc, struct inode *ino,
+                           struct group_head **headstart)
 {
        struct group_head *gh = (struct group_head *)((char *)wc->chead +
                                                      wc->chead_size);
@@ -863,8 +857,8 @@ static inline void cluster_addhead(struct wc *wc, struct inode *ino,
        wc->chead_size += sizeof(struct group_head);
 }
 
-static inline void cluster_closehead(struct wc *wc,
-                                    struct group_head *headstart)
+static void cluster_closehead(struct wc *wc,
+                             struct group_head *headstart)
 {
        int size = wc->chead_size - (((char *)headstart) - (char *)wc->chead);
 
@@ -872,9 +866,9 @@ static inline void cluster_closehead(struct wc *wc,
        headstart->group_size_words = size / 4;
 }
 
-static inline void cluster_addmini(struct wc *wc, u32 addr, int offset,
-                                  int size, const char *data,
-                                  int size2, const char *data2)
+static void cluster_addmini(struct wc *wc, u32 addr, int offset,
+                           int size, const char *data,
+                           int size2, const char *data2)
 {
        /* if size2 !=0, then only
         * (size-size2) is at 'data' and the rest is at 'data2'
@@ -895,8 +889,8 @@ static inline void cluster_addmini(struct wc *wc, u32 addr, int offset,
        wc->chead_size += ROUND_UP(size);
 }
 
-static inline void cluster_adddesc(struct wc *wc, struct block *blk,
-                                  struct descriptor **desc_start)
+static void cluster_adddesc(struct wc *wc, struct block *blk,
+                           struct descriptor **desc_start)
 {
        struct descriptor *dh = (struct descriptor *)((char *)wc->chead +
                                                      wc->chead_size);
@@ -910,8 +904,8 @@ static inline void cluster_adddesc(struct wc *wc, struct block *blk,
        wc->chead_size += sizeof(struct descriptor);
 }
 
-static inline void cluster_incdesc(struct wc *wc, struct descriptor *desc_start,
-                                  struct block *b, int blkbits)
+static void cluster_incdesc(struct wc *wc, struct descriptor *desc_start,
+                           struct block *b, int blkbits)
 {
        desc_start->block_cnt =
                cpu_to_le32(le32_to_cpu(desc_start->block_cnt)+1);
@@ -1135,7 +1129,6 @@ static void cluster_flush(struct fs *fs, int cnum)
        struct segpos segend;
        int which;
        int wake;
-       int blocks = 0;
        int vtype;
        int cluster_size;
 
@@ -1183,7 +1176,7 @@ static void cluster_flush(struct fs *fs, int cnum)
                cluster_incdesc(wc, desc_start, b, fs->blocksize_bits);
                addr = seg_next(fs, &wc->seg);
                if (cnum && test_bit(B_Dirty, &b->flags))
-                       /* Were a cleaning but this block is now dirty.
+                       /* We are cleaning but this block is now dirty.
                         * Don't waste the UnincCredit on recording the
                         * clean location as it will be written as
                         * dirty soon.  Just pin it to the current phase
@@ -1192,7 +1185,6 @@ static void cluster_flush(struct fs *fs, int cnum)
                        lafs_pin_block(b);
                else
                        lafs_allocated_block(fs, b, addr);
-               blocks++;
        }
 
        if (head_start)
@@ -1533,6 +1525,7 @@ int lafs_cluster_init(struct fs *fs, int cnum, u64 addr, u64 prev, u64 seq)
        wc->pending_next = 0;
        wc->cluster_seq = seq;
        wc->prev_addr = prev;
+       wc->cnum = cnum;
 
        if (addr) {
                seg_setpos(fs, &wc->seg, addr);
@@ -1542,7 +1535,6 @@ int lafs_cluster_init(struct fs *fs, int cnum, u64 addr, u64 prev, u64 seq)
                fs->free_blocks += wc->remaining+1;
                spin_unlock(&fs->lock);
        }
-       wc->cnum = cnum;
 
        return 0;
 }