xfs: metadata directories and realtime groups
Subsystems (4)
PATCH 36/36 xfs: use rtgroup busy extent list for FITRIM
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
For filesystems that have rtgroups and hence use the busy extent list for freed rt space, use that busy extent list so that FITRIM can issue discard commands asynchronously without worrying about other callers accidentally allocating and using space that is being discarded.
--- fs/xfs/xfs_discard.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 2 deletions(-)
fs/xfs/xfs_discard.c +144 -2
@@ -73,6 +73,8 @@* extent search so that it overlaps in flight discard IO. */ +#define XFS_DISCARD_MAX_EXAMINE (100) +struct workqueue_struct *xfs_discard_wq; static void
@@ -185,7 +187,7 @@ xfs_trim_gather_extents(struct xfs_buf *agbp;int error;int i; -int batch =100 ; +int batch =XFS_DISCARD_MAX_EXAMINE ;/* * Force out the log. This means any transactions that might have freed
@@ -565,6 +567,7 @@ xfs_trim_gather_rtextent(return 0 ; } +/* Trim extents on an !rtgroups realtime device */ static int xfs_trim_rtextents( struct xfs_rtgroup *rtg,
@@ -619,6 +622,140 @@ xfs_trim_rtextents(return error; } +struct xfs_trim_rtgroup { +/* list of rtgroup extents to free */ +struct xfs_busy_extents *extents; + +/* minimum length that caller allows us to trim */ +xfs_rtblock_t minlen_fsb; + +/* restart point for the rtbitmap walk */ +xfs_rtxnum_t restart_rtx; + +/* number of extents to examine before stopping to issue discard ios */ +int batch; + +/* number of extents queued for discard */ +int queued; +}; + +static int +xfs_trim_gather_rtgroup_extent ( +struct xfs_rtgroup *rtg, +struct xfs_trans *tp, +const struct xfs_rtalloc_rec *rec, +void *priv) +{ +struct xfs_trim_rtgroup *tr = priv; +xfs_rgblock_t rgbno; +xfs_extlen_t len; + +if (--tr->batch <=0 ) { +/* +* If we've checked a large number of extents, update the +* cursor to point at this extent so we restart the next batch +* from this extent. +*/ + tr->restart_rtx = rec->ar_startext; +return -ECANCELED ; + } + + rgbno =xfs_rtx_to_rgbno (rtg, rec->ar_startext); + len =xfs_rtxlen_to_extlen (rtg_mount (rtg), rec->ar_extcount); + +/* Ignore too small. */ +if (len < tr->minlen_fsb) { +trace_xfs_discard_toosmall (&rtg->rtg_group, rgbno, len); +return 0 ; + } + +/* +* If any blocks in the range are still busy, skip the discard and try +* again the next time. +*/ +if (xfs_extent_busy_search (&rtg->rtg_group, rgbno, len)) { +trace_xfs_discard_busy (&rtg->rtg_group, rgbno, len); +return 0 ; + } + +xfs_extent_busy_insert_discard (&rtg->rtg_group, rgbno, len, + &tr->extents->extent_list); + + tr->queued++; + tr->restart_rtx = rec->ar_startext + rec->ar_extcount; +return 0 ; +} + +/* Trim extents in this rtgroup using the busy extent machinery. */ +static int +xfs_trim_rtgroup_extents ( +struct xfs_rtgroup *rtg, +xfs_rtxnum_t low, +xfs_rtxnum_t high, +xfs_daddr_t minlen) +{ +struct xfs_mount *mp =rtg_mount (rtg); +struct xfs_trim_rtgroup tr = { + .minlen_fsb =XFS_BB_TO_FSB (mp, minlen), + }; +struct xfs_trans *tp; +int error; + + error =xfs_trans_alloc_empty (mp, &tp); +if (error) +return error; + +/* +* Walk the free ranges between low and high. The query_range function +* trims the extents returned. +*/ +do { + tr.extents =kzalloc (sizeof (*tr.extents),GFP_KERNEL ); +if (!tr.extents) { + error = -ENOMEM ; +break ; + } + + tr.queued =0 ; + tr.batch =XFS_DISCARD_MAX_EXAMINE ; + tr.extents->owner = tr.extents; +INIT_LIST_HEAD (&tr.extents->extent_list); + +xfs_rtgroup_lock (rtg,XFS_RTGLOCK_BITMAP_SHARED ); + error =xfs_rtalloc_query_range (rtg, tp, low, high, + xfs_trim_gather_rtgroup_extent, &tr); +xfs_rtgroup_unlock (rtg,XFS_RTGLOCK_BITMAP_SHARED ); +if (error == -ECANCELED ) + error =0 ; +if (error) { +kfree (tr.extents); +break ; + } + +if (!tr.queued) +break ; + +/* +* We hand the extent list to the discard function here so the +* discarded extents can be removed from the busy extent list. +* This allows the discards to run asynchronously with +* gathering the next round of extents to discard. +* +* However, we must ensure that we do not reference the extent +* list after this function call, as it may have been freed by +* the time control returns to us. +*/ + error =xfs_discard_extents (rtg_mount (rtg), tr.extents); +if (error) +break ; + + low = tr.restart_rtx; + }while (!xfs_trim_should_stop () && low <= high); + +xfs_trans_cancel (tp); +return error; +} + static int xfs_trim_rtdev_extents( struct xfs_mount *mp,
@@ -657,7 +794,12 @@ xfs_trim_rtdev_extents(if (rtg_rgno (rtg) == end_rgno) rtg_end =min (rtg_end, end_rtx); - error =xfs_trim_rtextents (rtg, start_rtx, rtg_end, minlen); +if (xfs_has_rtgroups (mp)) + error =xfs_trim_rtgroup_extents (rtg, start_rtx, + rtg_end, minlen); +else + error =xfs_trim_rtextents (rtg, start_rtx, rtg_end, + minlen);if (error) last_error = error;
Re: [PATCH 36/36] xfs: use rtgroup busy extent list for FITRIM
Looks good:
PATCH 7/9 xfs: persist quota options with metadir
In reply to Darrick J. WongHi all,
Store the quota files in the metadata directory tree instead of the superblock. Since we're introducing a new incompat feature flag, let's also make the mount process bring up quotas in whatever state they were when the filesystem was last unmounted, instead of requiring sysadmins to remember that themselves.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=metadir-quotas
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=metadir-quotas
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=metadir-quotas
---
Commits in this patchset:
* xfs: refactor xfs_qm_destroy_quotainos
* xfs: use metadir for quota inodes
* xfs: scrub quota file metapaths
* xfs: persist quota flags with metadir
--- fs/xfs/libxfs/xfs_dquot_buf.c | 190 ++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_fs.h | 6 + fs/xfs/libxfs/xfs_quota_defs.h | 43 +++++++ fs/xfs/libxfs/xfs_sb.c | 1 fs/xfs/scrub/metapath.c | 76 ++++++++++++ fs/xfs/xfs_mount.c | 15 ++ fs/xfs/xfs_mount.h | 6 + fs/xfs/xfs_qm.c | 250 +++++++++++++++++++++++++++++++--------- fs/xfs/xfs_qm_bhv.c | 18 +++ fs/xfs/xfs_quota.h | 2 fs/xfs/xfs_super.c | 22 ++++ 11 files changed, 571 insertions(+), 58 deletions(-)
PATCH 1/4 xfs: refactor xfs_qm_destroy_quotainos
From: Darrick J. Wong <[email protected]>
Reuse this function instead of open-coding the logic.
--- fs/xfs/xfs_qm.c | 53 ++++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 33 deletions(-)
fs/xfs/xfs_qm.c +20 -33
@@ -40,7 +40,6 @@ STATIC int xfs_qm_init_quotainos(struct xfs_mount *mp); STATIC int xfs_qm_init_quotainfo(struct xfs_mount *mp); -STATIC void xfs_qm_destroy_quotainos(struct xfs_quotainfo *qi); STATIC void xfs_qm_dqfree_one(struct xfs_dquot *dqp);/* * We use the batch lookup interface to iterate over the dquots as it
@@ -226,6 +225,24 @@ xfs_qm_unmount_rt(xfs_rtgroup_rele (rtg); } +STATIC void +xfs_qm_destroy_quotainos ( +struct xfs_quotainfo *qi) +{ +if (qi->qi_uquotaip) { +xfs_irele (qi->qi_uquotaip); + qi->qi_uquotaip =NULL ;/* paranoia */ + } +if (qi->qi_gquotaip) { +xfs_irele (qi->qi_gquotaip); + qi->qi_gquotaip =NULL ; + } +if (qi->qi_pquotaip) { +xfs_irele (qi->qi_pquotaip); + qi->qi_pquotaip =NULL ; + } +} +/* * Called from the vfsops layer. */
@@ -250,20 +267,8 @@ xfs_qm_unmount_quotas(/* * Release the quota inodes. */ -if (mp->m_quotainfo) { -if (mp->m_quotainfo->qi_uquotaip) { -xfs_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); - mp->m_quotainfo->qi_gquotaip =NULL ; - } -if (mp->m_quotainfo->qi_pquotaip) { -xfs_irele (mp->m_quotainfo->qi_pquotaip); - mp->m_quotainfo->qi_pquotaip =NULL ; - } - } +if (mp->m_quotainfo) +xfs_qm_destroy_quotainos (mp->m_quotainfo); }STATIC int
@@ -1712,24 +1717,6 @@ xfs_qm_init_quotainos(return error; } -STATIC void -xfs_qm_destroy_quotainos ( -struct xfs_quotainfo *qi) -{ -if (qi->qi_uquotaip) { -xfs_irele (qi->qi_uquotaip); - qi->qi_uquotaip =NULL ;/* paranoia */ - } -if (qi->qi_gquotaip) { -xfs_irele (qi->qi_gquotaip); - qi->qi_gquotaip =NULL ; - } -if (qi->qi_pquotaip) { -xfs_irele (qi->qi_pquotaip); - qi->qi_pquotaip =NULL ; - } -} - STATIC voidxfs_qm_dqfree_one (struct xfs_dquot *dqp)
PATCH 2/4 xfs: use metadir for quota inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Store the quota inodes in the /quota metadata directory if metadir is enabled. This enables us to stop using the sb_[ugp]uotino fields in the superblock. From this point on, all metadata files will be children of the metadata directory tree root.
--- fs/xfs/libxfs/xfs_dquot_buf.c | 190 +++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_quota_defs.h | 43 +++++++++ fs/xfs/libxfs/xfs_sb.c | 1 fs/xfs/xfs_qm.c | 197 +++++++++++++++++++++++++++++++++++----- 4 files changed, 407 insertions(+), 24 deletions(-)
fs/xfs/libxfs/xfs_dquot_buf.c +190 -0
@@ -16,6 +16,9 @@#include "xfs_trans.h" #include "xfs_qm.h" #include "xfs_error.h" +#include "xfs_health.h" +#include "xfs_metadir.h" +#include "xfs_metafile.h" int xfs_calc_dquots_per_chunk(
@@ -323,3 +326,190 @@ xfs_dquot_to_disk_ts(return cpu_to_be32 (t); } + +inline unsigned int +xfs_dqinode_sick_mask (xfs_dqtype_t type) +{ +switch (type) { +case XFS_DQTYPE_USER : +return XFS_SICK_FS_UQUOTA ; +case XFS_DQTYPE_GROUP : +return XFS_SICK_FS_GQUOTA ; +case XFS_DQTYPE_PROJ : +return XFS_SICK_FS_PQUOTA ; + } + +ASSERT (0 ); +return 0 ; +} + +/* +* Load the inode for a given type of quota, assuming that the sb fields have +* been sorted out. This is not true when switching quota types on a V4 +* filesystem, so do not use this function for that. If metadir is enabled, +* @dp must be the /quota metadir. +* +* Returns -ENOENT if the quota inode field is NULLFSINO; 0 and an inode on +* success; or a negative errno. +*/ +int +xfs_dqinode_load ( +struct xfs_trans *tp, +struct xfs_inode *dp, +xfs_dqtype_t type, +struct xfs_inode **ipp) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_inode *ip; +enum xfs_metafile_type metafile_type =xfs_dqinode_metafile_type (type); +int error; + +if (!xfs_has_metadir (mp)) { +xfs_ino_t ino; + +switch (type) { +case XFS_DQTYPE_USER : + ino = mp->m_sb.sb_uquotino; +break ; +case XFS_DQTYPE_GROUP : + ino = mp->m_sb.sb_gquotino; +break ; +case XFS_DQTYPE_PROJ : + ino = mp->m_sb.sb_pquotino; +break ; +default : +ASSERT (0 ); +return -EFSCORRUPTED ; + } + +/* Should have set 0 to NULLFSINO when loading superblock */ +if (ino ==NULLFSINO ) +return -ENOENT ; + + error =xfs_trans_metafile_iget (tp, ino, metafile_type, &ip); + }else { + error =xfs_metadir_load (tp, dp,xfs_dqinode_path (type), + metafile_type, &ip); +if (error == -ENOENT ) +return error; + } +if (error) { +if (xfs_metadata_is_sick (error)) +xfs_fs_mark_sick (mp,xfs_dqinode_sick_mask (type)); +return error; + } + +if (XFS_IS_CORRUPT (mp, ip->i_df.if_format !=XFS_DINODE_FMT_EXTENTS && + ip->i_df.if_format !=XFS_DINODE_FMT_BTREE )) { +xfs_irele (ip); +xfs_fs_mark_sick (mp,xfs_dqinode_sick_mask (type)); +return -EFSCORRUPTED ; + } + +if (XFS_IS_CORRUPT (mp, ip->i_projid !=0 )) { +xfs_irele (ip); +xfs_fs_mark_sick (mp,xfs_dqinode_sick_mask (type)); +return -EFSCORRUPTED ; + } + + *ipp = ip; +return 0 ; +} + +/* Create a metadata directory quota inode. */ +int +xfs_dqinode_metadir_create ( +struct xfs_inode *dp, +xfs_dqtype_t type, +struct xfs_inode **ipp) +{ +struct xfs_metadir_update upd = { + .dp = dp, + .metafile_type =xfs_dqinode_metafile_type (type), + .path =xfs_dqinode_path (type), + }; +int error; + + error =xfs_metadir_start_create (&upd); +if (error) +return error; + + error =xfs_metadir_create (&upd,S_IFREG ); +if (error) +return error; + +xfs_trans_log_inode (upd.tp, upd.ip,XFS_ILOG_CORE ); + + error =xfs_metadir_commit (&upd); +if (error) +return error; + +xfs_finish_inode_setup (upd.ip); + *ipp = upd.ip; +return 0 ; +} + +#ifndef __KERNEL__ +/* Link a metadata directory quota inode. */ +int +xfs_dqinode_metadir_link ( +struct xfs_inode *dp, +xfs_dqtype_t type, +struct xfs_inode *ip) +{ +struct xfs_metadir_update upd = { + .dp = dp, + .metafile_type =xfs_dqinode_metafile_type (type), + .path =xfs_dqinode_path (type), + .ip = ip, + }; +int error; + + error =xfs_metadir_start_link (&upd); +if (error) +return error; + + error =xfs_metadir_link (&upd); +if (error) +return error; + +xfs_trans_log_inode (upd.tp, upd.ip,XFS_ILOG_CORE ); + +return xfs_metadir_commit (&upd); +} +#endif /* __KERNEL__ */ + +/* Create the parent directory for all quota inodes and load it. */ +int +xfs_dqinode_mkdir_parent ( +struct xfs_mount *mp, +struct xfs_inode **dpp) +{ +if (!mp->m_metadirip) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR ); +return -EFSCORRUPTED ; + } + +return xfs_metadir_mkdir (mp->m_metadirip,"quota" , dpp); +} + +/* +* Load the parent directory of all quota inodes. Pass the inode to the caller +* because quota functions (e.g. QUOTARM) can be called on the quota files even +* if quotas are not enabled. +*/ +int +xfs_dqinode_load_parent ( +struct xfs_trans *tp, +struct xfs_inode **dpp) +{ +struct xfs_mount *mp = tp->t_mountp; + +if (!mp->m_metadirip) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR ); +return -EFSCORRUPTED ; + } + +return xfs_metadir_load (tp, mp->m_metadirip,"quota" ,XFS_METAFILE_DIR , + dpp); +}
fs/xfs/libxfs/xfs_quota_defs.h +43 -0
47 lines not on this page · raw message
fs/xfs/libxfs/xfs_sb.c +1 -0
@@ -841,6 +841,7 @@ xfs_sb_quota_to_disk(uint16_t qflags = from->sb_qflags;if (xfs_sb_version_hasmetadir (from)) { + to->sb_qflags =cpu_to_be16 (from->sb_qflags); to->sb_uquotino =cpu_to_be64 (0 ); to->sb_gquotino =cpu_to_be64 (0 ); to->sb_pquotino =cpu_to_be64 (0 );
fs/xfs/xfs_qm.c +173 -24
224 lines not on this page · raw message
PATCH 3/4 xfs: scrub quota file metapaths
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable online fsck for quota file metadata directory paths.
--- fs/xfs/libxfs/xfs_fs.h | 6 +++- fs/xfs/scrub/metapath.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_fs.h +5 -1
@@ -825,9 +825,13 @@ struct xfs_scrub_vec_head {#define XFS_SCRUB_METAPATH_RTDIR (1)/* rtrgroups metadir */ #define XFS_SCRUB_METAPATH_RTBITMAP (2)/* per-rtg bitmap */ #define XFS_SCRUB_METAPATH_RTSUMMARY (3)/* per-rtg summary */ +#define XFS_SCRUB_METAPATH_QUOTADIR (4)/* quota metadir */ +#define XFS_SCRUB_METAPATH_USRQUOTA (5)/* user quota */ +#define XFS_SCRUB_METAPATH_GRPQUOTA (6)/* group quota */ +#define XFS_SCRUB_METAPATH_PRJQUOTA (7)/* project quota */ /* Number of metapath sm_ino values */ -#define XFS_SCRUB_METAPATH_NR (4) +#define XFS_SCRUB_METAPATH_NR (8)/* * ioctl limits
fs/xfs/scrub/metapath.c +76 -0
88 lines not on this page · raw message
PATCH 4/4 xfs: persist quota flags with metadir
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
It's annoying that one has to keep reminding XFS about what quota options it should mount with, since the quota flags recording the previous state are sitting right there in the primary superblock. Even more strangely, there exists a noquota option to disable quotas completely, so it's odder still that providing no options is the same as noquota.
Starting with metadir, let's change the behavior so that if the user does not specify any quota-related mount options at all, the ondisk quota flags will be used to bring up quota. In other words, the filesystem will mount in the same state and with the same functionality as it had during the last mount.
--- fs/xfs/xfs_mount.c | 15 +++++++++++++++ fs/xfs/xfs_mount.h | 6 ++++++ fs/xfs/xfs_qm_bhv.c | 18 ++++++++++++++++++ fs/xfs/xfs_quota.h | 2 ++ fs/xfs/xfs_super.c | 22 ++++++++++++++++++++++ 5 files changed, 63 insertions(+)
fs/xfs/xfs_mount.c +15 -0
@@ -852,6 +852,13 @@ xfs_mountfs(if (error) goto out_fail_wait; +/* +* If we're resuming quota status, pick up the preliminary qflags from +* the ondisk superblock so that we know if we should recover dquots. +*/ +if (xfs_is_resuming_quotaon (mp)) +xfs_qm_resume_quotaon (mp); +/* * Log's mount-time initialization. The first part of recovery can place * some items on the AIL, to be handled when recovery is finished or
@@ -865,6 +872,14 @@ xfs_mountfs( goto out_inodegc_shrinker; } +/* +* If we're resuming quota status and recovered the log, re-sample the +* qflags from the ondisk superblock now that we've recovered it, just +* in case someone shut down enforcement just before a crash. +*/ +if (xfs_clear_resuming_quotaon (mp) &&xlog_recovery_needed (mp->m_log)) +xfs_qm_resume_quotaon (mp); +/* * If logged xattrs are still enabled after log recovery finishes, then * they'll be available until unmount. Otherwise, turn them off.
fs/xfs/xfs_mount.h +6 -0
@@ -489,6 +489,8 @@ __XFS_HAS_FEAT(nouuid, NOUUID)#define XFS_OPSTATE_UNSET_LOG_INCOMPAT 11/* Filesystem can use logged extended attributes */ #define XFS_OPSTATE_USE_LARP 12 +/* Filesystem should use qflags to determine quotaon status */ +#define XFS_OPSTATE_RESUMING_QUOTAON 13#define __XFS_IS_OPSTATE (name,NAME ) \ static inline bool xfs_is_ ## name (struct xfs_mount *mp) \
@@ -513,8 +515,12 @@ __XFS_IS_OPSTATE(inodegc_enabled, INODEGC_ENABLED) __XFS_IS_OPSTATE(blockgc_enabled, BLOCKGC_ENABLED)#ifdef CONFIG_XFS_QUOTA __XFS_IS_OPSTATE(quotacheck_running, QUOTACHECK_RUNNING) +__XFS_IS_OPSTATE(resuming_quotaon, RESUMING_QUOTAON)#else # define xfs_is_quotacheck_running (mp) (false) +# define xfs_is_resuming_quotaon (mp) (false) +# define xfs_set_resuming_quotaon (mp) (false) +# define xfs_clear_resuming_quotaon (mp) (false)#endif __XFS_IS_OPSTATE(done_with_log_incompat, UNSET_LOG_INCOMPAT)__XFS_IS_OPSTATE (using_logged_xattrs,USE_LARP )
fs/xfs/xfs_qm_bhv.c +18 -0
@@ -135,3 +135,21 @@ xfs_qm_newmount(return 0 ; } + +/* +* If the sysadmin didn't provide any quota mount options, restore the quota +* accounting and enforcement state from the ondisk superblock. Only do this +* for metadir filesystems because this is a behavior change. +*/ +void +xfs_qm_resume_quotaon ( +struct xfs_mount *mp) +{ +if (!xfs_has_metadir (mp)) +return ; +if (xfs_has_norecovery (mp)) +return ; + + mp->m_qflags = mp->m_sb.sb_qflags & (XFS_ALL_QUOTA_ACCT | +XFS_ALL_QUOTA_ENFD ); +}
fs/xfs/xfs_quota.h +2 -0
@@ -125,6 +125,7 @@ extern void xfs_qm_dqdetach(struct xfs_inode *);extern void xfs_qm_dqrele (struct xfs_dquot *);extern void xfs_qm_statvfs (struct xfs_inode *,struct kstatfs *);extern int xfs_qm_newmount (struct xfs_mount *,uint *,uint *); +void xfs_qm_resume_quotaon (struct xfs_mount *mp);extern void xfs_qm_mount_quotas (struct xfs_mount *);extern void xfs_qm_unmount (struct xfs_mount *);extern void xfs_qm_unmount_quotas (struct xfs_mount *);
@@ -202,6 +203,7 @@ xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp,#define xfs_qm_dqrele (d) do { (d) = (d); } while(0)#define xfs_qm_statvfs (ip, s) do { } while(0)#define xfs_qm_newmount (mp, a, b) (0) +#define xfs_qm_resume_quotaon (mp) ((void)0)#define xfs_qm_mount_quotas (mp)#define xfs_qm_unmount (mp)#define xfs_qm_unmount_quotas (mp)
fs/xfs/xfs_super.c +22 -0
@@ -67,6 +67,9 @@ enum xfs_dax_mode { XFS_DAX_NEVER = 2, }; +/* Were quota mount options provided? Must use the upper 16 bits of qflags. */ +#define XFS_QFLAGS_MNTOPTS (1U << 31) + static void xfs_mount_set_dax_mode( struct xfs_mount *mp,
@@ -1264,6 +1267,8 @@ xfs_fs_parse_param(int size =0 ;int opt; +BUILD_BUG_ON (XFS_QFLAGS_MNTOPTS &XFS_MOUNT_QUOTA_ALL ); + opt =fs_parse (fc, xfs_fs_parameters, param, &result);if (opt <0 )return opt;
@@ -1341,32 +1346,39 @@ xfs_fs_parse_param(case Opt_noquota: parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT ; parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD ; + parsing_mp->m_qflags |=XFS_QFLAGS_MNTOPTS ;return 0 ;case Opt_quota:case Opt_uquota:case Opt_usrquota: parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT |XFS_UQUOTA_ENFD ); + parsing_mp->m_qflags |=XFS_QFLAGS_MNTOPTS ;return 0 ;case Opt_qnoenforce:case Opt_uqnoenforce: parsing_mp->m_qflags |=XFS_UQUOTA_ACCT ; parsing_mp->m_qflags &= ~XFS_UQUOTA_ENFD ; + parsing_mp->m_qflags |=XFS_QFLAGS_MNTOPTS ;return 0 ;case Opt_pquota:case Opt_prjquota: parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT |XFS_PQUOTA_ENFD ); + parsing_mp->m_qflags |=XFS_QFLAGS_MNTOPTS ;return 0 ;case Opt_pqnoenforce: parsing_mp->m_qflags |=XFS_PQUOTA_ACCT ; parsing_mp->m_qflags &= ~XFS_PQUOTA_ENFD ; + parsing_mp->m_qflags |=XFS_QFLAGS_MNTOPTS ;return 0 ;case Opt_gquota:case Opt_grpquota: parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT |XFS_GQUOTA_ENFD ); + parsing_mp->m_qflags |=XFS_QFLAGS_MNTOPTS ;return 0 ;case Opt_gqnoenforce: parsing_mp->m_qflags |=XFS_GQUOTA_ACCT ; parsing_mp->m_qflags &= ~XFS_GQUOTA_ENFD ; + parsing_mp->m_qflags |=XFS_QFLAGS_MNTOPTS ;return 0 ;case Opt_discard: parsing_mp->m_features |=XFS_FEAT_DISCARD ;
@@ -1773,6 +1785,14 @@ xfs_fs_fill_super(xfs_warn (mp,"EXPERIMENTAL parent pointer feature enabled. Use at your own risk!" ); +/* +* If no quota mount options were provided, maybe we'll try to pick +* up the quota accounting and enforcement flags from the ondisk sb. +*/ +if (!(mp->m_qflags &XFS_QFLAGS_MNTOPTS )) +xfs_set_resuming_quotaon (mp); + mp->m_qflags &= ~XFS_QFLAGS_MNTOPTS ; + error =xfs_mountfs (mp);if (error) goto out_filestream_unmount;
@@ -1959,6 +1979,8 @@ xfs_fs_reconfigure(int flags = fc->sb_flags;int error; + new_mp->m_qflags &= ~XFS_QFLAGS_MNTOPTS ; +/* version 5 superblocks always support version counters. */ if (xfs_has_crc (mp)) fc->sb_flags |=SB_I_VERSION ;
PATCH 8/9 xfs: enable quota for realtime volumes
In reply to Darrick J. WongHi all,
At some point, I realized that I've refactored enough of the quota code in XFS that I should evaluate whether or not quota actually works on realtime volumes. It turns out that it nearly works: the only broken pieces are chown and delayed allocation, and reporting of project quotas in the statvfs output for projinherit+rtinherit directories.
Fix these things and we can have realtime quotas again after 20 years.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=realtime-quotas
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=realtime-quotas
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=realtime-quotas
---
Commits in this patchset:
* xfs: fix chown with rt quota
* xfs: advertise realtime quota support in the xqm stat files
* xfs: report realtime block quota limits on realtime directories
* xfs: create quota preallocation watermarks for realtime quota
* xfs: reserve quota for realtime files correctly
* xfs: enable realtime quota again
--- fs/xfs/xfs_dquot.c | 41 +++++++++++++++---------- fs/xfs/xfs_dquot.h | 18 +++++++++-- fs/xfs/xfs_iomap.c | 37 ++++++++++++++++++----- fs/xfs/xfs_qm.c | 75 +++++++++++++++++++++++++++++++--------------- fs/xfs/xfs_qm_bhv.c | 18 +++++++---- fs/xfs/xfs_quota.h | 12 ++++--- fs/xfs/xfs_rtalloc.c | 4 ++ fs/xfs/xfs_stats.c | 12 ++++++- fs/xfs/xfs_super.c | 11 +++---- fs/xfs/xfs_trans.c | 31 ++++++++++++++++++- fs/xfs/xfs_trans_dquot.c | 11 +++++++ 11 files changed, 194 insertions(+), 76 deletions(-)
PATCH 1/6 xfs: fix chown with rt quota
From: Darrick J. Wong <[email protected]>
Make chown's quota adjustments work with realtime files.
--- fs/xfs/xfs_qm.c | 44 +++++++++++++++++++++++++++----------------- fs/xfs/xfs_trans.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 19 deletions(-)
fs/xfs/xfs_qm.c +27 -17
@@ -1351,8 +1351,8 @@ xfs_qm_dqusage_adjust( void *data) {struct xfs_inode *ip; -xfs_qcnt_t nblks; -xfs_filblks_t rtblks =0 ;/* total rt blks */ +xfs_filblks_t nblks, rtblks; +unsigned int lock_mode;int error;ASSERT (XFS_IS_QUOTA_ON (mp));
@@ -1393,18 +1393,17 @@ xfs_qm_dqusage_adjust(ASSERT (ip->i_delayed_blks ==0 ); + lock_mode =xfs_ilock_data_map_shared (ip);if (XFS_IS_REALTIME_INODE (ip)) { -struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); - error =xfs_iread_extents (tp, ip,XFS_DATA_FORK ); -if (error) +if (error) { +xfs_iunlock (ip, lock_mode); goto error0; - -xfs_bmap_count_leaves (ifp, &rtblks); + } } - - nblks = (xfs_qcnt_t )ip->i_nblocks - rtblks; +xfs_inode_count_blocks (tp, ip, &nblks, &rtblks);xfs_iflags_clear (ip,XFS_IQUOTAUNCHECKED ); +xfs_iunlock (ip, lock_mode);/* * Add the (disk blocks and inode) resources occupied by this
@@ -2043,9 +2042,8 @@ xfs_qm_vop_chown( struct xfs_dquot *newdq) {struct xfs_dquot *prevdq; -uint bfield =XFS_IS_REALTIME_INODE (ip) ? -XFS_TRANS_DQ_RTBCOUNT :XFS_TRANS_DQ_BCOUNT ; - +xfs_filblks_t dblocks, rblocks; +bool isrt =XFS_IS_REALTIME_INODE (ip);xfs_assert_ilocked (ip,XFS_ILOCK_EXCL );ASSERT (XFS_IS_QUOTA_ON (ip->i_mount));
@@ -2056,11 +2054,17 @@ xfs_qm_vop_chown(ASSERT (prevdq);ASSERT (prevdq != newdq); -xfs_trans_mod_ino_dquot (tp, ip, prevdq, bfield, -(ip->i_nblocks)); +xfs_inode_count_blocks (tp, ip, &dblocks, &rblocks); + +xfs_trans_mod_ino_dquot (tp, ip, prevdq,XFS_TRANS_DQ_BCOUNT , + -(xfs_qcnt_t )dblocks); +xfs_trans_mod_ino_dquot (tp, ip, prevdq,XFS_TRANS_DQ_RTBCOUNT , + -(xfs_qcnt_t )rblocks);xfs_trans_mod_ino_dquot (tp, ip, prevdq,XFS_TRANS_DQ_ICOUNT ,-1 );/* the sparkling new dquot */ -xfs_trans_mod_ino_dquot (tp, ip, newdq, bfield, ip->i_nblocks); +xfs_trans_mod_ino_dquot (tp, ip, newdq,XFS_TRANS_DQ_BCOUNT , dblocks); +xfs_trans_mod_ino_dquot (tp, ip, newdq,XFS_TRANS_DQ_RTBCOUNT , rblocks);xfs_trans_mod_ino_dquot (tp, ip, newdq,XFS_TRANS_DQ_ICOUNT ,1 );/*
@@ -2070,7 +2074,8 @@ xfs_qm_vop_chown(* (having already bumped up the real counter) so that we don't have * any reservation to give back when we commit. */ -xfs_trans_mod_dquot (tp, newdq,XFS_TRANS_DQ_RES_BLKS , +xfs_trans_mod_dquot (tp, newdq, + isrt ?XFS_TRANS_DQ_RES_RTBLKS :XFS_TRANS_DQ_RES_BLKS , -ip->i_delayed_blks);/*
@@ -2082,8 +2087,13 @@ xfs_qm_vop_chown(*/ tp->t_flags |=XFS_TRANS_DIRTY ;xfs_dqlock (prevdq); -ASSERT (prevdq->q_blk.reserved >= ip->i_delayed_blks); - prevdq->q_blk.reserved -= ip->i_delayed_blks; +if (isrt) { +ASSERT (prevdq->q_rtb.reserved >= ip->i_delayed_blks); + prevdq->q_rtb.reserved -= ip->i_delayed_blks; + }else { +ASSERT (prevdq->q_blk.reserved >= ip->i_delayed_blks); + prevdq->q_blk.reserved -= ip->i_delayed_blks; + }xfs_dqunlock (prevdq);/*
fs/xfs/xfs_trans.c +29 -2
@@ -1288,11 +1288,26 @@ xfs_trans_alloc_ichange( gdqp = (new_gdqp != ip->i_gdquot) ? new_gdqp :NULL ; pdqp = (new_pdqp != ip->i_pdquot) ? new_pdqp :NULL ;if (udqp || gdqp || pdqp) { +xfs_filblks_t dblocks, rblocks;unsigned int qflags =XFS_QMOPT_RES_REGBLKS ; +bool isrt =XFS_IS_REALTIME_INODE (ip);if (force) qflags |=XFS_QMOPT_FORCE_RES ; +if (isrt) { + error =xfs_iread_extents (tp, ip,XFS_DATA_FORK ); +if (error) + goto out_cancel; + } + +xfs_inode_count_blocks (tp, ip, &dblocks, &rblocks); + +if (isrt) + rblocks += ip->i_delayed_blks; +else + dblocks += ip->i_delayed_blks; +/* * Reserve enough quota to handle blocks on disk and reserved * for a delayed allocation. We'll actually transfer the
@@ -1300,8 +1315,20 @@ xfs_trans_alloc_ichange(* though that part is only semi-transactional. */ error =xfs_trans_reserve_quota_bydquots (tp, mp, udqp, gdqp, - pdqp, ip->i_nblocks + ip->i_delayed_blks, -1 , qflags); + pdqp, dblocks,1 , qflags); +if ((error == -EDQUOT || error == -ENOSPC ) && !retried) { +xfs_trans_cancel (tp); +xfs_blockgc_free_dquots (mp, udqp, gdqp, pdqp,0 ); + retried = true; + goto retry; + } +if (error) + goto out_cancel; + +/* Do the same for realtime. */ + qflags =XFS_QMOPT_RES_RTBLKS | (qflags &XFS_QMOPT_FORCE_RES ); + error =xfs_trans_reserve_quota_bydquots (tp, mp, udqp, gdqp, + pdqp, rblocks,0 , qflags);if ((error == -EDQUOT || error == -ENOSPC ) && !retried) {xfs_trans_cancel (tp);xfs_blockgc_free_dquots (mp, udqp, gdqp, pdqp,0 );
Re: [PATCH 1/6] xfs: fix chown with rt quota
Quoted 3 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Make chown's quota adjustments work with realtime files.
Maybe explain how you made it work here?
Quoted 6 lines
fs/xfs/xfs_qm.c +1
-0@@ -1393,18 +1393,17 @@ xfs_qm_dqusage_adjust(ASSERT (ip->i_delayed_blks ==0 ); + lock_mode =xfs_ilock_data_map_shared (ip);if (XFS_IS_REALTIME_INODE (ip)) {
fs/xfs/xfs_qm.c xfs_qm_dqusage_adjust( · line 1402
Quoted 10 lines
fs/xfs/xfs_qm.c +3
-5-struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); - error =xfs_iread_extents (tp, ip,XFS_DATA_FORK ); -if (error) +if (error) { +xfs_iunlock (ip, lock_mode); goto error0; - -xfs_bmap_count_leaves (ifp, &rtblks); + }
So this obviously was missing locking :)
fs/xfs/xfs_qm.c xfs_qm_dqusage_adjust( · line 1406
Quoted 6 lines
fs/xfs/xfs_qm.c +2
-2} - - nblks = (xfs_qcnt_t )ip->i_nblocks - rtblks; +xfs_inode_count_blocks (tp, ip, &nblks, &rtblks);xfs_iflags_clear (ip,XFS_IQUOTAUNCHECKED ); +xfs_iunlock (ip, lock_mode);
But this now also forces lockign for !rt file systems, I guess we don't really care about an extra ilock roundtrip in chown, though.
The changes itself look good, but a useful commit log would be nice:
Re: [PATCH 1/6] xfs: fix chown with rt quota
Quoted 12 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Make chown's quota adjustments work with realtime files.
Maybe explain how you made it work here?
Quoted 4 lines
fs/xfs/xfs_qm.c +0
-0@@ -1393,18 +1393,17 @@ xfs_qm_dqusage_adjust(ASSERT (ip->i_delayed_blks ==0 );
Quoted 14 lines
fs/xfs/xfs_qm.c xfs_qm_dqusage_adjust( · line 1402
Quoted 12 lines
fs/xfs/xfs_qm.c +4
-5+ lock_mode =xfs_ilock_data_map_shared (ip);if (XFS_IS_REALTIME_INODE (ip)) { -struct xfs_ifork *ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); - error =xfs_iread_extents (tp, ip,XFS_DATA_FORK ); -if (error) +if (error) { +xfs_iunlock (ip, lock_mode); goto error0; - -xfs_bmap_count_leaves (ifp, &rtblks); + }So this obviously was missing locking :)
Yep. Luckily you could never mount with rt+quota before, so there weren't any corruption complaints. I guess that's one way to get to zero bugs. :P
Quoted 10 lines
fs/xfs/xfs_qm.c xfs_qm_dqusage_adjust( · line 1406
Quoted 6 lines
fs/xfs/xfs_qm.c +2
-2} - - nblks = (xfs_qcnt_t )ip->i_nblocks - rtblks; +xfs_inode_count_blocks (tp, ip, &nblks, &rtblks);xfs_iflags_clear (ip,XFS_IQUOTAUNCHECKED ); +xfs_iunlock (ip, lock_mode);But this now also forces lockign for !rt file systems, I guess we don't really care about an extra ilock roundtrip in chown, though.
Well, it's needed for correctness because you have to distinguish data and rtblocks usage to keep the accounting correct. The only way to do that is to walk the data fork mappings, which means ILOCK.
Quoted 1 line
The changes itself look good, but a useful commit log would be nice:
xfs: fix chown with rt quota
Make chown's quota adjustments work with realtime files. This is mostly a matter of calling xfs_inode_count_blocks on a given file to figure out the number of blocks allocated to the data device and to the realtime device, and using those quantities to update the quota accounting when the id changes. Delayed allocation reservations are moved from the old dquot's incore reservation to the new dquot's incore reservation.
Note that there was a missing ILOCK bug in xfs_qm_dqusage_adjust that we must fix before calling xfs_iread_extents. Prior to 2.6.37 the locking was correct, but then someone removed the ILOCK as part of a cleanup. Nobody noticed because nowhere in the git history have we ever supported rt+quota so nobody can use this.
I'm leaving git breadcrumbs in case anyone is desperate enough to try to backport the rtquota code to old kernels.
Not-Cc: <[email protected]> # v2.6.37
Quoted 1 line
Reviewed-by Christoph Hellwig <[email protected]>
Heh, thanks. :)
--D
PATCH 2/6 xfs: advertise realtime quota support in the xqm stat files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a fifth column to this (really old) stat file to advertise that the kernel supports quota for realtime volumes. This will be used by fstests to detect kernel support.
--- fs/xfs/xfs_stats.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/xfs/xfs_stats.c +9 -3
@@ -115,10 +115,16 @@ void xfs_stats_clearall(struct xfsstats __percpu *stats)static int xqm_proc_show (struct seq_file *m,void *v) { -/* maximum; incore; ratio free to inuse; freelist */ -seq_printf (m,"%d\t%d\t%d\t%u\n" , +/* maximum; incore; ratio free to inuse; freelist; rtquota */ +seq_printf (m,"%d\t%d\t%d\t%u\t%u\n" ,0 ,counter_val (xfsstats.xs_stats,XFSSTAT_END_XQMSTAT ), -0 ,counter_val (xfsstats.xs_stats,XFSSTAT_END_XQMSTAT +1 )); +0 ,counter_val (xfsstats.xs_stats,XFSSTAT_END_XQMSTAT +1 ), +#ifdef CONFIG_XFS_RT + 1 +#else +0 +#endif + );return 0 ; }
Re: [PATCH 2/6] xfs: advertise realtime quota support in the xqm stat files
fs/xfs/xfs_stats.c void xfs_stats_clearall(struct xfsstats __percpu *stats) · line 126
Quoted 5 lines
fs/xfs/xfs_stats.c +5
-0+#ifdef CONFIG_XFS_RT + 1 +#else + 0 +#endif
This should use IS_ENABLED()
Re: [PATCH 2/6] xfs: advertise realtime quota support in the xqm stat files
Quoted 7 lines · Christoph Hellwig
fs/xfs/xfs_stats.c void xfs_stats_clearall(struct xfsstats __percpu *stats) · line 126
Quoted 5 lines
fs/xfs/xfs_stats.c +5
-0+#ifdef CONFIG_XFS_RT + 1 +#else + 0 +#endif This should use
IS_ENABLED()
Done.
static int xqm_proc_show(struct seq_file *m, void *v)
{
/* maximum; incore; ratio free to inuse; freelist; rtquota */
seq_printf(m, "%d\t%d\t%d\t%u\t%u\n",
0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT),
0, counter_val(xfsstats.xs_stats, XFSSTAT_END_XQMSTAT + 1),
IS_ENABLED(CONFIG_XFS_RT));
return 0;
}Thanks to your other patch adding IS_ENABLED to xfs_alloc.c that got merged in -rc3, I had to port that to userspace, so now I actually know what that macro /really/ does. ;)
--D
PATCH 3/6 xfs: report realtime block quota limits on realtime directories
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
On the data device, calling statvfs on a projinherit directory results in the block and avail counts being curtailed to the project quota block limits, if any are set. Do the same for realtime files or directories, only use the project quota rt block limits.
--- fs/xfs/xfs_qm_bhv.c | 18 ++++++++++++------ fs/xfs/xfs_super.c | 11 +++++------ 2 files changed, 17 insertions(+), 12 deletions(-)
fs/xfs/xfs_qm_bhv.c +12 -6
@@ -19,18 +19,24 @@ STATIC voidxfs_fill_statvfs_from_dquot (struct kstatfs *statp, +struct xfs_inode *ip,struct xfs_dquot *dqp) { +struct xfs_dquot_res *blkres = &dqp->q_blk;uint64_t limit; - limit = dqp->q_blk.softlimit ? - dqp->q_blk.softlimit : - dqp->q_blk.hardlimit; +if (XFS_IS_REALTIME_MOUNT (ip->i_mount) && + (ip->i_diflags & (XFS_DIFLAG_RTINHERIT |XFS_DIFLAG_REALTIME ))) + blkres = &dqp->q_rtb; + + limit = blkres->softlimit ? + blkres->softlimit : + blkres->hardlimit;if (limit && statp->f_blocks > limit) { statp->f_blocks = limit; statp->f_bfree = statp->f_bavail = - (statp->f_blocks > dqp->q_blk.reserved) ? - (statp->f_blocks - dqp->q_blk.reserved) :0 ; + (statp->f_blocks > blkres->reserved) ? + (statp->f_blocks - blkres->reserved) :0 ; } limit = dqp->q_ino.softlimit ?
@@ -61,7 +67,7 @@ xfs_qm_statvfs(struct xfs_dquot *dqp;if (!xfs_qm_dqget (mp, ip->i_projid,XFS_DQTYPE_PROJ , false, &dqp)) { -xfs_fill_statvfs_from_dquot (statp, dqp); +xfs_fill_statvfs_from_dquot (statp, ip, dqp);xfs_qm_dqput (dqp); } }
fs/xfs/xfs_super.c +5 -6
@@ -877,12 +877,6 @@ xfs_fs_statfs( ffree = statp->f_files - (icount - ifree); statp->f_ffree =max_t (int64_t, ffree,0 ); - -if ((ip->i_diflags &XFS_DIFLAG_PROJINHERIT ) && - ((mp->m_qflags & (XFS_PQUOTA_ACCT |XFS_PQUOTA_ENFD ))) == - (XFS_PQUOTA_ACCT |XFS_PQUOTA_ENFD )) -xfs_qm_statvfs (ip, statp); -if (XFS_IS_REALTIME_MOUNT (mp) && (ip->i_diflags & (XFS_DIFLAG_RTINHERIT |XFS_DIFLAG_REALTIME ))) {s64 freertx;
@@ -893,6 +887,11 @@ xfs_fs_statfs(xfs_rtbxlen_to_blen (mp, freertx); } +if ((ip->i_diflags &XFS_DIFLAG_PROJINHERIT ) && + ((mp->m_qflags & (XFS_PQUOTA_ACCT |XFS_PQUOTA_ENFD ))) == + (XFS_PQUOTA_ACCT |XFS_PQUOTA_ENFD )) +xfs_qm_statvfs (ip, statp); +return 0 ; }
Re: [PATCH 3/6] xfs: report realtime block quota limits on realtime directories
Looks good:
PATCH 4/6 xfs: create quota preallocation watermarks for realtime quota
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Refactor the quota preallocation watermarking code so that it'll work for realtime quota too.
--- fs/xfs/xfs_dquot.c | 41 +++++++++++++++++++++++++---------------- fs/xfs/xfs_dquot.h | 18 ++++++++++++++---- fs/xfs/xfs_iomap.c | 37 ++++++++++++++++++++++++++++++------- fs/xfs/xfs_qm.c | 21 ++++++++++++++++----- 4 files changed, 85 insertions(+), 32 deletions(-)
fs/xfs/xfs_dquot.c +25 -16
@@ -277,6 +277,29 @@ xfs_qm_init_dquot_blk(xfs_trans_log_buf (tp, bp,0 ,BBTOB (q->qi_dqchunklen) -1 ); } +static void +xfs_dquot_set_prealloc ( +struct xfs_dquot_pre *pre, +const struct xfs_dquot_res *res) +{ +uint64_t space; + + pre->q_prealloc_hi_wmark = res->hardlimit; + pre->q_prealloc_lo_wmark = res->softlimit; +if (!pre->q_prealloc_lo_wmark) { + pre->q_prealloc_lo_wmark = pre->q_prealloc_hi_wmark; +do_div (pre->q_prealloc_lo_wmark,100 ); + pre->q_prealloc_lo_wmark *=95 ; + } + + space = pre->q_prealloc_hi_wmark; + +do_div (space,100 ); + pre->q_low_space[XFS_QLOWSP_1_PCNT ] = space; + pre->q_low_space[XFS_QLOWSP_3_PCNT ] = space *3 ; + pre->q_low_space[XFS_QLOWSP_5_PCNT ] = space *5 ; +} +/* * Initialize the dynamic speculative preallocation thresholds. The lo/hi * watermarks correspond to the soft and hard limits by default. If a soft limit
@@ -285,22 +308,8 @@ xfs_qm_init_dquot_blk(void xfs_dquot_set_prealloc_limits (struct xfs_dquot *dqp) { -uint64_t space; - - dqp->q_prealloc_hi_wmark = dqp->q_blk.hardlimit; - dqp->q_prealloc_lo_wmark = dqp->q_blk.softlimit; -if (!dqp->q_prealloc_lo_wmark) { - dqp->q_prealloc_lo_wmark = dqp->q_prealloc_hi_wmark; -do_div (dqp->q_prealloc_lo_wmark,100 ); - dqp->q_prealloc_lo_wmark *=95 ; - } - - space = dqp->q_prealloc_hi_wmark; - -do_div (space,100 ); - dqp->q_low_space[XFS_QLOWSP_1_PCNT ] = space; - dqp->q_low_space[XFS_QLOWSP_3_PCNT ] = space *3 ; - dqp->q_low_space[XFS_QLOWSP_5_PCNT ] = space *5 ; +xfs_dquot_set_prealloc (&dqp->q_blk_prealloc, &dqp->q_blk); +xfs_dquot_set_prealloc (&dqp->q_rtb_prealloc, &dqp->q_rtb); }/*
fs/xfs/xfs_dquot.h +14 -4
@@ -56,6 +56,12 @@ xfs_dquot_res_over_limits(return false; } +struct xfs_dquot_pre { +xfs_qcnt_t q_prealloc_lo_wmark; +xfs_qcnt_t q_prealloc_hi_wmark; +int64_t q_low_space[XFS_QLOWSP_MAX ]; +}; +/* * The incore dquot structure */
@@ -76,9 +82,9 @@ struct xfs_dquot {struct xfs_dq_logitem q_logitem; -xfs_qcnt_t q_prealloc_lo_wmark; -xfs_qcnt_t q_prealloc_hi_wmark; -int64_t q_low_space[XFS_QLOWSP_MAX ]; +struct xfs_dquot_pre q_blk_prealloc; +struct xfs_dquot_pre q_rtb_prealloc; +struct mutex q_qlock;struct completion q_flush;atomic_t q_pincount;
@@ -192,7 +198,11 @@ static inline bool xfs_dquot_lowsp(struct xfs_dquot *dqp)int64_t freesp; freesp = dqp->q_blk.hardlimit - dqp->q_blk.reserved; -if (freesp < dqp->q_low_space[XFS_QLOWSP_1_PCNT ]) +if (freesp < dqp->q_blk_prealloc.q_low_space[XFS_QLOWSP_1_PCNT ]) +return true; + + freesp = dqp->q_rtb.hardlimit - dqp->q_rtb.reserved; +if (freesp < dqp->q_rtb_prealloc.q_low_space[XFS_QLOWSP_1_PCNT ])return true;return false;
fs/xfs/xfs_iomap.c +30 -7
@@ -353,16 +353,26 @@ xfs_quota_need_throttle( xfs_fsblock_t alloc_blocks) {struct xfs_dquot *dq =xfs_inode_dquot (ip, type); +struct xfs_dquot_res *res; +struct xfs_dquot_pre *pre;if (!dq || !xfs_this_quota_on (ip->i_mount, type))return false; +if (XFS_IS_REALTIME_INODE (ip)) { + res = &dq->q_rtb; + pre = &dq->q_rtb_prealloc; + }else { + res = &dq->q_blk; + pre = &dq->q_blk_prealloc; + } +/* no hi watermark, no throttle */ -if (!dq->q_prealloc_hi_wmark) +if (!pre->q_prealloc_hi_wmark)return false;/* under the lo watermark, no throttle */ -if (dq->q_blk.reserved + alloc_blocks < dq->q_prealloc_lo_wmark) +if (res->reserved + alloc_blocks < pre->q_prealloc_lo_wmark)return false;return true;
@@ -377,22 +387,35 @@ xfs_quota_calc_throttle( int64_t *qfreesp) {struct xfs_dquot *dq =xfs_inode_dquot (ip, type); +struct xfs_dquot_res *res; +struct xfs_dquot_pre *pre;int64_t freesp;int shift =0 ; +if (!dq) { + res =NULL ; + pre =NULL ; + }else if (XFS_IS_REALTIME_INODE (ip)) { + res = &dq->q_rtb; + pre = &dq->q_rtb_prealloc; + }else { + res = &dq->q_blk; + pre = &dq->q_blk_prealloc; + } +/* no dq, or over hi wmark, squash the prealloc completely */ -if (!dq || dq->q_blk.reserved >= dq->q_prealloc_hi_wmark) { +if (!res || res->reserved >= pre->q_prealloc_hi_wmark) { *qblocks =0 ; *qfreesp =0 ;return ; } - freesp = dq->q_prealloc_hi_wmark - dq->q_blk.reserved; -if (freesp < dq->q_low_space[XFS_QLOWSP_5_PCNT ]) { + freesp = pre->q_prealloc_hi_wmark - res->reserved; +if (freesp < pre->q_low_space[XFS_QLOWSP_5_PCNT ]) { shift =2 ; -if (freesp < dq->q_low_space[XFS_QLOWSP_3_PCNT ]) +if (freesp < pre->q_low_space[XFS_QLOWSP_3_PCNT ]) shift +=2 ; -if (freesp < dq->q_low_space[XFS_QLOWSP_1_PCNT ]) +if (freesp < pre->q_low_space[XFS_QLOWSP_1_PCNT ]) shift +=2 ; }
fs/xfs/xfs_qm.c +16 -5
@@ -2178,6 +2178,8 @@ xfs_inode_near_dquot_enforcement( xfs_dqtype_t type) {struct xfs_dquot *dqp; +struct xfs_dquot_res *res; +struct xfs_dquot_pre *pre;int64_t freesp;/* We only care for quotas that are enabled and enforced. */
@@ -2186,21 +2188,30 @@ xfs_inode_near_dquot_enforcement(return false;if (xfs_dquot_res_over_limits (&dqp->q_ino) || +xfs_dquot_res_over_limits (&dqp->q_blk) ||xfs_dquot_res_over_limits (&dqp->q_rtb))return true; +if (XFS_IS_REALTIME_INODE (ip)) { + res = &dqp->q_rtb; + pre = &dqp->q_rtb_prealloc; + }else { + res = &dqp->q_blk; + pre = &dqp->q_blk_prealloc; + } +/* For space on the data device, check the various thresholds. */ -if (!dqp->q_prealloc_hi_wmark) +if (!pre->q_prealloc_hi_wmark)return false; -if (dqp->q_blk.reserved < dqp->q_prealloc_lo_wmark) +if (res->reserved < pre->q_prealloc_lo_wmark)return false; -if (dqp->q_blk.reserved >= dqp->q_prealloc_hi_wmark) +if (res->reserved >= pre->q_prealloc_hi_wmark)return true; - freesp = dqp->q_prealloc_hi_wmark - dqp->q_blk.reserved; -if (freesp < dqp->q_low_space[XFS_QLOWSP_5_PCNT ]) + freesp = pre->q_prealloc_hi_wmark - res->reserved; +if (freesp < pre->q_low_space[XFS_QLOWSP_5_PCNT ])return true;return false;
Re: [PATCH 4/6] xfs: create quota preallocation watermarks for realtime quota
fs/xfs/xfs_dquot.c xfs_qm_init_dquot_blk( · line 297
Quoted 11 lines · Darrick J. Wong
fs/xfs/xfs_dquot.c +11
-0+ pre->q_prealloc_hi_wmark = res->hardlimit; + pre->q_prealloc_lo_wmark = res->softlimit; +if (!pre->q_prealloc_lo_wmark) { + pre->q_prealloc_lo_wmark = pre->q_prealloc_hi_wmark; +do_div (pre->q_prealloc_lo_wmark,100 ); + pre->q_prealloc_lo_wmark *=95 ; + } + + space = pre->q_prealloc_hi_wmark; + +do_div (space,100 );
Maybe use div_u64 instead of the fugly do_div helper?
Otherwise looks good:
PATCH 5/6 xfs: reserve quota for realtime files correctly
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Fix xfs_quota_reserve_blkres to reserve rt block quota whenever we're dealing with a realtime file.
--- fs/xfs/xfs_quota.h | 12 ++++++------ fs/xfs/xfs_trans_dquot.c | 11 +++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-)
fs/xfs/xfs_quota.h +6 -6
@@ -130,6 +130,7 @@ extern void xfs_qm_mount_quotas(struct xfs_mount *);extern void xfs_qm_unmount (struct xfs_mount *);extern void xfs_qm_unmount_quotas (struct xfs_mount *);bool xfs_inode_near_dquot_enforcement (struct xfs_inode *ip,xfs_dqtype_t type); +int xfs_quota_reserve_blkres (struct xfs_inode *ip,int64_t blocks);# ifdef CONFIG_XFS_LIVE_HOOKS void xfs_trans_mod_ino_dquot(struct xfs_trans *tp, struct xfs_inode *ip,
@@ -209,6 +210,11 @@ xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp,#define xfs_qm_unmount_quotas (mp)#define xfs_inode_near_dquot_enforcement (ip, type) (false) +static inline int xfs_quota_reserve_blkres (struct xfs_inode *ip,int64_t blocks) +{ +return 0 ; +} +# ifdef CONFIG_XFS_LIVE_HOOKS # define xfs_dqtrx_hook_enable () ((void)0)# define xfs_dqtrx_hook_disable () ((void)0)
@@ -216,12 +222,6 @@ xfs_trans_reserve_quota_icreate(struct xfs_trans *tp, struct xfs_dquot *udqp,#endif /* CONFIG_XFS_QUOTA */ -static inline int -xfs_quota_reserve_blkres (struct xfs_inode *ip,int64_t blocks) -{ -return xfs_trans_reserve_quota_nblks (NULL , ip, blocks,0 , false); -} -static inline void xfs_quota_unreserve_blkres (struct xfs_inode *ip,uint64_t blocks) {
fs/xfs/xfs_trans_dquot.c +11 -0
@@ -1031,3 +1031,14 @@ xfs_trans_free_dqinfo(kmem_cache_free (xfs_dqtrx_cache, tp->t_dqinfo); tp->t_dqinfo =NULL ; } + +int +xfs_quota_reserve_blkres ( +struct xfs_inode *ip, +int64_t blocks) +{ +if (XFS_IS_REALTIME_INODE (ip)) +return xfs_trans_reserve_quota_nblks (NULL , ip,0 , blocks, + false); +return xfs_trans_reserve_quota_nblks (NULL , ip, blocks,0 , false); +}
Re: [PATCH 5/6] xfs: reserve quota for realtime files correctly
Looks good:
PATCH 6/6 xfs: enable realtime quota again
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable quotas for the realtime device.
--- fs/xfs/xfs_qm.c | 10 +++++++--- fs/xfs/xfs_rtalloc.c | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-)
fs/xfs/xfs_qm.c +7 -3
@@ -1663,14 +1663,18 @@ xfs_qm_mount_quotas(uint sbf;/* -* If quotas on realtime volumes is not supported, we disable -* quotas immediately. +* If quotas on realtime volumes is not supported, disable quotas +* immediately. We only support rtquota if rtgroups are enabled to +* avoid problems with older kernels. */ -if (mp->m_sb.sb_rextents) { +if (mp->m_sb.sb_rextents && !xfs_has_rtgroups (mp)) {xfs_notice (mp,"Cannot turn on quotas for realtime filesystem" ); mp->m_qflags =0 ; goto write_changes; } +if (mp->m_sb.sb_rextents) +xfs_warn (mp, +"EXPERIMENTAL realtime quota feature in use. Use at your own risk!" );ASSERT (XFS_IS_QUOTA_ON (mp));
fs/xfs/xfs_rtalloc.c +3 -1
@@ -1265,7 +1265,9 @@ xfs_growfs_rt(/* Unsupported realtime features. */ error = -EOPNOTSUPP ; -if (xfs_has_rmapbt (mp) ||xfs_has_reflink (mp) ||xfs_has_quota (mp)) +if (xfs_has_quota (mp) && !xfs_has_rtgroups (mp)) + goto out_unlock; +if (xfs_has_rmapbt (mp) ||xfs_has_reflink (mp)) goto out_unlock; error =xfs_sb_validate_fsb_count (&mp->m_sb, in->newblocks);
Re: [PATCH 6/6] xfs: enable realtime quota again
Looks good:
PATCH 9/9 xfs: enable metadir
In reply to Darrick J. WongHi all,
Actually enable this very large feature.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=metadir
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=metadir
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=metadir
xfsdocs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-documentation.git/log/?h=metadir
---
Commits in this patchset:
* xfs: update sb field checks when metadir is turned on
* xfs: enable metadata directory feature
--- fs/xfs/libxfs/xfs_format.h | 3 ++- fs/xfs/scrub/agheader.c | 36 ++++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 13 deletions(-)
PATCH 1/2 xfs: update sb field checks when metadir is turned on
From: Darrick J. Wong <[email protected]>
When metadir is enabled, we want to check the two new rtgroups fields, and we don't want to check the old inumbers that are now in the metadir.
--- fs/xfs/scrub/agheader.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)
fs/xfs/scrub/agheader.c +24 -12
@@ -147,14 +147,14 @@ xchk_superblock(if (xfs_has_metadir (sc->mp)) {if (sb->sb_metadirino !=cpu_to_be64 (mp->m_sb.sb_metadirino))xchk_block_set_preen (sc, bp); + }else { +if (sb->sb_rbmino !=cpu_to_be64 (mp->m_sb.sb_rbmino)) +xchk_block_set_preen (sc, bp); + +if (sb->sb_rsumino !=cpu_to_be64 (mp->m_sb.sb_rsumino)) +xchk_block_set_preen (sc, bp); } -if (sb->sb_rbmino !=cpu_to_be64 (mp->m_sb.sb_rbmino)) -xchk_block_set_preen (sc, bp); - -if (sb->sb_rsumino !=cpu_to_be64 (mp->m_sb.sb_rsumino)) -xchk_block_set_preen (sc, bp); -if (sb->sb_rextsize !=cpu_to_be32 (mp->m_sb.sb_rextsize))xchk_block_set_corrupt (sc, bp);
@@ -229,11 +229,13 @@ xchk_superblock(* sb_icount, sb_ifree, sb_fdblocks, sb_frexents */ -if (sb->sb_uquotino !=cpu_to_be64 (mp->m_sb.sb_uquotino)) -xchk_block_set_preen (sc, bp); +if (!xfs_has_metadir (mp)) { +if (sb->sb_uquotino !=cpu_to_be64 (mp->m_sb.sb_uquotino)) +xchk_block_set_preen (sc, bp); -if (sb->sb_gquotino !=cpu_to_be64 (mp->m_sb.sb_gquotino)) -xchk_block_set_preen (sc, bp); +if (sb->sb_gquotino !=cpu_to_be64 (mp->m_sb.sb_gquotino)) +xchk_block_set_preen (sc, bp); + }/* * Skip the quota flags since repair will force quotacheck.
@@ -349,8 +351,10 @@ xchk_superblock(if (sb->sb_spino_align !=cpu_to_be32 (mp->m_sb.sb_spino_align))xchk_block_set_corrupt (sc, bp); -if (sb->sb_pquotino !=cpu_to_be64 (mp->m_sb.sb_pquotino)) -xchk_block_set_preen (sc, bp); +if (!xfs_has_metadir (mp)) { +if (sb->sb_pquotino !=cpu_to_be64 (mp->m_sb.sb_pquotino)) +xchk_block_set_preen (sc, bp); + }/* Don't care about sb_lsn */ }
@@ -361,6 +365,14 @@ xchk_superblock(xchk_block_set_corrupt (sc, bp); } +if (xfs_has_metadir (mp)) { +if (sb->sb_rgcount !=cpu_to_be32 (mp->m_sb.sb_rgcount)) +xchk_block_set_corrupt (sc, bp); + +if (sb->sb_rgextents !=cpu_to_be32 (mp->m_sb.sb_rgextents)) +xchk_block_set_corrupt (sc, bp); + } +/* Everything else must be zero. */ if (memchr_inv (sb +1 ,0 ,BBTOB (bp->b_length) -sizeof (struct xfs_dsb )))
PATCH 2/2 xfs: enable metadata directory feature
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable the metadata directory feature. With this feature, all metadata inodes are placed in the metadata directory, and the only inumbers in the superblock are the roots of the two directory trees.
The RT device is now sharded into a number of rtgroups, where 0 rtgroups mean that no RT extents are supported, and the traditional XFS stub RT bitmap and summary inodes don't exist. A single rtgroup gives roughly identical behavior to the traditional RT setup, but now with checksummed and self identifying free space metadata.
For quota, the quota options are read from the superblock unless explicitly overridden via mount options.
--- fs/xfs/libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_format.h +2 -1
@@ -414,7 +414,8 @@ xfs_sb_has_ro_compat_feature( XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR | \ XFS_SB_FEAT_INCOMPAT_NREXT64 | \ XFS_SB_FEAT_INCOMPAT_EXCHRANGE | \ - XFS_SB_FEAT_INCOMPAT_PARENT) + XFS_SB_FEAT_INCOMPAT_PARENT | \ + XFS_SB_FEAT_INCOMPAT_METADIR)#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL static inline bool
PATCH 1/5 xfsprogs: metadata inode directory trees
In reply to Darrick J. WongHi all,
This series delivers a new feature -- metadata inode directories. This is a separate directory tree (rooted in the superblock) that contains only inodes that contain filesystem metadata. Different metadata objects can be looked up with regular paths.
We start by creating xfs_imeta_* functions to mediate access to metadata inode pointers. This enables the imeta code to abstract inode pointers, whether they're the classic five in the superblock, or the much more complex directory tree. All current users of metadata inodes (rt+quota) are converted to use the boilerplate code.
Next, we define the metadir on-disk format, which consists of marking inodes with a new iflag that says they're metadata. This we use to prevent bulkstat and friends from ever getting their hands on fs metadata.
Finally, we implement metadir operations so that clients can create, delete, zap, and look up metadata inodes by path. Beware that much of this code is only lightly used, because the five current users of metadata inodes don't tend to change them very often. This is likely to change if and when the subvolume and multiple-rt-volume features get written/merged/etc.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=metadata-directory-tree
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=metadata-directory-tree
---
Commits in this patchset:
* libfrog: report metadata directories in the geometry report
* libfrog: allow METADIR in xfrog_bulkstat_single5
* xfs_io: support scrubbing metadata directory paths
* xfs_db: disable xfs_check when metadir is enabled
* xfs_db: report metadir support for version command
* xfs_db: don't obfuscate metadata directories and attributes
* xfs_db: support metadata directories in the path command
* xfs_db: show the metadata root directory when dumping superblocks
* xfs_db: display di_metatype
* xfs_io: support the bulkstat metadata directory flag
* xfs_io: support scrubbing metadata directory paths
* xfs_spaceman: report health of metadir inodes too
* xfs_scrub: tread zero-length read verify as an IO error
* xfs_scrub: scan metadata directories during phase 3
* xfs_scrub: re-run metafile scrubbers during phase 5
* xfs_repair: preserve the metadirino field when zeroing supers
* xfs_repair: check metadir superblock padding fields
* xfs_repair: dont check metadata directory dirent inumbers
* xfs_repair: refactor fixing dotdot
* xfs_repair: refactor marking of metadata inodes
* xfs_repair: refactor root directory initialization
* xfs_repair: refactor grabbing realtime metadata inodes
* xfs_repair: check metadata inode flag
* xfs_repair: use libxfs_metafile_iget for quota/rt inodes
* xfs_repair: rebuild the metadata directory
* xfs_repair: don't let metadata and regular files mix
* xfs_repair: update incore metadata state whenever we create new files
* xfs_repair: pass private data pointer to scan_lbtree
* xfs_repair: mark space used by metadata files
* xfs_repair: adjust keep_fsinos to handle metadata directories
* xfs_repair: metadata dirs are never plausible root dirs
* xfs_repair: drop all the metadata directory files during pass 4
* xfs_repair: truncate and unmark orphaned metadata inodes
* xfs_repair: do not count metadata directory files when doing quotacheck
* xfs_repair: fix maximum file offset comparison
* xfs_repair: refactor generate_rtinfo
* mkfs.xfs: enable metadata directories
* mkfs: add a utility to generate protofiles
--- db/check.c | 6 + db/field.c | 2 db/field.h | 1 db/inode.c | 86 ++++++- db/inode.h | 2 db/metadump.c | 385 +++++++++++++++----------------- db/namei.c | 71 +++++- db/sb.c | 32 +++ io/bulkstat.c | 16 + io/scrub.c | 62 +++++ libfrog/bulkstat.c | 3 libfrog/fsgeom.c | 6 - libfrog/scrub.c | 14 + libfrog/scrub.h | 2 libxfs/libxfs_api_defs.h | 4 man/man8/mkfs.xfs.8.in | 11 + man/man8/xfs_db.8 | 23 ++ man/man8/xfs_io.8 | 13 + man/man8/xfs_protofile.8 | 33 +++ mkfs/Makefile | 10 + mkfs/lts_4.19.conf | 1 mkfs/lts_5.10.conf | 1 mkfs/lts_5.15.conf | 1 mkfs/lts_5.4.conf | 1 mkfs/lts_6.1.conf | 1 mkfs/lts_6.6.conf | 1 mkfs/proto.c | 68 ++++++ mkfs/xfs_mkfs.c | 29 ++ mkfs/xfs_protofile.in | 152 +++++++++++++ repair/agheader.c | 5 repair/dino_chunks.c | 43 ++++ repair/dinode.c | 198 ++++++++++++++--- repair/dinode.h | 6 - repair/dir2.c | 51 ++++ repair/globals.c | 9 - repair/globals.h | 9 - repair/incore.h | 63 ++++- repair/incore_ino.c | 1 repair/phase1.c | 2 repair/phase2.c | 58 ++++- repair/phase4.c | 18 ++ repair/phase5.c | 12 + repair/phase6.c | 547 +++++++++++++++++++++++++++++++--------------- repair/pptr.c | 94 ++++++++ repair/pptr.h | 2 repair/prefetch.c | 2 repair/quotacheck.c | 22 ++ repair/rt.c | 189 ++++++++++------ repair/rt.h | 12 - repair/sb.c | 8 + repair/scan.c | 43 +++- repair/scan.h | 7 - repair/versions.c | 7 - repair/xfs_repair.c | 56 +++++ scrub/inodes.c | 11 + scrub/inodes.h | 5 scrub/phase3.c | 7 + scrub/phase5.c | 102 ++++++++- scrub/phase6.c | 24 ++ scrub/read_verify.c | 8 + scrub/scrub.c | 18 ++ scrub/scrub.h | 7 + spaceman/health.c | 2 63 files changed, 2073 insertions(+), 612 deletions(-) create mode 100644 man/man8/xfs_protofile.8 create mode 100644 mkfs/xfs_protofile.in
PATCH 1/38 libfrog: report metadata directories in the geometry report
From: Darrick J. Wong <[email protected]>
Report the presence of a metadata directory tree in the geometry report.
--- libfrog/fsgeom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
libfrog/fsgeom.c +4 -2
@@ -33,6 +33,7 @@ xfs_report_geom(int nrext64;int exchangerange;int parent; +int metadir; isint = geo->logstart >0 ; lazycount = geo->flags &XFS_FSOP_GEOM_FLAGS_LAZYSB ?1 :0 ;
@@ -53,13 +54,14 @@ xfs_report_geom( nrext64 = geo->flags &XFS_FSOP_GEOM_FLAGS_NREXT64 ?1 :0 ; exchangerange = geo->flags &XFS_FSOP_GEOM_FLAGS_EXCHANGE_RANGE ?1 :0 ; parent = geo->flags &XFS_FSOP_GEOM_FLAGS_PARENT ?1 :0 ; + metadir = geo->flags &XFS_FSOP_GEOM_FLAGS_METADIR ?1 :0 ; printf(_( "meta-data=%-22s isize=%-6d agcount=%u, agsize=%u blks\n" " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n" " =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n" " =%-22s reflink=%-4u bigtime=%u inobtcount=%u nrext64=%u\n" -" =%-22s exchange=%-3u\n" +" =%-22s exchange=%-3u metadir=%u\n" "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n" " =%-22s sunit=%-6u swidth=%u blks\n" "naming =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d, parent=%d\n"
@@ -70,7 +72,7 @@ xfs_report_geom("" , geo->sectsize, attrversion, projid32bit,"" , crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,"" , reflink_enabled, bigtime_enabled, inobtcount, nrext64, -"" , exchangerange, +"" , exchangerange, metadir,"" , geo->blocksize, (unsigned long long )geo->datablocks, geo->imaxpct, "", geo->sunit, geo->swidth,
PATCH 2/38 libfrog: allow METADIR in xfrog_bulkstat_single5
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
This is a valid flag for a single-file bulkstat, so add that to the filter.
--- libfrog/bulkstat.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libfrog/bulkstat.c +2 -1
@@ -53,7 +53,8 @@ xfrog_bulkstat_single5(struct xfs_bulkstat_req *req;int ret; -if (flags & ~(XFS_BULK_IREQ_SPECIAL |XFS_BULK_IREQ_NREXT64 )) +if (flags & ~(XFS_BULK_IREQ_SPECIAL |XFS_BULK_IREQ_NREXT64 | +XFS_BULK_IREQ_METADIR ))return -EINVAL ;if (xfd->fsgeom.flags &XFS_FSOP_GEOM_FLAGS_NREXT64 )
PATCH 3/38 xfs_io: support scrubbing metadata directory paths
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support invoking the metadata directory path scrubber from xfs_io for testing.
--- libfrog/scrub.c | 14 +++++++++++++- libfrog/scrub.h | 2 ++ scrub/scrub.c | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)
libfrog/scrub.c +13 -1
@@ -154,8 +154,20 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { .descr = "directory tree structure", .group = XFROG_SCRUB_GROUP_INODE, }, + [XFS_SCRUB_TYPE_METAPATH] = { + .name = "metapath", + .descr = "metadata directory paths", + .group = XFROG_SCRUB_GROUP_METAPATH, + }, +}; + +const struct xfrog_scrub_descr xfrog_metapaths[XFS_SCRUB_METAPATH_NR ] = { + [XFS_SCRUB_METAPATH_PROBE ] = { + .name ="probe" , + .descr ="metapath" , + .group =XFROG_SCRUB_GROUP_NONE , + }, }; -#undef DEP/* Invoke the scrub ioctl. Returns zero or negative error code. */ int
libfrog/scrub.h +2 -0
@@ -15,6 +15,7 @@ enum xfrog_scrub_group {XFROG_SCRUB_GROUP_INODE ,/* per-inode metadata */ XFROG_SCRUB_GROUP_ISCAN ,/* metadata requiring full inode scan */ XFROG_SCRUB_GROUP_SUMMARY ,/* summary metadata */ + XFROG_SCRUB_GROUP_METAPATH, /* metadata directory path */ };/* Catalog of scrub types and names, indexed by XFS_SCRUB_TYPE_* */
@@ -25,6 +26,7 @@ struct xfrog_scrub_descr { };extern const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR ]; +extern const struct xfrog_scrub_descr xfrog_metapaths[XFS_SCRUB_METAPATH_NR ];int xfrog_scrub_metadata (struct xfs_fd *xfd,struct xfs_scrub_metadata *meta);
scrub/scrub.c +18 -0
@@ -53,6 +53,22 @@ static const unsigned int scrub_deps[XFS_SCRUB_TYPE_NR] = { };#undef DEP +static int +format_metapath_descr ( +char *buf, +size_t buflen, +struct xfs_scrub_vec_head *vhead) +{ +const struct xfrog_scrub_descr *sc; + +if (vhead->svh_ino >=XFS_SCRUB_METAPATH_NR ) +return snprintf (buf, buflen,_ ("unknown metadir path %llu" ), + (unsigned long long )vhead->svh_ino); + + sc = &xfrog_metapaths[vhead->svh_ino]; +return snprintf (buf, buflen,"%s" ,_ (sc->descr)); +} +/* Describe the current state of a vectored scrub. */ int format_scrubv_descr(
@@ -89,6 +105,8 @@ format_scrubv_descr(case XFROG_SCRUB_GROUP_ISCAN :case XFROG_SCRUB_GROUP_NONE :return snprintf (buf, buflen,_ ("%s" ),_ (sc->descr)); +case XFROG_SCRUB_GROUP_METAPATH : +return format_metapath_descr (buf, buflen, vhead); }return -1 ; }
PATCH 4/38 xfs_db: disable xfs_check when metadir is enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
As of July 2024, xfs_repair can detect more types of corruptions than xfs_check does. I don't think it makes sense to maintain the xfs_check code anymore, so let's just turn it off for any filesystem that has metadata directory trees.
--- db/check.c | 6 ++++++ 1 file changed, 6 insertions(+)
db/check.c +6 -0
@@ -831,6 +831,12 @@ blockget_f( dbprefix = oldprefix;return 0 ; } + +if (xfs_has_metadir (mp)) { + dbprefix = oldprefix; +return 0 ; + } +check_rootdir ();/* * Check that there are no blocks either
PATCH 5/38 xfs_db: report metadir support for version command
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Report metadir support if we have it enabled.
--- db/inode.c | 3 +++ db/sb.c | 2 ++ 2 files changed, 5 insertions(+)
db/inode.c +3 -0
@@ -207,6 +207,9 @@ const field_t inode_v3_flds[] = { {"nrext64" ,FLDT_UINT1 ,OI (COFF (flags2) +bitsz (uint64_t) -XFS_DIFLAG2_NREXT64_BIT -1 ),C1 , 0, TYP_NONE }, + { "metadata", FLDT_UINT1, +OI (COFF (flags2) +bitsz (uint64_t) -XFS_DIFLAG2_METADATA_BIT -1 ),C1 , + 0, TYP_NONE }, { NULL } };
db/sb.c +2 -0
@@ -711,6 +711,8 @@ version_string(strcat (s,",EXCHANGE" );if (xfs_has_parent (mp))strcat (s,",PARENT" ); +if (xfs_has_metadir (mp)) +strcat (s,",METADIR" );return s; }
PATCH 6/38 xfs_db: don't obfuscate metadata directories and attributes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Don't obfuscate the directory and attribute names of metadata inodes.
--- db/metadump.c | 385 +++++++++++++++++++++++++++------------------------------ 1 file changed, 183 insertions(+), 202 deletions(-)
db/metadump.c +183 -202
@@ -1056,10 +1056,26 @@ generate_obfuscated_name(free (orig_name); } +static inline bool +is_metadata_ino ( +struct xfs_dinode *dip) +{ +if (!xfs_has_metadir (mp) || dip->di_version <3 ) +return false; +return dip->di_flags2 &cpu_to_be64 (XFS_DIFLAG2_METADATA ); +} + +static inline bool +want_obfuscate_dirents (bool is_meta) +{ +return metadump.obfuscate && !is_meta; +} +static void process_sf_dir (struct xfs_dinode *dip) { +bool is_meta =is_metadata_ino (dip);struct xfs_dir2_sf_hdr *sfp;xfs_dir2_sf_entry_t *sfep;uint64_t ino_dir_size;
@@ -1105,7 +1121,7 @@ process_sf_dir( (char *)sfp); } -if (metadump.obfuscate) +if (want_obfuscate_dirents (is_meta))generate_obfuscated_name (libxfs_dir2_sf_get_ino (mp, sfp, sfep), namelen, &sfep->name[0 ]);
@@ -1201,7 +1217,8 @@ maybe_obfuscate_pptr(uint8_t *name, int namelen, const void *value, - int valuelen) + int valuelen, + bool is_meta) { unsigned char old_name[MAXNAMELEN];struct remap_ent *remap;
@@ -1210,7 +1227,7 @@ maybe_obfuscate_pptr(xfs_ino_t parent_ino;int error; -if (!metadump.obfuscate) +if (!metadump.obfuscate || is_meta)return ;if (!(attr_flags &XFS_ATTR_PARENT ))
@@ -1274,9 +1291,10 @@ want_obfuscate_attr(const void *name, unsigned int namelen, const void *value, - unsigned int valuelen) + unsigned int valuelen, + bool is_meta) { - if (!metadump.obfuscate) + if (!metadump.obfuscate || is_meta) return false;/*
@@ -1289,15 +1307,15 @@ want_obfuscate_attr(return true; } +/* +* Obfuscate the attr names and fill the actual values with 'v' (to see a valid +* string length, as opposed to NULLs). +*/ static void process_sf_attr (struct xfs_dinode *dip) { -/* -* with extended attributes, obfuscate the names and fill the actual -* values with 'v' (to see a valid string length, as opposed to NULLs) -*/ - +bool is_meta =is_metadata_ino (dip);struct xfs_attr_sf_hdr *hdr =XFS_DFORK_APTR (dip);struct xfs_attr_sf_entry *asfep =libxfs_attr_sf_firstentry (hdr);int ino_attr_size;
@@ -1338,9 +1356,9 @@ process_sf_attr(if (asfep->flags &XFS_ATTR_PARENT ) {maybe_obfuscate_pptr (asfep->flags, name, namelen, - value, asfep->valuelen); + value, asfep->valuelen, is_meta); }else if (want_obfuscate_attr (asfep->flags, name, namelen, - value, asfep->valuelen)) { + value, asfep->valuelen, is_meta)) {generate_obfuscated_name (0 , asfep->namelen, name);memset (value,'v' , asfep->valuelen); }
@@ -1442,7 +1460,8 @@ static voidprocess_dir_data_block ( char *block, xfs_fileoff_t offset, - int is_block_format) + int is_block_format, + bool is_meta) {/* * we have to rely on the fileoffset and signature of the block to
@@ -1549,7 +1568,7 @@ process_dir_data_block( dir_offset)return ; -if (metadump.obfuscate) +if (want_obfuscate_dirents (is_meta))generate_obfuscated_name (be64_to_cpu (dep->inumber), dep->namelen, &dep->name[0 ]); dir_offset += length;
@@ -1574,7 +1593,8 @@ process_symlink_block(xfs_fsblock_t s, xfs_filblks_t c, typnm_t btype, - xfs_fileoff_t last) + xfs_fileoff_t last, + bool is_meta) { struct bbmap map;char *link;
@@ -1599,7 +1619,7 @@ process_symlink_block(if (xfs_has_crc ((mp))) link +=sizeof (struct xfs_dsymlink_hdr ); -if (metadump.obfuscate) +if (want_obfuscate_dirents (is_meta))obfuscate_path_components (link,XFS_SYMLINK_BUF_SPACE (mp, mp->m_sb.sb_blocksize));if (metadump.zero_stale_data) {
@@ -1650,7 +1670,8 @@ add_remote_vals(static void process_attr_block (char *block, -xfs_fileoff_t offset) +xfs_fileoff_t offset, +bool is_meta) {struct xfs_attr_leafblock *leaf;struct xfs_attr3_icleaf_hdr hdr;
@@ -1730,10 +1751,10 @@ process_attr_block(if (entry->flags &XFS_ATTR_PARENT ) {maybe_obfuscate_pptr (entry->flags, name, local->namelen, value, - valuelen); + valuelen, is_meta); }else if (want_obfuscate_attr (entry->flags, name, local->namelen, value, - valuelen)) { + valuelen, is_meta)) {generate_obfuscated_name (0 , local->namelen, name);memset (value,'v' , valuelen);
@@ -1759,7 +1780,7 @@ process_attr_block(/* do not obfuscate obviously busted pptr */ add_remote_vals (be32_to_cpu (remote->valueblk),be32_to_cpu (remote->valuelen)); - }else if (metadump.obfuscate) { + }else if (want_obfuscate_dirents (is_meta)) {generate_obfuscated_name (0 , remote->namelen, &remote->name[0 ]); add_remote_vals(be32_to_cpu(remote->valueblk),
@@ -1792,7 +1813,8 @@ process_single_fsb_objects(xfs_fsblock_t s, xfs_filblks_t c, typnm_t btype, - xfs_fileoff_t last) + xfs_fileoff_t last, + bool is_meta) { int rval = 1;char *dp;
@@ -1862,12 +1884,13 @@ process_single_fsb_objects(process_dir_leaf_block (dp); }else {process_dir_data_block (dp, o, - last == mp->m_dir_geo->fsbcount); + last == mp->m_dir_geo->fsbcount, + is_meta); } iocur_top->need_crc =1 ;break ;case TYP_ATTR : -process_attr_block (dp, o); +process_attr_block (dp, o, is_meta); iocur_top->need_crc =1 ;break ;default :
@@ -1900,7 +1923,8 @@ process_multi_fsb_dir(xfs_fsblock_t s, xfs_filblks_t c, typnm_t btype, - xfs_fileoff_t last) + xfs_fileoff_t last, + bool is_meta) { char *dp;int rval =1 ;
@@ -1944,7 +1968,8 @@ process_multi_fsb_dir(process_dir_leaf_block (dp); }else {process_dir_data_block (dp, o, - last == mp->m_dir_geo->fsbcount); + last == mp->m_dir_geo->fsbcount, + is_meta); } iocur_top->need_crc =1 ; write:
@@ -1963,6 +1988,38 @@ process_multi_fsb_dir(return rval; } +static typnm_t +ifork_data_type ( +struct xfs_dinode *dip, +int whichfork) +{ +xfs_ino_t ino =be64_to_cpu (dip->di_ino); + +if (whichfork ==XFS_ATTR_FORK ) +return TYP_ATTR ; + +switch (be16_to_cpu (dip->di_mode) &S_IFMT ) { +case S_IFDIR : +return TYP_DIR2 ; +case S_IFLNK : +return TYP_SYMLINK ; +case S_IFREG : +if (ino == mp->m_sb.sb_rbmino) +return TYP_RTBITMAP ; +if (ino == mp->m_sb.sb_rsumino) +return TYP_RTSUMMARY ; +if (ino == mp->m_sb.sb_uquotino) +return TYP_DQBLK ; +if (ino == mp->m_sb.sb_gquotino) +return TYP_DQBLK ; +if (ino == mp->m_sb.sb_pquotino) +return TYP_DQBLK ; +return TYP_DATA ; +default : +return TYP_NONE ; + } +} + static bool is_multi_fsb_object( struct xfs_mount *mp,
@@ -1981,13 +2038,14 @@ process_multi_fsb_objects(xfs_fsblock_t s, xfs_filblks_t c, typnm_t btype, - xfs_fileoff_t last) + xfs_fileoff_t last, + bool is_meta) { switch (btype) { case TYP_DIR2: - return process_multi_fsb_dir(o, s, c, btype, last); + return process_multi_fsb_dir(o, s, c, btype, last, is_meta);case TYP_SYMLINK : -return process_symlink_block (o, s, c, btype, last); +return process_symlink_block (o, s, c, btype, last, is_meta);default :print_warning ("bad type for multi-fsb object %d" , btype);return 1 ;
@@ -1997,10 +2055,13 @@ process_multi_fsb_objects(/* inode copy routines */ static int process_bmbt_reclist ( -xfs_bmbt_rec_t *rp, -int numrecs, -typnm_t btype) +struct xfs_dinode *dip, +int whichfork, +struct xfs_bmbt_rec *rp, +int numrecs) { +bool is_meta =is_metadata_ino (dip); +typnm_t btype =ifork_data_type (dip, whichfork);int i;xfs_fileoff_t o, op =NULLFILEOFF ;xfs_fsblock_t s;
@@ -2009,7 +2070,6 @@ process_bmbt_reclist(xfs_fileoff_t last;xfs_agnumber_t agno;xfs_agblock_t agbno; -bool is_multi_fsb =is_multi_fsb_object (mp, btype);int rval =1 ;if (btype ==TYP_DATA )
@@ -2077,12 +2137,12 @@ process_bmbt_reclist( }/* multi-extent blocks require special handling */ -if (is_multi_fsb) +if (is_multi_fsb_object (mp, btype)) rval =process_multi_fsb_objects (o, s, c, btype, - last); + last, is_meta);else rval =process_single_fsb_objects (o, s, c, btype, - last); + last, is_meta);if (!rval)break ; }
@@ -2090,6 +2150,11 @@ process_bmbt_reclist(return rval; } +struct scan_bmap { +struct xfs_dinode *dip; +int whichfork; +}; + static int scanfunc_bmap( struct xfs_btree_block *block,
@@ -2097,8 +2162,9 @@ scanfunc_bmap(xfs_agblock_t agbno, int level, typnm_t btype, - void *arg) /* ptr to itype */ + void *arg) { + struct scan_bmap *sbm = arg;int i;xfs_bmbt_ptr_t *pp;int nrecs;
@@ -2113,8 +2179,8 @@ scanfunc_bmap( typtab[btype].name, agno, agbno);return 1 ; } -return process_bmbt_reclist (xfs_bmbt_rec_addr (mp, block,1 ), - nrecs, *(typnm_t *)arg); +return process_bmbt_reclist (sbm->dip, sbm->whichfork, +xfs_bmbt_rec_addr (mp, block,1 ), nrecs); }if (nrecs > mp->m_bmap_dmxr[1 ]) {
@@ -2149,23 +2215,17 @@ scanfunc_bmap(static int process_btinode (struct xfs_dinode *dip, -typnm_t itype) +int whichfork) { -xfs_bmdr_block_t *dib; -int i; -xfs_bmbt_ptr_t *pp; -int level; -int nrecs; +struct xfs_bmdr_block *dib = + (struct xfs_bmdr_block *)XFS_DFORK_PTR (dip, whichfork); +int level =be16_to_cpu (dib->bb_level); +int nrecs =be16_to_cpu (dib->bb_numrecs);int maxrecs; -int whichfork; -typnm_t btype; - - whichfork = (itype ==TYP_ATTR ) ?XFS_ATTR_FORK :XFS_DATA_FORK ; - btype = (itype ==TYP_ATTR ) ?TYP_BMAPBTA :TYP_BMAPBTD ; - - dib = (xfs_bmdr_block_t *)XFS_DFORK_PTR (dip, whichfork); - level =be16_to_cpu (dib->bb_level); - nrecs =be16_to_cpu (dib->bb_numrecs); +typnm_t btype = (whichfork ==XFS_ATTR_FORK ) ? +TYP_BMAPBTA :TYP_BMAPBTD ; +xfs_bmbt_ptr_t *pp; +int i;if (level >XFS_BM_MAXLEVELS (mp, whichfork)) {if (metadump.show_warnings)
@@ -2176,8 +2236,8 @@ process_btinode( }if (level ==0 ) { -return process_bmbt_reclist (xfs_bmdr_rec_addr (dib,1 ), - nrecs, itype); +return process_bmbt_reclist (dip, whichfork, +xfs_bmdr_rec_addr (dib,1 ), nrecs); } maxrecs =libxfs_bmdr_maxrecs (XFS_DFORK_SIZE (dip, mp, whichfork),0 );
@@ -2204,6 +2264,10 @@ process_btinode( }for (i =0 ; i < nrecs; i++) { +struct scan_bmap sbm = { + .dip = dip, + .whichfork = whichfork, + };xfs_agnumber_t ag;xfs_agblock_t bno;
@@ -2220,7 +2284,7 @@ process_btinode(continue ; } -if (!scan_btree (ag, bno, level, btype, &itype, scanfunc_bmap)) +if (!scan_btree (ag, bno, level, btype, &sbm, scanfunc_bmap))return 0 ; }return 1 ;
@@ -2229,19 +2293,13 @@ process_btinode(static int process_exinode (struct xfs_dinode *dip, -typnm_t itype) +int whichfork) { -int whichfork; -int used; -xfs_extnum_t nex, max_nex; +xfs_extnum_t max_nex =xfs_iext_max_nextents ( +xfs_dinode_has_large_extent_counts (dip), whichfork); +xfs_extnum_t nex =xfs_dfork_nextents (dip, whichfork); +int used = nex *sizeof (struct xfs_bmbt_rec ); - whichfork = (itype ==TYP_ATTR ) ?XFS_ATTR_FORK :XFS_DATA_FORK ; - - nex =xfs_dfork_nextents (dip, whichfork); - max_nex =xfs_iext_max_nextents ( -xfs_dinode_has_large_extent_counts (dip), - whichfork); - used = nex *sizeof (xfs_bmbt_rec_t);if (nex > max_nex || used >XFS_DFORK_SIZE (dip, mp, whichfork)) {if (metadump.show_warnings) print_warning("bad number of extents %llu in inode %lld",
@@ -2257,52 +2315,52 @@ process_exinode( XFS_DFORK_SIZE(dip, mp, whichfork) - used); -return process_bmbt_reclist ((xfs_bmbt_rec_t *)XFS_DFORK_PTR (dip, - whichfork), nex, itype); +return process_bmbt_reclist (dip, whichfork, + (struct xfs_bmbt_rec *)XFS_DFORK_PTR (dip, whichfork), + nex); }static int process_inode_data ( -struct xfs_dinode *dip, -typnm_t itype) +struct xfs_dinode *dip) {switch (dip->di_format) { -case XFS_DINODE_FMT_LOCAL : -if (!(metadump.obfuscate || metadump.zero_stale_data)) -break ; +case XFS_DINODE_FMT_LOCAL : +if (!(metadump.obfuscate || metadump.zero_stale_data)) +break ; -/* -* If the fork size is invalid, we can't safely do -* anything with this fork. Leave it alone to preserve -* the information for diagnostic purposes. -*/ -if (XFS_DFORK_DSIZE (dip, mp) >XFS_LITINO (mp)) { -print_warning ( +/* +* If the fork size is invalid, we can't safely do anything +* with this fork. Leave it alone to preserve the information +* for diagnostic purposes. +*/ +if (XFS_DFORK_DSIZE (dip, mp) >XFS_LITINO (mp)) { +print_warning ("Invalid data fork size (%d) in inode %llu, preserving contents!" , -XFS_DFORK_DSIZE (dip, mp), - (long long )metadump.cur_ino); -break ; - } +XFS_DFORK_DSIZE (dip, mp), + (long long )metadump.cur_ino); +break ; + } -switch (itype) { -case TYP_DIR2 : -process_sf_dir (dip); -break ; +switch (be16_to_cpu (dip->di_mode) &S_IFMT ) { +case S_IFDIR : +process_sf_dir (dip); +break ; -case TYP_SYMLINK : -process_sf_symlink (dip); -break ; +case S_IFLNK : +process_sf_symlink (dip); +break ; -default : -break ; - } +default :break ; + } +break ; -case XFS_DINODE_FMT_EXTENTS : -return process_exinode (dip, itype); +case XFS_DINODE_FMT_EXTENTS : +return process_exinode (dip,XFS_DATA_FORK ); -case XFS_DINODE_FMT_BTREE : -return process_btinode (dip, itype); +case XFS_DINODE_FMT_BTREE : +return process_btinode (dip,XFS_DATA_FORK ); }return 1 ; }
@@ -2375,28 +2433,22 @@ process_inode(/* copy appropriate data fork metadata */ switch (be16_to_cpu (dip->di_mode) &S_IFMT ) { -case S_IFDIR : - rval =process_inode_data (dip,TYP_DIR2 ); -if (dip->di_format ==XFS_DINODE_FMT_LOCAL ) - need_new_crc = true; -break ; -case S_IFLNK : - rval =process_inode_data (dip,TYP_SYMLINK ); -if (dip->di_format ==XFS_DINODE_FMT_LOCAL ) - need_new_crc = true; -break ; -case S_IFREG : - rval =process_inode_data (dip,TYP_DATA ); -break ; -case S_IFIFO : -case S_IFCHR : -case S_IFBLK : -case S_IFSOCK : -process_dev_inode (dip); +case S_IFDIR : +case S_IFLNK : +case S_IFREG : + rval =process_inode_data (dip); +if (dip->di_format ==XFS_DINODE_FMT_LOCAL ) need_new_crc = true; -break ; -default : -break ; +break ; +case S_IFIFO : +case S_IFCHR : +case S_IFBLK : +case S_IFSOCK : +process_dev_inode (dip); + need_new_crc = true; +break ; +default : +break ; }nametable_clear ();if (!rval)
@@ -2406,20 +2458,17 @@ process_inode(if (XFS_DFORK_DSIZE (dip, mp) <XFS_LITINO (mp)) { attr_data.remote_val_count =0 ;switch (dip->di_aformat) { -case XFS_DINODE_FMT_LOCAL : - need_new_crc = true; -if (metadump.obfuscate || - metadump.zero_stale_data) -process_sf_attr (dip); -break ; - -case XFS_DINODE_FMT_EXTENTS : - rval =process_exinode (dip,TYP_ATTR ); -break ; - -case XFS_DINODE_FMT_BTREE : - rval =process_btinode (dip,TYP_ATTR ); -break ; +case XFS_DINODE_FMT_LOCAL : + need_new_crc = true; +if (metadump.obfuscate || metadump.zero_stale_data) +process_sf_attr (dip); +break ; +case XFS_DINODE_FMT_EXTENTS : + rval =process_exinode (dip,XFS_ATTR_FORK ); +break ; +case XFS_DINODE_FMT_BTREE : + rval =process_btinode (dip,XFS_ATTR_FORK ); +break ; }nametable_clear (); }
@@ -2796,70 +2845,6 @@ scan_ag(return rval; } -static int -copy_ino ( -xfs_ino_t ino, -typnm_t itype) -{ -xfs_agnumber_t agno; -xfs_agblock_t agbno; -xfs_agino_t agino; -int offset; -int rval =1 ; - -if (ino ==0 || ino ==NULLFSINO ) -return 1 ; - - agno =XFS_INO_TO_AGNO (mp, ino); - agino =XFS_INO_TO_AGINO (mp, ino); - agbno =XFS_AGINO_TO_AGBNO (mp, agino); - offset =XFS_AGINO_TO_OFFSET (mp, agino); - -if (agno >= mp->m_sb.sb_agcount || agbno >= mp->m_sb.sb_agblocks || - offset >= mp->m_sb.sb_inopblock) { -if (metadump.show_warnings) -print_warning ("invalid %s inode number (%lld)" , - typtab[itype].name, (long long )ino); -return 1 ; - } - -push_cur (); -set_cur (&typtab[TYP_INODE ],XFS_AGB_TO_DADDR (mp, agno, agbno), - blkbb,DB_RING_IGN ,NULL ); -if (iocur_top->data ==NULL ) { -print_warning ("cannot read %s inode %lld" , - typtab[itype].name, (long long )ino); - rval = !metadump.stop_on_read_error; - goto pop_out; - } -off_cur (offset << mp->m_sb.sb_inodelog, mp->m_sb.sb_inodesize); - - metadump.cur_ino = ino; - rval =process_inode_data (iocur_top->data, itype); -pop_out: -pop_cur (); -return rval; -} - - -static int -copy_sb_inodes (void ) -{ -if (!copy_ino (mp->m_sb.sb_rbmino,TYP_RTBITMAP )) -return 0 ; - -if (!copy_ino (mp->m_sb.sb_rsumino,TYP_RTSUMMARY )) -return 0 ; - -if (!copy_ino (mp->m_sb.sb_uquotino,TYP_DQBLK )) -return 0 ; - -if (!copy_ino (mp->m_sb.sb_gquotino,TYP_DQBLK )) -return 0 ; - -return copy_ino (mp->m_sb.sb_pquotino,TYP_DQBLK ); -} -static int copy_log (void ) {
@@ -3296,10 +3281,6 @@ metadump_f( } } -/* copy realtime and quota inode contents */ -if (!exitcode) - exitcode = !copy_sb_inodes (); -/* copy log */ if (!exitcode && !(metadump.version ==1 && metadump.external_log)) exitcode = !copy_log ();
PATCH 7/38 xfs_db: support metadata directories in the path command
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach various directory tree debugger commands to traverse the metadata directory tree by adding a -m switch to select that tree.
--- db/namei.c | 71 ++++++++++++++++++++++++++++++++++++++++++++--------- man/man8/xfs_db.8 | 23 ++++++++++++++--- 2 files changed, 78 insertions(+), 16 deletions(-)
db/namei.c +59 -12
@@ -139,11 +139,11 @@ path_navigate(/* Walk a directory path to an inode and set the io cursor to that inode. */ static int path_walk ( +xfs_ino_t rootino,char *path) {struct dirpath *dirpath;char *p = path; -xfs_ino_t rootino = mp->m_sb.sb_rootino;int error =0 ;if (*p =='/' ) {
@@ -173,6 +173,9 @@ path_help(void)dbprintf (_ ("\n" " Navigate to an inode via directory path.\n" +"\n" +" Options:\n" +" -m -- Walk an absolute path down the metadata directory tree.\n" )); }
@@ -181,18 +184,34 @@ path_f(int argc, char **argv) { + xfs_ino_t rootino = mp->m_sb.sb_rootino;int c;int error; -while ((c =getopt (argc, argv,"" )) !=-1 ) { +while ((c =getopt (argc, argv,"m" )) !=-1 ) {switch (c) { +case 'm' : +/* Absolute path, start from metadata rootdir. */ +if (!xfs_has_metadir (mp)) { +dbprintf ( +_ ("filesystem does not support metadata directories.\n" )); + exitcode =1 ; +return 0 ; + } + rootino = mp->m_sb.sb_metadirino; +break ;default :path_help ();return 0 ; } } - error =path_walk (argv[optind]); +if (argc == optind || argc > optind +1 ) { +dbprintf (_ ("Only supply one path.\n" )); +return -1 ; + } + + error =path_walk (rootino, argv[optind]);if (error) {dbprintf ("%s: %s\n" , argv[optind],strerror (error)); exitcode =1 ;
@@ -206,7 +225,7 @@ static struct cmdinfo path_cmd = { .altname = NULL, .cfunc = path_f, .argmin = 1, - .argmax = 1, + .argmax = -1, .canpush = 0, .args = "", .help = path_help,
@@ -519,6 +538,7 @@ ls_help(void)" Options:\n" " -i -- Resolve the given paths to their corresponding inode numbers.\n" " If no paths are given, display the current inode number.\n" +" -m -- Walk an absolute path down the metadata directory tree.\n" "\n" " Directory contents will be listed in the format:\n" " dir_cookie inode_number type hash name_length name\n"
@@ -530,15 +550,26 @@ ls_f(int argc, char **argv) { + xfs_ino_t rootino = mp->m_sb.sb_rootino;bool inum_only = false;int c;int error =0 ; -while ((c =getopt (argc, argv,"i" )) !=-1 ) { +while ((c =getopt (argc, argv,"im" )) !=-1 ) {switch (c) {case 'i' : inum_only = true;break ; +case 'm' : +/* Absolute path, start from metadata rootdir. */ +if (!xfs_has_metadir (mp)) { +dbprintf ( +_ ("filesystem does not support metadata directories.\n" )); + exitcode =1 ; +return 0 ; + } + rootino = mp->m_sb.sb_metadirino; +break ;default :ls_help ();return 0 ;
@@ -561,7 +592,7 @@ ls_f(for (c = optind; c < argc; c++) {push_cur (); - error =path_walk (argv[c]); + error =path_walk (rootino, argv[c]);if (error) goto err_cur;
@@ -860,11 +891,22 @@ parent_f(int argc, char **argv) { + xfs_ino_t rootino = mp->m_sb.sb_rootino;int c;int error =0 ; -while ((c =getopt (argc, argv,"" )) !=-1 ) { +while ((c =getopt (argc, argv,"m" )) !=-1 ) {switch (c) { +case 'm' : +/* Absolute path, start from metadata rootdir. */ +if (!xfs_has_metadir (mp)) { +dbprintf ( +_ ("filesystem does not support metadata directories.\n" )); + exitcode =1 ; +return 0 ; + } + rootino = mp->m_sb.sb_metadirino; +break ;default :ls_help ();return 0 ;
@@ -884,7 +926,7 @@ parent_f(for (c = optind; c < argc; c++) {push_cur (); - error =path_walk (argv[c]); + error =path_walk (rootino, argv[c]);if (error) goto err_cur;
@@ -912,7 +954,7 @@ static struct cmdinfo parent_cmd = { .argmin = 0, .argmax = -1, .canpush = 0, - .args = "[paths...]", + .args = "[-m] [paths...]", .help = parent_help, };
@@ -926,6 +968,7 @@ link_help(void)"\n" " Options:\n" " -i -- Point to this specific inode number.\n" +" -m -- Select the metadata directory tree.\n" " -p -- Point to the inode given by this path.\n" " -t -- Set the file type to this value.\n" " name -- Create this directory entry with this name.\n"
@@ -1039,11 +1082,12 @@ link_f( {xfs_ino_t child_ino =NULLFSINO ;int ftype =XFS_DIR3_FT_UNKNOWN ; +xfs_ino_t rootino = mp->m_sb.sb_rootino;unsigned int i;int c;int error =0 ; -while ((c =getopt (argc, argv,"i:p:t:" )) !=-1 ) { +while ((c =getopt (argc, argv,"i:mp:t:" )) !=-1 ) {switch (c) {case 'i' : errno =0 ;
@@ -1054,9 +1098,12 @@ link_f(return 0 ; }break ; +case 'm' : + rootino = mp->m_sb.sb_metadirino; +break ;case 'p' :push_cur (); - error =path_walk (optarg); + error =path_walk (rootino, optarg);if (error) {printf ("%s: %s\n" , optarg,strerror (error)); exitcode =1 ;
@@ -1126,7 +1173,7 @@ static struct cmdinfo link_cmd = { .argmin = 0, .argmax = -1, .canpush = 0, - .args = "[-i ino] [-p path] [-t ftype] name", + .args = "[-i ino] [-m] [-p path] [-t ftype] name", .help = link_help, };
man/man8/xfs_db.8 +19 -4
@@ -992,7 +992,7 @@ .SH COMMANDS .I label is given, the current filesystem label is printed. .TP -.BI "link [-i " ino "] [-p " path "] [-t " ftype "] name" +.BI "link [-i " ino "] [-m] [-p " path "] [-t " ftype "] name" In the current directory, create a directory entry with the given .I name pointing to a file.
@@ -1005,6 +1005,10 @@ .SH COMMANDS child file unless the .I ftype option is given. +The +.B -m +option specifies that the path lookup should be done in the metadata directory +tree. The file being targetted must not be on the iunlink list. .TP .BI "log [stop | start " filename ]
@@ -1039,7 +1043,7 @@ .SH COMMANDS between xfsprogs and the kernel, which will help when diagnosing minimum log size calculation errors. .TP -.BI "ls [\-i] [" paths "]..." +.BI "ls [\-im] [" paths "]..." List the contents of a directory. If a path resolves to a directory, the directory will be listed. If no paths are supplied and the IO cursor points at a directory inode,
@@ -1053,6 +1057,9 @@ .SH COMMANDS Resolve each of the given paths to an inode number and print that number. If no paths are given and the IO cursor points to an inode, print the inode number. +.TP +.B \-m +Absolute paths should be walked from the root of the metadata directory tree. .RE .TP .BI "metadump [\-egow] " filename
@@ -1080,18 +1087,26 @@ .SH COMMANDS .B print command. .TP -.BI "parent [" paths "]..." +.BI "parent [\-m] [" paths "]..." List the parents of a file. If a path resolves to a file, the parents of that file will be listed. If no paths are supplied and the IO cursor points at an inode, the parents of that file will be listed. +The +.B \-m +option causes absolute paths to be walked from the root of the metadata +directory tree. The output format is: inode number, inode generation, ondisk namehash, namehash, name length, name. .TP -.BI "path " dir_path +.BI "path [\-m] " dir_path Walk the directory tree to an inode using the supplied path. Absolute and relative paths are supported. +The +.B \-m +option causes absolute paths to be walked from the root of the metadata +directory tree. .TP .B pop Pop location from the stack.
PATCH 8/38 xfs_db: show the metadata root directory when dumping superblocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Show the metadirino field when appropriate.
--- db/sb.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
db/sb.c +29 -1
@@ -50,6 +50,30 @@ sb_init(void)add_command (&version_cmd); } +/* +* Counts superblock fields that only exist when the metadata directory feature +* is enabled. +*/ +static int +metadirfld_count ( +void *obj, +int startoff) +{ +return xfs_has_metadir (mp) ?1 :0 ; +} + +/* +* Counts superblock fields that do not exist when the metadata directory +* feature is enabled. +*/ +static int +premetadirfld_count ( +void *obj, +int startoff) +{ +return xfs_has_metadir (mp) ?0 :1 ; +} +#define OFF (f) bitize(offsetof(struct xfs_dsb, sb_ ## f))#define SZC (f) szcount(struct xfs_dsb, sb_ ## f)const field_t sb_flds[] = {
@@ -99,7 +123,9 @@ const field_t sb_flds[] = { { "logsunit", FLDT_UINT32D, OI(OFF(logsunit)), C1, 0, TYP_NONE }, { "features2", FLDT_UINT32X, OI(OFF(features2)), C1, 0, TYP_NONE }, { "bad_features2", FLDT_UINT32X, OI(OFF(bad_features2)), - C1, 0, TYP_NONE }, + premetadirfld_count, FLD_COUNT, TYP_NONE }, + { "metadirpad", FLDT_UINT32X, OI(OFF(metadirpad)), metadirfld_count, + FLD_COUNT, TYP_NONE }, { "features_compat", FLDT_UINT32X, OI(OFF(features_compat)), C1, 0, TYP_NONE }, { "features_ro_compat", FLDT_UINT32X, OI(OFF(features_ro_compat)),
@@ -113,6 +139,8 @@ const field_t sb_flds[] = { { "pquotino", FLDT_INO, OI(OFF(pquotino)), C1, 0, TYP_INODE }, { "lsn", FLDT_UINT64X, OI(OFF(lsn)), C1, 0, TYP_NONE }, { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, + { "metadirino", FLDT_INO, OI(OFF(metadirino)), metadirfld_count, + FLD_COUNT, TYP_INODE }, { NULL } };
PATCH 9/38 xfs_db: display di_metatype
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Print the metadata file type if available.
--- db/field.c | 2 + db/field.h | 1 + db/inode.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- db/inode.h | 2 + 4 files changed, 78 insertions(+), 10 deletions(-)
db/field.c +2 -0
@@ -212,6 +212,8 @@ const ftattr_t ftattrtab[] = { SI(bitsz(struct xfs_dinode)), 0, NULL, inode_core_flds }, { FLDT_DINODE_FMT, "dinode_fmt", fp_dinode_fmt, NULL, SI(bitsz(int8_t)), 0, NULL, NULL }, + { FLDT_DINODE_METATYPE, "metatype", fp_metatype, NULL, + SI(bitsz(uint16_t)), 0, NULL, NULL }, { FLDT_DINODE_U, "dinode_u", NULL, (char *)inode_u_flds, inode_u_size, FTARG_SIZE|FTARG_OKEMPTY, NULL, inode_u_flds }, { FLDT_DINODE_V3, "dinode_v3", NULL, (char *)inode_v3_flds,
db/field.h +1 -0
@@ -95,6 +95,7 @@ typedef enum fldt {FLDT_DINODE_A ,FLDT_DINODE_CORE ,FLDT_DINODE_FMT , +FLDT_DINODE_METATYPE ,FLDT_DINODE_U , FLDT_DINODE_V3,
db/inode.c +73 -10
127 lines not on this page · raw message
db/inode.h +2 -0
@@ -16,6 +16,8 @@ extern const struct field timestamp_flds[];extern int fp_dinode_fmt (void *obj,int bit,int count,char *fmtstr,int size,int arg,int base,int array); +extern int fp_metatype (void *obj,int bit,int count,char *fmtstr, +int size,int arg,int base,int array);extern int inode_a_size (void *obj,int startoff,int idx);extern void inode_init (void );extern typnm_t inode_next_type (void );
PATCH 10/38 xfs_io: support the bulkstat metadata directory flag
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support the new XFS_BULK_IREQ_METADIR flag for bulkstat commands.
--- io/bulkstat.c | 16 +++++++++++++++- man/man8/xfs_io.8 | 10 +++++++--- 2 files changed, 22 insertions(+), 4 deletions(-)
io/bulkstat.c +15 -1
@@ -70,6 +70,7 @@ bulkstat_help(void)" -d Print debugging output.\n" " -q Be quiet, no output.\n" " -e <ino> Stop after this inode.\n" +" -m Include metadata directories.\n" " -n <nr> Ask for this many results at once.\n" " -s <ino> Inode to start with.\n" " -v <ver> Use this version of the ioctl (1 or 5).\n"));
@@ -107,11 +108,12 @@ bulkstat_f(bool has_agno = false;bool debug = false;bool quiet = false; +bool metadir = false;unsigned int i;int c;int ret; -while ((c =getopt (argc, argv,"a:de:n:qs:v:" )) !=-1 ) { +while ((c =getopt (argc, argv,"a:de:mn:qs:v:" )) !=-1 ) {switch (c) {case 'a' : agno =cvt_u32 (optarg,10 );
@@ -131,6 +133,9 @@ bulkstat_f(return 1 ; }break ; +case 'm' : + metadir = true; +break ;case 'n' : batch_size =cvt_u32 (optarg,10 );if (errno) {
@@ -185,6 +190,8 @@ bulkstat_f(if (has_agno)xfrog_bulkstat_set_ag (breq, agno); +if (metadir) + breq->hdr.flags |=XFS_BULK_IREQ_METADIR ;set_xfd_flags (&xfd, ver);
@@ -253,6 +260,7 @@ bulkstat_single_f(unsigned long ver =0 ;unsigned int i;bool debug = false; +bool metadir = false;int c;int ret;
@@ -261,6 +269,9 @@ bulkstat_single_f(case 'd' : debug = true;break ; +case 'm' : + metadir = true; +break ;case 'v' : errno =0 ; ver =strtoull (optarg,NULL ,10 );
@@ -313,6 +324,9 @@ bulkstat_single_f( } } +if (metadir) + flags |=XFS_BULK_IREQ_METADIR ; + ret = -xfrog_bulkstat_single (&xfd, ino, flags, &bulkstat);if (ret) {xfrog_perror (ret,"xfrog_bulkstat_single" );
man/man8/xfs_io.8 +7 -3
@@ -1243,7 +1243,7 @@ .SH MEMORY MAPPED I/O COMMANDS .SH FILESYSTEM COMMANDS .TP -.BI "bulkstat [ \-a " agno " ] [ \-d ] [ \-e " endino " ] [ \-n " batchsize " ] [ \-q ] [ \-s " startino " ] [ \-v " version" ] +.BI "bulkstat [ \-a " agno " ] [ \-d ] [ \-e " endino " ] [ \-m ] [ \-n " batchsize " ] [ \-q ] [ \-s " startino " ] [ \-v " version" ] Display raw stat information about a bunch of inodes in an XFS filesystem. Options are as follows: .RS 1.0i
@@ -1260,6 +1260,9 @@ .SH FILESYSTEM COMMANDS Stop displaying records when this inode number is reached. Defaults to stopping when the system call stops returning results. .TP +.BI \-m +Include metadata directories in the output. +.TP .BI \-n " batchsize" Retrieve at most this many records per call. Defaults to 4,096.
@@ -1280,10 +1283,11 @@ .SH FILESYSTEM COMMANDS .RE .PD .TP -.BI "bulkstat_single [ \-d ] [ \-v " version " ] [ " inum... " | " special... " ] +.BI "bulkstat_single [ \-d ] [ \-m ] [ \-v " version " ] [ " inum... " | " special... " ] Display raw stat information about individual inodes in an XFS filesystem. The -.B \-d +.BR \-d , +.BR \-m , and .B \-v options are the same as the
PATCH 11/38 xfs_io: support scrubbing metadata directory paths
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support invoking the metadata directory path scrubber from xfs_io for testing.
--- io/scrub.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++-- man/man8/xfs_io.8 | 3 ++- 2 files changed, 62 insertions(+), 3 deletions(-)
io/scrub.c +60 -2
@@ -41,6 +41,12 @@ scrub_help(void) " Known metadata scrub types are:"));for (i =0 , d = xfrog_scrubbers; i <XFS_SCRUB_TYPE_NR ; i++, d++)printf (" %s" , d->name); +printf (_ ( +"\n" +"\n" +" Known metapath scrub arguments are:" )); +for (i =0 , d = xfrog_metapaths; i <XFS_SCRUB_METAPATH_NR ; i++, d++) +printf (" %s" , d->name);printf ("\n" ); }
@@ -125,6 +131,40 @@ parse_none(return true; } +static bool +parse_metapath ( +int argc, +char **argv, +int optind, +__u64 *ino) +{ +char *p; +unsigned long long control; +int i; + +if (optind != argc -1 ) { +fprintf (stderr,_ ("Must specify metapath number.\n" )); +return false; + } + +for (i =0 ; i <XFS_SCRUB_METAPATH_NR ; i++) { +if (!strcmp (argv[optind], xfrog_metapaths[i].name)) { + *ino = i; +return true; + } + } + + control =strtoll (argv[optind], &p,0 ); +if (*p !='\0' ) { +fprintf (stderr,_ ("Bad metapath number '%s'.\n" ), + argv[optind]); +return false; + } + + *ino = control; +return true; +} + static int parse_args( int argc,
@@ -170,6 +210,12 @@ parse_args( meta->sm_flags = flags;switch (d->group) { +case XFROG_SCRUB_GROUP_METAPATH : +if (!parse_metapath (argc, argv, optind, &meta->sm_ino)) { + exitcode =1 ; +return command_usage (cmdinfo); + } +break ;case XFROG_SCRUB_GROUP_INODE :if (!parse_inode (argc, argv, optind, &meta->sm_ino, &meta->sm_gen)) {
@@ -244,7 +290,7 @@ scrub_init(void) scrub_cmd.argmin =1 ; scrub_cmd.argmax =-1 ; scrub_cmd.flags =CMD_NOMAP_OK ; - scrub_cmd.args =_ ("type [agno|ino gen]" ); + scrub_cmd.args =_ ("type [agno|ino gen|metapath]" ); scrub_cmd.oneline =_ ("scrubs filesystem metadata" ); scrub_cmd.help = scrub_help;
@@ -275,6 +321,12 @@ repair_help(void) " Known metadata repair types are:"));for (i =0 , d = xfrog_scrubbers; i <XFS_SCRUB_TYPE_NR ; i++, d++)printf (" %s" , d->name); +printf (_ ( +"\n" +"\n" +" Known metapath repair arguments are:" )); +for (i =0 , d = xfrog_metapaths; i <XFS_SCRUB_METAPATH_NR ; i++, d++) +printf (" %s" , d->name);printf ("\n" ); }
@@ -327,7 +379,7 @@ repair_init(void) repair_cmd.argmin =1 ; repair_cmd.argmax =-1 ; repair_cmd.flags =CMD_NOMAP_OK ; - repair_cmd.args =_ ("type [agno|ino gen]" ); + repair_cmd.args =_ ("type [agno|ino gen|metapath]" ); repair_cmd.oneline =_ ("repairs filesystem metadata" ); repair_cmd.help = repair_help;
@@ -495,6 +547,12 @@ scrubv_f( optind++;switch (group) { +case XFROG_SCRUB_GROUP_METAPATH : +if (!parse_metapath (argc, argv, optind, &scrubv.head.svh_ino)) { + exitcode =1 ; +return command_usage (&scrubv_cmd); + } +break ;case XFROG_SCRUB_GROUP_INODE :if (!parse_inode (argc, argv, optind, &scrubv.head.svh_ino, &scrubv.head.svh_gen)) {
man/man8/xfs_io.8 +2 -1
@@ -1425,13 +1425,14 @@ .SH FILESYSTEM COMMANDS .RE .PD .TP -.BI "scrub " type " [ " agnumber " | " "ino" " " "gen" " ]" +.BI "scrub " type " [ " agnumber " | " "ino" " " "gen" " | " metapath " ]" Scrub internal XFS filesystem metadata. The .BI type parameter specifies which type of metadata to scrub. For AG metadata, one AG number must be specified. For file metadata, the scrub is applied to the open file unless the inode number and generation number are specified. +For metapath, the name of a file or a raw number must be specified. .RE .PD .TP
PATCH 12/38 xfs_spaceman: report health of metadir inodes too
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If the filesystem has a metadata directory tree, we should include those inodes in the health report.
--- spaceman/health.c | 2 ++ 1 file changed, 2 insertions(+)
spaceman/health.c +2 -0
@@ -324,6 +324,8 @@ report_bulkstat_health(if (agno !=NULLAGNUMBER )xfrog_bulkstat_set_ag (breq, agno); +if (file->xfd.fsgeom.flags &XFS_FSOP_GEOM_FLAGS_METADIR ) + breq->hdr.flags |=XFS_BULK_IREQ_METADIR ; do { error = -xfrog_bulkstat(&file->xfd, breq);
PATCH 13/38 xfs_scrub: tread zero-length read verify as an IO error
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
While doing some chaos testing on the xfs_scrub read verify code, I noticed that if the device under a live filesystem gets resized while scrub is running a media scan, reads will start returning 0. This causes read_verify() to run around in an infinite loop instead of erroring out like it should.
--- scrub/phase6.c | 22 ++++++++++++++++++++++ scrub/read_verify.c | 8 ++++++++ 2 files changed, 30 insertions(+)
scrub/phase6.c +22 -0
@@ -44,6 +44,9 @@ struct media_verify_state {struct read_verify_pool *rvp_realtime;struct bitmap *d_bad;/* bytes */ struct bitmap *r_bad;/* bytes */ + bool d_trunc:1; + bool r_trunc:1; + bool l_trunc:1; };/* Find the fd for a given device identifier. */
@@ -544,6 +547,13 @@ report_all_media_errors( {int ret; +if (vs->d_trunc) +str_corrupt (ctx, ctx->mntpoint,_ ("data device truncated" )); +if (vs->l_trunc) +str_corrupt (ctx, ctx->mntpoint,_ ("log device truncated" )); +if (vs->r_trunc) +str_corrupt (ctx, ctx->mntpoint,_ ("rt device truncated" )); + ret =report_disk_ioerrs (ctx, ctx->datadev, vs);if (ret) {str_liberror (ctx, ret,_ ("walking datadev io errors" ));
@@ -663,6 +673,18 @@ remember_ioerr(struct bitmap *tree;int ret; +if (!length) { +dev_t dev =disk_to_dev (ctx, disk); + +if (dev == ctx->fsinfo.fs_datadev) + vs->d_trunc = true; +else if (dev == ctx->fsinfo.fs_rtdev) + vs->r_trunc = true; +else if (dev == ctx->fsinfo.fs_logdev) + vs->l_trunc = true; +return ; + } + tree =bitmap_for_disk (ctx, disk, vs);if (!tree) {str_liberror (ctx,ENOENT ,_ ("finding bad block bitmap" ));
scrub/read_verify.c +8 -0
@@ -245,6 +245,14 @@ read_verify( read_error); rvp->ioerr_fn (rvp->ctx, rvp->disk, rv->io_start, sz, read_error, rv->io_end_arg); + }else if (sz ==0 ) { +/* No bytes at all? Did we hit the end of the disk? */ +dbg_printf ("EOF %d @ %" PRIu64" %zu err %d\n" , + rvp->disk->d_fd, rv->io_start, sz, + read_error); + rvp->ioerr_fn (rvp->ctx, rvp->disk, rv->io_start, sz, + read_error, rv->io_end_arg); +break ; }else if (sz < len) {/* * A short direct read suggests that we might have hit
PATCH 14/38 xfs_scrub: scan metadata directories during phase 3
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Scan metadata directories for correctness during phase 3.
--- scrub/inodes.c | 11 ++++++++++- scrub/inodes.h | 5 ++++- scrub/phase3.c | 7 ++++++- scrub/phase5.c | 5 ++++- scrub/phase6.c | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-)
scrub/inodes.c +10 -1
@@ -56,6 +56,7 @@ bulkstat_for_inumbers( {struct xfs_bulkstat *bstat = breq->bulkstat;struct xfs_bulkstat *bs; +unsigned int flags =0 ;int i;int error;
@@ -70,6 +71,9 @@ bulkstat_for_inumbers( strerror_r(error, errbuf, DESCR_BUFSZ)); } +if (breq->hdr.flags &XFS_BULK_IREQ_METADIR ) + flags |=XFS_BULK_IREQ_METADIR ; +/* * Check each of the stats we got back to make sure we got the inodes * we asked for.
@@ -84,7 +88,7 @@ bulkstat_for_inumbers(/* Load the one inode. */ error = -xfrog_bulkstat_single (&ctx->mnt, - inumbers->xi_startino + i,0 , bs); + inumbers->xi_startino + i, flags, bs);if (error || bs->bs_ino != inumbers->xi_startino + i) {memset (bs,0 ,sizeof (struct xfs_bulkstat )); bs->bs_ino = inumbers->xi_startino + i;
@@ -100,6 +104,7 @@ struct scan_inodes {scrub_inode_iter_fn fn;void *arg;unsigned int nr_threads; +unsigned int flags;bool aborted; };
@@ -158,6 +163,8 @@ alloc_ichunk( breq =ichunk_to_bulkstat (ichunk); breq->hdr.icount =LIBFROG_BULKSTAT_CHUNKSIZE ; +if (si->flags &SCRUB_SCAN_METADIR ) + breq->hdr.flags |=XFS_BULK_IREQ_METADIR ; *ichunkp = ichunk;return 0 ;
@@ -380,10 +387,12 @@ intscrub_scan_all_inodes ( struct scrub_ctx *ctx, scrub_inode_iter_fn fn, + unsigned int flags, void *arg) { struct scan_inodes si = { .fn = fn, + .flags = flags, .arg = arg, .nr_threads =scrub_nproc_workqueue (ctx), };
scrub/inodes.h +4 -1
@@ -17,8 +17,11 @@typedef int (*scrub_inode_iter_fn )(struct scrub_ctx *ctx,struct xfs_handle *handle,struct xfs_bulkstat *bs,void *arg); +/* Return metadata directories too. */ +#define SCRUB_SCAN_METADIR (1 << 0) +int scrub_scan_all_inodes (struct scrub_ctx *ctx,scrub_inode_iter_fn fn, -void *arg); +unsigned int flags,void *arg);int scrub_open_handle (struct xfs_handle *handle);
scrub/phase3.c +6 -1
@@ -312,6 +312,7 @@ phase3_func(struct scrub_inode_ctx ictx = { .ctx = ctx };uint64_t val;xfs_agnumber_t agno; +unsigned int scan_flags =0 ;int err; err = -ptvar_alloc(scrub_nproc(ctx), sizeof(struct action_list),
@@ -328,6 +329,10 @@ phase3_func( goto out_ptvar; } +/* Scan the metadata directory tree too. */ +if (ctx->mnt.fsgeom.flags &XFS_FSOP_GEOM_FLAGS_METADIR ) + scan_flags |=SCRUB_SCAN_METADIR ; +/* * If we already have ag/fs metadata to repair from previous phases, * we would rather not try to repair file metadata until we've tried
@@ -338,7 +343,7 @@ phase3_func( ictx.always_defer_repairs = true; } - err =scrub_scan_all_inodes (ctx, scrub_inode, &ictx); + err =scrub_scan_all_inodes (ctx, scrub_inode, scan_flags, &ictx);if (!err && ictx.aborted) err =ECANCELED ;if (err)
scrub/phase5.c +4 -1
@@ -462,6 +462,9 @@ retry_deferred_inode(unsigned int flags =0 ;int error; +if (ctx->mnt.fsgeom.flags &XFS_FSOP_GEOM_FLAGS_METADIR ) + flags |=XFS_BULK_IREQ_METADIR ; + error = -xfrog_bulkstat_single (&ctx->mnt, ino, flags, &bstat);if (error ==ENOENT ) {/* Directory is gone, mark it clear. */
@@ -772,7 +775,7 @@ _("Filesystem has errors, skipping connectivity checks."));pthread_mutex_init (&ncs.lock,NULL ); - ret =scrub_scan_all_inodes (ctx, check_inode_names, &ncs); + ret =scrub_scan_all_inodes (ctx, check_inode_names,0 , &ncs);if (ret) goto out_lock;if (ncs.aborted) {
scrub/phase6.c +1 -1
@@ -578,7 +578,7 @@ report_all_media_errors( }/* Scan for unlinked files. */ -return scrub_scan_all_inodes (ctx, report_inode_loss, vs); +return scrub_scan_all_inodes (ctx, report_inode_loss,0 , vs); }/* Schedule a read-verify of a (data block) extent. */
PATCH 15/38 xfs_scrub: re-run metafile scrubbers during phase 5
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
For metadata files on a metadir filesystem, re-run the scrubbers during phase 5 to ensure that the metadata files are still connected.
--- scrub/phase5.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- scrub/scrub.h | 7 ++++ 2 files changed, 103 insertions(+), 1 deletion(-)
scrub/phase5.c +96 -1
@@ -745,6 +745,87 @@ run_kernel_fs_scan_scrubbers(return ret; } +/* Queue one metapath scrubber. */ +static int +queue_metapath_scan ( +struct workqueue *wq, +bool *abortedp, +uint64_t type) +{ +struct fs_scan_item *item; +struct scrub_ctx *ctx = wq->wq_ctx; +int ret; + + item =malloc (sizeof (struct fs_scan_item )); +if (!item) { + ret =ENOMEM ; +str_liberror (ctx, ret,_ ("setting up metapath scan" )); +return ret; + } +scrub_item_init_metapath (&item->sri, type); +scrub_item_schedule (&item->sri,XFS_SCRUB_TYPE_METAPATH ); + item->abortedp = abortedp; + + ret = -workqueue_add (wq, fs_scan_worker,0 , item); +if (ret) +str_liberror (ctx, ret,_ ("queuing metapath scan work" )); + +return ret; +} + +/* +* Scrub metadata directory file paths to ensure that fs metadata are still +* connected where the fs needs to find them. +*/ +static int +run_kernel_metadir_path_scrubbers ( +struct scrub_ctx *ctx) +{ +struct workqueue wq; +const struct xfrog_scrub_descr *sc; +uint64_t type; +unsigned int nr_threads =scrub_nproc_workqueue (ctx); +bool aborted = false; +int ret, ret2; + + ret = -workqueue_create (&wq, (struct xfs_mount *)ctx, nr_threads); +if (ret) { +str_liberror (ctx, ret,_ ("setting up metapath scan workqueue" )); +return ret; + } + +/* +* Scan all the metadata files in parallel if metadata directories +* are enabled, because the phase 3 scrubbers might have taken out +* parts of the metadir tree. +*/ +for (type =0 ; type <XFS_SCRUB_METAPATH_NR ; type++) { + sc = &xfrog_metapaths[type]; +if (sc->group !=XFROG_SCRUB_GROUP_FS ) +continue ; + + ret =queue_metapath_scan (&wq, &aborted, type); +if (ret) { +str_liberror (ctx, ret, +_ ("queueing metapath scrub work" )); + goto wait; + } + } + +wait: + ret2 = -workqueue_terminate (&wq); +if (ret2) { +str_liberror (ctx, ret2,_ ("joining metapath scan workqueue" )); +if (!ret) + ret = ret2; + } +if (aborted && !ret) + ret =ECANCELED ; + +workqueue_destroy (&wq); +return ret; +} +/* Check directory connectivity. */ int phase5_func(
@@ -753,6 +834,16 @@ phase5_func(struct ncheck_state ncs = { .ctx = ctx };int ret; +/* +* Make sure metadata files are still connected to the metadata +* directory tree now that phase 3 pruned all corrupt directory tree +* links. +*/ +if (ctx->mnt.fsgeom.flags &XFS_FSOP_GEOM_FLAGS_METADIR ) { + ret =run_kernel_metadir_path_scrubbers (ctx); +if (ret) +return ret; + }/* * Check and fix anything that requires a full filesystem scan. We do
@@ -805,8 +896,12 @@ phase5_estimate(unsigned int *nr_threads, int *rshift) { + unsigned int scans = 2; + *items =scrub_estimate_iscan_work (ctx); - *nr_threads =scrub_nproc (ctx) *2 ; +if (ctx->mnt.fsgeom.flags &XFS_FSOP_GEOM_FLAGS_METADIR ) + scans++; + *nr_threads =scrub_nproc (ctx) * scans; *rshift =0 ;return 0 ; }
scrub/scrub.h +7 -0
@@ -108,6 +108,13 @@ scrub_item_init_file(struct scrub_item *sri, const struct xfs_bulkstat *bstat) sri->sri_gen = bstat->bs_gen; } +static inline void +scrub_item_init_metapath (struct scrub_item *sri,uint64_t metapath) +{ +memset (sri,0 ,sizeof (*sri)); + sri->sri_ino = metapath; +} +void scrub_item_dump (struct scrub_item *sri,unsigned int group_mask,const char *tag);
PATCH 16/38 xfs_repair: preserve the metadirino field when zeroing supers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The metadata directory root inumber is now the last field in the superblock, so extend the zeroing code to know about that.
--- repair/agheader.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
repair/agheader.c +4 -1
@@ -357,7 +357,10 @@ secondary_sb_whack(* * size is the size of data which is valid for this sb. */ -if (xfs_sb_version_hasmetauuid (sb)) +if (xfs_sb_version_hasmetadir (sb)) + size = offsetof(struct xfs_dsb , sb_metadirino) + +sizeof (sb->sb_metadirino); +else if (xfs_sb_version_hasmetauuid (sb)) size = offsetof(struct xfs_dsb , sb_meta_uuid) +sizeof (sb->sb_meta_uuid);else if (xfs_sb_version_hascrc (sb))
PATCH 17/38 xfs_repair: check metadir superblock padding fields
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Since metadir removes sb_bad_features2 from the ondisk superblock, check that the padding field is zeroed.
--- repair/sb.c | 5 +++++ 1 file changed, 5 insertions(+)
repair/sb.c +5 -0
@@ -479,6 +479,11 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb)if (sb->sb_blocklog + sb->sb_dirblklog >XFS_MAX_BLOCKSIZE_LOG )return XR_BAD_DIR_SIZE_DATA ; +if (xfs_sb_version_hasmetadir (sb)) { +if (sb->sb_metadirpad) +return XR_SB_GEO_MISMATCH ; + } +return (XR_OK ); }
PATCH 18/38 xfs_repair: dont check metadata directory dirent inumbers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Phase 6 always rebuilds the entire metadata directory tree, and repair quietly ignores all the DIFLAG2_METADATA directory inodes that it finds. As a result, none of the metadata directories are marked inuse in the incore data. Therefore, the is_inode_free checks are not valid for anything we find in a metadata directory.
Therefore, avoid checking is_inode_free when scanning metadata directory dirents.
--- libxfs/libxfs_api_defs.h | 1 + repair/dir2.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
libxfs/libxfs_api_defs.h +1 -0
@@ -121,6 +121,7 @@#define xfs_dinode_calc_crc libxfs_dinode_calc_crc#define xfs_dinode_good_version libxfs_dinode_good_version#define xfs_dinode_verify libxfs_dinode_verify +#define xfs_dinode_verify_metadir libxfs_dinode_verify_metadir#define xfs_dir2_data_bestfree_p libxfs_dir2_data_bestfree_p#define xfs_dir2_data_entry_tag_p libxfs_dir2_data_entry_tag_p
repair/dir2.c +35 -0
@@ -136,6 +136,29 @@ process_sf_dir2_fixoff( } } +static inline bool +is_metadata_directory ( +struct xfs_mount *mp, +struct xfs_dinode *dip) +{ +xfs_failaddr_t fa; +uint16_t mode; +uint16_t flags; +uint64_t flags2; + +if (!xfs_has_metadir (mp)) +return false; +if (dip->di_version <3 || + !(dip->di_flags2 &cpu_to_be64 (XFS_DIFLAG2_METADATA ))) +return false; + + mode =be16_to_cpu (dip->di_mode); + flags =be16_to_cpu (dip->di_flags); + flags2 =be64_to_cpu (dip->di_flags2); + fa =libxfs_dinode_verify_metadir (mp, dip, mode, flags, flags2); +return fa ==NULL ; +} +/* * this routine performs inode discovery and tries to fix things * in place. available redundancy -- inode data size should match
@@ -227,6 +250,12 @@ process_sf_dir2( }else if (!libxfs_verify_dir_ino (mp, lino)) { junkit =1 ; junkreason =_ ("invalid" ); + }else if (is_metadata_directory (mp, dip)) { +/* +* Metadata directories are always rebuilt, so don't +* bother checking if the child inode is free or not. +*/ + junkit =0 ; }else if (lino == mp->m_sb.sb_rbmino) { junkit =1 ; junkreason =_ ("realtime bitmap" );
@@ -698,6 +727,12 @@ process_dir2_data(* directory since it's still structurally intact. */ clearreason =_ ("invalid" ); + }else if (is_metadata_directory (mp, dip)) { +/* +* Metadata directories are always rebuilt, so don't +* bother checking if the child inode is free or not. +*/ + clearino =0 ; }else if (ent_ino == mp->m_sb.sb_rbmino) { clearreason =_ ("realtime bitmap" ); }else if (ent_ino == mp->m_sb.sb_rsumino) {
PATCH 19/38 xfs_repair: refactor fixing dotdot
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Pull the code that fixes a directory's dot-dot entry into a separate helper function so that we can call it on the rootdir and (later) the metadir.
--- repair/phase6.c | 96 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 39 deletions(-)
repair/phase6.c +57 -39
@@ -2649,6 +2649,62 @@ dir_hash_add_parent_ptrs( } } +/* +* If we have to create a .. for /, do it now *before* we delete the bogus +* entries, otherwise the directory could transform into a shortform dir which +* would probably cause the simulation to choke. Even if the illegal entries +* get shifted around, it's ok because the entries are structurally intact and +* in in hash-value order so the simulation won't get confused if it has to +* move them around. +*/ +static void +fix_dotdot ( +struct xfs_mount *mp, +xfs_ino_t ino, +struct xfs_inode *ip, +xfs_ino_t rootino, +const char *tag, +int *need_dotdot) +{ +struct xfs_trans *tp; +int nres; +int error; + +if (ino != rootino || !*need_dotdot) +return ; + +if (no_modify) { +do_warn (_ ("would recreate %s directory .. entry\n" ), tag); +return ; + } + +ASSERT (ip->i_df.if_format !=XFS_DINODE_FMT_LOCAL ); + +do_warn (_ ("recreating %s directory .. entry\n" ), tag); + + nres =libxfs_mkdir_space_res (mp,2 ); + error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_mkdir, nres,0 ,0 , &tp); +if (error) +res_failed (error); + +libxfs_trans_ijoin (tp, ip,0 ); + + error = -libxfs_dir_createname (tp, ip, &xfs_name_dotdot, ip->i_ino, + nres); +if (error) +do_error ( +_ ("can't make \"..\" entry in %s inode %" PRIu64", createname error %d\n" ), + tag ,ino, error); + +libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); + error = -libxfs_trans_commit (tp); +if (error) +do_error ( +_ ("%s inode \"..\" entry recreation failed (%d)\n" ), tag, error); + + *need_dotdot =0 ; +} +/* * processes all reachable inodes in directories */
@@ -2778,45 +2834,7 @@ _("error %d fixing shortform directory %llu\n"),dir_hash_add_parent_ptrs (ip, hashtab);dir_hash_done (hashtab); -/* -* if we have to create a .. for /, do it now *before* -* we delete the bogus entries, otherwise the directory -* could transform into a shortform dir which would -* probably cause the simulation to choke. Even -* if the illegal entries get shifted around, it's ok -* because the entries are structurally intact and in -* in hash-value order so the simulation won't get confused -* if it has to move them around. -*/ -if (!no_modify && need_root_dotdot && ino == mp->m_sb.sb_rootino) { -ASSERT (ip->i_df.if_format !=XFS_DINODE_FMT_LOCAL ); - -do_warn (_ ("recreating root directory .. entry\n" )); - - nres =libxfs_mkdir_space_res (mp,2 ); - error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_mkdir, - nres,0 ,0 , &tp); -if (error) -res_failed (error); - -libxfs_trans_ijoin (tp, ip,0 ); - - error = -libxfs_dir_createname (tp, ip, &xfs_name_dotdot, - ip->i_ino, nres); -if (error) -do_error ( -_ ("can't make \"..\" entry in root inode %" PRIu64", createname error %d\n" ), ino, error); - -libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); - error = -libxfs_trans_commit (tp); -if (error) -do_error ( -_ ("root inode \"..\" entry recreation failed (%d)\n" ), error); - - need_root_dotdot =0 ; - }else if (need_root_dotdot && ino == mp->m_sb.sb_rootino) { -do_warn (_ ("would recreate root directory .. entry\n" )); - } +fix_dotdot (mp, ino, ip, mp->m_sb.sb_rootino,"root" , &need_root_dotdot);/* * if we need to create the '.' entry, do so only if
PATCH 20/38 xfs_repair: refactor marking of metadata inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Refactor the mechanics of marking a metadata inode into a helper function so that we don't have to open-code that for every single metadata inode.
--- repair/phase6.c | 76 ++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 48 deletions(-)
repair/phase6.c +28 -48
@@ -2891,6 +2891,22 @@ _("error %d fixing shortform directory %llu\n"),libxfs_irele (ip); } +static void +mark_inode ( +struct xfs_mount *mp, +xfs_ino_t ino) +{ +struct ino_tree_node *irec; +int offset; + + irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, ino), +XFS_INO_TO_AGINO (mp, ino)); + + offset =XFS_INO_TO_AGINO (mp, ino) - irec->ino_startnum; + +add_inode_reached (irec, offset); +} +/* * mark realtime bitmap and summary inodes as reached. * quota inode will be marked here as well
@@ -2898,54 +2914,18 @@ _("error %d fixing shortform directory %llu\n"),static void mark_standalone_inodes (xfs_mount_t *mp) { -ino_tree_node_t *irec; -int offset; - - irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, mp->m_sb.sb_rbmino), -XFS_INO_TO_AGINO (mp, mp->m_sb.sb_rbmino)); - - offset =XFS_INO_TO_AGINO (mp, mp->m_sb.sb_rbmino) - - irec->ino_startnum; - -add_inode_reached (irec, offset); - - irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, mp->m_sb.sb_rsumino), -XFS_INO_TO_AGINO (mp, mp->m_sb.sb_rsumino)); - - offset =XFS_INO_TO_AGINO (mp, mp->m_sb.sb_rsumino) - - irec->ino_startnum; - -add_inode_reached (irec, offset); - -if (fs_quotas) { -if (mp->m_sb.sb_uquotino - && mp->m_sb.sb_uquotino !=NULLFSINO ) { - irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, - mp->m_sb.sb_uquotino), -XFS_INO_TO_AGINO (mp, mp->m_sb.sb_uquotino)); - offset =XFS_INO_TO_AGINO (mp, mp->m_sb.sb_uquotino) - - irec->ino_startnum; -add_inode_reached (irec, offset); - } -if (mp->m_sb.sb_gquotino - && mp->m_sb.sb_gquotino !=NULLFSINO ) { - irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, - mp->m_sb.sb_gquotino), -XFS_INO_TO_AGINO (mp, mp->m_sb.sb_gquotino)); - offset =XFS_INO_TO_AGINO (mp, mp->m_sb.sb_gquotino) - - irec->ino_startnum; -add_inode_reached (irec, offset); - } -if (mp->m_sb.sb_pquotino - && mp->m_sb.sb_pquotino !=NULLFSINO ) { - irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, - mp->m_sb.sb_pquotino), -XFS_INO_TO_AGINO (mp, mp->m_sb.sb_pquotino)); - offset =XFS_INO_TO_AGINO (mp, mp->m_sb.sb_pquotino) - - irec->ino_startnum; -add_inode_reached (irec, offset); - } - } +mark_inode (mp, mp->m_sb.sb_rbmino); +mark_inode (mp, mp->m_sb.sb_rsumino); + +if (!fs_quotas) +return ; + +if (mp->m_sb.sb_uquotino && mp->m_sb.sb_uquotino !=NULLFSINO ) +mark_inode (mp, mp->m_sb.sb_uquotino); +if (mp->m_sb.sb_gquotino && mp->m_sb.sb_gquotino !=NULLFSINO ) +mark_inode (mp, mp->m_sb.sb_gquotino); +if (mp->m_sb.sb_pquotino && mp->m_sb.sb_pquotino !=NULLFSINO ) +mark_inode (mp, mp->m_sb.sb_pquotino); } static void
PATCH 21/38 xfs_repair: refactor root directory initialization
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Refactor root directory initialization into a separate function we can call for both the root dir and the metadir.
--- repair/phase6.c | 63 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 23 deletions(-)
repair/phase6.c +40 -23
@@ -587,27 +587,27 @@ mk_rsumino(xfs_mount_t *mp)libxfs_irele (ip); } -/* -* makes a new root directory. -*/ -static void -mk_root_dir (xfs_mount_t *mp) +/* Initialize a root directory. */ +static int +init_fs_root_dir ( +struct xfs_mount *mp, +xfs_ino_t ino, +mode_t mode, +struct xfs_inode **ipp) { -xfs_trans_t *tp; -xfs_inode_t *ip; -int i; -int error; -const mode_t mode =0755 ; -ino_tree_node_t *irec; +struct xfs_trans *tp; +struct xfs_inode *ip =NULL ; +struct ino_tree_node *irec; +int error; - ip =NULL ; - i = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_ichange,10 ,0 ,0 , &tp); -if (i) -res_failed (i); + error = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_ichange,10 ,0 ,0 , &tp); +if (error) +return error; - error = -libxfs_iget (mp, tp, mp->m_sb.sb_rootino,0 , &ip); + error = -libxfs_iget (mp, tp, ino,0 , &ip);if (error) { -do_error (_ ("could not iget root inode -- error - %d\n" ), error); +libxfs_trans_cancel (tp); +return error; }/* Reset the root directory. */
@@ -616,14 +616,31 @@ mk_root_dir(xfs_mount_t *mp) error = -libxfs_trans_commit (tp);if (error) -do_error (_ ("%s: commit failed, error %d\n" ), __func__, error); +return error; + + irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, ino), +XFS_INO_TO_AGINO (mp, ino)); +set_inode_isadir (irec,XFS_INO_TO_AGINO (mp, ino) - irec->ino_startnum); + *ipp = ip; +return 0 ; +} + +/* +* makes a new root directory. +*/ +static void +mk_root_dir (xfs_mount_t *mp) +{ +struct xfs_inode *ip =NULL ; +int error; + + error =init_fs_root_dir (mp, mp->m_sb.sb_rootino,0755 , &ip); +if (error) +do_error ( +_ ("Could not reinitialize root directory inode, error %d\n" ), + error);libxfs_irele (ip); - - irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, mp->m_sb.sb_rootino), -XFS_INO_TO_AGINO (mp, mp->m_sb.sb_rootino)); -set_inode_isadir (irec,XFS_INO_TO_AGINO (mp, mp->m_sb.sb_rootino) - - irec->ino_startnum); }/*
PATCH 22/38 xfs_repair: refactor grabbing realtime metadata inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a helper function to grab a realtime metadata inode. When metadir arrives, the bitmap and summary inodes can float, so we'll turn this function into a "load or allocate" function.
--- repair/phase6.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-)
repair/phase6.c +34 -17
@@ -474,6 +474,24 @@ reset_sbroot_ino(libxfs_inode_init (tp, &args, ip); } +/* Load a realtime freespace metadata inode from disk and reset it. */ +static int +ensure_rtino ( +struct xfs_trans *tp, +xfs_ino_t ino, +struct xfs_inode **ipp) +{ +struct xfs_mount *mp = tp->t_mountp; +int error; + + error = -libxfs_iget (mp, tp, ino,0 , ipp); +if (error) +return error; + +reset_sbroot_ino (tp,S_IFREG , *ipp); +return 0 ; +} +static void mk_rbmino (struct xfs_mount *mp)
@@ -486,15 +504,14 @@ mk_rbmino(if (error)res_failed (error); - error = -libxfs_iget (mp, tp, mp->m_sb.sb_rbmino,0 , &ip); -if (error) { -do_error ( -_ ("couldn't iget realtime bitmap inode -- error - %d\n" ), - error); - } -/* Reset the realtime bitmap inode. */ -reset_sbroot_ino (tp,S_IFREG , ip); + error =ensure_rtino (tp, mp->m_sb.sb_rbmino, &ip); +if (error) { +do_error ( +_ ("couldn't iget realtime bitmap inode -- error - %d\n" ), + error); + } + ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize;libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); error = -libxfs_trans_commit (tp);
@@ -560,7 +577,8 @@ _("couldn't re-initialize realtime summary inode, error %d\n"), error); }static void -mk_rsumino (xfs_mount_t *mp) +mk_rsumino ( +struct xfs_mount *mp) {struct xfs_trans *tp;struct xfs_inode *ip;
@@ -570,15 +588,14 @@ mk_rsumino(xfs_mount_t *mp)if (error)res_failed (error); - error = -libxfs_iget (mp, tp, mp->m_sb.sb_rsumino,0 , &ip); -if (error) { -do_error ( -_ ("couldn't iget realtime summary inode -- error - %d\n" ), - error); - } -/* Reset the rt summary inode. */ -reset_sbroot_ino (tp,S_IFREG , ip); + error =ensure_rtino (tp, mp->m_sb.sb_rsumino, &ip); +if (error) { +do_error ( +_ ("couldn't iget realtime summary inode -- error - %d\n" ), + error); + } + ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize;libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); error = -libxfs_trans_commit (tp);
PATCH 23/38 xfs_repair: check metadata inode flag
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Check whether or not the metadata inode flag is set appropriately.
--- repair/dinode.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
repair/dinode.c +41 -0
@@ -2331,6 +2331,26 @@ _("Bad extent size hint %u on inode %" PRIu64 ", "), } } +static inline bool +should_have_metadir_iflag ( +struct xfs_mount *mp, +xfs_ino_t ino) +{ +if (ino == mp->m_sb.sb_metadirino) +return true; +if (ino == mp->m_sb.sb_rbmino) +return true; +if (ino == mp->m_sb.sb_rsumino) +return true; +if (ino == mp->m_sb.sb_uquotino) +return true; +if (ino == mp->m_sb.sb_gquotino) +return true; +if (ino == mp->m_sb.sb_pquotino) +return true; +return false; +} +/* * returns 0 if the inode is ok, 1 if the inode is corrupt * check_dups can be set to 1 *only* when called by the
@@ -2680,6 +2700,27 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"), } } +if (flags2 &XFS_DIFLAG2_METADATA ) { +xfs_failaddr_t fa; + + fa =libxfs_dinode_verify_metadir (mp, dino, di_mode, +be16_to_cpu (dino->di_flags), flags2); +if (fa) { +if (!uncertain) +do_warn ( +_ ("inode %" PRIu64" is incorrectly marked as metadata\n" ), + lino); + goto clear_bad_out; + } + }else if (xfs_has_metadir (mp) && +should_have_metadir_iflag (mp, lino)) { +if (!uncertain) +do_warn ( +_ ("inode %" PRIu64" should be marked as metadata\n" ), + lino); + goto clear_bad_out; + } +if ((flags2 &XFS_DIFLAG2_REFLINK ) && !xfs_has_reflink (mp)) {if (!uncertain) {
PATCH 24/38 xfs_repair: use libxfs_metafile_iget for quota/rt inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use the new iget function for these metadata files so that we can check types, etc.
--- repair/phase6.c | 23 +++++++++-------------- repair/quotacheck.c | 17 ++++++++++++++--- repair/rt.c | 29 ++++++++++++++++++++++------- 3 files changed, 45 insertions(+), 24 deletions(-)
repair/phase6.c +9 -14
@@ -484,6 +484,11 @@ ensure_rtino(struct xfs_mount *mp = tp->t_mountp;int error; +/* +* Don't use metafile iget here because we're resetting sb-rooted +* inodes that live at fixed inumbers, but these inodes could be in +* an arbitrary state. +*/ error = -libxfs_iget (mp, tp, ino,0 , ipp);if (error)return error;
@@ -524,16 +529,11 @@ static voidfill_rbmino ( struct xfs_mount *mp) { -struct xfs_trans *tp;struct xfs_inode *ip;int error; - error = -libxfs_trans_alloc_rollable (mp,10 , &tp); -if (error) -res_failed (error); - - error = -libxfs_iget (mp, tp, mp->m_sb.sb_rbmino,0 , &ip); -libxfs_trans_cancel (tp); + error = -libxfs_metafile_iget (mp, mp->m_sb.sb_rbmino, +XFS_METAFILE_RTBITMAP , &ip);if (error)do_error (_ ("couldn't iget realtime bitmap inode, error %d\n" ), error);
@@ -551,16 +551,11 @@ static voidfill_rsumino ( struct xfs_mount *mp) { -struct xfs_trans *tp;struct xfs_inode *ip;int error; - error = -libxfs_trans_alloc_rollable (mp,10 , &tp); -if (error) -res_failed (error); - - error = -libxfs_iget (mp, tp, mp->m_sb.sb_rsumino,0 , &ip); -libxfs_trans_cancel (tp); + error = -libxfs_metafile_iget (mp, mp->m_sb.sb_rsumino, +XFS_METAFILE_RTSUMMARY , &ip);if (error)do_error (_ ("couldn't iget realtime summary inode, error %d\n" ), error);
repair/quotacheck.c +14 -3
@@ -403,21 +403,26 @@ quotacheck_verify(struct xfs_ifork *ifp;struct qc_dquots *dquots =NULL ;struct avl64node *node, *n; +struct xfs_trans *tp;xfs_ino_t ino =NULLFSINO ; +enum xfs_metafile_type metafile_type;int error;switch (type) {case XFS_DQTYPE_USER : ino = mp->m_sb.sb_uquotino; dquots = user_dquots; + metafile_type =XFS_METAFILE_USRQUOTA ;break ;case XFS_DQTYPE_GROUP : ino = mp->m_sb.sb_gquotino; dquots = group_dquots; + metafile_type =XFS_METAFILE_GRPQUOTA ;break ;case XFS_DQTYPE_PROJ : ino = mp->m_sb.sb_pquotino; dquots = proj_dquots; + metafile_type =XFS_METAFILE_PRJQUOTA ;break ; }
@@ -429,17 +434,21 @@ quotacheck_verify(if (!dquots || !chkd_flags)return ; - error = -libxfs_iget (mp,NULL , ino,0 , &ip); + error = -libxfs_trans_alloc_empty (mp, &tp); +if (error) +do_error (_ ("could not alloc transaction to open quota file\n" )); + + error = -libxfs_trans_metafile_iget (tp, ino, metafile_type, &ip);if (error) {do_warn (_ ("could not open %s inode %" PRIu64" for quotacheck, err=%d\n" ),qflags_typestr (type), ino, error); chkd_flags =0 ; -return ; + goto out_trans; } ifp =xfs_ifork_ptr (ip,XFS_DATA_FORK ); - error = -libxfs_iread_extents (NULL , ip,XFS_DATA_FORK ); + error = -libxfs_iread_extents (tp, ip,XFS_DATA_FORK );if (error) { do_warn( _("could not read %s inode %"PRIu64" extents, err=%d\n"),
@@ -477,6 +486,8 @@ _("%s record for id %u not found on disk (bcount %"PRIu64" rtbcount %"PRIu64" ic } err:libxfs_irele (ip); +out_trans: +libxfs_trans_cancel (tp); }/*
repair/rt.c +22 -7
@@ -144,18 +144,34 @@ generate_rtinfo(static void check_rtfile_contents (struct xfs_mount *mp, -const char *filename, -xfs_ino_t ino, -void *buf, +enum xfs_metafile_type metafile_type,xfs_fileoff_t filelen) {struct xfs_bmbt_irec map;struct xfs_buf *bp;struct xfs_inode *ip; +const char *filename; +void *buf; +xfs_ino_t ino;xfs_fileoff_t bno =0 ;int error; - error = -libxfs_iget (mp,NULL , ino,0 , &ip); +switch (metafile_type) { +case XFS_METAFILE_RTBITMAP : + ino = mp->m_sb.sb_rbmino; + filename ="rtbitmap" ; + buf = btmcompute; +break ; +case XFS_METAFILE_RTSUMMARY : + ino = mp->m_sb.sb_rsumino; + filename ="rtsummary" ; + buf = sumcompute; +break ; +default : +return ; + } + + error = -libxfs_metafile_iget (mp, ino, metafile_type, &ip);if (error) {do_warn (_ ("unable to open %s file, err %d\n" ), filename, error);return ;
@@ -216,7 +232,7 @@ check_rtbitmap(if (need_rbmino)return ; -check_rtfile_contents (mp,"rtbitmap" , mp->m_sb.sb_rbmino, btmcompute, +check_rtfile_contents (mp,XFS_METAFILE_RTBITMAP , mp->m_sb.sb_rbmblocks); }
@@ -227,6 +243,5 @@ check_rtsummary(if (need_rsumino)return ; -check_rtfile_contents (mp,"rtsummary" , mp->m_sb.sb_rsumino, sumcompute, - mp->m_rsumblocks); +check_rtfile_contents (mp,XFS_METAFILE_RTSUMMARY , mp->m_rsumblocks); }
PATCH 25/38 xfs_repair: rebuild the metadata directory
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Check the dirents in metadata directories for problems and repair them if necessary. Also make sure that the sb-rooted inodes (root, metadir root, rt bitmap, rt summary) are always allocated in that order.
Note that xfs_repair will always rebuild the metadata directory tree itself, so we only need to report problems, not fix them.
--- libxfs/libxfs_api_defs.h | 1 repair/dino_chunks.c | 12 ++++++ repair/dir2.c | 16 +++++++- repair/globals.c | 3 + repair/globals.h | 3 + repair/incore.h | 13 ++++++ repair/phase1.c | 2 + repair/phase2.c | 53 +++++++++++++++++++------- repair/phase4.c | 16 ++++++++ repair/phase6.c | 73 ++++++++++++++++++++++++++++++++++-- repair/pptr.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++ repair/pptr.h | 2 + repair/sb.c | 3 + repair/xfs_repair.c | 50 ++++++++++++++++++++++++ 14 files changed, 320 insertions(+), 21 deletions(-)
libxfs/libxfs_api_defs.h +1 -0
@@ -215,6 +215,7 @@#define xfs_metafile_iget libxfs_metafile_iget#define xfs_trans_metafile_iget libxfs_trans_metafile_iget +#define xfs_metafile_set_iflag libxfs_metafile_set_iflag#define xfs_metadir_link libxfs_metadir_link#define xfs_metadir_lookup libxfs_metadir_lookup#define xfs_metadir_start_create libxfs_metadir_start_create
repair/dino_chunks.c +12 -0
@@ -932,6 +932,18 @@ process_inode_chunk(_ ("would clear root inode %" PRIu64"\n" ), ino); } + }else if (mp->m_sb.sb_metadirino == ino) { + need_metadir_inode = true; + +if (!no_modify) { +do_warn ( +_ ("cleared metadata directory %" PRIu64"\n" ), + ino); + }else { +do_warn ( +_ ("would clear metadata directory %" PRIu64"\n" ), + ino); + } }else if (mp->m_sb.sb_rbmino == ino) { need_rbmino =1 ;
repair/dir2.c +14 -2
@@ -271,6 +271,9 @@ process_sf_dir2( }else if (lino == mp->m_sb.sb_pquotino) { junkit =1 ; junkreason =_ ("project quota" ); + }else if (lino == mp->m_sb.sb_metadirino) { + junkit =1 ; + junkreason =_ ("metadata directory root" ); }else if ((irec_p =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, lino),XFS_INO_TO_AGINO (mp, lino))) !=NULL ) {
@@ -564,7 +567,8 @@ _("corrected root directory %" PRIu64 " .. entry, was %" PRIu64 ", now %" PRIu64_ ("would have corrected root directory %" PRIu64" .. entry from %" PRIu64" to %" PRIu64"\n" ), ino, *parent, ino); } - }else if (ino == *parent && ino != mp->m_sb.sb_rootino) { + }else if (ino == *parent && ino != mp->m_sb.sb_rootino && + ino != mp->m_sb.sb_metadirino) {/* * likewise, non-root directories can't have .. pointing * to .
@@ -743,6 +747,8 @@ process_dir2_data( clearreason =_ ("group quota" ); }else if (ent_ino == mp->m_sb.sb_pquotino) { clearreason =_ ("project quota" ); + }else if (ent_ino == mp->m_sb.sb_metadirino) { + clearreason =_ ("metadata directory root" ); }else { irec_p = find_inode_rec(mp, XFS_INO_TO_AGNO(mp, ent_ino),
@@ -864,7 +870,8 @@ _("entry at block %u offset %" PRIdPTR " in directory inode %" PRIu64 " has ille* NULLFSINO otherwise. */ if (ino == ent_ino && - ino != mp->m_sb.sb_rootino) { + ino != mp->m_sb.sb_rootino && + ino != mp->m_sb.sb_metadirino) { *parent =NULLFSINO ; do_warn( _("bad .. entry in directory inode %" PRIu64 ", points to self: "),
@@ -1519,9 +1526,14 @@ process_dir2( }else if (dotdot ==0 && ino == mp->m_sb.sb_rootino) {do_warn (_ ("no .. entry for root directory %" PRIu64"\n" ), ino); need_root_dotdot =1 ; + }else if (dotdot ==0 && ino == mp->m_sb.sb_metadirino) { +do_warn (_ ("no .. entry for metaino directory %" PRIu64"\n" ), ino); + need_metadir_dotdot =1 ; }ASSERT ((ino != mp->m_sb.sb_rootino && ino != *parent) || + (ino == mp->m_sb.sb_metadirino && + (ino == *parent || need_metadir_dotdot ==1 )) || (ino == mp->m_sb.sb_rootino && (ino == *parent || need_root_dotdot ==1 )));
repair/globals.c +3 -0
@@ -66,6 +66,9 @@ int fs_is_dirty;int need_root_inode;int need_root_dotdot; +bool need_metadir_inode; +int need_metadir_dotdot; +int need_rbmino;int need_rsumino;
repair/globals.h +3 -0
@@ -107,6 +107,9 @@ extern int fs_is_dirty;extern int need_root_inode;extern int need_root_dotdot; +extern bool need_metadir_inode; +extern int need_metadir_dotdot; +extern int need_rbmino;extern int need_rsumino;
repair/incore.h +13 -0
@@ -661,4 +661,17 @@ inorec_set_freecount( rp->ir_u.f.ir_freecount = cpu_to_be32(freecount); } +/* +* Number of inodes assumed to be always allocated because they are created +* by mkfs. +*/ +static inline unsigned int +xfs_rootrec_inodes_inuse ( +struct xfs_mount *mp) +{ +if (xfs_has_metadir (mp)) +return 4 ;/* sb_rootino, sb_rbmino, sb_rsumino, sb_metadirino */ +return 3 ;/* sb_rootino, sb_rbmino, sb_rsumino */ +} +#endif /* XFS_REPAIR_INCORE_H */
repair/phase1.c +2 -0
@@ -48,6 +48,8 @@ phase1(xfs_mount_t *mp) primary_sb_modified =0 ; need_root_inode =0 ; need_root_dotdot =0 ; + need_metadir_inode = false; + need_metadir_dotdot =0 ; need_rbmino =0 ; need_rsumino =0 ; lost_quotas =0 ;
repair/phase2.c +38 -15
104 lines not on this page · raw message
repair/phase4.c +16 -0
@@ -264,6 +264,22 @@ phase4(xfs_mount_t *mp)do_warn (_ ("root inode lost\n" )); } +/* +* If metadata directory trees are enabled, the metadata root directory +* always comes immediately after the regular root directory, even if +* it's free. +*/ +if (xfs_has_metadir (mp) && + (is_inode_free (irec,1 ) || !inode_isadir (irec,1 ))) { + need_metadir_inode = true; +if (no_modify) +do_warn ( +_ ("metadata directory root inode would be lost\n" )); +else +do_warn ( +_ ("metadata directory root inode lost\n" )); + } +for (i =0 ; i < mp->m_sb.sb_agcount; i++) { ag_end = (i < mp->m_sb.sb_agcount -1 ) ? mp->m_sb.sb_agblocks : mp->m_sb.sb_dblocks -
repair/phase6.c +69 -4
132 lines not on this page · raw message
repair/pptr.c +94 -0
97 lines not on this page · raw message
repair/pptr.h +2 -0
@@ -14,4 +14,6 @@ void add_parent_ptr(xfs_ino_t ino, const unsigned char *fname,void check_parent_ptrs (struct xfs_mount *mp); +void try_erase_parent_ptrs (struct xfs_inode *ip); +#endif /* __REPAIR_PPTR_H__ */
repair/sb.c +3 -0
@@ -28,6 +28,7 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest)xfs_ino_t uquotino;xfs_ino_t gquotino;xfs_ino_t pquotino; +xfs_ino_t metadirino;uint16_t versionnum; rootino = dest->sb_rootino;
@@ -36,6 +37,7 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest) uquotino = dest->sb_uquotino; gquotino = dest->sb_gquotino; pquotino = dest->sb_pquotino; + metadirino = dest->sb_metadirino; versionnum = dest->sb_versionnum;
@@ -47,6 +49,7 @@ copy_sb(xfs_sb_t *source, xfs_sb_t *dest) dest->sb_uquotino = uquotino; dest->sb_gquotino = gquotino; dest->sb_pquotino = pquotino; + dest->sb_metadirino = metadirino; dest->sb_versionnum = versionnum;
repair/xfs_repair.c +50 -0
62 lines not on this page · raw message
PATCH 26/38 xfs_repair: don't let metadata and regular files mix
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Track whether or not inodes thought they were metadata inodes. We cannot allow metadata inodes to appear in the regular directory tree, and we cannot allow regular inodes to appear in the metadata directory tree.
--- repair/dinode.c | 21 +++++++++++++++++ repair/incore.h | 19 +++++++++++++++ repair/incore_ino.c | 1 + repair/phase2.c | 7 +++++- repair/phase6.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 1 deletion(-)
repair/dinode.c +21 -0
@@ -2392,6 +2392,7 @@ process_dinode_int(struct xfs_dinode *dino = *dinop;xfs_agino_t unlinked_ino;struct xfs_perag *pag; +bool is_meta = false; *dirty = *isa_dir =0 ; *used = is_used;
@@ -2971,6 +2972,18 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "),if (collect_rmaps)record_inode_reflink_flag (mp, dino, agno, ino, lino); +/* Does this inode think it was metadata? */ +if (dino->di_version >=3 && + (dino->di_flags2 &cpu_to_be64 (XFS_DIFLAG2_METADATA ))) { +struct ino_tree_node *irec; +int off; + + irec =find_inode_rec (mp, agno, ino); + off =get_inode_offset (mp, lino, irec); +set_inode_is_meta (irec, off); + is_meta = true; + } +/* * check data fork -- if it's bad, clear the inode */
@@ -3057,6 +3070,14 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "), *used = is_free; *isa_dir =0 ;blkmap_free (dblkmap); +if (is_meta) { +struct ino_tree_node *irec; +int off; + + irec =find_inode_rec (mp, agno, ino); + off =get_inode_offset (mp, lino, irec); +clear_inode_is_meta (irec, off); + }return 1 ; }
repair/incore.h +19 -0
@@ -271,6 +271,7 @@ typedef struct ino_tree_node {uint64_t ino_isa_dir;/* bit == 1 if a directory */ uint64_t ino_was_rl;/* bit == 1 if reflink flag set */ uint64_t ino_is_rl;/* bit == 1 if reflink flag should be set */ +uint64_t ino_is_meta;/* bit == 1 if metadata */ uint8_t nlink_size;union ino_nlink disk_nlinks;/* on-disk nlinks, set in P3 */ union {
@@ -538,6 +539,24 @@ static inline int inode_is_rl(struct ino_tree_node *irec, int offset)return (irec->ino_is_rl &IREC_MASK (offset)) !=0 ; } +/* +* set/clear/test was inode marked as metadata +*/ +static inline void set_inode_is_meta (struct ino_tree_node *irec,int offset) +{ + irec->ino_is_meta |=IREC_MASK (offset); +} + +static inline void clear_inode_is_meta (struct ino_tree_node *irec,int offset) +{ + irec->ino_is_meta &= ~IREC_MASK (offset); +} + +static inline int inode_is_meta (struct ino_tree_node *irec,int offset) +{ +return (irec->ino_is_meta &IREC_MASK (offset)) !=0 ; +} +/* * add_inode_reached() is set on inode I only if I has been reached * by an inode P claiming to be the parent and if I is a directory,
repair/incore_ino.c +1 -0
@@ -257,6 +257,7 @@ alloc_ino_node( irec->ino_isa_dir =0 ; irec->ino_was_rl =0 ; irec->ino_is_rl =0 ; + irec->ino_is_meta =0 ; irec->ir_free = (xfs_inofree_t) -1 ; irec->ir_sparse =0 ; irec->ino_un.ex_data =NULL ;
repair/phase2.c +6 -1
@@ -557,8 +557,10 @@ phase2(*/ ino_rec =set_inode_used_alloc (mp,0 ,XFS_INO_TO_AGINO (mp, sb->sb_rootino)); -for (j =1 ; j < inuse; j++) +for (j =1 ; j < inuse; j++) {set_inode_used (ino_rec, j); +set_inode_is_meta (ino_rec, j); + }for (j = inuse; j <XFS_INODES_PER_CHUNK ; j++)set_inode_free (ino_rec, j);
@@ -594,6 +596,7 @@ phase2(else do_warn (_ ("would correct\n" )); } +set_inode_is_meta (ino_rec, j); j++; }
@@ -605,6 +608,7 @@ phase2(else do_warn (_ ("would correct\n" )); } +set_inode_is_meta (ino_rec, j); j++;if (is_inode_free (ino_rec, j)) {
@@ -615,6 +619,7 @@ phase2(else do_warn (_ ("would correct\n" )); } +set_inode_is_meta (ino_rec, j); j++; }
repair/phase6.c +63 -0
75 lines not on this page · raw message
PATCH 27/38 xfs_repair: update incore metadata state whenever we create new files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make sure that we update our incore metadata inode bookkeepping whenever we create new metadata files. There will be many more of these later.
--- repair/phase6.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
repair/phase6.c +19 -0
@@ -474,6 +474,24 @@ reset_sbroot_ino(libxfs_inode_init (tp, &args, ip); } +/* +* Mark a newly allocated inode as metadata in the incore bitmap. Callers +* must have already called mark_ino_inuse to ensure there is an incore record. +*/ +static void +mark_ino_metadata ( +struct xfs_mount *mp, +xfs_ino_t ino) +{ +struct ino_tree_node *irec; +int ino_offset; + + irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, ino), +XFS_INO_TO_AGINO (mp, ino)); + ino_offset =get_inode_offset (mp, ino, irec); +set_inode_is_meta (irec, ino_offset); +} +/* Load a realtime freespace metadata inode from disk and reset it. */ static int ensure_rtino(
@@ -693,6 +711,7 @@ mk_metadir(libxfs_trans_ijoin (tp, mp->m_metadirip,0 );libxfs_metafile_set_iflag (tp, mp->m_metadirip,XFS_METAFILE_DIR ); +mark_ino_metadata (mp, mp->m_metadirip->i_ino); error = -libxfs_trans_commit (tp);if (error)
PATCH 28/38 xfs_repair: pass private data pointer to scan_lbtree
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Pass a private data pointer through scan_lbtree. We'll use this later when scanning the rtrmapbt to keep track of scan state.
--- repair/dinode.c | 2 +- repair/scan.c | 11 +++++++---- repair/scan.h | 7 +++++-- 3 files changed, 13 insertions(+), 7 deletions(-)
repair/dinode.c +1 -1
@@ -839,7 +839,7 @@ _("bad bmap btree ptr 0x%" PRIx64 " in ino %" PRIu64 "\n"),if (scan_lbtree (get_unaligned_be64 (&pp[i]), level, scan_bmapbt, type, whichfork, lino, tot, nex, blkmapp, - &cursor,1 , check_dups, magic, + &cursor,1 , check_dups, magic,NULL , &xfs_bmbt_buf_ops))return (1 );/*
repair/scan.c +7 -4
@@ -139,7 +139,8 @@ scan_lbtree(int isroot, int check_dups, int *dirty, - uint64_t magic), + uint64_t magic, + void *priv), int type, int whichfork, xfs_ino_t ino,
@@ -150,6 +151,7 @@ scan_lbtree(int isroot, int check_dups, uint64_t magic, + void *priv, const struct xfs_buf_ops *ops) { struct xfs_buf *bp;
@@ -181,7 +183,7 @@ scan_lbtree( err = (*func)(XFS_BUF_TO_BLOCK (bp), nlevels -1 , type, whichfork, root, ino, tot, nex, blkmapp, bm_cursor, isroot, check_dups, &dirty, - magic); + magic, priv);ASSERT (dirty ==0 || (dirty && !no_modify));
@@ -210,7 +212,8 @@ scan_bmapbt(int isroot, int check_dups, int *dirty, - uint64_t magic) + uint64_t magic, + void *priv) { int i;int err;
@@ -486,7 +489,7 @@ _("bad bmap btree ptr 0x%llx in ino %" PRIu64 "\n"), err =scan_lbtree (be64_to_cpu (pp[i]), level, scan_bmapbt, type, whichfork, ino, tot, nex, blkmapp, - bm_cursor,0 , check_dups, magic, + bm_cursor,0 , check_dups, magic, priv, &xfs_bmbt_buf_ops);if (err)return (1 );
repair/scan.h +5 -2
@@ -26,7 +26,8 @@ int scan_lbtree(int isroot, int check_dups, int *dirty, - uint64_t magic), + uint64_t magic, + void *priv), int type, int whichfork, xfs_ino_t ino,
@@ -37,6 +38,7 @@ int scan_lbtree(int isroot, int check_dups, uint64_t magic, + void *priv, const struct xfs_buf_ops *ops); int scan_bmapbt(
@@ -53,7 +55,8 @@ int scan_bmapbt(int isroot, int check_dups, int *dirty, - uint64_t magic); + uint64_t magic, + void *priv);void scan_ags(
PATCH 29/38 xfs_repair: mark space used by metadata files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Track space used by metadata files as a separate incore extent type. This ensures that we can warn about cross-linked metadata files, even though we are going to rebuild the entire metadata directory tree in the end.
--- repair/dino_chunks.c | 31 +++++++++++++ repair/dinode.c | 122 ++++++++++++++++++++++++++++++++++++++------------ repair/dinode.h | 6 ++ repair/incore.h | 31 ++++++++----- repair/phase4.c | 2 + repair/scan.c | 30 +++++++++++- 6 files changed, 175 insertions(+), 47 deletions(-)
repair/dino_chunks.c +31 -0
@@ -141,6 +141,16 @@ verify_inode_chunk(xfs_mount_t *mp,_ ("uncertain inode block %d/%d already known\n" ), agno, agbno);break ; +case XR_E_METADATA : +/* +* Files in the metadata directory tree are always +* reconstructed, so it's ok to let go if this block +* is also a valid inode cluster. +*/ +do_warn ( +_ ("inode block %d/%d claimed by metadata file\n" ), + agno, agbno); + fallthrough;case XR_E_UNKNOWN :case XR_E_FREE1 :case XR_E_FREE :
@@ -430,6 +440,7 @@ verify_inode_chunk(xfs_mount_t *mp,set_bmap_ext (agno, cur_agbno, blen,XR_E_MULT );pthread_mutex_unlock (&ag_locks[agno].lock);return 0 ; +case XR_E_METADATA :case XR_E_INO : do_error( _("uncertain inode block overlap, agbno = %d, ino = %" PRIu64 "\n"),
@@ -474,6 +485,16 @@ verify_inode_chunk(xfs_mount_t *mp,_ ("uncertain inode block %" PRIu64" already known\n" ), XFS_AGB_TO_FSB(mp, agno, cur_agbno));break ; +case XR_E_METADATA : +/* +* Files in the metadata directory tree are always +* reconstructed, so it's ok to let go if this block +* is also a valid inode cluster. +*/ +do_warn ( +_ ("inode block %d/%d claimed by metadata file\n" ), + agno, agbno); + fallthrough;case XR_E_UNKNOWN :case XR_E_FREE1 :case XR_E_FREE :
@@ -559,6 +580,16 @@ process_inode_agbno_state(switch (state) {case XR_E_INO :/* already marked */ break ; +case XR_E_METADATA : +/* +* Files in the metadata directory tree are always +* reconstructed, so it's ok to let go if this block is also a +* valid inode cluster. +*/ +do_warn ( +_ ("inode block %d/%d claimed by metadata file\n" ), + agno, agbno); + fallthrough;case XR_E_UNKNOWN :case XR_E_FREE :case XR_E_FREE1 :
repair/dinode.c +93 -29
302 lines not on this page · raw message
repair/dinode.h +4 -2
@@ -27,7 +27,8 @@ process_bmbt_reclist(xfs_mount_t *mp,struct blkmap **blkmapp, uint64_t *first_key, uint64_t *last_key, - int whichfork); + int whichfork, + bool zap_metadata);int scan_bmbt_reclist(
@@ -37,7 +38,8 @@ scan_bmbt_reclist(int type, xfs_ino_t ino, xfs_rfsblock_t *tot, - int whichfork); + int whichfork, + bool zap_metadata);void update_rootino (xfs_mount_t *mp);
repair/incore.h +19 -12
@@ -85,18 +85,25 @@ typedef struct rt_extent_tree_node {#define XR_E_UNKNOWN 0/* unknown state */ #define XR_E_FREE1 1/* free block (marked by one fs space tree) */ #define XR_E_FREE 2/* free block (marked by both fs space trees) */ -#define XR_E_INUSE 3/* extent used by file/dir data or metadata */ -#define XR_E_INUSE_FS 4/* extent used by fs ag header or log */ -#define XR_E_MULT 5/* extent is multiply referenced */ -#define XR_E_INO 6/* extent used by inodes (inode blocks) */ -#define XR_E_FS_MAP 7/* extent used by fs space/inode maps */ -#define XR_E_INUSE1 8/* used block (marked by rmap btree) */ -#define XR_E_INUSE_FS1 9/* used by fs ag header or log (rmap btree) */ -#define XR_E_INO1 10/* used by inodes (marked by rmap btree) */ -#define XR_E_FS_MAP1 11/* used by fs space/inode maps (rmap btree) */ -#define XR_E_REFC 12/* used by fs ag reference count btree */ -#define XR_E_COW 13/* leftover cow extent */ -#define XR_E_BAD_STATE 14 +/* +* Space used by metadata files. The entire metadata directory tree will be +* rebuilt from scratch during phase 6, so this value must be less than +* XR_E_INUSE so that the space will go back to the free space btrees during +* phase 5. +*/ +#define XR_E_METADATA 3 +#define XR_E_INUSE 4/* extent used by file/dir data or metadata */ +#define XR_E_INUSE_FS 5/* extent used by fs ag header or log */ +#define XR_E_MULT 6/* extent is multiply referenced */ +#define XR_E_INO 7/* extent used by inodes (inode blocks) */ +#define XR_E_FS_MAP 8/* extent used by fs space/inode maps */ +#define XR_E_INUSE1 9/* used block (marked by rmap btree) */ +#define XR_E_INUSE_FS1 10/* used by fs ag header or log (rmap btree) */ +#define XR_E_INO1 11/* used by inodes (marked by rmap btree) */ +#define XR_E_FS_MAP1 12/* used by fs space/inode maps (rmap btree) */ +#define XR_E_REFC 13/* used by fs ag reference count btree */ +#define XR_E_COW 14/* leftover cow extent */ +#define XR_E_BAD_STATE 15/* separate state bit, OR'ed into high (4th) bit of ex_state field */
repair/phase4.c +2 -0
@@ -303,6 +303,7 @@ phase4(xfs_mount_t *mp)_ ("unknown block state, ag %d, blocks %u-%u\n" ), i, j, j + blen - 1); fallthrough; +case XR_E_METADATA :case XR_E_UNKNOWN :case XR_E_FREE :case XR_E_INUSE :
@@ -335,6 +336,7 @@ phase4(xfs_mount_t *mp)_ ("unknown rt extent state, extent %" PRIu64"\n" ), rtx); fallthrough; +case XR_E_METADATA :case XR_E_UNKNOWN :case XR_E_FREE1 :case XR_E_FREE :
repair/scan.c +26 -4
@@ -227,6 +227,7 @@ scan_bmapbt(xfs_agnumber_t agno;xfs_agblock_t agbno;int state; +bool zap_metadata = priv !=NULL ;/* * unlike the ag freeblock btrees, if anything looks wrong
@@ -352,7 +353,20 @@ _("bad back (left) sibling pointer (saw %llu should be NULL (0))\n"case XR_E_UNKNOWN :case XR_E_FREE1 :case XR_E_FREE : -set_bmap (agno, agbno,XR_E_INUSE ); +set_bmap (agno, agbno, zap_metadata ?XR_E_METADATA : +XR_E_INUSE ); +break ; +case XR_E_METADATA : +/* +* bmbt block already claimed by a metadata file. We +* always reconstruct the entire metadata tree, so if +* this is a regular file we mark it owned by the file. +*/ +do_warn ( +_ ("inode 0x%" PRIx64"bmap block 0x%" PRIx64" claimed by metadata file\n" ), + ino, bno); +if (!zap_metadata) +set_bmap (agno, agbno,XR_E_INUSE );break ;case XR_E_FS_MAP :case XR_E_INUSE :
@@ -364,7 +378,8 @@ _("bad back (left) sibling pointer (saw %llu should be NULL (0))\n"* we made it here, the block probably * contains btree data. */ -set_bmap (agno, agbno,XR_E_MULT ); +if (!zap_metadata) +set_bmap (agno, agbno,XR_E_MULT );do_warn (_ ("inode 0x%" PRIx64"bmap block 0x%" PRIx64" claimed, state is %d\n" ), ino, bno, state);
@@ -429,7 +444,8 @@ _("inode %" PRIu64 " bad # of bmap records (%" PRIu64 ", min - %u, max - %u)\n")if (check_dups ==0 ) { err =process_bmbt_reclist (mp, rp, &numrecs, type, ino, tot, blkmapp, &first_key, - &last_key, whichfork); + &last_key, whichfork, + zap_metadata);if (err)return 1 ;
@@ -459,7 +475,7 @@ _("out-of-order bmap key (file offset) in inode %" PRIu64 ", %s fork, fsbno %" Preturn 0 ; } else {return scan_bmbt_reclist (mp, rp, &numrecs, type, ino, - tot, whichfork); + tot, whichfork, zap_metadata); } } if (numrecs > mp->m_bmap_dmxr[1] || (isroot == 0 && numrecs <
@@ -849,6 +865,12 @@ process_rmap_rec(break ; }break ; +case XR_E_METADATA : +do_warn ( +_ ("Metadata file block (%d,%d-%d) mismatch in %s tree, state - %d,%" PRIx64"\n" ), + agno, b, b + blen -1 , + name, state, owner); +break ;case XR_E_INUSE_FS :if (owner ==XFS_RMAP_OWN_FS || owner ==XFS_RMAP_OWN_LOG )
PATCH 30/38 xfs_repair: adjust keep_fsinos to handle metadata directories
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In keep_fsinos, mark the root of the metadata directory tree as inuse. The realtime bitmap and summary files still come after the root directories, so this is a fairly simple change to the loop test.
--- repair/phase5.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
repair/phase5.c +7 -2
@@ -419,13 +419,18 @@ static void keep_fsinos(xfs_mount_t *mp) {ino_tree_node_t *irec; -int i; +unsigned int inuse =xfs_rootrec_inodes_inuse (mp), i; irec =find_inode_rec (mp,XFS_INO_TO_AGNO (mp, mp->m_sb.sb_rootino),XFS_INO_TO_AGINO (mp, mp->m_sb.sb_rootino)); -for (i =0 ; i <3 ; i++) +for (i =0 ; i < inuse; i++) {set_inode_used (irec, i); + +/* Everything after the root dir is metadata */ +if (i) +set_inode_is_meta (irec, i); + } } static void
PATCH 31/38 xfs_repair: metadata dirs are never plausible root dirs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Metadata directories are never candidates to be the root of the user-accessible directory tree. Update has_plausible_rootdir to ignore them all, as well as detecting the case where the superblock incorrectly thinks both trees have the same root.
--- repair/xfs_repair.c | 6 ++++++ 1 file changed, 6 insertions(+)
repair/xfs_repair.c +6 -0
@@ -546,9 +546,15 @@ has_plausible_rootdir(int error;bool ret = false; +if (xfs_has_metadir (mp) && + mp->m_sb.sb_rootino == mp->m_sb.sb_metadirino) + goto out; + error = -libxfs_iget (mp,NULL , mp->m_sb.sb_rootino,0 , &ip);if (error) goto out; +if (xfs_is_metadir_inode (ip)) + goto out_rele;if (!S_ISDIR (VFS_I (ip)->i_mode)) goto out_rele;
PATCH 32/38 xfs_repair: drop all the metadata directory files during pass 4
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Drop the entire metadata directory tree during pass 4 so that we can reinitialize the entire tree in phase 6. The existing metadata files (rtbitmap, rtsummary, quotas) will be reattached to the newly rebuilt directory tree.
--- repair/dinode.c | 14 +++++++++++++- repair/scan.c | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-)
repair/dinode.c +13 -1
@@ -656,7 +656,7 @@ _("illegal state %d in block map %" PRIu64 "\n"),break ; } } -if (collect_rmaps)/* && !check_dups */ +if (collect_rmaps && !zap_metadata)/* && !check_dups */ rmap_add_rec (mp, ino, whichfork, &irec); *tot += irec.br_blockcount; }
@@ -3123,6 +3123,18 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "),*/ *dirty +=process_check_inode_nlink_version (dino, lino); +/* +* The entire metadata directory tree will be rebuilt during phase 6. +* Therefore, if we're at the end of phase 4 and this is a metadata +* file, zero the ondisk inode and the incore state. +*/ +if (check_dups && zap_metadata && !no_modify) { +clear_dinode (mp, dino, lino); + *dirty +=1 ; + *used = is_free; + *isa_dir =0 ; + } +return retval; clear_bad_out:
repair/scan.c +1 -1
@@ -418,7 +418,7 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"), numrecs =be16_to_cpu (block->bb_numrecs);/* Record BMBT blocks in the reverse-mapping data. */ -if (check_dups && collect_rmaps) { +if (check_dups && collect_rmaps && !zap_metadata) { agno =XFS_FSB_TO_AGNO (mp, bno);pthread_mutex_lock (&ag_locks[agno].lock);rmap_add_bmbt_rec (mp, ino, whichfork, bno);
PATCH 33/38 xfs_repair: truncate and unmark orphaned metadata inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If an inode claims to be a metadata inode but wasn't linked in either directory tree, remove the attr fork and reset the data fork if the contents weren't regular extent mappings before moving the inode to the lost+found.
We don't ifree the inode, because it's possible that the inode was not actually a metadata inode but simply got corrupted due to bitflips or something, and we'd rather let the sysadmin examine what's left of the file instead of photorec'ing it.
--- repair/phase6.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
repair/phase6.c +50 -0
@@ -855,6 +855,53 @@ mk_orphanage(return (ino); } +/* Don't let metadata inode contents leak to lost+found. */ +static void +trunc_metadata_inode ( +struct xfs_inode *ip) +{ +struct xfs_trans *tp; +struct xfs_mount *mp = ip->i_mount; +int err; + + err = -libxfs_trans_alloc (mp, &M_RES (mp)->tr_ichange,0 ,0 ,0 , &tp); +if (err) +do_error ( +_ ("space reservation failed (%d), filesystem may be out of space\n" ), + err); + +libxfs_trans_ijoin (tp, ip,0 ); + ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA ; + +switch (VFS_I (ip)->i_mode &S_IFMT ) { +case S_IFIFO : +case S_IFCHR : +case S_IFBLK : +case S_IFSOCK : + ip->i_df.if_format =XFS_DINODE_FMT_DEV ; +break ; +case S_IFREG : +switch (ip->i_df.if_format) { +case XFS_DINODE_FMT_EXTENTS : +case XFS_DINODE_FMT_BTREE : +break ; +default : + ip->i_df.if_format =XFS_DINODE_FMT_EXTENTS ; + ip->i_df.if_nextents =0 ; +break ; + } +break ; + } + +libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); + + err = -libxfs_trans_commit (tp); +if (err) +do_error ( +_ ("truncation of metadata inode 0x%llx failed, err=%d\n" ), + (unsigned long long )ip->i_ino, err); +} +/* * Add a parent pointer back to the orphanage for any file we're moving into * the orphanage, being careful not to trip over any existing parent pointer.
@@ -945,6 +992,9 @@ mv_orphanage(if (err)do_error (_ ("%d - couldn't iget disconnected inode\n" ), err); +if (xfs_is_metadir_inode (ino_p)) +trunc_metadata_inode (ino_p); + xname.type =libxfs_mode_to_ftype (VFS_I (ino_p)->i_mode);if (isa_dir) {
PATCH 34/38 xfs_repair: do not count metadata directory files when doing quotacheck
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Previously, we stated that files in the metadata directory tree are not counted in the dquot information. Fix the offline quotacheck code in xfs_repair and xfs_check to reflect this.
--- repair/quotacheck.c | 5 +++++ 1 file changed, 5 insertions(+)
repair/quotacheck.c +5 -0
@@ -217,6 +217,10 @@ quotacheck_adjust(return ; } +/* Metadata directory files aren't counted in quota. */ +if (xfs_is_metadir_inode (ip)) + goto out_rele; +/* Count the file's blocks. */ if (XFS_IS_REALTIME_INODE (ip)) rtblks =qc_count_rtblocks (ip);
@@ -229,6 +233,7 @@ quotacheck_adjust(if (proj_dquots)qc_adjust (proj_dquots, ip->i_projid, blocks, rtblks); +out_rele:libxfs_irele (ip); }
PATCH 35/38 xfs_repair: fix maximum file offset comparison
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When running generic/525 with rtinherit=1 and rextsize=28k, generic/525 trips over the following block mapping:
data offset 2251799813685247 startblock 7 (0/7) count 1 flag 0 data offset 2251799813685248 startblock 8 (0/8) count 6 flag 1
with this error:
inode 155 - extent exceeds max offset - start 2251799813685248, count 6, physical block 8
This is due to an incorrect check in xfs_repair, which tries to validate that a block mapping cannot exceed what it thinks is the maximum file offset. Unfortunately, the check is wrong, because only br_startoff is subject to the 2^52-1 limit -- not br_startoff + br_blockcount.
Nowadays libxfs provides a symbol XFS_MAX_FILEOFF for the maximum allowable file block offset that can be mapped into a file. Use this instead of the open-coded logic in versions.c and correct all the other checks. Note that this problem only surfaced when rtgroups were enabled because hch changed xfs_repair to use the same tree-based block state data structure that we use for AGs when rtgroups are enabled.
--- repair/dinode.c | 2 +- repair/globals.c | 1 - repair/globals.h | 1 - repair/prefetch.c | 2 +- repair/versions.c | 7 +------ 5 files changed, 3 insertions(+), 10 deletions(-)
repair/dinode.c +1 -1
@@ -501,7 +501,7 @@ _("inode %" PRIu64 " - bad extent overflows - start %" PRIu64 ", " }/* Ensure this extent does not extend beyond the max offset */ if (irec.br_startoff + irec.br_blockcount -1 > - fs_max_file_offset) { +XFS_MAX_FILEOFF ) { do_warn( _("inode %" PRIu64 " - extent exceeds max offset - start %" PRIu64 ", " "count %" PRIu64 ", physical block %" PRIu64 "\n"),
repair/globals.c +0 -1
@@ -86,7 +86,6 @@ int inodes_per_block;unsigned int glob_agcount;int chunks_pblock;/* # of 64-ino chunks per allocation */ int max_symlink_blocks; -int64_t fs_max_file_offset;/* realtime info */
repair/globals.h +0 -1
@@ -127,7 +127,6 @@ extern int inodes_per_block;extern unsigned int glob_agcount;extern int chunks_pblock;/* # of 64-ino chunks per allocation */ extern int max_symlink_blocks; -extern int64_t fs_max_file_offset;/* realtime info */
repair/prefetch.c +1 -1
@@ -185,7 +185,7 @@ pf_read_bmbt_reclist(if (((i >0 ) && (op + cp > irec.br_startoff)) || (irec.br_blockcount ==0 ) || - (irec.br_startoff >= fs_max_file_offset)) + (irec.br_startoff + irec.br_blockcount -1 >=XFS_MAX_FILEOFF )) goto out_free; if (!libxfs_verify_fsbno(mp, irec.br_startblock) ||
repair/versions.c +1 -6
@@ -180,10 +180,5 @@ _("WARNING: you have a V1 inode filesystem. It would be converted to a\n" fs_ino_alignment = mp->m_sb.sb_inoalignmt; } -/* -* calculate maximum file offset for this geometry -*/ - fs_max_file_offset =0x7fffffffffffffffLL >> mp->m_sb.sb_blocklog; - -return (0 ); +return 0 ; }
PATCH 36/38 xfs_repair: refactor generate_rtinfo
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Move the allocation of the computed values into generate_rtinfo, and thus make the variables holding them private in rt.c, and clean up a few formatting nits.
--- repair/globals.c | 5 -- repair/globals.h | 5 -- repair/phase5.c | 3 - repair/phase6.c | 51 +---------------- repair/rt.c | 160 ++++++++++++++++++++++++++++++++---------------------- repair/rt.h | 12 +--- 6 files changed, 104 insertions(+), 132 deletions(-)
repair/globals.c +0 -5
@@ -87,11 +87,6 @@ unsigned int glob_agcount;int chunks_pblock;/* # of 64-ino chunks per allocation */ int max_symlink_blocks; -/* realtime info */ - -union xfs_rtword_raw *btmcompute; -union xfs_suminfo_raw *sumcompute; -/* inode tree records have full or partial backptr fields ? */ int full_ino_ex_data;/*
repair/globals.h +0 -5
@@ -128,11 +128,6 @@ extern unsigned int glob_agcount;extern int chunks_pblock;/* # of 64-ino chunks per allocation */ extern int max_symlink_blocks; -/* realtime info */ - -extern union xfs_rtword_raw *btmcompute; -extern union xfs_suminfo_raw *sumcompute; -/* inode tree records have full or partial backptr fields ? */ extern int full_ino_ex_data;/*
repair/phase5.c +1 -2
@@ -627,8 +627,7 @@ voidcheck_rtmetadata ( struct xfs_mount *mp) { -rtinit (mp); -generate_rtinfo (mp, btmcompute, sumcompute); +generate_rtinfo (mp);check_rtbitmap (mp);check_rtsummary (mp); }
repair/phase6.c +3 -48
69 lines not on this page · raw message
repair/rt.c +96 -64
206 lines not on this page · raw message
repair/rt.h +4 -8
@@ -6,15 +6,11 @@#ifndef _XFS_REPAIR_RT_H_#define _XFS_REPAIR_RT_H_ -struct blkmap ; - -void -rtinit (xfs_mount_t *mp); - -int generate_rtinfo (struct xfs_mount *mp,union xfs_rtword_raw *words, -union xfs_suminfo_raw *sumcompute); - +void generate_rtinfo (struct xfs_mount *mp);void check_rtbitmap (struct xfs_mount *mp);void check_rtsummary (struct xfs_mount *mp); +void fill_rtbitmap (struct xfs_mount *mp); +void fill_rtsummary (struct xfs_mount *mp); +#endif /* _XFS_REPAIR_RT_H_ */
PATCH 37/38 mkfs.xfs: enable metadata directories
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable formatting filesystems with metadata directories.
--- libxfs/libxfs_api_defs.h | 2 + man/man8/mkfs.xfs.8.in | 11 +++++++ mkfs/lts_4.19.conf | 1 + mkfs/lts_5.10.conf | 1 + mkfs/lts_5.15.conf | 1 + mkfs/lts_5.4.conf | 1 + mkfs/lts_6.1.conf | 1 + mkfs/lts_6.6.conf | 1 + mkfs/proto.c | 68 +++++++++++++++++++++++++++++++++++++++++++++- mkfs/xfs_mkfs.c | 29 ++++++++++++++++++-- 10 files changed, 113 insertions(+), 3 deletions(-)
libxfs/libxfs_api_defs.h +2 -0
@@ -216,6 +216,8 @@#define xfs_metafile_iget libxfs_metafile_iget#define xfs_trans_metafile_iget libxfs_trans_metafile_iget#define xfs_metafile_set_iflag libxfs_metafile_set_iflag +#define xfs_metadir_cancel libxfs_metadir_cancel +#define xfs_metadir_commit libxfs_metadir_commit#define xfs_metadir_link libxfs_metadir_link#define xfs_metadir_lookup libxfs_metadir_lookup#define xfs_metadir_start_create libxfs_metadir_start_create
man/man8/mkfs.xfs.8.in +11 -0
@@ -271,6 +271,17 @@ .SH OPTIONS When the option .B \-m finobt=0 is used, the inode btree counter feature is not supported and is disabled. +.TP +.BI metadir= value +This option creates an internal directory tree to store filesystem metadata. +.IP +By default, +.B mkfs.xfs +will not enable this feature. +If the option +.B \-m crc=0 +is used, the metadata directory feature is not supported and is disabled. + .TP .BI uuid= value Use the given value as the filesystem UUID for the newly created filesystem.
mkfs/lts_4.19.conf +1 -0
@@ -6,6 +6,7 @@ crc=1 finobt=1 inobtcount=0 +metadir=0 reflink=0 rmapbt=0 autofsck=0
mkfs/lts_5.10.conf +1 -0
@@ -6,6 +6,7 @@ crc=1 finobt=1 inobtcount=0 +metadir=0 reflink=1 rmapbt=0 autofsck=0
mkfs/lts_5.15.conf +1 -0
@@ -6,6 +6,7 @@ crc=1 finobt=1 inobtcount=1 +metadir=0 reflink=1 rmapbt=0 autofsck=0
mkfs/lts_5.4.conf +1 -0
@@ -6,6 +6,7 @@ crc=1 finobt=1 inobtcount=0 +metadir=0 reflink=1 rmapbt=0 autofsck=0
mkfs/lts_6.1.conf +1 -0
@@ -6,6 +6,7 @@ crc=1 finobt=1 inobtcount=1 +metadir=0 reflink=1 rmapbt=0 autofsck=0
mkfs/lts_6.6.conf +1 -0
@@ -6,6 +6,7 @@ crc=1 finobt=1 inobtcount=1 +metadir=0 reflink=1 rmapbt=1 autofsck=0
mkfs/proto.c +67 -1
81 lines not on this page · raw message
mkfs/xfs_mkfs.c +27 -2
@@ -150,6 +150,7 @@ enum {M_INOBTCNT ,M_BIGTIME ,M_AUTOFSCK , +M_METADIR , M_MAX_OPTS, };
@@ -812,6 +813,7 @@ static struct opt_params mopts = { [M_INOBTCNT] = "inobtcount", [M_BIGTIME] = "bigtime", [M_AUTOFSCK] = "autofsck", + [M_METADIR] = "metadir", [M_MAX_OPTS ] =NULL , }, .subopt_params = {
@@ -861,6 +863,12 @@ static struct opt_params mopts = { .maxval = 1, .defaultval = 1, }, + { .index = M_METADIR, + .conflicts = { { NULL, LAST_CONFLICT } }, + .minval = 0, + .maxval = 1, + .defaultval = 1, + }, }, };
@@ -913,6 +921,7 @@ struct sb_feat_args {bool reflink;/* XFS_SB_FEAT_RO_COMPAT_REFLINK */ bool inobtcnt;/* XFS_SB_FEAT_RO_COMPAT_INOBTCNT */ bool bigtime;/* XFS_SB_FEAT_INCOMPAT_BIGTIME */ +bool metadir;/* XFS_SB_FEAT_INCOMPAT_METADIR */ bool nodalign;bool nortalign;bool nrext64;
@@ -1048,7 +1057,8 @@ usage( void ) /* blocksize */ [-b size=num]\n\ /* config file */ [-c options=xxx]\n\ /* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1,reflink=0|1,\n\ - inobtcount=0|1,bigtime=0|1,autofsck=xxx]\n\ + inobtcount=0|1,bigtime=0|1,autofsck=xxx,\n\ + metadir=0|1]\n\ /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\ (sunit=value,swidth=value|su=num,sw=num|noalign),\n\ sectsize=num,concurrency=num]\n\
@@ -1883,6 +1893,9 @@ meta_opts_parser(illegal (value,"m autofsck" ); }break ; +case M_METADIR : + cli->sb_feat.metadir =getnum (value, opts, subopt); +break ;default :return -EINVAL ; }
@@ -2465,6 +2478,14 @@ _("autofsck not supported without CRC support\n"));usage (); } cli->autofsck =FSPROP_AUTOFSCK_UNSET ; + +if (cli->sb_feat.metadir && +cli_opt_set (&mopts,M_METADIR )) { +fprintf (stderr, +_ ("metadata directory not supported without CRC support\n" )); +usage (); + } + cli->sb_feat.metadir = false; }if (!cli->sb_feat.finobt) {
@@ -3568,7 +3589,8 @@ sb_set_features(* the sb_bad_features2 field. To avoid older kernels mounting * filesystems they shouldn't, set both field to the same value. */ - sbp->sb_bad_features2 = sbp->sb_features2; +if (!fp->metadir) + sbp->sb_bad_features2 = sbp->sb_features2;if (!fp->crcs_enabled)return ;
@@ -3618,6 +3640,8 @@ sb_set_features(*/ sbp->sb_versionnum |=XFS_SB_VERSION_ATTRBIT ; } +if (fp->metadir) + sbp->sb_features_incompat |=XFS_SB_FEAT_INCOMPAT_METADIR ; }/*
@@ -4053,6 +4077,7 @@ finish_superblock_setup(platform_uuid_copy (&sbp->sb_meta_uuid, &cfg->uuid); sbp->sb_logstart = cfg->logstart; sbp->sb_rootino = sbp->sb_rbmino = sbp->sb_rsumino =NULLFSINO ; + sbp->sb_metadirino =NULLFSINO ; sbp->sb_agcount = (xfs_agnumber_t )cfg->agcount; sbp->sb_rbmblocks = cfg->rtbmblocks; sbp->sb_logblocks = (xfs_extlen_t )cfg->logblocks;
PATCH 38/38 mkfs: add a utility to generate protofiles
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a new utility to generate mkfs protofiles from a directory tree.
--- man/man8/xfs_protofile.8 | 33 ++++++++++ mkfs/Makefile | 10 +++ mkfs/xfs_protofile.in | 152 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 man/man8/xfs_protofile.8 create mode 100644 mkfs/xfs_protofile.in
man/man8/xfs_protofile.8 new file +33 -0
@@ -0,0 +1,33 @@ +.TH xfs_protofile 8 +.SH NAME +xfs_protofile \- create a protofile for use with mkfs.xfs +.SH SYNOPSIS +.B xfs_protofile +.I path +[ +.I paths... +] +.br +.B xfs_protofile \-V +.SH DESCRIPTION +.B xfs_protofile +walks a directory tree to generate a protofile. +The protofile format is specified in the +.BR mkfs.xfs (8) +manual page and is derived from 3rd edition Unix. +.SH OPTIONS +.TP 1.0i +.I path +Create protofile directives to copy this path into the root directory. +If the path is a directory, protofile directives will be emitted to +replicate the entire subtree as a subtree of the root directory. +If the path is a not a directory, protofile directives will be emitted +to create the file as an entry in the root directory. +The first path must resolve to a directory. + +.SH BUGS +Filenames cannot contain spaces. +Extended attributes are not copied into the filesystem. + +.PD +.RE
mkfs/Makefile +9 -1
@@ -6,6 +6,7 @@ TOPDIR = .. include $(TOPDIR)/include/builddefs LTCOMMAND = mkfs.xfs +XFS_PROTOFILE = xfs_protofile HFILES = CFILES = proto.c xfs_mkfs.c
@@ -22,14 +23,21 @@ LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBBLKID) \ $(LIBUUID) $(LIBINIH) $(LIBURCU) $(LIBPTHREAD) LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG) LLDFLAGS = -static-libtool-libs +DIRT = $(XFS_PROTOFILE) -default: depend $(LTCOMMAND) $(CFGFILES) +default: depend $(LTCOMMAND) $(CFGFILES) $(XFS_PROTOFILE) include $(BUILDRULES) +$(XFS_PROTOFILE): $(XFS_PROTOFILE).in + @echo " [SED] $@" + $(Q)$(SED) -e "s|@pkg_version@|$(PKG_VERSION)|g" < $< > $@ + $(Q)chmod a+x $@ + install: default $(INSTALL) -m 755 -d $(PKG_SBIN_DIR) $(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR) + $(INSTALL) -m 755 $(XFS_PROTOFILE) $(PKG_SBIN_DIR) $(INSTALL) -m 755 -d $(MKFS_CFG_DIR) $(INSTALL) -m 644 $(CFGFILES) $(MKFS_CFG_DIR)
mkfs/xfs_protofile.in new file +152 -0
152 lines not on this page · raw message
PATCH 2/5 xfsprogs: preparation for realtime allocation groups
In reply to Darrick J. WongHi all,
Clean up the userspace utilities libraries prior to merging of realtime allocation groups.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=rtgroups-prep
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=rtgroups-prep
---
Commits in this patchset:
* libfrog: add memchr_inv
* xfs_repair: remove calls to xfs_rtb_round{up,down}_rtx
--- libfrog/util.c | 14 ++++++++++++++ libfrog/util.h | 4 ++++ repair/dinode.c | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-)
PATCH 1/2 libfrog: add memchr_inv
From: Darrick J. Wong <[email protected]>
Add this kernel function so we can use it in userspace.
--- libfrog/util.c | 14 ++++++++++++++ libfrog/util.h | 4 ++++ 2 files changed, 18 insertions(+)
libfrog/util.c +14 -0
@@ -22,3 +22,17 @@ log2_roundup(unsigned int i) }return rval; } + +void * +memchr_inv (const void *start,int c,size_t bytes) +{ +const unsigned char *p = start; + +while (bytes >0 ) { +if (*p != (unsigned char )c) +return (void *)p; + bytes--; + } + +return NULL ; +}
libfrog/util.h +4 -0
@@ -6,6 +6,8 @@#ifndef __LIBFROG_UTIL_H__#define __LIBFROG_UTIL_H__ +#include <sys/types.h> +unsigned int log2_roundup (unsigned int i);#define min_t (type,x,y) \
@@ -13,4 +15,6 @@ unsigned int log2_roundup(unsigned int i);#define max_t (type,x,y) \ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) +void *memchr_inv (const void *start,int c,size_t bytes); +#endif /* __LIBFROG_UTIL_H__ */
PATCH 2/2 xfs_repair: remove calls to xfs_rtb_round{up,down}_rtx
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The kernel will remove xfs_rtb_roundup_rtx soon, so open code the single caller using the mod value that we already computed.
The kernel will remove xfs_rtb_rounddown_rtx soon, so remove the call because the xfs_rtb_to_rtx call below it already does the rounding for us.
--- repair/dinode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
repair/dinode.c +2 -2
@@ -197,7 +197,7 @@ process_rt_rec_dups(xfs_rtblock_t b;xfs_rtxnum_t ext; -for (b =xfs_rtb_rounddown_rtx (mp, irec->br_startblock); +for (b = irec->br_startblock; b < irec->br_startblock + irec->br_blockcount; b += mp->m_sb.sb_rextsize) { ext =xfs_rtb_to_rtx (mp, b);
@@ -245,7 +245,7 @@ process_rt_rec_state(do_error (_ ("data fork in rt inode %" PRIu64" found invalid rt extent %" PRIu64" state %d at rt block %" PRIu64"\n" ), ino, ext, state, b); - b =xfs_rtb_roundup_rtx (mp, b); + b += mp->m_sb.sb_rextsize - mod;continue ; }
PATCH 3/5 xfsprogs: shard the realtime section
In reply to Darrick J. WongHi all,
Right now, the realtime section uses a single pair of metadata inodes to store the free space information. This presents a scalability problem since every thread trying to allocate or free rt extents have to lock these files. Solve this problem by sharding the realtime section into separate realtime allocation groups.
While we're at it, define a superblock to be stamped into the start of the rt section. This enables utilities such as blkid to identify block devices containing realtime sections, and avoids the situation where anything written into block 0 of the realtime extent can be misinterpreted as file data.
The best advantage for rtgroups will become evident later when we get to adding rmap and reflink to the realtime volume, since the geometry constraints are the same for rt groups and AGs. Hence we can reuse all that code directly.
This is a very large patchset, but it catches us up with 20 years of technical debt that have accumulated.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=realtime-groups
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=realtime-groups
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=realtime-groups
xfsdocs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-documentation.git/log/?h=realtime-groups
---
Commits in this patchset:
* man: document the rt group geometry ioctl
* libxfs: port userspace deferred log item to handle rtgroups
* libxfs: implement some sanity checking for enormous rgcount
* libfrog: support scrubbing rtgroup metadata paths
* libfrog: report rt groups in output
* libfrog: add bitmap_clear
* xfs_logprint: report realtime EFIs
* xfs_repair: adjust rtbitmap/rtsummary word updates to handle big endian values
* xfs_repair: refactor phase4
* xfs_repair: refactor offsetof+sizeof to offsetofend
* xfs_repair: improve rtbitmap discrepancy reporting
* xfs_repair: simplify rt_lock handling
* xfs_repair: add a real per-AG bitmap abstraction
* xfs_repair: support realtime groups
* repair: use a separate bmaps array for real time groups
* xfs_repair: find and clobber rtgroup bitmap and summary files
* xfs_repair: support realtime superblocks
* xfs_repair: repair rtbitmap and rtsummary block headers
* xfs_repair: stop tracking duplicate RT extents with rtgroups
* xfs_db: listify the definition of enum typnm
* xfs_db: support dumping realtime group data and superblocks
* xfs_db: support changing the label and uuid of rt superblocks
* xfs_db: enable conversion of rt space units
* xfs_db: metadump metadir rt bitmap and summary files
* xfs_db: metadump realtime devices
* xfs_db: dump rt bitmap blocks
* xfs_db: dump rt summary blocks
* xfs_db: report rt group and block number in the bmap command
* xfs_mdrestore: restore rt group superblocks to realtime device
* xfs_io: support scrubbing rtgroup metadata
* xfs_io: support scrubbing rtgroup metadata paths
* xfs_io: add a command to display allocation group information
* xfs_io: add a command to display realtime group information
* xfs_io: display rt group in verbose bmap output
* xfs_io: display rt group in verbose fsmap output
* xfs_spaceman: report on realtime group health
* xfs_scrub: scrub realtime allocation group metadata
* xfs_scrub: check rtgroup metadata directory connections
* xfs_scrub: call GETFSMAP for each rt group in parallel
* xfs_scrub: trim realtime volumes too
* xfs_scrub: use histograms to speed up phase 8 on the realtime volume
* mkfs: add headers to realtime bitmap blocks
* mkfs: format realtime groups
--- db/Makefile | 1 db/bmap.c | 56 +++- db/command.c | 2 db/convert.c | 60 ++++ db/field.c | 20 + db/field.h | 10 + db/inode.c | 36 ++ db/metadump.c | 58 ++++ db/rtgroup.c | 154 ++++++++++ db/rtgroup.h | 21 + db/sb.c | 117 +++++++- db/type.c | 16 + db/type.h | 32 ++ db/xfs_metadump.sh | 5 include/xfs.h | 15 + include/xfs_metadump.h | 8 + io/Makefile | 1 io/aginfo.c | 216 ++++++++++++++ io/bmap.c | 27 +- io/fsmap.c | 22 + io/init.c | 1 io/io.h | 1 io/scrub.c | 81 +++++ libfrog/bitmap.c | 25 +- libfrog/bitmap.h | 1 libfrog/div64.h | 6 libfrog/fsgeom.c | 24 +- libfrog/fsgeom.h | 16 + libfrog/scrub.c | 19 + libfrog/util.c | 12 + libfrog/util.h | 1 libxfs/defer_item.c | 73 +++-- libxfs/init.c | 46 +++ libxfs/libxfs_api_defs.h | 5 libxfs/libxfs_priv.h | 6 libxfs/topology.c | 42 +++ libxfs/topology.h | 3 logprint/log_misc.c | 2 logprint/log_print_all.c | 8 + logprint/log_redo.c | 57 +++- man/man2/ioctl_xfs_rtgroup_geometry.2 | 103 +++++++ man/man8/mkfs.xfs.8.in | 31 ++ man/man8/xfs_db.8 | 17 + man/man8/xfs_io.8 | 29 ++ man/man8/xfs_mdrestore.8 | 10 + man/man8/xfs_metadump.8 | 11 + man/man8/xfs_spaceman.8 | 5 mdrestore/xfs_mdrestore.c | 59 +++- mkfs/proto.c | 88 +++++- mkfs/xfs_mkfs.c | 282 ++++++++++++++++++ repair/agheader.c | 21 - repair/dino_chunks.c | 58 +++- repair/dinode.c | 162 +++++++---- repair/dir2.c | 13 + repair/globals.c | 3 repair/globals.h | 6 repair/incore.c | 235 +++++++++++---- repair/incore.h | 36 ++ repair/incore_ext.c | 3 repair/phase2.c | 51 ++- repair/phase3.c | 4 repair/phase4.c | 221 ++++++++------ repair/phase5.c | 2 repair/phase6.c | 175 +++++++++++ repair/rmap.c | 4 repair/rt.c | 506 +++++++++++++++++++++++++++++---- repair/rt.h | 23 ++ repair/sb.c | 36 ++ repair/scan.c | 36 +- repair/xfs_repair.c | 19 + scrub/phase2.c | 124 ++++++-- scrub/phase5.c | 24 +- scrub/phase7.c | 7 scrub/phase8.c | 36 ++ scrub/scrub.c | 1 scrub/scrub.h | 13 + scrub/spacemap.c | 72 ++++- scrub/xfs_scrub.c | 2 scrub/xfs_scrub.h | 1 spaceman/health.c | 63 ++++ 80 files changed, 3329 insertions(+), 569 deletions(-) create mode 100644 db/rtgroup.c create mode 100644 db/rtgroup.h create mode 100644 io/aginfo.c create mode 100644 man/man2/ioctl_xfs_rtgroup_geometry.2
PATCH 1/43 man: document the rt group geometry ioctl
From: Darrick J. Wong <[email protected]>
Document the new ioctl that retrieves realtime allocation group geometry information.
--- man/man2/ioctl_xfs_rtgroup_geometry.2 | 103 +++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 man/man2/ioctl_xfs_rtgroup_geometry.2
man/man2/ioctl_xfs_rtgroup_geometry.2 new file +103 -0
@@ -0,0 +1,103 @@ +.\" Copyright (c) 2022-2024 Oracle. All rights reserved. +.\" +.\" %%%LICENSE_START(GPLv2+_DOC_FULL) +.\" SPDX-License-Identifier: GPL-2.0-or-later +.\" %%%LICENSE_END +.TH IOCTL-XFS-RTGROUP-GEOMETRY 2 2022-08-18 "XFS" +.SH NAME +ioctl_xfs_rtgroup_geometry \- query XFS realtime group geometry information +.SH SYNOPSIS +.br +.B #include <xfs/xfs_fs.h> +.PP +.BI "int ioctl(int " fd ", XFS_IOC_RTGROUP_GEOMETRY, struct xfs_rtgroup_geometry *" arg ); +.SH DESCRIPTION +This XFS ioctl retrieves the geometry information for a given realtime group. +The geometry information is conveyed in a structure of the following form: +.PP +.in +4n +.nf +struct xfs_rtgroup_geometry { + __u32 rg_number; + __u32 rg_length; + __u32 rg_capacity; + __u32 rg_sick; + __u32 rg_checked; + __u32 rg_flags; + __u64 rg_reserved[13]; +}; +.fi +.in +.TP +.I rg_number +The caller must set this field to the index of the realtime group that the +caller wishes to learn about. +.TP +.I rg_length +The length of the realtime group is returned in this field, in units of +filesystem blocks. +.I rg_capacity +The capacity of the realtime group is returned in this field, in units of +filesystem blocks. This value is smaller or equal to rq_length. +.I rg_flags +The caller can set this field to change the operational behavior of the ioctl. +Currently no flags are defined, so this field must be zero. +.TP +.IR rg_reserved " and " rg_pad +All reserved fields will be set to zero on return. +.PP +The fields +.IR rg_sick " and " rg_checked +indicate the relative health of various realtime group metadata: +.IP \[bu] 2 +If a given sick flag is set in +.IR rg_sick , +then that piece of metadata has been observed to be damaged. +The same bit will be set in +.IR rg_checked . +.IP \[bu] +If a given sick flag is set in +.I rg_checked +and is not set in +.IR rg_sick , +then that piece of metadata has been checked and is not faulty. +.IP \[bu] +If a given sick flag is not set in +.IR rg_checked , +then no conclusion can be made. +.PP +The following flags apply to these fields: +.RS 0.4i +.TP +.B XFS_RTGROUP_GEOM_SICK_SUPER +Realtime group superblock. +.TP +.B XFS_RTGROUP_GEOM_SICK_BITMAP +Realtime bitmap for this group. +.TP +.B XFS_RTGROUP_GEOM_SICK_SUMMARY +Realtime summary for this group. +.RE +.SH RETURN VALUE +On error, \-1 is returned, and +.I errno +is set to indicate the error. +.PP +.SH ERRORS +Error codes can be one of, but are not limited to, the following: +.TP +.B EFSBADCRC +Metadata checksum validation failed while performing the query. +.TP +.B EFSCORRUPTED +Metadata corruption was encountered while performing the query. +.TP +.B EINVAL +The specified realtime group number is not valid for this filesystem. +.TP +.B EIO +An I/O error was encountered while performing the query. +.SH CONFORMING TO +This API is specific to XFS filesystem on the Linux kernel. +.SH SEE ALSO +.BR ioctl (2)
PATCH 2/43 libxfs: port userspace deferred log item to handle rtgroups
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make the userspace log items to handle rt groups correctly.
--- libxfs/defer_item.c | 73 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 24 deletions(-)
libxfs/defer_item.c +49 -24
@@ -77,6 +77,17 @@ xfs_extent_free_create_done(return NULL ; } +static inline const struct xfs_defer_op_type * +xefi_ops ( +struct xfs_extent_free_item *xefi) +{ +if (xfs_efi_is_realtime (xefi)) +return &xfs_rtextent_free_defer_type; +if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) +return &xfs_agfl_free_defer_type; +return &xfs_extent_free_defer_type; +} +/* Add this deferred EFI to the transaction. */ void xfs_extent_free_defer_add(
@@ -86,14 +97,11 @@ xfs_extent_free_defer_add( {struct xfs_mount *mp = tp->t_mountp; +trace_xfs_extent_free_defer (mp, xefi); + xefi->xefi_group =xfs_group_intent_get (mp, xefi->xefi_startblock, -XG_TYPE_AG ); -if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) - *dfpp =xfs_defer_add (tp, &xefi->xefi_list, - &xfs_agfl_free_defer_type); -else - *dfpp =xfs_defer_add (tp, &xefi->xefi_list, - &xfs_extent_free_defer_type); +xfs_efi_is_realtime (xefi) ?XG_TYPE_RTG :XG_TYPE_AG ); + *dfpp =xfs_defer_add (tp, &xefi->xefi_list,xefi_ops (xefi)); }/* Cancel a free extent. */
@@ -159,6 +167,32 @@ const struct xfs_defer_op_type xfs_extent_free_defer_type = { .cancel_item = xfs_extent_free_cancel_item, }; +STATIC int +xfs_rtextent_free_finish_item ( +struct xfs_trans *tp, +struct xfs_log_item *done, +struct list_head *item, +struct xfs_btree_cur **state) +{ +struct xfs_extent_free_item *xefi =xefi_entry (item); +int error; + + error =xfs_rtfree_blocks (tp,to_rtg (xefi->xefi_group), + xefi->xefi_startblock, xefi->xefi_blockcount); +if (error != -EAGAIN ) +xfs_extent_free_cancel_item (item); +return error; +} + +const struct xfs_defer_op_type xfs_rtextent_free_defer_type = { + .name ="rtextent_free" , + .create_intent = xfs_extent_free_create_intent, + .abort_intent = xfs_extent_free_abort_intent, + .create_done = xfs_extent_free_create_done, + .finish_item = xfs_rtextent_free_finish_item, + .cancel_item = xfs_extent_free_cancel_item, +}; +/* * AGFL blocks are accounted differently in the reserve pools and are not * inserted into the busy extent list.
@@ -496,14 +530,16 @@ xfs_bmap_update_create_done(return NULL ; } -/* Take an active ref to the AG containing the space we're mapping. */ +/* Take a passive ref to the group containing the space we're mapping. */ static inline void xfs_bmap_update_get_group (struct xfs_mount *mp,struct xfs_bmap_intent *bi) { +enum xfs_group_type type =XG_TYPE_AG ; +if (xfs_ifork_is_realtime (bi->bi_owner, bi->bi_whichfork)) -return ; + type =XG_TYPE_RTG ;/* * Bump the intent count on behalf of the deferred rmap and refcount
@@ -513,7 +549,7 @@ xfs_bmap_update_get_group(* remains nonzero across the transaction roll. */ bi->bi_group =xfs_group_intent_get (mp, bi->bi_bmap.br_startblock, -XG_TYPE_AG ); + type); }/* Add this deferred BUI to the transaction. */
@@ -522,8 +558,6 @@ xfs_bmap_defer_add(struct xfs_trans *tp, struct xfs_bmap_intent *bi) { -trace_xfs_bmap_defer (bi ); - xfs_bmap_update_get_group(tp->t_mountp, bi);/*
@@ -536,20 +570,11 @@ xfs_bmap_defer_add(*/ if (bi->bi_type ==XFS_BMAP_MAP ) bi->bi_owner->i_delayed_blks += bi->bi_bmap.br_blockcount; + +trace_xfs_bmap_defer (bi);xfs_defer_add (tp, &bi->bi_list, &xfs_bmap_update_defer_type); } -/* Release an active AG ref after finishing mapping work. */ -static inline void -xfs_bmap_update_put_group ( -struct xfs_bmap_intent *bi) -{ -if (xfs_ifork_is_realtime (bi->bi_owner, bi->bi_whichfork)) -return ; - -xfs_group_intent_put (bi->bi_group); -} -/* Cancel a deferred bmap update. */ STATIC void xfs_bmap_update_cancel_item(
@@ -560,7 +585,7 @@ xfs_bmap_update_cancel_item(if (bi->bi_type ==XFS_BMAP_MAP ) bi->bi_owner->i_delayed_blks -= bi->bi_bmap.br_blockcount; -xfs_bmap_update_put_group (bi); +xfs_group_intent_put (bi->bi_group);kmem_cache_free (xfs_bmap_intent_cache, bi); }
PATCH 3/43 libxfs: implement some sanity checking for enormous rgcount
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Similar to what we do for suspiciously large sb_agcount values, if someone tries to get libxfs to load a filesystem with a very large realtime group count, let's do some basic checks of the rt device to see if it's really that large. If the read fails, only load the first rtgroup and warn the user.
--- libxfs/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
libxfs/init.c +46 -0
@@ -654,6 +654,49 @@ xfs_set_low_space_thresholds( mp->m_low_space[i] = dblocks * (i +1 ); } +/* +* libxfs_initialize_rtgroup will allocate a rtgroup structure for each +* rtgroup. If rgcount is corrupted and insanely high, this will OOM the box. +* Try to read what would be the last rtgroup superblock. If that fails, read +* the first one and let the user know to check the geometry. +*/ +static inline bool +check_many_rtgroups ( +struct xfs_mount *mp, +struct xfs_sb *sbp) +{ +struct xfs_buf *bp; +xfs_daddr_t d; +int error; + +if (!mp->m_rtdev->bt_bdev) { +fprintf (stderr,_ ("%s: no rt device, ignoring rgcount %u\n" ), + progname, sbp->sb_rgcount); +if (!xfs_is_debugger (mp)) +return false; + + sbp->sb_rgcount =0 ; +return true; + } + + d = (xfs_daddr_t )XFS_FSB_TO_BB (mp, mp->m_sb.sb_rblocks); + error =libxfs_buf_read (mp->m_rtdev, d -XFS_FSB_TO_BB (mp,1 ),1 ,0 , + &bp,NULL ); +if (!error) { +libxfs_buf_relse (bp); +return true; + } + +fprintf (stderr,_ ("%s: read of rtgroup %u failed\n" ), progname, + sbp->sb_rgcount -1 ); +if (!xfs_is_debugger (mp)) +return false; + +fprintf (stderr,_ ("%s: limiting reads to rtgroup 0\n" ), progname); + sbp->sb_rgcount =1 ; +return true; +} +/* * Mount structure initialization, provides a filled-in xfs_mount_t * such that the numerous XFS_* macros can be used. If dev is zero,
@@ -810,6 +853,9 @@ libxfs_mount(libxfs_buf_relse (bp); } +if (sbp->sb_rgcount >1000000 && !check_many_rtgroups (mp, sbp)) + goto out_da; + error =libxfs_initialize_perag (mp,0 , sbp->sb_agcount, sbp->sb_dblocks, &mp->m_maxagi);if (error) {
PATCH 4/43 libfrog: support scrubbing rtgroup metadata paths
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support scrubbing the metadata paths of rtgroup metadata inodes.
--- libfrog/scrub.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
libfrog/scrub.c +15 -0
@@ -172,6 +172,21 @@ const struct xfrog_scrub_descr xfrog_metapaths[XFS_SCRUB_METAPATH_NR] = { .descr = "metapath", .group = XFROG_SCRUB_GROUP_NONE, }, + [XFS_SCRUB_METAPATH_RTDIR] = { + .name = "rtdir", + .descr = "realtime group metadir", + .group = XFROG_SCRUB_GROUP_FS, + }, + [XFS_SCRUB_METAPATH_RTBITMAP] = { + .name = "rtbitmap", + .descr = "rtgroup bitmap", + .group = XFROG_SCRUB_GROUP_RTGROUP, + }, + [XFS_SCRUB_METAPATH_RTSUMMARY] = { + .name = "rtsummary", + .descr = "rtgroup summary", + .group = XFROG_SCRUB_GROUP_RTGROUP, + }, };/* Invoke the scrub ioctl. Returns zero or negative error code. */
PATCH 5/43 libfrog: report rt groups in output
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Report realtime group geometry.
--- libfrog/fsgeom.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
libfrog/fsgeom.c +4 -2
@@ -67,7 +67,8 @@ xfs_report_geom("naming =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d, parent=%d\n" "log =%-22s bsize=%-6d blocks=%u, version=%d\n" " =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n" -"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"), +"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n" +" =%-22s rgcount=%-4d rgsize=%u extents\n"), mntpoint, geo->inodesize, geo->agcount, geo->agblocks,"" , geo->sectsize, attrversion, projid32bit, "", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,
@@ -82,7 +83,8 @@ xfs_report_geom("" , geo->logsectsize, geo->logsunit / geo->blocksize, lazycount, !geo->rtblocks ?_ ("none" ) : rtname ? rtname :_ ("external" ), geo->rtextsize * geo->blocksize, (unsigned long long )geo->rtblocks, - (unsigned long long)geo->rtextents); + (unsigned long long )geo->rtextents, + "", geo->rgcount, geo->rgextents); }/* Try to obtain the xfs geometry. On error returns a negative error code. */
PATCH 6/43 libfrog: add bitmap_clear
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Uncomment and fix bitmap_clear so that xfs_repair can start using it.
--- libfrog/bitmap.c | 25 +++++++++++++++++++------ libfrog/bitmap.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-)
libfrog/bitmap.c +19 -6
@@ -233,10 +233,9 @@ bitmap_set(return res; } -#if 0 /* Unused, provided for completeness. */ /* Clear a region of bits. */ -int -bitmap_clear ( +static int +__bitmap_clear (struct bitmap *bmap,uint64_t start,uint64_t len)
@@ -251,8 +250,8 @@ bitmap_clear(uint64_t new_length;struct avl64node *node;int stat; +int ret =0 ; -pthread_mutex_lock (&bmap->bt_lock);/* Find any existing nodes over that range. */ avl64_findranges (bmap->bt_tree, start, start + len, &firstn, &lastn);
@@ -312,10 +311,24 @@ bitmap_clear( } out: -pthread_mutex_unlock (&bmap->bt_lock);return ret; } -#endif + +/* Clear a region of bits. */ +int +bitmap_clear ( +struct bitmap *bmap, +uint64_t start, +uint64_t length) +{ +int res; + +pthread_mutex_lock (&bmap->bt_lock); + res =__bitmap_clear (bmap, start, length); +pthread_mutex_unlock (&bmap->bt_lock); + +return res; +}/* Iterate the set regions of this bitmap. */ int
libfrog/bitmap.h +1 -0
@@ -14,6 +14,7 @@ struct bitmap {int bitmap_alloc (struct bitmap **bmap);void bitmap_free (struct bitmap **bmap);int bitmap_set (struct bitmap *bmap,uint64_t start,uint64_t length); +int bitmap_clear (struct bitmap *bmap,uint64_t start,uint64_t length);int bitmap_iterate (struct bitmap *bmap,int (*fn)(uint64_t ,uint64_t ,void *),void *arg); int bitmap_iterate_range(struct bitmap *bmap, uint64_t start, uint64_t length,
PATCH 7/43 xfs_logprint: report realtime EFIs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Decode the EFI format just enough to report if an EFI targets the realtime device or not.
--- logprint/log_misc.c | 2 ++ logprint/log_print_all.c | 8 ++++++ logprint/log_redo.c | 57 +++++++++++++++++++++++++++++++++++----------- 3 files changed, 53 insertions(+), 14 deletions(-)
logprint/log_misc.c +2 -0
@@ -997,12 +997,14 @@ xlog_print_record( &i, num_ops);break ; } +case XFS_LI_EFI_RT :case XFS_LI_EFI : { skip =xlog_print_trans_efi (&ptr,be32_to_cpu (op_head->oh_len), continued);break ; } +case XFS_LI_EFD_RT :case XFS_LI_EFD : { skip =xlog_print_trans_efd (&ptr,be32_to_cpu (op_head->oh_len));
logprint/log_print_all.c +8 -0
@@ -410,9 +410,11 @@ xlog_recover_print_logitem(case XFS_LI_INODE :xlog_recover_print_inode (item);break ; +case XFS_LI_EFD_RT :case XFS_LI_EFD :xlog_recover_print_efd (item);break ; +case XFS_LI_EFI_RT :case XFS_LI_EFI :xlog_recover_print_efi (item);break ;
@@ -474,6 +476,12 @@ xlog_recover_print_item(case XFS_LI_INODE :printf ("INO" );break ; +case XFS_LI_EFD_RT : +printf ("EFD_RT" ); +break ; +case XFS_LI_EFI_RT : +printf ("EFI_RT" ); +break ;case XFS_LI_EFD :printf ("EFD" );break ;
logprint/log_redo.c +43 -14
119 lines not on this page · raw message
PATCH 8/43 xfs_repair: adjust rtbitmap/rtsummary word updates to handle big endian values
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
With rtgroups, the rt bitmap and summary file words are defined to be be32 values. Adjust repair to handle the endianness correctly.
--- repair/rt.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
repair/rt.c +8 -2
@@ -24,7 +24,10 @@ set_rtword(union xfs_rtword_raw *word, xfs_rtword_t value) { - word->old = value; + if (xfs_has_rtgroups(mp)) + word->rtg = cpu_to_be32(value); + else + word->old = value; } static inline void
@@ -35,7 +38,10 @@ inc_sumcount( {union xfs_suminfo_raw *p = info + index; - p->old++; +if (xfs_has_rtgroups (mp)) +be32_add_cpu (&p->rtg,1 ); +else + p->old++; }/*
PATCH 9/43 xfs_repair: refactor phase4
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Split out helpers to process all duplicate extents in an AG and the RT duplicate extents.
--- repair/phase4.c | 210 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 96 deletions(-)
repair/phase4.c +114 -96
@@ -225,20 +225,122 @@ process_rmap_data(destroy_work_queue (&wq); } +static void +process_dup_rt_extents ( +struct xfs_mount *mp) +{ +xfs_rtxnum_t rt_start =0 ; +xfs_rtxlen_t rt_len =0 ; +xfs_rtxnum_t rtx; + +for (rtx =0 ; rtx < mp->m_sb.sb_rextents; rtx++) { +int state; + + state =get_rtbmap (rtx); +switch (state) { +case XR_E_BAD_STATE : +default : +do_warn ( +_ ("unknown rt extent state %d, extent %" PRIu64"\n" ), + state, rtx); + fallthrough; +case XR_E_METADATA : +case XR_E_UNKNOWN : +case XR_E_FREE1 : +case XR_E_FREE : +case XR_E_INUSE : +case XR_E_INUSE_FS : +case XR_E_INO : +case XR_E_FS_MAP : +if (rt_start ==0 ) +continue ; +/* +* Add extent and reset extent state. +*/ +add_rt_dup_extent (rt_start, rt_len); + rt_start =0 ; + rt_len =0 ; +break ; +case XR_E_MULT : +switch (rt_start) { +case 0 : + rt_start = rtx; + rt_len =1 ; +break ; +case XFS_MAX_BMBT_EXTLEN : +/* +* Large extent case. +*/ +add_rt_dup_extent (rt_start, rt_len); + rt_start = rtx; + rt_len =1 ; +break ; +default : + rt_len++; +break ; + } +break ; + } + } + +/* +* Catch the tail case, extent hitting the end of the RTG. +*/ +if (rt_start !=0 ) +add_rt_dup_extent (rt_start, rt_len); +} + +/* +* Set up duplicate extent list for an AG or RTG. +*/ +static void +process_dup_extents ( +xfs_agnumber_t agno, +xfs_agblock_t agbno, +xfs_agblock_t ag_end) +{ +do { +int bstate; +xfs_extlen_t blen; + + bstate =get_bmap_ext (agno, agbno, ag_end, &blen); +switch (bstate) { +case XR_E_FREE1 : +if (no_modify) +do_warn ( +_ ("free space (%u,%u-%u) only seen by one free space btree\n" ), + agno, agbno, agbno + blen -1 ); +break ; +case XR_E_METADATA : +case XR_E_UNKNOWN : +case XR_E_FREE : +case XR_E_INUSE : +case XR_E_INUSE_FS : +case XR_E_INO : +case XR_E_FS_MAP : +break ; +case XR_E_MULT : +add_dup_extent (agno, agbno, blen); +break ; +case XR_E_BAD_STATE : +default : +do_warn ( +_ ("unknown block state, ag %d, blocks %u-%u\n" ), + agno, agbno, agbno + blen -1 ); +break ; + } + + agbno += blen; + }while (agbno < ag_end); +} +void phase4 (xfs_mount_t *mp) {ino_tree_node_t *irec; -xfs_rtxnum_t rtx; -xfs_rtxnum_t rt_start; -xfs_rtxlen_t rt_len;xfs_agnumber_t i; -xfs_agblock_t j; -xfs_agblock_t ag_end; -xfs_extlen_t blen;int ag_hdr_len =4 * mp->m_sb.sb_sectsize;int ag_hdr_block; -int bstate;if (rmap_needs_work (mp)) collect_rmaps = true;
@@ -281,102 +383,19 @@ phase4(xfs_mount_t *mp) }for (i =0 ; i < mp->m_sb.sb_agcount; i++) { +xfs_agblock_t ag_end; + ag_end = (i < mp->m_sb.sb_agcount -1 ) ? mp->m_sb.sb_agblocks : mp->m_sb.sb_dblocks - (xfs_rfsblock_t ) mp->m_sb.sb_agblocks * i; -/* -* set up duplicate extent list for this ag -*/ -for (j = ag_hdr_block; j < ag_end; j += blen) { - bstate =get_bmap_ext (i, j, ag_end, &blen); -switch (bstate) { -case XR_E_FREE1 : -if (no_modify) -do_warn ( -_ ("free space (%u,%u-%u) only seen by one free space btree\n" ), - i, j, j + blen -1 ); -break ; -case XR_E_BAD_STATE : -default : -do_warn ( -_ ("unknown block state, ag %d, blocks %u-%u\n" ), - i, j, j + blen -1 ); - fallthrough; -case XR_E_METADATA : -case XR_E_UNKNOWN : -case XR_E_FREE : -case XR_E_INUSE : -case XR_E_INUSE_FS : -case XR_E_INO : -case XR_E_FS_MAP : -break ; -case XR_E_MULT : -add_dup_extent (i, j, blen); -break ; - } - } +process_dup_extents (i, ag_hdr_block, ag_end);PROG_RPT_INC (prog_rpt_done[i],1 ); }print_final_rpt (); -/* -* initialize realtime bitmap -*/ - rt_start =0 ; - rt_len =0 ; - -for (rtx =0 ; rtx < mp->m_sb.sb_rextents; rtx++) { - bstate =get_rtbmap (rtx); -switch (bstate) { -case XR_E_BAD_STATE : -default : -do_warn ( -_ ("unknown rt extent state, extent %" PRIu64"\n" ), - rtx); - fallthrough; -case XR_E_METADATA : -case XR_E_UNKNOWN : -case XR_E_FREE1 : -case XR_E_FREE : -case XR_E_INUSE : -case XR_E_INUSE_FS : -case XR_E_INO : -case XR_E_FS_MAP : -if (rt_start ==0 ) -continue ; -else { -/* -* add extent and reset extent state -*/ -add_rt_dup_extent (rt_start, rt_len); - rt_start =0 ; - rt_len =0 ; - } -break ; -case XR_E_MULT : -if (rt_start ==0 ) { - rt_start = rtx; - rt_len =1 ; - }else if (rt_len ==XFS_MAX_BMBT_EXTLEN ) { -/* -* large extent case -*/ -add_rt_dup_extent (rt_start, rt_len); - rt_start = rtx; - rt_len =1 ; - }else - rt_len++; -break ; - } - } - -/* -* catch tail-case, extent hitting the end of the ag -*/ -if (rt_start !=0 ) -add_rt_dup_extent (rt_start, rt_len); +process_dup_rt_extents (mp);/* * initialize bitmaps for all AGs
@@ -410,8 +429,7 @@ phase4(xfs_mount_t *mp)/* * free up memory used to track trealtime duplicate extents */ -if (rt_start !=0 ) -free_rt_dup_extent_tree (mp); +free_rt_dup_extent_tree (mp);/* * ensure consistency of quota inode pointers in superblock,
PATCH 10/43 xfs_repair: refactor offsetof+sizeof to offsetofend
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Replace this open-coded logic with the kernel's offsetofend macro before we start adding more in the next patch.
--- include/xfs.h | 15 +++++++++++++++ repair/agheader.c | 21 +++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-)
include/xfs.h +15 -0
@@ -38,8 +38,23 @@ extern int xfs_assert_largefile[sizeof(off_t)-8];#define BUILD_BUG_ON (condition) ((void)sizeof(char[1 - 2*!!(condition)]))#endif +/** +* sizeof_field() - Report the size of a struct field in bytes +* +* @TYPE: The structure containing the field of interest +* @MEMBER: The field to return the size of +*/ #define sizeof_field (TYPE ,MEMBER ) sizeof((((TYPE *)0)->MEMBER)) +/** +* offsetofend() - Report the offset of a struct field within the struct +* +* @TYPE: The type of the structure +* @MEMBER: The member within the structure to get the end offset of +*/ +#define offsetofend (TYPE ,MEMBER ) \ + (offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER)) +#include <xfs/xfs_types.h> /* Include deprecated/compat pre-vfs xfs-specific symbols */ #include <xfs/xfs_fs_compat.h>
repair/agheader.c +7 -14
@@ -358,26 +358,19 @@ secondary_sb_whack(* size is the size of data which is valid for this sb. */ if (xfs_sb_version_hasmetadir (sb)) - size = offsetof(struct xfs_dsb , sb_metadirino) - +sizeof (sb->sb_metadirino); + size = offsetofend(struct xfs_dsb, sb_metadirino);else if (xfs_sb_version_hasmetauuid (sb)) - size = offsetof(struct xfs_dsb , sb_meta_uuid) - +sizeof (sb->sb_meta_uuid); + size = offsetofend(struct xfs_dsb, sb_meta_uuid);else if (xfs_sb_version_hascrc (sb)) - size = offsetof(struct xfs_dsb , sb_lsn) - +sizeof (sb->sb_lsn); + size = offsetofend(struct xfs_dsb, sb_lsn);else if (xfs_sb_version_hasmorebits (sb)) - size = offsetof(struct xfs_dsb , sb_bad_features2) - +sizeof (sb->sb_bad_features2); + size = offsetofend(struct xfs_dsb, sb_bad_features2);else if (xfs_sb_version_haslogv2 (sb)) - size = offsetof(struct xfs_dsb , sb_logsunit) - +sizeof (sb->sb_logsunit); + size = offsetofend(struct xfs_dsb, sb_logsunit);else if (xfs_sb_version_hassector (sb)) - size = offsetof(struct xfs_dsb , sb_logsectsize) - +sizeof (sb->sb_logsectsize); + size = offsetofend(struct xfs_dsb, sb_logsectsize);else /* only support dirv2 or more recent */ - size = offsetof(struct xfs_dsb , sb_dirblklog) - +sizeof (sb->sb_dirblklog); + size = offsetofend(struct xfs_dsb, sb_dirblklog);/* Check the buffer we read from disk for garbage outside size */ for (ip = (char *)sbuf->b_addr + size;
PATCH 11/43 xfs_repair: improve rtbitmap discrepancy reporting
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Improve the reporting of discrepancies in the realtime bitmap and summary files by creating a separate helper function that will pinpoint the exact (word) locations of mismatches. This will help developers to diagnose problems with the rtgroups feature and users to figure out exactly what's bad in a filesystem.
--- repair/rt.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-)
repair/rt.c +39 -3
@@ -131,6 +131,44 @@ _("couldn't allocate memory for incore realtime summary info.\n")); } } +static void +check_rtwords ( +struct xfs_mount *mp, +const char *filename, +unsigned long long bno, +void *ondisk, +void *incore) +{ +unsigned int wordcnt = mp->m_blockwsize; +union xfs_rtword_raw *o = ondisk, *i = incore; +int badstart =-1 ; +unsigned int j; + +if (memcmp (ondisk, incore, wordcnt <<XFS_WORDLOG ) ==0 ) +return ; + +for (j =0 ; j < wordcnt; j++, o++, i++) { +if (o->old == i->old) { +/* Report a range of inconsistency that just ended. */ +if (badstart >=0 ) +do_warn ( +_ ("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n" ), + filename, bno, badstart, j -1 , wordcnt); + badstart =-1 ; +continue ; + } + +if (badstart ==-1 ) + badstart = j; + } + +if (badstart >=0 ) +do_warn ( +_ ("discrepancy in %s at dblock 0x%llx words 0x%x-0x%x/0x%x\n" ), + filename, bno, badstart, wordcnt, + wordcnt); +} + static void check_rtfile_contents( struct xfs_mount *mp,
@@ -203,9 +241,7 @@ check_rtfile_contents(break ; } -if (memcmp (bp->b_addr, buf, mp->m_blockwsize <<XFS_WORDLOG )) -do_warn (_ ("discrepancy in %s at dblock 0x%llx\n" ), - filename, (unsigned long long )bno); +check_rtwords (mp, filename, bno, bp->b_addr, buf); buf +=XFS_FSB_TO_B (mp, map.br_blockcount); bno += map.br_blockcount;
PATCH 12/43 xfs_repair: simplify rt_lock handling
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
No need to cacheline align rt_lock if we move it next to the data it protects. Also reduce the critical section to just where those data structures are accessed.
--- repair/dinode.c | 6 +++--- repair/globals.c | 1 - repair/globals.h | 2 +- repair/incore.c | 8 ++++---- 4 files changed, 8 insertions(+), 9 deletions(-)
repair/dinode.c +3 -3
@@ -304,7 +304,7 @@ process_rt_rec( bool zap_metadata) {xfs_fsblock_t lastb; -int bad; +int bad =0 ;/* * check numeric validity of the extent
@@ -338,10 +338,12 @@ _("inode %" PRIu64 " - bad rt extent overflows - start %" PRIu64 ", "return 1 ; } +pthread_mutex_lock (&rt_lock);if (check_dups) bad =process_rt_rec_dups (mp, ino, irec);else bad =process_rt_rec_state (mp, ino, zap_metadata, irec); +pthread_mutex_unlock (&rt_lock);if (bad)return bad;
@@ -451,10 +453,8 @@ _("zero length extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64 }if (type ==XR_INO_RTDATA && whichfork ==XFS_DATA_FORK ) { -pthread_mutex_lock (&rt_lock.lock); error2 =process_rt_rec (mp, &irec, ino, tot, check_dups, zap_metadata); -pthread_mutex_unlock (&rt_lock.lock);if (error2)return error2;
repair/globals.c +0 -1
@@ -112,7 +112,6 @@ uint32_t sb_unit;uint32_t sb_width;struct aglock *ag_locks; -struct aglock rt_lock;time_t report_interval;uint64_t *prog_rpt_done;
repair/globals.h +1 -1
@@ -156,7 +156,7 @@ struct aglock { pthread_mutex_t lock __attribute__((__aligned__(64))); };extern struct aglock *ag_locks; -extern struct aglock rt_lock; +extern pthread_mutex_t rt_lock;extern time_t report_interval;extern uint64_t *prog_rpt_done;
repair/incore.c +4 -4
@@ -166,6 +166,7 @@ get_bmap_ext(static uint64_t *rt_bmap;static size_t rt_bmap_size; +pthread_mutex_t rt_lock;/* block records fit into uint64_t's units */ #define XR_BB_UNIT 64/* number of bits/unit */
@@ -209,6 +210,7 @@ init_rt_bmap(if (mp->m_sb.sb_rextents ==0 )return ; +pthread_mutex_init (&rt_lock,NULL ); rt_bmap_size =roundup (howmany (mp->m_sb.sb_rextents, (NBBY /XR_BB )),sizeof (uint64_t ));
@@ -226,8 +228,9 @@ free_rt_bmap(xfs_mount_t *mp) {free (rt_bmap); rt_bmap =NULL ; -} +pthread_mutex_destroy (&rt_lock); +}void reset_bmaps (xfs_mount_t *mp)
@@ -290,7 +293,6 @@ init_bmaps(xfs_mount_t *mp)btree_init (&ag_bmap[i]);pthread_mutex_init (&ag_locks[i].lock,NULL ); } -pthread_mutex_init (&rt_lock.lock,NULL );init_rt_bmap (mp);reset_bmaps (mp);
@@ -301,8 +303,6 @@ free_bmaps(xfs_mount_t *mp) {xfs_agnumber_t i; -pthread_mutex_destroy (&rt_lock.lock); -for (i =0 ; i < mp->m_sb.sb_agcount; i++)pthread_mutex_destroy (&ag_locks[i].lock);
PATCH 13/43 xfs_repair: add a real per-AG bitmap abstraction
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Add a struct bmap that contains the btree root and the lock, and provide helpers for loking instead of directly poking into the data structure.
--- repair/dino_chunks.c | 23 +++++----- repair/dinode.c | 6 +-- repair/globals.c | 2 - repair/globals.h | 4 -- repair/incore.c | 114 ++++++++++++++++++++++++++++++++------------------ repair/incore.h | 3 + repair/rmap.c | 4 +- repair/scan.c | 8 ++-- 8 files changed, 97 insertions(+), 67 deletions(-)
repair/dino_chunks.c +11 -12
@@ -132,7 +132,7 @@ verify_inode_chunk(xfs_mount_t *mp,if (check_aginode_block (mp, agno, agino) ==0 )return 0 ; -pthread_mutex_lock (&ag_locks[agno].lock); +lock_ag (agno); state =get_bmap (agno, agbno);switch (state) {
@@ -167,8 +167,8 @@ verify_inode_chunk(xfs_mount_t *mp,_ ("inode block %d/%d multiply claimed, (state %d)\n" ), agno, agbno, state);set_bmap (agno, agbno,XR_E_MULT ); -pthread_mutex_unlock (&ag_locks[agno].lock); -return (0 ); +unlock_ag (agno); +return 0 ;default : do_warn( _("inode block %d/%d bad state, (state %d)\n"),
@@ -177,7 +177,7 @@ verify_inode_chunk(xfs_mount_t *mp,break ; } -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno); start_agino =XFS_AGB_TO_AGINO (mp, agbno); *start_ino =XFS_AGINO_TO_INO (mp, agno, start_agino);
@@ -424,7 +424,7 @@ verify_inode_chunk(xfs_mount_t *mp,* user data -- we're probably here as a result of a directory * entry or an iunlinked pointer */ -pthread_mutex_lock (&ag_locks[agno].lock); +lock_ag (agno);for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) {
@@ -438,7 +438,7 @@ verify_inode_chunk(xfs_mount_t *mp,_ ("inode block %d/%d multiply claimed, (state %d)\n" ), agno, cur_agbno, state);set_bmap_ext (agno, cur_agbno, blen,XR_E_MULT ); -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno);return 0 ;case XR_E_METADATA :case XR_E_INO :
@@ -450,7 +450,7 @@ verify_inode_chunk(xfs_mount_t *mp,break ; } } -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno);/* * ok, chunk is good. put the record into the tree if required,
@@ -473,8 +473,7 @@ verify_inode_chunk(xfs_mount_t *mp,set_inode_used (irec_p, agino - start_agino); -pthread_mutex_lock (&ag_locks[agno].lock); - +lock_ag (agno);for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) {
@@ -516,7 +515,7 @@ verify_inode_chunk(xfs_mount_t *mp,break ; } } -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno);return (ino_cnt); }
@@ -575,7 +574,7 @@ process_inode_agbno_state( {int state; -pthread_mutex_lock (&ag_locks[agno].lock); +lock_ag (agno); state =get_bmap (agno, agbno);switch (state) {case XR_E_INO :/* already marked */
@@ -605,7 +604,7 @@ process_inode_agbno_state( XFS_AGB_TO_FSB(mp, agno, agbno), state);break ; } -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno); }/*
repair/dinode.c +3 -3
@@ -540,9 +540,9 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" ebno = agbno + irec.br_blockcount;if (agno != locked_agno) {if (locked_agno !=-1 ) -pthread_mutex_unlock (&ag_locks[locked_agno].lock); -pthread_mutex_lock (&ag_locks[agno].lock); +unlock_ag (locked_agno); locked_agno = agno; +lock_ag (locked_agno); } for (b = irec.br_startblock;
@@ -663,7 +663,7 @@ _("illegal state %d in block map %" PRIu64 "\n"), error =0 ; done:if (locked_agno !=-1 ) -pthread_mutex_unlock (&ag_locks[locked_agno].lock); +unlock_ag (locked_agno);if (i != *numrecs) {ASSERT (i < *numrecs);
repair/globals.c +0 -2
@@ -111,8 +111,6 @@ xfs_extlen_t sb_inoalignmt;uint32_t sb_unit;uint32_t sb_width; -struct aglock *ag_locks; -time_t report_interval;uint64_t *prog_rpt_done;
repair/globals.h +0 -4
@@ -152,10 +152,6 @@ extern xfs_extlen_t sb_inoalignmt;extern uint32_t sb_unit;extern uint32_t sb_width; -struct aglock { -pthread_mutex_t lock __attribute__((__aligned__ (64 ))); -}; -extern struct aglock *ag_locks;extern pthread_mutex_t rt_lock;extern time_t report_interval;
repair/incore.c +74 -40
179 lines not on this page · raw message
repair/incore.h +3 -0
@@ -23,6 +23,9 @@ void init_bmaps(xfs_mount_t *mp);void reset_bmaps (xfs_mount_t *mp);void free_bmaps (xfs_mount_t *mp); +void lock_ag (xfs_agnumber_t agno); +void unlock_ag (xfs_agnumber_t agno); +void set_bmap_ext (xfs_agnumber_t agno,xfs_agblock_t agbno,xfs_extlen_t blen,int state); int get_bmap_ext(xfs_agnumber_t agno, xfs_agblock_t agbno,
repair/rmap.c +2 -2
@@ -761,12 +761,12 @@ mark_reflink_inodes( agno =XFS_INO_TO_AGNO (mp, rciter.ino); agino =XFS_INO_TO_AGINO (mp, rciter.ino); -pthread_mutex_lock (&ag_locks[agno].lock); +lock_ag (agno); irec =find_inode_rec (mp, agno, agino); off =get_inode_offset (mp, rciter.ino, irec);/* lock here because we might go outside this ag */ set_inode_is_rl (irec, off); -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno); }rcbag_ino_iter_stop (rcstack, &rciter); }
repair/scan.c +4 -4
@@ -340,7 +340,7 @@ _("bad back (left) sibling pointer (saw %llu should be NULL (0))\n" agno =XFS_FSB_TO_AGNO (mp, bno); agbno =XFS_FSB_TO_AGBNO (mp, bno); -pthread_mutex_lock (&ag_locks[agno].lock); +lock_ag (agno); state =get_bmap (agno, agbno);switch (state) {case XR_E_INUSE1 :
@@ -407,7 +407,7 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"), state, ino, bno);break ; } -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno); }else { if (search_dup_extent(XFS_FSB_TO_AGNO(mp, bno), XFS_FSB_TO_AGBNO(mp, bno),
@@ -420,9 +420,9 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"),/* Record BMBT blocks in the reverse-mapping data. */ if (check_dups && collect_rmaps && !zap_metadata) { agno =XFS_FSB_TO_AGNO (mp, bno); -pthread_mutex_lock (&ag_locks[agno].lock); +lock_ag (agno);rmap_add_bmbt_rec (mp, ino, whichfork, bno); -pthread_mutex_unlock (&ag_locks[agno].lock); +unlock_ag (agno); }if (level ==0 ) {
PATCH 14/43 xfs_repair: support realtime groups
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Make repair aware of multiple rtgroups. This now uses the same code as the AG-based data device for block usage tracking instead of the less optimal AVL trees and bitmaps used for the traditonal RT device.
Note this is still a bit hacky at the moment by just going beyond the AG arrays and not fully supporting the unknown state for RT allocation yet. The next patch will clean this up.
All this should be fixable.
Large parts of the code are based on patches from Darrick J. Wong.
--- libxfs/libxfs_api_defs.h | 1 repair/agheader.c | 2 repair/dinode.c | 102 ++++++++---- repair/dir2.c | 13 + repair/incore.c | 22 ++- repair/incore.h | 2 repair/incore_ext.c | 6 - repair/phase2.c | 49 +++--- repair/phase4.c | 13 + repair/phase6.c | 175 ++++++++++++++++++++ repair/rt.c | 404 ++++++++++++++++++++++++++++++++++++++-------- repair/rt.h | 20 ++ repair/sb.c | 36 ++++ repair/xfs_repair.c | 15 +- 14 files changed, 721 insertions(+), 139 deletions(-)
libxfs/libxfs_api_defs.h +1 -0
@@ -108,6 +108,7 @@#define xfs_calc_dquots_per_chunk libxfs_calc_dquots_per_chunk#define xfs_cntbt_init_cursor libxfs_cntbt_init_cursor#define xfs_compute_rextslog libxfs_compute_rextslog +#define xfs_compute_rgblklog libxfs_compute_rgblklog#define xfs_create_space_res libxfs_create_space_res#define xfs_da3_node_hdr_from_disk libxfs_da3_node_hdr_from_disk#define xfs_da3_node_read libxfs_da3_node_read
repair/agheader.c +1 -1
@@ -358,7 +358,7 @@ secondary_sb_whack(* size is the size of data which is valid for this sb. */ if (xfs_sb_version_hasmetadir (sb)) - size = offsetofend(struct xfs_dsb, sb_metadirino); + size = offsetofend(struct xfs_dsb, sb_rgextents);else if (xfs_sb_version_hasmetauuid (sb)) size = offsetofend(struct xfs_dsb, sb_meta_uuid);else if (xfs_sb_version_hascrc (sb))
repair/dinode.c +72 -30
202 lines not on this page · raw message
repair/dir2.c +9 -4
@@ -15,6 +15,7 @@#include "da_util.h" #include "prefetch.h" #include "progress.h" +#include "rt.h" /* * Known bad inode list. These are seen when the leaf and node
@@ -256,10 +257,12 @@ process_sf_dir2(* bother checking if the child inode is free or not. */ junkit =0 ; - }else if (lino == mp->m_sb.sb_rbmino) { + }else if (lino == mp->m_sb.sb_rbmino || +is_rtbitmap_inode (lino)) { junkit =1 ; junkreason =_ ("realtime bitmap" ); - }else if (lino == mp->m_sb.sb_rsumino) { + }else if (lino == mp->m_sb.sb_rsumino || +is_rtsummary_inode (lino)) { junkit =1 ; junkreason =_ ("realtime summary" ); }else if (lino == mp->m_sb.sb_uquotino) {
@@ -737,9 +740,11 @@ process_dir2_data(* bother checking if the child inode is free or not. */ clearino =0 ; - }else if (ent_ino == mp->m_sb.sb_rbmino) { + }else if (ent_ino == mp->m_sb.sb_rbmino || +is_rtbitmap_inode (ent_ino)) { clearreason =_ ("realtime bitmap" ); - }else if (ent_ino == mp->m_sb.sb_rsumino) { + }else if (ent_ino == mp->m_sb.sb_rsumino || +is_rtsummary_inode (ent_ino)) { clearreason =_ ("realtime summary" ); }else if (ent_ino == mp->m_sb.sb_uquotino) { clearreason =_ ("user quota" );
repair/incore.c +21 -1
@@ -254,7 +254,8 @@ free_rt_bmap(xfs_mount_t *mp)void reset_bmaps (xfs_mount_t *mp) { -xfs_agnumber_t agno; +unsigned int nr_groups = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; +unsigned int agno;xfs_agblock_t ag_size;int ag_hdr_block;
@@ -287,6 +288,25 @@ reset_bmaps(xfs_mount_t *mp)btree_insert (bmap, ag_size, &states[XR_E_BAD_STATE ]); } +for ( ; agno < nr_groups; agno++) { +struct btree_root *bmap = ag_bmaps[agno].root; +uint64_t rblocks; + +btree_clear (bmap); +if (agno == mp->m_sb.sb_agcount &&xfs_has_rtsb (mp)) { +btree_insert (bmap,0 , &states[XR_E_INUSE_FS ]); +btree_insert (bmap, mp->m_sb.sb_rextsize, + &states[XR_E_FREE ]); + }else { +btree_insert (bmap,0 , &states[XR_E_FREE ]); + } + + rblocks =xfs_rtbxlen_to_blen (mp, +xfs_rtgroup_extents (mp, + (agno - mp->m_sb.sb_agcount))); +btree_insert (bmap, rblocks, &states[XR_E_BAD_STATE ]); + } +if (mp->m_sb.sb_logstart !=0 ) { set_bmap_ext(XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart), XFS_FSB_TO_AGBNO(mp, mp->m_sb.sb_logstart),
repair/incore.h +2 -0
@@ -698,6 +698,8 @@ static inline unsigned intxfs_rootrec_inodes_inuse ( struct xfs_mount *mp) { +if (xfs_has_rtgroups (mp)) +return 2 ;/* sb_rootino, sb_metadirino */ if (xfs_has_metadir (mp))return 4 ;/* sb_rootino, sb_rbmino, sb_rsumino, sb_metadirino */ return 3 ;/* sb_rootino, sb_rbmino, sb_rsumino */
repair/incore_ext.c +3 -3
@@ -593,7 +593,6 @@ release_rt_extent_tree()void free_rt_dup_extent_tree (xfs_mount_t *mp) { -ASSERT (mp->m_sb.sb_rblocks !=0 );free (rt_ext_tree_ptr); rt_ext_tree_ptr =NULL ; }
@@ -726,8 +725,8 @@ static avl64ops_t avl64_extent_tree_ops = {void incore_ext_init (xfs_mount_t *mp) { +xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount;int i; -xfs_agnumber_t agcount = mp->m_sb.sb_agcount;pthread_mutex_init (&rt_ext_tree_lock,NULL );
@@ -779,9 +778,10 @@ incore_ext_init(xfs_mount_t *mp)void incore_ext_teardown (xfs_mount_t *mp) { +xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount;xfs_agnumber_t i; -for (i =0 ; i < mp->m_sb.sb_agcount; i++) { +for (i =0 ; i < agcount; i++) {btree_destroy (dup_extent_trees[i]);free (extent_bno_ptrs[i]);free (extent_bcnt_ptrs[i]);
repair/phase2.c +26 -23
77 lines not on this page · raw message
repair/phase4.c +12 -1
@@ -395,7 +395,18 @@ phase4(xfs_mount_t *mp) }print_final_rpt (); -process_dup_rt_extents (mp); +if (xfs_has_rtgroups (mp)) { +for (i =0 ; i < mp->m_sb.sb_rgcount; i++) { +uint64_t rblocks; + + rblocks =xfs_rtbxlen_to_blen (mp, +xfs_rtgroup_extents (mp, i)); +process_dup_extents (mp->m_sb.sb_agcount + i,0 , + rblocks); + } + }else { +process_dup_rt_extents (mp); + }/* * initialize bitmaps for all AGs
repair/phase6.c +172 -3
205 lines not on this page · raw message
repair/rt.c +335 -69
545 lines not on this page · raw message
repair/rt.h +20 -0
@@ -13,4 +13,24 @@ void check_rtsummary(struct xfs_mount *mp);void fill_rtbitmap (struct xfs_rtgroup *rtg);void fill_rtsummary (struct xfs_rtgroup *rtg); +void discover_rtgroup_inodes (struct xfs_mount *mp); +void unload_rtgroup_inodes (struct xfs_mount *mp); + +void init_rtgroup_inodes (void ); +void free_rtgroup_inodes (void ); + +bool is_rtgroup_inode (xfs_ino_t ino,enum xfs_rtg_inodes type); + +static inline bool is_rtbitmap_inode (xfs_ino_t ino) +{ +return is_rtgroup_inode (ino,XFS_RTGI_BITMAP ); +} +static inline bool is_rtsummary_inode (xfs_ino_t ino) +{ +return is_rtgroup_inode (ino,XFS_RTGI_SUMMARY ); +} + +void mark_rtgroup_inodes_bad (struct xfs_mount *mp,enum xfs_rtg_inodes type); +bool rtgroup_inodes_were_bad (enum xfs_rtg_inodes type); +#endif /* _XFS_REPAIR_RT_H_ */
repair/sb.c +36 -0
@@ -311,6 +311,38 @@ verify_sb_loginfo(return true; } +static int +verify_sb_rtgroups ( +struct xfs_sb *sbp) +{ +uint64_t groups; + +if (sbp->sb_rextsize ==0 ) +return XR_BAD_RT_GEO_DATA ; + +if (sbp->sb_rgextents >XFS_MAX_RGBLOCKS / sbp->sb_rextsize) +return XR_BAD_RT_GEO_DATA ; + +if (sbp->sb_rgextents <XFS_MIN_RGEXTENTS ) +return XR_BAD_RT_GEO_DATA ; + +if (sbp->sb_rgcount >XFS_MAX_RGNUMBER ) +return XR_BAD_RT_GEO_DATA ; + + groups =howmany_64 (sbp->sb_rextents, sbp->sb_rgextents); +if (groups != sbp->sb_rgcount) +return XR_BAD_RT_GEO_DATA ; + +if (!(sbp->sb_features_incompat &XFS_SB_FEAT_INCOMPAT_EXCHRANGE )) +return XR_BAD_RT_GEO_DATA ; + +if (sbp->sb_rgblklog !=libxfs_compute_rgblklog (sbp->sb_rgextents, + sbp->sb_rextsize)) +return XR_BAD_RT_GEO_DATA ; + +return 0 ; +} +/* * verify a superblock -- does not verify root inode # * can only check that geometry info is internally
@@ -485,6 +517,10 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb)if (xfs_sb_version_hasmetadir (sb)) {if (sb->sb_metadirpad0 || sb->sb_metadirpad1)return XR_SB_GEO_MISMATCH ; + + ret =verify_sb_rtgroups (sb); +if (ret) +return ret; }return (XR_OK );
repair/xfs_repair.c +11 -4
@@ -27,6 +27,7 @@#include "bulkload.h" #include "quotacheck.h" #include "rcbag_btree.h" +#include "rt.h" /* * option tables for getsubopt calls
@@ -729,10 +730,12 @@ _("sb root inode value %" PRIu64 " valid but in unaligned location (expected %"P rootino++; } -validate_sb_ino (&mp->m_sb.sb_rbmino, rootino +1 , -_ ("realtime bitmap" )); -validate_sb_ino (&mp->m_sb.sb_rsumino, rootino +2 , -_ ("realtime summary" )); +if (!xfs_has_rtgroups (mp)) { +validate_sb_ino (&mp->m_sb.sb_rbmino, rootino +1 , +_ ("realtime bitmap" )); +validate_sb_ino (&mp->m_sb.sb_rsumino, rootino +2 , +_ ("realtime summary" )); + } }/*
@@ -1345,6 +1348,7 @@ main(int argc, char **argv)incore_ino_init (mp);incore_ext_init (mp);rmaps_init (mp); +init_rtgroup_inodes ();/* initialize random globals now that we know the fs geometry */ inodes_per_block = mp->m_sb.sb_inopblock;
@@ -1390,11 +1394,14 @@ main(int argc, char **argv)phase6 (mp);phase_end (mp,6 ); +free_rtgroup_inodes (); +phase7 (mp, phase2_threads);phase_end (mp,7 ); }else {do_warn (_ ("Inode allocation btrees are too corrupted, skipping phases 6 and 7\n" )); +free_rtgroup_inodes (); }if (lost_quotas && !have_uquotino && !have_gquotino && !have_pquotino) {
PATCH 15/43 repair: use a separate bmaps array for real time groups
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Stop pretending RTGs are high numbered AGs and just use separate structures instead.
--- libxfs/libxfs_api_defs.h | 1 repair/dino_chunks.c | 12 +++-- repair/dinode.c | 26 ++++------ repair/incore.c | 117 +++++++++++++++++++++++++++++----------------- repair/incore.h | 35 ++++++++++---- repair/phase2.c | 2 - repair/phase4.c | 16 ++++-- repair/phase5.c | 2 - repair/rt.c | 5 +- repair/scan.c | 28 ++++++----- 10 files changed, 148 insertions(+), 96 deletions(-)
libxfs/libxfs_api_defs.h +1 -0
@@ -290,6 +290,7 @@#define xfs_rtsummary_create libxfs_rtsummary_create#define xfs_rtgroup_alloc libxfs_rtgroup_alloc +#define xfs_rtgroup_extents libxfs_rtgroup_extents#define xfs_rtgroup_grab libxfs_rtgroup_grab#define xfs_rtgroup_rele libxfs_rtgroup_rele
repair/dino_chunks.c +7 -5
@@ -428,7 +428,8 @@ verify_inode_chunk(xfs_mount_t *mp,for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) { - state =get_bmap_ext (agno, cur_agbno, chunk_stop_agbno, &blen); + state =get_bmap_ext (agno, cur_agbno, chunk_stop_agbno, &blen, + false);switch (state) {case XR_E_MULT :case XR_E_INUSE :
@@ -437,7 +438,7 @@ verify_inode_chunk(xfs_mount_t *mp,do_warn (_ ("inode block %d/%d multiply claimed, (state %d)\n" ), agno, cur_agbno, state); -set_bmap_ext (agno, cur_agbno, blen,XR_E_MULT ); +set_bmap_ext (agno, cur_agbno, blen,XR_E_MULT , false);unlock_ag (agno);return 0 ;case XR_E_METADATA :
@@ -477,7 +478,8 @@ verify_inode_chunk(xfs_mount_t *mp,for (cur_agbno = chunk_start_agbno; cur_agbno < chunk_stop_agbno; cur_agbno += blen) { - state =get_bmap_ext (agno, cur_agbno, chunk_stop_agbno, &blen); + state =get_bmap_ext (agno, cur_agbno, chunk_stop_agbno, &blen, + false);switch (state) {case XR_E_INO : do_error(
@@ -497,7 +499,7 @@ verify_inode_chunk(xfs_mount_t *mp,case XR_E_UNKNOWN :case XR_E_FREE1 :case XR_E_FREE : -set_bmap_ext (agno, cur_agbno, blen,XR_E_INO ); +set_bmap_ext (agno, cur_agbno, blen,XR_E_INO , false);break ;case XR_E_MULT :case XR_E_INUSE :
@@ -511,7 +513,7 @@ verify_inode_chunk(xfs_mount_t *mp,do_warn (_ ("inode block %d/%d bad state, (state %d)\n" ), agno, cur_agbno, state); -set_bmap_ext (agno, cur_agbno, blen,XR_E_INO ); +set_bmap_ext (agno, cur_agbno, blen,XR_E_INO , false);break ; } }
repair/dinode.c +10 -16
@@ -548,15 +548,8 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" } } -/* -* XXX: For rtgroup enabled file systems we treat the RTGs as -* basically another set of AGs tacked on at the end, but -* otherwise reuse all the existing code. That's why we'll -* see odd "agno" value here. -*/ if (isrt) { - agno = mp->m_sb.sb_agcount + -xfs_rtb_to_rgno (mp, irec.br_startblock); + agno =xfs_rtb_to_rgno (mp, irec.br_startblock); first_agbno =xfs_rtb_to_rgbno (mp, irec.br_startblock); }else { agno =XFS_FSB_TO_AGNO (mp, irec.br_startblock);
@@ -566,9 +559,9 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n" ebno = first_agbno + irec.br_blockcount;if (agno != locked_agno) {if (locked_agno !=-1 ) -unlock_ag (locked_agno); +unlock_group (locked_agno, isrt); locked_agno = agno; -lock_ag (locked_agno); +lock_group (locked_agno, isrt); }/*
@@ -578,7 +571,7 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n"for (b = irec.br_startblock; agbno < ebno; b += blen, agbno += blen) { - state =get_bmap_ext (agno, agbno, ebno, &blen); + state =get_bmap_ext (agno, agbno, ebno, &blen, isrt);switch (state) {case XR_E_FREE :/*
@@ -664,7 +657,7 @@ _("illegal state %d in block map %" PRIu64 "\n"), agbno = first_agbno; ebno = first_agbno + irec.br_blockcount;for (; agbno < ebno; agbno += blen) { - state =get_bmap_ext (agno, agbno, ebno, &blen); + state =get_bmap_ext (agno, agbno, ebno, &blen, isrt);switch (state) {case XR_E_METADATA :/*
@@ -679,15 +672,16 @@ _("illegal state %d in block map %" PRIu64 "\n"),case XR_E_FREE1 :case XR_E_INUSE1 :case XR_E_UNKNOWN : -set_bmap_ext (agno, agbno, blen, zap_metadata ? -XR_E_METADATA :XR_E_INUSE ); +set_bmap_ext (agno, agbno, blen, + zap_metadata ? +XR_E_METADATA :XR_E_INUSE , isrt);break ;case XR_E_INUSE :case XR_E_MULT :if (!zap_metadata)set_bmap_ext (agno, agbno, blen, -XR_E_MULT ); +XR_E_MULT , isrt);break ;default :break ;
@@ -700,7 +694,7 @@ _("illegal state %d in block map %" PRIu64 "\n"), error =0 ; done:if (locked_agno !=-1 ) -unlock_ag (locked_agno); +unlock_group (locked_agno, isrt);if (i != *numrecs) {ASSERT (i < *numrecs);
repair/incore.c +75 -42
193 lines not on this page · raw message
repair/incore.h +26 -9
@@ -23,29 +23,46 @@ void init_bmaps(xfs_mount_t *mp);void reset_bmaps (xfs_mount_t *mp);void free_bmaps (xfs_mount_t *mp); -void lock_ag (xfs_agnumber_t agno); -void unlock_ag (xfs_agnumber_t agno); +void lock_group (xfs_agnumber_t agno,bool isrt); +void unlock_group (xfs_agnumber_t agno,bool isrt); + +static inline void lock_ag (xfs_agnumber_t agno) +{ +lock_group (agno, false); +} + +static inline void unlock_ag (xfs_agnumber_t agno) +{ +unlock_group (agno, false); +}void set_bmap_ext (xfs_agnumber_t agno,xfs_agblock_t agbno, -xfs_extlen_t blen,int state); +xfs_extlen_t blen,int state,bool isrt);int get_bmap_ext (xfs_agnumber_t agno,xfs_agblock_t agbno, -xfs_agblock_t maxbno,xfs_extlen_t *blen); - -void set_rtbmap (xfs_rtxnum_t rtx,int state); -int get_rtbmap (xfs_rtxnum_t rtx); +xfs_agblock_t maxbno,xfs_extlen_t *blen, +bool isrt);static inline void set_bmap (xfs_agnumber_t agno,xfs_agblock_t agbno,int state) { -set_bmap_ext (agno, agbno,1 , state); +set_bmap_ext (agno, agbno,1 , state, false); }static inline int get_bmap (xfs_agnumber_t agno,xfs_agblock_t agbno) { -return get_bmap_ext (agno, agbno, agbno +1 ,NULL ); +return get_bmap_ext (agno, agbno, agbno +1 ,NULL , false); } +static inline int +get_rgbmap (xfs_rgnumber_t rgno,xfs_rgblock_t rgbno) +{ +return get_bmap_ext (rgno, rgbno, rgbno +1 ,NULL , true); +} + +void set_rtbmap (xfs_rtxnum_t rtx,int state); +int get_rtbmap (xfs_rtxnum_t rtx); +/* * extent tree definitions * right now, there are 3 trees per AG, a bno tree, a bcnt tree
repair/phase2.c +1 -1
@@ -568,7 +568,7 @@ phase2(* also mark blocks */ set_bmap_ext (0 ,XFS_INO_TO_AGBNO (mp, sb->sb_rootino), -M_IGEO (mp)->ialloc_blks,XR_E_INO ); +M_IGEO (mp)->ialloc_blks,XR_E_INO , false); }else {do_log (_ (" - found root inode chunk\n" )); j =0 ;
repair/phase4.c +9 -7
@@ -295,15 +295,17 @@ process_dup_rt_extents(*/ static void process_dup_extents ( +struct xfs_mount *mp,xfs_agnumber_t agno,xfs_agblock_t agbno, -xfs_agblock_t ag_end) +xfs_agblock_t ag_end, +bool isrt) { do { int bstate; xfs_extlen_t blen; - bstate = get_bmap_ext(agno, agbno, ag_end, &blen); + bstate = get_bmap_ext(agno, agbno, ag_end, &blen, isrt); switch (bstate) { case XR_E_FREE1: if (no_modify)
@@ -320,7 +322,8 @@ _("free space (%u,%u-%u) only seen by one free space btree\n"),case XR_E_FS_MAP :break ;case XR_E_MULT : -add_dup_extent (agno, agbno, blen); +add_dup_extent (agno + isrt ? mp->m_sb.sb_agcount :0 , + agbno, blen);break ;case XR_E_BAD_STATE :default :
@@ -389,7 +392,7 @@ phase4(xfs_mount_t *mp) mp->m_sb.sb_dblocks - (xfs_rfsblock_t ) mp->m_sb.sb_agblocks * i; -process_dup_extents (i, ag_hdr_block, ag_end); +process_dup_extents (mp, i, ag_hdr_block, ag_end, false);PROG_RPT_INC (prog_rpt_done[i],1 ); }
@@ -400,9 +403,8 @@ phase4(xfs_mount_t *mp)uint64_t rblocks; rblocks =xfs_rtbxlen_to_blen (mp, -xfs_rtgroup_extents (mp, i)); -process_dup_extents (mp->m_sb.sb_agcount + i,0 , - rblocks); +libxfs_rtgroup_extents (mp, i)); +process_dup_extents (mp, i,0 , rblocks, true); } }else {process_dup_rt_extents (mp);
repair/phase5.c +1 -1
@@ -72,7 +72,7 @@ mk_incore_fstree(* largest extent. */ for (agbno =0 ; agbno < ag_end; agbno += blen) { - bstate =get_bmap_ext (agno, agbno, ag_end, &blen); + bstate =get_bmap_ext (agno, agbno, ag_end, &blen, false);if (bstate <XR_E_INUSE ) { free_blocks += blen;if (in_extent ==0 ) {
repair/rt.c +2 -3
@@ -58,7 +58,6 @@ generate_rtgroup_rtinfo( {struct rtg_computed *comp = &rt_computed[rtg_rgno (rtg)];struct xfs_mount *mp =rtg_mount (rtg); -unsigned int idx = mp->m_sb.sb_agcount +rtg_rgno (rtg);unsigned int bitsperblock = mp->m_blockwsize <<XFS_NBWORDLOG ;xfs_rtxnum_t extno =0 ;
@@ -100,11 +99,11 @@ _("couldn't allocate memory for incore realtime summary info.\n"));/* * Note: for the RTG case it might make sense to use -* get_bmap_ext here and generate multiple bitmap +* get_rgbmap_ext here and generate multiple bitmap * entries per lookup. */ if (xfs_has_rtgroups (mp)) - state =get_bmap (idx, + state =get_rgbmap (rtg_rgno (rtg), extno * mp->m_sb.sb_rextsize);else state =get_rtbmap (extno);
repair/scan.c +16 -12
@@ -724,10 +724,11 @@ _("%s freespace btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), }for ( ; b < end; b += blen) { - state =get_bmap_ext (agno, b, end, &blen); + state =get_bmap_ext (agno, b, end, &blen, false);switch (state) {case XR_E_UNKNOWN : -set_bmap_ext (agno, b, blen,XR_E_FREE1 ); +set_bmap_ext (agno, b, blen,XR_E_FREE1 , + false);break ;case XR_E_FREE1 :/*
@@ -737,7 +738,7 @@ _("%s freespace btree block claimed (state %d), agno %d, bno %d, suspect %d\n"),if (magic ==XFS_ABTC_MAGIC || magic ==XFS_ABTC_CRC_MAGIC ) {set_bmap_ext (agno, b, blen, -XR_E_FREE ); +XR_E_FREE , false);break ; } fallthrough;
@@ -841,27 +842,27 @@ process_rmap_rec(switch (owner) {case XFS_RMAP_OWN_FS :case XFS_RMAP_OWN_LOG : -set_bmap_ext (agno, b, blen,XR_E_INUSE_FS1 ); +set_bmap_ext (agno, b, blen,XR_E_INUSE_FS1 , false);break ;case XFS_RMAP_OWN_AG :case XFS_RMAP_OWN_INOBT : -set_bmap_ext (agno, b, blen,XR_E_FS_MAP1 ); +set_bmap_ext (agno, b, blen,XR_E_FS_MAP1 , false);break ;case XFS_RMAP_OWN_INODES : -set_bmap_ext (agno, b, blen,XR_E_INO1 ); +set_bmap_ext (agno, b, blen,XR_E_INO1 , false);break ;case XFS_RMAP_OWN_REFC : -set_bmap_ext (agno, b, blen,XR_E_REFC ); +set_bmap_ext (agno, b, blen,XR_E_REFC , false);break ;case XFS_RMAP_OWN_COW : -set_bmap_ext (agno, b, blen,XR_E_COW ); +set_bmap_ext (agno, b, blen,XR_E_COW , false);break ;case XFS_RMAP_OWN_NULL :/* still unknown */ break ;default :/* file data */ -set_bmap_ext (agno, b, blen,XR_E_INUSE1 ); +set_bmap_ext (agno, b, blen,XR_E_INUSE1 , false);break ; }break ;
@@ -1207,7 +1208,8 @@ _("%s rmap btree block claimed (state %d), agno %d, bno %d, suspect %d\n"),/* Check for block owner collisions. */ for ( ; b < end; b += blen) { - state =get_bmap_ext (agno, b, end, &blen); + state =get_bmap_ext (agno, b, end, &blen, + false);process_rmap_rec (mp, agno, b, end, blen, owner, state, name); }
@@ -1483,14 +1485,16 @@ _("leftover CoW extent has invalid startblock in record %u of %s btree block %u/xfs_extlen_t cnr;for (c = agb; c < end; c += cnr) { - state =get_bmap_ext (agno, c, end, &cnr); + state =get_bmap_ext (agno, c, end, &cnr, + false);switch (state) {case XR_E_UNKNOWN :case XR_E_COW :do_warn (_ ("leftover CoW extent (%u/%u) len %u\n" ), agno, c, cnr); -set_bmap_ext (agno, c, cnr,XR_E_FREE ); +set_bmap_ext (agno, c, cnr, +XR_E_FREE , false);break ;default : do_warn(
PATCH 16/43 xfs_repair: find and clobber rtgroup bitmap and summary files
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
On a rtgroups filesystem, if the rtgroups bitmap or summary files are garbage, we need to clear the dinode and update the incore bitmap so that we don't bother to check the old rt freespace metadata.
However, we regenerate the entire rt metadata directory tree during phase 6. If the bitmap and summary files are ok, we still want to clear the dinode, but we can still use the incore inode to check the old freespace contents. Split the clear_dinode function into two pieces, one that merely zeroes the inode, and the old clear_dinode now turns off checking.
--- repair/dino_chunks.c | 23 +++++++++++++++++++++++ repair/dinode.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 57 insertions(+), 6 deletions(-)
repair/dino_chunks.c +23 -0
@@ -15,6 +15,7 @@#include "versions.h" #include "prefetch.h" #include "progress.h" +#include "rt.h" /* * validates inode block or chunk, returns # of good inodes
@@ -1000,6 +1001,28 @@ process_inode_chunk(_ ("would clear realtime summary inode %" PRIu64"\n" ), ino); } + }else if (is_rtbitmap_inode (ino)) { +mark_rtgroup_inodes_bad (mp,XFS_RTGI_BITMAP ); +if (!no_modify) { +do_warn ( +_ ("cleared rtgroup bitmap inode %" PRIu64"\n" ), + ino); + }else { +do_warn ( +_ ("would clear rtgroup bitmap inode %" PRIu64"\n" ), + ino); + } + }else if (is_rtsummary_inode (ino)) { +mark_rtgroup_inodes_bad (mp,XFS_RTGI_SUMMARY ); +if (!no_modify) { +do_warn ( +_ ("cleared rtgroup summary inode %" PRIu64"\n" ), + ino); + }else { +do_warn ( +_ ("would clear rtgroup summary inode %" PRIu64"\n" ), + ino); + } }else if (!no_modify) {do_warn (_ ("cleared inode %" PRIu64"\n" ), ino);
repair/dinode.c +34 -6
@@ -149,16 +149,36 @@ clear_dinode_unlinked(xfs_mount_t *mp, struct xfs_dinode *dino)* until after the agi unlinked lists are walked in phase 3. */ static void -clear_dinode (xfs_mount_t *mp,struct xfs_dinode *dino,xfs_ino_t ino_num) +zero_dinode ( +struct xfs_mount *mp, +struct xfs_dinode *dino, +xfs_ino_t ino_num) {clear_dinode_core (mp, dino, ino_num);clear_dinode_unlinked (mp, dino);/* and clear the forks */ memset (XFS_DFORK_DPTR (dino),0 ,XFS_LITINO (mp)); -return ; } +/* +* clear the inode core and, if this is a metadata inode, prevent subsequent +* phases from checking the (obviously bad) data in the file. +*/ +static void +clear_dinode ( +struct xfs_mount *mp, +struct xfs_dinode *dino, +xfs_ino_t ino_num) +{ +zero_dinode (mp, dino, ino_num); + +if (is_rtbitmap_inode (ino_num)) +mark_rtgroup_inodes_bad (mp,XFS_RTGI_BITMAP ); + +if (is_rtsummary_inode (ino_num)) +mark_rtgroup_inodes_bad (mp,XFS_RTGI_SUMMARY ); +}/* * misc. inode-related utility routines
@@ -3069,13 +3089,21 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "),switch (type) {case XR_INO_RTBITMAP :case XR_INO_RTSUM : +/* +* rt bitmap and summary files are always recreated +* when rtgroups are enabled. For older filesystems, +* they exist at fixed locations and cannot be zapped. +*/ +if (xfs_has_rtgroups (mp)) + zap_metadata = true; +break ;case XR_INO_UQUOTA :case XR_INO_GQUOTA :case XR_INO_PQUOTA :/* -* This inode was recognized as being filesystem -* metadata, so preserve the inode and its contents for -* later checking and repair. +* Quota checking and repair doesn't happen until +* phase7, so preserve quota inodes and their contents +* for later. */ break ;default :
@@ -3165,7 +3193,7 @@ _("Bad CoW extent size %u on inode %" PRIu64 ", "),* file, zero the ondisk inode and the incore state. */ if (check_dups && zap_metadata && !no_modify) { -clear_dinode (mp, dino, lino); +zero_dinode (mp, dino, lino); *dirty +=1 ; *used = is_free; *isa_dir =0 ;
PATCH 17/43 xfs_repair: support realtime superblocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support the realtime superblock feature.
--- libxfs/libxfs_api_defs.h | 1 + repair/incore.c | 12 ++++++++++ repair/phase3.c | 4 +++ repair/rt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ repair/rt.h | 3 +++ repair/xfs_repair.c | 4 +++ 6 files changed, 78 insertions(+)
libxfs/libxfs_api_defs.h +1 -0
@@ -301,6 +301,7 @@#define xfs_rtfree_extent libxfs_rtfree_extent#define xfs_rtfree_blocks libxfs_rtfree_blocks +#define xfs_update_rtsb libxfs_update_rtsb#define xfs_sb_from_disk libxfs_sb_from_disk#define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk#define xfs_sb_read_secondary libxfs_sb_read_secondary
repair/incore.c +12 -0
@@ -220,6 +220,15 @@ set_rtbmap( (((uint64_t) state) << ((rtx % XR_BB_NUM) * XR_BB))); } +static void +rtsb_init ( +struct xfs_mount *mp) +{ +/* The first rtx of the realtime device contains the super */ +if (xfs_has_rtsb (mp) && rt_bmap) +set_rtbmap (0 ,XR_E_INUSE_FS ); +} +static void reset_rt_bmap (void ) {
@@ -245,6 +254,8 @@ init_rt_bmap( mp->m_sb.sb_rextents);return ; } + +rtsb_init (mp); } static void
@@ -332,6 +343,7 @@ reset_bmaps(if (xfs_has_rtgroups (mp)) {reset_rtg_bmaps (mp); +rtsb_init (mp); }else {reset_rt_bmap (); }
repair/phase3.c +4 -0
@@ -17,6 +17,7 @@#include "progress.h" #include "bmap.h" #include "threads.h" +#include "rt.h" static void process_agi_unlinked(
@@ -116,6 +117,9 @@ phase3(set_progress_msg (PROG_FMT_AGI_UNLINKED , (uint64_t ) glob_agcount); +if (xfs_has_rtsb (mp) &&xfs_has_realtime (mp)) +check_rtsb (mp); +/* first clear the agi unlinked AGI list */ if (!no_modify) {for (i =0 ; i < mp->m_sb.sb_agcount; i++)
repair/rt.c +54 -0
57 lines not on this page · raw message
repair/rt.h +3 -0
@@ -33,4 +33,7 @@ static inline bool is_rtsummary_inode(xfs_ino_t ino)void mark_rtgroup_inodes_bad (struct xfs_mount *mp,enum xfs_rtg_inodes type);bool rtgroup_inodes_were_bad (enum xfs_rtg_inodes type); +void check_rtsb (struct xfs_mount *mp); +void rewrite_rtsb (struct xfs_mount *mp); +#endif /* _XFS_REPAIR_RT_H_ */
repair/xfs_repair.c +4 -0
@@ -1518,6 +1518,10 @@ _("Note - stripe unit (%d) and width (%d) were copied from a backup superblock.\XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR ; } +/* Always rewrite the realtime superblock */ +if (xfs_has_rtsb (mp) &&xfs_has_realtime (mp)) +rewrite_rtsb (mp); +/* * Done. Flush all cached buffers and inodes first to ensure all * verifiers are run (where we discover the max metadata LSN), reformat
PATCH 18/43 xfs_repair: repair rtbitmap and rtsummary block headers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Check and repair the new block headers attached to rtbitmap and rtsummary blocks.
--- repair/rt.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
repair/rt.c +14 -1
@@ -237,6 +237,7 @@ check_rtfile_contents(while (bno < filelen) {struct xfs_bmbt_irec map;struct xfs_buf *bp; +unsigned int offset =0 ;int nmap =1 ; error = -libxfs_bmapi_read (ip, bno,1 , &map, &nmap,0 );
@@ -262,7 +263,19 @@ check_rtfile_contents(break ; } -check_rtwords (rtg, filename, bno, bp->b_addr, buf); +if (xfs_has_rtgroups (mp)) { +struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + +if (hdr->rt_owner !=cpu_to_be64 (ip->i_ino)) { +do_warn ( +_ ("corrupt owner in %s at dblock 0x%llx\n" ), + filename, (unsigned long long )bno); + } + + offset =sizeof (*hdr); + } + +check_rtwords (rtg, filename, bno, bp->b_addr + offset, buf); buf += mp->m_blockwsize <<XFS_WORDLOG ; bno++;
PATCH 19/43 xfs_repair: stop tracking duplicate RT extents with rtgroups
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Nothing ever looks them up, so don't bother with tracking them by overloading the AG numbers.
--- repair/incore_ext.c | 5 ++--- repair/phase4.c | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-)
repair/incore_ext.c +2 -3
@@ -725,7 +725,7 @@ static avl64ops_t avl64_extent_tree_ops = {void incore_ext_init (xfs_mount_t *mp) { -xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount; +xfs_agnumber_t agcount = mp->m_sb.sb_agcount;int i;pthread_mutex_init (&rt_ext_tree_lock,NULL );
@@ -778,10 +778,9 @@ incore_ext_init(xfs_mount_t *mp)void incore_ext_teardown (xfs_mount_t *mp) { -xfs_agnumber_t agcount = mp->m_sb.sb_agcount + mp->m_sb.sb_rgcount;xfs_agnumber_t i; -for (i =0 ; i < agcount; i++) { +for (i =0 ; i < mp->m_sb.sb_agcount; i++) {btree_destroy (dup_extent_trees[i]);free (extent_bno_ptrs[i]);free (extent_bcnt_ptrs[i]);
repair/phase4.c +6 -2
@@ -322,8 +322,12 @@ _("free space (%u,%u-%u) only seen by one free space btree\n"),case XR_E_FS_MAP :break ;case XR_E_MULT : -add_dup_extent (agno + isrt ? mp->m_sb.sb_agcount :0 , - agbno, blen); +/* +* Nothing is searching for duplicate RT extents, so +* don't bother tracking them. +*/ +if (!isrt) +add_dup_extent (agno, agbno, blen);break ;case XR_E_BAD_STATE :default :
PATCH 20/43 xfs_db: listify the definition of enum typnm
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convert the enum definition into a list so that future patches adding things to enum typnm don't have to reflow the entire thing.
--- db/type.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-)
db/type.h +24 -5
@@ -11,11 +11,30 @@ struct field;typedef enum typnm { -TYP_AGF ,TYP_AGFL ,TYP_AGI ,TYP_ATTR ,TYP_BMAPBTA , -TYP_BMAPBTD ,TYP_BNOBT ,TYP_CNTBT ,TYP_RMAPBT ,TYP_REFCBT ,TYP_DATA , -TYP_DIR2 ,TYP_DQBLK ,TYP_INOBT ,TYP_INODATA ,TYP_INODE , -TYP_LOG ,TYP_RTBITMAP ,TYP_RTSUMMARY ,TYP_SB ,TYP_SYMLINK , -TYP_TEXT ,TYP_FINOBT ,TYP_NONE +TYP_AGF , +TYP_AGFL , +TYP_AGI , +TYP_ATTR , +TYP_BMAPBTA , +TYP_BMAPBTD , +TYP_BNOBT , +TYP_CNTBT , +TYP_RMAPBT , +TYP_REFCBT , +TYP_DATA , +TYP_DIR2 , +TYP_DQBLK , +TYP_INOBT , +TYP_INODATA , +TYP_INODE , +TYP_LOG , +TYP_RTBITMAP , +TYP_RTSUMMARY , +TYP_SB , +TYP_SYMLINK , +TYP_TEXT , +TYP_FINOBT , +TYP_NONE }typnm_t ;#define DB_FUZZ 2
PATCH 21/43 xfs_db: support dumping realtime group data and superblocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Allow dumping of realtime device superblocks and the new fields in the primary superblock that were added for rtgroups support.
--- db/Makefile | 1 + db/command.c | 2 + db/field.c | 10 ++++++ db/field.h | 5 +++ db/rtgroup.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ db/rtgroup.h | 15 +++++++++ db/sb.c | 8 +++++ db/type.c | 6 +++ db/type.h | 1 + 9 files changed, 148 insertions(+) create mode 100644 db/rtgroup.c create mode 100644 db/rtgroup.h
db/Makefile +1 -0
@@ -49,6 +49,7 @@ HFILES = \ output.h \ print.h \ quit.h \ + rtgroup.h \ sb.h \ sig.h \ strvec.h \
db/command.c +2 -0
@@ -39,6 +39,7 @@#include "fsmap.h" #include "crc.h" #include "fuzz.h" +#include "rtgroup.h" cmdinfo_t *cmdtab;int ncmds;
@@ -135,6 +136,7 @@ init_commands(void)output_init ();print_init ();quit_init (); +rtsb_init ();sb_init ();type_init ();write_init ();
db/field.c +10 -0
@@ -23,6 +23,7 @@#include "dir2.h" #include "dir2sf.h" #include "symlink.h" +#include "rtgroup.h" #define PPOFF (f) bitize(offsetof(struct xfs_parent_rec, f))const field_t parent_flds[] = {
@@ -52,6 +53,13 @@ const ftattr_t ftattrtab[] = { {FLDT_AGNUMBER ,"agnumber" , fp_num,"%u" ,SI (bitsz (xfs_agnumber_t)), FTARG_DONULL, NULL, NULL }, + { FLDT_RGBLOCK, "rgblock", fp_num, "%u", SI(bitsz(xfs_rgblock_t)), + FTARG_DONULL, NULL, NULL }, + { FLDT_RTXLEN, "rtxlen", fp_num, "%u", SI(bitsz(xfs_rtxlen_t)), + FTARG_DONULL, NULL, NULL }, + { FLDT_RGNUMBER, "rgnumber", fp_num, "%u", SI(bitsz(xfs_rgnumber_t)), + FTARG_DONULL, NULL, NULL }, +/* attr fields */ { FLDT_ATTR, "attr", NULL, (char *)attr_flds, attr_size, FTARG_SIZE, NULL, attr_flds },
@@ -357,6 +365,8 @@ const ftattr_t ftattrtab[] = { NULL, NULL }, {FLDT_SB ,"sb" ,NULL , (char *)sb_flds, sb_size,FTARG_SIZE ,NULL , sb_flds }, + { FLDT_RTSB, "rtsb", NULL, (char *)rtsb_flds, rtsb_size, FTARG_SIZE, + NULL, rtsb_flds },/* CRC enabled symlink */ { FLDT_SYMLINK_CRC, "symlink", NULL, (char *)symlink_crc_flds,
db/field.h +5 -0
@@ -15,6 +15,10 @@ typedef enum fldt {FLDT_AGINONN ,FLDT_AGNUMBER , +FLDT_RGBLOCK , +FLDT_RTXLEN , +FLDT_RGNUMBER , +/* attr fields */ FLDT_ATTR , FLDT_ATTR_BLKINFO,
@@ -167,6 +171,7 @@ typedef enum fldt {FLDT_QCNT ,FLDT_QWARNCNT ,FLDT_SB , +FLDT_RTSB ,/* CRC enabled symlink */ FLDT_SYMLINK_CRC,
db/rtgroup.c new file +100 -0
100 lines not on this page · raw message
db/rtgroup.h new file +15 -0
@@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022-2024 Oracle. All Rights Reserved. +* Author: Darrick J. Wong <[email protected]> +*/ +#ifndef DB_RTGROUP_H_ +#define DB_RTGROUP_H_ + +extern const struct field rtsb_flds[]; +extern const struct field rtsb_hfld[]; + +extern void rtsb_init (void ); +extern int rtsb_size (void *obj,int startoff,int idx); + +#endif /* DB_RTGROUP_H_ */
db/sb.c +8 -0
@@ -124,8 +124,12 @@ const field_t sb_flds[] = { { "features2", FLDT_UINT32X, OI(OFF(features2)), C1, 0, TYP_NONE }, { "bad_features2", FLDT_UINT32X, OI(OFF(bad_features2)), premetadirfld_count, FLD_COUNT, TYP_NONE }, + { "rgblklog", FLDT_UINT8D, OI(OFF(rgblklog)), metadirfld_count, + FLD_COUNT, TYP_NONE }, { "metadirpad0", FLDT_UINT8X, OI(OFF(metadirpad0)), metadirfld_count, FLD_COUNT, TYP_NONE }, + { "metadirpad1", FLDT_UINT16X, OI(OFF(metadirpad1)), metadirfld_count, + FLD_COUNT, TYP_NONE }, { "features_compat", FLDT_UINT32X, OI(OFF(features_compat)), C1, 0, TYP_NONE }, { "features_ro_compat", FLDT_UINT32X, OI(OFF(features_ro_compat)),
@@ -141,6 +145,10 @@ const field_t sb_flds[] = { { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, { "metadirino", FLDT_INO, OI(OFF(metadirino)), metadirfld_count, FLD_COUNT, TYP_INODE }, + { "rgcount", FLDT_RGNUMBER, OI(OFF(rgcount)), metadirfld_count, + FLD_COUNT, TYP_NONE }, + { "rgextents", FLDT_RTXLEN, OI(OFF(rgextents)), metadirfld_count, + FLD_COUNT, TYP_NONE }, { NULL } };
db/type.c +6 -0
@@ -28,6 +28,7 @@#include "text.h" #include "symlink.h" #include "fuzz.h" +#include "rtgroup.h" static const typ_t *findtyp (char *name);static int type_f (int argc,char **argv);
@@ -60,6 +61,7 @@ static const typ_t __typtab[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, NULL, TYP_F_NO_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_string, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF },
@@ -102,6 +104,8 @@ static const typ_t __typtab_crc[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, + XFS_SB_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, XFS_SB_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld,
@@ -146,6 +150,8 @@ static const typ_t __typtab_spcrc[] = { { TYP_LOG, "log", NULL, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTBITMAP, "rtbitmap", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_RTSUMMARY, "rtsummary", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RTSB, "rtsb", handle_struct, rtsb_hfld, &xfs_rtsb_buf_ops, + XFS_SB_CRC_OFF }, { TYP_SB, "sb", handle_struct, sb_hfld, &xfs_sb_buf_ops, XFS_SB_CRC_OFF }, { TYP_SYMLINK, "symlink", handle_struct, symlink_crc_hfld,
db/type.h +1 -0
@@ -30,6 +30,7 @@ typedef enum typnmTYP_LOG ,TYP_RTBITMAP ,TYP_RTSUMMARY , +TYP_RTSB ,TYP_SB ,TYP_SYMLINK , TYP_TEXT,
PATCH 22/43 xfs_db: support changing the label and uuid of rt superblocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Update the label and uuid commands to change the rt superblocks along with the filesystem superblocks.
--- db/sb.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 11 deletions(-)
db/sb.c +98 -11
@@ -27,6 +27,7 @@ static int label_f(int argc, char **argv);static void label_help (void );static int version_f (int argc,char **argv);static void version_help (void ); +static size_t check_label (char *label,bool can_warn);static const cmdinfo_t sb_cmd = {"sb" ,NULL , sb_f,0 ,1 ,1 ,N_ ("[agno]" ),
@@ -346,6 +347,65 @@ uuid_help(void) )); } +static bool +check_rtsb ( +struct xfs_mount *mp) +{ +int error; + +if (!xfs_has_rtsb (mp) || !xfs_has_realtime (mp)) +return false; + +push_cur (); + error =set_rt_cur (&typtab[TYP_RTSB ],XFS_RTSB_DADDR , +XFS_FSB_TO_BB (mp,1 ),DB_RING_ADD ,NULL ); +if (error ==ENODEV ) { +/* no rt dev means we should just bail out */ +pop_cur (); +return true; + } + +pop_cur (); +return false; +} + +static int +update_rtsb ( +struct xfs_mount *mp, +uuid_t *uuid, +char *label) +{ +struct xfs_rtsb *rsb; +int error; + +if (!xfs_has_rtsb (mp) || !xfs_has_realtime (mp)) +return false; + +push_cur (); + error =set_rt_cur (&typtab[TYP_RTSB ],XFS_RTSB_DADDR , +XFS_FSB_TO_BB (mp,1 ),DB_RING_ADD ,NULL ); +if (error ==ENODEV ) { +/* no rt dev means we should just bail out */ + exitcode =1 ; +pop_cur (); +return 1 ; + } + + rsb = iocur_top->data; +if (label) { +size_t len =check_label (label, false); + +memset (&rsb->rsb_fname,0 ,XFSLABEL_MAX ); +memcpy (&rsb->rsb_fname, label, len); + } +if (uuid) +memcpy (&rsb->rsb_uuid, uuid,sizeof (rsb->rsb_uuid)); +write_cur (); +pop_cur (); + +return 0 ; +} +static uuid_t *do_uuid (xfs_agnumber_t agno,uuid_t *uuid) {
@@ -390,6 +450,7 @@ do_uuid(xfs_agnumber_t agno, uuid_t *uuid)memcpy (&tsb.sb_uuid, uuid,sizeof (uuid_t));libxfs_sb_to_disk (iocur_top->data, &tsb);write_cur (); +memcpy (&mp->m_sb.sb_uuid, uuid,sizeof (uuid_t));return uuid; }
@@ -452,11 +513,18 @@ uuid_f( } } +if (check_rtsb (mp)) { + exitcode =1 ; +return 0 ; + } +/* clear the log (setting uuid) if it's not dirty */ if (!sb_logzero (&uu))return 0 ;dbprintf (_ ("writing all SBs\n" )); +if (update_rtsb (mp, &uu,NULL )) +return 1 ;for (agno =0 ; agno < mp->m_sb.sb_agcount; agno++)if (!do_uuid (agno, &uu)) {dbprintf (_ ("failed to set UUID in AG %d\n" ), agno);
@@ -525,6 +593,27 @@ label_help(void) )); } +static size_t +check_label ( +char *label, +bool can_warn) +{ +size_t len =strlen (label); + +if (len >XFSLABEL_MAX ) { +if (can_warn) +dbprintf (_ ("%s: truncating label length from %d to %d\n" ), + progname, (int )len,XFSLABEL_MAX ); + len =XFSLABEL_MAX ; + } +if ( len ==2 && + (strcmp (label,"\"\"" ) ==0 || +strcmp (label,"''" ) ==0 || +strcmp (label,"--" ) ==0 ) ) + label[0 ] = label[1 ] ='\0' ; +return len; +} +static char *do_label (xfs_agnumber_t agno,char *label) {
@@ -543,22 +632,13 @@ do_label(xfs_agnumber_t agno, char *label)return &lbl[0 ]; }/* set label */ -if ((len =strlen (label)) >sizeof (tsb.sb_fname)) { -if (agno ==0 ) -dbprintf (_ ("%s: truncating label length from %d to %d\n" ), - progname, (int )len, (int )sizeof (tsb.sb_fname)); - len =sizeof (tsb.sb_fname); - } -if ( len ==2 && - (strcmp (label,"\"\"" ) ==0 || -strcmp (label,"''" ) ==0 || -strcmp (label,"--" ) ==0 ) ) - label[0 ] = label[1 ] ='\0' ; + len =check_label (label, agno ==0 );memset (&tsb.sb_fname,0 ,sizeof (tsb.sb_fname));memcpy (&tsb.sb_fname, label, len);memcpy (&lbl[0 ], &tsb.sb_fname,sizeof (tsb.sb_fname));libxfs_sb_to_disk (iocur_top->data, &tsb);write_cur (); +memcpy (&mp->m_sb.sb_fname, &tsb.sb_fname,XFSLABEL_MAX );return &lbl[0 ]; }
@@ -590,7 +670,14 @@ label_f(return 0 ; } +if (check_rtsb (mp)) { + exitcode =1 ; +return 0 ; + } +dbprintf (_ ("writing all SBs\n" )); +if (update_rtsb (mp,NULL , argv[1 ])) +return 1 ;for (ag =0 ; ag < mp->m_sb.sb_agcount; ag++)if ((p =do_label (ag, argv[1 ])) ==NULL ) {dbprintf (_ ("failed to set label in AG %d\n" ), ag);
PATCH 23/43 xfs_db: enable conversion of rt space units
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach the xfs_db convert function about realtime extents, blocks, and realtime group numbers.
--- db/convert.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++- man/man8/xfs_db.8 | 17 +++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-)
db/convert.c +59 -1
@@ -34,6 +34,21 @@ rtblock_to_bytes(rtx_to_rtblock(xfs_rbmblock_to_rtx(mp, (uint64_t)x)))#define rbmword_to_bytes (x) \ rtblock_to_bytes(rtx_to_rtblock((uint64_t)(x) << XFS_NBWORDLOG)) +#define rgblock_to_bytes (x) \ + ((uint64_t)(x) << mp->m_sb.sb_blocklog) +#define rgnumber_to_bytes (x) \ + rgblock_to_bytes((uint64_t)(x) * mp->m_groups[XG_TYPE_RTG].blocks) + +static inline xfs_rgnumber_t +xfs_daddr_to_rgno ( +struct xfs_mount *mp, +xfs_daddr_t daddr) +{ +if (!xfs_has_rtgroups (mp)) +return 0 ; + +return XFS_BB_TO_FSBT (mp, daddr) / mp->m_groups[XG_TYPE_RTG ].blocks; +} typedef enum { CT_NONE = -1,
@@ -55,6 +70,8 @@ typedef enum {CT_RSUMBLOCK ,/* block within rt summary */ CT_RSUMLOG ,/* log level for rtsummary computations */ CT_RSUMINFO ,/* info word within rt summary */ +CT_RGBLOCK ,/* xfs_rgblock_t */ +CT_RGNUMBER ,/* xfs_rgno_t */ NCTS } ctype_t;
@@ -80,6 +97,8 @@ typedef union {xfs_fileoff_t rbmblock;unsigned int rbmword;xfs_fileoff_t rsumblock; +xfs_rgnumber_t rgnumber; +xfs_rgblock_t rgblock; } cval_t;static uint64_t bytevalue (ctype_t ctype,cval_t *val);
@@ -95,7 +114,7 @@ static const char *agnumber_names[] = { "agnumber", "agno", NULL };static const char *bboff_names[] = {"bboff" ,"daddroff" ,NULL };static const char *blkoff_names[] = {"blkoff" ,"fsboff" ,"agboff" ,NULL }; -static const char *rtblkoff_names[] = {"blkoff" ,"rtboff" , +static const char *rtblkoff_names[] = {"blkoff" ,"rtboff" ,"rgboff" ,NULL };static const char *byte_names[] = {"byte" ,"fsbyte" ,NULL };static const char *daddr_names[] = {"daddr" ,"bb" ,NULL };
@@ -111,6 +130,8 @@ static const char *rbmword_names[] = { "rbmword", "rbmw", NULL };static const char *rsumblock_names[] = {"rsumblock" ,"rsmb" ,NULL };static const char *rsumlog_names[] = {"rsumlog" ,"rsml" ,NULL };static const char *rsumword_names[] = {"rsuminfo" ,"rsmi" ,NULL }; +static const char *rgblock_names[] = {"rgblock" ,"rgbno" ,NULL }; +static const char *rgnumber_names[] = {"rgnumber" ,"rgno" ,NULL };static int rsuminfo;static int rsumlog;
@@ -208,6 +229,14 @@ static const ctydesc_t ctydescs_rt[NCTS] = { .allowed = M(RSUMBLOCK), .names = rsumword_names, }, + [CT_RGBLOCK] = { + .allowed = M(RGNUMBER)|M(BBOFF)|M(BLKOFF)|M(RSUMLOG), + .names = rgblock_names, + }, + [CT_RGNUMBER] = { + .allowed = M(RGBLOCK)|M(BBOFF)|M(BLKOFF)|M(RSUMLOG), + .names = rgnumber_names, + }, }; static const cmdinfo_t convert_cmd =
@@ -295,6 +324,10 @@ bytevalue(ctype_t ctype, cval_t *val)* value. */ return 0 ; +case CT_RGBLOCK : +return rgblock_to_bytes (val->rgblock); +case CT_RGNUMBER : +return rgnumber_to_bytes (val->rgnumber);case CT_NONE :case NCTS :break ;
@@ -401,6 +434,8 @@ convert_f(int argc, char **argv)case CT_RSUMBLOCK :case CT_RSUMLOG :case CT_RSUMINFO : +case CT_RGBLOCK : +case CT_RGNUMBER :/* shouldn't get here */ ASSERT (0 );break ;
@@ -459,6 +494,17 @@ rt_daddr_to_rsuminfo(return xfs_rtsumoffs_to_infoword (mp, rsumoff); } +static inline xfs_rgblock_t +rt_daddr_to_rgbno ( +struct xfs_mount *mp, +xfs_daddr_t daddr) +{ +if (!xfs_has_rtgroups (mp)) +return 0 ; + +return XFS_BB_TO_FSBT (mp, daddr) % mp->m_groups[XG_TYPE_RTG ].blocks; +} +static int rtconvert_f (int argc,char **argv) {
@@ -551,6 +597,12 @@ rtconvert_f(int argc, char **argv)case CT_RSUMINFO : v =rt_daddr_to_rsuminfo (mp, v);break ; +case CT_RGBLOCK : + v =rt_daddr_to_rgbno (mp, v >>BBSHIFT ); +break ; +case CT_RGNUMBER : + v =xfs_daddr_to_rgno (mp, v >>BBSHIFT ); +break ;case CT_AGBLOCK :case CT_AGINO :case CT_AGNUMBER :
@@ -643,6 +695,12 @@ getvalue(char *s, ctype_t ctype, cval_t *val)case CT_RSUMINFO : rsuminfo = (unsigned int )v;break ; +case CT_RGBLOCK : + val->rgblock = (xfs_rgblock_t )v; +break ; +case CT_RGNUMBER : + val->rgnumber = (xfs_rgnumber_t )v; +break ;case CT_NONE :case NCTS :/* NOTREACHED */
man/man8/xfs_db.8 +17 -0
@@ -1165,6 +1165,16 @@ .SH COMMANDS .RS 1.0i .PD 0 .HP +.B rgblock +or +.B rgbno +(realtime block within a realtime group) +.HP +.B rgnumber +or +.B rgno +(realtime group number) +.HP .B bboff or .B daddroff
@@ -1232,6 +1242,13 @@ .SH COMMANDS .RE .IP Only conversions that "make sense" are allowed. +The compound form (with more than three arguments) is useful for +conversions such as +.B convert rgno +.I rg +.B rgbno +.I rgb +.BR rtblock . Realtime summary file location conversions have the following rules: Each info word in the rt summary file counts the number of free extents of a
PATCH 24/43 xfs_db: metadump metadir rt bitmap and summary files
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Don't skip dumping the data fork for regular files that are marked as metadata inodes. This catches rtbitmap and summary inodes on rtgroup enabled file systems where their inode numbers aren't recorded in the superblock.
--- db/metadump.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
db/metadump.c +5 -1
@@ -2072,7 +2072,11 @@ process_bmbt_reclist(xfs_agblock_t agbno;int rval =1 ; -if (btype ==TYP_DATA ) +/* +* Ignore regular file data except for metadata inodes, where it is by +* definition metadata. +*/ +if (btype ==TYP_DATA && !is_metadata_ino (dip))return 1 ;convert_extent (&rp[numrecs -1 ], &o, &s, &c, &f);
PATCH 25/43 xfs_db: metadump realtime devices
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach the metadump device to dump the filesystem metadata of a realtime device to the metadump file. Currently, this is limited to the realtime superblock.
--- db/metadump.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ db/xfs_metadump.sh | 5 +++- include/xfs_metadump.h | 8 +++++++ man/man8/xfs_metadump.8 | 11 ++++++++++ mdrestore/xfs_mdrestore.c | 5 +++- 5 files changed, 78 insertions(+), 3 deletions(-)
db/metadump.c +52 -0
@@ -85,6 +85,7 @@ static struct metadump {bool dirty_log;bool external_log;bool stdout_metadump; +bool realtime_data;xfs_ino_t cur_ino;/* Metadump file */ FILE *outf;
@@ -3027,6 +3028,7 @@ init_metadump_v2(void) {struct xfs_metadump_header xmh = {0 };uint32_t compat_flags =0 ; +uint32_t incompat_flags =0 ; xmh.xmh_magic =cpu_to_be32 (XFS_MD_MAGIC_V2 ); xmh.xmh_version =cpu_to_be32 (2 );
@@ -3039,8 +3041,11 @@ init_metadump_v2(void) compat_flags |=XFS_MD2_COMPAT_DIRTYLOG ;if (metadump.external_log) compat_flags |=XFS_MD2_COMPAT_EXTERNALLOG ; +if (metadump.realtime_data) + incompat_flags |=XFS_MD2_INCOMPAT_RTDEVICE ; xmh.xmh_compat_flags =cpu_to_be32 (compat_flags); + xmh.xmh_incompat_flags =cpu_to_be32 (incompat_flags);if (fwrite (&xmh,sizeof (xmh),1 , metadump.outf) !=1 ) {print_warning ("error writing to target file" );
@@ -3050,6 +3055,30 @@ init_metadump_v2(void)return 0 ; } +static int +copy_rtsb (void ) +{ +int error; + +if (metadump.show_progress) +print_progress ("Copying realtime superblock" ); + +push_cur (); + error =set_rt_cur (&typtab[TYP_RTSB ],XFS_RTSB_DADDR , +XFS_FSB_TO_BB (mp,1 ),DB_RING_ADD ,NULL ); +if (error) +return 0 ; +if (iocur_top->data ==NULL ) { +pop_cur (); +print_warning ("cannot read realtime superblock" ); +return !metadump.stop_on_read_error; + } + error =write_buf (iocur_top); +pop_cur (); + +return error ?0 :1 ; +} + static int write_metadump_v2( enum typnm type,
@@ -3064,6 +3093,8 @@ write_metadump_v2(if (type ==TYP_LOG && mp->m_logdev_targp->bt_bdev != mp->m_ddev_targp->bt_bdev) addr |=XME_ADDR_LOG_DEVICE ; +else if (type ==TYP_RTSB ) + addr |=XME_ADDR_RT_DEVICE ;else addr |=XME_ADDR_DATA_DEVICE ;
@@ -3112,6 +3143,7 @@ metadump_f( metadump.zero_stale_data = true; metadump.dirty_log = false; metadump.external_log = false; + metadump.realtime_data = false;if (mp->m_sb.sb_magicnum !=XFS_SB_MAGIC ) { print_warning("bad superblock magic number %x, giving up",
@@ -3190,6 +3222,20 @@ metadump_f(return 1 ; } +/* The realtime device only contains metadata if rtgroups is enabled. */ +if (mp->m_rtdev_targp->bt_bdev &&xfs_has_rtgroups (mp)) + metadump.realtime_data = true; + +if (metadump.realtime_data && !version_opt_set) + metadump.version =2 ; + +if (metadump.version ==2 &&xfs_has_realtime (mp) && +xfs_has_rtgroups (mp) && + !metadump.realtime_data) { +print_warning ("realtime device not loaded, use -R" ); +return 1 ; + } +/* * If we'll copy the log, see if the log is dirty. *
@@ -3289,6 +3335,12 @@ metadump_f(if (!exitcode && !(metadump.version ==1 && metadump.external_log)) exitcode = !copy_log (); +/* copy rt superblock */ +if (!exitcode && metadump.realtime_data &&xfs_has_rtsb (mp)) { +if (!copy_rtsb ()) + exitcode =1 ; + } +/* write the remaining index */ if (!exitcode && metadump.mdops->finish_dump) exitcode = metadump.mdops->finish_dump () <0 ;
db/xfs_metadump.sh +3 -2
@@ -6,9 +6,9 @@ OPTS=" " DBOPTS=" " -USAGE="Usage: xfs_metadump [-aefFogwV] [-m max_extents] [-l logdev] source target" +USAGE="Usage: xfs_metadump [-aefFogwV] [-m max_extents] [-l logdev] [-r rtdev] [-v version] source target" -while getopts "aefgl:m:owFv:V" c +while getopts "aefFgl:m:or:wv:V" c do case $c in a) OPTS=$OPTS"-a ";;
@@ -25,6 +25,7 @@ do status=$? exit $status ;; + r) DBOPTS=$DBOPTS"-R "$OPTARG" ";; \?) echo $USAGE 1>&2 exit 2 ;;
include/xfs_metadump.h +8 -0
@@ -68,12 +68,18 @@ struct xfs_metadump_header {/* Dump contains external log contents. */ #define XFS_MD2_COMPAT_EXTERNALLOG (1 << 3) +/* Dump contains realtime device contents. */ +#define XFS_MD2_INCOMPAT_RTDEVICE (1U << 0) + +#define XFS_MD2_INCOMPAT_ALL (XFS_MD2_INCOMPAT_RTDEVICE) +struct xfs_meta_extent {/* * Lowest 54 bits are used to store 512 byte addresses. * Next 2 bits is used for indicating the device. * 00 - Data device * 01 - External log +* 10 - Realtime device */ __be64 xme_addr;/* In units of 512 byte blocks */
@@ -88,6 +94,8 @@ struct xfs_meta_extent {#define XME_ADDR_DATA_DEVICE (0ULL << XME_ADDR_DEVICE_SHIFT)/* Extent was copied from the log device */ #define XME_ADDR_LOG_DEVICE (1ULL << XME_ADDR_DEVICE_SHIFT) +/* Extent was copied from the rt device */ +#define XME_ADDR_RT_DEVICE (2ULL << XME_ADDR_DEVICE_SHIFT)#define XME_ADDR_DEVICE_MASK (3ULL << XME_ADDR_DEVICE_SHIFT)
man/man8/xfs_metadump.8 +11 -0
@@ -12,6 +12,9 @@ .SH SYNOPSIS .B \-l .I logdev ] [ +.B \-r +.I rtdev +] [ .B \-v .I version ]
@@ -146,6 +149,14 @@ .SH OPTIONS .B \-o Disables obfuscation of file names and extended attributes. .TP +.BI \-r " rtdev" +For filesystems that have a realtime section, this specifies the device where +the realtime section resides. +If the v2 metadump format is selected, the realtime group superblocks will be +copied to the metadump. +The v2 metadump format will be selected automatically if the filesystem +contains realtime groups. +.TP .B \-v The format of the metadump file to be produced. Valid values are 1 and 2.
mdrestore/xfs_mdrestore.c +4 -1
@@ -314,7 +314,7 @@ read_header_v2( sizeof(h->v2) - sizeof(h->v2.xmh_magic), 1, md_fp) != 1)fatal ("error reading from metadump file\n" ); -if (h->v2.xmh_incompat_flags !=0 ) +if (h->v2.xmh_incompat_flags &cpu_to_be32 (~XFS_MD2_INCOMPAT_ALL ))fatal ("Metadump header has unknown incompat flags set\n" );if (h->v2.xmh_reserved !=0 )
@@ -324,6 +324,9 @@ read_header_v2(if (!mdrestore.external_log && (compat &XFS_MD2_COMPAT_EXTERNALLOG ))fatal ("External Log device is required\n" ); + +if (h->v2.xmh_incompat_flags &cpu_to_be32 (XFS_MD2_INCOMPAT_RTDEVICE )) +fatal ("Realtime device not yet supported\n" ); } static void
PATCH 26/43 xfs_db: dump rt bitmap blocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that rtbitmap blocks have a header, make it so that xfs_db can analyze the structure.
--- db/field.c | 6 ++++++ db/field.h | 3 +++ db/inode.c | 34 +++++++++++++++++++++++++--------- db/rtgroup.c | 34 ++++++++++++++++++++++++++++++++++ db/rtgroup.h | 3 +++ db/type.c | 5 +++++ db/type.h | 1 + 7 files changed, 77 insertions(+), 9 deletions(-)
db/field.c +6 -0
@@ -406,6 +406,12 @@ const ftattr_t ftattrtab[] = { { FLDT_UUID, "uuid", fp_uuid, NULL, SI(bitsz(uuid_t)), 0, NULL, NULL }, { FLDT_PARENT_REC, "parent", NULL, (char *)parent_flds, SI(bitsz(struct xfs_parent_rec)), 0, NULL, parent_flds }, + + { FLDT_RTWORD, "rtword", fp_num, "%#x", SI(bitsz(xfs_rtword_t)), + 0, NULL, NULL }, + { FLDT_RGBITMAP, "rgbitmap", NULL, (char *)rgbitmap_flds, btblock_size, + FTARG_SIZE, NULL, rgbitmap_flds }, + { FLDT_ZZZ, NULL } };
db/field.h +3 -0
@@ -196,6 +196,9 @@ typedef enum fldt {FLDT_PARENT_REC , +FLDT_RTWORD , +FLDT_RGBITMAP , + FLDT_ZZZ /* mark last entry */ } fldt_t;
db/inode.c +25 -9
@@ -705,16 +705,32 @@ inode_next_type(void)case S_IFLNK :return TYP_SYMLINK ;case S_IFREG : -if (iocur_top->ino == mp->m_sb.sb_rbmino) -return TYP_RTBITMAP ; -else if (iocur_top->ino == mp->m_sb.sb_rsumino) -return TYP_RTSUMMARY ; -else if (iocur_top->ino == mp->m_sb.sb_uquotino || - iocur_top->ino == mp->m_sb.sb_gquotino || - iocur_top->ino == mp->m_sb.sb_pquotino) +if (xfs_has_rtgroups (mp)) { +struct xfs_dinode *dic = iocur_top->data; + +switch (be16_to_cpu (dic->di_metatype)) { +case XFS_METAFILE_USRQUOTA : +case XFS_METAFILE_GRPQUOTA : +case XFS_METAFILE_PRJQUOTA : +return TYP_DQBLK ; +case XFS_METAFILE_RTBITMAP : +return TYP_RGBITMAP ; +default : +return TYP_DATA ; + } + }else { +if (iocur_top->ino == mp->m_sb.sb_rbmino) +return TYP_RTBITMAP ; +if (iocur_top->ino == mp->m_sb.sb_rsumino) +return TYP_RTSUMMARY ; + } + +if (iocur_top->ino == mp->m_sb.sb_uquotino || + iocur_top->ino == mp->m_sb.sb_gquotino || + iocur_top->ino == mp->m_sb.sb_pquotino)return TYP_DQBLK ; -else -return TYP_DATA ; + +return TYP_DATA ;default :return TYP_NONE ; }
db/rtgroup.c +34 -0
@@ -44,6 +44,7 @@ const field_t rtsb_flds[] = { { "meta_uuid", FLDT_UUID, OI(OFF(meta_uuid)), C1, 0, TYP_NONE }, { NULL } }; +#undef OFFconst field_t rtsb_hfld[] = { {"" ,FLDT_RTSB ,OI (0 ),C1 ,0 ,TYP_NONE },
@@ -98,3 +99,36 @@ rtsb_size( {return bitize (mp->m_sb.sb_blocksize); } + +static int +rtwords_count ( +void *obj, +int startoff) +{ +unsigned int blksz = mp->m_sb.sb_blocksize; + +if (xfs_has_rtgroups (mp)) + blksz -=sizeof (struct xfs_rtbuf_blkinfo ); + +return blksz >>XFS_WORDLOG ; +} + +#define OFF (f) bitize(offsetof(struct xfs_rtbuf_blkinfo, rt_ ## f)) +const field_t rgbitmap_flds[] = { + {"magicnum" ,FLDT_UINT32X ,OI (OFF (magic)),C1 ,0 ,TYP_NONE }, + {"crc" ,FLDT_CRC ,OI (OFF (crc)),C1 ,0 ,TYP_NONE }, + {"owner" ,FLDT_INO ,OI (OFF (owner)),C1 ,0 ,TYP_NONE }, + {"bno" ,FLDT_DFSBNO ,OI (OFF (blkno)),C1 ,0 ,TYP_BMAPBTD }, + {"lsn" ,FLDT_UINT64X ,OI (OFF (lsn)),C1 ,0 ,TYP_NONE }, + {"uuid" ,FLDT_UUID ,OI (OFF (uuid)),C1 ,0 ,TYP_NONE }, +/* the rtword array is after the actual structure */ + {"rtwords" ,FLDT_RTWORD ,OI (bitize (sizeof (struct xfs_rtbuf_blkinfo ))), + rtwords_count,FLD_ARRAY |FLD_COUNT ,TYP_DATA }, + {NULL } +}; +#undef OFF + +const field_t rgbitmap_hfld[] = { + {"" ,FLDT_RGBITMAP ,OI (0 ),C1 ,0 ,TYP_NONE }, + {NULL } +};
db/rtgroup.h +3 -0
@@ -9,6 +9,9 @@extern const struct field rtsb_flds[];extern const struct field rtsb_hfld[]; +extern const struct field rgbitmap_flds[]; +extern const struct field rgbitmap_hfld[]; +extern void rtsb_init (void );extern int rtsb_size (void *obj,int startoff,int idx);
db/type.c +5 -0
@@ -67,6 +67,7 @@ static const typ_t __typtab[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_hfld, NULL, TYP_F_NO_CRC_OFF }, + { TYP_RGBITMAP, NULL }, { TYP_NONE, NULL } };
@@ -113,6 +114,8 @@ static const typ_t __typtab_crc[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_crc_hfld, &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, + { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, + &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } };
@@ -159,6 +162,8 @@ static const typ_t __typtab_spcrc[] = { { TYP_TEXT, "text", handle_text, NULL, NULL, TYP_F_NO_CRC_OFF }, { TYP_FINOBT, "finobt", handle_struct, finobt_spcrc_hfld, &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, + { TYP_RGBITMAP, "rgbitmap", handle_struct, rgbitmap_hfld, + &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } };
db/type.h +1 -0
@@ -35,6 +35,7 @@ typedef enum typnmTYP_SYMLINK ,TYP_TEXT ,TYP_FINOBT , +TYP_RGBITMAP , TYP_NONE } typnm_t;
PATCH 27/43 xfs_db: dump rt summary blocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that rtsummary blocks have a header, make it so that xfs_db can analyze the structure.
--- db/field.c | 4 ++++ db/field.h | 2 ++ db/inode.c | 2 ++ db/rtgroup.c | 20 ++++++++++++++++++++ db/rtgroup.h | 3 +++ db/type.c | 5 +++++ db/type.h | 1 + 7 files changed, 37 insertions(+)
db/field.c +4 -0
@@ -411,6 +411,10 @@ const ftattr_t ftattrtab[] = { 0, NULL, NULL }, {FLDT_RGBITMAP ,"rgbitmap" ,NULL , (char *)rgbitmap_flds, btblock_size, FTARG_SIZE, NULL, rgbitmap_flds }, + { FLDT_SUMINFO, "suminfo", fp_num, "%u", SI(bitsz(xfs_suminfo_t)), + 0, NULL, NULL }, + { FLDT_RGSUMMARY, "rgsummary", NULL, (char *)rgsummary_flds, + btblock_size, FTARG_SIZE, NULL, rgsummary_flds }, { FLDT_ZZZ, NULL } };
db/field.h +2 -0
@@ -198,6 +198,8 @@ typedef enum fldt {FLDT_RTWORD ,FLDT_RGBITMAP , +FLDT_SUMINFO , +FLDT_RGSUMMARY , FLDT_ZZZ /* mark last entry */ } fldt_t;
db/inode.c +2 -0
@@ -715,6 +715,8 @@ inode_next_type(void)return TYP_DQBLK ;case XFS_METAFILE_RTBITMAP :return TYP_RGBITMAP ; +case XFS_METAFILE_RTSUMMARY : +return TYP_RGSUMMARY ;default :return TYP_DATA ; }
db/rtgroup.c +20 -0
@@ -132,3 +132,23 @@ const field_t rgbitmap_hfld[] = { { "", FLDT_RGBITMAP, OI(0), C1, 0, TYP_NONE }, { NULL } }; + +#define OFF (f) bitize(offsetof(struct xfs_rtbuf_blkinfo, rt_ ## f)) +const field_t rgsummary_flds[] = { + {"magicnum" ,FLDT_UINT32X ,OI (OFF (magic)),C1 ,0 ,TYP_NONE }, + {"crc" ,FLDT_CRC ,OI (OFF (crc)),C1 ,0 ,TYP_NONE }, + {"owner" ,FLDT_INO ,OI (OFF (owner)),C1 ,0 ,TYP_NONE }, + {"bno" ,FLDT_DFSBNO ,OI (OFF (blkno)),C1 ,0 ,TYP_BMAPBTD }, + {"lsn" ,FLDT_UINT64X ,OI (OFF (lsn)),C1 ,0 ,TYP_NONE }, + {"uuid" ,FLDT_UUID ,OI (OFF (uuid)),C1 ,0 ,TYP_NONE }, +/* the suminfo array is after the actual structure */ + {"suminfo" ,FLDT_SUMINFO ,OI (bitize (sizeof (struct xfs_rtbuf_blkinfo ))), + rtwords_count,FLD_ARRAY |FLD_COUNT ,TYP_DATA }, + {NULL } +}; +#undef OFF + +const field_t rgsummary_hfld[] = { + {"" ,FLDT_RGSUMMARY ,OI (0 ),C1 ,0 ,TYP_NONE }, + {NULL } +};
db/rtgroup.h +3 -0
@@ -12,6 +12,9 @@ extern const struct field rtsb_hfld[];extern const struct field rgbitmap_flds[];extern const struct field rgbitmap_hfld[]; +extern const struct field rgsummary_flds[]; +extern const struct field rgsummary_hfld[]; +extern void rtsb_init (void );extern int rtsb_size (void *obj,int startoff,int idx);
db/type.c +5 -0
@@ -68,6 +68,7 @@ static const typ_t __typtab[] = { {TYP_FINOBT ,"finobt" , handle_struct, finobt_hfld,NULL , TYP_F_NO_CRC_OFF }, { TYP_RGBITMAP, NULL }, + { TYP_RGSUMMARY, NULL }, { TYP_NONE, NULL } };
@@ -116,6 +117,8 @@ static const typ_t __typtab_crc[] = { &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, {TYP_RGBITMAP ,"rgbitmap" , handle_struct, rgbitmap_hfld, &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, + { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, + &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } };
@@ -164,6 +167,8 @@ static const typ_t __typtab_spcrc[] = { &xfs_finobt_buf_ops, XFS_BTREE_SBLOCK_CRC_OFF }, {TYP_RGBITMAP ,"rgbitmap" , handle_struct, rgbitmap_hfld, &xfs_rtbitmap_buf_ops, XFS_RTBUF_CRC_OFF }, + { TYP_RGSUMMARY, "rgsummary", handle_struct, rgsummary_hfld, + &xfs_rtsummary_buf_ops, XFS_RTBUF_CRC_OFF }, { TYP_NONE, NULL } };
db/type.h +1 -0
@@ -36,6 +36,7 @@ typedef enum typnmTYP_TEXT ,TYP_FINOBT ,TYP_RGBITMAP , +TYP_RGSUMMARY , TYP_NONE } typnm_t;
PATCH 28/43 xfs_db: report rt group and block number in the bmap command
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The bmap command does not report startblocks for realtime files correctly. If rtgroups are enabled, we need to use the appropriate functions to crack the startblock into rtgroup and block numbers; if not, then we need to report a linear address and not try to report a group number.
Fix both of these issues.
--- db/bmap.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 7 deletions(-)
db/bmap.c +49 -7
@@ -119,6 +119,41 @@ bmap( *nexp = n; } +static void +print_group_bmbt ( +bool isrt, +int whichfork, +const struct bmap_ext *be) +{ +unsigned int gno; +unsigned long long gbno; + +if (whichfork ==XFS_DATA_FORK && isrt) { + gno =xfs_rtb_to_rgno (mp, be->startblock); + gbno =xfs_rtb_to_rgbno (mp, be->startblock); + }else { + gno =XFS_FSB_TO_AGNO (mp, be->startblock); + gbno =XFS_FSB_TO_AGBNO (mp, be->startblock); + } + +dbprintf ( +_ ("%s offset %lld startblock %llu (%u/%llu) count %llu flag %u\n" ), + whichfork ==XFS_DATA_FORK ?_ ("data" ) :_ ("attr" ), + be->startoff, be->startblock, + gno, gbno, + be->blockcount, be->flag); +} + +static void +print_linear_bmbt ( +const struct bmap_ext *be) +{ +dbprintf (_ ("%s offset %lld startblock %llu count %llu flag %u\n" ), +_ ("data" ), + be->startoff, be->startblock, + be->blockcount, be->flag); +} + static int bmap_f( int argc,
@@ -135,6 +170,7 @@ bmap_f(xfs_extnum_t nex;char *p;int whichfork; +bool isrt;if (iocur_top->ino ==NULLFSINO ) {dbprintf (_ ("no current inode\n" ));
@@ -154,6 +190,10 @@ bmap_f(return 0 ; } } + + dip = iocur_top->data; + isrt = (dip->di_flags &cpu_to_be16 (XFS_DIFLAG_REALTIME )); +if (afork + dfork ==0 ) {push_cur ();set_cur_inode (iocur_top->ino);
@@ -198,13 +238,15 @@ bmap_f(bmap (co, eo - co +1 , whichfork, &nex, &be);if (nex ==0 )break ; -dbprintf (_ ("%s offset %lld startblock %llu (%u/%u) count " -"%llu flag %u\n" ), - whichfork ==XFS_DATA_FORK ?_ ("data" ) :_ ("attr" ), - be.startoff, be.startblock, -XFS_FSB_TO_AGNO (mp, be.startblock), -XFS_FSB_TO_AGBNO (mp, be.startblock), - be.blockcount, be.flag); + +if (whichfork ==XFS_DATA_FORK && isrt) { +if (xfs_has_rtgroups (mp)) +print_group_bmbt (isrt, whichfork, &be); +else +print_linear_bmbt (&be); + }else { +print_group_bmbt (isrt, whichfork, &be); + } co = be.startoff + be.blockcount; } co = cosave;
PATCH 29/43 xfs_mdrestore: restore rt group superblocks to realtime device
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support restoring realtime device metadata to the realtime device, if the dumped filesystem had one.
--- man/man8/xfs_mdrestore.8 | 10 ++++++++ mdrestore/xfs_mdrestore.c | 58 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 57 insertions(+), 11 deletions(-)
man/man8/xfs_mdrestore.8 +10 -0
@@ -8,6 +8,9 @@ .SH SYNOPSIS ] [ .B \-l .I logdev +] [ +.B \-r +.I rtdev ] .I source .I target
@@ -17,6 +20,9 @@ .SH SYNOPSIS [ .B \-l .I logdev +] [ +.B \-r +.I rtdev ] .I source .br
@@ -61,6 +67,10 @@ .SH OPTIONS In such a scenario, the user has to provide a device to which the log device contents from the metadump file are copied. .TP +.BI \-r " rtdev" +Restore realtime device metadata to this device. +This is only required for a metadump in v2 format. +.TP .B \-V Prints the version number and exits. .SH DIAGNOSTICS
mdrestore/xfs_mdrestore.c +47 -11
154 lines not on this page · raw message
PATCH 30/43 xfs_io: support scrubbing rtgroup metadata
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support scrubbing all rtgroup metadata with a scrubv call.
--- io/scrub.c | 40 ++++++++++++++++++++++++++++++++++++++++ man/man8/xfs_io.8 | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-)
io/scrub.c +40 -0
@@ -165,6 +165,32 @@ parse_metapath(return true; } +static bool +parse_rtgroup ( +int argc, +char **argv, +int optind, +__u32 *rgno) +{ +char *p; +unsigned long control; + +if (optind != argc -1 ) { +fprintf (stderr,_ ("Must specify one rtgroup number.\n" )); +return false; + } + + control =strtoul (argv[optind], &p,0 ); +if (*p !='\0' ) { +fprintf (stderr,_ ("Bad rtgroup number '%s'.\n" ), + argv[optind]); +return false; + } + + *rgno = control; +return true; +} + static int parse_args( int argc,
@@ -230,6 +256,12 @@ parse_args(return command_usage (cmdinfo); }break ; +case XFROG_SCRUB_GROUP_RTGROUP : +if (!parse_rtgroup (argc, argv, optind, &meta->sm_agno)) { + exitcode =1 ; +return command_usage (cmdinfo); + } +break ;case XFROG_SCRUB_GROUP_FS :case XFROG_SCRUB_GROUP_NONE :case XFROG_SCRUB_GROUP_SUMMARY :
@@ -539,6 +571,8 @@ scrubv_f( group =XFROG_SCRUB_GROUP_ISCAN ; else if (!strcmp(argv[optind], "summary")) group =XFROG_SCRUB_GROUP_SUMMARY ; + else if (!strcmp(argv[optind], "rtgroup")) + group =XFROG_SCRUB_GROUP_RTGROUP ; else {printf (_ ("Unknown group '%s'.\n" ), argv[optind]); exitcode =1 ;
@@ -576,6 +610,12 @@ scrubv_f(return command_usage (&scrubv_cmd); }break ; +case XFROG_SCRUB_GROUP_RTGROUP : +if (!parse_rtgroup (argc, argv, optind, &scrubv.head.svh_agno)) { + exitcode =1 ; +return command_usage (&scrubv_cmd); + } +break ;default :ASSERT (0 );break ;
man/man8/xfs_io.8 +2 -1
@@ -1425,11 +1425,12 @@ .SH FILESYSTEM COMMANDS .RE .PD .TP -.BI "scrub " type " [ " agnumber " | " "ino" " " "gen" " | " metapath " ]" +.BI "scrub " type " [ " agnumber " | " rgnumber " | " "ino" " " "gen" " | " metapath " ]" Scrub internal XFS filesystem metadata. The .BI type parameter specifies which type of metadata to scrub. For AG metadata, one AG number must be specified. +For realtime group metadata, one rtgroup number must be specified. For file metadata, the scrub is applied to the open file unless the inode number and generation number are specified. For metapath, the name of a file or a raw number must be specified.
PATCH 31/43 xfs_io: support scrubbing rtgroup metadata paths
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support scrubbing the metadata directory path of an rtgroup metadata file.
--- io/scrub.c | 41 +++++++++++++++++++++++++++++++++++------ man/man8/xfs_io.8 | 3 ++- 2 files changed, 37 insertions(+), 7 deletions(-)
io/scrub.c +35 -6
@@ -136,21 +136,23 @@ parse_metapath(int argc, char **argv, int optind, - __u64 *ino) + __u64 *ino, + __u32 *group) { char *p;unsigned long long control; +unsigned long control2 =0 ;int i; -if (optind != argc -1 ) { +if (optind != argc -1 && optind != argc -2 ) {fprintf (stderr,_ ("Must specify metapath number.\n" ));return false; }for (i =0 ; i <XFS_SCRUB_METAPATH_NR ; i++) {if (!strcmp (argv[optind], xfrog_metapaths[i].name)) { - *ino = i; -return true; + control = i; + goto find_group; } }
@@ -161,7 +163,32 @@ parse_metapath(return false; } +find_group: +if (xfrog_metapaths[control].group ==XFROG_SCRUB_GROUP_RTGROUP ) { +if (optind == argc -1 ) { +fprintf (stderr, +_ ("%s: Metapath requires a group number.\n" ), + xfrog_metapaths[*ino].name); +return false; + } + control2 =strtoul (argv[optind +1 ], &p,0 ); +if (*p !='\0' ) { +fprintf (stderr, +_ ("Bad group number '%s'.\n" ), + argv[optind +1 ]); +return false; + } + }else { +if (optind == argc -2 ) { +fprintf (stderr, +_ ("%s: Metapath does not take a second argument.\n" ), + xfrog_metapaths[*ino].name); +return false; + } + } + *ino = control; + *group = control2;return true; }
@@ -237,7 +264,8 @@ parse_args(switch (d->group) {case XFROG_SCRUB_GROUP_METAPATH : -if (!parse_metapath (argc, argv, optind, &meta->sm_ino)) { +if (!parse_metapath (argc, argv, optind, &meta->sm_ino, + &meta->sm_agno)) { exitcode =1 ;return command_usage (cmdinfo); }
@@ -582,7 +610,8 @@ scrubv_f(switch (group) {case XFROG_SCRUB_GROUP_METAPATH : -if (!parse_metapath (argc, argv, optind, &scrubv.head.svh_ino)) { +if (!parse_metapath (argc, argv, optind, &scrubv.head.svh_ino, + &scrubv.head.svh_agno)) { exitcode =1 ;return command_usage (&scrubv_cmd); }
man/man8/xfs_io.8 +2 -1
@@ -1425,7 +1425,7 @@ .SH FILESYSTEM COMMANDS .RE .PD .TP -.BI "scrub " type " [ " agnumber " | " rgnumber " | " "ino" " " "gen" " | " metapath " ]" +.BI "scrub " type " [ " agnumber " | " rgnumber " | " "ino" " " "gen" " | " metapath " [ " rgnumber " ] ]" Scrub internal XFS filesystem metadata. The .BI type parameter specifies which type of metadata to scrub.
@@ -1434,6 +1434,7 @@ .SH FILESYSTEM COMMANDS For file metadata, the scrub is applied to the open file unless the inode number and generation number are specified. For metapath, the name of a file or a raw number must be specified. +If the metapath file is a per-rtgroup file, the group number must be specified. .RE .PD .TP
PATCH 32/43 xfs_io: add a command to display allocation group information
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a new 'aginfo' command to xfs_io so that we can display allocation group geometry.
--- io/Makefile | 1 io/aginfo.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++ io/init.c | 1 io/io.h | 1 man/man8/xfs_io.8 | 12 +++++ 5 files changed, 134 insertions(+) create mode 100644 io/aginfo.c
io/Makefile +1 -0
@@ -9,6 +9,7 @@ LTCOMMAND = xfs_io LSRCFILES = xfs_bmap.sh xfs_freeze.sh xfs_mkfile.sh xfs_property HFILES = init.h io.h CFILES = \ + aginfo.c \ attr.c \ bmap.c \ bulkstat.c \
io/aginfo.c new file +119 -0
119 lines not on this page · raw message
io/init.c +1 -0
@@ -44,6 +44,7 @@ init_cvtnum(static void init_commands (void ) { +aginfo_init ();attr_init ();bmap_init ();bulkstat_init ();
io/io.h +1 -0
@@ -155,3 +155,4 @@ extern void crc32cselftest_init(void);extern void bulkstat_init (void );void exchangerange_init (void );void fsprops_init (void ); +void aginfo_init (void );
man/man8/xfs_io.8 +12 -0
@@ -1242,6 +1242,18 @@ .SH MEMORY MAPPED I/O COMMANDS for the current memory mapping. .SH FILESYSTEM COMMANDS +.TP +.BI "aginfo [ \-a " agno " ]" +Show information about or update the state of allocation groups. +.RE +.RS 1.0i +.PD 0 +.TP +.BI \-a +Act only on a specific allocation group. +.PD +.RE + .TP .BI "bulkstat [ \-a " agno " ] [ \-d ] [ \-e " endino " ] [ \-m ] [ \-n " batchsize " ] [ \-q ] [ \-s " startino " ] [ \-v " version" ] Display raw stat information about a bunch of inodes in an XFS filesystem.
PATCH 33/43 xfs_io: add a command to display realtime group information
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a new 'rginfo' command to xfs_io so that we can display realtime group geometry.
--- io/aginfo.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++ libfrog/fsgeom.c | 18 ++++++++++ libfrog/fsgeom.h | 4 ++ man/man8/xfs_io.8 | 13 +++++++ 4 files changed, 132 insertions(+)
io/aginfo.c +97 -0
@@ -14,6 +14,7 @@#include "libfrog/fsgeom.h" static cmdinfo_t aginfo_cmd; +static cmdinfo_t rginfo_cmd;static int report_aginfo(
@@ -111,9 +112,105 @@ static cmdinfo_t aginfo_cmd = { .help = aginfo_help, }; +static int +report_rginfo ( +struct xfs_fd *xfd, +xfs_rgnumber_t rgno) +{ +struct xfs_rtgroup_geometry rgeo = {0 }; +int ret; + + ret = -xfrog_rtgroup_geometry (xfd->fd, rgno, &rgeo); +if (ret) { +xfrog_perror (ret,"rginfo" ); +return 1 ; + } + +printf (_ ("RG: %u\n" ), rgeo.rg_number); +printf (_ ("Length: %u\n" ), rgeo.rg_length); +printf (_ ("Capacity: %u\n" ), rgeo.rg_capacity); +printf (_ ("Sick: 0x%x\n" ), rgeo.rg_sick); +printf (_ ("Checked: 0x%x\n" ), rgeo.rg_checked); +printf (_ ("Flags: 0x%x\n" ), rgeo.rg_flags); + +return 0 ; +} + +/* Display rtgroup status. */ +static int +rginfo_f ( +int argc, +char **argv) +{ +struct xfs_fd xfd =XFS_FD_INIT (file->fd); +unsigned long long x; +xfs_rgnumber_t rgno =NULLRGNUMBER ; +int c; +int ret =0 ; + + ret = -xfd_prepare_geometry (&xfd); +if (ret) { +xfrog_perror (ret,"xfd_prepare_geometry" ); + exitcode =1 ; +return 1 ; + } + +while ((c =getopt (argc, argv,"r:" )) !=EOF ) { +switch (c) { +case 'r' : + errno =0 ; + x =strtoll (optarg,NULL ,10 ); +if (!errno && x >=NULLRGNUMBER ) + errno =ERANGE ; +if (errno) { +perror ("rginfo" ); +return 1 ; + } + rgno = x; +break ; +default : +return command_usage (&rginfo_cmd); + } + } + +if (rgno !=NULLRGNUMBER ) { + ret =report_rginfo (&xfd, rgno); + }else { +for (rgno =0 ; !ret && rgno < xfd.fsgeom.rgcount; rgno++) { + ret =report_rginfo (&xfd, rgno); + } + } + +return ret; +} + +static void +rginfo_help (void ) +{ +printf (_ ( +"\n" +"Report realtime group geometry.\n" +"\n" +" -r rgno -- Report on the given realtime group.\n" +"\n" )); + +} + +static cmdinfo_t rginfo_cmd = { + .name ="rginfo" , + .cfunc = rginfo_f, + .argmin =0 , + .argmax =-1 , + .args ="[-r rgno]" , + .flags =CMD_NOMAP_OK , + .help = rginfo_help, +}; +void aginfo_init (void ) { aginfo_cmd.oneline =_ ("Get XFS allocation group state." );add_command (&aginfo_cmd); + rginfo_cmd.oneline =_ ("Get XFS realtime group state." ); +add_command (&rginfo_cmd); }
libfrog/fsgeom.c +18 -0
@@ -214,3 +214,21 @@ xfrog_ag_geometry(return -errno;return 0 ; } + +/* +* Try to obtain a rt group's geometry. Returns zero or a negative error code. +*/ +int +xfrog_rtgroup_geometry ( +int fd, +unsigned int rgno, +struct xfs_rtgroup_geometry *rgeo) +{ +int ret; + + rgeo->rg_number = rgno; + ret =ioctl (fd,XFS_IOC_RTGROUP_GEOMETRY , rgeo); +if (ret) +return -errno; +return 0 ; +}
libfrog/fsgeom.h +4 -0
@@ -5,10 +5,14 @@#ifndef __LIBFROG_FSGEOM_H__#define __LIBFROG_FSGEOM_H__ +struct xfs_rtgroup_geometry ; +void xfs_report_geom (struct xfs_fsop_geom *geo,const char *mntpoint,const char *logname,const char *rtname);int xfrog_geometry (int fd,struct xfs_fsop_geom *fsgeo);int xfrog_ag_geometry (int fd,unsigned int agno,struct xfs_ag_geometry *ageo); +int xfrog_rtgroup_geometry (int fd,unsigned int rgno, +struct xfs_rtgroup_geometry *rgeo);/* * Structure for recording whatever observations we want about the level of
man/man8/xfs_io.8 +13 -0
@@ -1328,6 +1328,19 @@ .SH FILESYSTEM COMMANDS .I tag argument, displays the list of error tags available. Only available in expert mode and requires privileges. + +.TP +.BI "rginfo [ \-r " rgno " ]" +Show information about or update the state of realtime allocation groups. +.RE +.RS 1.0i +.PD 0 +.TP +.BI \-r +Act only on a specific realtime group. +.PD +.RE + .TP .BI "resblks [ " blocks " ]" Get and/or set count of reserved filesystem blocks using the
PATCH 34/43 xfs_io: display rt group in verbose bmap output
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Display the rt group number in the bmap -v output, just like we do for regular data files.
--- io/bmap.c | 27 ++++++++++++++++++--------- libfrog/fsgeom.h | 12 ++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-)
io/bmap.c +18 -9
@@ -257,16 +257,18 @@ bmap_f(#define FLG_BSW 0000010/* Not on begin of stripe width */ #define FLG_ESW 0000001/* Not on end of stripe width */ int agno; -off_t agoff, bbperag; +off_t agoff, bbperag;int foff_w, boff_w, aoff_w, tot_w, agno_w;char rbuf[32 ], bbuf[32 ], abuf[32 ];int sunit, swidth; foff_w = boff_w = aoff_w =MINRANGE_WIDTH ; tot_w =MINTOT_WIDTH ; -if (is_rt) - sunit = swidth = bbperag =0 ; -else { +if (is_rt) { + bbperag =bytes_per_rtgroup (&fsgeo) /BBSIZE ; + sunit =0 ; + swidth =0 ; + }else { bbperag = (off_t )fsgeo.agblocks * (off_t )fsgeo.blocksize /BBSIZE ; sunit = (fsgeo.sunit * fsgeo.blocksize) /BBSIZE ;
@@ -295,7 +297,7 @@ bmap_f( (long long )(map[i +1 ].bmv_block + map[i + 1].bmv_length - 1LL)); boff_w =max (boff_w,strlen (bbuf)); -if (!is_rt) { +if (bbperag >0 ) { agno = map[i +1 ].bmv_block / bbperag; agoff = map[i +1 ].bmv_block - (agno * bbperag);
@@ -312,13 +314,20 @@ bmap_f( numlen(map[i+1].bmv_length, 10)); } } - agno_w = is_rt ?0 :max (MINAG_WIDTH ,numlen (fsgeo.agcount,10 )); +if (is_rt) { +if (fsgeo.rgcount >0 ) + agno_w =max (MINAG_WIDTH ,numlen (fsgeo.rgcount,10 )); +else + agno_w =0 ; + }else { + agno_w =max (MINAG_WIDTH ,numlen (fsgeo.agcount,10 )); + }printf ("%4s: %-*s %-*s %*s %-*s %*s%s\n" ,_ ("EXT" ), foff_w,_ ("FILE-OFFSET" ), boff_w, is_rt ?_ ("RT-BLOCK-RANGE" ) :_ ("BLOCK-RANGE" ), - agno_w, is_rt ?"" :_ ("AG" ), - aoff_w, is_rt ?"" :_ ("AG-OFFSET" ), + agno_w, is_rt ? (fsgeo.rgcount ?_ ("RG" ) :"" ) :_ ("AG" ), + aoff_w, is_rt ? (fsgeo.rgcount ?_ ("RG-OFFSET" ) :"" ) :_ ("AG-OFFSET" ), tot_w,_ ("TOTAL" ), flg ?_ (" FLAGS" ) :"" );for (i =0 ; i < egcnt; i++) {
@@ -377,7 +386,7 @@ bmap_f( map[i + 1].bmv_length - 1LL));printf ("%4d: %-*s %-*s" , i, foff_w, rbuf, boff_w, bbuf); -if (!is_rt) { +if (bbperag >0 ) { agno = map[i +1 ].bmv_block / bbperag; agoff = map[i +1 ].bmv_block - (agno * bbperag);
libfrog/fsgeom.h +12 -0
@@ -205,4 +205,16 @@ cvt_b_to_agbno( return cvt_daddr_to_agbno(xfd, cvt_btobbt(byteno)); } +/* Return the number of bytes in an rtgroup. */ +static inline uint64_t +bytes_per_rtgroup ( +const struct xfs_fsop_geom *fsgeo) +{ +if (!fsgeo->rgcount) +return 0 ; + +return (uint64_t )fsgeo->rgextents * fsgeo->rtextsize * + fsgeo->blocksize; +} +#endif /* __LIBFROG_FSGEOM_H__ */
PATCH 35/43 xfs_io: display rt group in verbose fsmap output
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Display the rt group number in the fsmap output, just like we do for regular data files.
--- io/fsmap.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
io/fsmap.c +21 -1
@@ -14,6 +14,7 @@static cmdinfo_t fsmap_cmd;static dev_t xfs_data_dev; +static dev_t xfs_rt_dev;static void fsmap_help (void )
@@ -170,7 +171,7 @@ dump_map_verbose(unsigned long long i;struct fsmap *p;int agno; -off_t agoff, bperag; +off_t agoff, bperag, bperrtg;int foff_w, boff_w, aoff_w, tot_w, agno_w, own_w;int nr_w, dev_w;char rbuf[40 ], bbuf[40 ], abuf[40 ], obuf[40 ];
@@ -185,6 +186,7 @@ dump_map_verbose( tot_w =MINTOT_WIDTH ; bperag = (off_t )fsgeo->agblocks * (off_t )fsgeo->blocksize; + bperrtg =bytes_per_rtgroup (fsgeo); sunit = (fsgeo->sunit * fsgeo->blocksize); swidth = (fsgeo->swidth * fsgeo->blocksize);
@@ -243,6 +245,13 @@ dump_map_verbose("(%lld..%lld)" , (long long )BTOBBT (agoff), (long long)BTOBBT(agoff + p->fmr_length - 1)); + }else if (p->fmr_device == xfs_rt_dev && fsgeo->rgcount >0 ) { + agno = p->fmr_physical / bperrtg; + agoff = p->fmr_physical - (agno * bperrtg); +snprintf (abuf,sizeof (abuf), +"(%lld..%lld)" , + (long long )BTOBBT (agoff), + (long long )BTOBBT (agoff + p->fmr_length -1 )); }else abuf[0 ] =0 ; aoff_w =max (aoff_w,strlen (abuf));
@@ -315,6 +324,16 @@ dump_map_verbose(snprintf (gbuf,sizeof (gbuf),"%lld" , (long long )agno); + }else if (p->fmr_device == xfs_rt_dev && fsgeo->rgcount >0 ) { + agno = p->fmr_physical / bperrtg; + agoff = p->fmr_physical - (agno * bperrtg); +snprintf (abuf,sizeof (abuf), +"(%lld..%lld)" , + (long long )BTOBBT (agoff), + (long long )BTOBBT (agoff + p->fmr_length -1 )); +snprintf (gbuf,sizeof (gbuf), +"%lld" , + (long long )agno); }else { abuf[0 ] =0 ; gbuf[0 ] =0 ;
@@ -501,6 +520,7 @@ fsmap_f( } fs =fs_table_lookup (file->name,FS_MOUNT_POINT ); xfs_data_dev = fs ? fs->fs_datadev :0 ; + xfs_rt_dev = fs ? fs->fs_rtdev :0 ; head->fmh_count = map_size; do {
PATCH 36/43 xfs_spaceman: report on realtime group health
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add the realtime group status to the health reporting done by xfs_spaceman.
--- man/man8/xfs_spaceman.8 | 5 +++- spaceman/health.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-)
man/man8/xfs_spaceman.8 +4 -1
@@ -91,7 +91,7 @@ .SH COMMANDS .BR "xfs_info" "(8)" prints when querying a filesystem. .TP -.BI "health [ \-a agno] [ \-c ] [ \-f ] [ \-i inum ] [ \-n ] [ \-q ] [ paths ]" +.BI "health [ \-a agno] [ \-c ] [ \-f ] [ \-i inum ] [ \-n ] [ \-q ] [ \-r rgno ] [ paths ]" Reports the health of the given group of filesystem metadata. .RS 1.0i .PD 0
@@ -119,6 +119,9 @@ .SH COMMANDS .B \-q Report only unhealthy metadata. .TP +.B \-r +Report on the health of the given realtime group. +.TP .B paths Report on the health of the files at the given path. .PD
spaceman/health.c +61 -2
117 lines not on this page · raw message
PATCH 37/43 xfs_scrub: scrub realtime allocation group metadata
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Scan realtime group metadata as part of phase 2, just like we do for AG metadata. For pre-rtgroup filesystems, pretend that this is a "rtgroup 0" scrub request because the kernel expects that. Replace the old cond_wait code with a scrub barrier because they're equivalent for two items that cannot be scrubbed in parallel.
--- libfrog/scrub.c | 4 +- scrub/phase2.c | 124 ++++++++++++++++++++++++++++++++++++++----------------- scrub/scrub.c | 1 scrub/scrub.h | 9 ++++ 4 files changed, 98 insertions(+), 40 deletions(-)
libfrog/scrub.c +2 -2
@@ -107,12 +107,12 @@ const struct xfrog_scrub_descr xfrog_scrubbers[XFS_SCRUB_TYPE_NR] = { [XFS_SCRUB_TYPE_RTBITMAP] = { .name = "rtbitmap", .descr = "realtime bitmap", - .group = XFROG_SCRUB_GROUP_FS, + .group = XFROG_SCRUB_GROUP_RTGROUP, }, [XFS_SCRUB_TYPE_RTSUM] = { .name = "rtsummary", .descr = "realtime summary", - .group = XFROG_SCRUB_GROUP_FS, + .group = XFROG_SCRUB_GROUP_RTGROUP, }, [XFS_SCRUB_TYPE_UQUOTA] = { .name = "usrquota",
scrub/phase2.c +86 -38
192 lines not on this page · raw message
scrub/scrub.c +1 -0
@@ -50,6 +50,7 @@ static const unsigned int scrub_deps[XFS_SCRUB_TYPE_NR] = { [XFS_SCRUB_TYPE_QUOTACHECK ] =DEP (XFS_SCRUB_TYPE_UQUOTA ) |DEP (XFS_SCRUB_TYPE_GQUOTA ) | DEP(XFS_SCRUB_TYPE_PQUOTA), + [XFS_SCRUB_TYPE_RTSUM] = DEP(XFS_SCRUB_TYPE_RTBITMAP), };#undef DEP
scrub/scrub.h +9 -0
@@ -90,6 +90,15 @@ scrub_item_init_ag(struct scrub_item *sri, xfs_agnumber_t agno) sri->sri_gen =-1U ; } +static inline void +scrub_item_init_rtgroup (struct scrub_item *sri,xfs_rgnumber_t rgno) +{ +memset (sri,0 ,sizeof (*sri)); + sri->sri_agno = rgno; + sri->sri_ino =-1ULL ; + sri->sri_gen =-1U ; +} +static inline void scrub_item_init_fs (struct scrub_item *sri) {
PATCH 38/43 xfs_scrub: check rtgroup metadata directory connections
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Run the rtgroup metapath scrubber during phase 5 to ensure that any rtgroup metadata files are still connected to the metadir tree after we've pruned any bad links.
--- scrub/phase5.c | 24 ++++++++++++++++++++++-- scrub/scrub.h | 4 +++- 2 files changed, 25 insertions(+), 3 deletions(-)
scrub/phase5.c +22 -2
@@ -750,6 +750,7 @@ static intqueue_metapath_scan ( struct workqueue *wq, bool *abortedp, + xfs_rgnumber_t rgno, uint64_t type) { struct fs_scan_item *item;
@@ -762,7 +763,7 @@ queue_metapath_scan(str_liberror (ctx, ret,_ ("setting up metapath scan" ));return ret; } -scrub_item_init_metapath (&item->sri, type); +scrub_item_init_metapath (&item->sri, rgno, type);scrub_item_schedule (&item->sri,XFS_SCRUB_TYPE_METAPATH ); item->abortedp = abortedp;
@@ -785,6 +786,7 @@ run_kernel_metadir_path_scrubbers(const struct xfrog_scrub_descr *sc;uint64_t type;unsigned int nr_threads =scrub_nproc_workqueue (ctx); +xfs_rgnumber_t rgno;bool aborted = false;int ret, ret2;
@@ -804,7 +806,7 @@ run_kernel_metadir_path_scrubbers(if (sc->group !=XFROG_SCRUB_GROUP_FS )continue ; - ret =queue_metapath_scan (&wq, &aborted, type); + ret =queue_metapath_scan (&wq, &aborted,0 , type);if (ret) {str_liberror (ctx, ret,_ ("queueing metapath scrub work" ));
@@ -812,6 +814,24 @@ run_kernel_metadir_path_scrubbers( } } +/* Scan all rtgroup metadata files */ +for (rgno =0 ; + rgno < ctx->mnt.fsgeom.rgcount && !aborted; + rgno++) { +for (type =0 ; type <XFS_SCRUB_METAPATH_NR ; type++) { + sc = &xfrog_metapaths[type]; +if (sc->group !=XFROG_SCRUB_GROUP_RTGROUP ) +continue ; + + ret =queue_metapath_scan (&wq, &aborted, rgno, type); +if (ret) { +str_liberror (ctx, ret, +_ ("queueing metapath scrub work" )); + goto wait; + } + } + } + wait: ret2 = -workqueue_terminate (&wq);if (ret2) {
scrub/scrub.h +3 -1
@@ -118,9 +118,11 @@ scrub_item_init_file(struct scrub_item *sri, const struct xfs_bulkstat *bstat) }static inline void -scrub_item_init_metapath (struct scrub_item *sri,uint64_t metapath) +scrub_item_init_metapath (struct scrub_item *sri,xfs_rgnumber_t rgno, +uint64_t metapath) {memset (sri,0 ,sizeof (*sri)); + sri->sri_agno = rgno; sri->sri_ino = metapath; }
PATCH 39/43 xfs_scrub: call GETFSMAP for each rt group in parallel
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If realtime groups are enabled, we should take advantage of the sharding to speed up the spacemap scans. Do so by issuing per-rtgroup GETFSMAP calls.
--- scrub/spacemap.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 8 deletions(-)
scrub/spacemap.c +64 -8
@@ -128,6 +128,45 @@ scan_ag_rmaps( } } +/* Iterate all the reverse mappings of a realtime group. */ +static void +scan_rtg_rmaps ( +struct workqueue *wq, +xfs_agnumber_t rgno, +void *arg) +{ +struct scrub_ctx *ctx = (struct scrub_ctx *)wq->wq_ctx; +struct scan_blocks *sbx = arg; +struct fsmap keys[2 ]; +off_t bperrg =bytes_per_rtgroup (&ctx->mnt.fsgeom); +int ret; + + +memset (keys,0 ,sizeof (struct fsmap ) *2 ); + keys->fmr_device = ctx->fsinfo.fs_rtdev; + keys->fmr_physical = (xfs_rtblock_t )rgno * bperrg; + (keys +1 )->fmr_device = ctx->fsinfo.fs_rtdev; + (keys +1 )->fmr_physical = ((rgno +1 ) * bperrg) -1 ; + (keys +1 )->fmr_owner =ULLONG_MAX ; + (keys +1 )->fmr_offset =ULLONG_MAX ; + (keys +1 )->fmr_flags =UINT_MAX ; + +if (sbx->aborted) +return ; + + ret =scrub_iterate_fsmap (ctx, keys, sbx->fn, sbx->arg); +if (ret) { +char descr[DESCR_BUFSZ ]; + +snprintf (descr,DESCR_BUFSZ ,_ ("dev %d:%d rtgroup %u fsmap" ), +major (ctx->fsinfo.fs_datadev), +minor (ctx->fsinfo.fs_datadev), + rgno); +str_liberror (ctx, ret, descr); + sbx->aborted = true; + } +} +/* Iterate all the reverse mappings of a standalone device. */ static void scan_dev_rmaps(
@@ -208,14 +247,6 @@ scrub_scan_all_spacemaps(str_liberror (ctx, ret,_ ("creating fsmap workqueue" ));return ret; } -if (ctx->fsinfo.fs_rt) { - ret = -workqueue_add (&wq, scan_rt_rmaps,0 , &sbx); -if (ret) { - sbx.aborted = true; -str_liberror (ctx, ret,_ ("queueing rtdev fsmap work" )); - goto out; - } - }if (ctx->fsinfo.fs_log) { ret = -workqueue_add (&wq, scan_log_rmaps,0 , &sbx);if (ret) {
@@ -232,6 +263,31 @@ scrub_scan_all_spacemaps(break ; } } +if (ctx->fsinfo.fs_rt) { +for (agno =0 ; agno < ctx->mnt.fsgeom.rgcount; agno++) { + ret = -workqueue_add (&wq, scan_rtg_rmaps, agno, &sbx); +if (ret) { + sbx.aborted = true; +str_liberror (ctx, ret, +_ ("queueing rtgroup fsmap work" )); +break ; + } + } + +/* +* If the fs doesn't have any realtime groups, scan the entire +* volume all at once, since the above loop did nothing. +*/ +if (ctx->mnt.fsgeom.rgcount ==0 ) { + ret = -workqueue_add (&wq, scan_rt_rmaps,0 , &sbx); +if (ret) { + sbx.aborted = true; +str_liberror (ctx, ret, +_ ("queueing rtdev fsmap work" )); + goto out; + } + } + } out: ret = -workqueue_terminate (&wq);if (ret) {
PATCH 40/43 xfs_scrub: trim realtime volumes too
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
On the kernel side, the XFS realtime groups patchset added support for FITRIM of the realtime volume. This support doesn't actually require there to be any realtime groups, so teach scrub to run through the whole region.
--- scrub/phase8.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-)
scrub/phase8.c +29 -3
@@ -59,7 +59,8 @@ fstrim_fsblocks(struct scrub_ctx *ctx, uint64_t start_fsb, uint64_t fsbcount, - uint64_t minlen_fsb) + uint64_t minlen_fsb, + bool ignore_einval) { uint64_t start = cvt_off_fsb_to_b(&ctx->mnt, start_fsb);uint64_t len =cvt_off_fsb_to_b (&ctx->mnt, fsbcount);
@@ -72,6 +73,8 @@ fstrim_fsblocks( run =min (len,FSTRIM_MAX_BYTES ); error =fstrim (ctx, start, run, minlen); +if (error ==EINVAL && ignore_einval) + error =EOPNOTSUPP ;if (error ==EOPNOTSUPP ) {/* Pretend we finished all the work. */ progress_add (len);
@@ -193,7 +196,8 @@ fstrim_datadev(*/ progress_add (geo->blocksize); fsbcount =min (geo->datablocks - fsbno, geo->agblocks); - error =fstrim_fsblocks (ctx, fsbno, fsbcount, minlen_fsb); + error =fstrim_fsblocks (ctx, fsbno, fsbcount, minlen_fsb, + false);if (error)return error; }
@@ -201,15 +205,35 @@ fstrim_datadev(return 0 ; } +/* Trim the realtime device. */ +static int +fstrim_rtdev ( +struct scrub_ctx *ctx) +{ +struct xfs_fsop_geom *geo = &ctx->mnt.fsgeom; + +/* +* The fstrim ioctl pretends that the realtime volume is in the address +* space immediately after the data volume. Ignore EINVAL if someone +* tries to run us on an older kernel. +*/ +return fstrim_fsblocks (ctx, geo->datablocks, geo->rtblocks,0 , true); +} +/* Trim the filesystem, if desired. */ int phase8_func (struct scrub_ctx *ctx) { +int error; +if (!fstrim_ok (ctx))return 0 ; -return fstrim_datadev (ctx); + error =fstrim_datadev (ctx); +if (error) +return error; +return fstrim_rtdev (ctx); }/* Estimate how much work we're going to do. */
@@ -223,6 +247,8 @@ phase8_estimate(if (fstrim_ok (ctx)) { *items =cvt_off_fsb_to_b (&ctx->mnt, ctx->mnt.fsgeom.datablocks); + *items +=cvt_off_fsb_to_b (&ctx->mnt, + ctx->mnt.fsgeom.rtblocks); }else { *items =0 ; }
PATCH 41/43 xfs_scrub: use histograms to speed up phase 8 on the realtime volume
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Use the same statistical methods that we use on the data volume to compute the minimum threshold size for fstrims on the realtime volume.
--- scrub/phase7.c | 7 +++++++ scrub/phase8.c | 6 +++++- scrub/xfs_scrub.c | 2 ++ scrub/xfs_scrub.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-)
scrub/phase7.c +7 -0
@@ -31,6 +31,7 @@ struct summary_counts {/* Free space histogram, in fsb */ struct histogram datadev_hist; +struct histogram rtdev_hist; };/*
@@ -56,6 +57,7 @@ summary_count_init(struct summary_counts *counts = data;init_freesp_hist (&counts->datadev_hist); +init_freesp_hist (&counts->rtdev_hist); }/* Record block usage. */
@@ -83,6 +85,8 @@ count_block_summary( blocks =cvt_b_to_off_fsbt (&ctx->mnt, fsmap->fmr_length);if (fsmap->fmr_device == ctx->fsinfo.fs_datadev)hist_add (&counts->datadev_hist, blocks); +else if (fsmap->fmr_device == ctx->fsinfo.fs_rtdev) +hist_add (&counts->rtdev_hist, blocks);return 0 ; }
@@ -124,7 +128,9 @@ add_summaries( total->agbytes += item->agbytes;hist_import (&total->datadev_hist, &item->datadev_hist); +hist_import (&total->rtdev_hist, &item->rtdev_hist);hist_free (&item->datadev_hist); +hist_free (&item->rtdev_hist);return 0 ; }
@@ -195,6 +201,7 @@ phase7_func(/* Preserve free space histograms for phase 8. */ hist_move (&ctx->datadev_hist, &totalcount.datadev_hist); +hist_move (&ctx->rtdev_hist, &totalcount.rtdev_hist);/* Scan the whole fs. */ error =scrub_count_all_inodes (ctx, &counted_inodes);
scrub/phase8.c +5 -1
@@ -211,13 +211,17 @@ fstrim_rtdev( struct scrub_ctx *ctx) {struct xfs_fsop_geom *geo = &ctx->mnt.fsgeom; +uint64_t minlen_fsb; + + minlen_fsb =fstrim_compute_minlen (ctx, &ctx->rtdev_hist);/* * The fstrim ioctl pretends that the realtime volume is in the address * space immediately after the data volume. Ignore EINVAL if someone * tries to run us on an older kernel. */ -return fstrim_fsblocks (ctx, geo->datablocks, geo->rtblocks,0 , true); +return fstrim_fsblocks (ctx, geo->datablocks, geo->rtblocks, + minlen_fsb, true); }/* Trim the filesystem, if desired. */
scrub/xfs_scrub.c +2 -0
@@ -728,6 +728,7 @@ main(int error;hist_init (&ctx.datadev_hist); +hist_init (&ctx.rtdev_hist);fprintf (stdout,"EXPERIMENTAL xfs_scrub program in use! Use at your own risk!\n" );fflush (stdout);
@@ -960,6 +961,7 @@ main(unicrash_unload ();hist_free (&ctx.datadev_hist); +hist_free (&ctx.rtdev_hist);/* * If we're being run as a service, the return code must fit the LSB
scrub/xfs_scrub.h +1 -0
@@ -101,6 +101,7 @@ struct scrub_ctx {/* Free space histograms, in fsb */ struct histogram datadev_hist; +struct histogram rtdev_hist;/* * Pick the largest value for fstrim minlen such that we trim at least
PATCH 42/43 mkfs: add headers to realtime bitmap blocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When the rtgroups feature is enabled, format rtbitmap blocks with the appropriate block headers. libxfs takes care of the actual writing for us, so all we have to do is ensure that the bitmap is the correct size.
--- mkfs/xfs_mkfs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mkfs/xfs_mkfs.c +4 -1
@@ -3210,6 +3210,7 @@ validate_rtdev( struct cli_params *cli) {struct libxfs_init *xi = cli->xi; +unsigned int rbmblocksize = cfg->blocksize;if (!xi->rt.dev) {if (cli->rtsize) {
@@ -3253,8 +3254,10 @@ reported by the device (%u).\n"), _("cannot have an rt subvolume with zero extents\n"));usage (); } +if (cfg->sb_feat.metadir) + rbmblocksize -=sizeof (struct xfs_rtbuf_blkinfo ); cfg->rtbmblocks = (xfs_extlen_t )howmany (cfg->rtextents, -NBBY * cfg->blocksize); +NBBY * rbmblocksize); } static bool
PATCH 43/43 mkfs: format realtime groups
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create filesystems with the realtime group feature enabled.
--- libfrog/div64.h | 6 + libfrog/util.c | 12 ++ libfrog/util.h | 1 libxfs/libxfs_api_defs.h | 2 libxfs/libxfs_priv.h | 6 - libxfs/topology.c | 42 +++++++ libxfs/topology.h | 3 man/man8/mkfs.xfs.8.in | 31 +++++ mkfs/proto.c | 88 ++++++++++++-- mkfs/xfs_mkfs.c | 287 +++++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 449 insertions(+), 29 deletions(-)
libfrog/div64.h +6 -0
@@ -93,4 +93,10 @@ howmany_64(uint64_t x, uint32_t y) return x; } +static inline __attribute__((const)) +int is_power_of_2 (unsigned long n) +{ +return (n !=0 && ((n & (n -1 )) ==0 )); +} +#endif /* LIBFROG_DIV64_H_ */
libfrog/util.c +12 -0
@@ -36,3 +36,15 @@ memchr_inv(const void *start, int c, size_t bytes)return NULL ; } + +unsigned int +log2_rounddown (unsigned long long i) +{ +int rval; + +for (rval =NBBY *sizeof (i) -1 ; rval >=0 ; rval--) { +if ((1ULL << rval) < i) +break ; + } +return rval; +}
libfrog/util.h +1 -0
@@ -9,6 +9,7 @@#include <sys/types.h> unsigned int log2_roundup (unsigned int i); +unsigned int log2_rounddown (unsigned long long i);#define min_t (type,x,y) \ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
libxfs/libxfs_api_defs.h +2 -0
@@ -94,6 +94,7 @@#define xfs_btree_stage_afakeroot libxfs_btree_stage_afakeroot#define xfs_btree_stage_ifakeroot libxfs_btree_stage_ifakeroot#define xfs_btree_visit_blocks libxfs_btree_visit_blocks +#define xfs_buf_delwri_queue libxfs_buf_delwri_queue#define xfs_buf_delwri_submit libxfs_buf_delwri_submit#define xfs_buf_get libxfs_buf_get#define xfs_buf_get_uncached libxfs_buf_get_uncached
@@ -303,6 +304,7 @@#define xfs_rtfree_blocks libxfs_rtfree_blocks#define xfs_update_rtsb libxfs_update_rtsb#define xfs_sb_from_disk libxfs_sb_from_disk +#define xfs_sb_mount_rextsize libxfs_sb_mount_rextsize#define xfs_sb_quota_from_disk libxfs_sb_quota_from_disk#define xfs_sb_read_secondary libxfs_sb_read_secondary#define xfs_sb_to_disk libxfs_sb_to_disk
libxfs/libxfs_priv.h +0 -6
@@ -306,12 +306,6 @@ find_next_zero_bit(const unsigned long *addr, unsigned long size, }#define find_first_zero_bit (addr, size) find_next_zero_bit((addr), (size), 0) -static inline __attribute__((const)) -int is_power_of_2 (unsigned long n) -{ -return (n !=0 && ((n & (n -1 )) ==0 )); -} -/* * xfs_iroundup: round up argument to next power of two */
libxfs/topology.c +42 -0
48 lines not on this page · raw message
libxfs/topology.h +3 -0
@@ -37,6 +37,9 @@ calc_default_ag_geometry(uint64_t *agsize, uint64_t *agcount); +void calc_default_rtgroup_geometry (int blocklog,uint64_t rblocks, +uint64_t *rgsize,uint64_t *rgcount); +extern int check_overwrite (const char *device);
man/man8/mkfs.xfs.8.in +31 -0
@@ -1129,6 +1129,37 @@ .SH OPTIONS .BI noalign This option disables stripe size detection, enforcing a realtime device with no stripe geometry. +.TP +.BI rgcount= +This is used to specify the number of allocation groups in the realtime +section. +The realtime section of the filesystem can be divided into allocation groups to +improve the performance of XFS. +More allocation groups imply that more parallelism can be achieved when +allocating blocks. +The minimum allocation group size is 2 realtime extents; the maximum size is +2^31 blocks. +The rt section of the filesystem is divided into +.I value +allocation groups (default value is scaled automatically based +on the underlying device size). +.TP +.BI rgsize= value +This is an alternative to using the +.B rgcount +suboption. The +.I value +is the desired size of the realtime allocation group expressed in bytes +(usually using the +.BR m " or " g +suffixes). +This value must be a multiple of the realtime extent size, +must be at least two realtime extents, and no more than 2^31 blocks. +The +.B rgcount +and +.B rgsize +suboptions are mutually exclusive. .RE .PP .PD 0
mkfs/proto.c +72 -16
131 lines not on this page · raw message
mkfs/xfs_mkfs.c +280 -7
397 lines not on this page · raw message
PATCH 4/5 xfsprogs: store quota files in the metadir
In reply to Darrick J. WongHi all,
Store the quota files in the metadata directory tree instead of the superblock. Since we're introducing a new incompat feature flag, let's also make the mount process bring up quotas in whatever state they were when the filesystem was last unmounted, instead of requiring sysadmins to remember that themselves.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
This has been running on the djcloud for months with no problems. Enjoy! Comments and questions are, as always, welcome.
--D
kernel git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfs-linux.git/log/?h=metadir-quotas
xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=metadir-quotas
fstests git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfstests-dev.git/log/?h=metadir-quotas
---
Commits in this patchset:
* libfrog: scrub quota file metapaths
* xfs_db: support metadir quotas
* xfs_repair: refactor quota inumber handling
* xfs_repair: hoist the secondary sb qflags handling
* xfs_repair: support quota inodes in the metadata directory
* xfs_repair: try not to trash qflags on metadir filesystems
* mkfs: add quota flags when setting up filesystem
--- db/dquot.c | 59 +++++++++++++---- include/xfs_mount.h | 1 libfrog/scrub.c | 20 ++++++ libxfs/init.c | 2 - libxfs/libxfs_api_defs.h | 6 ++ man/man8/mkfs.xfs.8.in | 48 ++++++++++++++ mkfs/xfs_mkfs.c | 113 ++++++++++++++++++++++++++++++++ repair/agheader.c | 161 +++++++++++++++++++++++++--------------------- repair/dinode.c | 18 +++-- repair/dir2.c | 12 ++- repair/globals.c | 111 ++++++++++++++++++++++++++++++-- repair/globals.h | 15 +++- repair/phase2.c | 3 + repair/phase4.c | 116 +++++++++++++++++---------------- repair/phase6.c | 128 +++++++++++++++++++++++++++++++++++-- repair/quotacheck.c | 118 ++++++++++++++++++++++++++++++---- repair/quotacheck.h | 3 + repair/sb.c | 3 + repair/versions.c | 9 +-- repair/xfs_repair.c | 13 +++- 20 files changed, 753 insertions(+), 206 deletions(-)
PATCH 1/7 libfrog: scrub quota file metapaths
From: Darrick J. Wong <[email protected]>
Support scrubbing quota file metadir paths.
--- libfrog/scrub.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
libfrog/scrub.c +20 -0
@@ -187,6 +187,26 @@ const struct xfrog_scrub_descr xfrog_metapaths[XFS_SCRUB_METAPATH_NR] = { .descr = "rtgroup summary", .group = XFROG_SCRUB_GROUP_RTGROUP, }, + [XFS_SCRUB_METAPATH_QUOTADIR] = { + .name = "quotadir", + .descr = "quota file metadir", + .group = XFROG_SCRUB_GROUP_FS, + }, + [XFS_SCRUB_METAPATH_USRQUOTA] = { + .name = "usrquota", + .descr = "user quota file", + .group = XFROG_SCRUB_GROUP_FS, + }, + [XFS_SCRUB_METAPATH_GRPQUOTA] = { + .name = "grpquota", + .descr = "group quota file", + .group = XFROG_SCRUB_GROUP_FS, + }, + [XFS_SCRUB_METAPATH_PRJQUOTA] = { + .name = "prjquota", + .descr = "project quota file", + .group = XFROG_SCRUB_GROUP_FS, + }, };/* Invoke the scrub ioctl. Returns zero or negative error code. */
PATCH 2/7 xfs_db: support metadir quotas
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Support finding the quota files in the metadata directory.
--- db/dquot.c | 59 ++++++++++++++++++++++++++++++++++------------ libxfs/libxfs_api_defs.h | 6 +++++ 2 files changed, 50 insertions(+), 15 deletions(-)
db/dquot.c +44 -15
@@ -81,6 +81,41 @@ dquot_help(void) { } +static xfs_ino_t +dqtype_to_inode ( +struct xfs_mount *mp, +xfs_dqtype_t type) +{ +struct xfs_trans *tp; +struct xfs_inode *dp =NULL ; +struct xfs_inode *ip; +xfs_ino_t ret =NULLFSINO ; +int error; + + error = -libxfs_trans_alloc_empty (mp, &tp); +if (error) +return NULLFSINO ; + +if (xfs_has_metadir (mp)) { + error = -libxfs_dqinode_load_parent (tp, &dp); +if (error) + goto out_cancel; + } + + error = -libxfs_dqinode_load (tp, dp, type, &ip); +if (error) + goto out_dp; + + ret = ip->i_ino; +libxfs_irele (ip); +out_dp: +if (dp) +libxfs_irele (dp); +out_cancel: +libxfs_trans_cancel (tp); +return ret; +} + static int dquot_f( int argc,
@@ -88,8 +123,7 @@ dquot_f( {bmap_ext_t bm;int c; -int dogrp; -int doprj; +xfs_dqtype_t type =XFS_DQTYPE_USER ;xfs_dqid_t id;xfs_ino_t ino;xfs_extnum_t nex;
@@ -97,38 +131,33 @@ dquot_f(int perblock;xfs_fileoff_t qbno;int qoff; -char *s; +const char *s; - dogrp = doprj = optind =0 ; + optind =0 ;while ((c =getopt (argc, argv,"gpu" )) !=EOF ) {switch (c) {case 'g' : - dogrp =1 ; - doprj =0 ; + type =XFS_DQTYPE_GROUP ;break ;case 'p' : - doprj =1 ; - dogrp =0 ; + type =XFS_DQTYPE_PROJ ;break ;case 'u' : - dogrp = doprj =0 ; + type =XFS_DQTYPE_USER ;break ;default :dbprintf (_ ("bad option for dquot command\n" ));return 0 ; } } - s = doprj ?_ ("project" ) : dogrp ?_ ("group" ) :_ ("user" ); + + s =libxfs_dqinode_path (type);if (optind != argc -1 ) {dbprintf (_ ("dquot command requires one %s id argument\n" ), s);return 0 ; } - ino = mp->m_sb.sb_uquotino; -if (doprj) - ino = mp->m_sb.sb_pquotino; -else if (dogrp) - ino = mp->m_sb.sb_gquotino; + ino =dqtype_to_inode (mp, type);if (ino ==0 || ino ==NULLFSINO ) {dbprintf (_ ("no %s quota inode present\n" ), s);return 0 ;
libxfs/libxfs_api_defs.h +6 -0
@@ -159,6 +159,12 @@#define xfs_dir_replace libxfs_dir_replace#define xfs_dqblk_repair libxfs_dqblk_repair +#define xfs_dqinode_load libxfs_dqinode_load +#define xfs_dqinode_load_parent libxfs_dqinode_load_parent +#define xfs_dqinode_mkdir_parent libxfs_dqinode_mkdir_parent +#define xfs_dqinode_metadir_create libxfs_dqinode_metadir_create +#define xfs_dqinode_metadir_link libxfs_dqinode_metadir_link +#define xfs_dqinode_path libxfs_dqinode_path#define xfs_dquot_from_disk_ts libxfs_dquot_from_disk_ts#define xfs_dquot_verify libxfs_dquot_verify
PATCH 3/7 xfs_repair: refactor quota inumber handling
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
In preparation for putting quota files in the metadata directory tree, refactor repair's quota inumber handling to use its own variables instead of the xfs_mount's.
--- repair/dinode.c | 18 ++++---- repair/dir2.c | 12 +++--- repair/globals.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++--- repair/globals.h | 15 ++++--- repair/phase4.c | 96 ++++++++++++++++++-------------------------- repair/phase6.c | 12 +++--- repair/quotacheck.c | 47 +++++++++++++++------- repair/quotacheck.h | 2 + repair/versions.c | 9 +--- repair/xfs_repair.c | 12 ++++-- 10 files changed, 221 insertions(+), 113 deletions(-)
repair/dinode.c +9 -9
@@ -1662,29 +1662,29 @@ process_check_metadata_inodes( }return 0 ; } -if (lino == mp->m_sb.sb_uquotino) { +if (is_quota_inode (XFS_DQTYPE_USER , lino)) {if (*type !=XR_INO_UQUOTA ) {do_warn (_ ("user quota inode %" PRIu64" has bad type 0x%x\n" ), lino,dinode_fmt (dinoc)); - mp->m_sb.sb_uquotino =NULLFSINO ; +clear_quota_inode (XFS_DQTYPE_USER );return 1 ; }return 0 ; } -if (lino == mp->m_sb.sb_gquotino) { +if (is_quota_inode (XFS_DQTYPE_GROUP , lino)) {if (*type !=XR_INO_GQUOTA ) {do_warn (_ ("group quota inode %" PRIu64" has bad type 0x%x\n" ), lino,dinode_fmt (dinoc)); - mp->m_sb.sb_gquotino =NULLFSINO ; +clear_quota_inode (XFS_DQTYPE_GROUP );return 1 ; }return 0 ; } -if (lino == mp->m_sb.sb_pquotino) { +if (is_quota_inode (XFS_DQTYPE_PROJ , lino)) {if (*type !=XR_INO_PQUOTA ) {do_warn (_ ("project quota inode %" PRIu64" has bad type 0x%x\n" ), lino,dinode_fmt (dinoc)); - mp->m_sb.sb_pquotino =NULLFSINO ; +clear_quota_inode (XFS_DQTYPE_PROJ );return 1 ; }return 0 ;
@@ -2980,11 +2980,11 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"),else if (lino == mp->m_sb.sb_rsumino ||is_rtsummary_inode (lino)) type =XR_INO_RTSUM ; -else if (lino == mp->m_sb.sb_uquotino) +else if (is_quota_inode (XFS_DQTYPE_USER , lino)) type =XR_INO_UQUOTA ; -else if (lino == mp->m_sb.sb_gquotino) +else if (is_quota_inode (XFS_DQTYPE_GROUP , lino)) type =XR_INO_GQUOTA ; -else if (lino == mp->m_sb.sb_pquotino) +else if (is_quota_inode (XFS_DQTYPE_PROJ , lino)) type =XR_INO_PQUOTA ;else type =XR_INO_DATA ;
repair/dir2.c +6 -6
@@ -265,13 +265,13 @@ process_sf_dir2( is_rtsummary_inode(lino)) { junkit =1 ; junkreason =_ ("realtime summary" ); - } else if (lino == mp->m_sb.sb_uquotino) { + } else if (is_quota_inode(XFS_DQTYPE_USER, lino)) { junkit =1 ; junkreason =_ ("user quota" ); - } else if (lino == mp->m_sb.sb_gquotino) { + } else if (is_quota_inode(XFS_DQTYPE_GROUP, lino)) { junkit =1 ; junkreason =_ ("group quota" ); - } else if (lino == mp->m_sb.sb_pquotino) { + } else if (is_quota_inode(XFS_DQTYPE_PROJ, lino)) { junkit =1 ; junkreason =_ ("project quota" ); } else if (lino == mp->m_sb.sb_metadirino) {
@@ -746,11 +746,11 @@ process_dir2_data( }else if (ent_ino == mp->m_sb.sb_rsumino ||is_rtsummary_inode (ent_ino)) { clearreason =_ ("realtime summary" ); - }else if (ent_ino == mp->m_sb.sb_uquotino) { + }else if (is_quota_inode (XFS_DQTYPE_USER , ent_ino)) { clearreason =_ ("user quota" ); - }else if (ent_ino == mp->m_sb.sb_gquotino) { + }else if (is_quota_inode (XFS_DQTYPE_GROUP , ent_ino)) { clearreason =_ ("group quota" ); - }else if (ent_ino == mp->m_sb.sb_pquotino) { + }else if (is_quota_inode (XFS_DQTYPE_PROJ , ent_ino)) { clearreason =_ ("project quota" ); }else if (ent_ino == mp->m_sb.sb_metadirino) { clearreason =_ ("metadata directory root" );
repair/globals.c +105 -6
120 lines not on this page · raw message
repair/globals.h +9 -6
@@ -114,12 +114,6 @@ extern int need_rbmino;extern int need_rsumino;extern int lost_quotas; -extern int have_uquotino; -extern int have_gquotino; -extern int have_pquotino; -extern int lost_uquotino; -extern int lost_gquotino; -extern int lost_pquotino;/* configuration vars -- fs geometry dependent */
@@ -165,4 +159,13 @@ extern int fail_after_phase;extern struct libxfs_init x; +void set_quota_inode (xfs_dqtype_t type,xfs_ino_t ); +void lose_quota_inode (xfs_dqtype_t type); +void clear_quota_inode (xfs_dqtype_t type); +xfs_ino_t get_quota_inode (xfs_dqtype_t type); +bool is_quota_inode (xfs_dqtype_t type,xfs_ino_t ino); +bool is_any_quota_inode (xfs_ino_t ino); +bool lost_quota_inode (xfs_dqtype_t type); +bool has_quota_inode (xfs_dqtype_t type); +#endif /* _XFS_REPAIR_GLOBAL_H */
repair/phase4.c +40 -56
117 lines not on this page · raw message
repair/phase6.c +6 -6
@@ -3192,12 +3192,12 @@ mark_standalone_inodes(xfs_mount_t *mp)if (!fs_quotas)return ; -if (mp->m_sb.sb_uquotino && mp->m_sb.sb_uquotino !=NULLFSINO ) -mark_inode (mp, mp->m_sb.sb_uquotino); -if (mp->m_sb.sb_gquotino && mp->m_sb.sb_gquotino !=NULLFSINO ) -mark_inode (mp, mp->m_sb.sb_gquotino); -if (mp->m_sb.sb_pquotino && mp->m_sb.sb_pquotino !=NULLFSINO ) -mark_inode (mp, mp->m_sb.sb_pquotino); +if (has_quota_inode (XFS_DQTYPE_USER )) +mark_inode (mp,get_quota_inode (XFS_DQTYPE_USER )); +if (has_quota_inode (XFS_DQTYPE_GROUP )) +mark_inode (mp,get_quota_inode (XFS_DQTYPE_GROUP )); +if (has_quota_inode (XFS_DQTYPE_PROJ )) +mark_inode (mp,get_quota_inode (XFS_DQTYPE_PROJ )); } static void
repair/quotacheck.c +33 -14
105 lines not on this page · raw message
repair/quotacheck.h +2 -0
@@ -13,4 +13,6 @@ uint16_t quotacheck_results(void);int quotacheck_setup (struct xfs_mount *mp);void quotacheck_teardown (void ); +void update_sb_quotinos (struct xfs_mount *mp,struct xfs_buf *sbp); +#endif /* __XFS_REPAIR_QUOTACHECK_H__ */
repair/versions.c +3 -6
@@ -104,9 +104,6 @@ parse_sb_version( fs_sb_feature_bits =0 ; fs_ino_alignment =0 ; fs_has_extflgbit =1 ; - have_uquotino =0 ; - have_gquotino =0 ; - have_pquotino =0 ;if (mp->m_sb.sb_versionnum &XFS_SB_VERSION_SHAREDBIT ) {do_warn (_ ("Shared Version bit set. Not supported. Ever.\n" ));
@@ -166,13 +163,13 @@ _("WARNING: you have a V1 inode filesystem. It would be converted to a\n" fs_quotas =1 ;if (mp->m_sb.sb_uquotino !=0 && mp->m_sb.sb_uquotino !=NULLFSINO ) - have_uquotino =1 ; +set_quota_inode (XFS_DQTYPE_USER , mp->m_sb.sb_uquotino);if (mp->m_sb.sb_gquotino !=0 && mp->m_sb.sb_gquotino !=NULLFSINO ) - have_gquotino =1 ; +set_quota_inode (XFS_DQTYPE_GROUP , mp->m_sb.sb_gquotino);if (mp->m_sb.sb_pquotino !=0 && mp->m_sb.sb_pquotino !=NULLFSINO ) - have_pquotino =1 ; +set_quota_inode (XFS_DQTYPE_PROJ , mp->m_sb.sb_pquotino); }if (xfs_has_align (mp)) {
repair/xfs_repair.c +8 -4
@@ -1404,7 +1404,9 @@ _("Inode allocation btrees are too corrupted, skipping phases 6 and 7\n"));free_rtgroup_inodes (); } -if (lost_quotas && !have_uquotino && !have_gquotino && !have_pquotino) { +if (lost_quotas && !has_quota_inode (XFS_DQTYPE_USER ) && + !has_quota_inode (XFS_DQTYPE_GROUP ) && + !has_quota_inode (XFS_DQTYPE_PROJ )) {if (!no_modify) {do_warn (_ ("Warning: no quota inodes were found. Quotas disabled.\n" ));
@@ -1421,7 +1423,7 @@ _("Warning: quota inodes were cleared. Quotas disabled.\n")); _("Warning: quota inodes would be cleared. Quotas would be disabled.\n")); } }else { -if (lost_uquotino) { +if (lost_quota_inode (XFS_DQTYPE_USER )) {if (!no_modify) { do_warn( _("Warning: user quota information was cleared.\n"
@@ -1433,7 +1435,7 @@ _("Warning: user quota information would be cleared.\n" } } -if (lost_gquotino) { +if (lost_quota_inode (XFS_DQTYPE_GROUP )) {if (!no_modify) { do_warn( _("Warning: group quota information was cleared.\n"
@@ -1445,7 +1447,7 @@ _("Warning: group quota information would be cleared.\n" } } -if (lost_pquotino) { +if (lost_quota_inode (XFS_DQTYPE_PROJ )) {if (!no_modify) { do_warn( _("Warning: project quota information was cleared.\n"
@@ -1485,6 +1487,8 @@ _("Warning: project quota information would be cleared.\n"if (!sbp)do_error (_ ("couldn't get superblock\n" )); +update_sb_quotinos (mp, sbp); +if ((mp->m_sb.sb_qflags &XFS_ALL_QUOTA_CHKD ) !=quotacheck_results ()) {do_warn (_ ("Note - quota info will be regenerated on next " "quota mount.\n" ));