From patchwork Mon Nov 28 12:20:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 127971 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 024C8B6F94 for ; Mon, 28 Nov 2011 23:18:33 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753421Ab1K1MSb (ORCPT ); Mon, 28 Nov 2011 07:18:31 -0500 Received: from mail-gx0-f174.google.com ([209.85.161.174]:42861 "EHLO mail-gx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752455Ab1K1MSa (ORCPT ); Mon, 28 Nov 2011 07:18:30 -0500 Received: by ggnr5 with SMTP id r5so5139829ggn.19 for ; Mon, 28 Nov 2011 04:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=912VY67FAK/f4QRHfwi+wkjjaEFlLiEBbKpagXdNLF8=; b=Tl4/eGgRay1QTgczTHGGtJgXJgsjWpmW9IwBDb3MWIeiT3IsU8MZ4xJRUWKAYcODqf 4kGm+cPxeDYJknckgD9mk8l+rF4CrxOFCkBZhyTILMm+B5HagO+Os7LaUL9/xImWBRJb CxTOGOvRZRjfkDKOa+U+29r8Gn8VU+/EMbAxo= Received: by 10.50.40.135 with SMTP id x7mr12051465igk.48.1322482709394; Mon, 28 Nov 2011 04:18:29 -0800 (PST) Received: from localhost.localdomain ([182.92.247.2]) by mx.google.com with ESMTPS id cb15sm40036924ibb.4.2011.11.28.04.18.25 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Nov 2011 04:18:28 -0800 (PST) From: Zheng Liu To: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: Jens Axboe , Steven Whitehouse , Aditya Kali , Wang Shaoyan , Zheng Liu Subject: [PATCH v3 2/8] ext4: add wrapper functions for buffer layer Date: Mon, 28 Nov 2011 20:20:22 +0800 Message-Id: <1322482828-5529-2-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1322482828-5529-1-git-send-email-wenqing.lz@taobao.com> References: <1322482392-5346-1-git-send-email-wenqing.lz@taobao.com> <1322482828-5529-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu Wrapper functions are defined to account the result of IO type. CC: Jens Axboe CC: Steven Whitehouse CC: Aditya Kali Signed-off-by: Wang Shaoyan Signed-off-by: Zheng Liu --- 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 cd9c7f9..6b90493 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1963,6 +1963,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 3ef3e03b..b10b5ed 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5000,6 +5000,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) {