From patchwork Thu Feb 16 21:00: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: 13143888 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 97638C636CC for ; Thu, 16 Feb 2023 21:00:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230006AbjBPVAV (ORCPT ); Thu, 16 Feb 2023 16:00:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjBPVAU (ORCPT ); Thu, 16 Feb 2023 16:00:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B455A505F0 for ; Thu, 16 Feb 2023 13:00: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 60918B82958 for ; Thu, 16 Feb 2023 21:00:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C58DC433EF; Thu, 16 Feb 2023 21:00:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581217; bh=NdyeBZB7EKSNad8CInhPk6paiJFzl2XY4ECu4/FKe+A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=Gcadw2pUp1X5CdfQ0muCGy5glTYdRxqVOjYlY7frF2FuOUdX46M4e00rytCPkpx/Z Yi0LROftZCCnS+5C90K+oUR+QYK0DdGSnROnAaaUmSmEOzQ8v7T5djnwcf1g2i42Kg Dp2xsOIicW5Ku1zthQrFd3NbE1PhwYvMoqJOCzTPgwBozajkU2dFdPUZulm95zImiR NCNTIMOUNmZTKR4ZNYc+ZCFq3OPEtk9orZzk+uPal5Tl5PxSLuKkQl6VhDtcRz5M1f SF/k2DfpQLmULhxN2ApxSWCukf6dUPdjfE1HE/cMzlIv1oLenepMPQhO6P1sFy4Ujq lzT4337de39mg== Date: Thu, 16 Feb 2023 13:00:16 -0800 Subject: [PATCH 1/6] libxfs: initialize the slab cache for parent defer items From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879547.3476725.192173167629345902.stgit@magnolia> In-Reply-To: <167657879533.3476725.4672667573997149436.stgit@magnolia> References: <167657879533.3476725.4672667573997149436.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Initialize the slab cache for parent defer items. We'll need this in an upcoming patch. Signed-off-by: Darrick J. Wong --- include/libxfs.h | 1 + libxfs/init.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/libxfs.h b/include/libxfs.h index 915bf511..a38d78a1 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -77,6 +77,7 @@ struct iomap; #include "xfs_refcount_btree.h" #include "xfs_refcount.h" #include "xfs_btree_staging.h" +#include "xfs_parent.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/libxfs/init.c b/libxfs/init.c index 93dc1f1c..49cb2326 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -258,6 +258,8 @@ init_caches(void) "xfs_extfree_item"); xfs_trans_cache = kmem_cache_init( sizeof(struct xfs_trans), "xfs_trans"); + xfs_parent_intent_cache = kmem_cache_init( + sizeof(struct xfs_parent_defer), "xfs_parent_defer"); } static int @@ -275,6 +277,7 @@ destroy_caches(void) xfs_btree_destroy_cur_caches(); leaked += kmem_cache_destroy(xfs_extfree_item_cache); leaked += kmem_cache_destroy(xfs_trans_cache); + leaked += kmem_cache_destroy(xfs_parent_intent_cache); return leaked; } From patchwork Thu Feb 16 21:00: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: 13143889 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 E8238C636CC for ; Thu, 16 Feb 2023 21:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjBPVAi (ORCPT ); Thu, 16 Feb 2023 16:00:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbjBPVAh (ORCPT ); Thu, 16 Feb 2023 16:00:37 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D357D505D9 for ; Thu, 16 Feb 2023 13:00: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 sin.source.kernel.org (Postfix) with ESMTPS id 37225CE2BC8 for ; Thu, 16 Feb 2023 21:00:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3D20C4339B; Thu, 16 Feb 2023 21:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581232; bh=ywFQWDjqmWCgkZ2p0AZ5qIPBFt5uC8TIBbmnpDqkSqs=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CDyqnJX+wzLL0jJbh7g3UHnJWZ/CbPNFKmBpFiikAkbD+Ne4H3qnURTOx9lgDWeRa dfUQlOe+0tXnvd+VjIJkE/FgkhVMOR4TrDD1uswJk1ywBYNx07d9rGv32pSjnRR9me CGDLVrGvAXFGQyngOg66kI/WTXu6EO5evHXVYOtfVvSIG2vTk0juozZerLUgxE7Ye9 GvuoM4t/uN5NNLFafPxZGqO1renzeODlH4TsdXbrEsZqWz/7RZxPhAwnWiCs1ctbat 72mvkTagkp7KvQYey+ehLpqpowzz3/QGnbr8nVkZgXBl7uqCrU/RZAY/NCUVzNTnug Vz5zmj1uepoUA== Date: Thu, 16 Feb 2023 13:00:32 -0800 Subject: [PATCH 2/6] xfs: directory lookups should return diroffsets too From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879560.3476725.3323720669075001986.stgit@magnolia> In-Reply-To: <167657879533.3476725.4672667573997149436.stgit@magnolia> References: <167657879533.3476725.4672667573997149436.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Teach the directory lookup functions to return the dir offset of the dirent that it finds. Online fsck will use this when checking and repairing filesystems. Signed-off-by: Darrick J. Wong --- libxfs/xfs_dir2_block.c | 2 ++ libxfs/xfs_dir2_leaf.c | 2 ++ libxfs/xfs_dir2_node.c | 2 ++ libxfs/xfs_dir2_sf.c | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/libxfs/xfs_dir2_block.c b/libxfs/xfs_dir2_block.c index c743fa67..1ed3c974 100644 --- a/libxfs/xfs_dir2_block.c +++ b/libxfs/xfs_dir2_block.c @@ -746,6 +746,8 @@ xfs_dir2_block_lookup_int( cmp = xfs_dir2_compname(args, dep->name, dep->namelen); if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) { args->cmpresult = cmp; + args->offset = xfs_dir2_byte_to_dataptr( + (char *)dep - (char *)hdr); *bpp = bp; *entno = mid; if (cmp == XFS_CMP_EXACT) diff --git a/libxfs/xfs_dir2_leaf.c b/libxfs/xfs_dir2_leaf.c index 1be7773e..9ec01d02 100644 --- a/libxfs/xfs_dir2_leaf.c +++ b/libxfs/xfs_dir2_leaf.c @@ -1298,6 +1298,8 @@ xfs_dir2_leaf_lookup_int( cmp = xfs_dir2_compname(args, dep->name, dep->namelen); if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) { args->cmpresult = cmp; + args->offset = xfs_dir2_db_off_to_dataptr(args->geo, + newdb, (char *)dep - (char *)dbp->b_addr); *indexp = index; /* case exact match: return the current buffer. */ if (cmp == XFS_CMP_EXACT) { diff --git a/libxfs/xfs_dir2_node.c b/libxfs/xfs_dir2_node.c index 621e8bf5..b00fb3cf 100644 --- a/libxfs/xfs_dir2_node.c +++ b/libxfs/xfs_dir2_node.c @@ -884,6 +884,8 @@ xfs_dir2_leafn_lookup_for_entry( args->cmpresult = cmp; args->inumber = be64_to_cpu(dep->inumber); args->filetype = xfs_dir2_data_get_ftype(mp, dep); + args->offset = xfs_dir2_db_off_to_dataptr(args->geo, ++ newdb, (char *)dep - (char *)curbp->b_addr); *indexp = index; state->extravalid = 1; state->extrablk.bp = curbp; diff --git a/libxfs/xfs_dir2_sf.c b/libxfs/xfs_dir2_sf.c index 6a128748..9356bf62 100644 --- a/libxfs/xfs_dir2_sf.c +++ b/libxfs/xfs_dir2_sf.c @@ -889,6 +889,7 @@ xfs_dir2_sf_lookup( args->inumber = dp->i_ino; args->cmpresult = XFS_CMP_EXACT; args->filetype = XFS_DIR3_FT_DIR; + args->offset = 1; return -EEXIST; } /* @@ -899,6 +900,7 @@ xfs_dir2_sf_lookup( args->inumber = xfs_dir2_sf_get_parent_ino(sfp); args->cmpresult = XFS_CMP_EXACT; args->filetype = XFS_DIR3_FT_DIR; + args->offset = 2; return -EEXIST; } /* @@ -917,6 +919,8 @@ xfs_dir2_sf_lookup( args->cmpresult = cmp; args->inumber = xfs_dir2_sf_get_ino(mp, sfp, sfep); args->filetype = xfs_dir2_sf_get_ftype(mp, sfep); + args->offset = xfs_dir2_byte_to_dataptr( + xfs_dir2_sf_get_offset(sfep)); if (cmp == XFS_CMP_EXACT) return -EEXIST; ci_sfep = sfep; From patchwork Thu Feb 16 21:00:48 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: 13143890 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 A0EE4C636CC for ; Thu, 16 Feb 2023 21:00:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229993AbjBPVAx (ORCPT ); Thu, 16 Feb 2023 16:00:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjBPVAx (ORCPT ); Thu, 16 Feb 2023 16:00:53 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D05B1505E5 for ; Thu, 16 Feb 2023 13:00: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 sin.source.kernel.org (Postfix) with ESMTPS id 2AE2CCE2BC8 for ; Thu, 16 Feb 2023 21:00:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C23DC433EF; Thu, 16 Feb 2023 21:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581248; bh=l6ozBx4os0zEJBk3YDZ1sivlG4DR1Z3n5PaD/KEF224=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=RFONiytu/BrnGAJky49aw6Q8QtQDGrp4xoSaysekPXoqSOqNm4WZVwx9SavlMQhlo oxFDhipL93TfLR1DISxT82o3VQqrr1A+cHahZi6Bt9Kw7I7FfZAuyJqLKp0vcU48jy iAcn9gZl+tddxk+RVmTbfvN/oLciwAlaKMFLVJ6i2aL5tzj72NfXWdmRCecQ8TLm79 7T2k7nk1uD3TNOSSCh39XLb54bmJxx0oD7QjdDNqGwH/oYO3623XcZiTicQXEm2h0j OgGEg6iyuIdKN7mmL/ESoeM7xIh22zF6ULS+NxSV/fENz2TtfRn5x2X/RkExLvXnVs fel2kgh25YKDA== Date: Thu, 16 Feb 2023 13:00:48 -0800 Subject: [PATCH 3/6] xfs: move/add parent pointer validators to xfs_parent From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879574.3476725.2132610983551662772.stgit@magnolia> In-Reply-To: <167657879533.3476725.4672667573997149436.stgit@magnolia> References: <167657879533.3476725.4672667573997149436.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Move the parent pointer xattr name validator to xfs_parent.c, and add a new function to check the xattr value. Signed-off-by: Darrick J. Wong --- libxfs/xfs_attr.c | 61 +++++++++++---------------------------------------- libxfs/xfs_attr.h | 2 +- libxfs/xfs_parent.c | 44 +++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 7 ++++++ 4 files changed, 65 insertions(+), 49 deletions(-) diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 0cb76f8f..9afa0fef 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -24,6 +24,7 @@ #include "xfs_quota_defs.h" #include "xfs_trans_space.h" #include "xfs_trace.h" +#include "xfs_parent.h" struct kmem_cache *xfs_attr_intent_cache; @@ -1575,62 +1576,26 @@ xfs_attr_node_get( return error; } -/* - * 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) -{ - /* - * MAXNAMELEN includes the trailing null, but (name/length) leave it - * out, so use >= for the length check. - */ - if (length >= MAXNAMELEN) - return false; - - /* There shouldn't be any nulls here */ - 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) + unsigned 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); - } + if (flags & XFS_ATTR_PARENT) + return xfs_parent_namecheck(mp, name, length, flags); - return xfs_str_attr_namecheck(name, length); + /* + * MAXNAMELEN includes the trailing null, but (name/length) leave it + * out, so use >= for the length check. + */ + if (length >= MAXNAMELEN) + return false; + + /* There shouldn't be any nulls here */ + return !memchr(name, 0, length); } int __init diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index 98576126..d6d23cf1 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -551,7 +551,7 @@ 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(struct xfs_mount *mp, const void *name, size_t length, - int flags); + unsigned 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/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 47ea6b89..654eaec7 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -56,6 +56,50 @@ xfs_init_parent_ptr(struct xfs_parent_ptr *xpp, * occurring. */ +/* Return true if parent pointer EA name is valid. */ +bool +xfs_parent_namecheck( + struct xfs_mount *mp, + const struct xfs_parent_name_rec *rec, + size_t reclen, + unsigned int attr_flags) +{ + xfs_ino_t p_ino; + xfs_dir2_dataptr_t p_diroffset; + + if (reclen != sizeof(struct xfs_parent_name_rec)) + return false; + + /* Only one namespace bit allowed. */ + if (hweight32(attr_flags & XFS_ATTR_NSP_ONDISK_MASK) > 1) + return false; + + p_ino = be64_to_cpu(rec->p_ino); + if (!xfs_verify_ino(mp, p_ino)) + return false; + + p_diroffset = be32_to_cpu(rec->p_diroffset); + if (p_diroffset > XFS_DIR2_MAX_DATAPTR) + return false; + + return true; +} + +/* Return true if parent pointer EA value is valid. */ +bool +xfs_parent_valuecheck( + struct xfs_mount *mp, + const void *value, + size_t valuelen) +{ + if (valuelen == 0 || valuelen >= MAXNAMELEN) + return false; + + if (value == NULL) + return false; + + return true; +} /* Initializes a xfs_parent_name_rec to be stored as an attribute name */ void diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 13040b9d..4ffcb81d 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -8,6 +8,13 @@ extern struct kmem_cache *xfs_parent_intent_cache; +/* Metadata validators */ +bool xfs_parent_namecheck(struct xfs_mount *mp, + const struct xfs_parent_name_rec *rec, size_t reclen, + unsigned int attr_flags); +bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value, + size_t valuelen); + /* * Dynamically allocd structure used to wrap the needed data to pass around * the defer ops machinery From patchwork Thu Feb 16 21:01: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: 13143891 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 B35C5C6379F for ; Thu, 16 Feb 2023 21:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjBPVBI (ORCPT ); Thu, 16 Feb 2023 16:01:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230037AbjBPVBI (ORCPT ); Thu, 16 Feb 2023 16:01:08 -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 B76D8505E5 for ; Thu, 16 Feb 2023 13:01:06 -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 76D04B82962 for ; Thu, 16 Feb 2023 21:01:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CB3FC433EF; Thu, 16 Feb 2023 21:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581264; bh=TmSfSTkU+atxB1+XLNFJ+JmXNa/5JRppVl3vzzG6hYU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=WTlt9cr5IDQG18JEOEoxs3G8YfEdrCq5XwtBuxaLTec62pbZRp7lImR+CWopvkcPs fgjj6j+UGKTzS4xvsBpcbP+Ynmx60KpLtsEWSzDZhbr8tVDqPL9N7gqdHnwfmBce9p DXcyqzRF4Nw+ZAvMPv5klYLcPxPNpbc41aH7btdevqfFX2RFrqUz2AmgmhuZ1U4prE ru/rnQQwAL5IgwBnVckUbbutggWg0iTeSUoUcYu+cw7Uu/CKmhHG/bPc8Oxc8uSVV+ PeJ8jHQZzLA0UYCQfNfxS2jWYyCe1KMK2ceZPvK7O/CApZ+rICeVUMi1LaeT71yNWx l2k9RztyqO+YA== Date: Thu, 16 Feb 2023 13:01:03 -0800 Subject: [PATCH 4/6] xfs: don't remove the attr fork when parent pointers are enabled From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879587.3476725.1856410589948339842.stgit@magnolia> In-Reply-To: <167657879533.3476725.4672667573997149436.stgit@magnolia> References: <167657879533.3476725.4672667573997149436.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong When running generic/388, I observed the following .out.bad output: _check_xfs_filesystem: filesystem on /dev/sda4 is inconsistent (r) *** xfs_repair -n output *** Phase 1 - find and verify superblock... Phase 2 - using internal log - zero log... - scan filesystem freespace and inode maps... - found root inode chunk Phase 3 - for each AG... - scan (but don't clear) agi unlinked lists... - process known inodes and perform inode discovery... - agno = 0 - agno = 1 mismatch between format (2) and size (276) in symlink ino 37223730 bad data fork in symlink 37223730 would have cleared inode 37223730 - agno = 2 - agno = 3 mismatch between format (2) and size (276) in symlink ino 102725435 bad data fork in symlink 102725435 would have cleared inode 102725435 - process newly discovered inodes... Phase 4 - check for duplicate blocks... - setting up duplicate extent list... unknown block state, ag 1, blocks 458655-458655 unknown block state, ag 3, blocks 257772-257772 - check for inodes claiming duplicate blocks... - agno = 1 - agno = 2 - agno = 3 - agno = 0 mismatch between format (2) and size (276) in symlink ino 102725435 bad data fork in symlink 102725435 would have cleared inode 102725435 mismatch between format (2) and size (276) in symlink ino 37223730 bad data fork in symlink 37223730 would have cleared inode 37223730 No modify flag set, skipping phase 5 Phase 6 - check inode connectivity... - traversing filesystem ... - traversal finished ... - moving disconnected inodes to lost+found ... Phase 7 - verify link counts... user quota id 0 has bcount 1140448, expected 1140446 user quota id 0 has icount 39892, expected 39890 No modify flag set, skipping filesystem flush and exiting. Inode 37223730 is an unlinked remote-format symlink with no xattr fork. According to the inode verifier and xfs_repair, this symlink ought to have a local format data fork, since 276 bytes is small enough to fit in the immediate area. How did we get here? fsstress removed the symlink, which removed the last parent pointer xattr. There were no other xattrs, so that removal also removed the attr fork. This transaction got flushed to the log, but the system went down before we could inactivate the symlink. Log recovery tried to inactivate this inode (since it is on the unlinked list) but the verifier tripped over the remote value and leaked it. Hence we ended up with a file in this odd state on a "clean" mount. The "obvious" fix is to prohibit erasure of the attr fork to avoid tripping over the verifiers when pptrs are enabled. I wonder this could be reproduced with normal xattrs and (say) a directory? Maybe this fix should target /any/ symlink or directory? Signed-off-by: Darrick J. Wong --- libxfs/xfs_attr_leaf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c index 6cac2531..6391f6ab 100644 --- a/libxfs/xfs_attr_leaf.c +++ b/libxfs/xfs_attr_leaf.c @@ -851,7 +851,8 @@ xfs_attr_sf_removename( totsize -= size; if (totsize == sizeof(xfs_attr_sf_hdr_t) && xfs_has_attr2(mp) && (dp->i_df.if_format != XFS_DINODE_FMT_BTREE) && - !(args->op_flags & (XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE))) { + !(args->op_flags & (XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE)) && + !xfs_has_parent(mp)) { xfs_attr_fork_remove(dp, args->trans); } else { xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); @@ -860,7 +861,8 @@ xfs_attr_sf_removename( ASSERT(totsize > sizeof(xfs_attr_sf_hdr_t) || (args->op_flags & XFS_DA_OP_ADDNAME) || !xfs_has_attr2(mp) || - dp->i_df.if_format == XFS_DINODE_FMT_BTREE); + dp->i_df.if_format == XFS_DINODE_FMT_BTREE || + xfs_has_parent(mp)); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA); } From patchwork Thu Feb 16 21:01:19 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: 13143892 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 75256C636CC for ; Thu, 16 Feb 2023 21:01:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbjBPVB1 (ORCPT ); Thu, 16 Feb 2023 16:01:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbjBPVBZ (ORCPT ); Thu, 16 Feb 2023 16:01:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AF52505F0 for ; Thu, 16 Feb 2023 13:01:22 -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 072CBB82958 for ; Thu, 16 Feb 2023 21:01:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1AD1C433D2; Thu, 16 Feb 2023 21:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581279; bh=A2CowVBKySxkoJxcmUA7Fp0Aba7G137bR+CHi+Cbymk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=hoAIHXdjFq0d/rYNJ8g6YCy9WLvb80M+6gmdOt1eMY2A351C3fS6fLAmCm1ANONBO G2EBFqHSSigaYq6apZ3aa407g4edV4v4wZ2dRJ+dZnsfHvD6g6Kr7UuXR5OAbznGle doS4outbwV0vjavinHmp/i6l2Nl0bqEPixK1LP9K9ZQWHdLQEWBL+oaYk0KTKi82dF OHAo9Mxk3zlUnwAJiId2gb5OAsD0TldtmGPBlWtdy1EHLp4cm+al7o2U59Zl0wrKz7 aEKeCaKptqwM429vbhDvEynK+arH2VXzOUuoZzsD3JgI4KMN26THreblgd8IobQ2R2 lmV+SppgJH43w== Date: Thu, 16 Feb 2023 13:01:19 -0800 Subject: [PATCH 5/6] xfs: pass the attr value to put_listent when possible From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879600.3476725.10228582144058673841.stgit@magnolia> In-Reply-To: <167657879533.3476725.4672667573997149436.stgit@magnolia> References: <167657879533.3476725.4672667573997149436.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Pass the attr value to put_listent when we have local xattrs or shortform xattrs. Signed-off-by: Darrick J. Wong --- libxfs/xfs_attr.h | 5 +++-- libxfs/xfs_attr_sf.h | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_attr.h b/libxfs/xfs_attr.h index d6d23cf1..02a20b94 100644 --- a/libxfs/xfs_attr.h +++ b/libxfs/xfs_attr.h @@ -47,8 +47,9 @@ struct xfs_attrlist_cursor_kern { /* void; state communicated via *context */ -typedef void (*put_listent_func_t)(struct xfs_attr_list_context *, int, - unsigned char *, int, int); +typedef void (*put_listent_func_t)(struct xfs_attr_list_context *context, + int flags, unsigned char *name, int namelen, void *value, + int valuelen); struct xfs_attr_list_context { struct xfs_trans *tp; diff --git a/libxfs/xfs_attr_sf.h b/libxfs/xfs_attr_sf.h index 37578b36..c6e25979 100644 --- a/libxfs/xfs_attr_sf.h +++ b/libxfs/xfs_attr_sf.h @@ -24,6 +24,7 @@ typedef struct xfs_attr_sf_sort { uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */ xfs_dahash_t hash; /* this entry's hash value */ unsigned char *name; /* name value, pointer into buffer */ + void *value; } xfs_attr_sf_sort_t; #define XFS_ATTR_SF_ENTSIZE_MAX /* max space for name&value */ \ From patchwork Thu Feb 16 21:01: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: 13143893 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 AC3CCC61DA4 for ; Thu, 16 Feb 2023 21:01:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbjBPVBk (ORCPT ); Thu, 16 Feb 2023 16:01:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbjBPVBj (ORCPT ); Thu, 16 Feb 2023 16:01:39 -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 E8061505D9 for ; Thu, 16 Feb 2023 13:01:37 -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 9F634B82958 for ; Thu, 16 Feb 2023 21:01:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B581C433D2; Thu, 16 Feb 2023 21:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581295; bh=FRpWoOGlwtyuHn9xLVJUWZAVUxFwEa9C2ffU4OobmZY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=q/ovwizL9VdQei/jpO+AWk+xGXjhoJCoIINaw1u+t1BTWgQenSJUkMTO4U1VQ5iky 4pONwOiZh/+feo7clDjmo64kKYfdDBKkAOkKRkDDbsSDYhfdgCiyM2Aood749fxFv7 D0QdDN9vK/8zG1wJTUjKbiohj2Pdytu583X5gRjOkCbO98svjrdErjD7HTVEpA+NAj EmtovKRQ9qDG4W9s5Xe71TCt0YtKzJiWsxOZ834a336pFyipLdZu6WT5J1YdP1Gp+u HP81g5uekq0+czcQqxtXWf96lA/f1ipdQr5p8wFN6MY82r5r9mvQtGwUpAJe8xuuCI r5Zf8fTojC+Ig== Date: Thu, 16 Feb 2023 13:01:34 -0800 Subject: [PATCH 6/6] xfs: replace the XFS_IOC_GETPARENTS backend From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879613.3476725.13548814793158748741.stgit@magnolia> In-Reply-To: <167657879533.3476725.4672667573997149436.stgit@magnolia> References: <167657879533.3476725.4672667573997149436.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Now that xfs_attr_list can pass local xattr values to the put_listent function, build a new version of the GETPARENTS backend that supplies a custom put_listent function to format parent pointer info directly into the caller's buffer. This uses a lot less memory and obviates the iterate list and then grab the values logic, since parent pointers aren't supposed to have remote values anyway. Signed-off-by: Darrick J. Wong --- libxfs/xfs_parent.c | 40 ++++++++++++++++++++++++++++++---------- libxfs/xfs_parent.h | 21 +++++++++++++++++++-- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 654eaec7..74c7f1f7 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -30,16 +30,6 @@ 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. * @@ -116,6 +106,36 @@ xfs_init_parent_name_rec( rec->p_diroffset = cpu_to_be32(p_diroffset); } +/* + * Convert an ondisk parent_name xattr to its incore format. If @value is + * NULL, set @irec->p_namelen to zero and leave @irec->p_name untouched. + */ +void +xfs_parent_irec_from_disk( + struct xfs_parent_name_irec *irec, + const struct xfs_parent_name_rec *rec, + const void *value, + int valuelen) +{ + irec->p_ino = be64_to_cpu(rec->p_ino); + irec->p_gen = be32_to_cpu(rec->p_gen); + irec->p_diroffset = be32_to_cpu(rec->p_diroffset); + + if (!value) { + irec->p_namelen = 0; + return; + } + + ASSERT(valuelen > 0); + ASSERT(valuelen < MAXNAMELEN); + + valuelen = min(valuelen, MAXNAMELEN); + + irec->p_namelen = valuelen; + memcpy(irec->p_name, value, valuelen); + memset(&irec->p_name[valuelen], 0, sizeof(irec->p_name) - valuelen); +} + int __xfs_parent_init( struct xfs_mount *mp, diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index 4ffcb81d..f4f5887d 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -15,6 +15,25 @@ bool xfs_parent_namecheck(struct xfs_mount *mp, bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value, size_t valuelen); +/* + * Incore version of a parent pointer, also contains dirent name so callers + * can pass/obtain all the parent pointer information in a single structure + */ +struct xfs_parent_name_irec { + /* Key fields for looking up a particular parent pointer. */ + xfs_ino_t p_ino; + uint32_t p_gen; + xfs_dir2_dataptr_t p_diroffset; + + /* Attributes of a parent pointer. */ + uint8_t p_namelen; + unsigned char p_name[MAXNAMELEN]; +}; + +void xfs_parent_irec_from_disk(struct xfs_parent_name_irec *irec, + const struct xfs_parent_name_rec *rec, + const void *value, int valuelen); + /* * Dynamically allocd structure used to wrap the needed data to pass around * the defer ops machinery @@ -32,8 +51,6 @@ 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);