]> err.no Git - linux-2.6/blobdiff - fs/gfs2/log.c
Merge branch 'we21-fix' of git://git.kernel.org/pub/scm/linux/kernel/git/linville...
[linux-2.6] / fs / gfs2 / log.c
index 08b80b263ade9050751b31d63bc2a8bbb1f75b3d..0cace3da9dbb41795b6cacdbe97de52786d3678e 100644 (file)
@@ -58,12 +58,97 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
        return blks;
 }
 
+/**
+ * gfs2_ail1_start_one - Start I/O on a part of the AIL
+ * @sdp: the filesystem
+ * @tr: the part of the AIL
+ *
+ */
+
+static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
+{
+       struct gfs2_bufdata *bd, *s;
+       struct buffer_head *bh;
+       int retry;
+
+       BUG_ON(!spin_is_locked(&sdp->sd_log_lock));
+
+       do {
+               retry = 0;
+
+               list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
+                                                bd_ail_st_list) {
+                       bh = bd->bd_bh;
+
+                       gfs2_assert(sdp, bd->bd_ail == ai);
+
+                       if (!buffer_busy(bh)) {
+                               if (!buffer_uptodate(bh)) {
+                                       gfs2_log_unlock(sdp);
+                                       gfs2_io_error_bh(sdp, bh);
+                                       gfs2_log_lock(sdp);
+                               }
+                               list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
+                               continue;
+                       }
+
+                       if (!buffer_dirty(bh))
+                               continue;
+
+                       list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
+
+                       gfs2_log_unlock(sdp);
+                       wait_on_buffer(bh);
+                       ll_rw_block(WRITE, 1, &bh);
+                       gfs2_log_lock(sdp);
+
+                       retry = 1;
+                       break;
+               }
+       } while (retry);
+}
+
+/**
+ * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced
+ * @sdp: the filesystem
+ * @ai: the AIL entry
+ *
+ */
+
+static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai, int flags)
+{
+       struct gfs2_bufdata *bd, *s;
+       struct buffer_head *bh;
+
+       list_for_each_entry_safe_reverse(bd, s, &ai->ai_ail1_list,
+                                        bd_ail_st_list) {
+               bh = bd->bd_bh;
+
+               gfs2_assert(sdp, bd->bd_ail == ai);
+
+               if (buffer_busy(bh)) {
+                       if (flags & DIO_ALL)
+                               continue;
+                       else
+                               break;
+               }
+
+               if (!buffer_uptodate(bh))
+                       gfs2_io_error_bh(sdp, bh);
+
+               list_move(&bd->bd_ail_st_list, &ai->ai_ail2_list);
+       }
+
+       return list_empty(&ai->ai_ail1_list);
+}
+
 void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
 {
        struct list_head *head = &sdp->sd_ail1_list;
        u64 sync_gen;
-       struct list_head *first, *tmp;
-       struct gfs2_ail *first_ai, *ai;
+       struct list_head *first;
+       struct gfs2_ail *first_ai, *ai, *tmp;
+       int done = 0;
 
        gfs2_log_lock(sdp);
        if (list_empty(head)) {
@@ -75,27 +160,25 @@ void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
        first = head->prev;
        first_ai = list_entry(first, struct gfs2_ail, ai_list);
        first_ai->ai_sync_gen = sync_gen;
-       gfs2_ail1_start_one(sdp, first_ai);
+       gfs2_ail1_start_one(sdp, first_ai); /* This may drop log lock */
 
        if (flags & DIO_ALL)
                first = NULL;
 
-       for (;;) {
+       while(!done) {
                if (first && (head->prev != first ||
                              gfs2_ail1_empty_one(sdp, first_ai, 0)))
                        break;
 
-               for (tmp = head->prev; tmp != head; tmp = tmp->prev) {
-                       ai = list_entry(tmp, struct gfs2_ail, ai_list);
+               done = 1;
+               list_for_each_entry_safe_reverse(ai, tmp, head, ai_list) {
                        if (ai->ai_sync_gen >= sync_gen)
                                continue;
                        ai->ai_sync_gen = sync_gen;
-                       gfs2_ail1_start_one(sdp, ai);
+                       gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */
+                       done = 0;
                        break;
                }
-
-               if (tmp == head)
-                       break;
        }
 
        gfs2_log_unlock(sdp);
@@ -122,6 +205,31 @@ int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
        return ret;
 }
 
+
+/**
+ * gfs2_ail2_empty_one - Check whether or not a trans in the AIL has been synced
+ * @sdp: the filesystem
+ * @ai: the AIL entry
+ *
+ */
+
+static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
+{
+       struct list_head *head = &ai->ai_ail2_list;
+       struct gfs2_bufdata *bd;
+
+       while (!list_empty(head)) {
+               bd = list_entry(head->prev, struct gfs2_bufdata,
+                               bd_ail_st_list);
+               gfs2_assert(sdp, bd->bd_ail == ai);
+               bd->bd_ail = NULL;
+               list_del(&bd->bd_ail_st_list);
+               list_del(&bd->bd_ail_gl_list);
+               atomic_dec(&bd->bd_gl->gl_ail_count);
+               brelse(bd->bd_bh);
+       }
+}
+
 static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
 {
        struct gfs2_ail *ai, *safe;
@@ -204,10 +312,12 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
 
 static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
 {
+       struct inode *inode = sdp->sd_jdesc->jd_inode;
        int error;
-       struct buffer_head bh_map;
+       struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 };
 
-       error = gfs2_block_map(sdp->sd_jdesc->jd_inode, lbn, 0, &bh_map, 1);
+       bh_map.b_size = 1 << inode->i_blkbits;
+       error = gfs2_block_map(inode, lbn, 0, &bh_map);
        if (error || !bh_map.b_blocknr)
                printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, bh_map.b_blocknr, lbn);
        gfs2_assert_withdraw(sdp, !error && bh_map.b_blocknr);
@@ -461,16 +571,15 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
        else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle)
                log_write_header(sdp, 0, PULL);
        lops_after_commit(sdp, ai);
-       sdp->sd_log_head = sdp->sd_log_flush_head;
 
+       gfs2_log_lock(sdp);
+       sdp->sd_log_head = sdp->sd_log_flush_head;
        sdp->sd_log_blks_free -= sdp->sd_log_num_hdrs;
-
        sdp->sd_log_blks_reserved = 0;
        sdp->sd_log_commited_buf = 0;
        sdp->sd_log_num_hdrs = 0;
        sdp->sd_log_commited_revoke = 0;
 
-       gfs2_log_lock(sdp);
        if (!list_empty(&ai->ai_ail1_list)) {
                list_add(&ai->ai_list, &sdp->sd_ail1_list);
                ai = NULL;