Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / fs / gfs2 / recovery.c
index 6fb07d6..09fa319 100644 (file)
@@ -7,20 +7,20 @@
  * of the GNU General Public License version 2.
  */
 
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
 #include <linux/gfs2_ondisk.h>
 #include <linux/crc32.h>
-#include <linux/lm_interface.h>
+#include <linux/slow-work.h>
 
 #include "gfs2.h"
 #include "incore.h"
 #include "bmap.h"
 #include "glock.h"
 #include "glops.h"
-#include "lm.h"
 #include "lops.h"
 #include "meta_io.h"
 #include "recovery.h"
@@ -69,7 +69,7 @@ int gfs2_revoke_add(struct gfs2_sbd *sdp, u64 blkno, unsigned int where)
                return 0;
        }
 
-       rr = kmalloc(sizeof(struct gfs2_revoke_replay), GFP_KERNEL);
+       rr = kmalloc(sizeof(struct gfs2_revoke_replay), GFP_NOFS);
        if (!rr)
                return -ENOMEM;
 
@@ -150,7 +150,7 @@ static int get_log_header(struct gfs2_jdesc *jd, unsigned int blk,
                          struct gfs2_log_header_host *head)
 {
        struct buffer_head *bh;
-       struct gfs2_log_header_host lh;
+       struct gfs2_log_header_host uninitialized_var(lh);
        const u32 nothing = 0;
        u32 hash;
        int error;
@@ -425,18 +425,41 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header_host *hea
        return error;
 }
 
-/**
- * gfs2_recover_journal - recovery a given journal
- * @jd: the struct gfs2_jdesc describing the journal
- *
- * Acquire the journal's lock, check to see if the journal is clean, and
- * do recovery if necessary.
- *
- * Returns: errno
- */
 
-int gfs2_recover_journal(struct gfs2_jdesc *jd)
+static void gfs2_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
+                               unsigned int message)
+{
+       char env_jid[20];
+       char env_status[20];
+       char *envp[] = { env_jid, env_status, NULL };
+       struct lm_lockstruct *ls = &sdp->sd_lockstruct;
+        ls->ls_recover_jid_done = jid;
+        ls->ls_recover_jid_status = message;
+       sprintf(env_jid, "JID=%d", jid);
+       sprintf(env_status, "RECOVERY=%s",
+               message == LM_RD_SUCCESS ? "Done" : "Failed");
+        kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
+}
+
+static int gfs2_recover_get_ref(struct slow_work *work)
+{
+       struct gfs2_jdesc *jd = container_of(work, struct gfs2_jdesc, jd_work);
+       if (test_and_set_bit(JDF_RECOVERY, &jd->jd_flags))
+               return -EBUSY;
+       return 0;
+}
+
+static void gfs2_recover_put_ref(struct slow_work *work)
+{
+       struct gfs2_jdesc *jd = container_of(work, struct gfs2_jdesc, jd_work);
+       clear_bit(JDF_RECOVERY, &jd->jd_flags);
+       smp_mb__after_clear_bit();
+       wake_up_bit(&jd->jd_flags, JDF_RECOVERY);
+}
+
+static void gfs2_recover_work(struct slow_work *work)
 {
+       struct gfs2_jdesc *jd = container_of(work, struct gfs2_jdesc, jd_work);
        struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
        struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
        struct gfs2_log_header_host head;
@@ -496,7 +519,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
 
                error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED,
                                           LM_FLAG_NOEXP | LM_FLAG_PRIORITY |
-                                          GL_NOCANCEL | GL_NOCACHE, &t_gh);
+                                          GL_NOCACHE, &t_gh);
                if (error)
                        goto fail_gunlock_ji;
 
@@ -547,13 +570,13 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
        if (jd->jd_jid != sdp->sd_lockstruct.ls_jid)
                gfs2_glock_dq_uninit(&ji_gh);
 
-       gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS);
+       gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS);
 
        if (jd->jd_jid != sdp->sd_lockstruct.ls_jid)
                gfs2_glock_dq_uninit(&j_gh);
 
        fs_info(sdp, "jid=%u: Done\n", jd->jd_jid);
-       return 0;
+       return;
 
 fail_gunlock_tr:
        gfs2_glock_dq_uninit(&t_gh);
@@ -567,27 +590,30 @@ fail_gunlock_j:
        fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done");
 
 fail:
-       gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP);
-       return error;
+       gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP);
 }
 
-/**
- * gfs2_check_journals - Recover any dirty journals
- * @sdp: the filesystem
- *
- */
+struct slow_work_ops gfs2_recover_ops = {
+       .owner   = THIS_MODULE,
+       .get_ref = gfs2_recover_get_ref,
+       .put_ref = gfs2_recover_put_ref,
+       .execute = gfs2_recover_work,
+};
 
-void gfs2_check_journals(struct gfs2_sbd *sdp)
-{
-       struct gfs2_jdesc *jd;
 
-       for (;;) {
-               jd = gfs2_jdesc_find_dirty(sdp);
-               if (!jd)
-                       break;
+static int gfs2_recovery_wait(void *word)
+{
+       schedule();
+       return 0;
+}
 
-               if (jd != sdp->sd_jdesc)
-                       gfs2_recover_journal(jd);
-       }
+int gfs2_recover_journal(struct gfs2_jdesc *jd)
+{
+       int rv;
+       rv = slow_work_enqueue(&jd->jd_work);
+       if (rv)
+               return rv;
+       wait_on_bit(&jd->jd_flags, JDF_RECOVERY, gfs2_recovery_wait, TASK_UNINTERRUPTIBLE);
+       return 0;
 }