From patchwork Wed Mar 13 17:53:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13591683 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B95357883; Wed, 13 Mar 2024 17:53:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710352402; cv=none; b=t71GbVZ7mF+bMtSybpDyGSXUDIjggUISCBL2iX2+tYshVKhCnb7PBPcLgXokDwlRzDjkaQ6Al3OrMzAO9U2wI5zA9eA4brIDiI+du8PmQm5Dxop5RFMTqPR8DJoGW2r+QJ6n8Lij3BdVDHB/uPrGTQyAfCIjz8AeUIr5wffrJ/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710352402; c=relaxed/simple; bh=3PiQWLCvQqjS7LPBm90t4SOaaoJMbpAwofTbsuxbe28=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=I7Vr6CdRG5XTci+X6J82NI/LvmjHino6hW7WLNN+OiTU6TzsitTt8c4T8dbLnPDR+uqIcgRkeM17AMxWtWCea2o+Sn2yCoytuAoNTk3keaPiWskIw6wBnqgyx5rMKekC/gi365vSVhwjCn8FQZSyD3AH3N8lUn6vByJIGtuuN4k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uMsca0I7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uMsca0I7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EF46C433C7; Wed, 13 Mar 2024 17:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710352402; bh=3PiQWLCvQqjS7LPBm90t4SOaaoJMbpAwofTbsuxbe28=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=uMsca0I7Y5RMuBVfUKrHGZhMro1DK1OYupPS0SqJZocjzX531WxM7unVMubz1gCi7 VE3U0LkhKax6nlt5SIlkVW5gh7Re/pKrT1yVJ7OUF3Sgx8NE8rm9pOlKgfpT4w95KF PwUWLRVE3hOTIZfeRQFtCp4xjTo8Gsu/NVcCW112CuFzu/CyxPxJPbZc2EPme7gVKk uAHOrktJkK4RYDS4tcb94ffbk6PWtwYLYEadrzpgRJoEvXa4EXvo+xBbklW/AUNAli aIDnlzoQediGjsRlZEuNmTUEsNKAyMYllKsSRDtwgeHgglQjXlAe0UASihxI7Qh4fW In+djyAQfJinw== Date: Wed, 13 Mar 2024 10:53:21 -0700 Subject: [PATCH 03/29] xfs: define parent pointer ondisk extended attribute format From: "Darrick J. Wong" To: djwong@kernel.org, aalbersh@redhat.com, ebiggers@kernel.org Cc: Dave Chinner , Allison Henderson , linux-fsdevel@vger.kernel.org, fsverity@lists.linux.dev, linux-xfs@vger.kernel.org Message-ID: <171035223408.2613863.9861308344244312301.stgit@frogsfrogsfrogs> In-Reply-To: <171035223299.2613863.12196197862413309469.stgit@frogsfrogsfrogs> References: <171035223299.2613863.12196197862413309469.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 namehash} value={dirent name} 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. Storing the dirent name hash in the key reduces hash collisions if a file is hardlinked multiple times in the same directory. By using the NVLOOKUP mode in the extended attribute code to match parent pointers using both the xattr name and value, we can identify the exact parent pointer EA we need to modify/remove in rename/unlink operations without searching the entire EA space. By storing the dirent name, we have enough information to be able to validate and reconstruct damaged directory trees. Earlier iterations of this patchset encoded the directory offset in the parent pointer key, but this format required repair to keep that in sync across directory rebuilds, which is unnecessary complexity. Signed-off-by: Dave Chinner Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong [djwong: replace diroffset with the namehash in the pptr key] Signed-off-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_da_format.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h index 5434d4d5b551..67e8c33c4e82 100644 --- a/fs/xfs/libxfs/xfs_da_format.h +++ b/fs/xfs/libxfs/xfs_da_format.h @@ -878,4 +878,24 @@ 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 + * + * The xattr name encodes the parent inode number, generation and the crc32c + * hash of the dirent name. + * + * The xattr value contains the dirent name. + */ +struct xfs_parent_name_rec { + __be64 p_ino; + __be32 p_gen; + __be32 p_namehash; +}; + +/* + * Maximum size of the dirent name that can be stored in a parent pointer. + * This matches the maximum dirent name length. + */ +#define XFS_PARENT_DIRENT_NAME_MAX_SIZE (MAXNAMELEN - 1) + #endif /* __XFS_DA_FORMAT_H__ */