Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2153234imm; Mon, 3 Sep 2018 21:18:38 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb1kndgbVaYG2WHq0KM/F2VeYaPytIF+IkMWI0k6oLFoNrifhZ9cJyHNhjPCOKS4/S3iz66 X-Received: by 2002:a17:902:1c5:: with SMTP id b63-v6mr32288981plb.82.1536034718151; Mon, 03 Sep 2018 21:18:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536034718; cv=none; d=google.com; s=arc-20160816; b=AZWwhNhjlyAnE8DBeuRyrqCBrGBSB782iN9o4/MMf41P1DkmmJmJwjxoACWDzUYU3z KbxHRW2u+46DOsX6jo5RF3nECBzKEMX8cxZIlumXsQt6mnrASPMU8U6I81N+aXKrnTBR miT93uYkNx0y+9pZuXJdpvXLXZKNgAaiE7QvHtDD5W8DvpGCOsS/zjP7hncGU8Rm7XZy +rU7Xa5EaMzknuGleG/pHVCu4NiIwmbtPRyNUF7J/D6gQ23XKaknn56HDHHHGdsBzs2/ sASKmwUG/PNETDfEqwLtdyj1DvoxSlc3GTgtQt9aCD6agxj5+/CdEPNr4jr/UxaTrAsf BL4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=kd8hGUlGI9B103+6+XqoaBewOOhZJciMYDxbA1zg4Uo=; b=GIsqErfjD7PZWxucJaIufGxHIVf3khn7SttVDGzf5QTPL/hOnMwOXLsxbO/xqv7m3t xzLPar+rl+q1SguigbKLnfFrF9GjjTrBXBkZ7TUbeoDHFawn7cQV2WewAVCDxNs7qI4w hjts3HUd/DzLVFdq8NhU2quVZbTG7B0wtDy2YjUHALC0wGnNd8AYWOfZMqFdSI5XLXMX vJMmodxtrQb1nyBv7WAhOVYKJ3W3WGK3I4YjrsBXm3ZNfOZE4nZYOB2mLIN/qCHRAObp st1b0UYo2fxrLVgBWMHTw0OjJHSc10YVL/NUtjG7FHYcWJZzsdO8nnbuIOaqur6FcrJX UGuQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w133-v6si21085239pfd.313.2018.09.03.21.18.23; Mon, 03 Sep 2018 21:18:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbeIDIkJ (ORCPT + 99 others); Tue, 4 Sep 2018 04:40:09 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:37044 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725845AbeIDIkJ (ORCPT ); Tue, 4 Sep 2018 04:40:09 -0400 Received: from Beta.suse.asia (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Mon, 03 Sep 2018 22:16:44 -0600 From: Larry Chen To: mark@fasheh.com, jlbec@evilplan.org Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, akpm@linux-foundation.org Subject: [PATCH 2/2] fix clusters leak in ocfs2_defrag_extent Date: Tue, 4 Sep 2018 12:16:21 +0800 Message-Id: <20180904041621.16874-3-lchen@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180904041621.16874-1-lchen@suse.com> References: <20180904041621.16874-1-lchen@suse.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Larry Chen --- fs/ocfs2/move_extents.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c index d85dc8a02bd6..4f2ad054b419 100644 --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -226,6 +226,8 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, struct ocfs2_refcount_tree *ref_tree = NULL; u32 new_phys_cpos, new_len; u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos); + int need_free = 0; + struct ocfs2_alloc_context *data_ac; if ((ext_flags & OCFS2_EXT_REFCOUNTED) && *len) { BUG_ON(!ocfs2_is_refcount_inode(inode)); @@ -317,6 +319,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, if (!partial) { context->range->me_flags &= ~OCFS2_MOVE_EXT_FL_COMPLETE; ret = -ENOSPC; + need_free = 1; goto out_commit; } } @@ -341,6 +344,19 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context, mlog_errno(ret); out_commit: + if (need_free && context->data_ac) { + data_ac = context->data_ac; + if (context->data_ac->ac_which == OCFS2_AC_USE_LOCAL) + ocfs2_free_local_alloc_bits(osb, handle, data_ac, + new_phys_cpos, new_len); + else + ocfs2_free_clusters(handle, + data_ac->ac_inode, + data_ac->ac_bh, + ocfs2_clusters_to_blocks(osb->sb, new_phys_cpos), + new_len); + } + ocfs2_commit_trans(osb, handle); out_unlock_mutex: -- 2.13.7