netns xfrm: ipcomp6 support
[safe/jmp/linux-2.6] / fs / jfs / jfs_txnmgr.c
index f40301d..d945ea7 100644 (file)
@@ -4,21 +4,21 @@
  *
  *   This program is free software;  you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or 
+ *   the Free Software Foundation; either version 2 of the License, or
  *   (at your option) any later version.
- * 
+ *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
  *   the GNU General Public License for more details.
  *
  *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software 
+ *   along with this program;  if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 /*
- *      jfs_txnmgr.c: transaction manager
+ *     jfs_txnmgr.c: transaction manager
  *
  * notes:
  * transaction starts with txBegin() and ends with txCommit()
  * hold on to mp+lock thru update of maps
  */
 
-
 #include <linux/fs.h>
 #include <linux/vmalloc.h>
-#include <linux/smp_lock.h>
 #include <linux/completion.h>
-#include <linux/suspend.h>
+#include <linux/freezer.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/kthread.h>
+#include <linux/seq_file.h>
 #include "jfs_incore.h"
+#include "jfs_inode.h"
 #include "jfs_filsys.h"
 #include "jfs_metapage.h"
 #include "jfs_dinode.h"
@@ -60,7 +61,7 @@
 #include "jfs_debug.h"
 
 /*
- *      transaction management structures
+ *     transaction management structures
  */
 static struct {
        int freetid;            /* index of a free tid structure */
@@ -103,27 +104,25 @@ module_param(nTxLock, int, 0);
 MODULE_PARM_DESC(nTxLock,
                 "Number of transaction locks (max:65536)");
 
-struct tblock *TxBlock;                /* transaction block table */
-static int TxLockLWM;          /* Low water mark for number of txLocks used */
-static int TxLockHWM;          /* High water mark for number of txLocks used */
-static int TxLockVHWM;         /* Very High water mark */
-struct tlock *TxLock;           /* transaction lock table */
-
+struct tblock *TxBlock;        /* transaction block table */
+static int TxLockLWM;  /* Low water mark for number of txLocks used */
+static int TxLockHWM;  /* High water mark for number of txLocks used */
+static int TxLockVHWM; /* Very High water mark */
+struct tlock *TxLock;  /* transaction lock table */
 
 /*
- *      transaction management lock
+ *     transaction management lock
  */
 static DEFINE_SPINLOCK(jfsTxnLock);
 
-#define TXN_LOCK()              spin_lock(&jfsTxnLock)
-#define TXN_UNLOCK()            spin_unlock(&jfsTxnLock)
+#define TXN_LOCK()             spin_lock(&jfsTxnLock)
+#define TXN_UNLOCK()           spin_unlock(&jfsTxnLock)
 
 #define LAZY_LOCK_INIT()       spin_lock_init(&TxAnchor.LazyLock);
 #define LAZY_LOCK(flags)       spin_lock_irqsave(&TxAnchor.LazyLock, flags)
 #define LAZY_UNLOCK(flags) spin_unlock_irqrestore(&TxAnchor.LazyLock, flags)
 
-DECLARE_WAIT_QUEUE_HEAD(jfs_sync_thread_wait);
-DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
+static DECLARE_WAIT_QUEUE_HEAD(jfs_commit_thread_wait);
 static int jfs_commit_thread_waking;
 
 /*
@@ -136,8 +135,8 @@ static inline void TXN_SLEEP_DROP_LOCK(wait_queue_head_t * event)
        add_wait_queue(event, &wait);
        set_current_state(TASK_UNINTERRUPTIBLE);
        TXN_UNLOCK();
-       schedule();
-       current->state = TASK_RUNNING;
+       io_schedule();
+       __set_current_state(TASK_RUNNING);
        remove_wait_queue(event, &wait);
 }
 
@@ -149,9 +148,8 @@ static inline void TXN_SLEEP_DROP_LOCK(wait_queue_head_t * event)
 
 #define TXN_WAKEUP(event) wake_up_all(event)
 
-
 /*
- *      statistics
+ *     statistics
  */
 static struct {
        tid_t maxtid;           /* 4: biggest tid ever used */
@@ -161,16 +159,6 @@ static struct {
        int waitlock;           /* 4: # of tlock wait */
 } stattx;
 
-
-/*
- * external references
- */
-extern int lmGroupCommit(struct jfs_log *, struct tblock *);
-extern int jfs_commit_inode(struct inode *, int);
-extern int jfs_stop_threads;
-
-extern struct completion jfsIOwait;
-
 /*
  * forward references
  */
@@ -194,8 +182,8 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
 static void LogSyncRelease(struct metapage * mp);
 
 /*
- *              transaction block/lock management
- *              ---------------------------------
+ *             transaction block/lock management
+ *             ---------------------------------
  */
 
 /*
@@ -219,7 +207,7 @@ static lid_t txLockAlloc(void)
        if ((++TxAnchor.tlocksInUse > TxLockHWM) && (jfs_tlocks_low == 0)) {
                jfs_info("txLockAlloc tlocks low");
                jfs_tlocks_low = 1;
-               wake_up(&jfs_sync_thread_wait);
+               wake_up_process(jfsSyncThread);
        }
 
        return lid;
@@ -227,6 +215,7 @@ static lid_t txLockAlloc(void)
 
 static void txLockFree(lid_t lid)
 {
+       TxLock[lid].tid = 0;
        TxLock[lid].next = TxAnchor.freelock;
        TxAnchor.freelock = lid;
        TxAnchor.tlocksInUse--;
@@ -239,9 +228,9 @@ static void txLockFree(lid_t lid)
 }
 
 /*
- * NAME:        txInit()
+ * NAME:       txInit()
  *
- * FUNCTION:    initialize transaction management structures
+ * FUNCTION:   initialize transaction management structures
  *
  * RETURN:
  *
@@ -293,7 +282,7 @@ int txInit(void)
        TxLockVHWM = (nTxLock * 8) / 10;
 
        size = sizeof(struct tblock) * nTxBlock;
-       TxBlock = (struct tblock *) vmalloc(size);
+       TxBlock = vmalloc(size);
        if (TxBlock == NULL)
                return -ENOMEM;
 
@@ -318,7 +307,7 @@ int txInit(void)
         * tlock id = 0 is reserved.
         */
        size = sizeof(struct tlock) * nTxLock;
-       TxLock = (struct tlock *) vmalloc(size);
+       TxLock = vmalloc(size);
        if (TxLock == NULL) {
                vfree(TxBlock);
                return -ENOMEM;
@@ -345,9 +334,9 @@ int txInit(void)
 }
 
 /*
- * NAME:        txExit()
+ * NAME:       txExit()
  *
- * FUNCTION:    clean up when module is unloaded
+ * FUNCTION:   clean up when module is unloaded
  */
 void txExit(void)
 {
@@ -357,14 +346,13 @@ void txExit(void)
        TxBlock = NULL;
 }
 
-
 /*
- * NAME:        txBegin()
+ * NAME:       txBegin()
  *
- * FUNCTION:    start a transaction.
+ * FUNCTION:   start a transaction.
  *
- * PARAMETER:   sb     - superblock
- *              flag   - force for nested tx;
+ * PARAMETER:  sb      - superblock
+ *             flag    - force for nested tx;
  *
  * RETURN:     tid     - transaction id
  *
@@ -459,15 +447,14 @@ tid_t txBegin(struct super_block *sb, int flag)
        return t;
 }
 
-
 /*
- * NAME:        txBeginAnon()
+ * NAME:       txBeginAnon()
  *
- * FUNCTION:    start an anonymous transaction.
+ * FUNCTION:   start an anonymous transaction.
  *             Blocks if logsync or available tlocks are low to prevent
  *             anonymous tlocks from depleting supply.
  *
- * PARAMETER:   sb     - superblock
+ * PARAMETER:  sb      - superblock
  *
  * RETURN:     none
  */
@@ -502,13 +489,12 @@ void txBeginAnon(struct super_block *sb)
        TXN_UNLOCK();
 }
 
-
 /*
- *      txEnd()
+ *     txEnd()
  *
  * function: free specified transaction block.
  *
- *      logsync barrier processing:
+ *     logsync barrier processing:
  *
  * serialization:
  */
@@ -566,8 +552,10 @@ void txEnd(tid_t tid)
                 * synchronize with logsync barrier
                 */
                if (test_bit(log_SYNCBARRIER, &log->flag)) {
-                       /* forward log syncpt */
-                       /* lmSync(log); */
+                       TXN_UNLOCK();
+
+                       /* write dirty metadata & forward log syncpt */
+                       jfs_syncpt(log, 1);
 
                        jfs_info("log barrier off: 0x%x", log->lsn);
 
@@ -576,26 +564,27 @@ void txEnd(tid_t tid)
 
                        /* wakeup all waitors for logsync barrier */
                        TXN_WAKEUP(&log->syncwait);
+
+                       goto wakeup;
                }
        }
 
+       TXN_UNLOCK();
+wakeup:
        /*
         * wakeup all waitors for a free tblock
         */
        TXN_WAKEUP(&TxAnchor.freewait);
-
-       TXN_UNLOCK();
 }
 
-
 /*
- *      txLock()
+ *     txLock()
  *
  * function: acquire a transaction lock on the specified <mp>
  *
  * parameter:
  *
- * return:      transaction lock id
+ * return:     transaction lock id
  *
  * serialization:
  */
@@ -633,8 +622,10 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
 
        /* is page locked by the requester transaction ? */
        tlck = lid_to_tlock(lid);
-       if ((xtid = tlck->tid) == tid)
+       if ((xtid = tlck->tid) == tid) {
+               TXN_UNLOCK();
                goto grantLock;
+       }
 
        /*
         * is page locked by anonymous transaction/lock ?
@@ -649,6 +640,7 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
         */
        if (xtid == 0) {
                tlck->tid = tid;
+               TXN_UNLOCK();
                tblk = tid_to_tblock(tid);
                /*
                 * The order of the tlocks in the transaction is important
@@ -665,7 +657,9 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
                                /* only anonymous txn.
                                 * Remove from anon_list
                                 */
+                               TXN_LOCK();
                                list_del_init(&jfs_ip->anon_inode_list);
+                               TXN_UNLOCK();
                        }
                        jfs_ip->atlhead = tlck->next;
                } else {
@@ -706,17 +700,18 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
         */
        tlck->tid = tid;
 
+       TXN_UNLOCK();
+
        /* mark tlock for meta-data page */
        if (mp->xflag & COMMIT_PAGE) {
 
                tlck->flag = tlckPAGELOCK;
 
                /* mark the page dirty and nohomeok */
-               mark_metapage_dirty(mp);
-               atomic_inc(&mp->nohomeok);
+               metapage_nohomeok(mp);
 
                jfs_info("locking mp = 0x%p, nohomeok = %d tid = %d tlck = 0x%p",
-                        mp, atomic_read(&mp->nohomeok), tid, tlck);
+                        mp, mp->nohomeok, tid, tlck);
 
                /* if anonymous transaction, and buffer is on the group
                 * commit synclist, mark inode to show this.  This will
@@ -730,6 +725,9 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
        else
                tlck->flag = tlckINODELOCK;
 
+       if (S_ISDIR(ip->i_mode))
+               tlck->flag |= tlckDIRECTORY;
+
        tlck->type = 0;
 
        /* bind the tlock and the page */
@@ -762,8 +760,10 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
                if (tlck->next == 0) {
                        /* This inode's first anonymous transaction */
                        jfs_ip->atltail = lid;
+                       TXN_LOCK();
                        list_add_tail(&jfs_ip->anon_inode_list,
                                      &TxAnchor.anon_list);
+                       TXN_UNLOCK();
                }
        }
 
@@ -821,8 +821,6 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
       grantLock:
        tlck->type |= type;
 
-       TXN_UNLOCK();
-
        return tlck;
 
        /*
@@ -832,38 +830,49 @@ struct tlock *txLock(tid_t tid, struct inode *ip, struct metapage * mp,
        /* Only locks on ipimap or ipaimap should reach here */
        /* assert(jfs_ip->fileset == AGGREGATE_I); */
        if (jfs_ip->fileset != AGGREGATE_I) {
-               jfs_err("txLock: trying to lock locked page!");
-               dump_mem("ip", ip, sizeof(struct inode));
-               dump_mem("mp", mp, sizeof(struct metapage));
-               dump_mem("Locker's tblk", tid_to_tblock(tid),
-                        sizeof(struct tblock));
-               dump_mem("Tlock", tlck, sizeof(struct tlock));
+               printk(KERN_ERR "txLock: trying to lock locked page!");
+               print_hex_dump(KERN_ERR, "ip: ", DUMP_PREFIX_ADDRESS, 16, 4,
+                              ip, sizeof(*ip), 0);
+               print_hex_dump(KERN_ERR, "mp: ", DUMP_PREFIX_ADDRESS, 16, 4,
+                              mp, sizeof(*mp), 0);
+               print_hex_dump(KERN_ERR, "Locker's tblock: ",
+                              DUMP_PREFIX_ADDRESS, 16, 4, tid_to_tblock(tid),
+                              sizeof(struct tblock), 0);
+               print_hex_dump(KERN_ERR, "Tlock: ", DUMP_PREFIX_ADDRESS, 16, 4,
+                              tlck, sizeof(*tlck), 0);
                BUG();
        }
        INCREMENT(stattx.waitlock);     /* statistics */
+       TXN_UNLOCK();
        release_metapage(mp);
+       TXN_LOCK();
+       xtid = tlck->tid;       /* reacquire after dropping TXN_LOCK */
 
        jfs_info("txLock: in waitLock, tid = %d, xtid = %d, lid = %d",
                 tid, xtid, lid);
-       TXN_SLEEP_DROP_LOCK(&tid_to_tblock(xtid)->waitor);
+
+       /* Recheck everything since dropping TXN_LOCK */
+       if (xtid && (tlck->mp == mp) && (mp->lid == lid))
+               TXN_SLEEP_DROP_LOCK(&tid_to_tblock(xtid)->waitor);
+       else
+               TXN_UNLOCK();
        jfs_info("txLock: awakened     tid = %d, lid = %d", tid, lid);
 
        return NULL;
 }
 
-
 /*
- * NAME:        txRelease()
+ * NAME:       txRelease()
  *
- * FUNCTION:    Release buffers associated with transaction locks, but don't
+ * FUNCTION:   Release buffers associated with transaction locks, but don't
  *             mark homeok yet.  The allows other transactions to modify
  *             buffers, but won't let them go to disk until commit record
  *             actually gets written.
  *
  * PARAMETER:
- *              tblk    -
+ *             tblk    -
  *
- * RETURN:      Errors from subroutines.
+ * RETURN:     Errors from subroutines.
  */
 static void txRelease(struct tblock * tblk)
 {
@@ -891,12 +900,11 @@ static void txRelease(struct tblock * tblk)
        TXN_UNLOCK();
 }
 
-
 /*
- * NAME:        txUnlock()
+ * NAME:       txUnlock()
  *
- * FUNCTION:    Initiates pageout of pages modified by tid in journalled
- *              objects and frees their lockwords.
+ * FUNCTION:   Initiates pageout of pages modified by tid in journalled
+ *             objects and frees their lockwords.
  */
 static void txUnlock(struct tblock * tblk)
 {
@@ -906,6 +914,7 @@ static void txUnlock(struct tblock * tblk)
        struct metapage *mp;
        struct jfs_log *log;
        int difft, diffp;
+       unsigned long flags;
 
        jfs_info("txUnlock: tblk = 0x%p", tblk);
        log = JFS_SBI(tblk->sb)->log;
@@ -925,19 +934,14 @@ static void txUnlock(struct tblock * tblk)
                        assert(mp->xflag & COMMIT_PAGE);
 
                        /* hold buffer
-                        *
-                        * It's possible that someone else has the metapage.
-                        * The only things were changing are nohomeok, which
-                        * is handled atomically, and clsn which is protected
-                        * by the LOGSYNC_LOCK.
                         */
-                       hold_metapage(mp, 1);
+                       hold_metapage(mp);
 
-                       assert(atomic_read(&mp->nohomeok) > 0);
-                       atomic_dec(&mp->nohomeok);
+                       assert(mp->nohomeok > 0);
+                       _metapage_homeok(mp);
 
                        /* inherit younger/larger clsn */
-                       LOGSYNC_LOCK(log);
+                       LOGSYNC_LOCK(log, flags);
                        if (mp->clsn) {
                                logdiff(difft, tblk->clsn, log);
                                logdiff(diffp, mp->clsn, log);
@@ -945,16 +949,11 @@ static void txUnlock(struct tblock * tblk)
                                        mp->clsn = tblk->clsn;
                        } else
                                mp->clsn = tblk->clsn;
-                       LOGSYNC_UNLOCK(log);
+                       LOGSYNC_UNLOCK(log, flags);
 
                        assert(!(tlck->flag & tlckFREEPAGE));
 
-                       if (tlck->flag & tlckWRITEPAGE) {
-                               write_metapage(mp);
-                       } else {
-                               /* release page which has been forced */
-                               release_metapage(mp);
-                       }
+                       put_metapage(mp);
                }
 
                /* insert tlock, and linelock(s) of the tlock if any,
@@ -981,19 +980,18 @@ static void txUnlock(struct tblock * tblk)
         * has been inserted in logsync list at txUpdateMap())
         */
        if (tblk->lsn) {
-               LOGSYNC_LOCK(log);
+               LOGSYNC_LOCK(log, flags);
                log->count--;
                list_del(&tblk->synclist);
-               LOGSYNC_UNLOCK(log);
+               LOGSYNC_UNLOCK(log, flags);
        }
 }
 
-
 /*
- *      txMaplock()
+ *     txMaplock()
  *
  * function: allocate a transaction lock for freed page/entry;
- *      for freed page, maplock is used as xtlock/dtlock type;
+ *     for freed page, maplock is used as xtlock/dtlock type;
  */
 struct tlock *txMaplock(tid_t tid, struct inode *ip, int type)
 {
@@ -1018,6 +1016,8 @@ struct tlock *txMaplock(tid_t tid, struct inode *ip, int type)
 
        /* bind the tlock and the object */
        tlck->flag = tlckINODELOCK;
+       if (S_ISDIR(ip->i_mode))
+               tlck->flag |= tlckDIRECTORY;
        tlck->ip = ip;
        tlck->mp = NULL;
 
@@ -1061,9 +1061,8 @@ struct tlock *txMaplock(tid_t tid, struct inode *ip, int type)
        return tlck;
 }
 
-
 /*
- *      txLinelock()
+ *     txLinelock()
  *
  * function: allocate a transaction lock for log vector list
  */
@@ -1087,6 +1086,8 @@ struct linelock *txLinelock(struct linelock * tlock)
        linelock->flag = tlckLINELOCK;
        linelock->maxcnt = TLOCKLONG;
        linelock->index = 0;
+       if (tlck->flag & tlckDIRECTORY)
+               linelock->flag |= tlckDIRECTORY;
 
        /* append linelock after tlock */
        linelock->next = tlock->next;
@@ -1095,42 +1096,40 @@ struct linelock *txLinelock(struct linelock * tlock)
        return linelock;
 }
 
-
-
 /*
- *              transaction commit management
- *              -----------------------------
+ *             transaction commit management
+ *             -----------------------------
  */
 
 /*
- * NAME:        txCommit()
- *
- * FUNCTION:    commit the changes to the objects specified in
- *              clist.  For journalled segments only the
- *              changes of the caller are committed, ie by tid.
- *              for non-journalled segments the data are flushed to
- *              disk and then the change to the disk inode and indirect
- *              blocks committed (so blocks newly allocated to the
- *              segment will be made a part of the segment atomically).
- *
- *              all of the segments specified in clist must be in
- *              one file system. no more than 6 segments are needed
- *              to handle all unix svcs.
- *
- *              if the i_nlink field (i.e. disk inode link count)
- *              is zero, and the type of inode is a regular file or
- *              directory, or symbolic link , the inode is truncated
- *              to zero length. the truncation is committed but the
- *              VM resources are unaffected until it is closed (see
- *              iput and iclose).
+ * NAME:       txCommit()
+ *
+ * FUNCTION:   commit the changes to the objects specified in
+ *             clist.  For journalled segments only the
+ *             changes of the caller are committed, ie by tid.
+ *             for non-journalled segments the data are flushed to
+ *             disk and then the change to the disk inode and indirect
+ *             blocks committed (so blocks newly allocated to the
+ *             segment will be made a part of the segment atomically).
+ *
+ *             all of the segments specified in clist must be in
+ *             one file system. no more than 6 segments are needed
+ *             to handle all unix svcs.
+ *
+ *             if the i_nlink field (i.e. disk inode link count)
+ *             is zero, and the type of inode is a regular file or
+ *             directory, or symbolic link , the inode is truncated
+ *             to zero length. the truncation is committed but the
+ *             VM resources are unaffected until it is closed (see
+ *             iput and iclose).
  *
  * PARAMETER:
  *
  * RETURN:
  *
  * serialization:
- *              on entry the inode lock on each segment is assumed
- *              to be held.
+ *             on entry the inode lock on each segment is assumed
+ *             to be held.
  *
  * i/o error:
  */
@@ -1181,7 +1180,7 @@ int txCommit(tid_t tid,           /* transaction identifier */
        if ((flag & (COMMIT_FORCE | COMMIT_SYNC)) == 0)
                tblk->xflag |= COMMIT_LAZY;
        /*
-        *      prepare non-journaled objects for commit
+        *      prepare non-journaled objects for commit
         *
         * flush data pages of non-journaled file
         * to prevent the file getting non-initialized disk blocks
@@ -1192,7 +1191,7 @@ int txCommit(tid_t tid,           /* transaction identifier */
        cd.nip = nip;
 
        /*
-        *      acquire transaction lock on (on-disk) inodes
+        *      acquire transaction lock on (on-disk) inodes
         *
         * update on-disk inode from in-memory inode
         * acquiring transaction locks for AFTER records
@@ -1236,10 +1235,8 @@ int txCommit(tid_t tid,          /* transaction identifier */
                 * when we don't need to worry about it at all.
                 *
                 * if ((!S_ISDIR(ip->i_mode))
-                *    && (tblk->flag & COMMIT_DELETE) == 0) {
-                *      filemap_fdatawrite(ip->i_mapping);
-                *      filemap_fdatawait(ip->i_mapping);
-                * }
+                *    && (tblk->flag & COMMIT_DELETE) == 0)
+                *      filemap_write_and_wait(ip->i_mapping);
                 */
 
                /*
@@ -1270,7 +1267,7 @@ int txCommit(tid_t tid,           /* transaction identifier */
        }
 
        /*
-        *      write log records from transaction locks
+        *      write log records from transaction locks
         *
         * txUpdateMap() resets XAD_NEW in XAD.
         */
@@ -1293,7 +1290,14 @@ int txCommit(tid_t tid,          /* transaction identifier */
                 * commit the transaction synchronously, so the last iput
                 * will be done by the calling thread (or later)
                 */
-               if (tblk->u.ip->i_state & I_LOCK)
+               /*
+                * I believe this code is no longer needed.  Splitting I_LOCK
+                * into two bits, I_NEW and I_SYNC should prevent this
+                * deadlock as well.  But since I don't have a JFS testload
+                * to verify this, only a trivial s/I_LOCK/I_SYNC/ was done.
+                * Joern
+                */
+               if (tblk->u.ip->i_state & I_SYNC)
                        tblk->xflag &= ~COMMIT_LAZY;
        }
 
@@ -1302,7 +1306,7 @@ int txCommit(tid_t tid,           /* transaction identifier */
                !test_cflag(COMMIT_Nolink, tblk->u.ip)));
 
        /*
-        *      write COMMIT log record
+        *      write COMMIT log record
         */
        lrd->type = cpu_to_le16(LOG_COMMIT);
        lrd->length = 0;
@@ -1311,7 +1315,7 @@ int txCommit(tid_t tid,           /* transaction identifier */
        lmGroupCommit(log, tblk);
 
        /*
-        *      - transaction is now committed -
+        *      - transaction is now committed -
         */
 
        /*
@@ -1322,11 +1326,11 @@ int txCommit(tid_t tid,         /* transaction identifier */
                txForce(tblk);
 
        /*
-        *      update allocation map.
+        *      update allocation map.
         *
         * update inode allocation map and inode:
         * free pager lock on memory object of inode if any.
-        * update  block allocation map.
+        * update block allocation map.
         *
         * txUpdateMap() resets XAD_NEW in XAD.
         */
@@ -1334,7 +1338,7 @@ int txCommit(tid_t tid,           /* transaction identifier */
                txUpdateMap(tblk);
 
        /*
-        *      free transaction locks and pageout/free pages
+        *      free transaction locks and pageout/free pages
         */
        txRelease(tblk);
 
@@ -1343,7 +1347,7 @@ int txCommit(tid_t tid,           /* transaction identifier */
 
 
        /*
-        *      reset in-memory object state
+        *      reset in-memory object state
         */
        for (k = 0; k < cd.nip; k++) {
                ip = cd.iplist[k];
@@ -1365,13 +1369,12 @@ int txCommit(tid_t tid,         /* transaction identifier */
        return rc;
 }
 
-
 /*
- * NAME:        txLog()
+ * NAME:       txLog()
  *
- * FUNCTION:    Writes AFTER log records for all lines modified
- *              by tid for segments specified by inodes in comdata.
- *              Code assumes only WRITELOCKS are recorded in lockwords.
+ * FUNCTION:   Writes AFTER log records for all lines modified
+ *             by tid for segments specified by inodes in comdata.
+ *             Code assumes only WRITELOCKS are recorded in lockwords.
  *
  * PARAMETERS:
  *
@@ -1429,14 +1432,13 @@ static int txLog(struct jfs_log * log, struct tblock * tblk, struct commit * cd)
        return rc;
 }
 
-
 /*
- *      diLog()
+ *     diLog()
  *
- * function:    log inode tlock and format maplock to update bmap;
+ * function:   log inode tlock and format maplock to update bmap;
  */
 static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
-         struct tlock * tlck, struct commit * cd)
+                struct tlock * tlck, struct commit * cd)
 {
        int rc = 0;
        struct metapage *mp;
@@ -1452,12 +1454,11 @@ static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        pxd = &lrd->log.redopage.pxd;
 
        /*
-        *      inode after image
+        *      inode after image
         */
        if (tlck->type & tlckENTRY) {
                /* log after-image for logredo(): */
                lrd->type = cpu_to_le16(LOG_REDOPAGE);
-//              *pxd = mp->cm_pxd;
                PXDaddress(pxd, mp->index);
                PXDlength(pxd,
                          mp->logical_size >> tblk->sb->s_blocksize_bits);
@@ -1467,7 +1468,7 @@ static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                tlck->flag |= tlckWRITEPAGE;
        } else if (tlck->type & tlckFREE) {
                /*
-                *      free inode extent
+                *      free inode extent
                 *
                 * (pages of the freed inode extent have been invalidated and
                 * a maplock for free of the extent has been formatted at
@@ -1509,7 +1510,7 @@ static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                jfs_err("diLog: UFO type tlck:0x%p", tlck);
 #ifdef  _JFS_WIP
        /*
-        *      alloc/free external EA extent
+        *      alloc/free external EA extent
         *
         * a maplock for txUpdateMap() to update bPWMAP for alloc/free
         * of the extent has been formatted at txLock() time;
@@ -1544,11 +1545,10 @@ static int diLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        return rc;
 }
 
-
 /*
- *      dataLog()
+ *     dataLog()
  *
- * function:    log data tlock
+ * function:   log data tlock
  */
 static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
            struct tlock * tlck)
@@ -1573,8 +1573,8 @@ static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                 * the last entry, so don't bother logging this
                 */
                mp->lid = 0;
-               hold_metapage(mp, 0);
-               atomic_dec(&mp->nohomeok);
+               grab_metapage(mp);
+               metapage_homeok(mp);
                discard_metapage(mp);
                tlck->mp = NULL;
                return 0;
@@ -1591,11 +1591,10 @@ static int dataLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        return 0;
 }
 
-
 /*
- *      dtLog()
+ *     dtLog()
  *
- * function:    log dtree tlock and format maplock to update bmap;
+ * function:   log dtree tlock and format maplock to update bmap;
  */
 static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
           struct tlock * tlck)
@@ -1616,10 +1615,10 @@ static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
 
        /*
-        *      page extension via relocation: entry insertion;
-        *      page extension in-place: entry insertion;
-        *      new right page from page split, reinitialized in-line
-        *      root from root page split: entry insertion;
+        *      page extension via relocation: entry insertion;
+        *      page extension in-place: entry insertion;
+        *      new right page from page split, reinitialized in-line
+        *      root from root page split: entry insertion;
         */
        if (tlck->type & (tlckNEW | tlckEXTEND)) {
                /* log after-image of the new page for logredo():
@@ -1631,7 +1630,6 @@ static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                        lrd->log.redopage.type |= cpu_to_le16(LOG_EXTEND);
                else
                        lrd->log.redopage.type |= cpu_to_le16(LOG_NEW);
-//              *pxd = mp->cm_pxd;
                PXDaddress(pxd, mp->index);
                PXDlength(pxd,
                          mp->logical_size >> tblk->sb->s_blocksize_bits);
@@ -1655,8 +1653,8 @@ static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        }
 
        /*
-        *      entry insertion/deletion,
-        *      sibling page link update (old right page before split);
+        *      entry insertion/deletion,
+        *      sibling page link update (old right page before split);
         */
        if (tlck->type & (tlckENTRY | tlckRELINK)) {
                /* log after-image for logredo(): */
@@ -1672,11 +1670,11 @@ static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        }
 
        /*
-        *      page deletion: page has been invalidated
-        *      page relocation: source extent
+        *      page deletion: page has been invalidated
+        *      page relocation: source extent
         *
-        *      a maplock for free of the page has been formatted
-        *      at txLock() time);
+        *      a maplock for free of the page has been formatted
+        *      at txLock() time);
         */
        if (tlck->type & (tlckFREE | tlckRELOCATE)) {
                /* log LOG_NOREDOPAGE of the deleted page for logredo()
@@ -1696,11 +1694,10 @@ static void dtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        return;
 }
 
-
 /*
- *      xtLog()
+ *     xtLog()
  *
- * function:    log xtree tlock and format maplock to update bmap;
+ * function:   log xtree tlock and format maplock to update bmap;
  */
 static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
           struct tlock * tlck)
@@ -1712,7 +1709,7 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        struct maplock *maplock;
        struct xdlistlock *xadlock;
        struct pxd_lock *pxdlock;
-       pxd_t *pxd;
+       pxd_t *page_pxd;
        int next, lwm, hwm;
 
        ip = tlck->ip;
@@ -1722,7 +1719,7 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        lrd->log.redopage.type = cpu_to_le16(LOG_XTREE);
        lrd->log.redopage.l2linesize = cpu_to_le16(L2XTSLOTSIZE);
 
-       pxd = &lrd->log.redopage.pxd;
+       page_pxd = &lrd->log.redopage.pxd;
 
        if (tlck->type & tlckBTROOT) {
                lrd->log.redopage.type |= cpu_to_le16(LOG_BTROOT);
@@ -1740,8 +1737,8 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        xadlock = (struct xdlistlock *) maplock;
 
        /*
-        *      entry insertion/extension;
-        *      sibling page link update (old right page before split);
+        *      entry insertion/extension;
+        *      sibling page link update (old right page before split);
         */
        if (tlck->type & (tlckNEW | tlckGROW | tlckRELINK)) {
                /* log after-image for logredo():
@@ -1752,9 +1749,8 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                 * applying the after-image to the meta-data page.
                 */
                lrd->type = cpu_to_le16(LOG_REDOPAGE);
-//              *pxd = mp->cm_pxd;
-               PXDaddress(pxd, mp->index);
-               PXDlength(pxd,
+               PXDaddress(page_pxd, mp->index);
+               PXDlength(page_pxd,
                          mp->logical_size >> tblk->sb->s_blocksize_bits);
                lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
 
@@ -1776,25 +1772,31 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                tlck->flag |= tlckUPDATEMAP;
                xadlock->flag = mlckALLOCXADLIST;
                xadlock->count = next - lwm;
-               if ((xadlock->count <= 2) && (tblk->xflag & COMMIT_LAZY)) {
+               if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
                        int i;
+                       pxd_t *pxd;
                        /*
                         * Lazy commit may allow xtree to be modified before
                         * txUpdateMap runs.  Copy xad into linelock to
                         * preserve correct data.
+                        *
+                        * We can fit twice as may pxd's as xads in the lock
                         */
-                       xadlock->xdlist = &xtlck->pxdlock;
-                       memcpy(xadlock->xdlist, &p->xad[lwm],
-                              sizeof(xad_t) * xadlock->count);
-
-                       for (i = 0; i < xadlock->count; i++)
+                       xadlock->flag = mlckALLOCPXDLIST;
+                       pxd = xadlock->xdlist = &xtlck->pxdlock;
+                       for (i = 0; i < xadlock->count; i++) {
+                               PXDaddress(pxd, addressXAD(&p->xad[lwm + i]));
+                               PXDlength(pxd, lengthXAD(&p->xad[lwm + i]));
                                p->xad[lwm + i].flag &=
                                    ~(XAD_NEW | XAD_EXTENDED);
+                               pxd++;
+                       }
                } else {
                        /*
                         * xdlist will point to into inode's xtree, ensure
                         * that transaction is not committed lazily.
                         */
+                       xadlock->flag = mlckALLOCXADLIST;
                        xadlock->xdlist = &p->xad[lwm];
                        tblk->xflag &= ~COMMIT_LAZY;
                }
@@ -1811,7 +1813,7 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        }
 
        /*
-        *      page deletion: file deletion/truncation (ref. xtTruncate())
+        *      page deletion: file deletion/truncation (ref. xtTruncate())
         *
         * (page will be invalidated after log is written and bmap
         * is updated from the page);
@@ -1836,8 +1838,8 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                if (tblk->xflag & COMMIT_TRUNCATE) {
                        /* write NOREDOPAGE for the page */
                        lrd->type = cpu_to_le16(LOG_NOREDOPAGE);
-                       PXDaddress(pxd, mp->index);
-                       PXDlength(pxd,
+                       PXDaddress(page_pxd, mp->index);
+                       PXDlength(page_pxd,
                                  mp->logical_size >> tblk->sb->
                                  s_blocksize_bits);
                        lrd->backchain =
@@ -1872,22 +1874,32 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                 * deleted page itself;
                 */
                tlck->flag |= tlckUPDATEMAP;
-               xadlock->flag = mlckFREEXADLIST;
                xadlock->count = hwm - XTENTRYSTART + 1;
-               if ((xadlock->count <= 2) && (tblk->xflag & COMMIT_LAZY)) {
+               if ((xadlock->count <= 4) && (tblk->xflag & COMMIT_LAZY)) {
+                       int i;
+                       pxd_t *pxd;
                        /*
                         * Lazy commit may allow xtree to be modified before
                         * txUpdateMap runs.  Copy xad into linelock to
                         * preserve correct data.
+                        *
+                        * We can fit twice as may pxd's as xads in the lock
                         */
-                       xadlock->xdlist = &xtlck->pxdlock;
-                       memcpy(xadlock->xdlist, &p->xad[XTENTRYSTART],
-                              sizeof(xad_t) * xadlock->count);
+                       xadlock->flag = mlckFREEPXDLIST;
+                       pxd = xadlock->xdlist = &xtlck->pxdlock;
+                       for (i = 0; i < xadlock->count; i++) {
+                               PXDaddress(pxd,
+                                       addressXAD(&p->xad[XTENTRYSTART + i]));
+                               PXDlength(pxd,
+                                       lengthXAD(&p->xad[XTENTRYSTART + i]));
+                               pxd++;
+                       }
                } else {
                        /*
                         * xdlist will point to into inode's xtree, ensure
                         * that transaction is not committed lazily.
                         */
+                       xadlock->flag = mlckFREEXADLIST;
                        xadlock->xdlist = &p->xad[XTENTRYSTART];
                        tblk->xflag &= ~COMMIT_LAZY;
                }
@@ -1908,17 +1920,18 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        }
 
        /*
-        *      page/entry truncation: file truncation (ref. xtTruncate())
+        *      page/entry truncation: file truncation (ref. xtTruncate())
         *
-        *     |----------+------+------+---------------|
-        *                |      |      |
-        *                |      |     hwm - hwm before truncation
-        *                |     next - truncation point
-        *               lwm - lwm before truncation
+        *      |----------+------+------+---------------|
+        *                 |      |      |
+        *                 |      |     hwm - hwm before truncation
+        *                 |     next - truncation point
+        *                lwm - lwm before truncation
         * header ?
         */
        if (tlck->type & tlckTRUNCATE) {
-               pxd_t tpxd;     /* truncated extent of xad */
+               /* This odd declaration suppresses a bogus gcc warning */
+               pxd_t pxd = pxd;        /* truncated extent of xad */
                int twm;
 
                /*
@@ -1936,7 +1949,7 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                twm = xtlck->twm.offset;
 
                /*
-                *      write log records
+                *      write log records
                 */
                /* log after-image for logredo():
                 *
@@ -1947,8 +1960,9 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                 * applying the after-image to the meta-data page.
                 */
                lrd->type = cpu_to_le16(LOG_REDOPAGE);
-               PXDaddress(pxd, mp->index);
-               PXDlength(pxd, mp->logical_size >> tblk->sb->s_blocksize_bits);
+               PXDaddress(page_pxd, mp->index);
+               PXDlength(page_pxd,
+                         mp->logical_size >> tblk->sb->s_blocksize_bits);
                lrd->backchain = cpu_to_le32(lmLog(log, tblk, lrd, tlck));
 
                /*
@@ -1966,7 +1980,7 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                        lrd->log.updatemap.type = cpu_to_le16(LOG_FREEPXD);
                        lrd->log.updatemap.nxd = cpu_to_le16(1);
                        lrd->log.updatemap.pxd = pxdlock->pxd;
-                       tpxd = pxdlock->pxd;    /* save to format maplock */
+                       pxd = pxdlock->pxd;     /* save to format maplock */
                        lrd->backchain =
                            cpu_to_le32(lmLog(log, tblk, lrd, NULL));
                }
@@ -1995,7 +2009,7 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                }
 
                /*
-                *      format maplock(s) for txUpdateMap() to update bmap
+                *      format maplock(s) for txUpdateMap() to update bmap
                 */
                maplock->index = 0;
 
@@ -2024,8 +2038,6 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                 * truncate entry XAD[twm == next - 1]:
                 */
                if (twm == next - 1) {
-                       struct pxd_lock *pxdlock;
-
                        /* format a maplock for txUpdateMap() to update bmap
                         * to free truncated delta extent of the truncated
                         * entry XAD[next - 1];
@@ -2035,7 +2047,7 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
                        pxdlock = (struct pxd_lock *) xadlock;
                        pxdlock->flag = mlckFREEPXD;
                        pxdlock->count = 1;
-                       pxdlock->pxd = tpxd;
+                       pxdlock->pxd = pxd;
 
                        jfs_info("xtLog: truncate ip:0x%p mp:0x%p count:%d "
                                 "hwm:%d", ip, mp, pxdlock->count, hwm);
@@ -2068,21 +2080,20 @@ static void xtLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        return;
 }
 
-
 /*
- *      mapLog()
+ *     mapLog()
  *
- * function:    log from maplock of freed data extents;
+ * function:   log from maplock of freed data extents;
  */
-void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
-           struct tlock * tlck)
+static void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
+                  struct tlock * tlck)
 {
        struct pxd_lock *pxdlock;
        int i, nlock;
        pxd_t *pxd;
 
        /*
-        *      page relocation: free the source page extent
+        *      page relocation: free the source page extent
         *
         * a maplock for txUpdateMap() for free of the page
         * has been formatted at txLock() time saving the src
@@ -2155,12 +2166,11 @@ void mapLog(struct jfs_log * log, struct tblock * tblk, struct lrd * lrd,
        }
 }
 
-
 /*
- *      txEA()
+ *     txEA()
  *
- * function:    acquire maplock for EA/ACL extents or
- *              set COMMIT_INLINE flag;
+ * function:   acquire maplock for EA/ACL extents or
+ *             set COMMIT_INLINE flag;
  */
 void txEA(tid_t tid, struct inode *ip, dxd_t * oldea, dxd_t * newea)
 {
@@ -2208,14 +2218,13 @@ void txEA(tid_t tid, struct inode *ip, dxd_t * oldea, dxd_t * newea)
        }
 }
 
-
 /*
- *      txForce()
+ *     txForce()
  *
  * function: synchronously write pages locked by transaction
- *              after txLog() but before txUpdateMap();
+ *          after txLog() but before txUpdateMap();
  */
-void txForce(struct tblock * tblk)
+static void txForce(struct tblock * tblk)
 {
        struct tlock *tlck;
        lid_t lid, next;
@@ -2253,7 +2262,8 @@ void txForce(struct tblock * tblk)
                                tlck->flag &= ~tlckWRITEPAGE;
 
                                /* do not release page to freelist */
-
+                               force_metapage(mp);
+#if 0
                                /*
                                 * The "right" thing to do here is to
                                 * synchronously write the metadata.
@@ -2265,20 +2275,20 @@ void txForce(struct tblock * tblk)
                                 * we can get by with synchronously writing
                                 * the pages when they are released.
                                 */
-                               assert(atomic_read(&mp->nohomeok));
+                               assert(mp->nohomeok);
                                set_bit(META_dirty, &mp->flag);
                                set_bit(META_sync, &mp->flag);
+#endif
                        }
                }
        }
 }
 
-
 /*
- *      txUpdateMap()
+ *     txUpdateMap()
  *
- * function:    update persistent allocation map (and working map
- *              if appropriate);
+ * function:   update persistent allocation map (and working map
+ *             if appropriate);
  *
  * parameter:
  */
@@ -2300,7 +2310,7 @@ static void txUpdateMap(struct tblock * tblk)
 
 
        /*
-        *      update block allocation map
+        *      update block allocation map
         *
         * update allocation state in pmap (and wmap) and
         * update lsn of the pmap page;
@@ -2327,7 +2337,7 @@ static void txUpdateMap(struct tblock * tblk)
                         */
                        mp = tlck->mp;
                        ASSERT(mp->xflag & COMMIT_PAGE);
-                       hold_metapage(mp, 0);
+                       grab_metapage(mp);
                }
 
                /*
@@ -2363,7 +2373,7 @@ static void txUpdateMap(struct tblock * tblk)
                         */
                        else {  /* (maplock->flag & mlckFREE) */
 
-                               if (S_ISDIR(tlck->ip->i_mode))
+                               if (tlck->flag & tlckDIRECTORY)
                                        txFreeMap(ipimap, maplock,
                                                  tblk, COMMIT_PWMAP);
                                else
@@ -2377,14 +2387,14 @@ static void txUpdateMap(struct tblock * tblk)
                                ASSERT(mp->lid == lid);
                                tlck->mp->lid = 0;
                        }
-                       assert(atomic_read(&mp->nohomeok) == 1);
-                       atomic_dec(&mp->nohomeok);
+                       assert(mp->nohomeok == 1);
+                       metapage_homeok(mp);
                        discard_metapage(mp);
                        tlck->mp = NULL;
                }
        }
        /*
-        *      update inode allocation map
+        *      update inode allocation map
         *
         * update allocation state in pmap and
         * update lsn of the pmap page;
@@ -2393,8 +2403,7 @@ static void txUpdateMap(struct tblock * tblk)
         * unlock mapper/write lock
         */
        if (tblk->xflag & COMMIT_CREATE) {
-               diUpdatePMap(ipimap, tblk->ino, FALSE, tblk);
-               ipimap->i_state |= I_DIRTY;
+               diUpdatePMap(ipimap, tblk->ino, false, tblk);
                /* update persistent block allocation map
                 * for the allocation of inode extent;
                 */
@@ -2404,32 +2413,30 @@ static void txUpdateMap(struct tblock * tblk)
                txAllocPMap(ipimap, (struct maplock *) & pxdlock, tblk);
        } else if (tblk->xflag & COMMIT_DELETE) {
                ip = tblk->u.ip;
-               diUpdatePMap(ipimap, ip->i_ino, TRUE, tblk);
-               ipimap->i_state |= I_DIRTY;
+               diUpdatePMap(ipimap, ip->i_ino, true, tblk);
                iput(ip);
        }
 }
 
-
 /*
- *      txAllocPMap()
+ *     txAllocPMap()
  *
  * function: allocate from persistent map;
  *
  * parameter:
- *      ipbmap  -
- *      malock -
- *              xad list:
- *              pxd:
- *
- *      maptype -
- *              allocate from persistent map;
- *              free from persistent map;
- *              (e.g., tmp file - free from working map at releae
- *               of last reference);
- *              free from persistent and working map;
- *
- *      lsn     - log sequence number;
+ *     ipbmap  -
+ *     malock  -
+ *             xad list:
+ *             pxd:
+ *
+ *     maptype -
+ *             allocate from persistent map;
+ *             free from persistent map;
+ *             (e.g., tmp file - free from working map at releae
+ *              of last reference);
+ *             free from persistent and working map;
+ *
+ *     lsn     - log sequence number;
  */
 static void txAllocPMap(struct inode *ip, struct maplock * maplock,
                        struct tblock * tblk)
@@ -2454,7 +2461,7 @@ static void txAllocPMap(struct inode *ip, struct maplock * maplock,
                        if (xad->flag & (XAD_NEW | XAD_EXTENDED)) {
                                xaddr = addressXAD(xad);
                                xlen = lengthXAD(xad);
-                               dbUpdatePMap(ipbmap, FALSE, xaddr,
+                               dbUpdatePMap(ipbmap, false, xaddr,
                                             (s64) xlen, tblk);
                                xad->flag &= ~(XAD_NEW | XAD_EXTENDED);
                                jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
@@ -2465,7 +2472,7 @@ static void txAllocPMap(struct inode *ip, struct maplock * maplock,
                pxdlock = (struct pxd_lock *) maplock;
                xaddr = addressPXD(&pxdlock->pxd);
                xlen = lengthPXD(&pxdlock->pxd);
-               dbUpdatePMap(ipbmap, FALSE, xaddr, (s64) xlen, tblk);
+               dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen, tblk);
                jfs_info("allocPMap: xaddr:0x%lx xlen:%d", (ulong) xaddr, xlen);
        } else {                /* (maplock->flag & mlckALLOCPXDLIST) */
 
@@ -2474,7 +2481,7 @@ static void txAllocPMap(struct inode *ip, struct maplock * maplock,
                for (n = 0; n < pxdlistlock->count; n++, pxd++) {
                        xaddr = addressPXD(pxd);
                        xlen = lengthPXD(pxd);
-                       dbUpdatePMap(ipbmap, FALSE, xaddr, (s64) xlen,
+                       dbUpdatePMap(ipbmap, false, xaddr, (s64) xlen,
                                     tblk);
                        jfs_info("allocPMap: xaddr:0x%lx xlen:%d",
                                 (ulong) xaddr, xlen);
@@ -2482,11 +2489,10 @@ static void txAllocPMap(struct inode *ip, struct maplock * maplock,
        }
 }
 
-
 /*
- *      txFreeMap()
+ *     txFreeMap()
  *
- * function:    free from persistent and/or working map;
+ * function:   free from persistent and/or working map;
  *
  * todo: optimization
  */
@@ -2517,7 +2523,7 @@ void txFreeMap(struct inode *ip,
                                if (!(xad->flag & XAD_NEW)) {
                                        xaddr = addressXAD(xad);
                                        xlen = lengthXAD(xad);
-                                       dbUpdatePMap(ipbmap, TRUE, xaddr,
+                                       dbUpdatePMap(ipbmap, true, xaddr,
                                                     (s64) xlen, tblk);
                                        jfs_info("freePMap: xaddr:0x%lx "
                                                 "xlen:%d",
@@ -2528,7 +2534,7 @@ void txFreeMap(struct inode *ip,
                        pxdlock = (struct pxd_lock *) maplock;
                        xaddr = addressPXD(&pxdlock->pxd);
                        xlen = lengthPXD(&pxdlock->pxd);
-                       dbUpdatePMap(ipbmap, TRUE, xaddr, (s64) xlen,
+                       dbUpdatePMap(ipbmap, true, xaddr, (s64) xlen,
                                     tblk);
                        jfs_info("freePMap: xaddr:0x%lx xlen:%d",
                                 (ulong) xaddr, xlen);
@@ -2539,7 +2545,7 @@ void txFreeMap(struct inode *ip,
                        for (n = 0; n < pxdlistlock->count; n++, pxd++) {
                                xaddr = addressPXD(pxd);
                                xlen = lengthPXD(pxd);
-                               dbUpdatePMap(ipbmap, TRUE, xaddr,
+                               dbUpdatePMap(ipbmap, true, xaddr,
                                             (s64) xlen, tblk);
                                jfs_info("freePMap: xaddr:0x%lx xlen:%d",
                                         (ulong) xaddr, xlen);
@@ -2584,11 +2590,10 @@ void txFreeMap(struct inode *ip,
        }
 }
 
-
 /*
- *      txFreelock()
+ *     txFreelock()
  *
- * function:    remove tlock from inode anonymous locklist
+ * function:   remove tlock from inode anonymous locklist
  */
 void txFreelock(struct inode *ip)
 {
@@ -2625,9 +2630,8 @@ void txFreelock(struct inode *ip)
        TXN_UNLOCK();
 }
 
-
 /*
- *      txAbort()
+ *     txAbort()
  *
  * function: abort tx before commit;
  *
@@ -2687,7 +2691,7 @@ void txAbort(tid_t tid, int dirty)
 }
 
 /*
- *      txLazyCommit(void)
+ *     txLazyCommit(void)
  *
  *     All transactions except those changing ipimap (COMMIT_FORCE) are
  *     processed by this routine.  This insures that the inode and block
@@ -2736,7 +2740,7 @@ static void txLazyCommit(struct tblock * tblk)
 }
 
 /*
- *      jfs_lazycommit(void)
+ *     jfs_lazycommit(void)
  *
  *     To be run as a kernel daemon.  If lbmIODone is called in an interrupt
  *     context, or where blocking is not wanted, this routine will process
@@ -2749,10 +2753,6 @@ int jfs_lazycommit(void *arg)
        unsigned long flags;
        struct jfs_sb_info *sbi;
 
-       daemonize("jfsCommit");
-
-       complete(&jfsIOwait);
-
        do {
                LAZY_LOCK(flags);
                jfs_commit_thread_waking = 0;   /* OK to wake another thread */
@@ -2799,9 +2799,9 @@ int jfs_lazycommit(void *arg)
                /* In case a wakeup came while all threads were active */
                jfs_commit_thread_waking = 0;
 
-               if (current->flags & PF_FREEZE) {
+               if (freezing(current)) {
                        LAZY_UNLOCK(flags);
-                       refrigerator(PF_FREEZE);
+                       refrigerator();
                } else {
                        DECLARE_WAITQUEUE(wq, current);
 
@@ -2809,16 +2809,16 @@ int jfs_lazycommit(void *arg)
                        set_current_state(TASK_INTERRUPTIBLE);
                        LAZY_UNLOCK(flags);
                        schedule();
-                       current->state = TASK_RUNNING;
+                       __set_current_state(TASK_RUNNING);
                        remove_wait_queue(&jfs_commit_thread_wait, &wq);
                }
-       } while (!jfs_stop_threads);
+       } while (!kthread_should_stop());
 
        if (!list_empty(&TxAnchor.unlock_queue))
                jfs_err("jfs_lazycommit being killed w/pending transactions!");
        else
                jfs_info("jfs_lazycommit being killed\n");
-       complete_and_exit(&jfsIOwait, 0);
+       return 0;
 }
 
 void txLazyUnlock(struct tblock * tblk)
@@ -2844,24 +2844,9 @@ static void LogSyncRelease(struct metapage * mp)
 {
        struct jfs_log *log = mp->log;
 
-       assert(atomic_read(&mp->nohomeok));
+       assert(mp->nohomeok);
        assert(log);
-       atomic_dec(&mp->nohomeok);
-
-       if (atomic_read(&mp->nohomeok))
-               return;
-
-       hold_metapage(mp, 0);
-
-       LOGSYNC_LOCK(log);
-       mp->log = NULL;
-       mp->lsn = 0;
-       mp->clsn = 0;
-       log->count--;
-       list_del_init(&mp->synclist);
-       LOGSYNC_UNLOCK(log);
-
-       release_metapage(mp);
+       metapage_homeok(mp);
 }
 
 /*
@@ -2897,10 +2882,10 @@ restart:
                 */
                TXN_UNLOCK();
                tid = txBegin(ip->i_sb, COMMIT_INODE | COMMIT_FORCE);
-               down(&jfs_ip->commit_sem);
+               mutex_lock(&jfs_ip->commit_mutex);
                txCommit(tid, 1, &ip, 0);
                txEnd(tid);
-               up(&jfs_ip->commit_sem);
+               mutex_unlock(&jfs_ip->commit_mutex);
                /*
                 * Just to be safe.  I don't know how
                 * long we can run without blocking
@@ -2940,7 +2925,7 @@ void txResume(struct super_block *sb)
 }
 
 /*
- *      jfs_sync(void)
+ *     jfs_sync(void)
  *
  *     To be run as a kernel daemon.  This is awakened when tlocks run low.
  *     We write any inodes that have anonymous tlocks so they will become
@@ -2953,10 +2938,6 @@ int jfs_sync(void *arg)
        int rc;
        tid_t tid;
 
-       daemonize("jfsSync");
-
-       complete(&jfsIOwait);
-
        do {
                /*
                 * write each inode on the anonymous inode list
@@ -2973,7 +2954,7 @@ int jfs_sync(void *arg)
                                 * Inode is being freed
                                 */
                                list_del_init(&jfs_ip->anon_inode_list);
-                       } else if (! down_trylock(&jfs_ip->commit_sem)) {
+                       } else if (mutex_trylock(&jfs_ip->commit_mutex)) {
                                /*
                                 * inode will be removed from anonymous list
                                 * when it is committed
@@ -2982,7 +2963,7 @@ int jfs_sync(void *arg)
                                tid = txBegin(ip->i_sb, COMMIT_INODE);
                                rc = txCommit(tid, 1, &ip, 0);
                                txEnd(tid);
-                               up(&jfs_ip->commit_sem);
+                               mutex_unlock(&jfs_ip->commit_mutex);
 
                                iput(ip);
                                /*
@@ -2992,7 +2973,7 @@ int jfs_sync(void *arg)
                                cond_resched();
                                TXN_LOCK();
                        } else {
-                               /* We can't get the commit semaphore.  It may
+                               /* We can't get the commit mutex.  It may
                                 * be held by a thread waiting for tlock's
                                 * so let's not block here.  Save it to
                                 * put back on the anon_list.
@@ -3013,31 +2994,24 @@ int jfs_sync(void *arg)
                /* Add anon_list2 back to anon_list */
                list_splice_init(&TxAnchor.anon_list2, &TxAnchor.anon_list);
 
-               if (current->flags & PF_FREEZE) {
+               if (freezing(current)) {
                        TXN_UNLOCK();
-                       refrigerator(PF_FREEZE);
+                       refrigerator();
                } else {
-                       DECLARE_WAITQUEUE(wq, current);
-
-                       add_wait_queue(&jfs_sync_thread_wait, &wq);
                        set_current_state(TASK_INTERRUPTIBLE);
                        TXN_UNLOCK();
                        schedule();
-                       current->state = TASK_RUNNING;
-                       remove_wait_queue(&jfs_sync_thread_wait, &wq);
+                       __set_current_state(TASK_RUNNING);
                }
-       } while (!jfs_stop_threads);
+       } while (!kthread_should_stop());
 
        jfs_info("jfs_sync being killed");
-       complete_and_exit(&jfsIOwait, 0);
+       return 0;
 }
 
 #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_DEBUG)
-int jfs_txanchor_read(char *buffer, char **start, off_t offset, int length,
-                     int *eof, void *data)
+static int jfs_txanchor_proc_show(struct seq_file *m, void *v)
 {
-       int len = 0;
-       off_t begin;
        char *freewait;
        char *freelockwait;
        char *lowlockwait;
@@ -3049,7 +3023,7 @@ int jfs_txanchor_read(char *buffer, char **start, off_t offset, int length,
        lowlockwait =
            waitqueue_active(&TxAnchor.lowlockwait) ? "active" : "empty";
 
-       len += sprintf(buffer,
+       seq_printf(m,
                       "JFS TxAnchor\n"
                       "============\n"
                       "freetid = %d\n"
@@ -3068,31 +3042,27 @@ int jfs_txanchor_read(char *buffer, char **start, off_t offset, int length,
                       TxAnchor.tlocksInUse,
                       jfs_tlocks_low,
                       list_empty(&TxAnchor.unlock_queue) ? "" : "not ");
+       return 0;
+}
 
-       begin = offset;
-       *start = buffer + begin;
-       len -= begin;
-
-       if (len > length)
-               len = length;
-       else
-               *eof = 1;
-
-       if (len < 0)
-               len = 0;
-
-       return len;
+static int jfs_txanchor_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, jfs_txanchor_proc_show, NULL);
 }
+
+const struct file_operations jfs_txanchor_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = jfs_txanchor_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 #endif
 
 #if defined(CONFIG_PROC_FS) && defined(CONFIG_JFS_STATISTICS)
-int jfs_txstats_read(char *buffer, char **start, off_t offset, int length,
-                    int *eof, void *data)
+static int jfs_txstats_proc_show(struct seq_file *m, void *v)
 {
-       int len = 0;
-       off_t begin;
-
-       len += sprintf(buffer,
+       seq_printf(m,
                       "JFS TxStats\n"
                       "===========\n"
                       "calls to txBegin = %d\n"
@@ -3113,19 +3083,19 @@ int jfs_txstats_read(char *buffer, char **start, off_t offset, int length,
                       TxStat.txBeginAnon_lockslow,
                       TxStat.txLockAlloc,
                       TxStat.txLockAlloc_freelock);
+       return 0;
+}
 
-       begin = offset;
-       *start = buffer + begin;
-       len -= begin;
-
-       if (len > length)
-               len = length;
-       else
-               *eof = 1;
-
-       if (len < 0)
-               len = 0;
-
-       return len;
+static int jfs_txstats_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, jfs_txstats_proc_show, NULL);
 }
+
+const struct file_operations jfs_txstats_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = jfs_txstats_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 #endif