Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / fs / jfs / jfs_logmgr.c
index dfa1200..3315f0b 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/smp_lock.h>
 #include <linux/completion.h>
+#include <linux/kthread.h>
 #include <linux/buffer_head.h>         /* for sync_blockdev() */
 #include <linux/bio.h>
 #include <linux/suspend.h>
 #include <linux/delay.h>
+#include <linux/mutex.h>
 #include "jfs_incore.h"
 #include "jfs_filsys.h"
 #include "jfs_metapage.h"
+#include "jfs_superblock.h"
 #include "jfs_txnmgr.h"
 #include "jfs_debug.h"
 
  */
 static struct lbuf *log_redrive_list;
 static DEFINE_SPINLOCK(log_redrive_lock);
-DECLARE_WAIT_QUEUE_HEAD(jfs_IO_thread_wait);
 
 
 /*
  *     log read/write serialization (per log)
  */
-#define LOG_LOCK_INIT(log)     init_MUTEX(&(log)->loglock)
-#define LOG_LOCK(log)          down(&((log)->loglock))
-#define LOG_UNLOCK(log)                up(&((log)->loglock))
+#define LOG_LOCK_INIT(log)     mutex_init(&(log)->loglock)
+#define LOG_LOCK(log)          mutex_lock(&((log)->loglock))
+#define LOG_UNLOCK(log)                mutex_unlock(&((log)->loglock))
 
 
 /*
@@ -164,15 +166,7 @@ do {                                               \
  */
 static LIST_HEAD(jfs_external_logs);
 static struct jfs_log *dummy_log = NULL;
-static DECLARE_MUTEX(jfs_log_sem);
-
-/*
- * external references
- */
-extern void txLazyUnlock(struct tblock * tblk);
-extern int jfs_stop_threads;
-extern struct completion jfsIOwait;
-extern int jfs_tlocks_low;
+static DEFINE_MUTEX(jfs_log_mutex);
 
 /*
  * forward references
@@ -198,7 +192,7 @@ static int lbmIOWait(struct lbuf * bp, int flag);
 static bio_end_io_t lbmIODone;
 static void lbmStartIO(struct lbuf * bp);
 static void lmGCwrite(struct jfs_log * log, int cant_block);
-static int lmLogSync(struct jfs_log * log, int nosyncwait);
+static int lmLogSync(struct jfs_log * log, int hard_sync);
 
 
 
@@ -922,19 +916,17 @@ static void lmPostGC(struct lbuf * bp)
  *     if new sync address is available
  *     (normally the case if sync() is executed by back-ground
  *     process).
- *     if not, explicitly run jfs_blogsync() to initiate
- *     getting of new sync address.
  *     calculate new value of i_nextsync which determines when
  *     this code is called again.
  *
  * PARAMETERS: log     - log structure
- *             nosyncwait - 1 if called asynchronously
+ *             hard_sync - 1 to force all metadata to be written
  *
  * RETURN:     0
  *                     
  * serialization: LOG_LOCK() held on entry/exit
  */
-static int lmLogSync(struct jfs_log * log, int nosyncwait)
+static int lmLogSync(struct jfs_log * log, int hard_sync)
 {
        int logsize;
        int written;            /* written since last syncpt */
@@ -948,11 +940,18 @@ static int lmLogSync(struct jfs_log * log, int nosyncwait)
        unsigned long flags;
 
        /* push dirty metapages out to disk */
-       list_for_each_entry(sbi, &log->sb_list, log_list) {
-               filemap_flush(sbi->ipbmap->i_mapping);
-               filemap_flush(sbi->ipimap->i_mapping);
-               filemap_flush(sbi->direct_inode->i_mapping);
-       }
+       if (hard_sync)
+               list_for_each_entry(sbi, &log->sb_list, log_list) {
+                       filemap_fdatawrite(sbi->ipbmap->i_mapping);
+                       filemap_fdatawrite(sbi->ipimap->i_mapping);
+                       filemap_fdatawrite(sbi->direct_inode->i_mapping);
+               }
+       else
+               list_for_each_entry(sbi, &log->sb_list, log_list) {
+                       filemap_flush(sbi->ipbmap->i_mapping);
+                       filemap_flush(sbi->ipimap->i_mapping);
+                       filemap_flush(sbi->direct_inode->i_mapping);
+               }
 
        /*
         *      forward syncpt
@@ -1028,16 +1027,13 @@ static int lmLogSync(struct jfs_log * log, int nosyncwait)
                /* next syncpt trigger = written + more */
                log->nextsync = written + more;
 
-       /* return if lmLogSync() from outside of transaction, e.g., sync() */
-       if (nosyncwait)
-               return lsn;
-
        /* if number of bytes written from last sync point is more
         * than 1/4 of the log size, stop new transactions from
         * starting until all current transactions are completed
         * by setting syncbarrier flag.
         */
-       if (written > LOGSYNC_BARRIER(logsize) && logsize > 32 * LOGPSIZE) {
+       if (!test_bit(log_SYNCBARRIER, &log->flag) &&
+           (written > LOGSYNC_BARRIER(logsize)) && log->active) {
                set_bit(log_SYNCBARRIER, &log->flag);
                jfs_info("log barrier on: lsn=0x%x syncpt=0x%x", lsn,
                         log->syncpt);
@@ -1055,11 +1051,12 @@ static int lmLogSync(struct jfs_log * log, int nosyncwait)
  *
  * FUNCTION:   write log SYNCPT record for specified log
  *
- * PARAMETERS: log     - log structure
+ * PARAMETERS: log       - log structure
+ *             hard_sync - set to 1 to force metadata to be written
  */
-void jfs_syncpt(struct jfs_log *log)
+void jfs_syncpt(struct jfs_log *log, int hard_sync)
 {      LOG_LOCK(log);
-       lmLogSync(log, 1);
+       lmLogSync(log, hard_sync);
        LOG_UNLOCK(log);
 }
 
@@ -1089,31 +1086,30 @@ int lmLogOpen(struct super_block *sb)
        if (sbi->mntflag & JFS_INLINELOG)
                return open_inline_log(sb);
 
-       down(&jfs_log_sem);
+       mutex_lock(&jfs_log_mutex);
        list_for_each_entry(log, &jfs_external_logs, journal_list) {
                if (log->bdev->bd_dev == sbi->logdev) {
                        if (memcmp(log->uuid, sbi->loguuid,
                                   sizeof(log->uuid))) {
                                jfs_warn("wrong uuid on JFS journal\n");
-                               up(&jfs_log_sem);
+                               mutex_unlock(&jfs_log_mutex);
                                return -EINVAL;
                        }
                        /*
                         * add file system to log active file system list
                         */
                        if ((rc = lmLogFileSystem(log, sbi, 1))) {
-                               up(&jfs_log_sem);
+                               mutex_unlock(&jfs_log_mutex);
                                return rc;
                        }
                        goto journal_found;
                }
        }
 
-       if (!(log = kmalloc(sizeof(struct jfs_log), GFP_KERNEL))) {
-               up(&jfs_log_sem);
+       if (!(log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL))) {
+               mutex_unlock(&jfs_log_mutex);
                return -ENOMEM;
        }
-       memset(log, 0, sizeof(struct jfs_log));
        INIT_LIST_HEAD(&log->sb_list);
        init_waitqueue_head(&log->syncwait);
 
@@ -1156,7 +1152,7 @@ journal_found:
        sbi->log = log;
        LOG_UNLOCK(log);
 
-       up(&jfs_log_sem);
+       mutex_unlock(&jfs_log_mutex);
        return 0;
 
        /*
@@ -1173,7 +1169,7 @@ journal_found:
        blkdev_put(bdev);
 
       free:            /* free log descriptor */
-       up(&jfs_log_sem);
+       mutex_unlock(&jfs_log_mutex);
        kfree(log);
 
        jfs_warn("lmLogOpen: exit(%d)", rc);
@@ -1185,9 +1181,8 @@ static int open_inline_log(struct super_block *sb)
        struct jfs_log *log;
        int rc;
 
-       if (!(log = kmalloc(sizeof(struct jfs_log), GFP_KERNEL)))
+       if (!(log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL)))
                return -ENOMEM;
-       memset(log, 0, sizeof(struct jfs_log));
        INIT_LIST_HEAD(&log->sb_list);
        init_waitqueue_head(&log->syncwait);
 
@@ -1218,14 +1213,13 @@ static int open_dummy_log(struct super_block *sb)
 {
        int rc;
 
-       down(&jfs_log_sem);
+       mutex_lock(&jfs_log_mutex);
        if (!dummy_log) {
-               dummy_log = kmalloc(sizeof(struct jfs_log), GFP_KERNEL);
+               dummy_log = kzalloc(sizeof(struct jfs_log), GFP_KERNEL);
                if (!dummy_log) {
-                       up(&jfs_log_sem);
+                       mutex_unlock(&jfs_log_mutex);
                        return -ENOMEM;
                }
-               memset(dummy_log, 0, sizeof(struct jfs_log));
                INIT_LIST_HEAD(&dummy_log->sb_list);
                init_waitqueue_head(&dummy_log->syncwait);
                dummy_log->no_integrity = 1;
@@ -1236,7 +1230,7 @@ static int open_dummy_log(struct super_block *sb)
                if (rc) {
                        kfree(dummy_log);
                        dummy_log = NULL;
-                       up(&jfs_log_sem);
+                       mutex_unlock(&jfs_log_mutex);
                        return rc;
                }
        }
@@ -1245,7 +1239,7 @@ static int open_dummy_log(struct super_block *sb)
        list_add(&JFS_SBI(sb)->log_list, &dummy_log->sb_list);
        JFS_SBI(sb)->log = dummy_log;
        LOG_UNLOCK(dummy_log);
-       up(&jfs_log_sem);
+       mutex_unlock(&jfs_log_mutex);
 
        return 0;
 }
@@ -1473,7 +1467,7 @@ int lmLogClose(struct super_block *sb)
 
        jfs_info("lmLogClose: log:0x%p", log);
 
-       down(&jfs_log_sem);
+       mutex_lock(&jfs_log_mutex);
        LOG_LOCK(log);
        list_del(&sbi->log_list);
        LOG_UNLOCK(log);
@@ -1523,7 +1517,7 @@ int lmLogClose(struct super_block *sb)
        kfree(log);
 
       out:
-       up(&jfs_log_sem);
+       mutex_unlock(&jfs_log_mutex);
        jfs_info("lmLogClose: exit(%d)", rc);
        return rc;
 }
@@ -1624,6 +1618,8 @@ void jfs_flush_journal(struct jfs_log *log, int wait)
                }
        }
        assert(list_empty(&log->cqueue));
+
+#ifdef CONFIG_JFS_DEBUG
        if (!list_empty(&log->synclist)) {
                struct logsyncblk *lp;
 
@@ -1638,9 +1634,8 @@ void jfs_flush_journal(struct jfs_log *log, int wait)
                                dump_mem("orphan tblock", lp,
                                         sizeof(struct tblock));
                }
-//             current->state = TASK_INTERRUPTIBLE;
-//             schedule();
        }
+#endif
        //assert(list_empty(&log->synclist));
        clear_bit(log_FLUSH, &log->flag);
 }
@@ -1983,7 +1978,7 @@ static inline void lbmRedrive(struct lbuf *bp)
        log_redrive_list = bp;
        spin_unlock_irqrestore(&log_redrive_lock, flags);
 
-       wake_up(&jfs_IO_thread_wait);
+       wake_up_process(jfsIOthread);
 }
 
 
@@ -2350,13 +2345,7 @@ int jfsIOWait(void *arg)
 {
        struct lbuf *bp;
 
-       daemonize("jfsIO");
-
-       complete(&jfsIOwait);
-
        do {
-               DECLARE_WAITQUEUE(wq, current);
-
                spin_lock_irq(&log_redrive_lock);
                while ((bp = log_redrive_list) != 0) {
                        log_redrive_list = bp->l_redrive_next;
@@ -2365,21 +2354,19 @@ int jfsIOWait(void *arg)
                        lbmStartIO(bp);
                        spin_lock_irq(&log_redrive_lock);
                }
-               if (current->flags & PF_FREEZE) {
-                       spin_unlock_irq(&log_redrive_lock);
-                       refrigerator(PF_FREEZE);
+               spin_unlock_irq(&log_redrive_lock);
+
+               if (freezing(current)) {
+                       refrigerator();
                } else {
-                       add_wait_queue(&jfs_IO_thread_wait, &wq);
                        set_current_state(TASK_INTERRUPTIBLE);
-                       spin_unlock_irq(&log_redrive_lock);
                        schedule();
                        current->state = TASK_RUNNING;
-                       remove_wait_queue(&jfs_IO_thread_wait, &wq);
                }
-       } while (!jfs_stop_threads);
+       } while (!kthread_should_stop());
 
        jfs_info("jfsIOWait being killed!");
-       complete_and_exit(&jfsIOwait, 0);
+       return 0;
 }
 
 /*