From patchwork Tue Dec 3 12:11:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 296159 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 8B59D2C00A6 for ; Tue, 3 Dec 2013 23:09:20 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753328Ab3LCMJU (ORCPT ); Tue, 3 Dec 2013 07:09:20 -0500 Received: from mail-pd0-f169.google.com ([209.85.192.169]:55911 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752443Ab3LCMJT (ORCPT ); Tue, 3 Dec 2013 07:09:19 -0500 Received: by mail-pd0-f169.google.com with SMTP id v10so20038110pde.0 for ; Tue, 03 Dec 2013 04:09:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6+zhmt74mpIMtgL06sYHMOxjpR02XYra1RvVK1whtgI=; b=UX4fuIzTdD50LlPMTIVJhofIvAX+wnfU+CkrKWatQRynyQE9kUtRLiMkqUQpKo0FXc mPLYUfYeNvVNWf4Ui1PKKY68zGwmABrVUZJWu2k4hCwNCQcQPEtjMkzQ4oy/328lw7nD wTHtVz1T8aSv+yAL3yYA8oP6R2lY4M9BHOaVrkrjmgctnQW9OyL6PzR4UnbcPuKBWGS+ appqEOFO1aoeRRIq/GEABZi9ywDGiikeYK6Wu8AHA/Sa7rkwF/cXht/b3BVl2bdNpb4r 6l9NxQ8C30dU5dQe/10ejGAnz2DRukOF7Fk9xxk/4UgHg0Ijg5NvEIM/50O2GSlV5hXj 0JUA== X-Received: by 10.68.170.225 with SMTP id ap1mr38059534pbc.117.1386072558975; Tue, 03 Dec 2013 04:09:18 -0800 (PST) Received: from alpha.taobao.ali.com ([182.92.247.2]) by mx.google.com with ESMTPSA id xv2sm129628866pbb.39.2013.12.03.04.09.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Dec 2013 04:09:18 -0800 (PST) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Theodore Ts'o , "Darrick J. Wong" Subject: [PATCH v2 05/28] libext2fs: fix block leak when releasing xattr block Date: Tue, 3 Dec 2013 20:11:32 +0800 Message-Id: <1386072715-9869-6-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.9.7 In-Reply-To: <1386072715-9869-1-git-send-email-wenqing.lz@taobao.com> References: <1386072715-9869-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: "Darrick J. Wong" If in the process of writing EAs to an inode we discover that we no longer need the EA block, use the helper function to decrement the block's usage count and release it, instead of (brokenly) open-coding it. Also we need to decrement i_blocks when freeing the EA block. Signed-off-by: Darrick J. Wong --- lib/ext2fs/ext_attr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c index 94bc89b..3e09d58 100644 --- a/lib/ext2fs/ext_attr.c +++ b/lib/ext2fs/ext_attr.c @@ -315,6 +315,9 @@ errcode_t ext2fs_free_ext_attr(ext2_filsys fs, ext2_ino_t ino, ext2fs_file_acl_block_set(fs, (struct ext2_inode *)inode, 0); if (header->h_refcount == 0) ext2fs_block_alloc_stats2(fs, blk, -1); + err = ext2fs_iblk_sub_blocks(fs, (struct ext2_inode *)inode, 1); + if (err) + goto out2; /* Write inode? */ if (inode == &i) { @@ -549,13 +552,9 @@ skip_ea_block: blk = ext2fs_file_acl_block(handle->fs, (struct ext2_inode *)inode); if (!block_buf && blk) { /* xattrs shrunk, free the block */ - ext2fs_file_acl_block_set(handle->fs, - (struct ext2_inode *)inode, 0); - err = ext2fs_iblk_sub_blocks(handle->fs, - (struct ext2_inode *)inode, 1); + err = ext2fs_free_ext_attr(handle->fs, handle->ino, inode); if (err) goto out; - ext2fs_block_alloc_stats2(handle->fs, blk, -1); } /* Write the inode */