xfs: introduce the free inode btree
cover xfs: introduce the free inode btree
Hi all,
Here is the first release of free inode btree support for the kernel. It is based on the RFC previously made available here:
http://oss.sgi.com/archives/xfs/2013-09/msg00076.html
The free inode btree adds a new inode btree to XFS with the intent to track only inode chunks with at least one free inode. Patches 1-3 add the necessary support for the new XFS_BTNUM_FINOBT type and introduce a read-only v5 superblock flag. Patch 4 updates the transaction reservations for inode allocation operations to account for the finobt. Patches 5-9 add support to manage the finobt on inode chunk allocation, inode allocation, inode free (and chunk deletion) and growfs. The 10th and final patch adds the feature bit to the associated mask. Thoughts, reviews and flames appreciated.
Brian
v1:
- Separate patch to enable rw finobt support at end of series.
- Rework xfs_ialloc_log_agi() to log the agi in two distinct regions.
- Rework xfs_ialloc_btree.c changes to use separate finobt handlers where appropriate.
- Fix bug to show fibt2 stats data in stat proc file.
- Move finobt log reservation calculations into separate helper, made conditional and merged to a single patch.
- Use reserved block pool in xfs_inactive() codepath instead of flush.
- Moved and cleaned up xfs_inobt_insert() to use inobt helpers.
- Enhanced lookup algorithm for allocation (xfs_dialloc_ag()).
- Refactored xfs_difree() to use xfs_difree_inobt() and xfs_difree_finobt(), cleaned up the latter.
Brian Foster (10):
xfs: refactor xfs_ialloc_btree.c to support multiple inobt numbers
xfs: reserve v5 superblock read-only compat. feature bit for finobt
xfs: support the XFS_BTNUM_FINOBT free inode btree type
xfs: update inode allocation/free transaction reservations for finobt
xfs: insert newly allocated inode chunks into the finobt
xfs: use and update the finobt on inode allocation
xfs: refactor xfs_difree() inobt bits into xfs_difree_inobt() helper
xfs: update the finobt on inode free
xfs: add finobt support to growfs
xfs: enable the finobt feature on v5 superblocks
fs/xfs/xfs_ag.h | 32 ++- fs/xfs/xfs_btree.c | 6 +- fs/xfs/xfs_btree.h | 3 + fs/xfs/xfs_fsops.c | 32 +++ fs/xfs/xfs_ialloc.c | 616 ++++++++++++++++++++++++++++++++++++++-------- fs/xfs/xfs_ialloc_btree.c | 68 ++++- fs/xfs/xfs_ialloc_btree.h | 17 +- fs/xfs/xfs_inode.c | 4 +- fs/xfs/xfs_itable.c | 6 +- fs/xfs/xfs_log_recover.c | 2 + fs/xfs/xfs_sb.h | 10 +- fs/xfs/xfs_stats.c | 1 + fs/xfs/xfs_stats.h | 18 +- fs/xfs/xfs_trans_resv.c | 47 +++- fs/xfs/xfs_trans_space.h | 7 +- fs/xfs/xfs_types.h | 2 +- 16 files changed, 742 insertions(+), 129 deletions(-)
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 1/10 xfs: refactor xfs_ialloc_btree.c to support multiple inobt numbers
The introduction of the free inode btree (finobt) requires that xfs_ialloc_btree.c handle multiple trees. Refactor xfs_ialloc_btree.c so the caller specifies the btree type on cursor initialization to prepare for addition of the finobt.
--- fs/xfs/xfs_ialloc.c | 8 ++++---- fs/xfs/xfs_ialloc_btree.c | 8 +++++--- fs/xfs/xfs_ialloc_btree.h | 3 ++- fs/xfs/xfs_itable.c | 6 ++++-- 4 files changed, 15 insertions(+), 10 deletions(-)
fs/xfs/xfs_ialloc.c +4 -4
@@ -455,7 +455,7 @@ xfs_ialloc_ag_alloc(/* * Insert records describing the new inode chunk into the btree. */ - cur =xfs_inobt_init_cursor (args.mp, tp, agbp, agno); + cur =xfs_inobt_init_cursor (args.mp, tp, agbp, agno,XFS_BTNUM_INO );for (thisino = newino; thisino < newino + newlen; thisino +=XFS_INODES_PER_CHUNK ) {
@@ -701,7 +701,7 @@ xfs_dialloc_ag(ASSERT (pag->pagi_freecount >0 ); restart_pagno: - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO );/* * If pagino is 0 (this is the root inode allocation) use newino. * This must work because we've just allocated some.
@@ -1163,7 +1163,7 @@ xfs_difree(/* * Initialize the cursor. */ - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO ); error =xfs_check_agi_freecount (cur, agi);if (error)
@@ -1294,7 +1294,7 @@ xfs_imap_lookup(* we have a record, we need to ensure it contains the inode number * we are looking up. */ - cur =xfs_inobt_init_cursor (mp, tp, agbp, agno); + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO ); error =xfs_inobt_lookup (cur, agino,XFS_LOOKUP_LE , &i);if (!error) {if (i)
fs/xfs/xfs_ialloc_btree.c +5 -3
@@ -50,7 +50,8 @@ xfs_inobt_dup_cursor( struct xfs_btree_cur *cur) {return xfs_inobt_init_cursor (cur->bc_mp, cur->bc_tp, - cur->bc_private.a.agbp, cur->bc_private.a.agno); + cur->bc_private.a.agbp, cur->bc_private.a.agno, + cur->bc_btnum); }STATIC void
@@ -324,7 +325,8 @@ xfs_inobt_init_cursor(struct xfs_mount *mp,/* file system mount point */ struct xfs_trans *tp, /* transaction pointer */ struct xfs_buf *agbp, /* buffer for agi structure */ - xfs_agnumber_t agno) /* allocation group number */ + xfs_agnumber_t agno, /* allocation group number */ + xfs_btnum_t btnum) /* ialloc or free ino btree */ { struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);struct xfs_btree_cur *cur;
@@ -334,7 +336,7 @@ xfs_inobt_init_cursor( cur->bc_tp = tp; cur->bc_mp = mp; cur->bc_nlevels =be32_to_cpu (agi->agi_level); - cur->bc_btnum =XFS_BTNUM_INO ; + cur->bc_btnum = btnum; cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_ops = &xfs_inobt_ops;
fs/xfs/xfs_ialloc_btree.h +2 -1
@@ -107,7 +107,8 @@ typedef __be32 xfs_inobt_ptr_t; ((index) - 1) * sizeof(xfs_inobt_ptr_t)))extern struct xfs_btree_cur *xfs_inobt_init_cursor (struct xfs_mount *, -struct xfs_trans *,struct xfs_buf *,xfs_agnumber_t ); +struct xfs_trans *,struct xfs_buf *,xfs_agnumber_t , +xfs_btnum_t );extern int xfs_inobt_maxrecs (struct xfs_mount *,int ,int );extern const struct xfs_buf_ops xfs_inobt_buf_ops;
fs/xfs/xfs_itable.c +4 -2
@@ -275,7 +275,8 @@ xfs_bulkstat(/* * Allocate and initialize a btree cursor for ialloc btree. */ - cur =xfs_inobt_init_cursor (mp,NULL , agbp, agno); + cur =xfs_inobt_init_cursor (mp,NULL , agbp, agno, +XFS_BTNUM_INO ); irbp = irbuf; irbufend = irbuf + nirbuf; end_of_ag =0 ;
@@ -626,7 +627,8 @@ xfs_inumbers( agino =0 ;continue ; } - cur =xfs_inobt_init_cursor (mp,NULL , agbp, agno); + cur =xfs_inobt_init_cursor (mp,NULL , agbp, agno, +XFS_BTNUM_INO ); error =xfs_inobt_lookup (cur, agino,XFS_LOOKUP_GE , &tmp);if (error) {
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 2/10 xfs: reserve v5 superblock read-only compat. feature bit for finobt
In reply to Brian FosterReserve a v5 read-only compatibility feature bit for the finobt and create the xfs_sb_version_hasfinobt() helper to determine whether an fs has the feature enabled.
The finobt does not change existing on-disk structures, but must remain consistent with the ialloc btree. Modifications from older kernels would violate that constrant. Therefore, we restrict older kernels to read-only mounts of finobt-enabled filesystems.
Note that this does not yet enable the ability to rw mount a finobt fs (by setting the feature bit in the XFS_SB_FEAT_RO_COMPAT_ALL mask).
--- fs/xfs/xfs_sb.h | 7 +++++++ 1 file changed, 7 insertions(+)
fs/xfs/xfs_sb.h +7 -0
@@ -585,6 +585,7 @@ 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_ALL 0#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL static inline bool
@@ -639,6 +640,12 @@ static inline int xfs_sb_version_hasftype(struct xfs_sb *sbp) (sbp->sb_features2 & XFS_SB_VERSION2_FTYPE)); } +static inline int xfs_sb_version_hasfinobt (xfs_sb_t *sbp) +{ +return (XFS_SB_VERSION_NUM (sbp) ==XFS_SB_VERSION_5 ) && + (sbp->sb_features_ro_compat &XFS_SB_FEAT_RO_COMPAT_FINOBT ); +} +/* * end of superblock version macros */
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 3/10 xfs: support the XFS_BTNUM_FINOBT free inode btree type
In reply to Brian FosterDefine the AGI fields for the finobt root/level and add magic numbers. Update the btree code to add support for the new XFS_BTNUM_FINOBT inode btree.
The finobt root block is reserved immediately following the inobt root block in the AG. Update XFS_PREALLOC_BLOCKS() to determine the starting AG data block based on whether finobt support is enabled.
--- fs/xfs/xfs_ag.h | 32 +++++++++++++++---------- fs/xfs/xfs_btree.c | 6 +++-- fs/xfs/xfs_btree.h | 3 +++ fs/xfs/xfs_ialloc.c | 37 +++++++++++++++++++++++++---- fs/xfs/xfs_ialloc_btree.c | 60 +++++++++++++++++++++++++++++++++++++++++++++-- fs/xfs/xfs_ialloc_btree.h | 14 ++++++++++- fs/xfs/xfs_log_recover.c | 2 ++ fs/xfs/xfs_stats.c | 1 + fs/xfs/xfs_stats.h | 18 +++++++++++++- fs/xfs/xfs_types.h | 2 +- 10 files changed, 150 insertions(+), 25 deletions(-)
fs/xfs/xfs_ag.h +19 -13
@@ -166,22 +166,28 @@ typedef struct xfs_agi {__be32 agi_pad32;__be64 agi_lsn;/* last write sequence */ +__be32 agi_free_root;/* root of the free inode btree */ +__be32 agi_free_level;/* levels in free inode btree */ +/* structure must be padded to 64 bit alignment */ } xfs_agi_t; -#define XFS_AGI_MAGICNUM 0x00000001 -#define XFS_AGI_VERSIONNUM 0x00000002 -#define XFS_AGI_SEQNO 0x00000004 -#define XFS_AGI_LENGTH 0x00000008 -#define XFS_AGI_COUNT 0x00000010 -#define XFS_AGI_ROOT 0x00000020 -#define XFS_AGI_LEVEL 0x00000040 -#define XFS_AGI_FREECOUNT 0x00000080 -#define XFS_AGI_NEWINO 0x00000100 -#define XFS_AGI_DIRINO 0x00000200 -#define XFS_AGI_UNLINKED 0x00000400 -#define XFS_AGI_NUM_BITS 11 -#define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1) +#define XFS_AGI_MAGICNUM (1 << 0) +#define XFS_AGI_VERSIONNUM (1 << 1) +#define XFS_AGI_SEQNO (1 << 2) +#define XFS_AGI_LENGTH (1 << 3) +#define XFS_AGI_COUNT (1 << 4) +#define XFS_AGI_ROOT (1 << 5) +#define XFS_AGI_LEVEL (1 << 6) +#define XFS_AGI_FREECOUNT (1 << 7) +#define XFS_AGI_NEWINO (1 << 8) +#define XFS_AGI_DIRINO (1 << 9) +#define XFS_AGI_UNLINKED (1 << 10) +#define XFS_AGI_NUM_BITS_R1 11/* end of the 1st agi logging region */ +#define XFS_AGI_ALL_BITS_R1 ((1 << XFS_AGI_NUM_BITS_R1) - 1) +#define XFS_AGI_FREE_ROOT (1 << 11) +#define XFS_AGI_FREE_LEVEL (1 << 12) +#define XFS_AGI_NUM_BITS_R2 13/* disk block (xfs_daddr_t) in the AG */ #define XFS_AGI_DADDR (mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
fs/xfs/xfs_btree.c +4 -2
@@ -45,9 +45,10 @@ kmem_zone_t *xfs_btree_cur_zone;* Btree magic numbers. */ static const __uint32_t xfs_magics[2 ][XFS_BTNUM_MAX ] = { - {XFS_ABTB_MAGIC ,XFS_ABTC_MAGIC ,XFS_BMAP_MAGIC ,XFS_IBT_MAGIC }, + {XFS_ABTB_MAGIC ,XFS_ABTC_MAGIC ,XFS_BMAP_MAGIC ,XFS_IBT_MAGIC , +XFS_FIBT_MAGIC }, {XFS_ABTB_CRC_MAGIC ,XFS_ABTC_CRC_MAGIC , -XFS_BMAP_CRC_MAGIC ,XFS_IBT_CRC_MAGIC } +XFS_BMAP_CRC_MAGIC ,XFS_IBT_CRC_MAGIC ,XFS_FIBT_CRC_MAGIC } };#define xfs_btree_magic (cur) \ xfs_magics[!!((cur)->bc_flags & XFS_BTREE_CRC_BLOCKS)][cur->bc_btnum]
@@ -1119,6 +1120,7 @@ xfs_btree_set_refs(xfs_buf_set_ref (bp,XFS_ALLOC_BTREE_REF );break ;case XFS_BTNUM_INO : +case XFS_BTNUM_FINO :xfs_buf_set_ref (bp,XFS_INO_BTREE_REF );break ;case XFS_BTNUM_BMAP :
fs/xfs/xfs_btree.h +3 -0
@@ -37,6 +37,7 @@ extern kmem_zone_t *xfs_btree_cur_zone;#define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi)#define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi)#define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi) +#define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi)/* * Generic btree header.
@@ -147,6 +148,7 @@ do { \case XFS_BTNUM_CNT :__XFS_BTREE_STATS_INC (abtc, stat);break ; \case XFS_BTNUM_BMAP :__XFS_BTREE_STATS_INC (bmbt, stat);break ; \case XFS_BTNUM_INO :__XFS_BTREE_STATS_INC (ibt, stat);break ; \ +case XFS_BTNUM_FINO :__XFS_BTREE_STATS_INC (fibt, stat);break ; \case XFS_BTNUM_MAX :ASSERT (0 );/* fucking gcc */ ;break ; \ } \ }while (0 )
@@ -160,6 +162,7 @@ do { \case XFS_BTNUM_CNT :__XFS_BTREE_STATS_ADD (abtc, stat, val);break ; \case XFS_BTNUM_BMAP :__XFS_BTREE_STATS_ADD (bmbt, stat, val);break ; \case XFS_BTNUM_INO :__XFS_BTREE_STATS_ADD (ibt, stat, val);break ; \ +case XFS_BTNUM_FINO :__XFS_BTREE_STATS_ADD (fibt, stat, val);break ; \case XFS_BTNUM_MAX :ASSERT (0 );/* fucking gcc */ ;break ; \ } \ }while (0 )
fs/xfs/xfs_ialloc.c +32 -5
@@ -1505,6 +1505,8 @@ xfs_ialloc_log_agi( offsetof(xfs_agi_t , agi_newino), offsetof(xfs_agi_t , agi_dirino), offsetof(xfs_agi_t , agi_unlinked), + offsetof(xfs_agi_t , agi_free_root), + offsetof(xfs_agi_t , agi_free_level), sizeof(xfs_agi_t) };#ifdef DEBUG
@@ -1514,14 +1516,39 @@ xfs_ialloc_log_agi(ASSERT (agi->agi_magicnum ==cpu_to_be32 (XFS_AGI_MAGIC ));#endif /* -* Compute byte offsets for the first and last fields. +* The growth of the agi buffer over time now requires that we interpret +* the buffer as two logical regions delineated at the end of the unlinked +* list. This is due to the size of the hash table and its location in the +* middle of the agi. +* +* For example, a request to log a field before agi_unlinked and a field +* after agi_unlinked could cause us to log the entire hash table and use +* an excessive amount of log space. To avoid this behavior, log the +* region up through agi_unlinked in one call and the region after +* agi_unlinked through the end of the structure in another. */ -xfs_btree_offsets (fields, offsets,XFS_AGI_NUM_BITS , &first, &last); +xfs_trans_buf_set_type (tp, bp,XFS_BLFT_AGI_BUF ); +/* -* Log the allocation group inode header buffer. +* Compute byte offsets for the first and last fields in the first +* region and log agi buffer. This only logs up through agi_unlinked. */ -xfs_trans_buf_set_type (tp, bp,XFS_BLFT_AGI_BUF ); -xfs_trans_log_buf (tp, bp, first, last); +if (fields &XFS_AGI_ALL_BITS_R1 ) { +xfs_btree_offsets (fields, offsets,XFS_AGI_NUM_BITS_R1 , + &first, &last); +xfs_trans_log_buf (tp, bp, first, last); + } + +/* +* Mask off the bits in the first region and calculate the first and last +* field offsets for any bits in the second region. +*/ + fields &= ~XFS_AGI_ALL_BITS_R1 ; +if (fields) { +xfs_btree_offsets (fields, offsets,XFS_AGI_NUM_BITS_R2 , + &first, &last); +xfs_trans_log_buf (tp, bp, first, last); + } }#ifdef DEBUG
fs/xfs/xfs_ialloc_btree.c +58 -2
99 lines not on this page · raw message
fs/xfs/xfs_ialloc_btree.h +13 -1
@@ -31,6 +31,8 @@ struct xfs_mount;*/ #define XFS_IBT_MAGIC 0x49414254/* 'IABT' */ #define XFS_IBT_CRC_MAGIC 0x49414233/* 'IAB3' */ +#define XFS_FIBT_MAGIC 0x46494254/* 'FIBT' */ +#define XFS_FIBT_CRC_MAGIC 0x46494233/* 'FIB3' */ typedef __uint64_t xfs_inofree_t ;#define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
@@ -73,7 +75,17 @@ typedef __be32 xfs_inobt_ptr_t;* block numbers in the AG. */ #define XFS_IBT_BLOCK (mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1)) -#define XFS_PREALLOC_BLOCKS (mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1)) +#define XFS_FIBT_BLOCK (mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1)) + +/* +* The first data block of an AG depends on whether the filesystem was formatted +* with the finobt feature. If so, account for the finobt reserved root btree +* block. +*/ +#define XFS_PREALLOC_BLOCKS (mp) \ + (xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \ + XFS_FIBT_BLOCK(mp) + 1 : \ + XFS_IBT_BLOCK(mp) + 1)/* * Btree block header size depends on a superblock flag.
fs/xfs/xfs_log_recover.c +2 -0
@@ -2134,7 +2134,9 @@ xlog_recover_validate_buf_type( bp->b_ops = &xfs_allocbt_buf_ops;break ;case XFS_IBT_CRC_MAGIC : +case XFS_FIBT_CRC_MAGIC :case XFS_IBT_MAGIC : +case XFS_FIBT_MAGIC : bp->b_ops = &xfs_inobt_buf_ops;break ;case XFS_BMAP_CRC_MAGIC :
fs/xfs/xfs_stats.c +1 -0
@@ -59,6 +59,7 @@ static int xfs_stat_proc_show(struct seq_file *m, void *v) { "abtc2", XFSSTAT_END_ABTC_V2 }, { "bmbt2", XFSSTAT_END_BMBT_V2 }, { "ibt2", XFSSTAT_END_IBT_V2 }, + { "fibt2", XFSSTAT_END_FIBT_V2 },/* we print both series of quota information together */ { "qm", XFSSTAT_END_QM }, };
fs/xfs/xfs_stats.h +17 -1
@@ -183,7 +183,23 @@ struct xfsstats {__uint32_t xs_ibt_2_alloc;__uint32_t xs_ibt_2_free;__uint32_t xs_ibt_2_moves; -#define XFSSTAT_END_XQMSTAT (XFSSTAT_END_IBT_V2+6) +#define XFSSTAT_END_FIBT_V2 (XFSSTAT_END_IBT_V2+15) +__uint32_t xs_fibt_2_lookup; +__uint32_t xs_fibt_2_compare; +__uint32_t xs_fibt_2_insrec; +__uint32_t xs_fibt_2_delrec; +__uint32_t xs_fibt_2_newroot; +__uint32_t xs_fibt_2_killroot; +__uint32_t xs_fibt_2_increment; +__uint32_t xs_fibt_2_decrement; +__uint32_t xs_fibt_2_lshift; +__uint32_t xs_fibt_2_rshift; +__uint32_t xs_fibt_2_split; +__uint32_t xs_fibt_2_join; +__uint32_t xs_fibt_2_alloc; +__uint32_t xs_fibt_2_free; +__uint32_t xs_fibt_2_moves; +#define XFSSTAT_END_XQMSTAT (XFSSTAT_END_FIBT_V2+6)__uint32_t xs_qm_dqreclaims;__uint32_t xs_qm_dqreclaim_misses;__uint32_t xs_qm_dquot_dups;
fs/xfs/xfs_types.h +1 -1
@@ -134,7 +134,7 @@ typedef enum {typedef enum { XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_BMAPi, XFS_BTNUM_INOi, -XFS_BTNUM_MAX + XFS_BTNUM_FINOi,XFS_BTNUM_MAX }xfs_btnum_t ;struct xfs_name {
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 4/10 xfs: update inode allocation/free transaction reservations for finobt
In reply to Brian FosterCreate the xfs_calc_finobt_res() helper to calculate the finobt log reservation for inode allocation and free. Update XFS_IALLOC_SPACE_RES() to reserve blocks for the additional finobt insertion on inode allocation. Create XFS_IFREE_SPACE_RES() to reserve blocks for the potential finobt record insertion on inode free (i.e., if an inode chunk was previously fully allocated).
--- fs/xfs/xfs_inode.c | 4 +++- fs/xfs/xfs_trans_resv.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- fs/xfs/xfs_trans_space.h | 7 ++++++- 3 files changed, 52 insertions(+), 6 deletions(-)
fs/xfs/xfs_inode.c +3 -1
@@ -1731,7 +1731,9 @@ xfs_inactive_ifree(int error; tp =xfs_trans_alloc (mp,XFS_TRANS_INACTIVE ); - error =xfs_trans_reserve (tp, &M_RES (mp)->tr_ifree,0 ,0 ); + tp->t_flags |=XFS_TRANS_RESERVE ; + error =xfs_trans_reserve (tp, &M_RES (mp)->tr_ifree, +XFS_IFREE_SPACE_RES (mp),0 );if (error) {ASSERT (XFS_FORCED_SHUTDOWN (mp));xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES );
fs/xfs/xfs_trans_resv.c +43 -4
101 lines not on this page · raw message
fs/xfs/xfs_trans_space.h +6 -1
@@ -47,7 +47,9 @@#define XFS_DIRREMOVE_SPACE_RES (mp) \ XFS_DAREMOVE_SPACE_RES(mp, XFS_DATA_FORK)#define XFS_IALLOC_SPACE_RES (mp) \ - (XFS_IALLOC_BLOCKS(mp) + (mp)->m_in_maxlevels - 1) + (XFS_IALLOC_BLOCKS(mp) + \ + (xfs_sb_version_hasfinobt(&mp->m_sb) ? 2 : 1 * \ + ((mp)->m_in_maxlevels - 1)))/* * Space reservation values for various transactions.
@@ -82,5 +84,8 @@ (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))#define XFS_SYMLINK_SPACE_RES (mp,nl,b) \ (XFS_IALLOC_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl) + (b)) +#define XFS_IFREE_SPACE_RES (mp) \ + (xfs_sb_version_hasfinobt(&mp->m_sb) ? (mp)->m_in_maxlevels : 0) +#endif /* __XFS_TRANS_SPACE_H__ */
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 5/10 xfs: insert newly allocated inode chunks into the finobt
In reply to Brian FosterA newly allocated inode chunk, by definition, has at least one free inode, so a record is always inserted into the finobt.
Create the xfs_inobt_insert() helper from existing code to insert a record in an inobt based on the provided BTNUM. Update xfs_ialloc_ag_alloc() to invoke the helper for the existing XFS_BTNUM_INO tree and XFS_BTNUM_FINO tree, if enabled.
--- fs/xfs/xfs_ialloc.c | 93 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 70 insertions(+), 23 deletions(-)
fs/xfs/xfs_ialloc.c +70 -23
@@ -111,6 +111,66 @@ xfs_inobt_get_rec( }/* +* Insert a single inobt record. Cursor must already point to desired location. +*/ +STATIC int +xfs_inobt_insert_rec ( +struct xfs_btree_cur *cur, +__int32_t freecount, +xfs_inofree_t free, +int *stat) +{ + cur->bc_rec.i.ir_freecount = freecount; + cur->bc_rec.i.ir_free = free; +return xfs_btree_insert (cur, stat); +} + +/* +* Insert records describing a newly allocated inode chunk into the inobt. +*/ +STATIC int +xfs_inobt_insert ( +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_buf *agbp, +xfs_agino_t newino, +xfs_agino_t newlen, +xfs_btnum_t btnum) +{ +struct xfs_btree_cur *cur; +struct xfs_agi *agi =XFS_BUF_TO_AGI (agbp); +xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno); +xfs_agino_t thisino; +int i; +int error; + + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno, btnum); + +for (thisino = newino; + thisino < newino + newlen; + thisino +=XFS_INODES_PER_CHUNK ) { + error =xfs_inobt_lookup (cur, thisino,XFS_LOOKUP_EQ , &i); +if (error) { +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +return error; + } +ASSERT (i ==0 ); + + error =xfs_inobt_insert_rec (cur,XFS_INODES_PER_CHUNK , +XFS_INOBT_ALL_FREE , &i); +if (error) { +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +return error; + } +ASSERT (i ==1 ); + } + +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); + +return 0 ; +} + +/* * Verify that the number of free inodes in the AGI is correct. */ #ifdef DEBUG
@@ -309,13 +369,10 @@ xfs_ialloc_ag_alloc( {xfs_agi_t *agi;/* allocation group header */ xfs_alloc_arg_t args;/* allocation argument structure */ -xfs_btree_cur_t *cur;/* inode btree cursor */ xfs_agnumber_t agno;int error; -int i;xfs_agino_t newino;/* new first inode's number */ xfs_agino_t newlen;/* new number of inodes */ -xfs_agino_t thisino;/* current inode number, for loop */ int isaligned =0 ;/* inode allocation at stripe unit */ /* boundary */ struct xfs_perag *pag;
@@ -453,29 +510,19 @@ xfs_ialloc_ag_alloc( agi->agi_newino =cpu_to_be32 (newino);/* -* Insert records describing the new inode chunk into the btree. +* Insert records describing the new inode chunk into the btrees. */ - cur =xfs_inobt_init_cursor (args.mp, tp, agbp, agno,XFS_BTNUM_INO ); -for (thisino = newino; - thisino < newino + newlen; - thisino +=XFS_INODES_PER_CHUNK ) { - cur->bc_rec.i.ir_startino = thisino; - cur->bc_rec.i.ir_freecount =XFS_INODES_PER_CHUNK ; - cur->bc_rec.i.ir_free =XFS_INOBT_ALL_FREE ; - error =xfs_btree_lookup (cur,XFS_LOOKUP_EQ , &i); -if (error) { -xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); -return error; - } -ASSERT (i ==0 ); - error =xfs_btree_insert (cur, &i); -if (error) { -xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); + error =xfs_inobt_insert (args.mp, tp, agbp, newino, newlen, +XFS_BTNUM_INO ); +if (error) +return error; + +if (xfs_sb_version_hasfinobt (&args.mp->m_sb)) { + error =xfs_inobt_insert (args.mp, tp, agbp, newino, newlen, +XFS_BTNUM_FINO ); +if (error)return error; - } -ASSERT (i ==1 ); } -xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR );/* * Log allocation group header fields */
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 6/10 xfs: use and update the finobt on inode allocation
In reply to Brian FosterReplace xfs_dialloc_ag() with an implementation that looks for a record in the finobt. The finobt only tracks records with at least one free inode. This eliminates the need for the intra-ag scan in the original algorithm. Once the inode is allocated, update the finobt appropriately (possibly removing the record) as well as the inobt.
Move the original xfs_dialloc_ag() algorithm to xfs_dialloc_ag_slow() and fall back as such if finobt support is not enabled.
--- fs/xfs/xfs_ialloc.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 210 insertions(+), 1 deletion(-)
fs/xfs/xfs_ialloc.c +210 -1
@@ -722,7 +722,7 @@ xfs_ialloc_get_rec(* available. */ STATIC int -xfs_dialloc_ag( +xfs_dialloc_ag_slow( struct xfs_trans *tp, struct xfs_buf *agbp, xfs_ino_t parent,
@@ -980,6 +980,215 @@ error0:return error; } +STATIC int +xfs_dialloc_ag ( +struct xfs_trans *tp, +struct xfs_buf *agbp, +xfs_ino_t parent, +xfs_ino_t *inop) +{ +struct xfs_mount *mp = tp->t_mountp; +struct xfs_agi *agi =XFS_BUF_TO_AGI (agbp); +xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno); +xfs_agnumber_t pagno =XFS_INO_TO_AGNO (mp, parent); +xfs_agino_t pagino =XFS_INO_TO_AGINO (mp, parent); +struct xfs_perag *pag; +struct xfs_btree_cur *cur; +struct xfs_btree_cur *tcur; +struct xfs_inobt_rec_incore rec; +struct xfs_inobt_rec_incore trec; +xfs_ino_t ino; +int error; +int offset; +int i, j; + +if (!xfs_sb_version_hasfinobt (&mp->m_sb)) +return xfs_dialloc_ag_slow (tp, agbp, parent, inop); + + pag =xfs_perag_get (mp, agno); + +/* +* If pagino is 0 (this is the root inode allocation) use newino. +* This must work because we've just allocated some. +*/ +if (!pagino) + pagino =be32_to_cpu (agi->agi_newino); + + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_FINO ); + + error =xfs_check_agi_freecount (cur, agi); +if (error) + goto error_cur; + +if (agno == pagno) { +/* +* We're in the same AG as the parent inode so allocate the +* closest inode to the parent. +*/ + error =xfs_inobt_lookup (cur, pagino,XFS_LOOKUP_LE , &i); +if (error) + goto error_cur; +if (i ==1 ) { + error =xfs_inobt_get_rec (cur, &rec, &i); +if (error) + goto error_cur; +XFS_WANT_CORRUPTED_GOTO (i ==1 , error_cur); + +/* +* See if we've landed in the parent inode record. The +* finobt only tracks chunks with at least one free +* inode, so record existence is enough. +*/ +if (pagino >= rec.ir_startino && + pagino < (rec.ir_startino +XFS_INODES_PER_CHUNK )) + goto alloc_inode; + } + + error =xfs_btree_dup_cursor (cur, &tcur); +if (error) + goto error_cur; + + error =xfs_inobt_lookup (tcur, pagino,XFS_LOOKUP_GE , &j); +if (error) + goto error_tcur; +if (j ==1 ) { + error =xfs_inobt_get_rec (tcur, &trec, &j); +if (error) + goto error_tcur; +XFS_WANT_CORRUPTED_GOTO (j ==1 , error_tcur); + } + +if (i ==1 && j ==1 ) { +if ((pagino - rec.ir_startino +XFS_INODES_PER_CHUNK -1 ) > + (trec.ir_startino - pagino)) { + rec = trec; +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); + cur = tcur; + }else { +xfs_btree_del_cursor (tcur,XFS_BTREE_NOERROR ); + } + }else if (j ==1 ) { + rec = trec; +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); + cur = tcur; + }else { +xfs_btree_del_cursor (tcur,XFS_BTREE_NOERROR ); + } + }else { +/* +* Different AG from the parent inode. Check the record for the +* most recently allocated inode. +*/ +if (agi->agi_newino !=cpu_to_be32 (NULLAGINO )) { + error =xfs_inobt_lookup (cur, agi->agi_newino, +XFS_LOOKUP_EQ , &i); +if (error) + goto error_cur; +if (i ==1 ) { + error =xfs_inobt_get_rec (cur, &rec, &i); +if (error) + goto error_cur; +XFS_WANT_CORRUPTED_GOTO (i ==1 , error_cur); + goto alloc_inode; + } + } + +/* +* Allocate the first inode available in the AG. +*/ + error =xfs_inobt_lookup (cur,0 ,XFS_LOOKUP_GE , &i); +if (error) + goto error_cur; +XFS_WANT_CORRUPTED_GOTO (i ==1 , error_cur); + + error =xfs_inobt_get_rec (cur, &rec, &i); +if (error) + goto error_cur; +XFS_WANT_CORRUPTED_GOTO (i ==1 , error_cur); + } + +alloc_inode: + offset =xfs_lowbit64 (rec.ir_free); +ASSERT (offset >=0 ); +ASSERT (offset <XFS_INODES_PER_CHUNK ); +ASSERT ((XFS_AGINO_TO_OFFSET (mp, rec.ir_startino) % +XFS_INODES_PER_CHUNK ) ==0 ); + ino =XFS_AGINO_TO_INO (mp, agno, rec.ir_startino + offset); + +/* +* Modify or remove the finobt record. +*/ + rec.ir_free &= ~XFS_INOBT_MASK (offset); + rec.ir_freecount--; +if (rec.ir_freecount) + error =xfs_inobt_update (cur, &rec); +else + error =xfs_btree_delete (cur, &i); +if (error) + goto error_cur; + +/* +* Lookup and modify the equivalent record in the inobt. +*/ + tcur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_INO ); + + error =xfs_check_agi_freecount (tcur, agi); +if (error) + goto error_tcur; + + error =xfs_inobt_lookup (tcur, rec.ir_startino,XFS_LOOKUP_EQ , &i); +if (error) + goto error_tcur; +XFS_WANT_CORRUPTED_GOTO (i ==1 , error_tcur); + + error =xfs_inobt_get_rec (tcur, &trec, &i); +if (error) + goto error_tcur; +XFS_WANT_CORRUPTED_GOTO (i ==1 , error_tcur); +ASSERT ((XFS_AGINO_TO_OFFSET (mp, trec.ir_startino) % +XFS_INODES_PER_CHUNK ) ==0 ); + + trec.ir_free &= ~XFS_INOBT_MASK (offset); + trec.ir_freecount--; + +XFS_WANT_CORRUPTED_GOTO ((rec.ir_free == trec.ir_free) && + (rec.ir_freecount == trec.ir_freecount), + error_tcur); + + error =xfs_inobt_update (tcur, &trec); +if (error) + goto error_tcur; + +/* +* Update the perag and superblock. +*/ +be32_add_cpu (&agi->agi_freecount,-1 ); +xfs_ialloc_log_agi (tp, agbp,XFS_AGI_FREECOUNT ); + pag->pagi_freecount--; + +xfs_trans_mod_sb (tp,XFS_TRANS_SB_IFREE ,-1 ); + + error =xfs_check_agi_freecount (tcur, agi); +if (error) + goto error_tcur; + error =xfs_check_agi_freecount (cur, agi); +if (error) + goto error_tcur; + +xfs_btree_del_cursor (tcur,XFS_BTREE_NOERROR ); +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); +xfs_perag_put (pag); + *inop = ino; +return 0 ; + +error_tcur: +xfs_btree_del_cursor (tcur,XFS_BTREE_ERROR ); +error_cur: +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +xfs_perag_put (pag); +return error; +} +/* * Allocate an inode on disk. *
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 7/10 xfs: refactor xfs_difree() inobt bits into xfs_difree_inobt() helper
In reply to Brian FosterRefactor xfs_difree() in preparation for the finobt. xfs_difree() performs the validity checks against the ag and reads the agi header. The work of physically updating the inode allocation btree is pushed down into the new xfs_difree_inobt() helper.
--- fs/xfs/xfs_ialloc.c | 160 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 96 insertions(+), 64 deletions(-)
fs/xfs/xfs_ialloc.c +96 -64
@@ -1348,74 +1348,31 @@ out_error:return XFS_ERROR (error); } -/* -* Free disk inode. Carefully avoids touching the incore inode, all -* manipulations incore are the caller's responsibility. -* The on-disk inode is not changed by this operation, only the -* btree (free inode mask) is changed. -*/ -int -xfs_difree ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_ino_t inode,/* inode to be freed */ -xfs_bmap_free_t *flist,/* extents to free */ -int *delete,/* set if inode cluster was deleted */ -xfs_ino_t *first_ino)/* first inode in deleted cluster */ +STATIC int +xfs_difree_inobt ( +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_buf *agbp, +xfs_agino_t agino, +struct xfs_bmap_free *flist, +int *delete, +xfs_ino_t *first_ino, +struct xfs_inobt_rec_incore *orec) { -/* REFERENCED */ -xfs_agblock_t agbno;/* block number containing inode */ -xfs_buf_t *agbp;/* buffer containing allocation group header */ -xfs_agino_t agino;/* inode number relative to allocation group */ -xfs_agnumber_t agno;/* allocation group number */ -xfs_agi_t *agi;/* allocation group header */ -xfs_btree_cur_t *cur;/* inode btree cursor */ -int error;/* error return value */ -int i;/* result code */ -int ilen;/* inodes in an inode cluster */ -xfs_mount_t *mp;/* mount structure for filesystem */ -int off;/* offset of inode in inode chunk */ -xfs_inobt_rec_incore_t rec;/* btree record */ -struct xfs_perag *pag; - - mp = tp->t_mountp; +struct xfs_agi *agi =XFS_BUF_TO_AGI (agbp); +xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno); +xfs_agblock_t agbno =XFS_AGINO_TO_AGBNO (mp, agino); +struct xfs_perag *pag; +struct xfs_btree_cur *cur; +struct xfs_inobt_rec_incore rec; +int ilen; +int error; +int i; +int off; -/* -* Break up inode number into its components. -*/ - agno =XFS_INO_TO_AGNO (mp, inode); -if (agno >= mp->m_sb.sb_agcount) { -xfs_warn (mp,"%s: agno >= mp->m_sb.sb_agcount (%d >= %d)." , - __func__, agno, mp->m_sb.sb_agcount); -ASSERT (0 ); -return XFS_ERROR (EINVAL ); - } - agino =XFS_INO_TO_AGINO (mp, inode); -if (inode !=XFS_AGINO_TO_INO (mp, agno, agino)) { -xfs_warn (mp,"%s: inode != XFS_AGINO_TO_INO() (%llu != %llu)." , - __func__, (unsigned long long )inode, - (unsigned long long )XFS_AGINO_TO_INO (mp, agno, agino)); -ASSERT (0 ); -return XFS_ERROR (EINVAL ); - } - agbno =XFS_AGINO_TO_AGBNO (mp, agino); -if (agbno >= mp->m_sb.sb_agblocks) { -xfs_warn (mp,"%s: agbno >= mp->m_sb.sb_agblocks (%d >= %d)." , - __func__, agbno, mp->m_sb.sb_agblocks); -ASSERT (0 ); -return XFS_ERROR (EINVAL ); - } -/* -* Get the allocation group header. -*/ - error =xfs_ialloc_read_agi (mp, tp, agno, &agbp); -if (error) { -xfs_warn (mp,"%s: xfs_ialloc_read_agi() returned error %d." , - __func__, error); -return error; - } - agi =XFS_BUF_TO_AGI (agbp);ASSERT (agi->agi_magicnum ==cpu_to_be32 (XFS_AGI_MAGIC ));ASSERT (agbno <be32_to_cpu (agi->agi_length)); +/* * Initialize the cursor. */
@@ -1511,6 +1468,7 @@ xfs_difree(if (error) goto error0; + *orec = rec;xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR );return 0 ;
@@ -1519,6 +1477,80 @@ error0:return error; } +/* +* Free disk inode. Carefully avoids touching the incore inode, all +* manipulations incore are the caller's responsibility. +* The on-disk inode is not changed by this operation, only the +* btree (free inode mask) is changed. +*/ +int +xfs_difree ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_ino_t inode,/* inode to be freed */ +xfs_bmap_free_t *flist,/* extents to free */ +int *delete,/* set if inode cluster was deleted */ +xfs_ino_t *first_ino)/* first inode in deleted cluster */ +{ +/* REFERENCED */ +xfs_agblock_t agbno;/* block number containing inode */ +xfs_buf_t *agbp;/* buffer containing allocation group header */ +xfs_agino_t agino;/* inode number relative to allocation group */ +xfs_agnumber_t agno;/* allocation group number */ +int error;/* error return value */ +xfs_mount_t *mp;/* mount structure for filesystem */ +xfs_inobt_rec_incore_t rec;/* btree record */ + + mp = tp->t_mountp; + +/* +* Break up inode number into its components. +*/ + agno =XFS_INO_TO_AGNO (mp, inode); +if (agno >= mp->m_sb.sb_agcount) { +xfs_warn (mp,"%s: agno >= mp->m_sb.sb_agcount (%d >= %d)." , + __func__, agno, mp->m_sb.sb_agcount); +ASSERT (0 ); +return XFS_ERROR (EINVAL ); + } + agino =XFS_INO_TO_AGINO (mp, inode); +if (inode !=XFS_AGINO_TO_INO (mp, agno, agino)) { +xfs_warn (mp,"%s: inode != XFS_AGINO_TO_INO() (%llu != %llu)." , + __func__, (unsigned long long )inode, + (unsigned long long )XFS_AGINO_TO_INO (mp, agno, agino)); +ASSERT (0 ); +return XFS_ERROR (EINVAL ); + } + agbno =XFS_AGINO_TO_AGBNO (mp, agino); +if (agbno >= mp->m_sb.sb_agblocks) { +xfs_warn (mp,"%s: agbno >= mp->m_sb.sb_agblocks (%d >= %d)." , + __func__, agbno, mp->m_sb.sb_agblocks); +ASSERT (0 ); +return XFS_ERROR (EINVAL ); + } +/* +* Get the allocation group header. +*/ + error =xfs_ialloc_read_agi (mp, tp, agno, &agbp); +if (error) { +xfs_warn (mp,"%s: xfs_ialloc_read_agi() returned error %d." , + __func__, error); +return error; + } + +/* +* Fix up the inode allocation btree. +*/ + error =xfs_difree_inobt (mp, tp, agbp, agino, flist, delete, first_ino, + &rec); +if (error) + goto error0; + +return 0 ; + +error0: +return error; +} + STATIC int xfs_imap_lookup( struct xfs_mount *mp,
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 8/10 xfs: update the finobt on inode free
In reply to Brian FosterAn inode free operation can have several effects on the finobt. If all inodes have been freed and the chunk deallocated, we remove the finobt record. If the inode chunk was previously full, we must insert a new record based on the existing inobt record. Otherwise, we modify the record in place.
Create the xfs_ifree_finobt() function to identify the potential scenarios and update the finobt appropriately.
--- fs/xfs/xfs_ialloc.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+)
fs/xfs/xfs_ialloc.c +109 -0
@@ -1478,6 +1478,106 @@ error0: }/* +* Free an inode in the free inode btree. +*/ +STATIC int +xfs_difree_finobt ( +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_buf *agbp, +xfs_agino_t agino, +struct xfs_inobt_rec_incore *ibtrec)/* inobt record */ +{ +struct xfs_agi *agi =XFS_BUF_TO_AGI (agbp); +xfs_agnumber_t agno =be32_to_cpu (agi->agi_seqno); +struct xfs_btree_cur *cur; +struct xfs_inobt_rec_incore rec; +int offset = agino - ibtrec->ir_startino; +int error; +int i; + + cur =xfs_inobt_init_cursor (mp, tp, agbp, agno,XFS_BTNUM_FINO ); + + error =xfs_inobt_lookup (cur, ibtrec->ir_startino,XFS_LOOKUP_EQ , &i); +if (error) + goto error; +if (i ==0 ) { +/* +* If the record does not exist in the finobt, we must have just +* freed an inode in a previously fully allocated chunk. If not, +* something is out of sync. +*/ +XFS_WANT_CORRUPTED_GOTO (ibtrec->ir_freecount ==1 , error); + + error =xfs_inobt_insert_rec (cur, ibtrec->ir_freecount, + ibtrec->ir_free, &i); +if (error) + goto error; +ASSERT (i ==1 ); + + goto out; + } + +/* +* Read and update the existing record. +*/ + error =xfs_inobt_get_rec (cur, &rec, &i); +if (error) + goto error; +XFS_WANT_CORRUPTED_GOTO (i ==1 , error); + + rec.ir_free |=XFS_INOBT_MASK (offset); + rec.ir_freecount++; + +XFS_WANT_CORRUPTED_GOTO ((rec.ir_free == ibtrec->ir_free) && + (rec.ir_freecount == ibtrec->ir_freecount), + error); + +/* +* The content of inobt records should always match between the inobt +* and finobt. The lifecycle of records in the finobt is different from +* the inobt in that the finobt only tracks records with at least one +* free inode. This is to optimize lookup for inode allocation purposes. +* The following checks determine whether to update the existing record or +* remove it entirely. +*/ + +if (rec.ir_freecount ==XFS_IALLOC_INODES (mp) && + !(mp->m_flags &XFS_MOUNT_IKEEP )) { +/* +* If all inodes are free and we're in !ikeep mode, the entire +* inode chunk has been deallocated. Remove the record from the +* finobt. +*/ + error =xfs_btree_delete (cur, &i); +if (error) + goto error; +ASSERT (i ==1 ); + }else { +/* +* The existing finobt record was modified and has a combination +* of allocated and free inodes or is completely free and ikeep +* is enabled. Update the record. +*/ + error =xfs_inobt_update (cur, &rec); +if (error) + goto error; + } + +out: + error =xfs_check_agi_freecount (cur, agi); +if (error) + goto error; + +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); +return 0 ; + +error: +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +return error; +} + +/* * Free disk inode. Carefully avoids touching the incore inode, all * manipulations incore are the caller's responsibility. * The on-disk inode is not changed by this operation, only the
@@ -1545,6 +1645,15 @@ xfs_difree(if (error) goto error0; +/* +* Fix up the free inode btree. +*/ +if (xfs_sb_version_hasfinobt (&mp->m_sb)) { + error =xfs_difree_finobt (mp, tp, agbp, agino, &rec); +if (error) + goto error0; + } +return 0 ; error0:
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 9/10 xfs: add finobt support to growfs
In reply to Brian FosterAdd finobt support to growfs. Initialize the agi root/level fields and the root finobt block.
--- fs/xfs/xfs_fsops.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
fs/xfs/xfs_fsops.c +32 -0
@@ -311,6 +311,10 @@ xfs_growfs_data_private( agi->agi_dirino =cpu_to_be32 (NULLAGINO );if (xfs_sb_version_hascrc (&mp->m_sb))uuid_copy (&agi->agi_uuid, &mp->m_sb.sb_uuid); +if (xfs_sb_version_hasfinobt (&mp->m_sb)) { + agi->agi_free_root =cpu_to_be32 (XFS_FIBT_BLOCK (mp)); + agi->agi_free_level =cpu_to_be32 (1 ); + }for (bucket =0 ; bucket <XFS_AGI_UNLINKED_BUCKETS ; bucket++) agi->agi_unlinked[bucket] =cpu_to_be32 (NULLAGINO );
@@ -402,6 +406,34 @@ xfs_growfs_data_private(xfs_buf_relse (bp);if (error) goto error0; + +/* +* FINO btree root block +*/ +if (xfs_sb_version_hasfinobt (&mp->m_sb)) { + bp =xfs_growfs_get_hdr_buf (mp, +XFS_AGB_TO_DADDR (mp, agno,XFS_FIBT_BLOCK (mp)), +BTOBB (mp->m_sb.sb_blocksize),0 , + &xfs_inobt_buf_ops); +if (!bp) { + error =ENOMEM ; + goto error0; + } + +if (xfs_sb_version_hascrc (&mp->m_sb)) +xfs_btree_init_block (mp, bp,XFS_FIBT_CRC_MAGIC , +0 ,0 , agno, +XFS_BTREE_CRC_BLOCKS ); +else +xfs_btree_init_block (mp, bp,XFS_FIBT_MAGIC ,0 , +0 , agno,0 ); + + error =xfs_bwrite (bp); +xfs_buf_relse (bp); +if (error) + goto error0; + } + }xfs_trans_agblocks_delta (tp, nfree);/*
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 10/10 xfs: enable the finobt feature on v5 superblocks
In reply to Brian FosterAdd the finobt feature bit to the list of known features. As of this point, the kernel code knows how to mount and manage both finobt and non-finobt formatted filesystems.
--- fs/xfs/xfs_sb.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_sb.h +2 -1
@@ -586,7 +586,8 @@ xfs_sb_has_compat_feature( }#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0)/* free inode btree */ -#define XFS_SB_FEAT_RO_COMPAT_ALL 0 +#define XFS_SB_FEAT_RO_COMPAT_ALL \ + (XFS_SB_FEAT_RO_COMPAT_FINOBT)#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALLstatic inline bool xfs_sb_has_ro_compat_feature(
Signature · 6 lines
1.8.1.4 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
[ cc list ]
Quoted 41 lines · Brian Foster
Quoted 18 lines · Michael Semon
Quoted 17 lines · Brian Foster
Hi all,
Here is the first release of free inode btree support for the kernel. It is based on the RFC previously made available here:
http://oss.sgi.com/archives/xfs/2013-09/msg00076.html
The free inode btree adds a new inode btree to XFS with the intent to track only inode chunks with at least one free inode. Patches 1-3 add the necessary support for the new
XFS_BTNUM_FINOBTtype and introduce a read-only v5 superblock flag. Patch 4 updates the transaction reservations for inode allocation operations to account for the finobt. Patches 5-9 add support to manage the finobt on inode chunk allocation, inode allocation, inode free (and chunk deletion) and growfs. The 10th and final patch adds the feature bit to the associated mask. Thoughts, reviews and flames appreciated.Quoted 9 lines
Quoted 1 line
Brian
OK, I'm giving this a go on x86, and xfstests generic/* seems to be OK.
lockdep is happy so far. The merge was straightforward but not
automatic by any means. However, there was a crash on xfs/030, and I'm sending a simple crash log because I'm on vacation, and my test setup is not up to snuff (no serial, one drive dying, bad Internet connection, etc.).Hi Michael,
Interesting notion of vacation you have there. ;)
Yes, I'm aware of this issue. This is due to the current lack of
xfs_repairsupport for finobt.xfs_repairscans the existing inode btree into memory and actually regenerates and writes out a new inode btree afterwards. This doesn't yet happen for the finobt, soxfs_repaireffectively zeroes out (corrupts) the finobt root/level fields in the agi and leads to this explosion. In short, you'll want to run xfstests with "-x repair" until that support is added.
Quoted 239 lines
Now that I think of it, this should probably manifest as an fs shutdown or something more graceful than a panic. I'll look into that. Thanks for testing!
Brian
Quoted 232 lines
The merge against xfsprogs went fairly smoothly.
Both merges were over the top of some of Dave's recent work, and maybe that's why they weren't automatic.
Thanks!
Michael
[
crashsession follows]Script started on Thu 17 Oct 2013 07:21:41 PM EDT
root:/usr/src/dumps# crash vmlinux current-crashcrash 7.0.2
Copyright (C) 2002-2013 Red Hat, Inc.
Copyright (C) 2004, 2005, 2006, 2010 IBM Corporation Copyright (C) 1999-2006 Hewlett-Packard Co
Copyright (C) 2005, 2006, 2011, 2012 Fujitsu Limited Copyright (C) 2006, 2007 VA Linux Systems Japan K.K. Copyright (C) 2005, 2011 NEC Corporation
Copyright (C) 1999, 2002, 2007 Silicon Graphics, Inc. Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc. This program is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Enter "help copying" to see the conditions. This program has absolutely no warranty. Enter "help warranty" for details.GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...please wait... (gathering kmem slab cache data)
WARNING: cannot determine how modules are linked
WARNING: no kernel module accessplease wait... (gathering task table data)
please wait... (determining panic task)KERNEL: vmlinux DUMPFILE: current-crash CPUS: 1 DATE: Thu Oct 17 18:53:48 2013 UPTIME: 02:40:00 LOAD AVERAGE: 1.50, 18.11, 24.54 TASKS: 77 NODENAME: plbearer RELEASE: 3.12.0-rc4+ VERSION: #7 Thu Oct 17 15:30:41 EDT 2013 MACHINE: i686 (1794 Mhz) MEMORY: 510.6 MB PANIC: "Oops: 0000 [#1] DEBUG_PAGEALLOC" (check log for details) PID: 9475 COMMAND: "dd" TASK: de0b9430 [THREAD_INFO: d350c000] CPU: 0 STATE: TASK_RUNNING (PANIC)crash> ps
PID PPID CPU TASK ST %MEM VSZ RSS COMM 0 0 0 c174f620 RU 0.0 0 0 [swapper] 1 0 0 c0058000 IN 0.0 2116 76 init 2 0 0 c0059430 IN 0.0 0 0 [kthreadd] 3 2 0 c005a860 IN 0.0 0 0 [ksoftirqd/0] 5 2 0 c005d0c0 IN 0.0 0 0 [kworker/0:0H] 7 2 0 c0118000 IN 0.0 0 0 [watchdog/0] 8 2 0 c0119430 IN 0.0 0 0 [khelper] 9 2 0 c011a860 IN 0.0 0 0 [kdevtmpfs] 10 2 0 c011bc90 IN 0.0 0 0 [writeback] 11 2 0 c011d0c0 IN 0.0 0 0 [bioset] 12 2 0 c011e4f0 IN 0.0 0 0 [kblockd] 13 2 0 c01b8000 IN 0.0 0 0 [ata_sff] 14 2 0 c01b9430 IN 0.0 0 0 [khubd] 17 2 0 c01bd0c0 IN 0.0 0 0 [rt-test-0] 18 2 0 c01be4f0 IN 0.0 0 0 [rt-test-1] 19 2 0 c01bbc90 IN 0.0 0 0 [rt-test-2] 20 2 0 c0298000 IN 0.0 0 0 [rt-test-3] 21 2 0 c0299430 IN 0.0 0 0 [rt-test-4] 22 2 0 c029a860 IN 0.0 0 0 [rt-test-5] 23 2 0 c029bc90 IN 0.0 0 0 [rt-test-6] 24 2 0 c029d0c0 IN 0.0 0 0 [rt-test-7] 25 2 0 c029e4f0 IN 0.0 0 0 [khungtaskd] 26 2 0 c02b8000 IN 0.0 0 0 [kswapd0] 27 2 0 c02b9430 IN 0.0 0 0 [fsnotify_mark] 28 2 0 c02ba860 IN 0.0 0 0 [cifsiod] 29 2 0 c02bbc90 IN 0.0 0 0 [jfsIO] 30 2 0 c02bd0c0 IN 0.0 0 0 [jfsCommit] 31 2 0 c02be4f0 IN 0.0 0 0 [jfsSync] 32 2 0 de998000 IN 0.0 0 0 [xfsalloc] 33 2 0 de999430 IN 0.0 0 0 [xfs_mru_cache] 34 2 0 de99a860 IN 0.0 0 0 [xfslogd] 35 2 0 de99bc90 IN 0.0 0 0 [bioset] 36 2 0 de99d0c0 IN 0.0 0 0 [crypto] 52 2 0 de9d1430 IN 0.0 0 0 [scsi_eh_0] 53 2 0 de9d0000 IN 0.0 0 0 [scsi_eh_1] 56 2 0 de9d50c0 IN 0.0 0 0 [kpsmoused] 60 2 0 dead9430 IN 0.0 0 0 [kworker/0:1H] 61 2 0 deada860 IN 0.0 0 0 [kmemleak] 62 2 0 deadbc90 IN 0.0 0 0 [deferwq] 121 1 0 debd2860 IN 0.0 2168 260 syslogd 126 1 0 debd64f0 IN 0.0 2112 232 klogd 233 1 0 debd3c90 IN 0.1 5024 480 ntpd 238 1 0 debd50c0 IN 0.0 2128 52 acpid 240 1 0 deadd0c0 IN 0.0 2456 4 gpm 242 1 0 debd0000 IN 0.0 2348 172 crond 244 1 0 de550000 IN 0.0 2340 4 atd 250 1 0 de552860 IN 0.0 3828 4 bash 251 1 0 de553c90 IN 0.0 3828 4 bash 252 1 0 de5550c0 IN 0.0 3832 4 bash 253 1 0 de5564f0 IN 0.0 3828 4 bash 254 1 0 deade4f0 IN 0.0 2352 4 agetty 3574 2 0 c235bc90 IN 0.0 0 0 [kworker/u2:1] 8980 2 0 d7e62860 IN 0.0 0 0 [xfs-data/sda4] 8981 2 0 d7e60000 IN 0.0 0 0 [xfs-conv/sda4] 8982 2 0 d7e664f0 IN 0.0 0 0 [xfs-cil/sda4] 8983 2 0 d7e61430 IN 0.0 0 0 [xfsaild/sda4] 9003 26905 0 d7cae4f0 IN 0.3 3512 1744 030 9223 9003 0 d7e63c90 IN 0.2 3532 1256 030 9224 9003 0 d7e650c0 IN 0.1 2224 596 sed 9465 2 0 d08250c0 IN 0.0 0 0 [xfs-data/sda5] 9466 2 0 d0822860 IN 0.0 0 0 [xfs-conv/sda5] 9467 2 0 d08264f0 IN 0.0 0 0 [xfs-cil/sda5] 9468 2 0 d0823c90 IN 0.0 0 0 [xfsaild/sda5] 9469 9223 0 d7cad0c0 IN 0.2 3540 1176 030 9470 9223 0 d7cabc90 IN 0.2 3532 1060 030 9471 9470 0 d7caa860 IN 0.1 2184 456 fgrep > 9475 9469 0 de0b9430 RU 0.1 2008 384 dd 11362 2 0 de2b0000 IN 0.0 0 0 [kworker/0:2] 11364 2 0 de0bd0c0 IN 0.0 0 0 [kworker/0:3] 16034 2 0 d0821430 IN 0.0 0 0 [kworker/0:8] 16748 2 0 d7ca9430 IN 0.0 0 0 [kworker/0:14] 17966 2 0 c235d0c0 IN 0.0 0 0 [kworker/u2:2] 20267 251 0 de2b64f0 IN 0.1 2684 444 watch 26881 1 0 de0be4f0 IN 0.0 3824 4 bash 26905 26881 0 de0bbc90 IN 0.2 4072 1196 check 29183 250 0 de0b8000 IN 0.0 2384 40 cat 29240 2 0 de2b3c90 IN 0.0 0 0 [kworker/u2:0]crash> log -t # trimmed
XFS (sda5): Using inode cluster size of 16384 bytes XFS (sda5): Mounting Filesystem
XFS (sda5): Ending clean mountBUG: unable to handle kernel NULL pointer dereference at 00000006 IP: [<c11e098f>] xfs_btree_lookup+0x1b4/0x42a *pde = 00000000 Oops: 0000 [#1] DEBUG_PAGEALLOC CPU: 0 PID: 9475 Comm: dd Not tainted 3.12.0-rc4+ #7 Hardware name: Dell Computer Corporation Dimension 2350/07W080, BIOS A0112/17/2 002
task:de0b9430ti:d350c000task.ti:d350c000
EIP: 0060:[<c11e098f>] EFLAGS: 00010286 CPU: 0 EIP is atxfs_btree_lookup+0x1b4/0x42a
EAX: 00000000 EBX:deb11390ECX: 00000000 EDX:c0187a80
ESI: 00000060 EDI: ffffffff EBP:d350dc10ESP:d350dbd0
DS: 007b ES: 007b FS: 0000 GS: 00e0 SS: 0068
CR0:8005003bCR2: 00000006 CR3:0ec44000CR4:000007d0Stack: 00000060 c41c5a00 c0028200 00000001 d350dc54 ffffffff 00000001 00000000 00000000 00000000 d350dc10 c11fb45e de67ee00 deb11390 00000060 00000000 d350dc88 c11f921d 00000000 00000004 00000001 00000246 c120c778 de26d800 Call Trace: [<c11fb45e>] ? xfs_inobt_init_cursor+0x2c/0x91 [<c11f921d>] xfs_dialloc_ag+0x223/0x7fb [<c120c778>] ? xfs_perag_get+0xb8/0x21c [<c11fa087>] ? xfs_ialloc_read_agi+0x3a/0x95 [<c11fa0bf>] ? xfs_ialloc_read_agi+0x72/0x95 [<c11facd7>] ? xfs_dialloc+0x229/0x272 [<c11faafd>] xfs_dialloc+0x4f/0x272 [<c11fc8a9>] xfs_ialloc+0x4d/0x6f1 [<c11fb83b>] ? xfs_ilock+0x100/0x1f1 [<c11fcfc0>] xfs_dir_ialloc+0x73/0x245 [<c11fb83b>] ? xfs_ilock+0x100/0x1f1 [<c11fd3bf>] ? xfs_create+0x1b1/0x73e [<c11fd591>] xfs_create+0x383/0x73e [<c11b3091>] xfs_vn_mknod+0xb0/0x175 [<c11b3156>] ? xfs_vn_mknod+0x175/0x175 [<c11b3170>] xfs_vn_create+0x1a/0x1c [<c10e92f6>] vfs_create+0x69/0xc8 [<c10e9a7d>] do_last.isra.48+0x728/0xd54 [<c10e7c0f>] ? link_path_walk+0x54/0x6da [<c10ea151>] path_openat+0xa8/0x53c [<c1059fc5>] ? local_clock+0x3d/0x58 [<c10ea616>] do_filp_open+0x31/0x72 [<c10dd812>] do_sys_open+0x116/0x1de [<c156d9f2>] ? sysenter_exit+0xf/0x1d [<c10dd8fc>] SyS_open+0x22/0x24 [<c156d9bf>] sysenter_do_call+0x12/0x36 Code: fa 1f 89 d0 2b 45 d8 1b 55 dc 89 d0 c1 e8 1f 74 0c 83 7d cc 01 0f94 c0 3c 01 83 d7 ff 89 7b 4c 85 ff 0f 84 84 01 00 00 8b 45 e0 <0f> b7 40 06 86 e0 0f b7 c0 39 f8 0f 8c 70 01 00 00 8b 45 d8 8b
EIP: [<c11e098f>]xfs_btree_lookup+0x1b4/0x42aSS:ESP 0068:d350dbd0
CR2: 0000000000000006
crash> bt
PID: 9475 TASK:de0b9430CPU: 0 COMMAND: "dd"
#0 [d350da64]crash_kexecatc1080ca0
#1 [d350daa8]__bad_area_nosemaphoreatc15614f3
#2 [d350dae8]bad_areaatc15616df
#3 [d350db00]__do_page_faultatc10248bf
#4 [d350db88]do_page_faultatc1024b74
#5 [d350db90]error_code(viapage_fault) atc156d6b8EAX: 00000000 EBX: deb11390 ECX: 00000000 EDX: c0187a80 EBP: d350dc10 DS: 007b ESI: 00000060 ES: 007b EDI: ffffffff GS: 00e0 CS: 0060 EIP: c11e098f ERR: ffffffff EFLAGS: 00010286#6 [
d350dbc4]xfs_btree_lookupatc11e098f
#7 [d350dbfc]xfs_inobt_init_cursoratc11fb459
#8 [d350dc14]xfs_dialloc_agatc11f9218
#9 [d350dc8c]xfs_diallocatc11faaf8
#10 [d350dccc]xfs_iallocatc11fc8a4
#11 [d350dd0c]xfs_dir_iallocatc11fcfbb
#12 [d350dd5c]xfs_createatc11fd58c
#13 [d350ddd8]xfs_vn_mknodatc11b308c
#14 [d350de10]xfs_vn_createatc11b316b
#15 [d350de1c]vfs_createatc10e92f4
#16 [d350de48]do_lastatc10e9a78
#17 [d350dea4]path_openatatc10ea14c
#18 [d350def0]do_filp_openatc10ea611
#19 [d350df64]do_sys_openatc10dd80d
#20 [d350dfa4]sys_openatc10dd8f7
#21 [d350dfb0]ia32_sysenter_targetatc156d9b8EAX: 00000005 EBX: bfd0befd ECX: 00008241 EDX: 000001b6 DS: 007b ESI: 00000000 ES: 007b EDI: b778a000 SS: 007b ESP: bfd0a670 EBP: bfd0a7d8 GS: 0033 CS: 0073 EIP: b77b9424 ERR: 00000005 EFLAGS: 00000286crash> quit
root:/usr/src/dumps#
Script done on Thu 17 Oct 2013 07:23:23 PM EDT
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs