]> git.neil.brown.name Git - LaFS.git/commitdiff
Fix handling of extents during incorporation.
authorNeilBrown <neilb@suse.de>
Sun, 13 Jun 2010 09:24:17 +0000 (19:24 +1000)
committerNeilBrown <neilb@suse.de>
Sun, 13 Jun 2010 09:24:17 +0000 (19:24 +1000)
Modifying the indexblock in walk_extent is bad.
We could be using walk_extent just to examine the block,
so making changes causes corruption.
Also, there were two other places where we weren't making changes,
but later assumed we had.

So don't make any changes, and don't assume any changes
have been made.

Signed-off-by: NeilBrown <neilb@suse.de>
modify.c

index cfcc109061bc8909dd14aeea653d2c5fb34775c4..e781cc3040c6e3c269be5fd371dedb9014e1ab63 100644 (file)
--- a/modify.c
+++ b/modify.c
@@ -668,7 +668,7 @@ static int add_extent(void *data, u32 addr, u64 phys, int len)
        }
        if (li->esize) {
                /* need to close old extent */
-               p = li->data - 6;;
+               p = li->data - 6;
                encode16(p, li->esize);
                li->esize = 0;
        }
@@ -961,13 +961,9 @@ static u32 walk_extent(char **bufp, int len, struct uninc *ui,
                                ephys += overlap;
                        }
                        if (handled < hlen) {
-                               if (elen) {
-                                       buf -= 12;
-                                       *bufp = buf;
-                                       encode48(buf, ephys);
-                                       encode16(buf, elen);
-                                       encode32(buf, eaddr);
-                               } else
+                               if (elen)
+                                       *bufp = buf - 12;
+                               else
                                        *bufp = buf;
                                return ui->pending_addr[uinum].fileaddr
                                        + uioffset + handled;
@@ -1361,8 +1357,8 @@ static int do_incorporate_leaf(struct fs *fs, struct indexblock *ib,
                 * those in ui will not fill buf.
                 * So shift the buf extents up to the top of the buffer,
                 * then merge the remaining ui extents in.
-                * The first extent may be partially processed already, but
-                * if so, walk_extent modified it so we don't need to care.
+                * The first extent may be partially processed already, so
+                * we might need to adjust it.
                 */
                /* Find end of index list.  Could use a binary search,
                 * but not now.
@@ -1376,6 +1372,15 @@ static int do_incorporate_leaf(struct fs *fs, struct indexblock *ib,
                                b2 -= 12;
                                break;
                        }
+                       if (eaddr < next) {
+                               int handled = next - eaddr;
+                               BUG_ON(eaddr + elen <= next);
+                               b2 -= 12;
+                               BUG_ON(b2 != buf);
+                               encode48(b2, ephys + handled);
+                               encode16(b2, elen - handled);
+                               encode32(b2, next);
+                       }
                }
                /* Data we want extends from buf up to b2
                 * Move it to end of ibuf
@@ -1876,7 +1881,7 @@ void lafs_incorporate(struct fs *fs, struct indexblock *ib)
                /* new needs a B_Credit and a B_ICredit.
                 */
 
-               uit.credits--;;
+               uit.credits--;
                set_bit(B_Credit, &new->b.flags);
                if (uit.credits > 0){
                        set_bit(B_ICredit, &new->b.flags);