diff options
author | Darrick J. Wong <djwong@kernel.org> | 2024-04-22 09:47:46 -0700 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2024-04-23 07:46:58 -0700 |
commit | fb102fe7fe02e70f8a49cc7f74bc0769cdab2912 (patch) | |
tree | 0e47e492d4525dc31e018c8fdfc8578f8105c099 /fs/xfs/libxfs/xfs_parent.c | |
parent | 7dba4a5fe1c5cdf0859830380c52f29295cbf345 (diff) | |
download | linux-stable-fb102fe7fe02e70f8a49cc7f74bc0769cdab2912.tar.gz linux-stable-fb102fe7fe02e70f8a49cc7f74bc0769cdab2912.tar.bz2 linux-stable-fb102fe7fe02e70f8a49cc7f74bc0769cdab2912.zip |
xfs: create a hashname function for parent pointers
Although directory entry and parent pointer recordsets look very similar
(name -> ino), there's one major difference between them: a file can be
hardlinked from multiple parent directories with the same filename.
This is common in shared container environments where a base directory
tree might be hardlink-copied multiple times. IOWs the same 'ls'
program might be hardlinked to multiple /srv/*/bin/ls paths.
We don't want parent pointer operations to bog down on hash collisions
between the same dirent name, so create a special hash function that
mixes in the parent directory inode number.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/libxfs/xfs_parent.c')
-rw-r--r-- | fs/xfs/libxfs/xfs_parent.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_parent.c b/fs/xfs/libxfs/xfs_parent.c index 5961fa8c8561..d564baf2549c 100644 --- a/fs/xfs/libxfs/xfs_parent.c +++ b/fs/xfs/libxfs/xfs_parent.c @@ -90,3 +90,50 @@ xfs_parent_valuecheck( return true; } + +/* Compute the attribute name hash for a parent pointer. */ +xfs_dahash_t +xfs_parent_hashval( + struct xfs_mount *mp, + const uint8_t *name, + int namelen, + xfs_ino_t parent_ino) +{ + struct xfs_name xname = { + .name = name, + .len = namelen, + }; + + /* + * Use the same dirent name hash as would be used on the directory, but + * mix in the parent inode number to avoid collisions on hardlinked + * files with identical names but different parents. + */ + return xfs_dir2_hashname(mp, &xname) ^ + upper_32_bits(parent_ino) ^ lower_32_bits(parent_ino); +} + +/* Compute the attribute name hash from the xattr components. */ +xfs_dahash_t +xfs_parent_hashattr( + struct xfs_mount *mp, + const uint8_t *name, + int namelen, + const void *value, + int valuelen) +{ + const struct xfs_parent_rec *rec = value; + + /* Requires a local attr value in xfs_parent_rec format */ + if (valuelen != sizeof(struct xfs_parent_rec)) { + ASSERT(valuelen == sizeof(struct xfs_parent_rec)); + return 0; + } + + if (!value) { + ASSERT(value != NULL); + return 0; + } + + return xfs_parent_hashval(mp, name, namelen, be64_to_cpu(rec->p_ino)); +} |