From patchwork Mon Nov 11 01:18:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11236393 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E137514ED for ; Mon, 11 Nov 2019 01:18:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BFA6F20818 for ; Mon, 11 Nov 2019 01:18:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ie+WnWyB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726749AbfKKBSz (ORCPT ); Sun, 10 Nov 2019 20:18:55 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:59400 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726733AbfKKBSz (ORCPT ); Sun, 10 Nov 2019 20:18:55 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAB1IfUS103186; Mon, 11 Nov 2019 01:18:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=g68DiiaT8O1lk4xUYpV3oDNMtp6Zx6+SjwS6WBflA5Q=; b=ie+WnWyBqtBBhhu28/CORuDZ10xNoMYvspQFGsk00414BVtBHz3nftTjbA1JDHKMeYJH 2bCWH1twSwW0OK6bY5lr/k+9ZeoHBfmKVCpEH4iv84yEC6JPCLgcxdEsyFBXkWxuFt5G ADl7vsMNc+BcwpzlQO3Y343WrcXMuRmFLXuLwTAEnq4SLgO6metxL94ozKBozRu8x5AU H4n4K7tvFIEC1AZG8SZliH8QqCLzSo0izDXao53rNAZRSHQu/Iq2tfXLPmB4mDnrkDI3 kN1nGihcWRDi1zA0LNu3kGAdcDe6n1l3zAT7iEyn//MoN4yOcD9x9JyMqHCDUV+hXUC5 kA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2w5ndpv4k9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Nov 2019 01:18:41 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAB1IdKV014910; Mon, 11 Nov 2019 01:18:40 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2w66wjehmb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Nov 2019 01:18:40 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xAB1IMGe017557; Mon, 11 Nov 2019 01:18:23 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 10 Nov 2019 17:18:22 -0800 Subject: [PATCH 1/3] xfs: actually check xfs_btree_check_block return in xfs_btree_islastblock From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Sun, 10 Nov 2019 17:18:21 -0800 Message-ID: <157343510150.1948946.270237649955385275.stgit@magnolia> In-Reply-To: <157343509505.1948946.5379830250503479422.stgit@magnolia> References: <157343509505.1948946.5379830250503479422.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9437 signatures=668685 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-1910280000 definitions=main-1911110009 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9437 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911110009 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Coverity points out that xfs_btree_islastblock doesn't check the return value of xfs_btree_check_block. Since the question "Does the cursor point to the last block in this level?" only makes sense if the caller previously performed a lookup or seek operation, the block should already have been checked. Therefore, check the return value in an ASSERT and turn the whole thing into a static inline predicate. Coverity-id: 114069 Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_btree.c | 19 ------------------- fs/xfs/libxfs/xfs_btree.h | 25 +++++++++++++++++-------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index feab5b307c45..3d48878ab298 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c @@ -714,25 +714,6 @@ xfs_btree_get_bufs( return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0); } -/* - * Check for the cursor referring to the last block at the given level. - */ -int /* 1=is last block, 0=not last block */ -xfs_btree_islastblock( - xfs_btree_cur_t *cur, /* btree cursor */ - int level) /* level to check */ -{ - struct xfs_btree_block *block; /* generic btree block pointer */ - xfs_buf_t *bp; /* buffer containing block */ - - block = xfs_btree_get_block(cur, level, &bp); - xfs_btree_check_block(cur, block, level, bp); - if (cur->bc_flags & XFS_BTREE_LONG_PTRS) - return block->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK); - else - return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK); -} - /* * Change the cursor to point to the first record at the given level. * Other levels are unaffected. diff --git a/fs/xfs/libxfs/xfs_btree.h b/fs/xfs/libxfs/xfs_btree.h index 6670120cd690..fb9b2121c628 100644 --- a/fs/xfs/libxfs/xfs_btree.h +++ b/fs/xfs/libxfs/xfs_btree.h @@ -317,14 +317,6 @@ xfs_btree_get_bufs( xfs_agnumber_t agno, /* allocation group number */ xfs_agblock_t agbno); /* allocation group block number */ -/* - * Check for the cursor referring to the last block at the given level. - */ -int /* 1=is last block, 0=not last block */ -xfs_btree_islastblock( - xfs_btree_cur_t *cur, /* btree cursor */ - int level); /* level to check */ - /* * Compute first and last byte offsets for the fields given. * Interprets the offsets table, which contains struct field offsets. @@ -524,4 +516,21 @@ int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low, union xfs_btree_irec *high, bool *exists); bool xfs_btree_has_more_records(struct xfs_btree_cur *cur); +/* Does this cursor point to the last block in the given level? */ +static inline bool +xfs_btree_islastblock( + xfs_btree_cur_t *cur, + int level) +{ + struct xfs_btree_block *block; + struct xfs_buf *bp; + + block = xfs_btree_get_block(cur, level, &bp); + ASSERT(block && xfs_btree_check_block(cur, block, level, bp) == 0); + + if (cur->bc_flags & XFS_BTREE_LONG_PTRS) + return block->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK); + return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK); +} + #endif /* __XFS_BTREE_H__ */ From patchwork Mon Nov 11 01:18:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11236385 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81DF61709 for ; Mon, 11 Nov 2019 01:18:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F7232080F for ; Mon, 11 Nov 2019 01:18:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="pCCp2HTp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726730AbfKKBSt (ORCPT ); Sun, 10 Nov 2019 20:18:49 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45390 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfKKBSs (ORCPT ); Sun, 10 Nov 2019 20:18:48 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAB1IUCu117132; Mon, 11 Nov 2019 01:18:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=PawLnizGg+VitxEOtEIvZO5KT41ozCnq8697IpT13V4=; b=pCCp2HTpRH6UrG1DMnbrA+y/Fp2jT1MEB7nQzk490YFgcWNzmCYRKqsoTV2hClURd1iw VRlsaMQ/tUoUGjAAXytbH5pBo3Vhsmh16EtfdcgYYebUk2FjKY8fgKQuOS7kIJmnmecf B0KU6QxyDDLpZ2zaqQOZkW3nc2oXXVM2+bT+GsEgOYZrdtvPxveRsI/WzsgAlEwKSNry C22LlWOVulDTEjfDiyg34Fvxqxg7Q7BEA0VImmyp8hqBWI/fxAASKV5/tHG91WKxFTWE aUw3eXsv/BZS7qAthFuU5jhYObx2kWW3OBL4ifM3SN2z3VkfCb1Z4OaI1Tf1cVlW6pSG wQ== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2w5mvtc666-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Nov 2019 01:18:38 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAB1Ib59091548; Mon, 11 Nov 2019 01:18:37 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2w66ytmfsk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Nov 2019 01:18:37 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id xAB1ITNh017631; Mon, 11 Nov 2019 01:18:29 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 10 Nov 2019 17:18:29 -0800 Subject: [PATCH 2/3] xfs: attach dquots and reserve quota blocks during unwritten conversion From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Sun, 10 Nov 2019 17:18:27 -0800 Message-ID: <157343510780.1948946.16275987302017348487.stgit@magnolia> In-Reply-To: <157343509505.1948946.5379830250503479422.stgit@magnolia> References: <157343509505.1948946.5379830250503479422.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9437 signatures=668685 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-1910280000 definitions=main-1911110009 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9437 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911110009 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong In xfs_iomap_write_unwritten, we need to ensure that dquots are attached to the inode and quota blocks reserved so that we capture in the quota counters any blocks allocated to handle a bmbt split. This can happen on the first unwritten extent conversion to a preallocated sparse file on a fresh mount. This was found by running generic/311 with quotas enabled. The bug seems to have been introduced in "[XFS] rework iocore infrastructure, remove some code and make it more" from ~2002? Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_iomap.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index f234929b4f15..97dbe3b2aec0 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -539,6 +539,11 @@ xfs_iomap_write_unwritten( */ resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1; + /* Attach dquots so that bmbt splits are accounted correctly. */ + error = xfs_qm_dqattach(ip); + if (error) + return error; + do { /* * Set up a transaction to convert the range of extents @@ -557,6 +562,11 @@ xfs_iomap_write_unwritten( xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, 0); + error = xfs_trans_reserve_quota_nblks(tp, ip, resblks, 0, + XFS_QMOPT_RES_REGBLKS); + if (error) + goto error_on_bmapi_transaction; + /* * Modify the unwritten extent state of the buffer. */ From patchwork Mon Nov 11 01:18:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11236387 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C06EC14ED for ; Mon, 11 Nov 2019 01:18:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9CF4A206DF for ; Mon, 11 Nov 2019 01:18:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="gifH3lhU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726734AbfKKBSv (ORCPT ); Sun, 10 Nov 2019 20:18:51 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:45434 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfKKBSv (ORCPT ); Sun, 10 Nov 2019 20:18:51 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAB1IeUJ117231; Mon, 11 Nov 2019 01:18:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=JvOGjkHvnZHGZd3uwCy5qN+1lypDHLePCE8ExBJ9cG8=; b=gifH3lhUfx/cRWB23JNw5xb5EwGEExbCtvJWSsLAWMLHy3dxAzNdsKN2b9sEom6zBACZ +uzg/DV5HSz7+MJ82uD2vMMxoFN3KeSpm3DQvV81ThRTgwG0qIsgQVw3TcdeCtgewHko g5ZsOeMHrhcwt0qkD9Wm1As0XtnELtSk2jUEli7RV603M8T0FTB5B6N14e+gYTr/Ithf yi/E6jqQeAJy13URM9UUd6BiEddMq8Z3JEu7TY0KUbCdWw8JBk7mO5l5gDqPRuoNlbp6 b9Sfo4SwYZk807/rkVAO6e8vYojN4MRh9EdzoNe+APUEI31U5G+sqizDTDEFl6PxlHrd ww== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2w5mvtc66m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Nov 2019 01:18:40 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAB1IbAO091617; Mon, 11 Nov 2019 01:18:39 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2w66ytmft6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Nov 2019 01:18:38 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xAB1IZYG021854; Mon, 11 Nov 2019 01:18:35 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 10 Nov 2019 17:18:35 -0800 Subject: [PATCH 3/3] xfs: attach dquots before performing xfs_swap_extents From: "Darrick J. Wong" To: darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, hch@infradead.org Date: Sun, 10 Nov 2019 17:18:34 -0800 Message-ID: <157343511427.1948946.2692071497822316839.stgit@magnolia> In-Reply-To: <157343509505.1948946.5379830250503479422.stgit@magnolia> References: <157343509505.1948946.5379830250503479422.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9437 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=844 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911110009 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9437 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=915 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1910280000 definitions=main-1911110009 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Make sure we attach dquots to both inodes before swapping their extents. This was found via manual code inspection by looking for places where we could call xfs_trans_mod_dquot without dquots attached to inodes, and confirmed by instrumenting the kernel and running xfs/328. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_bmap_util.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 9d731b71e84f..2efd78a9719e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c @@ -1569,6 +1569,14 @@ xfs_swap_extents( goto out_unlock; } + error = xfs_qm_dqattach(ip); + if (error) + goto out_unlock; + + error = xfs_qm_dqattach(tip); + if (error) + goto out_unlock; + error = xfs_swap_extent_flush(ip); if (error) goto out_unlock;