linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zheng Liu <gnehzuil.liu@gmail.com>
To: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: Zheng Liu <wenqing.lz@taobao.com>, Jens Axboe <axboe@kernel.dk>,
	Steven Whitehouse <swhiteho@redhat.com>,
	Aditya Kali <adityakali@google.com>,
	Wang Shaoyan <wangshaoyan.pt@taobao.com>
Subject: [PATCH v4 2/8] ext4: add wrapper functions for buffer layer
Date: Tue, 24 Jan 2012 00:50:22 +0800	[thread overview]
Message-ID: <1327337428-8266-3-git-send-email-wenqing.lz@taobao.com> (raw)
In-Reply-To: <1327337428-8266-1-git-send-email-wenqing.lz@taobao.com>

Wrapper functions are defined to account the result of different IO type.

CC: Jens Axboe <axboe@kernel.dk>
CC: Steven Whitehouse <swhiteho@redhat.com>
CC: Aditya Kali <adityakali@google.com>
Signed-off-by: Wang Shaoyan <wangshaoyan.pt@taobao.com>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
---
 fs/ext4/ext4.h  |   21 +++++++++++++++
 fs/ext4/super.c |   78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 7ec0596..688891e 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1968,6 +1968,27 @@ static inline void ext4_ios_read(struct super_block *sb, int type,
 	__ext4_io_stat(sb, READ, type, count);
 }
 
+extern void ext4_submit_bh_read_nowait(int rw, struct buffer_head *bh,
+				       struct super_block *sb, int type,
+				       unsigned long count);
+extern int ext4_submit_bh_read(int rw, struct buffer_head *bh,
+			       struct super_block *sb, int type,
+			       unsigned long count);
+extern void ext4_submit_bh_write_nowait(int rw, struct buffer_head *bh,
+					struct super_block *sb, int type,
+					unsigned long count);
+extern struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
+					 int type, unsigned long count);
+extern void ext4_sb_breadahead(struct super_block *sb,
+			       sector_t block, int type);
+
+static inline int ext4_bh_submit_read(struct buffer_head *bh,
+				      struct super_block *sb,
+				      int type, unsigned long count)
+{
+	return ext4_submit_bh_read(READ, bh, sb, type, count);
+}
+
 extern void *ext4_kvmalloc(size_t size, gfp_t flags);
 extern void *ext4_kvzalloc(size_t size, gfp_t flags);
 extern void ext4_kvfree(void *ptr);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index f3a5cab..305ece7 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4999,6 +4999,84 @@ count:
 	__ext4_io_stat(sb, WRITE, type, count);
 }
 
+void ext4_submit_bh_read_nowait(int rw, struct buffer_head *bh,
+				struct super_block *sb, int type,
+				unsigned long count)
+{
+	BUG_ON(rw & WRITE);
+	BUG_ON(!buffer_locked(bh));
+
+	/* IO type accouting */
+	ext4_ios_read(sb, type, count);
+
+	get_bh(bh);
+	bh->b_end_io = end_buffer_read_sync;
+	submit_bh(rw, bh);
+}
+
+int ext4_submit_bh_read(int rw, struct buffer_head *bh, struct super_block *sb,
+			int type, unsigned long count)
+{
+	BUG_ON(rw & WRITE);
+	BUG_ON(!buffer_locked(bh));
+
+	if (buffer_uptodate(bh)) {
+		unlock_buffer(bh);
+		return 0;
+	}
+
+	ext4_submit_bh_read_nowait(rw, bh, sb, type, count);
+	wait_on_buffer(bh);
+	if (buffer_uptodate(bh))
+		return 0;
+	return -EIO;
+}
+
+void ext4_submit_bh_write_nowait(int rw, struct buffer_head *bh,
+				 struct super_block *sb, int type,
+				 unsigned long count)
+{
+	BUG_ON(!(rw & WRITE));
+	BUG_ON(!buffer_locked(bh));
+
+	/* IO type accouting */
+	ext4_ios_write(sb, NULL, NULL, type, count);
+
+	get_bh(bh);
+	bh->b_end_io = end_buffer_write_sync;
+	submit_bh(rw, bh);
+}
+
+struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block,
+				  int type, unsigned long count)
+{
+	struct buffer_head *bh = __getblk(sb->s_bdev, block, sb->s_blocksize);
+
+	if (likely(bh) && !buffer_uptodate(bh)) {
+		lock_buffer(bh);
+		if (ext4_submit_bh_read(READ, bh, sb, type, count)) {
+			brelse(bh);
+			bh = NULL;
+		}
+	}
+	return bh;
+}
+
+void ext4_sb_breadahead(struct super_block *sb, sector_t block, int type)
+{
+	struct buffer_head *bh = __getblk(sb->s_bdev, block, sb->s_blocksize);
+	if (likely(bh)) {
+		if (trylock_buffer(bh)) {
+			if (buffer_uptodate(bh))
+				ext4_submit_bh_read_nowait(READ, bh, sb,
+							   type, 1);
+			else
+				unlock_buffer(bh);
+		}
+		brelse(bh);
+	}
+}
+
 static struct dentry *ext4_mount(struct file_system_type *fs_type, int flags,
 		       const char *dev_name, void *data)
 {
-- 
1.7.4.1


  parent reply	other threads:[~2012-01-23 16:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-23 16:50 [PATCH v4 0/8] ext4: io type accouting Zheng Liu
2012-01-23 16:50 ` [PATCH v4 1/8] ext4: add percpu counters and related functions to account io types Zheng Liu
2012-01-23 16:50 ` Zheng Liu [this message]
2012-01-23 16:50 ` [PATCH v4 3/8] ext4: account the metadata request of read operations in buffered io Zheng Liu
2012-01-23 16:50 ` [PATCH v4 4/8] ext4: account the data " Zheng Liu
2012-01-23 16:50 ` [PATCH v4 5/8] ext4: account the metadata request of write " Zheng Liu
2012-01-23 16:50 ` [PATCH v4 6/8] ext4: account the data " Zheng Liu
2012-01-23 16:50 ` [PATCH v4 7/8] ext4: request accouting in direct io Zheng Liu
2012-01-23 16:50 ` [PATCH v4 8/8] ext4: show the result of io types accouting Zheng Liu

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=1327337428-8266-3-git-send-email-wenqing.lz@taobao.com \
    --to=gnehzuil.liu@gmail.com \
    --cc=adityakali@google.com \
    --cc=axboe@kernel.dk \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=swhiteho@redhat.com \
    --cc=wangshaoyan.pt@taobao.com \
    --cc=wenqing.lz@taobao.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).