xfs: metadata directories and realtime groups
Subsystems (4)
Re: [PATCH 11/24] xfs: create incore realtime group structures
In reply to Dave ChinnerQuoted 31 lines · Dave Chinner
Quoted 17 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create an incore object that will contain information about a realtime allocation group. This will eventually enable us to shard the realtime section in a similar manner to how we shard the data section, but for now just a single object for the entire RT subvolume is created.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_format.h | 3 + fs/xfs/libxfs/xfs_rtgroup.c | 196 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 212 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 7 + fs/xfs/libxfs/xfs_types.h | 4 + fs/xfs/xfs_log_recover.c | 20 ++++ fs/xfs/xfs_mount.c | 16 +++Quoted 8 lines
fs/xfs/xfs_mount.h | 14 +++ fs/xfs/xfs_rtalloc.c | 6 + fs/xfs/xfs_super.c | 1 fs/xfs/xfs_trace.c | 1 fs/xfs/xfs_trace.h | 38 ++++++++ 13 files changed, 517 insertions(+), 2 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_rtgroup.c create mode 100644 fs/xfs/libxfs/xfs_rtgroup.hOk, how is the global address space for real time extents laid out across rt groups? i.e. is it sparse similar to how fsbnos and inode numbers are created for the data device like so?
Quoted 5 lines
fsbno = (agno << agblklog) | agbno
Or is it something different? I can't find that defined anywhere in this patch, so I can't determine if the unit conversion code and validation is correct or not...
They're not sparse like fsbnos on the data device, they're laid end to end. IOWs, it's a straight linear translation. If you have an rtgroup that is 50 blocks long, then rtgroup 1 starts at (50 * blocksize).
This patch, FWIW, refactors the existing rt code so that a !rtgroups filesystem is represented by one large "group", with xfs_rtxnum_t now indexing rt extents within a group. Probably it should be renamed to xfs_rgxnum_t.
Note that we haven't defined the rtgroup ondisk format yet, so I'll go amend that patch to spell out the ondisk format of the brave new world.
Quoted 159 lines
Quoted 17 lines
fs/xfs/Makefile +1
-0@@ -60,6 +60,7 @@ xfs-y += $(addprefix libxfs/, \ # xfs_rtbitmap is shared with libxfs xfs-$(CONFIG_XFS_RT) += $(addprefix libxfs/, \ xfs_rtbitmap.o \ + xfs_rtgroup.o \ ) # highlevel codefs/xfs/libxfs/xfs_format.h +0
-0fs/xfs/libxfs/xfs_format.h typedef struct xfs_sb { · line 180
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +2
-0@@ -176,6 +176,9 @@ typedef struct xfs_sb {xfs_ino_t sb_metadirino;/* metadata directory tree root */ +xfs_rgnumber_t sb_rgcount;/* number of realtime groups */ +xfs_rtxlen_t sb_rgextents;/* size of a realtime group in rtx */ So min/max rtgroup size is defined by the
sb_rextsizefield? What redundant metadata do we end up with that allows us to validate thesb_rextsizefield is still valid w.r.t. rtgroups geometry?Also, rtgroup lengths are defined by "rtx counts", but the definitions in the
xfs_mountlater on are "m_rtblklog" and "m_rgblocks" and we usexfs_rgblock_tand rgbno all over the place.Just from the context of this patch, it is somewhat confusing trying to work out what the difference is...
Quoted 109 lines
fs/xfs/libxfs/xfs_format.h +0
-0/* must be padded to 64 bit alignment */ } xfs_sb_t;fs/xfs/libxfs/xfs_rtgroup.c new file +100
-0@@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022-2024 Oracle. All Rights Reserved. +* Author: Darrick J. Wong <[email protected]> +*/ +#include "xfs.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_trans_resv.h" +#include "xfs_bit.h" +#include "xfs_sb.h" +#include "xfs_mount.h" +#include "xfs_btree.h" +#include "xfs_alloc_btree.h" +#include "xfs_rmap_btree.h" +#include "xfs_alloc.h" +#include "xfs_ialloc.h" +#include "xfs_rmap.h" +#include "xfs_ag.h" +#include "xfs_ag_resv.h" +#include "xfs_health.h" +#include "xfs_error.h" +#include "xfs_bmap.h" +#include "xfs_defer.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" +#include "xfs_trace.h" +#include "xfs_inode.h" +#include "xfs_icache.h" +#include "xfs_rtgroup.h" +#include "xfs_rtbitmap.h" + +/* +* Passive reference counting access wrappers to the rtgroup structures. If +* the rtgroup structure is to be freed, the freeing code is responsible for +* cleaning up objects with passive references before freeing the structure. +*/ +struct xfs_rtgroup * +xfs_rtgroup_get ( +struct xfs_mount *mp, +xfs_rgnumber_t rgno) +{ +struct xfs_rtgroup *rtg; + +rcu_read_lock (); + rtg =xa_load (&mp->m_rtgroups, rgno); +if (rtg) { +trace_xfs_rtgroup_get (rtg, _RET_IP_); +ASSERT (atomic_read (&rtg->rtg_ref) >=0 ); +atomic_inc (&rtg->rtg_ref); + } +rcu_read_unlock (); +return rtg; +} + +/* Get a passive reference to the given rtgroup. */ +struct xfs_rtgroup * +xfs_rtgroup_hold ( +struct xfs_rtgroup *rtg) +{ +ASSERT (atomic_read (&rtg->rtg_ref) >0 || +atomic_read (&rtg->rtg_active_ref) >0 ); + +trace_xfs_rtgroup_hold (rtg, _RET_IP_); +atomic_inc (&rtg->rtg_ref); +return rtg; +} + +void +xfs_rtgroup_put ( +struct xfs_rtgroup *rtg) +{ +trace_xfs_rtgroup_put (rtg, _RET_IP_); +ASSERT (atomic_read (&rtg->rtg_ref) >0 ); +atomic_dec (&rtg->rtg_ref); +} + +/* +* Active references for rtgroup structures. This is for short term access to +* the rtgroup structures for walking trees or accessing state. If an rtgroup +* is being shrunk or is offline, then this will fail to find that group and +* return NULL instead. +*/ +struct xfs_rtgroup * +xfs_rtgroup_grab ( +struct xfs_mount *mp, +xfs_agnumber_t agno) +{ +struct xfs_rtgroup *rtg; + +rcu_read_lock (); + rtg =xa_load (&mp->m_rtgroups, agno); +if (rtg) { +trace_xfs_rtgroup_grab (rtg, _RET_IP_); +if (!atomic_inc_not_zero (&rtg->rtg_active_ref)) + rtg =NULL ; + } +rcu_read_unlock (); +return rtg;fs/xfs/libxfs/xfs_rtgroup.c line 110
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +10
-0+} + +void +xfs_rtgroup_rele ( +struct xfs_rtgroup *rtg) +{ +trace_xfs_rtgroup_rele (rtg, _RET_IP_); +if (atomic_dec_and_test (&rtg->rtg_active_ref)) +wake_up (&rtg->rtg_active_wq); +}This is all duplicates of the
xfs_peragcode. Can you put together a patchset to abstract this into a "xfs_group" and embed them in both the perag and and rtgroup structures?
Quoted 2 lines
That way we only need one set of lookup and iterator infrastructure, and it will work for both data and rt groups...
How will that work with perags still using the radix tree and rtgroups using the xarray? Yes, we should move the perags to use the xarray too (and indeed hch already has a series on list to do that) but here's really not the time to do that because I don't want to frontload a bunch more core changes onto this already huge patchset.
Quoted 29 lines
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +4
-0+ +/* Compute the number of rt extents in this realtime group. */ +xfs_rtxnum_t +xfs_rtgroup_extents((quoted diff) +1
-0+ struct xfs_mount *mp,fs/xfs/libxfs/xfs_rtgroup.c line 192
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +8
-0+ xfs_rgnumber_t rgno) +{ +xfs_rgnumber_t rgcount = mp->m_sb.sb_rgcount; + +ASSERT (rgno < rgcount); +if (rgno == rgcount -1 ) +return mp->m_sb.sb_rextents - + ((xfs_rtxnum_t )rgno * mp->m_sb.sb_rgextents);Urk. So this relies on a non-rtgroup filesystem doing a multiplication by zero of a field that the on-disk format does not understand to get the right result. I think this is a copying a bad pattern we've been slowly trying to remove from the normal allocation group code.
fs/xfs/libxfs/xfs_rtgroup.c line 196
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +4
-0+ +ASSERT (xfs_has_rtgroups (mp)); +return mp->m_sb.sb_rgextents; +}We already embed the length of the rtgroup in the rtgroup structure. THis should be looking up the rtgroup (or being passed the rtgroup the caller already has) and doing the right thing. i.e.
Quoted 3 lines
if (!rtg || !xfs_has_rtgroups(rtg->rtg_mount)) return mp->m_sb.sb_rextents; return rtg->rtg_extents;
xfs_rtgroup_extents is the function that we use to set rtg->rtg_extents.
Quoted 55 lines
Quoted 16 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +10
-0@@ -0,0 +1,212 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (c) 2022-2024 Oracle. All Rights Reserved. +* Author: Darrick J. Wong <[email protected]> +*/ +#ifndef __LIBXFS_RTGROUP_H +#define __LIBXFS_RTGROUP_H 1 + +struct xfs_mount ; +struct xfs_trans ;fs/xfs/libxfs/xfs_rtgroup.h line 20
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +10
-0+ +/* +* Realtime group incore structure, similar to the per-AG structure. +*/ +struct xfs_rtgroup { +struct xfs_mount *rtg_mount; +xfs_rgnumber_t rtg_rgno; +atomic_t rtg_ref;/* passive reference count */ +atomic_t rtg_active_ref;/* active reference count */ +wait_queue_head_t rtg_active_wq;/* woken active_ref falls to zero */ Yeah, that's all common with
xfs_perag........
Quoted 25 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +25
-0+/* +* rt group iteration APIs +*/ +static inline struct xfs_rtgroup * +xfs_rtgroup_next ( +struct xfs_rtgroup *rtg, +xfs_rgnumber_t *rgno, +xfs_rgnumber_t end_rgno) +{ +struct xfs_mount *mp = rtg->rtg_mount; + + *rgno = rtg->rtg_rgno +1 ; +xfs_rtgroup_rele (rtg); +if (*rgno > end_rgno) +return NULL ; +return xfs_rtgroup_grab (mp, *rgno); +} + +#define for_each_rtgroup_range (mp, rgno, end_rgno, rtg) \ + for ((rtg) = xfs_rtgroup_grab((mp), (rgno)); \ + (rtg) != NULL; \ + (rtg) = xfs_rtgroup_next((rtg), &(rgno), (end_rgno))) + +#define for_each_rtgroup_from (mp, rgno, rtg) \ + for_each_rtgroup_range((mp), (rgno), (mp)->m_sb.sb_rgcount - 1, (rtg))
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.h line 100
Quoted 5 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +5
-0+ + +#define for_each_rtgroup (mp, rgno, rtg) \ + (rgno) = 0; \ + for_each_rtgroup_from((mp), (rgno), (rtg))Yup, that's all common with
xfs_peragiteration, too. Can you put together a patchset to unify these, please?
Here's the first part of that, to convert perags to xarrays...
https://lore.kernel.org/linux-xfs/[email protected]/
Quoted 78 lines
fs/xfs/libxfs/xfs_rtgroup.h line 105
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +4
-0+static inline bool +xfs_verify_rgbno ( +struct xfs_rtgroup *rtg, +xfs_rgblock_t rgbno)Ok, what's the difference between and
xfs_rgblock_tand a "rtx"?OH.... Then penny just dropped - it's another "single letter difference that's really, really hard to spot" problem. You've defined "xfs_r*g*block_t" for the like a a*g*bno, but we have xfs_r*t*block_t for the global 64bit block number instead of a
xfs_fsbno_t.We just had a bug caused by exactly this sort of confusion with a patch that mixed xfs_[f]inobt changes together and one of the conversions was incorrect. Nobody spotted the single incorrect letter in the bigger patch, and I can see -exactly- the same sort of confusion happening with rtblock vs rgblock causing implicit 32/64 bit integer promotion bugs...
fs/xfs/libxfs/xfs_rtgroup.h line 110
Quoted 5 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +5
-0+{ +struct xfs_mount *mp = rtg->rtg_mount; + +if (rgbno >= rtg->rtg_extents * mp->m_sb.sb_rextsize) +return false;Why isn't the max valid "rgbno" stored in the rtgroup instead of having to multiply the extent count by extent size every time we have to verify a rgbno? (i.e. same as
pag->block_count).We know from the agbno verification this will be a -very- hot path, and so precalculating all the constants and storing them in the rtg should be done right from the start here.
fs/xfs/libxfs/xfs_rtgroup.h line 113
Quoted 3 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +3
-0+if (xfs_has_rtsb (mp) && rtg->rtg_rgno ==0 && + rgbno < mp->m_sb.sb_rextsize) +return false;Same here - this value is stored in
pag->min_block...fs/xfs/libxfs/xfs_rtgroup.h line 64
Quoted 2 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +2
-0+return true; +}And then, if we put the
max_bnoandmin_bnoin the generic "xfs_group" structure, we suddenly have a generic "group bno" verification mechanism that is independent of whether the groupstatic inline bool
xfs_verify_gbno(
structxfs_group*g,
xfs_gblock_tgbno){ struct xfs_mount *mp = g->g_mount; if (gbno >= g->block_count) return false; if (gbno < g->min_block) return false; return true; }And the rest of these functions fall out the same way....
fs/xfs/libxfs/xfs_rtgroup.h line 140
Quoted 9 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +9
-0+static inline xfs_rtblock_t +xfs_rgno_start_rtb ( +struct xfs_mount *mp, +xfs_rgnumber_t rgno) +{ +if (mp->m_rgblklog >=0 ) +return ((xfs_rtblock_t )rgno << mp->m_rgblklog); +return ((xfs_rtblock_t )rgno * mp->m_rgblocks); +}Where does
mp->m_rgblklogcome from? That wasn't added to the on-disk superblock structure and it is always initialised to zero in this patch.
Quoted 1 line
When will
m_rgblklogbe zero and when will it be non-zero? If it's
As I mentioned before, this patch merely ports non-rtg filesystems to use the rtgroup structure. m_rgblklog will be set to nonzero values when we get to defining the ondisk rtgroup structure.
But, to cut ahead here, m_rgblklog will be set to a non-negative value if the rtgroup size (in blocks) is a power of two. Then these unit conversion functions can use shifts instead of expensive multiplication and divisions. The same goes for rt extent to {fs,rt}block conversions.
Quoted 5 lines
only going to be zero for existing non-rtg realtime systems, then this code makes little sense (again, relying on multiplication by zero to get the right result). If it's not always used for rtg enabled filesytsems, then the reason for that has not been explained and I can't work out why this would ever need to be done.
https://lore.kernel.org/linux-xfs/172437088534.60592.14072619855969226822.stgit@frogsfrogsfrogs/
Quoted 27 lines
Quoted 13 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +12
-0+static inline xfs_rtblock_t +xfs_rgbno_to_rtb ( +struct xfs_mount *mp, +xfs_rgnumber_t rgno, +xfs_rgblock_t rgbno) +{ +return xfs_rgno_start_rtb (mp, rgno) + rgbno; +} + +static inline xfs_rgnumber_t +xfs_rtb_to_rgno( + struct xfs_mount *mp,fs/xfs/libxfs/xfs_rtgroup.h line 163
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +10
-0+ xfs_rtblock_t rtbno) +{ +if (!xfs_has_rtgroups (mp)) +return 0 ; + +if (mp->m_rgblklog >=0 ) +return rtbno >> mp->m_rgblklog; + +return div_u64 (rtbno, mp->m_rgblocks); +}Ah, now I'm really confused, because
m_rgblklogis completely bypassed for legacy rt filesystems.
Quoted 3 lines
And I just realised, this "if (
mp->m_rgblklog>= 0)" implies thatm_rgblklogcan have negative values and there's no comments anywhere about why that can happen and what would trigger it.
-1 is the magic value for "the rtgroup size is not a power of two, so you have to use slow integer division and multiplication".
Quoted 4 lines
We validate
sb_agblklogduring the superblock verifier, and so once the filesystem is mounted we never, ever need to check whethersb_agblklogis in range. Why is the rtblklog being handled so differently here?
This all could be documented better across the patches. Originally the incore and ondisk patches were adjacent and it was at least somewhat easier to figure these things out, but hch really wanted to shard the rtbitmaps, so now the patchset has grown even larger and harder to understand if you only read one patch at a time.
Quoted 12 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +12
-0+ +static inline uint64_t +__xfs_rtb_to_rgbno ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +uint32_t rem; + +if (!xfs_has_rtgroups (mp)) +return rtbno; + +if (mp->m_rgblklog >=0 )
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.h line 180
Quoted 5 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +5
-0+return rtbno & mp->m_rgblkmask; + +div_u64_rem (rtbno, mp->m_rgblocks, &rem); +return rem; +}Why is this function returning a
uint64_t- axfs_rgblock_tis only a 32 bit type...
group 0 on a !rtg filesystem can be 64-bits in block/rt count. This is a /very/ annoying pain point -- if you actually created such a filesystem it actually would never work because the rtsummary file would be created undersized due to an integer overflow, but the verifiers never checked any of that, and due to the same underflow the rtallocator would search the wrong places and (eventually) fall back to a dumb linear scan.
Soooooo this is an obnoxious usecase (broken large !rtg filesystems) that we can't just drop, though I'm pretty sure there aren't any systems in the wild.
Quoted 20 lines
Quoted 20 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +20
-0+ +static inline xfs_rgblock_t +xfs_rtb_to_rgbno ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +return __xfs_rtb_to_rgbno (mp, rtbno); +} + +static inline xfs_daddr_t +xfs_rtb_to_daddr ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +return rtbno << mp->m_blkbb_log; +} + +static inline xfs_rtblock_t +xfs_daddr_to_rtb( + struct xfs_mount *mp,
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.h line 204
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +4
-0+ xfs_daddr_t daddr) +{ +return daddr >> mp->m_blkbb_log; +}Ah. This code doesn't sparsify the
xfs_rtblock_taddress space for rtgroups.xfs_rtblock_tis still direct physical encoding of the location on disk.
Yes.
Quoted 23 lines
I really think that needs to be changed to match how
xfs_fsbno_tis a sparse encoding before these changes get merged. It shouldn't affect any of the other code in the patch set - the existing rt code has a rtgno of 0, so it will always be a direct physical encoding even when using a sparsexfs_rtblock_taddress space.All that moving to a sparse encoding means is that the addresses stored in the BMBT are logical addresses rather than physical addresses. It should not affect any of the other code, just what ends up stored on disk for global 64-bit rt extent addresses...
In doing this, I think we can greatly simply all this group management stuff as most of the verification, type conversion and iteration infrastructure can then be shared between the exist perag and the new rtg infrastructure....
Quoted 7 lines
fs/xfs/libxfs/xfs_types.h +0
-0@@ -9,10 +9,12 @@typedef uint32_t prid_t ;/* project ID */
Quoted 7 lines
fs/xfs/libxfs/xfs_types.h line 12
Quoted 2 lines
fs/xfs/libxfs/xfs_types.h +1
-0typedef uint32_t xfs_agblock_t ;/* blockno in alloc. group */ +typedef uint32_t xfs_rgblock_t ;/* blockno in realtime group */ Is that right? The rtg length is 2^32 * rtextsize, and rtextsize can be 2^20 bytes:
#define
XFS_MAX_RTEXTSIZE(1024 * 1024 * 1024)
No, the maximum rtgroup length is 2^32-1 blocks.
Quoted 4 lines
Hence for a 4kB fsbno filesystem, the actual maximum size of an rtg in filesystem blocks far exceeds what we can address with a 32 bit variable.
Quoted 8 lines
If
xfs_rgblock_tis actually indexing multi-fsbno rtextents, then it is an extent number index, not a "block" index. An extent number index won't overflow 32 bits (because the rtg has a max of 2^32 - 1 rtextents)IOWs, shouldn't this be named soemthing like:
typedef
uint32_txfs_rgext_t; /* extent number in realtime group */
and again, we can't do that because we emulate !rtg filesystems with a single "rtgroup" that can be more than 2^32 rtx long.
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_types.h +1
-0typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ typedef uint32_t xfs_rtxlen_t ;/* file extent length in rtextents */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ +typedef uint32_t xfs_rgnumber_t ;/* realtime group number */ typedef uint64_t xfs_extnum_t ;/* # of extents in a file */ typedef uint32_t xfs_aextnum_t ;/* # extents in an attribute fork */ typedef int64_t xfs_fsize_t ;/* bytes in a file */ @@ -53,7 +55,9 @@ typedef void * xfs_failaddr_t;#define NULLFILEOFF ((xfs_fileoff_t)-1)
Quoted 8 lines
fs/xfs/libxfs/xfs_types.h typedef void * xfs_failaddr_t; · line 60
Quoted 4 lines
fs/xfs/libxfs/xfs_types.h +2
-0#define NULLAGBLOCK ((xfs_agblock_t)-1) +#define NULLRGBLOCK ((xfs_rgblock_t)-1)#define NULLAGNUMBER ((xfs_agnumber_t)-1) +#define NULLRGNUMBER ((xfs_rgnumber_t)-1)What's the maximum valid rtg number? We're not ever going to be supporting 2^32 - 2 rtgs, so what is a realistic maximum we can cap this at and validate it at?
/me shrugs -- the smallest AG size on the data device is 16M, which technically speaking means that one /could/ format 2^(63-24) groups, or order 39.
Realistically with the maximum rtgroup size of 2^31 blocks, we probably only need 2^(63 - (31 + 10)) = 2^22 rtgroups max on a 1k fsblock fs.
Quoted 129 lines
Quoted 34 lines
fs/xfs/libxfs/xfs_types.h +0
-0#define NULLCOMMITLSN ((xfs_lsn_t)-1)fs/xfs/xfs_log_recover.c +10
-0@@ -28,6 +28,7 @@#include "xfs_ag.h" #include "xfs_quota.h" #include "xfs_reflink.h" +#include "xfs_rtgroup.h" #define BLK_AVG (blk1, blk2) ((blk1+blk2) >> 1)@@ -3346,6 +3347,7 @@ xlog_do_recover(struct xfs_mount *mp = log->l_mp;struct xfs_buf *bp = mp->m_sb_bp;struct xfs_sb *sbp = &mp->m_sb; +xfs_rgnumber_t old_rgcount = sbp->sb_rgcount;int error;trace_xfs_log_recover (log, head_blk, tail_blk);@@ -3399,6 +3401,24 @@ xlog_do_recover(xfs_warn (mp,"Failed post-recovery per-ag init: %d" , error);return error; } + +if (sbp->sb_rgcount < old_rgcount) { +xfs_warn (mp,"rgcount shrink not supported" ); +return -EINVAL ; + } +if (sbp->sb_rgcount > old_rgcount) { +xfs_rgnumber_t rgno; +fs/xfs/xfs_log_recover.c xlog_do_recover( · line 3421
Quoted 10 lines
fs/xfs/xfs_log_recover.c +10
-0+for (rgno = old_rgcount; rgno < sbp->sb_rgcount; rgno++) { + error =xfs_rtgroup_alloc (mp, rgno); +if (error) { +xfs_warn (mp, +"Failed post-recovery rtgroup init: %d" , + error); +return error; + } + } + }Please factor this out into a separate function with all the other rtgroup init/teardown code. That means we don't have to care about how rtgrowfs functions in recovery code, similar to the
xfs_initialize_perag()already in this function for handling recovery of data device growing...Quoted 24 lines
fs/xfs/xfs_log_recover.c +0
-0mp->m_alloc_set_aside =xfs_alloc_set_aside (mp);/* Normal transactions can now occur */ fs/xfs/xfs_mount.c +2
-0@@ -36,6 +36,7 @@#include "xfs_ag.h" #include "xfs_rtbitmap.h" #include "xfs_metafile.h" +#include "xfs_rtgroup.h" #include "scrub/stats.h" static DEFINE_MUTEX (xfs_uuid_table_mutex);@@ -664,6 +665,7 @@ xfs_mountfs(struct xfs_ino_geometry *igeo =M_IGEO (mp);uint quotamount =0 ;uint quotaflags =0 ; +xfs_rgnumber_t rgno;int error =0 ;xfs_sb_mount_common (mp, sbp);fs/xfs/xfs_mount.c xfs_mountfs( · line 841
Quoted 10 lines
fs/xfs/xfs_mount.c +7
-0@@ -830,10 +832,18 @@ xfs_mountfs( goto out_free_dir; } +for (rgno =0 ; rgno < mp->m_sb.sb_rgcount; rgno++) { + error =xfs_rtgroup_alloc (mp, rgno); +if (error) { +xfs_warn (mp,"Failed rtgroup init: %d" , error); + goto out_free_rtgroup; + } + }Same - factor this to a
xfs_rtgroup_init()function located with the rest of the rtgroup infrastructure...Quoted 20 lines
fs/xfs/xfs_mount.c +4
-2+if (XFS_IS_CORRUPT (mp, !sbp->sb_logblocks)) {xfs_warn (mp,"no log defined" ); error = -EFSCORRUPTED ; - goto out_free_perag; + goto out_free_rtgroup; } error =xfs_inodegc_register_shrinker (mp);@@ -1068,7 +1078,8 @@ xfs_mountfs(if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)xfs_buftarg_drain (mp->m_logdev_targp);xfs_buftarg_drain (mp->m_ddev_targp); - out_free_perag: + out_free_rtgroup: +xfs_free_rtgroups (mp, rgno);xfs_free_perag (mp); out_free_dir:xfs_da_unmount (mp);fs/xfs/xfs_mount.c xfs_unmountfs( · line 1166
Quoted 4 lines
fs/xfs/xfs_mount.c +1
-0@@ -1152,6 +1163,7 @@ xfs_unmountfs(xfs_errortag_clearall (mp);#endif shrinker_free (mp->m_inodegc_shrinker); +xfs_free_rtgroups (mp, mp->m_sb.sb_rgcount);... like you've already for the cleanup side ;)
....
fs/xfs/xfs_mount.c xfs_rtmount_inodes( · line 1174
Quoted 7 lines
fs/xfs/xfs_mount.c +3
-0@@ -1166,6 +1169,9 @@ xfs_rtmount_inodes(if (error) goto out_rele_summary; +for_each_rtgroup (mp, rgno, rtg) + rtg->rtg_extents =xfs_rtgroup_extents (mp, rtg->rtg_rgno); +This also needs to be done after recovery has initialised new rtgs as a result fo replaying a sb growfs modification, right?
Quoted 7 lines
Which leads to the next question: if there are thousands of rtgs, this requires walking every rtg at mount time, right? We know that walking thousands of static structures at mount time is a scalability issue, so can we please avoid this if at all possible? i.e. do demand loading of per-rtg metadata when it is first required (like we do with agf/agi information) rather than doing it all at mount time...
Sounds like a reasonable optimization patch...
--D
Quoted 6 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 11/24] xfs: create incore realtime group structures
Quoted 34 lines · Darrick J. Wong
Quoted 33 lines · Dave Chinner
Quoted 17 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create an incore object that will contain information about a realtime allocation group. This will eventually enable us to shard the realtime section in a similar manner to how we shard the data section, but for now just a single object for the entire RT subvolume is created.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_format.h | 3 + fs/xfs/libxfs/xfs_rtgroup.c | 196 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 212 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 7 + fs/xfs/libxfs/xfs_types.h | 4 + fs/xfs/xfs_log_recover.c | 20 ++++ fs/xfs/xfs_mount.c | 16 +++Quoted 8 lines
fs/xfs/xfs_mount.h | 14 +++ fs/xfs/xfs_rtalloc.c | 6 + fs/xfs/xfs_super.c | 1 fs/xfs/xfs_trace.c | 1 fs/xfs/xfs_trace.h | 38 ++++++++ 13 files changed, 517 insertions(+), 2 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_rtgroup.c create mode 100644 fs/xfs/libxfs/xfs_rtgroup.hOk, how is the global address space for real time extents laid out across rt groups? i.e. is it sparse similar to how fsbnos and inode numbers are created for the data device like so?
fsbno = (agno << agblklog) | agbno
Quoted 7 lines
Quoted 3 lines
Or is it something different? I can't find that defined anywhere in this patch, so I can't determine if the unit conversion code and validation is correct or not...
They're not sparse like fsbnos on the data device, they're laid end to end. IOWs, it's a straight linear translation. If you have an rtgroup that is 50 blocks long, then rtgroup 1 starts at (50 * blocksize).
Yes, I figured that out later. I think that's less than optimal, because it essentially repeats the problems we have with AGs being fixed size without the potential for fixing it easily. i.e. the global sharded fsbno address space is sparse, so we can actually space out the sparse address regions to allow future flexibility in group size and location work.
By having the rtgroup addressing being purely physical, we're completely stuck with fixed sized rtgroups and there is no way around that. IOWs, the physical address space sharding repeats the existing grow and shrink problems we have with the existing fixed size AGs.
We're discussing how to use the sparse fsbno addressing to allow resizing of AGs, but we will not be able to do that at all with rtgroups as they stand. The limitation is a 64 bit global rt extent address is essential the physical address of the extent in the block device LBA space.
Quoted 4 lines
This patch, FWIW, refactors the existing rt code so that a !rtgroups filesystem is represented by one large "group", with
xfs_rtxnum_tnow indexing rt extents within a group.
Right, we can do that regardless of whether we use logical or physical addressing for the global rtbno for sharded rtgroup layout. the rtgno of 0 for that rtg always results in logical = physical addressing.
Quoted 1 line
Probably it should be renamed to
xfs_rgxnum_t.
That might be a good idea.
Quoted 2 lines
Note that we haven't defined the rtgroup ondisk format yet, so I'll go amend that patch to spell out the ondisk format of the brave new world.
Yes, please! That would have made working out all the differences between all the combinations of rt, rtx, rg, num, len, blk, etc a whole lot easier to work out.
Quoted 31 lines
Quoted 31 lines
Quoted 16 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +16
-0+struct xfs_rtgroup * +xfs_rtgroup_grab ( +struct xfs_mount *mp, +xfs_agnumber_t agno) +{ +struct xfs_rtgroup *rtg; + +rcu_read_lock (); + rtg =xa_load (&mp->m_rtgroups, agno); +if (rtg) { +trace_xfs_rtgroup_grab (rtg, _RET_IP_); +if (!atomic_inc_not_zero (&rtg->rtg_active_ref)) + rtg =NULL ; + } +rcu_read_unlock (); +return rtg;fs/xfs/libxfs/xfs_rtgroup.c line 110
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +10
-0+} + +void +xfs_rtgroup_rele ( +struct xfs_rtgroup *rtg) +{ +trace_xfs_rtgroup_rele (rtg, _RET_IP_); +if (atomic_dec_and_test (&rtg->rtg_active_ref)) +wake_up (&rtg->rtg_active_wq); +}This is all duplicates of the
xfs_peragcode. Can you put together a patchset to abstract this into a "xfs_group" and embed them in both the perag and and rtgroup structures?
Quoted 8 lines
Quoted 2 lines
That way we only need one set of lookup and iterator infrastructure, and it will work for both data and rt groups...
How will that work with perags still using the radix tree and rtgroups using the xarray? Yes, we should move the perags to use the xarray too (and indeed hch already has a series on list to do that) but here's really not the time to do that because I don't want to frontload a bunch more core changes onto this already huge patchset.
Let's first assume they both use xarray (that's just a matter of time, yes?) so it's easier to reason about. Then we have something like this:
/*
* xfs_group - a contiguous 32 bit block address space group */
struct xfs_group {
struct xarray xarr;
u32 num_groups;
};struct xfs_group_item {
struct xfs_group *group; /* so put/rele don't need any other context */
u32 gno;
atomic_t passive_refs;
atomic_t active_refs;
wait_queue_head_t active_wq;
unsigned long opstate;
u32 blocks; /* length in fsb */
u32 extents; /* length in extents */
u32 blk_log; /* extent size in fsb */
/* limits for min/max valid addresses */
u32 max_addr;
u32 min_addr;
};And then we define:
struct xfs_perag {
struct xfs_group_item g;
/* perag specific stuff follows */
....
};struct xfs_rtgroup {
struct xfs_group_item g;
/* rtg specific stuff follows */
.....}
And then a couple of generic macros:
#define to_grpi(grpi, gi) container_of((gi), typeof(grpi), g)
#define to_gi(grpi) (&(grpi)->g)
though this might be better as just typed macros:
#define gi_to_pag(gi) container_of((gi), struct xfs_perag, g)
#define gi_to_rtg(gi) container_of((gi), struct xfs_rtgroup, g)
And then all the grab/rele/get/put stuff becomes:
rtg = to_grpi(rtg, xfs_group_grab(mp->m_rtgroups, rgno)); pag = to_grpi(pag, xfs_group_grab(mp->m_perags, agno)); .... xfs_group_put(&rtg->g); xfs_group_put(&pag->g);
or
rtg = gi_to_rtg(xfs_group_grab(mp->m_rtgroups, rgno)); pag = gi_to_pag(xfs_group_grab(mp->m_perags, agno)); .... xfs_group_put(&rtg->g); xfs_group_put(&pag->g);
then we pass the group to each of the "for_each_group..." iterators like so:
for_each_group(&mp->m_perags, agno, pag) {
/* do stuff with pag */
}or
for_each_group(&mp->m_rtgroups, rtgno, rtg) {
/* do stuff with rtg */
}And we use typeof() and container_of() to access the group structure within the pag/rtg. Something like:
#define to_grpi(grpi, gi) container_of((gi), typeof(grpi), g)
#define to_gi(grpi) (&(grpi)->g)
#define for_each_group(grp, gno, grpi) \ (gno) = 0; \ for ((grpi) = to_grpi((grpi), xfs_group_grab((grp), (gno))); \ (grpi) != NULL; \ (grpi) = to_grpi(grpi, xfs_group_next((grp), to_gi(grpi), \ &(gno), (grp)->num_groups))
And now we essentially have common group infrstructure for access, iteration, geometry and address verification purposes...
Quoted 30 lines
Quoted 30 lines
Quoted 5 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +4
-0+ +/* Compute the number of rt extents in this realtime group. */ +xfs_rtxnum_t +xfs_rtgroup_extents((quoted diff) +1
-0+ struct xfs_mount *mp,fs/xfs/libxfs/xfs_rtgroup.c line 192
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +8
-0+ xfs_rgnumber_t rgno) +{ +xfs_rgnumber_t rgcount = mp->m_sb.sb_rgcount; + +ASSERT (rgno < rgcount); +if (rgno == rgcount -1 ) +return mp->m_sb.sb_rextents - + ((xfs_rtxnum_t )rgno * mp->m_sb.sb_rgextents);Urk. So this relies on a non-rtgroup filesystem doing a multiplication by zero of a field that the on-disk format does not understand to get the right result. I think this is a copying a bad pattern we've been slowly trying to remove from the normal allocation group code.
fs/xfs/libxfs/xfs_rtgroup.c line 196
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +4
-0+ +ASSERT (xfs_has_rtgroups (mp)); +return mp->m_sb.sb_rgextents; +}We already embed the length of the rtgroup in the rtgroup structure. THis should be looking up the rtgroup (or being passed the rtgroup the caller already has) and doing the right thing. i.e.
Quoted 5 lines
Quoted 3 lines
if (!rtg || !xfs_has_rtgroups(rtg->rtg_mount)) return mp->m_sb.sb_rextents; return rtg->rtg_extents;
xfs_rtgroup_extentsis the function that we use to setrtg->rtg_extents.
That wasn't clear from the context of the patch. Perhaps a better name xfs_rtgroup_calc_extents() to indicate that it is a setup function, not something that should be regularly called at runtime?
Quoted 15 lines
Quoted 15 lines
fs/xfs/libxfs/xfs_rtgroup.h line 140
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +9
-0+static inline xfs_rtblock_t +xfs_rgno_start_rtb ( +struct xfs_mount *mp, +xfs_rgnumber_t rgno) +{ +if (mp->m_rgblklog >=0 ) +return ((xfs_rtblock_t )rgno << mp->m_rgblklog); +return ((xfs_rtblock_t )rgno * mp->m_rgblocks); +}Where does
mp->m_rgblklogcome from? That wasn't added to the on-disk superblock structure and it is always initialised to zero in this patch.
Quoted 5 lines
Quoted 1 line
When will
m_rgblklogbe zero and when will it be non-zero? If it'sAs I mentioned before, this patch merely ports non-rtg filesystems to use the rtgroup structure.
m_rgblklogwill be set to nonzero values when we get to defining the ondisk rtgroup structure.
Yeah, which makes some of the context in the patch hard to understand... :/
Quoted 4 lines
But, to cut ahead here,
m_rgblklogwill be set to a non-negative value if the rtgroup size (in blocks) is a power of two. Then these unit conversion functions can use shifts instead of expensive multiplication and divisions. The same goes for rt extent to {fs,rt}block conversions.
yeah, so mp->m_rgblklog is not equivalent of mp->m_agblklog at all. It took me some time to understand that - the names are the same, they are used in similar address conversions, but they have completely different functions.
I suspect we need some better naming here, regardless of the rtgroups global address space layout discussion...
Quoted 29 lines
Quoted 12 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +12
-0+ +static inline uint64_t +__xfs_rtb_to_rgbno ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +uint32_t rem; + +if (!xfs_has_rtgroups (mp)) +return rtbno; + +if (mp->m_rgblklog >=0 )Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.h line 180
Quoted 5 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +5
-0+return rtbno & mp->m_rgblkmask; + +div_u64_rem (rtbno, mp->m_rgblocks, &rem); +return rem; +}Why is this function returning a
uint64_t- axfs_rgblock_tis only a 32 bit type...group 0 on a !rtg filesystem can be 64-bits in block/rt count. This is a /very/ annoying pain point -- if you actually created such a filesystem it actually would never work because the rtsummary file would be created undersized due to an integer overflow, but the verifiers never checked any of that, and due to the same underflow the rtallocator would search the wrong places and (eventually) fall back to a dumb linear scan.
Quoted 3 lines
Soooooo this is an obnoxious usecase (broken large !rtg filesystems) that we can't just drop, though I'm pretty sure there aren't any systems in the wild.
Ugh. That definitely needs to be a comment somewhere in the code to explain this. :/
Quoted 13 lines
Quoted 13 lines
fs/xfs/libxfs/xfs_types.h line 12
Quoted 9 lines
fs/xfs/libxfs/xfs_types.h +1
-0@@ -9,10 +9,12 @@typedef uint32_t prid_t ;/* project ID */ typedef uint32_t xfs_agblock_t ;/* blockno in alloc. group */ +typedef uint32_t xfs_rgblock_t ;/* blockno in realtime group */ Is that right? The rtg length is 2^32 * rtextsize, and rtextsize can be 2^20 bytes:
Quoted 3 lines
Quoted 1 line
#define
XFS_MAX_RTEXTSIZE(1024 * 1024 * 1024)No, the maximum rtgroup length is 2^32-1 blocks.
I couldn't tell if the max length was being defined as the maximum number of rt extents that the rtgroup could index, of whether it was the maximum number of filesystem blocks (i.e. data device fsblock size) tha an rtgroup could index...
Quoted 9 lines
Quoted 9 lines
Hence for a 4kB fsbno filesystem, the actual maximum size of an rtg in filesystem blocks far exceeds what we can address with a 32 bit variable.
If
xfs_rgblock_tis actually indexing multi-fsbno rtextents, then it is an extent number index, not a "block" index. An extent number index won't overflow 32 bits (because the rtg has a max of 2^32 - 1 rtextents)
Quoted 6 lines
Quoted 3 lines
IOWs, shouldn't this be named soemthing like:
typedef
uint32_txfs_rgext_t; /* extent number in realtime group */and again, we can't do that because we emulate !rtg filesystems with a single "rtgroup" that can be more than 2^32 rtx long.
*nod*
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_types.h +1
-0typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ typedef uint32_t xfs_rtxlen_t ;/* file extent length in rtextents */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ +typedef uint32_t xfs_rgnumber_t ;/* realtime group number */ typedef uint64_t xfs_extnum_t ;/* # of extents in a file */ typedef uint32_t xfs_aextnum_t ;/* # extents in an attribute fork */ typedef int64_t xfs_fsize_t ;/* bytes in a file */ @@ -53,7 +55,9 @@ typedef void * xfs_failaddr_t;#define NULLFILEOFF ((xfs_fileoff_t)-1)Quoted 8 lines
fs/xfs/libxfs/xfs_types.h typedef void * xfs_failaddr_t; · line 60
Quoted 4 lines
fs/xfs/libxfs/xfs_types.h +2
-0#define NULLAGBLOCK ((xfs_agblock_t)-1) +#define NULLRGBLOCK ((xfs_rgblock_t)-1)#define NULLAGNUMBER ((xfs_agnumber_t)-1) +#define NULLRGNUMBER ((xfs_rgnumber_t)-1)What's the maximum valid rtg number? We're not ever going to be supporting 2^32 - 2 rtgs, so what is a realistic maximum we can cap this at and validate it at?
Quoted 6 lines
/me shrugs -- the smallest AG size on the data device is 16M, which technically speaking means that one /could/ format 2^(63-24) groups, or order 39.
Realistically with the maximum rtgroup size of 2^31 blocks, we probably only need 2^(63 - (31 + 10)) = 2^22 rtgroups max on a 1k fsblock fs.
Right, those are the theoretical maximums. Practically speaking, though, mkfs and mount iteration of all AGs means millions to billions of IOs need to be done before the filesystem can even be fully mounted. Hence the practical limit to AG count is closer to a few tens of thousands, not hundreds of billions.
Hence I'm wondering if we should actually cap the maximum number of rtgroups. WE're just about at BS > PS, so with a 64k block size a single rtgroup can index 2^32 * 2^16 bytes which puts individual rtgs at 256TB in size. Unless there are use cases for rtgroup sizes smaller than a few GBs, I just don't see the need for support theoretical maximum counts on tiny block size filesystems. Thirty thousand rtgs at 256TB per rtg puts us at 64 bit device size limits, and we hit those limits on 4kB block sizes at around 500,000 rtgs.
So do we need to support millions of rtgs? I'd say no....
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 11/24] xfs: create incore realtime group structures
Quoted 56 lines · Dave Chinner
Quoted 34 lines · Darrick J. Wong
Quoted 33 lines · Dave Chinner
Quoted 17 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create an incore object that will contain information about a realtime allocation group. This will eventually enable us to shard the realtime section in a similar manner to how we shard the data section, but for now just a single object for the entire RT subvolume is created.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_format.h | 3 + fs/xfs/libxfs/xfs_rtgroup.c | 196 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 212 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 7 + fs/xfs/libxfs/xfs_types.h | 4 + fs/xfs/xfs_log_recover.c | 20 ++++ fs/xfs/xfs_mount.c | 16 +++Quoted 8 lines
fs/xfs/xfs_mount.h | 14 +++ fs/xfs/xfs_rtalloc.c | 6 + fs/xfs/xfs_super.c | 1 fs/xfs/xfs_trace.c | 1 fs/xfs/xfs_trace.h | 38 ++++++++ 13 files changed, 517 insertions(+), 2 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_rtgroup.c create mode 100644 fs/xfs/libxfs/xfs_rtgroup.hOk, how is the global address space for real time extents laid out across rt groups? i.e. is it sparse similar to how fsbnos and inode numbers are created for the data device like so?
fsbno = (agno << agblklog) | agbno
Quoted 7 lines
Quoted 3 lines
Or is it something different? I can't find that defined anywhere in this patch, so I can't determine if the unit conversion code and validation is correct or not...
They're not sparse like fsbnos on the data device, they're laid end to end. IOWs, it's a straight linear translation. If you have an rtgroup that is 50 blocks long, then rtgroup 1 starts at (50 * blocksize).
Yes, I figured that out later. I think that's less than optimal, because it essentially repeats the problems we have with AGs being fixed size without the potential for fixing it easily. i.e. the global sharded fsbno address space is sparse, so we can actually space out the sparse address regions to allow future flexibility in group size and location work.
By having the rtgroup addressing being purely physical, we're completely stuck with fixed sized rtgroups and there is no way around that. IOWs, the physical address space sharding repeats the existing grow and shrink problems we have with the existing fixed size AGs.
Quoted 5 lines
We're discussing how to use the sparse fsbno addressing to allow resizing of AGs, but we will not be able to do that at all with rtgroups as they stand. The limitation is a 64 bit global rt extent address is essential the physical address of the extent in the block device LBA space.
<nod> I /think/ it's pretty simple to convert the rtgroups rtblock numbers to sparse ala xfs_fsblock_t -- all we have to do is make sure that mp->m_rgblklog is set to highbit64(rtgroup block count) and then delete all the multiply/divide code, just like we do on the data device.
The thing I *don't* know is how will this affect hch's zoned device support -- he's mentioned that rtgroups will eventually have both a size and a "capacity" to keep the zones aligned to groups, or groups aligned to zones, I don't remember which. I don't know if segmenting br_startblock for rt mappings makes things better or worse for that.
Quoted 11 lines
Quoted 3 lines
This patch, FWIW, refactors the existing rt code so that a !rtgroups filesystem is represented by one large "group", with
xfs_rtxnum_tnow indexing rt extents within a group.Right, we can do that regardless of whether we use logical or physical addressing for the global rtbno for sharded rtgroup layout. the rtgno of 0 for that rtg always results in logical = physical addressing.
Quoted 1 line
Probably it should be renamed to
xfs_rgxnum_t.
Quoted 8 lines
That might be a good idea.
Quoted 2 lines
Note that we haven't defined the rtgroup ondisk format yet, so I'll go amend that patch to spell out the ondisk format of the brave new world.
Yes, please! That would have made working out all the differences between all the combinations of rt, rtx, rg, num, len, blk, etc a whole lot easier to work out.
<Nod> I'll go work all that out.
Quoted 44 lines
Quoted 31 lines
Quoted 31 lines
Quoted 16 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +16
-0+struct xfs_rtgroup * +xfs_rtgroup_grab ( +struct xfs_mount *mp, +xfs_agnumber_t agno) +{ +struct xfs_rtgroup *rtg; + +rcu_read_lock (); + rtg =xa_load (&mp->m_rtgroups, agno); +if (rtg) { +trace_xfs_rtgroup_grab (rtg, _RET_IP_); +if (!atomic_inc_not_zero (&rtg->rtg_active_ref)) + rtg =NULL ; + } +rcu_read_unlock (); +return rtg;fs/xfs/libxfs/xfs_rtgroup.c line 110
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +10
-0+} + +void +xfs_rtgroup_rele ( +struct xfs_rtgroup *rtg) +{ +trace_xfs_rtgroup_rele (rtg, _RET_IP_); +if (atomic_dec_and_test (&rtg->rtg_active_ref)) +wake_up (&rtg->rtg_active_wq); +}This is all duplicates of the
xfs_peragcode. Can you put together a patchset to abstract this into a "xfs_group" and embed them in both the perag and and rtgroup structures?Quoted 8 lines
Quoted 2 lines
That way we only need one set of lookup and iterator infrastructure, and it will work for both data and rt groups...
How will that work with perags still using the radix tree and rtgroups using the xarray? Yes, we should move the perags to use the xarray too (and indeed hch already has a series on list to do that) but here's really not the time to do that because I don't want to frontload a bunch more core changes onto this already huge patchset.
Let's first assume they both use xarray (that's just a matter of time, yes?) so it's easier to reason about. Then we have something like this:
Quoted 7 lines
/*
*xfs_group- a contiguous 32 bit block address space group */struct xfs_group { struct xarray xarr; u32 num_groups; };
Ah, that's the group head. I might call this struct xfs_groups?
So ... would it theoretically make more sense to use an rhashtable here? Insofar as the only place that totally falls down is if you want to iterate tagged groups; and that's only done for AGs.
I'm ok with using an xarray here, fwiw.
Quoted 8 lines
struct xfs_group_item {
struct xfs_group *group; /* so put/rele don't need any other context */
u32 gno;
atomic_t passive_refs;
atomic_t active_refs;
wait_queue_head_t active_wq;
unsigned long opstate;Quoted 8 lines
u32 blocks; /* length in fsb */ u32 extents; /* length in extents */ u32 blk_log; /* extent size in fsb */ /* limits for min/max valid addresses */ u32 max_addr; u32 min_addr; };
Yeah, that's pretty much what I had in the prototype that I shredded an hour ago.
Quoted 70 lines
And then we define:
struct xfs_perag { struct xfs_group_item g; /* perag specific stuff follows */ .... };struct xfs_rtgroup { struct xfs_group_item g; /* rtg specific stuff follows */ .....}
And then a couple of generic macros:
#define
to_grpi(grpi, gi)container_of((gi), typeof(grpi), g)
#defineto_gi(grpi)(&(grpi)->g)though this might be better as just typed macros:
#define
gi_to_pag(gi)container_of((gi), struct xfs_perag, g)
#definegi_to_rtg(gi)container_of((gi), struct xfs_rtgroup, g)And then all the grab/rele/get/put stuff becomes:
rtg = to_grpi(rtg, xfs_group_grab(mp->m_rtgroups, rgno)); pag = to_grpi(pag, xfs_group_grab(mp->m_perags, agno)); .... xfs_group_put(&rtg->g); xfs_group_put(&pag->g);or
rtg = gi_to_rtg(xfs_group_grab(mp->m_rtgroups, rgno)); pag = gi_to_pag(xfs_group_grab(mp->m_perags, agno)); .... xfs_group_put(&rtg->g); xfs_group_put(&pag->g);then we pass the group to each of the "
for_each_group..." iterators like so:for_each_group(&mp->m_perags, agno, pag) { /* do stuff with pag */ }or
for_each_group(&mp->m_rtgroups, rtgno, rtg) { /* do stuff with rtg */ }And we use
typeof()andcontainer_of()to access the group structure within the pag/rtg. Something like:#define
to_grpi(grpi, gi)container_of((gi), typeof(grpi), g)
#defineto_gi(grpi)(&(grpi)->g)#define for_each_group(grp, gno, grpi) \ (gno) = 0; \ for ((grpi) = to_grpi((grpi), xfs_group_grab((grp), (gno))); \ (grpi) != NULL; \ (grpi) = to_grpi(grpi, xfs_group_next((grp), to_gi(grpi), \ &(gno), (grp)->num_groups))
Quoted 2 lines
And now we essentially have common group infrstructure for access, iteration, geometry and address verification purposes...
<nod> That's pretty much what I had drafted, albeit with different helper macros since I kept the for_each_{perag,rtgroup} things around for type safety. Though I think for_each_perag just becomes:
#define for_each_perag(mp, agno, pag) \ for_each_group((mp)->m_perags, (agno), (pag))
Right?
Quoted 34 lines
Quoted 34 lines
Quoted 33 lines
Quoted 5 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +4
-0+ +/* Compute the number of rt extents in this realtime group. */ +xfs_rtxnum_t +xfs_rtgroup_extents((quoted diff) +1
-0+ struct xfs_mount *mp,fs/xfs/libxfs/xfs_rtgroup.c line 192
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +8
-0+ xfs_rgnumber_t rgno) +{ +xfs_rgnumber_t rgcount = mp->m_sb.sb_rgcount; + +ASSERT (rgno < rgcount); +if (rgno == rgcount -1 ) +return mp->m_sb.sb_rextents - + ((xfs_rtxnum_t )rgno * mp->m_sb.sb_rgextents);Urk. So this relies on a non-rtgroup filesystem doing a multiplication by zero of a field that the on-disk format does not understand to get the right result. I think this is a copying a bad pattern we've been slowly trying to remove from the normal allocation group code.
fs/xfs/libxfs/xfs_rtgroup.c line 196
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.c new file +4
-0+ +ASSERT (xfs_has_rtgroups (mp)); +return mp->m_sb.sb_rgextents; +}We already embed the length of the rtgroup in the rtgroup structure. THis should be looking up the rtgroup (or being passed the rtgroup the caller already has) and doing the right thing. i.e.
if (!rtg || !xfs_has_rtgroups(rtg->rtg_mount)) return mp->m_sb.sb_rextents; return rtg->rtg_extents;
Quoted 5 lines
Quoted 1 line
xfs_rtgroup_extentsis the function that we use to setrtg->rtg_extents.That wasn't clear from the context of the patch. Perhaps a better name
xfs_rtgroup_calc_extents()to indicate that it is a setup function, not something that should be regularly called at runtime?
<nod>
Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
fs/xfs/libxfs/xfs_rtgroup.h line 140
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +9
-0+static inline xfs_rtblock_t +xfs_rgno_start_rtb ( +struct xfs_mount *mp, +xfs_rgnumber_t rgno) +{ +if (mp->m_rgblklog >=0 ) +return ((xfs_rtblock_t )rgno << mp->m_rgblklog); +return ((xfs_rtblock_t )rgno * mp->m_rgblocks); +}Where does
mp->m_rgblklogcome from? That wasn't added to the on-disk superblock structure and it is always initialised to zero in this patch.Quoted 5 lines
Quoted 1 line
When will
m_rgblklogbe zero and when will it be non-zero? If it'sAs I mentioned before, this patch merely ports non-rtg filesystems to use the rtgroup structure.
m_rgblklogwill be set to nonzero values when we get to defining the ondisk rtgroup structure.Yeah, which makes some of the context in the patch hard to understand... :/
Quoted 4 lines
But, to cut ahead here,
m_rgblklogwill be set to a non-negative value if the rtgroup size (in blocks) is a power of two. Then these unit conversion functions can use shifts instead of expensive multiplication and divisions. The same goes for rt extent to {fs,rt}block conversions.
Quoted 7 lines
yeah, so
mp->m_rgblklogis not equivalent ofmp->m_agblklogat all. It took me some time to understand that - the names are the same, they are used in similar address conversions, but they have completely different functions.I suspect we need some better naming here, regardless of the rtgroups global address space layout discussion...
Or just make xfs_rtblock_t sparse, in which case I think m_rgblklog usage patterns become exactly the same as m_agblklog.
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +12
-0+ +static inline uint64_t +__xfs_rtb_to_rgbno ( +struct xfs_mount *mp, +xfs_rtblock_t rtbno) +{ +uint32_t rem; + +if (!xfs_has_rtgroups (mp)) +return rtbno; + +if (mp->m_rgblklog >=0 )Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.h line 180
Quoted 5 lines
fs/xfs/libxfs/xfs_rtgroup.h new file +5
-0+return rtbno & mp->m_rgblkmask; + +div_u64_rem (rtbno, mp->m_rgblocks, &rem); +return rem; +}Why is this function returning a
uint64_t- axfs_rgblock_tis only a 32 bit type...group 0 on a !rtg filesystem can be 64-bits in block/rt count. This is a /very/ annoying pain point -- if you actually created such a filesystem it actually would never work because the rtsummary file would be created undersized due to an integer overflow, but the verifiers never checked any of that, and due to the same underflow the rtallocator would search the wrong places and (eventually) fall back to a dumb linear scan.
Quoted 6 lines
Quoted 3 lines
Soooooo this is an obnoxious usecase (broken large !rtg filesystems) that we can't just drop, though I'm pretty sure there aren't any systems in the wild.
Ugh. That definitely needs to be a comment somewhere in the code to explain this. :/
Well it's all in the commit that fixed the rtsummary for those things.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
fs/xfs/libxfs/xfs_types.h line 12
Quoted 9 lines
fs/xfs/libxfs/xfs_types.h +1
-0@@ -9,10 +9,12 @@typedef uint32_t prid_t ;/* project ID */ typedef uint32_t xfs_agblock_t ;/* blockno in alloc. group */ +typedef uint32_t xfs_rgblock_t ;/* blockno in realtime group */ Is that right? The rtg length is 2^32 * rtextsize, and rtextsize can be 2^20 bytes:
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
#define
XFS_MAX_RTEXTSIZE(1024 * 1024 * 1024)No, the maximum rtgroup length is 2^32-1 blocks.
I couldn't tell if the max length was being defined as the maximum number of rt extents that the rtgroup could index, of whether it was the maximum number of filesystem blocks (i.e. data device fsblock size) tha an rtgroup could index...
The max rtgroup length is defined in blocks; the min is defined in rt extents. I might want to bump up the minimum a bit, but I think Christoph should weigh in on that first -- I think his zns patchset currently assigns one rtgroup to each zone? Because he was muttering about how 130,000x 256MB rtgroups really sucks. Would it be very messy to have a minimum size of (say) 1GB?
Quoted 60 lines
Quoted 9 lines
Quoted 9 lines
Hence for a 4kB fsbno filesystem, the actual maximum size of an rtg in filesystem blocks far exceeds what we can address with a 32 bit variable.
If
xfs_rgblock_tis actually indexing multi-fsbno rtextents, then it is an extent number index, not a "block" index. An extent number index won't overflow 32 bits (because the rtg has a max of 2^32 - 1 rtextents)Quoted 6 lines
Quoted 3 lines
IOWs, shouldn't this be named soemthing like:
typedef
uint32_txfs_rgext_t; /* extent number in realtime group */and again, we can't do that because we emulate !rtg filesystems with a single "rtgroup" that can be more than 2^32 rtx long.
*nod*
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
fs/xfs/libxfs/xfs_types.h +1
-0typedef uint32_t xfs_agino_t ;/* inode # within allocation grp */ typedef uint32_t xfs_extlen_t ;/* extent length in blocks */ typedef uint32_t xfs_rtxlen_t ;/* file extent length in rtextents */ typedef uint32_t xfs_agnumber_t ;/* allocation group number */ +typedef uint32_t xfs_rgnumber_t ;/* realtime group number */ typedef uint64_t xfs_extnum_t ;/* # of extents in a file */ typedef uint32_t xfs_aextnum_t ;/* # extents in an attribute fork */ typedef int64_t xfs_fsize_t ;/* bytes in a file */ @@ -53,7 +55,9 @@ typedef void * xfs_failaddr_t;#define NULLFILEOFF ((xfs_fileoff_t)-1)Quoted 8 lines
fs/xfs/libxfs/xfs_types.h typedef void * xfs_failaddr_t; · line 60
Quoted 4 lines
fs/xfs/libxfs/xfs_types.h +2
-0#define NULLAGBLOCK ((xfs_agblock_t)-1) +#define NULLRGBLOCK ((xfs_rgblock_t)-1)#define NULLAGNUMBER ((xfs_agnumber_t)-1) +#define NULLRGNUMBER ((xfs_rgnumber_t)-1)What's the maximum valid rtg number? We're not ever going to be supporting 2^32 - 2 rtgs, so what is a realistic maximum we can cap this at and validate it at?
Quoted 6 lines
/me shrugs -- the smallest AG size on the data device is 16M, which technically speaking means that one /could/ format 2^(63-24) groups, or order 39.
Realistically with the maximum rtgroup size of 2^31 blocks, we probably only need 2^(63 - (31 + 10)) = 2^22 rtgroups max on a 1k fsblock fs.
Right, those are the theoretical maximums. Practically speaking, though, mkfs and mount iteration of all AGs means millions to billions of IOs need to be done before the filesystem can even be fully mounted. Hence the practical limit to AG count is closer to a few tens of thousands, not hundreds of billions.
Hence I'm wondering if we should actually cap the maximum number of rtgroups. WE're just about at BS > PS, so with a 64k block size a single rtgroup can index 2^32 * 2^16 bytes which puts individual rtgs at 256TB in size. Unless there are use cases for rtgroup sizes smaller than a few GBs, I just don't see the need for support theoretical maximum counts on tiny block size filesystems. Thirty thousand rtgs at 256TB per rtg puts us at 64 bit device size limits, and we hit those limits on 4kB block sizes at around 500,000 rtgs.
Quoted 1 line
So do we need to support millions of rtgs? I'd say no....
...but we might. Christoph, how gnarly does zns support get if you have to be able to pack multiple SMR zones into a single rtgroup?
--D
Quoted 4 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 11/24] xfs: create incore realtime group structures
Quoted 68 lines · Darrick J. Wong
Quoted 56 lines · Dave Chinner
Quoted 34 lines · Darrick J. Wong
Quoted 33 lines · Dave Chinner
Quoted 17 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create an incore object that will contain information about a realtime allocation group. This will eventually enable us to shard the realtime section in a similar manner to how we shard the data section, but for now just a single object for the entire RT subvolume is created.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_format.h | 3 + fs/xfs/libxfs/xfs_rtgroup.c | 196 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 212 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 7 + fs/xfs/libxfs/xfs_types.h | 4 + fs/xfs/xfs_log_recover.c | 20 ++++ fs/xfs/xfs_mount.c | 16 +++Quoted 8 lines
fs/xfs/xfs_mount.h | 14 +++ fs/xfs/xfs_rtalloc.c | 6 + fs/xfs/xfs_super.c | 1 fs/xfs/xfs_trace.c | 1 fs/xfs/xfs_trace.h | 38 ++++++++ 13 files changed, 517 insertions(+), 2 deletions(-) create mode 100644 fs/xfs/libxfs/xfs_rtgroup.c create mode 100644 fs/xfs/libxfs/xfs_rtgroup.hOk, how is the global address space for real time extents laid out across rt groups? i.e. is it sparse similar to how fsbnos and inode numbers are created for the data device like so?
fsbno = (agno << agblklog) | agbno
Quoted 7 lines
Quoted 3 lines
Or is it something different? I can't find that defined anywhere in this patch, so I can't determine if the unit conversion code and validation is correct or not...
They're not sparse like fsbnos on the data device, they're laid end to end. IOWs, it's a straight linear translation. If you have an rtgroup that is 50 blocks long, then rtgroup 1 starts at (50 * blocksize).
Yes, I figured that out later. I think that's less than optimal, because it essentially repeats the problems we have with AGs being fixed size without the potential for fixing it easily. i.e. the global sharded fsbno address space is sparse, so we can actually space out the sparse address regions to allow future flexibility in group size and location work.
By having the rtgroup addressing being purely physical, we're completely stuck with fixed sized rtgroups and there is no way around that. IOWs, the physical address space sharding repeats the existing grow and shrink problems we have with the existing fixed size AGs.
Quoted 5 lines
We're discussing how to use the sparse fsbno addressing to allow resizing of AGs, but we will not be able to do that at all with rtgroups as they stand. The limitation is a 64 bit global rt extent address is essential the physical address of the extent in the block device LBA space.
<nod> I /think/ it's pretty simple to convert the rtgroups rtblock numbers to sparse ala
xfs_fsblock_t-- all we have to do is make sure thatmp->m_rgblklogis set to highbit64(rtgroup block count) and then delete all the multiply/divide code, just like we do on the data device.
Quoted 5 lines
The thing I *don't* know is how will this affect hch's zoned device support -- he's mentioned that rtgroups will eventually have both a size and a "capacity" to keep the zones aligned to groups, or groups aligned to zones, I don't remember which. I don't know if segmenting
br_startblockfor rt mappings makes things better or worse for that.
I can't really comment on that because I haven't heard anything about this requirement. It kinda sounds like sparse addressing just with different names, but I'm just guessing there. Maybe Christoph can educate us here...
Quoted 25 lines
Quoted 17 lines
Quoted 4 lines
Quoted 4 lines
This is all duplicates of the
xfs_peragcode. Can you put together a patchset to abstract this into a "xfs_group" and embed them in both the perag and and rtgroup structures?Quoted 8 lines
Quoted 2 lines
That way we only need one set of lookup and iterator infrastructure, and it will work for both data and rt groups...
How will that work with perags still using the radix tree and rtgroups using the xarray? Yes, we should move the perags to use the xarray too (and indeed hch already has a series on list to do that) but here's really not the time to do that because I don't want to frontload a bunch more core changes onto this already huge patchset.
Let's first assume they both use xarray (that's just a matter of time, yes?) so it's easier to reason about. Then we have something like this:
Quoted 7 lines
/*
*xfs_group- a contiguous 32 bit block address space group */struct xfs_group { struct xarray xarr; u32 num_groups; };
Quoted 1 line
Ah, that's the group head. I might call this struct
xfs_groups?
Sure.
Quoted 4 lines
So ... would it theoretically make more sense to use an rhashtable here? Insofar as the only place that totally falls down is if you want to iterate tagged groups; and that's only done for AGs.
The index is contiguous and starts at zero, so it packs extremely well into an xarray. For small numbers of groups (i.e. the vast majority of installations) item lookup is essentially O(1) (single node), and it scales out at O(log N) for large numbers and random access. It also has efficient sequential iteration, which is what we mostly do with groups.
rhashtable has an advantage at scale of being mostly O(1), but it comes at an increased memory footprint and has terrible for ordered iteration behaviour even ignoring tags (essentially random memory access).
Quoted 1 line
I'm ok with using an xarray here, fwiw.
OK.
Quoted 28 lines
Quoted 25 lines
then we pass the group to each of the "
for_each_group..." iterators like so:for_each_group(&mp->m_perags, agno, pag) { /* do stuff with pag */ }or
for_each_group(&mp->m_rtgroups, rtgno, rtg) { /* do stuff with rtg */ }And we use
typeof()andcontainer_of()to access the group structure within the pag/rtg. Something like:#define
to_grpi(grpi, gi)container_of((gi), typeof(grpi), g)
#defineto_gi(grpi)(&(grpi)->g)#define for_each_group(grp, gno, grpi) \ (gno) = 0; \ for ((grpi) = to_grpi((grpi), xfs_group_grab((grp), (gno))); \ (grpi) != NULL; \ (grpi) = to_grpi(grpi, xfs_group_next((grp), to_gi(grpi), \ &(gno), (grp)->num_groups))Quoted 2 lines
And now we essentially have common group infrstructure for access, iteration, geometry and address verification purposes...
Quoted 8 lines
<nod> That's pretty much what I had drafted, albeit with different helper macros since I kept the for_each_{perag,rtgroup} things around for type safety. Though I think
for_each_peragjust becomes:#define for_each_perag(mp, agno, pag) \ for_each_group((mp)->m_perags, (agno), (pag))Right?
Yeah, that's what I though of doing first, but then figured a little bit of compiler magic gets rid of the need for the type specific iterator wrappers altogether...
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
fs/xfs/libxfs/xfs_types.h +0
-0@@ -9,10 +9,12 @@typedef uint32_t prid_t ;/* project ID */ Quoted 7 lines
fs/xfs/libxfs/xfs_types.h line 12
Quoted 2 lines
fs/xfs/libxfs/xfs_types.h +1
-0typedef uint32_t xfs_agblock_t ;/* blockno in alloc. group */ +typedef uint32_t xfs_rgblock_t ;/* blockno in realtime group */ Is that right? The rtg length is 2^32 * rtextsize, and rtextsize can be 2^20 bytes:
#define
XFS_MAX_RTEXTSIZE(1024 * 1024 * 1024)No, the maximum rtgroup length is 2^32-1 blocks.
Quoted 7 lines
Quoted 4 lines
I couldn't tell if the max length was being defined as the maximum number of rt extents that the rtgroup could index, of whether it was the maximum number of filesystem blocks (i.e. data device fsblock size) tha an rtgroup could index...
The max rtgroup length is defined in blocks; the min is defined in rt extents.
I think that's part of the problem - can we define min and max in the same units? Or have two sets of definitions - one for each unit?
Quoted 4 lines
I might want to bump up the minimum a bit, but I think Christoph should weigh in on that first -- I think his zns patchset currently assigns one rtgroup to each zone? Because he was muttering about how 130,000x 256MB rtgroups really sucks.
Ah, that might be the capacity vs size thing - to allow rtgroups to be sized as an integer multiple of the zone capacity and so have an rtgroup for every N contiguous zones....
Quoted 2 lines
Would it be very messy
to have a minimum size of (say) 1GB?
I was thinking of larger than that, but the question comes down to how *small* do we need to support for rtg based rtdevs? I was thinking that hundreds of GB would be the smallest size device we might deploy this sort of feature on, in which case somewhere around 50GB would be the typical minimum rtg size...
I'm kind worried that 1GB sizes still allows the crazy growfs small to huge capacity problems we have with AGs. It's probably a good place to start, but I think larger would be better...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 11/24] xfs: create incore realtime group structures
In reply to Darrick J. WongQuoted 5 lines · Darrick J. Wong
The thing I *don't* know is how will this affect hch's zoned device support -- he's mentioned that rtgroups will eventually have both a size and a "capacity" to keep the zones aligned to groups, or groups aligned to zones, I don't remember which. I don't know if segmenting
br_startblockfor rt mappings makes things better or worse for that.
This should be fine. The ZNS zone capacity features where zones have a size (LBA space allocated to it) and a capacity (LBAs that can actually be written to) is the hardware equivalent of this.
Quoted 3 lines
So ... would it theoretically make more sense to use an rhashtable here? Insofar as the only place that totally falls down is if you want to iterate tagged groups; and that's only done for AGs.
It also is an important part of garbage collection for zoned XFS, where we'll use it on RTGs.
Quoted 11 lines
Quoted 10 lines
#define for_each_group(grp, gno, grpi) \ (gno) = 0; \ for ((grpi) = to_grpi((grpi), xfs_group_grab((grp), (gno))); \ (grpi) != NULL; \ (grpi) = to_grpi(grpi, xfs_group_next((grp), to_gi(grpi), \ &(gno), (grp)->num_groups))And now we essentially have common group infrstructure for access, iteration, geometry and address verification purposes...
Quoted 8 lines
<nod> That's pretty much what I had drafted, albeit with different helper macros since I kept the for_each_{perag,rtgroup} things around for type safety. Though I think
for_each_peragjust becomes:#define for_each_perag(mp, agno, pag) \ for_each_group((mp)->m_perags, (agno), (pag))Right?
Btw, if we touch all of this anyway I'd drop the agno argument. We can get the group number from the group struct (see my perag xarray conversion series for an example where I'm doing this for the tagged iteration).
Quoted 7 lines
The max rtgroup length is defined in blocks; the min is defined in rt extents. I might want to bump up the minimum a bit, but I think Christoph should weigh in on that first -- I think his zns patchset currently assigns one rtgroup to each zone? Because he was muttering about how 130,000x 256MB rtgroups really sucks. Would it be very messy to have a minimum size of (say) 1GB?
Very messy. I can live with a minimum of 256 MB, but no byte less :) This is the size used by all shipping SMR hard drivers. For ZNS SSDs there are samples with very small zones size that are basically open channel devices in disguise - no sane person would want them and they don't make sense to support in XFS as they require extensive erasure encoding and error correction. The ZNS drives with full data integrity support have zone sizes and capacities way over 1GB and growing.
Quoted 6 lines
Quoted 3 lines
and we hit those limits on 4kB block sizes at around 500,000 rtgs.
So do we need to support millions of rtgs? I'd say no....
...but we might. Christoph, how gnarly does zns support get if you have to be able to pack multiple SMR zones into a single rtgroup?
I thought about it, but it creates real accounting nightmares. It's not entirely doable, but really messy.
Re: [PATCH 11/24] xfs: create incore realtime group structures
In reply to Dave ChinnerQuoted 5 lines · Dave Chinner
We're discussing how to use the sparse fsbno addressing to allow resizing of AGs, but we will not be able to do that at all with rtgroups as they stand. The limitation is a 64 bit global rt extent address is essential the physical address of the extent in the block device LBA space.
With this series there are not global RT extent addresses, the extents are always relative to the group and an entity only used in the allocator.
Quoted 8 lines
/*
*xfs_group- a contiguous 32 bit block address space group */struct xfs_group { struct xarray xarr; u32 num_groups; };
Quoted 5 lines
struct xfs_group_item {
struct xfs_group *group; /* so put/rele don't need any other context */
u32 gno;
atomic_t passive_refs;
atomic_t active_refs;What is the point of splitting the group and group_item? This isn't done in the current perag struture either.
Quoted 10 lines
Hence I'm wondering if we should actually cap the maximum number of rtgroups. WE're just about at BS > PS, so with a 64k block size a single rtgroup can index 2^32 * 2^16 bytes which puts individual rtgs at 256TB in size. Unless there are use cases for rtgroup sizes smaller than a few GBs, I just don't see the need for support theoretical maximum counts on tiny block size filesystems. Thirty thousand rtgs at 256TB per rtg puts us at 64 bit device size limits, and we hit those limits on 4kB block sizes at around 500,000 rtgs.
So do we need to support millions of rtgs? I'd say no....
As said before hardware is having a word with with the 256GB hardware zone size in SMR HDDs. I hope that size will eventually increase, but I would not bet my house on it.
Re: [PATCH 11/24] xfs: create incore realtime group structures
Quoted 19 lines · Christoph Hellwig
Quoted 5 lines · Dave Chinner
We're discussing how to use the sparse fsbno addressing to allow resizing of AGs, but we will not be able to do that at all with rtgroups as they stand. The limitation is a 64 bit global rt extent address is essential the physical address of the extent in the block device LBA space.
With this series there are not global RT extent addresses, the extents are always relative to the group and an entity only used in the allocator.
Quoted 8 lines
/*
*xfs_group- a contiguous 32 bit block address space group */struct xfs_group { struct xarray xarr; u32 num_groups; };
Quoted 8 lines
Quoted 5 lines
struct xfs_group_item { struct xfs_group *group; /* so put/rele don't need any other context */ u32 gno; atomic_t passive_refs; atomic_t active_refs;What is the point of splitting the group and
group_item? This isn't done in the current perag struture either.
I think xfs_group encapsulates/replaces the radix tree root in struct xfs_mount, and the xarray inside it points to xfs_group_item objects.
Quoted 9 lines
Quoted 9 lines
Hence I'm wondering if we should actually cap the maximum number of rtgroups. WE're just about at BS > PS, so with a 64k block size a single rtgroup can index 2^32 * 2^16 bytes which puts individual rtgs at 256TB in size. Unless there are use cases for rtgroup sizes smaller than a few GBs, I just don't see the need for support theoretical maximum counts on tiny block size filesystems. Thirty thousand rtgs at 256TB per rtg puts us at 64 bit device size limits, and we hit those limits on 4kB block sizes at around 500,000 rtgs.
Quoted 5 lines
Quoted 1 line
So do we need to support millions of rtgs? I'd say no....
As said before hardware is having a word with with the 256GB hardware zone size in SMR HDDs. I hope that size will eventually increase, but I would not bet my house on it.
Wait, 256 *gigabytes*? That wouldn't be such a bad minimum.
--D
Re: [PATCH 11/24] xfs: create incore realtime group structures
Quoted 16 lines · Darrick J. Wong
Quoted 16 lines
allocator.
Quoted 13 lines
/*
*xfs_group- a contiguous 32 bit block address space group */struct xfs_group { struct xarray xarr; u32 num_groups; };struct xfs_group_item { struct xfs_group *group; /* so put/rele don't need any other context */ u32 gno; atomic_t passive_refs; atomic_t active_refs;
Quoted 5 lines
Quoted 2 lines
What is the point of splitting the group and
group_item? This isn't done in the current perag struture either.I think
xfs_groupencapsulates/replaces the radix tree root in structxfs_mount, and the xarray inside it points toxfs_group_itemobjects.
Ahh. So it's now a xfs_group structure, but a xfs_groups one, with the group item really being xfs_group.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Hence I'm wondering if we should actually cap the maximum number of rtgroups. WE're just about at BS > PS, so with a 64k block size a single rtgroup can index 2^32 * 2^16 bytes which puts individual rtgs at 256TB in size. Unless there are use cases for rtgroup sizes smaller than a few GBs, I just don't see the need for support theoretical maximum counts on tiny block size filesystems. Thirty thousand rtgs at 256TB per rtg puts us at 64 bit device size limits, and we hit those limits on 4kB block sizes at around 500,000 rtgs.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
So do we need to support millions of rtgs? I'd say no....
As said before hardware is having a word with with the 256GB hardware zone size in SMR HDDs. I hope that size will eventually increase, but I would not bet my house on it.
Wait, 256 *gigabytes*? That wouldn't be such a bad minimum.
Sorry, MB. My units really suck this morning :)
Re: [PATCH 11/24] xfs: create incore realtime group structures
In reply to Darrick J. WongQuoted 3 lines · Darrick J. Wong
They're not sparse like fsbnos on the data device, they're laid end to end. IOWs, it's a straight linear translation. If you have an rtgroup that is 50 blocks long, then rtgroup 1 starts at (50 * blocksize).
Except with the zone capacity features on ZNS devices, where they already are sparse. But that's like 200 patches away from the state here..
Quoted 11 lines
group 0 on a !rtg filesystem can be 64-bits in block/rt count. This is a /very/ annoying pain point -- if you actually created such a filesystem it actually would never work because the rtsummary file would be created undersized due to an integer overflow, but the verifiers never checked any of that, and due to the same underflow the rtallocator would search the wrong places and (eventually) fall back to a dumb linear scan.
Soooooo this is an obnoxious usecase (broken large !rtg filesystems) that we can't just drop, though I'm pretty sure there aren't any systems in the wild.
So, do we really need to support that? I think we've always supported a 64-bit block count, so we'll have to support that, but if a > 32bit extent count was always broken maybe we should simply stop to pretend to support it?
Quoted 10 lines
Quoted 3 lines
What's the maximum valid rtg number? We're not ever going to be supporting 2^32 - 2 rtgs, so what is a realistic maximum we can cap this at and validate it at?
/me shrugs -- the smallest AG size on the data device is 16M, which technically speaking means that one /could/ format 2^(63-24) groups, or order 39.
Realistically with the maximum rtgroup size of 2^31 blocks, we probably only need 2^(63 - (31 + 10)) = 2^22 rtgroups max on a 1k fsblock fs.
Note that with zoned file system later on we are bound by hardware size. SMR HDDs by convention some with 256MB zones. This is a bit on the small side, but grouping multiple of those into a RT group would be a major pain. I hope the hardware size will eventually increase, maybe when they move to 3-digit TB capcity points.
Re: [PATCH 11/24] xfs: create incore realtime group structures
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong
They're not sparse like fsbnos on the data device, they're laid end to end. IOWs, it's a straight linear translation. If you have an rtgroup that is 50 blocks long, then rtgroup 1 starts at (50 * blocksize).
Except with the zone capacity features on ZNS devices, where they already are sparse. But that's like 200 patches away from the state here..
Heh.
Quoted 8 lines
Quoted 8 lines
group 0 on a !rtg filesystem can be 64-bits in block/rt count. This is a /very/ annoying pain point -- if you actually created such a filesystem it actually would never work because the rtsummary file would be created undersized due to an integer overflow, but the verifiers never checked any of that, and due to the same underflow the rtallocator would search the wrong places and (eventually) fall back to a dumb linear scan.
Quoted 8 lines
Quoted 3 lines
Soooooo this is an obnoxious usecase (broken large !rtg filesystems) that we can't just drop, though I'm pretty sure there aren't any systems in the wild.
So, do we really need to support that? I think we've always supported a 64-bit block count, so we'll have to support that, but if a > 32bit extent count was always broken maybe we should simply stop to pretend to support it?
I'm in favor of that. The rextslog computation only got fixed in 6.8, which means none of the LTS kernels really have it yet. And the ones that do are migrating verrrrry slowly due to the global rtbmp lock.
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
What's the maximum valid rtg number? We're not ever going to be supporting 2^32 - 2 rtgs, so what is a realistic maximum we can cap this at and validate it at?
/me shrugs -- the smallest AG size on the data device is 16M, which technically speaking means that one /could/ format 2^(63-24) groups, or order 39.
Quoted 8 lines
Quoted 2 lines
Realistically with the maximum rtgroup size of 2^31 blocks, we probably only need 2^(63 - (31 + 10)) = 2^22 rtgroups max on a 1k fsblock fs.
Note that with zoned file system later on we are bound by hardware size. SMR HDDs by convention some with 256MB zones. This is a bit on the small side, but grouping multiple of those into a RT group would be a major pain. I hope the hardware size will eventually increase, maybe when they move to 3-digit TB capcity points.
<nod>
--D
PATCH 12/24 xfs: define locking primitives for realtime groups
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Define helper functions to lock all metadata inodes related to a realtime group. There's not much to look at now, but this will become important when we add per-rtgroup metadata files and online fsck code for them.
--- fs/xfs/libxfs/xfs_rtgroup.c | 49 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 16 ++++++++++++++ 2 files changed, 65 insertions(+)
fs/xfs/libxfs/xfs_rtgroup.c +49 -0
@@ -194,3 +194,52 @@ xfs_rtgroup_extents(ASSERT (xfs_has_rtgroups (mp));return mp->m_sb.sb_rgextents; } + +/* Lock metadata inodes associated with this rt group. */ +void +xfs_rtgroup_lock ( +struct xfs_rtgroup *rtg, +unsigned int rtglock_flags) +{ +ASSERT (!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS )); +ASSERT (!(rtglock_flags &XFS_RTGLOCK_BITMAP_SHARED ) || + !(rtglock_flags &XFS_RTGLOCK_BITMAP )); + +if (rtglock_flags &XFS_RTGLOCK_BITMAP ) +xfs_rtbitmap_lock (rtg->rtg_mount); +else if (rtglock_flags &XFS_RTGLOCK_BITMAP_SHARED ) +xfs_rtbitmap_lock_shared (rtg->rtg_mount,XFS_RBMLOCK_BITMAP ); +} + +/* Unlock metadata inodes associated with this rt group. */ +void +xfs_rtgroup_unlock ( +struct xfs_rtgroup *rtg, +unsigned int rtglock_flags) +{ +ASSERT (!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS )); +ASSERT (!(rtglock_flags &XFS_RTGLOCK_BITMAP_SHARED ) || + !(rtglock_flags &XFS_RTGLOCK_BITMAP )); + +if (rtglock_flags &XFS_RTGLOCK_BITMAP ) +xfs_rtbitmap_unlock (rtg->rtg_mount); +else if (rtglock_flags &XFS_RTGLOCK_BITMAP_SHARED ) +xfs_rtbitmap_unlock_shared (rtg->rtg_mount,XFS_RBMLOCK_BITMAP ); +} + +/* +* Join realtime group metadata inodes to the transaction. The ILOCKs will be +* released on transaction commit. +*/ +void +xfs_rtgroup_trans_join ( +struct xfs_trans *tp, +struct xfs_rtgroup *rtg, +unsigned int rtglock_flags) +{ +ASSERT (!(rtglock_flags & ~XFS_RTGLOCK_ALL_FLAGS )); +ASSERT (!(rtglock_flags &XFS_RTGLOCK_BITMAP_SHARED )); + +if (rtglock_flags &XFS_RTGLOCK_BITMAP ) +xfs_rtbitmap_trans_join (tp); +}
fs/xfs/libxfs/xfs_rtgroup.h +16 -0
@@ -205,8 +205,24 @@ xfs_daddr_to_rtb(#ifdef CONFIG_XFS_RT xfs_rtxnum_t xfs_rtgroup_extents (struct xfs_mount *mp,xfs_rgnumber_t rgno); + +/* Lock the rt bitmap inode in exclusive mode */ +#define XFS_RTGLOCK_BITMAP (1U << 0) +/* Lock the rt bitmap inode in shared mode */ +#define XFS_RTGLOCK_BITMAP_SHARED (1U << 1) + +#define XFS_RTGLOCK_ALL_FLAGS (XFS_RTGLOCK_BITMAP | \ + XFS_RTGLOCK_BITMAP_SHARED) + +void xfs_rtgroup_lock (struct xfs_rtgroup *rtg,unsigned int rtglock_flags); +void xfs_rtgroup_unlock (struct xfs_rtgroup *rtg,unsigned int rtglock_flags); +void xfs_rtgroup_trans_join (struct xfs_trans *tp,struct xfs_rtgroup *rtg, +unsigned int rtglock_flags);#else # define xfs_rtgroup_extents (mp, rgno) (0) +# define xfs_rtgroup_lock (rtg, gf) ((void)0) +# define xfs_rtgroup_unlock (rtg, gf) ((void)0) +# define xfs_rtgroup_trans_join (tp, rtg, gf) ((void)0)#endif /* CONFIG_XFS_RT */ #endif /* __LIBXFS_RTGROUP_H */
Re: [PATCH 12/24] xfs: define locking primitives for realtime groups
Looks good:
PATCH 13/24 xfs: add a lockdep class key for rtgroup inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add a dynamic lockdep class key for rtgroup inodes. This will enable lockdep to deduce inconsistencies in the rtgroup metadata ILOCK locking order. Each class can have 8 subclasses, and for now we will only have 2 inodes per group. This enables rtgroup order and inode order checks when nesting ILOCKs.
--- fs/xfs/libxfs/xfs_rtgroup.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
fs/xfs/libxfs/xfs_rtgroup.c +52 -0
@@ -243,3 +243,55 @@ xfs_rtgroup_trans_join(if (rtglock_flags &XFS_RTGLOCK_BITMAP )xfs_rtbitmap_trans_join (tp); } + +#ifdef CONFIG_PROVE_LOCKING +static struct lock_class_key xfs_rtginode_lock_class; + +static int +xfs_rtginode_ilock_cmp_fn ( +const struct lockdep_map *m1, +const struct lockdep_map *m2) +{ +const struct xfs_inode *ip1 = + container_of(m1, struct xfs_inode, i_lock.dep_map); +const struct xfs_inode *ip2 = + container_of(m2, struct xfs_inode, i_lock.dep_map); + +if (ip1->i_projid < ip2->i_projid) +return -1 ; +if (ip1->i_projid > ip2->i_projid) +return 1 ; +return 0 ; +} + +static inline void +xfs_rtginode_ilock_print_fn ( +const struct lockdep_map *m) +{ +const struct xfs_inode *ip = + container_of(m, struct xfs_inode, i_lock.dep_map); + +printk (KERN_CONT " rgno=%u" , ip->i_projid); +} + +/* +* Most of the time each of the RTG inode locks are only taken one at a time. +* But when committing deferred ops, more than one of a kind can be taken. +* However, deferred rt ops will be committed in rgno order so there is no +* potential for deadlocks. The code here is needed to tell lockdep about this +* order. +*/ +static inline void +xfs_rtginode_lockdep_setup ( +struct xfs_inode *ip, +xfs_rgnumber_t rgno, +enum xfs_rtg_inodes type) +{ +lockdep_set_class_and_subclass (&ip->i_lock, &xfs_rtginode_lock_class, + type); +lock_set_cmp_fn (&ip->i_lock, xfs_rtginode_ilock_cmp_fn, + xfs_rtginode_ilock_print_fn); +} +#else +#define xfs_rtginode_lockdep_setup (ip, rgno, type) do { } while (0) +#endif /* CONFIG_PROVE_LOCKING */
Re: [PATCH 13/24] xfs: add a lockdep class key for rtgroup inodes
Looks good:
Re: [PATCH 13/24] xfs: add a lockdep class key for rtgroup inodes
In reply to Darrick J. WongQuoted 32 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Add a dynamic lockdep class key for rtgroup inodes. This will enable lockdep to deduce inconsistencies in the rtgroup metadata ILOCK locking order. Each class can have 8 subclasses, and for now we will only have 2 inodes per group. This enables rtgroup order and inode order checks when nesting ILOCKs.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)fs/xfs/libxfs/xfs_rtgroup.c +10
-0@@ -243,3 +243,55 @@ xfs_rtgroup_trans_join(if (rtglock_flags &XFS_RTGLOCK_BITMAP )xfs_rtbitmap_trans_join (tp); } + +#ifdef CONFIG_PROVE_LOCKING +static struct lock_class_key xfs_rtginode_lock_class; + +static int +xfs_rtginode_ilock_cmp_fn ( +const struct lockdep_map *m1, +const struct lockdep_map *m2) +{ + const struct xfs_inode *ip1 =
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtgroup_trans_join( · line 265
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+ container_of(m1, struct xfs_inode, i_lock.dep_map); +const struct xfs_inode *ip2 = + container_of(m2, struct xfs_inode, i_lock.dep_map); + +if (ip1->i_projid < ip2->i_projid) +return -1 ; +if (ip1->i_projid > ip2->i_projid) +return 1 ; +return 0 ; +}
What's the project ID of the inode got to do with realtime groups?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 13/24] xfs: add a lockdep class key for rtgroup inodes
Quoted 37 lines · Dave Chinner
Quoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Add a dynamic lockdep class key for rtgroup inodes. This will enable lockdep to deduce inconsistencies in the rtgroup metadata ILOCK locking order. Each class can have 8 subclasses, and for now we will only have 2 inodes per group. This enables rtgroup order and inode order checks when nesting ILOCKs.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)fs/xfs/libxfs/xfs_rtgroup.c +14
-0@@ -243,3 +243,55 @@ xfs_rtgroup_trans_join(if (rtglock_flags &XFS_RTGLOCK_BITMAP )xfs_rtbitmap_trans_join (tp); } + +#ifdef CONFIG_PROVE_LOCKING +static struct lock_class_key xfs_rtginode_lock_class; + +static int +xfs_rtginode_ilock_cmp_fn ( +const struct lockdep_map *m1, +const struct lockdep_map *m2) +{ +const struct xfs_inode *ip1 = + container_of(m1, struct xfs_inode, i_lock.dep_map); +const struct xfs_inode *ip2 = + container_of(m2, struct xfs_inode, i_lock.dep_map); +
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtgroup_trans_join( · line 265
Quoted 6 lines
fs/xfs/libxfs/xfs_rtgroup.c +6
-0+if (ip1->i_projid < ip2->i_projid) +return -1 ; +if (ip1->i_projid > ip2->i_projid) +return 1 ; +return 0 ; +}What's the project ID of the inode got to do with realtime groups?
Each rtgroup metadata file stores its group number in i_projid so that mount can detect if there's a corruption in /rtgroup and we just opened the bitmap from the wrong group.
We can also use lockdep to detect code that locks rtgroup metadata in the wrong order. Potentially we could use this _cmp_fn to enforce that we always ILOCK in the order bitmap -> summary -> rmap -> refcount based on i_metatype.
--D
Quoted 5 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 13/24] xfs: add a lockdep class key for rtgroup inodes
Quoted 47 lines · Darrick J. Wong
Quoted 37 lines · Dave Chinner
Quoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Add a dynamic lockdep class key for rtgroup inodes. This will enable lockdep to deduce inconsistencies in the rtgroup metadata ILOCK locking order. Each class can have 8 subclasses, and for now we will only have 2 inodes per group. This enables rtgroup order and inode order checks when nesting ILOCKs.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)fs/xfs/libxfs/xfs_rtgroup.c +14
-0@@ -243,3 +243,55 @@ xfs_rtgroup_trans_join(if (rtglock_flags &XFS_RTGLOCK_BITMAP )xfs_rtbitmap_trans_join (tp); } + +#ifdef CONFIG_PROVE_LOCKING +static struct lock_class_key xfs_rtginode_lock_class; + +static int +xfs_rtginode_ilock_cmp_fn ( +const struct lockdep_map *m1, +const struct lockdep_map *m2) +{ +const struct xfs_inode *ip1 = + container_of(m1, struct xfs_inode, i_lock.dep_map); +const struct xfs_inode *ip2 = + container_of(m2, struct xfs_inode, i_lock.dep_map); +Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtgroup_trans_join( · line 265
Quoted 6 lines
fs/xfs/libxfs/xfs_rtgroup.c +6
-0+if (ip1->i_projid < ip2->i_projid) +return -1 ; +if (ip1->i_projid > ip2->i_projid) +return 1 ; +return 0 ; +}What's the project ID of the inode got to do with realtime groups?
Quoted 8 lines
Each rtgroup metadata file stores its group number in
i_projidso that mount can detect if there's a corruption in /rtgroup and we just opened the bitmap from the wrong group.We can also use lockdep to detect code that locks rtgroup metadata in the wrong order. Potentially we could use this
_cmp_fnto enforce that we always ILOCK in the order bitmap -> summary -> rmap -> refcount based oni_metatype.
Ok, can we union the i_projid field (both in memory and in the on-disk structure) so that dual use of the field is well documented by the code?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 13/24] xfs: add a lockdep class key for rtgroup inodes
Quoted 52 lines · Dave Chinner
Quoted 51 lines · Darrick J. Wong
Quoted 37 lines · Dave Chinner
Quoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Add a dynamic lockdep class key for rtgroup inodes. This will enable lockdep to deduce inconsistencies in the rtgroup metadata ILOCK locking order. Each class can have 8 subclasses, and for now we will only have 2 inodes per group. This enables rtgroup order and inode order checks when nesting ILOCKs.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)fs/xfs/libxfs/xfs_rtgroup.c +14
-0@@ -243,3 +243,55 @@ xfs_rtgroup_trans_join(if (rtglock_flags &XFS_RTGLOCK_BITMAP )xfs_rtbitmap_trans_join (tp); } + +#ifdef CONFIG_PROVE_LOCKING +static struct lock_class_key xfs_rtginode_lock_class; + +static int +xfs_rtginode_ilock_cmp_fn ( +const struct lockdep_map *m1, +const struct lockdep_map *m2) +{ +const struct xfs_inode *ip1 = + container_of(m1, struct xfs_inode, i_lock.dep_map); +const struct xfs_inode *ip2 = + container_of(m2, struct xfs_inode, i_lock.dep_map); +Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtgroup_trans_join( · line 265
Quoted 6 lines
fs/xfs/libxfs/xfs_rtgroup.c +6
-0+if (ip1->i_projid < ip2->i_projid) +return -1 ; +if (ip1->i_projid > ip2->i_projid) +return 1 ; +return 0 ; +}What's the project ID of the inode got to do with realtime groups?
Each rtgroup metadata file stores its group number in
i_projidso that mount can detect if there's a corruption in /rtgroup and we just opened the bitmap from the wrong group.
Quoted 8 lines
Quoted 4 lines
We can also use lockdep to detect code that locks rtgroup metadata in the wrong order. Potentially we could use this
_cmp_fnto enforce that we always ILOCK in the order bitmap -> summary -> rmap -> refcount based oni_metatype.Ok, can we union the
i_projidfield (both in memory and in the on-disk structure) so that dual use of the field is well documented by the code?
Sounds good to me. Does
union {
xfs_prid_t i_projid;
uint32_t i_metagroup;
};sound ok?
--D
Quoted 4 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 13/24] xfs: add a lockdep class key for rtgroup inodes
Quoted 62 lines · Darrick J. Wong
Quoted 52 lines · Dave Chinner
Quoted 51 lines · Darrick J. Wong
Quoted 37 lines · Dave Chinner
Quoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Add a dynamic lockdep class key for rtgroup inodes. This will enable lockdep to deduce inconsistencies in the rtgroup metadata ILOCK locking order. Each class can have 8 subclasses, and for now we will only have 2 inodes per group. This enables rtgroup order and inode order checks when nesting ILOCKs.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)fs/xfs/libxfs/xfs_rtgroup.c +14
-0@@ -243,3 +243,55 @@ xfs_rtgroup_trans_join(if (rtglock_flags &XFS_RTGLOCK_BITMAP )xfs_rtbitmap_trans_join (tp); } + +#ifdef CONFIG_PROVE_LOCKING +static struct lock_class_key xfs_rtginode_lock_class; + +static int +xfs_rtginode_ilock_cmp_fn ( +const struct lockdep_map *m1, +const struct lockdep_map *m2) +{ +const struct xfs_inode *ip1 = + container_of(m1, struct xfs_inode, i_lock.dep_map); +const struct xfs_inode *ip2 = + container_of(m2, struct xfs_inode, i_lock.dep_map); +Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtgroup_trans_join( · line 265
Quoted 6 lines
fs/xfs/libxfs/xfs_rtgroup.c +6
-0+if (ip1->i_projid < ip2->i_projid) +return -1 ; +if (ip1->i_projid > ip2->i_projid) +return 1 ; +return 0 ; +}What's the project ID of the inode got to do with realtime groups?
Each rtgroup metadata file stores its group number in
i_projidso that mount can detect if there's a corruption in /rtgroup and we just opened the bitmap from the wrong group.Quoted 8 lines
Quoted 4 lines
We can also use lockdep to detect code that locks rtgroup metadata in the wrong order. Potentially we could use this
_cmp_fnto enforce that we always ILOCK in the order bitmap -> summary -> rmap -> refcount based oni_metatype.Ok, can we union the
i_projidfield (both in memory and in the on-disk structure) so that dual use of the field is well documented by the code?
Quoted 8 lines
Sounds good to me. Does
union { xfs_prid_t i_projid; uint32_t i_metagroup; };sound ok?
Yup.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 14/24 xfs: support caching rtgroup metadata inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory.
--- fs/xfs/libxfs/xfs_rtgroup.c | 182 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 28 +++++++ fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 48 +++++++++++ 4 files changed, 258 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_rtgroup.c +182 -0
@@ -30,6 +30,8 @@#include "xfs_icache.h" #include "xfs_rtgroup.h" #include "xfs_rtbitmap.h" +#include "xfs_metafile.h" +#include "xfs_metadir.h" /* * Passive reference counting access wrappers to the rtgroup structures. If
@@ -295,3 +297,183 @@ xfs_rtginode_lockdep_setup(#else #define xfs_rtginode_lockdep_setup (ip, rgno, type) do { } while (0)#endif /* CONFIG_PROVE_LOCKING */ + +struct xfs_rtginode_ops { +const char *name;/* short name */ + +enum xfs_metafile_type metafile_type; + +/* Does the fs have this feature? */ +bool (*enabled)(struct xfs_mount *mp); + +/* Create this rtgroup metadata inode and initialize it. */ +int (*create)(struct xfs_rtgroup *rtg, +struct xfs_inode *ip, +struct xfs_trans *tp, +bool init); +}; + +static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX ] = { +}; + +/* Return the shortname of this rtgroup inode. */ +const char * +xfs_rtginode_name ( +enum xfs_rtg_inodes type) +{ +return xfs_rtginode_ops[type].name; +} + +/* Should this rtgroup inode be present? */ +bool +xfs_rtginode_enabled ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type) +{ +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; + +if (!ops->enabled) +return true; +return ops->enabled (rtg->rtg_mount); +} + +/* Load and existing rtgroup inode into the rtgroup structure. */ +int +xfs_rtginode_load ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type, +struct xfs_trans *tp) +{ +struct xfs_mount *mp = tp->t_mountp; +const char *path; +struct xfs_inode *ip; +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; +int error; + +if (!xfs_rtginode_enabled (rtg, type)) +return 0 ; + +if (!mp->m_rtdirip) +return -EFSCORRUPTED ; + + path =xfs_rtginode_path (rtg->rtg_rgno, type); +if (!path) +return -ENOMEM ; + error =xfs_metadir_load (tp, mp->m_rtdirip, path, ops->metafile_type, + &ip); +kfree (path); + +if (error) +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); +return -EFSCORRUPTED ; + } + +if (XFS_IS_CORRUPT (mp, ip->i_projid != rtg->rtg_rgno)) { +xfs_irele (ip); +return -EFSCORRUPTED ; + } + +xfs_rtginode_lockdep_setup (ip, rtg->rtg_rgno, type); + rtg->rtg_inodes[type] = ip; +return 0 ; +} + +/* Release an rtgroup metadata inode. */ +void +xfs_rtginode_irele ( +struct xfs_inode **ipp) +{ +if (*ipp) +xfs_irele (*ipp); + *ipp =NULL ; +} + +/* Add a metadata inode for a realtime rmap btree. */ +int +xfs_rtginode_create ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type, +bool init) +{ +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; +struct xfs_mount *mp = rtg->rtg_mount; +struct xfs_metadir_update upd = { + .dp = mp->m_rtdirip, + .metafile_type = ops->metafile_type, + }; +int error; + +if (!xfs_rtginode_enabled (rtg, type)) +return 0 ; + +if (!mp->m_rtdirip) +return -EFSCORRUPTED ; + + upd.path =xfs_rtginode_path (rtg->rtg_rgno, type); +if (!upd.path) +return -ENOMEM ; + + error =xfs_metadir_start_create (&upd); +if (error) + goto out_path; + + error =xfs_metadir_create (&upd,S_IFREG ); +if (error) +return error; + +xfs_rtginode_lockdep_setup (upd.ip, rtg->rtg_rgno, type); + + upd.ip->i_projid = rtg->rtg_rgno; + error = ops->create (rtg, upd.ip, upd.tp, init); +if (error) + goto out_cancel; + + error =xfs_metadir_commit (&upd); +if (error) + goto out_path; + +kfree (upd.path); +xfs_finish_inode_setup (upd.ip); + rtg->rtg_inodes[type] = upd.ip; +return 0 ; + +out_cancel: +xfs_metadir_cancel (&upd, error); +/* Have to finish setting up the inode to ensure it's deleted. */ +if (upd.ip) { +xfs_finish_inode_setup (upd.ip); +xfs_irele (upd.ip); + } +out_path: +kfree (upd.path); +return error; +} + +/* Create the parent directory for all rtgroup inodes and load it. */ +int +xfs_rtginode_mkdir_parent ( +struct xfs_mount *mp) +{ +if (!mp->m_metadirip) +return -EFSCORRUPTED ; + +return xfs_metadir_mkdir (mp->m_metadirip,"rtgroups" , &mp->m_rtdirip); +} + +/* Load the parent directory of all rtgroup inodes. */ +int +xfs_rtginode_load_parent ( +struct xfs_trans *tp) +{ +struct xfs_mount *mp = tp->t_mountp; + +if (!mp->m_metadirip) +return -EFSCORRUPTED ; + +return xfs_metadir_load (tp, mp->m_metadirip,"rtgroups" , +XFS_METAFILE_DIR , &mp->m_rtdirip); +}
fs/xfs/libxfs/xfs_rtgroup.h +28 -0
@@ -9,6 +9,14 @@struct xfs_mount ;struct xfs_trans ; +enum xfs_rtg_inodes { +XFS_RTGI_MAX , +}; + +#ifdef MAX_LOCKDEP_SUBCLASSES +static_assert (XFS_RTGI_MAX <=MAX_LOCKDEP_SUBCLASSES ); +#endif +/* * Realtime group incore structure, similar to the per-AG structure. */
@@ -19,6 +27,9 @@ struct xfs_rtgroup {atomic_t rtg_active_ref;/* active reference count */ wait_queue_head_t rtg_active_wq;/* woken active_ref falls to zero */ +/* per-rtgroup metadata inodes */ +struct xfs_inode *rtg_inodes[1 /* hack */ ]; +/* Number of blocks in this group */ xfs_rtxnum_t rtg_extents;
@@ -218,6 +229,23 @@ void xfs_rtgroup_lock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);void xfs_rtgroup_unlock (struct xfs_rtgroup *rtg,unsigned int rtglock_flags);void xfs_rtgroup_trans_join (struct xfs_trans *tp,struct xfs_rtgroup *rtg,unsigned int rtglock_flags); + +int xfs_rtginode_mkdir_parent (struct xfs_mount *mp); +int xfs_rtginode_load_parent (struct xfs_trans *tp); + +const char *xfs_rtginode_name (enum xfs_rtg_inodes type); +bool xfs_rtginode_enabled (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type); +int xfs_rtginode_load (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type, +struct xfs_trans *tp); +int xfs_rtginode_create (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type, +bool init); +void xfs_rtginode_irele (struct xfs_inode **ipp); + +static inline const char *xfs_rtginode_path (xfs_rgnumber_t rgno, +enum xfs_rtg_inodes type) +{ +return kasprintf (GFP_KERNEL ,"%u.%s" , rgno,xfs_rtginode_name (type)); +}#else # define xfs_rtgroup_extents (mp, rgno) (0)# define xfs_rtgroup_lock (rtg, gf) ((void)0)
fs/xfs/xfs_mount.h +1 -0
@@ -94,6 +94,7 @@ typedef struct xfs_mount {struct xfs_inode *m_rsumip;/* pointer to summary inode */ struct xfs_inode *m_rootip;/* pointer to root directory */ struct xfs_inode *m_metadirip;/* ptr to metadata directory */ +struct xfs_inode *m_rtdirip;/* ptr to realtime metadir */ struct xfs_quotainfo *m_quotainfo;/* disk quota information */ struct xfs_buftarg *m_ddev_targp;/* data device */ struct xfs_buftarg *m_logdev_targp;/* log device */
fs/xfs/xfs_rtalloc.c +47 -1
92 lines not on this page · raw message
Re: [PATCH 14/24] xfs: support caching rtgroup metadata inodes
Looks good:
Re: [PATCH 14/24] xfs: support caching rtgroup metadata inodes
In reply to Darrick J. WongQuoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 182 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 28 +++++++ fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 48 +++++++++++ 4 files changed, 258 insertions(+), 1 deletion(-)fs/xfs/libxfs/xfs_rtgroup.c +7
-0@@ -30,6 +30,8 @@#include "xfs_icache.h" #include "xfs_rtgroup.h" #include "xfs_rtbitmap.h" +#include "xfs_metafile.h" +#include "xfs_metadir.h" /* * Passive reference counting access wrappers to the rtgroup structures. If @@ -295,3 +297,183 @@ xfs_rtginode_lockdep_setup(#else #define xfs_rtginode_lockdep_setup (ip, rgno, type) do { } while (0)#endif /* CONFIG_PROVE_LOCKING */ + +struct xfs_rtginode_ops { +const char *name;/* short name */ + +enum xfs_metafile_type metafile_type;
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 314
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+ +/* Does the fs have this feature? */ +bool (*enabled)(struct xfs_mount *mp); + +/* Create this rtgroup metadata inode and initialize it. */ +int (*create)(struct xfs_rtgroup *rtg, +struct xfs_inode *ip, +struct xfs_trans *tp, +bool init); +};
What's all this for?
AFAICT, loading the inodes into the rtgs requires a call to xfs_metadir_load() when initialising the rtg (either at mount or lazily on the first access to the rtg). Hence I'm not really sure what this complexity is needed for, and the commit message is not very informative....
Quoted 48 lines
fs/xfs/libxfs/xfs_rtgroup.c +48
-0+static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX ] = { +}; + +/* Return the shortname of this rtgroup inode. */ +const char * +xfs_rtginode_name ( +enum xfs_rtg_inodes type) +{ +return xfs_rtginode_ops[type].name; +} + +/* Should this rtgroup inode be present? */ +bool +xfs_rtginode_enabled ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type) +{ +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; + +if (!ops->enabled) +return true; +return ops->enabled (rtg->rtg_mount); +} + +/* Load and existing rtgroup inode into the rtgroup structure. */ +int +xfs_rtginode_load ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type, +struct xfs_trans *tp) +{ +struct xfs_mount *mp = tp->t_mountp; +const char *path; +struct xfs_inode *ip; +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; +int error; + +if (!xfs_rtginode_enabled (rtg, type)) +return 0 ; + +if (!mp->m_rtdirip) +return -EFSCORRUPTED ; + + path =xfs_rtginode_path (rtg->rtg_rgno, type); +if (!path) +return -ENOMEM ; + error =xfs_metadir_load (tp, mp->m_rtdirip, path, ops->metafile_type, + &ip);
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 373
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+kfree (path); + +if (error) +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); +return -EFSCORRUPTED ; + }
We don't support LOCAL format for any type of regular file inodes, so I'm a little confiused as to why this wouldn't be caught by the verifier on inode read? i.e. What problem is this trying to catch, and why doesn't the inode verifier catch it for us?
Quoted 16 lines
fs/xfs/libxfs/xfs_rtgroup.c +16
-0+if (XFS_IS_CORRUPT (mp, ip->i_projid != rtg->rtg_rgno)) { +xfs_irele (ip); +return -EFSCORRUPTED ; + } + +xfs_rtginode_lockdep_setup (ip, rtg->rtg_rgno, type); + rtg->rtg_inodes[type] = ip; +return 0 ; +} + +/* Release an rtgroup metadata inode. */ +void +xfs_rtginode_irele ( +struct xfs_inode **ipp) +{ +if (*ipp)
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 400
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+xfs_irele (*ipp); + *ipp =NULL ; +} + +/* Add a metadata inode for a realtime rmap btree. */ +int +xfs_rtginode_create ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type, +bool init)
This doesn't seem to belong in this patchset...
....
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 459
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.c +4
-0+/* Create the parent directory for all rtgroup inodes and load it. */ +int +xfs_rtginode_mkdir_parent ( +struct xfs_mount *mp)
Or this...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 14/24] xfs: support caching rtgroup metadata inodes
Quoted 50 lines · Dave Chinner
Quoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 182 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 28 +++++++ fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 48 +++++++++++ 4 files changed, 258 insertions(+), 1 deletion(-)fs/xfs/libxfs/xfs_rtgroup.c +7
-0@@ -30,6 +30,8 @@#include "xfs_icache.h" #include "xfs_rtgroup.h" #include "xfs_rtbitmap.h" +#include "xfs_metafile.h" +#include "xfs_metadir.h" /* * Passive reference counting access wrappers to the rtgroup structures. If @@ -295,3 +297,183 @@ xfs_rtginode_lockdep_setup(#else #define xfs_rtginode_lockdep_setup (ip, rgno, type) do { } while (0)#endif /* CONFIG_PROVE_LOCKING */ + +struct xfs_rtginode_ops { +const char *name;/* short name */ + +enum xfs_metafile_type metafile_type;fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 314
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+ +/* Does the fs have this feature? */ +bool (*enabled)(struct xfs_mount *mp); + +/* Create this rtgroup metadata inode and initialize it. */ +int (*create)(struct xfs_rtgroup *rtg, +struct xfs_inode *ip, +struct xfs_trans *tp, +bool init); +};What's all this for?
Quoted 5 lines
AFAICT, loading the inodes into the rtgs requires a call to
xfs_metadir_load()when initialising the rtg (either at mount or lazily on the first access to the rtg). Hence I'm not really sure what this complexity is needed for, and the commit message is not very informative....
Yes, the creation and mkdir code in here is really to support growfs, mkfs, and repair. How about I change the commit message to:
"Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory and to create directory trees on the fly. Loading is needed by the mounting process. Creation is needed by growfs, mkfs, and repair."
Quoted 55 lines
Quoted 55 lines
fs/xfs/libxfs/xfs_rtgroup.c +55
-0+static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX ] = { +}; + +/* Return the shortname of this rtgroup inode. */ +const char * +xfs_rtginode_name ( +enum xfs_rtg_inodes type) +{ +return xfs_rtginode_ops[type].name; +} + +/* Should this rtgroup inode be present? */ +bool +xfs_rtginode_enabled ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type) +{ +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; + +if (!ops->enabled) +return true; +return ops->enabled (rtg->rtg_mount); +} + +/* Load and existing rtgroup inode into the rtgroup structure. */ +int +xfs_rtginode_load ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type, +struct xfs_trans *tp) +{ +struct xfs_mount *mp = tp->t_mountp; +const char *path; +struct xfs_inode *ip; +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; +int error; + +if (!xfs_rtginode_enabled (rtg, type)) +return 0 ; + +if (!mp->m_rtdirip) +return -EFSCORRUPTED ; + + path =xfs_rtginode_path (rtg->rtg_rgno, type); +if (!path) +return -ENOMEM ; + error =xfs_metadir_load (tp, mp->m_rtdirip, path, ops->metafile_type, + &ip); +kfree (path); + +if (error) +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 )) {
Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 373
Quoted 3 lines
fs/xfs/libxfs/xfs_rtgroup.c +3
-0+xfs_irele (ip); +return -EFSCORRUPTED ; + }We don't support LOCAL format for any type of regular file inodes, so I'm a little confiused as to why this wouldn't be caught by the verifier on inode read? i.e. What problem is this trying to catch, and why doesn't the inode verifier catch it for us?
This is really more of a placeholder for more refactorings coming down the line for the rtrmap patchset, which will create a new XFS_DINODE_FMT_RMAP. At that time we'll need to check that an inode that we are loading to be the rmap btree actually has that set.
Quoted 44 lines
Quoted 16 lines
fs/xfs/libxfs/xfs_rtgroup.c +16
-0+if (XFS_IS_CORRUPT (mp, ip->i_projid != rtg->rtg_rgno)) { +xfs_irele (ip); +return -EFSCORRUPTED ; + } + +xfs_rtginode_lockdep_setup (ip, rtg->rtg_rgno, type); + rtg->rtg_inodes[type] = ip; +return 0 ; +} + +/* Release an rtgroup metadata inode. */ +void +xfs_rtginode_irele ( +struct xfs_inode **ipp) +{ +if (*ipp)fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 400
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+xfs_irele (*ipp); + *ipp =NULL ; +} + +/* Add a metadata inode for a realtime rmap btree. */ +int +xfs_rtginode_create ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type, +bool init)This doesn't seem to belong in this patchset...
....
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 459
Quoted 4 lines
fs/xfs/libxfs/xfs_rtgroup.c +4
-0+/* Create the parent directory for all rtgroup inodes and load it. */ +int +xfs_rtginode_mkdir_parent ( +struct xfs_mount *mp)Or this...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 14/24] xfs: support caching rtgroup metadata inodes
Quoted 57 lines · Darrick J. Wong
Quoted 50 lines · Dave Chinner
Quoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 182 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 28 +++++++ fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 48 +++++++++++ 4 files changed, 258 insertions(+), 1 deletion(-)fs/xfs/libxfs/xfs_rtgroup.c +7
-0@@ -30,6 +30,8 @@#include "xfs_icache.h" #include "xfs_rtgroup.h" #include "xfs_rtbitmap.h" +#include "xfs_metafile.h" +#include "xfs_metadir.h" /* * Passive reference counting access wrappers to the rtgroup structures. If @@ -295,3 +297,183 @@ xfs_rtginode_lockdep_setup(#else #define xfs_rtginode_lockdep_setup (ip, rgno, type) do { } while (0)#endif /* CONFIG_PROVE_LOCKING */ + +struct xfs_rtginode_ops { +const char *name;/* short name */ + +enum xfs_metafile_type metafile_type;fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 314
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+ +/* Does the fs have this feature? */ +bool (*enabled)(struct xfs_mount *mp); + +/* Create this rtgroup metadata inode and initialize it. */ +int (*create)(struct xfs_rtgroup *rtg, +struct xfs_inode *ip, +struct xfs_trans *tp, +bool init); +};What's all this for?
Quoted 5 lines
AFAICT, loading the inodes into the rtgs requires a call to
xfs_metadir_load()when initialising the rtg (either at mount or lazily on the first access to the rtg). Hence I'm not really sure what this complexity is needed for, and the commit message is not very informative....
Quoted 7 lines
Yes, the creation and mkdir code in here is really to support growfs, mkfs, and repair. How about I change the commit message to:
"Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory and to create directory trees on the fly. Loading is needed by the mounting process. Creation is needed by growfs, mkfs, and repair."
IMO it would have been nicer to add this with the patch that adds growfs support for rtgs. That way the initial inode loading would be much easier to understand and review, and the rest of it would have enough context to be able to review it sanely. There isn't enough context in this patch to determine if the creation code is sane or works correctly....
Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
fs/xfs/libxfs/xfs_rtgroup.c +12
-0+ path =xfs_rtginode_path (rtg->rtg_rgno, type); +if (!path) +return -ENOMEM ; + error =xfs_metadir_load (tp, mp->m_rtdirip, path, ops->metafile_type, + &ip); +kfree (path); + +if (error) +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 )) {Quoted 8 lines
fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 373
Quoted 3 lines
fs/xfs/libxfs/xfs_rtgroup.c +3
-0+xfs_irele (ip); +return -EFSCORRUPTED ; + }We don't support LOCAL format for any type of regular file inodes, so I'm a little confiused as to why this wouldn't be caught by the verifier on inode read? i.e. What problem is this trying to catch, and why doesn't the inode verifier catch it for us?
Quoted 4 lines
This is really more of a placeholder for more refactorings coming down the line for the rtrmap patchset, which will create a new
XFS_DINODE_FMT_RMAP. At that time we'll need to check that an inode that we are loading to be the rmap btree actually has that set.
Ok, can you leave a comment to indicate this so I don't have to remember why this code exists?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 14/24] xfs: support caching rtgroup metadata inodes
Quoted 66 lines · Dave Chinner
Quoted 57 lines · Darrick J. Wong
Quoted 50 lines · Dave Chinner
Quoted 36 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_rtgroup.c | 182 +++++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 28 +++++++ fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 48 +++++++++++ 4 files changed, 258 insertions(+), 1 deletion(-)fs/xfs/libxfs/xfs_rtgroup.c +7
-0@@ -30,6 +30,8 @@#include "xfs_icache.h" #include "xfs_rtgroup.h" #include "xfs_rtbitmap.h" +#include "xfs_metafile.h" +#include "xfs_metadir.h" /* * Passive reference counting access wrappers to the rtgroup structures. If @@ -295,3 +297,183 @@ xfs_rtginode_lockdep_setup(#else #define xfs_rtginode_lockdep_setup (ip, rgno, type) do { } while (0)#endif /* CONFIG_PROVE_LOCKING */ + +struct xfs_rtginode_ops { +const char *name;/* short name */ + +enum xfs_metafile_type metafile_type;fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 314
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+ +/* Does the fs have this feature? */ +bool (*enabled)(struct xfs_mount *mp); + +/* Create this rtgroup metadata inode and initialize it. */ +int (*create)(struct xfs_rtgroup *rtg, +struct xfs_inode *ip, +struct xfs_trans *tp, +bool init); +};What's all this for?
Quoted 5 lines
AFAICT, loading the inodes into the rtgs requires a call to
xfs_metadir_load()when initialising the rtg (either at mount or lazily on the first access to the rtg). Hence I'm not really sure what this complexity is needed for, and the commit message is not very informative....Quoted 7 lines
Yes, the creation and mkdir code in here is really to support growfs, mkfs, and repair. How about I change the commit message to:
"Create the necessary per-rtgroup infrastructure that we need to load metadata inodes into memory and to create directory trees on the fly. Loading is needed by the mounting process. Creation is needed by growfs, mkfs, and repair."
Quoted 6 lines
IMO it would have been nicer to add this with the patch that adds growfs support for rtgs. That way the initial inode loading would be much easier to understand and review, and the rest of it would have enough context to be able to review it sanely. There isn't enough context in this patch to determine if the creation code is sane or works correctly....
<nod> I think that's doable. I also want to change the name to ->init_inode because that's the only thing it can really do at the point that we're creating inodes in growfs.
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_rtgroup.c +5
-0+ path =xfs_rtginode_path (rtg->rtg_rgno, type); +if (!path) +return -ENOMEM ; + error =xfs_metadir_load (tp, mp->m_rtdirip, path, ops->metafile_type, + &ip);fs/xfs/libxfs/xfs_rtgroup.c xfs_rtginode_lockdep_setup( · line 373
Quoted 10 lines
fs/xfs/libxfs/xfs_rtgroup.c +10
-0+kfree (path); + +if (error) +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); +return -EFSCORRUPTED ; + }We don't support LOCAL format for any type of regular file inodes, so I'm a little confiused as to why this wouldn't be caught by the verifier on inode read? i.e. What problem is this trying to catch, and why doesn't the inode verifier catch it for us?
Quoted 7 lines
Quoted 4 lines
This is really more of a placeholder for more refactorings coming down the line for the rtrmap patchset, which will create a new
XFS_DINODE_FMT_RMAP. At that time we'll need to check that an inode that we are loading to be the rmap btree actually has that set.Ok, can you leave a comment to indicate this so I don't have to remember why this code exists?
Will do.
--D
Quoted 4 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 15/24 xfs: add rtgroup-based realtime scrubbing context management
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a pair of helpers to deal with setting up the necessary incore context to check metadata records against the realtime metadata. Right now this is limited to locking the realtime bitmap and summary inodes, but as we add rmap and reflink to the realtime device this will grow to include btree cursors.
--- fs/xfs/scrub/common.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/common.h | 30 +++++++++++++++++++ fs/xfs/scrub/scrub.c | 29 ++++++++++++++++++ fs/xfs/scrub/scrub.h | 13 ++++++++ 4 files changed, 150 insertions(+)
fs/xfs/scrub/common.c +78 -0
@@ -34,6 +34,7 @@#include "xfs_quota.h" #include "xfs_exchmaps.h" #include "xfs_rtbitmap.h" +#include "xfs_rtgroup.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h"
@@ -121,6 +122,17 @@ xchk_process_error( XFS_SCRUB_OFLAG_CORRUPT, __return_address); } +bool +xchk_process_rt_error ( +struct xfs_scrub *sc, +xfs_rgnumber_t rgno, +xfs_rgblock_t rgbno, +int *error) +{ +return __xchk_process_error (sc, rgno, rgbno, error, +XFS_SCRUB_OFLAG_CORRUPT , __return_address); +} + bool xchk_xref_process_error( struct xfs_scrub *sc,
@@ -684,6 +696,72 @@ xchk_ag_init(return 0 ; } +#ifdef CONFIG_XFS_RT +/* +* For scrubbing a realtime group, grab all the in-core resources we'll need to +* check the metadata, which means taking the ILOCK of the realtime group's +* metadata inodes. Callers must not join these inodes to the transaction with +* non-zero lockflags or concurrency problems will result. The @rtglock_flags +* argument takes XFS_RTGLOCK_* flags. +*/ +int +xchk_rtgroup_init ( +struct xfs_scrub *sc, +xfs_rgnumber_t rgno, +struct xchk_rt *sr) +{ +ASSERT (sr->rtg ==NULL ); +ASSERT (sr->rtlock_flags ==0 ); + + sr->rtg =xfs_rtgroup_get (sc->mp, rgno); +if (!sr->rtg) +return -ENOENT ; +return 0 ; +} + +void +xchk_rtgroup_lock ( +struct xchk_rt *sr, +unsigned int rtglock_flags) +{ +xfs_rtgroup_lock (sr->rtg, rtglock_flags); + sr->rtlock_flags = rtglock_flags; +} + +/* +* Unlock the realtime group. This must be done /after/ committing (or +* cancelling) the scrub transaction. +*/ +static void +xchk_rtgroup_unlock ( +struct xchk_rt *sr) +{ +ASSERT (sr->rtg !=NULL ); + +if (sr->rtlock_flags) { +xfs_rtgroup_unlock (sr->rtg, sr->rtlock_flags); + sr->rtlock_flags =0 ; + } +} + +/* +* Unlock the realtime group and release its resources. This must be done +* /after/ committing (or cancelling) the scrub transaction. +*/ +void +xchk_rtgroup_free ( +struct xfs_scrub *sc, +struct xchk_rt *sr) +{ +ASSERT (sr->rtg !=NULL ); + +xchk_rtgroup_unlock (sr); + +xfs_rtgroup_put (sr->rtg); + sr->rtg =NULL ; +} +#endif /* CONFIG_XFS_RT */ +/* Per-scrubber setup functions */ void
fs/xfs/scrub/common.h +30 -0
@@ -12,6 +12,8 @@ void xchk_trans_cancel(struct xfs_scrub *sc);bool xchk_process_error (struct xfs_scrub *sc,xfs_agnumber_t agno,xfs_agblock_t bno,int *error); +bool xchk_process_rt_error (struct xfs_scrub *sc,xfs_rgnumber_t rgno, +xfs_rgblock_t rgbno,int *error);bool xchk_fblock_process_error (struct xfs_scrub *sc,int whichfork,xfs_fileoff_t offset,int *error);
@@ -118,6 +120,34 @@ xchk_ag_init_existing(return error == -ENOENT ? -EFSCORRUPTED : error; } +#ifdef CONFIG_XFS_RT + +/* All the locks we need to check an rtgroup. */ +#define XCHK_RTGLOCK_ALL (XFS_RTGLOCK_BITMAP) + +int xchk_rtgroup_init (struct xfs_scrub *sc,xfs_rgnumber_t rgno, +struct xchk_rt *sr); + +static inline int +xchk_rtgroup_init_existing ( +struct xfs_scrub *sc, +xfs_rgnumber_t rgno, +struct xchk_rt *sr) +{ +int error =xchk_rtgroup_init (sc, rgno, sr); + +return error == -ENOENT ? -EFSCORRUPTED : error; +} + +void xchk_rtgroup_lock (struct xchk_rt *sr,unsigned int rtglock_flags); +void xchk_rtgroup_free (struct xfs_scrub *sc,struct xchk_rt *sr); +#else +# define xchk_rtgroup_init (sc, rgno, sr) (-EFSCORRUPTED) +# define xchk_rtgroup_init_existing (sc, rgno, sr) (-EFSCORRUPTED) +# define xchk_rtgroup_lock (sc, lockflags) do { } while (0) +# define xchk_rtgroup_free (sc, sr) do { } while (0) +#endif /* CONFIG_XFS_RT */ +int xchk_ag_read_headers (struct xfs_scrub *sc,xfs_agnumber_t agno,struct xchk_ag *sa);void xchk_ag_btcur_free (struct xchk_ag *sa);
fs/xfs/scrub/scrub.c +29 -0
@@ -225,6 +225,8 @@ xchk_teardown(xfs_trans_cancel (sc->tp); sc->tp =NULL ; } +if (sc->sr.rtg) +xchk_rtgroup_free (sc, &sc->sr);if (sc->ip) {if (sc->ilock_flags)xchk_iunlock (sc, sc->ilock_flags);
@@ -498,6 +500,33 @@ xchk_validate_inputs(break ;case ST_GENERIC :break ; +case ST_RTGROUP : +if (sm->sm_ino || sm->sm_gen) + goto out; +if (xfs_has_rtgroups (mp)) { +/* +* On a rtgroups filesystem, there won't be an rtbitmap +* or rtsummary file for group 0 unless there's +* actually a realtime volume attached. However, older +* xfs_scrub always calls the rtbitmap/rtsummary +* scrubbers with sm_agno==0 so transform the error +* code to ENOENT. +*/ +if (sm->sm_agno >= mp->m_sb.sb_rgcount) { +if (sm->sm_agno ==0 ) + error = -ENOENT ; + goto out; + } + }else { +/* +* Prior to rtgroups, the rtbitmap/rtsummary scrubbers +* accepted sm_agno==0, so we still accept that for +* scrubbing pre-rtgroups filesystems. +*/ +if (sm->sm_agno !=0 ) + goto out; + } +break ;default : goto out; }
fs/xfs/scrub/scrub.h +13 -0
@@ -74,6 +74,7 @@ enum xchk_type {ST_FS ,/* per-FS metadata */ ST_INODE ,/* per-inode metadata */ ST_GENERIC ,/* determined by the scrubber */ + ST_RTGROUP, /* rtgroup metadata */ }; struct xchk_meta_ops {
@@ -118,6 +119,15 @@ struct xchk_ag {struct xfs_btree_cur *refc_cur; }; +/* Inode lock state for the RT volume. */ +struct xchk_rt { +/* incore rtgroup, if applicable */ +struct xfs_rtgroup *rtg; + +/* XFS_RTGLOCK_* lock state if locked */ +unsigned int rtlock_flags; +}; +struct xfs_scrub {/* General scrub state. */ struct xfs_mount *mp;
@@ -179,6 +189,9 @@ struct xfs_scrub {/* State tracking for single-AG operations. */ struct xchk_ag sa; + +/* State tracking for realtime operations. */ +struct xchk_rt sr; };/* XCHK state flags grow up from zero, XREP state flags grown down from 2^31 */
Re: [PATCH 15/24] xfs: add rtgroup-based realtime scrubbing context management
Looks good:
PATCH 16/24 xfs: move RT bitmap and summary information to the rtgroup
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Move the pointers to the RT bitmap and summary inodes as well as the summary cache to the rtgroups structure to prepare for having a separate bitmap and summary inodes for each rtgroup.
Code using the inodes now needs to operate on a rtgroup. Where easily possible such code is converted to iterate over all rtgroups, else rtgroup 0 (the only one that can currently exist) is hardcoded.
--- fs/xfs/libxfs/xfs_bmap.c | 40 +++- fs/xfs/libxfs/xfs_rtbitmap.c | 174 ++++++++-------- fs/xfs/libxfs/xfs_rtbitmap.h | 68 +++--- fs/xfs/libxfs/xfs_rtgroup.c | 90 +++++++- fs/xfs/libxfs/xfs_rtgroup.h | 14 + fs/xfs/scrub/bmap.c | 13 + fs/xfs/scrub/fscounters.c | 26 +- fs/xfs/scrub/repair.c | 24 ++ fs/xfs/scrub/repair.h | 7 + fs/xfs/scrub/rtbitmap.c | 45 ++-- fs/xfs/scrub/rtsummary.c | 93 +++++---- fs/xfs/scrub/rtsummary_repair.c | 7 - fs/xfs/scrub/scrub.c | 4 fs/xfs/xfs_discard.c | 100 ++++++--- fs/xfs/xfs_fsmap.c | 143 ++++++++----- fs/xfs/xfs_mount.h | 10 - fs/xfs/xfs_qm.c | 27 ++- fs/xfs/xfs_rtalloc.c | 415 ++++++++++++++++++++++----------------- 18 files changed, 763 insertions(+), 537 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +29 -11
@@ -5167,6 +5167,34 @@ xfs_bmap_del_extent_cow( ip->i_delayed_blks -= del->br_blockcount; } +static int +xfs_bmap_free_rtblocks ( +struct xfs_trans *tp, +struct xfs_bmbt_irec *del) +{ +struct xfs_rtgroup *rtg; +int error; + + rtg =xfs_rtgroup_grab (tp->t_mountp,0 ); +if (!rtg) +return -EIO ; + +/* +* Ensure the bitmap and summary inodes are locked and joined to the +* transaction before modifying them. +*/ +if (!(tp->t_flags &XFS_TRANS_RTBITMAP_LOCKED )) { + tp->t_flags |=XFS_TRANS_RTBITMAP_LOCKED ; +xfs_rtgroup_lock (rtg,XFS_RTGLOCK_BITMAP ); +xfs_rtgroup_trans_join (tp, rtg,XFS_RTGLOCK_BITMAP ); + } + + error =xfs_rtfree_blocks (tp, rtg, del->br_startblock, + del->br_blockcount); +xfs_rtgroup_rele (rtg); +return error; +} +/* * Called by xfs_bmapi to update file extent records and the btree * after removing space.
@@ -5382,17 +5410,7 @@ xfs_bmap_del_extent_real(if (xfs_is_reflink_inode (ip) && whichfork ==XFS_DATA_FORK ) {xfs_refcount_decrease_extent (tp, del); }else if (xfs_ifork_is_realtime (ip, whichfork)) { -/* -* Ensure the bitmap and summary inodes are locked -* and joined to the transaction before modifying them. -*/ -if (!(tp->t_flags &XFS_TRANS_RTBITMAP_LOCKED )) { - tp->t_flags |=XFS_TRANS_RTBITMAP_LOCKED ; -xfs_rtbitmap_lock (mp); -xfs_rtbitmap_trans_join (tp); - } - error =xfs_rtfree_blocks (tp, del->br_startblock, - del->br_blockcount); + error =xfs_bmap_free_rtblocks (tp, del); }else {unsigned int efi_flags =0 ;
fs/xfs/libxfs/xfs_rtbitmap.c +80 -94
334 lines not on this page · raw message
fs/xfs/libxfs/xfs_rtbitmap.h +27 -41
105 lines not on this page · raw message
fs/xfs/libxfs/xfs_rtgroup.c +70 -20
132 lines not on this page · raw message
fs/xfs/libxfs/xfs_rtgroup.h +13 -1
@@ -10,6 +10,9 @@ struct xfs_mount;struct xfs_trans ;enum xfs_rtg_inodes { +XFS_RTGI_BITMAP ,/* allocation bitmap */ +XFS_RTGI_SUMMARY ,/* allocation summary */ +XFS_RTGI_MAX , };
@@ -28,11 +31,19 @@ struct xfs_rtgroup {wait_queue_head_t rtg_active_wq;/* woken active_ref falls to zero */ /* per-rtgroup metadata inodes */ -struct xfs_inode *rtg_inodes[1 /* hack */ ]; +struct xfs_inode *rtg_inodes[XFS_RTGI_MAX ];/* Number of blocks in this group */ xfs_rtxnum_t rtg_extents; +/* +* Optional cache of rt summary level per bitmap block with the +* invariant that rtg_rsum_cache[bbno] > the maximum i for which +* rsum[i][bbno] != 0, or 0 if rsum[i][bbno] == 0 for all i. +* Reads and writes are serialized by the rsumip inode lock. +*/ +uint8_t *rtg_rsum_cache; +#ifdef __KERNEL__/* -- kernel only structures below this line -- */ spinlock_t rtg_state_lock;
@@ -234,6 +245,7 @@ int xfs_rtginode_mkdir_parent(struct xfs_mount *mp);int xfs_rtginode_load_parent (struct xfs_trans *tp);const char *xfs_rtginode_name (enum xfs_rtg_inodes type); +enum xfs_metafile_type xfs_rtginode_metafile_type (enum xfs_rtg_inodes type);bool xfs_rtginode_enabled (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type);int xfs_rtginode_load (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type,struct xfs_trans *tp);
fs/xfs/scrub/bmap.c +13 -0
@@ -19,6 +19,7 @@#include "xfs_bmap_btree.h" #include "xfs_rmap.h" #include "xfs_rmap_btree.h" +#include "xfs_rtgroup.h" #include "xfs_health.h" #include "scrub/scrub.h" #include "scrub/common.h"
@@ -314,8 +315,20 @@ xchk_bmap_rt_iextent_xref(struct xchk_bmap_info *info, struct xfs_bmbt_irec *irec) { + int error; + + error =xchk_rtgroup_init_existing (info->sc, +xfs_rtb_to_rgno (ip->i_mount, irec->br_startblock), + &info->sc->sr); +if (!xchk_fblock_process_error (info->sc, info->whichfork, + irec->br_startoff, &error)) +return ; + +xchk_rtgroup_lock (&info->sc->sr,XCHK_RTGLOCK_ALL );xchk_xref_is_used_rt_space (info->sc, irec->br_startblock, irec->br_blockcount); + +xchk_rtgroup_free (info->sc, &info->sc->sr); }/* Cross-reference a single datadev extent record. */
fs/xfs/scrub/fscounters.c +15 -11
@@ -19,6 +19,7 @@#include "xfs_rtbitmap.h" #include "xfs_inode.h" #include "xfs_icache.h" +#include "xfs_rtgroup.h" #include "scrub/scrub.h" #include "scrub/common.h" #include "scrub/trace.h"
@@ -388,7 +389,7 @@ xchk_fscount_aggregate_agcounts(#ifdef CONFIG_XFS_RT STATIC intxchk_fscount_add_frextent ( -struct xfs_mount *mp, +struct xfs_rtgroup *rtg,struct xfs_trans *tp,const struct xfs_rtalloc_rec *rec,void *priv)
@@ -409,6 +410,8 @@ xchk_fscount_count_frextents( struct xchk_fscounters *fsc) {struct xfs_mount *mp = sc->mp; +struct xfs_rtgroup *rtg; +xfs_rgnumber_t rgno;int error; fsc->frextents =0 ;
@@ -416,19 +419,20 @@ xchk_fscount_count_frextents(if (!xfs_has_realtime (mp))return 0 ; -xfs_rtbitmap_lock_shared (sc->mp,XFS_RBMLOCK_BITMAP ); - error =xfs_rtalloc_query_all (sc->mp, sc->tp, - xchk_fscount_add_frextent, fsc); -if (error) { -xchk_set_incomplete (sc); - goto out_unlock; +for_each_rtgroup (mp, rgno, rtg) { +xfs_rtgroup_lock (rtg,XFS_RTGLOCK_BITMAP_SHARED ); + error =xfs_rtalloc_query_all (rtg, sc->tp, + xchk_fscount_add_frextent, fsc); +xfs_rtgroup_unlock (rtg,XFS_RTGLOCK_BITMAP_SHARED ); +if (error) { +xchk_set_incomplete (sc); +xfs_rtgroup_rele (rtg); +return error; + } } fsc->frextents_delayed =percpu_counter_sum (&mp->m_delalloc_rtextents); - -out_unlock: -xfs_rtbitmap_unlock_shared (sc->mp,XFS_RBMLOCK_BITMAP ); - return error; + return 0; }#else STATIC int
fs/xfs/scrub/repair.c +24 -0
@@ -21,6 +21,7 @@#include "xfs_rmap.h" #include "xfs_rmap_btree.h" #include "xfs_refcount_btree.h" +#include "xfs_rtbitmap.h" #include "xfs_extent_busy.h" #include "xfs_ag.h" #include "xfs_ag_resv.h"
@@ -953,6 +954,29 @@ xrep_ag_init(return 0 ; } +#ifdef CONFIG_XFS_RT +/* +* Given a reference to a rtgroup structure, lock rtgroup btree inodes and +* create btree cursors. Must only be called to repair a regular rt file. +*/ +int +xrep_rtgroup_init ( +struct xfs_scrub *sc, +struct xfs_rtgroup *rtg, +struct xchk_rt *sr, +unsigned int rtglock_flags) +{ +ASSERT (sr->rtg ==NULL ); + +xfs_rtgroup_lock (rtg, rtglock_flags); + sr->rtlock_flags = rtglock_flags; + +/* Grab our own passive reference from the caller's ref. */ + sr->rtg =xfs_rtgroup_hold (rtg); +return 0 ; +} +#endif /* CONFIG_XFS_RT */ +/* Reinitialize the per-AG block reservation for the AG we just fixed. */ int xrep_reset_perag_resv(
fs/xfs/scrub/repair.h +7 -0
@@ -8,6 +8,7 @@#include "xfs_quota_defs.h" +struct xfs_rtgroup ;struct xchk_stats_run ;static inline int xrep_notsupported (struct xfs_scrub *sc)
@@ -106,6 +107,12 @@ int xrep_setup_inode(struct xfs_scrub *sc, const struct xfs_imap *imap);void xrep_ag_btcur_init (struct xfs_scrub *sc,struct xchk_ag *sa);int xrep_ag_init (struct xfs_scrub *sc,struct xfs_perag *pag,struct xchk_ag *sa); +#ifdef CONFIG_XFS_RT +int xrep_rtgroup_init (struct xfs_scrub *sc,struct xfs_rtgroup *rtg, +struct xchk_rt *sr,unsigned int rtglock_flags); +#else +# define xrep_rtgroup_init (sc, rtg, sr, lockflags) (-ENOSYS) +#endif /* CONFIG_XFS_RT */ /* Metadata revalidators */
fs/xfs/scrub/rtbitmap.c +26 -19
137 lines not on this page · raw message
fs/xfs/scrub/rtsummary.c +48 -45
209 lines not on this page · raw message
fs/xfs/scrub/rtsummary_repair.c +4 -3
@@ -76,8 +76,9 @@ xrep_rtsummary_prep_buf(union xfs_suminfo_raw *ondisk;int error; - rts->args.mp = sc->mp; + rts->args.mp = mp; rts->args.tp = sc->tp; + rts->args.rtg = sc->sr.rtg; rts->args.sumbp = bp; ondisk =xfs_rsumblock_infoptr (&rts->args,0 ); rts->args.sumbp =NULL ;
@@ -162,8 +163,8 @@ xrep_rtsummary(return error;/* Reset incore state and blow out the summary cache. */ -if (mp->m_rsum_cache) -memset (mp->m_rsum_cache,0xFF , mp->m_sb.sb_rbmblocks); +if (sc->sr.rtg->rtg_rsum_cache) +memset (sc->sr.rtg->rtg_rsum_cache,0xFF , mp->m_sb.sb_rbmblocks); mp->m_rsumlevels = rts->rsumlevels; mp->m_rsumblocks = rts->rsumblocks;
fs/xfs/scrub/scrub.c +2 -2
@@ -384,13 +384,13 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .repair = xrep_parent, }, [XFS_SCRUB_TYPE_RTBITMAP] = { /* realtime bitmap */ - .type = ST_FS, + .type = ST_RTGROUP, .setup = xchk_setup_rtbitmap, .scrub = xchk_rtbitmap, .repair = xrep_rtbitmap, }, [XFS_SCRUB_TYPE_RTSUM] = { /* realtime summary */ - .type = ST_FS, + .type = ST_RTGROUP, .setup = xchk_setup_rtsummary, .scrub = xchk_rtsummary, .repair = xrep_rtsummary,
fs/xfs/xfs_discard.c +65 -35
165 lines not on this page · raw message
fs/xfs/xfs_fsmap.c +86 -57
193 lines not on this page · raw message
fs/xfs/xfs_mount.h +0 -10
@@ -90,8 +90,6 @@ typedef struct xfs_mount {struct xfs_da_geometry *m_dir_geo;/* directory block geometry */ struct xfs_da_geometry *m_attr_geo;/* attribute block geometry */ struct xlog *m_log;/* log specific stuff */ -struct xfs_inode *m_rbmip;/* pointer to bitmap inode */ -struct xfs_inode *m_rsumip;/* pointer to summary inode */ struct xfs_inode *m_rootip;/* pointer to root directory */ struct xfs_inode *m_metadirip;/* ptr to metadata directory */ struct xfs_inode *m_rtdirip;/* ptr to realtime metadir */
@@ -100,14 +98,6 @@ typedef struct xfs_mount {struct xfs_buftarg *m_logdev_targp;/* log device */ struct xfs_buftarg *m_rtdev_targp;/* rt device */ void __percpu *m_inodegc;/* percpu inodegc structures */ - -/* -* Optional cache of rt summary level per bitmap block with the -* invariant that m_rsum_cache[bbno] > the maximum i for which -* rsum[i][bbno] != 0, or 0 if rsum[i][bbno] == 0 for all i. -* Reads and writes are serialized by the rsumip inode lock. -*/ -uint8_t *m_rsum_cache;struct xfs_mru_cache *m_filestream;/* per-mount filestream data */ struct workqueue_struct *m_buf_workqueue;struct workqueue_struct *m_unwritten_workqueue;
fs/xfs/xfs_qm.c +23 -4
@@ -29,6 +29,7 @@#include "xfs_health.h" #include "xfs_da_format.h" #include "xfs_metafile.h" +#include "xfs_rtgroup.h" /* * The global quota manager. There is only one of these for the entire
@@ -210,6 +211,21 @@ xfs_qm_unmount( } } +static void +xfs_qm_unmount_rt ( +struct xfs_mount *mp) +{ +struct xfs_rtgroup *rtg =xfs_rtgroup_grab (mp,0 ); + +if (!rtg) +return ; +if (rtg->rtg_inodes[XFS_RTGI_BITMAP ]) +xfs_qm_dqdetach (rtg->rtg_inodes[XFS_RTGI_BITMAP ]); +if (rtg->rtg_inodes[XFS_RTGI_SUMMARY ]) +xfs_qm_dqdetach (rtg->rtg_inodes[XFS_RTGI_SUMMARY ]); +xfs_rtgroup_rele (rtg); +} +/* * Called from the vfsops layer. */
@@ -223,10 +239,13 @@ xfs_qm_unmount_quotas(*/ ASSERT (mp->m_rootip);xfs_qm_dqdetach (mp->m_rootip); -if (mp->m_rbmip) -xfs_qm_dqdetach (mp->m_rbmip); -if (mp->m_rsumip) -xfs_qm_dqdetach (mp->m_rsumip); + +/* +* For pre-RTG file systems, the RT inodes have quotas attached, +* detach them now. +*/ +if (!xfs_has_rtgroups (mp)) +xfs_qm_unmount_rt (mp);/* * Release the quota inodes.
fs/xfs/xfs_rtalloc.c +231 -184
680 lines not on this page · raw message
Re: [PATCH 16/24] xfs: move RT bitmap and summary information to the rtgroup
Quoted 25 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Move the pointers to the RT bitmap and summary inodes as well as the summary cache to the rtgroups structure to prepare for having a separate bitmap and summary inodes for each rtgroup.
Code using the inodes now needs to operate on a rtgroup. Where easily possible such code is converted to iterate over all rtgroups, else rtgroup 0 (the only one that can currently exist) is hardcoded.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 40 +++- fs/xfs/libxfs/xfs_rtbitmap.c | 174 ++++++++-------- fs/xfs/libxfs/xfs_rtbitmap.h | 68 +++--- fs/xfs/libxfs/xfs_rtgroup.c | 90 +++++++- fs/xfs/libxfs/xfs_rtgroup.h | 14 + fs/xfs/scrub/bmap.c | 13 + fs/xfs/scrub/fscounters.c | 26 +- fs/xfs/scrub/repair.c | 24 ++ fs/xfs/scrub/repair.h | 7 + fs/xfs/scrub/rtbitmap.c | 45 ++-- fs/xfs/scrub/rtsummary.c | 93 +++++----
Quoted 8 lines
fs/xfs/scrub/rtsummary_repair.c | 7 - fs/xfs/scrub/scrub.c | 4 fs/xfs/xfs_discard.c | 100 ++++++--- fs/xfs/xfs_fsmap.c | 143 ++++++++----- fs/xfs/xfs_mount.h | 10 - fs/xfs/xfs_qm.c | 27 ++- fs/xfs/xfs_rtalloc.c | 415 ++++++++++++++++++++++----------------- 18 files changed, 763 insertions(+), 537 deletions(-)
I'm finding this patch does far too many things to be reviewable. There's code factoring, abstraction by local variables, changes to locking APIs, etc that are needed to simplify the conversion, but could all be done separately before the actual changeover to using rtgroups.
There's also multiple functional changes in the code - like support for growfs using rtgroups and moving to per-rtg summary caches - so it's really difficult to separate and review the individual changes in this.
Can you please split this up into a couple of separate steps? One for all the local variable conversions and "no change" factoring, one to move the summary cache code, one to add the grwofs support and, finally, one to actually convert everything over to use rtgroups directly?
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 17/24 xfs: remove XFS_ILOCK_RT*
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Now that we've centralized the realtime metadata locking routines, get rid of the ILOCK subclasses since we now use explicit lockdep classes.
--- fs/xfs/xfs_inode.c | 3 +-- fs/xfs/xfs_inode.h | 13 ++++--------- fs/xfs/xfs_rtalloc.c | 9 ++++----- 3 files changed, 9 insertions(+), 16 deletions(-)
fs/xfs/xfs_inode.c +1 -2
@@ -342,8 +342,7 @@ xfs_lock_inumorder( {uint class =0 ; -ASSERT (!(lock_mode & (XFS_ILOCK_PARENT |XFS_ILOCK_RTBITMAP | -XFS_ILOCK_RTSUM ))); +ASSERT (!(lock_mode &XFS_ILOCK_PARENT ));ASSERT (xfs_lockdep_subclass_ok (subclass));if (lock_mode & (XFS_IOLOCK_SHARED |XFS_IOLOCK_EXCL )) {
fs/xfs/xfs_inode.h +4 -9
@@ -443,9 +443,8 @@ static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip)* However, MAX_LOCKDEP_SUBCLASSES == 8, which means we are greatly * limited to the subclasses we can represent via nesting. We need at least * 5 inodes nest depth for the ILOCK through rename, and we also have to support -* XFS_ILOCK_PARENT, which gives 6 subclasses. Then we have XFS_ILOCK_RTBITMAP -* and XFS_ILOCK_RTSUM, which are another 2 unique subclasses, so that's all -* 8 subclasses supported by lockdep. +* XFS_ILOCK_PARENT, which gives 6 subclasses. That's 6 of the 8 subclasses +* supported by lockdep. * * This also means we have to number the sub-classes in the lowest bits of * the mask we keep, and we have to ensure we never exceed 3 bits of lockdep
@@ -471,8 +470,8 @@ static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip)* ILOCK values * 0-4 subclass values * 5 PARENT subclass (not nestable) -* 6 RTBITMAP subclass (not nestable) -* 7 RTSUM subclass (not nestable) +* 6 unused +* 7 unused * */ #define XFS_IOLOCK_SHIFT 16
@@ -487,12 +486,8 @@ static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip)#define XFS_ILOCK_SHIFT 24#define XFS_ILOCK_PARENT_VAL 5u#define XFS_ILOCK_MAX_SUBCLASS (XFS_ILOCK_PARENT_VAL - 1) -#define XFS_ILOCK_RTBITMAP_VAL 6u -#define XFS_ILOCK_RTSUM_VAL 7u#define XFS_ILOCK_DEP_MASK 0xff000000u#define XFS_ILOCK_PARENT (XFS_ILOCK_PARENT_VAL << XFS_ILOCK_SHIFT) -#define XFS_ILOCK_RTBITMAP (XFS_ILOCK_RTBITMAP_VAL << XFS_ILOCK_SHIFT) -#define XFS_ILOCK_RTSUM (XFS_ILOCK_RTSUM_VAL << XFS_ILOCK_SHIFT)#define XFS_LOCK_SUBCLASS_MASK (XFS_IOLOCK_DEP_MASK | \ XFS_MMAPLOCK_DEP_MASK | \
fs/xfs/xfs_rtalloc.c +4 -5
@@ -1188,12 +1188,11 @@ xfs_rtalloc_reinit_frextents(static inline int xfs_rtmount_iread_extents (struct xfs_trans *tp, -struct xfs_inode *ip, -unsigned int lock_class) +struct xfs_inode *ip) {int error; -xfs_ilock (ip,XFS_ILOCK_EXCL | lock_class); +xfs_ilock (ip,XFS_ILOCK_EXCL ); error =xfs_iread_extents (tp, ip,XFS_DATA_FORK );if (error)
@@ -1206,7 +1205,7 @@ xfs_rtmount_iread_extents( } out_unlock: -xfs_iunlock (ip,XFS_ILOCK_EXCL | lock_class); +xfs_iunlock (ip,XFS_ILOCK_EXCL );return error; }
@@ -1227,7 +1226,7 @@ xfs_rtmount_rtg(if (rtg->rtg_inodes[i]) { error =xfs_rtmount_iread_extents (tp, - rtg->rtg_inodes[i],0 ); + rtg->rtg_inodes[i]);if (error)return error; }
Re: [PATCH 17/24] xfs: remove XFS_ILOCK_RT*
Looks good:
PATCH 18/24 xfs: calculate RT bitmap and summary blocks based on sb_rextents
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Use the on-disk rextents to calculate the bitmap and summary blocks instead of the calculated one so that we can refactor the helpers for calculating them.
As the RT bitmap and summary scrubbers already check that sb_rextents match the block count this does not change coverage of the scrubber.
--- fs/xfs/scrub/rtbitmap.c | 3 ++- fs/xfs/scrub/rtsummary.c | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-)
fs/xfs/scrub/rtbitmap.c +2 -1
@@ -67,7 +67,8 @@ xchk_setup_rtbitmap(if (mp->m_sb.sb_rblocks) { rtb->rextents =xfs_rtb_to_rtx (mp, mp->m_sb.sb_rblocks); rtb->rextslog =xfs_compute_rextslog (rtb->rextents); - rtb->rbmblocks =xfs_rtbitmap_blockcount (mp, rtb->rextents); + rtb->rbmblocks =xfs_rtbitmap_blockcount (mp, + mp->m_sb.sb_rextents); }return 0 ;
fs/xfs/scrub/rtsummary.c +3 -2
@@ -105,9 +105,10 @@ xchk_setup_rtsummary(int rextslog; rts->rextents =xfs_rtb_to_rtx (mp, mp->m_sb.sb_rblocks); - rextslog =xfs_compute_rextslog (rts->rextents); + rextslog =xfs_compute_rextslog (mp->m_sb.sb_rextents); rts->rsumlevels = rextslog +1 ; - rts->rbmblocks =xfs_rtbitmap_blockcount (mp, rts->rextents); + rts->rbmblocks =xfs_rtbitmap_blockcount (mp, + mp->m_sb.sb_rextents); rts->rsumblocks =xfs_rtsummary_blockcount (mp, rts->rsumlevels, rts->rbmblocks); }
PATCH 19/24 xfs: factor out a xfs_growfs_rt_alloc_fake_mount helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Split the code to set up a fake mount point to calculate new RT geometry out of xfs_growfs_rt_bmblock so that it can be reused.
Note that this changes the rmblocks calculation method to be based on the passed in rblocks and extsize and not the explicitly passed one, but both methods will always lead to the same result. The new version just does a little bit more math while being more general.
--- fs/xfs/xfs_rtalloc.c | 52 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 16 deletions(-)
fs/xfs/xfs_rtalloc.c +36 -16
@@ -734,6 +734,36 @@ xfs_rtginode_ensure(return xfs_rtginode_create (rtg, type, true); } +static struct xfs_mount * +xfs_growfs_rt_alloc_fake_mount ( +const struct xfs_mount *mp, +xfs_rfsblock_t rblocks, +xfs_agblock_t rextsize) +{ +struct xfs_mount *nmp; + + nmp =kmemdup (mp,sizeof (*mp),GFP_KERNEL ); +if (!nmp) +return NULL ; + nmp->m_sb.sb_rextsize = rextsize; +xfs_mount_sb_set_rextsize (nmp, &nmp->m_sb); + nmp->m_sb.sb_rblocks = rblocks; + nmp->m_sb.sb_rextents =xfs_rtb_to_rtx (nmp, nmp->m_sb.sb_rblocks); + nmp->m_sb.sb_rbmblocks =xfs_rtbitmap_blockcount (nmp, + nmp->m_sb.sb_rextents); + nmp->m_sb.sb_rextslog =xfs_compute_rextslog (nmp->m_sb.sb_rextents); + nmp->m_rsumlevels = nmp->m_sb.sb_rextslog +1 ; + nmp->m_rsumblocks =xfs_rtsummary_blockcount (nmp, nmp->m_rsumlevels, + nmp->m_sb.sb_rbmblocks); + +if (rblocks >0 ) + nmp->m_features |=XFS_FEAT_REALTIME ; + +/* recompute growfsrt reservation from new rsumsize */ +xfs_trans_resv_calc (nmp, &nmp->m_resv); +return nmp; +} + static int xfs_growfs_rt_bmblock( struct xfs_rtgroup *rtg,
@@ -756,25 +786,15 @@ xfs_growfs_rt_bmblock(xfs_rtbxlen_t freed_rtx;int error; - - nrblocks_step = (bmbno +1 ) *NBBY * mp->m_sb.sb_blocksize * rextsize; - - nmp = nargs.mp =kmemdup (mp,sizeof (*mp),GFP_KERNEL ); -if (!nmp) -return -ENOMEM ; -/* * Calculate new sb and mount fields for this round. */ - nmp->m_sb.sb_rextsize = rextsize; -xfs_mount_sb_set_rextsize (nmp, &nmp->m_sb); - nmp->m_sb.sb_rbmblocks = bmbno +1 ; - nmp->m_sb.sb_rblocks =min (nrblocks, nrblocks_step); - nmp->m_sb.sb_rextents =xfs_rtb_to_rtx (nmp, nmp->m_sb.sb_rblocks); - nmp->m_sb.sb_rextslog =xfs_compute_rextslog (nmp->m_sb.sb_rextents); - nmp->m_rsumlevels = nmp->m_sb.sb_rextslog +1 ; - nmp->m_rsumblocks =xfs_rtsummary_blockcount (mp, nmp->m_rsumlevels, - nmp->m_sb.sb_rbmblocks); + nrblocks_step = (bmbno +1 ) *NBBY * mp->m_sb.sb_blocksize * rextsize; + nmp = nargs.mp =xfs_growfs_rt_alloc_fake_mount (mp, +min (nrblocks, nrblocks_step), rextsize); +if (!nmp) +return -ENOMEM ; + rtg->rtg_extents =xfs_rtgroup_extents (nmp, rtg->rtg_rgno);/*
PATCH 20/24 xfs: use xfs_growfs_rt_alloc_fake_mount in xfs_growfs_rt_alloc_blocks
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Use xfs_growfs_rt_alloc_fake_mount instead of manually recalculating the RT bitmap geometry.
--- fs/xfs/xfs_rtalloc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
fs/xfs/xfs_rtalloc.c +8 -4
@@ -935,10 +935,10 @@ xfs_growfs_rt_alloc_blocks(struct xfs_mount *mp = rtg->rtg_mount;struct xfs_inode *rbmip = rtg->rtg_inodes[XFS_RTGI_BITMAP ];struct xfs_inode *rsumip = rtg->rtg_inodes[XFS_RTGI_SUMMARY ]; -xfs_rtxnum_t nrextents =div_u64 (nrblocks, rextsize);xfs_extlen_t orbmblocks;xfs_extlen_t orsumblocks;xfs_extlen_t nrsumblocks; +struct xfs_mount *nmp;int error;/*
@@ -948,9 +948,13 @@ xfs_growfs_rt_alloc_blocks( orbmblocks =XFS_B_TO_FSB (mp, rbmip->i_disk_size); orsumblocks =XFS_B_TO_FSB (mp, rsumip->i_disk_size); - *nrbmblocks =xfs_rtbitmap_blockcount (mp, nrextents); - nrsumblocks =xfs_rtsummary_blockcount (mp, -xfs_compute_rextslog (nrextents) +1 , *nrbmblocks); + nmp =xfs_growfs_rt_alloc_fake_mount (mp, nrblocks, rextsize); +if (!nmp) +return -ENOMEM ; + + *nrbmblocks = nmp->m_sb.sb_rbmblocks; + nrsumblocks = nmp->m_rsumblocks; +kfree (nmp); error =xfs_rtfile_initialize_blocks (rtg,XFS_RTGI_BITMAP , orbmblocks, *nrbmblocks,NULL );
PATCH 21/24 xfs: factor out a xfs_growfs_check_rtgeom helper
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Split the check that the rtsummary fits into the log into a separate helper, and use xfs_growfs_rt_alloc_fake_mount to calculate the new RT geometry.
--- fs/xfs/xfs_rtalloc.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)
fs/xfs/xfs_rtalloc.c +29 -14
@@ -1023,6 +1023,31 @@ xfs_growfs_rtg(return error; } +static int +xfs_growfs_check_rtgeom ( +const struct xfs_mount *mp, +xfs_rfsblock_t rblocks, +xfs_extlen_t rextsize) +{ +struct xfs_mount *nmp; +int error =0 ; + + nmp =xfs_growfs_rt_alloc_fake_mount (mp, rblocks, rextsize); +if (!nmp) +return -ENOMEM ; + +/* +* New summary size can't be more than half the size of the log. This +* prevents us from getting a log overflow, since we'll log basically +* the whole summary file at once. +*/ +if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >>1 )) + error = -EINVAL ; + +kfree (nmp); +return error; +} +/* * Grow the realtime area of the filesystem. */
@@ -1031,9 +1056,6 @@ xfs_growfs_rt( xfs_mount_t *mp, /* mount point for filesystem */ xfs_growfs_rt_t *in) /* growfs rt input struct */ { -xfs_rtxnum_t nrextents; -xfs_extlen_t nrbmblocks; -xfs_extlen_t nrsumblocks;struct xfs_buf *bp;xfs_agblock_t old_rextsize = mp->m_sb.sb_rextsize;int error;
@@ -1082,20 +1104,13 @@ xfs_growfs_rt(/* * Calculate new parameters. These are the final values to be reached. */ - nrextents =div_u64 (in->newblocks, in->extsize); error = -EINVAL ; -if (nrextents ==0 ) +if (in->newblocks < in->extsize) goto out_unlock; - nrbmblocks =xfs_rtbitmap_blockcount (mp, nrextents); - nrsumblocks =xfs_rtsummary_blockcount (mp, -xfs_compute_rextslog (nrextents) +1 , nrbmblocks); -/* -* New summary size can't be more than half the size of -* the log. This prevents us from getting a log overflow, -* since we'll log basically the whole summary file at once. -*/ -if (nrsumblocks > (mp->m_sb.sb_logblocks >>1 )) +/* Make sure the new fs size won't cause problems with the log. */ + error =xfs_growfs_check_rtgeom (mp, in->newblocks, in->extsize); +if (error) goto out_unlock; error =xfs_growfs_rtg (mp, in->newblocks, in->extsize);
Re: [PATCH 21/24] xfs: factor out a xfs_growfs_check_rtgeom helper
Quoted 33 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Split the check that the rtsummary fits into the log into a separate helper, and use
xfs_growfs_rt_alloc_fake_mountto calculate the new RT geometry.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>[djwong: avoid division for the 0-rtx growfs check]Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_rtalloc.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)fs/xfs/xfs_rtalloc.c +10
-0@@ -1023,6 +1023,31 @@ xfs_growfs_rtg(return error; } +static int +xfs_growfs_check_rtgeom ( +const struct xfs_mount *mp, +xfs_rfsblock_t rblocks, +xfs_extlen_t rextsize) +{ +struct xfs_mount *nmp; +int error =0 ; + + nmp =xfs_growfs_rt_alloc_fake_mount (mp, rblocks, rextsize);
fs/xfs/xfs_rtalloc.c xfs_growfs_rtg( · line 1045
Quoted 10 lines
fs/xfs/xfs_rtalloc.c +10
-0+if (!nmp) +return -ENOMEM ; + +/* +* New summary size can't be more than half the size of the log. This +* prevents us from getting a log overflow, since we'll log basically +* the whole summary file at once. +*/ +if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >>1 )) + error = -EINVAL ;
FWIW, the new size needs to be smaller than that, because the "half the log size" must to include all the log metadata needed to encapsulate that object. The grwofs transaction also logs inodes and the superblock, so that also takes away from the maximum size of the summary file....
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/24] xfs: factor out a xfs_growfs_check_rtgeom helper
Quoted 42 lines · Dave Chinner
Quoted 41 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Split the check that the rtsummary fits into the log into a separate helper, and use
xfs_growfs_rt_alloc_fake_mountto calculate the new RT geometry.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>[djwong: avoid division for the 0-rtx growfs check]Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_rtalloc.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)fs/xfs/xfs_rtalloc.c +18
-0@@ -1023,6 +1023,31 @@ xfs_growfs_rtg(return error; } +static int +xfs_growfs_check_rtgeom ( +const struct xfs_mount *mp, +xfs_rfsblock_t rblocks, +xfs_extlen_t rextsize) +{ +struct xfs_mount *nmp; +int error =0 ; + + nmp =xfs_growfs_rt_alloc_fake_mount (mp, rblocks, rextsize); +if (!nmp) +return -ENOMEM ; + +/* +* New summary size can't be more than half the size of the log. This +* prevents us from getting a log overflow, since we'll log basically +* the whole summary file at once. +*/
Quoted 8 lines
fs/xfs/xfs_rtalloc.c xfs_growfs_rtg( · line 1045
Quoted 2 lines
fs/xfs/xfs_rtalloc.c +2
-0+if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >>1 )) + error = -EINVAL ;FWIW, the new size needs to be smaller than that, because the "half the log size" must to include all the log metadata needed to encapsulate that object. The grwofs transaction also logs inodes and the superblock, so that also takes away from the maximum size of the summary file....
<shrug> It's the same logic as what's there now, and there haven't been any bug reports, have there? Though I suppose that's just a reduction of what? One block for the rtbitmap, and (conservatively) two inodes and a superblock?
n = nmp->m_rsumblocks + 1 + howmany(inodesize * 2, blocksize) + 1; if (n > (logblocks / 2))
return -EINVAL;
--D
Quoted 6 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/24] xfs: factor out a xfs_growfs_check_rtgeom helper
Quoted 52 lines · Darrick J. Wong
Quoted 42 lines · Dave Chinner
Quoted 41 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Split the check that the rtsummary fits into the log into a separate helper, and use
xfs_growfs_rt_alloc_fake_mountto calculate the new RT geometry.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>[djwong: avoid division for the 0-rtx growfs check]Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_rtalloc.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)fs/xfs/xfs_rtalloc.c +18
-0@@ -1023,6 +1023,31 @@ xfs_growfs_rtg(return error; } +static int +xfs_growfs_check_rtgeom ( +const struct xfs_mount *mp, +xfs_rfsblock_t rblocks, +xfs_extlen_t rextsize) +{ +struct xfs_mount *nmp; +int error =0 ; + + nmp =xfs_growfs_rt_alloc_fake_mount (mp, rblocks, rextsize); +if (!nmp) +return -ENOMEM ; + +/* +* New summary size can't be more than half the size of the log. This +* prevents us from getting a log overflow, since we'll log basically +* the whole summary file at once. +*/ Quoted 8 lines
fs/xfs/xfs_rtalloc.c xfs_growfs_rtg( · line 1045
Quoted 2 lines
fs/xfs/xfs_rtalloc.c +2
-0+if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >>1 )) + error = -EINVAL ;FWIW, the new size needs to be smaller than that, because the "half the log size" must to include all the log metadata needed to encapsulate that object. The grwofs transaction also logs inodes and the superblock, so that also takes away from the maximum size of the summary file....
Quoted 2 lines
<shrug> It's the same logic as what's there now, and there haven't been any bug reports, have there?
No, none that I know of - it was just an observation that the code doesn't actually guarantee what the comment says it should do.
Quoted 3 lines
Though I suppose that's just a reduction
of what? One block for the rtbitmap, and (conservatively) two inodes and a superblock?
The rtbitmap update might touch a lot more than one block. The newly allocated space in the rtbitmap inode is initialised to zeros, and so the xfs_rtfree_range() call from the growfs code to mark the new space free has to write all 1s to that range of the rtbitmap. This is all done in a single transaction, so we might actually be logging a *lot* of rtbitmap buffers here.
IIRC, there is a bit per rtextent, so in a 4kB buffer we can mark 32768 rtextents free. If they are 4kB each, then that's 128MB of space tracked per rtbitmap block. This adds up to roughly 3.5MB of log space for the rtbitmap updates per TB of grown rtdev space....
So, yeah, I think that calculation and comment is inaccurate, but we don't have to fix this right now.
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/24] xfs: factor out a xfs_growfs_check_rtgeom helper
Quoted 70 lines · Dave Chinner
Quoted 52 lines · Darrick J. Wong
Quoted 42 lines · Dave Chinner
Quoted 41 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Split the check that the rtsummary fits into the log into a separate helper, and use
xfs_growfs_rt_alloc_fake_mountto calculate the new RT geometry.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>[djwong: avoid division for the 0-rtx growfs check]Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_rtalloc.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)fs/xfs/xfs_rtalloc.c +18
-0@@ -1023,6 +1023,31 @@ xfs_growfs_rtg(return error; } +static int +xfs_growfs_check_rtgeom ( +const struct xfs_mount *mp, +xfs_rfsblock_t rblocks, +xfs_extlen_t rextsize) +{ +struct xfs_mount *nmp; +int error =0 ; + + nmp =xfs_growfs_rt_alloc_fake_mount (mp, rblocks, rextsize); +if (!nmp) +return -ENOMEM ; + +/* +* New summary size can't be more than half the size of the log. This +* prevents us from getting a log overflow, since we'll log basically +* the whole summary file at once. +*/ Quoted 8 lines
fs/xfs/xfs_rtalloc.c xfs_growfs_rtg( · line 1045
Quoted 2 lines
fs/xfs/xfs_rtalloc.c +2
-0+if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >>1 )) + error = -EINVAL ;FWIW, the new size needs to be smaller than that, because the "half the log size" must to include all the log metadata needed to encapsulate that object. The grwofs transaction also logs inodes and the superblock, so that also takes away from the maximum size of the summary file....
Quoted 2 lines
<shrug> It's the same logic as what's there now, and there haven't been any bug reports, have there?
No, none that I know of - it was just an observation that the code doesn't actually guarantee what the comment says it should do.
Quoted 3 lines
Though I suppose that's just a reduction
of what? One block for the rtbitmap, and (conservatively) two inodes and a superblock?The rtbitmap update might touch a lot more than one block. The newly allocated space in the rtbitmap inode is initialised to zeros, and so the
xfs_rtfree_range()call from the growfs code to mark the new space free has to write all 1s to that range of the rtbitmap. This is all done in a single transaction, so we might actually be logging a *lot* of rtbitmap buffers here.
Quoted 7 lines
IIRC, there is a bit per rtextent, so in a 4kB buffer we can mark 32768 rtextents free. If they are 4kB each, then that's 128MB of space tracked per rtbitmap block. This adds up to roughly 3.5MB of log space for the rtbitmap updates per TB of grown rtdev space....
So, yeah, I think that calculation and comment is inaccurate, but we don't have to fix this right now.
The kernel only "frees" the new space one rbmblock at a time, so I think that's why this calculation has never misfired. I /think/ that means that each transaction only ends up logging two rtsummary blocks at a time? One to decrement a counter, and again to increment one another level up?
--D
Quoted 5 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/24] xfs: factor out a xfs_growfs_check_rtgeom helper
Quoted 76 lines · Darrick J. Wong
Quoted 75 lines · Dave Chinner
Quoted 52 lines · Darrick J. Wong
Quoted 42 lines · Dave Chinner
Quoted 41 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Split the check that the rtsummary fits into the log into a separate helper, and use
xfs_growfs_rt_alloc_fake_mountto calculate the new RT geometry.Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>[djwong: avoid division for the 0-rtx growfs check]Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/xfs_rtalloc.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)fs/xfs/xfs_rtalloc.c +18
-0@@ -1023,6 +1023,31 @@ xfs_growfs_rtg(return error; } +static int +xfs_growfs_check_rtgeom ( +const struct xfs_mount *mp, +xfs_rfsblock_t rblocks, +xfs_extlen_t rextsize) +{ +struct xfs_mount *nmp; +int error =0 ; + + nmp =xfs_growfs_rt_alloc_fake_mount (mp, rblocks, rextsize); +if (!nmp) +return -ENOMEM ; + +/* +* New summary size can't be more than half the size of the log. This +* prevents us from getting a log overflow, since we'll log basically +* the whole summary file at once. +*/ Quoted 8 lines
fs/xfs/xfs_rtalloc.c xfs_growfs_rtg( · line 1045
Quoted 2 lines
fs/xfs/xfs_rtalloc.c +2
-0+if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >>1 )) + error = -EINVAL ;FWIW, the new size needs to be smaller than that, because the "half the log size" must to include all the log metadata needed to encapsulate that object. The grwofs transaction also logs inodes and the superblock, so that also takes away from the maximum size of the summary file....
Quoted 2 lines
<shrug> It's the same logic as what's there now, and there haven't been any bug reports, have there?
No, none that I know of - it was just an observation that the code doesn't actually guarantee what the comment says it should do.
Quoted 3 lines
Though I suppose that's just a reduction
of what? One block for the rtbitmap, and (conservatively) two inodes and a superblock?The rtbitmap update might touch a lot more than one block. The newly allocated space in the rtbitmap inode is initialised to zeros, and so the
xfs_rtfree_range()call from the growfs code to mark the new space free has to write all 1s to that range of the rtbitmap. This is all done in a single transaction, so we might actually be logging a *lot* of rtbitmap buffers here.IIRC, there is a bit per rtextent, so in a 4kB buffer we can mark 32768 rtextents free. If they are 4kB each, then that's 128MB of space tracked per rtbitmap block. This adds up to roughly 3.5MB of log space for the rtbitmap updates per TB of grown rtdev space....
Quoted 5 lines
Quoted 2 lines
So, yeah, I think that calculation and comment is inaccurate, but we don't have to fix this right now.
The kernel only "frees" the new space one rbmblock at a time, so I think that's why this calculation has never misfired.
not quite. It iterates all the rbmblocks in the given range (i.e. the entire extent being freed) in xfs_rtmodify_range() in a single transaction, but...
Quoted 4 lines
I /think/ that means
that each transaction only ends up logging two rtsummary blocks at a time? One to decrement a counter, and again to increment one another level up?
... we only do one update of the summary blocks per extent being freed (i.e. in xfs_rtfree_range() after the call to xfs_rtmodify_range()). So, yes, we should only end up logging two rtsummary blocks per extent being freed, but the number of rbmblocks logged in that same transaction is O(extent length).
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 22/24 xfs: refactor xfs_rtbitmap_blockcount
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Rename the existing xfs_rtbitmap_blockcount to xfs_rtbitmap_blockcount_len and add a new xfs_rtbitmap_blockcount wrapper around it that takes the number of extents from the mount structure.
This will simplify the move to per-rtgroup bitmaps as those will need to pass in the number of extents per rtgroup instead.
--- fs/xfs/libxfs/xfs_rtbitmap.c | 12 +++++++++++- fs/xfs/libxfs/xfs_rtbitmap.h | 7 ++++--- fs/xfs/libxfs/xfs_trans_resv.c | 2 +- fs/xfs/scrub/rtbitmap.c | 3 +-- fs/xfs/scrub/rtsummary.c | 7 ++----- fs/xfs/xfs_rtalloc.c | 3 +-- 6 files changed, 20 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.c +11 -1
@@ -1149,13 +1149,23 @@ xfs_rtalloc_extent_is_free(* extents. */ xfs_filblks_t -xfs_rtbitmap_blockcount ( +xfs_rtbitmap_blockcount_len (struct xfs_mount *mp,xfs_rtbxlen_t rtextents) {return howmany_64 (rtextents,NBBY * mp->m_sb.sb_blocksize); } +/* +* Compute the number of rtbitmap blocks used for a given file system. +*/ +xfs_filblks_t +xfs_rtbitmap_blockcount ( +struct xfs_mount *mp) +{ +return xfs_rtbitmap_blockcount_len (mp, mp->m_sb.sb_rextents); +} +/* Compute the number of rtsummary blocks needed to track the given rt space. */ xfs_filblks_t xfs_rtsummary_blockcount(
fs/xfs/libxfs/xfs_rtbitmap.h +4 -3
@@ -307,8 +307,9 @@ int xfs_rtfree_extent(struct xfs_trans *tp, struct xfs_rtgroup *rtg,int xfs_rtfree_blocks (struct xfs_trans *tp,struct xfs_rtgroup *rtg,xfs_fsblock_t rtbno,xfs_filblks_t rtlen); -xfs_filblks_t xfs_rtbitmap_blockcount (struct xfs_mount *mp,xfs_rtbxlen_t - rtextents); +xfs_filblks_t xfs_rtbitmap_blockcount (struct xfs_mount *mp); +xfs_filblks_t xfs_rtbitmap_blockcount_len (struct xfs_mount *mp, +xfs_rtbxlen_t rtextents);xfs_filblks_t xfs_rtsummary_blockcount (struct xfs_mount *mp,unsigned int rsumlevels,xfs_extlen_t rbmblocks);
@@ -336,7 +337,7 @@ static inline int xfs_rtfree_blocks(struct xfs_trans *tp,# define xfs_rtbuf_cache_relse (a) (0)# define xfs_rtalloc_extent_is_free (m,t,s,l,i) (-ENOSYS)static inline xfs_filblks_t -xfs_rtbitmap_blockcount (struct xfs_mount *mp,xfs_rtbxlen_t rtextents) +xfs_rtbitmap_blockcount_len (struct xfs_mount *mp,xfs_rtbxlen_t rtextents) {/* shut up gcc */ return 0 ;
fs/xfs/libxfs/xfs_trans_resv.c +1 -1
@@ -224,7 +224,7 @@ xfs_rtalloc_block_count(xfs_rtxlen_t rtxlen; rtxlen =xfs_extlen_to_rtxlen (mp,XFS_MAX_BMBT_EXTLEN ); - rtbmp_blocks =xfs_rtbitmap_blockcount (mp, rtxlen); + rtbmp_blocks =xfs_rtbitmap_blockcount_len (mp, rtxlen);return (rtbmp_blocks +1 ) * num_ops; }
fs/xfs/scrub/rtbitmap.c +1 -2
@@ -67,8 +67,7 @@ xchk_setup_rtbitmap(if (mp->m_sb.sb_rblocks) { rtb->rextents =xfs_rtb_to_rtx (mp, mp->m_sb.sb_rblocks); rtb->rextslog =xfs_compute_rextslog (rtb->rextents); - rtb->rbmblocks =xfs_rtbitmap_blockcount (mp, - mp->m_sb.sb_rextents); + rtb->rbmblocks =xfs_rtbitmap_blockcount (mp); }return 0 ;
fs/xfs/scrub/rtsummary.c +2 -5
@@ -107,8 +107,7 @@ xchk_setup_rtsummary( rts->rextents =xfs_rtb_to_rtx (mp, mp->m_sb.sb_rblocks); rextslog =xfs_compute_rextslog (mp->m_sb.sb_rextents); rts->rsumlevels = rextslog +1 ; - rts->rbmblocks =xfs_rtbitmap_blockcount (mp, - mp->m_sb.sb_rextents); + rts->rbmblocks =xfs_rtbitmap_blockcount (mp); rts->rsumblocks =xfs_rtsummary_blockcount (mp, rts->rsumlevels, rts->rbmblocks); }
@@ -215,11 +214,9 @@ xchk_rtsum_compute( {struct xfs_mount *mp = sc->mp;struct xfs_rtgroup *rtg = sc->sr.rtg; -unsigned long long rtbmp_blocks;/* If the bitmap size doesn't match the computed size, bail. */ - rtbmp_blocks =xfs_rtbitmap_blockcount (mp, mp->m_sb.sb_rextents); -if (XFS_FSB_TO_B (mp, rtbmp_blocks) != +if (XFS_FSB_TO_B (mp,xfs_rtbitmap_blockcount (mp)) != rtg->rtg_inodes[XFS_RTGI_BITMAP ]->i_disk_size)return -EFSCORRUPTED ;
fs/xfs/xfs_rtalloc.c +1 -2
@@ -749,8 +749,7 @@ xfs_growfs_rt_alloc_fake_mount(xfs_mount_sb_set_rextsize (nmp, &nmp->m_sb); nmp->m_sb.sb_rblocks = rblocks; nmp->m_sb.sb_rextents =xfs_rtb_to_rtx (nmp, nmp->m_sb.sb_rblocks); - nmp->m_sb.sb_rbmblocks =xfs_rtbitmap_blockcount (nmp, - nmp->m_sb.sb_rextents); + nmp->m_sb.sb_rbmblocks =xfs_rtbitmap_blockcount (nmp); nmp->m_sb.sb_rextslog =xfs_compute_rextslog (nmp->m_sb.sb_rextents); nmp->m_rsumlevels = nmp->m_sb.sb_rextslog +1 ; nmp->m_rsumblocks = xfs_rtsummary_blockcount(nmp, nmp->m_rsumlevels,
PATCH 23/24 xfs: refactor xfs_rtsummary_blockcount
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Make xfs_rtsummary_blockcount take all the required information from the mount structure and return the number of summary levels from it as well. This cleans up many of the callers and prepares for making the rtsummary files per-rtgroup where they need to look at different value.
This means we recalculate some values in some callers, but as all these calculations are outside the fast path and cheap that seems like a price worth paying.
--- fs/xfs/libxfs/xfs_rtbitmap.c | 13 +++++++++---- fs/xfs/libxfs/xfs_rtbitmap.h | 3 +-- fs/xfs/scrub/rtsummary.c | 8 ++------ fs/xfs/xfs_mount.h | 2 +- fs/xfs/xfs_rtalloc.c | 13 ++++--------- 5 files changed, 17 insertions(+), 22 deletions(-)
fs/xfs/libxfs/xfs_rtbitmap.c +9 -4
@@ -20,6 +20,7 @@#include "xfs_error.h" #include "xfs_rtbitmap.h" #include "xfs_health.h" +#include "xfs_sb.h" /* * Realtime allocator bitmap functions shared with userspace.
@@ -1166,16 +1167,20 @@ xfs_rtbitmap_blockcount(return xfs_rtbitmap_blockcount_len (mp, mp->m_sb.sb_rextents); } -/* Compute the number of rtsummary blocks needed to track the given rt space. */ +/* +* Compute the geometry of the rtsummary file needed to track the given rt +* space. +*/ xfs_filblks_t xfs_rtsummary_blockcount (struct xfs_mount *mp, -unsigned int rsumlevels, -xfs_extlen_t rbmblocks) +unsigned int *rsumlevels) {unsigned long long rsumwords; - rsumwords = (unsigned long long )rsumlevels * rbmblocks; + *rsumlevels =xfs_compute_rextslog (mp->m_sb.sb_rextents) +1 ; + + rsumwords =xfs_rtbitmap_blockcount (mp) * (*rsumlevels);return XFS_B_TO_FSB (mp, rsumwords <<XFS_WORDLOG ); }
fs/xfs/libxfs/xfs_rtbitmap.h +1 -2
@@ -311,7 +311,7 @@ xfs_filblks_t xfs_rtbitmap_blockcount(struct xfs_mount *mp);xfs_filblks_t xfs_rtbitmap_blockcount_len (struct xfs_mount *mp,xfs_rtbxlen_t rtextents);xfs_filblks_t xfs_rtsummary_blockcount (struct xfs_mount *mp, -unsigned int rsumlevels,xfs_extlen_t rbmblocks); +unsigned int *rsumlevels); int xfs_rtfile_initialize_blocks(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type, xfs_fileoff_t offset_fsb,
@@ -342,7 +342,6 @@ xfs_rtbitmap_blockcount_len(struct xfs_mount *mp, xfs_rtbxlen_t rtextents)/* shut up gcc */ return 0 ; } -# define xfs_rtsummary_blockcount (mp, l, b) (0)#endif /* CONFIG_XFS_RT */ #endif /* __XFS_RTBITMAP_H__ */
fs/xfs/scrub/rtsummary.c +2 -6
@@ -102,14 +102,10 @@ xchk_setup_rtsummary(*/ xchk_rtgroup_lock (&sc->sr,XFS_RTGLOCK_BITMAP );if (mp->m_sb.sb_rblocks) { -int rextslog; - rts->rextents =xfs_rtb_to_rtx (mp, mp->m_sb.sb_rblocks); - rextslog =xfs_compute_rextslog (mp->m_sb.sb_rextents); - rts->rsumlevels = rextslog +1 ; rts->rbmblocks =xfs_rtbitmap_blockcount (mp); - rts->rsumblocks =xfs_rtsummary_blockcount (mp, rts->rsumlevels, - rts->rbmblocks); + rts->rsumblocks = +xfs_rtsummary_blockcount (mp, &rts->rsumlevels); }return 0 ;
fs/xfs/xfs_mount.h +1 -1
@@ -139,7 +139,7 @@ typedef struct xfs_mount {uint m_allocsize_blocks;/* min write size blocks */ int m_logbufs;/* number of log buffers */ int m_logbsize;/* size of each log buffer */ -uint m_rsumlevels;/* rt summary levels */ +unsigned int m_rsumlevels;/* rt summary levels */ xfs_filblks_t m_rsumblocks;/* size of rt summary, FSBs */ uint32_t m_rgblocks;/* size of rtgroup in rtblocks */ int m_fixedfsid[2 ];/* unchanged for life of FS */
fs/xfs/xfs_rtalloc.c +4 -9
@@ -751,9 +751,7 @@ xfs_growfs_rt_alloc_fake_mount( nmp->m_sb.sb_rextents =xfs_rtb_to_rtx (nmp, nmp->m_sb.sb_rblocks); nmp->m_sb.sb_rbmblocks =xfs_rtbitmap_blockcount (nmp); nmp->m_sb.sb_rextslog =xfs_compute_rextslog (nmp->m_sb.sb_rextents); - nmp->m_rsumlevels = nmp->m_sb.sb_rextslog +1 ; - nmp->m_rsumblocks =xfs_rtsummary_blockcount (nmp, nmp->m_rsumlevels, - nmp->m_sb.sb_rbmblocks); + nmp->m_rsumblocks =xfs_rtsummary_blockcount (nmp, &nmp->m_rsumlevels);if (rblocks >0 ) nmp->m_features |=XFS_FEAT_REALTIME ;
@@ -1138,21 +1136,18 @@ xfs_rtmount_init( struct xfs_mount *mp) /* file system mount structure */ {struct xfs_buf *bp;/* buffer for last block of subvolume */ -struct xfs_sb *sbp;/* filesystem superblock copy in mount */ xfs_daddr_t d;/* address of last block of subvolume */ int error; - sbp = &mp->m_sb; -if (sbp->sb_rblocks ==0 ) +if (mp->m_sb.sb_rblocks ==0 )return 0 ;if (mp->m_rtdev_targp ==NULL ) {xfs_warn (mp,"Filesystem has a realtime volume, use rtdev=device option" );return -ENODEV ; } - mp->m_rsumlevels = sbp->sb_rextslog +1 ; - mp->m_rsumblocks =xfs_rtsummary_blockcount (mp, mp->m_rsumlevels, - mp->m_sb.sb_rbmblocks); + + mp->m_rsumblocks =xfs_rtsummary_blockcount (mp, &mp->m_rsumlevels);/* * Check that the realtime section is an ok size.
PATCH 24/24 xfs: make RT extent numbers relative to the rtgroup
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
To prepare for adding per-rtgroup bitmap files, make the xfs_rtxnum_t type encode the RT extent number relative to the rtgroup. The biggest part of this to clearly distinguish between the relative extent number that gets masked when converting from a global block number and length values that just have a factor applied to them when converting from file system blocks.
--- fs/xfs/libxfs/xfs_bmap.c | 6 ++-- fs/xfs/libxfs/xfs_rtbitmap.h | 69 ++++++++++++++++++++++++++---------------- fs/xfs/scrub/rtbitmap.c | 9 ++--- fs/xfs/scrub/rtsummary.c | 6 ++-- fs/xfs/xfs_discard.c | 4 +- fs/xfs/xfs_fsmap.c | 4 +- fs/xfs/xfs_iomap.c | 4 +- fs/xfs/xfs_mount.c | 2 + fs/xfs/xfs_rtalloc.c | 4 +- fs/xfs/xfs_super.c | 3 +- 10 files changed, 64 insertions(+), 47 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +3 -3
@@ -4126,7 +4126,7 @@ xfs_bmapi_reserve_delalloc( fdblocks = indlen;if (XFS_IS_REALTIME_INODE (ip)) { - error =xfs_dec_frextents (mp,xfs_rtb_to_rtx (mp, alen)); + error =xfs_dec_frextents (mp,xfs_blen_to_rtbxlen (mp, alen));if (error) goto out_unreserve_quota; }else {
@@ -4161,7 +4161,7 @@ xfs_bmapi_reserve_delalloc( out_unreserve_frextents:if (XFS_IS_REALTIME_INODE (ip)) -xfs_add_frextents (mp,xfs_rtb_to_rtx (mp, alen)); +xfs_add_frextents (mp,xfs_blen_to_rtbxlen (mp, alen)); out_unreserve_quota:if (XFS_IS_QUOTA_ON (mp))xfs_quota_unreserve_blkres (ip, alen);
@@ -5088,7 +5088,7 @@ xfs_bmap_del_extent_delay( fdblocks = da_diff;if (isrt) -xfs_add_frextents (mp,xfs_rtb_to_rtx (mp, del->br_blockcount)); +xfs_add_frextents (mp,xfs_blen_to_rtbxlen (mp, del->br_blockcount));else fdblocks += del->br_blockcount;
fs/xfs/libxfs/xfs_rtbitmap.h +43 -26
98 lines not on this page · raw message
fs/xfs/scrub/rtbitmap.c +4 -5
@@ -65,7 +65,7 @@ xchk_setup_rtbitmap(*/ xchk_rtgroup_lock (&sc->sr,XFS_RTGLOCK_BITMAP );if (mp->m_sb.sb_rblocks) { - rtb->rextents =xfs_rtb_to_rtx (mp, mp->m_sb.sb_rblocks); + rtb->rextents =xfs_blen_to_rtbxlen (mp, mp->m_sb.sb_rblocks); rtb->rextslog =xfs_compute_rextslog (rtb->rextents); rtb->rbmblocks =xfs_rtbitmap_blockcount (mp); }
@@ -83,15 +83,14 @@ xchk_rtbitmap_rec(const struct xfs_rtalloc_rec *rec, void *priv) { - struct xfs_mount *mp = rtg->rtg_mount; struct xfs_scrub *sc = priv;xfs_rtblock_t startblock;xfs_filblks_t blockcount; - startblock =xfs_rtx_to_rtb (mp, rec->ar_startext); - blockcount =xfs_rtx_to_rtb (mp, rec->ar_extcount); + startblock =xfs_rtx_to_rtb (rtg, rec->ar_startext); + blockcount =xfs_rtxlen_to_extlen (rtg->rtg_mount, rec->ar_extcount); -if (!xfs_verify_rtbext (mp, startblock, blockcount)) +if (!xfs_verify_rtbext (rtg->rtg_mount, startblock, blockcount))xchk_fblock_set_corrupt (sc,XFS_DATA_FORK ,0 );return 0 ; }
fs/xfs/scrub/rtsummary.c +3 -3
@@ -102,7 +102,7 @@ xchk_setup_rtsummary(*/ xchk_rtgroup_lock (&sc->sr,XFS_RTGLOCK_BITMAP );if (mp->m_sb.sb_rblocks) { - rts->rextents =xfs_rtb_to_rtx (mp, mp->m_sb.sb_rblocks); + rts->rextents =xfs_blen_to_rtbxlen (mp, mp->m_sb.sb_rblocks); rts->rbmblocks =xfs_rtbitmap_blockcount (mp); rts->rsumblocks =xfs_rtsummary_blockcount (mp, &rts->rsumlevels);
@@ -182,8 +182,8 @@ xchk_rtsum_record_free( lenlog =xfs_highbit64 (rec->ar_extcount); offs =xfs_rtsumoffs (mp, lenlog, rbmoff); - rtbno =xfs_rtx_to_rtb (mp, rec->ar_startext); - rtlen =xfs_rtx_to_rtb (mp, rec->ar_extcount); + rtbno =xfs_rtx_to_rtb (rtg, rec->ar_startext); + rtlen =xfs_rtxlen_to_extlen (mp, rec->ar_extcount);if (!xfs_verify_rtbext (mp, rtbno, rtlen)) { xchk_ino_xref_set_corrupt(sc,
fs/xfs/xfs_discard.c +2 -2
@@ -526,8 +526,8 @@ xfs_trim_gather_rtextent(return -ECANCELED ; } - rbno =xfs_rtx_to_rtb (rtg->rtg_mount, rec->ar_startext); - rlen =xfs_rtx_to_rtb (rtg->rtg_mount, rec->ar_extcount); + rbno =xfs_rtx_to_rtb (rtg, rec->ar_startext); + rlen =xfs_rtxlen_to_extlen (rtg->rtg_mount, rec->ar_extcount);/* Ignore too small. */ if (rlen < tr->minlen_fsb) {
fs/xfs/xfs_fsmap.c +2 -2
@@ -726,9 +726,9 @@ xfs_getfsmap_rtdev_rtbitmap_helper(struct xfs_mount *mp = rtg->rtg_mount;struct xfs_getfsmap_info *info = priv;xfs_rtblock_t start_rtb = -xfs_rtx_to_rtb (mp, rec->ar_startext); +xfs_rtx_to_rtb (rtg, rec->ar_startext);uint64_t rtbcount = -xfs_rtx_to_rtb (mp, rec->ar_extcount); +xfs_rtbxlen_to_blen (mp, rec->ar_extcount);struct xfs_rmap_irec irec = { .rm_startblock = start_rtb, .rm_blockcount = rtbcount,
fs/xfs/xfs_iomap.c +2 -2
@@ -501,8 +501,8 @@ xfs_iomap_prealloc_size( alloc_blocks);if (unlikely (XFS_IS_REALTIME_INODE (ip))) - freesp =xfs_rtx_to_rtb (mp, -xfs_iomap_freesp (&mp->m_frextents, + freesp =xfs_rtbxlen_to_blen (mp, +xfs_iomap_freesp (&mp->m_frextents, mp->m_low_rtexts, &shift));else freesp = xfs_iomap_freesp(&mp->m_fdblocks, mp->m_low_space,
fs/xfs/xfs_mount.c +1 -1
@@ -1472,7 +1472,7 @@ xfs_mod_delalloc(if (XFS_IS_REALTIME_INODE (ip)) {percpu_counter_add_batch (&mp->m_delalloc_rtextents, -xfs_rtb_to_rtx (mp, data_delta), +xfs_blen_to_rtbxlen (mp, data_delta),XFS_DELALLOC_BATCH );if (!ind_delta)return ;
fs/xfs/xfs_rtalloc.c +2 -2
@@ -748,7 +748,7 @@ xfs_growfs_rt_alloc_fake_mount( nmp->m_sb.sb_rextsize = rextsize;xfs_mount_sb_set_rextsize (nmp, &nmp->m_sb); nmp->m_sb.sb_rblocks = rblocks; - nmp->m_sb.sb_rextents =xfs_rtb_to_rtx (nmp, nmp->m_sb.sb_rblocks); + nmp->m_sb.sb_rextents =xfs_blen_to_rtbxlen (nmp, nmp->m_sb.sb_rblocks); nmp->m_sb.sb_rbmblocks =xfs_rtbitmap_blockcount (nmp); nmp->m_sb.sb_rextslog =xfs_compute_rextslog (nmp->m_sb.sb_rextents); nmp->m_rsumblocks =xfs_rtsummary_blockcount (nmp, &nmp->m_rsumlevels);
@@ -1464,7 +1464,7 @@ xfs_rtallocate(xfs_trans_mod_sb (tp, wasdel ?XFS_TRANS_SB_RES_FREXTENTS :XFS_TRANS_SB_FREXTENTS , -(long )len); - *bno =xfs_rtx_to_rtb (args.mp, rtx); + *bno =xfs_rtx_to_rtb (args.rtg, rtx); *blen =xfs_rtxlen_to_extlen (args.mp, len); out_release:
fs/xfs/xfs_super.c +2 -1
@@ -885,7 +885,8 @@ xfs_fs_statfs( statp->f_blocks = sbp->sb_rblocks; freertx =percpu_counter_sum_positive (&mp->m_frextents); - statp->f_bavail = statp->f_bfree =xfs_rtx_to_rtb (mp, freertx); + statp->f_bavail = statp->f_bfree = +xfs_rtbxlen_to_blen (mp, freertx); }return 0 ;
PATCH 8/10 xfs: preparation for realtime allocation groups
In reply to Darrick J. WongHi all,
Having cleaned up the rtbitmap code and fixed various weird bugs in the allocator, now we want to do some more cleanups to the rt free space management code to get it ready for the introduction of 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:
* iomap: add a merge boundary flag
--- fs/iomap/buffered-io.c | 6 ++++++ include/linux/iomap.h | 4 ++++ 2 files changed, 10 insertions(+)
PATCH 1/1 iomap: add a merge boundary flag
From: Christoph Hellwig <[email protected]>
File systems might have boundaries over which merges aren't possible. In fact these are very common, although most of the time some kind of header at the beginning of this region (e.g. XFS alloation groups, ext4 block groups) automatically create a merge barrier. But if that is not present, say for a device purely used for data we need to manually communicate that to iomap.
Add a IOMAP_F_BOUNDARY flag to never merge I/O into a previous mapping.
--- fs/iomap/buffered-io.c | 6 ++++++ include/linux/iomap.h | 4 ++++ 2 files changed, 10 insertions(+)
fs/iomap/buffered-io.c +6 -0
@@ -1603,6 +1603,8 @@ iomap_ioend_can_merge(struct iomap_ioend *ioend, struct iomap_ioend *next) {if (ioend->io_bio.bi_status != next->io_bio.bi_status)return false; +if (next->io_flags &IOMAP_F_BOUNDARY ) +return false;if ((ioend->io_flags &IOMAP_F_SHARED ) ^ (next->io_flags &IOMAP_F_SHARED ))return false;
@@ -1722,6 +1724,8 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,INIT_LIST_HEAD (&ioend->io_list); ioend->io_type = wpc->iomap.type; ioend->io_flags = wpc->iomap.flags; +if (pos > wpc->iomap.offset) + wpc->iomap.flags &= ~IOMAP_F_BOUNDARY ; ioend->io_inode = inode; ioend->io_size =0 ; ioend->io_offset = pos;
@@ -1733,6 +1737,8 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,static bool iomap_can_add_to_ioend (struct iomap_writepage_ctx *wpc,loff_t pos) { +if (wpc->iomap.offset == pos && (wpc->iomap.flags &IOMAP_F_BOUNDARY )) +return false;if ((wpc->iomap.flags &IOMAP_F_SHARED ) != (wpc->ioend->io_flags &IOMAP_F_SHARED ))return false;
include/linux/iomap.h +4 -0
@@ -53,6 +53,9 @@ struct vm_fault;* * IOMAP_F_XATTR indicates that the iomap is for an extended attribute extent * rather than a file data extent. +* +* IOMAP_F_BOUNDARY indicates that I/O and I/O completions for this iomap must +* never be merged with the mapping before it. */ #define IOMAP_F_NEW (1U << 0)#define IOMAP_F_DIRTY (1U << 1)
@@ -64,6 +67,7 @@ struct vm_fault;#define IOMAP_F_BUFFER_HEAD 0#endif /* CONFIG_BUFFER_HEAD */ #define IOMAP_F_XATTR (1U << 5) +#define IOMAP_F_BOUNDARY (1U << 6)/* * Flags set by the core iomap code during operations:
PATCH 9/10 xfs: 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. It would be very useful if we could begin to tackle these problems by sharding the realtime section, so create the notion of realtime groups, which are similar to allocation groups on the data section.
While we're at it, define a superblock to be stamped into the start of each rt section. This enables utilities such as blkid to identify block devices containing realtime sections, and helpfully avoids the situation where a file extent can cross an rtgroup boundary.
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.
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:
* xfs: define the format of rt groups
* xfs: check the realtime superblock at mount time
* xfs: update realtime super every time we update the primary fs super
* xfs: export realtime group geometry via XFS_FSOP_GEOM
* xfs: check that rtblock extents do not break rtsupers or rtgroups
* xfs: add a helper to prevent bmap merges across rtgroup boundaries
* xfs: add frextents to the lazysbcounters when rtgroups enabled
* xfs: convert sick_map loops to use ARRAY_SIZE
* xfs: record rt group metadata errors in the health system
* xfs: export the geometry of realtime groups to userspace
* xfs: add block headers to realtime bitmap and summary blocks
* xfs: encode the rtbitmap in big endian format
* xfs: encode the rtsummary in big endian format
* xfs: grow the realtime section when realtime groups are enabled
* xfs: store rtgroup information with a bmap intent
* xfs: force swapext to a realtime file to use the file content exchange ioctl
* xfs: support logging EFIs for realtime extents
* xfs: support error injection when freeing rt extents
* xfs: use realtime EFI to free extents when rtgroups are enabled
* xfs: don't merge ioends across RTGs
* xfs: make the RT allocator rtgroup aware
* xfs: don't coalesce file mappings that cross rtgroup boundaries in scrub
* xfs: scrub the realtime group superblock
* xfs: repair realtime group superblock
* xfs: scrub metadir paths for rtgroup metadata
* xfs: mask off the rtbitmap and summary inodes when metadir in use
--- fs/xfs/Makefile | 1 fs/xfs/libxfs/xfs_alloc.c | 15 + fs/xfs/libxfs/xfs_alloc.h | 17 + fs/xfs/libxfs/xfs_bmap.c | 86 ++++++- fs/xfs/libxfs/xfs_bmap.h | 5 fs/xfs/libxfs/xfs_defer.c | 6 + fs/xfs/libxfs/xfs_defer.h | 1 fs/xfs/libxfs/xfs_format.h | 76 ++++++ fs/xfs/libxfs/xfs_fs.h | 29 ++ fs/xfs/libxfs/xfs_health.h | 61 +++-- fs/xfs/libxfs/xfs_log_format.h | 6 - fs/xfs/libxfs/xfs_log_recover.h | 2 fs/xfs/libxfs/xfs_ondisk.h | 4 fs/xfs/libxfs/xfs_rtbitmap.c | 211 +++++++++++++++--- fs/xfs/libxfs/xfs_rtbitmap.h | 64 +++++ fs/xfs/libxfs/xfs_rtgroup.c | 195 ++++++++++++++++- fs/xfs/libxfs/xfs_rtgroup.h | 20 ++ fs/xfs/libxfs/xfs_sb.c | 165 +++++++++++++- fs/xfs/libxfs/xfs_sb.h | 2 fs/xfs/libxfs/xfs_shared.h | 4 fs/xfs/libxfs/xfs_types.c | 38 +++ fs/xfs/scrub/bmap.c | 16 + fs/xfs/scrub/common.h | 2 fs/xfs/scrub/fscounters_repair.c | 9 - fs/xfs/scrub/health.c | 34 ++- fs/xfs/scrub/metapath.c | 92 ++++++++ fs/xfs/scrub/repair.h | 3 fs/xfs/scrub/rgsuper.c | 89 ++++++++ fs/xfs/scrub/rtsummary.c | 5 fs/xfs/scrub/rtsummary_repair.c | 15 + fs/xfs/scrub/scrub.c | 7 + fs/xfs/scrub/scrub.h | 2 fs/xfs/scrub/stats.c | 1 fs/xfs/scrub/trace.h | 4 fs/xfs/xfs_bmap_item.c | 18 +- fs/xfs/xfs_bmap_util.c | 12 + fs/xfs/xfs_buf_item_recover.c | 43 +++- fs/xfs/xfs_discard.c | 2 fs/xfs/xfs_extfree_item.c | 281 ++++++++++++++++++++++-- fs/xfs/xfs_health.c | 205 +++++++++++------ fs/xfs/xfs_ioctl.c | 37 +++ fs/xfs/xfs_iomap.c | 14 + fs/xfs/xfs_log_recover.c | 2 fs/xfs/xfs_mount.h | 11 + fs/xfs/xfs_rtalloc.c | 446 ++++++++++++++++++++++++++++++++++---- fs/xfs/xfs_rtalloc.h | 6 + fs/xfs/xfs_super.c | 12 + fs/xfs/xfs_trace.h | 30 ++- fs/xfs/xfs_trans.c | 27 ++ fs/xfs/xfs_trans.h | 2 fs/xfs/xfs_trans_buf.c | 25 ++ 51 files changed, 2146 insertions(+), 314 deletions(-) create mode 100644 fs/xfs/scrub/rgsuper.c
PATCH 1/26 xfs: define the format of rt groups
From: Darrick J. Wong <[email protected]>
Define the ondisk format of realtime group metadata, and a superblock for realtime volumes. rt supers are protected by a separate rocompat bit so that we can leave them off if the rt device is zoned.
Add a xfs_sb_version_hasrtgroups so that xfs_repair knows how to zero the tail of superblocks.
For rt group enabled file systems there is a separate bitmap and summary file for each group and thus the number of bitmap and summary blocks needs to be calculated differently.
--- fs/xfs/libxfs/xfs_format.h | 50 +++++++++++++++++++-- fs/xfs/libxfs/xfs_ondisk.h | 3 + fs/xfs/libxfs/xfs_rtbitmap.c | 20 +++++++- fs/xfs/libxfs/xfs_rtgroup.c | 82 ++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_sb.c | 102 +++++++++++++++++++++++++++++++++++++----- fs/xfs/libxfs/xfs_shared.h | 1 fs/xfs/xfs_mount.h | 6 ++ fs/xfs/xfs_rtalloc.c | 30 +++++++++++- 8 files changed, 268 insertions(+), 26 deletions(-)
fs/xfs/libxfs/xfs_format.h +45 -5
@@ -265,8 +265,15 @@ struct xfs_dsb {uuid_t sb_meta_uuid;/* metadata file system unique id */ __be64 sb_metadirino;/* metadata directory tree root */ +__be32 sb_rgcount;/* # of realtime groups */ +__be32 sb_rgextents;/* size of rtgroup in rtx */ -/* must be padded to 64 bit alignment */ +/* +* The size of this structure must be padded to 64 bit alignment. +* +* NOTE: Don't forget to update secondary_sb_whack in xfs_repair when +* adding new fields here. +*/ };#define XFS_SB_CRC_OFF offsetof(struct xfs_dsb, sb_crc)
@@ -355,10 +362,10 @@ xfs_sb_has_compat_feature(return (sbp->sb_features_compat & feature) !=0 ; } -#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */ -#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ -#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ -#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ +#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */ +#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ +#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ +#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ #define XFS_SB_FEAT_RO_COMPAT_ALL \ (XFS_SB_FEAT_RO_COMPAT_FINOBT | \ XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
@@ -722,6 +729,39 @@ union xfs_suminfo_raw {__u32 old; }; +/* +* Realtime allocation groups break the rt section into multiple pieces that +* could be locked independently. Realtime block group numbers are 32-bit +* quantities. Block numbers within a group are also 32-bit quantities, but +* the upper bit must never be set. rtgroup 0 might have a superblock in it, +* so the minimum size of an rtgroup is 2 rtx. +*/ +#define XFS_MAX_RGBLOCKS ((xfs_rgblock_t)(1U << 31) - 1) +#define XFS_MIN_RGEXTENTS ((xfs_rtxlen_t)2) +#define XFS_MAX_RGNUMBER ((xfs_rgnumber_t)(-1U)) + +#define XFS_RTSB_MAGIC 0x46726F67/* 'Frog' */ + +/* +* Realtime superblock - on disk version. Must be padded to 64 bit alignment. +* The first block of the realtime volume contains this superblock. +*/ +struct xfs_rtsb { +__be32 rsb_magicnum;/* magic number == XFS_RTSB_MAGIC */ +__le32 rsb_crc;/* superblock crc */ + +__be32 rsb_pad;/* zero */ +unsigned char rsb_fname[XFSLABEL_MAX ];/* file system name */ + +uuid_t rsb_uuid;/* user-visible file system unique id */ +uuid_t rsb_meta_uuid;/* metadata file system unique id */ + +/* must be padded to 64 bit alignment */ +}; + +#define XFS_RTSB_CRC_OFF offsetof(struct xfs_rtsb, rsb_crc) +#define XFS_RTSB_DADDR ((xfs_daddr_t)0)/* daddr in rt section */ +/* * XFS Timestamps * ==============
fs/xfs/libxfs/xfs_ondisk.h +2 -1
@@ -37,7 +37,7 @@ xfs_check_ondisk_structs(void) XFS_CHECK_STRUCT_SIZE(struct xfs_dinode, 176); XFS_CHECK_STRUCT_SIZE(struct xfs_disk_dquot, 104); XFS_CHECK_STRUCT_SIZE(struct xfs_dqblk, 136); - XFS_CHECK_STRUCT_SIZE(struct xfs_dsb, 272); + XFS_CHECK_STRUCT_SIZE(struct xfs_dsb, 280); XFS_CHECK_STRUCT_SIZE(struct xfs_dsymlink_hdr, 56); XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_key, 4); XFS_CHECK_STRUCT_SIZE(struct xfs_inobt_rec, 16);
@@ -53,6 +53,7 @@ xfs_check_ondisk_structs(void)XFS_CHECK_STRUCT_SIZE (xfs_inobt_ptr_t,4 );XFS_CHECK_STRUCT_SIZE (xfs_refcount_ptr_t,4 );XFS_CHECK_STRUCT_SIZE (xfs_rmap_ptr_t,4 ); + XFS_CHECK_STRUCT_SIZE(struct xfs_rtsb, 56);/* dir/attr trees */ XFS_CHECK_STRUCT_SIZE(struct xfs_attr3_leaf_hdr, 80);
fs/xfs/libxfs/xfs_rtbitmap.c +17 -3
@@ -1157,6 +1157,21 @@ xfs_rtbitmap_blockcount_len(return howmany_64 (rtextents,NBBY * mp->m_sb.sb_blocksize); } +/* How many rt extents does each rtbitmap file track? */ +static inline xfs_rtbxlen_t +xfs_rtbitmap_bitcount ( +struct xfs_mount *mp) +{ +if (!mp->m_sb.sb_rextents) +return 0 ; + +/* rtgroup size can be nonzero even if rextents is zero */ +if (xfs_has_rtgroups (mp)) +return mp->m_sb.sb_rgextents; + +return mp->m_sb.sb_rextents; +} +/* * Compute the number of rtbitmap blocks used for a given file system. */
@@ -1164,7 +1179,7 @@ xfs_filblks_txfs_rtbitmap_blockcount ( struct xfs_mount *mp) { -return xfs_rtbitmap_blockcount_len (mp, mp->m_sb.sb_rextents); +return xfs_rtbitmap_blockcount_len (mp,xfs_rtbitmap_bitcount (mp)); }/*
@@ -1178,8 +1193,7 @@ xfs_rtsummary_blockcount( {unsigned long long rsumwords; - *rsumlevels =xfs_compute_rextslog (mp->m_sb.sb_rextents) +1 ; - + *rsumlevels =xfs_compute_rextslog (xfs_rtbitmap_bitcount (mp)) +1 ; rsumwords =xfs_rtbitmap_blockcount (mp) * (*rsumlevels);return XFS_B_TO_FSB (mp, rsumwords <<XFS_WORDLOG ); }
fs/xfs/libxfs/xfs_rtgroup.c +82 -0
91 lines not on this page · raw message
fs/xfs/libxfs/xfs_sb.c +90 -12
156 lines not on this page · raw message
fs/xfs/libxfs/xfs_shared.h +1 -0
@@ -39,6 +39,7 @@ extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;extern const struct xfs_buf_ops xfs_refcountbt_buf_ops;extern const struct xfs_buf_ops xfs_rmapbt_buf_ops;extern const struct xfs_buf_ops xfs_rtbuf_ops; +extern const struct xfs_buf_ops xfs_rtsb_buf_ops;extern const struct xfs_buf_ops xfs_sb_buf_ops;extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;extern const struct xfs_buf_ops xfs_symlink_buf_ops;
fs/xfs/xfs_mount.h +4 -2
@@ -355,12 +355,14 @@ __XFS_HAS_FEAT(metadir, METADIR)static inline bool xfs_has_rtgroups (struct xfs_mount *mp) { -return false; +/* all metadir file systems also allow rtgroups */ +return xfs_has_metadir (mp); }static inline bool xfs_has_rtsb (struct xfs_mount *mp) { -return false; +/* all rtgroups filesystems with an rt section have an rtsb */ +return xfs_has_rtgroups (mp) &&xfs_has_realtime (mp); }/*
fs/xfs/xfs_rtalloc.c +27 -3
@@ -751,6 +751,11 @@ xfs_growfs_rt_alloc_fake_mount( nmp->m_sb.sb_rextents =xfs_blen_to_rtbxlen (nmp, nmp->m_sb.sb_rblocks); nmp->m_sb.sb_rbmblocks =xfs_rtbitmap_blockcount (nmp); nmp->m_sb.sb_rextslog =xfs_compute_rextslog (nmp->m_sb.sb_rextents); +if (xfs_has_rtgroups (nmp)) + nmp->m_sb.sb_rgcount = +howmany_64 (nmp->m_sb.sb_rextents, nmp->m_sb.sb_rgextents); +else + nmp->m_sb.sb_rgcount =1 ; nmp->m_rsumblocks =xfs_rtsummary_blockcount (nmp, &nmp->m_rsumlevels);if (rblocks >0 )
@@ -761,6 +766,26 @@ xfs_growfs_rt_alloc_fake_mount(return nmp; } +static xfs_rfsblock_t +xfs_growfs_rt_nrblocks ( +struct xfs_rtgroup *rtg, +xfs_rfsblock_t nrblocks, +xfs_agblock_t rextsize, +xfs_fileoff_t bmbno) +{ +struct xfs_mount *mp = rtg->rtg_mount; +xfs_rfsblock_t step; + + step = (bmbno +1 ) *NBBY * mp->m_sb.sb_blocksize * rextsize; +if (xfs_has_rtgroups (mp)) { +xfs_rfsblock_t rgblocks = mp->m_sb.sb_rgextents * rextsize; + + step =min (rgblocks, step) + rgblocks * rtg->rtg_rgno; + } + +return min (nrblocks, step); +} + static int xfs_growfs_rt_bmblock( struct xfs_rtgroup *rtg,
@@ -779,16 +804,15 @@ xfs_growfs_rt_bmblock( .rtg = rtg, };struct xfs_mount *nmp; -xfs_rfsblock_t nrblocks_step;xfs_rtbxlen_t freed_rtx;int error;/* * Calculate new sb and mount fields for this round. */ - nrblocks_step = (bmbno +1 ) *NBBY * mp->m_sb.sb_blocksize * rextsize; nmp = nargs.mp =xfs_growfs_rt_alloc_fake_mount (mp, -min (nrblocks, nrblocks_step), rextsize); +xfs_growfs_rt_nrblocks (rtg, nrblocks, rextsize, bmbno), + rextsize);if (!nmp)return -ENOMEM ;
Re: [PATCH 01/26] xfs: define the format of rt groups
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Define the ondisk format of realtime group metadata, and a superblock for realtime volumes. rt supers are protected by a separate rocompat bit so that we can leave them off if the rt device is zoned.
We actually killed the flag again and just kept the separate helper to check for it.
Quoted 2 lines
Add a
xfs_sb_version_hasrtgroupsso thatxfs_repairknows how to zero the tail of superblocks.
.. and merged the rtgroup and metadir flags, so while this helper still exists (and will get lots of use to make the code readable), that particular use case is gone now.
fs/xfs/libxfs/xfs_format.h xfs_sb_has_compat_feature( · line 368
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h +4
-4-#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */ -#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ -#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ -#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ +#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */ +#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ +#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ +#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */
That also means the above is just a spurious unrelated cleanup now. Still useful, but maybe it should go into a sepaarate patch? Or just don't bother. Btw, one day we should clearly mark all our on-disk bitmaps as unsigned.
fs/xfs/xfs_rtalloc.c xfs_growfs_rt_alloc_fake_mount( · line 756
Quoted 3 lines
fs/xfs/xfs_rtalloc.c +3
-0+if (xfs_has_rtgroups (nmp)) + nmp->m_sb.sb_rgcount = +howmany_64 (nmp->m_sb.sb_rextents, nmp->m_sb.sb_rgextents);
nmp->m_sb.sb_rgcount = howmany_64(nmp->m_sb.sb_rextents, nmp->m_sb.sb_rgextents);
to avoid the overly long line.
Otherwise looks good:
Re: [PATCH 01/26] xfs: define the format of rt groups
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Define the ondisk format of realtime group metadata, and a superblock for realtime volumes. rt supers are protected by a separate rocompat bit so that we can leave them off if the rt device is zoned.
We actually killed the flag again and just kept the separate helper to check for it.
Quoted 6 lines
Quoted 2 lines
Add a
xfs_sb_version_hasrtgroupsso thatxfs_repairknows how to zero the tail of superblocks... and merged the rtgroup and metadir flags, so while this helper still exists (and will get lots of use to make the code readable), that particular use case is gone now.
I'll just delete this sentence since xfs_sb_version_hasmetadir is in another patch anyway.
Quoted 5 lines
Quoted 5 lines
fs/xfs/libxfs/xfs_format.h +1
-4-#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */ -#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ -#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ -#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ +#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */
Quoted 8 lines
fs/xfs/libxfs/xfs_format.h xfs_sb_has_compat_feature( · line 368
Quoted 3 lines
fs/xfs/libxfs/xfs_format.h +3
-0+#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1)/* reverse map btree */ +#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2)/* reflinked files */ +#define XFS_SB_FEAT_RO_COMPAT_INOBTCNT (1 << 3)/* inobt block counts */ That also means the above is just a spurious unrelated cleanup now. Still useful, but maybe it should go into a sepaarate patch? Or just don't bother. Btw, one day we should clearly mark all our on-disk bitmaps as unsigned.
Eh, I'll drop it and make the next new rocompat feature do it.
Quoted 6 lines
fs/xfs/xfs_rtalloc.c xfs_growfs_rt_alloc_fake_mount( · line 756
Quoted 3 lines
fs/xfs/xfs_rtalloc.c +3
-0+if (xfs_has_rtgroups (nmp)) + nmp->m_sb.sb_rgcount = +howmany_64 (nmp->m_sb.sb_rextents, nmp->m_sb.sb_rgextents);nmp->m_sb.sb_rgcount = howmany_64(nmp->m_sb.sb_rextents, nmp->m_sb.sb_rgextents);
Done.
Quoted 5 lines
to avoid the overly long line.
Otherwise looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Thanks!
--D
PATCH 2/26 xfs: check the realtime superblock at mount time
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Check the realtime superblock at mount time, to ensure that the label and uuids actually match the primary superblock on the data device. If the rt superblock is good, attach it to the xfs_mount so that the log can use ordered buffers to keep this primary in sync with the primary super on the data device.
--- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_rtalloc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_rtalloc.h | 6 ++++++ fs/xfs/xfs_super.c | 12 ++++++++++-- 4 files changed, 67 insertions(+), 2 deletions(-)
fs/xfs/xfs_mount.h +1 -0
@@ -85,6 +85,7 @@ typedef struct xfs_mount {struct super_block *m_super;struct xfs_ail *m_ail;/* fs active log item list */ struct xfs_buf *m_sb_bp;/* buffer for superblock */ +struct xfs_buf *m_rtsb_bp;/* realtime superblock */ char *m_rtname;/* realtime device name */ char *m_logname;/* external log device name */ struct xfs_da_geometry *m_dir_geo;/* directory block geometry */
fs/xfs/xfs_rtalloc.c +50 -0
56 lines not on this page · raw message
fs/xfs/xfs_rtalloc.h +6 -0
@@ -12,6 +12,10 @@ struct xfs_mount;struct xfs_trans ;#ifdef CONFIG_XFS_RT +/* rtgroup superblock initialization */ +int xfs_rtmount_readsb (struct xfs_mount *mp); +void xfs_rtmount_freesb (struct xfs_mount *mp); +/* * Initialize realtime fields in the mount structure. */
@@ -42,6 +46,8 @@ int xfs_rtalloc_reinit_frextents(struct xfs_mount *mp);#else # define xfs_growfs_rt (mp,in) (-ENOSYS)# define xfs_rtalloc_reinit_frextents (m) (0) +# define xfs_rtmount_readsb (mp) (0) +# define xfs_rtmount_freesb (mp) ((void)0)static inline int /* error */ xfs_rtmount_init (xfs_mount_t *mp)/* file system mount structure */
fs/xfs/xfs_super.c +10 -2
@@ -45,6 +45,7 @@#include "xfs_rtbitmap.h" #include "xfs_exchmaps_item.h" #include "xfs_parent.h" +#include "xfs_rtalloc.h" #include "scrub/stats.h" #include "scrub/rcbag_btree.h"
@@ -1145,6 +1146,7 @@ xfs_fs_put_super(xfs_filestream_unmount (mp);xfs_unmountfs (mp); +xfs_rtmount_freesb (mp);xfs_freesb (mp);xchk_mount_stats_free (mp);free_percpu (mp->m_stats.xs_stats);
@@ -1680,9 +1682,13 @@ xfs_fs_fill_super( goto out_free_sb; } + error =xfs_rtmount_readsb (mp); +if (error) + goto out_free_sb; + error =xfs_filestream_mount (mp);if (error) - goto out_free_sb; + goto out_free_rtsb;/* * we must configure the block size in the superblock before we run the
@@ -1774,6 +1780,8 @@ xfs_fs_fill_super( out_filestream_unmount:xfs_filestream_unmount (mp); + out_free_rtsb: +xfs_rtmount_freesb (mp); out_free_sb:xfs_freesb (mp); out_free_scrub_stats:
@@ -1793,7 +1801,7 @@ xfs_fs_fill_super( out_unmount:xfs_filestream_unmount (mp);xfs_unmountfs (mp); - goto out_free_sb; + goto out_free_rtsb; } static int
Re: [PATCH 02/26] xfs: check the realtime superblock at mount time
Quoted 7 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Check the realtime superblock at mount time, to ensure that the label and uuids actually match the primary superblock on the data device. If the rt superblock is good, attach it to the
xfs_mountso that the log can use ordered buffers to keep this primary in sync with the primary super on the data device.
Looks good:
PATCH 3/26 xfs: update realtime super every time we update the primary fs super
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Every time we update parts of the primary filesystem superblock that are echoed in the rt superblock, we must update the rt super. Avoid changing the log to support logging to the rt device by using ordered buffers.
--- fs/xfs/libxfs/xfs_rtgroup.c | 60 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 7 +++++ fs/xfs/libxfs/xfs_sb.c | 14 +++++++++- fs/xfs/libxfs/xfs_sb.h | 2 + fs/xfs/xfs_buf_item_recover.c | 18 ++++++++++++ fs/xfs/xfs_ioctl.c | 4 ++- fs/xfs/xfs_trans.c | 1 + fs/xfs/xfs_trans.h | 1 + fs/xfs/xfs_trans_buf.c | 25 ++++++++++++++--- 9 files changed, 124 insertions(+), 8 deletions(-)
fs/xfs/libxfs/xfs_rtgroup.c +60 -0
@@ -609,3 +609,63 @@ const struct xfs_buf_ops xfs_rtsb_buf_ops = { .verify_write = xfs_rtsb_write_verify, .verify_struct = xfs_rtsb_verify_all, }; + +/* Update a realtime superblock from the primary fs super */ +void +xfs_update_rtsb ( +struct xfs_buf *rtsb_bp, +const struct xfs_buf *sb_bp) +{ +const struct xfs_dsb *dsb = sb_bp->b_addr; +struct xfs_rtsb *rsb = rtsb_bp->b_addr; +const uuid_t *meta_uuid; + + rsb->rsb_magicnum =cpu_to_be32 (XFS_RTSB_MAGIC ); + + rsb->rsb_pad =0 ; +memcpy (&rsb->rsb_fname, &dsb->sb_fname,XFSLABEL_MAX ); + +memcpy (&rsb->rsb_uuid, &dsb->sb_uuid,sizeof (rsb->rsb_uuid)); + +/* +* The metadata uuid is the fs uuid if the metauuid feature is not +* enabled. +*/ +if (dsb->sb_features_incompat & +cpu_to_be32 (XFS_SB_FEAT_INCOMPAT_META_UUID )) + meta_uuid = &dsb->sb_meta_uuid; +else + meta_uuid = &dsb->sb_uuid; +memcpy (&rsb->rsb_meta_uuid, meta_uuid,sizeof (rsb->rsb_meta_uuid)); +} + +/* +* Update the realtime superblock from a filesystem superblock and log it to +* the given transaction. +*/ +struct xfs_buf * +xfs_log_rtsb ( +struct xfs_trans *tp, +const struct xfs_buf *sb_bp) +{ +struct xfs_buf *rtsb_bp; + +if (!xfs_has_rtsb (tp->t_mountp)) +return NULL ; + + rtsb_bp =xfs_trans_getrtsb (tp); +if (!rtsb_bp) { +/* +* It's possible for the rtgroups feature to be enabled but +* there is no incore rt superblock buffer if the rt geometry +* was specified at mkfs time but the rt section has not yet +* been attached. In this case, rblocks must be zero. +*/ +ASSERT (tp->t_mountp->m_sb.sb_rblocks ==0 ); +return NULL ; + } + +xfs_update_rtsb (rtsb_bp, sb_bp); +xfs_trans_ordered_buf (tp, rtsb_bp); +return rtsb_bp; +}
fs/xfs/libxfs/xfs_rtgroup.h +7 -0
@@ -258,11 +258,18 @@ static inline const char *xfs_rtginode_path(xfs_rgnumber_t rgno, {return kasprintf (GFP_KERNEL ,"%u.%s" , rgno,xfs_rtginode_name (type)); } + +void xfs_update_rtsb (struct xfs_buf *rtsb_bp, +const struct xfs_buf *sb_bp); +struct xfs_buf *xfs_log_rtsb (struct xfs_trans *tp, +const struct xfs_buf *sb_bp);#else # define xfs_rtgroup_extents (mp, rgno) (0)# define xfs_rtgroup_lock (rtg, gf) ((void)0)# define xfs_rtgroup_unlock (rtg, gf) ((void)0)# define xfs_rtgroup_trans_join (tp, rtg, gf) ((void)0) +# define xfs_update_rtsb (bp, sb_bp) ((void)0) +# define xfs_log_rtsb (tp, sb_bp) (NULL)#endif /* CONFIG_XFS_RT */ #endif /* __LIBXFS_RTGROUP_H */
fs/xfs/libxfs/xfs_sb.c +13 -1
@@ -27,6 +27,7 @@#include "xfs_ag.h" #include "xfs_rtbitmap.h" #include "xfs_exchrange.h" +#include "xfs_rtgroup.h" /* * Physical superblock buffer manipulations. Shared with libxfs in userspace.
@@ -1270,10 +1271,12 @@ xfs_update_secondary_sbs(*/ int xfs_sync_sb_buf ( -struct xfs_mount *mp) +struct xfs_mount *mp, +bool update_rtsb) {struct xfs_trans *tp;struct xfs_buf *bp; +struct xfs_buf *rtsb_bp =NULL ;int error; error =xfs_trans_alloc (mp, &M_RES (mp)->tr_sb,0 ,0 ,0 , &tp);
@@ -1283,6 +1286,11 @@ xfs_sync_sb_buf( bp =xfs_trans_getsb (tp);xfs_log_sb (tp);xfs_trans_bhold (tp, bp); +if (update_rtsb) { + rtsb_bp =xfs_log_rtsb (tp, bp); +if (rtsb_bp) +xfs_trans_bhold (tp, rtsb_bp); + }xfs_trans_set_sync (tp); error =xfs_trans_commit (tp);if (error)
@@ -1291,7 +1299,11 @@ xfs_sync_sb_buf(* write out the sb buffer to get the changes to disk */ error =xfs_bwrite (bp); +if (!error && rtsb_bp) + error =xfs_bwrite (rtsb_bp); out: +if (rtsb_bp) +xfs_buf_relse (rtsb_bp);xfs_buf_relse (bp);return error; }
fs/xfs/libxfs/xfs_sb.h +1 -1
@@ -15,7 +15,7 @@ struct xfs_perag;extern void xfs_log_sb (struct xfs_trans *tp);extern int xfs_sync_sb (struct xfs_mount *mp,bool wait); -extern int xfs_sync_sb_buf (struct xfs_mount *mp); +extern int xfs_sync_sb_buf (struct xfs_mount *mp,bool update_rtsb);extern void xfs_sb_mount_common (struct xfs_mount *mp,struct xfs_sb *sbp);void xfs_mount_sb_set_rextsize (struct xfs_mount *mp,struct xfs_sb *sbp);
fs/xfs/xfs_buf_item_recover.c +18 -0
@@ -22,6 +22,7 @@#include "xfs_inode.h" #include "xfs_dir2.h" #include "xfs_quota.h" +#include "xfs_rtgroup.h" /* * This is the number of entries in the l_buf_cancel_table used during
@@ -995,6 +996,23 @@ xlog_recover_buf_commit_pass2(ASSERT (bp->b_mount == mp); bp->b_flags |= _XBF_LOGRECOVERY;xfs_buf_delwri_queue (bp, buffer_list); + +/* +* Update the rt super if we just recovered the primary fs +* super. +*/ +if (xfs_has_rtsb (mp) && bp->b_ops == &xfs_sb_buf_ops) { +struct xfs_buf *rtsb_bp = mp->m_rtsb_bp; + +if (rtsb_bp) { +xfs_buf_lock (rtsb_bp); +xfs_buf_hold (rtsb_bp); +xfs_update_rtsb (rtsb_bp, bp); + rtsb_bp->b_flags |= _XBF_LOGRECOVERY; +xfs_buf_delwri_queue (rtsb_bp, buffer_list); +xfs_buf_relse (rtsb_bp); + } + } } out_release:
fs/xfs/xfs_ioctl.c +3 -1
@@ -1028,7 +1028,7 @@ xfs_ioc_setlabel(* buffered reads from userspace (i.e. from blkid) are invalidated, * and userspace will see the newly-written label. */ - error =xfs_sync_sb_buf (mp); + error =xfs_sync_sb_buf (mp, true);if (error) goto out;/*
@@ -1039,6 +1039,8 @@ xfs_ioc_setlabel(mutex_unlock (&mp->m_growlock);invalidate_bdev (mp->m_ddev_targp->bt_bdev); +if (xfs_has_rtsb (mp) && mp->m_rtdev_targp) +invalidate_bdev (mp->m_rtdev_targp->bt_bdev); out:mnt_drop_write_file (filp);
fs/xfs/xfs_trans.c +1 -0
@@ -25,6 +25,7 @@#include "xfs_dquot.h" #include "xfs_icache.h" #include "xfs_rtbitmap.h" +#include "xfs_rtgroup.h" struct kmem_cache *xfs_trans_cache;
fs/xfs/xfs_trans.h +1 -0
@@ -214,6 +214,7 @@ xfs_trans_read_buf( }struct xfs_buf *xfs_trans_getsb (struct xfs_trans *); +struct xfs_buf *xfs_trans_getrtsb (struct xfs_trans *tp);void xfs_trans_brelse (xfs_trans_t *,struct xfs_buf *);void xfs_trans_bjoin (xfs_trans_t *,struct xfs_buf *);
fs/xfs/xfs_trans_buf.c +20 -5
@@ -168,12 +168,11 @@ xfs_trans_get_buf_map(/* * Get and lock the superblock buffer for the given transaction. */ -struct xfs_buf * -xfs_trans_getsb ( -struct xfs_trans *tp) +static struct xfs_buf * +__xfs_trans_getsb ( +struct xfs_trans *tp, +struct xfs_buf *bp) { -struct xfs_buf *bp = tp->t_mountp->m_sb_bp; -/* * Just increment the lock recursion count if the buffer is already * attached to this transaction.
@@ -197,6 +196,22 @@ xfs_trans_getsb(return bp; } +struct xfs_buf * +xfs_trans_getsb ( +struct xfs_trans *tp) +{ +return __xfs_trans_getsb (tp, tp->t_mountp->m_sb_bp); +} + +struct xfs_buf * +xfs_trans_getrtsb ( +struct xfs_trans *tp) +{ +if (!tp->t_mountp->m_rtsb_bp) +return NULL ; +return __xfs_trans_getsb (tp, tp->t_mountp->m_rtsb_bp); +} +/* * Get and lock the buffer for the caller if it is not already * locked within the given transaction. If it has not yet been
Re: [PATCH 03/26] xfs: update realtime super every time we update the primary fs super
Looks good:
PATCH 4/26 xfs: export realtime group geometry via XFS_FSOP_GEOM
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Export the realtime geometry information so that userspace can query it.
--- fs/xfs/libxfs/xfs_fs.h | 4 +++- fs/xfs/libxfs/xfs_sb.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_fs.h +3 -1
@@ -186,7 +186,9 @@ struct xfs_fsop_geom {__u32 logsunit;/* log stripe unit, bytes */ uint32_t sick;/* o: unhealthy fs & rt metadata */ uint32_t checked;/* o: checked fs & rt metadata */ -__u64 reserved[17 ];/* reserved space */ +__u32 rgextents;/* rt extents in a realtime group */ +__u32 rgcount;/* number of realtime groups */ +__u64 reserved[16 ];/* reserved space */ };#define XFS_FSOP_GEOM_SICK_COUNTERS (1 << 0)/* summary counters */
fs/xfs/libxfs/xfs_sb.c +5 -0
@@ -1407,6 +1407,11 @@ xfs_fs_geometry(return ; geo->version =XFS_FSOP_GEOM_VERSION_V5 ; + +if (xfs_has_rtgroups (mp)) { + geo->rgcount = sbp->sb_rgcount; + geo->rgextents = sbp->sb_rgextents; + } }/* Read a secondary superblock. */
Re: [PATCH 04/26] xfs: export realtime group geometry via XFS_FSOP_GEOM
Looks good:
PATCH 5/26 xfs: check that rtblock extents do not break rtsupers or rtgroups
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Check that rt block pointers do not point to the realtime superblock and that allocated rt space extents do not cross rtgroup boundaries.
--- fs/xfs/libxfs/xfs_types.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-)
fs/xfs/libxfs/xfs_types.c +33 -5
@@ -12,6 +12,8 @@#include "xfs_bit.h" #include "xfs_mount.h" #include "xfs_ag.h" +#include "xfs_rtbitmap.h" +#include "xfs_rtgroup.h" /*
@@ -135,18 +137,37 @@ xfs_verify_dir_ino( }/* -* Verify that an realtime block number pointer doesn't point off the -* end of the realtime device. +* Verify that a realtime block number pointer neither points outside the +* allocatable areas of the rtgroup nor off the end of the realtime +* device. */ inline bool xfs_verify_rtbno (struct xfs_mount *mp,xfs_rtblock_t rtbno) { -return rtbno < mp->m_sb.sb_rblocks; +if (rtbno >= mp->m_sb.sb_rblocks) +return false; + +if (xfs_has_rtgroups (mp)) { +xfs_rgnumber_t rgno =xfs_rtb_to_rgno (mp, rtbno); +xfs_rtxnum_t rtx =xfs_rtb_to_rtx (mp, rtbno); + +if (rgno >= mp->m_sb.sb_rgcount) +return false; +if (rtx >=xfs_rtgroup_extents (mp, rgno)) +return false; +if (xfs_has_rtsb (mp) && rgno ==0 && rtx ==0 ) +return false; + } +return true; } -/* Verify that a realtime device extent is fully contained inside the volume. */ +/* +* Verify that an allocated realtime device extent neither points outside +* allocatable areas of the rtgroup, across an rtgroup boundary, nor off the +* end of the realtime device. +*/ bool xfs_verify_rtbext( struct xfs_mount *mp,
@@ -159,7 +180,14 @@ xfs_verify_rtbext(if (!xfs_verify_rtbno (mp, rtbno))return false; -return xfs_verify_rtbno (mp, rtbno + len -1 ); +if (!xfs_verify_rtbno (mp, rtbno + len -1 )) +return false; + +if (xfs_has_rtgroups (mp) && +xfs_rtb_to_rgno (mp, rtbno) !=xfs_rtb_to_rgno (mp, rtbno + len -1 )) +return false; + +return true; }/* Calculate the range of valid icount values. */
Re: [PATCH 05/26] xfs: check that rtblock extents do not break rtsupers or rtgroups
Looks good:
PATCH 6/26 xfs: add a helper to prevent bmap merges across rtgroup boundaries
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Except for the rt superblock, realtime groups do not store any metadata at the start (or end) of the group. There is nothing to prevent the bmap code from merging allocations from multiple groups into a single bmap record. Add a helper to check for this case.
--- fs/xfs/libxfs/xfs_bmap.c | 56 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 12 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +44 -12
@@ -40,6 +40,7 @@#include "xfs_bmap_item.h" #include "xfs_symlink_remote.h" #include "xfs_inode_util.h" +#include "xfs_rtgroup.h" struct kmem_cache *xfs_bmap_intent_cache;
@@ -1426,6 +1427,24 @@ xfs_bmap_last_offset(* Extent tree manipulation functions used during allocation. */ +static inline bool +xfs_bmap_same_rtgroup ( +struct xfs_inode *ip, +int whichfork, +struct xfs_bmbt_irec *left, +struct xfs_bmbt_irec *right) +{ +struct xfs_mount *mp = ip->i_mount; + +if (xfs_ifork_is_realtime (ip, whichfork) &&xfs_has_rtgroups (mp)) { +if (xfs_rtb_to_rgno (mp, left->br_startblock) != +xfs_rtb_to_rgno (mp, right->br_startblock)) +return false; + } + +return true; +} +/* * Convert a delayed allocation to a real allocation. */
@@ -1495,7 +1514,8 @@ xfs_bmap_add_extent_delay_real(LEFT .br_startoff +LEFT .br_blockcount == new->br_startoff &&LEFT .br_startblock +LEFT .br_blockcount == new->br_startblock &&LEFT .br_state == new->br_state && - LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) +LEFT .br_blockcount + new->br_blockcount <=XFS_MAX_BMBT_EXTLEN && + xfs_bmap_same_rtgroup(bma->ip, whichfork, &LEFT, new)) state |= BMAP_LEFT_CONTIG;/*
@@ -1519,7 +1539,8 @@ xfs_bmap_add_extent_delay_real( (BMAP_LEFT_CONTIG |BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING ) ||LEFT .br_blockcount + new->br_blockcount +RIGHT .br_blockcount - <= XFS_MAX_BMBT_EXTLEN)) + <= XFS_MAX_BMBT_EXTLEN) && + xfs_bmap_same_rtgroup(bma->ip, whichfork, new, &RIGHT)) state |= BMAP_RIGHT_CONTIG; error =0 ;
@@ -2064,7 +2085,8 @@ xfs_bmap_add_extent_unwritten_real(LEFT .br_startoff +LEFT .br_blockcount == new->br_startoff &&LEFT .br_startblock +LEFT .br_blockcount == new->br_startblock &&LEFT .br_state == new->br_state && - LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) +LEFT .br_blockcount + new->br_blockcount <=XFS_MAX_BMBT_EXTLEN && + xfs_bmap_same_rtgroup(ip, whichfork, &LEFT, new)) state |= BMAP_LEFT_CONTIG;/*
@@ -2088,7 +2110,8 @@ xfs_bmap_add_extent_unwritten_real( (BMAP_LEFT_CONTIG |BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING ) ||LEFT .br_blockcount + new->br_blockcount +RIGHT .br_blockcount - <= XFS_MAX_BMBT_EXTLEN)) + <= XFS_MAX_BMBT_EXTLEN) && + xfs_bmap_same_rtgroup(ip, whichfork, new, &RIGHT)) state |= BMAP_RIGHT_CONTIG;/*
@@ -2597,7 +2620,8 @@ xfs_bmap_add_extent_hole_delay(*/ if ((state &BMAP_LEFT_VALID ) && (state &BMAP_LEFT_DELAY ) && left.br_startoff + left.br_blockcount == new->br_startoff && - left.br_blockcount + new->br_blockcount <=XFS_MAX_BMBT_EXTLEN ) + left.br_blockcount + new->br_blockcount <=XFS_MAX_BMBT_EXTLEN && +xfs_bmap_same_rtgroup (ip, whichfork, &left, new)) state |=BMAP_LEFT_CONTIG ; if ((state & BMAP_RIGHT_VALID) && (state & BMAP_RIGHT_DELAY) &&
@@ -2605,7 +2629,8 @@ xfs_bmap_add_extent_hole_delay( new->br_blockcount + right.br_blockcount <=XFS_MAX_BMBT_EXTLEN && (!(state &BMAP_LEFT_CONTIG ) || (left.br_blockcount + new->br_blockcount + - right.br_blockcount <= XFS_MAX_BMBT_EXTLEN))) + right.br_blockcount <=XFS_MAX_BMBT_EXTLEN )) && + xfs_bmap_same_rtgroup(ip, whichfork, new, &right)) state |= BMAP_RIGHT_CONTIG;/*
@@ -2748,7 +2773,8 @@ xfs_bmap_add_extent_hole_real( left.br_startoff + left.br_blockcount == new->br_startoff && left.br_startblock + left.br_blockcount == new->br_startblock && left.br_state == new->br_state && - left.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) + left.br_blockcount + new->br_blockcount <=XFS_MAX_BMBT_EXTLEN && + xfs_bmap_same_rtgroup(ip, whichfork, &left, new)) state |= BMAP_LEFT_CONTIG; if ((state & BMAP_RIGHT_VALID) && !(state & BMAP_RIGHT_DELAY) &&
@@ -2758,7 +2784,8 @@ xfs_bmap_add_extent_hole_real( new->br_blockcount + right.br_blockcount <=XFS_MAX_BMBT_EXTLEN && (!(state &BMAP_LEFT_CONTIG ) || left.br_blockcount + new->br_blockcount + - right.br_blockcount <= XFS_MAX_BMBT_EXTLEN)) + right.br_blockcount <=XFS_MAX_BMBT_EXTLEN ) && + xfs_bmap_same_rtgroup(ip, whichfork, new, &right)) state |= BMAP_RIGHT_CONTIG; error =0 ;
@@ -5766,6 +5793,8 @@ xfs_bunmapi(*/ STATIC boolxfs_bmse_can_merge ( +struct xfs_inode *ip, +int whichfork,struct xfs_bmbt_irec *left,/* preceding extent */ struct xfs_bmbt_irec *got,/* current extent to shift */ xfs_fileoff_t shift)/* shift fsb */
@@ -5781,7 +5810,8 @@ xfs_bmse_can_merge(if ((left->br_startoff + left->br_blockcount != startoff) || (left->br_startblock + left->br_blockcount != got->br_startblock) || (left->br_state != got->br_state) || - (left->br_blockcount + got->br_blockcount >XFS_MAX_BMBT_EXTLEN )) + (left->br_blockcount + got->br_blockcount >XFS_MAX_BMBT_EXTLEN ) || + !xfs_bmap_same_rtgroup (ip, whichfork, left, got))return false;return true;
@@ -5817,7 +5847,7 @@ xfs_bmse_merge( blockcount = left->br_blockcount + got->br_blockcount;xfs_assert_ilocked (ip,XFS_IOLOCK_EXCL |XFS_ILOCK_EXCL ); -ASSERT (xfs_bmse_can_merge (left, got, shift)); +ASSERT (xfs_bmse_can_merge (ip, whichfork, left, got, shift)); new = *left; new.br_blockcount = blockcount;
@@ -5979,7 +6009,8 @@ xfs_bmap_collapse_extents( goto del_cursor; } -if (xfs_bmse_can_merge (&prev, &got, offset_shift_fsb)) { +if (xfs_bmse_can_merge (ip, whichfork, &prev, &got, + offset_shift_fsb)) { error =xfs_bmse_merge (tp, ip, whichfork, offset_shift_fsb, &icur, &got, &prev, cur, &logflags);
@@ -6115,7 +6146,8 @@ xfs_bmap_insert_extents(* never find mergeable extents in this scenario. Check anyways * and warn if we encounter two extents that could be one. */ -if (xfs_bmse_can_merge (&got, &next, offset_shift_fsb)) +if (xfs_bmse_can_merge (ip, whichfork, &got, &next, + offset_shift_fsb))WARN_ON_ONCE (1 ); }
PATCH 7/26 xfs: add frextents to the lazysbcounters when rtgroups enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make the free rt extent count a part of the lazy sb counters when the realtime groups feature is enabled. This is possible because the patch to recompute frextents from the rtbitmap during log recovery predates the code adding rtgroup support, hence we know that the value will always be correct during runtime.
--- fs/xfs/libxfs/xfs_sb.c | 8 ++++++++ fs/xfs/scrub/fscounters_repair.c | 9 +++++---- fs/xfs/xfs_trans.c | 17 ++++++++++++++--- 3 files changed, 27 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_sb.c +8 -0
@@ -1146,6 +1146,11 @@ xfs_log_sb(* sb counters, despite having a percpu counter. It is always kept * consistent with the ondisk rtbitmap by xfs_trans_apply_sb_deltas() * and hence we don't need have to update it here. +* +* sb_frextents was added to the lazy sb counters when the rt groups +* feature was introduced. This counter can go negative due to the way +* we handle nearly-lockless reservations, so we must use the _positive +* variant here to avoid writing out nonsense frextents. */ if (xfs_has_lazysbcount (mp)) { mp->m_sb.sb_icount =percpu_counter_sum_positive (&mp->m_icount);
@@ -1155,6 +1160,9 @@ xfs_log_sb( mp->m_sb.sb_fdblocks =percpu_counter_sum_positive (&mp->m_fdblocks); } +if (xfs_has_rtgroups (mp)) + mp->m_sb.sb_frextents = +percpu_counter_sum_positive (&mp->m_frextents);xfs_sb_to_disk (bp->b_addr, &mp->m_sb);xfs_trans_buf_set_type (tp, bp,XFS_BLFT_SB_BUF );
fs/xfs/scrub/fscounters_repair.c +5 -4
@@ -68,15 +68,16 @@ xrep_fscounters(/* * Online repair is only supported on v5 file systems, which require -* lazy sb counters and thus no update of sb_fdblocks here. But as of -* now we don't support lazy counting sb_frextents yet, and thus need -* to also update it directly here. And for that we need to keep +* lazy sb counters and thus no update of sb_fdblocks here. But +* sb_frextents only uses a lazy counter with rtgroups, and thus needs +* to be updated directly here otherwise. And for that we need to keep * track of the delalloc reservations separately, as they are are * subtracted from m_frextents, but not included in sb_frextents. */ percpu_counter_set (&mp->m_frextents, fsc->frextents - fsc->frextents_delayed); - mp->m_sb.sb_frextents = fsc->frextents; +if (!xfs_has_rtgroups (mp)) + mp->m_sb.sb_frextents = fsc->frextents;return 0 ; }
fs/xfs/xfs_trans.c +14 -3
@@ -421,6 +421,8 @@ xfs_trans_mod_sb(ASSERT (tp->t_rtx_res_used <= tp->t_rtx_res); } tp->t_frextents_delta += delta; +if (xfs_has_rtgroups (mp)) + flags &= ~XFS_TRANS_SB_DIRTY ;break ;case XFS_TRANS_SB_RES_FREXTENTS :/*
@@ -510,8 +512,14 @@ xfs_trans_apply_sb_deltas(* * Don't touch m_frextents because it includes incore reservations, * and those are handled by the unreserve function. +* +* sb_frextents was added to the lazy sb counters when the rt groups +* feature was introduced. This is possible because we know that all +* kernels supporting rtgroups will also recompute frextents from the +* realtime bitmap. */ -if (tp->t_frextents_delta || tp->t_res_frextents_delta) { +if ((tp->t_frextents_delta || tp->t_res_frextents_delta) && + !xfs_has_rtgroups (tp->t_mountp)) {struct xfs_mount *mp = tp->t_mountp;int64_t rtxdelta;
@@ -619,7 +627,7 @@ xfs_trans_unreserve_and_mod_sb( }ASSERT (tp->t_rtx_res || tp->t_frextents_delta >=0 ); -if (tp->t_flags &XFS_TRANS_SB_DIRTY ) { +if (xfs_has_rtgroups (mp) || (tp->t_flags &XFS_TRANS_SB_DIRTY )) { rtxdelta += tp->t_frextents_delta;ASSERT (rtxdelta >=0 ); }
@@ -655,8 +663,11 @@ xfs_trans_unreserve_and_mod_sb(* Do not touch sb_frextents here because we are dealing with incore * reservation. sb_frextents is not part of the lazy sb counters so it * must be consistent with the ondisk rtbitmap and must never include -* incore reservations. +* incore reservations. sb_frextents was added to the lazy sb counters +* when the realtime groups feature was introduced. */ +if (xfs_has_rtgroups (mp)) + mp->m_sb.sb_frextents += rtxdelta; mp->m_sb.sb_dblocks += tp->t_dblocks_delta; mp->m_sb.sb_agcount += tp->t_agcount_delta; mp->m_sb.sb_imax_pct += tp->t_imaxpct_delta;
Re: [PATCH 07/26] xfs: add frextents to the lazysbcounters when rtgroups enabled
Looks good:
PATCH 8/26 xfs: convert sick_map loops to use ARRAY_SIZE
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Convert these arrays to use ARRAY_SIZE insteead of requiring an empty sentinel array element at the end. This saves memory and would have avoided a bug that worked its way into the next patch.
--- fs/xfs/xfs_health.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
fs/xfs/xfs_health.c +7 -8
@@ -369,6 +369,9 @@ struct ioctl_sick_map {unsigned int ioctl_mask; }; +#define for_each_sick_map (map, m) \ + for ((m) = (map); (m) < (map) + ARRAY_SIZE(map); (m)++) +static const struct ioctl_sick_map fs_map[] = { {XFS_SICK_FS_COUNTERS ,XFS_FSOP_GEOM_SICK_COUNTERS }, {XFS_SICK_FS_UQUOTA ,XFS_FSOP_GEOM_SICK_UQUOTA },
@@ -378,13 +381,11 @@ static const struct ioctl_sick_map fs_map[] = { { XFS_SICK_FS_NLINKS, XFS_FSOP_GEOM_SICK_NLINKS }, { XFS_SICK_FS_METADIR, XFS_FSOP_GEOM_SICK_METADIR }, { XFS_SICK_FS_METAPATH, XFS_FSOP_GEOM_SICK_METAPATH }, - { 0, 0 }, };static const struct ioctl_sick_map rt_map[] = { {XFS_SICK_RT_BITMAP ,XFS_FSOP_GEOM_SICK_RT_BITMAP }, {XFS_SICK_RT_SUMMARY ,XFS_FSOP_GEOM_SICK_RT_SUMMARY }, - {0 ,0 }, }; static inline void
@@ -414,11 +415,11 @@ xfs_fsop_geom_health( geo->checked =0 ;xfs_fs_measure_sickness (mp, &sick, &checked); -for (m = fs_map; m->sick_mask; m++) +for_each_sick_map (fs_map, m)xfgeo_health_tick (geo, sick, checked, m);xfs_rt_measure_sickness (mp, &sick, &checked); -for (m = rt_map; m->sick_mask; m++) +for_each_sick_map (rt_map, m)xfgeo_health_tick (geo, sick, checked, m); }
@@ -434,7 +435,6 @@ static const struct ioctl_sick_map ag_map[] = { { XFS_SICK_AG_RMAPBT, XFS_AG_GEOM_SICK_RMAPBT }, { XFS_SICK_AG_REFCNTBT, XFS_AG_GEOM_SICK_REFCNTBT }, { XFS_SICK_AG_INODES, XFS_AG_GEOM_SICK_INODES }, - { 0, 0 }, };/* Fill out ag geometry health info. */
@@ -451,7 +451,7 @@ xfs_ag_geom_health( ageo->ag_checked =0 ;xfs_ag_measure_sickness (pag, &sick, &checked); -for (m = ag_map; m->sick_mask; m++) { +for_each_sick_map (ag_map, m) {if (checked & m->sick_mask) ageo->ag_checked |= m->ioctl_mask;if (sick & m->sick_mask)
@@ -473,7 +473,6 @@ static const struct ioctl_sick_map ino_map[] = { { XFS_SICK_INO_DIR_ZAPPED, XFS_BS_SICK_DIR }, { XFS_SICK_INO_SYMLINK_ZAPPED, XFS_BS_SICK_SYMLINK }, { XFS_SICK_INO_DIRTREE, XFS_BS_SICK_DIRTREE }, - { 0, 0 }, };/* Fill out bulkstat health info. */
@@ -490,7 +489,7 @@ xfs_bulkstat_health( bs->bs_checked =0 ;xfs_inode_measure_sickness (ip, &sick, &checked); -for (m = ino_map; m->sick_mask; m++) { +for_each_sick_map (ino_map, m) {if (checked & m->sick_mask) bs->bs_checked |= m->ioctl_mask;if (sick & m->sick_mask)
Re: [PATCH 08/26] xfs: convert sick_map loops to use ARRAY_SIZE
Looks good:
PATCH 9/26 xfs: record rt group metadata errors in the health system
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Record the state of per-rtgroup metadata sickness in the rtgroup structure for later reporting.
--- fs/xfs/libxfs/xfs_health.h | 59 ++++++++------- fs/xfs/libxfs/xfs_rtbitmap.c | 37 +++++---- fs/xfs/libxfs/xfs_rtgroup.c | 38 ++++++++-- fs/xfs/libxfs/xfs_rtgroup.h | 9 ++ fs/xfs/scrub/health.c | 33 ++++++-- fs/xfs/xfs_health.c | 164 ++++++++++++++++++++++++------------------ fs/xfs/xfs_trace.h | 30 +++++++- 7 files changed, 236 insertions(+), 134 deletions(-)
fs/xfs/libxfs/xfs_health.h +32 -27
@@ -52,6 +52,7 @@ struct xfs_inode;struct xfs_fsop_geom ;struct xfs_btree_cur ;struct xfs_da_args ; +struct xfs_rtgroup ;/* Observable health issues for metadata spanning the entire filesystem. */ #define XFS_SICK_FS_COUNTERS (1 << 0)/* summary counters */
@@ -63,9 +64,10 @@ struct xfs_da_args;#define XFS_SICK_FS_METADIR (1 << 6)/* metadata directory tree */ #define XFS_SICK_FS_METAPATH (1 << 7)/* metadata directory tree path */ -/* Observable health issues for realtime volume metadata. */ -#define XFS_SICK_RT_BITMAP (1 << 0)/* realtime bitmap */ -#define XFS_SICK_RT_SUMMARY (1 << 1)/* realtime summary */ +/* Observable health issues for realtime group metadata. */ +#define XFS_SICK_RG_SUPER (1 << 0)/* rt group superblock */ +#define XFS_SICK_RG_BITMAP (1 << 1)/* rt group bitmap */ +#define XFS_SICK_RG_SUMMARY (1 << 2)/* rt groups summary */ /* Observable health issues for AG metadata. */ #define XFS_SICK_AG_SB (1 << 0)/* superblock */
@@ -109,8 +111,9 @@ struct xfs_da_args; XFS_SICK_FS_METADIR | \ XFS_SICK_FS_METAPATH) -#define XFS_SICK_RT_PRIMARY (XFS_SICK_RT_BITMAP | \ - XFS_SICK_RT_SUMMARY) +#define XFS_SICK_RG_PRIMARY (XFS_SICK_RG_SUPER | \ + XFS_SICK_RG_BITMAP | \ + XFS_SICK_RG_SUMMARY)#define XFS_SICK_AG_PRIMARY (XFS_SICK_AG_SB | \ XFS_SICK_AG_AGF | \
@@ -140,26 +143,26 @@ struct xfs_da_args;/* Secondary state related to (but not primary evidence of) health problems. */ #define XFS_SICK_FS_SECONDARY (0) -#define XFS_SICK_RT_SECONDARY (0) +#define XFS_SICK_RG_SECONDARY (0)#define XFS_SICK_AG_SECONDARY (0)#define XFS_SICK_INO_SECONDARY (XFS_SICK_INO_FORGET)/* Evidence of health problems elsewhere. */ #define XFS_SICK_FS_INDIRECT (0) -#define XFS_SICK_RT_INDIRECT (0) +#define XFS_SICK_RG_INDIRECT (0)#define XFS_SICK_AG_INDIRECT (XFS_SICK_AG_INODES)#define XFS_SICK_INO_INDIRECT (0)/* All health masks. */ -#define XFS_SICK_FS_ALL (XFS_SICK_FS_PRIMARY | \ +#define XFS_SICK_FS_ALL (XFS_SICK_FS_PRIMARY | \ XFS_SICK_FS_SECONDARY | \ XFS_SICK_FS_INDIRECT) -#define XFS_SICK_RT_ALL (XFS_SICK_RT_PRIMARY | \ - XFS_SICK_RT_SECONDARY | \ - XFS_SICK_RT_INDIRECT) +#define XFS_SICK_RG_ALL (XFS_SICK_RG_PRIMARY | \ + XFS_SICK_RG_SECONDARY | \ + XFS_SICK_RG_INDIRECT) -#define XFS_SICK_AG_ALL (XFS_SICK_AG_PRIMARY | \ +#define XFS_SICK_AG_ALL (XFS_SICK_AG_PRIMARY | \ XFS_SICK_AG_SECONDARY | \ XFS_SICK_AG_INDIRECT)
@@ -193,10 +196,12 @@ void xfs_fs_mark_healthy(struct xfs_mount *mp, unsigned int mask);void xfs_fs_measure_sickness (struct xfs_mount *mp,unsigned int *sick,unsigned int *checked); -void xfs_rt_mark_sick (struct xfs_mount *mp,unsigned int mask); -void xfs_rt_mark_corrupt (struct xfs_mount *mp,unsigned int mask); -void xfs_rt_mark_healthy (struct xfs_mount *mp,unsigned int mask); -void xfs_rt_measure_sickness (struct xfs_mount *mp,unsigned int *sick, +void xfs_rgno_mark_sick (struct xfs_mount *mp,xfs_rgnumber_t rgno, +unsigned int mask); +void xfs_rtgroup_mark_sick (struct xfs_rtgroup *rtg,unsigned int mask); +void xfs_rtgroup_mark_corrupt (struct xfs_rtgroup *rtg,unsigned int mask); +void xfs_rtgroup_mark_healthy (struct xfs_rtgroup *rtg,unsigned int mask); +void xfs_rtgroup_measure_sickness (struct xfs_rtgroup *rtg,unsigned int *sick,unsigned int *checked); void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno,
@@ -230,15 +235,6 @@ xfs_fs_has_sickness(struct xfs_mount *mp, unsigned int mask)return sick & mask; } -static inline bool -xfs_rt_has_sickness (struct xfs_mount *mp,unsigned int mask) -{ -unsigned int sick, checked; - -xfs_rt_measure_sickness (mp, &sick, &checked); -return sick & mask; -} -static inline bool xfs_ag_has_sickness (struct xfs_perag *pag,unsigned int mask) {
@@ -248,6 +244,15 @@ xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask)return sick & mask; } +static inline bool +xfs_rtgroup_has_sickness (struct xfs_rtgroup *rtg,unsigned int mask) +{ +unsigned int sick, checked; + +xfs_rtgroup_measure_sickness (rtg, &sick, &checked); +return sick & mask; +} +static inline bool xfs_inode_has_sickness (struct xfs_inode *ip,unsigned int mask) {
@@ -264,9 +269,9 @@ xfs_fs_is_healthy(struct xfs_mount *mp) }static inline bool -xfs_rt_is_healthy (struct xfs_mount *mp) +xfs_rtgroup_is_healthy (struct xfs_rtgroup *rtg) { -return !xfs_rt_has_sickness (mp,-1U ); +return !xfs_rtgroup_has_sickness (rtg,-1U ); } static inline bool
fs/xfs/libxfs/xfs_rtbitmap.c +19 -18
@@ -76,28 +76,31 @@ static intxfs_rtbuf_get ( struct xfs_rtalloc_args *args, xfs_fileoff_t block, /* block number in bitmap or summary */ - int issum) /* is summary not bitmap */ + enum xfs_rtg_inodes type) { + struct xfs_inode *ip = args->rtg->rtg_inodes[type];struct xfs_mount *mp = args->mp;struct xfs_buf **cbpp;/* cached block buffer */ xfs_fileoff_t *coffp;/* cached block number */ struct xfs_buf *bp;/* block buffer, result */ -struct xfs_inode *ip;/* bitmap or summary inode */ struct xfs_bmbt_irec map; -enum xfs_blft type; +enum xfs_blft buf_type;int nmap =1 ;int error; -if (issum) { +switch (type) { +case XFS_RTGI_SUMMARY : cbpp = &args->sumbp; coffp = &args->sumoff; - ip = args->rtg->rtg_inodes[XFS_RTGI_SUMMARY ]; - type =XFS_BLFT_RTSUMMARY_BUF ; - }else { + buf_type =XFS_BLFT_RTSUMMARY_BUF ; +break ; +case XFS_RTGI_BITMAP : cbpp = &args->rbmbp; coffp = &args->rbmoff; - ip = args->rtg->rtg_inodes[XFS_RTGI_BITMAP ]; - type =XFS_BLFT_RTBITMAP_BUF ; + buf_type =XFS_BLFT_RTBITMAP_BUF ; +break ; +default : +return -EINVAL ; }/*
@@ -120,8 +123,7 @@ xfs_rtbuf_get(return error;if (XFS_IS_CORRUPT (mp, nmap ==0 || !xfs_bmap_is_written_extent (&map))) { -xfs_rt_mark_sick (mp, issum ?XFS_SICK_RT_SUMMARY : -XFS_SICK_RT_BITMAP ); +xfs_rtginode_mark_sick (args->rtg, type);return -EFSCORRUPTED ; }
@@ -130,12 +132,11 @@ xfs_rtbuf_get(XFS_FSB_TO_DADDR (mp, map.br_startblock), mp->m_bsize, 0, &bp, &xfs_rtbuf_ops);if (xfs_metadata_is_sick (error)) -xfs_rt_mark_sick (mp, issum ?XFS_SICK_RT_SUMMARY : -XFS_SICK_RT_BITMAP ); +xfs_rtginode_mark_sick (args->rtg, type);if (error)return error; -xfs_trans_buf_set_type (args->tp, bp, type); +xfs_trans_buf_set_type (args->tp, bp, buf_type); *cbpp = bp; *coffp = block;return 0 ;
@@ -149,11 +150,11 @@ xfs_rtbitmap_read_buf(struct xfs_mount *mp = args->mp;if (XFS_IS_CORRUPT (mp, block >= mp->m_sb.sb_rbmblocks)) { -xfs_rt_mark_sick (mp,XFS_SICK_RT_BITMAP ); +xfs_rtginode_mark_sick (args->rtg,XFS_RTGI_BITMAP );return -EFSCORRUPTED ; } -return xfs_rtbuf_get (args, block,0 ); +return xfs_rtbuf_get (args, block,XFS_RTGI_BITMAP ); }int
@@ -164,10 +165,10 @@ xfs_rtsummary_read_buf(struct xfs_mount *mp = args->mp;if (XFS_IS_CORRUPT (mp, block >= mp->m_rsumblocks)) { -xfs_rt_mark_sick (args->mp,XFS_SICK_RT_SUMMARY ); +xfs_rtginode_mark_sick (args->rtg,XFS_RTGI_SUMMARY );return -EFSCORRUPTED ; } -return xfs_rtbuf_get (args, block,1 ); +return xfs_rtbuf_get (args, block,XFS_RTGI_SUMMARY ); }/*
fs/xfs/libxfs/xfs_rtgroup.c +33 -5
@@ -316,6 +316,8 @@ struct xfs_rtginode_ops {enum xfs_metafile_type metafile_type; +unsigned int sick;/* rtgroup sickness flag */ +/* Does the fs have this feature? */ bool (*enabled)(struct xfs_mount *mp);
@@ -330,11 +332,13 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX] = { [XFS_RTGI_BITMAP ] = { .name ="bitmap" , .metafile_type =XFS_METAFILE_RTBITMAP , + .sick =XFS_SICK_RG_BITMAP , .create = xfs_rtbitmap_create, }, [XFS_RTGI_SUMMARY ] = { .name ="summary" , .metafile_type =XFS_METAFILE_RTSUMMARY , + .sick =XFS_SICK_RG_SUMMARY , .create = xfs_rtsummary_create, }, };
@@ -368,6 +372,17 @@ xfs_rtginode_enabled(return ops->enabled (rtg->rtg_mount); } +/* Mark an rtgroup inode sick */ +void +xfs_rtginode_mark_sick ( +struct xfs_rtgroup *rtg, +enum xfs_rtg_inodes type) +{ +const struct xfs_rtginode_ops *ops = &xfs_rtginode_ops[type]; + +xfs_rtgroup_mark_sick (rtg, ops->sick); +} +/* Load and existing rtgroup inode into the rtgroup structure. */ int xfs_rtginode_load(
@@ -403,8 +418,10 @@ xfs_rtginode_load( }else {const char *path; -if (!mp->m_rtdirip) +if (!mp->m_rtdirip) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + } path =xfs_rtginode_path (rtg->rtg_rgno, type);if (!path)
@@ -414,17 +431,22 @@ xfs_rtginode_load(kfree (path); } -if (error) +if (error) { +if (xfs_metadata_is_sick (error)) +xfs_rtginode_mark_sick (rtg, 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_rtginode_mark_sick (rtg, type);return -EFSCORRUPTED ; }if (XFS_IS_CORRUPT (mp, ip->i_projid != rtg->rtg_rgno)) {xfs_irele (ip); +xfs_rtginode_mark_sick (rtg, type);return -EFSCORRUPTED ; }
@@ -461,8 +483,10 @@ xfs_rtginode_create(if (!xfs_rtginode_enabled (rtg, type))return 0 ; -if (!mp->m_rtdirip) +if (!mp->m_rtdirip) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + } upd.path =xfs_rtginode_path (rtg->rtg_rgno, type);if (!upd.path)
@@ -509,8 +533,10 @@ intxfs_rtginode_mkdir_parent ( struct xfs_mount *mp) { -if (!mp->m_metadirip) +if (!mp->m_metadirip) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + }return xfs_metadir_mkdir (mp->m_metadirip,"rtgroups" , &mp->m_rtdirip); }
@@ -522,8 +548,10 @@ xfs_rtginode_load_parent( {struct xfs_mount *mp = tp->t_mountp; -if (!mp->m_metadirip) +if (!mp->m_metadirip) { +xfs_fs_mark_sick (mp,XFS_SICK_FS_METADIR );return -EFSCORRUPTED ; + }return xfs_metadir_load (tp, mp->m_metadirip,"rtgroups" ,XFS_METAFILE_DIR , &mp->m_rtdirip);
fs/xfs/libxfs/xfs_rtgroup.h +9 -0
@@ -36,6 +36,14 @@ struct xfs_rtgroup {/* Number of blocks in this group */ xfs_rtxnum_t rtg_extents; +/* +* Bitsets of per-rtgroup metadata that have been checked and/or are +* sick. Callers should hold rtg_state_lock before accessing this +* field. +*/ +uint16_t rtg_checked; +uint16_t rtg_sick; +/* * Optional cache of rt summary level per bitmap block with the * invariant that rtg_rsum_cache[bbno] > the maximum i for which
@@ -247,6 +255,7 @@ int xfs_rtginode_load_parent(struct xfs_trans *tp);const char *xfs_rtginode_name (enum xfs_rtg_inodes type);enum xfs_metafile_type xfs_rtginode_metafile_type (enum xfs_rtg_inodes type);bool xfs_rtginode_enabled (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type); +void xfs_rtginode_mark_sick (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type);int xfs_rtginode_load (struct xfs_rtgroup *rtg,enum xfs_rtg_inodes type,struct xfs_trans *tp); int xfs_rtginode_create(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type,
fs/xfs/scrub/health.c +22 -11
@@ -12,6 +12,7 @@#include "xfs_btree.h" #include "xfs_ag.h" #include "xfs_health.h" +#include "xfs_rtgroup.h" #include "scrub/scrub.h" #include "scrub/health.h" #include "scrub/common.h"
@@ -71,9 +72,9 @@enum xchk_health_group {XHG_FS =1 , -XHG_RT ,XHG_AG ,XHG_INO , +XHG_RTGROUP , };struct xchk_health_map {
@@ -100,8 +101,8 @@ static const struct xchk_health_map type_to_health_flag[XFS_SCRUB_TYPE_NR] = { [XFS_SCRUB_TYPE_XATTR] = { XHG_INO, XFS_SICK_INO_XATTR }, [XFS_SCRUB_TYPE_SYMLINK] = { XHG_INO, XFS_SICK_INO_SYMLINK }, [XFS_SCRUB_TYPE_PARENT] = { XHG_INO, XFS_SICK_INO_PARENT }, - [XFS_SCRUB_TYPE_RTBITMAP] = { XHG_RT, XFS_SICK_RT_BITMAP }, - [XFS_SCRUB_TYPE_RTSUM] = { XHG_RT, XFS_SICK_RT_SUMMARY }, + [XFS_SCRUB_TYPE_RTBITMAP] = { XHG_RTGROUP, XFS_SICK_RG_BITMAP }, + [XFS_SCRUB_TYPE_RTSUM] = { XHG_RTGROUP, XFS_SICK_RG_SUMMARY }, [XFS_SCRUB_TYPE_UQUOTA] = { XHG_FS, XFS_SICK_FS_UQUOTA }, [XFS_SCRUB_TYPE_GQUOTA] = { XHG_FS, XFS_SICK_FS_GQUOTA }, [XFS_SCRUB_TYPE_PQUOTA] = { XHG_FS, XFS_SICK_FS_PQUOTA },
@@ -162,12 +163,15 @@ xchk_mark_all_healthy( struct xfs_mount *mp) {struct xfs_perag *pag; +struct xfs_rtgroup *rtg;xfs_agnumber_t agno; +xfs_rgnumber_t rgno;xfs_fs_mark_healthy (mp,XFS_SICK_FS_INDIRECT ); -xfs_rt_mark_healthy (mp,XFS_SICK_RT_INDIRECT );for_each_perag (mp, agno, pag)xfs_ag_mark_healthy (pag,XFS_SICK_AG_INDIRECT ); +for_each_rtgroup (mp, rgno, rtg) +xfs_rtgroup_mark_healthy (rtg,XFS_SICK_RG_INDIRECT ); }/*
@@ -185,6 +189,7 @@ xchk_update_health( struct xfs_scrub *sc) {struct xfs_perag *pag; +struct xfs_rtgroup *rtg;bool bad;/*
@@ -237,11 +242,13 @@ xchk_update_health(else xfs_fs_mark_healthy (sc->mp, sc->sick_mask);break ; -case XHG_RT : +case XHG_RTGROUP : + rtg =xfs_rtgroup_get (sc->mp, sc->sm->sm_agno);if (bad) -xfs_rt_mark_corrupt (sc->mp, sc->sick_mask); +xfs_rtgroup_mark_corrupt (rtg, sc->sick_mask);else -xfs_rt_mark_healthy (sc->mp, sc->sick_mask); +xfs_rtgroup_mark_healthy (rtg, sc->sick_mask); +xfs_rtgroup_put (rtg);break ;default :ASSERT (0 );
@@ -296,7 +303,9 @@ xchk_health_record( {struct xfs_mount *mp = sc->mp;struct xfs_perag *pag; +struct xfs_rtgroup *rtg;xfs_agnumber_t agno; +xfs_rgnumber_t rgno;unsigned int sick;unsigned int checked;
@@ -305,15 +314,17 @@ xchk_health_record(if (sick &XFS_SICK_FS_PRIMARY )xchk_set_corrupt (sc); -xfs_rt_measure_sickness (mp, &sick, &checked); -if (sick &XFS_SICK_RT_PRIMARY ) -xchk_set_corrupt (sc); -for_each_perag (mp, agno, pag) {xfs_ag_measure_sickness (pag, &sick, &checked);if (sick &XFS_SICK_AG_PRIMARY )xchk_set_corrupt (sc); } +for_each_rtgroup (mp, rgno, rtg) { +xfs_rtgroup_measure_sickness (rtg, &sick, &checked); +if (sick &XFS_SICK_RG_PRIMARY ) +xchk_set_corrupt (sc); + } +return 0 ; }
fs/xfs/xfs_health.c +95 -69
213 lines not on this page · raw message
fs/xfs/xfs_trace.h +26 -4
@@ -4224,10 +4224,6 @@ DEFINE_FS_CORRUPT_EVENT(xfs_fs_mark_sick);DEFINE_FS_CORRUPT_EVENT (xfs_fs_mark_corrupt);DEFINE_FS_CORRUPT_EVENT (xfs_fs_mark_healthy);DEFINE_FS_CORRUPT_EVENT (xfs_fs_unfixed_corruption); -DEFINE_FS_CORRUPT_EVENT (xfs_rt_mark_sick); -DEFINE_FS_CORRUPT_EVENT (xfs_rt_mark_corrupt); -DEFINE_FS_CORRUPT_EVENT (xfs_rt_mark_healthy); -DEFINE_FS_CORRUPT_EVENT (xfs_rt_unfixed_corruption); DECLARE_EVENT_CLASS(xfs_ag_corrupt_class, TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno, unsigned int flags),
@@ -4256,6 +4252,32 @@ DEFINE_AG_CORRUPT_EVENT(xfs_ag_mark_corrupt);DEFINE_AG_CORRUPT_EVENT (xfs_ag_mark_healthy);DEFINE_AG_CORRUPT_EVENT (xfs_ag_unfixed_corruption); +DECLARE_EVENT_CLASS (xfs_rtgroup_corrupt_class, + TP_PROTO(struct xfs_rtgroup *rtg, unsigned int flags), +TP_ARGS (rtg, flags), +TP_STRUCT__entry ( + __field(dev_t, dev) + __field(xfs_rgnumber_t, rgno) + __field(unsigned int, flags) + ), +TP_fast_assign ( + __entry->dev = rtg->rtg_mount->m_super->s_dev; + __entry->rgno = rtg->rtg_rgno; + __entry->flags = flags; + ), +TP_printk ("dev %d:%d rgno 0x%x flags 0x%x" , +MAJOR (__entry->dev),MINOR (__entry->dev), + __entry->rgno, __entry->flags) +); +#define DEFINE_RTGROUP_CORRUPT_EVENT (name) \ +DEFINE_EVENT(xfs_rtgroup_corrupt_class, name, \ + TP_PROTO(struct xfs_rtgroup *rtg, unsigned int flags), \ + TP_ARGS(rtg, flags)) +DEFINE_RTGROUP_CORRUPT_EVENT (xfs_rtgroup_mark_sick); +DEFINE_RTGROUP_CORRUPT_EVENT (xfs_rtgroup_mark_corrupt); +DEFINE_RTGROUP_CORRUPT_EVENT (xfs_rtgroup_mark_healthy); +DEFINE_RTGROUP_CORRUPT_EVENT (xfs_rtgroup_unfixed_corruption); + DECLARE_EVENT_CLASS(xfs_inode_corrupt_class, TP_PROTO(struct xfs_inode *ip, unsigned int flags), TP_ARGS(ip, flags),
Re: [PATCH 09/26] xfs: record rt group metadata errors in the health system
Looks good:
PATCH 10/26 xfs: export the geometry of realtime groups to userspace
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create an ioctl so that the kernel can report the status of realtime groups to userspace.
--- fs/xfs/libxfs/xfs_fs.h | 17 +++++++++++++++++ fs/xfs/libxfs/xfs_health.h | 2 ++ fs/xfs/libxfs/xfs_rtgroup.c | 15 +++++++++++++++ fs/xfs/libxfs/xfs_rtgroup.h | 4 ++++ fs/xfs/xfs_health.c | 28 ++++++++++++++++++++++++++++ fs/xfs/xfs_ioctl.c | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+)
fs/xfs/libxfs/xfs_fs.h +17 -0
@@ -971,6 +971,22 @@ struct xfs_getparents_by_handle {struct xfs_getparents gph_request; }; +/* +* Output for XFS_IOC_RTGROUP_GEOMETRY +*/ +struct xfs_rtgroup_geometry { +__u32 rg_number;/* i/o: rtgroup number */ +__u32 rg_length;/* o: length in blocks */ +__u32 rg_capacity;/* o: usable capacity in blocks */ +__u32 rg_sick;/* o: sick things in ag */ +__u32 rg_checked;/* o: checked metadata in ag */ +__u32 rg_flags;/* i/o: flags for this ag */ +__u64 rg_reserved[13 ];/* o: zero */ +}; +#define XFS_RTGROUP_GEOM_SICK_SUPER (1U << 0)/* superblock */ +#define XFS_RTGROUP_GEOM_SICK_BITMAP (1U << 1)/* rtbitmap */ +#define XFS_RTGROUP_GEOM_SICK_SUMMARY (1U << 2)/* rtsummary */ +/* * ioctl commands that are used by Linux filesystems */
@@ -1009,6 +1025,7 @@ struct xfs_getparents_by_handle {#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents)#define XFS_IOC_GETPARENTS_BY_HANDLE _IOWR('X', 63, struct xfs_getparents_by_handle)#define XFS_IOC_SCRUBV_METADATA _IOWR('X', 64, struct xfs_scrub_vec_head) +#define XFS_IOC_RTGROUP_GEOMETRY _IOWR('X', 65, struct xfs_rtgroup_geometry)/* * ioctl commands that replace IRIX syssgi()'s
fs/xfs/libxfs/xfs_health.h +2 -0
@@ -288,6 +288,8 @@ xfs_inode_is_healthy(struct xfs_inode *ip)void xfs_fsop_geom_health (struct xfs_mount *mp,struct xfs_fsop_geom *geo);void xfs_ag_geom_health (struct xfs_perag *pag,struct xfs_ag_geometry *ageo); +void xfs_rtgroup_geom_health (struct xfs_rtgroup *rtg, +struct xfs_rtgroup_geometry *rgeo);void xfs_bulkstat_health (struct xfs_inode *ip,struct xfs_bulkstat *bs);#define xfs_metadata_is_sick (error) \
fs/xfs/libxfs/xfs_rtgroup.c +15 -0
@@ -259,6 +259,21 @@ xfs_rtgroup_trans_join( } } +/* Retrieve rt group geometry. */ +int +xfs_rtgroup_get_geometry ( +struct xfs_rtgroup *rtg, +struct xfs_rtgroup_geometry *rgeo) +{ +/* Fill out form. */ +memset (rgeo,0 ,sizeof (*rgeo)); + rgeo->rg_number = rtg->rtg_rgno; + rgeo->rg_length = rtg->rtg_extents * rtg->rtg_mount->m_sb.sb_rextsize; + rgeo->rg_capacity = rgeo->rg_length; +xfs_rtgroup_geom_health (rtg, rgeo); +return 0 ; +} +#ifdef CONFIG_PROVE_LOCKING static struct lock_class_key xfs_rtginode_lock_class;
fs/xfs/libxfs/xfs_rtgroup.h +4 -0
@@ -249,6 +249,9 @@ void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);void xfs_rtgroup_trans_join (struct xfs_trans *tp,struct xfs_rtgroup *rtg,unsigned int rtglock_flags); +int xfs_rtgroup_get_geometry (struct xfs_rtgroup *rtg, +struct xfs_rtgroup_geometry *rgeo); +int xfs_rtginode_mkdir_parent (struct xfs_mount *mp);int xfs_rtginode_load_parent (struct xfs_trans *tp);
@@ -279,6 +282,7 @@ struct xfs_buf *xfs_log_rtsb(struct xfs_trans *tp,# define xfs_rtgroup_trans_join (tp, rtg, gf) ((void)0)# define xfs_update_rtsb (bp, sb_bp) ((void)0)# define xfs_log_rtsb (tp, sb_bp) (NULL) +# define xfs_rtgroup_get_geometry (rtg, rgeo) (-EOPNOTSUPP)#endif /* CONFIG_XFS_RT */ #endif /* __LIBXFS_RTGROUP_H */
fs/xfs/xfs_health.c +28 -0
@@ -485,6 +485,34 @@ xfs_ag_geom_health( } } +static const struct ioctl_sick_map rtgroup_map[] = { + {XFS_SICK_RG_SUPER ,XFS_RTGROUP_GEOM_SICK_SUPER }, + {XFS_SICK_RG_BITMAP ,XFS_RTGROUP_GEOM_SICK_BITMAP }, + {XFS_SICK_RG_SUMMARY ,XFS_RTGROUP_GEOM_SICK_SUMMARY }, +}; + +/* Fill out rtgroup geometry health info. */ +void +xfs_rtgroup_geom_health ( +struct xfs_rtgroup *rtg, +struct xfs_rtgroup_geometry *rgeo) +{ +const struct ioctl_sick_map *m; +unsigned int sick; +unsigned int checked; + + rgeo->rg_sick =0 ; + rgeo->rg_checked =0 ; + +xfs_rtgroup_measure_sickness (rtg, &sick, &checked); +for_each_sick_map (rtgroup_map, m) { +if (checked & m->sick_mask) + rgeo->rg_checked |= m->ioctl_mask; +if (sick & m->sick_mask) + rgeo->rg_sick |= m->ioctl_mask; + } +} +static const struct ioctl_sick_map ino_map[] = { {XFS_SICK_INO_CORE ,XFS_BS_SICK_INODE }, {XFS_SICK_INO_BMBTD ,XFS_BS_SICK_BMBTD },
fs/xfs/xfs_ioctl.c +33 -0
@@ -40,6 +40,7 @@#include "xfs_file.h" #include "xfs_exchrange.h" #include "xfs_handle.h" +#include "xfs_rtgroup.h" #include <linux/mount.h> #include <linux/fileattr.h>
@@ -403,6 +404,36 @@ xfs_ioc_ag_geometry(return 0 ; } +STATIC int +xfs_ioc_rtgroup_geometry ( +struct xfs_mount *mp, +void __user *arg) +{ +struct xfs_rtgroup *rtg; +struct xfs_rtgroup_geometry rgeo; +int error; + +if (copy_from_user (&rgeo, arg,sizeof (rgeo))) +return -EFAULT ; +if (rgeo.rg_flags) +return -EINVAL ; +if (memchr_inv (&rgeo.rg_reserved,0 ,sizeof (rgeo.rg_reserved))) +return -EINVAL ; + + rtg =xfs_rtgroup_get (mp, rgeo.rg_number); +if (!rtg) +return -EINVAL ; + + error =xfs_rtgroup_get_geometry (rtg, &rgeo); +xfs_rtgroup_put (rtg); +if (error) +return error; + +if (copy_to_user (arg, &rgeo,sizeof (rgeo))) +return -EFAULT ; +return 0 ; +} +/* * Linux extended inode flags interface. */
@@ -1225,6 +1256,8 @@ xfs_file_ioctl(case XFS_IOC_AG_GEOMETRY :return xfs_ioc_ag_geometry (mp, arg); +case XFS_IOC_RTGROUP_GEOMETRY : +return xfs_ioc_rtgroup_geometry (mp, arg);case XFS_IOC_GETVERSION :return put_user (inode->i_generation, (int __user *)arg);
Re: [PATCH 10/26] xfs: export the geometry of realtime groups to userspace
Looks good:
PATCH 11/26 xfs: add block headers to realtime bitmap and summary blocks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Upgrade rtbitmap and rtsummary blocks to have self describing metadata like most every other thing in XFS.
--- fs/xfs/libxfs/xfs_format.h | 18 +++++ fs/xfs/libxfs/xfs_ondisk.h | 1 fs/xfs/libxfs/xfs_rtbitmap.c | 146 +++++++++++++++++++++++++++++++++++---- fs/xfs/libxfs/xfs_rtbitmap.h | 50 +++++++++++++ fs/xfs/libxfs/xfs_sb.c | 20 +++++ fs/xfs/libxfs/xfs_shared.h | 2 + fs/xfs/scrub/rtsummary_repair.c | 15 +++- fs/xfs/xfs_buf_item_recover.c | 25 ++++++- fs/xfs/xfs_discard.c | 2 - fs/xfs/xfs_mount.h | 3 + fs/xfs/xfs_rtalloc.c | 2 - 11 files changed, 256 insertions(+), 28 deletions(-)
fs/xfs/libxfs/xfs_format.h +18 -0
@@ -1272,6 +1272,24 @@ static inline bool xfs_dinode_has_large_extent_counts(#define XFS_DFL_RTEXTSIZE (64 * 1024)/* 64kB */ #define XFS_MIN_RTEXTSIZE (4 * 1024)/* 4kB */ +/* +* RT bit manipulation macros. +*/ +#define XFS_RTBITMAP_MAGIC 0x424D505A/* BMPZ */ +#define XFS_RTSUMMARY_MAGIC 0x53554D59/* SUMY */ + +struct xfs_rtbuf_blkinfo { +__be32 rt_magic;/* validity check on block */ +__be32 rt_crc;/* CRC of block */ +__be64 rt_owner;/* inode that owns the block */ +__be64 rt_blkno;/* first block of the buffer */ +__be64 rt_lsn;/* sequence number of last write */ +uuid_t rt_uuid;/* filesystem we belong to */ +}; + +#define XFS_RTBUF_CRC_OFF \ + offsetof(struct xfs_rtbuf_blkinfo, rt_crc) +/* * Dquot and dquot block format definitions */
fs/xfs/libxfs/xfs_ondisk.h +1 -0
@@ -76,6 +76,7 @@ xfs_check_ondisk_structs(void)/* realtime structures */ XFS_CHECK_STRUCT_SIZE(union xfs_rtword_raw, 4); XFS_CHECK_STRUCT_SIZE(union xfs_suminfo_raw, 4); + XFS_CHECK_STRUCT_SIZE(struct xfs_rtbuf_blkinfo, 48);/* * m68k has problems with xfs_attr_leaf_name_remote_t, but we pad it to
fs/xfs/libxfs/xfs_rtbitmap.c +131 -15
220 lines not on this page · raw message
fs/xfs/libxfs/xfs_rtbitmap.h +48 -2
104 lines not on this page · raw message
fs/xfs/libxfs/xfs_sb.c +17 -3
@@ -245,11 +245,25 @@ xfs_extents_per_rbm(return sbp->sb_rextents; } +/* +* Return the payload size of a single rt bitmap block (without the metadata +* header if any). +*/ +static inline unsigned int +xfs_rtbmblock_size ( +struct xfs_sb *sbp) +{ +if (xfs_sb_version_hasmetadir (sbp)) +return sbp->sb_blocksize -sizeof (struct xfs_rtbuf_blkinfo ); +return sbp->sb_blocksize; +} +static uint64_t xfs_expected_rbmblocks (struct xfs_sb *sbp) { -return howmany_64 (xfs_extents_per_rbm (sbp),NBBY * sbp->sb_blocksize); +return howmany_64 (xfs_extents_per_rbm (sbp), +NBBY *xfs_rtbmblock_size (sbp)); }/* Validate the realtime geometry */
@@ -1092,8 +1106,8 @@ xfs_sb_mount_common( mp->m_sectbb_log = sbp->sb_sectlog -BBSHIFT ; mp->m_agno_log =xfs_highbit32 (sbp->sb_agcount -1 ) +1 ; mp->m_blockmask = sbp->sb_blocksize -1 ; - mp->m_blockwsize = sbp->sb_blocksize >>XFS_WORDLOG ; - mp->m_blockwmask = mp->m_blockwsize -1 ; + mp->m_blockwsize =xfs_rtbmblock_size (sbp) >>XFS_WORDLOG ; + mp->m_rtx_per_rbmblock = mp->m_blockwsize <<XFS_NBWORDLOG ;xfs_mount_sb_set_rextsize (mp, sbp); mp->m_alloc_mxr[0 ] =xfs_allocbt_maxrecs (mp, sbp->sb_blocksize,1 );
fs/xfs/libxfs/xfs_shared.h +2 -0
@@ -38,6 +38,8 @@ extern const struct xfs_buf_ops xfs_inode_buf_ops;extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;extern const struct xfs_buf_ops xfs_refcountbt_buf_ops;extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; +extern const struct xfs_buf_ops xfs_rtbitmap_buf_ops; +extern const struct xfs_buf_ops xfs_rtsummary_buf_ops;extern const struct xfs_buf_ops xfs_rtbuf_ops;extern const struct xfs_buf_ops xfs_rtsb_buf_ops;extern const struct xfs_buf_ops xfs_sb_buf_ops;
fs/xfs/scrub/rtsummary_repair.c +13 -2
@@ -83,12 +83,23 @@ xrep_rtsummary_prep_buf( ondisk =xfs_rsumblock_infoptr (&rts->args,0 ); rts->args.sumbp =NULL ; - bp->b_ops = &xfs_rtbuf_ops; - error =xfsum_copyout (sc, rts->prep_wordoff, ondisk, mp->m_blockwsize);if (error)return error; +if (xfs_has_rtgroups (sc->mp)) { +struct xfs_rtbuf_blkinfo *hdr = bp->b_addr; + + hdr->rt_magic =cpu_to_be32 (XFS_RTSUMMARY_MAGIC ); + hdr->rt_owner =cpu_to_be64 (sc->ip->i_ino); + hdr->rt_blkno =cpu_to_be64 (xfs_buf_daddr (bp)); + hdr->rt_lsn =0 ; +uuid_copy (&hdr->rt_uuid, &sc->mp->m_sb.sb_meta_uuid); + bp->b_ops = &xfs_rtsummary_buf_ops; + }else { + bp->b_ops = &xfs_rtbuf_ops; + } + rts->prep_wordoff += mp->m_blockwsize;xfs_trans_buf_set_type (sc->tp, bp,XFS_BLFT_RTSUMMARY_BUF );return 0 ;
fs/xfs/xfs_buf_item_recover.c +22 -3
@@ -23,6 +23,7 @@#include "xfs_dir2.h" #include "xfs_quota.h" #include "xfs_rtgroup.h" +#include "xfs_rtbitmap.h" /* * This is the number of entries in the l_buf_cancel_table used during
@@ -391,9 +392,18 @@ xlog_recover_validate_buf_type(break ;#ifdef CONFIG_XFS_RT case XFS_BLFT_RTBITMAP_BUF : +if (xfs_has_rtgroups (mp) && magic32 !=XFS_RTBITMAP_MAGIC ) { + warnmsg ="Bad rtbitmap magic!" ; +break ; + } + bp->b_ops =xfs_rtblock_ops (mp,XFS_RTGI_BITMAP ); +break ;case XFS_BLFT_RTSUMMARY_BUF : -/* no magic numbers for verification of RT buffers */ - bp->b_ops = &xfs_rtbuf_ops; +if (xfs_has_rtgroups (mp) && magic32 !=XFS_RTSUMMARY_MAGIC ) { + warnmsg ="Bad rtsummary magic!" ; +break ; + } + bp->b_ops =xfs_rtblock_ops (mp,XFS_RTGI_SUMMARY );break ;#endif /* CONFIG_XFS_RT */ default :
@@ -728,11 +738,20 @@ xlog_recover_get_buf_lsn(* UUIDs, so we must recover them immediately. */ blft =xfs_blft_from_flags (buf_f); -if (blft ==XFS_BLFT_RTBITMAP_BUF || blft ==XFS_BLFT_RTSUMMARY_BUF ) +if (!xfs_has_rtgroups (mp) && (blft ==XFS_BLFT_RTBITMAP_BUF || + blft ==XFS_BLFT_RTSUMMARY_BUF )) goto recover_immediately; magic32 =be32_to_cpu (*(__be32 *)blk);switch (magic32) { +case XFS_RTSUMMARY_MAGIC : +case XFS_RTBITMAP_MAGIC : { +struct xfs_rtbuf_blkinfo *hdr = blk; + + lsn =be64_to_cpu (hdr->rt_lsn); + uuid = &hdr->rt_uuid; +break ; + }case XFS_ABTB_CRC_MAGIC :case XFS_ABTC_CRC_MAGIC :case XFS_ABTB_MAGIC :
fs/xfs/xfs_discard.c +1 -1
@@ -572,7 +572,7 @@ xfs_trim_rtg_extents(* trims the extents returned. */ do { - tr.stop_rtx = low + (mp->m_sb.sb_blocksize * NBBY); + tr.stop_rtx = low + xfs_rtbitmap_rtx_per_rbmblock(mp); xfs_rtgroup_lock(rtg, XFS_RTGLOCK_BITMAP_SHARED); error = xfs_rtalloc_query_range(rtg, tp, low, high, xfs_trim_gather_rtextent, &tr);
fs/xfs/xfs_mount.h +2 -1
@@ -116,7 +116,8 @@ typedef struct xfs_mount {int8_t m_rgblklog;/* log2 of rt group sz if possible */ uint m_blockmask;/* sb_blocksize-1 */ uint m_blockwsize;/* sb_blocksize in words */ -uint m_blockwmask;/* blockwsize-1 */ +/* number of rt extents per rt bitmap block if rtgroups enabled */ +unsigned int m_rtx_per_rbmblock;uint m_alloc_mxr[2 ];/* max alloc btree records */ uint m_alloc_mnr[2 ];/* min alloc btree records */ uint m_bmap_dmxr[2 ];/* max bmap btree records */
fs/xfs/xfs_rtalloc.c +1 -1
@@ -776,7 +776,7 @@ xfs_growfs_rt_nrblocks(struct xfs_mount *mp = rtg->rtg_mount;xfs_rfsblock_t step; - step = (bmbno +1 ) *NBBY * mp->m_sb.sb_blocksize * rextsize; + step = (bmbno +1 ) * mp->m_rtx_per_rbmblock * rextsize;if (xfs_has_rtgroups (mp)) {xfs_rfsblock_t rgblocks = mp->m_sb.sb_rgextents * rextsize;
Re: [PATCH 11/26] xfs: add block headers to realtime bitmap and summary blocks
Looks good:
PATCH 12/26 xfs: encode the rtbitmap in big endian format
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Currently, the ondisk realtime bitmap file is accessed in units of 32-bit words. There's no endian translation of the contents of this file, which means that the Bad Things Happen(tm) if you go from (say) x86 to powerpc. Since we have a new feature flag, let's take the opportunity to enforce an endianness on the file.
--- fs/xfs/libxfs/xfs_format.h | 4 +++- fs/xfs/libxfs/xfs_rtbitmap.h | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_format.h +3 -1
@@ -715,10 +715,12 @@ struct xfs_agfl {/* * Realtime bitmap information is accessed by the word, which is currently -* stored in host-endian format. +* stored in host-endian format. Starting with the realtime groups feature, +* the words are stored in be32 ondisk. */ union xfs_rtword_raw {__u32 old; +__be32 rtg; };/*
fs/xfs/libxfs/xfs_rtbitmap.h +6 -1
@@ -210,6 +210,8 @@ xfs_rtbitmap_getword( {union xfs_rtword_raw *word =xfs_rbmblock_wordptr (args, index); +if (xfs_has_rtgroups (args->mp)) +return be32_to_cpu (word->rtg);return word->old; }
@@ -222,7 +224,10 @@ xfs_rtbitmap_setword( {union xfs_rtword_raw *word =xfs_rbmblock_wordptr (args, index); - word->old = value; +if (xfs_has_rtgroups (args->mp)) + word->rtg =cpu_to_be32 (value); +else + word->old = value; }/*
Re: [PATCH 12/26] xfs: encode the rtbitmap in big endian format
Looks good:
PATCH 13/26 xfs: encode the rtsummary in big endian format
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Currently, the ondisk realtime summary file counters are accessed in units of 32-bit words. There's no endian translation of the contents of this file, which means that the Bad Things Happen(tm) if you go from (say) x86 to powerpc. Since we have a new feature flag, let's take the opportunity to enforce an endianness on the file. Encode the summary information in big endian format, like most of the rest of the filesystem.
--- fs/xfs/libxfs/xfs_format.h | 4 +++- fs/xfs/libxfs/xfs_rtbitmap.h | 7 +++++++ fs/xfs/scrub/rtsummary.c | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_format.h +3 -1
@@ -725,10 +725,12 @@ union xfs_rtword_raw {/* * Realtime summary counts are accessed by the word, which is currently -* stored in host-endian format. +* stored in host-endian format. Starting with the realtime groups feature, +* the words are stored in be32 ondisk. */ union xfs_suminfo_raw {__u32 old; +__be32 rtg; };/*
fs/xfs/libxfs/xfs_rtbitmap.h +7 -0
@@ -300,6 +300,8 @@ xfs_suminfo_get( {union xfs_suminfo_raw *info =xfs_rsumblock_infoptr (args, index); +if (xfs_has_rtgroups (args->mp)) +return be32_to_cpu (info->rtg);return info->old; }
@@ -312,6 +314,11 @@ xfs_suminfo_add( {union xfs_suminfo_raw *info =xfs_rsumblock_infoptr (args, index); +if (xfs_has_rtgroups (args->mp)) { +be32_add_cpu (&info->rtg, delta); +return be32_to_cpu (info->rtg); + } + info->old += delta;return info->old; }
fs/xfs/scrub/rtsummary.c +5 -0
@@ -151,6 +151,11 @@ xchk_rtsum_inc(struct xfs_mount *mp, union xfs_suminfo_raw *v) { + if (xfs_has_rtgroups(mp)) { + be32_add_cpu(&v->rtg, 1); +return be32_to_cpu (v->rtg); + } + v->old +=1 ;return v->old; }
Re: [PATCH 13/26] xfs: encode the rtsummary in big endian format
Looks good:
PATCH 14/26 xfs: grow the realtime section when realtime groups are enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable growing the rt section when realtime groups are enabled.
--- fs/xfs/libxfs/xfs_shared.h | 1 fs/xfs/xfs_rtalloc.c | 268 ++++++++++++++++++++++++++++++++++++++------ fs/xfs/xfs_trans.c | 9 + fs/xfs/xfs_trans.h | 1 4 files changed, 242 insertions(+), 37 deletions(-)
fs/xfs/libxfs/xfs_shared.h +1 -0
@@ -160,6 +160,7 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,#define XFS_TRANS_SB_RBLOCKS 0x00000800#define XFS_TRANS_SB_REXTENTS 0x00001000#define XFS_TRANS_SB_REXTSLOG 0x00002000 +#define XFS_TRANS_SB_RGCOUNT 0x00004000/* * Here we centralize the specification of XFS meta-data buffer reference count
fs/xfs/xfs_rtalloc.c +231 -37
363 lines not on this page · raw message
fs/xfs/xfs_trans.c +9 -0
@@ -458,6 +458,10 @@ xfs_trans_mod_sb(case XFS_TRANS_SB_REXTSLOG : tp->t_rextslog_delta += delta;break ; +case XFS_TRANS_SB_RGCOUNT : +ASSERT (delta >0 ); + tp->t_rgcount_delta += delta; +break ;default :ASSERT (0 );return ;
@@ -563,6 +567,10 @@ xfs_trans_apply_sb_deltas( sbp->sb_rextslog += tp->t_rextslog_delta; whole =1 ; } +if (tp->t_rgcount_delta) { +be32_add_cpu (&sbp->sb_rgcount, tp->t_rgcount_delta); + whole =1 ; + }xfs_trans_buf_set_type (tp, bp,XFS_BLFT_SB_BUF );if (whole)
@@ -680,6 +688,7 @@ xfs_trans_unreserve_and_mod_sb( mp->m_sb.sb_rblocks += tp->t_rblocks_delta; mp->m_sb.sb_rextents += tp->t_rextents_delta; mp->m_sb.sb_rextslog += tp->t_rextslog_delta; + mp->m_sb.sb_rgcount += tp->t_rgcount_delta;spin_unlock (&mp->m_sb_lock);/*
fs/xfs/xfs_trans.h +1 -0
@@ -148,6 +148,7 @@ typedef struct xfs_trans {int64_t t_rblocks_delta;/* superblock rblocks change */ int64_t t_rextents_delta;/* superblocks rextents chg */ int64_t t_rextslog_delta;/* superblocks rextslog chg */ +int64_t t_rgcount_delta;/* realtime group count */ struct list_head t_items;/* log item descriptors */ struct list_head t_busy;/* list of busy extents */ struct list_head t_dfops;/* deferred operations */
Re: [PATCH 14/26] xfs: grow the realtime section when realtime groups are enabled
Looks good:
PATCH 15/26 xfs: store rtgroup information with a bmap intent
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make the bmap intent items take an active reference to the rtgroup containing the space that is being mapped or unmapped. We will need this functionality once we start enabling rmap and reflink on the rt volume.
--- fs/xfs/libxfs/xfs_bmap.h | 5 ++++- fs/xfs/xfs_bmap_item.c | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_bmap.h +4 -1
@@ -248,7 +248,10 @@ struct xfs_bmap_intent {enum xfs_bmap_intent_type bi_type;int bi_whichfork;struct xfs_inode *bi_owner; -struct xfs_perag *bi_pag; +union { +struct xfs_perag *bi_pag; +struct xfs_rtgroup *bi_rtg; + };struct xfs_bmbt_irec bi_bmap; };
fs/xfs/xfs_bmap_item.c +16 -2
@@ -26,6 +26,7 @@#include "xfs_log_recover.h" #include "xfs_ag.h" #include "xfs_trace.h" +#include "xfs_rtgroup.h" struct kmem_cache *xfs_bui_cache;struct kmem_cache *xfs_bud_cache;
@@ -324,8 +325,18 @@ xfs_bmap_update_get_group(struct xfs_mount *mp, struct xfs_bmap_intent *bi) { - if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) + if (xfs_ifork_is_realtime(bi->bi_owner, bi->bi_whichfork)) { + if (xfs_has_rtgroups(mp)) { + xfs_rgnumber_t rgno; + + rgno =xfs_rtb_to_rgno (mp, bi->bi_bmap.br_startblock); + bi->bi_rtg =xfs_rtgroup_get (mp, rgno); + } else { + bi->bi_rtg =NULL ; + } +return ; + }/* * Bump the intent count on behalf of the deferred rmap and refcount
@@ -354,8 +365,11 @@ static inline voidxfs_bmap_update_put_group ( struct xfs_bmap_intent *bi) { -if (xfs_ifork_is_realtime (bi->bi_owner, bi->bi_whichfork)) +if (xfs_ifork_is_realtime (bi->bi_owner, bi->bi_whichfork)) { +if (xfs_has_rtgroups (bi->bi_owner->i_mount)) +xfs_rtgroup_put (bi->bi_rtg);return ; + }xfs_perag_intent_put (bi->bi_pag); }
Re: [PATCH 15/26] xfs: store rtgroup information with a bmap intent
Looks good:
PATCH 16/26 xfs: force swapext to a realtime file to use the file content exchange ioctl
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
xfs_swap_extent_rmap does not use log items to track the overall progress of an attempt to swap the extent mappings between two files. If the system crashes in the middle of swapping a partially written realtime extent, the mapping will be left in an inconsistent state wherein a file can point to multiple extents on the rt volume.
The new file range exchange functionality handles this correctly, so all callers must upgrade to that.
--- fs/xfs/xfs_bmap_util.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/xfs/xfs_bmap_util.c +12 -0
@@ -1522,6 +1522,18 @@ xfs_swap_extents( goto out_unlock; } +/* +* The rmapbt implementation is unable to resume a swapext operation +* after a crash if the allocation unit size is larger than a block. +* This (deprecated) interface will not be upgraded to handle this +* situation. Defragmentation must be performed with the commit range +* ioctl. +*/ +if (XFS_IS_REALTIME_INODE (ip) &&xfs_has_rtgroups (ip->i_mount)) { + error = -EOPNOTSUPP ; + goto out_unlock; + } + error =xfs_qm_dqattach (ip);if (error) goto out_unlock;
Re: [PATCH 16/26] xfs: force swapext to a realtime file to use the file content exchange ioctl
Looks good:
PATCH 17/26 xfs: support logging EFIs for realtime extents
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Teach the EFI mechanism how to free realtime extents. We're going to need this to enforce proper ordering of operations when we enable realtime rmap.
Declare a new log intent item type (XFS_LI_EFI_RT) and a separate defer ops for rt extents. This keeps the ondisk artifacts and processing code completely separate between the rt and non-rt cases. Hopefully this will make it easier to debug filesystem problems.
--- fs/xfs/libxfs/xfs_alloc.c | 15 ++ fs/xfs/libxfs/xfs_alloc.h | 17 ++ fs/xfs/libxfs/xfs_defer.c | 6 + fs/xfs/libxfs/xfs_defer.h | 1 fs/xfs/libxfs/xfs_log_format.h | 6 + fs/xfs/libxfs/xfs_log_recover.h | 2 fs/xfs/xfs_extfree_item.c | 281 ++++++++++++++++++++++++++++++++++++--- fs/xfs/xfs_log_recover.c | 2 8 files changed, 305 insertions(+), 25 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +13 -2
@@ -2645,8 +2645,17 @@ xfs_defer_extent_free(ASSERT (!isnullstartblock (bno));ASSERT (!(free_flags & ~XFS_FREE_EXTENT_ALL_FLAGS )); -if (XFS_IS_CORRUPT (mp, !xfs_verify_fsbext (mp, bno, len))) -return -EFSCORRUPTED ; +if (free_flags &XFS_FREE_EXTENT_REALTIME ) { +if (type !=XFS_AG_RESV_NONE ) { +ASSERT (type ==XFS_AG_RESV_NONE ); +return -EFSCORRUPTED ; + } +if (XFS_IS_CORRUPT (mp, !xfs_verify_rtbext (mp, bno, len))) +return -EFSCORRUPTED ; + }else { +if (XFS_IS_CORRUPT (mp, !xfs_verify_fsbext (mp, bno, len))) +return -EFSCORRUPTED ; + } xefi =kmem_cache_zalloc (xfs_extfree_item_cache,GFP_KERNEL | __GFP_NOFAIL);
@@ -2655,6 +2664,8 @@ xfs_defer_extent_free( xefi->xefi_agresv = type;if (free_flags &XFS_FREE_EXTENT_SKIP_DISCARD ) xefi->xefi_flags |=XFS_EFI_SKIP_DISCARD ; +if (free_flags &XFS_FREE_EXTENT_REALTIME ) + xefi->xefi_flags |=XFS_EFI_REALTIME ;if (oinfo) {ASSERT (oinfo->oi_offset ==0 );
fs/xfs/libxfs/xfs_alloc.h +15 -2
@@ -240,7 +240,11 @@ int xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno,/* Don't issue a discard for the blocks freed. */ #define XFS_FREE_EXTENT_SKIP_DISCARD (1U << 0) -#define XFS_FREE_EXTENT_ALL_FLAGS (XFS_FREE_EXTENT_SKIP_DISCARD) +/* Free blocks on the realtime device. */ +#define XFS_FREE_EXTENT_REALTIME (1U << 1) + +#define XFS_FREE_EXTENT_ALL_FLAGS (XFS_FREE_EXTENT_SKIP_DISCARD | \ + XFS_FREE_EXTENT_REALTIME)/* * List of extents to be free "later".
@@ -251,7 +255,10 @@ struct xfs_extent_free_item {uint64_t xefi_owner;xfs_fsblock_t xefi_startblock;/* starting fs block number */ xfs_extlen_t xefi_blockcount;/* number of blocks in extent */ -struct xfs_perag *xefi_pag; +union { +struct xfs_perag *xefi_pag; +struct xfs_rtgroup *xefi_rtg; + };unsigned int xefi_flags;enum xfs_ag_resv_type xefi_agresv; };
@@ -260,6 +267,12 @@ struct xfs_extent_free_item {#define XFS_EFI_ATTR_FORK (1U << 1)/* freeing attr fork block */ #define XFS_EFI_BMBT_BLOCK (1U << 2)/* freeing bmap btree block */ #define XFS_EFI_CANCELLED (1U << 3)/* dont actually free the space */ +#define XFS_EFI_REALTIME (1U << 4)/* freeing realtime extent */ + +static inline bool xfs_efi_is_realtime (const struct xfs_extent_free_item *xefi) +{ +return xefi->xefi_flags &XFS_EFI_REALTIME ; +}struct xfs_alloc_autoreap {struct xfs_defer_pending *dfp;
fs/xfs/libxfs/xfs_defer.c +6 -0
@@ -847,6 +847,12 @@ xfs_defer_add(ASSERT (tp->t_flags &XFS_TRANS_PERM_LOG_RES ); +if (!ops->finish_item) { +ASSERT (ops->finish_item !=NULL ); +xfs_force_shutdown (tp->t_mountp,SHUTDOWN_CORRUPT_INCORE ); +return NULL ; + } + dfp =xfs_defer_find_last (tp, ops);if (!dfp || !xfs_defer_can_append (dfp, ops)) dfp =xfs_defer_alloc (&tp->t_dfops, ops);
fs/xfs/libxfs/xfs_defer.h +1 -0
@@ -71,6 +71,7 @@ extern const struct xfs_defer_op_type xfs_refcount_update_defer_type;extern const struct xfs_defer_op_type xfs_rmap_update_defer_type;extern const struct xfs_defer_op_type xfs_extent_free_defer_type;extern const struct xfs_defer_op_type xfs_agfl_free_defer_type; +extern const struct xfs_defer_op_type xfs_rtextent_free_defer_type;extern const struct xfs_defer_op_type xfs_attr_defer_type;extern const struct xfs_defer_op_type xfs_exchmaps_defer_type;
fs/xfs/libxfs/xfs_log_format.h +5 -1
@@ -248,6 +248,8 @@ typedef struct xfs_trans_header {#define XFS_LI_ATTRD 0x1247/* attr set/remove done */ #define XFS_LI_XMI 0x1248/* mapping exchange intent */ #define XFS_LI_XMD 0x1249/* mapping exchange done */ +#define XFS_LI_EFI_RT 0x124a/* realtime extent free intent */ +#define XFS_LI_EFD_RT 0x124b/* realtime extent free done */ #define XFS_LI_TYPE_DESC \ { XFS_LI_EFI, "XFS_LI_EFI" }, \
@@ -267,7 +269,9 @@ typedef struct xfs_trans_header { { XFS_LI_ATTRI, "XFS_LI_ATTRI" }, \ { XFS_LI_ATTRD, "XFS_LI_ATTRD" }, \ { XFS_LI_XMI, "XFS_LI_XMI" }, \ - { XFS_LI_XMD, "XFS_LI_XMD" } + { XFS_LI_XMD, "XFS_LI_XMD" }, \ + { XFS_LI_EFI_RT, "XFS_LI_EFI_RT" }, \ + { XFS_LI_EFD_RT, "XFS_LI_EFD_RT" }/* * Inode Log Item Format definitions.
fs/xfs/libxfs/xfs_log_recover.h +2 -0
@@ -77,6 +77,8 @@ extern const struct xlog_recover_item_ops xlog_attri_item_ops;extern const struct xlog_recover_item_ops xlog_attrd_item_ops;extern const struct xlog_recover_item_ops xlog_xmi_item_ops;extern const struct xlog_recover_item_ops xlog_xmd_item_ops; +extern const struct xlog_recover_item_ops xlog_rtefi_item_ops; +extern const struct xlog_recover_item_ops xlog_rtefd_item_ops;/* * Macros, structures, prototypes for internal log manager use.
fs/xfs/xfs_extfree_item.c +261 -20
425 lines not on this page · raw message
fs/xfs/xfs_log_recover.c +2 -0
@@ -1819,6 +1819,8 @@ static const struct xlog_recover_item_ops *xlog_recover_item_ops[] = { &xlog_attrd_item_ops, &xlog_xmi_item_ops, &xlog_xmd_item_ops, + &xlog_rtefi_item_ops, + &xlog_rtefd_item_ops, }; static const struct xlog_recover_item_ops *
Re: [PATCH 17/26] xfs: support logging EFIs for realtime extents
Looks good:
Re: [PATCH 17/26] xfs: support logging EFIs for realtime extents
In reply to Darrick J. WongQuoted 10 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Teach the EFI mechanism how to free realtime extents. We're going to need this to enforce proper ordering of operations when we enable realtime rmap.
Declare a new log intent item type (
XFS_LI_EFI_RT) and a separate defer ops for rt extents. This keeps the ondisk artifacts and processing code completely separate between the rt and non-rt cases. Hopefully this will make it easier to debug filesystem problems.
Doesn't this now require busy extent tracking for rt extents that are being freed? i.e. they get marked as free with the EFD, but cannot be reallocated (or discarded) until the EFD is committed to disk.
we don't allow user data allocation on the data device to reuse busy ranges because the freeing of the extent has not yet been committed to the journal. Because we use async transaction commits, that means we can return to userspace without even the EFI in the journal - it can still be in memory in the CIL. Hence we cannot allow userspace to reallocate that range and write to it, even though it is marked free in the in-memory metadata.
If userspace then does a write and then we crash without the original EFI on disk, then we've just violated metadata vs data update ordering because recovery will not replay the extent free nor the new allocation, yet the data in that extent will have been changed.
Hence I think that if we are moving to intent based freeing of real time extents, we absolutely need to add support for busy extent tracking to realtime groups before we enable EFIs on realtime groups.....
Also ....
Quoted 8 lines
fs/xfs/xfs_extfree_item.c +4
-0@@ -447,6 +467,17 @@ xfs_extent_free_defer_add(trace_xfs_extent_free_defer (mp, xefi); +if (xfs_efi_is_realtime (xefi)) { +xfs_rgnumber_t rgno; + + rgno =xfs_rtb_to_rgno (mp, xefi->xefi_startblock);
fs/xfs/xfs_extfree_item.c xfs_extent_free_defer_add( · line 483
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +7
-0+ xefi->xefi_rtg =xfs_rtgroup_get (mp, rgno); + + *dfpp =xfs_defer_add (tp, &xefi->xefi_list, + &xfs_rtextent_free_defer_type); +return ; + } + xefi->xefi_pag =xfs_perag_intent_get (mp, xefi->xefi_startblock);if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) *dfpp = xfs_defer_add(tp, &xefi->xefi_list,
Hmmmm. Isn't this also missing the xfs_drain intent interlocks that allow online repair to wait until all the intents outstanding on a group complete?
Quoted 29 lines
fs/xfs/xfs_extfree_item.c +25
-0@@ -687,6 +735,106 @@ const struct xfs_defer_op_type xfs_agfl_free_defer_type = { .relog_intent = xfs_extent_free_relog_intent, }; +#ifdef CONFIG_XFS_RT +/* Sort realtime efi items by rtgroup for efficiency. */ +static int +xfs_rtextent_free_diff_items ( +void *priv, +const struct list_head *a, +const struct list_head *b) +{ +struct xfs_extent_free_item *ra =xefi_entry (a); +struct xfs_extent_free_item *rb =xefi_entry (b); + +return ra->xefi_rtg->rtg_rgno - rb->xefi_rtg->rtg_rgno; +} + +/* Create a realtime extent freeing */ +static struct xfs_log_item * +xfs_rtextent_free_create_intent ( +struct xfs_trans *tp, +struct list_head *items, +unsigned int count, +bool sort) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_efi_log_item *efip; +struct xfs_extent_free_item *xefi;
fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 772
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+ +ASSERT (count >0 ); + + efip =xfs_efi_init (mp,XFS_LI_EFI_RT , count); +if (sort) +list_sort (mp, items, xfs_rtextent_free_diff_items); +list_for_each_entry (xefi, items, xefi_list) +xfs_extent_free_log_item (tp, efip, xefi); +return &efip->efi_item; +}
Hmmmm - when would we get an XFS_LI_EFI_RT with multiple extents in it? We only ever free a single user data extent per transaction at a time, right? There will be no metadata blocks being freed on the rt device - all the BMBT, refcountbt and rmapbt blocks that get freed as a result of freeing the user data extent will be in the data device and so will use EFIs, not EFI_RTs....
Quoted 9 lines
fs/xfs/xfs_extfree_item.c +9
-0+ +/* Cancel a realtime extent freeing. */ +STATIC void +xfs_rtextent_free_cancel_item ( +struct list_head *item) +{ +struct xfs_extent_free_item *xefi =xefi_entry (item); + +xfs_rtgroup_put (xefi->xefi_rtg);
fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 791
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+kmem_cache_free (xfs_extfree_item_cache, xefi); +} + +/* Process a free realtime extent. */ +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)
btree cursor ....
fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 796
Quoted 5 lines
fs/xfs/xfs_extfree_item.c +5
-0+{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_extent_free_item *xefi =xefi_entry (item); +struct xfs_efd_log_item *efdp =EFD_ITEM (done); +struct xfs_rtgroup **rtgp = (struct xfs_rtgroup **)state;
... but is apparently holding a xfs_rtgroup. that's kinda nasty, and the rtg the xefi is supposed to be associated with is already held by the xefi, so....
fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 806
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+int error =0 ; + +trace_xfs_extent_free_deferred (mp, xefi); + +if (!(xefi->xefi_flags &XFS_EFI_CANCELLED )) { +if (*rtgp != xefi->xefi_rtg) { +xfs_rtgroup_lock (xefi->xefi_rtg,XFS_RTGLOCK_BITMAP ); +xfs_rtgroup_trans_join (tp, xefi->xefi_rtg, +XFS_RTGLOCK_BITMAP ); + *rtgp = xefi->xefi_rtg;
How does this case happen? Why is it safe to lock the xefi rtg here, and why are we returning the xefi rtg to the caller without taking extra references or dropping the rtg the caller passed in?
At least a comment explaining what is happening is necessary here...
Quoted 81 lines
fs/xfs/xfs_extfree_item.c +66
-1+ } + error =xfs_rtfree_blocks (tp, xefi->xefi_rtg, + xefi->xefi_startblock, xefi->xefi_blockcount); + } +if (error == -EAGAIN ) { +xfs_efd_from_efi (efdp); +return error; + } + +xfs_efd_add_extent (efdp, xefi); +xfs_rtextent_free_cancel_item (item); +return error; +} + +const struct xfs_defer_op_type xfs_rtextent_free_defer_type = { + .name ="rtextent_free" , + .max_items =XFS_EFI_MAX_FAST_EXTENTS , + .create_intent = xfs_rtextent_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_rtextent_free_cancel_item, + .recover_work = xfs_extent_free_recover_work, + .relog_intent = xfs_extent_free_relog_intent, +}; +#else +const struct xfs_defer_op_type xfs_rtextent_free_defer_type = { + .name ="rtextent_free" , +}; +#endif /* CONFIG_XFS_RT */ + STATIC bool xfs_efi_item_match( struct xfs_log_item *lip,@@ -731,7 +879,7 @@ xlog_recover_efi_commit_pass2(return -EFSCORRUPTED ; } - efip =xfs_efi_init (mp, efi_formatp->efi_nextents); + efip =xfs_efi_init (mp,ITEM_TYPE (item), efi_formatp->efi_nextents); error =xfs_efi_copy_format (&item->ri_buf[0 ], &efip->efi_format);if (error) {xfs_efi_item_free (efip);@@ -749,6 +897,58 @@ const struct xlog_recover_item_ops xlog_efi_item_ops = { .commit_pass2 = xlog_recover_efi_commit_pass2, }; +#ifdef CONFIG_XFS_RT +STATIC int +xlog_recover_rtefi_commit_pass2 ( +struct xlog *log, +struct list_head *buffer_list, +struct xlog_recover_item *item, +xfs_lsn_t lsn) +{ +struct xfs_mount *mp = log->l_mp; +struct xfs_efi_log_item *efip; +struct xfs_efi_log_format *efi_formatp; +int error; + + efi_formatp = item->ri_buf[0 ].i_addr; + +if (item->ri_buf[0 ].i_len <xfs_efi_log_format_sizeof (0 )) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); +return -EFSCORRUPTED ; + } + + efip =xfs_efi_init (mp,ITEM_TYPE (item), efi_formatp->efi_nextents); + error =xfs_efi_copy_format (&item->ri_buf[0 ], &efip->efi_format); +if (error) { +xfs_efi_item_free (efip); +return error; + } +atomic_set (&efip->efi_next_extent, efi_formatp->efi_nextents); + +xlog_recover_intent_item (log, &efip->efi_item, lsn, + &xfs_rtextent_free_defer_type); +return 0 ; +} +#else
fs/xfs/xfs_extfree_item.c const struct xlog_recover_item_ops xlog_efi_item_ops = { · line 943
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+STATIC int +xlog_recover_rtefi_commit_pass2 ( +struct xlog *log, +struct list_head *buffer_list, +struct xlog_recover_item *item, +xfs_lsn_t lsn) +{ +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , log->l_mp, + item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); +return -EFSCORRUPTED ;
This needs to be a more meaningful error. It's not technically a corruption - we recognised that an RTEFI is needing to be recovered, but this kernel does not have RTEFI support compiled in. Hence the error should be something along the lines of
"RTEFI found in journal, but kernel not compiled with CONFIG_XFS_RT enabled. Cannot recover journal, please remount using a kernel with RT device support enabled."
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 17/26] xfs: support logging EFIs for realtime extents
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Teach the EFI mechanism how to free realtime extents. We're going to need this to enforce proper ordering of operations when we enable realtime rmap.
Declare a new log intent item type (
XFS_LI_EFI_RT) and a separate defer ops for rt extents. This keeps the ondisk artifacts and processing code completely separate between the rt and non-rt cases. Hopefully this will make it easier to debug filesystem problems.Doesn't this now require busy extent tracking for rt extents that are being freed? i.e. they get marked as free with the EFD, but cannot be reallocated (or discarded) until the EFD is committed to disk.
Quoted 7 lines
we don't allow user data allocation on the data device to reuse busy ranges because the freeing of the extent has not yet been committed to the journal. Because we use async transaction commits, that means we can return to userspace without even the EFI in the journal - it can still be in memory in the CIL. Hence we cannot allow userspace to reallocate that range and write to it, even though it is marked free in the in-memory metadata.
Ah, that's a good point -- in memory the bunmapi -> RTEFI -> RTEFD -> rtalloc -> bmapi transactions succeed, userspace writes to the file blocks, then the log goes down without completing /any/ of those transactions, and now a read of the old file gets new contents.
Quoted 10 lines
If userspace then does a write and then we crash without the original EFI on disk, then we've just violated metadata vs data update ordering because recovery will not replay the extent free nor the new allocation, yet the data in that extent will have been changed.
Hence I think that if we are moving to intent based freeing of real time extents, we absolutely need to add support for busy extent tracking to realtime groups before we enable EFIs on realtime groups.....
Yep. As a fringe benefit, we'd be able to support issuing discards from FITRIM without holding the rtbitmap lock, and -o discard on rt extents too.
Quoted 16 lines
Also ....
Quoted 14 lines
fs/xfs/xfs_extfree_item.c +10
-0@@ -447,6 +467,17 @@ xfs_extent_free_defer_add(trace_xfs_extent_free_defer (mp, xefi); +if (xfs_efi_is_realtime (xefi)) { +xfs_rgnumber_t rgno; + + rgno =xfs_rtb_to_rgno (mp, xefi->xefi_startblock); + xefi->xefi_rtg =xfs_rtgroup_get (mp, rgno); + + *dfpp =xfs_defer_add (tp, &xefi->xefi_list, + &xfs_rtextent_free_defer_type); +return ; + }
Quoted 8 lines
fs/xfs/xfs_extfree_item.c xfs_extent_free_defer_add( · line 483
Quoted 4 lines
fs/xfs/xfs_extfree_item.c +1
-0+ xefi->xefi_pag =xfs_perag_intent_get (mp, xefi->xefi_startblock);if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) *dfpp = xfs_defer_add(tp, &xefi->xefi_list,Hmmmm. Isn't this also missing the
xfs_drainintent interlocks that allow online repair to wait until all the intents outstanding on a group complete?
Yep. I forgot about that.
Quoted 38 lines
Quoted 38 lines
fs/xfs/xfs_extfree_item.c +34
-0@@ -687,6 +735,106 @@ const struct xfs_defer_op_type xfs_agfl_free_defer_type = { .relog_intent = xfs_extent_free_relog_intent, }; +#ifdef CONFIG_XFS_RT +/* Sort realtime efi items by rtgroup for efficiency. */ +static int +xfs_rtextent_free_diff_items ( +void *priv, +const struct list_head *a, +const struct list_head *b) +{ +struct xfs_extent_free_item *ra =xefi_entry (a); +struct xfs_extent_free_item *rb =xefi_entry (b); + +return ra->xefi_rtg->rtg_rgno - rb->xefi_rtg->rtg_rgno; +} + +/* Create a realtime extent freeing */ +static struct xfs_log_item * +xfs_rtextent_free_create_intent ( +struct xfs_trans *tp, +struct list_head *items, +unsigned int count, +bool sort) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_efi_log_item *efip; +struct xfs_extent_free_item *xefi; + +ASSERT (count >0 ); + + efip =xfs_efi_init (mp,XFS_LI_EFI_RT , count); +if (sort) +list_sort (mp, items, xfs_rtextent_free_diff_items); +list_for_each_entry (xefi, items, xefi_list) +xfs_extent_free_log_item (tp, efip, xefi); +return &efip->efi_item;
Quoted 8 lines
Review const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 772
Quoted 1 line
(quoted diff) +1
-0+}Hmmmm - when would we get an
XFS_LI_EFI_RTwith multiple extents in it? We only ever free a single user data extent per transaction at a time, right? There will be no metadata blocks being freed on the rt device - all the BMBT, refcountbt and rmapbt blocks that get freed as a result of freeing the user data extent will be in the data device and so will use EFIs, notEFI_RTs....
Later on when we get to reflink, a refcount decrement operation on an extent that has a mix of single and multiple-owned blocks can generate RTEFIs with multiple extents.
Quoted 22 lines
Quoted 9 lines
fs/xfs/xfs_extfree_item.c +9
-0+ +/* Cancel a realtime extent freeing. */ +STATIC void +xfs_rtextent_free_cancel_item ( +struct list_head *item) +{ +struct xfs_extent_free_item *xefi =xefi_entry (item); + +xfs_rtgroup_put (xefi->xefi_rtg);fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 791
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+kmem_cache_free (xfs_extfree_item_cache, xefi); +} + +/* Process a free realtime extent. */ +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)btree cursor ....
Quoted 9 lines
fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 796
Quoted 5 lines
fs/xfs/xfs_extfree_item.c +5
-0+{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_extent_free_item *xefi =xefi_entry (item); +struct xfs_efd_log_item *efdp =EFD_ITEM (done); +struct xfs_rtgroup **rtgp = (struct xfs_rtgroup **)state;... but is apparently holding a
xfs_rtgroup. that's kinda nasty, and the rtg the xefi is supposed to be associated with is already held by the xefi, so....
It's very nasty, and I preferred when it was just a void**. Maybe we should just change that to a:
struct xfs_intent_item_state {
struct xfs_btree_cur *cur;
struct xfs_rtgroup *rtg;
};and pass that around? At least then the compiler can typecheck that for us.
Quoted 15 lines
fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 806
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+int error =0 ; + +trace_xfs_extent_free_deferred (mp, xefi); + +if (!(xefi->xefi_flags &XFS_EFI_CANCELLED )) { +if (*rtgp != xefi->xefi_rtg) { +xfs_rtgroup_lock (xefi->xefi_rtg,XFS_RTGLOCK_BITMAP ); +xfs_rtgroup_trans_join (tp, xefi->xefi_rtg, +XFS_RTGLOCK_BITMAP ); + *rtgp = xefi->xefi_rtg;How does this case happen? Why is it safe to lock the xefi rtg here, and why are we returning the xefi rtg to the caller without taking extra references or dropping the rtg the caller passed in?
Quoted 1 line
At least a comment explaining what is happening is necessary here...
Hmm, I wonder when /is/ this possible? I don't think it can actually happen ... except maybe in the case of a bunmapi where we pass in a large bmbt_irec array? Let me investigate...
The locks and ijoins will be dropped at transaction commit.
Quoted 97 lines
Quoted 81 lines
fs/xfs/xfs_extfree_item.c +66
-1+ } + error =xfs_rtfree_blocks (tp, xefi->xefi_rtg, + xefi->xefi_startblock, xefi->xefi_blockcount); + } +if (error == -EAGAIN ) { +xfs_efd_from_efi (efdp); +return error; + } + +xfs_efd_add_extent (efdp, xefi); +xfs_rtextent_free_cancel_item (item); +return error; +} + +const struct xfs_defer_op_type xfs_rtextent_free_defer_type = { + .name ="rtextent_free" , + .max_items =XFS_EFI_MAX_FAST_EXTENTS , + .create_intent = xfs_rtextent_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_rtextent_free_cancel_item, + .recover_work = xfs_extent_free_recover_work, + .relog_intent = xfs_extent_free_relog_intent, +}; +#else +const struct xfs_defer_op_type xfs_rtextent_free_defer_type = { + .name ="rtextent_free" , +}; +#endif /* CONFIG_XFS_RT */ + STATIC bool xfs_efi_item_match( struct xfs_log_item *lip,@@ -731,7 +879,7 @@ xlog_recover_efi_commit_pass2(return -EFSCORRUPTED ; } - efip =xfs_efi_init (mp, efi_formatp->efi_nextents); + efip =xfs_efi_init (mp,ITEM_TYPE (item), efi_formatp->efi_nextents); error =xfs_efi_copy_format (&item->ri_buf[0 ], &efip->efi_format);if (error) {xfs_efi_item_free (efip);@@ -749,6 +897,58 @@ const struct xlog_recover_item_ops xlog_efi_item_ops = { .commit_pass2 = xlog_recover_efi_commit_pass2, }; +#ifdef CONFIG_XFS_RT +STATIC int +xlog_recover_rtefi_commit_pass2 ( +struct xlog *log, +struct list_head *buffer_list, +struct xlog_recover_item *item, +xfs_lsn_t lsn) +{ +struct xfs_mount *mp = log->l_mp; +struct xfs_efi_log_item *efip; +struct xfs_efi_log_format *efi_formatp; +int error; + + efi_formatp = item->ri_buf[0 ].i_addr; + +if (item->ri_buf[0 ].i_len <xfs_efi_log_format_sizeof (0 )) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, + item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); +return -EFSCORRUPTED ; + } + + efip =xfs_efi_init (mp,ITEM_TYPE (item), efi_formatp->efi_nextents); + error =xfs_efi_copy_format (&item->ri_buf[0 ], &efip->efi_format); +if (error) { +xfs_efi_item_free (efip); +return error; + } +atomic_set (&efip->efi_next_extent, efi_formatp->efi_nextents); + +xlog_recover_intent_item (log, &efip->efi_item, lsn, + &xfs_rtextent_free_defer_type); +return 0 ; +} +#else fs/xfs/xfs_extfree_item.c const struct xlog_recover_item_ops xlog_efi_item_ops = { · line 943
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+STATIC int +xlog_recover_rtefi_commit_pass2 ( +struct xlog *log, +struct list_head *buffer_list, +struct xlog_recover_item *item, +xfs_lsn_t lsn) +{ +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , log->l_mp, + item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len); +return -EFSCORRUPTED ;This needs to be a more meaningful error. It's not technically a corruption - we recognised that an RTEFI is needing to be recovered, but this kernel does not have RTEFI support compiled in. Hence the error should be something along the lines of
Quoted 3 lines
"RTEFI found in journal, but kernel not compiled with
CONFIG_XFS_RTenabled. Cannot recover journal, please remount using a kernel with RT device support enabled."
Ok. That should probably get applied to the RTRUI and RTCUI recovery stubs too.
--D
Quoted 6 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 17/26] xfs: support logging EFIs for realtime extents
Quoted 26 lines · Darrick J. Wong
Quoted 17 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Teach the EFI mechanism how to free realtime extents. We're going to need this to enforce proper ordering of operations when we enable realtime rmap.
Declare a new log intent item type (
XFS_LI_EFI_RT) and a separate defer ops for rt extents. This keeps the ondisk artifacts and processing code completely separate between the rt and non-rt cases. Hopefully this will make it easier to debug filesystem problems.Doesn't this now require busy extent tracking for rt extents that are being freed? i.e. they get marked as free with the EFD, but cannot be reallocated (or discarded) until the EFD is committed to disk.
Quoted 7 lines
we don't allow user data allocation on the data device to reuse busy ranges because the freeing of the extent has not yet been committed to the journal. Because we use async transaction commits, that means we can return to userspace without even the EFI in the journal - it can still be in memory in the CIL. Hence we cannot allow userspace to reallocate that range and write to it, even though it is marked free in the in-memory metadata.
Quoted 4 lines
Ah, that's a good point -- in memory the bunmapi -> RTEFI -> RTEFD -> rtalloc -> bmapi transactions succeed, userspace writes to the file blocks, then the log goes down without completing /any/ of those transactions, and now a read of the old file gets new contents.
*nod*
Quoted 6 lines
Quoted 6 lines
If userspace then does a write and then we crash without the original EFI on disk, then we've just violated metadata vs data update ordering because recovery will not replay the extent free nor the new allocation, yet the data in that extent will have been changed.
Quoted 8 lines
Quoted 4 lines
Hence I think that if we are moving to intent based freeing of real time extents, we absolutely need to add support for busy extent tracking to realtime groups before we enable EFIs on realtime groups.....
Yep. As a fringe benefit, we'd be able to support issuing discards from FITRIM without holding the rtbitmap lock, and -o discard on rt extents too.
Yes. And I suspect that if we unify the perag and rtg into a single group abstraction, the busy extent tracking will work for both allocators without much functional change being needed at all...
Quoted 25 lines
Quoted 16 lines
Also ....
Quoted 14 lines
fs/xfs/xfs_extfree_item.c +10
-0@@ -447,6 +467,17 @@ xfs_extent_free_defer_add(trace_xfs_extent_free_defer (mp, xefi); +if (xfs_efi_is_realtime (xefi)) { +xfs_rgnumber_t rgno; + + rgno =xfs_rtb_to_rgno (mp, xefi->xefi_startblock); + xefi->xefi_rtg =xfs_rtgroup_get (mp, rgno); + + *dfpp =xfs_defer_add (tp, &xefi->xefi_list, + &xfs_rtextent_free_defer_type); +return ; + }Quoted 8 lines
fs/xfs/xfs_extfree_item.c xfs_extent_free_defer_add( · line 483
Quoted 4 lines
fs/xfs/xfs_extfree_item.c +1
-0+ xefi->xefi_pag =xfs_perag_intent_get (mp, xefi->xefi_startblock);if (xefi->xefi_agresv ==XFS_AG_RESV_AGFL ) *dfpp = xfs_defer_add(tp, &xefi->xefi_list,Hmmmm. Isn't this also missing the
xfs_drainintent interlocks that allow online repair to wait until all the intents outstanding on a group complete?
Quoted 1 line
Yep. I forgot about that.
Same comment about unified group infrastructure ;)
Quoted 35 lines
Quoted 22 lines
Quoted 9 lines
fs/xfs/xfs_extfree_item.c +9
-0+ +/* Cancel a realtime extent freeing. */ +STATIC void +xfs_rtextent_free_cancel_item ( +struct list_head *item) +{ +struct xfs_extent_free_item *xefi =xefi_entry (item); + +xfs_rtgroup_put (xefi->xefi_rtg);fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 791
Quoted 10 lines
fs/xfs/xfs_extfree_item.c +10
-0+kmem_cache_free (xfs_extfree_item_cache, xefi); +} + +/* Process a free realtime extent. */ +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)btree cursor ....
Quoted 9 lines
fs/xfs/xfs_extfree_item.c const struct xfs_defer_op_type xfs_agfl_free_defer_type = { · line 796
Quoted 5 lines
fs/xfs/xfs_extfree_item.c +5
-0+{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_extent_free_item *xefi =xefi_entry (item); +struct xfs_efd_log_item *efdp =EFD_ITEM (done); +struct xfs_rtgroup **rtgp = (struct xfs_rtgroup **)state;... but is apparently holding a
xfs_rtgroup. that's kinda nasty, and the rtg the xefi is supposed to be associated with is already held by the xefi, so....It's very nasty, and I preferred when it was just a void**. Maybe we should just change that to a:
Quoted 7 lines
struct xfs_intent_item_state { struct xfs_btree_cur *cur; struct xfs_rtgroup *rtg; };and pass that around? At least then the compiler can typecheck that for us.
Sounds good to me. :)
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 18/26 xfs: support error injection when freeing rt extents
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
A handful of fstests expect to be able to test what happens when extent free intents fail to actually free the extent. Now that we're supporting EFIs for realtime extents, add to xfs_rtfree_extent the same injection point that exists in the regular extent freeing code.
--- fs/xfs/libxfs/xfs_rtbitmap.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/xfs/libxfs/xfs_rtbitmap.c +4 -0
@@ -21,6 +21,7 @@#include "xfs_rtbitmap.h" #include "xfs_health.h" #include "xfs_sb.h" +#include "xfs_errortag.h" #include "xfs_log.h" #include "xfs_buf_item.h"
@@ -1065,6 +1066,9 @@ xfs_rtfree_extent(ASSERT (rbmip->i_itemp !=NULL );xfs_assert_ilocked (rbmip,XFS_ILOCK_EXCL ); +if (XFS_TEST_ERROR (false, mp,XFS_ERRTAG_FREE_EXTENT )) +return -EIO ; + error =xfs_rtcheck_alloc_range (&args, start, len);if (error)return error;
Re: [PATCH 18/26] xfs: support error injection when freeing rt extents
Looks good:
PATCH 19/26 xfs: use realtime EFI to free extents when rtgroups are enabled
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
When rmap is enabled, XFS expects a certain order of operations, which
is: 1) remove the file mapping, 2) remove the reverse mapping, and then
3) free the blocks. When reflink is enabled, XFS replaces (3) with a deferred refcount decrement operation that can schedule freeing the blocks if that was the last refcount.
For realtime files, xfs_bmap_del_extent_real tries to do 1 and 3 in the same transaction, which will break both rmap and reflink unless we switch it to use realtime EFIs. Both rmap and reflink depend on the rtgroups feature, so let's turn on EFIs for all rtgroups filesystems.
--- fs/xfs/libxfs/xfs_bmap.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_bmap.c +16 -1
@@ -5434,9 +5434,11 @@ xfs_bmap_del_extent_real(* If we need to, add to list of extents to delete. */ if (!(bflags &XFS_BMAPI_REMAP )) { +bool isrt =xfs_ifork_is_realtime (ip, whichfork); +if (xfs_is_reflink_inode (ip) && whichfork ==XFS_DATA_FORK ) {xfs_refcount_decrease_extent (tp, del); - }else if (xfs_ifork_is_realtime (ip, whichfork)) { + }else if (isrt && !xfs_has_rtgroups (mp)) { error =xfs_bmap_free_rtblocks (tp, del); }else {unsigned int efi_flags =0 ;
@@ -5445,6 +5447,19 @@ xfs_bmap_del_extent_real( del->br_state == XFS_EXT_UNWRITTEN) efi_flags |=XFS_FREE_EXTENT_SKIP_DISCARD ; +/* +* Historically, we did not use EFIs to free realtime +* extents. However, when reverse mapping is enabled, +* we must maintain the same order of operations as the +* data device, which is: Remove the file mapping, +* remove the reverse mapping, and then free the +* blocks. Reflink for realtime volumes requires the +* same sort of ordering. Both features rely on +* rtgroups, so let's gate rt EFI usage on rtgroups. +*/ +if (isrt) + efi_flags |=XFS_FREE_EXTENT_REALTIME ; + error =xfs_free_extent_later (tp, del->br_startblock, del->br_blockcount,NULL ,XFS_AG_RESV_NONE , efi_flags);
Re: [PATCH 19/26] xfs: use realtime EFI to free extents when rtgroups are enabled
Looks good:
PATCH 20/26 xfs: don't merge ioends across RTGs
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Unlike AGs, RTGs don't always have metadata in their first blocks, and thus we don't get automatic protection from merging I/O completions across RTG boundaries. Add code to set the IOMAP_F_BOUNDARY flag for ioends that start at the first block of a RTG so that they never get merged into the previous ioend.
--- fs/xfs/xfs_iomap.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
fs/xfs/xfs_iomap.c +13 -1
@@ -24,6 +24,7 @@#include "xfs_iomap.h" #include "xfs_trace.h" #include "xfs_quota.h" +#include "xfs_rtgroup.h" #include "xfs_dquot_item.h" #include "xfs_dquot.h" #include "xfs_reflink.h"
@@ -115,7 +116,9 @@ xfs_bmbt_to_iomap( iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_DELALLOC ; }else { - iomap->addr =BBTOB (xfs_fsb_to_db (ip, imap->br_startblock)); +xfs_daddr_t bno =xfs_fsb_to_db (ip, imap->br_startblock); + + iomap->addr =BBTOB (bno);if (mapping_flags &IOMAP_DAX ) iomap->addr += target->bt_dax_part_off;
@@ -124,6 +127,15 @@ xfs_bmbt_to_iomap(else iomap->type =IOMAP_MAPPED ; +/* +* Mark iomaps starting at the first sector of a RTG as merge +* boundary so that each I/O completions is contained to a +* single RTG. +*/ +if (XFS_IS_REALTIME_INODE (ip) &&xfs_has_rtgroups (mp) && +xfs_rtb_to_rtx (mp, bno) ==0 && +xfs_rtb_to_rtxoff (mp, bno) ==0 ) + iomap->flags |=IOMAP_F_BOUNDARY ; } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount);
PATCH 21/26 xfs: make the RT allocator rtgroup aware
In reply to Darrick J. WongFrom: Christoph Hellwig <[email protected]>
Make the allocator rtgroup aware by either picking a specific group if there is a hint, or loop over all groups otherwise. A simple rotor is provided to pick the placement for initial allocations.
--- fs/xfs/libxfs/xfs_bmap.c | 13 +++++- fs/xfs/libxfs/xfs_rtbitmap.c | 6 ++- fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 98 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 105 insertions(+), 13 deletions(-)
fs/xfs/libxfs/xfs_bmap.c +11 -2
@@ -3151,8 +3151,17 @@ xfs_bmap_adjacent_valid(struct xfs_mount *mp = ap->ip->i_mount;if (XFS_IS_REALTIME_INODE (ap->ip) && - (ap->datatype &XFS_ALLOC_USERDATA )) -return x < mp->m_sb.sb_rblocks; + (ap->datatype &XFS_ALLOC_USERDATA )) { +if (x >= mp->m_sb.sb_rblocks) +return false; +if (!xfs_has_rtgroups (mp)) +return true; + +return xfs_rtb_to_rgno (mp, x) ==xfs_rtb_to_rgno (mp, y) && +xfs_rtb_to_rgno (mp, x) < mp->m_sb.sb_rgcount && +xfs_rtb_to_rtx (mp, x) < mp->m_sb.sb_rgextents; + + }return XFS_FSB_TO_AGNO (mp, x) ==XFS_FSB_TO_AGNO (mp, y) && XFS_FSB_TO_AGNO(mp, x) < mp->m_sb.sb_agcount &&
fs/xfs/libxfs/xfs_rtbitmap.c +4 -2
@@ -1084,11 +1084,13 @@ xfs_rtfree_extent(* Mark more blocks free in the superblock. */ xfs_trans_mod_sb (tp,XFS_TRANS_SB_FREXTENTS , (long )len); +/* * If we've now freed all the blocks, reset the file sequence -* number to 0. +* number to 0 for pre-RTG file systems. */ -if (tp->t_frextents_delta + mp->m_sb.sb_frextents == +if (!xfs_has_rtgroups (mp) && + tp->t_frextents_delta + mp->m_sb.sb_frextents == mp->m_sb.sb_rextents) {if (!(rbmip->i_diflags &XFS_DIFLAG_NEWRTBM )) rbmip->i_diflags |=XFS_DIFLAG_NEWRTBM ;
fs/xfs/xfs_mount.h +1 -0
@@ -223,6 +223,7 @@ typedef struct xfs_mount {#endif xfs_agnumber_t m_agfrotor;/* last ag where space found */ atomic_t m_agirotor;/* last ag dir inode alloced */ +atomic_t m_rtgrotor;/* last rtgroup rtpicked */ /* Memory shrinker to throttle and reprioritize inodegc */ struct shrinker *m_inodegc_shrinker;
fs/xfs/xfs_rtalloc.c +89 -9
143 lines not on this page · raw message
Re: [PATCH 21/26] xfs: make the RT allocator rtgroup aware
Quoted 26 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Make the allocator rtgroup aware by either picking a specific group if there is a hint, or loop over all groups otherwise. A simple rotor is provided to pick the placement for initial allocations.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 13 +++++- fs/xfs/libxfs/xfs_rtbitmap.c | 6 ++- fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 98 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 105 insertions(+), 13 deletions(-)fs/xfs/libxfs/xfs_bmap.c +0
-1@@ -3151,8 +3151,17 @@ xfs_bmap_adjacent_valid(struct xfs_mount *mp = ap->ip->i_mount; if (XFS_IS_REALTIME_INODE(ap->ip) && - (ap->datatype &XFS_ALLOC_USERDATA ))
fs/xfs/libxfs/xfs_bmap.c xfs_bmap_adjacent_valid( · line 3162
Quoted 10 lines
fs/xfs/libxfs/xfs_bmap.c +9
-1-return x < mp->m_sb.sb_rblocks; + (ap->datatype & XFS_ALLOC_USERDATA)) { +if (x >= mp->m_sb.sb_rblocks) +return false; +if (!xfs_has_rtgroups (mp)) +return true; + +return xfs_rtb_to_rgno (mp, x) ==xfs_rtb_to_rgno (mp, y) && +xfs_rtb_to_rgno (mp, x) < mp->m_sb.sb_rgcount && +xfs_rtb_to_rtx (mp, x) < mp->m_sb.sb_rgextents;
WHy do we need the xfs_has_rtgroups() check here? The new rtg logic will return true for an old school rt device here, right?
Quoted 53 lines
fs/xfs/xfs_rtalloc.c +22
-4@@ -1661,8 +1661,9 @@ xfs_rtalloc_align_minmax( } static int -xfs_rtallocate( +xfs_rtallocate_rtg( struct xfs_trans *tp, + xfs_rgnumber_t rgno, xfs_rtblock_t bno_hint, xfs_rtxlen_t minlen, xfs_rtxlen_t maxlen,@@ -1682,16 +1683,33 @@ xfs_rtallocate(xfs_rtxlen_t len =0 ;int error =0 ; - args.rtg =xfs_rtgroup_grab (args.mp,0 ); + args.rtg =xfs_rtgroup_grab (args.mp, rgno);if (!args.rtg)return -ENOSPC ;/* -* Lock out modifications to both the RT bitmap and summary inodes. +* We need to lock out modifications to both the RT bitmap and summary +* inodes for finding free space in xfs_rtallocate_extent_{near,size} +* and join the bitmap and summary inodes for the actual allocation +* down in xfs_rtallocate_range. +* +* For RTG-enabled file system we don't want to join the inodes to the +* transaction until we are committed to allocate to allocate from this +* RTG so that only one inode of each type is locked at a time. +* +* But for pre-RTG file systems we need to already to join the bitmap +* inode to the transaction for xfs_rtpick_extent, which bumps the +* sequence number in it, so we'll have to join the inode to the +* transaction early here. +* +* This is all a bit messy, but at least the mess is contained in +* this function. */ if (!*rtlocked) {xfs_rtgroup_lock (args.rtg,XFS_RTGLOCK_BITMAP ); -xfs_rtgroup_trans_join (tp, args.rtg,XFS_RTGLOCK_BITMAP ); +if (!xfs_has_rtgroups (args.mp)) +xfs_rtgroup_trans_join (tp, args.rtg, +XFS_RTGLOCK_BITMAP ); *rtlocked = true; }
fs/xfs/xfs_rtalloc.c xfs_rtallocate( · line 1723
Quoted 6 lines
fs/xfs/xfs_rtalloc.c +1
-1@@ -1701,7 +1719,7 @@ xfs_rtallocate(*/ if (bno_hint) start =xfs_rtb_to_rtx (args.mp, bno_hint); -else if (initial_user_data) +else if (!xfs_has_rtgroups (args.mp) && initial_user_data) start =xfs_rtpick_extent (args.rtg, tp, maxlen);
Check initial_user_data first - we don't care if there are rtgroups enabled if initial_user_data is not true, and we only ever allocate initial data on an inode once...
Quoted 60 lines
fs/xfs/xfs_rtalloc.c +47
-2@@ -1741,6 +1767,53 @@ xfs_rtallocate(return error; } +static int +xfs_rtallocate_rtgs ( +struct xfs_trans *tp, +xfs_fsblock_t bno_hint, +xfs_rtxlen_t minlen, +xfs_rtxlen_t maxlen, +xfs_rtxlen_t prod, +bool wasdel, +bool initial_user_data, +xfs_rtblock_t *bno, +xfs_extlen_t *blen) +{ +struct xfs_mount *mp = tp->t_mountp; +xfs_rgnumber_t start_rgno, rgno; +int error; + +/* +* For now this just blindly iterates over the RTGs for an initial +* allocation. We could try to keep an in-memory rtg_longest member +* to avoid the locking when just looking for big enough free space, +* but for now this keep things simple. +*/ +if (bno_hint !=NULLFSBLOCK ) + start_rgno =xfs_rtb_to_rgno (mp, bno_hint); +else + start_rgno = (atomic_inc_return (&mp->m_rtgrotor) -1 ) % + mp->m_sb.sb_rgcount; + + rgno = start_rgno; +do { +bool rtlocked = false; + + error =xfs_rtallocate_rtg (tp, rgno, bno_hint, minlen, maxlen, + prod, wasdel, initial_user_data, &rtlocked, + bno, blen); +if (error != -ENOSPC ) +return error; +ASSERT (!rtlocked); + +if (++rgno == mp->m_sb.sb_rgcount) + rgno =0 ; + bno_hint =NULLFSBLOCK ; + }while (rgno != start_rgno); + +return -ENOSPC ; +} + static int xfs_rtallocate_align( struct xfs_bmalloca *ap,@@ -1835,9 +1908,16 @@ xfs_bmap_rtalloc(if (xfs_bmap_adjacent (ap)) bno_hint = ap->blkno; - error = xfs_rtallocate(ap->tp, bno_hint, raminlen, ralen, prod, - ap->wasdel, initial_user_data, &rtlocked,
fs/xfs/xfs_rtalloc.c xfs_bmap_rtalloc( · line 1919
Quoted 10 lines
fs/xfs/xfs_rtalloc.c +9
-1- &ap->blkno, &ap->length); +if (xfs_has_rtgroups (ap->ip->i_mount)) { + error =xfs_rtallocate_rtgs (ap->tp, bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &ap->blkno, &ap->length); + }else { + error =xfs_rtallocate_rtg (ap->tp,0 , bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &rtlocked, &ap->blkno, &ap->length); + }
The xfs_has_rtgroups() check is unnecessary. The iterator in xfs_rtallocate_rtgs() will do the right thing for the !xfs_has_rtgroups() case - it'll set start_rgno = 0 and break out after a single call to xfs_rtallocate_rtg() with rgno = 0.
Another thing that probably should be done here is push all the constant value calculations a couple of functions down the stack to where they are used. Then we only need to pass two parameters down through the rg iterator here, not 11...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/26] xfs: make the RT allocator rtgroup aware
Quoted 25 lines · Dave Chinner
Quoted 24 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Make the allocator rtgroup aware by either picking a specific group if there is a hint, or loop over all groups otherwise. A simple rotor is provided to pick the placement for initial allocations.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 13 +++++- fs/xfs/libxfs/xfs_rtbitmap.c | 6 ++- fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 98 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 105 insertions(+), 13 deletions(-)fs/xfs/libxfs/xfs_bmap.c +0
-0@@ -3151,8 +3151,17 @@ xfs_bmap_adjacent_valid(struct xfs_mount *mp = ap->ip->i_mount;
Quoted 15 lines
fs/xfs/libxfs/xfs_bmap.c xfs_bmap_adjacent_valid( · line 3162
Quoted 12 lines
fs/xfs/libxfs/xfs_bmap.c +9
-2if (XFS_IS_REALTIME_INODE (ap->ip) && - (ap->datatype &XFS_ALLOC_USERDATA )) -return x < mp->m_sb.sb_rblocks; + (ap->datatype &XFS_ALLOC_USERDATA )) { +if (x >= mp->m_sb.sb_rblocks) +return false; +if (!xfs_has_rtgroups (mp)) +return true; + +return xfs_rtb_to_rgno (mp, x) ==xfs_rtb_to_rgno (mp, y) && +xfs_rtb_to_rgno (mp, x) < mp->m_sb.sb_rgcount && +xfs_rtb_to_rtx (mp, x) < mp->m_sb.sb_rgextents;WHy do we need the
xfs_has_rtgroups()check here? The new rtg logic will return true for an old school rt device here, right?
The incore sb_rgextents is zero on !rtg filesystems, so we need the xfs_has_rtgroups.
Quoted 52 lines
Quoted 52 lines
fs/xfs/xfs_rtalloc.c +22
-4@@ -1661,8 +1661,9 @@ xfs_rtalloc_align_minmax( } static int -xfs_rtallocate( +xfs_rtallocate_rtg( struct xfs_trans *tp, + xfs_rgnumber_t rgno, xfs_rtblock_t bno_hint, xfs_rtxlen_t minlen, xfs_rtxlen_t maxlen,@@ -1682,16 +1683,33 @@ xfs_rtallocate(xfs_rtxlen_t len =0 ;int error =0 ; - args.rtg =xfs_rtgroup_grab (args.mp,0 ); + args.rtg =xfs_rtgroup_grab (args.mp, rgno);if (!args.rtg)return -ENOSPC ;/* -* Lock out modifications to both the RT bitmap and summary inodes. +* We need to lock out modifications to both the RT bitmap and summary +* inodes for finding free space in xfs_rtallocate_extent_{near,size} +* and join the bitmap and summary inodes for the actual allocation +* down in xfs_rtallocate_range. +* +* For RTG-enabled file system we don't want to join the inodes to the +* transaction until we are committed to allocate to allocate from this +* RTG so that only one inode of each type is locked at a time. +* +* But for pre-RTG file systems we need to already to join the bitmap +* inode to the transaction for xfs_rtpick_extent, which bumps the +* sequence number in it, so we'll have to join the inode to the +* transaction early here. +* +* This is all a bit messy, but at least the mess is contained in +* this function. */ if (!*rtlocked) {xfs_rtgroup_lock (args.rtg,XFS_RTGLOCK_BITMAP ); -xfs_rtgroup_trans_join (tp, args.rtg,XFS_RTGLOCK_BITMAP ); +if (!xfs_has_rtgroups (args.mp)) +xfs_rtgroup_trans_join (tp, args.rtg, +XFS_RTGLOCK_BITMAP ); *rtlocked = true; }
Quoted 11 lines
fs/xfs/xfs_rtalloc.c xfs_rtallocate( · line 1723
Quoted 7 lines
fs/xfs/xfs_rtalloc.c +1
-1@@ -1701,7 +1719,7 @@ xfs_rtallocate(*/ if (bno_hint) start =xfs_rtb_to_rtx (args.mp, bno_hint); -else if (initial_user_data) +else if (!xfs_has_rtgroups (args.mp) && initial_user_data) start =xfs_rtpick_extent (args.rtg, tp, maxlen);Check
initial_user_datafirst - we don't care if there are rtgroups enabled ifinitial_user_datais not true, and we only ever allocate initial data on an inode once...
<nod>
Quoted 76 lines
Quoted 60 lines
fs/xfs/xfs_rtalloc.c +47
-2@@ -1741,6 +1767,53 @@ xfs_rtallocate(return error; } +static int +xfs_rtallocate_rtgs ( +struct xfs_trans *tp, +xfs_fsblock_t bno_hint, +xfs_rtxlen_t minlen, +xfs_rtxlen_t maxlen, +xfs_rtxlen_t prod, +bool wasdel, +bool initial_user_data, +xfs_rtblock_t *bno, +xfs_extlen_t *blen) +{ +struct xfs_mount *mp = tp->t_mountp; +xfs_rgnumber_t start_rgno, rgno; +int error; + +/* +* For now this just blindly iterates over the RTGs for an initial +* allocation. We could try to keep an in-memory rtg_longest member +* to avoid the locking when just looking for big enough free space, +* but for now this keep things simple. +*/ +if (bno_hint !=NULLFSBLOCK ) + start_rgno =xfs_rtb_to_rgno (mp, bno_hint); +else + start_rgno = (atomic_inc_return (&mp->m_rtgrotor) -1 ) % + mp->m_sb.sb_rgcount; + + rgno = start_rgno; +do { +bool rtlocked = false; + + error =xfs_rtallocate_rtg (tp, rgno, bno_hint, minlen, maxlen, + prod, wasdel, initial_user_data, &rtlocked, + bno, blen); +if (error != -ENOSPC ) +return error; +ASSERT (!rtlocked); + +if (++rgno == mp->m_sb.sb_rgcount) + rgno =0 ; + bno_hint =NULLFSBLOCK ; + }while (rgno != start_rgno); + +return -ENOSPC ; +} + static int xfs_rtallocate_align( struct xfs_bmalloca *ap,@@ -1835,9 +1908,16 @@ xfs_bmap_rtalloc(if (xfs_bmap_adjacent (ap)) bno_hint = ap->blkno; - error = xfs_rtallocate(ap->tp, bno_hint, raminlen, ralen, prod, - ap->wasdel, initial_user_data, &rtlocked,fs/xfs/xfs_rtalloc.c xfs_bmap_rtalloc( · line 1919
Quoted 10 lines
fs/xfs/xfs_rtalloc.c +9
-1- &ap->blkno, &ap->length); +if (xfs_has_rtgroups (ap->ip->i_mount)) { + error =xfs_rtallocate_rtgs (ap->tp, bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &ap->blkno, &ap->length); + }else { + error =xfs_rtallocate_rtg (ap->tp,0 , bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &rtlocked, &ap->blkno, &ap->length); + }The
xfs_has_rtgroups()check is unnecessary. The iterator inxfs_rtallocate_rtgs()will do the right thing for the !xfs_has_rtgroups() case - it'll setstart_rgno= 0 and break out after a single call toxfs_rtallocate_rtg()with rgno = 0.
Quoted 4 lines
Another thing that probably should be done here is push all the constant value calculations a couple of functions down the stack to where they are used. Then we only need to pass two parameters down through the rg iterator here, not 11...
..and pass the ap itself too, to remove three of the parameters?
--D
Quoted 5 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/26] xfs: make the RT allocator rtgroup aware
Quoted 42 lines · Darrick J. Wong
Quoted 25 lines · Dave Chinner
Quoted 24 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Make the allocator rtgroup aware by either picking a specific group if there is a hint, or loop over all groups otherwise. A simple rotor is provided to pick the placement for initial allocations.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 13 +++++- fs/xfs/libxfs/xfs_rtbitmap.c | 6 ++- fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 98 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 105 insertions(+), 13 deletions(-)fs/xfs/libxfs/xfs_bmap.c +0
-0@@ -3151,8 +3151,17 @@ xfs_bmap_adjacent_valid(struct xfs_mount *mp = ap->ip->i_mount;Quoted 15 lines
fs/xfs/libxfs/xfs_bmap.c xfs_bmap_adjacent_valid( · line 3162
Quoted 12 lines
fs/xfs/libxfs/xfs_bmap.c +9
-2if (XFS_IS_REALTIME_INODE (ap->ip) && - (ap->datatype &XFS_ALLOC_USERDATA )) -return x < mp->m_sb.sb_rblocks; + (ap->datatype &XFS_ALLOC_USERDATA )) { +if (x >= mp->m_sb.sb_rblocks) +return false; +if (!xfs_has_rtgroups (mp)) +return true; + +return xfs_rtb_to_rgno (mp, x) ==xfs_rtb_to_rgno (mp, y) && +xfs_rtb_to_rgno (mp, x) < mp->m_sb.sb_rgcount && +xfs_rtb_to_rtx (mp, x) < mp->m_sb.sb_rgextents;WHy do we need the
xfs_has_rtgroups()check here? The new rtg logic will return true for an old school rt device here, right?
Quoted 2 lines
The incore
sb_rgextentsis zero on !rtg filesystems, so we need thexfs_has_rtgroups.
Hmmm. Could we initialise it in memory only for !rtg filesystems, and make sure we never write it back via a check in the xfs_sb_to_disk() formatter function?
That would remove one of the problematic in-memory differences between old skool rtdev setups and the new rtg-based setups...
Quoted 22 lines
Quoted 22 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_bmap.c +0
-2@@ -1835,9 +1908,16 @@ xfs_bmap_rtalloc(if (xfs_bmap_adjacent (ap)) bno_hint = ap->blkno; - error = xfs_rtallocate(ap->tp, bno_hint, raminlen, ralen, prod, - ap->wasdel, initial_user_data, &rtlocked,fs/xfs/libxfs/xfs_bmap.c xfs_bmap_rtalloc( · line 1919
Quoted 10 lines
fs/xfs/libxfs/xfs_bmap.c +9
-1- &ap->blkno, &ap->length); +if (xfs_has_rtgroups (ap->ip->i_mount)) { + error =xfs_rtallocate_rtgs (ap->tp, bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &ap->blkno, &ap->length); + }else { + error =xfs_rtallocate_rtg (ap->tp,0 , bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &rtlocked, &ap->blkno, &ap->length); + }The
xfs_has_rtgroups()check is unnecessary. The iterator inxfs_rtallocate_rtgs()will do the right thing for the !xfs_has_rtgroups() case - it'll setstart_rgno= 0 and break out after a single call toxfs_rtallocate_rtg()with rgno = 0.
Quoted 6 lines
Quoted 4 lines
Another thing that probably should be done here is push all the constant value calculations a couple of functions down the stack to where they are used. Then we only need to pass two parameters down through the rg iterator here, not 11...
..and pass the ap itself too, to remove three of the parameters?
Yeah, I was thinking that the iterator only needs the bno_hint to determine which group to start iterating. Everything else is derived from information in the ap structure and so doesn't need to be calculated above the iterator.
Though we could just lift the xfs_rtalloc_args() up to this level and stuff all the parameters into that structure and pass it down instead (like we do with xfs_alloc_args for the btree allocator). Then we only need to pass args through xfs_rtallocate(), xfs_rtallocate_extent_near/size() and all the other helper functions, too.
That's a much bigger sort of cleanup, though, but I think it would be worth doing a some point because it would bring the rtalloc code closer to how the btalloc code is structured. And, perhaps, allow us to potentially share group selection and iteration code between the bt and rt allocators in future...
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/26] xfs: make the RT allocator rtgroup aware
Quoted 43 lines · Dave Chinner
Quoted 42 lines · Darrick J. Wong
Quoted 40 lines · Dave Chinner
Quoted 26 lines · Darrick J. Wong
From: Christoph Hellwig <[email protected]>
Make the allocator rtgroup aware by either picking a specific group if there is a hint, or loop over all groups otherwise. A simple rotor is provided to pick the placement for initial allocations.
Signed-off-by Christoph Hellwig <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/libxfs/xfs_bmap.c | 13 +++++- fs/xfs/libxfs/xfs_rtbitmap.c | 6 ++- fs/xfs/xfs_mount.h | 1 fs/xfs/xfs_rtalloc.c | 98 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 105 insertions(+), 13 deletions(-)fs/xfs/libxfs/xfs_bmap.c +0
-1@@ -3151,8 +3151,17 @@ xfs_bmap_adjacent_valid(struct xfs_mount *mp = ap->ip->i_mount; if (XFS_IS_REALTIME_INODE(ap->ip) && - (ap->datatype &XFS_ALLOC_USERDATA ))fs/xfs/libxfs/xfs_bmap.c xfs_bmap_adjacent_valid( · line 3162
Quoted 10 lines
fs/xfs/libxfs/xfs_bmap.c +9
-1-return x < mp->m_sb.sb_rblocks; + (ap->datatype & XFS_ALLOC_USERDATA)) { +if (x >= mp->m_sb.sb_rblocks) +return false; +if (!xfs_has_rtgroups (mp)) +return true; + +return xfs_rtb_to_rgno (mp, x) ==xfs_rtb_to_rgno (mp, y) && +xfs_rtb_to_rgno (mp, x) < mp->m_sb.sb_rgcount && +xfs_rtb_to_rtx (mp, x) < mp->m_sb.sb_rgextents;WHy do we need the
xfs_has_rtgroups()check here? The new rtg logic will return true for an old school rt device here, right?
Quoted 6 lines
Quoted 2 lines
The incore
sb_rgextentsis zero on !rtg filesystems, so we need thexfs_has_rtgroups.Hmmm. Could we initialise it in memory only for !rtg filesystems, and make sure we never write it back via a check in the
xfs_sb_to_disk()formatter function?
Only if the incore sb_rgextents becomes u64, which will then cause the incore and ondisk superblock structures not to match anymore. There's probably not much reason to keep them the same anymore. That said, up until recently the metadir patchset actually broke the two apart, but then hch and I put things back to reduce our own confusion.
Quoted 44 lines
That would remove one of the problematic in-memory differences between old skool rtdev setups and the new rtg-based setups...
Quoted 22 lines
Quoted 22 lines
Quoted 6 lines
fs/xfs/libxfs/xfs_bmap.c +0
-2@@ -1835,9 +1908,16 @@ xfs_bmap_rtalloc(if (xfs_bmap_adjacent (ap)) bno_hint = ap->blkno; - error = xfs_rtallocate(ap->tp, bno_hint, raminlen, ralen, prod, - ap->wasdel, initial_user_data, &rtlocked,fs/xfs/libxfs/xfs_bmap.c xfs_bmap_rtalloc( · line 1919
Quoted 10 lines
fs/xfs/libxfs/xfs_bmap.c +9
-1- &ap->blkno, &ap->length); +if (xfs_has_rtgroups (ap->ip->i_mount)) { + error =xfs_rtallocate_rtgs (ap->tp, bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &ap->blkno, &ap->length); + }else { + error =xfs_rtallocate_rtg (ap->tp,0 , bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &rtlocked, &ap->blkno, &ap->length); + }The
xfs_has_rtgroups()check is unnecessary. The iterator inxfs_rtallocate_rtgs()will do the right thing for the !xfs_has_rtgroups() case - it'll setstart_rgno= 0 and break out after a single call toxfs_rtallocate_rtg()with rgno = 0.Quoted 6 lines
Quoted 4 lines
Another thing that probably should be done here is push all the constant value calculations a couple of functions down the stack to where they are used. Then we only need to pass two parameters down through the rg iterator here, not 11...
..and pass the ap itself too, to remove three of the parameters?
Yeah, I was thinking that the iterator only needs the
bno_hintto determine which group to start iterating. Everything else is derived from information in the ap structure and so doesn't need to be calculated above the iterator.Though we could just lift the
xfs_rtalloc_args()up to this level and stuff all the parameters into that structure and pass it down instead (like we do withxfs_alloc_argsfor the btree allocator). Then we only need to pass args throughxfs_rtallocate(), xfs_rtallocate_extent_near/size() and all the other helper functions, too.
Quoted 5 lines
That's a much bigger sort of cleanup, though, but I think it would be worth doing a some point because it would bring the rtalloc code closer to how the btalloc code is structured. And, perhaps, allow us to potentially share group selection and iteration code between the bt and rt allocators in future...
Well we're already tearing the rt allocator to pieces and rebuilding it, so why not...
--D
Quoted 4 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 21/26] xfs: make the RT allocator rtgroup aware
Quoted 9 lines · Darrick J. Wong
Quoted 3 lines
Hmmm. Could we initialise it in memory only for !rtg filesystems, and make sure we never write it back via a check in the
xfs_sb_to_disk()formatter function?Only if the incore
sb_rgextentsbecomes u64, which will then cause the incore and ondisk superblock structures not to match anymore. There's probably not much reason to keep them the same anymore. That said, up until recently the metadir patchset actually broke the two apart, but then hch and I put things back to reduce our own confusion.
Note that the incore sb really isn't much of a thing. It's a random structure that only exists embedded into the XFS mount. The only reason we keep adding fields to it is because some of the conversion functions from/to disk are a mess. The RT growfs cleanups earlier in this patchbomb actually take care of a large part of that, so we should be able to retire it in the not too distant future.
Re: [PATCH 21/26] xfs: make the RT allocator rtgroup aware
In reply to Darrick J. WongQuoted 1 line · Darrick J. Wong
..and pass the ap itself too, to remove three of the parameters?
I tried that earlier, but it breaks the allocation added from the repair code later in your tree. We could fake up a partial xfs_bmalloca there, but that seemed pretty ugly.
Re: [PATCH 21/26] xfs: make the RT allocator rtgroup aware
In reply to Dave ChinnerQuoted 6 lines · Dave Chinner
Quoted 6 lines
fs/xfs/xfs_rtalloc.c +6
-0+if (xfs_has_rtgroups (ap->ip->i_mount)) { + error =xfs_rtallocate_rtgs (ap->tp, bno_hint, raminlen, ralen, + prod, ap->wasdel, initial_user_data, + &ap->blkno, &ap->length); + }else { + error = xfs_rtallocate_rtg(ap->tp, 0, bno_hint, raminlen, ralen,
Quoted 8 lines
fs/xfs/xfs_rtalloc.c xfs_bmap_rtalloc( · line 1919
Quoted 3 lines
fs/xfs/xfs_rtalloc.c +3
-0+ prod, ap->wasdel, initial_user_data, + &rtlocked, &ap->blkno, &ap->length); + }The
xfs_has_rtgroups()check is unnecessary. The iterator inxfs_rtallocate_rtgs()will do the right thing for the !xfs_has_rtgroups() case - it'll setstart_rgno= 0 and break out after a single call toxfs_rtallocate_rtg()with rgno = 0.
The iterator itself does, but the start_rgno calculation does not. But we can make that conditional, which shouldn't be too bad especially if we merge xfs_rtallocate_rtgs into xfs_bmap_rtalloc.
Quoted 4 lines
Another thing that probably should be done here is push all the constant value calculations a couple of functions down the stack to where they are used. Then we only need to pass two parameters down through the rg iterator here, not 11...
Well, not too much of that actually is constant.
PATCH 22/26 xfs: don't coalesce file mappings that cross rtgroup boundaries in scrub
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
The bmbt scrubber will combine file mappings if they are mergeable to reduce the number of cross-referencing checks. However, we shouldn't combine mappings that cross rt group boundaries because that will cause verifiers to trip incorrectly.
--- fs/xfs/scrub/bmap.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
fs/xfs/scrub/bmap.c +15 -1
@@ -835,9 +835,12 @@ xchk_bmap_iext_mapping(/* Are these two mappings contiguous with each other? */ static inline bool xchk_are_bmaps_contiguous ( +const struct xchk_bmap_info *info,const struct xfs_bmbt_irec *b1,const struct xfs_bmbt_irec *b2) { +struct xfs_mount *mp = info->sc->mp; +/* Don't try to combine unallocated mappings. */ if (!xfs_bmap_is_real_extent (b1))return false;
@@ -851,6 +854,17 @@ xchk_are_bmaps_contiguous(return false;if (b1->br_state != b2->br_state)return false; + +/* +* Don't combine bmaps that would cross rtgroup boundaries. This is a +* valid state, but if combined they will fail rtb extent checks. +*/ +if (info->is_rt &&xfs_has_rtgroups (mp)) { +if (xfs_rtb_to_rgno (mp, b1->br_startblock) != +xfs_rtb_to_rgno (mp, b2->br_startblock)) +return false; + } +return true; }
@@ -888,7 +902,7 @@ xchk_bmap_iext_iter(* that we just read, if possible. */ while (xfs_iext_peek_next_extent (ifp, &info->icur, &got)) { -if (!xchk_are_bmaps_contiguous (irec, &got)) +if (!xchk_are_bmaps_contiguous (info, irec, &got))break ;if (!xchk_bmap_iext_mapping (info, &got)) {
Re: [PATCH 22/26] xfs: don't coalesce file mappings that cross rtgroup boundaries in scrub
Looks good:
PATCH 23/26 xfs: scrub the realtime group superblock
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable scrubbing of realtime group superblocks.
--- fs/xfs/Makefile | 1 + fs/xfs/libxfs/xfs_fs.h | 3 +- fs/xfs/scrub/common.h | 2 + fs/xfs/scrub/health.c | 1 + fs/xfs/scrub/rgsuper.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/scrub/scrub.c | 7 +++++ fs/xfs/scrub/scrub.h | 2 + fs/xfs/scrub/stats.c | 1 + fs/xfs/scrub/trace.h | 4 ++- 9 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 fs/xfs/scrub/rgsuper.c
fs/xfs/Makefile +1 -0
@@ -190,6 +190,7 @@ xfs-y += $(addprefix scrub/, \ xfs-$(CONFIG_XFS_ONLINE_SCRUB_STATS) += scrub/stats.o xfs-$(CONFIG_XFS_RT) += $(addprefix scrub/, \ + rgsuper.o \ rtbitmap.o \ rtsummary.o \ )
fs/xfs/libxfs/xfs_fs.h +2 -1
@@ -736,9 +736,10 @@ struct xfs_scrub_metadata {#define XFS_SCRUB_TYPE_HEALTHY 27/* everything checked out ok */ #define XFS_SCRUB_TYPE_DIRTREE 28/* directory tree structure */ #define XFS_SCRUB_TYPE_METAPATH 29/* metadata directory tree paths */ +#define XFS_SCRUB_TYPE_RGSUPER 30/* realtime superblock */ /* Number of scrub subcommands. */ -#define XFS_SCRUB_TYPE_NR 30 +#define XFS_SCRUB_TYPE_NR 31/* * This special type code only applies to the vectored scrub implementation.
fs/xfs/scrub/common.h +2 -0
@@ -79,9 +79,11 @@ int xchk_setup_metapath(struct xfs_scrub *sc);#ifdef CONFIG_XFS_RT int xchk_setup_rtbitmap (struct xfs_scrub *sc);int xchk_setup_rtsummary (struct xfs_scrub *sc); +int xchk_setup_rgsuperblock (struct xfs_scrub *sc);#else # define xchk_setup_rtbitmap xchk_setup_nothing# define xchk_setup_rtsummary xchk_setup_nothing +# define xchk_setup_rgsuperblock xchk_setup_nothing#endif #ifdef CONFIG_XFS_QUOTA int xchk_ino_dqattach (struct xfs_scrub *sc);
fs/xfs/scrub/health.c +1 -0
@@ -111,6 +111,7 @@ static const struct xchk_health_map type_to_health_flag[XFS_SCRUB_TYPE_NR] = { [XFS_SCRUB_TYPE_NLINKS] = { XHG_FS, XFS_SICK_FS_NLINKS }, [XFS_SCRUB_TYPE_DIRTREE] = { XHG_INO, XFS_SICK_INO_DIRTREE }, [XFS_SCRUB_TYPE_METAPATH] = { XHG_FS, XFS_SICK_FS_METAPATH }, + [XFS_SCRUB_TYPE_RGSUPER] = { XHG_RTGROUP, XFS_SICK_RG_SUPER }, };/* Return the health status mask for this scrub type. */
fs/xfs/scrub/rgsuper.c new file +73 -0
73 lines not on this page · raw message
fs/xfs/scrub/scrub.c +7 -0
@@ -451,6 +451,13 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .has = xfs_has_metadir, .repair = xrep_metapath, }, + [XFS_SCRUB_TYPE_RGSUPER] = { /* realtime group superblock */ + .type = ST_RTGROUP, + .setup = xchk_setup_rgsuperblock, + .scrub = xchk_rgsuperblock, + .has = xfs_has_rtsb, + .repair = xrep_notsupported, + }, }; static int
fs/xfs/scrub/scrub.h +2 -0
@@ -273,9 +273,11 @@ int xchk_metapath(struct xfs_scrub *sc);#ifdef CONFIG_XFS_RT int xchk_rtbitmap (struct xfs_scrub *sc);int xchk_rtsummary (struct xfs_scrub *sc); +int xchk_rgsuperblock (struct xfs_scrub *sc);#else # define xchk_rtbitmap xchk_nothing# define xchk_rtsummary xchk_nothing +# define xchk_rgsuperblock xchk_nothing#endif #ifdef CONFIG_XFS_QUOTA int xchk_quota (struct xfs_scrub *sc);
fs/xfs/scrub/stats.c +1 -0
@@ -81,6 +81,7 @@ static const char *name_map[XFS_SCRUB_TYPE_NR] = { [XFS_SCRUB_TYPE_NLINKS] = "nlinks", [XFS_SCRUB_TYPE_DIRTREE] = "dirtree", [XFS_SCRUB_TYPE_METAPATH] = "metapath", + [XFS_SCRUB_TYPE_RGSUPER] = "rgsuper", };/* Format the scrub stats into a text buffer, similar to pcp style. */
fs/xfs/scrub/trace.h +3 -1
@@ -71,6 +71,7 @@ TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_HEALTHY);TRACE_DEFINE_ENUM (XFS_SCRUB_TYPE_DIRTREE );TRACE_DEFINE_ENUM (XFS_SCRUB_TYPE_BARRIER );TRACE_DEFINE_ENUM (XFS_SCRUB_TYPE_METAPATH ); +TRACE_DEFINE_ENUM (XFS_SCRUB_TYPE_RGSUPER );#define XFS_SCRUB_TYPE_STRINGS \ { XFS_SCRUB_TYPE_PROBE, "probe" }, \
@@ -103,7 +104,8 @@ TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_METAPATH); { XFS_SCRUB_TYPE_HEALTHY, "healthy" }, \ { XFS_SCRUB_TYPE_DIRTREE, "dirtree" }, \ { XFS_SCRUB_TYPE_BARRIER, "barrier" }, \ - { XFS_SCRUB_TYPE_METAPATH, "metapath" } + { XFS_SCRUB_TYPE_METAPATH, "metapath" }, \ + { XFS_SCRUB_TYPE_RGSUPER, "rgsuper" } #define XFS_SCRUB_FLAG_STRINGS \ { XFS_SCRUB_IFLAG_REPAIR, "repair" }, \
Re: [PATCH 23/26] xfs: scrub the realtime group superblock
Looks good:
PATCH 24/26 xfs: repair realtime group superblock
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Repair the realtime superblock if it has become out of date with the primary superblock.
--- fs/xfs/scrub/repair.h | 3 +++ fs/xfs/scrub/rgsuper.c | 16 ++++++++++++++++ fs/xfs/scrub/scrub.c | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-)
fs/xfs/scrub/repair.h +3 -0
@@ -146,9 +146,11 @@ int xrep_metapath(struct xfs_scrub *sc);#ifdef CONFIG_XFS_RT int xrep_rtbitmap (struct xfs_scrub *sc);int xrep_rtsummary (struct xfs_scrub *sc); +int xrep_rgsuperblock (struct xfs_scrub *sc);#else # define xrep_rtbitmap xrep_notsupported# define xrep_rtsummary xrep_notsupported +# define xrep_rgsuperblock xrep_notsupported#endif /* CONFIG_XFS_RT */ #ifdef CONFIG_XFS_QUOTA
@@ -253,6 +255,7 @@ static inline int xrep_setup_symlink(struct xfs_scrub *sc, unsigned int *x)#define xrep_symlink xrep_notsupported#define xrep_dirtree xrep_notsupported#define xrep_metapath xrep_notsupported +#define xrep_rgsuperblock xrep_notsupported#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/rgsuper.c +16 -0
@@ -10,8 +10,12 @@#include "xfs_trans_resv.h" #include "xfs_mount.h" #include "xfs_rtgroup.h" +#include "xfs_log_format.h" +#include "xfs_trans.h" +#include "xfs_sb.h" #include "scrub/scrub.h" #include "scrub/common.h" +#include "scrub/repair.h" /* Set us up with a transaction and an empty context. */ int
@@ -71,3 +75,15 @@ xchk_rgsuperblock(xchk_rgsuperblock_xref (sc);return 0 ; } + +#ifdef CONFIG_XFS_ONLINE_REPAIR +int +xrep_rgsuperblock ( +struct xfs_scrub *sc) +{ +ASSERT (sc->sr.rtg->rtg_rgno ==0 ); + +xfs_log_sb (sc->tp); +return 0 ; +} +#endif /* CONFIG_XFS_ONLINE_REPAIR */
fs/xfs/scrub/scrub.c +1 -1
@@ -456,7 +456,7 @@ static const struct xchk_meta_ops meta_scrub_ops[] = { .setup = xchk_setup_rgsuperblock, .scrub = xchk_rgsuperblock, .has = xfs_has_rtsb, - .repair = xrep_notsupported, + .repair = xrep_rgsuperblock, }, };
Re: [PATCH 24/26] xfs: repair realtime group superblock
Looks good:
PATCH 25/26 xfs: scrub metadir paths for rtgroup metadata
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Add the code we need to scan the metadata directory paths of rt group metadata files.
--- fs/xfs/libxfs/xfs_fs.h | 5 ++- fs/xfs/scrub/metapath.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_fs.h +4 -1
@@ -822,9 +822,12 @@ struct xfs_scrub_vec_head {* path checking. */ #define XFS_SCRUB_METAPATH_PROBE (0)/* do we have a metapath scrubber? */ +#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 */ /* Number of metapath sm_ino values */ -#define XFS_SCRUB_METAPATH_NR (1) +#define XFS_SCRUB_METAPATH_NR (4)/* * ioctl limits
fs/xfs/scrub/metapath.c +92 -0
110 lines not on this page · raw message
Re: [PATCH 25/26] xfs: scrub metadir paths for rtgroup metadata
Looks good:
PATCH 26/26 xfs: mask off the rtbitmap and summary inodes when metadir in use
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Set the rtbitmap and summary file inumbers to NULLFSINO in the superblock and make sure they're zeroed whenever we write the superblock to disk, to mimic mkfs behavior.
--- fs/xfs/libxfs/xfs_sb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
fs/xfs/libxfs/xfs_sb.c +18 -0
@@ -656,6 +656,13 @@ xfs_validate_sb_common(void xfs_sb_quota_from_disk (struct xfs_sb *sbp) { +if (xfs_sb_version_hasmetadir (sbp)) { + sbp->sb_uquotino =NULLFSINO ; + sbp->sb_gquotino =NULLFSINO ; + sbp->sb_pquotino =NULLFSINO ; +return ; + } +/* * older mkfs doesn't initialize quota inodes to NULLFSINO. This * leads to in-core values having two different values for a quota
@@ -784,6 +791,8 @@ __xfs_sb_from_disk( to->sb_metadirino =be64_to_cpu (from->sb_metadirino); to->sb_rgcount =be32_to_cpu (from->sb_rgcount); to->sb_rgextents =be32_to_cpu (from->sb_rgextents); + to->sb_rbmino =NULLFSINO ; + to->sb_rsumino =NULLFSINO ; }else { to->sb_metadirino =NULLFSINO ; to->sb_rgcount =1 ;
@@ -806,6 +815,13 @@ xfs_sb_quota_to_disk( {uint16_t qflags = from->sb_qflags; +if (xfs_sb_version_hasmetadir (from)) { + to->sb_uquotino =cpu_to_be64 (0 ); + to->sb_gquotino =cpu_to_be64 (0 ); + to->sb_pquotino =cpu_to_be64 (0 ); +return ; + } + to->sb_uquotino =cpu_to_be64 (from->sb_uquotino);/*
@@ -941,6 +957,8 @@ xfs_sb_to_disk( to->sb_metadirino =cpu_to_be64 (from->sb_metadirino); to->sb_rgcount =cpu_to_be32 (from->sb_rgcount); to->sb_rgextents =cpu_to_be32 (from->sb_rgextents); + to->sb_rbmino =cpu_to_be64 (0 ); + to->sb_rsumino =cpu_to_be64 (0 ); } }
Re: [PATCH 26/26] xfs: mask off the rtbitmap and summary inodes when metadir in use
Looks good:
PATCH 10/10 xfs: 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:
* xfs: refactor xfs_qm_destroy_quotainos
* xfs: use metadir for quota inodes
* xfs: scrub quota file metapaths
* xfs: persist quota flags with metadir
* xfs: update sb field checks when metadir is turned on
* xfs: enable metadata directory feature
--- fs/xfs/libxfs/xfs_dquot_buf.c | 190 ++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_format.h | 3 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/agheader.c | 36 ++++-- 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 ++++ 13 files changed, 597 insertions(+), 71 deletions(-)
PATCH 1/6 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)
Re: [PATCH 1/6] xfs: refactor xfs_qm_destroy_quotainos
Looks good:
PATCH 2/6 xfs: use metadir for quota inodes
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Store the quota inodes in a metadata directory if metadir is enabled.
--- 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
@@ -816,6 +816,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
Re: [PATCH 2/6] xfs: use metadir for quota inodes
Quoted 3 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Store the quota inodes in a metadata directory if metadir is enabled.
I think this commit log could explain a bit better what this means and why it is done.
Otherwis looks good:
Re: [PATCH 2/6] xfs: use metadir for quota inodes
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Store the quota inodes in a metadata directory if metadir is enabled.
I think this commit log could explain a bit better what this means and why it is done.
How about:
"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."
Quoted 3 lines
Otherwis looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Thanks!
--D
PATCH 3/6 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
Re: [PATCH 3/6] xfs: scrub quota file metapaths
Looks good:
PATCH 4/6 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
@@ -850,6 +850,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
@@ -863,6 +870,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
@@ -459,6 +459,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) \
@@ -483,8 +485,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 ;
@@ -1761,6 +1773,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;
@@ -1947,6 +1967,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 ;
Re: [PATCH 4/6] xfs: persist quota flags with metadir
Quoted 5 lines · Darrick J. Wong
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.
Finally!
Are you going to send some tests that test this behavior?
Re: [PATCH 4/6] xfs: persist quota flags with metadir
Quoted 7 lines · Christoph Hellwig
Quoted 5 lines · Darrick J. Wong
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.
Quoted 5 lines
Finally!
Are you going to send some tests that test this behavior?
Reviewed-by Christoph Hellwig <[email protected]>
Yes.
--D
xfs: test persistent quota flags
Test the persistent quota flags that come with the metadir feature.
--- tests/xfs/1891 | 128 +++++++++++++++++++++++++++++++++++++++++++++ tests/xfs/1891.out | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 282 insertions(+), 1 deletion(-) create mode 100755 tests/xfs/1891 create mode 100644 tests/xfs/1891.out
tests/xfs/1891 new file +128 -0
@@ -0,0 +1,128 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2024 Oracle. All Rights Reserved. +# +# FS QA Test 1891 +# +# Functionality test for persistent quota accounting and enforcement flags in +# XFS when metadata directories are enabled. +# +. ./common/preamble +_begin_fstest auto quick quota + +. ./common/filter +. ./common/quota + +$MKFS_XFS_PROG 2>&1 | grep -q 'uquota' || \ + _notrun "mkfs does not support uquota option" + +_require_scratch +_require_xfs_quota + +filter_quota_state() { + sed -e 's/Inode: #[0-9]\+/Inode #XXX/g' \ + -e '/max warnings:/d' \ + -e '/Blocks grace time:/d' \ + -e '/Inodes grace time:/d' \ + | _filter_scratch +} + +qerase_mkfs_options() { + echo "$MKFS_OPTIONS" | sed \ + -e 's/uquota//g' \ + -e 's/gquota//g' \ + -e 's/pquota//g' \ + -e 's/uqnoenforce//g' \ + -e 's/gqnoenforce//g' \ + -e 's/pqnoenforce//g' \ + -e 's/,,*/,/g' +} + +confirm() { + echo "$MOUNT_OPTIONS" | grep -E -q '(qnoenforce|quota)' && \ + echo "saw quota mount options" + _scratch_mount + $XFS_QUOTA_PROG -x -c "state -ugp" $SCRATCH_MNT | filter_quota_state + _check_xfs_scratch_fs + _scratch_unmount +} + +ORIG_MOUNT_OPTIONS="$MOUNT_OPTIONS" +MKFS_OPTIONS="$(qerase_mkfs_options)" + +echo "Test 0: formatting a subset" +_scratch_mkfs -m uquota,gqnoenforce &>> $seqres.full +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option # blank out quota options +confirm + +echo "Test 1: formatting" +_scratch_mkfs -m uquota,gquota,pquota &>> $seqres.full +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option # blank out quota options +confirm + +echo "Test 2: only grpquota" +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option grpquota +confirm + +echo "Test 3: repair" +_scratch_xfs_repair &>> $seqres.full || echo "repair failed?" +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option # blank out quota options +confirm + +echo "Test 4: weird options" +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option pqnoenforce,uquota +confirm + +echo "Test 5: simple recovery" +_scratch_mkfs -m uquota,gquota,pquota &>> $seqres.full +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option # blank out quota options +echo "$MOUNT_OPTIONS" | grep -E -q '(qnoenforce|quota)' && \ + echo "saw quota mount options" +_scratch_mount +$XFS_QUOTA_PROG -x -c "state -ugp" $SCRATCH_MNT | filter_quota_state +touch $SCRATCH_MNT/a +_scratch_shutdown -v -f >> $seqres.full +echo shutdown +_scratch_unmount +confirm + +echo "Test 6: simple recovery with mount options" +_scratch_mkfs -m uquota,gquota,pquota &>> $seqres.full +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option # blank out quota options +echo "$MOUNT_OPTIONS" | grep -E -q '(qnoenforce|quota)' && \ + echo "saw quota mount options" +_scratch_mount +$XFS_QUOTA_PROG -x -c "state -ugp" $SCRATCH_MNT | filter_quota_state +touch $SCRATCH_MNT/a +_scratch_shutdown -v -f >> $seqres.full +echo shutdown +_scratch_unmount +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option gqnoenforce +confirm + +echo "Test 7: user quotaoff recovery" +_scratch_mkfs -m uquota,gquota,pquota &>> $seqres.full +MOUNT_OPTIONS="$ORIG_MOUNT_OPTIONS" +_qmount_option # blank out quota options +echo "$MOUNT_OPTIONS" | grep -E -q '(qnoenforce|quota)' && \ + echo "saw quota mount options" +_scratch_mount +$XFS_QUOTA_PROG -x -c "state -ugp" $SCRATCH_MNT | filter_quota_state +touch $SCRATCH_MNT/a +$XFS_QUOTA_PROG -x -c 'off -u' $SCRATCH_MNT +_scratch_shutdown -v -f >> $seqres.full +echo shutdown +_scratch_unmount +confirm + +# success, all done +status=0 +exit
tests/xfs/1891.out new file +147 -0
147 lines not on this page · raw message
Re: [PATCH 4/6] xfs: persist quota flags with metadir
In reply to Darrick J. WongQuoted 9 lines · Darrick J. Wong
From: 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.
Quoted 5 lines
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.
This means the only way to switch quota off completely with this functionality is to explicitly unmount the filesystem and then mount it again with the "-o noquota" option instead of mounting it again without any quota options.
If so, this will need clear documentation in various man pages because users will not expect this change of quota admin behaviour caused by enabling some other unrelated functionality (like rtgroups).....
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 4/6] xfs: persist quota flags with metadir
Quoted 21 lines · Dave Chinner
Quoted 9 lines · Darrick J. Wong
From: 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.
Quoted 5 lines
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.
This means the only way to switch quota off completely with this functionality is to explicitly unmount the filesystem and then mount it again with the "-o noquota" option instead of mounting it again without any quota options.
Quoted 4 lines
If so, this will need clear documentation in various man pages because users will not expect this change of quota admin behaviour caused by enabling some other unrelated functionality (like rtgroups).....
Yeah, manpage updates are in progress.
--D
Quoted 5 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 5/6 xfs: update sb field checks when metadir is turned on
In reply to Darrick J. WongFrom: 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.
@@ -342,8 +344,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 */ }
@@ -354,6 +358,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 )))
Re: [PATCH 5/6] xfs: update sb field checks when metadir is turned on
Looks good:
Re: [PATCH 5/6] xfs: update sb field checks when metadir is turned on
In reply to Darrick J. WongQuoted 23 lines · Darrick J. Wong
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.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/agheader.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)fs/xfs/scrub/agheader.c +4
-0@@ -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); +
fs/xfs/scrub/agheader.c xchk_superblock( · line 157
Quoted 10 lines
fs/xfs/scrub/agheader.c +2
-6+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 metadir is enabled, then shouldn't sb->sb_rbmino/sb_rsumino both be NULLFSINO to indicate they aren't valid?
Given the rt inodes should have a well defined value even when metadir is enabled, I would say the current code that is validating the values are consistent with the primary across all secondary superblocks is correct and this change is unnecessary....
Quoted 5 lines
fs/xfs/scrub/agheader.c +0
-1@@ -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))
fs/xfs/scrub/agheader.c xchk_superblock( · line 238
Quoted 10 lines
fs/xfs/scrub/agheader.c +6
-3-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); + }
Same - if metadir is in use and quota inodes are in the metadir, then the superblock quota inodes should be NULLFSINO....
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 5/6] xfs: update sb field checks when metadir is turned on
Quoted 28 lines · Dave Chinner
Quoted 27 lines · Darrick J. Wong
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.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/agheader.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)fs/xfs/scrub/agheader.c +6
-0@@ -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); }
Quoted 9 lines
fs/xfs/scrub/agheader.c xchk_superblock( · line 157
Quoted 6 lines
fs/xfs/scrub/agheader.c +0
-6-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 metadir is enabled, then shouldn't sb->sb_rbmino/sb_rsumino both be NULLFSINO to indicate they aren't valid?
The ondisk sb values aren't defined anymore and we set the incore values to NULLFSINO (and never write that back out) so there's not much to check anymore. I guess we could check that they're all zero or something, which is what mkfs writes out, though my intent here was to leave them as undefined bits, figuring that if we ever want to reuse those fields we're going to define a new incompat bit anyway.
OTOH now would be the time to define what the field contents are supposed to be -- zero or NULLFSINO?
Quoted 16 lines
Given the rt inodes should have a well defined value even when metadir is enabled, I would say the current code that is validating the values are consistent with the primary across all secondary superblocks is correct and this change is unnecessary....
Quoted 10 lines
fs/xfs/scrub/agheader.c +3
-2@@ -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);
Quoted 8 lines
fs/xfs/scrub/agheader.c xchk_superblock( · line 238
Quoted 5 lines
fs/xfs/scrub/agheader.c +3
-2-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); + }Same - if metadir is in use and quota inodes are in the metadir, then the superblock quota inodes should be NULLFSINO....
Ok, I'll go with NULLFSINO ondisk and in memory.
--D
Quoted 5 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 5/6] xfs: update sb field checks when metadir is turned on
Quoted 46 lines · Darrick J. Wong
Quoted 28 lines · Dave Chinner
Quoted 27 lines · Darrick J. Wong
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.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/agheader.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)fs/xfs/scrub/agheader.c +6
-0@@ -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); }Quoted 9 lines
fs/xfs/scrub/agheader.c xchk_superblock( · line 157
Quoted 6 lines
fs/xfs/scrub/agheader.c +0
-6-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 metadir is enabled, then shouldn't sb->sb_rbmino/sb_rsumino both be NULLFSINO to indicate they aren't valid?
The ondisk sb values aren't defined anymore and we set the incore values to NULLFSINO (and never write that back out) so there's not much to check anymore. I guess we could check that they're all zero or something, which is what mkfs writes out, though my intent here was to leave them as undefined bits, figuring that if we ever want to reuse those fields we're going to define a new incompat bit anyway.
Quoted 2 lines
OTOH now would be the time to define what the field contents are supposed to be -- zero or NULLFSINO?
Yeah, I think it's best to give them a solid definition, that way we don't bump up against "we can't tell if it has never been used before" problems.
Quoted 26 lines
Quoted 17 lines
Given the rt inodes should have a well defined value even when metadir is enabled, I would say the current code that is validating the values are consistent with the primary across all secondary superblocks is correct and this change is unnecessary....
Quoted 10 lines
fs/xfs/scrub/agheader.c +3
-2@@ -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);Quoted 8 lines
fs/xfs/scrub/agheader.c xchk_superblock( · line 238
Quoted 5 lines
fs/xfs/scrub/agheader.c +3
-2-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); + }Same - if metadir is in use and quota inodes are in the metadir, then the superblock quota inodes should be NULLFSINO....
Quoted 1 line
Ok, I'll go with NULLFSINO ondisk and in memory.
OK.
Just to add to that (because I looked), mkfs.xfs does this to initialise rtino numbers before they are allocated:
$ git grep NULLFSINO mkfs mkfs/xfs_mkfs.c: sbp->sb_rootino = sbp->sb_rbmino = sbp->sb_rsumino = NULLFSINO; $
and repair does this for quota inodes when clearing the superblock inode fields:
$ git grep NULLFSINO repair/dinode.c repair/dinode.c: mp->m_sb.sb_uquotino = NULLFSINO; repair/dinode.c: mp->m_sb.sb_gquotino = NULLFSINO; repair/dinode.c: mp->m_sb.sb_pquotino = NULLFSINO; $
So the current code is typically using NULLFSINO instead of zero on disk for "inode does not exist".
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
Re: [PATCH 5/6] xfs: update sb field checks when metadir is turned on
Quoted 94 lines · Dave Chinner
Quoted 46 lines · Darrick J. Wong
Quoted 28 lines · Dave Chinner
Quoted 27 lines · Darrick J. Wong
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.
Signed-off-by Darrick J. Wong <[email protected]>--- fs/xfs/scrub/agheader.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-)fs/xfs/scrub/agheader.c +6
-0@@ -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); }Quoted 9 lines
fs/xfs/scrub/agheader.c xchk_superblock( · line 157
Quoted 6 lines
fs/xfs/scrub/agheader.c +0
-6-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 metadir is enabled, then shouldn't sb->sb_rbmino/sb_rsumino both be NULLFSINO to indicate they aren't valid?
The ondisk sb values aren't defined anymore and we set the incore values to NULLFSINO (and never write that back out) so there's not much to check anymore. I guess we could check that they're all zero or something, which is what mkfs writes out, though my intent here was to leave them as undefined bits, figuring that if we ever want to reuse those fields we're going to define a new incompat bit anyway.
Quoted 2 lines
OTOH now would be the time to define what the field contents are supposed to be -- zero or NULLFSINO?
Yeah, I think it's best to give them a solid definition, that way we don't bump up against "we can't tell if it has never been used before" problems.
Quoted 26 lines
Quoted 17 lines
Given the rt inodes should have a well defined value even when metadir is enabled, I would say the current code that is validating the values are consistent with the primary across all secondary superblocks is correct and this change is unnecessary....
Quoted 10 lines
fs/xfs/scrub/agheader.c +3
-2@@ -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);Quoted 8 lines
fs/xfs/scrub/agheader.c xchk_superblock( · line 238
Quoted 5 lines
fs/xfs/scrub/agheader.c +3
-2-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); + }Same - if metadir is in use and quota inodes are in the metadir, then the superblock quota inodes should be NULLFSINO....
Quoted 1 line
Ok, I'll go with NULLFSINO ondisk and in memory.
OK.
Just to add to that (because I looked), mkfs.xfs does this to initialise rtino numbers before they are allocated:
$ git grep NULLFSINO mkfs mkfs/xfs_mkfs.c: sbp->sb_rootino = sbp->sb_rbmino = sbp->sb_rsumino = NULLFSINO; $and repair does this for quota inodes when clearing the superblock inode fields:
Quoted 8 lines
$ git grep NULLFSINO repair/dinode.c repair/dinode.c: mp->m_sb.sb_uquotino = NULLFSINO; repair/dinode.c: mp->m_sb.sb_gquotino = NULLFSINO; repair/dinode.c: mp->m_sb.sb_pquotino = NULLFSINO; $So the current code is typically using NULLFSINO instead of zero on disk for "inode does not exist".
<nod> Though I noticed that it writes out sb_[ugp]quotino = 0. Christoph once remarked that those parts of the sb were at some point unused, so they were zero, and they only become NULLFSINO once someone turns on QUOTABIT in sb_versionnum.
Regardless, all 1s is ok by me.
--D
Quoted 4 lines
-Dave.
Signature · 2 lines
Dave Chinner [email protected]
PATCH 6/6 xfs: enable metadata directory feature
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Enable the metadata directory feature.
--- fs/xfs/libxfs/xfs_format.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_format.h +2 -1
@@ -397,7 +397,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
Re: [PATCH 6/6] xfs: enable metadata directory feature
Quoted 3 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Enable the metadata directory feature.
Maybe put in just a little bit more information. E.g.:
With this feature all metadata inodes are places in the metadata directory and no sb root metadata except for the metadir itself it left.
The RT device is now shared 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, while a single rtgroup gives roughly identical behavior to the traditional RT setup, just with checksummed and self identifying metadata.
For quota the quota options are read from the superblock unless explicitly overridden.
Otherwise looks good:
Re: [PATCH 6/6] xfs: enable metadata directory feature
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Darrick J. Wong
From: Darrick J. Wong <[email protected]>
Enable the metadata directory feature.
Maybe put in just a little bit more information. E.g.:
With this feature all metadata inodes are places in the metadata directory and no sb root metadata except for the metadir itself it left.
Quoted 8 lines
The RT device is now shared 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, while a single rtgroup gives roughly identical behavior to the traditional RT setup, just with checksummed and self identifying metadata.
For quota the quota options are read from the superblock unless explicitly overridden.
I've massaged that into:
"With this feature all metadata inodes are places in the metadata directory and no sb root metadata except for the metadir itself it left.
"The RT device is now shared 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, while a single rtgroup gives roughly identical behavior to the traditional RT setup, just with checksummed and self identifying metadata.
"For quota the quota options are read from the superblock unless explicitly overridden."
Quoted 3 lines
Otherwise looks good:
Reviewed-by Christoph Hellwig <[email protected]>
Thanks for all your help getting this ready!
--D