From patchwork Tue May 3 02:04:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongqiang Yang X-Patchwork-Id: 93735 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 23D65B6FBF for ; Tue, 3 May 2011 12:09:01 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752698Ab1ECCI6 (ORCPT ); Mon, 2 May 2011 22:08:58 -0400 Received: from mail-px0-f170.google.com ([209.85.212.170]:55352 "EHLO mail-px0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751592Ab1ECCI6 (ORCPT ); Mon, 2 May 2011 22:08:58 -0400 Received: by mail-px0-f170.google.com with SMTP id 19so2589779pxi.1 for ; Mon, 02 May 2011 19:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=oXvO7TKsVn8941YthaJYi7exDrwofuF8gXqCBrGHqq0=; b=WdjTZ1i120Rr5EbN1DfdNSfvekUxpuXEcFKCj4DrblyrsIC6jzVXkFokrp97x1+Ozk xwZqPlaDRJErtIgr1MAet7JTpb2c7dHVnSHZfqPqEqKSu4F/5QORqS5cWSGJ5P+8a33Z 4HLzl+FdnunB5UAScguf3ESNGT7LlU6Kc9KcY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=VS69M5usw8Lkgj/p2z8iXypf7TGzm20xl8J1TmrnadJULMJt0MsiMoIKk87ixTs+Qw JsrsEjdonDEhLLe3hq8lZHpIMiWhTKF35eVm2crjR1yHIahSxLqKoECOYRwD+NES77jf gJr7DDFwuNm4X+MKSfi9VFVpcECsHygJVRndQ= Received: by 10.68.68.52 with SMTP id s20mr4702039pbt.219.1304388537819; Mon, 02 May 2011 19:08:57 -0700 (PDT) Received: from localhost.localdomain ([159.226.40.136]) by mx.google.com with ESMTPS id f2sm4179626pbq.35.2011.05.02.19.08.54 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 02 May 2011 19:08:56 -0700 (PDT) From: Yongqiang Yang To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, achender@linux.vnet.ibm.com, cmm@us.ibm.com, Yongqiang Yang Subject: [PATCH v2 1/3] ext4:Add a function merging extent right and left. Date: Mon, 2 May 2011 19:04:59 -0700 Message-Id: <1304388301-9452-2-git-send-email-xiaoqiangnk@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1304388301-9452-1-git-send-email-xiaoqiangnk@gmail.com> References: <1304388301-9452-1-git-send-email-xiaoqiangnk@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 1] Rename ext4_ext_try_to_merge() to ext4_ext_try_to_merge_right(). 2] Add a new function ext4_ext_try_to_merge() which tries to merge an extent both left and right. 3] Use the new function in ext4_ext_convert_unwritten_endio() and ext4_ext_insert_extent(). Signed-off-by: Yongqiang Yang Tested-by: Allison Henderson Reviewed-by: Mingming Cao --- fs/ext4/extents.c | 65 ++++++++++++++++++++++++++++------------------------ 1 files changed, 35 insertions(+), 30 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index dd2cb50..11f30d2 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1563,7 +1563,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, * Returns 0 if the extents (ex and ex+1) were _not_ merged and returns * 1 if they got merged. */ -static int ext4_ext_try_to_merge(struct inode *inode, +static int ext4_ext_try_to_merge_right(struct inode *inode, struct ext4_ext_path *path, struct ext4_extent *ex) { @@ -1603,6 +1603,31 @@ static int ext4_ext_try_to_merge(struct inode *inode, } /* + * This function tries to merge the @ex extent to neighbours in the tree. + * return 1 if merge left else 0. + */ +static int ext4_ext_try_to_merge(struct inode *inode, + struct ext4_ext_path *path, + struct ext4_extent *ex) { + struct ext4_extent_header *eh; + unsigned int depth; + int merge_done = 0; + int ret = 0; + + depth = ext_depth(inode); + BUG_ON(path[depth].p_hdr == NULL); + eh = path[depth].p_hdr; + + if (ex > EXT_FIRST_EXTENT(eh)) + merge_done = ext4_ext_try_to_merge_right(inode, path, ex - 1); + + if (!merge_done) + ret = ext4_ext_try_to_merge_right(inode, path, ex); + + return ret; +} + +/* * check if a portion of the "newext" extent overlaps with an * existing extent. * @@ -3039,6 +3064,7 @@ fix_extent_len: ext4_ext_dirty(handle, inode, path + depth); return err; } + static int ext4_convert_unwritten_extents_endio(handle_t *handle, struct inode *inode, struct ext4_ext_path *path) @@ -3047,46 +3073,25 @@ static int ext4_convert_unwritten_extents_endio(handle_t *handle, struct ext4_extent_header *eh; int depth; int err = 0; - int ret = 0; depth = ext_depth(inode); eh = path[depth].p_hdr; ex = path[depth].p_ext; + ext_debug("ext4_convert_unwritten_extents_endio: inode %lu, logical" + "block %llu, max_blocks %u\n", inode->i_ino, + (unsigned long long)le32_to_cpu(ex->ee_block), + ext4_ext_get_actual_len(ex)); + err = ext4_ext_get_access(handle, inode, path + depth); if (err) goto out; /* first mark the extent as initialized */ ext4_ext_mark_initialized(ex); - /* - * We have to see if it can be merged with the extent - * on the left. - */ - if (ex > EXT_FIRST_EXTENT(eh)) { - /* - * To merge left, pass "ex - 1" to try_to_merge(), - * since it merges towards right _only_. - */ - ret = ext4_ext_try_to_merge(inode, path, ex - 1); - if (ret) { - err = ext4_ext_correct_indexes(handle, inode, path); - if (err) - goto out; - depth = ext_depth(inode); - ex--; - } - } - /* - * Try to Merge towards right. - */ - ret = ext4_ext_try_to_merge(inode, path, ex); - if (ret) { - err = ext4_ext_correct_indexes(handle, inode, path); - if (err) - goto out; - depth = ext_depth(inode); - } + /* correct indexes is nt needed becasue borders are not changed */ + ext4_ext_try_to_merge(inode, path, ex); + /* Mark modified extent as dirty */ err = ext4_ext_dirty(handle, inode, path + depth); out: