This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / fs / jfs / jfs_xtree.c
index 11c58c5..b4dc159 100644 (file)
@@ -958,7 +958,7 @@ xtSplitUp(tid_t tid,
 
        /* is inode xtree root extension/inline EA area free ? */
        if ((sp->header.flag & BT_ROOT) && (!S_ISDIR(ip->i_mode)) &&
-           (le16_to_cpu(sp->header.maxentry) < XTROOTMAXSLOT) &&
+           (sp->header.maxentry < cpu_to_le16(XTROOTMAXSLOT)) &&
            (JFS_IP(ip)->mode2 & INLINEEA)) {
                sp->header.maxentry = cpu_to_le16(XTROOTMAXSLOT);
                JFS_IP(ip)->mode2 &= ~INLINEEA;
@@ -1622,6 +1622,7 @@ int xtExtend(tid_t tid,           /* transaction id */
        s64 xaddr;
        struct tlock *tlck;
        struct xtlock *xtlck = NULL;
+       int rootsplit = 0;
 
        jfs_info("xtExtend: nxoff:0x%lx nxlen:0x%x", (ulong) xoff, xlen);
 
@@ -1677,6 +1678,8 @@ int xtExtend(tid_t tid,           /* transaction id */
         * The xtSplitUp() will insert the entry and unpin the leaf page.
         */
        if (nextindex == le16_to_cpu(p->header.maxentry)) {
+               rootsplit = p->header.flag & BT_ROOT;
+
                /* xtSpliUp() unpins leaf pages */
                split.mp = mp;
                split.index = index + 1;
@@ -1688,21 +1691,16 @@ int xtExtend(tid_t tid,         /* transaction id */
                if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
                        return rc;
 
-               /* get back old page */
-               XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
-               if (rc)
-                       return rc;
                /*
                 * if leaf root has been split, original root has been
                 * copied to new child page, i.e., original entry now
                 * resides on the new child page;
                 */
-               if (p->header.flag & BT_INTERNAL) {
+               if (rootsplit) {
                        ASSERT(p->header.nextindex ==
                               cpu_to_le16(XTENTRYSTART + 1));
                        xad = &p->xad[XTENTRYSTART];
                        bn = addressXAD(xad);
-                       XT_PUTPAGE(mp);
 
                        /* get new child page */
                        XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
@@ -1714,6 +1712,11 @@ int xtExtend(tid_t tid,          /* transaction id */
                                tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
                                xtlck = (struct xtlock *) & tlck->lock;
                        }
+               } else {
+                       /* get back old page */
+                       XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
+                       if (rc)
+                               return rc;
                }
        }
        /*
@@ -1787,6 +1790,7 @@ int xtTailgate(tid_t tid,         /* transaction id */
        struct xtlock *xtlck = 0;
        struct tlock *mtlck;
        struct maplock *pxdlock;
+       int rootsplit = 0;
 
 /*
 printf("xtTailgate: nxoff:0x%lx nxlen:0x%x nxaddr:0x%lx\n",
@@ -1844,6 +1848,8 @@ printf("xtTailgate: xoff:0x%lx xlen:0x%x xaddr:0x%lx\n",
         * The xtSplitUp() will insert the entry and unpin the leaf page.
         */
        if (nextindex == le16_to_cpu(p->header.maxentry)) {
+               rootsplit = p->header.flag & BT_ROOT;
+
                /* xtSpliUp() unpins leaf pages */
                split.mp = mp;
                split.index = index + 1;
@@ -1855,21 +1861,16 @@ printf("xtTailgate: xoff:0x%lx xlen:0x%x xaddr:0x%lx\n",
                if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
                        return rc;
 
-               /* get back old page */
-               XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
-               if (rc)
-                       return rc;
                /*
                 * if leaf root has been split, original root has been
                 * copied to new child page, i.e., original entry now
                 * resides on the new child page;
                 */
-               if (p->header.flag & BT_INTERNAL) {
+               if (rootsplit) {
                        ASSERT(p->header.nextindex ==
                               cpu_to_le16(XTENTRYSTART + 1));
                        xad = &p->xad[XTENTRYSTART];
                        bn = addressXAD(xad);
-                       XT_PUTPAGE(mp);
 
                        /* get new child page */
                        XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
@@ -1881,6 +1882,11 @@ printf("xtTailgate: xoff:0x%lx xlen:0x%x xaddr:0x%lx\n",
                                tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
                                xtlck = (struct xtlock *) & tlck->lock;
                        }
+               } else {
+                       /* get back old page */
+                       XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
+                       if (rc)
+                               return rc;
                }
        }
        /*
@@ -1970,7 +1976,7 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
        s64 nxaddr, xaddr;
        struct tlock *tlck;
        struct xtlock *xtlck = NULL;
-       int newpage = 0;
+       int rootsplit = 0, newpage = 0;
 
        /* there must exist extent to be tailgated */
        nxoff = offsetXAD(nxad);
@@ -2177,6 +2183,7 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
 
        /* insert nXAD:recorded */
        if (nextindex == le16_to_cpu(p->header.maxentry)) {
+               rootsplit = p->header.flag & BT_ROOT;
 
                /* xtSpliUp() unpins leaf pages */
                split.mp = mp;
@@ -2189,21 +2196,16 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
                if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
                        return rc;
 
-               /* get back old page */
-               XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
-               if (rc)
-                       return rc;
                /*
                 * if leaf root has been split, original root has been
                 * copied to new child page, i.e., original entry now
                 * resides on the new child page;
                 */
-               if (p->header.flag & BT_INTERNAL) {
+               if (rootsplit) {
                        ASSERT(p->header.nextindex ==
                               cpu_to_le16(XTENTRYSTART + 1));
                        xad = &p->xad[XTENTRYSTART];
                        bn = addressXAD(xad);
-                       XT_PUTPAGE(mp);
 
                        /* get new child page */
                        XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
@@ -2216,6 +2218,11 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
                                xtlck = (struct xtlock *) & tlck->lock;
                        }
                } else {
+                       /* get back old page */
+                       XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
+                       if (rc)
+                               return rc;
+
                        /* is nXAD on new page ? */
                        if (newindex >
                            (le16_to_cpu(p->header.maxentry) >> 1)) {
@@ -2329,6 +2336,8 @@ int xtUpdate(tid_t tid, struct inode *ip, xad_t * nxad)
        xlen = xlen - nxlen;
        xaddr = xaddr + nxlen;
        if (nextindex == le16_to_cpu(p->header.maxentry)) {
+               rootsplit = p->header.flag & BT_ROOT;
+
 /*
 printf("xtUpdate.updateLeft.split p:0x%p\n", p);
 */
@@ -2343,22 +2352,16 @@ printf("xtUpdate.updateLeft.split p:0x%p\n", p);
                if ((rc = xtSplitUp(tid, ip, &split, &btstack)))
                        return rc;
 
-               /* get back old page */
-               XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
-               if (rc)
-                       return rc;
-
                /*
                 * if leaf root has been split, original root has been
                 * copied to new child page, i.e., original entry now
                 * resides on the new child page;
                 */
-               if (p->header.flag & BT_INTERNAL) {
+               if (rootsplit) {
                        ASSERT(p->header.nextindex ==
                               cpu_to_le16(XTENTRYSTART + 1));
                        xad = &p->xad[XTENTRYSTART];
                        bn = addressXAD(xad);
-                       XT_PUTPAGE(mp);
 
                        /* get new child page */
                        XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
@@ -2370,6 +2373,11 @@ printf("xtUpdate.updateLeft.split p:0x%p\n", p);
                                tlck = txLock(tid, ip, mp, tlckXTREE|tlckGROW);
                                xtlck = (struct xtlock *) & tlck->lock;
                        }
+               } else {
+                       /* get back old page */
+                       XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
+                       if (rc)
+                               return rc;
                }
        } else {
                /* if insert into middle, shift right remaining entries */