From patchwork Thu Nov 1 21:15:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wengang Wang X-Patchwork-Id: 10664521 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 D28C014E2 for ; Thu, 1 Nov 2018 21:16:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C02642C2DB for ; Thu, 1 Nov 2018 21:16:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B198E2C348; Thu, 1 Nov 2018 21:16:32 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 36F262C2DB for ; Thu, 1 Nov 2018 21:16:32 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wA1L98rb190236; Thu, 1 Nov 2018 21:16:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : date : message-id : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : mime-version : content-type : content-transfer-encoding : sender; s=corp-2018-07-02; bh=yiBbHiJixikYfg7BVSP2CSOc82iYH22B+bCZ9T0xhUs=; b=rSs8EHmD5pXlscxvHVC5q7hNCAThr224wk5rHqO0pRLBlFBAdYQ2JZ205Avuvty/SgTH /uxsFEwwPx9xDK+ostIwVZLUSiaA0+AC7xVT+3SoPpzK8wDMnDtXjDxpEXoW5I8ux5d7 9oWzTgmtO09w4geRwKVD5kFvEI0yV+T4zbsKXKvzLvNcKYzO5mxw1c/w7zpX/RLts8Bu w3F9WfxvjdPU1338r+8rZak5+Qnu+Cp2wGbzEiVdAa3ygNXyadKM0Vibb693ZXTKkWST wrvWukmFdQL+sjoK/inQ3ExMzR8HqZwptiPjbI9muLc4kD+GKuHbq77BUsT8KCu9naiO BA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2ncgnrbbt0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Nov 2018 21:16:13 +0000 Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wA1LGAsN009812 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 1 Nov 2018 21:16:10 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 1gIKK2-000174-Ih; Thu, 01 Nov 2018 14:16:10 -0700 Received: from userv0021.oracle.com ([156.151.31.71]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1gIKJc-00016F-Tk for ocfs2-devel@oss.oracle.com; Thu, 01 Nov 2018 14:15:45 -0700 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id wA1LFi7S001864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 1 Nov 2018 21:15:44 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wA1LFhoh000933 for ; Thu, 1 Nov 2018 21:15:43 GMT Received: from oracle.com (/10.211.52.31) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 Nov 2018 14:15:43 -0700 From: Wengang Wang To: ocfs2-devel@oss.oracle.com Date: Thu, 1 Nov 2018 14:15:31 -0700 Message-Id: <20181101211531.21036-1-wen.gang.wang@oracle.com> X-Mailer: git-send-email 2.9.5 Subject: [Ocfs2-devel] [PATCH] ocfs2: free up write context when direct IO failed 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=9064 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1811010176 X-Virus-Scanned: ClamAV using ClamSMTP The write context should also be freed even when direct IO failed. Otherwise a memory leak is introduced and entries remain in oi->ip_unwritten_list causing the following BUG later in unlink path: ERROR: bug expression: !list_empty(&oi->ip_unwritten_list) ERROR: Clear inode of 215043, inode has unwritten extents ... Call Trace: ? __set_current_blocked+0x42/0x68 ocfs2_evict_inode+0x91/0x6a0 [ocfs2] ? bit_waitqueue+0x40/0x33 evict+0xdb/0x1af iput+0x1a2/0x1f7 do_unlinkat+0x194/0x28f SyS_unlinkat+0x1b/0x2f do_syscall_64+0x79/0x1ae entry_SYSCALL_64_after_hwframe+0x151/0x0 Signed-off-by: Wengang Wang Reviewed-by: Changwei Ge Acked-by: Joseph Qi --- fs/ocfs2/aops.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c index 302cd7c..a87ca42d 100644 --- a/fs/ocfs2/aops.c +++ b/fs/ocfs2/aops.c @@ -2412,8 +2412,15 @@ static int ocfs2_dio_end_io(struct kiocb *iocb, /* this io's submitter should not have unlocked this before we could */ BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); - if (bytes > 0 && private) - ret = ocfs2_dio_end_io_write(inode, private, offset, bytes); + if (private) { + if (bytes > 0) { + ret = ocfs2_dio_end_io_write(inode, private, offset, + bytes); + } else { + mlog(ML_ERROR, "Direct IO failed, free write ctx"); + ocfs2_dio_free_write_ctx(inode, private); + } + } ocfs2_iocb_clear_rw_locked(iocb);