From patchwork Tue Sep 4 04:16:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Larry Chen X-Patchwork-Id: 10586595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 044375A4 for ; Tue, 4 Sep 2018 04:18:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FBAE28E62 for ; Tue, 4 Sep 2018 04:18:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93D4F28E7C; Tue, 4 Sep 2018 04:18:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3160528E62 for ; Tue, 4 Sep 2018 04:18:11 +0000 (UTC) Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w844E3JD157099; Tue, 4 Sep 2018 04:18:02 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2m7jqpac8a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 04 Sep 2018 04:18:02 +0000 Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w844I0fM002859 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 4 Sep 2018 04:18:00 GMT Received: from localhost ([127.0.0.1] helo=lb-oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1fx2mt-0000FT-Nh; Mon, 03 Sep 2018 21:17:59 -0700 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1fx2lu-0000Bx-HO for ocfs2-devel@oss.oracle.com; Mon, 03 Sep 2018 21:16:58 -0700 Received: from userp2040.oracle.com (userp2040.oracle.com [156.151.31.90]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w844GwuD001109 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 4 Sep 2018 04:16:58 GMT Received: from pps.filterd (userp2040.oracle.com [127.0.0.1]) by userp2040.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w844EZqf045558 for ; Tue, 4 Sep 2018 04:16:58 GMT Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) by userp2040.oracle.com with ESMTP id 2m9d5qvf2r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 04 Sep 2018 04:16:57 +0000 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 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> X-CLX-Shades: MLX X-CLX-Response: 1TFkXGRkTEQpMehcYGRgRCllNF2dmchEKWUkXGnEaEBp3BhkbE3EbHxkTEBp 3BhgaBhoRClleF2hjeREKSUYXRVhLSUZPdVpYRU5fSV5DRUQZdU9LEQpDThd1RhJMHlxYbk4YXR piQnxTTRJBcGdSb3xBYWNgE31LUxEKWFwXHwQaBBseHwcfGklMSU4SGgUbGgQbGhoEHhIEGxAbH hofGhEKXlkXeV0cXHwRCk1cFx4fHhEKTFoXaGlNTV0RCkxGF2xraxEKQ1oXGxkdBBwfBBgfGgQS GxEKQl4XGxEKRF4XGBEKREkXGREKQkYXYml9ZUUYWhxNE2YRCkJcFxoRCkJFF3pme1gSW1N6bh0 eEQpCThdnHmAac0VMYUcBRBEKQkwXa1tebURFH0J8REURCkJsF2RdaHhaaFN9Z0ZhEQpCQBdlY2 JBe2VuTgFMbREKQlgXYn1veQFPGBlwcHsRClpYFxsRCnBoF2xdUHp4RFBhZF4dEBoRCnBoF24fH BNQYVIeX24aEBoRCnBoF2F6axxeaR9bX3tgEBoRCnBoF296QXJjZ0AFXngcEBoRCnBoF2t7bkNf aQUTHV1sEBoRCnBsF2wYR0FrY1NsRlBZEB0aEQptfhcaEQpYTRdLESA= X-PDR: PASS X-Source-IP: 137.65.250.81 X-ServerName: smtp2.provo.novell.com X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 include:novell.com ~all X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9005 signatures=668708 X-Proofpoint-DMARC-Record: none X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=232 malwarescore=0 suspectscore=8 phishscore=0 bulkscore=0 spamscore=0 clxscore=339 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=583 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809040043 X-Spam: Clean Cc: linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com Subject: [Ocfs2-devel] [PATCH 2/2] fix clusters leak in ocfs2_defrag_extent X-BeenThere: ocfs2-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9005 signatures=668708 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809040043 X-Virus-Scanned: ClamAV using ClamSMTP 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: