From patchwork Fri Oct 28 17:00:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Monakhov X-Patchwork-Id: 122445 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 E48B1B6F67 for ; Sat, 29 Oct 2011 04:00:29 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756088Ab1J1RAW (ORCPT ); Fri, 28 Oct 2011 13:00:22 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:45611 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756081Ab1J1RAU (ORCPT ); Fri, 28 Oct 2011 13:00:20 -0400 Received: by mail-bw0-f46.google.com with SMTP id zt4so624020bkb.19 for ; Fri, 28 Oct 2011 10:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=So1xsFxpMncOh4Id79Umuub7s4XMMYaaHW2UJz0tvCA=; b=jM86sUpSXv1tGETQnlbUolwddvplm72vwWermVlyaL3Ihm9xDbguP/T4WqQhgz4PHk vKNKUIcgAmPTTXxlkDndTPh7DCOVpLdLkSY/x05eU/tw1VrPwJmgpyHpRovq8uppJNcO ucMdtMlbRUOM4JX5GJbcY3eJ8hYX83sI/4cns= Received: by 10.204.13.131 with SMTP id c3mr3141744bka.10.1319821219986; Fri, 28 Oct 2011 10:00:19 -0700 (PDT) Received: from localhost.localdomain (swsoft-msk-nat.sw.ru. [195.214.232.10]) by mx.google.com with ESMTPS id x8sm3655808bkv.10.2011.10.28.10.00.17 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 28 Oct 2011 10:00:18 -0700 (PDT) From: Dmitry Monakhov To: linux-ext4@vger.kernel.org Cc: achender@linux.vnet.ibm.com, tytso@mit.edu, Dmitry Monakhov Subject: [PATCH 2/7] ext4: move inode indepth shrink logic to didicated function Date: Fri, 28 Oct 2011 21:00:05 +0400 Message-Id: <1319821210-7374-3-git-send-email-dmonakhov@openvz.org> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1319821210-7374-1-git-send-email-dmonakhov@openvz.org> References: <1319821210-7374-1-git-send-email-dmonakhov@openvz.org> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org - add ext4_ext_try_shrink helper - ext4_mark_inode_dirty() called externally in order to allow caller to butch several inode updates in to one mark_dirty call. Signed-off-by: Dmitry Monakhov --- fs/ext4/extents.c | 59 ++++++++++++++++++++++------------------------------ 1 files changed, 25 insertions(+), 34 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index eae9680..6e3ce38 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2496,6 +2496,22 @@ ext4_ext_more_to_rm(struct ext4_ext_path *path) return 1; } +static int ext4_ext_try_shrink(handle_t *handle, struct inode *inode) +{ + /* TODO: flexible tree reduction should be here */ + if (ext_depth(inode) && ext_inode_hdr(inode)->eh_entries == 0) { + /* + * truncate to zero freed all the tree, + * so we need to correct eh_depth + */ + ext_inode_hdr(inode)->eh_depth = 0; + ext_inode_hdr(inode)->eh_max = + cpu_to_le16(ext4_ext_space_root(inode, 0)); + return 1; + } + return 0; +} + static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start) { struct super_block *sb = inode->i_sb; @@ -2503,7 +2519,7 @@ static int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start) struct ext4_ext_path *path; ext4_fsblk_t partial_cluster = 0; handle_t *handle; - int i, err; + int i, err, err2; ext_debug("truncate since %u\n", start); @@ -2629,29 +2645,18 @@ again: EXT4_SB(sb)->s_cluster_ratio, flags); partial_cluster = 0; } - - /* TODO: flexible tree reduction should be here */ - if (path->p_hdr->eh_entries == 0) { - /* - * truncate to zero freed all the tree, - * so we need to correct eh_depth - */ - err = ext4_ext_get_access(handle, inode, path); - if (err == 0) { - ext_inode_hdr(inode)->eh_depth = 0; - ext_inode_hdr(inode)->eh_max = - cpu_to_le16(ext4_ext_space_root(inode, 0)); - err = ext4_ext_dirty(handle, inode, path); - } - } + if(ext4_ext_try_shrink(handle, inode)) + err2 = ext4_mark_inode_dirty(handle, inode); + if (!err) + err = err2; out: ext4_ext_drop_refs(path); kfree(path); if (err == -EAGAIN) goto again; - ext4_journal_stop(handle); + err2 = ext4_journal_stop(handle); - return err; + return err ? err : err2; } /* @@ -3895,22 +3900,8 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode, &partial_cluster, map->m_lblk, map->m_lblk + punched_out); - if (!err && path->p_hdr->eh_entries == 0) { - /* - * Punch hole freed all of this sub tree, - * so we need to correct eh_depth - */ - err = ext4_ext_get_access(handle, inode, path); - if (err == 0) { - ext_inode_hdr(inode)->eh_depth = 0; - ext_inode_hdr(inode)->eh_max = - cpu_to_le16(ext4_ext_space_root( - inode, 0)); - - err = ext4_ext_dirty( - handle, inode, path); - } - } + if (!err && ext4_ext_try_shrink(handle, inode)) + err = ext4_mark_inode_dirty(handle, inode); goto out2; }