From patchwork Thu Feb 16 21:01: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: 13143894 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 3B64DC636CC for ; Thu, 16 Feb 2023 21:01:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbjBPVBx (ORCPT ); Thu, 16 Feb 2023 16:01:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjBPVBw (ORCPT ); Thu, 16 Feb 2023 16:01:52 -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 DFCB7528B7 for ; Thu, 16 Feb 2023 13:01: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 7D4DB60C69 for ; Thu, 16 Feb 2023 21:01:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFC00C433EF; Thu, 16 Feb 2023 21:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581310; bh=SDCH4xNH1104nGicDC3U5cXSbbaLc3IomO7ExFQX2MA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=HG0+Gy8kwgP3xahu6IoNdcmVB2sAMsFKcVamtTBGeQc93jLzKOtVUwk/0YUsqjDdk DeIY7oN9fJFwE/0Q/IFGjdg4OMtylwuccoW4pz4UCSctunXAK+Pei/BbFEpNobzWww ipznyfR1pGvqPitK8f1l4DqkCANpZyGRZm6l8Qu/XEMwKC5HwnLlAdgRF7qGM0RoaY hQvERpF1a1cdYfSA6jpz6k3knUM0Eo0S5cMWRlfO0KOJmq3Xp8fPTnIrRiMpmkfdeK r0mINxG3ASe9CdHNsPZE4jtHhZdpP25LS91MYnHfhpU0ichXSpjnSsiAFdyCgd9tgE Bov4Uy269fL6A== Date: Thu, 16 Feb 2023 13:01:50 -0800 Subject: [PATCH 1/6] xfs_scrub: don't report media errors for space with unknowable owner From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879909.3476911.18047241575255398541.stgit@magnolia> In-Reply-To: <167657879895.3476911.2211427543938389071.stgit@magnolia> References: <167657879895.3476911.2211427543938389071.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 On filesystems that don't have the reverse mapping feature enabled, the GETFSMAP call cannot tell us much about the owner of a space extent -- we're limited to static fs metadata, free space, or "unknown". In this case, nothing is corrupt, so str_corrupt is not an appropriate logging function. Relax this to str_info so that the user sees a notice that media errors have been found so that the user knows something bad happened even if the directory tree walker cannot find the file owning the space where the media error was found. Filesystems with rmap enabled are never supposed to return OWN_UNKNOWN from a GETFSMAP report, so continue to report that as a corruption. This fixes regressions reported by xfs/556. Signed-off-by: Darrick J. Wong --- scrub/phase6.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scrub/phase6.c b/scrub/phase6.c index afdb16b6..1a2643bd 100644 --- a/scrub/phase6.c +++ b/scrub/phase6.c @@ -397,7 +397,18 @@ report_ioerr_fsmap( snprintf(buf, DESCR_BUFSZ, _("disk offset %"PRIu64), (uint64_t)map->fmr_physical + err_off); type = decode_special_owner(map->fmr_owner); - str_corrupt(ctx, buf, _("media error in %s."), type); + /* + * On filesystems that don't store reverse mappings, the + * GETFSMAP call returns OWNER_UNKNOWN for allocated space. + * We'll have to let the directory tree walker find the file + * that lost data. + */ + if (!(ctx->mnt.fsgeom.flags & XFS_FSOP_GEOM_FLAGS_RMAPBT) && + map->fmr_owner == XFS_FMR_OWN_UNKNOWN) { + str_info(ctx, buf, _("media error detected.")); + } else { + str_corrupt(ctx, buf, _("media error in %s."), type); + } } /* Report extent maps */ From patchwork Thu Feb 16 21:02:06 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: 13143895 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 6D189C636CC for ; Thu, 16 Feb 2023 21:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230059AbjBPVCS (ORCPT ); Thu, 16 Feb 2023 16:02:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbjBPVCQ (ORCPT ); Thu, 16 Feb 2023 16:02:16 -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 4019C52CCC for ; Thu, 16 Feb 2023 13:02:09 -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 DFE82B829AB for ; Thu, 16 Feb 2023 21:02:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85C8CC433D2; Thu, 16 Feb 2023 21:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581326; bh=lGxe/3NSkCR2N4qIznRETgwDZYuohvDsOAEyphDQIak=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ak5xHSkt0Z/C1uXpGG0C8XSBxO3qLN6laJoZO6ihIn5qDCaZiA0cDBpRaUZ/XTGeY jIGv5HqBAWGt4QgCF150QASnXqKa8A5ys+hCI41ZcJjvM/TtMD03GvSP1Jl4ERUlZN tKk1gBLQ4ZJGwqesu7r0+PobXcelNuq0dQHAN56V7695Vp8oY8yau56WT+Ue+5yQWJ vrezJOo+seUqMGhqLgO1+QPIKXSw6mN2KCUtlAhkzsgwu0/p9JfjgdVwMjdKeZqyxK fn3kryRNKrrEx5hcyCEpjuBumS5D0VuhhHvHPUnjbPYHBm62q4OqNNePZXSNoHIP4e Quuf61lcteTgg== Date: Thu, 16 Feb 2023 13:02:06 -0800 Subject: [PATCH 2/6] mkfs: fix libxfs api misuse From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879922.3476911.12374504204515101304.stgit@magnolia> In-Reply-To: <167657879895.3476911.2211427543938389071.stgit@magnolia> References: <167657879895.3476911.2211427543938389071.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 Fix libxfs usage problems as pointed out by xfs/437. Signed-off-by: Darrick J. Wong --- libxfs/libxfs_api_defs.h | 1 + mkfs/proto.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index f8efcce7..e44b0b29 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -124,6 +124,7 @@ #define xfs_initialize_perag libxfs_initialize_perag #define xfs_initialize_perag_data libxfs_initialize_perag_data #define xfs_init_local_fork libxfs_init_local_fork +#define xfs_init_parent_name_rec libxfs_init_parent_name_rec #define xfs_inobt_maxrecs libxfs_inobt_maxrecs #define xfs_inobt_stage_cursor libxfs_inobt_stage_cursor diff --git a/mkfs/proto.c b/mkfs/proto.c index 36d8cde2..ac7ffbe9 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -613,8 +613,8 @@ parseproto( .value = (void *)xname.name, .valuelen = xname.len, }; - xfs_init_parent_name_rec(&rec, pip, offset); - error = xfs_attr_set(&args); + libxfs_init_parent_name_rec(&rec, pip, offset); + error = -libxfs_attr_set(&args); if (error) fail(_("Error creating parent pointer"), error); } From patchwork Thu Feb 16 21:02: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: 13143896 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 23B1AC636CC for ; Thu, 16 Feb 2023 21:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230060AbjBPVC0 (ORCPT ); Thu, 16 Feb 2023 16:02:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230044AbjBPVCZ (ORCPT ); Thu, 16 Feb 2023 16:02:25 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B91DB4D606 for ; Thu, 16 Feb 2023 13:02: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 6A15EB826BA for ; Thu, 16 Feb 2023 21:02:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A047C433EF; Thu, 16 Feb 2023 21:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581342; bh=rISdAqbnC6MnxgB7Wv3rwsQ4zrQIcNsV1+cIf6kwnXQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=FuGYdwaW+yjNBDE7MuQI6QU861eCovvqyXk4+LdV3VKPuhcuJofwUL26sMyIDHZWU 8TGCMcJ1zClNkbJ5j4NOd1P6aMhrOmytXqGPg2ZwT9528W4Og2uOh2IWg15g7NPkNY Lcwr3Fjwgs3+4Lyj4PMphe+g2FMDIn+fmsx3F/nICsszeAo+U/utNyL7Qz6YNDvO0O bys9+TBkJ21goqH6joYIYFA2In4lPgNzDLMUD/cFqxoUbdoy5HRAAOHQzl+c++3rWN lCLsrEk4GQ/HIIo3dggIeZZATrkAp44bRGpYF6e/WxXKwVxkQfHV4CGhIwMoiuMmEP waZNTCsmOB9Kg== Date: Thu, 16 Feb 2023 13:02:21 -0800 Subject: [PATCH 3/6] libxfs: create new files with attr forks if necessary From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879935.3476911.5056578529876837289.stgit@magnolia> In-Reply-To: <167657879895.3476911.2211427543938389071.stgit@magnolia> References: <167657879895.3476911.2211427543938389071.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 Create new files with attr forks if they're going to have parent pointers. In the next patch we'll fix mkfs to use the same parent creation functions as the kernel, so we're going to need this. Signed-off-by: Darrick J. Wong --- libxfs/init.c | 4 ++++ libxfs/util.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/libxfs/init.c b/libxfs/init.c index 49cb2326..cffd8a63 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -736,14 +736,18 @@ void libxfs_compute_all_maxlevels( struct xfs_mount *mp) { + struct xfs_ino_geometry *igeo = M_IGEO(mp); + xfs_alloc_compute_maxlevels(mp); xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK); xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK); + igeo->attr_fork_offset = xfs_bmap_compute_attr_offset(mp); xfs_ialloc_setup_geometry(mp); xfs_rmapbt_compute_maxlevels(mp); xfs_refcountbt_compute_maxlevels(mp); xfs_agbtree_compute_maxlevels(mp); + } /* diff --git a/libxfs/util.c b/libxfs/util.c index 6525f63d..bea5f1c7 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -322,6 +322,20 @@ libxfs_init_new_inode( ASSERT(0); } + /* + * If we need to create attributes immediately after allocating the + * inode, initialise an empty attribute fork right now. We use the + * default fork offset for attributes here as we don't know exactly what + * size or how many attributes we might be adding. We can do this + * safely here because we know the data fork is completely empty and + * this saves us from needing to run a separate transaction to set the + * fork offset in the immediate future. + */ + if (xfs_has_parent(tp->t_mountp) && xfs_has_attr(tp->t_mountp)) { + ip->i_forkoff = xfs_default_attroffset(ip) >> 3; + xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); + } + /* * Log the new values stuffed into the inode. */ From patchwork Thu Feb 16 21:02:37 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: 13143897 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 398B7C636CC for ; Thu, 16 Feb 2023 21:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230044AbjBPVCm (ORCPT ); Thu, 16 Feb 2023 16:02:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjBPVCl (ORCPT ); Thu, 16 Feb 2023 16:02:41 -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 67F1E505D9 for ; Thu, 16 Feb 2023 13:02: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 17B15B82760 for ; Thu, 16 Feb 2023 21:02:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A67B5C433D2; Thu, 16 Feb 2023 21:02:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581357; bh=XTWBKIFcR5QHsPdYCtx0/DmPIFjUUOWqRHV24fdQZPI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=HfcfDJDi5Rh3at5leRnMSwhwCFl7Vehv0tg+YNav7CKmo0h+Ja3JRb16fyV9+0j0h 0c9AL91929xM3A5MiaYAxNoELj4pzjPl2k7x3F8cFOoPb0rANA+99lMJRESy3cDBm4 CVEkwZxptGgpdTb5ZUgcmw4VvsYI6xW16YZj+XCZhcuiLox+xsW0aqfviafZva+EK7 TNsgqNRNnWySswhqn4cTbmzKfcm23B8oAw0E3cM5lk9Pbu2khDquTk+3wrOpiqQQH7 ztX9okvnQMOlj6dPJoFQxn3zBgV3EAaVPo3fTtzu+DQtn+5m6c348dtrNBW1qs3CnG 13Pc41uDzKNxA== Date: Thu, 16 Feb 2023 13:02:37 -0800 Subject: [PATCH 4/6] mkfs: fix subdir parent pointer creation From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879948.3476911.9370952561179748819.stgit@magnolia> In-Reply-To: <167657879895.3476911.2211427543938389071.stgit@magnolia> References: <167657879895.3476911.2211427543938389071.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 Rework the protofile code so that it uses the same deferred parent pointer ops that the kernel uses to create parent pointers. While we're at it, make it so that subdirs of the root directory and reserved files also get parent pointers. Found by xfs/019. Signed-off-by: Darrick J. Wong --- libxfs/libxfs_api_defs.h | 3 ++ mkfs/proto.c | 65 +++++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index e44b0b29..055d2862 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -140,6 +140,9 @@ #define xfs_log_get_max_trans_res libxfs_log_get_max_trans_res #define xfs_log_sb libxfs_log_sb #define xfs_mode_to_ftype libxfs_mode_to_ftype +#define xfs_parent_defer_add libxfs_parent_defer_add +#define xfs_parent_finish libxfs_parent_finish +#define xfs_parent_start libxfs_parent_start #define xfs_perag_get libxfs_perag_get #define xfs_perag_put libxfs_perag_put #define xfs_prealloc_blocks libxfs_prealloc_blocks diff --git a/mkfs/proto.c b/mkfs/proto.c index ac7ffbe9..e0131df5 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -8,7 +8,6 @@ #include #include "libfrog/convert.h" #include "proto.h" -#include "xfs_parent.h" /* * Prototypes for internal functions. @@ -349,6 +348,20 @@ newdirectory( fail(_("directory create error"), error); } +static struct xfs_parent_defer * +newpptr( + struct xfs_mount *mp) +{ + struct xfs_parent_defer *ret; + int error; + + error = -libxfs_parent_start(mp, &ret); + if (error) + fail(_("initializing parent pointer"), error); + + return ret; +} + static void parseproto( xfs_mount_t *mp, @@ -384,6 +397,7 @@ parseproto( char *value; struct xfs_name xname; xfs_dir2_dataptr_t offset; + struct xfs_parent_defer *parent = NULL; memset(&creds, 0, sizeof(creds)); mstr = getstr(pp); @@ -458,6 +472,7 @@ parseproto( case IF_REGULAR: buf = newregfile(pp, &len); tp = getres(mp, XFS_B_TO_FSB(mp, len)); + parent = newpptr(mp); error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); if (error) @@ -481,7 +496,7 @@ parseproto( exit(1); } tp = getres(mp, XFS_B_TO_FSB(mp, llen)); - + parent = newpptr(mp); error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); if (error) @@ -492,15 +507,24 @@ parseproto( xname.type = XFS_DIR3_FT_REG_FILE; newdirent(mp, tp, pip, &xname, ip->i_ino, &offset); libxfs_trans_log_inode(tp, ip, flags); + if (parent) { + error = -libxfs_parent_defer_add(tp, parent, pip, + &xname, offset, ip); + if (error) + fail(_("committing parent pointers failed."), + error); + } error = -libxfs_trans_commit(tp); if (error) fail(_("Space preallocation failed."), error); + libxfs_parent_finish(mp, parent); rsvfile(mp, ip, llen); libxfs_irele(ip); return; case IF_BLOCK: tp = getres(mp, 0); + parent = newpptr(mp); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFBLK, 1, @@ -516,6 +540,7 @@ parseproto( case IF_CHAR: tp = getres(mp, 0); + parent = newpptr(mp); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFCHR, 1, @@ -530,6 +555,7 @@ parseproto( case IF_FIFO: tp = getres(mp, 0); + parent = newpptr(mp); error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFIFO, 1, 0, &creds, fsxp, &ip); if (error) @@ -542,6 +568,7 @@ parseproto( buf = getstr(pp); len = (int)strlen(buf); tp = getres(mp, XFS_B_TO_FSB(mp, len)); + parent = newpptr(mp); error = -libxfs_dir_ialloc(&tp, pip, mode|S_IFLNK, 1, 0, &creds, fsxp, &ip); if (error) @@ -564,6 +591,7 @@ parseproto( libxfs_log_sb(tp); isroot = 1; } else { + parent = newpptr(mp); libxfs_trans_ijoin(tp, pip, 0); xname.type = XFS_DIR3_FT_DIR; newdirent(mp, tp, pip, &xname, ip->i_ino, &offset); @@ -572,9 +600,19 @@ parseproto( } newdirectory(mp, tp, ip, pip); libxfs_trans_log_inode(tp, ip, flags); + if (parent) { + error = -libxfs_parent_defer_add(tp, parent, pip, + &xname, offset, ip); + if (error) + fail(_("committing parent pointers failed."), + error); + } error = -libxfs_trans_commit(tp); if (error) fail(_("Directory inode allocation failed."), error); + + libxfs_parent_finish(mp, parent); + /* * RT initialization. Do this here to ensure that * the RT inodes get placed after the root inode. @@ -597,28 +635,19 @@ parseproto( fail(_("Unknown format"), EINVAL); } libxfs_trans_log_inode(tp, ip, flags); + if (parent) { + error = -libxfs_parent_defer_add(tp, parent, pip, &xname, + offset, ip); + if (error) + fail(_("committing parent pointers failed."), error); + } error = -libxfs_trans_commit(tp); if (error) { fail(_("Error encountered creating file from prototype file"), error); } - if (xfs_has_parent(mp)) { - struct xfs_parent_name_rec rec; - struct xfs_da_args args = { - .dp = ip, - .name = (const unsigned char *)&rec, - .namelen = sizeof(rec), - .attr_filter = XFS_ATTR_PARENT, - .value = (void *)xname.name, - .valuelen = xname.len, - }; - libxfs_init_parent_name_rec(&rec, pip, offset); - error = -libxfs_attr_set(&args); - if (error) - fail(_("Error creating parent pointer"), error); - } - + libxfs_parent_finish(mp, parent); libxfs_irele(ip); } From patchwork Thu Feb 16 21:02: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: 13143898 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 E47BAC61DA4 for ; Thu, 16 Feb 2023 21:02:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229985AbjBPVC6 (ORCPT ); Thu, 16 Feb 2023 16:02:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjBPVC6 (ORCPT ); Thu, 16 Feb 2023 16:02:58 -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 285CF16324 for ; Thu, 16 Feb 2023 13:02:55 -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 906DCB8217A for ; Thu, 16 Feb 2023 21:02:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DC81C433D2; Thu, 16 Feb 2023 21:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581373; bh=UMhw1UjO0TQN3LZ5FNiHOIU/igE8TkRZQ7MTgvgFSh0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=pjNRjn4ALZaDCSJZd8hCBCrpjKpei27Cderz/IT96sIqUJ++v03vtxjAgLMz8lNHK TiXNc6RScplUnZGEy+5ZJEqB0poV5T+GgKE8JIAmbqYbWbUP8ZS9b1WphXb78ZiBK/ cyFJqSC4bVMVU/T+SdYdEbg139Pei+s8i94jXvqwGOLow236xdurx+vgJ+Sv7OTDoP yxJP7FfjkQzkOFboGUxQ5EqaTLN80n+pGNYwotuSA9CpjbnB1FIR45Snpwu5U8WjVX 2dQ0QnVMHgcOu3ajPvYlmBA9/BDFlBEry9gI5/bkLN4OIcdrn1JBSdoqWTyy8SC3Cw RXgwif0muVfug== Date: Thu, 16 Feb 2023 13:02:52 -0800 Subject: [PATCH 5/6] xfs_db: report parent pointer keys From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879962.3476911.9549384051252763800.stgit@magnolia> In-Reply-To: <167657879895.3476911.2211427543938389071.stgit@magnolia> References: <167657879895.3476911.2211427543938389071.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 Decode the parent pointer inode, generation, and diroffset fields. Signed-off-by: Darrick J. Wong --- db/attr.c | 31 +++++++++++++++++++++++++++++++ db/attrshort.c | 25 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/db/attr.c b/db/attr.c index f29e4a54..db7cf54b 100644 --- a/db/attr.c +++ b/db/attr.c @@ -19,6 +19,7 @@ static int attr_leaf_entries_count(void *obj, int startoff); static int attr_leaf_hdr_count(void *obj, int startoff); static int attr_leaf_name_local_count(void *obj, int startoff); static int attr_leaf_name_local_name_count(void *obj, int startoff); +static int attr_leaf_name_pptr_count(void *obj, int startoff); static int attr_leaf_name_local_value_count(void *obj, int startoff); static int attr_leaf_name_local_value_offset(void *obj, int startoff, int idx); @@ -111,6 +112,8 @@ const field_t attr_leaf_map_flds[] = { #define LNOFF(f) bitize(offsetof(xfs_attr_leaf_name_local_t, f)) #define LVOFF(f) bitize(offsetof(xfs_attr_leaf_name_remote_t, f)) +#define PPOFF(f) bitize(offsetof(xfs_attr_leaf_name_local_t, nameval) + \ + offsetof(struct xfs_parent_name_rec, f)) const field_t attr_leaf_name_flds[] = { { "valuelen", FLDT_UINT16D, OI(LNOFF(valuelen)), attr_leaf_name_local_count, FLD_COUNT, TYP_NONE }, @@ -118,6 +121,12 @@ const field_t attr_leaf_name_flds[] = { attr_leaf_name_local_count, FLD_COUNT, TYP_NONE }, { "name", FLDT_CHARNS, OI(LNOFF(nameval)), attr_leaf_name_local_name_count, FLD_COUNT, TYP_NONE }, + { "parent_ino", FLDT_INO, OI(PPOFF(p_ino)), + attr_leaf_name_pptr_count, FLD_COUNT, TYP_INODE }, + { "parent_gen", FLDT_UINT32D, OI(PPOFF(p_gen)), + attr_leaf_name_pptr_count, FLD_COUNT, TYP_NONE }, + { "parent_diroffset", FLDT_UINT32D, OI(PPOFF(p_diroffset)), + attr_leaf_name_pptr_count, FLD_COUNT, TYP_NONE }, { "value", FLDT_CHARNS, attr_leaf_name_local_value_offset, attr_leaf_name_local_value_count, FLD_COUNT|FLD_OFFSET, TYP_NONE }, { "valueblk", FLDT_UINT32X, OI(LVOFF(valueblk)), @@ -273,6 +282,26 @@ attr_leaf_name_local_count( __attr_leaf_name_local_count); } +static int +__attr_leaf_name_pptr_count( + struct xfs_attr_leafblock *leaf, + struct xfs_attr_leaf_entry *e, + int i) +{ + if (e->flags & XFS_ATTR_PARENT) + return 1; + return 0; +} + +static int +attr_leaf_name_pptr_count( + void *obj, + int startoff) +{ + return attr_leaf_entry_walk(obj, startoff, + __attr_leaf_name_pptr_count); +} + static int __attr_leaf_name_local_name_count( struct xfs_attr_leafblock *leaf, @@ -283,6 +312,8 @@ __attr_leaf_name_local_name_count( if (!(e->flags & XFS_ATTR_LOCAL)) return 0; + if (e->flags & XFS_ATTR_PARENT) + return 0; l = xfs_attr3_leaf_name_local(leaf, i); return l->namelen; diff --git a/db/attrshort.c b/db/attrshort.c index 872d771d..7c8ac485 100644 --- a/db/attrshort.c +++ b/db/attrshort.c @@ -13,6 +13,7 @@ #include "attrshort.h" static int attr_sf_entry_name_count(void *obj, int startoff); +static int attr_sf_entry_pptr_count(void *obj, int startoff); static int attr_sf_entry_value_count(void *obj, int startoff); static int attr_sf_entry_value_offset(void *obj, int startoff, int idx); static int attr_shortform_list_count(void *obj, int startoff); @@ -34,6 +35,8 @@ const field_t attr_sf_hdr_flds[] = { }; #define EOFF(f) bitize(offsetof(struct xfs_attr_sf_entry, f)) +#define PPOFF(f) bitize(offsetof(struct xfs_attr_sf_entry, nameval) + \ + offsetof(struct xfs_parent_name_rec, f)) const field_t attr_sf_entry_flds[] = { { "namelen", FLDT_UINT8D, OI(EOFF(namelen)), C1, 0, TYP_NONE }, { "valuelen", FLDT_UINT8D, OI(EOFF(valuelen)), C1, 0, TYP_NONE }, @@ -49,11 +52,31 @@ const field_t attr_sf_entry_flds[] = { TYP_NONE }, { "name", FLDT_CHARNS, OI(EOFF(nameval)), attr_sf_entry_name_count, FLD_COUNT, TYP_NONE }, + { "parent_ino", FLDT_INO, OI(PPOFF(p_ino)), attr_sf_entry_pptr_count, + FLD_COUNT, TYP_INODE }, + { "parent_gen", FLDT_UINT32D, OI(PPOFF(p_gen)), attr_sf_entry_pptr_count, + FLD_COUNT, TYP_NONE }, + { "parent_diroffset", FLDT_UINT32D, OI(PPOFF(p_diroffset)), + attr_sf_entry_pptr_count, FLD_COUNT, TYP_NONE }, { "value", FLDT_CHARNS, attr_sf_entry_value_offset, attr_sf_entry_value_count, FLD_COUNT|FLD_OFFSET, TYP_NONE }, { NULL } }; +static int +attr_sf_entry_pptr_count( + void *obj, + int startoff) +{ + struct xfs_attr_sf_entry *e; + + ASSERT(bitoffs(startoff) == 0); + e = (struct xfs_attr_sf_entry *)((char *)obj + byteize(startoff)); + if (e->flags & XFS_ATTR_PARENT) + return 1; + return 0; +} + static int attr_sf_entry_name_count( void *obj, @@ -63,6 +86,8 @@ attr_sf_entry_name_count( ASSERT(bitoffs(startoff) == 0); e = (struct xfs_attr_sf_entry *)((char *)obj + byteize(startoff)); + if (e->flags & XFS_ATTR_PARENT) + return 0; return e->namelen; } From patchwork Thu Feb 16 21:03: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: 13143899 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 4E0A4C61DA4 for ; Thu, 16 Feb 2023 21:03:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbjBPVDN (ORCPT ); Thu, 16 Feb 2023 16:03:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjBPVDM (ORCPT ); Thu, 16 Feb 2023 16:03:12 -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 66D692A16F for ; Thu, 16 Feb 2023 13:03: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 28A5AB8217A for ; Thu, 16 Feb 2023 21:03:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2ED6C433D2; Thu, 16 Feb 2023 21:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581388; bh=xOrrU5sb2aMdnsZ1/qSxdUGBJNZl7InBE75xBzthy6A=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=MTHz73iGr+m9rA+l6i8msrNOz3jokTHMvW8LY0jqxxScHFEmQcozFdORRmJTGaNOo I/XoQhSysN9lKvSfQWVO+tUWwl0av/chr5qoxN6LEKK/3LlqKxWc6LcMBDeLrEn6V1 ttGDCZ+XdkxdH/gW8vWBBZH4RX9WsWfzV29JtdQz4/vSDoTUDtoecFXqDgto0mNmk/ VR/rLzU1hZfkkH7kmezTDxhjXdQtjC2Ck5DHoByhEFZRRWssYRHbZMCaid9ITsPqu+ UgVzNmCdkMvipln/NE1sziF1Yq7vGroACVGVJgmKa/3hDdCUMnsGPpNH2Hx0nHIkgA 969RaoaiBTJ2A== Date: Thu, 16 Feb 2023 13:03:08 -0800 Subject: [PATCH 6/6] xfs_db: obfuscate dirent and pptr names consistently From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657879975.3476911.17527186602594776178.stgit@magnolia> In-Reply-To: <167657879895.3476911.2211427543938389071.stgit@magnolia> References: <167657879895.3476911.2211427543938389071.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 someone wants to perform an obfuscated metadump of a filesystem where parent pointers are enabled, we have to use the *exact* same obfuscated name for both the directory entry and the parent pointer. Instead of using an RNG to influence the obfuscated name, use the dirent inode number to start the obfuscated name. This makes them consistent, though the resulting names aren't quite so full of control characters. Signed-off-by: Darrick J. Wong --- db/metadump.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/db/metadump.c b/db/metadump.c index 27d1df43..bb441fbb 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -740,12 +740,14 @@ nametable_add(xfs_dahash_t hash, int namelen, unsigned char *name) #define rol32(x,y) (((x) << (y)) | ((x) >> (32 - (y)))) static inline unsigned char -random_filename_char(void) +random_filename_char(xfs_ino_t ino) { static unsigned char filename_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789-_"; + if (ino) + return filename_alphabet[ino % (sizeof filename_alphabet - 1)]; return filename_alphabet[random() % (sizeof filename_alphabet - 1)]; } @@ -815,6 +817,7 @@ in_lost_found( */ static void obfuscate_name( + xfs_ino_t ino, xfs_dahash_t hash, size_t name_len, unsigned char *name) @@ -842,7 +845,7 @@ obfuscate_name( * Accumulate its new hash value as we go. */ for (i = 0; i < name_len - 5; i++) { - *newp = random_filename_char(); + *newp = random_filename_char(ino); new_hash = *newp ^ rol32(new_hash, 7); newp++; } @@ -1207,7 +1210,10 @@ generate_obfuscated_name( /* Obfuscate the name (if possible) */ hash = libxfs_da_hashname(name, namelen); - obfuscate_name(hash, namelen, name); + if (xfs_has_parent(mp)) + obfuscate_name(ino, hash, namelen, name); + else + obfuscate_name(0, hash, namelen, name); /* * Make sure the name is not something already seen. If we @@ -1320,7 +1326,7 @@ obfuscate_path_components( /* last (or single) component */ namelen = strnlen((char *)comp, len); hash = libxfs_da_hashname(comp, namelen); - obfuscate_name(hash, namelen, comp); + obfuscate_name(0, hash, namelen, comp); break; } namelen = slash - (char *)comp; @@ -1331,7 +1337,7 @@ obfuscate_path_components( continue; } hash = libxfs_da_hashname(comp, namelen); - obfuscate_name(hash, namelen, comp); + obfuscate_name(0, hash, namelen, comp); comp += namelen + 1; len -= namelen + 1; } @@ -1407,10 +1413,15 @@ process_sf_attr( } if (obfuscate) { - generate_obfuscated_name(0, asfep->namelen, - &asfep->nameval[0]); - memset(&asfep->nameval[asfep->namelen], 'v', - asfep->valuelen); + if (asfep->flags & XFS_ATTR_PARENT) { + generate_obfuscated_name(cur_ino, asfep->valuelen, + &asfep->nameval[asfep->namelen]); + } else { + generate_obfuscated_name(0, asfep->namelen, + &asfep->nameval[0]); + memset(&asfep->nameval[asfep->namelen], 'v', + asfep->valuelen); + } } asfep = (struct xfs_attr_sf_entry *)((char *)asfep + @@ -1785,7 +1796,7 @@ process_attr_block( (long long)cur_ino); break; } - if (obfuscate) { + if (obfuscate && !(entry->flags & XFS_ATTR_PARENT)) { generate_obfuscated_name(0, local->namelen, &local->nameval[0]); memset(&local->nameval[local->namelen], 'v', @@ -1797,6 +1808,9 @@ process_attr_block( zlen = xfs_attr_leaf_entsize_local(nlen, vlen) - (sizeof(xfs_attr_leaf_name_local_t) - 1 + nlen + vlen); + if (obfuscate && (entry->flags & XFS_ATTR_PARENT)) + generate_obfuscated_name(cur_ino, vlen, + &local->nameval[nlen]); if (zero_stale_data) memset(&local->nameval[nlen + vlen], 0, zlen); } else {