summaryrefslogtreecommitdiff
path: root/fs/xfs
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 11:11:01 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-12-15 17:29:06 -0800
commit87a4d240821a54628701df1e4a6a86113b586be6 (patch)
tree9911fb20452ce94a5d2ee0731d4fae0365d092f5 /fs/xfs
parent3bb48abd08490f924bea58c49dd8327a5e2b5325 (diff)
xfs: iget for metadata inodes
Create a xfs_iget_meta function for metadata inodes to ensure that we always check that the inobt thinks a metadata inode is in use. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/libxfs/xfs_imeta.h5
-rw-r--r--fs/xfs/xfs_icache.c36
-rw-r--r--fs/xfs/xfs_inode.c7
-rw-r--r--fs/xfs/xfs_qm.c33
-rw-r--r--fs/xfs/xfs_qm_syscalls.c4
-rw-r--r--fs/xfs/xfs_rtalloc.c14
6 files changed, 77 insertions, 22 deletions
diff --git a/fs/xfs/libxfs/xfs_imeta.h b/fs/xfs/libxfs/xfs_imeta.h
index 78e3060d2126..36788fe65d6d 100644
--- a/fs/xfs/libxfs/xfs_imeta.h
+++ b/fs/xfs/libxfs/xfs_imeta.h
@@ -45,4 +45,9 @@ int xfs_imeta_mount(struct xfs_mount *mp);
unsigned int xfs_imeta_create_space_res(struct xfs_mount *mp);
unsigned int xfs_imeta_unlink_space_res(struct xfs_mount *mp);
+/* Must be implemented by the libxfs client */
+int xfs_imeta_iget(struct xfs_mount *mp, xfs_ino_t ino, unsigned char ftype,
+ struct xfs_inode **ipp);
+void xfs_imeta_irele(struct xfs_inode *ip);
+
#endif /* __XFS_IMETA_H__ */
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 4169b54a65b9..5c93b9f391b7 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -24,6 +24,9 @@
#include "xfs_ialloc.h"
#include "xfs_ag.h"
#include "xfs_health.h"
+#include "xfs_da_format.h"
+#include "xfs_dir2.h"
+#include "xfs_imeta.h"
#include <linux/iversion.h>
@@ -893,6 +896,39 @@ out_pag:
return error;
}
+/* Get a metadata inode. The ftype must match exactly. */
+int
+xfs_imeta_iget(
+ struct xfs_mount *mp,
+ xfs_ino_t ino,
+ unsigned char ftype,
+ struct xfs_inode **ipp)
+{
+ struct xfs_inode *ip;
+ int error;
+
+ ASSERT(ftype != XFS_DIR3_FT_UNKNOWN);
+
+ error = xfs_iget(mp, NULL, ino, XFS_IGET_UNTRUSTED, 0, &ip);
+ if (error == -EFSCORRUPTED)
+ goto whine;
+ if (error)
+ return error;
+
+ if (VFS_I(ip)->i_nlink == 0)
+ goto bad_rele;
+ if (xfs_mode_to_ftype(VFS_I(ip)->i_mode) != ftype)
+ goto bad_rele;
+
+ *ipp = ip;
+ return 0;
+bad_rele:
+ xfs_irele(ip);
+whine:
+ xfs_err(mp, "metadata inode 0x%llx is corrupt", ino);
+ return -EFSCORRUPTED;
+}
+
/*
* Grab the inode for reclaim exclusively.
*
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index d02cc7ee07dd..6c2efa979b56 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -2647,6 +2647,13 @@ xfs_irele(
iput(VFS_I(ip));
}
+void
+xfs_imeta_irele(
+ struct xfs_inode *ip)
+{
+ xfs_irele(ip);
+}
+
/*
* Ensure all commited transactions touching the inode are written to the log.
*/
diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
index cf371199f366..41c70ec13fd5 100644
--- a/fs/xfs/xfs_qm.c
+++ b/fs/xfs/xfs_qm.c
@@ -27,6 +27,7 @@
#include "xfs_ialloc.h"
#include "xfs_health.h"
#include "xfs_imeta.h"
+#include "xfs_da_format.h"
/*
* The global quota manager. There is only one of these for the entire
@@ -232,15 +233,15 @@ xfs_qm_unmount_quotas(
*/
if (mp->m_quotainfo) {
if (mp->m_quotainfo->qi_uquotaip) {
- xfs_irele(mp->m_quotainfo->qi_uquotaip);
+ xfs_imeta_irele(mp->m_quotainfo->qi_uquotaip);
mp->m_quotainfo->qi_uquotaip = NULL;
}
if (mp->m_quotainfo->qi_gquotaip) {
- xfs_irele(mp->m_quotainfo->qi_gquotaip);
+ xfs_imeta_irele(mp->m_quotainfo->qi_gquotaip);
mp->m_quotainfo->qi_gquotaip = NULL;
}
if (mp->m_quotainfo->qi_pquotaip) {
- xfs_irele(mp->m_quotainfo->qi_pquotaip);
+ xfs_imeta_irele(mp->m_quotainfo->qi_pquotaip);
mp->m_quotainfo->qi_pquotaip = NULL;
}
}
@@ -791,7 +792,7 @@ xfs_qm_qino_switch(
if (ino == NULLFSINO)
return 0;
- error = xfs_iget(mp, NULL, ino, 0, 0, ipp);
+ error = xfs_imeta_iget(mp, ino, XFS_DIR3_FT_REG_FILE, ipp);
if (error)
return error;
@@ -1551,24 +1552,24 @@ xfs_qm_init_quotainos(
if (XFS_IS_UQUOTA_ON(mp) &&
mp->m_sb.sb_uquotino != NULLFSINO) {
ASSERT(mp->m_sb.sb_uquotino > 0);
- error = xfs_iget(mp, NULL, mp->m_sb.sb_uquotino,
- 0, 0, &uip);
+ error = xfs_imeta_iget(mp, mp->m_sb.sb_uquotino,
+ XFS_DIR3_FT_REG_FILE, &uip);
if (error)
return error;
}
if (XFS_IS_GQUOTA_ON(mp) &&
mp->m_sb.sb_gquotino != NULLFSINO) {
ASSERT(mp->m_sb.sb_gquotino > 0);
- error = xfs_iget(mp, NULL, mp->m_sb.sb_gquotino,
- 0, 0, &gip);
+ error = xfs_imeta_iget(mp, mp->m_sb.sb_gquotino,
+ XFS_DIR3_FT_REG_FILE, &gip);
if (error)
goto error_rele;
}
if (XFS_IS_PQUOTA_ON(mp) &&
mp->m_sb.sb_pquotino != NULLFSINO) {
ASSERT(mp->m_sb.sb_pquotino > 0);
- error = xfs_iget(mp, NULL, mp->m_sb.sb_pquotino,
- 0, 0, &pip);
+ error = xfs_imeta_iget(mp, mp->m_sb.sb_pquotino,
+ XFS_DIR3_FT_REG_FILE, &pip);
if (error)
goto error_rele;
}
@@ -1613,11 +1614,11 @@ xfs_qm_init_quotainos(
error_rele:
if (uip)
- xfs_irele(uip);
+ xfs_imeta_irele(uip);
if (gip)
- xfs_irele(gip);
+ xfs_imeta_irele(gip);
if (pip)
- xfs_irele(pip);
+ xfs_imeta_irele(pip);
return error;
}
@@ -1626,15 +1627,15 @@ xfs_qm_destroy_quotainos(
struct xfs_quotainfo *qi)
{
if (qi->qi_uquotaip) {
- xfs_irele(qi->qi_uquotaip);
+ xfs_imeta_irele(qi->qi_uquotaip);
qi->qi_uquotaip = NULL; /* paranoia */
}
if (qi->qi_gquotaip) {
- xfs_irele(qi->qi_gquotaip);
+ xfs_imeta_irele(qi->qi_gquotaip);
qi->qi_gquotaip = NULL;
}
if (qi->qi_pquotaip) {
- xfs_irele(qi->qi_pquotaip);
+ xfs_imeta_irele(qi->qi_pquotaip);
qi->qi_pquotaip = NULL;
}
}
diff --git a/fs/xfs/xfs_qm_syscalls.c b/fs/xfs/xfs_qm_syscalls.c
index 7d5a31827681..e59698e60edd 100644
--- a/fs/xfs/xfs_qm_syscalls.c
+++ b/fs/xfs/xfs_qm_syscalls.c
@@ -18,6 +18,8 @@
#include "xfs_quota.h"
#include "xfs_qm.h"
#include "xfs_icache.h"
+#include "xfs_imeta.h"
+#include "xfs_da_format.h"
int
xfs_qm_scall_quotaoff(
@@ -62,7 +64,7 @@ xfs_qm_scall_trunc_qfile(
if (ino == NULLFSINO)
return 0;
- error = xfs_iget(mp, NULL, ino, 0, 0, &ip);
+ error = xfs_imeta_iget(mp, ino, XFS_DIR3_FT_REG_FILE, &ip);
if (error)
return error;
diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 2c46552895ec..36b3655e5ec9 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -21,6 +21,8 @@
#include "xfs_sb.h"
#include "xfs_health.h"
#include "xfs_trace.h"
+#include "xfs_da_format.h"
+#include "xfs_imeta.h"
/*
* Read and return the summary information for a given extent size,
@@ -1298,18 +1300,20 @@ xfs_rtmount_inodes(
xfs_sb_t *sbp;
sbp = &mp->m_sb;
- error = xfs_iget(mp, NULL, sbp->sb_rbmino, 0, 0, &mp->m_rbmip);
+ error = xfs_imeta_iget(mp, mp->m_sb.sb_rbmino, XFS_DIR3_FT_REG_FILE,
+ &mp->m_rbmip);
if (xfs_metadata_is_sick(error))
xfs_rt_mark_sick(mp, XFS_SICK_RT_BITMAP);
if (error)
return error;
ASSERT(mp->m_rbmip != NULL);
- error = xfs_iget(mp, NULL, sbp->sb_rsumino, 0, 0, &mp->m_rsumip);
+ error = xfs_imeta_iget(mp, mp->m_sb.sb_rsumino, XFS_DIR3_FT_REG_FILE,
+ &mp->m_rsumip);
if (xfs_metadata_is_sick(error))
xfs_rt_mark_sick(mp, XFS_SICK_RT_SUMMARY);
if (error) {
- xfs_irele(mp->m_rbmip);
+ xfs_imeta_irele(mp->m_rbmip);
return error;
}
ASSERT(mp->m_rsumip != NULL);
@@ -1323,9 +1327,9 @@ xfs_rtunmount_inodes(
{
kmem_free(mp->m_rsum_cache);
if (mp->m_rbmip)
- xfs_irele(mp->m_rbmip);
+ xfs_imeta_irele(mp->m_rbmip);
if (mp->m_rsumip)
- xfs_irele(mp->m_rsumip);
+ xfs_imeta_irele(mp->m_rsumip);
}
/*