]> err.no Git - linux-2.6/blobdiff - fs/gfs2/glops.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[linux-2.6] / fs / gfs2 / glops.c
index 75d4c50cff45cf62dc5e55adf0ca87db549eb193..41a6b6818a505e1087ba5040d50c7018af6c64b2 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License v.2.
+ * of the GNU General Public License version 2.
  */
 
 #include <linux/sched.h>
@@ -13,9 +13,9 @@
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
 #include <linux/gfs2_ondisk.h>
+#include <linux/lm_interface.h>
 
 #include "gfs2.h"
-#include "lm_interface.h"
 #include "incore.h"
 #include "bmap.h"
 #include "glock.h"
 #include "recovery.h"
 #include "rgrp.h"
 #include "util.h"
+#include "trans.h"
 
+/**
+ * ail_empty_gl - remove all buffers for a given lock from the AIL
+ * @gl: the glock
+ *
+ * None of the buffers should be dirty, locked, or pinned.
+ */
+
+static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
+{
+       struct gfs2_sbd *sdp = gl->gl_sbd;
+       unsigned int blocks;
+       struct list_head *head = &gl->gl_ail_list;
+       struct gfs2_bufdata *bd;
+       struct buffer_head *bh;
+       u64 blkno;
+       int error;
+
+       blocks = atomic_read(&gl->gl_ail_count);
+       if (!blocks)
+               return;
+
+       error = gfs2_trans_begin(sdp, 0, blocks);
+       if (gfs2_assert_withdraw(sdp, !error))
+               return;
+
+       gfs2_log_lock(sdp);
+       while (!list_empty(head)) {
+               bd = list_entry(head->next, struct gfs2_bufdata,
+                               bd_ail_gl_list);
+               bh = bd->bd_bh;
+               blkno = bh->b_blocknr;
+               gfs2_assert_withdraw(sdp, !buffer_busy(bh));
+
+               bd->bd_ail = NULL;
+               list_del(&bd->bd_ail_st_list);
+               list_del(&bd->bd_ail_gl_list);
+               atomic_dec(&gl->gl_ail_count);
+               brelse(bh);
+               gfs2_log_unlock(sdp);
+
+               gfs2_trans_add_revoke(sdp, blkno);
+
+               gfs2_log_lock(sdp);
+       }
+       gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
+       gfs2_log_unlock(sdp);
+
+       gfs2_trans_end(sdp);
+       gfs2_log_flush(sdp, NULL);
+}
 
 /**
  * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock
@@ -77,32 +128,24 @@ static void gfs2_page_inval(struct gfs2_glock *gl)
 }
 
 /**
- * gfs2_page_sync - Sync the data pages (not metadata) associated with a glock
+ * gfs2_page_wait - Wait for writeback of data
  * @gl: the glock
- * @flags: DIO_START | DIO_WAIT
  *
  * Syncs data (not metadata) for a regular file.
  * No-op for all other types.
  */
 
-static void gfs2_page_sync(struct gfs2_glock *gl, int flags)
+static void gfs2_page_wait(struct gfs2_glock *gl)
 {
-       struct gfs2_inode *ip;
-       struct inode *inode;
-       struct address_space *mapping;
-       int error = 0;
+       struct gfs2_inode *ip = gl->gl_object;
+       struct inode *inode = &ip->i_inode;
+       struct address_space *mapping = inode->i_mapping;
+       int error;
 
-       ip = gl->gl_object;
-       inode = &ip->i_inode;
-       if (!ip || !S_ISREG(ip->i_di.di_mode))
+       if (!S_ISREG(ip->i_di.di_mode))
                return;
 
-       mapping = inode->i_mapping;
-
-       if (flags & DIO_START)
-               filemap_fdatawrite(mapping);
-       if (!error && (flags & DIO_WAIT))
-               error = filemap_fdatawait(mapping);
+       error = filemap_fdatawait(mapping);
 
        /* Put back any errors cleared by filemap_fdatawait()
           so they can be caught by someone who can pass them
@@ -115,6 +158,18 @@ static void gfs2_page_sync(struct gfs2_glock *gl, int flags)
 
 }
 
+static void gfs2_page_writeback(struct gfs2_glock *gl)
+{
+       struct gfs2_inode *ip = gl->gl_object;
+       struct inode *inode = &ip->i_inode;
+       struct address_space *mapping = inode->i_mapping;
+
+       if (!S_ISREG(ip->i_di.di_mode))
+               return;
+
+       filemap_fdatawrite(mapping);
+}
+
 /**
  * meta_go_sync - sync out the metadata for this glock
  * @gl: the glock
@@ -132,12 +187,11 @@ static void meta_go_sync(struct gfs2_glock *gl, int flags)
 
        if (test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) {
                gfs2_log_flush(gl->gl_sbd, gl);
-               gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT);
+               gfs2_meta_sync(gl);
                if (flags & DIO_RELEASE)
                        gfs2_ail_empty_gl(gl);
        }
 
-       clear_bit(GLF_SYNC, &gl->gl_flags);
 }
 
 /**
@@ -186,8 +240,7 @@ static void inode_go_xmote_bh(struct gfs2_glock *gl)
 
        if (gl->gl_state != LM_ST_UNLOCKED &&
            (!gh || !(gh->gh_flags & GL_SKIP))) {
-               error = gfs2_meta_read(gl, gl->gl_name.ln_number, DIO_START,
-                                      &bh);
+               error = gfs2_meta_read(gl, gl->gl_name.ln_number, 0, &bh);
                if (!error)
                        brelse(bh);
        }
@@ -222,21 +275,21 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags)
 
        if (test_bit(GLF_DIRTY, &gl->gl_flags)) {
                if (meta && data) {
-                       gfs2_page_sync(gl, flags | DIO_START);
+                       gfs2_page_writeback(gl);
                        gfs2_log_flush(gl->gl_sbd, gl);
-                       gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT);
-                       gfs2_page_sync(gl, flags | DIO_WAIT);
+                       gfs2_meta_sync(gl);
+                       gfs2_page_wait(gl);
                        clear_bit(GLF_DIRTY, &gl->gl_flags);
                } else if (meta) {
                        gfs2_log_flush(gl->gl_sbd, gl);
-                       gfs2_meta_sync(gl, flags | DIO_START | DIO_WAIT);
-               } else if (data)
-                       gfs2_page_sync(gl, flags | DIO_START | DIO_WAIT);
+                       gfs2_meta_sync(gl);
+               } else if (data) {
+                       gfs2_page_writeback(gl);
+                       gfs2_page_wait(gl);
+               }
                if (flags & DIO_RELEASE)
                        gfs2_ail_empty_gl(gl);
        }
-
-       clear_bit(GLF_SYNC, &gl->gl_flags);
 }
 
 /**
@@ -326,12 +379,11 @@ static void inode_go_unlock(struct gfs2_holder *gh)
        struct gfs2_glock *gl = gh->gh_gl;
        struct gfs2_inode *ip = gl->gl_object;
 
-       if (ip) {
-               if (test_bit(GLF_DIRTY, &gl->gl_flags))
-                       gfs2_inode_attr_in(ip);
-
-               gfs2_meta_cache_flush(ip);
-       }
+       if (ip == NULL)
+               return;
+       if (test_bit(GLF_DIRTY, &gl->gl_flags))
+               gfs2_inode_attr_in(ip);
+       gfs2_meta_cache_flush(ip);
 }
 
 /**
@@ -493,13 +545,13 @@ static int quota_go_demote_ok(struct gfs2_glock *gl)
        return !atomic_read(&gl->gl_lvb_count);
 }
 
-struct gfs2_glock_operations gfs2_meta_glops = {
+const struct gfs2_glock_operations gfs2_meta_glops = {
        .go_xmote_th = gfs2_glock_xmote_th,
        .go_drop_th = gfs2_glock_drop_th,
-       .go_type = LM_TYPE_META
+       .go_type = LM_TYPE_META,
 };
 
-struct gfs2_glock_operations gfs2_inode_glops = {
+const struct gfs2_glock_operations gfs2_inode_glops = {
        .go_xmote_th = inode_go_xmote_th,
        .go_xmote_bh = inode_go_xmote_bh,
        .go_drop_th = inode_go_drop_th,
@@ -509,10 +561,10 @@ struct gfs2_glock_operations gfs2_inode_glops = {
        .go_lock = inode_go_lock,
        .go_unlock = inode_go_unlock,
        .go_greedy = inode_greedy,
-       .go_type = LM_TYPE_INODE
+       .go_type = LM_TYPE_INODE,
 };
 
-struct gfs2_glock_operations gfs2_rgrp_glops = {
+const struct gfs2_glock_operations gfs2_rgrp_glops = {
        .go_xmote_th = gfs2_glock_xmote_th,
        .go_drop_th = gfs2_glock_drop_th,
        .go_sync = meta_go_sync,
@@ -520,45 +572,44 @@ struct gfs2_glock_operations gfs2_rgrp_glops = {
        .go_demote_ok = rgrp_go_demote_ok,
        .go_lock = rgrp_go_lock,
        .go_unlock = rgrp_go_unlock,
-       .go_type = LM_TYPE_RGRP
+       .go_type = LM_TYPE_RGRP,
 };
 
-struct gfs2_glock_operations gfs2_trans_glops = {
+const struct gfs2_glock_operations gfs2_trans_glops = {
        .go_xmote_th = trans_go_xmote_th,
        .go_xmote_bh = trans_go_xmote_bh,
        .go_drop_th = trans_go_drop_th,
-       .go_type = LM_TYPE_NONDISK
+       .go_type = LM_TYPE_NONDISK,
 };
 
-struct gfs2_glock_operations gfs2_iopen_glops = {
+const struct gfs2_glock_operations gfs2_iopen_glops = {
        .go_xmote_th = gfs2_glock_xmote_th,
        .go_drop_th = gfs2_glock_drop_th,
-       .go_callback = gfs2_iopen_go_callback,
-       .go_type = LM_TYPE_IOPEN
+       .go_type = LM_TYPE_IOPEN,
 };
 
-struct gfs2_glock_operations gfs2_flock_glops = {
+const struct gfs2_glock_operations gfs2_flock_glops = {
        .go_xmote_th = gfs2_glock_xmote_th,
        .go_drop_th = gfs2_glock_drop_th,
-       .go_type = LM_TYPE_FLOCK
+       .go_type = LM_TYPE_FLOCK,
 };
 
-struct gfs2_glock_operations gfs2_nondisk_glops = {
+const struct gfs2_glock_operations gfs2_nondisk_glops = {
        .go_xmote_th = gfs2_glock_xmote_th,
        .go_drop_th = gfs2_glock_drop_th,
-       .go_type = LM_TYPE_NONDISK
+       .go_type = LM_TYPE_NONDISK,
 };
 
-struct gfs2_glock_operations gfs2_quota_glops = {
+const struct gfs2_glock_operations gfs2_quota_glops = {
        .go_xmote_th = gfs2_glock_xmote_th,
        .go_drop_th = gfs2_glock_drop_th,
        .go_demote_ok = quota_go_demote_ok,
-       .go_type = LM_TYPE_QUOTA
+       .go_type = LM_TYPE_QUOTA,
 };
 
-struct gfs2_glock_operations gfs2_journal_glops = {
+const struct gfs2_glock_operations gfs2_journal_glops = {
        .go_xmote_th = gfs2_glock_xmote_th,
        .go_drop_th = gfs2_glock_drop_th,
-       .go_type = LM_TYPE_JOURNAL
+       .go_type = LM_TYPE_JOURNAL,
 };