add_command(&inode_cmd);
}
-struct rtgroup_inodes {
- xfs_ino_t rmap_ino;
- xfs_ino_t refcount_ino;
-};
-
-static struct rtgroup_inodes *rtgroup_inodes;
-static struct bitmap *rmap_inodes;
-static struct bitmap *refcount_inodes;
+/* Per-type bitmaps of rt group inodes */
+static struct bitmap *rtg_inodes[XFS_RTG_MAX];
static inline int
-set_rtgroup_rmap_inode(
+set_rtginode(
struct xfs_trans *tp,
- struct xfs_inode *dp,
- xfs_rgnumber_t rgno)
+ struct xfs_rtgroup *rtg,
+ enum xfs_rtg_inodes type)
{
- const char *path;
- xfs_ino_t rtino;
+ struct xfs_inode *ip;
int error;
- if (!xfs_has_rtrmapbt(dp->i_mount))
- return 0;
-
- path = xfs_rtginode_path(rgno, XFS_RTG_RMAP);
- if (!path)
- return ENOMEM;
-
-
- error = -libxfs_imeta_lookup(tp, dp, path, &rtino);
- if (error == -ENOENT) {
- rtino = NULLFSINO;
- error = 0;
- }
- if (error)
- goto out_path;
-
- if (!libxfs_verify_ino(dp->i_mount, rtino)) {
- error = EFSCORRUPTED;
- goto out_path;
- }
-
- error = bitmap_set(rmap_inodes, rtino, 1);
+ error = -xfs_rtginode_load(rtg, type, tp);
if (error)
- goto out_path;
-
- rtgroup_inodes[rgno].rmap_ino = rtino;
-
-out_path:
- kfree(path);
- return error;
-}
-
-static inline int
-set_rtgroup_refcount_inode(
- struct xfs_trans *tp,
- struct xfs_inode *dp,
- xfs_rgnumber_t rgno)
-{
- const char *path;
- xfs_ino_t rtino;
- int error;
+ return error;
- if (!xfs_has_rtreflink(dp->i_mount))
+ ip = rtg->rtg_inodes[type];
+ if (!ip) /* inode type not enabled */
return 0;
- path = xfs_rtginode_path(rgno, XFS_RTG_REFCOUNT);
- if (!path)
- return ENOMEM;
-
- error = -libxfs_imeta_lookup(tp, dp, path, &rtino);
- if (error == -ENOENT) {
- rtino = NULLFSINO;
- error = 0;
- }
- if (error)
- goto out_path;
-
- if (!libxfs_verify_ino(dp->i_mount, rtino)) {
- error = EFSCORRUPTED;
- goto out_path;
- }
-
- error = bitmap_set(refcount_inodes, rtino, 1);
- if (error)
- goto out_path;
-
- rtgroup_inodes[rgno].refcount_ino = rtino;
-
-out_path:
- kfree(path);
- return error;
+ if (bitmap_test(rtg_inodes[type], ip->i_ino, 1))
+ return EFSCORRUPTED;
+ return bitmap_set(rtg_inodes[type], ip->i_ino, 1);
}
int
struct xfs_mount *mp)
{
struct xfs_trans *tp;
- struct xfs_inode *dp;
+ struct xfs_rtgroup *rtg;
xfs_rgnumber_t rgno;
- int error;
+ int error, err2;
+ int i;
if (!xfs_has_rtgroups(mp))
return 0;
- if (rmap_inodes)
+ if (rtg_inodes[0])
return 0;
- rtgroup_inodes = calloc(mp->m_sb.sb_rgcount,
- sizeof(struct rtgroup_inodes));
- if (!rtgroup_inodes)
- return ENOMEM;
-
- error = bitmap_alloc(&rmap_inodes);
- if (error)
- return error;
-
- error = bitmap_alloc(&refcount_inodes);
- if (error)
- return error;
+ for (i = 0; i < XFS_RTG_MAX; i++) {
+ error = bitmap_alloc(&rtg_inodes[i]);
+ if (error)
+ return error;
+ }
error = -libxfs_trans_alloc_empty(mp, &tp);
if (error)
return error;
error = -libxfs_imeta_load(tp, mp->m_metadirip, "realtime", S_IFDIR,
- &dp);
+ &mp->m_rtdirip);
if (error)
- return error;
+ goto out_cancel;
- for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) {
- int err2 = set_rtgroup_rmap_inode(tp, dp, rgno);
- if (err2 && !error)
- error = err2;
- err2 = set_rtgroup_refcount_inode(tp, dp, rgno);
- if (err2 && !error)
- error = err2;
+ for_each_rtgroup(mp, rgno, rtg) {
+ for (i = 0; i < XFS_RTG_MAX; i++) {
+ err2 = set_rtginode(tp, rtg, i);
+ if (err2 && !error)
+ error = err2;
+ }
}
+out_cancel:
libxfs_trans_cancel(tp);
- xfs_irele(dp);
return error;
}
-bool is_rtrmap_inode(xfs_ino_t ino)
+xfs_rgnumber_t
+rtgroup_for_rtginode(
+ struct xfs_mount *mp,
+ xfs_ino_t ino,
+ enum xfs_rtg_inodes type)
{
- if (!rmap_inodes)
- return false;
- return bitmap_test(rmap_inodes, ino, 1);
-}
+ struct xfs_rtgroup *rtg;
+ xfs_rgnumber_t rgno;
-xfs_rgnumber_t rtgroup_for_rtrmap_ino(struct xfs_mount *mp, xfs_ino_t ino)
-{
- unsigned int i;
+ if (!rtg_inodes[type])
+ return NULLRGNUMBER;
- for (i = 0; i < mp->m_sb.sb_rgcount; i++) {
- if (rtgroup_inodes[i].rmap_ino == ino)
- return i;
+ for_each_rtgroup(mp, rgno, rtg) {
+ if (rtg->rtg_inodes[type] &&
+ rtg->rtg_inodes[type]->i_ino == ino)
+ return rgno;
}
return NULLRGNUMBER;
}
-bool is_rtrefcount_inode(xfs_ino_t ino)
+bool
+is_rtgroup_inode(
+ xfs_ino_t ino,
+ enum xfs_rtg_inodes type)
{
- if (!refcount_inodes)
+ if (!rtg_inodes[type])
return false;
- return bitmap_test(refcount_inodes, ino, 1);
-}
-
-xfs_rgnumber_t rtgroup_for_rtrefcount_ino(struct xfs_mount *mp, xfs_ino_t ino)
-{
- unsigned int i;
-
- for (i = 0; i < mp->m_sb.sb_rgcount; i++) {
- if (rtgroup_inodes[i].refcount_ino == ino)
- return i;
- }
-
- return NULLRGNUMBER;
+ return bitmap_test(rtg_inodes[type], ino, 1);
}
typnm_t
extern void set_cur_inode(xfs_ino_t ino);
int init_rtmeta_inode_bitmaps(struct xfs_mount *mp);
-bool is_rtrmap_inode(xfs_ino_t ino);
-xfs_rgnumber_t rtgroup_for_rtrmap_ino(struct xfs_mount *mp, xfs_ino_t ino);
-bool is_rtrefcount_inode(xfs_ino_t ino);
-xfs_rgnumber_t rtgroup_for_rtrefcount_ino(struct xfs_mount *mp, xfs_ino_t ino);
+
+xfs_rgnumber_t rtgroup_for_rtginode(struct xfs_mount *mp, xfs_ino_t ino,
+ enum xfs_rtg_inodes type);
+static inline xfs_rgnumber_t
+rtgroup_for_rtrmap_ino(struct xfs_mount *mp, xfs_ino_t ino)
+{
+ return rtgroup_for_rtginode(mp, ino, XFS_RTG_RMAP);
+}
+static inline xfs_rgnumber_t
+rtgroup_for_rtrefcount_ino(struct xfs_mount *mp, xfs_ino_t ino)
+{
+ return rtgroup_for_rtginode(mp, ino, XFS_RTG_REFCOUNT);
+}
+
+bool is_rtgroup_inode(xfs_ino_t ino, enum xfs_rtg_inodes type);
+static inline bool is_rtrmap_inode(xfs_ino_t ino)
+{
+ return is_rtgroup_inode(ino, XFS_RTG_RMAP);
+}
+static inline bool is_rtrefcount_inode(xfs_ino_t ino)
+{
+ return is_rtgroup_inode(ino, XFS_RTG_REFCOUNT);
+}