]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: iget for metadata inodes
authorDarrick J. Wong <djwong@kernel.org>
Wed, 29 May 2024 04:10:54 +0000 (21:10 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:13:16 +0000 (17:13 -0700)
Create a xfs_imeta_iget function for metadata inodes to ensure that when
we try to iget a metadata file, the inobt thinks a metadata inode is in
use and that the file type matches what we are expecting.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
include/libxfs.h
include/xfs_inode.h
libxfs/Makefile
libxfs/inode.c
libxfs/libxfs_api_defs.h
libxfs/xfs_metafile.h [new file with mode: 0644]

index c49f229357f29da85af5da3264f7e9c54768acc2..1e55d42d5c6e31e9418318cf5dd68dca69d8052d 100644 (file)
@@ -93,6 +93,7 @@ struct iomap;
 #include "xfs_btree_mem.h"
 #include "xfs_parent.h"
 #include "xfs_ag_resv.h"
+#include "xfs_metafile.h"
 
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
index 4fe2826f9bdfcb89c1542c0e885a2e40404ef2ae..27c050357c544a8848a82dbab1f843afc0e60379 100644 (file)
@@ -210,6 +210,11 @@ static inline struct timespec64 inode_set_ctime_current(struct inode *inode)
        return now;
 }
 
+static inline bool inode_wrong_type(const struct inode *inode, umode_t mode)
+{
+       return (inode->i_mode ^ mode) & S_IFMT;
+}
+
 typedef struct xfs_inode {
        struct cache_node       i_node;
        struct xfs_mount        *i_mount;       /* fs mount struct ptr */
index 1f713d5551379334c50c5200be5fbed931a39735..39809c4987afeb3084555a661cb7cf325b2239c9 100644 (file)
@@ -54,6 +54,7 @@ HFILES = \
        xfs_inode_buf.h \
        xfs_inode_fork.h \
        xfs_inode_util.h \
+       xfs_metafile.h \
        xfs_parent.h \
        xfs_quota_defs.h \
        xfs_refcount.h \
index 9230ad24a5cb6c00a7773b8c53f10ad9527e827b..35fc2632e1042544599896c6218290349189901a 100644 (file)
@@ -205,6 +205,36 @@ out_destroy:
        return error;
 }
 
+/*
+ * Get a metadata inode.  The file type part of @mode must match the inode
+ * exactly.  Caller must supply a transaction (even if empty) to avoid
+ * livelocking if the inobt has a cycle.
+ */
+int
+libxfs_metafile_iget(
+       struct xfs_trans        *tp,
+       xfs_ino_t               ino,
+       umode_t                 mode,
+       struct xfs_inode        **ipp)
+{
+       struct xfs_mount        *mp = tp->t_mountp;
+       struct xfs_inode        *ip;
+       int                     error;
+
+       error = libxfs_iget(mp, tp, ino, XFS_IGET_UNTRUSTED, &ip);
+       if (error)
+               return error;
+
+       if (inode_wrong_type(VFS_I(ip), mode))
+               goto bad_rele;
+
+       *ipp = ip;
+       return 0;
+bad_rele:
+       libxfs_irele(ip);
+       return -EFSCORRUPTED;
+}
+
 static void
 libxfs_idestroy(
        struct xfs_inode        *ip)
index 48fed384a527422210a00cb40c166a2dc754198e..f70fa86bda7eae5fbe36ee30c82acfda84734162 100644 (file)
 #define xfs_iext_next                  libxfs_iext_next
 #define xfs_ifork_zap_attr             libxfs_ifork_zap_attr
 #define xfs_imap_to_bp                 libxfs_imap_to_bp
+
 #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_log_calc_minimum_size      libxfs_log_calc_minimum_size
 #define xfs_log_get_max_trans_res      libxfs_log_get_max_trans_res
 #define xfs_log_sb                     libxfs_log_sb
+
+#define xfs_metafile_iget              libxfs_metafile_iget
 #define xfs_mode_to_ftype              libxfs_mode_to_ftype
 #define xfs_mkdir_space_res            libxfs_mkdir_space_res
+
 #define xfs_parent_addname             libxfs_parent_addname
 #define xfs_parent_finish              libxfs_parent_finish
 #define xfs_parent_hashval             libxfs_parent_hashval
diff --git a/libxfs/xfs_metafile.h b/libxfs/xfs_metafile.h
new file mode 100644 (file)
index 0000000..ea0ba76
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2018-2024 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <djwong@kernel.org>
+ */
+#ifndef __XFS_METAFILE_H__
+#define __XFS_METAFILE_H__
+
+/* Code specific to kernel/userspace; must be provided externally. */
+
+int xfs_metafile_iget(struct xfs_trans *tp, xfs_ino_t ino, umode_t mode,
+               struct xfs_inode **ipp);
+
+#endif /* __XFS_METAFILE_H__ */