@@ -970,6 +970,10 @@ libxfs_rtmount_destroy(xfs_mount_t *mp)
xfs_rgnumber_t rgno;
for_each_rtgroup(mp, rgno, rtg) {
+ if (rtg->rtg_refcountip)
+ libxfs_imeta_irele(rtg->rtg_refcountip);
+ rtg->rtg_refcountip = NULL;
+
if (rtg->rtg_rmapip)
libxfs_imeta_irele(rtg->rtg_rmapip);
rtg->rtg_rmapip = NULL;
@@ -5105,9 +5105,13 @@ xfs_bmap_del_extent_real(
* the same order of operations as the data device, which is:
* Remove the file mapping, remove the reverse mapping, and
* then free the blocks. This means that we must delay the
- * freeing until after we've scheduled the rmap update.
+ * freeing until after we've scheduled the rmap update. If
+ * realtime reflink is enabled, use deferred refcount intent
+ * items to decide what to do with the extent, just like we do
+ * for the data device.
*/
- if (want_free && !xfs_has_rtrmapbt(mp)) {
+ if (want_free && !xfs_has_rtrmapbt(mp) &&
+ !xfs_has_rtreflink(mp)) {
error = xfs_rtfree_blocks(tp, del->br_startblock,
del->br_blockcount);
if (error)
@@ -1028,6 +1028,7 @@ enum xfs_dinode_fmt {
XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */
XFS_DINODE_FMT_UUID, /* added long ago, but never used */
XFS_DINODE_FMT_RMAP, /* reverse mapping btree */
+ XFS_DINODE_FMT_REFCOUNT, /* reference count btree */
};
#define XFS_INODE_FORMAT_STR \
@@ -1036,7 +1037,8 @@ enum xfs_dinode_fmt {
{ XFS_DINODE_FMT_EXTENTS, "extent" }, \
{ XFS_DINODE_FMT_BTREE, "btree" }, \
{ XFS_DINODE_FMT_UUID, "uuid" }, \
- { XFS_DINODE_FMT_RMAP, "rmap" }
+ { XFS_DINODE_FMT_RMAP, "rmap" }, \
+ { XFS_DINODE_FMT_REFCOUNT, "refcount" }
/*
* Max values for extnum and aextnum.
@@ -414,6 +414,12 @@ xfs_dinode_verify_fork(
if (!(dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADIR)))
return __this_address;
break;
+ case XFS_DINODE_FMT_REFCOUNT:
+ if (!xfs_has_rtreflink(mp))
+ return __this_address;
+ if (!(dip->di_flags2 & cpu_to_be64(XFS_DIFLAG2_METADIR)))
+ return __this_address;
+ break;
default:
return __this_address;
}
@@ -434,6 +440,7 @@ xfs_dinode_verify_forkoff(
return __this_address;
break;
case XFS_DINODE_FMT_RMAP:
+ case XFS_DINODE_FMT_REFCOUNT:
if (!(xfs_has_metadir(mp) && xfs_has_parent(mp)))
return __this_address;
fallthrough;
@@ -705,6 +712,7 @@ xfs_dinode_verify(
if (flags2 & XFS_DIFLAG2_METADIR) {
switch (XFS_DFORK_FORMAT(dip, XFS_DATA_FORK)) {
case XFS_DINODE_FMT_RMAP:
+ case XFS_DINODE_FMT_REFCOUNT:
break;
default:
if (nextents + naextents == 0 && nblocks != 0)
@@ -269,6 +269,11 @@ xfs_iformat_data_fork(
return -EFSCORRUPTED;
}
return xfs_iformat_rtrmap(ip, dip);
+ case XFS_DINODE_FMT_REFCOUNT:
+ if (!xfs_has_rtreflink(ip->i_mount))
+ return -EFSCORRUPTED;
+ ASSERT(0); /* to be implemented later */
+ return -EFSCORRUPTED;
default:
xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__,
dip, sizeof(*dip), __this_address);
@@ -664,6 +669,10 @@ xfs_iflush_fork(
xfs_iflush_rtrmap(ip, dip);
break;
+ case XFS_DINODE_FMT_REFCOUNT:
+ ASSERT(0); /* to be implemented later */
+ break;
+
default:
ASSERT(0);
break;
@@ -25,6 +25,9 @@ struct xfs_rtgroup {
/* reverse mapping btree inode */
struct xfs_inode *rtg_rmapip;
+ /* refcount btree inode */
+ struct xfs_inode *rtg_refcountip;
+
/* Number of blocks in this group */
xfs_rgblock_t rtg_blockcount;
@@ -24,6 +24,7 @@
#include "xfs_cksum.h"
#include "xfs_rtgroup.h"
#include "xfs_rtbitmap.h"
+#include "xfs_imeta.h"
static struct kmem_cache *xfs_rtrefcountbt_cur_cache;
@@ -353,6 +354,7 @@ xfs_rtrefcountbt_commit_staged_btree(
int flags = XFS_ILOG_CORE | XFS_ILOG_DBROOT;
ASSERT(cur->bc_flags & XFS_BTREE_STAGING);
+ ASSERT(ifake->if_fork->if_format == XFS_DINODE_FMT_REFCOUNT);
/*
* Free any resources hanging off the real fork, then shallow-copy the
@@ -456,3 +458,34 @@ xfs_rtrefcountbt_compute_maxlevels(
/* Add one level to handle the inode root level. */
mp->m_rtrefc_maxlevels = min(d_maxlevels, r_maxlevels) + 1;
}
+
+#define XFS_RTREFC_NAMELEN 21
+
+/* Create the metadata directory path for an rtrefcount btree inode. */
+int
+xfs_rtrefcountbt_create_path(
+ struct xfs_mount *mp,
+ xfs_rgnumber_t rgno,
+ struct xfs_imeta_path **pathp)
+{
+ struct xfs_imeta_path *path;
+ unsigned char *fname;
+ int error;
+
+ error = xfs_imeta_create_file_path(mp, 2, &path);
+ if (error)
+ return error;
+
+ fname = kmalloc(XFS_RTREFC_NAMELEN, GFP_KERNEL);
+ if (!fname) {
+ xfs_imeta_free_path(path);
+ return -ENOMEM;
+ }
+
+ snprintf(fname, XFS_RTREFC_NAMELEN, "%u.refcount", rgno);
+ path->im_path[0] = "realtime";
+ path->im_path[1] = fname;
+ path->im_dynamicmask = 0x2;
+ *pathp = path;
+ return 0;
+}
@@ -11,6 +11,7 @@ struct xfs_btree_cur;
struct xfs_mount;
struct xbtree_ifakeroot;
struct xfs_rtgroup;
+struct xfs_imeta_path;
/* refcounts only exist on crc enabled filesystems */
#define XFS_RTREFCOUNT_BLOCK_LEN XFS_BTREE_LBLOCK_CRC_LEN
@@ -68,4 +69,7 @@ unsigned int xfs_rtrefcountbt_maxlevels_ondisk(void);
int __init xfs_rtrefcountbt_init_cur_cache(void);
void xfs_rtrefcountbt_destroy_cur_cache(void);
+int xfs_rtrefcountbt_create_path(struct xfs_mount *mp, xfs_rgnumber_t rgno,
+ struct xfs_imeta_path **pathp);
+
#endif /* __XFS_RTREFCOUNT_BTREE_H__ */