cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: swhiteho@redhat.com <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 07/58] [GFS2] Introduce gfs2_set_aops()
Date: Mon, 21 Jan 2008 09:21:25 +0000	[thread overview]
Message-ID: <12009073542596-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <12009073531216-git-send-email-swhiteho@redhat.com>

From: Steven Whitehouse <swhiteho@redhat.com>

Just like ext3 we now have three sets of address space operations
to cover the cases of writeback, ordered and journalled data
writes. This means that the individual operations can now become
less complicated as we are able to remove some of the tests for
file data mode from the code.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index af493fc..532784e 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -136,7 +136,6 @@ void gfs2_set_iop(struct inode *inode)
 	if (S_ISREG(mode)) {
 		inode->i_op = &gfs2_file_iops;
 		inode->i_fop = &gfs2_file_fops;
-		inode->i_mapping->a_ops = &gfs2_file_aops;
 	} else if (S_ISDIR(mode)) {
 		inode->i_op = &gfs2_dir_iops;
 		inode->i_fop = &gfs2_dir_fops;
@@ -290,6 +289,9 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
 	di->di_entries = be32_to_cpu(str->di_entries);
 
 	di->di_eattr = be64_to_cpu(str->di_eattr);
+	if (S_ISREG(ip->i_inode.i_mode))
+		gfs2_set_aops(&ip->i_inode);
+
 	return 0;
 }
 
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index bed3dc2..d446506 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -26,6 +26,12 @@ static inline int gfs2_is_writeback(const struct gfs2_inode *ip)
 	return (sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK) && !gfs2_is_jdata(ip);
 }
 
+static inline int gfs2_is_ordered(const struct gfs2_inode *ip)
+{
+	const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
+	return (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) && !gfs2_is_jdata(ip);
+}
+
 static inline int gfs2_is_dir(const struct gfs2_inode *ip)
 {
 	return S_ISDIR(ip->i_inode.i_mode);
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index ed154af..207014f 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -162,28 +162,18 @@ out_ignore:
 }
 
 /**
- * gfs2_writepages - Write a bunch of dirty pages back to disk
+ * gfs2_writeback_writepages - Write a bunch of dirty pages back to disk
  * @mapping: The mapping to write
  * @wbc: Write-back control
  *
- * For journaled files and/or ordered writes this just falls back to the
- * kernel's default writepages path for now. We will probably want to change
- * that eventually (i.e. when we look at allocate on flush).
- *
- * For the data=writeback case though we can already ignore buffer heads
+ * For the data=writeback case we can already ignore buffer heads
  * and write whole extents at once. This is a big reduction in the
  * number of I/O requests we send and the bmap calls we make in this case.
  */
-static int gfs2_writepages(struct address_space *mapping,
-			   struct writeback_control *wbc)
+static int gfs2_writeback_writepages(struct address_space *mapping,
+				     struct writeback_control *wbc)
 {
-	struct inode *inode = mapping->host;
-	struct gfs2_inode *ip = GFS2_I(inode);
-
-	if (gfs2_is_writeback(ip))
-		return mpage_writepages(mapping, wbc, gfs2_get_block_noalloc);
-
-	return generic_writepages(mapping, wbc);
+	return mpage_writepages(mapping, wbc, gfs2_get_block_noalloc);
 }
 
 /**
@@ -644,11 +634,7 @@ failed:
  
 static int gfs2_set_page_dirty(struct page *page)
 {
-	struct gfs2_inode *ip = GFS2_I(page->mapping->host);
-	struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
-
-	if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip))
-		SetPageChecked(page);
+	SetPageChecked(page);
 	return __set_page_dirty_buffers(page);
 }
 
@@ -738,13 +724,9 @@ static int gfs2_ok_for_dio(struct gfs2_inode *ip, int rw, loff_t offset)
 {
 	/*
 	 * Should we return an error here? I can't see that O_DIRECT for
-	 * a journaled file makes any sense. For now we'll silently fall
-	 * back to buffered I/O, likewise we do the same for stuffed
-	 * files since they are (a) small and (b) unaligned.
+	 * a stuffed file makes any sense. For now we'll silently fall
+	 * back to buffered I/O
 	 */
-	if (gfs2_is_jdata(ip))
-		return 0;
-
 	if (gfs2_is_stuffed(ip))
 		return 0;
 
@@ -855,9 +837,22 @@ cannot_release:
 	return 0;
 }
 
-const struct address_space_operations gfs2_file_aops = {
+static const struct address_space_operations gfs2_writeback_aops = {
+	.writepage = gfs2_writepage,
+	.writepages = gfs2_writeback_writepages,
+	.readpage = gfs2_readpage,
+	.readpages = gfs2_readpages,
+	.sync_page = block_sync_page,
+	.write_begin = gfs2_write_begin,
+	.write_end = gfs2_write_end,
+	.bmap = gfs2_bmap,
+	.invalidatepage = gfs2_invalidatepage,
+	.releasepage = gfs2_releasepage,
+	.direct_IO = gfs2_direct_IO,
+};
+
+static const struct address_space_operations gfs2_ordered_aops = {
 	.writepage = gfs2_writepage,
-	.writepages = gfs2_writepages,
 	.readpage = gfs2_readpage,
 	.readpages = gfs2_readpages,
 	.sync_page = block_sync_page,
@@ -870,3 +865,30 @@ const struct address_space_operations gfs2_file_aops = {
 	.direct_IO = gfs2_direct_IO,
 };
 
+static const struct address_space_operations gfs2_jdata_aops = {
+	.writepage = gfs2_writepage,
+	.readpage = gfs2_readpage,
+	.readpages = gfs2_readpages,
+	.sync_page = block_sync_page,
+	.write_begin = gfs2_write_begin,
+	.write_end = gfs2_write_end,
+	.set_page_dirty = gfs2_set_page_dirty,
+	.bmap = gfs2_bmap,
+	.invalidatepage = gfs2_invalidatepage,
+	.releasepage = gfs2_releasepage,
+};
+
+void gfs2_set_aops(struct inode *inode)
+{
+	struct gfs2_inode *ip = GFS2_I(inode);
+
+	if (gfs2_is_writeback(ip))
+		inode->i_mapping->a_ops = &gfs2_writeback_aops;
+	else if (gfs2_is_ordered(ip))
+		inode->i_mapping->a_ops = &gfs2_ordered_aops;
+	else if (gfs2_is_jdata(ip))
+		inode->i_mapping->a_ops = &gfs2_jdata_aops;
+	else
+		BUG();
+}
+
diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h
index e8fe83f..d3b76d0 100644
--- a/fs/gfs2/ops_address.h
+++ b/fs/gfs2/ops_address.h
@@ -14,12 +14,12 @@
 #include <linux/buffer_head.h>
 #include <linux/mm.h>
 
-extern const struct address_space_operations gfs2_file_aops;
 extern int gfs2_get_block(struct inode *inode, sector_t lblock,
 			  struct buffer_head *bh_result, int create);
 extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask);
 extern int gfs2_internal_read(struct gfs2_inode *ip,
 			      struct file_ra_state *ra_state,
 			      char *buf, loff_t *pos, unsigned size);
+extern void gfs2_set_aops(struct inode *inode);
 
 #endif /* __OPS_ADDRESS_DOT_H__ */
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index 6f3aeb0..ad5daaa 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -38,6 +38,7 @@
 #include "trans.h"
 #include "util.h"
 #include "eaops.h"
+#include "ops_address.h"
 
 /**
  * gfs2_llseek - seek to a location in a file
@@ -245,7 +246,16 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
 		if (error)
 			goto out;
 	}
-
+	if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
+		if (flags & GFS2_DIF_JDATA)
+			gfs2_log_flush(sdp, ip->i_gl);
+		error = filemap_fdatawrite(inode->i_mapping);
+		if (error)
+			goto out;
+		error = filemap_fdatawait(inode->i_mapping);
+		if (error)
+			goto out;
+	}
 	error = gfs2_trans_begin(sdp, RES_DINODE, 0);
 	if (error)
 		goto out;
@@ -257,6 +267,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
 	gfs2_dinode_out(ip, bh->b_data);
 	brelse(bh);
 	gfs2_set_inode_flags(inode);
+	gfs2_set_aops(inode);
 out_trans_end:
 	gfs2_trans_end(sdp);
 out:
-- 
1.5.1.2



  reply	other threads:[~2008-01-21  9:21 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-21  9:21 [Cluster-devel] [GFS2] Pre-pull patch posting swhiteho
2008-01-21  9:21 ` [Cluster-devel] [PATCH 01/58] [GFS2] Handle multiple glock demote requests swhiteho
2008-01-21  9:21   ` [Cluster-devel] [PATCH 02/58] [GFS2] Clean up internal read function swhiteho
2008-01-21  9:21     ` [Cluster-devel] [PATCH 03/58] [GFS2] Use ->page_mkwrite() for mmap() swhiteho
2008-01-21  9:21       ` [Cluster-devel] [PATCH 04/58] [GFS2] Remove useless i_cache from inodes swhiteho
2008-01-21  9:21         ` [Cluster-devel] [PATCH 05/58] [GFS2] Remove unused field in struct gfs2_inode swhiteho
2008-01-21  9:21           ` [Cluster-devel] [PATCH 06/58] [GFS2] Add gfs2_is_writeback() swhiteho
2008-01-21  9:21             ` swhiteho [this message]
2008-01-21  9:21               ` [Cluster-devel] [PATCH 08/58] [GFS2] Split gfs2_writepage into three cases swhiteho
2008-01-21  9:21                 ` [Cluster-devel] [PATCH 09/58] [GFS2] Add writepages for GFS2 jdata swhiteho
2008-01-21  9:21                   ` [Cluster-devel] [PATCH 10/58] [GFS2] Don't hold page lock when starting transaction swhiteho
2008-01-21  9:21                     ` [Cluster-devel] [PATCH 11/58] [GFS2] Use correct include file in ops_address.c swhiteho
2008-01-21  9:21                       ` [Cluster-devel] [PATCH 12/58] [GFS2] Remove unused variables swhiteho
2008-01-21  9:21                         ` [Cluster-devel] [PATCH 13/58] [GFS2] Remove "reclaim limit" swhiteho
2008-01-21  9:21                           ` [Cluster-devel] [PATCH 14/58] [GFS2] Add sync_page to metadata address space operations swhiteho
2008-01-21  9:21                             ` [Cluster-devel] [PATCH 15/58] [GFS2] Reorder writeback for glock sync swhiteho
2008-01-21  9:21                               ` [Cluster-devel] [PATCH 16/58] [GFS2] Remove flags no longer required swhiteho
2008-01-21  9:21                                 ` [Cluster-devel] [PATCH 17/58] [GFS2] Given device ID rather than s_id in "id" sysfs file swhiteho
2008-01-21  9:21                                   ` [Cluster-devel] [PATCH 18/58] [GFS2] check kthread_should_stop when waiting swhiteho
2008-01-21  9:21                                     ` [Cluster-devel] [PATCH 19/58] [GFS2] Don't add glocks to the journal swhiteho
2008-01-21  9:21                                       ` [Cluster-devel] [PATCH 20/58] [GFS2] Use atomic_t for journal free blocks counter swhiteho
2008-01-21  9:21                                         ` [Cluster-devel] [PATCH 21/58] [GFS2] Move gfs2_logd into log.c swhiteho
2008-01-21  9:21                                           ` [Cluster-devel] [PATCH 22/58] [GFS2] Don't periodically update the jindex swhiteho
2008-01-21  9:21                                             ` [Cluster-devel] [PATCH 23/58] [GFS2] Check for installation of mount helpers for DLM mounts swhiteho
2008-01-21  9:21                                               ` [Cluster-devel] [PATCH 24/58] [GFS2] tidy up error message swhiteho
2008-01-21  9:21                                                 ` [Cluster-devel] [PATCH 25/58] [GFS2] Fix runtime issue with UP kernels swhiteho
2008-01-21  9:21                                                   ` [Cluster-devel] [PATCH 26/58] [GFS2] Revise gfs2_logd and flush thresholds swhiteho
2008-01-21  9:21                                                     ` [Cluster-devel] [PATCH 27/58] [GFS2] remove unnecessary permission checks swhiteho
2008-01-21  9:21                                                       ` [Cluster-devel] [PATCH 28/58] [GFS2] Fix build warnings swhiteho
2008-01-21  9:21                                                         ` [Cluster-devel] [PATCH 29/58] [GFS2] Remove unrequired code swhiteho
2008-01-21  9:21                                                           ` [Cluster-devel] [PATCH 30/58] [GFS2] Remove lock methods for lock_nolock protocol swhiteho
2008-01-21  9:21                                                             ` [Cluster-devel] [PATCH 31/58] [GFS2] patch to check for recursive lock requests in gfs2_rename code path swhiteho
2008-01-21  9:21                                                               ` [Cluster-devel] [PATCH 32/58] [GFS2] Remove unused variable swhiteho
2008-01-21  9:21                                                                 ` [Cluster-devel] [PATCH 33/58] [GFS2] use pid for plock owner for nfs clients swhiteho
2008-01-21  9:21                                                                   ` [Cluster-devel] [PATCH 34/58] [GFS2] Remove function gfs2_get_block swhiteho
2008-01-21  9:21                                                                     ` [Cluster-devel] [PATCH 35/58] [GFS2] Fix typo in log.c swhiteho
2008-01-21  9:21                                                                       ` [Cluster-devel] [PATCH 36/58] [GFS2] Journal extent mapping swhiteho
2008-01-21  9:21                                                                         ` [Cluster-devel] [PATCH 37/58] [GFS2] Get rid of useless "found" variable in quota.c swhiteho
2008-01-21  9:21                                                                           ` [Cluster-devel] [PATCH 38/58] [GFS2] Run through full bitmaps quicker in gfs2_bitfit swhiteho
2008-01-21  9:21                                                                             ` [Cluster-devel] [PATCH 39/58] [GFS2] Reorganize function gfs2_glmutex_lock swhiteho
2008-01-21  9:21                                                                               ` [Cluster-devel] [PATCH 40/58] [GFS2] Only fetch the dinode once in block_map swhiteho
2008-01-21  9:21                                                                                 ` [Cluster-devel] [PATCH 41/58] [GFS2] Function meta_read optimization swhiteho
2008-01-21  9:22                                                                                   ` [Cluster-devel] [PATCH 42/58] [GFS2] Incremental patch to fix compiler warning swhiteho
2008-01-21  9:22                                                                                     ` [Cluster-devel] [PATCH 43/58] [GFS2] Eliminate the no longer needed sd_statfs_mutex swhiteho
2008-01-21  9:22                                                                                       ` [Cluster-devel] [PATCH 44/58] [GFS2] Minor correction swhiteho
2008-01-21  9:22                                                                                         ` [Cluster-devel] [PATCH 45/58] [GFS2] Fix log block mapper swhiteho
2008-01-21  9:22                                                                                           ` [Cluster-devel] [PATCH 46/58] [GFS2] Remove unused variable swhiteho
2008-01-21  9:22                                                                                             ` [Cluster-devel] [PATCH 47/58] [GFS2] Allow page migration for writeback and ordered pages swhiteho
2008-01-21  9:22                                                                                               ` [Cluster-devel] [PATCH 48/58] [GFS2] Initialize extent_list earlier swhiteho
2008-01-21  9:22                                                                                                 ` [Cluster-devel] [PATCH 49/58] [GFS2] Fix problems relating to execution of files on GFS2 swhiteho
2008-01-21  9:22                                                                                                   ` [Cluster-devel] [PATCH 50/58] [GFS2] Fix assert in log code swhiteho
2008-01-21  9:22                                                                                                     ` [Cluster-devel] [PATCH 51/58] [GFS2] Reduce inode size by moving i_alloc out of line swhiteho
2008-01-21  9:22                                                                                                       ` [Cluster-devel] [PATCH 52/58] [GFS2] Remove unneeded i_spin swhiteho
2008-01-21  9:22                                                                                                         ` [Cluster-devel] [PATCH 53/58] [GFS2] gfs2_alloc_required performance swhiteho
2008-01-21  9:22                                                                                                           ` [Cluster-devel] [PATCH 54/58] [GFS2] Fix write alloc required shortcut calculation swhiteho
2008-01-21  9:22                                                                                                             ` [Cluster-devel] [PATCH 55/58] [GFS2] Fix typo swhiteho
2008-01-21  9:22                                                                                                               ` [Cluster-devel] [PATCH 56/58] [GFS2] Fix page_mkwrite truncation race path swhiteho
2008-01-21  9:22                                                                                                                 ` [Cluster-devel] [PATCH 57/58] [GFS2] Lockup on error swhiteho
2008-01-21  9:22                                                                                                                   ` [Cluster-devel] [PATCH 58/58] [GFS2] Allow journal recovery on read-only mount swhiteho
     [not found]                                                   ` <be5784b198847d5cdfa103c6882383c11eb6d7d2.1200905287.git.swhiteho@redhat.com>
2008-01-21 14:56                                                     ` [Cluster-devel] [PATCH 26/58] [GFS2] Revise gfs2_logd and flush thresholds Kevin Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12009073542596-git-send-email-swhiteho@redhat.com \
    --to=swhiteho@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).