[GFS2] Update copyright, tidy up incore.h
[linux-2.6-block.git] / fs / gfs2 / glops.c
index d180c89dd567340725c7095d33701fb26a34435b..8e1d8ee68e2ec2b7ae1e2cd73927625b8fe966fd 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
- * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
  *
  * 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,7 +13,6 @@
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
 #include <linux/gfs2_ondisk.h>
-#include <asm/semaphore.h>
 
 #include "gfs2.h"
 #include "lm_interface.h"
 #include "inode.h"
 #include "log.h"
 #include "meta_io.h"
-#include "page.h"
 #include "recovery.h"
 #include "rgrp.h"
 #include "util.h"
 
+
+/**
+ * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock
+ * @gl: the glock
+ *
+ */
+
+static void gfs2_pte_inval(struct gfs2_glock *gl)
+{
+       struct gfs2_inode *ip;
+       struct inode *inode;
+
+       ip = gl->gl_object;
+       inode = &ip->i_inode;
+       if (!ip || !S_ISREG(ip->i_di.di_mode))
+               return;
+
+       if (!test_bit(GIF_PAGED, &ip->i_flags))
+               return;
+
+       unmap_shared_mapping_range(inode->i_mapping, 0, 0);
+
+       if (test_bit(GIF_SW_PAGED, &ip->i_flags))
+               set_bit(GLF_DIRTY, &gl->gl_flags);
+
+       clear_bit(GIF_SW_PAGED, &ip->i_flags);
+}
+
+/**
+ * gfs2_page_inval - Invalidate all pages associated with a glock
+ * @gl: the glock
+ *
+ */
+
+static void gfs2_page_inval(struct gfs2_glock *gl)
+{
+       struct gfs2_inode *ip;
+       struct inode *inode;
+
+       ip = gl->gl_object;
+       inode = &ip->i_inode;
+       if (!ip || !S_ISREG(ip->i_di.di_mode))
+               return;
+
+       truncate_inode_pages(inode->i_mapping, 0);
+       gfs2_assert_withdraw(GFS2_SB(&ip->i_inode), !inode->i_mapping->nrpages);
+       clear_bit(GIF_PAGED, &ip->i_flags);
+}
+
+/**
+ * gfs2_page_sync - Sync the data pages (not metadata) associated with a glock
+ * @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)
+{
+       struct gfs2_inode *ip;
+       struct inode *inode;
+       struct address_space *mapping;
+       int error = 0;
+
+       ip = gl->gl_object;
+       inode = &ip->i_inode;
+       if (!ip || !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);
+
+       /* Put back any errors cleared by filemap_fdatawait()
+          so they can be caught by someone who can pass them
+          up to user space. */
+
+       if (error == -ENOSPC)
+               set_bit(AS_ENOSPC, &mapping->flags);
+       else if (error)
+               set_bit(AS_EIO, &mapping->flags);
+
+}
+
 /**
  * meta_go_sync - sync out the metadata for this glock
  * @gl: the glock
@@ -51,7 +137,6 @@ static void meta_go_sync(struct gfs2_glock *gl, int flags)
                        gfs2_ail_empty_gl(gl);
        }
 
-       clear_bit(GLF_SYNC, &gl->gl_flags);
 }
 
 /**
@@ -70,18 +155,6 @@ static void meta_go_inval(struct gfs2_glock *gl, int flags)
        gl->gl_vn++;
 }
 
-/**
- * meta_go_demote_ok - Check to see if it's ok to unlock a glock
- * @gl: the glock
- *
- * Returns: 1 if we have no cached data; ok to demote meta glock
- */
-
-static int meta_go_demote_ok(struct gfs2_glock *gl)
-{
-       return !gl->gl_aspace->i_mapping->nrpages;
-}
-
 /**
  * inode_go_xmote_th - promote/demote a glock
  * @gl: the glock
@@ -162,7 +235,6 @@ static void inode_go_sync(struct gfs2_glock *gl, int flags)
                        gfs2_ail_empty_gl(gl);
        }
 
-       clear_bit(GLF_SYNC, &gl->gl_flags);
 }
 
 /**
@@ -252,11 +324,12 @@ 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 && test_bit(GLF_DIRTY, &gl->gl_flags))
-               gfs2_inode_attr_in(ip);
+       if (ip) {
+               if (test_bit(GLF_DIRTY, &gl->gl_flags))
+                       gfs2_inode_attr_in(ip);
 
-       if (ip)
                gfs2_meta_cache_flush(ip);
+       }
 }
 
 /**
@@ -289,7 +362,7 @@ static void inode_greedy(struct gfs2_glock *gl)
 
        spin_unlock(&ip->i_spin);
 
-       gfs2_inode_put(ip);
+       iput(&ip->i_inode);
 }
 
 /**
@@ -362,14 +435,14 @@ static void trans_go_xmote_th(struct gfs2_glock *gl, unsigned int state,
 static void trans_go_xmote_bh(struct gfs2_glock *gl)
 {
        struct gfs2_sbd *sdp = gl->gl_sbd;
-       struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip;
+       struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
        struct gfs2_glock *j_gl = ip->i_gl;
        struct gfs2_log_header head;
        int error;
 
        if (gl->gl_state != LM_ST_UNLOCKED &&
            test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
-               gfs2_meta_cache_flush(sdp->sd_jdesc->jd_inode->u.generic_ip);
+               gfs2_meta_cache_flush(GFS2_I(sdp->sd_jdesc->jd_inode));
                j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA);
 
                error = gfs2_find_jhead(sdp->sd_jdesc, &head);
@@ -418,16 +491,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_sync = meta_go_sync,
-       .go_inval = meta_go_inval,
-       .go_demote_ok = meta_go_demote_ok,
        .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,
@@ -440,7 +510,7 @@ struct gfs2_glock_operations gfs2_inode_glops = {
        .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,
@@ -451,40 +521,40 @@ struct gfs2_glock_operations gfs2_rgrp_glops = {
        .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
 };
 
-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
 };
 
-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
 };
 
-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
 };
 
-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
 };
 
-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