From e4bad0781704e8a3bfe22a37a3ed0b929b9da248 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 3 Jul 2024 14:21:45 -0700 Subject: [PATCH] xfs_repair: allow sysadmins to add reflink Allow the sysadmin to use xfs_repair to upgrade an existing filesystem to support the reference count btree, and therefore reflink. Signed-off-by: Darrick J. Wong --- man/man8/xfs_admin.8 | 6 ++++++ repair/globals.c | 1 + repair/globals.h | 1 + repair/phase2.c | 33 ++++++++++++++++++++++++++++++++- repair/rmap.c | 4 ++-- repair/xfs_repair.c | 11 +++++++++++ 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/man/man8/xfs_admin.8 b/man/man8/xfs_admin.8 index e07fc3ddb..3a9175c9f 100644 --- a/man/man8/xfs_admin.8 +++ b/man/man8/xfs_admin.8 @@ -170,6 +170,12 @@ allocation on old filesystems. This upgrade can fail if any AG has less than 1% free space remaining. The filesystem cannot be downgraded after this feature is enabled. This feature was added to Linux 3.16. +.TP 0.4i +.B reflink +Enable sharing of file data blocks. +This upgrade can fail if any AG has less than 2% free space remaining. +The filesystem cannot be downgraded after this feature is enabled. +This feature was added to Linux 4.9. .RE .TP .BI \-U " uuid" diff --git a/repair/globals.c b/repair/globals.c index 3ea5fd881..07a15ddfc 100644 --- a/repair/globals.c +++ b/repair/globals.c @@ -54,6 +54,7 @@ bool add_bigtime; /* add support for timestamps up to 2486 */ bool add_nrext64; bool add_exchrange; /* add file content exchange support */ bool add_finobt; /* add free inode btrees */ +bool add_reflink; /* add reference count btrees */ /* misc status variables */ diff --git a/repair/globals.h b/repair/globals.h index 9f9ecb261..c5114b54b 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -95,6 +95,7 @@ extern bool add_bigtime; /* add support for timestamps up to 2486 */ extern bool add_nrext64; extern bool add_exchrange; /* add file content exchange support */ extern bool add_finobt; /* add free inode btrees */ +extern bool add_reflink; /* add reference count btrees */ /* misc status variables */ diff --git a/repair/phase2.c b/repair/phase2.c index 9dc10db78..ccd737a6d 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -198,7 +198,7 @@ set_exchrange( exit(0); } - if (!xfs_has_reflink(mp)) { + if (!xfs_has_reflink(mp) && !add_reflink) { printf( _("File exchange-range feature cannot be added without reflink.\n")); exit(0); @@ -232,6 +232,33 @@ set_finobt( return true; } +static bool +set_reflink( + struct xfs_mount *mp, + struct xfs_sb *new_sb) +{ + if (xfs_has_reflink(mp)) { + printf(_("Filesystem already supports reflink.\n")); + exit(0); + } + + if (!xfs_has_crc(mp)) { + printf( + _("Reflink feature only supported on V5 filesystems.\n")); + exit(0); + } + + if (xfs_has_realtime(mp)) { + printf(_("Reflink feature not supported with realtime.\n")); + exit(0); + } + + printf(_("Adding reflink support to filesystem.\n")); + new_sb->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_REFLINK; + new_sb->sb_features_incompat |= XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR; + return true; +} + struct check_state { struct xfs_sb sb; uint64_t features; @@ -401,6 +428,8 @@ need_check_fs_free_space( { if (xfs_has_finobt(mp) && !(old->features & XFS_FEAT_FINOBT)) return true; + if (xfs_has_reflink(mp) && !(old->features & XFS_FEAT_REFLINK)) + return true; return false; } @@ -480,6 +509,8 @@ upgrade_filesystem( dirty |= set_exchrange(mp, &new_sb); if (add_finobt) dirty |= set_finobt(mp, &new_sb); + if (add_reflink) + dirty |= set_reflink(mp, &new_sb); if (!dirty) return; diff --git a/repair/rmap.c b/repair/rmap.c index 553c7a6c3..97591e1b1 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -58,7 +58,7 @@ bool rmap_needs_work( struct xfs_mount *mp) { - return xfs_has_reflink(mp) || + return xfs_has_reflink(mp) || add_reflink || xfs_has_rmapbt(mp); } @@ -1515,7 +1515,7 @@ check_refcounts( int i; int error; - if (!xfs_has_reflink(mp)) + if (!xfs_has_reflink(mp) || add_reflink) return; if (refcbt_suspect) { if (no_modify && agno == 0) diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 3755e3e7f..22142674e 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -71,6 +71,7 @@ enum c_opt_nums { CONVERT_NREXT64, CONVERT_EXCHRANGE, CONVERT_FINOBT, + CONVERT_REFLINK, C_MAX_OPTS, }; @@ -81,6 +82,7 @@ static char *c_opts[] = { [CONVERT_NREXT64] = "nrext64", [CONVERT_EXCHRANGE] = "exchange", [CONVERT_FINOBT] = "finobt", + [CONVERT_REFLINK] = "reflink", [C_MAX_OPTS] = NULL, }; @@ -382,6 +384,15 @@ process_args(int argc, char **argv) _("-c finobt only supports upgrades\n")); add_finobt = true; break; + case CONVERT_REFLINK: + if (!val) + do_abort( + _("-c reflink requires a parameter\n")); + if (strtol(val, NULL, 0) != 1) + do_abort( + _("-c reflink only supports upgrades\n")); + add_reflink = true; + break; default: unknown('c', val); break; -- 2.50.1