From patchwork Thu Feb 16 20:32:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143752 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81666C61DA4 for ; Thu, 16 Feb 2023 20:33:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbjBPUdC (ORCPT ); Thu, 16 Feb 2023 15:33:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjBPUdB (ORCPT ); Thu, 16 Feb 2023 15:33:01 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 214732A6E0 for ; Thu, 16 Feb 2023 12:32:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AC9CC60C1D for ; Thu, 16 Feb 2023 20:32:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17141C433EF; Thu, 16 Feb 2023 20:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579576; bh=aZQMgoY5g4iTqpy59rV7S59r7MCGWV3xg3W8wtmf8Kc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uCdXIJcB1bV6jSfnQbwe4KiiLXQan4Vk5cjOBJX7UVA41GoW89aQnC1fAqWrPjLjY sWBMPLei2385RnVCJE6wewDJgfgvAkKN9XeVh56/2PUQ+tea+Mn/zr5taP9ZdBLbpe b2aQxpMzrwsS196Yv41WWZ6EazpgdYNZoyNA9ZMXB7bDJzZ7rcIZQdUJkBnZhllzML 4Ukg6cjxqho1/1b+y1Vc//g8mqJhgXVq4W3x9znHAI1YN8gxvOMkVIslX0Ps76pqOT xcUy9L6exrq5qjC8wyQE8cBVuN75+dUVgeuICfe3tsj3kGmdIEVupgQScy2sRw5+gN /Lz+OdG9/u1+A== Date: Thu, 16 Feb 2023 12:32:55 -0800 Subject: [PATCH 01/28] xfs: Add new name to attri/d From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872379.3473407.3201439810984462738.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson This patch adds two new fields to the atti/d. They are nname and nnamelen. This will be used for parent pointer updates since a rename operation may cause the parent pointer to update both the name and value. So we need to carry both the new name as well as the target name in the attri/d. Signed-off-by: Allison Henderson --- fs/xfs/libxfs/xfs_attr.c | 12 +++- fs/xfs/libxfs/xfs_attr.h | 4 + fs/xfs/libxfs/xfs_da_btree.h | 2 + fs/xfs/libxfs/xfs_log_format.h | 6 +- fs/xfs/xfs_attr_item.c | 135 +++++++++++++++++++++++++++++++++------- fs/xfs/xfs_attr_item.h | 1 6 files changed, 133 insertions(+), 27 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index e28d93d232de..b1dbed7655e8 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -423,6 +423,12 @@ xfs_attr_complete_op( args->op_flags &= ~XFS_DA_OP_REPLACE; if (do_replace) { args->attr_filter &= ~XFS_ATTR_INCOMPLETE; + if (args->new_namelen > 0) { + args->name = args->new_name; + args->namelen = args->new_namelen; + args->hashval = xfs_da_hashname(args->name, + args->namelen); + } return replace_state; } return XFS_DAS_DONE; @@ -922,9 +928,13 @@ xfs_attr_defer_replace( struct xfs_da_args *args) { struct xfs_attr_intent *new; + int op_flag; int error = 0; - error = xfs_attr_intent_init(args, XFS_ATTRI_OP_FLAGS_REPLACE, &new); + op_flag = args->new_namelen == 0 ? XFS_ATTRI_OP_FLAGS_REPLACE : + XFS_ATTRI_OP_FLAGS_NVREPLACE; + + error = xfs_attr_intent_init(args, op_flag, &new); if (error) return error; diff --git a/fs/xfs/libxfs/xfs_attr.h b/fs/xfs/libxfs/xfs_attr.h index 81be9b3e4004..3e81f3f48560 100644 --- a/fs/xfs/libxfs/xfs_attr.h +++ b/fs/xfs/libxfs/xfs_attr.h @@ -510,8 +510,8 @@ struct xfs_attr_intent { struct xfs_da_args *xattri_da_args; /* - * Shared buffer containing the attr name and value so that the logging - * code can share large memory buffers between log items. + * Shared buffer containing the attr name, new name, and value so that + * the logging code can share large memory buffers between log items. */ struct xfs_attri_log_nameval *xattri_nameval; diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h index ffa3df5b2893..a4b29827603f 100644 --- a/fs/xfs/libxfs/xfs_da_btree.h +++ b/fs/xfs/libxfs/xfs_da_btree.h @@ -55,7 +55,9 @@ enum xfs_dacmp { typedef struct xfs_da_args { struct xfs_da_geometry *geo; /* da block geometry */ const uint8_t *name; /* string (maybe not NULL terminated) */ + const uint8_t *new_name; /* new attr name */ int namelen; /* length of string (maybe no NULL) */ + int new_namelen; /* new attr name len */ uint8_t filetype; /* filetype of inode for directories */ void *value; /* set of bytes (maybe contain NULLs) */ int valuelen; /* length of value */ diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index f13e0809dc63..ae9c99762a24 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -117,7 +117,8 @@ struct xfs_unmount_log_format { #define XLOG_REG_TYPE_ATTRD_FORMAT 28 #define XLOG_REG_TYPE_ATTR_NAME 29 #define XLOG_REG_TYPE_ATTR_VALUE 30 -#define XLOG_REG_TYPE_MAX 30 +#define XLOG_REG_TYPE_ATTR_NNAME 31 +#define XLOG_REG_TYPE_MAX 31 /* @@ -957,6 +958,7 @@ struct xfs_icreate_log { #define XFS_ATTRI_OP_FLAGS_SET 1 /* Set the attribute */ #define XFS_ATTRI_OP_FLAGS_REMOVE 2 /* Remove the attribute */ #define XFS_ATTRI_OP_FLAGS_REPLACE 3 /* Replace the attribute */ +#define XFS_ATTRI_OP_FLAGS_NVREPLACE 4 /* Replace attr name and val */ #define XFS_ATTRI_OP_FLAGS_TYPE_MASK 0xFF /* Flags type mask */ /* @@ -974,7 +976,7 @@ struct xfs_icreate_log { struct xfs_attri_log_format { uint16_t alfi_type; /* attri log item type */ uint16_t alfi_size; /* size of this item */ - uint32_t __pad; /* pad to 64 bit aligned */ + uint32_t alfi_nname_len; /* attr new name length */ uint64_t alfi_id; /* attri identifier */ uint64_t alfi_ino; /* the inode for this attr operation */ uint32_t alfi_op_flags; /* marks the op as a set or remove */ diff --git a/fs/xfs/xfs_attr_item.c b/fs/xfs/xfs_attr_item.c index 2788a6f2edcd..95e9ecbb4a67 100644 --- a/fs/xfs/xfs_attr_item.c +++ b/fs/xfs/xfs_attr_item.c @@ -75,6 +75,8 @@ static inline struct xfs_attri_log_nameval * xfs_attri_log_nameval_alloc( const void *name, unsigned int name_len, + const void *nname, + unsigned int nname_len, const void *value, unsigned int value_len) { @@ -85,15 +87,25 @@ xfs_attri_log_nameval_alloc( * this. But kvmalloc() utterly sucks, so we use our own version. */ nv = xlog_kvmalloc(sizeof(struct xfs_attri_log_nameval) + - name_len + value_len); + name_len + nname_len + value_len); nv->name.i_addr = nv + 1; nv->name.i_len = name_len; nv->name.i_type = XLOG_REG_TYPE_ATTR_NAME; memcpy(nv->name.i_addr, name, name_len); + if (nname_len) { + nv->nname.i_addr = nv->name.i_addr + name_len; + nv->nname.i_len = nname_len; + memcpy(nv->nname.i_addr, nname, nname_len); + } else { + nv->nname.i_addr = NULL; + nv->nname.i_len = 0; + } + nv->nname.i_type = XLOG_REG_TYPE_ATTR_NNAME; + if (value_len) { - nv->value.i_addr = nv->name.i_addr + name_len; + nv->value.i_addr = nv->name.i_addr + nname_len + name_len; nv->value.i_len = value_len; memcpy(nv->value.i_addr, value, value_len); } else { @@ -147,11 +159,15 @@ xfs_attri_item_size( *nbytes += sizeof(struct xfs_attri_log_format) + xlog_calc_iovec_len(nv->name.i_len); - if (!nv->value.i_len) - return; + if (nv->nname.i_len) { + *nvecs += 1; + *nbytes += xlog_calc_iovec_len(nv->nname.i_len); + } - *nvecs += 1; - *nbytes += xlog_calc_iovec_len(nv->value.i_len); + if (nv->value.i_len) { + *nvecs += 1; + *nbytes += xlog_calc_iovec_len(nv->value.i_len); + } } /* @@ -181,6 +197,9 @@ xfs_attri_item_format( ASSERT(nv->name.i_len > 0); attrip->attri_format.alfi_size++; + if (nv->nname.i_len > 0) + attrip->attri_format.alfi_size++; + if (nv->value.i_len > 0) attrip->attri_format.alfi_size++; @@ -188,6 +207,10 @@ xfs_attri_item_format( &attrip->attri_format, sizeof(struct xfs_attri_log_format)); xlog_copy_from_iovec(lv, &vecp, &nv->name); + + if (nv->nname.i_len > 0) + xlog_copy_from_iovec(lv, &vecp, &nv->nname); + if (nv->value.i_len > 0) xlog_copy_from_iovec(lv, &vecp, &nv->value); } @@ -374,6 +397,7 @@ xfs_attr_log_item( attrp->alfi_op_flags = attr->xattri_op_flags; attrp->alfi_value_len = attr->xattri_nameval->value.i_len; attrp->alfi_name_len = attr->xattri_nameval->name.i_len; + attrp->alfi_nname_len = attr->xattri_nameval->nname.i_len; ASSERT(!(attr->xattri_da_args->attr_filter & ~XFS_ATTRI_FILTER_MASK)); attrp->alfi_attr_filter = attr->xattri_da_args->attr_filter; } @@ -415,7 +439,8 @@ xfs_attr_create_intent( * deferred work state structure. */ attr->xattri_nameval = xfs_attri_log_nameval_alloc(args->name, - args->namelen, args->value, args->valuelen); + args->namelen, args->new_name, + args->new_namelen, args->value, args->valuelen); } attrip = xfs_attri_init(mp, attr->xattri_nameval); @@ -503,7 +528,8 @@ xfs_attri_validate( unsigned int op = attrp->alfi_op_flags & XFS_ATTRI_OP_FLAGS_TYPE_MASK; - if (attrp->__pad != 0) + if (attrp->alfi_op_flags != XFS_ATTRI_OP_FLAGS_NVREPLACE && + attrp->alfi_nname_len != 0) return false; if (attrp->alfi_op_flags & ~XFS_ATTRI_OP_FLAGS_TYPE_MASK) @@ -517,6 +543,7 @@ xfs_attri_validate( case XFS_ATTRI_OP_FLAGS_SET: case XFS_ATTRI_OP_FLAGS_REPLACE: case XFS_ATTRI_OP_FLAGS_REMOVE: + case XFS_ATTRI_OP_FLAGS_NVREPLACE: break; default: return false; @@ -526,9 +553,14 @@ xfs_attri_validate( return false; if ((attrp->alfi_name_len > XATTR_NAME_MAX) || + (attrp->alfi_nname_len > XATTR_NAME_MAX) || (attrp->alfi_name_len == 0)) return false; + if (op == XFS_ATTRI_OP_FLAGS_REMOVE && + attrp->alfi_value_len != 0) + return false; + return xfs_verify_ino(mp, attrp->alfi_ino); } @@ -589,6 +621,8 @@ xfs_attri_item_recover( args->whichfork = XFS_ATTR_FORK; args->name = nv->name.i_addr; args->namelen = nv->name.i_len; + args->new_name = nv->nname.i_addr; + args->new_namelen = nv->nname.i_len; args->hashval = xfs_da_hashname(args->name, args->namelen); args->attr_filter = attrp->alfi_attr_filter & XFS_ATTRI_FILTER_MASK; args->op_flags = XFS_DA_OP_RECOVERY | XFS_DA_OP_OKNOENT | @@ -599,6 +633,7 @@ xfs_attri_item_recover( switch (attr->xattri_op_flags) { case XFS_ATTRI_OP_FLAGS_SET: case XFS_ATTRI_OP_FLAGS_REPLACE: + case XFS_ATTRI_OP_FLAGS_NVREPLACE: args->value = nv->value.i_addr; args->valuelen = nv->value.i_len; args->total = xfs_attr_calc_size(args, &local); @@ -688,6 +723,7 @@ xfs_attri_item_relog( new_attrp->alfi_op_flags = old_attrp->alfi_op_flags; new_attrp->alfi_value_len = old_attrp->alfi_value_len; new_attrp->alfi_name_len = old_attrp->alfi_name_len; + new_attrp->alfi_nname_len = old_attrp->alfi_nname_len; new_attrp->alfi_attr_filter = old_attrp->alfi_attr_filter; xfs_trans_add_item(tp, &new_attrip->attri_item); @@ -710,48 +746,102 @@ xlog_recover_attri_commit_pass2( const void *attr_value = NULL; const void *attr_name; size_t len; - - attri_formatp = item->ri_buf[0].i_addr; - attr_name = item->ri_buf[1].i_addr; + const void *attr_nname = NULL; + int op, i = 0; /* Validate xfs_attri_log_format before the large memory allocation */ len = sizeof(struct xfs_attri_log_format); - if (item->ri_buf[0].i_len != len) { + if (item->ri_buf[i].i_len != len) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[0].i_addr, item->ri_buf[0].i_len); + item->ri_buf[i].i_addr, item->ri_buf[i].i_len); return -EFSCORRUPTED; } + attri_formatp = item->ri_buf[i].i_addr; if (!xfs_attri_validate(mp, attri_formatp)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[0].i_addr, item->ri_buf[0].i_len); + item->ri_buf[i].i_addr, item->ri_buf[i].i_len); return -EFSCORRUPTED; } + op = attri_formatp->alfi_op_flags & XFS_ATTRI_OP_FLAGS_TYPE_MASK; + switch (op) { + case XFS_ATTRI_OP_FLAGS_SET: + case XFS_ATTRI_OP_FLAGS_REPLACE: + if (item->ri_total != 3) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + attri_formatp, len); + return -EFSCORRUPTED; + } + break; + case XFS_ATTRI_OP_FLAGS_REMOVE: + if (item->ri_total != 2) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + attri_formatp, len); + return -EFSCORRUPTED; + } + break; + case XFS_ATTRI_OP_FLAGS_NVREPLACE: + if (item->ri_total != 4) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + attri_formatp, len); + return -EFSCORRUPTED; + } + break; + default: + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + attri_formatp, len); + return -EFSCORRUPTED; + } + + i++; /* Validate the attr name */ - if (item->ri_buf[1].i_len != + if (item->ri_buf[i].i_len != xlog_calc_iovec_len(attri_formatp->alfi_name_len)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[0].i_addr, item->ri_buf[0].i_len); + attri_formatp, len); return -EFSCORRUPTED; } + attr_name = item->ri_buf[i].i_addr; if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[1].i_addr, item->ri_buf[1].i_len); + item->ri_buf[i].i_addr, item->ri_buf[i].i_len); return -EFSCORRUPTED; } + i++; + if (attri_formatp->alfi_nname_len) { + /* Validate the attr nname */ + if (item->ri_buf[i].i_len != + xlog_calc_iovec_len(attri_formatp->alfi_nname_len)) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + item->ri_buf[i].i_addr, + item->ri_buf[i].i_len); + return -EFSCORRUPTED; + } + + attr_nname = item->ri_buf[i].i_addr; + if (!xfs_attr_namecheck(attr_nname, + attri_formatp->alfi_nname_len)) { + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, + item->ri_buf[i].i_addr, + item->ri_buf[i].i_len); + return -EFSCORRUPTED; + } + i++; + } + + /* Validate the attr value, if present */ if (attri_formatp->alfi_value_len != 0) { - if (item->ri_buf[2].i_len != xlog_calc_iovec_len(attri_formatp->alfi_value_len)) { + if (item->ri_buf[i].i_len != xlog_calc_iovec_len(attri_formatp->alfi_value_len)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, - item->ri_buf[0].i_addr, - item->ri_buf[0].i_len); + attri_formatp, len); return -EFSCORRUPTED; } - attr_value = item->ri_buf[2].i_addr; + attr_value = item->ri_buf[i].i_addr; } /* @@ -760,7 +850,8 @@ xlog_recover_attri_commit_pass2( * reference. */ nv = xfs_attri_log_nameval_alloc(attr_name, - attri_formatp->alfi_name_len, attr_value, + attri_formatp->alfi_name_len, attr_nname, + attri_formatp->alfi_nname_len, attr_value, attri_formatp->alfi_value_len); attrip = xfs_attri_init(mp, nv); diff --git a/fs/xfs/xfs_attr_item.h b/fs/xfs/xfs_attr_item.h index 3280a7930287..24d4968dd6cc 100644 --- a/fs/xfs/xfs_attr_item.h +++ b/fs/xfs/xfs_attr_item.h @@ -13,6 +13,7 @@ struct kmem_zone; struct xfs_attri_log_nameval { struct xfs_log_iovec name; + struct xfs_log_iovec nname; struct xfs_log_iovec value; refcount_t refcount; From patchwork Thu Feb 16 20:33:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3209AC636CC for ; Thu, 16 Feb 2023 20:33:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbjBPUdO (ORCPT ); Thu, 16 Feb 2023 15:33:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjBPUdN (ORCPT ); Thu, 16 Feb 2023 15:33:13 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 023D45589 for ; Thu, 16 Feb 2023 12:33:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 90FBA60A3B for ; Thu, 16 Feb 2023 20:33:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F19FFC433EF; Thu, 16 Feb 2023 20:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579592; bh=qEEX9yu/yN1YPXkk6ytKUPOEZ2JLmz86BaxWjcTF1WA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=iMk9lRrc++hW6ZuhREb+ziWKkeJr6fayzUn//c87faW0UM87ePQBvBK3s4W8tSqSC SVGZu1ZqetE9WHJGXhqdHv4UWROwZ7XxBEnWQTwD3jpWbitc1MHDV3n456i/yQq53R A23BU9SfvXV9mZ8yzI4j6jM2PJABDggO6scxauzrsjx6qowYFvpe34Xq5xZDgtkLll g6Ub+LwXICez/hEbLCZPlO+h/VKa8/BoGlJGr4MF/s80J7hRWeHJoddh3XyTwWtSJ6 4UvAU1SSfQxyLhps3D+ZNvXiIy5wRUjTumrCIE/nrCzmSX6Thb0Lnrd5FEPZKH1l/Z W8UfDQx8drxHA== Date: Thu, 16 Feb 2023 12:33:11 -0800 Subject: [PATCH 02/28] xfs: Increase XFS_DEFER_OPS_NR_INODES to 5 From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , Catherine Hoang , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872394.3473407.14758300418831859650.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Renames that generate parent pointer updates can join up to 5 inodes locked in sorted order. So we need to increase the number of defer ops inodes and relock them in the same way. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang --- fs/xfs/libxfs/xfs_defer.c | 28 ++++++++++++++++++++++++++-- fs/xfs/libxfs/xfs_defer.h | 8 +++++++- fs/xfs/xfs_inode.c | 2 +- fs/xfs/xfs_inode.h | 1 + 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_defer.c b/fs/xfs/libxfs/xfs_defer.c index 5a321b783398..c0279b57e51d 100644 --- a/fs/xfs/libxfs/xfs_defer.c +++ b/fs/xfs/libxfs/xfs_defer.c @@ -820,13 +820,37 @@ xfs_defer_ops_continue( struct xfs_trans *tp, struct xfs_defer_resources *dres) { - unsigned int i; + unsigned int i, j; + struct xfs_inode *sips[XFS_DEFER_OPS_NR_INODES]; + struct xfs_inode *temp; ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES); ASSERT(!(tp->t_flags & XFS_TRANS_DIRTY)); /* Lock the captured resources to the new transaction. */ - if (dfc->dfc_held.dr_inos == 2) + if (dfc->dfc_held.dr_inos > 2) { + /* + * Renames with parent pointer updates can lock up to 5 inodes, + * sorted by their inode number. So we need to make sure they + * are relocked in the same way. + */ + memset(sips, 0, sizeof(sips)); + for (i = 0; i < dfc->dfc_held.dr_inos; i++) + sips[i] = dfc->dfc_held.dr_ip[i]; + + /* Bubble sort of at most 5 inodes */ + for (i = 0; i < dfc->dfc_held.dr_inos; i++) { + for (j = 1; j < dfc->dfc_held.dr_inos; j++) { + if (sips[j]->i_ino < sips[j-1]->i_ino) { + temp = sips[j]; + sips[j] = sips[j-1]; + sips[j-1] = temp; + } + } + } + + xfs_lock_inodes(sips, dfc->dfc_held.dr_inos, XFS_ILOCK_EXCL); + } else if (dfc->dfc_held.dr_inos == 2) xfs_lock_two_inodes(dfc->dfc_held.dr_ip[0], XFS_ILOCK_EXCL, dfc->dfc_held.dr_ip[1], XFS_ILOCK_EXCL); else if (dfc->dfc_held.dr_inos == 1) diff --git a/fs/xfs/libxfs/xfs_defer.h b/fs/xfs/libxfs/xfs_defer.h index 114a3a4930a3..fdf6941f8f4d 100644 --- a/fs/xfs/libxfs/xfs_defer.h +++ b/fs/xfs/libxfs/xfs_defer.h @@ -70,7 +70,13 @@ extern const struct xfs_defer_op_type xfs_attr_defer_type; /* * Deferred operation item relogging limits. */ -#define XFS_DEFER_OPS_NR_INODES 2 /* join up to two inodes */ + +/* + * Rename w/ parent pointers can require up to 5 inodes with deferred ops to + * be joined to the transaction: src_dp, target_dp, src_ip, target_ip, and wip. + * These inodes are locked in sorted order by their inode numbers + */ +#define XFS_DEFER_OPS_NR_INODES 5 #define XFS_DEFER_OPS_NR_BUFS 2 /* join up to two buffers */ /* Resources that must be held across a transaction roll. */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index d354ea2b74f9..27532053a67b 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -447,7 +447,7 @@ xfs_lock_inumorder( * lock more than one at a time, lockdep will report false positives saying we * have violated locking orders. */ -static void +void xfs_lock_inodes( struct xfs_inode **ips, int inodes, diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index fa780f08dc89..2eaed98af814 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -574,5 +574,6 @@ void xfs_end_io(struct work_struct *work); int xfs_ilock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2); void xfs_iunlock2_io_mmap(struct xfs_inode *ip1, struct xfs_inode *ip2); +void xfs_lock_inodes(struct xfs_inode **ips, int inodes, uint lock_mode); #endif /* __XFS_INODE_H__ */ From patchwork Thu Feb 16 20:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99AAEC636CC for ; Thu, 16 Feb 2023 20:33:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229653AbjBPUda (ORCPT ); Thu, 16 Feb 2023 15:33:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjBPUda (ORCPT ); Thu, 16 Feb 2023 15:33:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A395F7288 for ; Thu, 16 Feb 2023 12:33:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 470A460AB9 for ; Thu, 16 Feb 2023 20:33:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8736C433EF; Thu, 16 Feb 2023 20:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579607; bh=1EdUW1nDJ8piaVeb4s0J1VgmztjJUps3uGVIIaIA/oM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=oxIke+tX9PQIXPvLKVZPcL9+RIC+XcGvR6TcjI6YIJQ4hb7GR+asy3K+51k6GhOxj mxI1W+ExFC7wbEjzAZY89ejFZ08i9w4S5Vq560sZlnfAhS5rzdQp7ZjbVMnBr6Pf5b BIDJYRsXWhiaoWHCpjOJSeIlIypJYept3XC/YWMqxP02uWVeAJaFW7gBei/YYroZ28 l36Y1gwqyvzEIbAVJcAFjHaqsX7NnWq0Ypgw9mEku1tqPXT7F21+a0eV6vNctQw2X5 IqLBw3KVx1z2NWYBSqigWanZWfbo9DZlHRcYUtOLfsmQF2ncKoGKZi3cGhedltMhiF 7+grjoAQCWNdA== Date: Thu, 16 Feb 2023 12:33:27 -0800 Subject: [PATCH 03/28] xfs: Increase XFS_QM_TRANS_MAXDQS to 5 From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872409.3473407.17009064808697145467.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson With parent pointers enabled, a rename operation can update up to 5 inodes: src_dp, target_dp, src_ip, target_ip and wip. This causes their dquots to a be attached to the transaction chain, so we need to increase XFS_QM_TRANS_MAXDQS. This patch also add a helper function xfs_dqlockn to lock an arbitrary number of dquots. Signed-off-by: Allison Henderson --- fs/xfs/xfs_dquot.c | 38 ++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_dquot.h | 1 + fs/xfs/xfs_qm.h | 2 +- fs/xfs/xfs_trans_dquot.c | 15 ++++++++++----- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c index 8fb90da89787..9f311729c4c8 100644 --- a/fs/xfs/xfs_dquot.c +++ b/fs/xfs/xfs_dquot.c @@ -1333,6 +1333,44 @@ xfs_dqlock2( } } +static int +xfs_dqtrx_cmp( + const void *a, + const void *b) +{ + const struct xfs_dqtrx *qa = a; + const struct xfs_dqtrx *qb = b; + + if (qa->qt_dquot->q_id > qb->qt_dquot->q_id) + return 1; + if (qa->qt_dquot->q_id < qb->qt_dquot->q_id) + return -1; + return 0; +} + +void +xfs_dqlockn( + struct xfs_dqtrx *q) +{ + unsigned int i; + + /* Sort in order of dquot id, do not allow duplicates */ + for (i = 0; i < XFS_QM_TRANS_MAXDQS && q[i].qt_dquot != NULL; i++) { + unsigned int j; + + for (j = 0; j < i; j++) + ASSERT(q[i].qt_dquot != q[j].qt_dquot); + } + if (i == 0) + return; + + sort(q, i, sizeof(struct xfs_dqtrx), xfs_dqtrx_cmp, NULL); + + mutex_lock(&q[0].qt_dquot->q_qlock); + for (i = 1; i < XFS_QM_TRANS_MAXDQS && q[i].qt_dquot != NULL; i++) + mutex_lock_nested(&q[i].qt_dquot->q_qlock, XFS_QLOCK_NESTED); +} + int __init xfs_qm_init(void) { diff --git a/fs/xfs/xfs_dquot.h b/fs/xfs/xfs_dquot.h index 80c8f851a2f3..dc7d0226242b 100644 --- a/fs/xfs/xfs_dquot.h +++ b/fs/xfs/xfs_dquot.h @@ -223,6 +223,7 @@ int xfs_qm_dqget_uncached(struct xfs_mount *mp, void xfs_qm_dqput(struct xfs_dquot *dqp); void xfs_dqlock2(struct xfs_dquot *, struct xfs_dquot *); +void xfs_dqlockn(struct xfs_dqtrx *q); void xfs_dquot_set_prealloc_limits(struct xfs_dquot *); diff --git a/fs/xfs/xfs_qm.h b/fs/xfs/xfs_qm.h index 9683f0457d19..c6ec88779356 100644 --- a/fs/xfs/xfs_qm.h +++ b/fs/xfs/xfs_qm.h @@ -120,7 +120,7 @@ enum { XFS_QM_TRANS_PRJ, XFS_QM_TRANS_DQTYPES }; -#define XFS_QM_TRANS_MAXDQS 2 +#define XFS_QM_TRANS_MAXDQS 5 struct xfs_dquot_acct { struct xfs_dqtrx dqs[XFS_QM_TRANS_DQTYPES][XFS_QM_TRANS_MAXDQS]; }; diff --git a/fs/xfs/xfs_trans_dquot.c b/fs/xfs/xfs_trans_dquot.c index aa00cf67ad72..8a48175ea3a7 100644 --- a/fs/xfs/xfs_trans_dquot.c +++ b/fs/xfs/xfs_trans_dquot.c @@ -268,24 +268,29 @@ xfs_trans_mod_dquot( /* * Given an array of dqtrx structures, lock all the dquots associated and join - * them to the transaction, provided they have been modified. We know that the - * highest number of dquots of one type - usr, grp and prj - involved in a - * transaction is 3 so we don't need to make this very generic. + * them to the transaction, provided they have been modified. */ STATIC void xfs_trans_dqlockedjoin( struct xfs_trans *tp, struct xfs_dqtrx *q) { + unsigned int i; ASSERT(q[0].qt_dquot != NULL); if (q[1].qt_dquot == NULL) { xfs_dqlock(q[0].qt_dquot); xfs_trans_dqjoin(tp, q[0].qt_dquot); - } else { - ASSERT(XFS_QM_TRANS_MAXDQS == 2); + } else if (q[2].qt_dquot == NULL) { xfs_dqlock2(q[0].qt_dquot, q[1].qt_dquot); xfs_trans_dqjoin(tp, q[0].qt_dquot); xfs_trans_dqjoin(tp, q[1].qt_dquot); + } else { + xfs_dqlockn(q); + for (i = 0; i < XFS_QM_TRANS_MAXDQS; i++) { + if (q[i].qt_dquot == NULL) + break; + xfs_trans_dqjoin(tp, q[i].qt_dquot); + } } } From patchwork Thu Feb 16 20:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 527C1C6379F for ; Thu, 16 Feb 2023 20:33:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbjBPUdr (ORCPT ); Thu, 16 Feb 2023 15:33:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbjBPUdq (ORCPT ); Thu, 16 Feb 2023 15:33:46 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9077D505 for ; Thu, 16 Feb 2023 12:33:45 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 82F71B826BA for ; Thu, 16 Feb 2023 20:33:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43818C433EF; Thu, 16 Feb 2023 20:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579623; bh=DfbJCu3FjXlxQrtguuDYk9tELvdTTZpXREPQ3LQ242Y=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=rz39Qn+3Tn74Wltnb5IqNf8y9IMEMahmQbBY3YkFsROIwXWxgnftnD8gNCVR8PYeU e6LFfmG1tEYBltsqrdA7a8FnK4KlDoZPda3HzP9zE0K9jBd5ofqKI5KT+sBaUKrA+L JhXMJ6bNT5XEU6RsPQiLkC8mWtvLrnHOji9YXqJizdElet0Z0Mob3za0m8Pz/vyREQ gCExzC4BBWzcwCX8qLY3Y3fg8q6+7vnZuOXZtzqKIOEFZF2qotfzq5vcpRjDkWQQV5 Llul48b2FN3EbN0EC9Dx+08b9r5m/JVpyE3tjkV+pZRxLJIgwgqQBy5ZomuDUT4+Zq mtfU/NI0AO6CA== Date: Thu, 16 Feb 2023 12:33:42 -0800 Subject: [PATCH 04/28] xfs: Hold inode locks in xfs_ialloc From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , Catherine Hoang , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872425.3473407.18416781697745859040.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Modify xfs_ialloc to hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operations Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang --- fs/xfs/xfs_inode.c | 8 +++++++- fs/xfs/xfs_qm.c | 4 +++- fs/xfs/xfs_symlink.c | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 27532053a67b..772e3f105b7b 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -774,6 +774,8 @@ xfs_inode_inherit_flags2( /* * Initialise a newly allocated inode and return the in-core inode to the * caller locked exclusively. + * + * Caller is responsible for unlocking the inode manually upon return */ int xfs_init_new_inode( @@ -899,7 +901,7 @@ xfs_init_new_inode( /* * Log the new values stuffed into the inode. */ - xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, ip, 0); xfs_trans_log_inode(tp, ip, flags); /* now that we have an i_mode we can setup the inode structure */ @@ -1076,6 +1078,7 @@ xfs_create( xfs_qm_dqrele(pdqp); *ipp = ip; + xfs_iunlock(ip, XFS_ILOCK_EXCL); return 0; out_trans_cancel: @@ -1089,6 +1092,7 @@ xfs_create( if (ip) { xfs_finish_inode_setup(ip); xfs_irele(ip); + xfs_iunlock(ip, XFS_ILOCK_EXCL); } out_release_dquots: xfs_qm_dqrele(udqp); @@ -1172,6 +1176,7 @@ xfs_create_tmpfile( xfs_qm_dqrele(pdqp); *ipp = ip; + xfs_iunlock(ip, XFS_ILOCK_EXCL); return 0; out_trans_cancel: @@ -1185,6 +1190,7 @@ xfs_create_tmpfile( if (ip) { xfs_finish_inode_setup(ip); xfs_irele(ip); + xfs_iunlock(ip, XFS_ILOCK_EXCL); } out_release_dquots: xfs_qm_dqrele(udqp); diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index e2c542f6dcd4..fbecf54d3b44 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -826,8 +826,10 @@ xfs_qm_qino_alloc( ASSERT(xfs_is_shutdown(mp)); xfs_alert(mp, "%s failed (error %d)!", __func__, error); } - if (need_alloc) + if (need_alloc) { xfs_finish_inode_setup(*ipp); + xfs_iunlock(*ipp, XFS_ILOCK_EXCL); + } return error; } diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 8389f3ef88ef..d8e120913036 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -337,6 +337,7 @@ xfs_symlink( xfs_qm_dqrele(pdqp); *ipp = ip; + xfs_iunlock(ip, XFS_ILOCK_EXCL); return 0; out_trans_cancel: @@ -358,6 +359,8 @@ xfs_symlink( if (unlock_dp_on_error) xfs_iunlock(dp, XFS_ILOCK_EXCL); + if (ip) + xfs_iunlock(ip, XFS_ILOCK_EXCL); return error; } From patchwork Thu Feb 16 20:33:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143757 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C154C61DA4 for ; Thu, 16 Feb 2023 20:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbjBPUeC (ORCPT ); Thu, 16 Feb 2023 15:34:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjBPUeB (ORCPT ); Thu, 16 Feb 2023 15:34:01 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA0F77288 for ; Thu, 16 Feb 2023 12:33:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6651760C1A for ; Thu, 16 Feb 2023 20:33:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C538FC433D2; Thu, 16 Feb 2023 20:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579638; bh=FEcFkezD4pW+sJtiz41JVyBH/XDqxVkDRoGSRNfWgJo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZI9LSVJsOtVyYthrU9dANhc4IYGq72C1GkqXwXtZ/InliZJd2sGSKvLzU9f7RsOFi taRpWcg3hYezRnR+Wsgi/jajoMhuYBOSSsulXT7f4koxg6Vx5jvi2VI3X6oOXFwvat OszzY5lVy0eTW9xuc9OFs7XO3h066waLal4hMx7vY1UVH/EhIojpek8IKrRuaOpl37 jfgTrgChS3kCCRHX1nWaoeBVZ1uoqHNr4x57yHay3brf7q0jg3xE2URgLPF14DS24j JRAw0w0pXi9qF1aNDnBSLZKTnki1bJiPeu+CR+1xjRbLuKbYMLDeTd0fbXJHx3JiQf L0LIp8pkLXJVg== Date: Thu, 16 Feb 2023 12:33:58 -0800 Subject: [PATCH 05/28] xfs: Hold inode locks in xfs_trans_alloc_dir From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , Catherine Hoang , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872440.3473407.9158565302104798420.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Modify xfs_trans_alloc_dir to hold locks after return. Caller will be responsible for manual unlock. We will need this later to hold locks across parent pointer operations Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang --- fs/xfs/xfs_inode.c | 14 ++++++++++++-- fs/xfs/xfs_trans.c | 9 +++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 772e3f105b7b..e292688ee608 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1279,10 +1279,15 @@ xfs_link( if (xfs_has_wsync(mp) || xfs_has_dirsync(mp)) xfs_trans_set_sync(tp); - return xfs_trans_commit(tp); + error = xfs_trans_commit(tp); + xfs_iunlock(tdp, XFS_ILOCK_EXCL); + xfs_iunlock(sip, XFS_ILOCK_EXCL); + return error; error_return: xfs_trans_cancel(tp); + xfs_iunlock(tdp, XFS_ILOCK_EXCL); + xfs_iunlock(sip, XFS_ILOCK_EXCL); std_return: if (error == -ENOSPC && nospace_error) error = nospace_error; @@ -2518,15 +2523,20 @@ xfs_remove( error = xfs_trans_commit(tp); if (error) - goto std_return; + goto out_unlock; if (is_dir && xfs_inode_is_filestream(ip)) xfs_filestream_deassociate(ip); + xfs_iunlock(ip, XFS_ILOCK_EXCL); + xfs_iunlock(dp, XFS_ILOCK_EXCL); return 0; out_trans_cancel: xfs_trans_cancel(tp); + out_unlock: + xfs_iunlock(ip, XFS_ILOCK_EXCL); + xfs_iunlock(dp, XFS_ILOCK_EXCL); std_return: return error; } diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 7bd16fbff534..43f4b0943f49 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -1356,6 +1356,8 @@ xfs_trans_alloc_ichange( * The caller must ensure that the on-disk dquots attached to this inode have * already been allocated and initialized. The ILOCKs will be dropped when the * transaction is committed or cancelled. + * + * Caller is responsible for unlocking the inodes manually upon return */ int xfs_trans_alloc_dir( @@ -1386,8 +1388,8 @@ xfs_trans_alloc_dir( xfs_lock_two_inodes(dp, XFS_ILOCK_EXCL, ip, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, dp, 0); + xfs_trans_ijoin(tp, ip, 0); error = xfs_qm_dqattach_locked(dp, false); if (error) { @@ -1410,6 +1412,9 @@ xfs_trans_alloc_dir( if (error == -EDQUOT || error == -ENOSPC) { if (!retried) { xfs_trans_cancel(tp); + xfs_iunlock(dp, XFS_ILOCK_EXCL); + if (dp != ip) + xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_blockgc_free_quota(dp, 0); retried = true; goto retry; From patchwork Thu Feb 16 20:34:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143758 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADDE8C61DA4 for ; Thu, 16 Feb 2023 20:34:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjBPUeT (ORCPT ); Thu, 16 Feb 2023 15:34:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjBPUeS (ORCPT ); Thu, 16 Feb 2023 15:34:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1C1623129 for ; Thu, 16 Feb 2023 12:34:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AACBBB82962 for ; Thu, 16 Feb 2023 20:34:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 699FAC433EF; Thu, 16 Feb 2023 20:34:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579654; bh=MiAQBcJQ24eaLyMqvg5QZPlXwIxIoGe3IiopViUmXS0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qvkkYdl0NKTGgWMWTV3wCjKgh5E7RXzBus2xzOJB9FvegHByNE6cfoYkXR+jyXlsu 8zVEeth2W2KHTQJQSfsu+sB2sGlgjnpjL59wrk/6MHMSGxy6r0B9lk0/Zdnd31dim4 B3B3Dwc+p5OKFL1577qsg45YaiabaQ5p0LnK0Q3aJKGIXETwNvb6JXhFCI4LtfnnmS 2tZWc5dvvFbS2YUZxhlNTcG7SmeE68WnN1rvQADXkhuBBADgMxSauuHy0xpur3dpv3 M2Y3YR/31b9sLazvOgqcZ+w5jYd2iSccXAIWM83Dx+uFu84pMqpi86sGMBm291pM/9 47jkD/Q37O9Rg== Date: Thu, 16 Feb 2023 12:34:13 -0800 Subject: [PATCH 06/28] xfs: Hold inode locks in xfs_rename From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , Catherine Hoang , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872455.3473407.13905988613618289717.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Modify xfs_rename to hold all inode locks across a rename operation We will need this later when we add parent pointers Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang --- fs/xfs/xfs_inode.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index e292688ee608..131abf84ea87 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2541,6 +2541,21 @@ xfs_remove( return error; } +static inline void +xfs_iunlock_rename( + struct xfs_inode **i_tab, + int num_inodes) +{ + int i; + + for (i = num_inodes - 1; i >= 0; i--) { + /* Skip duplicate inodes if src and target dps are the same */ + if (!i_tab[i] || (i > 0 && i_tab[i] == i_tab[i - 1])) + continue; + xfs_iunlock(i_tab[i], XFS_ILOCK_EXCL); + } +} + /* * Enter all inodes for a rename transaction into a sorted array. */ @@ -2839,18 +2854,16 @@ xfs_rename( xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL); /* - * Join all the inodes to the transaction. From this point on, - * we can rely on either trans_commit or trans_cancel to unlock - * them. + * Join all the inodes to the transaction. */ - xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, src_dp, 0); if (new_parent) - xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL); - xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, target_dp, 0); + xfs_trans_ijoin(tp, src_ip, 0); if (target_ip) - xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, target_ip, 0); if (wip) - xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); + xfs_trans_ijoin(tp, wip, 0); /* * If we are using project inheritance, we only allow renames @@ -2864,10 +2877,12 @@ xfs_rename( } /* RENAME_EXCHANGE is unique from here on. */ - if (flags & RENAME_EXCHANGE) - return xfs_cross_rename(tp, src_dp, src_name, src_ip, + if (flags & RENAME_EXCHANGE) { + error = xfs_cross_rename(tp, src_dp, src_name, src_ip, target_dp, target_name, target_ip, spaceres); + goto out_unlock; + } /* * Try to reserve quota to handle an expansion of the target directory. @@ -2881,6 +2896,7 @@ xfs_rename( if (error == -EDQUOT || error == -ENOSPC) { if (!retried) { xfs_trans_cancel(tp); + xfs_iunlock_rename(inodes, num_inodes); xfs_blockgc_free_quota(target_dp, 0); retried = true; goto retry; @@ -3092,12 +3108,13 @@ xfs_rename( xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE); error = xfs_finish_rename(tp); - if (wip) - xfs_irele(wip); - return error; + + goto out_unlock; out_trans_cancel: xfs_trans_cancel(tp); +out_unlock: + xfs_iunlock_rename(inodes, num_inodes); out_release_wip: if (wip) xfs_irele(wip); From patchwork Thu Feb 16 20:34:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143759 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94D29C636CC for ; Thu, 16 Feb 2023 20:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229744AbjBPUee (ORCPT ); Thu, 16 Feb 2023 15:34:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjBPUed (ORCPT ); Thu, 16 Feb 2023 15:34:33 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B89F87288 for ; Thu, 16 Feb 2023 12:34:32 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 61817B82970 for ; Thu, 16 Feb 2023 20:34:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0BD66C433D2; Thu, 16 Feb 2023 20:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579670; bh=IvXZ2/ELhJsXM8A/GUm6uKrcJRT55NRyUH7W/3dgins=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qepATzOQamisu9zJpXNl5kRv0wadSzdeISjjrLQXESQU2U6RPdaxWaiR1vsehIBQp bXSVd7Wm/dfqSg34xVktiCPS4OUn0bnhkiwox+wuBUZGX5wR8Sha0us6rvq8gdCrj+ wrSvANrNPmJ5+2xgrIOFFTjPz4xpWDLuhZHGrcRwOK6B9Br+yw4kyGLQl18r2bn+ie ZY/U4yFf8AbPqdBonZBQ0yucJBBGWU0YXAKtY8P6xTskWJNs/Yj3m/7v3J5DZZ9gfM JPhdXROJncRp6IUadOQvlQ/zg4+nFiQG0upyRw4w1lBTKeJzh52ZoSWmbBQpO3yPMT cNE6yPXH5yYTQ== Date: Thu, 16 Feb 2023 12:34:29 -0800 Subject: [PATCH 07/28] xfs: Expose init_xattrs in xfs_create_tmpfile From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872470.3473407.6718782019226919297.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Tmp files are used as part of rename operations and will need attr forks initialized for parent pointers. Expose the init_xattrs parameter to the calling function to initialize the fork. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_inode.c | 5 +++-- fs/xfs/xfs_inode.h | 2 +- fs/xfs/xfs_iops.c | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 131abf84ea87..267d629a33d9 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1109,6 +1109,7 @@ xfs_create_tmpfile( struct user_namespace *mnt_userns, struct xfs_inode *dp, umode_t mode, + bool init_xattrs, struct xfs_inode **ipp) { struct xfs_mount *mp = dp->i_mount; @@ -1149,7 +1150,7 @@ xfs_create_tmpfile( error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (!error) error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode, - 0, 0, prid, false, &ip); + 0, 0, prid, init_xattrs, &ip); if (error) goto out_trans_cancel; @@ -2750,7 +2751,7 @@ xfs_rename_alloc_whiteout( int error; error = xfs_create_tmpfile(mnt_userns, dp, S_IFCHR | WHITEOUT_MODE, - &tmpfile); + false, &tmpfile); if (error) return error; diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h index 2eaed98af814..5735de32beeb 100644 --- a/fs/xfs/xfs_inode.h +++ b/fs/xfs/xfs_inode.h @@ -478,7 +478,7 @@ int xfs_create(struct user_namespace *mnt_userns, umode_t mode, dev_t rdev, bool need_xattr, struct xfs_inode **ipp); int xfs_create_tmpfile(struct user_namespace *mnt_userns, - struct xfs_inode *dp, umode_t mode, + struct xfs_inode *dp, umode_t mode, bool init_xattrs, struct xfs_inode **ipp); int xfs_remove(struct xfs_inode *dp, struct xfs_name *name, struct xfs_inode *ip); diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index 515318dfbc38..45e66c961829 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -200,7 +200,8 @@ xfs_generic_create( xfs_create_need_xattr(dir, default_acl, acl), &ip); } else { - error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, &ip); + error = xfs_create_tmpfile(mnt_userns, XFS_I(dir), mode, true, + &ip); } if (unlikely(error)) goto out_free_acl; From patchwork Thu Feb 16 20:34:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143760 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC7EAC61DA4 for ; Thu, 16 Feb 2023 20:34:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229756AbjBPUez (ORCPT ); Thu, 16 Feb 2023 15:34:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbjBPUer (ORCPT ); Thu, 16 Feb 2023 15:34:47 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B68537288 for ; Thu, 16 Feb 2023 12:34:46 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4348560AB9 for ; Thu, 16 Feb 2023 20:34:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E8E8C433EF; Thu, 16 Feb 2023 20:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579685; bh=yEMWUdT59eFC87axEleI317B/CNEQz2LYsuGNV3Yzfw=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EIFzOEfTSVn2sfGhwtgCZBa6+2k0PifLF1yoIIC/lUottDIzNTRbUm8rMyLb/f2Cy h7OJ0yI0zhtuWlAfRY4lM35eNGtR2OR6cMUp5Ni+EUAmDIAVTK8QstUcSPkc1J3M82 LMaNqg0p7zJW3M1ipgI2Faq+uLvYN0r4Fmebwtmo1gYCABsrq01C2BbD8w8yWxmpjM tDXhjc6XWj/vAUQYHFjys/UmKZ6PcYjHOe/v885J+7p+tPpATEyqBOnMbeJP2Cg4Ym +kBzsHSBIzcrN/d7Rob3ylSwon1hsoqOVOI/cSkNdOVVed/Mg3OB3PSwO2RVMZnfCU nEutnC1jpt4lg== Date: Thu, 16 Feb 2023 12:34:45 -0800 Subject: [PATCH 08/28] xfs: get directory offset when adding directory name From: "Darrick J. Wong" To: djwong@kernel.org Cc: Dave Chinner , Allison Henderson , Catherine Hoang , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872486.3473407.13624092156728112916.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Return the directory offset information when adding an entry to the directory. This offset will be used as the parent pointer offset in xfs_create, xfs_symlink, xfs_link and xfs_rename. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang --- fs/xfs/libxfs/xfs_da_btree.h | 1 + fs/xfs/libxfs/xfs_dir2.c | 9 +++++++-- fs/xfs/libxfs/xfs_dir2.h | 2 +- fs/xfs/libxfs/xfs_dir2_block.c | 1 + fs/xfs/libxfs/xfs_dir2_leaf.c | 2 ++ fs/xfs/libxfs/xfs_dir2_node.c | 2 ++ fs/xfs/libxfs/xfs_dir2_sf.c | 2 ++ fs/xfs/xfs_inode.c | 6 +++--- fs/xfs/xfs_symlink.c | 3 ++- 9 files changed, 21 insertions(+), 7 deletions(-) diff --git a/fs/xfs/libxfs/xfs_da_btree.h b/fs/xfs/libxfs/xfs_da_btree.h index a4b29827603f..90b86d00258f 100644 --- a/fs/xfs/libxfs/xfs_da_btree.h +++ b/fs/xfs/libxfs/xfs_da_btree.h @@ -81,6 +81,7 @@ typedef struct xfs_da_args { int rmtvaluelen2; /* remote attr value length in bytes */ uint32_t op_flags; /* operation flags */ enum xfs_dacmp cmpresult; /* name compare result for lookups */ + xfs_dir2_dataptr_t offset; /* OUT: offset in directory */ } xfs_da_args_t; /* diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 92bac3373f1f..69a6561c22cc 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -257,7 +257,8 @@ xfs_dir_createname( struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, /* new entry inode number */ - xfs_extlen_t total) /* bmap's total block count */ + xfs_extlen_t total, /* bmap's total block count */ + xfs_dir2_dataptr_t *offset) /* OUT entry's dir offset */ { struct xfs_da_args *args; int rval; @@ -312,6 +313,10 @@ xfs_dir_createname( rval = xfs_dir2_node_addname(args); out_free: + /* return the location that this entry was place in the parent inode */ + if (offset) + *offset = args->offset; + kmem_free(args); return rval; } @@ -550,7 +555,7 @@ xfs_dir_canenter( xfs_inode_t *dp, struct xfs_name *name) /* name of entry to add */ { - return xfs_dir_createname(tp, dp, name, 0, 0); + return xfs_dir_createname(tp, dp, name, 0, 0, NULL); } /* diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index dd39f17dd9a9..d96954478696 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -40,7 +40,7 @@ extern int xfs_dir_init(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_inode *pdp); extern int xfs_dir_createname(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, - xfs_extlen_t tot); + xfs_extlen_t tot, xfs_dir2_dataptr_t *offset); extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t *inum, struct xfs_name *ci_name); diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index 00f960a703b2..70aeab9d2a12 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -573,6 +573,7 @@ xfs_dir2_block_addname( xfs_dir2_data_put_ftype(dp->i_mount, dep, args->filetype); tagp = xfs_dir2_data_entry_tag_p(dp->i_mount, dep); *tagp = cpu_to_be16((char *)dep - (char *)hdr); + args->offset = xfs_dir2_byte_to_dataptr((char *)dep - (char *)hdr); /* * Clean up the bestfree array and log the header, tail, and entry. */ diff --git a/fs/xfs/libxfs/xfs_dir2_leaf.c b/fs/xfs/libxfs/xfs_dir2_leaf.c index cb9e950a911d..9ab520b66547 100644 --- a/fs/xfs/libxfs/xfs_dir2_leaf.c +++ b/fs/xfs/libxfs/xfs_dir2_leaf.c @@ -870,6 +870,8 @@ xfs_dir2_leaf_addname( xfs_dir2_data_put_ftype(dp->i_mount, dep, args->filetype); tagp = xfs_dir2_data_entry_tag_p(dp->i_mount, dep); *tagp = cpu_to_be16((char *)dep - (char *)hdr); + args->offset = xfs_dir2_db_off_to_dataptr(args->geo, use_block, + (char *)dep - (char *)hdr); /* * Need to scan fix up the bestfree table. */ diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c index 7a03aeb9f4c9..5a9513c036b8 100644 --- a/fs/xfs/libxfs/xfs_dir2_node.c +++ b/fs/xfs/libxfs/xfs_dir2_node.c @@ -1974,6 +1974,8 @@ xfs_dir2_node_addname_int( xfs_dir2_data_put_ftype(dp->i_mount, dep, args->filetype); tagp = xfs_dir2_data_entry_tag_p(dp->i_mount, dep); *tagp = cpu_to_be16((char *)dep - (char *)hdr); + args->offset = xfs_dir2_db_off_to_dataptr(args->geo, dbno, + (char *)dep - (char *)hdr); xfs_dir2_data_log_entry(args, dbp, dep); /* Rescan the freespace and log the data block if needed. */ diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 8cd37e6e9d38..44bc4ba3da8a 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -485,6 +485,7 @@ xfs_dir2_sf_addname_easy( memcpy(sfep->name, args->name, sfep->namelen); xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber); xfs_dir2_sf_put_ftype(mp, sfep, args->filetype); + args->offset = xfs_dir2_byte_to_dataptr(offset); /* * Update the header and inode. @@ -575,6 +576,7 @@ xfs_dir2_sf_addname_hard( memcpy(sfep->name, args->name, sfep->namelen); xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber); xfs_dir2_sf_put_ftype(mp, sfep, args->filetype); + args->offset = xfs_dir2_byte_to_dataptr(offset); sfp->count++; if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange) sfp->i8count++; diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 267d629a33d9..143de4202cf4 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1038,7 +1038,7 @@ xfs_create( unlock_dp_on_error = false; error = xfs_dir_createname(tp, dp, name, ip->i_ino, - resblks - XFS_IALLOC_SPACE_RES(mp)); + resblks - XFS_IALLOC_SPACE_RES(mp), NULL); if (error) { ASSERT(error != -ENOSPC); goto out_trans_cancel; @@ -1264,7 +1264,7 @@ xfs_link( } error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino, - resblks); + resblks, NULL); if (error) goto error_return; xfs_trans_ichgtime(tp, tdp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); @@ -3001,7 +3001,7 @@ xfs_rename( * to account for the ".." reference from the new entry. */ error = xfs_dir_createname(tp, target_dp, target_name, - src_ip->i_ino, spaceres); + src_ip->i_ino, spaceres, NULL); if (error) goto out_trans_cancel; diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index d8e120913036..27a7d7c57015 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -314,7 +314,8 @@ xfs_symlink( /* * Create the directory entry for the symlink. */ - error = xfs_dir_createname(tp, dp, link_name, ip->i_ino, resblks); + error = xfs_dir_createname(tp, dp, link_name, + ip->i_ino, resblks, NULL); if (error) goto out_trans_cancel; xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); From patchwork Thu Feb 16 20:35:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAA38C61DA4 for ; Thu, 16 Feb 2023 20:35:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbjBPUfG (ORCPT ); Thu, 16 Feb 2023 15:35:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbjBPUfF (ORCPT ); Thu, 16 Feb 2023 15:35:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02B6E4AFD3 for ; Thu, 16 Feb 2023 12:35:04 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7F9CDB82962 for ; Thu, 16 Feb 2023 20:35:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 386CFC433EF; Thu, 16 Feb 2023 20:35:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579701; bh=BtOLDm4HxIdB1HRsNu+7D42qER5e/a2S4t94XvAss9U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=EETjdDZgdvicvmO705P+kACo4gM3lGSIhnbXWM5bhSvUOnhhRQLhjVru3Rvc63vTu EZF5J4ZloIRk0VDzR4DIEBd6IyFZrwnkKoWbW0ES2T2qRbyrotPog9gA0ORkv7MtkW BZ8QJRLCRuf2ftvXQIu32AfFaIocThCwzSJuPKBUTQ3AAV4GjareLqo6kJFmvI2PuP dfJY3Lyiyjdz/rk0N4ejamMZh/oc7XFb8Y52AreEZONW2YrI6iUJryNUP8jkRV7l1k FdX6yVX6n2Ra3frx5wn5xxrg9X0cDKDbObH+YQ1W+ZBArbYbbIeQyXxiNYa+w+PJ/o Q4wfJntX05h1g== Date: Thu, 16 Feb 2023 12:35:00 -0800 Subject: [PATCH 09/28] xfs: get directory offset when removing directory name From: "Darrick J. Wong" To: djwong@kernel.org Cc: Mark Tinguely , Dave Chinner , Allison Henderson , Catherine Hoang , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872502.3473407.9632936076429548132.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Return the directory offset information when removing an entry to the directory. This offset will be used as the parent pointer offset in xfs_remove. Signed-off-by: Mark Tinguely Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Reviewed-by: Catherine Hoang --- fs/xfs/libxfs/xfs_dir2.c | 6 +++++- fs/xfs/libxfs/xfs_dir2.h | 3 ++- fs/xfs/libxfs/xfs_dir2_block.c | 4 ++-- fs/xfs/libxfs/xfs_dir2_leaf.c | 5 +++-- fs/xfs/libxfs/xfs_dir2_node.c | 5 +++-- fs/xfs/libxfs/xfs_dir2_sf.c | 2 ++ fs/xfs/xfs_inode.c | 4 ++-- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 69a6561c22cc..891c1f701f53 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -436,7 +436,8 @@ xfs_dir_removename( struct xfs_inode *dp, struct xfs_name *name, xfs_ino_t ino, - xfs_extlen_t total) /* bmap's total block count */ + xfs_extlen_t total, /* bmap's total block count */ + xfs_dir2_dataptr_t *offset) /* OUT: offset in directory */ { struct xfs_da_args *args; int rval; @@ -481,6 +482,9 @@ xfs_dir_removename( else rval = xfs_dir2_node_removename(args); out_free: + if (offset) + *offset = args->offset; + kmem_free(args); return rval; } diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index d96954478696..0c2d7c0af78f 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -46,7 +46,8 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *ci_name); extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *name, xfs_ino_t ino, - xfs_extlen_t tot); + xfs_extlen_t tot, + xfs_dir2_dataptr_t *offset); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, xfs_extlen_t tot); diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index 70aeab9d2a12..d36f3f1491da 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -810,9 +810,9 @@ xfs_dir2_block_removename( /* * Point to the data entry using the leaf entry. */ + args->offset = be32_to_cpu(blp[ent].address); dep = (xfs_dir2_data_entry_t *)((char *)hdr + - xfs_dir2_dataptr_to_off(args->geo, - be32_to_cpu(blp[ent].address))); + xfs_dir2_dataptr_to_off(args->geo, args->offset)); /* * Mark the data entry's space free. */ diff --git a/fs/xfs/libxfs/xfs_dir2_leaf.c b/fs/xfs/libxfs/xfs_dir2_leaf.c index 9ab520b66547..b4a066259d97 100644 --- a/fs/xfs/libxfs/xfs_dir2_leaf.c +++ b/fs/xfs/libxfs/xfs_dir2_leaf.c @@ -1386,9 +1386,10 @@ xfs_dir2_leaf_removename( * Point to the leaf entry, use that to point to the data entry. */ lep = &leafhdr.ents[index]; - db = xfs_dir2_dataptr_to_db(geo, be32_to_cpu(lep->address)); + args->offset = be32_to_cpu(lep->address); + db = xfs_dir2_dataptr_to_db(args->geo, args->offset); dep = (xfs_dir2_data_entry_t *)((char *)hdr + - xfs_dir2_dataptr_to_off(geo, be32_to_cpu(lep->address))); + xfs_dir2_dataptr_to_off(args->geo, args->offset)); needscan = needlog = 0; oldbest = be16_to_cpu(bf[0].length); ltp = xfs_dir2_leaf_tail_p(geo, leaf); diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c index 5a9513c036b8..39cbdeafa0f6 100644 --- a/fs/xfs/libxfs/xfs_dir2_node.c +++ b/fs/xfs/libxfs/xfs_dir2_node.c @@ -1296,9 +1296,10 @@ xfs_dir2_leafn_remove( /* * Extract the data block and offset from the entry. */ - db = xfs_dir2_dataptr_to_db(geo, be32_to_cpu(lep->address)); + args->offset = be32_to_cpu(lep->address); + db = xfs_dir2_dataptr_to_db(args->geo, args->offset); ASSERT(dblk->blkno == db); - off = xfs_dir2_dataptr_to_off(geo, be32_to_cpu(lep->address)); + off = xfs_dir2_dataptr_to_off(args->geo, args->offset); ASSERT(dblk->index == off); /* diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 44bc4ba3da8a..b49578a547b3 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -969,6 +969,8 @@ xfs_dir2_sf_removename( XFS_CMP_EXACT) { ASSERT(xfs_dir2_sf_get_ino(mp, sfp, sfep) == args->inumber); + args->offset = xfs_dir2_byte_to_dataptr( + xfs_dir2_sf_get_offset(sfep)); break; } } diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 143de4202cf4..e5ed8bdef9fe 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2508,7 +2508,7 @@ xfs_remove( if (error) goto out_trans_cancel; - error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks); + error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, NULL); if (error) { ASSERT(error != -ENOENT); goto out_trans_cancel; @@ -3098,7 +3098,7 @@ xfs_rename( spaceres); else error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, - spaceres); + spaceres, NULL); if (error) goto out_trans_cancel; From patchwork Thu Feb 16 20:35:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C7EBC636CC for ; Thu, 16 Feb 2023 20:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229541AbjBPUfY (ORCPT ); Thu, 16 Feb 2023 15:35:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbjBPUfV (ORCPT ); Thu, 16 Feb 2023 15:35:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77340D505 for ; Thu, 16 Feb 2023 12:35:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2DE55B82962 for ; Thu, 16 Feb 2023 20:35:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFF90C433D2; Thu, 16 Feb 2023 20:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579716; bh=xQ6fSvsdxOn3NApz3gKUIapmiykVpoPUWwacjofq958=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UEU46IcN2DtWJdk4E2+Ga9auJVQVV3M7qcruZYVKZC9+veHMzXQS0Aq4vv/qJ1dKA xLzj8FFoFdBwA5BKa+aT97nJQB0U0BjEqgUb2dXtncZ/SQl50mX7r//wUgs2ggVOib xhv7Hx5+YCUCABHdZnP5Ka5oLKfy0dyQioco5OhQ/EqnooO3ud+31kMCrQeKB1yE4G UfUhJd2fKT+6LshSPN2aIN/VL6AVceb2YZfcB5US3vNd22pkv77xzFOq90E3EoEcCJ sDIFF63XobJxe34pNIHVCMcHI7JT4fiUhLYKbqqE9p8upM5SZCFDs6MjqN1EniISSa OJ5pBkbtg+wdg== Date: Thu, 16 Feb 2023 12:35:16 -0800 Subject: [PATCH 10/28] xfs: get directory offset when replacing a directory name From: "Darrick J. Wong" To: djwong@kernel.org Cc: Mark Tinguely , Dave Chinner , Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872518.3473407.1175424125890822450.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Return the directory offset information when replacing an entry to the directory. This offset will be used as the parent pointer offset in xfs_rename. Signed-off-by: Mark Tinguely Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2.c | 8 ++++++-- fs/xfs/libxfs/xfs_dir2.h | 2 +- fs/xfs/libxfs/xfs_dir2_block.c | 4 ++-- fs/xfs/libxfs/xfs_dir2_leaf.c | 1 + fs/xfs/libxfs/xfs_dir2_node.c | 1 + fs/xfs/libxfs/xfs_dir2_sf.c | 2 ++ fs/xfs/xfs_inode.c | 16 ++++++++-------- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c index 891c1f701f53..c1a9394d7478 100644 --- a/fs/xfs/libxfs/xfs_dir2.c +++ b/fs/xfs/libxfs/xfs_dir2.c @@ -482,7 +482,7 @@ xfs_dir_removename( else rval = xfs_dir2_node_removename(args); out_free: - if (offset) + if (!rval && offset) *offset = args->offset; kmem_free(args); @@ -498,7 +498,8 @@ xfs_dir_replace( struct xfs_inode *dp, const struct xfs_name *name, /* name of entry to replace */ xfs_ino_t inum, /* new inode number */ - xfs_extlen_t total) /* bmap's total block count */ + xfs_extlen_t total, /* bmap's total block count */ + xfs_dir2_dataptr_t *offset) /* OUT: offset in directory */ { struct xfs_da_args *args; int rval; @@ -546,6 +547,9 @@ xfs_dir_replace( else rval = xfs_dir2_node_replace(args); out_free: + if (offset) + *offset = args->offset; + kmem_free(args); return rval; } diff --git a/fs/xfs/libxfs/xfs_dir2.h b/fs/xfs/libxfs/xfs_dir2.h index 0c2d7c0af78f..ff59f009d1fd 100644 --- a/fs/xfs/libxfs/xfs_dir2.h +++ b/fs/xfs/libxfs/xfs_dir2.h @@ -50,7 +50,7 @@ extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp, xfs_dir2_dataptr_t *offset); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, - xfs_extlen_t tot); + xfs_extlen_t tot, xfs_dir2_dataptr_t *offset); extern int xfs_dir_canenter(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_name *name); diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index d36f3f1491da..0f3a03e87278 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -885,9 +885,9 @@ xfs_dir2_block_replace( /* * Point to the data entry we need to change. */ + args->offset = be32_to_cpu(blp[ent].address); dep = (xfs_dir2_data_entry_t *)((char *)hdr + - xfs_dir2_dataptr_to_off(args->geo, - be32_to_cpu(blp[ent].address))); + xfs_dir2_dataptr_to_off(args->geo, args->offset)); ASSERT(be64_to_cpu(dep->inumber) != args->inumber); /* * Change the inode number to the new value. diff --git a/fs/xfs/libxfs/xfs_dir2_leaf.c b/fs/xfs/libxfs/xfs_dir2_leaf.c index b4a066259d97..fe75ffadace9 100644 --- a/fs/xfs/libxfs/xfs_dir2_leaf.c +++ b/fs/xfs/libxfs/xfs_dir2_leaf.c @@ -1523,6 +1523,7 @@ xfs_dir2_leaf_replace( /* * Point to the data entry. */ + args->offset = be32_to_cpu(lep->address); dep = (xfs_dir2_data_entry_t *) ((char *)dbp->b_addr + xfs_dir2_dataptr_to_off(args->geo, be32_to_cpu(lep->address))); diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c index 39cbdeafa0f6..53cd0d5d94f7 100644 --- a/fs/xfs/libxfs/xfs_dir2_node.c +++ b/fs/xfs/libxfs/xfs_dir2_node.c @@ -2242,6 +2242,7 @@ xfs_dir2_node_replace( hdr = state->extrablk.bp->b_addr; ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC)); + args->offset = be32_to_cpu(leafhdr.ents[blk->index].address); dep = (xfs_dir2_data_entry_t *) ((char *)hdr + xfs_dir2_dataptr_to_off(args->geo, diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index b49578a547b3..032c65804610 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -1107,6 +1107,8 @@ xfs_dir2_sf_replace( xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber); xfs_dir2_sf_put_ftype(mp, sfep, args->filetype); + args->offset = xfs_dir2_byte_to_dataptr( + xfs_dir2_sf_get_offset(sfep)); break; } } diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index e5ed8bdef9fe..a896ee4c9680 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2489,7 +2489,7 @@ xfs_remove( */ if (dp->i_ino != tp->t_mountp->m_sb.sb_rootino) { error = xfs_dir_replace(tp, ip, &xfs_name_dotdot, - tp->t_mountp->m_sb.sb_rootino, 0); + tp->t_mountp->m_sb.sb_rootino, 0, NULL); if (error) goto out_trans_cancel; } @@ -2644,12 +2644,12 @@ xfs_cross_rename( int dp2_flags = 0; /* Swap inode number for dirent in first parent */ - error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres); + error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, NULL); if (error) goto out_trans_abort; /* Swap inode number for dirent in second parent */ - error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres); + error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, NULL); if (error) goto out_trans_abort; @@ -2663,7 +2663,7 @@ xfs_cross_rename( if (S_ISDIR(VFS_I(ip2)->i_mode)) { error = xfs_dir_replace(tp, ip2, &xfs_name_dotdot, - dp1->i_ino, spaceres); + dp1->i_ino, spaceres, NULL); if (error) goto out_trans_abort; @@ -2687,7 +2687,7 @@ xfs_cross_rename( if (S_ISDIR(VFS_I(ip1)->i_mode)) { error = xfs_dir_replace(tp, ip1, &xfs_name_dotdot, - dp2->i_ino, spaceres); + dp2->i_ino, spaceres, NULL); if (error) goto out_trans_abort; @@ -3022,7 +3022,7 @@ xfs_rename( * name at the destination directory, remove it first. */ error = xfs_dir_replace(tp, target_dp, target_name, - src_ip->i_ino, spaceres); + src_ip->i_ino, spaceres, NULL); if (error) goto out_trans_cancel; @@ -3056,7 +3056,7 @@ xfs_rename( * directory. */ error = xfs_dir_replace(tp, src_ip, &xfs_name_dotdot, - target_dp->i_ino, spaceres); + target_dp->i_ino, spaceres, NULL); ASSERT(error != -EEXIST); if (error) goto out_trans_cancel; @@ -3095,7 +3095,7 @@ xfs_rename( */ if (wip) error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino, - spaceres); + spaceres, NULL); else error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, spaceres, NULL); From patchwork Thu Feb 16 20:35:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF4FDC636CC for ; Thu, 16 Feb 2023 20:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229627AbjBPUff (ORCPT ); Thu, 16 Feb 2023 15:35:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbjBPUfe (ORCPT ); Thu, 16 Feb 2023 15:35:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EDF97288 for ; Thu, 16 Feb 2023 12:35:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1A71560AB9 for ; Thu, 16 Feb 2023 20:35:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77D0AC433D2; Thu, 16 Feb 2023 20:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579732; bh=mk5q9PV0hl4AJHCYEtgSjhsL4Lm5kZ7VOBXgQyxKZWk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Iz6Pnj8L8oWHB4G4LV105I/p+Os20JUcu/XG5e/GBNbEMh1oGoy0WinCP5ctKjcFI 8UCRZurqmoz5fou2u81NsQsqhPJlgQoPrC2ik6Dv8VfgoZ/QKTmqPZSXZArIPga9rw 5jhHdLQS1ATzdV1zHS9saJUMWRNNkI8pWGUpzcv2JouUTqedFK5zSKgTxbxiNFvYKZ dwX9UzTduSfeAUW04TESLqFKHUUs5Fv2mK+kJxcDj4gipjvzn7ZSLrYvFtzO8Lw4ae UEkJodwZQhquh+Q/wawRmQPa3/R25BmZl+0eVEMZjlaQCTTZIvtNRjyxxE+g+tQ5N9 Pjkqw5Mx7UFIQ== Date: Thu, 16 Feb 2023 12:35:32 -0800 Subject: [PATCH 11/28] xfs: add parent pointer support to attribute code From: "Darrick J. Wong" To: djwong@kernel.org Cc: Mark Tinguely , Dave Chinner , Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872534.3473407.14403907109254934064.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Add the new parent attribute type. XFS_ATTR_PARENT is used only for parent pointer entries; it uses reserved blocks like XFS_ATTR_ROOT. Signed-off-by: Mark Tinguely Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr.c | 4 +++- fs/xfs/libxfs/xfs_da_format.h | 5 ++++- fs/xfs/libxfs/xfs_log_format.h | 1 + fs/xfs/scrub/attr.c | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index b1dbed7655e8..101823772bf9 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -976,11 +976,13 @@ xfs_attr_set( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; struct xfs_trans_res tres; - bool rsvd = (args->attr_filter & XFS_ATTR_ROOT); + bool rsvd; int error, local; int rmt_blks = 0; unsigned int total; + rsvd = (args->attr_filter & (XFS_ATTR_ROOT | XFS_ATTR_PARENT)) != 0; + if (xfs_is_shutdown(dp->i_mount)) return -EIO; diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 25e2841084e1..3dc03968bba6 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -688,12 +688,15 @@ struct xfs_attr3_leafblock { #define XFS_ATTR_LOCAL_BIT 0 /* attr is stored locally */ #define XFS_ATTR_ROOT_BIT 1 /* limit access to trusted attrs */ #define XFS_ATTR_SECURE_BIT 2 /* limit access to secure attrs */ +#define XFS_ATTR_PARENT_BIT 3 /* parent pointer attrs */ #define XFS_ATTR_INCOMPLETE_BIT 7 /* attr in middle of create/delete */ #define XFS_ATTR_LOCAL (1u << XFS_ATTR_LOCAL_BIT) #define XFS_ATTR_ROOT (1u << XFS_ATTR_ROOT_BIT) #define XFS_ATTR_SECURE (1u << XFS_ATTR_SECURE_BIT) +#define XFS_ATTR_PARENT (1u << XFS_ATTR_PARENT_BIT) #define XFS_ATTR_INCOMPLETE (1u << XFS_ATTR_INCOMPLETE_BIT) -#define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE) +#define XFS_ATTR_NSP_ONDISK_MASK \ + (XFS_ATTR_ROOT | XFS_ATTR_SECURE | XFS_ATTR_PARENT) /* * Alignment for namelist and valuelist entries (since they are mixed diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h index ae9c99762a24..727b5a858028 100644 --- a/fs/xfs/libxfs/xfs_log_format.h +++ b/fs/xfs/libxfs/xfs_log_format.h @@ -967,6 +967,7 @@ struct xfs_icreate_log { */ #define XFS_ATTRI_FILTER_MASK (XFS_ATTR_ROOT | \ XFS_ATTR_SECURE | \ + XFS_ATTR_PARENT | \ XFS_ATTR_INCOMPLETE) /* diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c index 31529b9bf389..9d2e33743ecd 100644 --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c @@ -441,7 +441,7 @@ xchk_xattr_rec( /* Retrieve the entry and check it. */ hash = be32_to_cpu(ent->hashval); badflags = ~(XFS_ATTR_LOCAL | XFS_ATTR_ROOT | XFS_ATTR_SECURE | - XFS_ATTR_INCOMPLETE); + XFS_ATTR_INCOMPLETE | XFS_ATTR_PARENT); if ((ent->flags & badflags) != 0) xchk_da_set_corrupt(ds, level); if (ent->flags & XFS_ATTR_LOCAL) { From patchwork Thu Feb 16 20:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143764 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1DEFC61DA4 for ; Thu, 16 Feb 2023 20:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbjBPUfv (ORCPT ); Thu, 16 Feb 2023 15:35:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbjBPUft (ORCPT ); Thu, 16 Feb 2023 15:35:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D23F196AA for ; Thu, 16 Feb 2023 12:35:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C839160A55 for ; Thu, 16 Feb 2023 20:35:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33468C433EF; Thu, 16 Feb 2023 20:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579748; bh=83Af1t9Ev58nDbwfUW4gzOd8nf2eU0GMLkvmfXSmvEE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=HC7uAHY1Pl1SaKS3cx0TnYER1FrcDEgrMeJlPx8FCY0/uQwl8Ir7rD/mpxyNtfyrx jX4E9ekvhLp7QWVT+M1PNRiXQvAIUI3UEbk2tuh8RuCAiWSXNtAv6z1eqaasfbS4v3 2+a+PGZaGP8STgRJYht8eEizjGDkTaE/GKBHE6NZb2nRZkh0jmvDN2ko5HGfD8u2XR G6F+eldU3JogQA4/fGgf3ftw4+m9TUelecyJvsOWj0Rot02jfbL373FtoQJYeEUpO8 xv+x2gBRTgelhX6oDQ3obyUJq5lbmUpy6rGWTnMvqgcvkUU7TVwzC71erD6NjkJ/xL VpjoSpDX7mIMw== Date: Thu, 16 Feb 2023 12:35:47 -0800 Subject: [PATCH 12/28] xfs: define parent pointer xattr format From: "Darrick J. Wong" To: djwong@kernel.org Cc: Dave Chinner , Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872549.3473407.13588553882490573241.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson We need to define the parent pointer attribute format before we start adding support for it into all the code that needs to use it. The EA format we will use encodes the following information: name={parent inode #, parent inode generation, dirent offset} value={dirent filename} The inode/gen gives all the information we need to reliably identify the parent without requiring child->parent lock ordering, and allows userspace to do pathname component level reconstruction without the kernel ever needing to verify the parent itself as part of ioctl calls. By using the dirent offset in the EA name, we have a method of knowing the exact parent pointer EA we need to modify/remove in rename/unlink without an unbound EA name search. By keeping the dirent name in the value, we have enough information to be able to validate and reconstruct damaged directory trees. While the diroffset of a filename alone is not unique enough to identify the child, the {diroffset,filename,child_inode} tuple is sufficient. That is, if the diroffset gets reused and points to a different filename, we can detect that from the contents of EA. If a link of the same name is created, then we can check whether it points at the same inode as the parent EA we current have. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_da_format.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 3dc03968bba6..b02b67f1999e 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -805,4 +805,29 @@ static inline unsigned int xfs_dir2_dirblock_bytes(struct xfs_sb *sbp) xfs_failaddr_t xfs_da3_blkinfo_verify(struct xfs_buf *bp, struct xfs_da3_blkinfo *hdr3); +/* + * Parent pointer attribute format definition + * + * EA name encodes the parent inode number, generation and the offset of + * the dirent that points to the child inode. The EA value contains the + * same name as the dirent in the parent directory. + */ +struct xfs_parent_name_rec { + __be64 p_ino; + __be32 p_gen; + __be32 p_diroffset; +}; + +/* + * incore version of the above, also contains name pointers so callers + * can pass/obtain all the parent pointer information in a single structure + */ +struct xfs_parent_name_irec { + xfs_ino_t p_ino; + uint32_t p_gen; + xfs_dir2_dataptr_t p_diroffset; + const char *p_name; + uint8_t p_namelen; +}; + #endif /* __XFS_DA_FORMAT_H__ */ From patchwork Thu Feb 16 20:36:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B3E1C61DA4 for ; Thu, 16 Feb 2023 20:36:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbjBPUgG (ORCPT ); Thu, 16 Feb 2023 15:36:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229614AbjBPUgF (ORCPT ); Thu, 16 Feb 2023 15:36:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C25B0199DF for ; Thu, 16 Feb 2023 12:36:04 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5E4E060B3A for ; Thu, 16 Feb 2023 20:36:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2B14C433D2; Thu, 16 Feb 2023 20:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579763; bh=nQpBJ2gFHb7//Hsb+FCC8ehi0nUsaEvjz7fyM4wP8YU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WD3iMyP+C10wLws8gcLxOO/nXGy5bQQX6A039a/oHEcbLFocxJRPShqPpiSkPmV6N oIVkJAaeigFFMpUmJ42MGRJhKbNXn0D8qwx3ucQ3hdcVtAokgXqvnKd3jFuuyR3/eK jsS12XTML1Uc9nUseuIxBPaQ2F/2dAn22IIjNPCIDUNyNpEqv8rlKTzaobP5atroMO TlojeIpn1AzShIn5ks8m83I1HHA00My8oQnPktBiOtL4WMYxXJ1che7XNTohUwrxGh N/fwwX2eNpDzxHBL7JfJN3pd1kcpBHWLuurtfFCWMEK5xgB0EaK1AEQ+L/CDkjsPv6 6sUjYq5tAcImQ== Date: Thu, 16 Feb 2023 12:36:03 -0800 Subject: [PATCH 13/28] xfs: Add xfs_verify_pptr From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872564.3473407.13367441011593399553.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Attribute names of parent pointers are not strings. So we need to modify attr_namecheck to verify parent pointer records when the XFS_ATTR_PARENT flag is set. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr.c | 47 ++++++++++++++++++++++++++++++++++++++--- fs/xfs/libxfs/xfs_attr.h | 3 ++- fs/xfs/libxfs/xfs_da_format.h | 8 +++++++ fs/xfs/scrub/attr.c | 2 +- fs/xfs/xfs_attr_item.c | 11 ++++++---- fs/xfs/xfs_attr_list.c | 17 ++++++++++----- 6 files changed, 74 insertions(+), 14 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index 101823772bf9..711022742e34 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -1577,9 +1577,33 @@ xfs_attr_node_get( return error; } -/* Returns true if the attribute entry name is valid. */ -bool -xfs_attr_namecheck( +/* + * Verify parent pointer attribute is valid. + * Return true on success or false on failure + */ +STATIC bool +xfs_verify_pptr( + struct xfs_mount *mp, + const struct xfs_parent_name_rec *rec) +{ + xfs_ino_t p_ino; + xfs_dir2_dataptr_t p_diroffset; + + p_ino = be64_to_cpu(rec->p_ino); + p_diroffset = be32_to_cpu(rec->p_diroffset); + + if (!xfs_verify_ino(mp, p_ino)) + return false; + + if (p_diroffset > XFS_DIR2_MAX_DATAPTR) + return false; + + return true; +} + +/* Returns true if the string attribute entry name is valid. */ +static bool +xfs_str_attr_namecheck( const void *name, size_t length) { @@ -1594,6 +1618,23 @@ xfs_attr_namecheck( return !memchr(name, 0, length); } +/* Returns true if the attribute entry name is valid. */ +bool +xfs_attr_namecheck( + struct xfs_mount *mp, + const void *name, + size_t length, + int flags) +{ + if (flags & XFS_ATTR_PARENT) { + if (length != sizeof(struct xfs_parent_name_rec)) + return false; + return xfs_verify_pptr(mp, (struct xfs_parent_name_rec *)name); + } + + return xfs_str_attr_namecheck(name, length); +} + int __init xfs_attr_intent_init_cache(void) { diff --git a/fs/xfs/libxfs/xfs_attr.h b/fs/xfs/libxfs/xfs_attr.h index 3e81f3f48560..b79dae788cfb 100644 --- a/fs/xfs/libxfs/xfs_attr.h +++ b/fs/xfs/libxfs/xfs_attr.h @@ -547,7 +547,8 @@ int xfs_attr_get(struct xfs_da_args *args); int xfs_attr_set(struct xfs_da_args *args); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); -bool xfs_attr_namecheck(const void *name, size_t length); +bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length, + int flags); int xfs_attr_calc_size(struct xfs_da_args *args, int *local); void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres, unsigned int *total); diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index b02b67f1999e..75b13807145d 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -731,6 +731,14 @@ xfs_attr3_leaf_name(xfs_attr_leafblock_t *leafp, int idx) return &((char *)leafp)[be16_to_cpu(entries[idx].nameidx)]; } +static inline int +xfs_attr3_leaf_flags(xfs_attr_leafblock_t *leafp, int idx) +{ + struct xfs_attr_leaf_entry *entries = xfs_attr3_leaf_entryp(leafp); + + return entries[idx].flags; +} + static inline xfs_attr_leaf_name_remote_t * xfs_attr3_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx) { diff --git a/fs/xfs/scrub/attr.c b/fs/xfs/scrub/attr.c index 9d2e33743ecd..2a79a13cb600 100644 --- a/fs/xfs/scrub/attr.c +++ b/fs/xfs/scrub/attr.c @@ -129,7 +129,7 @@ xchk_xattr_listent( } /* Does this name make sense? */ - if (!xfs_attr_namecheck(name, namelen)) { + if (!xfs_attr_namecheck(sx->sc->mp, name, namelen, flags)) { xchk_fblock_set_corrupt(sx->sc, XFS_ATTR_FORK, args.blkno); return; } diff --git a/fs/xfs/xfs_attr_item.c b/fs/xfs/xfs_attr_item.c index 95e9ecbb4a67..da807f286a09 100644 --- a/fs/xfs/xfs_attr_item.c +++ b/fs/xfs/xfs_attr_item.c @@ -593,7 +593,8 @@ xfs_attri_item_recover( */ attrp = &attrip->attri_format; if (!xfs_attri_validate(mp, attrp) || - !xfs_attr_namecheck(nv->name.i_addr, nv->name.i_len)) + !xfs_attr_namecheck(mp, nv->name.i_addr, nv->name.i_len, + attrp->alfi_attr_filter)) return -EFSCORRUPTED; error = xlog_recover_iget(mp, attrp->alfi_ino, &ip); @@ -804,7 +805,8 @@ xlog_recover_attri_commit_pass2( } attr_name = item->ri_buf[i].i_addr; - if (!xfs_attr_namecheck(attr_name, attri_formatp->alfi_name_len)) { + if (!xfs_attr_namecheck(mp, attr_name, attri_formatp->alfi_name_len, + attri_formatp->alfi_attr_filter)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, item->ri_buf[i].i_addr, item->ri_buf[i].i_len); return -EFSCORRUPTED; @@ -822,8 +824,9 @@ xlog_recover_attri_commit_pass2( } attr_nname = item->ri_buf[i].i_addr; - if (!xfs_attr_namecheck(attr_nname, - attri_formatp->alfi_nname_len)) { + if (!xfs_attr_namecheck(mp, attr_nname, + attri_formatp->alfi_nname_len, + attri_formatp->alfi_attr_filter)) { XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, item->ri_buf[i].i_addr, item->ri_buf[i].i_len); diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c index 99bbbe1a0e44..a51f7f13a352 100644 --- a/fs/xfs/xfs_attr_list.c +++ b/fs/xfs/xfs_attr_list.c @@ -58,9 +58,13 @@ xfs_attr_shortform_list( struct xfs_attr_sf_sort *sbuf, *sbp; struct xfs_attr_shortform *sf; struct xfs_attr_sf_entry *sfe; + struct xfs_mount *mp; int sbsize, nsbuf, count, i; int error = 0; + ASSERT(context != NULL); + ASSERT(dp != NULL); + mp = dp->i_mount; sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data; ASSERT(sf != NULL); if (!sf->hdr.count) @@ -82,8 +86,9 @@ xfs_attr_shortform_list( (dp->i_af.if_bytes + sf->hdr.count * 16) < context->bufsize)) { for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) { if (XFS_IS_CORRUPT(context->dp->i_mount, - !xfs_attr_namecheck(sfe->nameval, - sfe->namelen))) + !xfs_attr_namecheck(mp, sfe->nameval, + sfe->namelen, + sfe->flags))) return -EFSCORRUPTED; context->put_listent(context, sfe->flags, @@ -174,8 +179,9 @@ xfs_attr_shortform_list( cursor->offset = 0; } if (XFS_IS_CORRUPT(context->dp->i_mount, - !xfs_attr_namecheck(sbp->name, - sbp->namelen))) { + !xfs_attr_namecheck(mp, sbp->name, + sbp->namelen, + sbp->flags))) { error = -EFSCORRUPTED; goto out; } @@ -465,7 +471,8 @@ xfs_attr3_leaf_list_int( } if (XFS_IS_CORRUPT(context->dp->i_mount, - !xfs_attr_namecheck(name, namelen))) + !xfs_attr_namecheck(mp, name, namelen, + entry->flags))) return -EFSCORRUPTED; context->put_listent(context, entry->flags, name, namelen, valuelen); From patchwork Thu Feb 16 20:36:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143766 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BADD3C61DA4 for ; Thu, 16 Feb 2023 20:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbjBPUgZ (ORCPT ); Thu, 16 Feb 2023 15:36:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjBPUgZ (ORCPT ); Thu, 16 Feb 2023 15:36:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73DDF4FAB9 for ; Thu, 16 Feb 2023 12:36:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0113660AB9 for ; Thu, 16 Feb 2023 20:36:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E1D3C433D2; Thu, 16 Feb 2023 20:36:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579779; bh=mFpdHDLUGSD+ME8FhXWUkHJjT1nvuknsCMebKbnEQpk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=fQRRhzoHZ03r/Y5DQ/n9fpD+Bj7EMXm2JxDxB+4doV4tYeFTNRG9braQXjrctmWg3 xAJkFLxZHYBK/7G2OC3ACd72138nTByXpnV87LTYpJsTch0+tNyXSB0xHrV4AyMQD8 5oC0sdEtadoFIQVeHvn8kpp+m76NtfGH1NFHXlFs2zWCwRcAZewglAZPZrkfI8ho8Q nuYIRYBMX2czVuaxdtvIOukMR38q0JpKhQDzYU2DZhHaxYkNUybNJWYk016cYw85wo xSP12duhDMrdynPT8FIk4cdKJ/Ljq8qlHeHsJOX+nzoorRFqAdox2y5KykW+vDIjlr w0T8Ombww9q8w== Date: Thu, 16 Feb 2023 12:36:18 -0800 Subject: [PATCH 14/28] xfs: extend transaction reservations for parent attributes From: "Darrick J. Wong" To: djwong@kernel.org Cc: Dave Chinner , Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872580.3473407.13102525263752429602.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson We need to add, remove or modify parent pointer attributes during create/link/unlink/rename operations atomically with the dirents in the parent directories being modified. This means they need to be modified in the same transaction as the parent directories, and so we need to add the required space for the attribute modifications to the transaction reservations. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson --- fs/xfs/libxfs/xfs_trans_resv.c | 324 ++++++++++++++++++++++++++++++++++------ 1 file changed, 272 insertions(+), 52 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c index 5b2f27cbdb80..93419956b9e5 100644 --- a/fs/xfs/libxfs/xfs_trans_resv.c +++ b/fs/xfs/libxfs/xfs_trans_resv.c @@ -19,6 +19,9 @@ #include "xfs_trans.h" #include "xfs_qm.h" #include "xfs_trans_space.h" +#include "xfs_attr_item.h" +#include "xfs_log.h" +#include "xfs_da_format.h" #define _ALLOC true #define _FREE false @@ -420,29 +423,108 @@ xfs_calc_itruncate_reservation_minlogsize( return xfs_calc_itruncate_reservation(mp, true); } +static inline unsigned int xfs_calc_pptr_link_overhead(void) +{ + return sizeof(struct xfs_attri_log_format) + + xlog_calc_iovec_len(XATTR_NAME_MAX) + + xlog_calc_iovec_len(sizeof(struct xfs_parent_name_rec)); +} +static inline unsigned int xfs_calc_pptr_unlink_overhead(void) +{ + return sizeof(struct xfs_attri_log_format) + + xlog_calc_iovec_len(sizeof(struct xfs_parent_name_rec)); +} +static inline unsigned int xfs_calc_pptr_replace_overhead(void) +{ + return sizeof(struct xfs_attri_log_format) + + xlog_calc_iovec_len(XATTR_NAME_MAX) + + xlog_calc_iovec_len(XATTR_NAME_MAX) + + xlog_calc_iovec_len(sizeof(struct xfs_parent_name_rec)); +} + /* * In renaming a files we can modify: * the five inodes involved: 5 * inode size * the two directory btrees: 2 * (max depth + v2) * dir block size * the two directory bmap btrees: 2 * max depth * block size * And the bmap_finish transaction can free dir and bmap blocks (two sets - * of bmap blocks) giving: + * of bmap blocks) giving (t2): * the agf for the ags in which the blocks live: 3 * sector size * the agfl for the ags in which the blocks live: 3 * sector size * the superblock for the free block count: sector size * the allocation btrees: 3 exts * 2 trees * (2 * max depth - 1) * block size + * If parent pointers are enabled (t3), then each transaction in the chain + * must be capable of setting or removing the extended attribute + * containing the parent information. It must also be able to handle + * the three xattr intent items that track the progress of the parent + * pointer update. */ STATIC uint xfs_calc_rename_reservation( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - max((xfs_calc_inode_res(mp, 5) + - xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), - XFS_FSB_TO_B(mp, 1))), - (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3), - XFS_FSB_TO_B(mp, 1)))); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int t1, t2, t3 = 0; + + t1 = xfs_calc_inode_res(mp, 5) + + xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), + XFS_FSB_TO_B(mp, 1)); + + t2 = xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, 3), + XFS_FSB_TO_B(mp, 1)); + + if (xfs_has_parent(mp)) { + unsigned int rename_overhead, exchange_overhead; + + t3 = max(resp->tr_attrsetm.tr_logres, + resp->tr_attrrm.tr_logres); + + /* + * For a standard rename, the three xattr intent log items + * are (1) replacing the pptr for the source file; (2) + * removing the pptr on the dest file; and (3) adding a + * pptr for the whiteout file in the src dir. + * + * For an RENAME_EXCHANGE, there are two xattr intent + * items to replace the pptr for both src and dest + * files. Link counts don't change and there is no + * whiteout. + * + * In the worst case we can end up relogging all log + * intent items to allow the log tail to move ahead, so + * they become overhead added to each transaction in a + * processing chain. + */ + rename_overhead = xfs_calc_pptr_replace_overhead() + + xfs_calc_pptr_unlink_overhead() + + xfs_calc_pptr_link_overhead(); + exchange_overhead = 2 * xfs_calc_pptr_replace_overhead(); + + overhead += max(rename_overhead, exchange_overhead); + } + + return overhead + max3(t1, t2, t3); +} + +static inline unsigned int +xfs_rename_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + /* One for the rename, one more for freeing blocks */ + unsigned int ret = XFS_RENAME_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to remove or add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += max(resp->tr_attrsetm.tr_logcount, + resp->tr_attrrm.tr_logcount); + + return ret; } /* @@ -459,6 +541,23 @@ xfs_calc_iunlink_remove_reservation( 2 * M_IGEO(mp)->inode_cluster_size; } +static inline unsigned int +xfs_link_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_LINK_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} + /* * For creating a link to an inode: * the parent directory inode: inode size @@ -475,14 +574,23 @@ STATIC uint xfs_calc_link_reservation( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - xfs_calc_iunlink_remove_reservation(mp) + - max((xfs_calc_inode_res(mp, 2) + - xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), - XFS_FSB_TO_B(mp, 1))), - (xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 1), - XFS_FSB_TO_B(mp, 1)))); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int t1, t2, t3 = 0; + + overhead += xfs_calc_iunlink_remove_reservation(mp); + t1 = xfs_calc_inode_res(mp, 2) + + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)); + t2 = xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, 1), + XFS_FSB_TO_B(mp, 1)); + + if (xfs_has_parent(mp)) { + t3 = resp->tr_attrsetm.tr_logres; + overhead += xfs_calc_pptr_link_overhead(); + } + + return overhead + max3(t1, t2, t3); } /* @@ -497,6 +605,23 @@ xfs_calc_iunlink_add_reservation(xfs_mount_t *mp) M_IGEO(mp)->inode_cluster_size; } +static inline unsigned int +xfs_remove_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_REMOVE_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrrm.tr_logcount; + + return ret; +} + /* * For removing a directory entry we can modify: * the parent directory inode: inode size @@ -513,14 +638,24 @@ STATIC uint xfs_calc_remove_reservation( struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - xfs_calc_iunlink_add_reservation(mp) + - max((xfs_calc_inode_res(mp, 2) + - xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), - XFS_FSB_TO_B(mp, 1))), - (xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) + - xfs_calc_buf_res(xfs_allocfree_block_count(mp, 2), - XFS_FSB_TO_B(mp, 1)))); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int t1, t2, t3 = 0; + + overhead += xfs_calc_iunlink_add_reservation(mp); + + t1 = xfs_calc_inode_res(mp, 2) + + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1)); + t2 = xfs_calc_buf_res(4, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(xfs_allocfree_block_count(mp, 2), + XFS_FSB_TO_B(mp, 1)); + + if (xfs_has_parent(mp)) { + t3 = resp->tr_attrrm.tr_logres; + overhead += xfs_calc_pptr_unlink_overhead(); + } + + return overhead + max3(t1, t2, t3); } /* @@ -569,12 +704,40 @@ xfs_calc_icreate_resv_alloc( xfs_calc_finobt_res(mp); } +static inline unsigned int +xfs_icreate_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_CREATE_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} + STATIC uint -xfs_calc_icreate_reservation(xfs_mount_t *mp) +xfs_calc_icreate_reservation( + struct xfs_mount *mp) { - return XFS_DQUOT_LOGRES(mp) + - max(xfs_calc_icreate_resv_alloc(mp), - xfs_calc_create_resv_modify(mp)); + struct xfs_trans_resv *resp = M_RES(mp); + unsigned int overhead = XFS_DQUOT_LOGRES(mp); + unsigned int t1, t2, t3 = 0; + + t1 = xfs_calc_icreate_resv_alloc(mp); + t2 = xfs_calc_create_resv_modify(mp); + + if (xfs_has_parent(mp)) { + t3 = resp->tr_attrsetm.tr_logres; + overhead += xfs_calc_pptr_link_overhead(); + } + + return overhead + max3(t1, t2, t3); } STATIC uint @@ -587,6 +750,23 @@ xfs_calc_create_tmpfile_reservation( return res + xfs_calc_iunlink_add_reservation(mp); } +static inline unsigned int +xfs_mkdir_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_MKDIR_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} + /* * Making a new directory is the same as creating a new file. */ @@ -597,6 +777,22 @@ xfs_calc_mkdir_reservation( return xfs_calc_icreate_reservation(mp); } +static inline unsigned int +xfs_symlink_log_count( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + unsigned int ret = XFS_SYMLINK_LOG_COUNT; + + /* + * Pre-reserve enough log reservation to handle the transaction + * rolling needed to add one parent pointer. + */ + if (xfs_has_parent(mp)) + ret += resp->tr_attrsetm.tr_logcount; + + return ret; +} /* * Making a new symplink is the same as creating a new file, but @@ -909,6 +1105,52 @@ xfs_calc_sb_reservation( return xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); } +/* + * Namespace reservations. + * + * These get tricky when parent pointers are enabled as we have attribute + * modifications occurring from within these transactions. Rather than confuse + * each of these reservation calculations with the conditional attribute + * reservations, add them here in a clear and concise manner. This requires that + * the attribute reservations have already been calculated. + * + * Note that we only include the static attribute reservation here; the runtime + * reservation will have to be modified by the size of the attributes being + * added/removed/modified. See the comments on the attribute reservation + * calculations for more details. + */ +STATIC void +xfs_calc_namespace_reservations( + struct xfs_mount *mp, + struct xfs_trans_resv *resp) +{ + ASSERT(resp->tr_attrsetm.tr_logres > 0); + + resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); + resp->tr_rename.tr_logcount = xfs_rename_log_count(mp, resp); + resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_link.tr_logres = xfs_calc_link_reservation(mp); + resp->tr_link.tr_logcount = xfs_link_log_count(mp, resp); + resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp); + resp->tr_remove.tr_logcount = xfs_remove_log_count(mp, resp); + resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp); + resp->tr_symlink.tr_logcount = xfs_symlink_log_count(mp, resp); + resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_create.tr_logres = xfs_calc_icreate_reservation(mp); + resp->tr_create.tr_logcount = xfs_icreate_log_count(mp, resp); + resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + + resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); + resp->tr_mkdir.tr_logcount = xfs_mkdir_log_count(mp, resp); + resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; +} + void xfs_trans_resv_calc( struct xfs_mount *mp, @@ -928,35 +1170,11 @@ xfs_trans_resv_calc( resp->tr_itruncate.tr_logcount = XFS_ITRUNCATE_LOG_COUNT; resp->tr_itruncate.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_rename.tr_logres = xfs_calc_rename_reservation(mp); - resp->tr_rename.tr_logcount = XFS_RENAME_LOG_COUNT; - resp->tr_rename.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_link.tr_logres = xfs_calc_link_reservation(mp); - resp->tr_link.tr_logcount = XFS_LINK_LOG_COUNT; - resp->tr_link.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_remove.tr_logres = xfs_calc_remove_reservation(mp); - resp->tr_remove.tr_logcount = XFS_REMOVE_LOG_COUNT; - resp->tr_remove.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_symlink.tr_logres = xfs_calc_symlink_reservation(mp); - resp->tr_symlink.tr_logcount = XFS_SYMLINK_LOG_COUNT; - resp->tr_symlink.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - - resp->tr_create.tr_logres = xfs_calc_icreate_reservation(mp); - resp->tr_create.tr_logcount = XFS_CREATE_LOG_COUNT; - resp->tr_create.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_create_tmpfile.tr_logres = xfs_calc_create_tmpfile_reservation(mp); resp->tr_create_tmpfile.tr_logcount = XFS_CREATE_TMPFILE_LOG_COUNT; resp->tr_create_tmpfile.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_mkdir.tr_logres = xfs_calc_mkdir_reservation(mp); - resp->tr_mkdir.tr_logcount = XFS_MKDIR_LOG_COUNT; - resp->tr_mkdir.tr_logflags |= XFS_TRANS_PERM_LOG_RES; - resp->tr_ifree.tr_logres = xfs_calc_ifree_reservation(mp); resp->tr_ifree.tr_logcount = XFS_INACTIVE_LOG_COUNT; resp->tr_ifree.tr_logflags |= XFS_TRANS_PERM_LOG_RES; @@ -986,6 +1204,8 @@ xfs_trans_resv_calc( resp->tr_qm_dqalloc.tr_logcount = XFS_WRITE_LOG_COUNT; resp->tr_qm_dqalloc.tr_logflags |= XFS_TRANS_PERM_LOG_RES; + xfs_calc_namespace_reservations(mp, resp); + /* * The following transactions are logged in logical format with * a default log count. From patchwork Thu Feb 16 20:36:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1306BC61DA4 for ; Thu, 16 Feb 2023 20:36:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229616AbjBPUgi (ORCPT ); Thu, 16 Feb 2023 15:36:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjBPUgh (ORCPT ); Thu, 16 Feb 2023 15:36:37 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C3AAD505 for ; Thu, 16 Feb 2023 12:36:36 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8D8AC60B3A for ; Thu, 16 Feb 2023 20:36:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBB2CC433D2; Thu, 16 Feb 2023 20:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579795; bh=R1/wP/C3yFrLcZGz/Kas/51wi+7+cKK3xXNkT7ldHKY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MH7jDDEoCsPHvEkFPNQEOU9ir7WE9+1tU1MkQ8SwFDnkUMfnTOC0WQhlzPUnN+I1N UsjK47PVRyxs8pAjTH0eN/p9jr4EcCqoRbIf6KjtPLzV8CkhZSFg6xcbTFQrkCIuzk QbYhHE+8TkI9C/hI/zOR8yWH9p24rhgmfNZzehgEYoncIQcDJ7sYwRP75z86OdQerd 3/aHjXup31fmU7zWHWTfO/8MzZDrkju1ewzl2W6Bdgn3MCZoWx1ys2W411tIJXhbyT paXC2acf6rH/BCtpktAGnMVtH9mLJ/OvO1o0Y3P4LT4OLRcnkvK1GkwbCKJ2+E2GOv XEaeIls63OY5Q== Date: Thu, 16 Feb 2023 12:36:34 -0800 Subject: [PATCH 15/28] xfs: parent pointer attribute creation From: "Darrick J. Wong" To: djwong@kernel.org Cc: Dave Chinner , Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872594.3473407.14255826102621334169.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Add parent pointer attribute during xfs_create, and subroutines to initialize attributes Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson --- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_attr.c | 4 + fs/xfs/libxfs/xfs_attr.h | 4 + fs/xfs/libxfs/xfs_da_format.h | 12 ---- fs/xfs/libxfs/xfs_parent.c | 139 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_parent.h | 57 +++++++++++++++++ fs/xfs/xfs_inode.c | 64 ++++++++++++++++--- fs/xfs/xfs_super.c | 10 +++ fs/xfs/xfs_xattr.c | 4 + fs/xfs/xfs_xattr.h | 2 + 10 files changed, 271 insertions(+), 26 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_parent.c create mode 100644 fs/xfs/libxfs/xfs_parent.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index 03135a1c31b6..e2b2cf50ffcf 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -40,6 +40,7 @@ xfs-y += $(addprefix libxfs/, \ xfs_inode_fork.o \ xfs_inode_buf.o \ xfs_log_rlimit.o \ + xfs_parent.o \ xfs_ag_resv.o \ xfs_rmap.o \ xfs_rmap_btree.o \ diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index 711022742e34..f68d41f0f998 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -886,7 +886,7 @@ xfs_attr_lookup( return error; } -static int +int xfs_attr_intent_init( struct xfs_da_args *args, unsigned int op_flags, /* op flag (set or remove) */ @@ -904,7 +904,7 @@ xfs_attr_intent_init( } /* Sets an attribute for an inode as a deferred operation */ -static int +int xfs_attr_defer_add( struct xfs_da_args *args) { diff --git a/fs/xfs/libxfs/xfs_attr.h b/fs/xfs/libxfs/xfs_attr.h index b79dae788cfb..0cf23f5117ad 100644 --- a/fs/xfs/libxfs/xfs_attr.h +++ b/fs/xfs/libxfs/xfs_attr.h @@ -544,6 +544,7 @@ int xfs_inode_hasattr(struct xfs_inode *ip); bool xfs_attr_is_leaf(struct xfs_inode *ip); int xfs_attr_get_ilocked(struct xfs_da_args *args); int xfs_attr_get(struct xfs_da_args *args); +int xfs_attr_defer_add(struct xfs_da_args *args); int xfs_attr_set(struct xfs_da_args *args); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); @@ -552,7 +553,8 @@ bool xfs_attr_namecheck(struct xfs_mount *mp, const void *name, size_t length, int xfs_attr_calc_size(struct xfs_da_args *args, int *local); void xfs_init_attr_trans(struct xfs_da_args *args, struct xfs_trans_res *tres, unsigned int *total); - +int xfs_attr_intent_init(struct xfs_da_args *args, unsigned int op_flags, + struct xfs_attr_intent **attr); /* * Check to see if the attr should be upgraded from non-existent or shortform to * single-leaf-block attribute list. diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 75b13807145d..2db1cf97b2c8 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -826,16 +826,4 @@ struct xfs_parent_name_rec { __be32 p_diroffset; }; -/* - * incore version of the above, also contains name pointers so callers - * can pass/obtain all the parent pointer information in a single structure - */ -struct xfs_parent_name_irec { - xfs_ino_t p_ino; - uint32_t p_gen; - xfs_dir2_dataptr_t p_diroffset; - const char *p_name; - uint8_t p_namelen; -}; - #endif /* __XFS_DA_FORMAT_H__ */ diff --git a/fs/xfs/libxfs/xfs_parent.c b/fs/xfs/libxfs/xfs_parent.c new file mode 100644 index 000000000000..6b6d415319e6 --- /dev/null +++ b/fs/xfs/libxfs/xfs_parent.c @@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Oracle, Inc. + * All rights reserved. + */ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_format.h" +#include "xfs_da_format.h" +#include "xfs_log_format.h" +#include "xfs_shared.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_bmap_btree.h" +#include "xfs_inode.h" +#include "xfs_error.h" +#include "xfs_trace.h" +#include "xfs_trans.h" +#include "xfs_da_btree.h" +#include "xfs_attr.h" +#include "xfs_da_btree.h" +#include "xfs_attr_sf.h" +#include "xfs_bmap.h" +#include "xfs_defer.h" +#include "xfs_log.h" +#include "xfs_xattr.h" +#include "xfs_parent.h" +#include "xfs_trans_space.h" + +struct kmem_cache *xfs_parent_intent_cache; + +/* + * Parent pointer attribute handling. + * + * Because the attribute value is a filename component, it will never be longer + * than 255 bytes. This means the attribute will always be a local format + * attribute as it is xfs_attr_leaf_entsize_local_max() for v5 filesystems will + * always be larger than this (max is 75% of block size). + * + * Creating a new parent attribute will always create a new attribute - there + * should never, ever be an existing attribute in the tree for a new inode. + * ENOSPC behavior is problematic - creating the inode without the parent + * pointer is effectively a corruption, so we allow parent attribute creation + * to dip into the reserve block pool to avoid unexpected ENOSPC errors from + * occurring. + */ + + +/* Initializes a xfs_parent_name_rec to be stored as an attribute name */ +void +xfs_init_parent_name_rec( + struct xfs_parent_name_rec *rec, + struct xfs_inode *ip, + uint32_t p_diroffset) +{ + xfs_ino_t p_ino = ip->i_ino; + uint32_t p_gen = VFS_I(ip)->i_generation; + + rec->p_ino = cpu_to_be64(p_ino); + rec->p_gen = cpu_to_be32(p_gen); + rec->p_diroffset = cpu_to_be32(p_diroffset); +} + +int +__xfs_parent_init( + struct xfs_mount *mp, + struct xfs_parent_defer **parentp) +{ + struct xfs_parent_defer *parent; + int error; + + error = xfs_attr_grab_log_assist(mp); + if (error) + return error; + + parent = kmem_cache_zalloc(xfs_parent_intent_cache, GFP_KERNEL); + if (!parent) { + xfs_attr_rele_log_assist(mp); + return -ENOMEM; + } + + /* init parent da_args */ + parent->args.geo = mp->m_attr_geo; + parent->args.whichfork = XFS_ATTR_FORK; + parent->args.attr_filter = XFS_ATTR_PARENT; + parent->args.op_flags = XFS_DA_OP_OKNOENT | XFS_DA_OP_LOGGED; + parent->args.name = (const uint8_t *)&parent->rec; + parent->args.namelen = sizeof(struct xfs_parent_name_rec); + + *parentp = parent; + return 0; +} + +int +xfs_parent_defer_add( + struct xfs_trans *tp, + struct xfs_parent_defer *parent, + struct xfs_inode *dp, + struct xfs_name *parent_name, + xfs_dir2_dataptr_t diroffset, + struct xfs_inode *child) +{ + struct xfs_da_args *args = &parent->args; + + xfs_init_parent_name_rec(&parent->rec, dp, diroffset); + args->hashval = xfs_da_hashname(args->name, args->namelen); + + args->trans = tp; + args->dp = child; + if (parent_name) { + parent->args.value = (void *)parent_name->name; + parent->args.valuelen = parent_name->len; + } + + return xfs_attr_defer_add(args); +} + +void +__xfs_parent_cancel( + xfs_mount_t *mp, + struct xfs_parent_defer *parent) +{ + xlog_drop_incompat_feat(mp->m_log); + kmem_cache_free(xfs_parent_intent_cache, parent); +} + +unsigned int +xfs_pptr_calc_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + /* + * Pptrs are always the first attr in an attr tree, and never larger + * than a block + */ + return XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK) + + XFS_NEXTENTADD_SPACE_RES(mp, namelen, XFS_ATTR_FORK); +} + diff --git a/fs/xfs/libxfs/xfs_parent.h b/fs/xfs/libxfs/xfs_parent.h new file mode 100644 index 000000000000..d5a8c8e52cb5 --- /dev/null +++ b/fs/xfs/libxfs/xfs_parent.h @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Oracle, Inc. + * All Rights Reserved. + */ +#ifndef __XFS_PARENT_H__ +#define __XFS_PARENT_H__ + +extern struct kmem_cache *xfs_parent_intent_cache; + +/* + * Dynamically allocd structure used to wrap the needed data to pass around + * the defer ops machinery + */ +struct xfs_parent_defer { + struct xfs_parent_name_rec rec; + struct xfs_da_args args; +}; + +/* + * Parent pointer attribute prototypes + */ +void xfs_init_parent_name_rec(struct xfs_parent_name_rec *rec, + struct xfs_inode *ip, + uint32_t p_diroffset); +int __xfs_parent_init(struct xfs_mount *mp, struct xfs_parent_defer **parentp); + +static inline int +xfs_parent_start( + struct xfs_mount *mp, + struct xfs_parent_defer **pp) +{ + *pp = NULL; + + if (xfs_has_parent(mp)) + return __xfs_parent_init(mp, pp); + return 0; +} + +int xfs_parent_defer_add(struct xfs_trans *tp, struct xfs_parent_defer *parent, + struct xfs_inode *dp, struct xfs_name *parent_name, + xfs_dir2_dataptr_t diroffset, struct xfs_inode *child); +void __xfs_parent_cancel(struct xfs_mount *mp, struct xfs_parent_defer *parent); + +static inline void +xfs_parent_finish( + struct xfs_mount *mp, + struct xfs_parent_defer *p) +{ + if (p) + __xfs_parent_cancel(mp, p); +} + +unsigned int xfs_pptr_calc_space_res(struct xfs_mount *mp, + unsigned int namelen); + +#endif /* __XFS_PARENT_H__ */ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index a896ee4c9680..ba488310ea9c 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -37,6 +37,8 @@ #include "xfs_reflink.h" #include "xfs_ag.h" #include "xfs_log_priv.h" +#include "xfs_parent.h" +#include "xfs_xattr.h" struct kmem_cache *xfs_inode_cache; @@ -946,10 +948,32 @@ xfs_bumplink( xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); } +static unsigned int +xfs_create_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + unsigned int ret; + + ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen); + if (xfs_has_parent(mp)) + ret += xfs_pptr_calc_space_res(mp, namelen); + + return ret; +} + +static unsigned int +xfs_mkdir_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + return xfs_create_space_res(mp, namelen); +} + int xfs_create( struct user_namespace *mnt_userns, - xfs_inode_t *dp, + struct xfs_inode *dp, struct xfs_name *name, umode_t mode, dev_t rdev, @@ -961,7 +985,7 @@ xfs_create( struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; int error; - bool unlock_dp_on_error = false; + bool unlock_dp_on_error = false; prid_t prid; struct xfs_dquot *udqp = NULL; struct xfs_dquot *gdqp = NULL; @@ -969,6 +993,8 @@ xfs_create( struct xfs_trans_res *tres; uint resblks; xfs_ino_t ino; + xfs_dir2_dataptr_t diroffset; + struct xfs_parent_defer *parent; trace_xfs_create(dp, name); @@ -988,13 +1014,17 @@ xfs_create( return error; if (is_dir) { - resblks = XFS_MKDIR_SPACE_RES(mp, name->len); + resblks = xfs_mkdir_space_res(mp, name->len); tres = &M_RES(mp)->tr_mkdir; } else { - resblks = XFS_CREATE_SPACE_RES(mp, name->len); + resblks = xfs_create_space_res(mp, name->len); tres = &M_RES(mp)->tr_create; } + error = xfs_parent_start(mp, &parent); + if (error) + goto out_release_dquots; + /* * Initially assume that the file does not exist and * reserve the resources for that case. If that is not @@ -1010,7 +1040,7 @@ xfs_create( resblks, &tp); } if (error) - goto out_release_dquots; + goto out_parent; xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); unlock_dp_on_error = true; @@ -1020,6 +1050,7 @@ xfs_create( * entry pointing to them, but a directory also the "." entry * pointing to itself. */ + init_xattrs = init_xattrs || xfs_has_parent(mp); error = xfs_dialloc(&tp, dp->i_ino, mode, &ino); if (!error) error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode, @@ -1034,11 +1065,11 @@ xfs_create( * the transaction cancel unlocking dp so don't do it explicitly in the * error path. */ - xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); - unlock_dp_on_error = false; + xfs_trans_ijoin(tp, dp, 0); error = xfs_dir_createname(tp, dp, name, ip->i_ino, - resblks - XFS_IALLOC_SPACE_RES(mp), NULL); + resblks - XFS_IALLOC_SPACE_RES(mp), + &diroffset); if (error) { ASSERT(error != -ENOSPC); goto out_trans_cancel; @@ -1054,6 +1085,17 @@ xfs_create( xfs_bumplink(tp, dp); } + /* + * If we have parent pointers, we need to add the attribute containing + * the parent information now. + */ + if (parent) { + error = xfs_parent_defer_add(tp, parent, dp, name, diroffset, + ip); + if (error) + goto out_trans_cancel; + } + /* * If this is a synchronous mount, make sure that the * create transaction goes to disk before returning to @@ -1079,6 +1121,8 @@ xfs_create( *ipp = ip; xfs_iunlock(ip, XFS_ILOCK_EXCL); + xfs_iunlock(dp, XFS_ILOCK_EXCL); + xfs_parent_finish(mp, parent); return 0; out_trans_cancel: @@ -1090,10 +1134,12 @@ xfs_create( * transactions and deadlocks from xfs_inactive. */ if (ip) { + xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_finish_inode_setup(ip); xfs_irele(ip); - xfs_iunlock(ip, XFS_ILOCK_EXCL); } + out_parent: + xfs_parent_finish(mp, parent); out_release_dquots: xfs_qm_dqrele(udqp); xfs_qm_dqrele(gdqp); diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 0c4b73e9b29d..6795761c31e0 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -41,6 +41,7 @@ #include "xfs_attr_item.h" #include "xfs_xattr.h" #include "xfs_iunlink_item.h" +#include "xfs_parent.h" #include #include @@ -2115,8 +2116,16 @@ xfs_init_caches(void) if (!xfs_iunlink_cache) goto out_destroy_attri_cache; + xfs_parent_intent_cache = kmem_cache_create("xfs_parent_intent", + sizeof(struct xfs_parent_defer), + 0, 0, NULL); + if (!xfs_parent_intent_cache) + goto out_destroy_iul_cache; + return 0; + out_destroy_iul_cache: + kmem_cache_destroy(xfs_iunlink_cache); out_destroy_attri_cache: kmem_cache_destroy(xfs_attri_cache); out_destroy_attrd_cache: @@ -2171,6 +2180,7 @@ xfs_destroy_caches(void) * destroy caches. */ rcu_barrier(); + kmem_cache_destroy(xfs_parent_intent_cache); kmem_cache_destroy(xfs_iunlink_cache); kmem_cache_destroy(xfs_attri_cache); kmem_cache_destroy(xfs_attrd_cache); diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c index 10aa1fd39d2b..8bb5f53a31fe 100644 --- a/fs/xfs/xfs_xattr.c +++ b/fs/xfs/xfs_xattr.c @@ -27,7 +27,7 @@ * they must release the permission by calling xlog_drop_incompat_feat * when they're done. */ -static inline int +int xfs_attr_grab_log_assist( struct xfs_mount *mp) { @@ -61,7 +61,7 @@ xfs_attr_grab_log_assist( return error; } -static inline void +void xfs_attr_rele_log_assist( struct xfs_mount *mp) { diff --git a/fs/xfs/xfs_xattr.h b/fs/xfs/xfs_xattr.h index 2b09133b1b9b..7e0a2f3bb7f8 100644 --- a/fs/xfs/xfs_xattr.h +++ b/fs/xfs/xfs_xattr.h @@ -7,6 +7,8 @@ #define __XFS_XATTR_H__ int xfs_attr_change(struct xfs_da_args *args); +int xfs_attr_grab_log_assist(struct xfs_mount *mp); +void xfs_attr_rele_log_assist(struct xfs_mount *mp); extern const struct xattr_handler *xfs_xattr_handlers[]; From patchwork Thu Feb 16 20:36:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FD08C636CC for ; Thu, 16 Feb 2023 20:36:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjBPUgx (ORCPT ); Thu, 16 Feb 2023 15:36:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjBPUgw (ORCPT ); Thu, 16 Feb 2023 15:36:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2CDD7288 for ; Thu, 16 Feb 2023 12:36:51 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3ED3860B3A for ; Thu, 16 Feb 2023 20:36:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97B82C433EF; Thu, 16 Feb 2023 20:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579810; bh=B/l6UY8uQv25QF7Hb3mkKMg8zzlnk2IzdAmnmimP5Og=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=upuPRnbKIZBFEoBa6ofwkayVxlmzu5E210YDnk9WCxE/0AIzHRiMneEHADbW+1Wl7 bWbXGqGdg6lDusxTLhd7+6lM5WkEvg3b7iWaJQlhYcr7ijlqVT4gWE0OipHnu8mi60 UA7d4qfdQ4ea0VvPPDBdNsqcirgmpCu0UrnbvA7QMd7XNKgdvM8JHWd3bWJLOrE0H2 nRgUdDlaQ30yX8IjFrp5aFX5NKj8WkpM8Nyko458BWpm9UeqkdxNXcwNe6y8QlOb6z FQ3tgIFl1KgfrrJFObmkTgGUsgJ2VTemyWN8OJeO6ttwABaynkhFewpZivXdWZeFdf Vpc+VDQaqJfJg== Date: Thu, 16 Feb 2023 12:36:50 -0800 Subject: [PATCH 16/28] xfs: add parent attributes to link From: "Darrick J. Wong" To: djwong@kernel.org Cc: Dave Chinner , Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872610.3473407.6167059905518183897.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson This patch modifies xfs_link to add a parent pointer to the inode. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_trans_space.h | 2 - fs/xfs/xfs_inode.c | 60 ++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_space.h b/fs/xfs/libxfs/xfs_trans_space.h index 87b31c69a773..f72207923ec2 100644 --- a/fs/xfs/libxfs/xfs_trans_space.h +++ b/fs/xfs/libxfs/xfs_trans_space.h @@ -84,8 +84,6 @@ (2 * (mp)->m_alloc_maxlevels) #define XFS_GROWFSRT_SPACE_RES(mp,b) \ ((b) + XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK)) -#define XFS_LINK_SPACE_RES(mp,nl) \ - XFS_DIRENTER_SPACE_RES(mp,nl) #define XFS_MKDIR_SPACE_RES(mp,nl) \ (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) #define XFS_QM_DQALLOC_SPACE_RES(mp) \ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index ba488310ea9c..b4318df03b5c 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -1247,16 +1247,32 @@ xfs_create_tmpfile( return error; } +static unsigned int +xfs_link_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + unsigned int ret; + + ret = XFS_DIRENTER_SPACE_RES(mp, namelen); + if (xfs_has_parent(mp)) + ret += xfs_pptr_calc_space_res(mp, namelen); + + return ret; +} + int xfs_link( - xfs_inode_t *tdp, - xfs_inode_t *sip, + struct xfs_inode *tdp, + struct xfs_inode *sip, struct xfs_name *target_name) { - xfs_mount_t *mp = tdp->i_mount; - xfs_trans_t *tp; + struct xfs_mount *mp = tdp->i_mount; + struct xfs_trans *tp; int error, nospace_error = 0; int resblks; + xfs_dir2_dataptr_t diroffset; + struct xfs_parent_defer *parent = NULL; trace_xfs_link(tdp, target_name); @@ -1273,11 +1289,25 @@ xfs_link( if (error) goto std_return; - resblks = XFS_LINK_SPACE_RES(mp, target_name->len); + error = xfs_parent_start(mp, &parent); + if (error) + goto std_return; + + resblks = xfs_link_space_res(mp, target_name->len); error = xfs_trans_alloc_dir(tdp, &M_RES(mp)->tr_link, sip, &resblks, &tp, &nospace_error); if (error) - goto std_return; + goto out_parent; + + /* + * We don't allow reservationless or quotaless hardlinking when parent + * pointers are enabled because we can't back out if the xattrs must + * grow. + */ + if (parent && nospace_error) { + error = nospace_error; + goto error_return; + } /* * If we are using project inheritance, we only allow hard link @@ -1310,7 +1340,7 @@ xfs_link( } error = xfs_dir_createname(tp, tdp, target_name, sip->i_ino, - resblks, NULL); + resblks, &diroffset); if (error) goto error_return; xfs_trans_ichgtime(tp, tdp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); @@ -1318,6 +1348,19 @@ xfs_link( xfs_bumplink(tp, sip); + /* + * If we have parent pointers, we now need to add the parent record to + * the attribute fork of the inode. If this is the initial parent + * attribute, we need to create it correctly, otherwise we can just add + * the parent to the inode. + */ + if (parent) { + error = xfs_parent_defer_add(tp, parent, tdp, target_name, + diroffset, sip); + if (error) + goto error_return; + } + /* * If this is a synchronous mount, make sure that the * link transaction goes to disk before returning to @@ -1329,12 +1372,15 @@ xfs_link( error = xfs_trans_commit(tp); xfs_iunlock(tdp, XFS_ILOCK_EXCL); xfs_iunlock(sip, XFS_ILOCK_EXCL); + xfs_parent_finish(mp, parent); return error; error_return: xfs_trans_cancel(tp); xfs_iunlock(tdp, XFS_ILOCK_EXCL); xfs_iunlock(sip, XFS_ILOCK_EXCL); + out_parent: + xfs_parent_finish(mp, parent); std_return: if (error == -ENOSPC && nospace_error) error = nospace_error; From patchwork Thu Feb 16 20:37:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8228CC61DA4 for ; Thu, 16 Feb 2023 20:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbjBPUhK (ORCPT ); Thu, 16 Feb 2023 15:37:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjBPUhK (ORCPT ); Thu, 16 Feb 2023 15:37:10 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9738D505 for ; Thu, 16 Feb 2023 12:37:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8DE76B829A7 for ; Thu, 16 Feb 2023 20:37:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3909DC433EF; Thu, 16 Feb 2023 20:37:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579826; bh=xLf4Lb0ntkI/zAWGxBgjhsCRKhomJ2WZxNRWfMWKiSg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=T1OMzyWUWDOQAG50fuwFY/uTlx3KgfuNkccXcou548EpV+ExH+/zeqXKb/s4hDlJx Is3z0fZqqLqUFuR5z3R8AVfeZOYv9g4AAZLzLnwJ9RXwVs33T/ZzShZTg/A9jESAew D8/5D8xfcuEw6TAl8+Kny05NwG/d+FSobbhqTmR4uWBIEEznUcZA9znOY+vqX+S68/ 4A9icEyjfPPCg6zPTfpw23bBJEX/dSLlP23MsqhtIBSigFil8usz+uzlGLMnBBjKWq Ol+oklfme3nkoYhj6KwKZFY57JCRqWtr4SUPqop/Dbwj7KScnKweGrEOuY4VuECYuv N/UlAMCExBXuA== Date: Thu, 16 Feb 2023 12:37:05 -0800 Subject: [PATCH 17/28] xfs: add parent attributes to symlink From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872625.3473407.12362172628393928186.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson This patch modifies xfs_symlink to add a parent pointer to the inode. Signed-off-by: Allison Henderson --- fs/xfs/libxfs/xfs_trans_space.h | 2 - fs/xfs/xfs_symlink.c | 58 ++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/fs/xfs/libxfs/xfs_trans_space.h b/fs/xfs/libxfs/xfs_trans_space.h index f72207923ec2..25a55650baf4 100644 --- a/fs/xfs/libxfs/xfs_trans_space.h +++ b/fs/xfs/libxfs/xfs_trans_space.h @@ -95,8 +95,6 @@ XFS_DIRREMOVE_SPACE_RES(mp) #define XFS_RENAME_SPACE_RES(mp,nl) \ (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) -#define XFS_SYMLINK_SPACE_RES(mp,nl,b) \ - (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b)) #define XFS_IFREE_SPACE_RES(mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0) diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c index 27a7d7c57015..f305226109f0 100644 --- a/fs/xfs/xfs_symlink.c +++ b/fs/xfs/xfs_symlink.c @@ -23,6 +23,8 @@ #include "xfs_trans.h" #include "xfs_ialloc.h" #include "xfs_error.h" +#include "xfs_parent.h" +#include "xfs_defer.h" /* ----- Kernel only functions below ----- */ int @@ -142,6 +144,23 @@ xfs_readlink( return error; } +static unsigned int +xfs_symlink_space_res( + struct xfs_mount *mp, + unsigned int namelen, + unsigned int fsblocks) +{ + unsigned int ret; + + ret = XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp, namelen) + + fsblocks; + + if (xfs_has_parent(mp)) + ret += xfs_pptr_calc_space_res(mp, namelen); + + return ret; +} + int xfs_symlink( struct user_namespace *mnt_userns, @@ -172,6 +191,8 @@ xfs_symlink( struct xfs_dquot *pdqp = NULL; uint resblks; xfs_ino_t ino; + xfs_dir2_dataptr_t diroffset; + struct xfs_parent_defer *parent; *ipp = NULL; @@ -202,18 +223,24 @@ xfs_symlink( /* * The symlink will fit into the inode data fork? - * There can't be any attributes so we get the whole variable part. + * If there are no parent pointers, then there wont't be any attributes. + * So we get the whole variable part, and do not need to reserve extra + * blocks. Otherwise, we need to reserve the blocks. */ - if (pathlen <= XFS_LITINO(mp)) + if (pathlen <= XFS_LITINO(mp) && !xfs_has_parent(mp)) fs_blocks = 0; else fs_blocks = xfs_symlink_blocks(mp, pathlen); - resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks); + resblks = xfs_symlink_space_res(mp, link_name->len, fs_blocks); + + error = xfs_parent_start(mp, &parent); + if (error) + goto out_release_dquots; error = xfs_trans_alloc_icreate(mp, &M_RES(mp)->tr_symlink, udqp, gdqp, pdqp, resblks, &tp); if (error) - goto out_release_dquots; + goto out_parent; xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); unlock_dp_on_error = true; @@ -233,7 +260,7 @@ xfs_symlink( if (!error) error = xfs_init_new_inode(mnt_userns, tp, dp, ino, S_IFLNK | (mode & ~S_IFMT), 1, 0, prid, - false, &ip); + xfs_has_parent(mp), &ip); if (error) goto out_trans_cancel; @@ -244,8 +271,7 @@ xfs_symlink( * the transaction cancel unlocking dp so don't do it explicitly in the * error path. */ - xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); - unlock_dp_on_error = false; + xfs_trans_ijoin(tp, dp, 0); /* * Also attach the dquot(s) to it, if applicable. @@ -315,12 +341,20 @@ xfs_symlink( * Create the directory entry for the symlink. */ error = xfs_dir_createname(tp, dp, link_name, - ip->i_ino, resblks, NULL); + ip->i_ino, resblks, &diroffset); if (error) goto out_trans_cancel; xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); + if (parent) { + error = xfs_parent_defer_add(tp, parent, dp, link_name, + diroffset, ip); + if (error) + goto out_trans_cancel; + } + + /* * If this is a synchronous mount, make sure that the * symlink transaction goes to disk before returning to @@ -339,6 +373,8 @@ xfs_symlink( *ipp = ip; xfs_iunlock(ip, XFS_ILOCK_EXCL); + xfs_iunlock(dp, XFS_ILOCK_EXCL); + xfs_parent_finish(mp, parent); return 0; out_trans_cancel: @@ -350,9 +386,12 @@ xfs_symlink( * transactions and deadlocks from xfs_inactive. */ if (ip) { + xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_finish_inode_setup(ip); xfs_irele(ip); } +out_parent: + xfs_parent_finish(mp, parent); out_release_dquots: xfs_qm_dqrele(udqp); xfs_qm_dqrele(gdqp); @@ -360,8 +399,7 @@ xfs_symlink( if (unlock_dp_on_error) xfs_iunlock(dp, XFS_ILOCK_EXCL); - if (ip) - xfs_iunlock(ip, XFS_ILOCK_EXCL); + return error; } From patchwork Thu Feb 16 20:37:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F16C4C636CC for ; Thu, 16 Feb 2023 20:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229506AbjBPUh0 (ORCPT ); Thu, 16 Feb 2023 15:37:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229764AbjBPUhZ (ORCPT ); Thu, 16 Feb 2023 15:37:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 779C2D505 for ; Thu, 16 Feb 2023 12:37:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2EB28B826BA for ; Thu, 16 Feb 2023 20:37:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAB73C433EF; Thu, 16 Feb 2023 20:37:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579841; bh=M8YD+8rKE3mJ3o/zsXUt7fG1b1BqE+A3JMOmOabDa8w=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Sx4hIIh/1DxKF/tYFkt287UJf7Ykz8N7Z58qQNKsN62SneY+YvySV1/sJEsCd/lRQ XMhm+I+EWzNQGJIvNU0cUfYHGhugjrweMbhTLiCwLnDhfalpyiu5mWLN5yVAehNOS2 9lmtvPAhTNEgS4DcztM89kf7uusHiTsGHWQ8TvOr6WWgEBE41pW2ZkXFP/6+PeOcvF 9YG9xH7TTr5qy7qmDw2TPmA9f3dWCBSUb0SDGFrZU8EKuhL+gIEnGpJjiVlKyhJjbx emJNUlmVfYAxD9OpL+akHn7TmDEScJbRBAXMjQdNdCSLSJckliB1a3551CghF3e38Q xJ55ayV7fBCjg== Date: Thu, 16 Feb 2023 12:37:21 -0800 Subject: [PATCH 18/28] xfs: remove parent pointers in unlink From: "Darrick J. Wong" To: djwong@kernel.org Cc: Dave Chinner , Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872640.3473407.7393115324146048389.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson This patch removes the parent pointer attribute during unlink Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr.c | 2 +- fs/xfs/libxfs/xfs_attr.h | 1 + fs/xfs/libxfs/xfs_parent.c | 17 ++++++++++++++++ fs/xfs/libxfs/xfs_parent.h | 5 +++++ fs/xfs/libxfs/xfs_trans_space.h | 2 -- fs/xfs/xfs_inode.c | 42 +++++++++++++++++++++++++++++++++------ 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index f68d41f0f998..a8db44728b11 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -946,7 +946,7 @@ xfs_attr_defer_replace( } /* Removes an attribute for an inode as a deferred operation */ -static int +int xfs_attr_defer_remove( struct xfs_da_args *args) { diff --git a/fs/xfs/libxfs/xfs_attr.h b/fs/xfs/libxfs/xfs_attr.h index 0cf23f5117ad..033005542b9e 100644 --- a/fs/xfs/libxfs/xfs_attr.h +++ b/fs/xfs/libxfs/xfs_attr.h @@ -545,6 +545,7 @@ bool xfs_attr_is_leaf(struct xfs_inode *ip); int xfs_attr_get_ilocked(struct xfs_da_args *args); int xfs_attr_get(struct xfs_da_args *args); int xfs_attr_defer_add(struct xfs_da_args *args); +int xfs_attr_defer_remove(struct xfs_da_args *args); int xfs_attr_set(struct xfs_da_args *args); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); diff --git a/fs/xfs/libxfs/xfs_parent.c b/fs/xfs/libxfs/xfs_parent.c index 6b6d415319e6..245855a5f969 100644 --- a/fs/xfs/libxfs/xfs_parent.c +++ b/fs/xfs/libxfs/xfs_parent.c @@ -115,6 +115,23 @@ xfs_parent_defer_add( return xfs_attr_defer_add(args); } +int +xfs_parent_defer_remove( + struct xfs_trans *tp, + struct xfs_inode *dp, + struct xfs_parent_defer *parent, + xfs_dir2_dataptr_t diroffset, + struct xfs_inode *child) +{ + struct xfs_da_args *args = &parent->args; + + xfs_init_parent_name_rec(&parent->rec, dp, diroffset); + args->trans = tp; + args->dp = child; + args->hashval = xfs_da_hashname(args->name, args->namelen); + return xfs_attr_defer_remove(args); +} + void __xfs_parent_cancel( xfs_mount_t *mp, diff --git a/fs/xfs/libxfs/xfs_parent.h b/fs/xfs/libxfs/xfs_parent.h index d5a8c8e52cb5..0f39d033d84e 100644 --- a/fs/xfs/libxfs/xfs_parent.h +++ b/fs/xfs/libxfs/xfs_parent.h @@ -40,6 +40,11 @@ xfs_parent_start( int xfs_parent_defer_add(struct xfs_trans *tp, struct xfs_parent_defer *parent, struct xfs_inode *dp, struct xfs_name *parent_name, xfs_dir2_dataptr_t diroffset, struct xfs_inode *child); +int xfs_parent_defer_remove(struct xfs_trans *tp, struct xfs_inode *dp, + struct xfs_parent_defer *parent, + xfs_dir2_dataptr_t diroffset, + struct xfs_inode *child); + void __xfs_parent_cancel(struct xfs_mount *mp, struct xfs_parent_defer *parent); static inline void diff --git a/fs/xfs/libxfs/xfs_trans_space.h b/fs/xfs/libxfs/xfs_trans_space.h index 25a55650baf4..b5ab6701e7fb 100644 --- a/fs/xfs/libxfs/xfs_trans_space.h +++ b/fs/xfs/libxfs/xfs_trans_space.h @@ -91,8 +91,6 @@ XFS_DQUOT_CLUSTER_SIZE_FSB) #define XFS_QM_QINOCREATE_SPACE_RES(mp) \ XFS_IALLOC_SPACE_RES(mp) -#define XFS_REMOVE_SPACE_RES(mp) \ - XFS_DIRREMOVE_SPACE_RES(mp) #define XFS_RENAME_SPACE_RES(mp,nl) \ (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) #define XFS_IFREE_SPACE_RES(mp) \ diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index b4318df03b5c..7b34ca2de569 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2477,6 +2477,19 @@ xfs_iunpin_wait( __xfs_iunpin_wait(ip); } +static unsigned int +xfs_remove_space_res( + struct xfs_mount *mp, + unsigned int namelen) +{ + unsigned int ret = XFS_DIRREMOVE_SPACE_RES(mp); + + if (xfs_has_parent(mp)) + ret += xfs_pptr_calc_space_res(mp, namelen); + + return ret; +} + /* * Removing an inode from the namespace involves removing the directory entry * and dropping the link count on the inode. Removing the directory entry can @@ -2506,16 +2519,18 @@ xfs_iunpin_wait( */ int xfs_remove( - xfs_inode_t *dp, + struct xfs_inode *dp, struct xfs_name *name, - xfs_inode_t *ip) + struct xfs_inode *ip) { - xfs_mount_t *mp = dp->i_mount; - xfs_trans_t *tp = NULL; + struct xfs_mount *mp = dp->i_mount; + struct xfs_trans *tp = NULL; int is_dir = S_ISDIR(VFS_I(ip)->i_mode); int dontcare; int error = 0; uint resblks; + xfs_dir2_dataptr_t dir_offset; + struct xfs_parent_defer *parent = NULL; trace_xfs_remove(dp, name); @@ -2530,6 +2545,10 @@ xfs_remove( if (error) goto std_return; + error = xfs_parent_start(mp, &parent); + if (error) + goto std_return; + /* * We try to get the real space reservation first, allowing for * directory btree deletion(s) implying possible bmap insert(s). If we @@ -2541,12 +2560,12 @@ xfs_remove( * the directory code can handle a reservationless update and we don't * want to prevent a user from trying to free space by deleting things. */ - resblks = XFS_REMOVE_SPACE_RES(mp); + resblks = xfs_remove_space_res(mp, name->len); error = xfs_trans_alloc_dir(dp, &M_RES(mp)->tr_remove, ip, &resblks, &tp, &dontcare); if (error) { ASSERT(error != -ENOSPC); - goto std_return; + goto out_parent; } /* @@ -2600,12 +2619,18 @@ xfs_remove( if (error) goto out_trans_cancel; - error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, NULL); + error = xfs_dir_removename(tp, dp, name, ip->i_ino, resblks, &dir_offset); if (error) { ASSERT(error != -ENOENT); goto out_trans_cancel; } + if (parent) { + error = xfs_parent_defer_remove(tp, dp, parent, dir_offset, ip); + if (error) + goto out_trans_cancel; + } + /* * If this is a synchronous mount, make sure that the * remove transaction goes to disk before returning to @@ -2623,6 +2648,7 @@ xfs_remove( xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_iunlock(dp, XFS_ILOCK_EXCL); + xfs_parent_finish(mp, parent); return 0; out_trans_cancel: @@ -2630,6 +2656,8 @@ xfs_remove( out_unlock: xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_iunlock(dp, XFS_ILOCK_EXCL); + out_parent: + xfs_parent_finish(mp, parent); std_return: return error; } From patchwork Thu Feb 16 20:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18573C636CC for ; Thu, 16 Feb 2023 20:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbjBPUhm (ORCPT ); Thu, 16 Feb 2023 15:37:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbjBPUhl (ORCPT ); Thu, 16 Feb 2023 15:37:41 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ABEE2A6DC for ; Thu, 16 Feb 2023 12:37:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B5E37B829AC for ; Thu, 16 Feb 2023 20:37:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F355C433EF; Thu, 16 Feb 2023 20:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579857; bh=TSZKUn/fGIq79buNH5NYWgRkNgMC2ZveSMypYFqO1gM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=dguzzyR2ZajLM7ycPDQBThSGhmAccGbIJPcy8oIiDr52/R7zpNKNOCS46frahMg6t PdHj3eF/Q2BTwY/e7kC4xddrHqBp7CDz4KwNBnNJSHkr/GFquN4aAne3Uoe4qWRNt9 1FYJSjlgl4/bNcvCcgxW7zhvXVnaHO2aIMPR6hRMJ8J9lOV4rr/+JQVOiKKT0GKuNp DNk52G3o/7YBZy0woMYzp7N4/6ot4tdFWf7XsoEwpjL7p3ez6JgVPeLGB7a3hcEPay /WlEFgf83MBxi0/67ACcwyVaLT9Zr56Vee6DqrIX6GVDZ6o2PI2Nhus7JGBWroFji2 igHCpw+aXCVKA== Date: Thu, 16 Feb 2023 12:37:36 -0800 Subject: [PATCH 19/28] xfs: Indent xfs_rename From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872655.3473407.2603580719369341628.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Indent variables and parameters in xfs_rename in preparation for parent pointer modifications. White space only, no functional changes. This will make reviewing new code easier on reviewers. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_inode.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 7b34ca2de569..2d8f225cb57d 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2902,26 +2902,27 @@ xfs_rename_alloc_whiteout( */ int xfs_rename( - struct user_namespace *mnt_userns, - struct xfs_inode *src_dp, - struct xfs_name *src_name, - struct xfs_inode *src_ip, - struct xfs_inode *target_dp, - struct xfs_name *target_name, - struct xfs_inode *target_ip, - unsigned int flags) + struct user_namespace *mnt_userns, + struct xfs_inode *src_dp, + struct xfs_name *src_name, + struct xfs_inode *src_ip, + struct xfs_inode *target_dp, + struct xfs_name *target_name, + struct xfs_inode *target_ip, + unsigned int flags) { - struct xfs_mount *mp = src_dp->i_mount; - struct xfs_trans *tp; - struct xfs_inode *wip = NULL; /* whiteout inode */ - struct xfs_inode *inodes[__XFS_SORT_INODES]; - int i; - int num_inodes = __XFS_SORT_INODES; - bool new_parent = (src_dp != target_dp); - bool src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode); - int spaceres; - bool retried = false; - int error, nospace_error = 0; + struct xfs_mount *mp = src_dp->i_mount; + struct xfs_trans *tp; + struct xfs_inode *wip = NULL; /* whiteout inode */ + struct xfs_inode *inodes[__XFS_SORT_INODES]; + int i; + int num_inodes = __XFS_SORT_INODES; + bool new_parent = (src_dp != target_dp); + bool src_is_directory = + S_ISDIR(VFS_I(src_ip)->i_mode); + int spaceres; + bool retried = false; + int error, nospace_error = 0; trace_xfs_rename(src_dp, target_dp, src_name, target_name); From patchwork Thu Feb 16 20:37:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0A10C61DA4 for ; Thu, 16 Feb 2023 20:37:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbjBPUh5 (ORCPT ); Thu, 16 Feb 2023 15:37:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjBPUhz (ORCPT ); Thu, 16 Feb 2023 15:37:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 222E6C64B for ; Thu, 16 Feb 2023 12:37:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A469760C0D for ; Thu, 16 Feb 2023 20:37:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10260C433EF; Thu, 16 Feb 2023 20:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579873; bh=jp1tVkkQz6ODQam1C0xiEDF8g4JQIc0QATo2F9x4BFo=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=LmUb1raHCGe9OMVIVFYJbZrc5u7D7tc6E49umWZtOSNC9qDIqCDD1dHE91Os0G6/9 px09yaCsBnvLj7UzTLfmG56Z17/ZKpP0GAB69rf16TxucsAFgF08w7X3yodLVjYm89 YnFXIqk2Gh+9SQOKqaPghIS1Yjtn2nNSXq7bOad0EzhoR5gjO7ZdO+2SJJNjFl/MZq hboysrFgPnBdUtUA893TVmyQ6VHJaRMPweEBcsn0mFxe1lXRy7CV0HoSWShfX1+UTe lmCc5wCfsLAG441Gy/raHgAnsaa13EiUGX9FtsAQ9lQCmAtqAU1AUbhShWwRamRuto 3capdrA9mvh7g== Date: Thu, 16 Feb 2023 12:37:52 -0800 Subject: [PATCH 20/28] xfs: Add parent pointers to rename From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872670.3473407.14365632577962680788.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson This patch removes the old parent pointer attribute during the rename operation, and re-adds the updated parent pointer. Signed-off-by: Allison Henderson --- fs/xfs/libxfs/xfs_attr.c | 2 - fs/xfs/libxfs/xfs_attr.h | 1 fs/xfs/libxfs/xfs_parent.c | 47 ++++++++++++++-- fs/xfs/libxfs/xfs_parent.h | 24 +++++++- fs/xfs/libxfs/xfs_trans_space.h | 2 - fs/xfs/xfs_inode.c | 117 ++++++++++++++++++++++++++++++++++++--- 6 files changed, 174 insertions(+), 19 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr.c b/fs/xfs/libxfs/xfs_attr.c index a8db44728b11..57080ea4c869 100644 --- a/fs/xfs/libxfs/xfs_attr.c +++ b/fs/xfs/libxfs/xfs_attr.c @@ -923,7 +923,7 @@ xfs_attr_defer_add( } /* Sets an attribute for an inode as a deferred operation */ -static int +int xfs_attr_defer_replace( struct xfs_da_args *args) { diff --git a/fs/xfs/libxfs/xfs_attr.h b/fs/xfs/libxfs/xfs_attr.h index 033005542b9e..985761264d1f 100644 --- a/fs/xfs/libxfs/xfs_attr.h +++ b/fs/xfs/libxfs/xfs_attr.h @@ -546,6 +546,7 @@ int xfs_attr_get_ilocked(struct xfs_da_args *args); int xfs_attr_get(struct xfs_da_args *args); int xfs_attr_defer_add(struct xfs_da_args *args); int xfs_attr_defer_remove(struct xfs_da_args *args); +int xfs_attr_defer_replace(struct xfs_da_args *args); int xfs_attr_set(struct xfs_da_args *args); int xfs_attr_set_iter(struct xfs_attr_intent *attr); int xfs_attr_remove_iter(struct xfs_attr_intent *attr); diff --git a/fs/xfs/libxfs/xfs_parent.c b/fs/xfs/libxfs/xfs_parent.c index 245855a5f969..629762701952 100644 --- a/fs/xfs/libxfs/xfs_parent.c +++ b/fs/xfs/libxfs/xfs_parent.c @@ -64,22 +64,27 @@ xfs_init_parent_name_rec( int __xfs_parent_init( struct xfs_mount *mp, + bool grab_log, struct xfs_parent_defer **parentp) { struct xfs_parent_defer *parent; int error; - error = xfs_attr_grab_log_assist(mp); - if (error) - return error; + if (grab_log) { + error = xfs_attr_grab_log_assist(mp); + if (error) + return error; + } parent = kmem_cache_zalloc(xfs_parent_intent_cache, GFP_KERNEL); if (!parent) { - xfs_attr_rele_log_assist(mp); + if (grab_log) + xfs_attr_rele_log_assist(mp); return -ENOMEM; } /* init parent da_args */ + parent->have_log = grab_log; parent->args.geo = mp->m_attr_geo; parent->args.whichfork = XFS_ATTR_FORK; parent->args.attr_filter = XFS_ATTR_PARENT; @@ -132,12 +137,44 @@ xfs_parent_defer_remove( return xfs_attr_defer_remove(args); } + +int +xfs_parent_defer_replace( + struct xfs_trans *tp, + struct xfs_parent_defer *new_parent, + struct xfs_inode *old_dp, + xfs_dir2_dataptr_t old_diroffset, + struct xfs_name *parent_name, + struct xfs_inode *new_dp, + xfs_dir2_dataptr_t new_diroffset, + struct xfs_inode *child) +{ + struct xfs_da_args *args = &new_parent->args; + + xfs_init_parent_name_rec(&new_parent->old_rec, old_dp, old_diroffset); + xfs_init_parent_name_rec(&new_parent->rec, new_dp, new_diroffset); + new_parent->args.name = (const uint8_t *)&new_parent->old_rec; + new_parent->args.namelen = sizeof(struct xfs_parent_name_rec); + new_parent->args.new_name = (const uint8_t *)&new_parent->rec; + new_parent->args.new_namelen = sizeof(struct xfs_parent_name_rec); + args->trans = tp; + args->dp = child; + + ASSERT(parent_name != NULL); + new_parent->args.value = (void *)parent_name->name; + new_parent->args.valuelen = parent_name->len; + + args->hashval = xfs_da_hashname(args->name, args->namelen); + return xfs_attr_defer_replace(args); +} + void __xfs_parent_cancel( xfs_mount_t *mp, struct xfs_parent_defer *parent) { - xlog_drop_incompat_feat(mp->m_log); + if (parent->have_log) + xlog_drop_incompat_feat(mp->m_log); kmem_cache_free(xfs_parent_intent_cache, parent); } diff --git a/fs/xfs/libxfs/xfs_parent.h b/fs/xfs/libxfs/xfs_parent.h index 0f39d033d84e..039005883bb6 100644 --- a/fs/xfs/libxfs/xfs_parent.h +++ b/fs/xfs/libxfs/xfs_parent.h @@ -14,7 +14,9 @@ extern struct kmem_cache *xfs_parent_intent_cache; */ struct xfs_parent_defer { struct xfs_parent_name_rec rec; + struct xfs_parent_name_rec old_rec; struct xfs_da_args args; + bool have_log; }; /* @@ -23,7 +25,8 @@ struct xfs_parent_defer { void xfs_init_parent_name_rec(struct xfs_parent_name_rec *rec, struct xfs_inode *ip, uint32_t p_diroffset); -int __xfs_parent_init(struct xfs_mount *mp, struct xfs_parent_defer **parentp); +int __xfs_parent_init(struct xfs_mount *mp, bool grab_log, + struct xfs_parent_defer **parentp); static inline int xfs_parent_start( @@ -33,13 +36,30 @@ xfs_parent_start( *pp = NULL; if (xfs_has_parent(mp)) - return __xfs_parent_init(mp, pp); + return __xfs_parent_init(mp, true, pp); + return 0; +} + +static inline int +xfs_parent_start_locked( + struct xfs_mount *mp, + struct xfs_parent_defer **pp) +{ + *pp = NULL; + + if (xfs_has_parent(mp)) + return __xfs_parent_init(mp, false, pp); return 0; } int xfs_parent_defer_add(struct xfs_trans *tp, struct xfs_parent_defer *parent, struct xfs_inode *dp, struct xfs_name *parent_name, xfs_dir2_dataptr_t diroffset, struct xfs_inode *child); +int xfs_parent_defer_replace(struct xfs_trans *tp, + struct xfs_parent_defer *new_parent, struct xfs_inode *old_dp, + xfs_dir2_dataptr_t old_diroffset, struct xfs_name *parent_name, + struct xfs_inode *new_ip, xfs_dir2_dataptr_t new_diroffset, + struct xfs_inode *child); int xfs_parent_defer_remove(struct xfs_trans *tp, struct xfs_inode *dp, struct xfs_parent_defer *parent, xfs_dir2_dataptr_t diroffset, diff --git a/fs/xfs/libxfs/xfs_trans_space.h b/fs/xfs/libxfs/xfs_trans_space.h index b5ab6701e7fb..810610a14c4d 100644 --- a/fs/xfs/libxfs/xfs_trans_space.h +++ b/fs/xfs/libxfs/xfs_trans_space.h @@ -91,8 +91,6 @@ XFS_DQUOT_CLUSTER_SIZE_FSB) #define XFS_QM_QINOCREATE_SPACE_RES(mp) \ XFS_IALLOC_SPACE_RES(mp) -#define XFS_RENAME_SPACE_RES(mp,nl) \ - (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl)) #define XFS_IFREE_SPACE_RES(mp) \ (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 2d8f225cb57d..cdbd7df64ff0 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2871,7 +2871,7 @@ xfs_rename_alloc_whiteout( int error; error = xfs_create_tmpfile(mnt_userns, dp, S_IFCHR | WHITEOUT_MODE, - false, &tmpfile); + xfs_has_parent(dp->i_mount), &tmpfile); if (error) return error; @@ -2897,6 +2897,31 @@ xfs_rename_alloc_whiteout( return 0; } +static unsigned int +xfs_rename_space_res( + struct xfs_mount *mp, + struct xfs_name *src_name, + struct xfs_parent_defer *target_parent_ptr, + struct xfs_name *target_name, + struct xfs_parent_defer *new_parent_ptr, + struct xfs_inode *wip) +{ + unsigned int ret; + + ret = XFS_DIRREMOVE_SPACE_RES(mp) + + XFS_DIRENTER_SPACE_RES(mp, target_name->len); + + if (new_parent_ptr) { + if (wip) + ret += xfs_pptr_calc_space_res(mp, src_name->len); + ret += 2 * xfs_pptr_calc_space_res(mp, target_name->len); + } + if (target_parent_ptr) + ret += xfs_pptr_calc_space_res(mp, target_name->len); + + return ret; +} + /* * xfs_rename */ @@ -2923,6 +2948,11 @@ xfs_rename( int spaceres; bool retried = false; int error, nospace_error = 0; + xfs_dir2_dataptr_t new_diroffset; + xfs_dir2_dataptr_t old_diroffset; + struct xfs_parent_defer *src_ip_pptr = NULL; + struct xfs_parent_defer *tgt_ip_pptr = NULL; + struct xfs_parent_defer *wip_pptr = NULL; trace_xfs_rename(src_dp, target_dp, src_name, target_name); @@ -2947,9 +2977,26 @@ xfs_rename( xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, wip, inodes, &num_inodes); + error = xfs_parent_start(mp, &src_ip_pptr); + if (error) + goto out_release_wip; + + if (wip) { + error = xfs_parent_start_locked(mp, &wip_pptr); + if (error) + goto out_src_ip_pptr; + } + + if (target_ip) { + error = xfs_parent_start_locked(mp, &tgt_ip_pptr); + if (error) + goto out_wip_pptr; + } + retry: nospace_error = 0; - spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len); + spaceres = xfs_rename_space_res(mp, src_name, tgt_ip_pptr, + target_name, src_ip_pptr, wip); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0, 0, &tp); if (error == -ENOSPC) { nospace_error = error; @@ -2958,14 +3005,26 @@ xfs_rename( &tp); } if (error) - goto out_release_wip; + goto out_tgt_ip_pptr; + + /* + * We don't allow reservationless renaming when parent pointers are + * enabled because we can't back out if the xattrs must grow. + */ + if (src_ip_pptr && nospace_error) { + error = nospace_error; + xfs_trans_cancel(tp); + goto out_tgt_ip_pptr; + } /* * Attach the dquots to the inodes */ error = xfs_qm_vop_rename_dqattach(inodes); - if (error) - goto out_trans_cancel; + if (error) { + xfs_trans_cancel(tp); + goto out_tgt_ip_pptr; + } /* * Lock all the participating inodes. Depending upon whether @@ -3032,6 +3091,15 @@ xfs_rename( goto out_trans_cancel; } + /* + * We don't allow quotaless renaming when parent pointers are enabled + * because we can't back out if the xattrs must grow. + */ + if (src_ip_pptr && nospace_error) { + error = nospace_error; + goto out_trans_cancel; + } + /* * Check for expected errors before we dirty the transaction * so we can return an error without a transaction abort. @@ -3122,7 +3190,7 @@ xfs_rename( * to account for the ".." reference from the new entry. */ error = xfs_dir_createname(tp, target_dp, target_name, - src_ip->i_ino, spaceres, NULL); + src_ip->i_ino, spaceres, &new_diroffset); if (error) goto out_trans_cancel; @@ -3143,7 +3211,7 @@ xfs_rename( * name at the destination directory, remove it first. */ error = xfs_dir_replace(tp, target_dp, target_name, - src_ip->i_ino, spaceres, NULL); + src_ip->i_ino, spaceres, &new_diroffset); if (error) goto out_trans_cancel; @@ -3216,14 +3284,38 @@ xfs_rename( */ if (wip) error = xfs_dir_replace(tp, src_dp, src_name, wip->i_ino, - spaceres, NULL); + spaceres, &old_diroffset); else error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, - spaceres, NULL); + spaceres, &old_diroffset); if (error) goto out_trans_cancel; + if (wip_pptr) { + error = xfs_parent_defer_add(tp, wip_pptr, + src_dp, src_name, + old_diroffset, wip); + if (error) + goto out_trans_cancel; + } + + if (src_ip_pptr) { + error = xfs_parent_defer_replace(tp, src_ip_pptr, src_dp, + old_diroffset, target_name, target_dp, + new_diroffset, src_ip); + if (error) + goto out_trans_cancel; + } + + if (tgt_ip_pptr) { + error = xfs_parent_defer_remove(tp, target_dp, + tgt_ip_pptr, + new_diroffset, target_ip); + if (error) + goto out_trans_cancel; + } + xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE); if (new_parent) @@ -3237,6 +3329,13 @@ xfs_rename( xfs_trans_cancel(tp); out_unlock: xfs_iunlock_rename(inodes, num_inodes); +out_tgt_ip_pptr: + xfs_parent_finish(mp, tgt_ip_pptr); +out_wip_pptr: + xfs_parent_finish(mp, wip_pptr); +out_src_ip_pptr: + xfs_parent_finish(mp, src_ip_pptr); + out_release_wip: if (wip) xfs_irele(wip); From patchwork Thu Feb 16 20:38:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A21BEC636CC for ; Thu, 16 Feb 2023 20:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229536AbjBPUiR (ORCPT ); Thu, 16 Feb 2023 15:38:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbjBPUiQ (ORCPT ); Thu, 16 Feb 2023 15:38:16 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B3FC1ADE6 for ; Thu, 16 Feb 2023 12:38:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DA590B829AB for ; Thu, 16 Feb 2023 20:38:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 979B5C433EF; Thu, 16 Feb 2023 20:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579888; bh=O91viBnqgRv85OXv+/myTq/Dq25e/lyYESBFLPLkB5E=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JZzN7VOkDjPm3yVrFYf6XCJ/mce+gPGk3IwIQ9gdrs0BGMCiFJGaPYZHS7jGt/I24 AVfJ5E69er88Xw/YOH29cbEL0/ZCKcILT4jfjq1HAdhl854LUEjWNAc4fHc6cg585v AwnF/pzuBe1hIslBli2Y44w1j5zSWekfc5JzWh0FlMN4UIk/gMNc7+dpOHA15tQP9y JdasitRvYkxivhRpyqYxP+zhkcHoY4iYDZcR6wi8vJ/FqHa0Snew33rv3QG3DuM/Ps WxDktySqlEwLVn5BPLQ1pY+uPKZMOfxK+6dxceCh5vhaCCgf8NZUKrc7+MZ7cqcakw l6kZDIldwoEtQ== Date: Thu, 16 Feb 2023 12:38:08 -0800 Subject: [PATCH 21/28] xfs: Add parent pointers to xfs_cross_rename From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872685.3473407.9005998270517975325.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Cross renames are handled separately from standard renames, and need different handling to update the parent attributes correctly. Signed-off-by: Allison Henderson --- fs/xfs/xfs_inode.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index cdbd7df64ff0..6626aa7486f1 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2749,27 +2749,31 @@ xfs_finish_rename( */ STATIC int xfs_cross_rename( - struct xfs_trans *tp, - struct xfs_inode *dp1, - struct xfs_name *name1, - struct xfs_inode *ip1, - struct xfs_inode *dp2, - struct xfs_name *name2, - struct xfs_inode *ip2, - int spaceres) + struct xfs_trans *tp, + struct xfs_inode *dp1, + struct xfs_name *name1, + struct xfs_inode *ip1, + struct xfs_parent_defer *ip1_pptr, + struct xfs_inode *dp2, + struct xfs_name *name2, + struct xfs_inode *ip2, + struct xfs_parent_defer *ip2_pptr, + int spaceres) { - int error = 0; - int ip1_flags = 0; - int ip2_flags = 0; - int dp2_flags = 0; + struct xfs_mount *mp = dp1->i_mount; + int error = 0; + int ip1_flags = 0; + int ip2_flags = 0; + int dp2_flags = 0; + int new_diroffset, old_diroffset; /* Swap inode number for dirent in first parent */ - error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, NULL); + error = xfs_dir_replace(tp, dp1, name1, ip2->i_ino, spaceres, &old_diroffset); if (error) goto out_trans_abort; /* Swap inode number for dirent in second parent */ - error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, NULL); + error = xfs_dir_replace(tp, dp2, name2, ip1->i_ino, spaceres, &new_diroffset); if (error) goto out_trans_abort; @@ -2830,6 +2834,18 @@ xfs_cross_rename( } } + if (xfs_has_parent(mp)) { + error = xfs_parent_defer_replace(tp, ip1_pptr, dp1, + old_diroffset, name2, dp2, new_diroffset, ip1); + if (error) + goto out_trans_abort; + + error = xfs_parent_defer_replace(tp, ip2_pptr, dp2, + new_diroffset, name1, dp1, old_diroffset, ip2); + if (error) + goto out_trans_abort; + } + if (ip1_flags) { xfs_trans_ichgtime(tp, ip1, ip1_flags); xfs_trans_log_inode(tp, ip1, XFS_ILOG_CORE); @@ -2844,6 +2860,7 @@ xfs_cross_rename( } xfs_trans_ichgtime(tp, dp1, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); xfs_trans_log_inode(tp, dp1, XFS_ILOG_CORE); + return xfs_finish_rename(tp); out_trans_abort: @@ -3060,8 +3077,8 @@ xfs_rename( /* RENAME_EXCHANGE is unique from here on. */ if (flags & RENAME_EXCHANGE) { error = xfs_cross_rename(tp, src_dp, src_name, src_ip, - target_dp, target_name, target_ip, - spaceres); + src_ip_pptr, target_dp, target_name, target_ip, + tgt_ip_pptr, spaceres); goto out_unlock; } From patchwork Thu Feb 16 20:38:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143774 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C8F8C636CC for ; Thu, 16 Feb 2023 20:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229747AbjBPUio (ORCPT ); Thu, 16 Feb 2023 15:38:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbjBPUim (ORCPT ); Thu, 16 Feb 2023 15:38:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 377D81EFF4 for ; Thu, 16 Feb 2023 12:38:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C857D60AB9 for ; Thu, 16 Feb 2023 20:38:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 362A5C433D2; Thu, 16 Feb 2023 20:38:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579904; bh=Sqf4Ua+n4tCL+BS6xayVnxOvRtMB6P5fuj9uYbsJFa4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=d1lB0n3UJeLDtLlDNizpYdzEhlx/iqCKQ/CNJc+asODrdY8GZH80swRudojBzIdRG Q/hPz/jIZwEBUaitgOSGHExTh2RCdEmgBSGLrLdyFZ8NI+bOfajcoVGXDo9jVdGHlg Wu/RDJy+Ki65bgQOocP8FjA5QAIf7B3ZntpNb95vNAT41e5SqBS95/hwgKrg0jqT0a d0EaZC9vPzCqguA80R+GKx6z0tDCjVAcBvYepRaZ9xQvLgJKSDmgE3n5iuo97HpaB/ vLs12zTD9xh13vkb5edOkUlZPkzkjnWEUlUJy8Bt9PEcJ8w1Mlhia+8aSSZuCO409D Jzquu/ypTAdbQ== Date: Thu, 16 Feb 2023 12:38:23 -0800 Subject: [PATCH 22/28] xfs: Add the parent pointer support to the superblock version 5. From: "Darrick J. Wong" To: djwong@kernel.org Cc: Mark Tinguely , Dave Chinner , Allison Henderson , "Darrick J. Wong" , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872700.3473407.13911241710498376259.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Signed-off-by: Mark Tinguely Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_format.h | 4 +++- fs/xfs/libxfs/xfs_fs.h | 1 + fs/xfs/libxfs/xfs_sb.c | 4 ++++ fs/xfs/xfs_super.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h index 371dc07233e0..f413819b2a8a 100644 --- a/fs/xfs/libxfs/xfs_format.h +++ b/fs/xfs/libxfs/xfs_format.h @@ -373,13 +373,15 @@ xfs_sb_has_ro_compat_feature( #define XFS_SB_FEAT_INCOMPAT_BIGTIME (1 << 3) /* large timestamps */ #define XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR (1 << 4) /* needs xfs_repair */ #define XFS_SB_FEAT_INCOMPAT_NREXT64 (1 << 5) /* large extent counters */ +#define XFS_SB_FEAT_INCOMPAT_PARENT (1 << 6) /* parent pointers */ #define XFS_SB_FEAT_INCOMPAT_ALL \ (XFS_SB_FEAT_INCOMPAT_FTYPE| \ XFS_SB_FEAT_INCOMPAT_SPINODES| \ XFS_SB_FEAT_INCOMPAT_META_UUID| \ XFS_SB_FEAT_INCOMPAT_BIGTIME| \ XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR| \ - XFS_SB_FEAT_INCOMPAT_NREXT64) + XFS_SB_FEAT_INCOMPAT_NREXT64| \ + XFS_SB_FEAT_INCOMPAT_PARENT) #define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index 1cfd5bc6520a..b0b4d7a3aa15 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -237,6 +237,7 @@ typedef struct xfs_fsop_resblks { #define XFS_FSOP_GEOM_FLAGS_BIGTIME (1 << 21) /* 64-bit nsec timestamps */ #define XFS_FSOP_GEOM_FLAGS_INOBTCNT (1 << 22) /* inobt btree counter */ #define XFS_FSOP_GEOM_FLAGS_NREXT64 (1 << 23) /* large extent counters */ +#define XFS_FSOP_GEOM_FLAGS_PARENT (1 << 24) /* parent pointers */ /* * Minimum and maximum sizes need for growth checks. diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c index 1eeecf2eb2a7..a59bf09495b1 100644 --- a/fs/xfs/libxfs/xfs_sb.c +++ b/fs/xfs/libxfs/xfs_sb.c @@ -173,6 +173,8 @@ xfs_sb_version_to_features( features |= XFS_FEAT_NEEDSREPAIR; if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_NREXT64) features |= XFS_FEAT_NREXT64; + if (sbp->sb_features_incompat & XFS_SB_FEAT_INCOMPAT_PARENT) + features |= XFS_FEAT_PARENT; return features; } @@ -1189,6 +1191,8 @@ xfs_fs_geometry( geo->flags |= XFS_FSOP_GEOM_FLAGS_BIGTIME; if (xfs_has_inobtcounts(mp)) geo->flags |= XFS_FSOP_GEOM_FLAGS_INOBTCNT; + if (xfs_has_parent(mp)) + geo->flags |= XFS_FSOP_GEOM_FLAGS_PARENT; if (xfs_has_sector(mp)) { geo->flags |= XFS_FSOP_GEOM_FLAGS_SECTOR; geo->logsectsize = sbp->sb_logsectsize; diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 6795761c31e0..0ac55d191f1f 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -1664,6 +1664,10 @@ xfs_fs_fill_super( xfs_warn(mp, "EXPERIMENTAL Large extent counts feature in use. Use at your own risk!"); + if (xfs_has_parent(mp)) + xfs_alert(mp, + "EXPERIMENTAL parent pointer feature enabled. Use at your own risk!"); + error = xfs_mountfs(mp); if (error) goto out_filestream_unmount; From patchwork Thu Feb 16 20:38:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46070C61DA4 for ; Thu, 16 Feb 2023 20:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229818AbjBPUip (ORCPT ); Thu, 16 Feb 2023 15:38:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbjBPUin (ORCPT ); Thu, 16 Feb 2023 15:38:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75E6D1CF73 for ; Thu, 16 Feb 2023 12:38:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1D326B829AC for ; Thu, 16 Feb 2023 20:38:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA494C433EF; Thu, 16 Feb 2023 20:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579919; bh=JbIaAh6MpblAeP2hYvdmjKkhvegG2735a4K+s77OEsA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=sDb/+rNcxUAJULxw1rVujC7w74jkV3PAguuXMVr33CeAotpzkHG+wsapdnxjRWju1 JnlOF23Wi1chk3fbVw+hGQ5CwxRh/NxkNgjbI3Pqz1hk1Yjx8Plkc/ksdmM6Vdxq0l FeP6FSpD03QJAMwqXCXCeD3qMXwcGIvmM3HUwUCbSpF5f6ZKU4bpZCLUZg/5bKlZT0 PrNATgD0Eet6oiiPxnKZrxYfel3WLdZaWTWVqQd0gc2CY/KPQ0QsDkeVL96tt5M5k+ eLSycHJ9mfEDZsEeK9yS91ZMrzNLTm2xFLXUKMnxaAByKiX3+UE6I1l5Ku7hqKIjow i3RQMlIlC+9DA== Date: Thu, 16 Feb 2023 12:38:39 -0800 Subject: [PATCH 23/28] xfs: Add helper function xfs_attr_list_context_init From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872715.3473407.1602330056133097351.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson This patch adds a helper function xfs_attr_list_context_init used by xfs_attr_list. This function initializes the xfs_attr_list_context structure passed to xfs_attr_list_int. We will need this later to call xfs_attr_list_int_ilocked when the node is already locked. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 1 + fs/xfs/xfs_ioctl.c | 54 +++++++++++++++++++++++++++++++++++++--------------- fs/xfs/xfs_ioctl.h | 2 ++ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 595a5bcf46b9..9c09d32a6c9e 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -17,6 +17,7 @@ #include "xfs_bmap_util.h" #include "xfs_dir2.h" #include "xfs_dir2_priv.h" +#include "xfs_attr.h" #include "xfs_ioctl.h" #include "xfs_trace.h" #include "xfs_log.h" diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 736510bc241b..5cd5154d4d1e 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -369,6 +369,40 @@ xfs_attr_flags( return 0; } +/* + * Initializes an xfs_attr_list_context suitable for + * use by xfs_attr_list + */ +int +xfs_ioc_attr_list_context_init( + struct xfs_inode *dp, + char *buffer, + int bufsize, + int flags, + struct xfs_attr_list_context *context) +{ + struct xfs_attrlist *alist; + + /* + * Initialize the output buffer. + */ + context->dp = dp; + context->resynch = 1; + context->attr_filter = xfs_attr_filter(flags); + context->buffer = buffer; + context->bufsize = round_down(bufsize, sizeof(uint32_t)); + context->firstu = context->bufsize; + context->put_listent = xfs_ioc_attr_put_listent; + + alist = context->buffer; + alist->al_count = 0; + alist->al_more = 0; + alist->al_offset[0] = context->bufsize; + + return 0; +} + + int xfs_ioc_attr_list( struct xfs_inode *dp, @@ -378,7 +412,6 @@ xfs_ioc_attr_list( struct xfs_attrlist_cursor __user *ucursor) { struct xfs_attr_list_context context = { }; - struct xfs_attrlist *alist; void *buffer; int error; @@ -410,21 +443,10 @@ xfs_ioc_attr_list( if (!buffer) return -ENOMEM; - /* - * Initialize the output buffer. - */ - context.dp = dp; - context.resynch = 1; - context.attr_filter = xfs_attr_filter(flags); - context.buffer = buffer; - context.bufsize = round_down(bufsize, sizeof(uint32_t)); - context.firstu = context.bufsize; - context.put_listent = xfs_ioc_attr_put_listent; - - alist = context.buffer; - alist->al_count = 0; - alist->al_more = 0; - alist->al_offset[0] = context.bufsize; + error = xfs_ioc_attr_list_context_init(dp, buffer, bufsize, flags, + &context); + if (error) + return error; error = xfs_attr_list(&context); if (error) diff --git a/fs/xfs/xfs_ioctl.h b/fs/xfs/xfs_ioctl.h index d4abba2c13c1..ca60e1c427a3 100644 --- a/fs/xfs/xfs_ioctl.h +++ b/fs/xfs/xfs_ioctl.h @@ -35,6 +35,8 @@ int xfs_ioc_attrmulti_one(struct file *parfilp, struct inode *inode, int xfs_ioc_attr_list(struct xfs_inode *dp, void __user *ubuf, size_t bufsize, int flags, struct xfs_attrlist_cursor __user *ucursor); +int xfs_ioc_attr_list_context_init(struct xfs_inode *dp, char *buffer, + int bufsize, int flags, struct xfs_attr_list_context *context); extern struct dentry * xfs_handle_to_dentry( From patchwork Thu Feb 16 20:38:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143776 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 795E0C6379F for ; Thu, 16 Feb 2023 20:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbjBPUi6 (ORCPT ); Thu, 16 Feb 2023 15:38:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjBPUi5 (ORCPT ); Thu, 16 Feb 2023 15:38:57 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A36422028 for ; Thu, 16 Feb 2023 12:38:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EB5E460C1E for ; Thu, 16 Feb 2023 20:38:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F44EC433EF; Thu, 16 Feb 2023 20:38:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579935; bh=t1fiih6oG55Rxkca+9y7YyKSEIU7dqt4ykdlDhgH5zY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tL6jvHgJLpZjScdSsAMal4MIK0mhRYMowdB/vS7oxAHMrolOh7/SYLHzkpUe/RX59 HUttSapg3IIIhpFcq8C804MyA9ZSpumbhNR1nUb3Rui6LVsTXTauwuITBg8CUBT1h9 uG05+gjyZHffmWd5TIhktv7ubJHzZNtw7Y1hgPZSNVw7MA8HR1qN7rGV5eVMPthUSD 3KXtLOU51r0W/ZP8Oq2rGwrJSKmg4syw2i3JY0SaRd5fuGdVltiQMiU/DJkZIUNSNi h8UMwOlVNcK8biTeXEjpWqRU1r7EbYdRk9Sv/zMK9C+VxZltTH3P2P2yE0pzU3rAXL gn0CfKHTUY4Uw== Date: Thu, 16 Feb 2023 12:38:54 -0800 Subject: [PATCH 24/28] xfs: Filter XFS_ATTR_PARENT for getfattr From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872730.3473407.10774924524532838927.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Parent pointers returned to the get_fattr tool cause errors since the tool cannot parse parent pointers. Fix this by filtering parent parent pointers from xfs_xattr_put_listent. Signed-off-by: Allison Henderson --- fs/xfs/xfs_xattr.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/xfs/xfs_xattr.c b/fs/xfs/xfs_xattr.c index 8bb5f53a31fe..ddc2db5d6f73 100644 --- a/fs/xfs/xfs_xattr.c +++ b/fs/xfs/xfs_xattr.c @@ -234,6 +234,9 @@ xfs_xattr_put_listent( ASSERT(context->count >= 0); + if (flags & XFS_ATTR_PARENT) + return; + if (flags & XFS_ATTR_ROOT) { #ifdef CONFIG_XFS_POSIX_ACL if (namelen == SGI_ACL_FILE_SIZE && From patchwork Thu Feb 16 20:39:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143787 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 650C0C61DA4 for ; Thu, 16 Feb 2023 20:39:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbjBPUjT (ORCPT ); Thu, 16 Feb 2023 15:39:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbjBPUjP (ORCPT ); Thu, 16 Feb 2023 15:39:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06940211DE for ; Thu, 16 Feb 2023 12:39:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 909D960C1E for ; Thu, 16 Feb 2023 20:39:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED1FEC4339B; Thu, 16 Feb 2023 20:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579951; bh=uTe3aQuTOHJ8JXrnP1Cusl2wxeDQLNxu1H/cSD3SmMg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=vFB3w8IhxQ4gMybVdrmbs00euzz0UlUGh5QcI7BKL0dDqkE28vVGFYy+ZqqOa0VAF L0ayWqnh+tgYglhsCnZLr8IqqGSdHGNlz5V9GgRsEIVPm9qGjJnuarmdY2YM9VjKRQ qv5sJ4uDMZvIrYnhDTTPwcUulhszx/hwnCygTDw/96mjnxr5WO1cyqoHesGZzZ+ZAN zwZczyjsPkcLswuO3lAowfid3yayo5hqZiXapVRySEW3RNhSViQDAEWzMBRZjUSjZ5 hF8Awuebfjm/2WAz+IelI33qK0I1i9vuPPP8RygMt1ZyaeZ+n4R5+F32fNU6i7aKBM GPTs/b/iTUgrg== Date: Thu, 16 Feb 2023 12:39:10 -0800 Subject: [PATCH 25/28] xfs: Add parent pointer ioctl From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872744.3473407.10713843286901630791.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson This patch adds a new file ioctl to retrieve the parent pointer of a given inode Signed-off-by: Allison Henderson --- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_fs.h | 74 ++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_parent.c | 10 +++ fs/xfs/libxfs/xfs_parent.h | 2 + fs/xfs/xfs_ioctl.c | 94 ++++++++++++++++++++++++++++++++- fs/xfs/xfs_ondisk.h | 4 + fs/xfs/xfs_parent_utils.c | 126 ++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_parent_utils.h | 11 ++++ 8 files changed, 321 insertions(+), 1 deletion(-) create mode 100644 fs/xfs/xfs_parent_utils.c create mode 100644 fs/xfs/xfs_parent_utils.h diff --git a/fs/xfs/Makefile b/fs/xfs/Makefile index e2b2cf50ffcf..42d0496fdad7 100644 --- a/fs/xfs/Makefile +++ b/fs/xfs/Makefile @@ -86,6 +86,7 @@ xfs-y += xfs_aops.o \ xfs_mount.o \ xfs_mru_cache.o \ xfs_pwork.o \ + xfs_parent_utils.o \ xfs_reflink.o \ xfs_stats.o \ xfs_super.o \ diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index b0b4d7a3aa15..9e59a1fdfb0c 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -752,6 +752,79 @@ struct xfs_scrub_metadata { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED) #define XFS_SCRUB_FLAGS_ALL (XFS_SCRUB_FLAGS_IN | XFS_SCRUB_FLAGS_OUT) +#define XFS_PPTR_MAXNAMELEN 256 + +/* return parents of the handle, not the open fd */ +#define XFS_PPTR_IFLAG_HANDLE (1U << 0) + +/* target was the root directory */ +#define XFS_PPTR_OFLAG_ROOT (1U << 1) + +/* Cursor is done iterating pptrs */ +#define XFS_PPTR_OFLAG_DONE (1U << 2) + + #define XFS_PPTR_FLAG_ALL (XFS_PPTR_IFLAG_HANDLE | XFS_PPTR_OFLAG_ROOT | \ + XFS_PPTR_OFLAG_DONE) + +/* Get an inode parent pointer through ioctl */ +struct xfs_parent_ptr { + __u64 xpp_ino; /* Inode */ + __u32 xpp_gen; /* Inode generation */ + __u32 xpp_diroffset; /* Directory offset */ + __u64 xpp_rsvd; /* Reserved */ + __u8 xpp_name[XFS_PPTR_MAXNAMELEN]; /* File name */ +}; + +/* Iterate through an inodes parent pointers */ +struct xfs_pptr_info { + /* File handle, if XFS_PPTR_IFLAG_HANDLE is set */ + struct xfs_handle pi_handle; + + /* + * Structure to track progress in iterating the parent pointers. + * Must be initialized to zeroes before the first ioctl call, and + * not touched by callers after that. + */ + struct xfs_attrlist_cursor pi_cursor; + + /* Operational flags: XFS_PPTR_*FLAG* */ + __u32 pi_flags; + + /* Must be set to zero */ + __u32 pi_reserved; + + /* # of entries in array */ + __u32 pi_ptrs_size; + + /* # of entries filled in (output) */ + __u32 pi_ptrs_used; + + /* Must be set to zero */ + __u64 pi_reserved2[6]; + + /* + * An array of struct xfs_parent_ptr follows the header + * information. Use xfs_ppinfo_to_pp() to access the + * parent pointer array entries. + */ + struct xfs_parent_ptr pi_parents[]; +}; + +static inline size_t +xfs_pptr_info_sizeof(int nr_ptrs) +{ + return sizeof(struct xfs_pptr_info) + + (nr_ptrs * sizeof(struct xfs_parent_ptr)); +} + +static inline struct xfs_parent_ptr* +xfs_ppinfo_to_pp( + struct xfs_pptr_info *info, + int idx) +{ + return &info->pi_parents[idx]; +} + /* * ioctl limits */ @@ -797,6 +870,7 @@ struct xfs_scrub_metadata { /* XFS_IOC_GETFSMAP ------ hoisted 59 */ #define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata) #define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry) +#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_parent_ptr) /* * ioctl commands that replace IRIX syssgi()'s diff --git a/fs/xfs/libxfs/xfs_parent.c b/fs/xfs/libxfs/xfs_parent.c index 629762701952..9176adfaa9e8 100644 --- a/fs/xfs/libxfs/xfs_parent.c +++ b/fs/xfs/libxfs/xfs_parent.c @@ -29,6 +29,16 @@ struct kmem_cache *xfs_parent_intent_cache; +/* Initializes a xfs_parent_ptr from an xfs_parent_name_rec */ +void +xfs_init_parent_ptr(struct xfs_parent_ptr *xpp, + const struct xfs_parent_name_rec *rec) +{ + xpp->xpp_ino = be64_to_cpu(rec->p_ino); + xpp->xpp_gen = be32_to_cpu(rec->p_gen); + xpp->xpp_diroffset = be32_to_cpu(rec->p_diroffset); +} + /* * Parent pointer attribute handling. * diff --git a/fs/xfs/libxfs/xfs_parent.h b/fs/xfs/libxfs/xfs_parent.h index 039005883bb6..13040b9d8b08 100644 --- a/fs/xfs/libxfs/xfs_parent.h +++ b/fs/xfs/libxfs/xfs_parent.h @@ -25,6 +25,8 @@ struct xfs_parent_defer { void xfs_init_parent_name_rec(struct xfs_parent_name_rec *rec, struct xfs_inode *ip, uint32_t p_diroffset); +void xfs_init_parent_ptr(struct xfs_parent_ptr *xpp, + const struct xfs_parent_name_rec *rec); int __xfs_parent_init(struct xfs_mount *mp, bool grab_log, struct xfs_parent_defer **parentp); diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 5cd5154d4d1e..df5a45b97f8f 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -37,6 +37,7 @@ #include "xfs_health.h" #include "xfs_reflink.h" #include "xfs_ioctl.h" +#include "xfs_parent_utils.h" #include "xfs_xattr.h" #include @@ -1675,6 +1676,96 @@ xfs_ioc_scrub_metadata( return 0; } +/* + * IOCTL routine to get the parent pointers of an inode and return it to user + * space. Caller must pass a buffer space containing a struct xfs_pptr_info, + * followed by a region large enough to contain an array of struct + * xfs_parent_ptr of a size specified in pi_ptrs_size. If the inode contains + * more parent pointers than can fit in the buffer space, caller may re-call + * the function using the returned pi_cursor to resume iteration. The + * number of xfs_parent_ptr returned will be stored in pi_ptrs_used. + * + * Returns 0 on success or non-zero on failure + */ +STATIC int +xfs_ioc_get_parent_pointer( + struct file *filp, + void __user *arg) +{ + struct xfs_pptr_info *ppi = NULL; + int error = 0; + struct xfs_inode *ip = XFS_I(file_inode(filp)); + struct xfs_mount *mp = ip->i_mount; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + /* Allocate an xfs_pptr_info to put the user data */ + ppi = kmalloc(sizeof(struct xfs_pptr_info), 0); + if (!ppi) + return -ENOMEM; + + /* Copy the data from the user */ + error = copy_from_user(ppi, arg, sizeof(struct xfs_pptr_info)); + if (error) { + error = -EFAULT; + goto out; + } + + /* Check size of buffer requested by user */ + if (xfs_pptr_info_sizeof(ppi->pi_ptrs_size) > XFS_XATTR_LIST_MAX) { + error = -ENOMEM; + goto out; + } + + if (ppi->pi_flags & ~XFS_PPTR_FLAG_ALL) { + error = -EINVAL; + goto out; + } + ppi->pi_flags &= ~(XFS_PPTR_OFLAG_ROOT | XFS_PPTR_OFLAG_DONE); + + /* + * Now that we know how big the trailing buffer is, expand + * our kernel xfs_pptr_info to be the same size + */ + ppi = krealloc(ppi, xfs_pptr_info_sizeof(ppi->pi_ptrs_size), 0); + if (!ppi) + return -ENOMEM; + + if (ppi->pi_flags & XFS_PPTR_IFLAG_HANDLE) { + error = xfs_iget(mp, NULL, ppi->pi_handle.ha_fid.fid_ino, + 0, 0, &ip); + if (error) + goto out; + + if (VFS_I(ip)->i_generation != ppi->pi_handle.ha_fid.fid_gen) { + error = -EINVAL; + goto out; + } + } + + if (ip->i_ino == mp->m_sb.sb_rootino) + ppi->pi_flags |= XFS_PPTR_OFLAG_ROOT; + + /* Get the parent pointers */ + error = xfs_attr_get_parent_pointer(ip, ppi); + + if (error) + goto out; + + /* Copy the parent pointers back to the user */ + error = copy_to_user(arg, ppi, + xfs_pptr_info_sizeof(ppi->pi_ptrs_size)); + if (error) { + error = -EFAULT; + goto out; + } + +out: + kmem_free(ppi); + return error; +} + int xfs_ioc_swapext( xfs_swapext_t *sxp) @@ -1964,7 +2055,8 @@ xfs_file_ioctl( case XFS_IOC_FSGETXATTRA: return xfs_ioc_fsgetxattra(ip, arg); - + case XFS_IOC_GETPARENTS: + return xfs_ioc_get_parent_pointer(filp, arg); case XFS_IOC_GETBMAP: case XFS_IOC_GETBMAPA: case XFS_IOC_GETBMAPX: diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h index 9737b5a9f405..6a6bd05c2a68 100644 --- a/fs/xfs/xfs_ondisk.h +++ b/fs/xfs/xfs_ondisk.h @@ -150,6 +150,10 @@ xfs_check_ondisk_structs(void) XFS_CHECK_OFFSET(struct xfs_efi_log_format_32, efi_extents, 16); XFS_CHECK_OFFSET(struct xfs_efi_log_format_64, efi_extents, 16); + /* parent pointer ioctls */ + XFS_CHECK_STRUCT_SIZE(struct xfs_parent_ptr, 280); + XFS_CHECK_STRUCT_SIZE(struct xfs_pptr_info, 104); + /* * The v5 superblock format extended several v4 header structures with * additional data. While new fields are only accessible on v5 diff --git a/fs/xfs/xfs_parent_utils.c b/fs/xfs/xfs_parent_utils.c new file mode 100644 index 000000000000..771279731d42 --- /dev/null +++ b/fs/xfs/xfs_parent_utils.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Oracle, Inc. + * All rights reserved. + */ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_shared.h" +#include "xfs_trans_resv.h" +#include "xfs_mount.h" +#include "xfs_bmap_btree.h" +#include "xfs_inode.h" +#include "xfs_error.h" +#include "xfs_trace.h" +#include "xfs_trans.h" +#include "xfs_da_format.h" +#include "xfs_da_btree.h" +#include "xfs_attr.h" +#include "xfs_ioctl.h" +#include "xfs_parent.h" +#include "xfs_da_btree.h" +#include "xfs_parent_utils.h" + +/* + * Get the parent pointers for a given inode + * + * Returns 0 on success and non zero on error + */ +int +xfs_attr_get_parent_pointer( + struct xfs_inode *ip, + struct xfs_pptr_info *ppi) +{ + + struct xfs_attrlist *alist; + struct xfs_attrlist_ent *aent; + struct xfs_parent_ptr *xpp; + struct xfs_parent_name_rec *xpnr; + char *namebuf; + unsigned int namebuf_size; + int name_len, i, error = 0; + unsigned int lock_mode, flags = XFS_ATTR_PARENT; + struct xfs_attr_list_context context; + + /* Allocate a buffer to store the attribute names */ + namebuf_size = sizeof(struct xfs_attrlist) + + (ppi->pi_ptrs_size) * sizeof(struct xfs_attrlist_ent); + namebuf = kvzalloc(namebuf_size, GFP_KERNEL); + if (!namebuf) + return -ENOMEM; + + memset(&context, 0, sizeof(struct xfs_attr_list_context)); + error = xfs_ioc_attr_list_context_init(ip, namebuf, namebuf_size, 0, + &context); + if (error) + goto out_kfree; + + /* Copy the cursor provided by caller */ + memcpy(&context.cursor, &ppi->pi_cursor, + sizeof(struct xfs_attrlist_cursor)); + context.attr_filter = XFS_ATTR_PARENT; + + lock_mode = xfs_ilock_attr_map_shared(ip); + + error = xfs_attr_list_ilocked(&context); + if (error) + goto out_unlock; + + alist = (struct xfs_attrlist *)namebuf; + for (i = 0; i < alist->al_count; i++) { + struct xfs_da_args args = { + .geo = ip->i_mount->m_attr_geo, + .whichfork = XFS_ATTR_FORK, + .dp = ip, + .namelen = sizeof(struct xfs_parent_name_rec), + .attr_filter = flags, + }; + + xpp = xfs_ppinfo_to_pp(ppi, i); + memset(xpp, 0, sizeof(struct xfs_parent_ptr)); + aent = (struct xfs_attrlist_ent *) + &namebuf[alist->al_offset[i]]; + xpnr = (struct xfs_parent_name_rec *)(aent->a_name); + + if (aent->a_valuelen > XFS_PPTR_MAXNAMELEN) { + error = -EFSCORRUPTED; + goto out_unlock; + } + name_len = aent->a_valuelen; + + args.name = (char *)xpnr; + args.hashval = xfs_da_hashname(args.name, args.namelen), + args.value = (unsigned char *)(xpp->xpp_name); + args.valuelen = name_len; + + error = xfs_attr_get_ilocked(&args); + error = (error == -EEXIST ? 0 : error); + if (error) { + error = -EFSCORRUPTED; + goto out_unlock; + } + + xfs_init_parent_ptr(xpp, xpnr); + if (!xfs_verify_ino(args.dp->i_mount, xpp->xpp_ino)) { + error = -EFSCORRUPTED; + goto out_unlock; + } + } + ppi->pi_ptrs_used = alist->al_count; + if (!alist->al_more) + ppi->pi_flags |= XFS_PPTR_OFLAG_DONE; + + /* Update the caller with the current cursor position */ + memcpy(&ppi->pi_cursor, &context.cursor, + sizeof(struct xfs_attrlist_cursor)); + +out_unlock: + xfs_iunlock(ip, lock_mode); +out_kfree: + kvfree(namebuf); + + return error; +} + diff --git a/fs/xfs/xfs_parent_utils.h b/fs/xfs/xfs_parent_utils.h new file mode 100644 index 000000000000..ad60baee8b2a --- /dev/null +++ b/fs/xfs/xfs_parent_utils.h @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022 Oracle, Inc. + * All rights reserved. + */ +#ifndef __XFS_PARENT_UTILS_H__ +#define __XFS_PARENT_UTILS_H__ + +int xfs_attr_get_parent_pointer(struct xfs_inode *ip, + struct xfs_pptr_info *ppi); +#endif /* __XFS_PARENT_UTILS_H__ */ From patchwork Thu Feb 16 20:39:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143788 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD96FC636CC for ; Thu, 16 Feb 2023 20:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbjBPUjb (ORCPT ); Thu, 16 Feb 2023 15:39:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbjBPUja (ORCPT ); Thu, 16 Feb 2023 15:39:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3F21ADE1 for ; Thu, 16 Feb 2023 12:39:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 00DC9B829AB for ; Thu, 16 Feb 2023 20:39:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4F19C433EF; Thu, 16 Feb 2023 20:39:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579966; bh=G+TVT88xeTLLIg/BcMdJm0nmzc8+6ht9hlMDK87rT74=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ZsDb3G/lgm4kYov/HNxbnhtVB3/jID2/rao0ux0zDVlO3/eVwpozDFIf+uzIj11mx LZ2v0vBMG6zlGvDHykEOENoa9o+AsRUZRPj3LcIXveayVdyTB5z4rIlHnNUJTZuwli cyH4iw7PHRdotroT+5K91tvRNFxbd6TpJQjVtnrs1cAQVKKegwWY0go0EBK1BuaFxj 4k3JOL5tIMDgc7bJSUthg1YRHD4DByRm0iav9nBvMSr8f17nGrMMWDrva//+Dkp7ts +FNsC644ZT06q5ZJgEGPBoebbzRpBrSryyQCYWhV89U0115LNCfhP+EdxQSOFpDFVp M3Yx0bqn50ong== Date: Thu, 16 Feb 2023 12:39:26 -0800 Subject: [PATCH 26/28] xfs: fix unit conversion error in xfs_log_calc_max_attrsetm_res From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872758.3473407.14701547116272587116.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Dave and I were discussing some recent test regressions as a result of me turning on nrext64=1 on realtime filesystems, when we noticed that the minimum log size of a 32M filesystem jumped from 954 blocks to 4287 blocks. Digging through xfs_log_calc_max_attrsetm_res, Dave noticed that @size contains the maximum estimated amount of space needed for a local format xattr, in bytes, but we feed this quantity to XFS_NEXTENTADD_SPACE_RES, which requires units of blocks. This has resulted in an overestimation of the minimum log size over the years. We should nominally correct this, but there's a backwards compatibility problem -- if we enable it now, the minimum log size will decrease. If a corrected mkfs formats a filesystem with this new smaller log size, a user will encounter mount failures on an uncorrected kernel due to the larger minimum log size computations there. However, the large extent counters feature is still EXPERIMENTAL, so we can gate the correction on that feature (or any features that get added after that) being enabled. Any filesystem with nrext64 or any of the as-yet-undefined feature bits turned on will be rejected by old uncorrected kernels, so this should be safe even in the upgrade case. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson --- fs/xfs/libxfs/xfs_log_rlimit.c | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/fs/xfs/libxfs/xfs_log_rlimit.c b/fs/xfs/libxfs/xfs_log_rlimit.c index 9975b93a7412..e5c606fb7a6a 100644 --- a/fs/xfs/libxfs/xfs_log_rlimit.c +++ b/fs/xfs/libxfs/xfs_log_rlimit.c @@ -16,6 +16,39 @@ #include "xfs_bmap_btree.h" #include "xfs_trace.h" +/* + * Decide if the filesystem has the parent pointer feature or any feature + * added after that. + */ +static inline bool +xfs_has_parent_or_newer_feature( + struct xfs_mount *mp) +{ + if (!xfs_sb_is_v5(&mp->m_sb)) + return false; + + if (xfs_sb_has_compat_feature(&mp->m_sb, ~0)) + return true; + + if (xfs_sb_has_ro_compat_feature(&mp->m_sb, + ~(XFS_SB_FEAT_RO_COMPAT_FINOBT | + XFS_SB_FEAT_RO_COMPAT_RMAPBT | + XFS_SB_FEAT_RO_COMPAT_REFLINK | + XFS_SB_FEAT_RO_COMPAT_INOBTCNT))) + return true; + + if (xfs_sb_has_incompat_feature(&mp->m_sb, + ~(XFS_SB_FEAT_INCOMPAT_FTYPE | + XFS_SB_FEAT_INCOMPAT_SPINODES | + XFS_SB_FEAT_INCOMPAT_META_UUID | + XFS_SB_FEAT_INCOMPAT_BIGTIME | + XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | + XFS_SB_FEAT_INCOMPAT_NREXT64))) + return true; + + return false; +} + /* * Calculate the maximum length in bytes that would be required for a local * attribute value as large attributes out of line are not logged. @@ -31,6 +64,16 @@ xfs_log_calc_max_attrsetm_res( MAXNAMELEN - 1; nblks = XFS_DAENTER_SPACE_RES(mp, XFS_ATTR_FORK); nblks += XFS_B_TO_FSB(mp, size); + + /* + * Starting with the parent pointer feature, every new fs feature + * corrects a unit conversion error in the xattr transaction + * reservation code that resulted in oversized minimum log size + * computations. + */ + if (xfs_has_parent_or_newer_feature(mp)) + size = XFS_B_TO_FSB(mp, size); + nblks += XFS_NEXTENTADD_SPACE_RES(mp, size, XFS_ATTR_FORK); return M_RES(mp)->tr_attrsetm.tr_logres + From patchwork Thu Feb 16 20:39:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77B3FC61DA4 for ; Thu, 16 Feb 2023 20:39:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229482AbjBPUjr (ORCPT ); Thu, 16 Feb 2023 15:39:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53388 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbjBPUjp (ORCPT ); Thu, 16 Feb 2023 15:39:45 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8B59CC0D for ; Thu, 16 Feb 2023 12:39:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 65731B82958 for ; Thu, 16 Feb 2023 20:39:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33A9CC433D2; Thu, 16 Feb 2023 20:39:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579982; bh=8VPQKMFoc+cxsGYakxUHlLz/psc13YLtgg059UQ2xvQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=I25jEFacICTWYVSmDVJOsaGKTmIDgqn3/cDGKDA8i4bUydwSOUW914Jfh3n31+jl/ /2NrATiqxY61OIsZth52PBVO1Pl2jK7z+ze+4+PJZ/UyTtwLDgozTsuJMi9zjzzEpe +gEtOdTfQM4IY7qxF4NRbiv8wj7Kw8Kfi7oLuCSqZZMC/agewtHkTH7ZZPEG8g4r9e 7iJFRMNlec3dA4aWwP5qFoDS7JGBxpiMlWiqxZjYURnnKQGnbq4Fk2XL29ddBn7HB7 0VYH3YEwiHWKFn9qxIaz9QRC19ZnhSMyNWnzFftkqNOq4S73OXWPYov9M0B43NmRoc UrMb7uHFPrsvQ== Date: Thu, 16 Feb 2023 12:39:41 -0800 Subject: [PATCH 27/28] xfs: drop compatibility minimum log size computations for reflink From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872774.3473407.8554373450859748211.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Having established that we can reduce the minimum log size computation for filesystems with parent pointers or any newer feature, we should also drop the compat minlogsize code that we added when we reduced the transaction reservation size for rmap and reflink. Signed-off-by: Darrick J. Wong Reviewed-by: Allison Henderson --- fs/xfs/libxfs/xfs_log_rlimit.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/xfs/libxfs/xfs_log_rlimit.c b/fs/xfs/libxfs/xfs_log_rlimit.c index e5c606fb7a6a..74821c7fd0cc 100644 --- a/fs/xfs/libxfs/xfs_log_rlimit.c +++ b/fs/xfs/libxfs/xfs_log_rlimit.c @@ -91,6 +91,16 @@ xfs_log_calc_trans_resv_for_minlogblocks( { unsigned int rmap_maxlevels = mp->m_rmap_maxlevels; + /* + * Starting with the parent pointer feature, every new fs feature + * drops the oversized minimum log size computation introduced by the + * original reflink code. + */ + if (xfs_has_parent_or_newer_feature(mp)) { + xfs_trans_resv_calc(mp, resv); + return; + } + /* * In the early days of rmap+reflink, we always set the rmap maxlevels * to 9 even if the AG was small enough that it would never grow to From patchwork Thu Feb 16 20:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8382EC636CC for ; Thu, 16 Feb 2023 20:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbjBPUj7 (ORCPT ); Thu, 16 Feb 2023 15:39:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbjBPUj7 (ORCPT ); Thu, 16 Feb 2023 15:39:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1AC6CC0D for ; Thu, 16 Feb 2023 12:39:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4D47360AB9 for ; Thu, 16 Feb 2023 20:39:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B073CC433EF; Thu, 16 Feb 2023 20:39:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676579997; bh=AyxI8j1KARAxJx4RfXjzej0s22wRKl+/oAxqaGBPahI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=PT8rkyKlOlF8Z9SoY/NV5i8OGObYmdWZc1TXYctUwZd+zGVBSGGcIFmrgJvqhDHJi J5CX2jkswZKezNzVuwfSlqz2DIgfa0+CuTvaMdNdL58DBuK4lWQLDQJjf/UQXr6KqG 4AIlQU1nl1KioiXtBsJ7EiItrKGGnm7+ATuQi4cZ0PiwPijVToTB3HqpDZGap1GyDh MDdE8IEFeQPMALGFPwhTxMAaolQDjgzlXgLoFn6XrrSGYb5Uduc+8IlvmDNuqfYmLa rEg9frfbHB6J8mX3OjaNYGqHGZVEFe9G5ftWVjisqNv+dl9oVF841jX5fWQSuAydC5 5DBVi2+e5BlJw== Date: Thu, 16 Feb 2023 12:39:57 -0800 Subject: [PATCH 28/28] xfs: add xfs_trans_mod_sb tracing From: "Darrick J. Wong" To: djwong@kernel.org Cc: Allison Henderson , allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657872789.3473407.18173047314099746828.stgit@magnolia> In-Reply-To: <167657872335.3473407.14628732092515467392.stgit@magnolia> References: <167657872335.3473407.14628732092515467392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Reservationless operations are not allowed with parent pointers because the attr expansion may cause a shutdown if an operation is retried without reservation and succeeds without enough space for the parent pointer. Add tracing to detect if this shutdown occurs. Signed-off-by: Allison Henderson --- fs/xfs/xfs_trans.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c index 43f4b0943f49..bfb7e87e7794 100644 --- a/fs/xfs/xfs_trans.c +++ b/fs/xfs/xfs_trans.c @@ -375,8 +375,10 @@ xfs_trans_mod_sb( */ if (delta < 0) { tp->t_blk_res_used += (uint)-delta; - if (tp->t_blk_res_used > tp->t_blk_res) + if (tp->t_blk_res_used > tp->t_blk_res) { + xfs_err(mp, "URK blkres 0x%x used 0x%x", tp->t_blk_res, tp->t_blk_res_used); xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); + } } else if (delta > 0 && (tp->t_flags & XFS_TRANS_RES_FDBLKS)) { int64_t blkres_delta;