]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
fixups
authorChristoph Hellwig <hch@lst.de>
Wed, 17 Jul 2024 06:31:49 +0000 (08:31 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 17 Jul 2024 06:42:26 +0000 (08:42 +0200)
db/fsmap.c
db/inode.c
include/xfs_mount.h
libxfs/libxfs_api_defs.h
mkfs/proto.c
repair/bmap_repair.c
repair/phase2.c
repair/phase6.c
repair/rmap.c

index 31bd4f87a5f8deef236e6662bfb310bb6fd47e82..0b883010dbd2a00a3b94d46e186c0ab90d7fa75b 100644 (file)
@@ -130,13 +130,12 @@ fsmap_rtgroup(
 {
        struct xfs_mount        *mp = rtg->rtg_mount;
        struct xfs_trans        *tp;
-       struct xfs_inode        *ip;
-       struct xfs_imeta_path   *path;
+       struct xfs_inode        *dp, *ip;
+       const char              *path;
        struct xfs_btree_cur    *bt_cur;
-       xfs_ino_t               ino;
        int                     error;
 
-       path = xfs_rtrmapbt_create_path(mp, rtg->rtg_rgno);
+       path = xfs_rtrmapbt_path(rtg->rtg_rgno);
        if (!path) {
                dbprintf(
  _("Cannot create path to rtgroup %u rmap inode\n"),
@@ -152,26 +151,25 @@ fsmap_rtgroup(
                goto out_path;
        }
 
-       error = -libxfs_imeta_lookup(tp, path, &ino);
-       if (ino == NULLFSINO)
-               error = ENOENT;
+       error = -libxfs_imeta_load(tp, mp->m_metadirip, "realtime", S_IFDIR,
+                       &dp);
        if (error) {
-               dbprintf(_("Cannot look up rtgroup %u rmap inode, error %d\n"),
-                               rtg->rtg_rgno, error);
+               dbprintf(_("Cannot load realtime inode, error %d\n"),
+                       error);
                goto out_trans;
        }
 
-       error = -libxfs_imeta_iget(tp, ino, S_IFREG, &ip);
+       error = -libxfs_imeta_load(tp, dp, path, S_IFREG, &ip);
        if (error) {
-               dbprintf(_("Cannot load rtgroup %u rmap inode\n"),
-                               rtg->rtg_rgno);
-               goto out_trans;
+               dbprintf(_("Cannot load rtgroup %u rmap inode, error %d\n"),
+                       rtg->rtg_rgno, error);
+               goto out_rele_dp;
        }
 
        bt_cur = libxfs_rtrmapbt_init_cursor(mp, tp, rtg, ip);
        if (!bt_cur) {
                dbprintf(_("Not enough memory.\n"));
-               goto out_rele;
+               goto out_rele_ip;
        }
 
        error = -libxfs_rmap_query_range(bt_cur, low, high, fsmap_rt_fn,
@@ -184,12 +182,14 @@ fsmap_rtgroup(
 
 out_cur:
        libxfs_btree_del_cursor(bt_cur, error);
-out_rele:
+out_rele_ip:
        libxfs_irele(ip);
+out_rele_dp:
+       libxfs_irele(dp);
 out_trans:
        libxfs_trans_cancel(tp);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
index 3d2632f75687e188da23a24c716438ee37c68704..e0cbac22e72c798de83b743f0494af733ff107cf 100644 (file)
@@ -651,87 +651,84 @@ static struct bitmap              *refcount_inodes;
 
 static inline int
 set_rtgroup_rmap_inode(
-       struct xfs_mount        *mp,
+       struct xfs_trans        *tp,
+       struct xfs_inode        *dp,
        xfs_rgnumber_t          rgno)
 {
-       struct xfs_imeta_path   *path;
-       struct xfs_trans        *tp;
+       const char              *path;
        xfs_ino_t               rtino;
        int                     error;
 
-       if (!xfs_has_rtrmapbt(mp))
+       if (!xfs_has_rtrmapbt(dp->i_mount))
                return 0;
 
-       path = xfs_rtrmapbt_create_path(mp, rgno);
+       path = xfs_rtrmapbt_path(rgno);
        if (!path)
                return ENOMEM;
 
-       error = -libxfs_trans_alloc_empty(mp, &tp);
-       if (error)
-               goto out_path;
 
-       error = -libxfs_imeta_lookup(tp, path, &rtino);
+       error = -libxfs_imeta_lookup(tp, dp, path, &rtino);
+       if (error == -ENOENT) {
+               rtino = NULLFSINO;
+               error = 0;
+       }
        if (error)
-               goto out_trans;
+               goto out_path;
 
-       if (!libxfs_verify_ino(mp, rtino)) {
+       if (!libxfs_verify_ino(dp->i_mount, rtino)) {
                error = EFSCORRUPTED;
-               goto out_trans;
+               goto out_path;
        }
 
        error = bitmap_set(rmap_inodes, rtino, 1);
        if (error)
-               goto out_trans;
+               goto out_path;
 
        rtgroup_inodes[rgno].rmap_ino = rtino;
 
-out_trans:
-       libxfs_trans_cancel(tp);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
 static inline int
 set_rtgroup_refcount_inode(
-       struct xfs_mount        *mp,
+       struct xfs_trans        *tp,
+       struct xfs_inode        *dp,
        xfs_rgnumber_t          rgno)
 {
-       struct xfs_imeta_path   *path;
-       struct xfs_trans        *tp;
+       const char              *path;
        xfs_ino_t               rtino;
        int                     error;
 
-       if (!xfs_has_rtreflink(mp))
+       if (!xfs_has_rtreflink(dp->i_mount))
                return 0;
 
-       path = xfs_rtrefcountbt_create_path(mp, rgno);
+       path = xfs_rtrefcountbt_path(rgno);
        if (!path)
                return ENOMEM;
 
-       error = -libxfs_trans_alloc_empty(mp, &tp);
+       error = -libxfs_imeta_lookup(tp, dp, path, &rtino);
+       if (error == -ENOENT) {
+               rtino = NULLFSINO;
+               error = 0;
+       }
        if (error)
                goto out_path;
 
-       error = -libxfs_imeta_lookup(tp, path, &rtino);
-       if (error)
-               goto out_trans;
-
-       if (!libxfs_verify_ino(mp, rtino)) {
+       if (!libxfs_verify_ino(dp->i_mount, rtino)) {
                error = EFSCORRUPTED;
-               goto out_trans;
+               goto out_path;
        }
 
        error = bitmap_set(refcount_inodes, rtino, 1);
        if (error)
-               goto out_trans;
+               goto out_path;
 
        rtgroup_inodes[rgno].refcount_ino = rtino;
 
-out_trans:
-       libxfs_trans_cancel(tp);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
@@ -739,9 +736,14 @@ int
 init_rtmeta_inode_bitmaps(
        struct xfs_mount        *mp)
 {
+       struct xfs_trans        *tp;
+       struct xfs_inode        *dp;
        xfs_rgnumber_t          rgno;
        int                     error;
 
+       if (!xfs_has_rtgroups(mp))
+               return 0;
+
        if (rmap_inodes)
                return 0;
 
@@ -758,20 +760,33 @@ init_rtmeta_inode_bitmaps(
        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);
+       if (error)
+               return error;
+
        for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) {
-               int err2 = set_rtgroup_rmap_inode(mp, rgno);
+               int err2 = set_rtgroup_rmap_inode(tp, dp, rgno);
                if (err2 && !error)
                        error = err2;
-               err2 = set_rtgroup_refcount_inode(mp, rgno);
+               err2 = set_rtgroup_refcount_inode(tp, dp, rgno);
                if (err2 && !error)
                        error = err2;
        }
 
+       libxfs_trans_cancel(tp);
+       xfs_irele(dp);
        return error;
 }
 
 bool is_rtrmap_inode(xfs_ino_t ino)
 {
+       if (!rmap_inodes)
+               return false;
        return bitmap_test(rmap_inodes, ino, 1);
 }
 
@@ -789,6 +804,8 @@ xfs_rgnumber_t rtgroup_for_rtrmap_ino(struct xfs_mount *mp, xfs_ino_t ino)
 
 bool is_rtrefcount_inode(xfs_ino_t ino)
 {
+       if (!refcount_inodes)
+               return false;
        return bitmap_test(refcount_inodes, ino, 1);
 }
 
index a34e4d46f229d066de6ac13be73198a37c2ac811..c2473bc9d485dbfdab8e4a413d1a05c402c2bbc3 100644 (file)
@@ -63,6 +63,7 @@ typedef struct xfs_mount {
        struct xfs_inode        *m_rbmip;       /* pointer to bitmap inode */
        struct xfs_inode        *m_rsumip;      /* pointer to summary inode */
        struct xfs_inode        *m_metadirip;   /* ptr to metadata directory */
+       struct xfs_inode        *m_rtdirip;
        struct xfs_buftarg      *m_ddev_targp;
        struct xfs_buftarg      *m_logdev_targp;
        struct xfs_buftarg      *m_rtdev_targp;
index fe03424f4bbb483036996ee021d42ebe95d03efb..fd18e3773afff22a1d513576491e031181dc9871 100644 (file)
 
 #define xfs_imeta_cancel               libxfs_imeta_cancel
 #define xfs_imeta_commit               libxfs_imeta_commit
-#define xfs_imeta_create_file_path     libxfs_imeta_create_file_path
-#define xfs_imeta_ensure_dirpath       libxfs_imeta_ensure_dirpath
-#define xfs_imeta_free_path            libxfs_imeta_free_path
 #define xfs_imeta_iget                 libxfs_imeta_iget
 #define xfs_imeta_link                 libxfs_imeta_link
 #define xfs_imeta_lookup               libxfs_imeta_lookup
+#define xfs_imeta_load                 libxfs_imeta_load
+#define xfs_imeta_mkdir                        libxfs_imeta_mkdir
 #define xfs_imeta_resv_free_inode      libxfs_imeta_resv_free_inode
 #define xfs_imeta_resv_init_inode      libxfs_imeta_resv_init_inode
 #define xfs_imeta_set_iflag            libxfs_imeta_set_iflag
index 3d048b32c2233b79b651adbc813b7b342906d227..275a3afc603ddaf584bcbcf01a70031676cbd455 100644 (file)
@@ -902,19 +902,15 @@ rtrmapbt_create(
 {
        struct xfs_imeta_update upd = { };
        struct xfs_mount        *mp = rtg->rtg_mount;
-       struct xfs_imeta_path   *path;
+       const char              *path;
        struct xfs_btree_cur    *cur;
        int                     error;
 
-       path = xfs_rtrmapbt_create_path(mp, rtg->rtg_rgno);
+       path = xfs_rtrmapbt_path(rtg->rtg_rgno);
        if (!path)
                fail( _("rtrmap inode path creation failed"), ENOMEM);
 
-       error = -libxfs_imeta_ensure_dirpath(mp, path);
-       if (error)
-               fail(_("rtgroup directory allocation failed"), error);
-
-       error = -libxfs_imeta_start_create(mp, path, &upd);
+       error = -libxfs_imeta_start_create(mp->m_rtdirip, path, &upd);
        if (error)
                res_failed(error);
 
@@ -946,7 +942,7 @@ rtrmapbt_create(
        if (error)
                fail(_("rtrmapbt commit failed"), error);
 
-       libxfs_imeta_free_path(path);
+       kfree(path);
        rtg->rtg_rmapip = upd.ip;
 }
 
@@ -957,19 +953,14 @@ rtrefcountbt_create(
 {
        struct xfs_imeta_update upd = { };
        struct xfs_mount        *mp = rtg->rtg_mount;
-       struct xfs_imeta_path   *path;
+       const char              *path;
        int                     error;
 
-       path = xfs_rtrefcountbt_create_path(mp, rtg->rtg_rgno);
+       path = xfs_rtrefcountbt_path(rtg->rtg_rgno);
        if (!path)
                fail( _("rtrefcount inode path creation failed"), ENOMEM);
 
-       error = -libxfs_imeta_ensure_dirpath(mp, path);
-       if (error)
-               fail(_("rtgroup allocation failed"),
-                               error);
-
-       error = -libxfs_imeta_start_create(mp, path, &upd);
+       error = -libxfs_imeta_start_create(mp->m_rtdirip, path, &upd);
        if (error)
                res_failed(error);
 
@@ -981,7 +972,7 @@ rtrefcountbt_create(
        if (error)
                fail(_("rtrefcountbt commit failed"), error);
 
-       libxfs_imeta_free_path(path);
+       kfree(path);
        rtg->rtg_refcountip = upd.ip;
 }
 
@@ -1142,6 +1133,15 @@ rtinit(
        rtbitmap_create(mp);
        rtsummary_create(mp);
 
+       if (xfs_has_rtgroups(mp)) {
+               int             error;
+
+               error = xfs_imeta_mkdir(mp->m_metadirip, "realtime",
+                               &mp->m_rtdirip);
+               if (error)
+                       fail(_("rtgroup directory allocation failed"), error);
+       }
+
        for_each_rtgroup(mp, rgno, rtg) {
                if (xfs_has_rtrmapbt(mp))
                        rtrmapbt_create(rtg);
index 1441542e7fa082e15fc83b977ac610ad4d938e06..240ec6d4739095154b8b3e9da589346ecca3d98c 100644 (file)
@@ -294,19 +294,18 @@ xrep_bmap_scan_rt(
        struct xfs_mount        *mp = sc->mp;
        struct xfs_btree_cur    *cur;
        struct xfs_inode        *ip;
-       struct xfs_imeta_path   *path;
-       xfs_ino_t               ino;
+       const char              *path;
        int                     error;
 
-       path = xfs_rtrmapbt_create_path(mp, rtg->rtg_rgno);
+       /* failed to load the rtdir inode? */
+       if (!mp->m_rtdirip)
+               return ENOENT;
+
+       path = xfs_rtrmapbt_path(rtg->rtg_rgno);
        if (!path)
                return ENOMEM;
 
-       error = -libxfs_imeta_lookup(sc->tp, path, &ino);
-       if (error)
-               goto out_path;
-
-       error = -libxfs_imeta_iget(sc->tp, ino, S_IFREG, &ip);
+       error = -libxfs_imeta_load(sc->tp, mp->m_rtdirip, path, S_IFREG, &ip);
        if (error)
                goto out_path;
 
@@ -318,7 +317,7 @@ out_cur:
        libxfs_btree_del_cursor(cur, error);
        libxfs_irele(ip);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
index 868da40b4c78e439053880db4763af62fe39ef2a..951b2532da2897c00765f5d81fbcc558a75340e1 100644 (file)
@@ -543,15 +543,18 @@ reserve_rtrmap_inode(
 {
        struct xfs_mount        *mp = rtg->rtg_mount;
        struct xfs_trans        *tp;
-       struct xfs_imeta_path   *path;
-       xfs_ino_t               ino;
+       const char              *path;
        xfs_filblks_t           ask;
        int                     error;
 
        if (!xfs_has_rtrmapbt(mp))
                return 0;
 
-       path = xfs_rtrmapbt_create_path(mp, rtg->rtg_rgno);
+       /* failed to load the rtdir inode? */
+       if (!mp->m_rtdirip)
+               return ENOENT;
+
+       path = xfs_rtrmapbt_path(rtg->rtg_rgno);
        if (!path)
                return ENOMEM;
 
@@ -561,26 +564,22 @@ reserve_rtrmap_inode(
 
        ask = libxfs_rtrmapbt_calc_reserves(mp);
 
-       error = -libxfs_imeta_lookup(tp, path, &ino);
-       if (error)
-               goto out_trans;
-
-       if (ino == NULLFSINO) {
-               *new_resv += ask;
-               error = 0;
+       error = -libxfs_imeta_load(tp, mp->m_rtdirip, path, S_IFREG,
+                       &rtg->rtg_rmapip);
+       if (error) {
+               if (error == -ENOENT) {
+                       *new_resv += ask;
+                       error = 0;
+               }
                goto out_trans;
        }
 
-       error = -libxfs_imeta_iget(tp, ino, S_IFREG, &rtg->rtg_rmapip);
-       if (error)
-               goto out_trans;
-
        error = -libxfs_imeta_resv_init_inode(rtg->rtg_rmapip, ask);
 
 out_trans:
        libxfs_trans_cancel(tp);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
@@ -599,16 +598,19 @@ reserve_rtrefcount_inode(
        xfs_rfsblock_t          *new_resv)
 {
        struct xfs_mount        *mp = rtg->rtg_mount;
-       struct xfs_imeta_path   *path;
+       const char              *path;
        struct xfs_trans        *tp;
-       xfs_ino_t               ino;
        xfs_filblks_t           ask;
        int                     error;
 
        if (!xfs_has_rtreflink(mp))
                return 0;
 
-       path = xfs_rtrefcountbt_create_path(mp, rtg->rtg_rgno);
+       /* failed to load the rtdir inode? */
+       if (!mp->m_rtdirip)
+               return ENOENT;
+
+       path = xfs_rtrefcountbt_path(rtg->rtg_rgno);
        if (!path)
                return ENOMEM;
 
@@ -618,26 +620,22 @@ reserve_rtrefcount_inode(
 
        ask = libxfs_rtrefcountbt_calc_reserves(mp);
 
-       error = -libxfs_imeta_lookup(tp, path, &ino);
-       if (error)
-               goto out_trans;
-
-       if (ino == NULLFSINO) {
-               *new_resv += ask;
-               error = 0;
+       error = -libxfs_imeta_load(tp, mp->m_rtdirip, path, S_IFREG,
+                       &rtg->rtg_refcountip);
+       if (error) {
+               if (error == -ENOENT) {
+                       *new_resv += ask;
+                       error = 0;
+               }
                goto out_trans;
        }
 
-       error = -libxfs_imeta_iget(tp, ino, S_IFREG, &rtg->rtg_refcountip);
-       if (error)
-               goto out_trans;
-
        error = -libxfs_imeta_resv_init_inode(rtg->rtg_refcountip, ask);
 
 out_trans:
        libxfs_trans_cancel(tp);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
index 2b5a9f4d652aaf393ab41c8c2264c7b0a794168c..1310dd840ac74351402459d7933b749ed90cd66c 100644 (file)
@@ -828,64 +828,11 @@ mark_ino_inuse(
                set_inode_isadir(irec, ino_offset);
 }
 
-/* Make sure this metadata directory path exists. */
-static int
-ensure_imeta_dirpath(
-       struct xfs_mount                *mp,
-       const struct xfs_imeta_path     *path)
-{
-       struct xfs_imeta_path           temp_path = {
-               .im_path                = path->im_path,
-               .im_ftype               = XFS_DIR3_FT_DIR,
-       };
-       struct xfs_trans                *tp;
-       xfs_ino_t                       parent;
-       int                             error;
-
-       if (!xfs_has_metadir(mp))
-               return 0;
-
-       error = -libxfs_imeta_ensure_dirpath(mp, path);
-       if (error)
-               return error;
-
-       error = -libxfs_trans_alloc_empty(mp, &tp);
-       if (error)
-               return error;
-
-       /* Mark all directories in this path as inuse. */
-       parent = mp->m_metadirip->i_ino;
-       for (temp_path.im_depth = 1;
-            temp_path.im_depth < path->im_depth;
-            temp_path.im_depth++) {
-               xfs_ino_t               ino;
-
-               error = -libxfs_imeta_lookup(tp, &temp_path, &ino);
-               if (error)
-                       break;
-               if (ino == NULLFSINO) {
-                       error = ENOENT;
-                       break;
-               }
-               if (!libxfs_verify_ino(mp, ino)) {
-                       error = EFSCORRUPTED;
-                       break;
-               }
-
-               mark_ino_inuse(mp, ino, S_IFDIR, parent);
-               mark_ino_metadata(mp, ino);
-               parent = ino;
-       }
-
-       libxfs_trans_cancel(tp);
-       return error;
-}
-
 static struct xfs_inode *
 ensure_rtgroup_file(
        struct xfs_rtgroup      *rtg,
        xfs_ino_t               ino,
-       struct xfs_imeta_path   *path,
+       const char              *path,
        const char              *name,
        int                     (*create)(struct xfs_imeta_update *upd))
 {
@@ -904,12 +851,6 @@ ensure_rtgroup_file(
                do_warn(_("resetting rtgroup %u %s inode\n"),
                        rtg->rtg_rgno, name);
 
-       error = ensure_imeta_dirpath(mp, path);
-       if (error)
-               do_error(
- _("Couldn't create rtgroup %u metadata directory, error %d\n"),
-                               rtg->rtg_rgno, error);
-
        if (ino != NULLFSINO) {
                struct xfs_trans        *tp;
 
@@ -941,7 +882,8 @@ ensure_rtgroup_file(
                 */
                try_erase_parent_ptrs(upd.ip);
 
-               error = -libxfs_imeta_start_link(mp, path, upd.ip, &upd);
+               error = -libxfs_imeta_start_link(mp->m_rtdirip, path, upd.ip,
+                               &upd);
                if (error)
                        do_error(
  _("Couldn't grab resources to reconnect rtgroup %u %s, error %d\n"),
@@ -963,7 +905,7 @@ zap:
                 * The inode was bad or gone, so just make a new one and give
                 * our reference to the rtgroup structure.
                 */
-               error = -libxfs_imeta_start_create(mp, path, &upd);
+               error = -libxfs_imeta_start_create(mp->m_rtdirip, path, &upd);
                if (error)
                        do_error(
  _("Couldn't grab resources to recreate rtgroup %u %s, error %d\n"),
@@ -995,13 +937,13 @@ ensure_rtgroup_rmapbt(
        struct xfs_rtgroup      *rtg,
        xfs_filblks_t           est_fdblocks)
 {
-       struct xfs_imeta_path   *path;
+       const char              *path;
        struct xfs_inode        *ip;
 
        if (!xfs_has_rtrmapbt(rtg->rtg_mount))
                return;
 
-       path = xfs_rtrmapbt_create_path(rtg->rtg_mount, rtg->rtg_rgno);
+       path = xfs_rtrmapbt_path(rtg->rtg_rgno);
        if (!path)
                do_error(
  _("Couldn't create rtgroup %u rmap file path\n"),
@@ -1013,7 +955,7 @@ ensure_rtgroup_rmapbt(
                populate_rtgroup_rmapbt(rtg, ip, est_fdblocks);
                libxfs_irele(ip);
        }
-       libxfs_imeta_free_path(path);
+       kfree(path);
 }
 
 static void
@@ -1021,13 +963,13 @@ ensure_rtgroup_refcountbt(
        struct xfs_rtgroup      *rtg,
        xfs_filblks_t           est_fdblocks)
 {
-       struct xfs_imeta_path   *path;
+       const char              *path;
        struct xfs_inode        *ip;
 
        if (!xfs_has_rtreflink(rtg->rtg_mount))
                return;
 
-       path = xfs_rtrefcountbt_create_path(rtg->rtg_mount, rtg->rtg_rgno);
+       path = xfs_rtrefcountbt_path(rtg->rtg_rgno);
        if (!path)
                do_error(
  _("Couldn't create rtgroup %u refcount file path\n"),
@@ -1039,7 +981,7 @@ ensure_rtgroup_refcountbt(
                populate_rtgroup_refcountbt(rtg, ip, est_fdblocks);
                libxfs_irele(ip);
        }
-       libxfs_imeta_free_path(path);
+       kfree(path);
 }
 
 /* Initialize a root directory. */
@@ -1106,6 +1048,11 @@ mk_metadir(
        struct xfs_trans        *tp;
        int                     error;
 
+       if (mp->m_rtdirip) {
+               xfs_irele(mp->m_rtdirip);
+               mp->m_rtdirip = NULL;
+       }
+
        error = init_fs_root_dir(mp, mp->m_sb.sb_metadirino, 0,
                        &mp->m_metadirip);
        if (error)
@@ -3688,6 +3635,19 @@ reset_rt_metadata_inodes(
        xfs_filblks_t           metadata_blocks = 0;
        xfs_filblks_t           est_fdblocks = 0;
        xfs_rgnumber_t          rgno;
+       int                     error;
+
+       if (!no_modify) {
+               error = -libxfs_imeta_mkdir(mp->m_metadirip, "realtime",
+                               &mp->m_rtdirip);
+               if (error)
+                       do_error(_("failed to create realtime directory (%d)\n"),
+                               error);
+       }
+
+       mark_ino_inuse(mp, mp->m_rtdirip->i_ino, S_IFDIR,
+                       mp->m_metadirip->i_ino);
+       mark_ino_metadata(mp, mp->m_rtdirip->i_ino);
 
        /*
         * Estimate how much free space will be left after building btrees
@@ -3821,7 +3781,8 @@ phase6(xfs_mount_t *mp)
                }
        }
 
-       reset_rt_metadata_inodes(mp);
+       if (xfs_has_rtgroups(mp))
+               reset_rt_metadata_inodes(mp);
 
        if (!no_modify)  {
                do_log(
index 47f08bb07f5768d8b570e6735d8e27f37a1576d6..88589f7cbe4113dd345e32cd98e969ed3392b56e 100644 (file)
@@ -218,8 +218,8 @@ set_rtgroup_rmap_inode(
        struct xfs_mount        *mp,
        xfs_rgnumber_t          rgno)
 {
-       struct xfs_imeta_path   *path;
        struct xfs_ag_rmap      *ar = rmaps_for_group(true, rgno);
+       const char              *path;
        struct xfs_trans        *tp;
        xfs_ino_t               ino;
        int                     error;
@@ -227,7 +227,7 @@ set_rtgroup_rmap_inode(
        if (!xfs_has_rtrmapbt(mp))
                return 0;
 
-       path = xfs_rtrmapbt_create_path(mp, rgno);
+       path = xfs_rtrmapbt_path(rgno);
        if (!path)
                return ENOMEM;
 
@@ -235,7 +235,11 @@ set_rtgroup_rmap_inode(
        if (error)
                goto out_path;
 
-       error = -libxfs_imeta_lookup(tp, path, &ino);
+       error = -libxfs_imeta_lookup(tp, mp->m_rtdirip, path, &ino);
+       if (error == -ENOENT) {
+               ino = NULLFSINO;
+               error = 0;
+       }
        if (error)
                goto out_trans;
 
@@ -253,7 +257,7 @@ set_rtgroup_rmap_inode(
 out_trans:
        libxfs_trans_cancel(tp);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
@@ -262,8 +266,8 @@ set_rtgroup_refcount_inode(
        struct xfs_mount        *mp,
        xfs_rgnumber_t          rgno)
 {
-       struct xfs_imeta_path   *path;
        struct xfs_ag_rmap      *ar = rmaps_for_group(true, rgno);
+       const char              *path;
        struct xfs_trans        *tp;
        xfs_ino_t               ino;
        int                     error;
@@ -271,7 +275,7 @@ set_rtgroup_refcount_inode(
        if (!xfs_has_rtreflink(mp))
                return 0;
 
-       path = xfs_rtrefcountbt_create_path(mp, rgno);
+       path = xfs_rtrefcountbt_path(rgno);
        if (!path)
                return ENOMEM;
 
@@ -279,7 +283,11 @@ set_rtgroup_refcount_inode(
        if (error)
                goto out_path;
 
-       error = -libxfs_imeta_lookup(tp, path, &ino);
+       error = -libxfs_imeta_lookup(tp, mp->m_rtdirip, path, &ino);
+       if (error == -ENOENT) {
+               ino = NULLFSINO;
+               error = 0;
+       }
        if (error)
                goto out_trans;
 
@@ -298,7 +306,7 @@ set_rtgroup_refcount_inode(
 out_trans:
        libxfs_trans_cancel(tp);
 out_path:
-       libxfs_imeta_free_path(path);
+       kfree(path);
        return error;
 }
 
@@ -306,6 +314,7 @@ static void
 discover_rtgroup_inodes(
        struct xfs_mount        *mp)
 {
+       struct xfs_trans        *tp;
        xfs_rgnumber_t          rgno;
        int                     error;
 
@@ -319,6 +328,15 @@ discover_rtgroup_inodes(
                goto out;
        }
 
+       error = -libxfs_trans_alloc_empty(mp, &tp);
+       if (error)
+               goto out;
+       error = -libxfs_imeta_load(tp, mp->m_metadirip, "realtime", S_IFDIR,
+                       &mp->m_rtdirip);
+       libxfs_trans_cancel(tp);
+       if (error)
+               goto out;
+
        for (rgno = 0; rgno < mp->m_sb.sb_rgcount; rgno++) {
                int err2 = set_rtgroup_rmap_inode(mp, rgno);
                if (err2 && !error)
@@ -399,6 +417,9 @@ rmaps_init(
        for (i = 0; i < mp->m_sb.sb_agcount; i++)
                rmaps_init_ag(mp, i, &ag_rmaps[i]);
 
+       if (!xfs_has_rtgroups(mp))
+               return;
+
        rg_rmaps = calloc(mp->m_sb.sb_rgcount, sizeof(struct xfs_ag_rmap));
        if (!rg_rmaps)
                do_error(_("couldn't allocate per-rtgroup reverse map roots\n"));
@@ -421,12 +442,14 @@ rmaps_free(
        if (!rmap_needs_work(mp))
                return;
 
-       free_rtmeta_inode_bitmaps();
+       if (xfs_has_rtgroups(mp)) {
+               free_rtmeta_inode_bitmaps();
 
-       for (i = 0; i < mp->m_sb.sb_rgcount; i++)
-               rmaps_destroy(mp, &rg_rmaps[i]);
-       free(rg_rmaps);
-       rg_rmaps = NULL;
+               for (i = 0; i < mp->m_sb.sb_rgcount; i++)
+                       rmaps_destroy(mp, &rg_rmaps[i]);
+               free(rg_rmaps);
+               rg_rmaps = NULL;
+       }
 
        for (i = 0; i < mp->m_sb.sb_agcount; i++)
                rmaps_destroy(mp, &ag_rmaps[i]);