xfsprogs: add reverse-mapping, reflink, and dedupe support
v4 cover xfsprogs: add reverse-mapping, reflink, and dedupe support
Hi all,
This is the fourth revision of an RFC for adding to xfsprogs support for tracking reverse-mappings of physical blocks to file and metadata; and support for mapping multiple file logical blocks to the same physical block, more commonly known as reflinking. Given the significant amount of re-engineering required to make the initial rmap implementation compatible with reflink, I decided to publish both features as an integrated patchset off of upstream. This means that rmap and reflink are (still) compatible with each other.
The patch set is based on the current (4.3.0+) for-next branch. This code should be relatively bug-free, and the bulk of the patches are to teach xfs_repair how to record all mappings and to use that data both to regenerate the reference count data (refcntbt) and the reverse mapping index (rmapbt). There are way too many patches to discuss them individually, but roughly speaking they're grouped by functional area:
0. Cleanups
1. Implement reflink and dedupe in xfs_io
2. Spot-check and fuzz v5 filesystems in xfs_db (otherwise the test/scratch fs checks in xfstests get unhappy)
3. rmapbt support
4. rmapbt rebuilding in xfs_repair
5. refcntbt support
6. refcntbt rebuilding in xfs_repair
Issues:
* Under certain circumstances, mkfs underestimates the minimum log
size and the kernel refuses to mount. The last patch in the set hacks around this in an ugly way.
If you're going to start using this mess, you probably ought to just pull from my github trees for kernel[1], xfsprogs[2], and xfstests[3]. There's also repositories for xfs documentation[4] and man-pages[5]. These patches have not changed significantly since RFCv3.
This is an extraordinary way to eat your data. Enjoy!
Comments and questions are, as always, welcome.
--D
[1] https://github.com/djwong/linux/tree/for-dave
[2] https://github.com/djwong/xfsprogs/tree/for-dave
[3] https://github.com/djwong/xfstests/tree/for-dave
[4] https://github.com/djwong/xfs-documentation/tree/for-dave
[5] https://github.com/djwong/man-pages/commits/for-mtk
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 1/53 xfs_io: allow zero-length reflink/dedupe commands
Since it's convention that calling the reflink/dedupe ioctls with a zero length means "do this until you hit EOF in the source file", explicitly permit this as an input. Fix the ioctl code to handle this correctly.
--- io/reflink.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
io/reflink.c +13 -11
@@ -71,7 +71,7 @@ dedupe_ioctl( info->fd = file->fd; info->logical_offset = doffset; -while (args->length >0 ) { +while (args->length >0 || !*ops) { error =ioctl (fd,XFS_IOC_FILE_EXTENT_SAME , args);if (error) {perror ("XFS_IOC_FILE_EXTENT_SAME" );
@@ -85,14 +85,16 @@ dedupe_ioctl(printf (_ ("Extents did not match.\n" )); goto done; } -if (info->bytes_deduped ==0 || - info->bytes_deduped > args->length) +if (args->length !=0 && + (info->bytes_deduped ==0 || + info->bytes_deduped > args->length))break ; (*ops)++; args->logical_offset += info->bytes_deduped; info->logical_offset += info->bytes_deduped; - args->length -= info->bytes_deduped; +if (args->length >= info->bytes_deduped) + args->length -= info->bytes_deduped; deduped += info->bytes_deduped; } done:
@@ -145,7 +147,7 @@ dedupe_f( } optind++; count =cvtnum (fsblocksize, fssectsize, argv[optind]); -if (count <1 ) { +if (count <0 ) {printf (_ ("non-positive length argument -- %s\n" ), argv[optind]);return 0 ; }
@@ -202,7 +204,11 @@ reflink_ioctl(struct xfs_clone_args args;int error; -if (len) { +if (soffset ==0 && doffset ==0 && len ==0 ) { + error =ioctl (file->fd,XFS_IOC_CLONE , fd); +if (error) +perror ("XFS_IOC_CLONE" ); + }else { args.src_fd = fd; args.src_offset = soffset; args.src_length = len;
@@ -210,10 +216,6 @@ reflink_ioctl( error =ioctl (file->fd,XFS_IOC_CLONE_RANGE , &args);if (error)perror ("XFS_IOC_CLONE_RANGE" ); - }else { - error =ioctl (file->fd,XFS_IOC_CLONE , fd); -if (error) -perror ("XFS_IOC_CLONE" ); }if (!error) (*ops)++;
@@ -268,7 +270,7 @@ reflink_f( } optind++; count =cvtnum (fsblocksize, fssectsize, argv[optind]); -if (count <1 ) { +if (count <0 ) {printf (_ ("non-positive length argument -- %s\n" ), argv[optind]);return 0 ; }
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 2/53 xfs_db: make check work for sparse inodes
In reply to Darrick J. WongTeach the inobt/finobt scanning functions how to deal with sparse inode chunks well enough that we can pass the spot-check. Should fix the xfs/076 failures.
v2: Put the alignment checks back in, and for each individual chunk of inodes hanging off an inobt record, parse each chunk separately. There is no (future) guarantee that all the inodes in a sparse inobt record will be contiguous.
--- db/check.c | 249 ++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 200 insertions(+), 49 deletions(-)
db/check.c +200 -49
@@ -4319,6 +4319,51 @@ scanfunc_cnt(scan_sbtree (agf,be32_to_cpu (pp[i]), level,0 , scanfunc_cnt,TYP_CNTBT ); } +static bool +ino_issparse ( +struct xfs_inobt_rec *rp, +int offset) +{ +if (!xfs_sb_version_hassparseinodes (&mp->m_sb)) +return false; + +return xfs_inobt_is_sparse_disk (rp, offset); +} + +static int +find_one_ino_bit ( +__u16 mask, +int startino) +{ +int n; +int b; + + startino /=XFS_INODES_PER_HOLEMASK_BIT ; + b = startino; + mask >>= startino; +for (n = startino; n <sizeof (mask) *NBBY && !(mask &1 ); n++, mask >>=1 ) + b++; + +return b *XFS_INODES_PER_HOLEMASK_BIT ; +} + +static int +find_zero_ino_bit ( +__u16 mask, +int startino) +{ +int n; +int b; + + startino /=XFS_INODES_PER_HOLEMASK_BIT ; + b = startino; + mask >>= startino; +for (n = startino; n <sizeof (mask) *NBBY && (mask &1 ); n++, mask >>=1 ) + b++; + +return b *XFS_INODES_PER_HOLEMASK_BIT ; +} + static void scanfunc_ino( struct xfs_btree_block *block,
@@ -4336,6 +4381,13 @@ scanfunc_ino(int off;xfs_inobt_ptr_t *pp;xfs_inobt_rec_t *rp; +bool sparse, crc; +int inodes_per_chunk; +int freecount; +int startidx, endidx; +__u16 holemask; +xfs_agino_t rino; +xfs_extlen_t cblocks;if (be32_to_cpu (block->bb_magic) !=XFS_IBT_MAGIC &&be32_to_cpu (block->bb_magic) !=XFS_IBT_CRC_MAGIC ) {
@@ -4363,59 +4415,111 @@ scanfunc_ino(return ; } rp =XFS_INOBT_REC_ADDR (mp, block,1 ); + sparse =xfs_sb_version_hassparseinodes (&mp->m_sb); + crc =xfs_sb_version_hascrc (&mp->m_sb);for (i =0 ; i <be16_to_cpu (block->bb_numrecs); i++) { + nfree =0 ; + +/* First let's look at the inode chunk alignment */ agino =be32_to_cpu (rp[i].ir_startino); off =XFS_INO_TO_OFFSET (mp, agino); -if (off ==0 ) { -if ((sbversion &XFS_SB_VERSION_ALIGNBIT ) && - mp->m_sb.sb_inoalignmt && - (XFS_INO_TO_AGBNO (mp, agino) % - mp->m_sb.sb_inoalignmt)) +if (off ==0 && + (sbversion &XFS_SB_VERSION_ALIGNBIT ) && + mp->m_sb.sb_inoalignmt && + (XFS_INO_TO_AGBNO (mp, agino) % + mp->m_sb.sb_inoalignmt)) { +if (sparse || crc) { +dbprintf (_ ("incorrect record %u/%u " +"alignment in inobt block " +"%u/%u\n" ), + seqno, agino, seqno, bno); + error++; + }else sbversion &= ~XFS_SB_VERSION_ALIGNBIT ; -set_dbmap (seqno,XFS_AGINO_TO_AGBNO (mp, agino), - (xfs_extlen_t )MAX (1 , -XFS_INODES_PER_CHUNK >> - mp->m_sb.sb_inopblog), -DBM_INODE , seqno, bno); } - icount +=XFS_INODES_PER_CHUNK ; - agicount +=XFS_INODES_PER_CHUNK ; - ifree +=be32_to_cpu (rp[i].ir_u.f.ir_freecount); - agifreecount +=be32_to_cpu (rp[i].ir_u.f.ir_freecount); -push_cur (); -set_cur (&typtab[TYP_INODE ], -XFS_AGB_TO_DADDR (mp, seqno, -XFS_AGINO_TO_AGBNO (mp, agino)), - (int )XFS_FSB_TO_BB (mp, mp->m_ialloc_blks), -DB_RING_IGN ,NULL ); -if (iocur_top->data ==NULL ) { -if (!sflag) -dbprintf (_ ("can't read inode block " + +/* Move on to examining the inode chunks */ +if (sparse) { + inodes_per_chunk = rp[i].ir_u.sp.ir_count; + freecount = rp[i].ir_u.sp.ir_freecount; + holemask =be16_to_cpu (rp[i].ir_u.sp.ir_holemask); + startidx =find_zero_ino_bit (holemask,0 ); + }else { + inodes_per_chunk =XFS_INODES_PER_CHUNK ; + freecount =be32_to_cpu (rp[i].ir_u.f.ir_freecount); + holemask =0 ; + startidx =0 ; + } + +/* For each allocated chunk, look at each inode. */ + endidx =find_one_ino_bit (holemask, startidx); +do { + rino = agino + startidx; + cblocks = (endidx - startidx) >> + mp->m_sb.sb_inopblog; + +/* Check the sparse chunk alignment */ +if (sparse && + (XFS_INO_TO_AGBNO (mp, rino) % + mp->m_sb.sb_spino_align)) { +dbprintf (_ ("incorrect chunk %u/%u " +"alignment in inobt block " "%u/%u\n" ), - seqno, -XFS_AGINO_TO_AGBNO (mp, agino)); - error++; + seqno, rino, seqno, bno); + error++; + } + +/* Check the block map */ +set_dbmap (seqno,XFS_AGINO_TO_AGBNO (mp, rino), + cblocks,DBM_INODE , seqno, bno); + +push_cur (); +set_cur (&typtab[TYP_INODE ], +XFS_AGB_TO_DADDR (mp, seqno, +XFS_AGINO_TO_AGBNO (mp, rino)), + (int )XFS_FSB_TO_BB (mp, cblocks), +DB_RING_IGN ,NULL ); +if (iocur_top->data ==NULL ) { +if (!sflag) +dbprintf (_ ("can't read inode block " +"%u/%u\n" ), + seqno, +XFS_AGINO_TO_AGBNO (mp, agino)); + error++; +pop_cur (); +continue ; + } + +/* Examine each inode in this chunk */ +for (j = startidx; j < endidx; j++) { +if (ino_issparse (&rp[i], j)) +continue ; + isfree =XFS_INOBT_IS_FREE_DISK (&rp[i], j); +if (isfree) + nfree++; +process_inode (agf, agino + j, + (xfs_dinode_t *)((char *)iocur_top->data + ((j - startidx) << mp->m_sb.sb_inodelog)), + isfree); + }pop_cur (); -continue ; - } -for (j =0 , nfree =0 ; j <XFS_INODES_PER_CHUNK ; j++) { - isfree =XFS_INOBT_IS_FREE_DISK (&rp[i], j); -if (isfree) - nfree++; -process_inode (agf, agino + j, - (xfs_dinode_t *)((char *)iocur_top->data + ((off + j) << mp->m_sb.sb_inodelog)), - isfree); - } -if (nfree !=be32_to_cpu (rp[i].ir_u.f.ir_freecount)) { + + startidx =find_zero_ino_bit (holemask, endidx); + endidx =find_one_ino_bit (holemask, startidx); + }while (endidx <XFS_INODES_PER_CHUNK ); + icount += inodes_per_chunk; + agicount += inodes_per_chunk; + ifree += freecount; + agifreecount += freecount; + +if (nfree != freecount) {if (!sflag)dbprintf (_ ("ir_freecount/free mismatch, " "inode chunk %u/%u, freecount " "%d nfree %d\n" ), seqno, agino, -be32_to_cpu (rp[i].ir_u.f.ir_freecount), nfree); + freecount, nfree); error++; } -pop_cur (); }return ; }
@@ -4447,6 +4551,11 @@ scanfunc_fino(int off;xfs_inobt_ptr_t *pp;struct xfs_inobt_rec *rp; +bool sparse, crc; +int startidx, endidx; +__u16 holemask; +xfs_agino_t rino; +xfs_extlen_t cblocks;if (be32_to_cpu (block->bb_magic) !=XFS_FIBT_MAGIC &&be32_to_cpu (block->bb_magic) !=XFS_FIBT_CRC_MAGIC ) {
@@ -4474,21 +4583,63 @@ scanfunc_fino(return ; } rp =XFS_INOBT_REC_ADDR (mp, block,1 ); + sparse =xfs_sb_version_hassparseinodes (&mp->m_sb); + crc =xfs_sb_version_hascrc (&mp->m_sb);for (i =0 ; i <be16_to_cpu (block->bb_numrecs); i++) { +/* First let's look at the inode chunk alignment */ agino =be32_to_cpu (rp[i].ir_startino); off =XFS_INO_TO_OFFSET (mp, agino); -if (off ==0 ) { -if ((sbversion &XFS_SB_VERSION_ALIGNBIT ) && - mp->m_sb.sb_inoalignmt && - (XFS_INO_TO_AGBNO (mp, agino) % - mp->m_sb.sb_inoalignmt)) +if (off ==0 && + (sbversion &XFS_SB_VERSION_ALIGNBIT ) && + mp->m_sb.sb_inoalignmt && + (XFS_INO_TO_AGBNO (mp, agino) % + mp->m_sb.sb_inoalignmt)) { +if (sparse || crc) { +dbprintf (_ ("incorrect record %u/%u " +"alignment in finobt block " +"%u/%u\n" ), + seqno, agino, seqno, bno); + error++; + }else sbversion &= ~XFS_SB_VERSION_ALIGNBIT ; -check_set_dbmap (seqno,XFS_AGINO_TO_AGBNO (mp, agino), - (xfs_extlen_t )MAX (1 , -XFS_INODES_PER_CHUNK >> - mp->m_sb.sb_inopblog), -DBM_INODE ,DBM_INODE , seqno, bno); } + +/* Move on to examining the inode chunks */ +if (sparse) { + holemask =be16_to_cpu (rp[i].ir_u.sp.ir_holemask); + startidx =find_zero_ino_bit (holemask,0 ); + }else { + holemask =0 ; + startidx =0 ; + } + +/* For each allocated chunk... */ + endidx =find_one_ino_bit (holemask, startidx); +do { + rino = agino + startidx; + cblocks = (endidx - startidx) >> + mp->m_sb.sb_inopblog; + +/* Check the sparse chunk alignment */ +if (sparse && + (XFS_INO_TO_AGBNO (mp, rino) % + mp->m_sb.sb_spino_align)) { +dbprintf (_ ("incorrect chunk %u/%u " +"alignment in finobt block " +"%u/%u\n" ), + seqno, rino, seqno, bno); + error++; + } + +/* Check the block map */ +check_set_dbmap (seqno, +XFS_AGINO_TO_AGBNO (mp, rino), + cblocks,DBM_INODE ,DBM_INODE , + seqno, bno); + + startidx =find_zero_ino_bit (holemask, endidx); + endidx =find_one_ino_bit (holemask, startidx); + }while (endidx <XFS_INODES_PER_CHUNK ); }return ; }
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 3/53 repair: request inode buffers sized to fit one inode cluster
In reply to Darrick J. WongIn get_agino_buf, grab inode buffers using the same size as the inode processing code. Since the inode processing code uses that same buffer size, this means that get_agino_buf can serve requests from the cache instead of pointlessly dropping the cache entry and screaming about it.
(This function is currently unused, but the refink flag fixer code wants to use it.)
--- repair/dinode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
repair/dinode.c +2 -1
@@ -850,7 +850,8 @@ get_agino_buf(xfs_mount_t *mp,if ((irec =find_inode_rec (mp, agno, agino)) ==NULL )return (NULL ); - size =XFS_FSB_TO_BB (mp,MAX (1 ,XFS_INODES_PER_CHUNK /inodes_per_block)); + size =MAX (1 ,XFS_FSB_TO_BB (mp, + mp->m_inode_cluster_size >> mp->m_sb.sb_blocklog)); bp =libxfs_readbuf (mp->m_dev,XFS_AGB_TO_DADDR (mp, agno,XFS_AGINO_TO_AGBNO (mp, irec->ino_startnum)), size,0 , &xfs_inode_buf_ops);
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 4/53 libxfs: reorder xfs_bmap_add_free args
In reply to Darrick J. WongMove the mount & transaction arguments to the start of xfs_bmap_add_free, like most API calls. The kernel version of rmap makes this change, so porting it to xfsprogs will make maintenance easier.
--- libxfs/xfs_bmap.c | 12 ++++++------ libxfs/xfs_bmap.h | 4 ++-- libxfs/xfs_bmap_btree.c | 2 +- libxfs/xfs_ialloc.c | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-)
libxfs/xfs_bmap.c +6 -6
@@ -559,10 +559,10 @@ xfs_bmap_validate_ret(*/ void xfs_bmap_add_free ( +struct xfs_mount *mp,/* mount point structure */ +struct xfs_bmap_free *flist,/* list of extents */ xfs_fsblock_t bno,/* fs block number of extent */ -xfs_filblks_t len,/* length of extent */ -xfs_bmap_free_t *flist,/* list of extents */ -xfs_mount_t *mp)/* mount point structure */ +xfs_filblks_t len)/* length of extent */ {xfs_bmap_free_item_t *cur;/* current (next) element */ xfs_bmap_free_item_t *new;/* new element */
@@ -688,7 +688,7 @@ xfs_bmap_btree_to_extents( cblock =XFS_BUF_TO_BLOCK (cbp);if ((error =xfs_btree_check_block (cur, cblock,0 , cbp)))return error; -xfs_bmap_add_free (cbno,1 , cur->bc_private.b.flist, mp); +xfs_bmap_add_free (mp, cur->bc_private.b.flist, cbno,1 ); ip->i_d.di_nblocks--;xfs_trans_mod_dquot_byino (tp, ip,XFS_TRANS_DQ_BCOUNT ,-1L );xfs_trans_binval (tp, cbp);
@@ -4969,8 +4969,8 @@ xfs_bmap_del_extent(* If we need to, add to list of extents to delete. */ if (do_fx) -xfs_bmap_add_free (del->br_startblock, del->br_blockcount, flist, - mp); +xfs_bmap_add_free (mp, flist, del->br_startblock, + del->br_blockcount);/* * Adjust inode # blocks in the file. */
libxfs/xfs_bmap.h +2 -2
@@ -182,8 +182,8 @@ void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt,int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd);void xfs_bmap_local_to_extents_empty (struct xfs_inode *ip,int whichfork); -void xfs_bmap_add_free (xfs_fsblock_t bno,xfs_filblks_t len, -struct xfs_bmap_free *flist,struct xfs_mount *mp); +void xfs_bmap_add_free (struct xfs_mount *mp,struct xfs_bmap_free *flist, +xfs_fsblock_t bno,xfs_filblks_t len);void xfs_bmap_cancel (struct xfs_bmap_free *flist);int xfs_bmap_finish (struct xfs_trans **tp,struct xfs_bmap_free *flist,int *committed);
libxfs/xfs_bmap_btree.c +1 -1
@@ -523,7 +523,7 @@ xfs_bmbt_free_block(struct xfs_trans *tp = cur->bc_tp;xfs_fsblock_t fsbno =XFS_DADDR_TO_FSB (mp,XFS_BUF_ADDR (bp)); -xfs_bmap_add_free (fsbno,1 , cur->bc_private.b.flist, mp); +xfs_bmap_add_free (mp, cur->bc_private.b.flist, fsbno,1 ); ip->i_d.di_nblocks--;xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE );
libxfs/xfs_ialloc.c +4 -4
@@ -1822,9 +1822,9 @@ xfs_difree_inode_chunk(if (!xfs_inobt_issparse (rec->ir_holemask)) {/* not sparse, calculate extent info directly */ -xfs_bmap_add_free (XFS_AGB_TO_FSB (mp, agno, +xfs_bmap_add_free (mp, flist,XFS_AGB_TO_FSB (mp, agno,XFS_AGINO_TO_AGBNO (mp, rec->ir_startino)), - mp->m_ialloc_blks, flist, mp); + mp->m_ialloc_blks);return ; }
@@ -1867,8 +1867,8 @@ xfs_difree_inode_chunk(ASSERT (agbno % mp->m_sb.sb_spino_align ==0 );ASSERT (contigblk % mp->m_sb.sb_spino_align ==0 ); -xfs_bmap_add_free (XFS_AGB_TO_FSB (mp, agno, agbno), contigblk, - flist, mp); +xfs_bmap_add_free (mp, flist,XFS_AGB_TO_FSB (mp, agno, agbno), + contigblk);/* reset range to current bit and carry on... */ startidx = endidx = nextbit;
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 5/53 libxfs: use a convenience variable instead of open-coding the fork
In reply to Darrick J. WongUse a convenience variable instead of open-coding the inode fork. This isn't really needed for now, but will become important when we add the copy-on-write fork later.
--- libxfs/xfs_bmap.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
libxfs/xfs_bmap.c +12 -11
@@ -1714,9 +1714,10 @@ xfs_bmap_add_extent_delay_real(xfs_filblks_t temp2=0 ;/* value for da_new calculations */ int tmp_rval;/* partial logging flags */ struct xfs_mount *mp; +int whichfork =XFS_DATA_FORK ; mp = bma->tp ? bma->tp->t_mountp :NULL ; - ifp =XFS_IFORK_PTR (bma->ip,XFS_DATA_FORK ); + ifp =XFS_IFORK_PTR (bma->ip, whichfork);ASSERT (bma->idx >=0 );ASSERT (bma->idx <= ifp->if_bytes /sizeof (struct xfs_bmbt_rec ));
@@ -1775,7 +1776,7 @@ xfs_bmap_add_extent_delay_real(* Don't set contiguous if the combined extent would be too large. * Also check for all-three-contiguous being too large. */ -if (bma->idx < bma->ip->i_df.if_bytes / (uint )sizeof (xfs_bmbt_rec_t) -1 ) { +if (bma->idx < ifp->if_bytes / (uint )sizeof (xfs_bmbt_rec_t) -1 ) { state |=BMAP_RIGHT_VALID ;xfs_bmbt_get_all (xfs_iext_get_ext (ifp, bma->idx +1 ), &RIGHT );
@@ -2006,10 +2007,10 @@ xfs_bmap_add_extent_delay_real(XFS_WANT_CORRUPTED_GOTO (mp, i ==1 , done); } -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { +if (xfs_bmap_needs_btree (bma->ip, whichfork)) { error =xfs_bmap_extents_to_btree (bma->tp, bma->ip, bma->firstblock, bma->flist, - &bma->cur,1 , &tmp_rval,XFS_DATA_FORK ); + &bma->cur,1 , &tmp_rval, whichfork); rval |= tmp_rval;if (error) goto done;
@@ -2090,10 +2091,10 @@ xfs_bmap_add_extent_delay_real(XFS_WANT_CORRUPTED_GOTO (mp, i ==1 , done); } -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { +if (xfs_bmap_needs_btree (bma->ip, whichfork)) { error =xfs_bmap_extents_to_btree (bma->tp, bma->ip, bma->firstblock, bma->flist, &bma->cur,1 , - &tmp_rval,XFS_DATA_FORK ); + &tmp_rval, whichfork); rval |= tmp_rval;if (error) goto done;
@@ -2159,10 +2160,10 @@ xfs_bmap_add_extent_delay_real(XFS_WANT_CORRUPTED_GOTO (mp, i ==1 , done); } -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { +if (xfs_bmap_needs_btree (bma->ip, whichfork)) { error =xfs_bmap_extents_to_btree (bma->tp, bma->ip, bma->firstblock, bma->flist, &bma->cur, -1 , &tmp_rval,XFS_DATA_FORK ); +1 , &tmp_rval, whichfork); rval |= tmp_rval;if (error) goto done;
@@ -2205,13 +2206,13 @@ xfs_bmap_add_extent_delay_real( }/* convert to a btree if necessary */ -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { +if (xfs_bmap_needs_btree (bma->ip, whichfork)) {int tmp_logflags;/* partial log flag return val */ ASSERT (bma->cur ==NULL ); error =xfs_bmap_extents_to_btree (bma->tp, bma->ip, bma->firstblock, bma->flist, &bma->cur, - da_old >0 , &tmp_logflags,XFS_DATA_FORK ); + da_old >0 , &tmp_logflags, whichfork); bma->logflags |= tmp_logflags;if (error) goto done;
@@ -2232,7 +2233,7 @@ xfs_bmap_add_extent_delay_real(if (bma->cur) bma->cur->bc_private.b.allocated =0 ; -xfs_bmap_check_leaf_extents (bma->cur, bma->ip,XFS_DATA_FORK ); +xfs_bmap_check_leaf_extents (bma->cur, bma->ip, whichfork); done: bma->logflags |= rval;return error;
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 6/53 libxfs: refactor the btree size calculator code
In reply to Darrick J. WongCreate a macro to generate btree height calculator functions. This will be used (much) later when we get to the refcount btree.
--- libxfs/xfs_bmap.c | 18 +----------------- libxfs/xfs_bmap_btree.c | 2 ++ libxfs/xfs_bmap_btree.h | 2 ++ libxfs/xfs_inode_fork.c | 1 + libxfs/xfs_shared.h | 29 +++++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 17 deletions(-)
libxfs/xfs_bmap.c +1 -17
@@ -172,25 +172,9 @@ xfs_bmap_worst_indlen( xfs_inode_t *ip, /* incore inode pointer */ xfs_filblks_t len) /* delayed extent length */ { - int level; /* btree level number */ -int maxrecs;/* maximum record count at this level */ -xfs_mount_t *mp;/* mount structure */ xfs_filblks_t rval;/* return value */ - mp = ip->i_mount; - maxrecs = mp->m_bmap_dmxr[0 ]; -for (level =0 , rval =0 ; - level <XFS_BM_MAXLEVELS (mp,XFS_DATA_FORK ); - level++) { - len += maxrecs -1 ; -do_div (len, maxrecs); - rval += len; -if (len ==1 ) -return rval +XFS_BM_MAXLEVELS (mp,XFS_DATA_FORK ) - - level -1 ; -if (level ==0 ) - maxrecs = mp->m_bmap_dmxr[1 ]; - } + rval =xfs_bmbt_calc_btree_size (ip->i_mount, len);return rval; }
libxfs/xfs_bmap_btree.c +2 -0
@@ -880,3 +880,5 @@ xfs_bmbt_change_owner(xfs_btree_del_cursor (cur, error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR );return error; } + +DEFINE_BTREE_SIZE_FN (bmbt, m_bmap_dmxr,XFS_BM_MAXLEVELS (mp,XFS_DATA_FORK ))
libxfs/xfs_bmap_btree.h +2 -0
@@ -140,4 +140,6 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,extern struct xfs_btree_cur *xfs_bmbt_init_cursor (struct xfs_mount *,struct xfs_trans *,struct xfs_inode *,int ); +DECLARE_BTREE_SIZE_FN (bmbt); +#endif /* __XFS_BMAP_BTREE_H__ */
libxfs/xfs_inode_fork.c +1 -0
@@ -17,6 +17,7 @@*/ #include "libxfs_priv.h" #include "xfs_fs.h" +#include "xfs_shared.h" #include "xfs_format.h" #include "xfs_log_format.h" #include "xfs_trans_resv.h"
libxfs/xfs_shared.h +29 -0
@@ -234,4 +234,33 @@ bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset,void xfs_symlink_local_to_remote (struct xfs_trans *tp,struct xfs_buf *bp,struct xfs_inode *ip,struct xfs_ifork *ifp); +/* btree size calculator templates */ +#define DECLARE_BTREE_SIZE_FN (btree) \ +xfs_filblks_t xfs_##btree##_calc_btree_size(struct xfs_mount *mp, \ + unsigned long len); + +#define DEFINE_BTREE_SIZE_FN (btree, limitfield, maxlevels) \ +xfs_filblks_t \ +xfs_##btree##_calc_btree_size( \ + struct xfs_mount *mp, \ + unsigned long len) \ +{ \ + int level; \ + int maxrecs; \ + xfs_filblks_t rval; \ +\ + maxrecs = mp->limitfield[0]; \ + for (level = 0, rval = 0; level < maxlevels; level++) { \ + len += maxrecs - 1; \ + do_div(len, maxrecs); \ + rval += len; \ + if (len == 1) \ + return rval + maxlevels - \ + level - 1; \ + if (level == 0) \ + maxrecs = mp->limitfield[1]; \ + } \ + return rval; \ +} +#endif /* __XFS_SHARED_H__ */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 7/53 libxfs: pack the agfl header structure so XFS_AGFL_SIZE is correct
In reply to Darrick J. WongBecause struct xfs_agfl is 36 bytes long and has a 64-bit integer inside it, gcc will quietly round the structure size up to the nearest 64 bits -- in this case, 40 bytes. This results in the XFS_AGFL_SIZE macro returning incorrect results for v5 filesystems on 64-bit machines (118 items instead of 119). As a result, a 32-bit xfs_repair will see garbage in AGFL item 119 and complain.
Therefore, tell gcc not to pad the structure so that the AGFL size calculation is correct.
--- libxfs/xfs_format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libxfs/xfs_format.h +1 -1
@@ -787,7 +787,7 @@ typedef struct xfs_agfl {__be64 agfl_lsn;__be32 agfl_crc;__be32 agfl_bno[];/* actually XFS_AGFL_SIZE(mp) */ -} xfs_agfl_t; +} __attribute__((packed)) xfs_agfl_t;#define XFS_AGFL_CRC_OFF offsetof(struct xfs_agfl, agfl_crc)
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 8/53 libxfs: add the reverse-mapping btree
In reply to Darrick J. WongQuoted 1 line
From : Dave Chinner <[email protected]>
Provide the basic libxfs code for the rmap btree from the kernel.
--- include/libxfs.h | 1 include/xfs_mount.h | 2 include/xfs_trace.h | 7 + libxfs/Makefile | 3 libxfs/xfs_alloc.c | 27 +++ libxfs/xfs_alloc.h | 6 + libxfs/xfs_bmap.c | 3 libxfs/xfs_bmap_btree.c | 1 libxfs/xfs_btree.h | 22 ++ libxfs/xfs_format.h | 86 ++++++++- libxfs/xfs_ialloc.c | 1 libxfs/xfs_ialloc_btree.c | 1 libxfs/xfs_rmap.c | 413 +++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rmap_btree.c | 404 ++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rmap_btree.h | 65 +++++++ libxfs/xfs_sb.c | 6 + libxfs/xfs_shared.h | 1 libxfs/xfs_types.h | 4 18 files changed, 1032 insertions(+), 21 deletions(-) create mode 100644 libxfs/xfs_rmap.c create mode 100644 libxfs/xfs_rmap_btree.c create mode 100644 libxfs/xfs_rmap_btree.h
include/libxfs.h +1 -0
@@ -66,6 +66,7 @@ extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);#include "xfs_bmap_btree.h" #include "xfs_alloc_btree.h" #include "xfs_ialloc_btree.h" +#include "xfs_rmap_btree.h" #include "xfs_attr_sf.h" #include "xfs_inode_fork.h" #include "xfs_inode_buf.h"
include/xfs_mount.h +2 -0
@@ -64,6 +64,8 @@ typedef struct xfs_mount {uint m_bmap_dmnr[2 ];/* XFS_BMAP_BLOCK_DMINRECS */ uint m_inobt_mxr[2 ];/* XFS_INOBT_BLOCK_MAXRECS */ uint m_inobt_mnr[2 ];/* XFS_INOBT_BLOCK_MINRECS */ +uint m_rmap_mxr[2 ];/* max rmap btree records */ +uint m_rmap_mnr[2 ];/* min rmap btree records */ uint m_ag_maxlevels;/* XFS_AG_MAXLEVELS */ uint m_bm_maxlevels[2 ];/* XFS_BM_MAXLEVELS */ uint m_in_maxlevels;/* XFS_IN_MAXLEVELS */
include/xfs_trace.h +7 -0
@@ -171,4 +171,11 @@#define trace_xfs_perag_get_tag (a,b,c,d) ((c) = (c))#define trace_xfs_perag_put (a,b,c,d) ((c) = (c)) +#define trace_xfs_rmap_alloc_extent (a,b,c,d,e) ((void) 0) +#define trace_xfs_rmap_alloc_extent_done (a,b,c,d,e) ((void) 0) +#define trace_xfs_rmap_alloc_extent_error (a,b,c,d,e) ((void) 0) +#define trace_xfs_rmap_free_extent (a,b,c,d,e) ((void) 0) +#define trace_xfs_rmap_free_extent_done (a,b,c,d,e) ((void) 0) +#define trace_xfs_rmap_free_extent_error (a,b,c,d,e) ((void) 0) +#endif /* __TRACE_H__ */
libxfs/Makefile +3 -0
@@ -35,6 +35,7 @@ HFILES = \ xfs_inode_buf.h \ xfs_inode_fork.h \ xfs_quota_defs.h \ + xfs_rmap_btree.h \ xfs_sb.h \ xfs_shared.h \ xfs_trans_resv.h \
@@ -80,6 +81,8 @@ CFILES = cache.c \ xfs_ialloc_btree.c \ xfs_log_rlimit.c \ xfs_rtbitmap.c \ + xfs_rmap.c \ + xfs_rmap_btree.c \ xfs_sb.c \ xfs_symlink_remote.c \ xfs_trans_resv.c
libxfs/xfs_alloc.c +27 -0
@@ -26,6 +26,7 @@#include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_btree.h" +#include "xfs_rmap_btree.h" #include "xfs_alloc_btree.h" #include "xfs_alloc.h" #include "xfs_cksum.h"
@@ -632,6 +633,12 @@ xfs_alloc_ag_vextent(ASSERT (!args->wasfromfl || !args->isfl);ASSERT (args->agbno % args->alignment ==0 ); +/* insert new block into the reverse map btree */ + error =xfs_rmap_alloc (args->tp, args->agbp, args->agno, + args->agbno, args->len, args->owner); +if (error) +return error; +if (!args->wasfromfl) { error = xfs_alloc_update_counters(args->tp, args->pag, args->agbp,
@@ -2016,6 +2023,7 @@ xfs_alloc_fix_freelist(memset (&targs,0 ,sizeof (targs)); targs.tp = tp; targs.mp = mp; + targs.owner =XFS_RMAP_OWN_AG ; targs.agbp = agbp; targs.agno = args->agno; targs.alignment = targs.minlen = targs.prod = targs.isfl =1 ;
@@ -2651,6 +2659,8 @@ error0:* Free an extent. * Just break up the extent address and hand off to xfs_free_ag_extent * after fixing up the freelist. +* +* XXX: need owner of extent being freed */ int /* error */ xfs_free_extent(
@@ -2692,6 +2702,12 @@ xfs_free_extent( goto error0; } +/* XXX: need owner */ + error =xfs_rmap_free (tp, args.agbp, args.agno, args.agbno, len,0 ); +if (error) + goto error0; + +/* XXX: initially no multiple references, so just free it */ error =xfs_free_ag_extent (tp, args.agbp, args.agno, args.agbno, len,0 );if (!error)xfs_extent_busy_insert (tp, args.agno, args.agbno, len,0 );
@@ -2699,3 +2715,14 @@ error0:xfs_perag_put (args.pag);return error; } + +xfs_extlen_t +xfs_prealloc_blocks ( +struct xfs_mount *mp) +{ +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) +return XFS_RMAP_BLOCK (mp) +1 ; +if (xfs_sb_version_hasfinobt (&mp->m_sb)) +return XFS_FIBT_BLOCK (mp) +1 ; +return XFS_IBT_BLOCK (mp) +1 ; +}
libxfs/xfs_alloc.h +6 -0
@@ -72,6 +72,8 @@ typedef unsigned int xfs_alloctype_t;* needed freelist blocks is 4 fsbs _per AG_, a potential split of file's bmap * btree requires 1 fsb, so we set the number of set-aside blocks * to 4 + 4*agcount. +* +* XXX: this changes for rmapbt filesystems. */ #define XFS_ALLOC_SET_ASIDE (mp) (4 + ((mp)->m_sb.sb_agcount * 4))
@@ -86,10 +88,13 @@ typedef unsigned int xfs_alloctype_t;* * The AG headers are sector sized, so the amount of space they take up is * dependent on filesystem geometry. The others are all single blocks. +* +* XXX: this changes for rmapbt filesystems. */ #define XFS_ALLOC_AG_MAX_USABLE (mp) \ ((mp)->m_sb.sb_agblocks - XFS_BB_TO_FSB(mp, XFS_FSS_TO_BB(mp, 4)) - 7) +xfs_extlen_t xfs_prealloc_blocks (struct xfs_mount *mp);/* * Argument structure for xfs_alloc routines.
@@ -122,6 +127,7 @@ typedef struct xfs_alloc_arg {char isfl;/* set if is freelist blocks - !acctg */ char userdata;/* set if this is user data */ xfs_fsblock_t firstblock;/* io first block allocated */ +uint64_t owner;/* owner of blocks being allocated */ } xfs_alloc_arg_t;/*
libxfs/xfs_bmap.c +3 -0
@@ -753,6 +753,7 @@ xfs_bmap_extents_to_btree(memset (&args,0 ,sizeof (args)); args.tp = tp; args.mp = mp; + args.owner = ip->i_ino; args.firstblock = *firstblock;if (*firstblock ==NULLFSBLOCK ) { args.type =XFS_ALLOCTYPE_START_BNO ;
@@ -899,6 +900,7 @@ xfs_bmap_local_to_extents(memset (&args,0 ,sizeof (args)); args.tp = tp; args.mp = ip->i_mount; + args.owner = ip->i_ino; args.firstblock = *firstblock;/* * Allocate a block. We know we need only one, since the
@@ -3680,6 +3682,7 @@ xfs_bmap_btalloc(memset (&args,0 ,sizeof (args)); args.tp = ap->tp; args.mp = mp; + args.owner = ap->ip->i_ino; args.fsbno = ap->blkno;/* Trim the allocation back to the maximum an AG can fit. */
libxfs/xfs_bmap_btree.c +1 -0
@@ -443,6 +443,7 @@ xfs_bmbt_alloc_block( args.mp = cur->bc_mp; args.fsbno = cur->bc_private.b.firstblock; args.firstblock = args.fsbno; + args.owner = cur->bc_private.b.ip->i_ino;if (args.fsbno ==NULLFSBLOCK ) { args.fsbno =be64_to_cpu (start->l);
libxfs/xfs_btree.h +14 -8
@@ -38,17 +38,19 @@ union xfs_btree_ptr { };union xfs_btree_key { -xfs_bmbt_key_t bmbt; -xfs_bmdr_key_t bmbr;/* bmbt root block */ -xfs_alloc_key_t alloc; -xfs_inobt_key_t inobt; +struct xfs_bmbt_key bmbt; +xfs_bmdr_key_t bmbr;/* bmbt root block */ +xfs_alloc_key_t alloc; +struct xfs_inobt_key inobt; +struct xfs_rmap_key rmap; };union xfs_btree_rec { -xfs_bmbt_rec_t bmbt; -xfs_bmdr_rec_t bmbr;/* bmbt root block */ -xfs_alloc_rec_t alloc; -xfs_inobt_rec_t inobt; +struct xfs_bmbt_rec bmbt; +xfs_bmdr_rec_t bmbr;/* bmbt root block */ +struct xfs_alloc_rec alloc; +struct xfs_inobt_rec inobt; +struct xfs_rmap_rec rmap; };/*
@@ -63,6 +65,7 @@ union xfs_btree_rec {#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) +#define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi)/* * For logging record fields.
@@ -94,6 +97,7 @@ do { \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_RMAP :__XFS_BTREE_STATS_INC (rmap, stat);break ; \case XFS_BTNUM_MAX :ASSERT (0 );/* fucking gcc */ ;break ; \ } \ }while (0 )
@@ -108,6 +112,7 @@ do { \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_RMAP :__XFS_BTREE_STATS_ADD (rmap, stat, val);break ; \case XFS_BTNUM_MAX :ASSERT (0 );/* fucking gcc */ ;break ; \ } \ }while (0 )
@@ -199,6 +204,7 @@ typedef struct xfs_btree_curxfs_alloc_rec_incore_t a;xfs_bmbt_irec_t b;xfs_inobt_rec_incore_t i; +struct xfs_rmap_irec r; } bc_rec;/* current insert/search record value */ struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS ];/* buf ptr per level */ int bc_ptrs[XFS_BTREE_MAXLEVELS ];/* key/record # */
libxfs/xfs_format.h +75 -11
127 lines not on this page · raw message
libxfs/xfs_ialloc.c +1 -0
@@ -615,6 +615,7 @@ xfs_ialloc_ag_alloc( args.mp->m_ialloc_min_blks < args.mp->m_ialloc_blks) do_sparse =prandom_u32 () &1 ;#endif + args.owner =XFS_RMAP_OWN_INODES ;/* * Locking will ensure that we don't have two callers in here
libxfs/xfs_ialloc_btree.c +1 -0
@@ -95,6 +95,7 @@ xfs_inobt_alloc_block(memset (&args,0 ,sizeof (args)); args.tp = cur->bc_tp; args.mp = cur->bc_mp; + args.owner =XFS_RMAP_OWN_INOBT ; args.fsbno =XFS_AGB_TO_FSB (args.mp, cur->bc_private.a.agno, sbno); args.minlen =1 ; args.maxlen =1 ;
libxfs/xfs_rmap.c new file +413 -0
413 lines not on this page · raw message
libxfs/xfs_rmap_btree.c new file +404 -0
404 lines not on this page · raw message
libxfs/xfs_rmap_btree.h new file +65 -0
65 lines not on this page · raw message
libxfs/xfs_sb.c +6 -0
@@ -33,6 +33,7 @@#include "xfs_bmap_btree.h" #include "xfs_alloc_btree.h" #include "xfs_ialloc_btree.h" +#include "xfs_rmap_btree.h" /* * Physical superblock buffer manipulations. Shared with libxfs in userspace.
@@ -711,6 +712,11 @@ xfs_sb_mount_common( mp->m_bmap_dmnr[0 ] = mp->m_bmap_dmxr[0 ] /2 ; mp->m_bmap_dmnr[1 ] = mp->m_bmap_dmxr[1 ] /2 ; + mp->m_rmap_mxr[0 ] =xfs_rmapbt_maxrecs (mp, sbp->sb_blocksize,1 ); + mp->m_rmap_mxr[1 ] =xfs_rmapbt_maxrecs (mp, sbp->sb_blocksize,0 ); + mp->m_rmap_mnr[0 ] = mp->m_rmap_mxr[0 ] /2 ; + mp->m_rmap_mnr[1 ] = mp->m_rmap_mxr[1 ] /2 ; + mp->m_bsize =XFS_FSB_TO_BB (mp,1 ); mp->m_ialloc_inos = (int )MAX ((__uint16_t )XFS_INODES_PER_CHUNK , sbp->sb_inopblock);
libxfs/xfs_shared.h +1 -0
@@ -38,6 +38,7 @@ extern const struct xfs_buf_ops xfs_agi_buf_ops;extern const struct xfs_buf_ops xfs_agf_buf_ops;extern const struct xfs_buf_ops xfs_agfl_buf_ops;extern const struct xfs_buf_ops xfs_allocbt_buf_ops; +extern const struct xfs_buf_ops xfs_rmapbt_buf_ops;extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;extern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;extern const struct xfs_buf_ops xfs_bmbt_buf_ops;
libxfs/xfs_types.h +2 -2
@@ -111,8 +111,8 @@ typedef enum { } xfs_lookup_t;typedef enum { - XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_BMAPi, XFS_BTNUM_INOi, - XFS_BTNUM_FINOi,XFS_BTNUM_MAX + XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi, + XFS_BTNUM_INOi, XFS_BTNUM_FINOi,XFS_BTNUM_MAX }xfs_btnum_t ;struct xfs_name {
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 9/53 libxfs: resync xfs_prealloc_blocks with the kernel
In reply to Darrick J. WongMove xfs_prealloc_blocks() to the same line as in the kernel code.
--- libxfs/xfs_alloc.c | 22 +++++++++++----------- libxfs/xfs_alloc.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-)
libxfs/xfs_alloc.c +11 -11
@@ -46,6 +46,17 @@ STATIC int xfs_alloc_ag_vextent_size(xfs_alloc_arg_t *); STATIC int xfs_alloc_ag_vextent_small(xfs_alloc_arg_t *,xfs_btree_cur_t *,xfs_agblock_t *,xfs_extlen_t *,int *); +xfs_extlen_t +xfs_prealloc_blocks ( +struct xfs_mount *mp) +{ +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) +return XFS_RMAP_BLOCK (mp) +1 ; +if (xfs_sb_version_hasfinobt (&mp->m_sb)) +return XFS_FIBT_BLOCK (mp) +1 ; +return XFS_IBT_BLOCK (mp) +1 ; +} +/* * Lookup the record equal to [bno, len] in the btree given by cur. */
@@ -2715,14 +2726,3 @@ error0:xfs_perag_put (args.pag);return error; } - -xfs_extlen_t -xfs_prealloc_blocks ( -struct xfs_mount *mp) -{ -if (xfs_sb_version_hasrmapbt (&mp->m_sb)) -return XFS_RMAP_BLOCK (mp) +1 ; -if (xfs_sb_version_hasfinobt (&mp->m_sb)) -return XFS_FIBT_BLOCK (mp) +1 ; -return XFS_IBT_BLOCK (mp) +1 ; -}
libxfs/xfs_alloc.h +2 -2
@@ -94,8 +94,6 @@ typedef unsigned int xfs_alloctype_t;#define XFS_ALLOC_AG_MAX_USABLE (mp) \ ((mp)->m_sb.sb_agblocks - XFS_BB_TO_FSB(mp, XFS_FSS_TO_BB(mp, 4)) - 7) -xfs_extlen_t xfs_prealloc_blocks (struct xfs_mount *mp); -/* * Argument structure for xfs_alloc routines. * This is turned into a structure to avoid having 20 arguments passed
@@ -241,4 +239,6 @@ int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp, xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);int xfs_alloc_fix_freelist (struct xfs_alloc_arg *args,int flags); +xfs_extlen_t xfs_prealloc_blocks (struct xfs_mount *mp); +#endif /* __XFS_ALLOC_H__ */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 10/53 xfs: rmap btree transaction reservations
In reply to Darrick J. WongQuoted 1 line
From : Dave Chinner <[email protected]>
The rmap btrees will use the AGFL as the block allocation source, so we need to ensure that the transaction reservations reflect the fact this tree is modified by allocation and freeing. Hence we need to extend all the extent allocation/free reservations used in transactions to handle this.
Note that this also gets rid of the unused XFS_ALLOCFREE_LOG_RES macro, as we now do buffer reservations based on the number of buffers logged via xfs_calc_buf_res(). Hence we only need the buffer count calculation now.
--- libxfs/xfs_trans_resv.c | 56 +++++++++++++++++++++++++++++++++-------------- libxfs/xfs_trans_resv.h | 10 -------- 2 files changed, 39 insertions(+), 27 deletions(-)
libxfs/xfs_trans_resv.c +39 -17
@@ -63,6 +63,28 @@ xfs_calc_buf_res( }/* +* Per-extent log reservation for the allocation btree changes +* involved in freeing or allocating an extent. When rmap is not enabled, +* there are only two trees that will be modified (free space trees), and when +* rmap is enabled there will be three (freespace + rmap trees). The number of +* blocks reserved is based on the formula: +* +* num trees * ((2 blocks/level * max depth) - 1) +*/ +static uint +xfs_allocfree_log_count ( +struct xfs_mount *mp, +uint num_ops) +{ +uint num_trees =2 ; + +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) + num_trees++; + +return num_ops * num_trees * (2 * mp->m_ag_maxlevels -1 ); +} + +/* * Logging inodes is really tricksy. They are logged in memory format, * which means that what we write into the log doesn't directly translate into * the amount of space they use on disk.
@@ -125,7 +147,7 @@ xfs_calc_inode_res(*/ STATIC uintxfs_calc_finobt_res ( -struct xfs_mount *mp, +struct xfs_mount *mp,int alloc,int modify) {
@@ -136,7 +158,7 @@ xfs_calc_finobt_res( res =xfs_calc_buf_res (mp->m_in_maxlevels,XFS_FSB_TO_B (mp,1 ));if (alloc) - res +=xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), + res +=xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 ));if (modify) res += (uint )XFS_FSB_TO_B (mp,1 );
@@ -187,10 +209,10 @@ xfs_calc_write_reservation(xfs_calc_buf_res (XFS_BM_MAXLEVELS (mp,XFS_DATA_FORK ),XFS_FSB_TO_B (mp,1 )) +xfs_calc_buf_res (3 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,2 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,2 ), XFS_FSB_TO_B(mp, 1))), (xfs_calc_buf_res (5 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,2 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,2 ), XFS_FSB_TO_B(mp, 1)))); }
@@ -216,10 +238,10 @@ xfs_calc_itruncate_reservation(xfs_calc_buf_res (XFS_BM_MAXLEVELS (mp,XFS_DATA_FORK ) +1 , XFS_FSB_TO_B(mp, 1))), (xfs_calc_buf_res (9 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,4 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,4 ),XFS_FSB_TO_B (mp,1 )) +xfs_calc_buf_res (5 ,0 ) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 )) +xfs_calc_buf_res (2 + mp->m_ialloc_blks + mp->m_in_maxlevels, 0)));
@@ -246,7 +268,7 @@ xfs_calc_rename_reservation(xfs_calc_buf_res (2 *XFS_DIROP_LOG_COUNT (mp), XFS_FSB_TO_B(mp, 1))), (xfs_calc_buf_res (7 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,3 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,3 ), XFS_FSB_TO_B(mp, 1)))); }
@@ -285,7 +307,7 @@ xfs_calc_link_reservation(xfs_calc_buf_res (XFS_DIROP_LOG_COUNT (mp), XFS_FSB_TO_B(mp, 1))), (xfs_calc_buf_res (3 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ), XFS_FSB_TO_B(mp, 1)))); }
@@ -323,7 +345,7 @@ xfs_calc_remove_reservation(xfs_calc_buf_res (XFS_DIROP_LOG_COUNT (mp), XFS_FSB_TO_B(mp, 1))), (xfs_calc_buf_res (4 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,2 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,2 ), XFS_FSB_TO_B(mp, 1)))); }
@@ -370,7 +392,7 @@ xfs_calc_create_resv_alloc( mp->m_sb.sb_sectsize +xfs_calc_buf_res (mp->m_ialloc_blks,XFS_FSB_TO_B (mp,1 )) +xfs_calc_buf_res (mp->m_in_maxlevels,XFS_FSB_TO_B (mp,1 )) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 )); }
@@ -398,7 +420,7 @@ xfs_calc_icreate_resv_alloc(return xfs_calc_buf_res (2 , mp->m_sb.sb_sectsize) + mp->m_sb.sb_sectsize +xfs_calc_buf_res (mp->m_in_maxlevels,XFS_FSB_TO_B (mp,1 )) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 )) +xfs_calc_finobt_res (mp,0 ,0 ); }
@@ -482,7 +504,7 @@ xfs_calc_ifree_reservation(xfs_calc_buf_res (1 ,0 ) +xfs_calc_buf_res (2 + mp->m_ialloc_blks + mp->m_in_maxlevels,0 ) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 )) +xfs_calc_finobt_res (mp,0 ,1 ); }
@@ -512,7 +534,7 @@ xfs_calc_growdata_reservation( struct xfs_mount *mp) {return xfs_calc_buf_res (3 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 )); }
@@ -534,7 +556,7 @@ xfs_calc_growrtalloc_reservation(xfs_calc_buf_res (XFS_BM_MAXLEVELS (mp,XFS_DATA_FORK ),XFS_FSB_TO_B (mp,1 )) +xfs_calc_inode_res (mp,1 ) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 )); }
@@ -610,7 +632,7 @@ xfs_calc_addafork_reservation(xfs_calc_buf_res (1 , mp->m_dir_geo->blksize) +xfs_calc_buf_res (XFS_DAENTER_BMAP1B (mp,XFS_DATA_FORK ) +1 ,XFS_FSB_TO_B (mp,1 )) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,1 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,1 ),XFS_FSB_TO_B (mp,1 )); }
@@ -633,7 +655,7 @@ xfs_calc_attrinval_reservation(xfs_calc_buf_res (XFS_BM_MAXLEVELS (mp,XFS_ATTR_FORK ), XFS_FSB_TO_B(mp, 1))), (xfs_calc_buf_res (9 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,4 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,4 ), XFS_FSB_TO_B(mp, 1)))); }
@@ -700,7 +722,7 @@ xfs_calc_attrrm_reservation( XFS_BM_MAXLEVELS(mp, XFS_ATTR_FORK)) + xfs_calc_buf_res(XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), 0)), (xfs_calc_buf_res (5 , mp->m_sb.sb_sectsize) + -xfs_calc_buf_res (XFS_ALLOCFREE_LOG_COUNT (mp,2 ), +xfs_calc_buf_res (xfs_allocfree_log_count (mp,2 ), XFS_FSB_TO_B(mp, 1)))); }
libxfs/xfs_trans_resv.h +0 -10
@@ -68,16 +68,6 @@ struct xfs_trans_resv {#define M_RES (mp) (&(mp)->m_resv)/* -* Per-extent log reservation for the allocation btree changes -* involved in freeing or allocating an extent. -* 2 trees * (2 blocks/level * max depth - 1) * block size -*/ -#define XFS_ALLOCFREE_LOG_RES (mp,nx) \ - ((nx) * (2 * XFS_FSB_TO_B((mp), 2 * (mp)->m_ag_maxlevels - 1))) -#define XFS_ALLOCFREE_LOG_COUNT (mp,nx) \ - ((nx) * (2 * (2 * (mp)->m_ag_maxlevels - 1))) - -/* * Per-directory log reservation for any directory change. * dir blocks: (1 btree block per level + data block + free block) * dblock size * bmap btree: (levels + 2) * max depth * block size
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 11/53 xfs: rmap btree requires more reserved free space
In reply to Darrick J. WongQuoted 1 line
From : Dave Chinner <[email protected]>
The rmap btree is allocated from the AGFL, which means we have to ensure ENOSPC is reported to userspace before we run out of free space in each AG. The last allocation in an AG can cause a full height rmap btree split, and that means we have to reserve at least this many blocks *in each AG* to be placed on the AGFL at ENOSPC. Update the various space calculation functiosn to handle this.
Also, because the macros are now executing conditional code and are called quite frequently, convert them to functions that initialise varaibles in the struct xfs_mount, use the new variables everywhere and document the calculations better.
--- include/xfs_mount.h | 2 + libxfs/xfs_alloc.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_alloc.h | 43 ++++---------------------------- libxfs/xfs_bmap.c | 2 + libxfs/xfs_sb.c | 2 + 5 files changed, 79 insertions(+), 39 deletions(-)
include/xfs_mount.h +2 -0
@@ -69,6 +69,8 @@ typedef struct xfs_mount {uint m_ag_maxlevels;/* XFS_AG_MAXLEVELS */ uint m_bm_maxlevels[2 ];/* XFS_BM_MAXLEVELS */ uint m_in_maxlevels;/* XFS_IN_MAXLEVELS */ +uint m_alloc_set_aside;/* space we can't use */ +uint m_ag_max_usable;/* max space per AG */ struct radix_tree_root m_perag_tree;uint m_flags;/* global mount flags */ uint m_qflags;/* quota status flags */
libxfs/xfs_alloc.c +69 -0
81 lines not on this page · raw message
libxfs/xfs_alloc.h +5 -38
55 lines not on this page · raw message
libxfs/xfs_bmap.c +1 -1
@@ -3686,7 +3686,7 @@ xfs_bmap_btalloc( args.fsbno = ap->blkno;/* Trim the allocation back to the maximum an AG can fit. */ - args.maxlen =MIN (ap->length,XFS_ALLOC_AG_MAX_USABLE (mp)); + args.maxlen =MIN (ap->length, mp->m_ag_max_usable); args.firstblock = *ap->firstblock; blen =0 ;if (nullfb) {
libxfs/xfs_sb.c +2 -0
@@ -726,6 +726,8 @@ xfs_sb_mount_common( mp->m_ialloc_min_blks = sbp->sb_spino_align; else mp->m_ialloc_min_blks = mp->m_ialloc_blks; + mp->m_alloc_set_aside =xfs_alloc_set_aside (mp); + mp->m_ag_max_usable =xfs_alloc_ag_max_usable (mp); }/*
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 12/53 libxfs: propagate a bunch of case changes to mkfs and repair
In reply to Darrick J. WongA few macros got replaced with functions, so update mkfs and repair to use the new symbol names. Fix a duplicate #define too.
--- libxfs/xfs_format.h | 12 ------------ mkfs/xfs_mkfs.c | 16 ++++++++-------- 2 files changed, 8 insertions(+), 20 deletions(-)
libxfs/xfs_format.h +0 -12
@@ -1359,24 +1359,12 @@ typedef __be32 xfs_rmap_ptr_t;/* * block numbers in the AG. */ -#define XFS_IBT_BLOCK (mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1)) -#define XFS_FIBT_BLOCK (mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))#define XFS_RMAP_BLOCK (mp) \ (xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \ XFS_FIBT_BLOCK(mp) + 1 : \ XFS_IBT_BLOCK(mp) + 1)/* -* The first data block of an AG depends on whether the filesystem was formatted -* with the optional btree features. These need to be accounted for -* appropriately. -* -* XXX: this should be calculated once at mount time and stored in the struct -* xfs_mount rather than calculated every time it is used. -*/ -#define XFS_PREALLOC_BLOCKS (mp) xfs_prealloc_blocks(mp) - -/* * BMAP Btree format definitions * * This includes both the root block definition that sits inside an inode fork
mkfs/xfs_mkfs.c +8 -8
@@ -2482,7 +2482,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),/* * sb_versionnum and finobt flags must be set before we use -* XFS_PREALLOC_BLOCKS(). +* xfs_prealloc_blocks(). */ sbp->sb_features2 = XFS_SB_VERSION2_MKFS(crcs_enabled, lazy_sb_counters, attrversion == 2, !projid16bit, 0,
@@ -2511,12 +2511,12 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),*/ if (!logsize) { logblocks =MIN (logblocks, -XFS_ALLOC_AG_MAX_USABLE (mp)); +xfs_alloc_ag_max_usable (mp));/* revalidate the log size is valid if we changed it */ validate_log_size (logblocks, blocklog, min_logblocks); } -if (logblocks > agsize -XFS_PREALLOC_BLOCKS (mp)) { +if (logblocks > agsize -xfs_prealloc_blocks (mp)) {fprintf (stderr,_ ("internal log size %lld too large, must fit in allocation group\n" ), (long long )logblocks);
@@ -2533,7 +2533,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), }else logagno = (xfs_agnumber_t)(agcount /2 ); - logstart =XFS_AGB_TO_FSB (mp, logagno,XFS_PREALLOC_BLOCKS (mp)); + logstart =XFS_AGB_TO_FSB (mp, logagno,xfs_prealloc_blocks (mp));/* * Align the logstart at stripe unit boundary. */
@@ -2616,7 +2616,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), sbp->sb_imax_pct = imaxpct; sbp->sb_icount =0 ; sbp->sb_ifree =0 ; - sbp->sb_fdblocks = dblocks - agcount *XFS_PREALLOC_BLOCKS (mp) - + sbp->sb_fdblocks = dblocks - agcount *xfs_prealloc_blocks (mp) - (loginternal ? logblocks :0 ); sbp->sb_frextents =0 ;/* will do a free later */ sbp->sb_uquotino = sbp->sb_gquotino = sbp->sb_pquotino =0 ;
@@ -2767,7 +2767,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), agf->agf_flfirst =0 ; agf->agf_fllast =cpu_to_be32 (XFS_AGFL_SIZE (mp) -1 ); agf->agf_flcount =0 ; - nbmblocks = (xfs_extlen_t)(agsize -XFS_PREALLOC_BLOCKS (mp)); + nbmblocks = (xfs_extlen_t)(agsize -xfs_prealloc_blocks (mp)); agf->agf_freeblks =cpu_to_be32 (nbmblocks); agf->agf_longest =cpu_to_be32 (nbmblocks);if (xfs_sb_version_hascrc (&mp->m_sb))
@@ -2848,7 +2848,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), agno, 0); arec =XFS_ALLOC_REC_ADDR (mp, block,1 ); - arec->ar_startblock =cpu_to_be32 (XFS_PREALLOC_BLOCKS (mp)); + arec->ar_startblock =cpu_to_be32 (xfs_prealloc_blocks (mp));if (loginternal && agno == logagno) {if (lalign) {/*
@@ -2903,7 +2903,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), agno, 0); arec =XFS_ALLOC_REC_ADDR (mp, block,1 ); - arec->ar_startblock =cpu_to_be32 (XFS_PREALLOC_BLOCKS (mp)); + arec->ar_startblock =cpu_to_be32 (xfs_prealloc_blocks (mp));if (loginternal && agno == logagno) {if (lalign) { arec->ar_blockcount = cpu_to_be32(
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 13/53 libxfs: fix min freelist length calculation
In reply to Darrick J. WongIf rmapbt is disabled, it is incorrect to require 1 extra AGFL block for the rmapbt (due to the + 1); the entire clause needs to be gated on the feature flag.
This causes serious problems if formatting a v4 filesystem because the extra AGFL block causes the root inode not to be where xfs_repair expects it. In turn, xfs_repair reports major FS damage when everything is fine.
--- libxfs/xfs_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
libxfs/xfs_alloc.c +4 -2
@@ -1967,8 +1967,10 @@ xfs_alloc_min_freelist( min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_CNTi] + 1, mp->m_ag_maxlevels);/* space needed reverse mapping used space btree */ - min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_RMAPi] + 1, - mp->m_ag_maxlevels); +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) + min_free += min_t(unsigned int, + pag->pagf_levels[XFS_BTNUM_RMAPi] +1 , + mp->m_ag_maxlevels);return min_free; }
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 14/53 libxfs: add the RMAP CRC to the xfs_magics list
In reply to Darrick J. Wong--- libxfs/xfs_btree.c | 7 +++++-- libxfs/xfs_shared.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-)
libxfs/xfs_btree.c +5 -2
@@ -39,9 +39,9 @@ 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 ,0 ,XFS_BMAP_MAGIC ,XFS_IBT_MAGIC ,XFS_FIBT_MAGIC }, - {XFS_ABTB_CRC_MAGIC ,XFS_ABTC_CRC_MAGIC , + {XFS_ABTB_CRC_MAGIC ,XFS_ABTC_CRC_MAGIC ,XFS_RMAP_CRC_MAGIC ,XFS_BMAP_CRC_MAGIC ,XFS_IBT_CRC_MAGIC ,XFS_FIBT_CRC_MAGIC } };#define xfs_btree_magic (cur) \
@@ -1125,6 +1125,9 @@ xfs_btree_set_refs(case XFS_BTNUM_BMAP :xfs_buf_set_ref (bp,XFS_BMAP_BTREE_REF );break ; +case XFS_BTNUM_RMAP : +xfs_buf_set_ref (bp,XFS_RMAP_BTREE_REF ); +break ;default :ASSERT (0 ); }
libxfs/xfs_shared.h +1 -0
@@ -211,6 +211,7 @@ int xfs_log_calc_minimum_size(struct xfs_mount *);#define XFS_INO_BTREE_REF 3#define XFS_ALLOC_BTREE_REF 2#define XFS_BMAP_BTREE_REF 2 +#define XFS_RMAP_BTREE_REF 2#define XFS_DIR_BTREE_REF 2#define XFS_INO_REF 2#define XFS_ATTR_BTREE_REF 1
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 15/53 libxfs: piggyback rmapbt update intents in the bmap free structure
In reply to Darrick J. WongExtend the xfs_bmap_free structure to track a list of rmapbt update intents. In a subsequent patch, we'll defer all data fork rmapbt edits until we're done making changes to the bmbt, at which point we can replay the rmap edits in order of increasing AG number. This enables us to avoid deadlocks by complying with AG lock ordering rules.
--- include/libxfs.h | 3 ++- libxfs/util.c | 9 +++++---- libxfs/xfs_attr.c | 18 +++++++++--------- libxfs/xfs_attr_remote.c | 4 ++-- libxfs/xfs_bmap.c | 4 ++-- libxfs/xfs_bmap.h | 13 ++++++++++++- mkfs/proto.c | 12 ++++++------ repair/phase6.c | 24 ++++++++++++------------ 8 files changed, 50 insertions(+), 37 deletions(-)
include/libxfs.h +2 -1
@@ -165,7 +165,8 @@ extern unsigned int libxfs_log2_roundup(unsigned int i);extern int libxfs_alloc_file_space (struct xfs_inode *,xfs_off_t ,xfs_off_t ,int ,int ); -extern int libxfs_bmap_finish (xfs_trans_t **,xfs_bmap_free_t *,int *); +extern int libxfs_bmap_finish (xfs_trans_t **,xfs_bmap_free_t *,int *, +struct xfs_inode *ip);extern void libxfs_fs_repair_cmn_err (int ,struct xfs_mount *,char *, ...);extern void libxfs_fs_cmn_err (int ,struct xfs_mount *,char *, ...);
libxfs/util.c +5 -4
@@ -491,9 +491,10 @@ libxfs_mod_incore_sb(int libxfs_bmap_finish ( -xfs_trans_t **tp, -xfs_bmap_free_t *flist, -int *committed) +xfs_trans_t **tp, +xfs_bmap_free_t *flist, +int *committed, +struct xfs_inode *ip) {xfs_bmap_free_item_t *free;/* free extent list item */ xfs_bmap_free_item_t *next;/* next item on free list */
@@ -586,7 +587,7 @@ libxfs_alloc_file_space( goto error0;/* complete the transaction */ - error =xfs_bmap_finish (&tp, &free_list, &committed); + error =xfs_bmap_finish (&tp, &free_list, &committed, ip);if (error) goto error0;
libxfs/xfs_attr.c +9 -9
@@ -329,7 +329,7 @@ xfs_attr_set( error =xfs_attr_shortform_to_leaf (&args);if (!error) { error =xfs_bmap_finish (&args.trans, args.flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -623,7 +623,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args) error =xfs_attr3_leaf_to_node (args);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -725,7 +725,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -798,7 +798,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)/* bp is gone due to xfs_da_shrink_inode */ if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -934,7 +934,7 @@ restart:if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -972,7 +972,7 @@ restart: error =xfs_da3_split (state);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -1082,7 +1082,7 @@ restart:if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -1215,7 +1215,7 @@ xfs_attr_node_removename(xfs_da_args_t *args) error =xfs_da3_join (state);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -1261,7 +1261,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
libxfs/xfs_attr_remote.c +2 -2
@@ -464,7 +464,7 @@ xfs_attr_rmtval_set( args->total, &map, &nmap, args->flist);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, dp); }if (error) {ASSERT (committed);
@@ -618,7 +618,7 @@ xfs_attr_rmtval_remove( args->flist, &done);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, - &committed); + &committed, args->dp); }if (error) {ASSERT (committed);
libxfs/xfs_bmap.c +2 -2
@@ -1190,7 +1190,7 @@ xfs_bmap_add_attrfork(xfs_log_sb (tp); } - error =xfs_bmap_finish (&tp, &flist, &committed); + error =xfs_bmap_finish (&tp, &flist, &committed,NULL );if (error) goto bmap_cancel; error =xfs_trans_commit (tp);
@@ -5918,7 +5918,7 @@ xfs_bmap_split_extent(if (error) goto out; - error =xfs_bmap_finish (&tp, &free_list, &committed); + error =xfs_bmap_finish (&tp, &free_list, &committed,NULL );if (error) goto out;
libxfs/xfs_bmap.h +12 -1
@@ -56,6 +56,7 @@ struct xfs_bmalloca {bool aeof;/* allocated space at eof */ bool conv;/* overwriting unwritten extents */ int flags; +struct xfs_rmap_list *rlist; };/*
@@ -69,6 +70,13 @@ typedef struct xfs_bmap_free_itemstruct xfs_bmap_free_item *xbfi_next;/* link to next entry */ } xfs_bmap_free_item_t; +struct xfs_rmap_intent ; + +struct xfs_rmap_list { +struct xfs_rmap_intent *rl_first; +unsigned int rl_count; +}; +/* * Header for free extent list. *
@@ -88,6 +96,7 @@ typedef struct xfs_bmap_freexfs_bmap_free_item_t *xbf_first;/* list of to-be-free extents */ int xbf_count;/* count of items on list */ int xbf_low;/* alloc in low mode */ +struct xfs_rmap_list xbf_rlist;/* rmap intent list */ } xfs_bmap_free_t;#define XFS_BMAP_MAX_NMAP 4
@@ -134,6 +143,8 @@ static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp) { ((flp)->xbf_first =NULL , (flp)->xbf_count =0 , \ (flp)->xbf_low =0 , *(fbp) =NULLFSBLOCK ); + flp->xbf_rlist.rl_first =NULL ; + flp->xbf_rlist.rl_count =0 ; }/*
@@ -186,7 +197,7 @@ void xfs_bmap_add_free(struct xfs_mount *mp, struct xfs_bmap_free *flist, xfs_fsblock_t bno, xfs_filblks_t len);void xfs_bmap_cancel (struct xfs_bmap_free *flist);int xfs_bmap_finish (struct xfs_trans **tp,struct xfs_bmap_free *flist, -int *committed); +int *committed,struct xfs_inode *ip);void xfs_bmap_compute_maxlevels (struct xfs_mount *mp,int whichfork);int xfs_bmap_first_unused (struct xfs_trans *tp,struct xfs_inode *ip,xfs_extlen_t len,xfs_fileoff_t *unused,int whichfork);
mkfs/proto.c +6 -6
@@ -481,7 +481,7 @@ parseproto(newdirent (mp, tp, pip, &xname, ip->i_ino, &first, &flist);libxfs_trans_log_inode (tp, ip, flags); - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);if (error)fail (_ ("Pre-allocated file creation failed" ), error);libxfs_trans_commit (tp);
@@ -563,7 +563,7 @@ parseproto( }newdirectory (mp, tp, ip, pip);libxfs_trans_log_inode (tp, ip, flags); - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);if (error)fail (_ ("Directory creation failed" ), error);libxfs_trans_commit (tp);
@@ -589,7 +589,7 @@ parseproto(fail (_ ("Unknown format" ),EINVAL ); }libxfs_trans_log_inode (tp, ip, flags); - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);if (error) {fail (_ ("Error encountered creating file from prototype file" ), error);
@@ -700,7 +700,7 @@ rtinit( } } - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, rbmip);if (error) {fail (_ ("Completion of the realtime bitmap failed" ), error); }
@@ -735,7 +735,7 @@ rtinit( bno += ep->br_blockcount; } } - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, rsumip);if (error) {fail (_ ("Completion of the realtime summary failed" ), error); }
@@ -759,7 +759,7 @@ rtinit(fail (_ ("Error initializing the realtime space" ), error); } - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, rbmip);if (error) {fail (_ ("Error completing the realtime space" ), error); }
repair/phase6.c +12 -12
@@ -578,7 +578,7 @@ mk_rbmino(xfs_mount_t *mp) bno += ep->br_blockcount; } } - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);if (error) { do_error( _("allocation of the realtime bitmap failed, error = %d\n"),
@@ -843,7 +843,7 @@ mk_rsumino(xfs_mount_t *mp) bno += ep->br_blockcount; } } - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);if (error) { do_error( _("allocation of the realtime summary ino failed, error = %d\n"),
@@ -1059,7 +1059,7 @@ mk_orphanage(xfs_mount_t *mp)libxfs_dir_init (tp, ip, pip);libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, pip);if (error) {do_error (_ ("%s directory creation failed -- bmapf error %d\n" ),ORPHANAGE , error);
@@ -1168,7 +1168,7 @@ mv_orphanage( ino_p->i_d.di_nlink++;libxfs_trans_log_inode (tp, ino_p,XFS_ILOG_CORE ); - err = -libxfs_bmap_finish (&tp, &flist, &committed); + err = -libxfs_bmap_finish (&tp, &flist, &committed, ino_p);if (err) do_error( _("bmap finish failed (err - %d), filesystem may be out of space\n"),
@@ -1215,7 +1215,7 @@ mv_orphanage( err); } - err = -libxfs_bmap_finish (&tp, &flist, &committed); + err = -libxfs_bmap_finish (&tp, &flist, &committed, ino_p);if (err) do_error( _("bmap finish failed (%d), filesystem may be out of space\n"),
@@ -1254,7 +1254,7 @@ mv_orphanage( ino_p->i_d.di_nlink =1 ;libxfs_trans_log_inode (tp, ino_p,XFS_ILOG_CORE ); - err = -libxfs_bmap_finish (&tp, &flist, &committed); + err = -libxfs_bmap_finish (&tp, &flist, &committed, orphanage_ip);if (err) do_error( _("bmap finish failed (%d), filesystem may be out of space\n"),
@@ -1356,7 +1356,7 @@ longform_dir2_rebuild( goto out_bmap_cancel; } - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);libxfs_trans_commit (tp);
@@ -1391,7 +1391,7 @@ _("name create failed in ino %" PRIu64 " (%d), filesystem may be out of space\n" goto out_bmap_cancel; } - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);if (error) { do_warn( _("bmap finish failed (%d), filesystem may be out of space\n"),
@@ -1453,7 +1453,7 @@ dir2_kill_block(if (error)do_error (_ ("shrink_inode failed inode %" PRIu64" block %u\n" ), ip->i_ino, da_bno); -libxfs_bmap_finish (&tp, &flist, &committed); +libxfs_bmap_finish (&tp, &flist, &committed, ip);libxfs_trans_commit (tp); }
@@ -1930,7 +1930,7 @@ _("entry \"%s\" in dir inode %" PRIu64 " inconsistent with .. value (%" PRIu64 "libxfs_dir2_data_freescan (mp->m_dir_geo,M_DIROPS (mp), d, &i);if (needlog)libxfs_dir2_data_log_header (&da, bp); -libxfs_bmap_finish (&tp, &flist, &committed); +libxfs_bmap_finish (&tp, &flist, &committed, ip);libxfs_trans_commit (tp);/* record the largest free space in the freetab for later checking */
@@ -2996,7 +2996,7 @@ process_dir_inode(libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);ASSERT (error ==0 );libxfs_trans_commit (tp);
@@ -3057,7 +3057,7 @@ process_dir_inode(libxfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); - error = -libxfs_bmap_finish (&tp, &flist, &committed); + error = -libxfs_bmap_finish (&tp, &flist, &committed, ip);ASSERT (error ==0 );libxfs_trans_commit (tp); }
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 16/53 libxfs: enhance rmapbt definition to support reflink
In reply to Darrick J. WongEnlarge the rmapbt records to support reflink operation.
--- include/xfs_trace.h | 12 + libxfs/util.c | 13 - libxfs/xfs_alloc.c | 48 +- libxfs/xfs_alloc.h | 5 libxfs/xfs_bmap.c | 200 ++++++++- libxfs/xfs_bmap.h | 4 libxfs/xfs_bmap_btree.c | 7 libxfs/xfs_format.h | 122 +++++ libxfs/xfs_ialloc.c | 8 libxfs/xfs_ialloc_btree.c | 6 libxfs/xfs_rmap.c | 1013 +++++++++++++++++++++++++++++++++++++++++---- libxfs/xfs_rmap_btree.c | 86 ++-- libxfs/xfs_rmap_btree.h | 78 +++ 13 files changed, 1434 insertions(+), 168 deletions(-)
include/xfs_trace.h +12 -0
@@ -178,4 +178,16 @@#define trace_xfs_rmap_free_extent_done (a,b,c,d,e) ((void) 0)#define trace_xfs_rmap_free_extent_error (a,b,c,d,e) ((void) 0) +#define trace_xfs_rmapbt_delete(a...) ((void) 0) +#define trace_xfs_rmapbt_insert(a...) ((void) 0) +#define trace_xfs_rmap_insert(a...) ((void) 0) +#define trace_xfs_rmap_delete(a...) ((void) 0) +#define trace_xfs_rmap_move(a...) ((void) 0) +#define trace_xfs_rmap_slide(a...) ((void) 0) +#define trace_xfs_rmap_resize(a...) ((void) 0) +#define trace_xfs_rmapbt_update(a...) ((void) 0) +#define trace_xfs_rmap_combine(a...) ((void) 0) +#define trace_xfs_rmap_lcombine(a...) ((void) 0) +#define trace_xfs_rmap_rcombine(a...) ((void) 0) +#endif /* __TRACE_H__ */
libxfs/util.c +9 -4
@@ -33,6 +33,7 @@#include "xfs_trans_space.h" #include "xfs_ialloc.h" #include "xfs_alloc.h" +#include "xfs_rmap_btree.h" /* * Calculate the worst case log unit reservation for a given superblock
@@ -500,15 +501,19 @@ libxfs_bmap_finish(xfs_bmap_free_item_t *next;/* next item on free list */ int error; -if (flist->xbf_count ==0 ) { - *committed =0 ; + *committed =0 ; + error =xfs_rmap_finish ((*tp)->t_mountp, tp, ip, &flist->xbf_rlist, + committed); +if (error) +return error; + +if (flist->xbf_count ==0 )return 0 ; - }for (free = flist->xbf_first; free !=NULL ; free = next) { next = free->xbfi_next;if ((error =xfs_free_extent (*tp, free->xbfi_startblock, - free->xbfi_blockcount))) + free->xbfi_blockcount, &free->xbfi_oinfo)))return error;xfs_bmap_del_free (flist,NULL , free); }
libxfs/xfs_alloc.c +30 -18
118 lines not on this page · raw message
libxfs/xfs_alloc.h +3 -2
@@ -87,7 +87,7 @@ typedef struct xfs_alloc_arg {char isfl;/* set if is freelist blocks - !acctg */ char userdata;/* set if this is user data */ xfs_fsblock_t firstblock;/* io first block allocated */ -uint64_t owner;/* owner of blocks being allocated */ +struct xfs_owner_info oinfo;/* owner of blocks being allocated */ } xfs_alloc_arg_t;/*
@@ -179,7 +179,8 @@ int /* error */xfs_free_extent ( struct xfs_trans *tp, /* transaction pointer */ xfs_fsblock_t bno, /* starting block number of extent */ - xfs_extlen_t len); /* length of extent */ + xfs_extlen_t len, /* length of extent */ + struct xfs_owner_info *oinfo); /* extent owner */int /* error */ xfs_alloc_lookup_le(
libxfs/xfs_bmap.c +189 -11
517 lines not on this page · raw message
libxfs/xfs_bmap.h +3 -1
@@ -67,6 +67,7 @@ typedef struct xfs_bmap_free_item {xfs_fsblock_t xbfi_startblock;/* starting fs block number */ xfs_extlen_t xbfi_blockcount;/* number of blocks in extent */ +struct xfs_owner_info xbfi_oinfo;/* extent owner */ struct xfs_bmap_free_item *xbfi_next;/* link to next entry */ } xfs_bmap_free_item_t;
@@ -194,7 +195,8 @@ void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt,int xfs_bmap_add_attrfork (struct xfs_inode *ip,int size,int rsvd);void xfs_bmap_local_to_extents_empty (struct xfs_inode *ip,int whichfork);void xfs_bmap_add_free (struct xfs_mount *mp,struct xfs_bmap_free *flist, -xfs_fsblock_t bno,xfs_filblks_t len); +xfs_fsblock_t bno,xfs_filblks_t len, +struct xfs_owner_info *oinfo);void xfs_bmap_cancel (struct xfs_bmap_free *flist);int xfs_bmap_finish (struct xfs_trans **tp,struct xfs_bmap_free *flist,int *committed,struct xfs_inode *ip);
libxfs/xfs_bmap_btree.c +5 -2
@@ -443,7 +443,8 @@ xfs_bmbt_alloc_block( args.mp = cur->bc_mp; args.fsbno = cur->bc_private.b.firstblock; args.firstblock = args.fsbno; - args.owner = cur->bc_private.b.ip->i_ino; +XFS_RMAP_INO_BMBT_OWNER (&args.oinfo, cur->bc_private.b.ip->i_ino, + cur->bc_private.b.whichfork);if (args.fsbno ==NULLFSBLOCK ) { args.fsbno =be64_to_cpu (start->l);
@@ -523,8 +524,10 @@ xfs_bmbt_free_block(struct xfs_inode *ip = cur->bc_private.b.ip;struct xfs_trans *tp = cur->bc_tp;xfs_fsblock_t fsbno =XFS_DADDR_TO_FSB (mp,XFS_BUF_ADDR (bp)); +struct xfs_owner_info oinfo; -xfs_bmap_add_free (mp, cur->bc_private.b.flist, fsbno,1 ); +XFS_RMAP_INO_BMBT_OWNER (&oinfo, ip->i_ino, cur->bc_private.b.whichfork); +xfs_bmap_add_free (mp, cur->bc_private.b.flist, fsbno,1 , &oinfo); ip->i_d.di_nblocks--;xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE );
libxfs/xfs_format.h +118 -4
161 lines not on this page · raw message
libxfs/xfs_ialloc.c +5 -3
@@ -608,6 +608,7 @@ xfs_ialloc_ag_alloc( args.tp = tp; args.mp = tp->t_mountp; args.fsbno =NULLFSBLOCK ; +XFS_RMAP_AG_OWNER (&args.oinfo,XFS_RMAP_OWN_INODES );#ifdef DEBUG /* randomly do sparse inode allocations */
@@ -615,7 +616,6 @@ xfs_ialloc_ag_alloc( args.mp->m_ialloc_min_blks < args.mp->m_ialloc_blks) do_sparse =prandom_u32 () &1 ;#endif - args.owner =XFS_RMAP_OWN_INODES ;/* * Locking will ensure that we don't have two callers in here
@@ -1819,13 +1819,15 @@ xfs_difree_inode_chunk(int nextbit;xfs_agblock_t agbno;int contigblk; +struct xfs_owner_info oinfo;DECLARE_BITMAP (holemask,XFS_INOBT_HOLEMASK_BITS ); +XFS_RMAP_AG_OWNER (&oinfo,XFS_RMAP_OWN_INODES );if (!xfs_inobt_issparse (rec->ir_holemask)) {/* not sparse, calculate extent info directly */ xfs_bmap_add_free (mp, flist,XFS_AGB_TO_FSB (mp, agno,XFS_AGINO_TO_AGBNO (mp, rec->ir_startino)), - mp->m_ialloc_blks); + mp->m_ialloc_blks, &oinfo);return ; }
@@ -1869,7 +1871,7 @@ xfs_difree_inode_chunk(ASSERT (agbno % mp->m_sb.sb_spino_align ==0 );ASSERT (contigblk % mp->m_sb.sb_spino_align ==0 );xfs_bmap_add_free (mp, flist,XFS_AGB_TO_FSB (mp, agno, agbno), - contigblk); + contigblk, &oinfo);/* reset range to current bit and carry on... */ startidx = endidx = nextbit;
libxfs/xfs_ialloc_btree.c +4 -2
@@ -95,7 +95,7 @@ xfs_inobt_alloc_block(memset (&args,0 ,sizeof (args)); args.tp = cur->bc_tp; args.mp = cur->bc_mp; - args.owner =XFS_RMAP_OWN_INOBT ; +XFS_RMAP_AG_OWNER (&args.oinfo,XFS_RMAP_OWN_INOBT ); args.fsbno =XFS_AGB_TO_FSB (args.mp, cur->bc_private.a.agno, sbno); args.minlen =1 ; args.maxlen =1 ;
@@ -127,9 +127,11 @@ xfs_inobt_free_block( {xfs_fsblock_t fsbno;int error; +struct xfs_owner_info oinfo; +XFS_RMAP_AG_OWNER (&oinfo,XFS_RMAP_OWN_INOBT ); fsbno =XFS_DADDR_TO_FSB (cur->bc_mp,XFS_BUF_ADDR (bp)); - error =xfs_free_extent (cur->bc_tp, fsbno,1 ); + error =xfs_free_extent (cur->bc_tp, fsbno,1 , &oinfo);if (error)return error;
libxfs/xfs_rmap.c +931 -82
1,225 lines not on this page · raw message
libxfs/xfs_rmap_btree.c +53 -33
151 lines not on this page · raw message
libxfs/xfs_rmap_btree.h +72 -6
96 lines not on this page · raw message
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 17/53 libxfs: refactor short btree block verification
In reply to Darrick J. WongCreate xfs_btree_sblock_verify() to verify short-format btree blocks (i.e. the per-AG btrees with 32-bit block pointers) instead of open-coding them.
--- libxfs/xfs_alloc_btree.c | 30 ++--------------------- libxfs/xfs_btree.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_btree.h | 3 ++ libxfs/xfs_ialloc_btree.c | 24 ++----------------- libxfs/xfs_rmap_btree.c | 23 ++---------------- 5 files changed, 70 insertions(+), 68 deletions(-)
libxfs/xfs_alloc_btree.c +3 -27
@@ -293,12 +293,7 @@ xfs_allocbt_verify(case cpu_to_be32 (XFS_ABTB_CRC_MAGIC ):if (!xfs_sb_version_hascrc (&mp->m_sb))return false; -if (!uuid_equal (&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) -return false; -if (block->bb_u.s.bb_blkno !=cpu_to_be64 (bp->b_bn)) -return false; -if (pag && -be32_to_cpu (block->bb_u.s.bb_owner) != pag->pag_agno) +if (!xfs_btree_sblock_v5hdr_verify (bp))return false;/* fall through */ case cpu_to_be32 (XFS_ABTB_MAGIC ):
@@ -311,12 +306,7 @@ xfs_allocbt_verify(case cpu_to_be32 (XFS_ABTC_CRC_MAGIC ):if (!xfs_sb_version_hascrc (&mp->m_sb))return false; -if (!uuid_equal (&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) -return false; -if (block->bb_u.s.bb_blkno !=cpu_to_be64 (bp->b_bn)) -return false; -if (pag && -be32_to_cpu (block->bb_u.s.bb_owner) != pag->pag_agno) +if (!xfs_btree_sblock_v5hdr_verify (bp))return false;/* fall through */ case cpu_to_be32 (XFS_ABTC_MAGIC ):
@@ -330,21 +320,7 @@ xfs_allocbt_verify(return false; } -/* numrecs verification */ -if (be16_to_cpu (block->bb_numrecs) > mp->m_alloc_mxr[level !=0 ]) -return false; - -/* sibling pointer verification */ -if (!block->bb_u.s.bb_leftsib || - (be32_to_cpu (block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks && - block->bb_u.s.bb_leftsib !=cpu_to_be32 (NULLAGBLOCK ))) -return false; -if (!block->bb_u.s.bb_rightsib || - (be32_to_cpu (block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks && - block->bb_u.s.bb_rightsib !=cpu_to_be32 (NULLAGBLOCK ))) -return false; - -return true; +return xfs_btree_sblock_verify (bp, mp->m_alloc_mxr[level !=0 ]); } static void
libxfs/xfs_btree.c +58 -0
61 lines not on this page · raw message
libxfs/xfs_btree.h +3 -0
@@ -471,4 +471,7 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block)#define XFS_BTREE_TRACE_ARGR (c, r)#define XFS_BTREE_TRACE_CURSOR (c, t) +bool xfs_btree_sblock_v5hdr_verify (struct xfs_buf *bp); +bool xfs_btree_sblock_verify (struct xfs_buf *bp,unsigned int max_recs); +#endif /* __XFS_BTREE_H__ */
libxfs/xfs_ialloc_btree.c +3 -21
@@ -223,7 +223,6 @@ xfs_inobt_verify( {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); -struct xfs_perag *pag = bp->b_pag;unsigned int level;/*
@@ -241,12 +240,7 @@ xfs_inobt_verify(case cpu_to_be32 (XFS_FIBT_CRC_MAGIC ):if (!xfs_sb_version_hascrc (&mp->m_sb))return false; -if (!uuid_equal (&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) -return false; -if (block->bb_u.s.bb_blkno !=cpu_to_be64 (bp->b_bn)) -return false; -if (pag && -be32_to_cpu (block->bb_u.s.bb_owner) != pag->pag_agno) +if (!xfs_btree_sblock_v5hdr_verify (bp))return false;/* fall through */ case cpu_to_be32 (XFS_IBT_MAGIC ):
@@ -256,24 +250,12 @@ xfs_inobt_verify(return 0 ; } -/* numrecs and level verification */ +/* level verification */ level =be16_to_cpu (block->bb_level);if (level >= mp->m_in_maxlevels)return false; -if (be16_to_cpu (block->bb_numrecs) > mp->m_inobt_mxr[level !=0 ]) -return false; - -/* sibling pointer verification */ -if (!block->bb_u.s.bb_leftsib || - (be32_to_cpu (block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks && - block->bb_u.s.bb_leftsib !=cpu_to_be32 (NULLAGBLOCK ))) -return false; -if (!block->bb_u.s.bb_rightsib || - (be32_to_cpu (block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks && - block->bb_u.s.bb_rightsib !=cpu_to_be32 (NULLAGBLOCK ))) -return false; -return true; +return xfs_btree_sblock_verify (bp, mp->m_inobt_mxr[level !=0 ]); } static void
libxfs/xfs_rmap_btree.c +3 -20
@@ -252,13 +252,10 @@ xfs_rmapbt_verify(if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return false; -if (!uuid_equal (&block->bb_u.s.bb_uuid, &mp->m_sb.sb_uuid)) -return false; -if (block->bb_u.s.bb_blkno !=cpu_to_be64 (bp->b_bn)) -return false; -if (pag &&be32_to_cpu (block->bb_u.s.bb_owner) != pag->pag_agno) +if (!xfs_btree_sblock_v5hdr_verify (bp))return false; +/* level verification */ level =be16_to_cpu (block->bb_level);if (pag && pag->pagf_init) {if (level >= pag->pagf_levels[XFS_BTNUM_RMAPi])
@@ -266,21 +263,7 @@ xfs_rmapbt_verify( }else if (level >= mp->m_ag_maxlevels)return false; -/* numrecs verification */ -if (be16_to_cpu (block->bb_numrecs) > mp->m_rmap_mxr[level !=0 ]) -return false; - -/* sibling pointer verification */ -if (!block->bb_u.s.bb_leftsib || - (be32_to_cpu (block->bb_u.s.bb_leftsib) >= mp->m_sb.sb_agblocks && - block->bb_u.s.bb_leftsib !=cpu_to_be32 (NULLAGBLOCK ))) -return false; -if (!block->bb_u.s.bb_rightsib || - (be32_to_cpu (block->bb_u.s.bb_rightsib) >= mp->m_sb.sb_agblocks && - block->bb_u.s.bb_rightsib !=cpu_to_be32 (NULLAGBLOCK ))) -return false; - -return true; +return xfs_btree_sblock_verify (bp, mp->m_rmap_mxr[level !=0 ]); } static void
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 18/53 xfs: don't update rmapbt when fixing agfl
In reply to Darrick J. WongAllow a caller of xfs_alloc_fix_freelist to disable rmapbt updates when fixing the AG freelist. xfs_repair needs this during phase 5 to be able to adjust the freelist while it's reconstructing the rmap btree; the missing entries will be added back at the very end of phase 5 once the AGFL contents settle down.
--- libxfs/xfs_alloc.c | 40 ++++++++++++++++++++++++++-------------- libxfs/xfs_alloc.h | 2 ++ 2 files changed, 28 insertions(+), 14 deletions(-)
libxfs/xfs_alloc.c +26 -14
@@ -2098,26 +2098,38 @@ xfs_alloc_fix_freelist(* anything other than extra overhead when we need to put more blocks * back on the free list? Maybe we should only do this when space is * getting low or the AGFL is more than half full? +* +* The NOSHRINK flag prevents the AGFL from being shrunk if it's too +* big; the NORMAP flag prevents AGFL expand/shrink operations from +* updating the rmapbt. Both flags are used in xfs_repair while we're +* rebuilding the rmapbt, and neither are used by the kernel. They're +* both required to ensure that rmaps are correctly recorded for the +* regenerated AGFL, bnobt, and cntbt. See repair/phase5.c and +* repair/rmap.c in xfsprogs for details. */ -XFS_RMAP_AG_OWNER (&targs.oinfo,XFS_RMAP_OWN_AG ); -while (pag->pagf_flcount > need) { -struct xfs_buf *bp; +memset (&targs,0 ,sizeof (targs)); +if (!(flags &XFS_ALLOC_FLAG_NOSHRINK )) { +if (!(flags &XFS_ALLOC_FLAG_NORMAP )) +XFS_RMAP_AG_OWNER (&targs.oinfo,XFS_RMAP_OWN_AG ); +while (pag->pagf_flcount > need) { +struct xfs_buf *bp; - error =xfs_alloc_get_freelist (tp, agbp, &bno,0 ); -if (error) - goto out_agbp_relse; - error =xfs_free_ag_extent (tp, agbp, args->agno, bno,1 , - &targs.oinfo,1 ); -if (error) - goto out_agbp_relse; - bp =xfs_btree_get_bufs (mp, tp, args->agno, bno,0 ); -xfs_trans_binval (tp, bp); + error =xfs_alloc_get_freelist (tp, agbp, &bno,0 ); +if (error) + goto out_agbp_relse; + error =xfs_free_ag_extent (tp, agbp, args->agno, bno,1 , + &targs.oinfo,1 ); +if (error) + goto out_agbp_relse; + bp =xfs_btree_get_bufs (mp, tp, args->agno, bno,0 ); +xfs_trans_binval (tp, bp); + } } -memset (&targs,0 ,sizeof (targs)); targs.tp = tp; targs.mp = mp; -XFS_RMAP_AG_OWNER (&targs.oinfo,XFS_RMAP_OWN_AG ); +if (!(flags &XFS_ALLOC_FLAG_NORMAP )) +XFS_RMAP_AG_OWNER (&targs.oinfo,XFS_RMAP_OWN_AG ); targs.agbp = agbp; targs.agno = args->agno; targs.alignment = targs.minlen = targs.prod = targs.isfl =1 ;
libxfs/xfs_alloc.h +2 -0
@@ -54,6 +54,8 @@ typedef unsigned int xfs_alloctype_t;*/ #define XFS_ALLOC_FLAG_TRYLOCK 0x00000001/* use trylock for buffer locking */ #define XFS_ALLOC_FLAG_FREEING 0x00000002/* indicate caller is freeing extents*/ +#define XFS_ALLOC_FLAG_NORMAP 0x00000004/* don't modify the rmapbt */ +#define XFS_ALLOC_FLAG_NOSHRINK 0x00000008/* don't shrink the freelist */ /*
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 19/53 libxfs: implement XFS_IOC_SWAPEXT when rmap btree is enabled
In reply to Darrick J. WongSynchronize the libxfs components of the kernel patch. No code in xfsprogs actually calls this.
--- libxfs/xfs_btree.c | 17 +++++++++ libxfs/xfs_rmap.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_rmap_btree.h | 9 +++++ 3 files changed, 116 insertions(+)
libxfs/xfs_btree.c +17 -0
@@ -29,6 +29,7 @@#include "xfs_trace.h" #include "xfs_cksum.h" #include "xfs_alloc.h" +#include "xfs_rmap_btree.h" /* * Cursor allocation zone.
@@ -4001,6 +4002,8 @@ xfs_btree_block_change_owner(struct xfs_btree_block *block;struct xfs_buf *bp;union xfs_btree_ptr rptr; +struct xfs_owner_info old_oinfo, new_oinfo; +int error;/* do right sibling readahead */ xfs_btree_readahead (cur, level,XFS_BTCUR_RIGHTRA );
@@ -4012,6 +4015,20 @@ xfs_btree_block_change_owner(else block->bb_u.s.bb_owner =cpu_to_be32 (new_owner); +/* change rmap owners (bmbt blocks only) */ +if (cur->bc_flags &XFS_BTREE_LONG_PTRS ) { +XFS_RMAP_INO_BMBT_OWNER (&old_oinfo, + cur->bc_private.b.ip->i_ino, + cur->bc_private.b.whichfork); +XFS_RMAP_INO_BMBT_OWNER (&new_oinfo, + new_owner, + cur->bc_private.b.whichfork); + error =xfs_rmap_change_bmbt_owner (cur, bp, &old_oinfo, + &new_oinfo); +if (error) +return error; + } +/* * If the block is a root block hosted in an inode, we might not have a * buffer pointer here and we shouldn't attempt to log the change as the
libxfs/xfs_rmap.c +90 -0
93 lines not on this page · raw message
libxfs/xfs_rmap_btree.h +9 -0
@@ -128,4 +128,13 @@ int xfs_rmap_finish(struct xfs_mount *mp, struct xfs_trans **tpp, struct xfs_inode *ip, struct xfs_rmap_list *rlist, int *committed); +/* functions for changing rmap ownership */ +int xfs_rmap_change_extent_owner (struct xfs_mount *mp,struct xfs_inode *ip, +xfs_ino_t ino,xfs_fileoff_t isize,struct xfs_trans *tp, +int whichfork,xfs_ino_t new_owner, +struct xfs_rmap_list *rlist); +int xfs_rmap_change_bmbt_owner (struct xfs_btree_cur *bcur,struct xfs_buf *bp, +struct xfs_owner_info *old_owner, +struct xfs_owner_info *new_owner); +#endif /* __XFS_RMAP_BTREE_H__ */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 20/53 xfs_db: display rmap btree contents
In reply to Darrick J. WongQuoted 1 line
From : Dave Chinner <[email protected]>
Teach the debugger how to dump the reverse-mapping btree contents.
--- db/agf.c | 6 ++++++ db/btblock.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ db/btblock.h | 5 +++++ db/field.c | 9 +++++++++ db/field.h | 4 ++++ db/type.c | 3 +++ db/type.h | 2 +- 7 files changed, 78 insertions(+), 1 deletion(-)
db/agf.c +6 -0
@@ -55,6 +55,9 @@ const field_t agf_flds[] = { {"cntroot" ,FLDT_AGBLOCK ,OI (OFF (roots) +XFS_BTNUM_CNT *SZ (roots[XFS_BTNUM_CNT ])),C1 ,0 , TYP_CNTBT }, + { "rmaproot", FLDT_AGBLOCK, +OI (OFF (roots) +XFS_BTNUM_RMAP *SZ (roots[XFS_BTNUM_RMAP ])),C1 ,0 , + TYP_RMAPBT }, { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF), FLD_ARRAY|FLD_SKIPALL, TYP_NONE }, { "bnolevel", FLDT_UINT32D,
@@ -63,6 +66,9 @@ const field_t agf_flds[] = { {"cntlevel" ,FLDT_UINT32D ,OI (OFF (levels) +XFS_BTNUM_CNT *SZ (levels[XFS_BTNUM_CNT ])),C1 ,0 , TYP_NONE }, + { "rmaplevel", FLDT_UINT32D, +OI (OFF (levels) +XFS_BTNUM_RMAP *SZ (levels[XFS_BTNUM_RMAP ])),C1 ,0 , + TYP_NONE }, { "flfirst", FLDT_UINT32D, OI(OFF(flfirst)), C1, 0, TYP_NONE }, { "fllast", FLDT_UINT32D, OI(OFF(fllast)), C1, 0, TYP_NONE }, { "flcount", FLDT_UINT32D, OI(OFF(flcount)), C1, 0, TYP_NONE },
db/btblock.c +50 -0
59 lines not on this page · raw message
db/btblock.h +5 -0
@@ -54,4 +54,9 @@ extern const struct field cntbt_crc_hfld[];extern const struct field cntbt_key_flds[];extern const struct field cntbt_rec_flds[]; +extern const struct field rmapbt_crc_flds[]; +extern const struct field rmapbt_crc_hfld[]; +extern const struct field rmapbt_key_flds[]; +extern const struct field rmapbt_rec_flds[]; +extern int btblock_size (void *obj,int startoff,int idx);
db/field.c +9 -0
@@ -164,6 +164,15 @@ const ftattr_t ftattrtab[] = { {FLDT_CNTBTREC ,"cntbtrec" , fp_sarray, (char *)cntbt_rec_flds, SI(bitsz(xfs_alloc_rec_t)), 0, NULL, cntbt_rec_flds }, + { FLDT_RMAPBT_CRC, "rmapbt", NULL, (char *)rmapbt_crc_flds, btblock_size, + FTARG_SIZE, NULL, rmapbt_crc_flds }, + { FLDT_RMAPBTKEY, "rmapbtkey", fp_sarray, (char *)rmapbt_key_flds, + SI(bitsz(struct xfs_rmap_key)), 0, NULL, rmapbt_key_flds }, + { FLDT_RMAPBTPTR, "rmapbtptr", fp_num, "%u", + SI(bitsz(xfs_rmap_ptr_t)), 0, fa_agblock, NULL }, + { FLDT_RMAPBTREC, "rmapbtrec", fp_sarray, (char *)rmapbt_rec_flds, + SI(bitsz(struct xfs_rmap_rec)), 0, NULL, rmapbt_rec_flds }, +/* CRC field */ { FLDT_CRC, "crc", fp_crc, "%#x (%s)", SI(bitsz(__uint32_t)), 0, NULL, NULL },
db/field.h +4 -0
@@ -80,6 +80,10 @@ typedef enum fldt {FLDT_CNTBTKEY ,FLDT_CNTBTPTR ,FLDT_CNTBTREC , +FLDT_RMAPBT_CRC , +FLDT_RMAPBTKEY , +FLDT_RMAPBTPTR , +FLDT_RMAPBTREC ,/* CRC field type */ FLDT_CRC,
db/type.c +3 -0
@@ -58,6 +58,7 @@ static const typ_t __typtab[] = { { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_hfld, NULL }, { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld, NULL }, { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld, NULL }, + { TYP_RMAPBT, NULL }, { TYP_DATA, "data", handle_block, NULL, NULL }, { TYP_DIR2, "dir2", handle_struct, dir2_hfld, NULL }, { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, NULL },
@@ -88,6 +89,8 @@ static const typ_t __typtab_crc[] = { &xfs_allocbt_buf_ops }, {TYP_CNTBT ,"cntbt" , handle_struct, cntbt_crc_hfld, &xfs_allocbt_buf_ops }, + { TYP_RMAPBT, "rmapbt", handle_struct, rmapbt_crc_hfld, + &xfs_rmapbt_buf_ops }, { TYP_DATA, "data", handle_block, NULL, NULL }, { TYP_DIR2, "dir3", handle_struct, dir3_hfld, &xfs_dir3_db_buf_ops },
db/type.h +1 -1
@@ -24,7 +24,7 @@ struct field; typedef enum typnm { TYP_AGF, TYP_AGFL, TYP_AGI, TYP_ATTR, TYP_BMAPBTA, - TYP_BMAPBTD, TYP_BNOBT, TYP_CNTBT, TYP_DATA, + TYP_BMAPBTD, TYP_BNOBT, TYP_CNTBT, TYP_RMAPBT, TYP_DATA, TYP_DIR2, TYP_DQBLK, TYP_INOBT, TYP_INODATA, TYP_INODE, TYP_LOG, TYP_RTBITMAP, TYP_RTSUMMARY, TYP_SB, TYP_SYMLINK, TYP_TEXT, TYP_FINOBT, TYP_NONE
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 21/53 xfs_dump: display enhanced rmapbt fields
In reply to Darrick J. WongDecode the extra fields in the rmapbt records.
--- db/agf.c | 2 +- db/btblock.c | 24 +++++++++++++++++++++--- db/field.c | 10 ++++++++++ db/field.h | 5 +++++ db/type.c | 2 ++ 5 files changed, 39 insertions(+), 4 deletions(-)
db/agf.c +1 -1
@@ -55,7 +55,7 @@ const field_t agf_flds[] = { {"cntroot" ,FLDT_AGBLOCK ,OI (OFF (roots) +XFS_BTNUM_CNT *SZ (roots[XFS_BTNUM_CNT ])),C1 ,0 , TYP_CNTBT }, - { "rmaproot", FLDT_AGBLOCK, + { "rmaproot", FLDT_AGBLOCKNZ,OI (OFF (roots) +XFS_BTNUM_RMAP *SZ (roots[XFS_BTNUM_RMAP ])),C1 ,0 , TYP_RMAPBT }, { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF),
db/btblock.c +21 -3
@@ -645,15 +645,33 @@ const field_t rmapbt_crc_flds[] = {#define KOFF (f) bitize(offsetof(struct xfs_rmap_key, rm_ ## f))const field_t rmapbt_key_flds[] = { {"startblock" ,FLDT_AGBLOCK ,OI (KOFF (startblock)),C1 ,0 ,TYP_DATA }, + {"owner" ,FLDT_INT64D ,OI (KOFF (owner)),C1 ,0 ,TYP_NONE }, + {"offset" ,FLDT_CFILEOFFD ,OI (KOFF (offset)),C1 ,0 ,TYP_NONE }, {NULL } };#undef KOFF#define ROFF (f) bitize(offsetof(struct xfs_rmap_rec, rm_ ## f)) + +#define RMAPBT_STARTBLOCK_BITOFF 0 +#define RMAPBT_EXNTFLAG_BITOFF (RMAPBT_STARTBLOCK_BITOFF + RMAPBT_STARTBLOCK_BITLEN) +#define RMAPBT_BLOCKCOUNT_BITOFF (RMAPBT_EXNTFLAG_BITOFF + RMAPBT_EXNTFLAG_BITLEN) +#define RMAPBT_OWNER_BITOFF (RMAPBT_BLOCKCOUNT_BITOFF + RMAPBT_BLOCKCOUNT_BITLEN) +#define RMAPBT_ATTRFLAG_BITOFF (RMAPBT_OWNER_BITOFF + RMAPBT_OWNER_BITLEN) +#define RMAPBT_BMBTFLAG_BITOFF (RMAPBT_ATTRFLAG_BITOFF + RMAPBT_ATTRFLAG_BITLEN) +#define RMAPBT_OFFSET_BITOFF (RMAPBT_BMBTFLAG_BITOFF + RMAPBT_BMBTFLAG_BITLEN) +const field_t rmapbt_rec_flds[] = { - {"startblock" ,FLDT_AGBLOCK ,OI (ROFF (startblock)),C1 ,0 ,TYP_DATA }, - {"blockcount" ,FLDT_EXTLEN ,OI (ROFF (blockcount)),C1 ,0 ,TYP_NONE }, - {"owner" ,FLDT_UINT64X ,OI (ROFF (owner)),C1 ,0 ,TYP_NONE }, + {"startblock" ,FLDT_AGBLOCK ,OI (RMAPBT_STARTBLOCK_BITOFF ),C1 ,0 ,TYP_DATA }, + {"blockcount" ,FLDT_REXTLEN ,OI (RMAPBT_BLOCKCOUNT_BITOFF ),C1 ,0 ,TYP_NONE }, + {"owner" ,FLDT_INT64D ,OI (RMAPBT_OWNER_BITOFF ),C1 ,0 ,TYP_NONE }, + {"offset" ,FLDT_RFILEOFFD ,OI (RMAPBT_OFFSET_BITOFF ),C1 ,0 ,TYP_NONE }, + {"extentflag" ,FLDT_REXTFLG ,OI (RMAPBT_EXNTFLAG_BITOFF ),C1 ,0 , +TYP_NONE }, + {"attrfork" ,FLDT_RATTRFORKFLG ,OI (RMAPBT_ATTRFLAG_BITOFF ),C1 ,0 , +TYP_NONE }, + {"bmbtblock" ,FLDT_RBMBTFLG ,OI (RMAPBT_BMBTFLAG_BITOFF ),C1 ,0 , +TYP_NONE }, {NULL } };#undef ROFF
db/field.c +10 -0
@@ -153,6 +153,16 @@ const ftattr_t ftattrtab[] = { {FLDT_CHARNS ,"charns" , fp_charns,NULL ,SI (bitsz (char)),0 ,NULL , NULL }, { FLDT_CHARS, "chars", fp_num, "%c", SI(bitsz(char)), 0, NULL, NULL }, + { FLDT_REXTLEN, "rextlen", fp_num, "%u", SI(RMAPBT_BLOCKCOUNT_BITLEN), + 0, NULL, NULL }, + { FLDT_RFILEOFFD, "rfileoffd", fp_num, "%llu", SI(RMAPBT_OFFSET_BITLEN), + 0, NULL, NULL }, + { FLDT_REXTFLG, "rextflag", fp_num, "%u", SI(RMAPBT_EXNTFLAG_BITLEN), 0, + NULL, NULL }, + { FLDT_RATTRFORKFLG, "rattrforkflag", fp_num, "%u", SI(RMAPBT_ATTRFLAG_BITLEN), 0, + NULL, NULL }, + { FLDT_RBMBTFLG, "rbmbtflag", fp_num, "%u", SI(RMAPBT_BMBTFLAG_BITLEN), 0, + NULL, NULL }, { FLDT_CNTBT, "cntbt", NULL, (char *)cntbt_flds, btblock_size, FTARG_SIZE, NULL, cntbt_flds }, { FLDT_CNTBT_CRC, "cntbt", NULL, (char *)cntbt_crc_flds, btblock_size,
db/field.h +5 -0
@@ -75,6 +75,11 @@ typedef enum fldt {FLDT_CFSBLOCK ,FLDT_CHARNS ,FLDT_CHARS , +FLDT_REXTLEN , +FLDT_RFILEOFFD , +FLDT_REXTFLG , +FLDT_RATTRFORKFLG , +FLDT_RBMBTFLG ,FLDT_CNTBT ,FLDT_CNTBT_CRC , FLDT_CNTBTKEY,
db/type.c +2 -0
@@ -127,6 +127,8 @@ static const typ_t __typtab_spcrc[] = { &xfs_allocbt_buf_ops }, {TYP_CNTBT ,"cntbt" , handle_struct, cntbt_crc_hfld, &xfs_allocbt_buf_ops }, + { TYP_RMAPBT, "rmapbt", handle_struct, rmapbt_crc_hfld, + &xfs_rmapbt_buf_ops }, { TYP_DATA, "data", handle_block, NULL, NULL }, { TYP_DIR2, "dir3", handle_struct, dir3_hfld, &xfs_dir3_db_buf_ops },
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 22/53 xfs_db: check rmapbt
In reply to Darrick J. Wong--- db/check.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-)
db/check.c +84 -1
@@ -44,7 +44,7 @@ typedef enum {DBM_FREE1 ,DBM_FREE2 ,DBM_FREELIST ,DBM_INODE ,DBM_LOG ,DBM_MISSING ,DBM_QUOTA ,DBM_RTBITMAP ,DBM_RTDATA ,DBM_RTFREE ,DBM_RTSUM ,DBM_SB , -DBM_SYMLINK ,DBM_BTFINO , +DBM_SYMLINK ,DBM_BTFINO ,DBM_BTRMAP , DBM_NDBM } dbm_t;
@@ -171,6 +171,7 @@ static const char *typename[] = {"sb" ,"symlink" ,"btfino" , +"btrmap" , NULL };static int verbose;
@@ -349,6 +350,9 @@ static void scanfunc_ino(struct xfs_btree_block *block, int level,static void scanfunc_fino (struct xfs_btree_block *block,int level,struct xfs_agf *agf,xfs_agblock_t bno,int isroot); +static void scanfunc_rmap (struct xfs_btree_block *block,int level, +struct xfs_agf *agf,xfs_agblock_t bno, +int isroot);static void set_dbmap (xfs_agnumber_t agno,xfs_agblock_t agbno,xfs_extlen_t len,dbm_t type,xfs_agnumber_t c_agno,xfs_agblock_t c_agbno);
@@ -1050,6 +1054,7 @@ blocktrash_f( (1 <<DBM_RTSUM ) | (1 <<DBM_SYMLINK ) | (1 <<DBM_BTFINO ) | + (1 <<DBM_BTRMAP ) | (1 <<DBM_SB );while ((c =getopt (argc, argv,"0123n:o:s:t:x:y:z" )) !=EOF ) {switch (c) {
@@ -3907,6 +3912,12 @@ scan_ag(be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNT ]),be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]), 1, scanfunc_cnt, TYP_CNTBT); +if (agf->agf_roots[XFS_BTNUM_RMAP ]) { +scan_sbtree (agf, +be32_to_cpu (agf->agf_roots[XFS_BTNUM_RMAP ]), +be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]), +1 , scanfunc_rmap,TYP_RMAPBT ); + } scan_sbtree(agf, be32_to_cpu(agi->agi_root), be32_to_cpu(agi->agi_level),
@@ -4658,6 +4669,78 @@ scanfunc_fino( }static void +scanfunc_rmap ( +struct xfs_btree_block *block, +int level, +struct xfs_agf *agf, +xfs_agblock_t bno, +int isroot) +{ +xfs_agnumber_t seqno =be32_to_cpu (agf->agf_seqno); +int i; +xfs_rmap_ptr_t *pp; +struct xfs_rmap_rec *rp; +xfs_agblock_t lastblock; + +if (be32_to_cpu (block->bb_magic) !=XFS_RMAP_CRC_MAGIC ) { +dbprintf (_ ("bad magic # %#x in rmapbt block %u/%u\n" ), +be32_to_cpu (block->bb_magic), seqno, bno); + serious_error++; +return ; + } +if (be16_to_cpu (block->bb_level) != level) { +if (!sflag) +dbprintf (_ ("expected level %d got %d in rmapbt block " +"%u/%u\n" ), + level,be16_to_cpu (block->bb_level), seqno, bno); + error++; + } +if (!isroot) { + fdblocks++; + agfbtreeblks++; + } +set_dbmap (seqno, bno,1 ,DBM_BTRMAP , seqno, bno); +if (level ==0 ) { +if (be16_to_cpu (block->bb_numrecs) > mp->m_rmap_mxr[0 ] || + (isroot ==0 &&be16_to_cpu (block->bb_numrecs) < mp->m_rmap_mnr[0 ])) { +dbprintf (_ ("bad btree nrecs (%u, min=%u, max=%u) in " +"rmapbt block %u/%u\n" ), +be16_to_cpu (block->bb_numrecs), mp->m_rmap_mnr[0 ], + mp->m_rmap_mxr[0 ], seqno, bno); + serious_error++; +return ; + } + rp =XFS_RMAP_REC_ADDR (block,1 ); + lastblock =0 ; +for (i =0 ; i <be16_to_cpu (block->bb_numrecs); i++) { +if (be32_to_cpu (rp[i].rm_startblock) < lastblock) { +dbprintf (_ ( +"out-of-order rmap btree record %d (%u %u) block %u/%u\n" ), + i,be32_to_cpu (rp[i].rm_startblock), +be32_to_cpu (rp[i].rm_startblock), +be32_to_cpu (agf->agf_seqno), bno); + }else { + lastblock =be32_to_cpu (rp[i].rm_startblock); + } + } +return ; + } +if (be16_to_cpu (block->bb_numrecs) > mp->m_rmap_mxr[1 ] || + (isroot ==0 &&be16_to_cpu (block->bb_numrecs) < mp->m_rmap_mnr[1 ])) { +dbprintf (_ ("bad btree nrecs (%u, min=%u, max=%u) in rmapbt " +"block %u/%u\n" ), +be16_to_cpu (block->bb_numrecs), mp->m_rmap_mnr[1 ], + mp->m_rmap_mxr[1 ], seqno, bno); + serious_error++; +return ; + } + pp =XFS_RMAP_PTR_ADDR (block,1 , mp->m_rmap_mxr[1 ]); +for (i =0 ; i <be16_to_cpu (block->bb_numrecs); i++) +scan_sbtree (agf,be32_to_cpu (pp[i]), level,0 , scanfunc_rmap, +TYP_RMAPBT ); +} + +static void set_dbmap( xfs_agnumber_t agno, xfs_agblock_t agbno,
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 23/53 xfs_db: copy the rmap btree
In reply to Darrick J. Wong--- db/metadump.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
db/metadump.c +74 -0
@@ -524,6 +524,78 @@ copy_free_cnt_btree(return scan_btree (agno, root, levels,TYP_CNTBT , agf, scanfunc_freesp); } +static int +scanfunc_rmapbt ( +struct xfs_btree_block *block, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +int level, +typnm_t btype, +void *arg) +{ +xfs_rmap_ptr_t *pp; +int i; +int numrecs; + +if (level ==0 ) +return 1 ; + + numrecs =be16_to_cpu (block->bb_numrecs); +if (numrecs > mp->m_rmap_mxr[1 ]) { +if (show_warnings) +print_warning ("invalid numrecs (%u) in %s block %u/%u" , + numrecs, typtab[btype].name, agno, agbno); +return 1 ; + } + + pp =XFS_RMAP_PTR_ADDR (block,1 , mp->m_rmap_mxr[1 ]); +for (i =0 ; i < numrecs; i++) { +if (!valid_bno (agno,be32_to_cpu (pp[i]))) { +if (show_warnings) +print_warning ("invalid block number (%u/%u) " +"in %s block %u/%u" , + agno,be32_to_cpu (pp[i]), + typtab[btype].name, agno, agbno); +continue ; + } +if (!scan_btree (agno,be32_to_cpu (pp[i]), level, btype, arg, + scanfunc_rmapbt)) +return 0 ; + } +return 1 ; +} + +static int +copy_rmap_btree ( +xfs_agnumber_t agno, +struct xfs_agf *agf) +{ +xfs_agblock_t root; +int levels; + +if (!xfs_sb_version_hasrmapbt (&mp->m_sb)) +return 1 ; + + root =be32_to_cpu (agf->agf_roots[XFS_BTNUM_RMAP ]); + levels =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]); + +/* validate root and levels before processing the tree */ +if (root ==0 || root > mp->m_sb.sb_agblocks) { +if (show_warnings) +print_warning ("invalid block number (%u) in rmapbt " +"root in agf %u" , root, agno); +return 1 ; + } +if (levels >=XFS_BTREE_MAXLEVELS ) { +if (show_warnings) +print_warning ("invalid level (%u) in rmapbt root " +"in agf %u" , levels, agno); +return 1 ; + } + +return scan_btree (agno, root, levels,TYP_RMAPBT , agf, scanfunc_rmapbt); +} +/* filename and extended attribute obfuscation routines */ struct name_ent {
@@ -2432,6 +2504,8 @@ scan_ag( goto pop_out;if (!copy_free_cnt_btree (agno, agf)) goto pop_out; +if (!copy_rmap_btree (agno, agf)) + goto pop_out; }/* copy inode btrees and the inodes and their associated metadata */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 24/53 xfs_growfs: report rmapbt presence
In reply to Darrick J. Wong--- growfs/xfs_growfs.c | 14 +++++++++----- libxfs/xfs_fs.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-)
growfs/xfs_growfs.c +9 -5
@@ -58,12 +58,13 @@ report_info( int cimode, int ftype_enabled, int finobt_enabled, - int spinodes) + int spinodes, + int rmapbt_enabled) { printf(_("meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n" " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n" -" =%-22s crc=%-8u finobt=%u spinodes=%u\n" +" =%-22s crc=%-8u finobt=%u spinodes=%u rmapbt=%u\n" "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n" " =%-22s sunit=%-6u swidth=%u blks\n" "naming =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
@@ -73,7 +74,7 @@ report_info( mntpoint, geo.inodesize, geo.agcount, geo.agblocks,"" , geo.sectsize, attrversion, projid32bit, -"" , crcs_enabled, finobt_enabled, spinodes, +"" , crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,"" , geo.blocksize, (unsigned long long )geo.datablocks, geo.imaxpct, "", geo.sunit, geo.swidth,
@@ -127,6 +128,7 @@ main(int argc, char **argv)int ftype_enabled =0 ;int finobt_enabled;/* free inode btree */ int spinodes; +int rmapbt_enabled; progname =basename (argv[0 ]);setlocale (LC_ALL ,"" );
@@ -250,11 +252,13 @@ main(int argc, char **argv) ftype_enabled = geo.flags &XFS_FSOP_GEOM_FLAGS_FTYPE ?1 :0 ; finobt_enabled = geo.flags &XFS_FSOP_GEOM_FLAGS_FINOBT ?1 :0 ; spinodes = geo.flags &XFS_FSOP_GEOM_FLAGS_SPINODES ?1 :0 ; + rmapbt_enabled = geo.flags &XFS_FSOP_GEOM_FLAGS_RMAPBT ?1 :0 ;if (nflag) {report_info (geo, datadev, isint, logdev, rtdev, lazycount, dirversion, logversion, attrversion, projid32bit, crcs_enabled, ci, - ftype_enabled, finobt_enabled, spinodes); + ftype_enabled, finobt_enabled, spinodes, + rmapbt_enabled);exit (0 ); }
@@ -292,7 +296,7 @@ main(int argc, char **argv)report_info (geo, datadev, isint, logdev, rtdev, lazycount, dirversion, logversion, attrversion, projid32bit, crcs_enabled, ci, ftype_enabled, - finobt_enabled, spinodes); + finobt_enabled, spinodes, rmapbt_enabled); ddsize = xi.dsize; dlsize = ( xi.logBBsize? xi.logBBsize :
libxfs/xfs_fs.h +1 -0
@@ -240,6 +240,7 @@ typedef struct xfs_fsop_resblks {#define XFS_FSOP_GEOM_FLAGS_FTYPE 0x10000/* inode directory types */ #define XFS_FSOP_GEOM_FLAGS_FINOBT 0x20000/* free inode btree */ #define XFS_FSOP_GEOM_FLAGS_SPINODES 0x40000/* sparse inode chunks */ +#define XFS_FSOP_GEOM_FLAGS_RMAPBT 0x80000/* reverse-mapping btree */ /* * Minimum and maximum sizes need for growth checks.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 25/53 xfs_repair: use rmap btree data to check block types
In reply to Darrick J. WongQuoted 1 line
From : Dave Chinner <[email protected]>
Use the rmap btree to pre-populate the block type information so that when repair iterates the primary metadata, we can confirm the block type.
--- repair/dinode.c | 6 + repair/incore.h | 16 +- repair/scan.c | 336 ++++++++++++++++++++++++++++++++++++++++++++++++--- repair/xfs_repair.c | 2 4 files changed, 331 insertions(+), 29 deletions(-)
repair/dinode.c +6 -0
@@ -744,6 +744,7 @@ _("%s fork in ino %" PRIu64 " claims dup extent, "_ ("%s fork in ino %" PRIu64" claims free block %" PRIu64"\n" ), forkname, ino, (__uint64_t) b);/* fall through ... */ +case XR_E_INUSE1 :/* seen by rmap */ case XR_E_UNKNOWN :set_bmap_ext (agno, agbno, blen,XR_E_INUSE );break ;
@@ -751,6 +752,11 @@ _("%s fork in ino %" PRIu64 " claims free block %" PRIu64 "\n"),case XR_E_BAD_STATE :do_error (_ ("bad state in block map %" PRIu64"\n" ), b); +case XR_E_FS_MAP1 : +case XR_E_INO1 : +case XR_E_INUSE_FS1 : +do_warn (_ ("rmap claims metadata use!\n" )); +/* fall through */ case XR_E_FS_MAP :case XR_E_INO :case XR_E_INUSE_FS :
repair/incore.h +5 -11
@@ -102,17 +102,11 @@ typedef struct rt_extent_tree_node {#define XR_E_MULT 5/* extent is multiply referenced */ #define XR_E_INO 6/* extent used by inodes (inode blocks) */ #define XR_E_FS_MAP 7/* extent used by fs space/inode maps */ -#define XR_E_BAD_STATE 8 - -/* extent states, in 64 bit word chunks */ -#define XR_E_UNKNOWN_LL 0x0000000000000000LL -#define XR_E_FREE1_LL 0x1111111111111111LL -#define XR_E_FREE_LL 0x2222222222222222LL -#define XR_E_INUSE_LL 0x3333333333333333LL -#define XR_E_INUSE_FS_LL 0x4444444444444444LL -#define XR_E_MULT_LL 0x5555555555555555LL -#define XR_E_INO_LL 0x6666666666666666LL -#define XR_E_FS_MAP_LL 0x7777777777777777LL +#define XR_E_INUSE1 8/* used block (marked by rmap btree) */ +#define XR_E_INUSE_FS1 9/* used by fs ag header or log (rmap btree) */ +#define XR_E_INO1 10/* used by inodes (marked by rmap btree) */ +#define XR_E_FS_MAP1 11/* used by fs space/inode maps (rmap btree) */ +#define XR_E_BAD_STATE 12/* separate state bit, OR'ed into high (4th) bit of ex_state field */
repair/scan.c +318 -18
417 lines not on this page · raw message
repair/xfs_repair.c +2 -0
@@ -416,6 +416,8 @@ calc_mkfs(xfs_mount_t *mp) fino_bno = inobt_root + (2 *min (2 , mp->m_ag_maxlevels)) +1 ;if (xfs_sb_version_hasfinobt (&mp->m_sb)) fino_bno++; +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) + fino_bno++;/* * If the log is allocated in the first allocation group we need to
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 26/53 xfs_repair: mask off length appropriately
In reply to Darrick J. WongEnsure that we remove the flag bits from blockcount before using the length field.
--- repair/scan.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-)
repair/scan.c +24 -8
@@ -792,6 +792,8 @@ scan_rmapbt(int numrecs;int state;xfs_agblock_t lastblock =0 ; +int64_t lastowner =0 ; +int64_t lastoffset =0 ;if (magic !=XFS_RMAP_CRC_MAGIC ) { name ="(unknown)" ;
@@ -859,11 +861,12 @@ _("%s rmap btree block claimed (state %d), agno %d, bno %d, suspect %d\n"),for (i =0 ; i < numrecs; i++) {xfs_agblock_t b, end;xfs_extlen_t len, blen; -int64_t owner; +int64_t owner, offset; b =be32_to_cpu (rp[i].rm_startblock); - len =be32_to_cpu (rp[i].rm_blockcount); + len =XFS_RMAP_LEN (be32_to_cpu (rp[i].rm_blockcount)); owner =be64_to_cpu (rp[i].rm_owner); + offset =be64_to_cpu (rp[i].rm_offset); end = b + len;if (!verify_agbno (mp, agno, b)) {
@@ -879,14 +882,27 @@ _("%s rmap btree block claimed (state %d), agno %d, bno %d, suspect %d\n"),continue ; } -/* XXX: range check owner */ +if (!(owner >0 || (owner >XFS_RMAP_OWN_MIN && + owner <=XFS_RMAP_OWN_FS ))) +do_warn ( +_ ("invalid owner in rmap btree record %d (%" PRId64" %u) block %u/%u\n" ), + i, owner, len, agno, bno); -if (b && b <= lastblock) { -do_warn (_ ( -"out-of-order rmap btree record %d (%u %u) block %u/%u\n" ), - i, b, len, agno, bno); - }else { +if (i ==0 ) { +advance: lastblock = b; + lastowner = owner; + lastoffset = offset; + }else { +bool bad; + + bad = b <= lastblock; +if (bad) +do_warn ( +_ ("out-of-order rmap btree record %d (%u %" PRId64" %" PRIx64" %u) block %u/%u\n" ), + i, b, owner, offset, len, agno, bno); +else + goto advance; }for ( ; b < end; b += blen) {
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 27/53 xfs_repair: fix fino_bno calculation when rmapbt is enabled
In reply to Darrick J. WongIn xfs_repair, we calculate where we think mkfs put the root inode block. However, the rmapbt component doesn't account for the fact that mkfs reserved 2 AGFL blocks for the rmapbt, so its calculation is off by a bit. This leads to it complaining (incorrectly) about the root inode block being in the wrong place and blowing up.
--- repair/xfs_repair.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
repair/xfs_repair.c +3 -1
@@ -416,8 +416,10 @@ calc_mkfs(xfs_mount_t *mp) fino_bno = inobt_root + (2 *min (2 , mp->m_ag_maxlevels)) +1 ;if (xfs_sb_version_hasfinobt (&mp->m_sb)) fino_bno++; -if (xfs_sb_version_hasrmapbt (&mp->m_sb)) +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) { + fino_bno +=min (2 , mp->m_ag_maxlevels); fino_bno++; + }/* * If the log is allocated in the first allocation group we need to
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 28/53 xfs_repair: create a slab API for allocating arrays in large chunks
In reply to Darrick J. WongCreate a slab-based array and a bag-of-pointers data structure to facilitate rapid linear scans of reverse-mapping data for later reconstruction of the refcount and rmap btrees.
--- repair/Makefile | 4 repair/slab.c | 473 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/slab.h | 58 +++++++ 3 files changed, 533 insertions(+), 2 deletions(-) create mode 100644 repair/slab.c create mode 100644 repair/slab.h
repair/Makefile +2 -2
@@ -11,13 +11,13 @@ LTCOMMAND = xfs_repair HFILES = agheader.h attr_repair.h avl.h avl64.h bmap.h btree.h \ da_util.h dinode.h dir2.h err_protos.h globals.h incore.h protos.h \ - rt.h progress.h scan.h versions.h prefetch.h threads.h + rt.h progress.h scan.h versions.h prefetch.h slab.h threads.h CFILES = agheader.c attr_repair.c avl.c avl64.c bmap.c btree.c \ da_util.c dino_chunks.c dinode.c dir2.c globals.c incore.c \ incore_bmc.c init.c incore_ext.c incore_ino.c phase1.c \ phase2.c phase3.c phase4.c phase5.c phase6.c phase7.c \ - progress.c prefetch.c rt.c sb.c scan.c threads.c \ + progress.c prefetch.c rt.c sb.c scan.c slab.c threads.c \ versions.c xfs_repair.c LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
repair/slab.c new file +473 -0
473 lines not on this page · raw message
repair/slab.h new file +58 -0
58 lines not on this page · raw message
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 29/53 xfs_repair: collect reverse-mapping data for refcount/rmap tree rebuilding
In reply to Darrick J. WongCollect reverse-mapping data for the entire filesystem so that we can later check and rebuild the reference count tree and the reverse mapping tree.
--- repair/Makefile | 4 + repair/dinode.c | 9 ++ repair/phase4.c | 5 + repair/rmap.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 30 ++++++++ repair/xfs_repair.c | 4 + 6 files changed, 245 insertions(+), 2 deletions(-) create mode 100644 repair/rmap.c create mode 100644 repair/rmap.h
repair/Makefile +2 -2
@@ -11,13 +11,13 @@ LTCOMMAND = xfs_repair HFILES = agheader.h attr_repair.h avl.h avl64.h bmap.h btree.h \ da_util.h dinode.h dir2.h err_protos.h globals.h incore.h protos.h \ - rt.h progress.h scan.h versions.h prefetch.h slab.h threads.h + rt.h progress.h scan.h versions.h prefetch.h rmap.h slab.h threads.h CFILES = agheader.c attr_repair.c avl.c avl64.c bmap.c btree.c \ da_util.c dino_chunks.c dinode.c dir2.c globals.c incore.c \ incore_bmc.c init.c incore_ext.c incore_ino.c phase1.c \ phase2.c phase3.c phase4.c phase5.c phase6.c phase7.c \ - progress.c prefetch.c rt.c sb.c scan.c slab.c threads.c \ + progress.c prefetch.c rmap.c rt.c sb.c scan.c slab.c threads.c \ versions.c xfs_repair.c LLDLIBS = $(LIBXFS) $(LIBXLOG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
repair/dinode.c +9 -0
@@ -30,6 +30,8 @@#include "attr_repair.h" #include "bmap.h" #include "threads.h" +#include "slab.h" +#include "rmap.h" /* * gettext lookups for translations of strings use mutexes internally to
@@ -779,6 +781,13 @@ _("illegal state %d in block map %" PRIu64 "\n"), state, b); } } +if (collect_rmaps) {/* && !check_dups */ + error =add_rmap (mp, ino, whichfork, &irec); +if (error) +do_error ( +_ ("couldn't add reverse mapping\n" ) + ); + } *tot += irec.br_blockcount; } error =0 ;
repair/phase4.c +5 -0
@@ -30,7 +30,10 @@#include "versions.h" #include "dir2.h" #include "progress.h" +#include "slab.h" +#include "rmap.h" +bool collect_rmaps = false;/* * null out quota inode fields in sb if they point to non-existent inodes.
@@ -170,6 +173,8 @@ phase4(xfs_mount_t *mp)int ag_hdr_block;int bstate; +if (needs_rmap_work (mp)) + collect_rmaps = true; ag_hdr_block =howmany (ag_hdr_len, mp->m_sb.sb_blocksize);do_log (_ ("Phase 4 - check for duplicate blocks...\n" ));
repair/rmap.c new file +195 -0
195 lines not on this page · raw message
repair/rmap.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (c) 2015 Oracle. +* All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#ifndef RMAP_H_ +#define RMAP_H_ + +extern bool collect_rmaps; + +extern bool needs_rmap_work (struct xfs_mount *); + +extern void init_rmaps (struct xfs_mount *); +extern void free_rmaps (struct xfs_mount *); + +extern int add_rmap (struct xfs_mount *,xfs_ino_t ,int ,struct xfs_bmbt_irec *); + +#endif /* RMAP_H_ */
repair/xfs_repair.c +4 -0
@@ -31,6 +31,8 @@#include "threads.h" #include "progress.h" #include "dinode.h" +#include "slab.h" +#include "rmap.h" #define rounddown (x, y) (((x)/(y))*(y))
@@ -858,6 +860,7 @@ main(int argc, char **argv)init_bmaps (mp);incore_ino_init (mp);incore_ext_init (mp); +init_rmaps (mp);/* initialize random globals now that we know the fs geometry */ inodes_per_block = mp->m_sb.sb_inopblock;
@@ -891,6 +894,7 @@ main(int argc, char **argv)/* * Done with the block usage maps, toss them... */ +free_rmaps (mp);free_bmaps (mp);if (!bad_ino_btree) {
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 30/53 xfs_repair: record and merge raw rmap data
In reply to Darrick J. WongSince we still allow merging of BMBT block, AG metadata, and AG btree block rmaps, provide a facility to collect these raw observations and merge them (with maximal length) into the main rmap list.
--- repair/rmap.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 3 + 2 files changed, 140 insertions(+)
repair/rmap.c +137 -0
@@ -37,6 +37,7 @@/* per-AG rmap object anchor */ struct xfs_ag_rmap {struct xfs_slab *ar_rmaps;/* rmap observations, p4 */ +struct xfs_slab *ar_raw_rmaps;/* unmerged rmaps */ };static struct xfs_ag_rmap *ag_rmaps;
@@ -107,6 +108,11 @@ init_rmaps(if (error)do_error (_ ("Insufficient memory while allocating reverse mapping slabs." )); + error =init_slab (&ag_rmaps[i].ar_raw_rmaps, +sizeof (struct xfs_rmap_irec )); +if (error) +do_error ( +_ ("Insufficient memory while allocating raw metadata reverse mapping slabs." )); } }
@@ -126,6 +132,7 @@ free_rmaps(for (i =0 ; i < mp->m_sb.sb_agcount; i++) {free_slab (&ag_rmaps[i].ar_rmaps); +free_slab (&ag_rmaps[i].ar_raw_rmaps); }free (ag_rmaps); ag_rmaps =NULL ;
@@ -175,6 +182,136 @@ add_rmap(return slab_add (rmaps, &rmap); } +/* add a raw rmap; these will be merged later */ +static int +__add_raw_rmap ( +struct xfs_mount *mp, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +xfs_extlen_t len, +uint64_t owner, +bool is_attr, +bool is_bmbt) +{ +struct xfs_rmap_irec rmap; + + rmap.rm_owner = owner; + rmap.rm_offset =0 ; +if (is_attr) + rmap.rm_offset |=XFS_RMAP_OFF_ATTR ; +if (is_bmbt) + rmap.rm_offset |=XFS_RMAP_OFF_BMBT ; + rmap.rm_startblock = agbno; + rmap.rm_blockcount = len; +return slab_add (ag_rmaps[agno].ar_raw_rmaps, &rmap); +} + +/** +* add_ag_rmap() -- Add an reverse mapping for a per-AG fixed metadata object. +* +* @mp: XFS mount object. +* @agno: The AG number. +* @agbno: The block within the AG. +* @len: The length of the extent. +* @owner: The owner of the block. +*/ +int +add_ag_rmap ( +struct xfs_mount *mp, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +xfs_extlen_t len, +uint64_t owner) +{ +if (!needs_rmap_work (mp)) +return 0 ; + +ASSERT (agno !=NULLAGNUMBER ); +ASSERT (agno < mp->m_sb.sb_agcount); +ASSERT (agbno + len <= mp->m_sb.sb_agblocks); + +return __add_raw_rmap (mp, agno, agbno, len, owner, false, false); +} + +static bool +mergeable_rmaps ( +struct xfs_rmap_irec *r1, +struct xfs_rmap_irec *r2) +{ +if (r1->rm_startblock + r1->rm_blockcount != r2->rm_startblock) +return false; +if (r1->rm_owner != r2->rm_owner) +return false; +if (XFS_RMAP_NON_INODE_OWNER (r2->rm_owner)) +return true; +/* must be an inode owner */ +if (XFS_RMAP_IS_ATTR_FORK (r1->rm_offset) ^ +XFS_RMAP_IS_ATTR_FORK (r2->rm_offset)) +return false; +if (XFS_RMAP_IS_BMBT (r1->rm_offset) ||XFS_RMAP_IS_BMBT (r2->rm_offset)) +return XFS_RMAP_IS_BMBT (r1->rm_offset) && +XFS_RMAP_IS_BMBT (r2->rm_offset); +return r1->rm_offset + r1->rm_blockcount == r2->rm_offset; +} + +/** +* fold_raw_rmaps() - Merge adjacent raw rmaps and add them to the main +* rmap list. +* @mp: XFS mount. +* @agno: AG number. +*/ +int +fold_raw_rmaps ( +struct xfs_mount *mp, +xfs_agnumber_t agno) +{ +struct xfs_slab_cursor *cur =NULL ; +struct xfs_rmap_irec *prev, *rec; +size_t old_sz; +int error; + + old_sz =slab_count (ag_rmaps[agno].ar_rmaps); +if (slab_count (ag_rmaps[agno].ar_raw_rmaps) ==0 ) + goto no_raw; +qsort_slab (ag_rmaps[agno].ar_raw_rmaps, rmap_compare); + error =init_slab_cursor (ag_rmaps[agno].ar_raw_rmaps, rmap_compare, + &cur); +if (error) + goto err; + + prev =pop_slab_cursor (cur); + rec =pop_slab_cursor (cur); +while (rec) { +if (mergeable_rmaps (prev, rec)) { + prev->rm_blockcount += rec->rm_blockcount; + rec =pop_slab_cursor (cur); +continue ; + } + error =slab_add (ag_rmaps[agno].ar_rmaps, prev); +if (error) + goto err; + prev = rec; + rec =pop_slab_cursor (cur); + } +if (prev) { + error =slab_add (ag_rmaps[agno].ar_rmaps, prev); +if (error) + goto err; + } +free_slab (&ag_rmaps[agno].ar_raw_rmaps); + error =init_slab (&ag_rmaps[agno].ar_raw_rmaps, +sizeof (struct xfs_rmap_irec )); +if (error) +do_error ( +_ ("Insufficient memory while allocating raw metadata reverse mapping slabs." )); +no_raw: +if (old_sz) +qsort_slab (ag_rmaps[agno].ar_rmaps, rmap_compare); +err: +free_slab_cursor (&cur); +return error; +} +#ifdef RMAP_DEBUG static void dump_rmap(
repair/rmap.h +3 -0
@@ -26,5 +26,8 @@ extern void init_rmaps(struct xfs_mount *);extern void free_rmaps (struct xfs_mount *);extern int add_rmap (struct xfs_mount *,xfs_ino_t ,int ,struct xfs_bmbt_irec *); +extern int add_ag_rmap (struct xfs_mount *,xfs_agnumber_t agno, +xfs_agblock_t agbno,xfs_extlen_t len,uint64_t owner); +extern int fold_raw_rmaps (struct xfs_mount *mp,xfs_agnumber_t agno);#endif /* RMAP_H_ */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 31/53 xfs_repair: add inode bmbt block rmaps
In reply to Darrick J. WongRecord BMBT blocks in the raw rmap list.
--- repair/rmap.c | 32 ++++++++++++++++++++++++++++++++ repair/rmap.h | 1 + repair/scan.c | 11 +++++++++++ 3 files changed, 44 insertions(+)
repair/rmap.c +32 -0
@@ -207,6 +207,38 @@ __add_raw_rmap( }/** +* add_bmbt_rmap() -- Add an observation about a bmbt block for later +* btree reconstruction. +* +* @mp: XFS mount object. +* @ino: The inode number associated with the extent mapping. +* @whichfork: Data or attribute fork? +* @fsbno: fsblock number of the bmbt block +*/ +int +add_bmbt_rmap ( +struct xfs_mount *mp, +xfs_ino_t ino, +int whichfork, +xfs_fsblock_t fsbno) +{ +xfs_agnumber_t agno; +xfs_agblock_t agbno; + +if (!needs_rmap_work (mp)) +return 0 ; + + agno =XFS_FSB_TO_AGNO (mp, fsbno); + agbno =XFS_FSB_TO_AGBNO (mp, fsbno); +ASSERT (agno !=NULLAGNUMBER ); +ASSERT (agno < mp->m_sb.sb_agcount); +ASSERT (agbno +1 <= mp->m_sb.sb_agblocks); + +return __add_raw_rmap (mp, agno, agbno,1 , ino, + whichfork ==XFS_ATTR_FORK , true); +} + +/** * add_ag_rmap() -- Add an reverse mapping for a per-AG fixed metadata object. * * @mp: XFS mount object.
repair/rmap.h +1 -0
@@ -28,6 +28,7 @@ extern void free_rmaps(struct xfs_mount *);extern int add_rmap (struct xfs_mount *,xfs_ino_t ,int ,struct xfs_bmbt_irec *);extern int add_ag_rmap (struct xfs_mount *,xfs_agnumber_t agno,xfs_agblock_t agbno,xfs_extlen_t len,uint64_t owner); +extern int add_bmbt_rmap (struct xfs_mount *,xfs_ino_t ,int ,xfs_fsblock_t );extern int fold_raw_rmaps (struct xfs_mount *mp,xfs_agnumber_t agno);#endif /* RMAP_H_ */
repair/scan.c +11 -0
@@ -29,6 +29,7 @@#include "bmap.h" #include "progress.h" #include "threads.h" +#include "rmap.h" static xfs_mount_t *mp =NULL ;
@@ -197,6 +198,7 @@ scan_bmapbt(xfs_agnumber_t agno;xfs_agblock_t agbno;int state; +int error;/* * unlike the ag freeblock btrees, if anything looks wrong
@@ -378,6 +380,15 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"), (*tot)++; numrecs =be16_to_cpu (block->bb_numrecs); +/* Record BMBT blocks in the reverse-mapping data. */ +if (check_dups && collect_rmaps) { + error =add_bmbt_rmap (mp, ino, whichfork, bno); +if (error) +do_error ( +_ ("couldn't add inode %" PRIu64" bmbt block %" PRIu64" reverse-mapping data." ), + ino, bno); + } +if (level ==0 ) {if (numrecs > mp->m_bmap_dmxr[0 ] || (isroot ==0 && numrecs < mp->m_bmap_dmnr[0 ])) {
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 32/53 xfs_repair: add fixed-location per-AG rmaps
In reply to Darrick J. WongAdd reverse-mappings for fixed-location per-AG metadata such as inode chunks, superblocks, and the log to the raw rmap list, then merge the raw rmap data (which also has the BMBT data) into the main rmap list.
v2: Support sparse inode chunks.
--- repair/phase4.c | 41 +++++++++++++++++++++++++ repair/rmap.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 2 + 3 files changed, 134 insertions(+)
repair/phase4.c +41 -0
@@ -157,6 +157,40 @@ process_ags(do_inode_prefetch (mp, ag_stride, process_ag_func, true, false); } +static void +check_rmap_btrees ( +work_queue_t *wq, +xfs_agnumber_t agno, +void *arg) +{ +int error; + + error =add_fixed_ag_rmap_data (wq->mp, agno); +if (error) +do_error ( +_ ("unable to add AG %u metadata reverse-mapping data.\n" ), agno); + + error =fold_raw_rmaps (wq->mp, agno); +if (error) +do_error ( +_ ("unable to merge AG %u metadata reverse-mapping data.\n" ), agno); +} + +static void +process_rmap_data ( +struct xfs_mount *mp) +{ +struct work_queue wq; +xfs_agnumber_t i; + +if (!needs_rmap_work (mp)) +return ; + +create_work_queue (&wq, mp,libxfs_nproc ()); +for (i =0 ; i < mp->m_sb.sb_agcount; i++) +queue_work (&wq, check_rmap_btrees, i,NULL ); +destroy_work_queue (&wq); +}void phase4 (xfs_mount_t *mp)
@@ -306,6 +340,13 @@ phase4(xfs_mount_t *mp)* already in phase 3. */ process_ags (mp); + +/* +* Process all the reverse-mapping data that we collected. This +* involves checking the rmap data against the btree. +*/ +process_rmap_data (mp); +print_final_rpt ();/*
repair/rmap.c +91 -0
97 lines not on this page · raw message
repair/rmap.h +2 -0
@@ -31,4 +31,6 @@ extern int add_ag_rmap(struct xfs_mount *, xfs_agnumber_t agno,extern int add_bmbt_rmap (struct xfs_mount *,xfs_ino_t ,int ,xfs_fsblock_t );extern int fold_raw_rmaps (struct xfs_mount *mp,xfs_agnumber_t agno); +extern int add_fixed_ag_rmap_data (struct xfs_mount *,xfs_agnumber_t ); +#endif /* RMAP_H_ */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 33/53 xfs_repair: check existing rmapbt entries against observed rmaps
In reply to Darrick J. WongIf we're running in -n mode, check the rmaps that we observe against what's in the rmap btree and complain if there's a mismatch.
--- include/libxfs.h | 1 repair/phase4.c | 6 ++ repair/rmap.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 5 ++ repair/scan.c | 19 ++++-- 5 files changed, 198 insertions(+), 6 deletions(-)
include/libxfs.h +1 -0
@@ -77,6 +77,7 @@ extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);#include "xfs_bmap.h" #include "xfs_trace.h" #include "xfs_trans.h" +#include "xfs_rmap_btree.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))
repair/phase4.c +6 -0
@@ -174,6 +174,12 @@ _("unable to add AG %u metadata reverse-mapping data.\n"), agno);if (error)do_error (_ ("unable to merge AG %u metadata reverse-mapping data.\n" ), agno); + + error =check_rmaps (wq->mp, agno); +if (error) +do_error ( +_ ("%s while checking reverse-mappings" ), +strerror (-error)); } static void
repair/rmap.c +173 -0
182 lines not on this page · raw message
repair/rmap.h +5 -0
@@ -33,4 +33,9 @@ extern int fold_raw_rmaps(struct xfs_mount *mp, xfs_agnumber_t agno);extern int add_fixed_ag_rmap_data (struct xfs_mount *,xfs_agnumber_t ); +extern size_t rmap_record_count (struct xfs_mount *,xfs_agnumber_t ); +extern int init_rmap_cursor (xfs_agnumber_t ,struct xfs_slab_cursor **); +extern void rmap_avoid_check (void ); +extern int check_rmaps (struct xfs_mount *,xfs_agnumber_t ); +#endif /* RMAP_H_ */
repair/scan.c +13 -6
@@ -29,6 +29,7 @@#include "bmap.h" #include "progress.h" #include "threads.h" +#include "slab.h" #include "rmap.h" static xfs_mount_t *mp =NULL ;
@@ -808,7 +809,9 @@ scan_rmapbt(if (magic !=XFS_RMAP_CRC_MAGIC ) { name ="(unknown)" ; -assert (0 ); + hdr_errors++; + suspect++; + goto out; }if (be32_to_cpu (block->bb_magic) != magic) {
@@ -816,7 +819,7 @@ scan_rmapbt( be32_to_cpu(block->bb_magic), name, agno, bno); hdr_errors++;if (suspect) -return ; + goto out; }/*
@@ -834,7 +837,7 @@ scan_rmapbt( level, be16_to_cpu(block->bb_level), name, agno, bno); hdr_errors++;if (suspect) -return ; + goto out; }/* check for btree blocks multiply claimed */
@@ -844,7 +847,7 @@ scan_rmapbt(do_warn (_ ("%s rmap btree block claimed (state %d), agno %d, bno %d, suspect %d\n" ), name, state, agno, bno, suspect); -return ; + goto out; }set_bmap (agno, bno,XR_E_FS_MAP );
@@ -992,7 +995,7 @@ _("unknown block (%d,%d-%d) mismatch on %s tree, state - %d,%" PRIx64 "\n"), } } } -return ; + goto out; }/*
@@ -1020,7 +1023,7 @@ _("unknown block (%d,%d-%d) mismatch on %s tree, state - %d,%" PRIx64 "\n"), mp->m_rmap_mnr[1 ], mp->m_rmap_mxr[1 ], name, agno, bno);if (suspect) -return ; + goto out; suspect++; }else if (suspect) { suspect =0 ;
@@ -1043,6 +1046,10 @@ _("unknown block (%d,%d-%d) mismatch on %s tree, state - %d,%" PRIx64 "\n"), magic, priv, &xfs_rmapbt_buf_ops); } } + +out: +if (suspect) +rmap_avoid_check (); }/*
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 34/53 xfs_repair: rebuild reverse-mapping btree
In reply to Darrick J. WongRebuild the reverse-mapping btree with the rmap observations corresponding to file extents, bmbt blocks, and fixed per-AG metadata.
--- repair/phase5.c | 321 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 316 insertions(+), 5 deletions(-)
repair/phase5.c +316 -5
@@ -28,6 +28,8 @@#include "versions.h" #include "threads.h" #include "progress.h" +#include "slab.h" +#include "rmap.h" /* * we maintain the current slice (path from root to leaf)
@@ -1326,6 +1328,292 @@ nextrec: } } +/* rebuild the rmap tree */ + +#define XR_RMAPBT_BLOCK_MAXRECS (mp, level) \ + ((mp)->m_rmap_mxr[(level) != 0]) + +/* +* we don't have to worry here about how chewing up free extents +* may perturb things because rmap tree building happens before +* freespace tree building. +*/ +static void +init_rmapbt_cursor (xfs_mount_t *mp,xfs_agnumber_t agno,bt_status_t *btree_curs) +{ +size_t num_recs; +int level; +bt_stat_level_t *lptr; +bt_stat_level_t *p_lptr; +xfs_extlen_t blocks_allocated; + +if (!xfs_sb_version_hasrmapbt (&mp->m_sb)) { +memset (btree_curs,0 ,sizeof (bt_status_t)); +return ; + } + + lptr = &btree_curs->level[0 ]; + btree_curs->init =1 ; + +/* +* build up statistics +*/ + num_recs =rmap_record_count (mp, agno); +if (num_recs ==0 ) { +/* +* easy corner-case -- no refcount records +*/ + lptr->num_blocks =1 ; + lptr->modulo =0 ; + lptr->num_recs_pb =0 ; + lptr->num_recs_tot =0 ; + + btree_curs->num_levels =1 ; + btree_curs->num_tot_blocks = btree_curs->num_free_blocks =1 ; + +setup_cursor (mp, agno, btree_curs); + +return ; + } + + blocks_allocated = lptr->num_blocks =howmany (num_recs, +XR_RMAPBT_BLOCK_MAXRECS (mp,0 )); + + lptr->modulo = num_recs % lptr->num_blocks; + lptr->num_recs_pb = num_recs / lptr->num_blocks; + lptr->num_recs_tot = num_recs; + level =1 ; + +if (lptr->num_blocks >1 ) { +for (; btree_curs->level[level-1 ].num_blocks >1 + && level <XFS_BTREE_MAXLEVELS ; + level++) { + lptr = &btree_curs->level[level]; + p_lptr = &btree_curs->level[level -1 ]; + lptr->num_blocks =howmany (p_lptr->num_blocks, +XR_RMAPBT_BLOCK_MAXRECS (mp, level)); + lptr->modulo = p_lptr->num_blocks % lptr->num_blocks; + lptr->num_recs_pb = p_lptr->num_blocks + / lptr->num_blocks; + lptr->num_recs_tot = p_lptr->num_blocks; + + blocks_allocated += lptr->num_blocks; + } + } +ASSERT (lptr->num_blocks ==1 ); + btree_curs->num_levels = level; + + btree_curs->num_tot_blocks = btree_curs->num_free_blocks + = blocks_allocated; + +setup_cursor (mp, agno, btree_curs); +} + +static void +prop_rmap_cursor (xfs_mount_t *mp,xfs_agnumber_t agno,bt_status_t *btree_curs, +struct xfs_rmap_irec *rm_rec,int level) +{ +struct xfs_btree_block *bt_hdr; +struct xfs_rmap_key *bt_key; +xfs_rmap_ptr_t *bt_ptr; +xfs_agblock_t agbno; +bt_stat_level_t *lptr; + + level++; + +if (level >= btree_curs->num_levels) +return ; + + lptr = &btree_curs->level[level]; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); + +if (be16_to_cpu (bt_hdr->bb_numrecs) ==0 ) { +/* +* this only happens once to initialize the +* first path up the left side of the tree +* where the agbno's are already set up +*/ +prop_rmap_cursor (mp, agno, btree_curs, rm_rec, level); + } + +if (be16_to_cpu (bt_hdr->bb_numrecs) == + lptr->num_recs_pb + (lptr->modulo >0 )) { +/* +* write out current prev block, grab us a new block, +* and set the rightsib pointer of current block +*/ +#ifdef XR_BLD_INO_TRACE +fprintf (stderr," ino prop agbno %d " , lptr->prev_agbno); +#endif +if (lptr->prev_agbno !=NULLAGBLOCK ) { +ASSERT (lptr->prev_buf_p !=NULL ); +libxfs_writebuf (lptr->prev_buf_p,0 ); + } + lptr->prev_agbno = lptr->agbno; + lptr->prev_buf_p = lptr->buf_p; + agbno =get_next_blockaddr (agno, level, btree_curs); + + bt_hdr->bb_u.s.bb_rightsib =cpu_to_be32 (agbno); + + lptr->buf_p =libxfs_getbuf (mp->m_dev, +XFS_AGB_TO_DADDR (mp, agno, agbno), +XFS_FSB_TO_BB (mp,1 )); + lptr->agbno = agbno; + +if (lptr->modulo) + lptr->modulo--; + +/* +* initialize block header +*/ + lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); +memset (bt_hdr,0 , mp->m_sb.sb_blocksize); +xfs_btree_init_block (mp, lptr->buf_p,XFS_RMAP_CRC_MAGIC , + level,0 , agno, +XFS_BTREE_CRC_BLOCKS ); + + bt_hdr->bb_u.s.bb_leftsib =cpu_to_be32 (lptr->prev_agbno); + +/* +* propagate extent record for first extent in new block up +*/ +prop_rmap_cursor (mp, agno, btree_curs, rm_rec, level); + } +/* +* add inode info to current block +*/ +be16_add_cpu (&bt_hdr->bb_numrecs,1 ); + + bt_key =XFS_RMAP_KEY_ADDR (bt_hdr, +be16_to_cpu (bt_hdr->bb_numrecs)); + bt_ptr =XFS_RMAP_PTR_ADDR (bt_hdr, +be16_to_cpu (bt_hdr->bb_numrecs), + mp->m_rmap_mxr[1 ]); + + bt_key->rm_startblock =cpu_to_be32 (rm_rec->rm_startblock); + bt_key->rm_owner =cpu_to_be64 (rm_rec->rm_owner); + bt_key->rm_offset =cpu_to_be64 (rm_rec->rm_offset); + + *bt_ptr =cpu_to_be32 (btree_curs->level[level-1 ].agbno); +} + +/* +* rebuilds a rmap btree given a cursor. +*/ +static void +build_rmap_tree (xfs_mount_t *mp,xfs_agnumber_t agno,bt_status_t *btree_curs) +{ +xfs_agnumber_t i; +xfs_agblock_t j; +xfs_agblock_t agbno; +struct xfs_btree_block *bt_hdr; +struct xfs_rmap_irec *rm_rec; +struct xfs_slab_cursor *rmap_cur; +struct xfs_rmap_rec *bt_rec; +struct bt_stat_level *lptr; +int level = btree_curs->num_levels; +int error; + +for (i =0 ; i < level; i++) { + lptr = &btree_curs->level[i]; + + agbno =get_next_blockaddr (agno, i, btree_curs); + lptr->buf_p =libxfs_getbuf (mp->m_dev, +XFS_AGB_TO_DADDR (mp, agno, agbno), +XFS_FSB_TO_BB (mp,1 )); + +if (i == btree_curs->num_levels -1 ) + btree_curs->root = agbno; + + lptr->agbno = agbno; + lptr->prev_agbno =NULLAGBLOCK ; + lptr->prev_buf_p =NULL ; +/* +* initialize block header +*/ + + lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); +memset (bt_hdr,0 , mp->m_sb.sb_blocksize); +xfs_btree_init_block (mp, lptr->buf_p,XFS_RMAP_CRC_MAGIC , + i,0 , agno, +XFS_BTREE_CRC_BLOCKS ); + } + +/* +* run along leaf, setting up records. as we have to switch +* blocks, call the prop_rmap_cursor routine to set up the new +* pointers for the parent. that can recurse up to the root +* if required. set the sibling pointers for leaf level here. +*/ + error =init_rmap_cursor (agno, &rmap_cur); +if (error) +do_error ( +_ ("Insufficient memory to construct reverse-map cursor." )); + rm_rec =pop_slab_cursor (rmap_cur); + lptr = &btree_curs->level[0 ]; + +for (i =0 ; i < lptr->num_blocks; i++) { +/* +* block initialization, lay in block header +*/ + lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); +memset (bt_hdr,0 , mp->m_sb.sb_blocksize); +xfs_btree_init_block (mp, lptr->buf_p,XFS_RMAP_CRC_MAGIC , +0 ,0 , agno, +XFS_BTREE_CRC_BLOCKS ); + + bt_hdr->bb_u.s.bb_leftsib =cpu_to_be32 (lptr->prev_agbno); + bt_hdr->bb_numrecs =cpu_to_be16 (lptr->num_recs_pb + + (lptr->modulo >0 )); + +if (lptr->modulo >0 ) + lptr->modulo--; + +if (lptr->num_recs_pb >0 ) +prop_rmap_cursor (mp, agno, btree_curs, rm_rec,0 ); + + bt_rec = (struct xfs_rmap_rec *) + ((char *)bt_hdr +XFS_RMAP_BLOCK_LEN ); +for (j =0 ; j <be16_to_cpu (bt_hdr->bb_numrecs); j++) { +ASSERT (rm_rec !=NULL ); + bt_rec[j].rm_startblock = +cpu_to_be32 (rm_rec->rm_startblock); + bt_rec[j].rm_blockcount = +cpu_to_be32 (rm_rec->rm_blockcount); + bt_rec[j].rm_owner =cpu_to_be64 (rm_rec->rm_owner); + bt_rec[j].rm_offset =cpu_to_be64 (rm_rec->rm_offset); + + rm_rec =pop_slab_cursor (rmap_cur); + } + +if (rm_rec !=NULL ) { +/* +* get next leaf level block +*/ +if (lptr->prev_buf_p !=NULL ) { +#ifdef XR_BLD_RL_TRACE +fprintf (stderr,"writing rmapbt agbno %u\n" , + lptr->prev_agbno); +#endif +ASSERT (lptr->prev_agbno !=NULLAGBLOCK ); +libxfs_writebuf (lptr->prev_buf_p,0 ); + } + lptr->prev_buf_p = lptr->buf_p; + lptr->prev_agbno = lptr->agbno; + lptr->agbno =get_next_blockaddr (agno,0 , btree_curs); + bt_hdr->bb_u.s.bb_rightsib =cpu_to_be32 (lptr->agbno); + + lptr->buf_p =libxfs_getbuf (mp->m_dev, +XFS_AGB_TO_DADDR (mp, agno, lptr->agbno), +XFS_FSB_TO_BB (mp,1 )); + } + } +free_slab_cursor (&rmap_cur); +} +/* * build both the agf and the agfl for an agno given both * btree cursors.
@@ -1338,7 +1626,8 @@ build_agf_agfl(xfs_mount_t *mp, bt_status_t *bno_bt, bt_status_t *bcnt_bt, xfs_extlen_t freeblks, /* # free blocks in tree */ - int lostblocks) /* # blocks that will be lost */ + int lostblocks, /* # blocks that will be lost */ + bt_status_t *rmap_bt) {extent_tree_node_t *ext_ptr;xfs_buf_t *agf_buf, *agfl_buf;
@@ -1377,20 +1666,25 @@ build_agf_agfl(xfs_mount_t *mp, agf->agf_levels[XFS_BTNUM_BNO ] =cpu_to_be32 (bno_bt->num_levels); agf->agf_roots[XFS_BTNUM_CNT ] =cpu_to_be32 (bcnt_bt->root); agf->agf_levels[XFS_BTNUM_CNT ] =cpu_to_be32 (bcnt_bt->num_levels); + agf->agf_roots[XFS_BTNUM_RMAP ] =cpu_to_be32 (rmap_bt->root); + agf->agf_levels[XFS_BTNUM_RMAP ] =cpu_to_be32 (rmap_bt->num_levels); agf->agf_freeblks =cpu_to_be32 (freeblks);/* * Count and record the number of btree blocks consumed if required. */ if (xfs_sb_version_haslazysbcount (&mp->m_sb)) { +unsigned int blks;/* * Don't count the root blocks as they are already * accounted for. */ - agf->agf_btreeblks =cpu_to_be32 ( - (bno_bt->num_tot_blocks - bno_bt->num_free_blocks) + + blks = (bno_bt->num_tot_blocks - bno_bt->num_free_blocks) + (bcnt_bt->num_tot_blocks - bcnt_bt->num_free_blocks) - -2 ); +2 ; +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) + blks += rmap_bt->num_tot_blocks - rmap_bt->num_free_blocks -1 ; + agf->agf_btreeblks =cpu_to_be32 (blks);#ifdef XR_BLD_FREE_TRACE fprintf (stderr,"agf->agf_btreeblks = %u\n" ,be32_to_cpu (agf->agf_btreeblks));
@@ -1581,6 +1875,7 @@ phase5_func(bt_status_t bcnt_btree_curs;bt_status_t ino_btree_curs;bt_status_t fino_btree_curs; +bt_status_t rmap_btree_curs;int extra_blocks =0 ;uint num_freeblocks;xfs_extlen_t freeblks1;
@@ -1636,6 +1931,12 @@ phase5_func( sb_icount_ag[agno] += num_inos; sb_ifree_ag[agno] += num_free_inos; +/* +* Set up the btree cursors for the on-disk rmap btrees, +* which includes pre-allocating all required blocks. +*/ +init_rmapbt_cursor (mp, agno, &rmap_btree_curs); + num_extents =count_bno_extents_blocks (agno, &num_freeblocks);/* * lose two blocks per AG -- the space tree roots
@@ -1720,11 +2021,19 @@ phase5_func(ASSERT (freeblks1 == freeblks2); +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) { +build_rmap_tree (mp, agno, &rmap_btree_curs); +write_cursor (&rmap_btree_curs); + sb_fdblocks_ag[agno] += (rmap_btree_curs.num_tot_blocks - + rmap_btree_curs.num_free_blocks) -1 ; + } +/* * set up agf and agfl */ build_agf_agfl (mp, agno, &bno_btree_curs, - &bcnt_btree_curs, freeblks1, extra_blocks); + &bcnt_btree_curs, freeblks1, extra_blocks, + &rmap_btree_curs);/* * build inode allocation tree. */
@@ -1753,6 +2062,8 @@ phase5_func(*/ finish_cursor (&bno_btree_curs);finish_cursor (&ino_btree_curs); +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) +finish_cursor (&rmap_btree_curs);if (xfs_sb_version_hasfinobt (&mp->m_sb))finish_cursor (&fino_btree_curs);finish_cursor (&bcnt_btree_curs);
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 35/53 xfs_repair: add per-AG btree blocks to rmap data and add to rmapbt
In reply to Darrick J. WongSince we can't know the location of the new per-AG btree blocks prior to constructing the rmapbt, we must record raw reverse-mapping data for btree blocks while the new btrees are under construction. After the rmapbt has been rebuilt, merge the btree rmap entries into the rmapbt with the libxfs code.
Also refactor the freelist fixing code since we need it to tidy up the AGFL after each rmapbt allocation.
--- repair/phase5.c | 47 ++++++------ repair/rmap.c | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 4 + 3 files changed, 248 insertions(+), 23 deletions(-)
repair/phase5.c +24 -23
@@ -74,6 +74,7 @@ typedef struct bt_status {* per-level status info */ bt_stat_level_t level[XFS_BTREE_MAXLEVELS ]; +uint64_t owner;/* owner */ } bt_status_t;/*
@@ -205,6 +206,7 @@ setup_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *curs)extent_tree_node_t *bno_ext_ptr;xfs_extlen_t blocks_allocated;xfs_agblock_t *agb_ptr; +int error;/* * get the number of blocks we need to allocate, then
@@ -249,6 +251,12 @@ setup_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *curs) blocks_allocated++; } + error =add_ag_rmap (mp, agno, ext_ptr->ex_startblock, u, + curs->owner); +if (error) +do_error (_ ("could not set up btree rmaps: %s\n" ), +strerror (-error)); +/* * if we only used part of this last extent, then we * need only to reset the extent in the extent
@@ -916,6 +924,7 @@ init_ino_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs, lptr = &btree_curs->level[0 ]; btree_curs->init =1 ; + btree_curs->owner =XFS_RMAP_OWN_INOBT ;/* * build up statistics
@@ -1354,6 +1363,7 @@ init_rmapbt_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs lptr = &btree_curs->level[0 ]; btree_curs->init =1 ; + btree_curs->owner =XFS_RMAP_OWN_AG ;/* * build up statistics
@@ -1766,6 +1776,7 @@ build_agf_agfl(xfs_mount_t *mp, agf->agf_flfirst =0 ; agf->agf_fllast =cpu_to_be32 (i -1 ); agf->agf_flcount =cpu_to_be32 (i); +rmap_store_agflcount (mp, agno, i);#ifdef XR_BLD_FREE_TRACE fprintf (stderr,"writing agfl for ag %u\n" , agno);
@@ -1790,30 +1801,8 @@ build_agf_agfl(xfs_mount_t *mp,/* * now fix up the free list appropriately -* XXX: code lifted from mkfs, should be shared. */ - { -xfs_alloc_arg_t args; -xfs_trans_t *tp; -struct xfs_trans_res tres = {0 }; -int error; - -memset (&args,0 ,sizeof (args)); - args.tp = tp =libxfs_trans_alloc (mp,0 ); - args.mp = mp; - args.agno = agno; - args.alignment =1 ; - args.pag =xfs_perag_get (mp,agno); -libxfs_trans_reserve (tp, &tres, -xfs_alloc_min_freelist (mp, args.pag),0 ); - error =libxfs_alloc_fix_freelist (&args,0 ); -xfs_perag_put (args.pag); -if (error) { -do_error (_ ("failed to fix AGFL on AG %d, error %d\n" ), - agno, error); - } -libxfs_trans_commit (tp); - } +fix_freelist (mp, agno, true);#ifdef XR_BLD_FREE_TRACE fprintf (stderr,"wrote agf for ag %u\n" , agno);
@@ -1885,6 +1874,7 @@ phase5_func(xfs_agblock_t num_extents;__uint32_t magic;struct agi_stat agi_stat = {0 ,}; +int error;if (verbose)do_log (_ (" - agno = %d\n" ), agno);
@@ -1990,6 +1980,8 @@ phase5_func( bcnt_btree_curs = bno_btree_curs; + bno_btree_curs.owner =XFS_RMAP_OWN_AG ; + bcnt_btree_curs.owner =XFS_RMAP_OWN_AG ;setup_cursor (mp, agno, &bno_btree_curs);setup_cursor (mp, agno, &bcnt_btree_curs);
@@ -2067,6 +2059,15 @@ phase5_func(if (xfs_sb_version_hasfinobt (&mp->m_sb))finish_cursor (&fino_btree_curs);finish_cursor (&bcnt_btree_curs); + +/* +* Put the per-AG btree rmap data into the rmapbt +*/ + error =store_ag_btree_rmap_data (mp, agno); +if (error) +do_error ( +_ ("unable to add AG %u reverse-mapping data to btree.\n" ), agno); +/* * release the incore per-AG bno/bcnt trees so * the extent nodes can be recycled
repair/rmap.c +220 -0
235 lines not on this page · raw message
repair/rmap.h +4 -0
@@ -32,10 +32,14 @@ extern int add_bmbt_rmap(struct xfs_mount *, xfs_ino_t, int, xfs_fsblock_t);extern int fold_raw_rmaps (struct xfs_mount *mp,xfs_agnumber_t agno);extern int add_fixed_ag_rmap_data (struct xfs_mount *,xfs_agnumber_t ); +extern int store_ag_btree_rmap_data (struct xfs_mount *,xfs_agnumber_t );extern size_t rmap_record_count (struct xfs_mount *,xfs_agnumber_t );extern int init_rmap_cursor (xfs_agnumber_t ,struct xfs_slab_cursor **);extern void rmap_avoid_check (void );extern int check_rmaps (struct xfs_mount *,xfs_agnumber_t ); +extern void fix_freelist (struct xfs_mount *,xfs_agnumber_t ,bool ); +extern void rmap_store_agflcount (struct xfs_mount *,xfs_agnumber_t ,int ); +#endif /* RMAP_H_ */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 36/53 mkfs.xfs: Create rmapbt filesystems
In reply to Darrick J. WongQuoted 1 line
From : Dave Chinner <[email protected]>
Create v5 filesystems with rmapbt turned on.
--- mkfs/xfs_mkfs.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 101 insertions(+), 17 deletions(-)
mkfs/xfs_mkfs.c +101 -17
@@ -185,6 +185,8 @@ char *mopts[] = { "finobt",#define M_UUID 2 "uuid", +#define M_RMAPBT 3 +"rmapbt" , NULL };
@@ -984,6 +986,7 @@ main(int finobt;bool finobtflag;int spinodes; +bool rmapbt;platform_uuid_generate (&uuid); progname =basename (argv[0 ]);
@@ -1022,6 +1025,7 @@ main( finobt =1 ; finobtflag = false; spinodes =0 ; + rmapbt = false;memset (&fsx,0 ,sizeof (fsx));memset (&xi,0 ,sizeof (xi));
@@ -1531,6 +1535,13 @@ main(reqval ('m' , mopts,M_UUID );if (platform_uuid_parse (value, &uuid))illegal (optarg,"m uuid" ); +case M_RMAPBT : +if (!value || *value =='\0' ) +reqval ('m' , mopts,M_CRC ); + c =atoi (value); +if (c <0 || c >1 ) +illegal (value,"m rmapbt" ); + rmapbt = c;break ;default :unknown ('m' , value);
@@ -1888,6 +1899,12 @@ _("warning: sparse inodes not supported without CRC support, disabled.\n")); spinodes =0 ; } +if (rmapbt && !crcs_enabled) { +fprintf (stderr, +_ ("warning: rmapbt not supported without CRC support, disabled.\n" )); + rmapbt =0 ; + } +if (nsflag || nlflag) {if (dirblocksize < blocksize || dirblocksize >XFS_MAX_BLOCKSIZE ) {
@@ -2481,7 +2498,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), mp->m_sectbb_log = sbp->sb_sectlog -BBSHIFT ;/* -* sb_versionnum and finobt flags must be set before we use +* sb_versionnum, finobt and rmapbt flags must be set before we use * xfs_prealloc_blocks(). */ sbp->sb_features2 = XFS_SB_VERSION2_MKFS(crcs_enabled, lazy_sb_counters,
@@ -2503,6 +2520,8 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),if (finobt) sbp->sb_features_ro_compat =XFS_SB_FEAT_RO_COMPAT_FINOBT ; +if (rmapbt) + sbp->sb_features_ro_compat |=XFS_SB_FEAT_RO_COMPAT_RMAPBT ;if (loginternal) {/*
@@ -2566,7 +2585,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), printf(_( "meta-data=%-22s isize=%-6d agcount=%lld, agsize=%lld blks\n" " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n" - " =%-22s crc=%-8u finobt=%u, sparse=%u\n" + " =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n" "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n" " =%-22s sunit=%-6u swidth=%u blks\n" "naming =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
@@ -2575,7 +2594,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), "realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"), dfile, isize, (long long )agcount, (long long )agsize,"" , sectorsize, attrversion, !projid16bit, -"" , crcs_enabled, finobt, spinodes, +"" , crcs_enabled, finobt, spinodes, rmapbt,"" , blocksize, (long long )dblocks, imaxpct,"" , dsunit, dswidth, dirversion, dirblocksize, nci, dirftype,
@@ -2764,6 +2783,12 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), agf->agf_levels[XFS_BTNUM_CNTi] =cpu_to_be32 (1 ); pag->pagf_levels[XFS_BTNUM_BNOi] =1 ; pag->pagf_levels[XFS_BTNUM_CNTi] =1 ; +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) { + agf->agf_roots[XFS_BTNUM_RMAPi] = +cpu_to_be32 (XFS_RMAP_BLOCK (mp)); + agf->agf_levels[XFS_BTNUM_RMAPi] =cpu_to_be32 (1 ); + } + agf->agf_flfirst =0 ; agf->agf_fllast =cpu_to_be32 (XFS_AGFL_SIZE (mp) -1 ); agf->agf_flcount =0 ;
@@ -2951,24 +2976,83 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),/* * Free INO btree root block */ -if (!finobt) { -xfs_perag_put (pag); -continue ; +if (finobt) { + buf =libxfs_getbuf (mp->m_ddev_targp, +XFS_AGB_TO_DADDR (mp, agno,XFS_FIBT_BLOCK (mp)), + bsize); + buf->b_ops = &xfs_inobt_buf_ops; + block =XFS_BUF_TO_BLOCK (buf); +memset (block,0 , blocksize); +if (xfs_sb_version_hascrc (&mp->m_sb)) +xfs_btree_init_block (mp, buf,XFS_FIBT_CRC_MAGIC ,0 ,0 , + agno,XFS_BTREE_CRC_BLOCKS ); +else +xfs_btree_init_block (mp, buf,XFS_FIBT_MAGIC ,0 ,0 , + agno,0 ); +libxfs_writebuf (buf,LIBXFS_EXIT_ON_FAILURE ); } - buf =libxfs_getbuf (mp->m_ddev_targp, -XFS_AGB_TO_DADDR (mp, agno,XFS_FIBT_BLOCK (mp)), +/* RMAP btree root block */ +if (rmapbt) { +struct xfs_rmap_rec *rrec; + + buf =libxfs_getbuf (mp->m_ddev_targp, +XFS_AGB_TO_DADDR (mp, agno,XFS_RMAP_BLOCK (mp)), bsize); - buf->b_ops = &xfs_inobt_buf_ops; - block =XFS_BUF_TO_BLOCK (buf); -memset (block,0 , blocksize); -if (xfs_sb_version_hascrc (&mp->m_sb)) -xfs_btree_init_block (mp, buf,XFS_FIBT_CRC_MAGIC ,0 ,0 , + buf->b_ops = &xfs_rmapbt_buf_ops; + block =XFS_BUF_TO_BLOCK (buf); +memset (block,0 , blocksize); + +xfs_btree_init_block (mp, buf,XFS_RMAP_CRC_MAGIC ,0 ,0 , agno,XFS_BTREE_CRC_BLOCKS ); -else -xfs_btree_init_block (mp, buf,XFS_FIBT_MAGIC ,0 ,0 , - agno,0 ); -libxfs_writebuf (buf,LIBXFS_EXIT_ON_FAILURE ); + +/* +* mark the AG header regions as static metadata +* The BNO btree block is the first block after the +* headers, so it's location defines the size of region +* the static metadata consumes. +*/ + rrec =XFS_RMAP_REC_ADDR (block,1 ); + rrec->rm_startblock =0 ; + rrec->rm_blockcount =cpu_to_be32 (XFS_BNO_BLOCK (mp)); + rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_FS ); +be16_add_cpu (&block->bb_numrecs,1 ); + +/* account freespace btree root blocks */ + rrec =XFS_RMAP_REC_ADDR (block,2 ); + rrec->rm_startblock =cpu_to_be32 (XFS_BNO_BLOCK (mp)); + rrec->rm_blockcount =cpu_to_be32 (2 ); + rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_AG ); +be16_add_cpu (&block->bb_numrecs,1 ); + +/* account inode btree root blocks */ + rrec =XFS_RMAP_REC_ADDR (block,3 ); + rrec->rm_startblock =cpu_to_be32 (XFS_IBT_BLOCK (mp)); + rrec->rm_blockcount =cpu_to_be32 (XFS_RMAP_BLOCK (mp) - +XFS_IBT_BLOCK (mp)); + rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_INOBT ); +be16_add_cpu (&block->bb_numrecs,1 ); + +/* account for rmap btree root */ + rrec =XFS_RMAP_REC_ADDR (block,4 ); + rrec->rm_startblock =cpu_to_be32 (XFS_RMAP_BLOCK (mp)); + rrec->rm_blockcount =cpu_to_be32 (1 ); + rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_AG ); +be16_add_cpu (&block->bb_numrecs,1 ); + +/* account for the log space */ +if (loginternal && agno == logagno) { + rrec =XFS_RMAP_REC_ADDR (block,5 ); + rrec->rm_startblock =cpu_to_be32 ( +XFS_FSB_TO_AGBNO (mp, logstart)); + rrec->rm_blockcount =cpu_to_be32 (logblocks); + rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_LOG ); +be16_add_cpu (&block->bb_numrecs,1 ); + } + +libxfs_writebuf (buf,LIBXFS_EXIT_ON_FAILURE ); + } +xfs_perag_put (pag); }
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 37/53 xfs_mkfs: initialize extra fields during mkfs, add docs
In reply to Darrick J. WongDocument the rmapbt options to mkfs, and initialize the extra field we added.
--- man/man8/mkfs.xfs.8 | 20 ++++++++++++++++++++ mkfs/xfs_mkfs.c | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-)
man/man8/mkfs.xfs.8 +20 -0
@@ -173,6 +173,26 @@ is used, the free inode btree feature is not supported and is disabled. .BI uuid= value Use the given value as the filesystem UUID for the newly created filesystem. The default is to generate a random UUID. +.TP +.BI rmapbt= value +This option enables the creation of a reverse-mapping btree index in each +allocation group. THe value is either 0 to disable the feature, or 1 to +create the btree. +.IP +The reverse mapping btree maps filesystem blocks to the owner of the +filesystem block. Most of the mappings will be to an inode number and an +offset, though there will also be mappings to filesystem metadata. This +secondary metadata can be used to validate the primary metadata or to +pinpoint exactly which data has been lost when a disk error occurs. +.IP +By default, +.B mkfs.xfs +will not create reverse mapping btrees. This feature is only available +for filesystems created with the (default) +.B \-m crc=1 +option set. When the option +.B \-m crc=0 +is used, the reverse mapping btree feature is not supported and is disabled. .RE .TP .BI \-d " data_section_options"
mkfs/xfs_mkfs.c +6 -1
@@ -3016,6 +3016,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), rrec->rm_startblock =0 ; rrec->rm_blockcount =cpu_to_be32 (XFS_BNO_BLOCK (mp)); rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_FS ); + rrec->rm_offset =0 ;be16_add_cpu (&block->bb_numrecs,1 );/* account freespace btree root blocks */
@@ -3023,6 +3024,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), rrec->rm_startblock =cpu_to_be32 (XFS_BNO_BLOCK (mp)); rrec->rm_blockcount =cpu_to_be32 (2 ); rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_AG ); + rrec->rm_offset =0 ;be16_add_cpu (&block->bb_numrecs,1 );/* account inode btree root blocks */
@@ -3031,6 +3033,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), rrec->rm_blockcount =cpu_to_be32 (XFS_RMAP_BLOCK (mp) -XFS_IBT_BLOCK (mp)); rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_INOBT ); + rrec->rm_offset =0 ;be16_add_cpu (&block->bb_numrecs,1 );/* account for rmap btree root */
@@ -3038,6 +3041,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), rrec->rm_startblock =cpu_to_be32 (XFS_RMAP_BLOCK (mp)); rrec->rm_blockcount =cpu_to_be32 (1 ); rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_AG ); + rrec->rm_offset =0 ;be16_add_cpu (&block->bb_numrecs,1 );/* account for the log space */
@@ -3047,6 +3051,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), XFS_FSB_TO_AGBNO(mp, logstart)); rrec->rm_blockcount =cpu_to_be32 (logblocks); rrec->rm_owner =cpu_to_be64 (XFS_RMAP_OWN_LOG ); + rrec->rm_offset =0 ;be16_add_cpu (&block->bb_numrecs,1 ); }
@@ -3290,7 +3295,7 @@ usage( void ) { fprintf(stderr, _("Usage: %s\n\ /* blocksize */ [-b log=n|size=num]\n\ -/* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx]\n\ +/* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx,rmapbt=0|1]\n\ /* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,\n\ (sunit=value,swidth=value|su=num,sw=num|noalign),\n\ sectlog=n|sectsize=num\n\
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 38/53 libxfs: add the refcount helper functions from the kernel
In reply to Darrick J. WongImport definitions and refcount helper code from the kernel. This is a separate patch to avoid blowing out the mail server...
--- libxfs/xfs_refcount.c | 1131 +++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_refcount.h | 45 ++ 2 files changed, 1176 insertions(+) create mode 100644 libxfs/xfs_refcount.c create mode 100644 libxfs/xfs_refcount.h
libxfs/xfs_refcount.c new file +1131 -0
@@ -0,0 +1,1131 @@ +/* +* Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. +* Copyright (c) 2015 Oracle. +* All Rights Reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +#include "libxfs_priv.h" +#include "xfs_fs.h" +#include "xfs_shared.h" +#include "xfs_format.h" +#include "xfs_log_format.h" +#include "xfs_trans_resv.h" +#include "xfs_sb.h" +#include "xfs_mount.h" +#include "xfs_btree.h" +#include "xfs_bmap.h" +#include "xfs_refcount_btree.h" +#include "xfs_alloc.h" +#include "xfs_trace.h" +#include "xfs_cksum.h" +#include "xfs_trans.h" +#include "xfs_bit.h" +#include "xfs_refcount.h" + +/** +* xfs_refcountbt_lookup_le() -- Look up the first record less than or equal to +* [bno, len] in the btree given by cur. +* @cur: refcount btree cursor +* @bno: AG block number to look up +* @stat: set to 1 if successful, 0 otherwise +*/ +int +xfs_refcountbt_lookup_le ( +struct xfs_btree_cur *cur, +xfs_agblock_t bno, +int *stat) +{ +trace_xfs_refcountbt_lookup (cur->bc_mp, cur->bc_private.a.agno, bno, +XFS_LOOKUP_LE ); + cur->bc_rec.rc.rc_startblock = bno; + cur->bc_rec.rc.rc_blockcount =0 ; +return xfs_btree_lookup (cur,XFS_LOOKUP_LE , stat); +} + +/** +* xfs_refcountbt_lookup_ge() -- Look up the first record greater than or equal +* to [bno, len] in the btree given by cur. +* @cur: refcount btree cursor +* @bno: AG block number to look up +* @stat: set to 1 if successful, 0 otherwise +*/ +int /* error */ +xfs_refcountbt_lookup_ge ( +struct xfs_btree_cur *cur,/* btree cursor */ +xfs_agblock_t bno,/* starting block of extent */ +int *stat)/* success/failure */ +{ +trace_xfs_refcountbt_lookup (cur->bc_mp, cur->bc_private.a.agno, bno, +XFS_LOOKUP_GE ); + cur->bc_rec.rc.rc_startblock = bno; + cur->bc_rec.rc.rc_blockcount =0 ; +return xfs_btree_lookup (cur,XFS_LOOKUP_GE , stat); +} + +/** +* xfs_refcountbt_get_rec() -- Get the data from the pointed-to record. +* +* @cur: refcount btree cursor +* @irec: set to the record currently pointed to by the btree cursor +* @stat: set to 1 if successful, 0 otherwise +*/ +int +xfs_refcountbt_get_rec ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *irec, +int *stat) +{ +union xfs_btree_rec *rec; +int error; + + error =xfs_btree_get_rec (cur, &rec, stat); +if (!error && *stat ==1 ) { + irec->rc_startblock =be32_to_cpu (rec->refc.rc_startblock); + irec->rc_blockcount =be32_to_cpu (rec->refc.rc_blockcount); + irec->rc_refcount =be32_to_cpu (rec->refc.rc_refcount); +trace_xfs_refcountbt_get (cur->bc_mp, cur->bc_private.a.agno, + irec); + } +return error; +} + +/* +* Update the record referred to by cur to the value given +* by [bno, len, refcount]. +* This either works (return 0) or gets an EFSCORRUPTED error. +*/ +STATIC int +xfs_refcountbt_update ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *irec) +{ +union xfs_btree_rec rec; + +trace_xfs_refcountbt_update (cur->bc_mp, cur->bc_private.a.agno, irec); + rec.refc.rc_startblock =cpu_to_be32 (irec->rc_startblock); + rec.refc.rc_blockcount =cpu_to_be32 (irec->rc_blockcount); + rec.refc.rc_refcount =cpu_to_be32 (irec->rc_refcount); +return xfs_btree_update (cur, &rec); +} + +/* +* Insert the record referred to by cur to the value given +* by [bno, len, refcount]. +* This either works (return 0) or gets an EFSCORRUPTED error. +*/ +STATIC int +xfs_refcountbt_insert ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *irec, +int *i) +{ +trace_xfs_refcountbt_insert (cur->bc_mp, cur->bc_private.a.agno, irec); + cur->bc_rec.rc.rc_startblock = irec->rc_startblock; + cur->bc_rec.rc.rc_blockcount = irec->rc_blockcount; + cur->bc_rec.rc.rc_refcount = irec->rc_refcount; +return xfs_btree_insert (cur, i); +} + +/* +* Remove the record referred to by cur, then set the pointer to the spot +* where the record could be re-inserted, in case we want to increment or +* decrement the cursor. +* This either works (return 0) or gets an EFSCORRUPTED error. +*/ +STATIC int +xfs_refcountbt_delete ( +struct xfs_btree_cur *cur, +int *i) +{ +struct xfs_refcount_irec irec; +int found_rec; +int error; + + error =xfs_refcountbt_get_rec (cur, &irec, &found_rec); +if (error) +return error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); +trace_xfs_refcountbt_delete (cur->bc_mp, cur->bc_private.a.agno, &irec); + error =xfs_btree_delete (cur, i); +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, *i ==1 , out_error); +if (error) +return error; + error =xfs_refcountbt_lookup_ge (cur, irec.rc_startblock, &found_rec); +out_error: +return error; +} + +/* +* Adjusting the Reference Count +* +* As stated elsewhere, the reference count btree (refcbt) stores +* >1 reference counts for extents of physical blocks. In this +* operation, we're either raising or lowering the reference count of +* some subrange stored in the tree: +* +* <------ adjustment range ------> +* ----+ +---+-----+ +--+--------+--------- +* 2 | | 3 | 4 | |17| 55 | 10 +* ----+ +---+-----+ +--+--------+--------- +* X axis is physical blocks number; +* reference counts are the numbers inside the rectangles +* +* The first thing we need to do is to ensure that there are no +* refcount extents crossing either boundary of the range to be +* adjusted. For any extent that does cross a boundary, split it into +* two extents so that we can increment the refcount of one of the +* pieces later: +* +* <------ adjustment range ------> +* ----+ +---+-----+ +--+--------+----+---- +* 2 | | 3 | 2 | |17| 55 | 10 | 10 +* ----+ +---+-----+ +--+--------+----+---- +* +* For this next step, let's assume that all the physical blocks in +* the adjustment range are mapped to a file and are therefore in use +* at least once. Therefore, we can infer that any gap in the +* refcount tree within the adjustment range represents a physical +* extent with refcount == 1: +* +* <------ adjustment range ------> +* ----+---+---+-----+-+--+--------+----+---- +* 2 |"1"| 3 | 2 |1|17| 55 | 10 | 10 +* ----+---+---+-----+-+--+--------+----+---- +* ^ +* +* For each extent that falls within the interval range, figure out +* which extent is to the left or the right of that extent. Now we +* have a left, current, and right extent. If the new reference count +* of the center extent enables us to merge left, center, and right +* into one record covering all three, do so. If the center extent is +* at the left end of the range, abuts the left extent, and its new +* reference count matches the left extent's record, then merge them. +* If the center extent is at the right end of the range, abuts the +* right extent, and the reference counts match, merge those. In the +* example, we can left merge (assuming an increment operation): +* +* <------ adjustment range ------> +* --------+---+-----+-+--+--------+----+---- +* 2 | 3 | 2 |1|17| 55 | 10 | 10 +* --------+---+-----+-+--+--------+----+---- +* ^ +* +* For all other extents within the range, adjust the reference count +* or delete it if the refcount falls below 2. If we were +* incrementing, the end result looks like this: +* +* <------ adjustment range ------> +* --------+---+-----+-+--+--------+----+---- +* 2 | 4 | 3 |2|18| 56 | 11 | 10 +* --------+---+-----+-+--+--------+----+---- +* +* The result of a decrement operation looks as such: +* +* <------ adjustment range ------> +* ----+ +---+ +--+--------+----+---- +* 2 | | 2 | |16| 54 | 9 | 10 +* ----+ +---+ +--+--------+----+---- +* DDDD 111111DD +* +* The blocks marked "D" are freed; the blocks marked "1" are only +* referenced once and therefore the record is removed from the +* refcount btree. +*/ + +#define RCNEXT (rc) ((rc).rc_startblock + (rc).rc_blockcount) +/* +* Split a left rcextent that crosses agbno. +*/ +STATIC int +try_split_left_rcextent ( +struct xfs_btree_cur *cur, +xfs_agblock_t agbno) +{ +struct xfs_refcount_irec left, tmp; +int found_rec; +int error; + + error =xfs_refcountbt_lookup_le (cur, agbno, &found_rec); +if (error) + goto out_error; +if (!found_rec) +return 0 ; + + error =xfs_refcountbt_get_rec (cur, &left, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); +if (left.rc_startblock >= agbno ||RCNEXT (left) <= agbno) +return 0 ; + +trace_xfs_refcount_split_left_extent (cur->bc_mp, cur->bc_private.a.agno, + &left, agbno); + tmp = left; + tmp.rc_blockcount = agbno - left.rc_startblock; + error =xfs_refcountbt_update (cur, &tmp); +if (error) + goto out_error; + + error =xfs_btree_increment (cur,0 , &found_rec); +if (error) + goto out_error; + + tmp = left; + tmp.rc_startblock = agbno; + tmp.rc_blockcount -= (agbno - left.rc_startblock); + error =xfs_refcountbt_insert (cur, &tmp, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); +return error; + +out_error: +trace_xfs_refcount_split_left_extent_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} + +/* +* Split a right rcextent that crosses agbno. +*/ +STATIC int +try_split_right_rcextent ( +struct xfs_btree_cur *cur, +xfs_agblock_t agbnext) +{ +struct xfs_refcount_irec right, tmp; +int found_rec; +int error; + + error =xfs_refcountbt_lookup_le (cur, agbnext -1 , &found_rec); +if (error) + goto out_error; +if (!found_rec) +return 0 ; + + error =xfs_refcountbt_get_rec (cur, &right, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); +if (RCNEXT (right) <= agbnext) +return 0 ; + +trace_xfs_refcount_split_right_extent (cur->bc_mp, + cur->bc_private.a.agno, &right, agbnext); + tmp = right; + tmp.rc_startblock = agbnext; + tmp.rc_blockcount -= (agbnext - right.rc_startblock); + error =xfs_refcountbt_update (cur, &tmp); +if (error) + goto out_error; + + tmp = right; + tmp.rc_blockcount = agbnext - right.rc_startblock; + error =xfs_refcountbt_insert (cur, &tmp, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); +return error; + +out_error: +trace_xfs_refcount_split_right_extent_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} + +/* +* Merge the left, center, and right extents. +*/ +STATIC int +merge_center ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *left, +struct xfs_refcount_irec *center, +unsigned long long extlen, +xfs_agblock_t *agbno, +xfs_extlen_t *aglen) +{ +int error; +int found_rec; + + error =xfs_refcountbt_lookup_ge (cur, center->rc_startblock, + &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); + + error =xfs_refcountbt_delete (cur, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); + +if (center->rc_refcount >1 ) { + error =xfs_refcountbt_delete (cur, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , + out_error); + } + + error =xfs_refcountbt_lookup_le (cur, left->rc_startblock, + &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); + + left->rc_blockcount = extlen; + error =xfs_refcountbt_update (cur, left); +if (error) + goto out_error; + + *aglen =0 ; +return error; + +out_error: +trace_xfs_refcount_merge_center_extents_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} + +/* +* Merge with the left extent. +*/ +STATIC int +merge_left ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *left, +struct xfs_refcount_irec *cleft, +xfs_agblock_t *agbno, +xfs_extlen_t *aglen) +{ +int error; +int found_rec; + +if (cleft->rc_refcount >1 ) { + error =xfs_refcountbt_lookup_le (cur, cleft->rc_startblock, + &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , + out_error); + + error =xfs_refcountbt_delete (cur, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , + out_error); + } + + error =xfs_refcountbt_lookup_le (cur, left->rc_startblock, + &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); + + left->rc_blockcount += cleft->rc_blockcount; + error =xfs_refcountbt_update (cur, left); +if (error) + goto out_error; + + *agbno += cleft->rc_blockcount; + *aglen -= cleft->rc_blockcount; +return error; + +out_error: +trace_xfs_refcount_merge_left_extent_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} + +/* +* Merge with the right extent. +*/ +STATIC int +merge_right ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *right, +struct xfs_refcount_irec *cright, +xfs_agblock_t *agbno, +xfs_extlen_t *aglen) +{ +int error; +int found_rec; + +if (cright->rc_refcount >1 ) { + error =xfs_refcountbt_lookup_le (cur, cright->rc_startblock, + &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , + out_error); + + error =xfs_refcountbt_delete (cur, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , + out_error); + } + + error =xfs_refcountbt_lookup_le (cur, right->rc_startblock, + &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); + + right->rc_startblock -= cright->rc_blockcount; + right->rc_blockcount += cright->rc_blockcount; + error =xfs_refcountbt_update (cur, right); +if (error) + goto out_error; + + *aglen -= cright->rc_blockcount; +return error; + +out_error: +trace_xfs_refcount_merge_right_extent_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} + +/* +* Find the left extent and the one after it (cleft). This function assumes +* that we've already split any extent crossing agbno. +*/ +STATIC int +find_left_extent ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *left, +struct xfs_refcount_irec *cleft, +xfs_agblock_t agbno, +xfs_extlen_t aglen) +{ +struct xfs_refcount_irec tmp; +int error; +int found_rec; + + left->rc_blockcount = cleft->rc_blockcount =0 ; + error =xfs_refcountbt_lookup_le (cur, agbno -1 , &found_rec); +if (error) + goto out_error; +if (!found_rec) +return 0 ; + + error =xfs_refcountbt_get_rec (cur, &tmp, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); + +if (RCNEXT (tmp) != agbno) +return 0 ; +/* We have a left extent; retrieve (or invent) the next right one */ + *left = tmp; + + error =xfs_btree_increment (cur,0 , &found_rec); +if (error) + goto out_error; +if (found_rec) { + error =xfs_refcountbt_get_rec (cur, &tmp, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , + out_error); + +/* if tmp starts at the end of our range, just use that */ +if (tmp.rc_startblock == agbno) + *cleft = tmp; +else { +/* +* There's a gap in the refcntbt at the start of the +* range we're interested in (refcount == 1) so +* create the implied extent and pass it back. +*/ + cleft->rc_startblock = agbno; + cleft->rc_blockcount =min (aglen, + tmp.rc_startblock - agbno); + cleft->rc_refcount =1 ; + } + }else { +/* +* No extents, so pretend that there's one covering the whole +* range. +*/ + cleft->rc_startblock = agbno; + cleft->rc_blockcount = aglen; + cleft->rc_refcount =1 ; + } +trace_xfs_refcount_find_left_extent (cur->bc_mp, cur->bc_private.a.agno, + left, cleft, agbno); +return error; + +out_error: +trace_xfs_refcount_find_left_extent_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} + +/* +* Find the right extent and the one before it (cright). This function +* assumes that we've already split any extents crossing agbno + aglen. +*/ +STATIC int +find_right_extent ( +struct xfs_btree_cur *cur, +struct xfs_refcount_irec *right, +struct xfs_refcount_irec *cright, +xfs_agblock_t agbno, +xfs_extlen_t aglen) +{ +struct xfs_refcount_irec tmp; +int error; +int found_rec; + + right->rc_blockcount = cright->rc_blockcount =0 ; + error =xfs_refcountbt_lookup_ge (cur, agbno + aglen, &found_rec); +if (error) + goto out_error; +if (!found_rec) +return 0 ; + + error =xfs_refcountbt_get_rec (cur, &tmp, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , out_error); + +if (tmp.rc_startblock != agbno + aglen) +return 0 ; +/* We have a right extent; retrieve (or invent) the next left one */ + *right = tmp; + + error =xfs_btree_decrement (cur,0 , &found_rec); +if (error) + goto out_error; +if (found_rec) { + error =xfs_refcountbt_get_rec (cur, &tmp, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, found_rec ==1 , + out_error); + +/* if tmp ends at the end of our range, just use that */ +if (RCNEXT (tmp) == agbno + aglen) + *cright = tmp; +else { +/* +* There's a gap in the refcntbt at the end of the +* range we're interested in (refcount == 1) so +* create the implied extent and pass it back. +*/ + cright->rc_startblock =max (agbno,RCNEXT (tmp)); + cright->rc_blockcount = right->rc_startblock - + cright->rc_startblock; + cright->rc_refcount =1 ; + } + }else { +/* +* No extents, so pretend that there's one covering the whole +* range. +*/ + cright->rc_startblock = agbno; + cright->rc_blockcount = aglen; + cright->rc_refcount =1 ; + } +trace_xfs_refcount_find_right_extent (cur->bc_mp, cur->bc_private.a.agno, + cright, right, agbno + aglen); +return error; + +out_error: +trace_xfs_refcount_find_right_extent_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} +#undef RCNEXT + +/* +* Try to merge with any extents on the boundaries of the adjustment range. +*/ +STATIC int +try_merge_rcextents ( +struct xfs_btree_cur *cur, +xfs_agblock_t *agbno, +xfs_extlen_t *aglen, +int adjust) +{ +struct xfs_refcount_irec left = {0 }, cleft = {0 }; +struct xfs_refcount_irec cright = {0 }, right = {0 }; +int error; +unsigned long long ulen; +bool cequal; + +/* +* Find the extent just below agbno [left], just above agbno [cleft], +* just below (agbno + aglen) [cright], and just above (agbno + aglen) +* [right]. +*/ + error =find_left_extent (cur, &left, &cleft, *agbno, *aglen); +if (error) +return error; + error =find_right_extent (cur, &right, &cright, *agbno, *aglen); +if (error) +return error; + +/* No left or right extent to merge; exit. */ +if (left.rc_blockcount ==0 && right.rc_blockcount ==0 ) +return 0 ; + + cequal = (cleft.rc_startblock == cright.rc_startblock) && + (cleft.rc_blockcount == cright.rc_blockcount); + +/* Try to merge left, cleft, and right. cleft must == cright. */ + ulen = (unsigned long long )left.rc_blockcount + cleft.rc_blockcount + + right.rc_blockcount; +if (left.rc_blockcount !=0 && right.rc_blockcount !=0 && + cleft.rc_blockcount !=0 && cright.rc_blockcount !=0 && + cequal && + left.rc_refcount == cleft.rc_refcount + adjust && + right.rc_refcount == cleft.rc_refcount + adjust && + ulen <MAXREFCEXTLEN ) { +trace_xfs_refcount_merge_center_extents (cur->bc_mp, + cur->bc_private.a.agno, &left, &cleft, &right); +return merge_center (cur, &left, &cleft, ulen, agbno, aglen); + } + +/* Try to merge left and cleft. */ + ulen = (unsigned long long )left.rc_blockcount + cleft.rc_blockcount; +if (left.rc_blockcount !=0 && cleft.rc_blockcount !=0 && + left.rc_refcount == cleft.rc_refcount + adjust && + ulen <MAXREFCEXTLEN ) { +trace_xfs_refcount_merge_left_extent (cur->bc_mp, + cur->bc_private.a.agno, &left, &cleft); + error =merge_left (cur, &left, &cleft, agbno, aglen); +if (error) +return error; + +/* +* If we just merged left + cleft and cleft == cright, +* we no longer have a cright to merge with right. We're done. +*/ +if (cequal) +return 0 ; + } + +/* Try to merge cright and right. */ + ulen = (unsigned long long )right.rc_blockcount + cright.rc_blockcount; +if (right.rc_blockcount !=0 && cright.rc_blockcount !=0 && + right.rc_refcount == cright.rc_refcount + adjust && + ulen <MAXREFCEXTLEN ) { +trace_xfs_refcount_merge_right_extent (cur->bc_mp, + cur->bc_private.a.agno, &cright, &right); +return merge_right (cur, &right, &cright, agbno, aglen); + } + +return error; +} + +/* +* Adjust the refcounts of middle extents. At this point we should have +* split extents that crossed the adjustment range; merged with adjacent +* extents; and updated agbno/aglen to reflect the merges. Therefore, +* all we have to do is update the extents inside [agbno, agbno + aglen]. +*/ +STATIC int +adjust_rcextents ( +struct xfs_btree_cur *cur, +xfs_agblock_t agbno, +xfs_extlen_t aglen, +int adj, +struct xfs_bmap_free *flist, +struct xfs_owner_info *oinfo) +{ +struct xfs_refcount_irec ext, tmp; +int error; +int found_rec, found_tmp; +xfs_fsblock_t fsbno; + + error =xfs_refcountbt_lookup_ge (cur, agbno, &found_rec); +if (error) + goto out_error; + +while (aglen >0 ) { + error =xfs_refcountbt_get_rec (cur, &ext, &found_rec); +if (error) + goto out_error; +if (!found_rec) { + ext.rc_startblock = cur->bc_mp->m_sb.sb_agblocks; + ext.rc_blockcount =0 ; + ext.rc_refcount =0 ; + } + +/* +* Deal with a hole in the refcount tree; if a file maps to +* these blocks and there's no refcountbt recourd, pretend that +* there is one with refcount == 1. +*/ +if (ext.rc_startblock != agbno) { + tmp.rc_startblock = agbno; + tmp.rc_blockcount =min (aglen, + ext.rc_startblock - agbno); + tmp.rc_refcount =1 + adj; +trace_xfs_refcount_modify_extent (cur->bc_mp, + cur->bc_private.a.agno, &tmp); + +/* +* Either cover the hole (increment) or +* delete the range (decrement). +*/ +if (tmp.rc_refcount) { + error =xfs_refcountbt_insert (cur, &tmp, + &found_tmp); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, + found_tmp ==1 , out_error); + }else { + fsbno =XFS_AGB_TO_FSB (cur->bc_mp, + cur->bc_private.a.agno, + tmp.rc_startblock); +xfs_bmap_add_free (cur->bc_mp, flist, fsbno, + tmp.rc_blockcount, oinfo); + } + + agbno += tmp.rc_blockcount; + aglen -= tmp.rc_blockcount; + + error =xfs_refcountbt_lookup_ge (cur, agbno, + &found_rec); +if (error) + goto out_error; + } + +/* Stop if there's nothing left to modify */ +if (aglen ==0 ) +break ; + +/* +* Adjust the reference count and either update the tree +* (incr) or free the blocks (decr). +*/ + ext.rc_refcount += adj; +trace_xfs_refcount_modify_extent (cur->bc_mp, + cur->bc_private.a.agno, &ext); +if (ext.rc_refcount >1 ) { + error =xfs_refcountbt_update (cur, &ext); +if (error) + goto out_error; + }else if (ext.rc_refcount ==1 ) { + error =xfs_refcountbt_delete (cur, &found_rec); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (cur->bc_mp, + found_rec ==1 , out_error); + goto advloop; + }else { + fsbno =XFS_AGB_TO_FSB (cur->bc_mp, + cur->bc_private.a.agno, + ext.rc_startblock); +xfs_bmap_add_free (cur->bc_mp, flist, fsbno, + ext.rc_blockcount, oinfo); + } + + error =xfs_btree_increment (cur,0 , &found_rec); +if (error) + goto out_error; + +advloop: + agbno += ext.rc_blockcount; + aglen -= ext.rc_blockcount; + } + +return error; +out_error: +trace_xfs_refcount_modify_extent_error (cur->bc_mp, + cur->bc_private.a.agno, error, _RET_IP_); +return error; +} + +/* +* Adjust the reference count of a range of AG blocks. +* +* @mp: XFS mount object +* @tp: XFS transaction object +* @agbp: Buffer containing the AGF +* @agno: AG number +* @agbno: Start of range to adjust +* @aglen: Length of range to adjust +* @adj: +1 to increment, -1 to decrement reference count +* @flist: freelist (only required if adj == -1) +* @owner: owner of the blocks (only required if adj == -1) +*/ +STATIC int +xfs_refcountbt_adjust_refcount ( +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_buf *agbp, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +xfs_extlen_t aglen, +int adj, +struct xfs_bmap_free *flist, +struct xfs_owner_info *oinfo) +{ +struct xfs_btree_cur *cur; +int error; + + cur =xfs_refcountbt_init_cursor (mp, tp, agbp, agno, flist); + +/* +* Ensure that no rcextents cross the boundary of the adjustment range. +*/ + error =try_split_left_rcextent (cur, agbno); +if (error) + goto out_error; + + error =try_split_right_rcextent (cur, agbno + aglen); +if (error) + goto out_error; + +/* +* Try to merge with the left or right extents of the range. +*/ + error =try_merge_rcextents (cur, &agbno, &aglen, adj); +if (error) + goto out_error; + +/* Now that we've taken care of the ends, adjust the middle extents */ + error =adjust_rcextents (cur, agbno, aglen, adj, flist, oinfo); +if (error) + goto out_error; + +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); +return 0 ; + +out_error: +trace_xfs_refcount_adjust_error (mp, agno, error, _RET_IP_); +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +return error; +} + +/** +* Increase the reference count of a range of AG blocks. +* +* @mp: XFS mount object +* @tp: XFS transaction object +* @agbp: Buffer containing the AGF +* @agno: AG number +* @agbno: Start of range to adjust +* @aglen: Length of range to adjust +* @flist: List of blocks to free +*/ +int +xfs_refcount_increase ( +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_buf *agbp, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +xfs_extlen_t aglen, +struct xfs_bmap_free *flist) +{ +trace_xfs_refcount_increase (mp, agno, agbno, aglen); +return xfs_refcountbt_adjust_refcount (mp, tp, agbp, agno, agbno, + aglen,1 , flist,NULL ); +} + +/** +* Decrease the reference count of a range of AG blocks. +* +* @mp: XFS mount object +* @tp: XFS transaction object +* @agbp: Buffer containing the AGF +* @agno: AG number +* @agbno: Start of range to adjust +* @aglen: Length of range to adjust +* @flist: List of blocks to free +* @owner: Extent owner +*/ +int +xfs_refcount_decrease ( +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_buf *agbp, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +xfs_extlen_t aglen, +struct xfs_bmap_free *flist, +struct xfs_owner_info *oinfo) +{ +trace_xfs_refcount_decrease (mp, agno, agbno, aglen); +return xfs_refcountbt_adjust_refcount (mp, tp, agbp, agno, agbno, + aglen,-1 , flist, oinfo); +} + +/** +* xfs_refcount_put_extent() - release a range of blocks +* +* @mp: XFS mount object +* @tp: transaction that goes with the free operation +* @flist: List of blocks to be freed at the end of the transaction +* @fsbno: First fs block of the range to release +* @len: Length of range +* @owner: owner of the extent +*/ +int +xfs_refcount_put_extent ( +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_bmap_free *flist, +xfs_fsblock_t fsbno, +xfs_filblks_t fslen, +struct xfs_owner_info *oinfo) +{ +int error; +struct xfs_buf *agbp; +xfs_agnumber_t agno;/* allocation group number */ +xfs_agblock_t agbno;/* ag start of range to free */ +xfs_extlen_t aglen;/* ag length of range to free */ + + agno =XFS_FSB_TO_AGNO (mp, fsbno); + agbno =XFS_FSB_TO_AGBNO (mp, fsbno); + aglen = fslen; + +/* +* Drop reference counts in the refcount tree. +*/ + error =xfs_alloc_read_agf (mp, tp, agno,0 , &agbp); +if (error) +return error; + + error =xfs_refcount_decrease (mp, tp, agbp, agno, agbno, aglen, flist, + oinfo); +xfs_trans_brelse (tp, agbp); +return error; +} + +/** +* xfs_refcount_find_shared() -- Given an AG extent, find the lowest-numbered +* run of shared blocks within that range. +* +* @mp: XFS mount. +* @agno: AG number. +* @agbno: AG block number to start searching. +* @aglen: Length of the range to search. +* @fbno: Returns the AG block number of the first shared range, or +* agbno + aglen if no shared blocks are found. +* @flen: Returns the length of the shared range found, or 0 if no shared +* blocks are found. +* @find_maximal: If true, find the length of the run of shared blocks. +* Otherwise, the length of the first refcount extent is found. +*/ +int +xfs_refcount_find_shared ( +struct xfs_mount *mp, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +xfs_extlen_t aglen, +xfs_agblock_t *fbno, +xfs_extlen_t *flen, +bool find_maximal) +{ +struct xfs_btree_cur *cur; +struct xfs_buf *agbp; +struct xfs_refcount_irec tmp; +int error; +int i, have; +int bt_error =XFS_BTREE_ERROR ; + +trace_xfs_refcount_find_shared (mp, agno, agbno, aglen); + + error =xfs_alloc_read_agf (mp,NULL , agno,0 , &agbp); +if (error) + goto out; + cur =xfs_refcountbt_init_cursor (mp,NULL , agbp, agno,NULL ); + +/* By default, skip the whole range */ + *fbno = agbno + aglen; + *flen =0 ; + +/* Try to find a refcount extent that crosses the start */ + error =xfs_refcountbt_lookup_le (cur, agbno, &have); +if (error) + goto out_error; +if (!have) { +/* No left extent, look at the next one */ + error =xfs_btree_increment (cur,0 , &have); +if (error) + goto out_error; +if (!have) + goto done; + } + error =xfs_refcountbt_get_rec (cur, &tmp, &i); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (mp, i ==1 , out_error); + +/* If the extent ends before the start, look at the next one */ +if (tmp.rc_startblock + tmp.rc_blockcount <= agbno) { + error =xfs_btree_increment (cur,0 , &have); +if (error) + goto out_error; +if (!have) + goto done; + error =xfs_refcountbt_get_rec (cur, &tmp, &i); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (mp, i ==1 , out_error); + } + +/* If the extent ends after the range we want, bail out */ +if (tmp.rc_startblock >= agbno + aglen) + goto done; + +/* We found the start of a shared extent! */ +if (tmp.rc_startblock < agbno) { + tmp.rc_blockcount -= (agbno - tmp.rc_startblock); + tmp.rc_startblock = agbno; + } + + *fbno = tmp.rc_startblock; + *flen =min (tmp.rc_blockcount, agbno + aglen - *fbno); +if (!find_maximal) + goto done; + +/* Otherwise, find the end of this shared extent */ +while (*fbno + *flen < agbno + aglen) { + error =xfs_btree_increment (cur,0 , &have); +if (error) + goto out_error; +if (!have) +break ; + error =xfs_refcountbt_get_rec (cur, &tmp, &i); +if (error) + goto out_error; +XFS_WANT_CORRUPTED_GOTO (mp, i ==1 , out_error); +if (tmp.rc_startblock >= agbno + aglen || + tmp.rc_startblock != *fbno + *flen) +break ; + *flen =min (*flen + tmp.rc_blockcount, agbno + aglen - *fbno); + } + +done: + bt_error =XFS_BTREE_NOERROR ; +trace_xfs_refcount_find_shared_result (mp, agno, *fbno, *flen); + +out_error: +xfs_btree_del_cursor (cur, bt_error); +xfs_buf_relse (agbp); +out: +if (error) +trace_xfs_refcount_find_shared_error (mp, agno, error, _RET_IP_); +return error; +}
libxfs/xfs_refcount.h new file +45 -0
45 lines not on this page · raw message
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 39/53 libxfs: add support for refcount btrees
In reply to Darrick J. WongImport definitions and refcount btree code from the kernel.
--- include/libxfs.h | 2 include/linux.h | 1 include/list.h | 3 include/xfs_inode.h | 8 + include/xfs_mount.h | 4 include/xfs_trace.h | 43 +++ libxfs/Makefile | 6 libxfs/xfs_alloc.c | 21 ++ libxfs/xfs_bmap.c | 364 ++++++++++++++++++++++++--- libxfs/xfs_bmap.h | 30 ++ libxfs/xfs_bmap_btree.c | 1 libxfs/xfs_btree.c | 8 - libxfs/xfs_btree.h | 7 + libxfs/xfs_format.h | 71 +++++ libxfs/xfs_fs.h | 1 libxfs/xfs_inode_fork.c | 72 +++++ libxfs/xfs_inode_fork.h | 28 ++ libxfs/xfs_perag_pool.c | 378 ++++++++++++++++++++++++++++ libxfs/xfs_perag_pool.h | 47 ++++ libxfs/xfs_refcount_btree.c | 576 +++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_refcount_btree.h | 71 +++++ libxfs/xfs_rmap.c | 2 libxfs/xfs_sb.c | 9 + libxfs/xfs_shared.h | 2 libxfs/xfs_types.h | 3 25 files changed, 1694 insertions(+), 64 deletions(-) create mode 100644 libxfs/xfs_perag_pool.c create mode 100644 libxfs/xfs_perag_pool.h create mode 100644 libxfs/xfs_refcount_btree.c create mode 100644 libxfs/xfs_refcount_btree.h
include/libxfs.h +2 -0
@@ -78,6 +78,8 @@ extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);#include "xfs_trace.h" #include "xfs_trans.h" #include "xfs_rmap_btree.h" +#include "xfs_refcount.h" +#include "xfs_refcount_btree.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]))
include/linux.h +1 -0
@@ -145,6 +145,7 @@ typedef loff_t xfs_off_t;typedef __uint64_t xfs_ino_t ;typedef __uint32_t xfs_dev_t ;typedef __int64_t xfs_daddr_t ; +typedef __uint32_t xfs_nlink_t ;/** * Abstraction of mountpoints.
include/list.h +3 -0
@@ -161,4 +161,7 @@ static inline void list_splice_init(struct list_head *list, &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) +#define list_first_entry (ptr, type, member) \ + list_entry((ptr)->next, type, member) +#endif /* __LIST_H__ */
include/xfs_inode.h +8 -0
@@ -38,6 +38,7 @@ typedef struct xfs_inode {struct xfs_imap i_imap;/* location for xfs_imap() */ struct xfs_buftarg i_dev;/* dev for this inode */ struct xfs_ifork *i_afp;/* attribute fork pointer */ +struct xfs_ifork *i_cowfp;/* copy on write extents */ struct xfs_ifork i_df;/* data fork */ struct xfs_trans *i_transp;/* ptr to owning transaction */ struct xfs_inode_log_item *i_itemp;/* logging information */
@@ -45,6 +46,8 @@ typedef struct xfs_inode {struct xfs_icdinode i_d;/* most of ondisk inode */ xfs_fsize_t i_size;/* in-memory size */ const struct xfs_dir_ops *d_ops;/* directory ops vector */ +xfs_extnum_t i_cnextents;/* # of extents in cow fork */ +unsigned int i_cformat;/* format of cow fork */ } xfs_inode_t;/*
@@ -81,6 +84,11 @@ xfs_set_projid(struct xfs_icdinode *id, prid_t projid) id->di_projid_lo = (__uint16_t) (projid &0xffff ); } +static inline bool xfs_is_reflink_inode (struct xfs_inode *ip) +{ +return ip->i_d.di_flags2 &XFS_DIFLAG2_REFLINK ; +} + typedef struct cred { uid_t cr_uid; gid_t cr_gid;
include/xfs_mount.h +4 -0
@@ -66,6 +66,8 @@ typedef struct xfs_mount {uint m_inobt_mnr[2 ];/* XFS_INOBT_BLOCK_MINRECS */ uint m_rmap_mxr[2 ];/* max rmap btree records */ uint m_rmap_mnr[2 ];/* min rmap btree records */ +uint m_refc_mxr[2 ];/* max refc btree records */ +uint m_refc_mnr[2 ];/* min refc btree records */ uint m_ag_maxlevels;/* XFS_AG_MAXLEVELS */ uint m_bm_maxlevels[2 ];/* XFS_BM_MAXLEVELS */ uint m_in_maxlevels;/* XFS_IN_MAXLEVELS */
@@ -140,6 +142,8 @@ typedef struct xfs_perag {xfs_agino_t pagl_leftrec;xfs_agino_t pagl_rightrec;int pagb_count;/* pagb slots in use */ +__uint8_t pagf_refcount_level; +struct xfs_perag_pool *pagf_refcountbt_pool; } xfs_perag_t;#define LIBXFS_MOUNT_DEBUGGER 0x0001
include/xfs_trace.h +43 -0
47 lines not on this page · raw message
libxfs/Makefile +6 -0
@@ -35,7 +35,10 @@ HFILES = \ xfs_inode_buf.h \ xfs_inode_fork.h \ xfs_quota_defs.h \ + xfs_perag_pool.h \ xfs_rmap_btree.h \ + xfs_refcount.h \ + xfs_refcount_btree.h \ xfs_sb.h \ xfs_shared.h \ xfs_trans_resv.h \
@@ -80,6 +83,9 @@ CFILES = cache.c \ xfs_inode_fork.c \ xfs_ialloc_btree.c \ xfs_log_rlimit.c \ + xfs_perag_pool.c \ + xfs_refcount.c \ + xfs_refcount_btree.c \ xfs_rtbitmap.c \ xfs_rmap.c \ xfs_rmap_btree.c \
libxfs/xfs_alloc.c +21 -0
@@ -32,6 +32,7 @@#include "xfs_cksum.h" #include "xfs_trace.h" #include "xfs_trans.h" +#include "xfs_refcount_btree.h" struct workqueue_struct *xfs_alloc_wq;
@@ -46,10 +47,23 @@ STATIC int xfs_alloc_ag_vextent_size(xfs_alloc_arg_t *); STATIC int xfs_alloc_ag_vextent_small(xfs_alloc_arg_t *,xfs_btree_cur_t *,xfs_agblock_t *,xfs_extlen_t *,int *); +unsigned int +xfs_refc_block ( +struct xfs_mount *mp) +{ +if (xfs_sb_version_hasrmapbt (&mp->m_sb)) +return XFS_RMAP_BLOCK (mp) +1 ; +if (xfs_sb_version_hasfinobt (&mp->m_sb)) +return XFS_FIBT_BLOCK (mp) +1 ; +return XFS_IBT_BLOCK (mp) +1 ; +} +xfs_extlen_t xfs_prealloc_blocks (struct xfs_mount *mp) { +if (xfs_sb_version_hasreflink (&mp->m_sb)) +return xfs_refc_block (mp) +1 ;if (xfs_sb_version_hasrmapbt (&mp->m_sb))return XFS_RMAP_BLOCK (mp) +1 ;if (xfs_sb_version_hasfinobt (&mp->m_sb))
@@ -119,6 +133,8 @@ xfs_alloc_ag_max_usable(struct xfs_mount *mp)/* rmap root block + full tree split on full AG */ blocks +=1 + (2 * mp->m_ag_maxlevels) -1 ; } +if (xfs_sb_version_hasreflink (&mp->m_sb)) + blocks +=xfs_refcountbt_max_btree_size (mp);return mp->m_sb.sb_agblocks - blocks; }
@@ -2409,6 +2425,10 @@ xfs_agf_verify( be32_to_cpu(agf->agf_btreeblks) > be32_to_cpu(agf->agf_length))return false; +if (xfs_sb_version_hasreflink (&mp->m_sb) && +be32_to_cpu (agf->agf_refcount_level) >XFS_BTREE_MAXLEVELS ) +return false; +return true;; }
@@ -2529,6 +2549,7 @@ xfs_alloc_read_agf(be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNTi]); pag->pagf_levels[XFS_BTNUM_RMAPi] =be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAPi]); + pag->pagf_refcount_level =be32_to_cpu (agf->agf_refcount_level);spin_lock_init (&pag->pagb_lock); pag->pagb_count =0 ;/* XXX: pagb_tree doesn't exist in userspace */
libxfs/xfs_bmap.c +319 -45
683 lines not on this page · raw message
libxfs/xfs_bmap.h +27 -3
@@ -118,6 +118,15 @@ typedef struct xfs_bmap_free* from written to unwritten, otherwise convert from unwritten to written. */ #define XFS_BMAPI_CONVERT 0x040 +/* +* Map the inode offset to the block given in ap->firstblock. Primarily +* used for reflink. The range must be in a hole, and this flag cannot be +* turned on with PREALLOC or CONVERT, and cannot be used on the attr fork. +*/ +#define XFS_BMAPI_REMAP 0x100 + +/* Map something in the CoW fork. */ +#define XFS_BMAPI_COWFORK 0x200#define XFS_BMAPI_FLAGS \ { XFS_BMAPI_ENTIRE, "ENTIRE" }, \
@@ -126,7 +135,9 @@ typedef struct xfs_bmap_free { XFS_BMAPI_PREALLOC, "PREALLOC" }, \ { XFS_BMAPI_IGSTATE, "IGSTATE" }, \ { XFS_BMAPI_CONTIG, "CONTIG" }, \ - { XFS_BMAPI_CONVERT, "CONVERT" } + { XFS_BMAPI_CONVERT, "CONVERT" }, \ + { XFS_BMAPI_REMAP, "REMAP" }, \ + { XFS_BMAPI_COWFORK, "COWFORK" } static inline int xfs_bmapi_aflag(int w)
@@ -134,6 +145,15 @@ static inline int xfs_bmapi_aflag(int w)return (w ==XFS_ATTR_FORK ?XFS_BMAPI_ATTRFORK :0 ); } +static inline int xfs_bmapi_whichfork (int bmapi_flags) +{ +if (bmapi_flags &XFS_BMAPI_COWFORK ) +return XFS_COW_FORK ; +else if (bmapi_flags &XFS_BMAPI_ATTRFORK ) +return XFS_ATTR_FORK ; +return XFS_DATA_FORK ; +} +/* * Special values for xfs_bmbt_irec_t br_startblock field. */
@@ -160,13 +180,15 @@ static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp)#define BMAP_LEFT_VALID (1 << 6)#define BMAP_RIGHT_VALID (1 << 7)#define BMAP_ATTRFORK (1 << 8) +#define BMAP_COWFORK (1 << 9)#define XFS_BMAP_EXT_FLAGS \ { BMAP_LEFT_CONTIG, "LC" }, \ { BMAP_RIGHT_CONTIG, "RC" }, \ { BMAP_LEFT_FILLING, "LF" }, \ { BMAP_RIGHT_FILLING, "RF" }, \ - { BMAP_ATTRFORK, "ATTR" } + { BMAP_ATTRFORK, "ATTR" }, \ + { BMAP_COWFORK, "COW" }/*
@@ -213,7 +235,7 @@ int xfs_bmap_read_extents(struct xfs_trans *tp, struct xfs_inode *ip,int xfs_bmapi_read (struct xfs_inode *ip,xfs_fileoff_t bno,xfs_filblks_t len,struct xfs_bmbt_irec *mval,int *nmap,int flags); -int xfs_bmapi_delay (struct xfs_inode *ip,xfs_fileoff_t bno, +int xfs_bmapi_delay (struct xfs_inode *ip,int whichfork,xfs_fileoff_t bno,xfs_filblks_t len,struct xfs_bmbt_irec *mval,int *nmap,int flags); int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip,
@@ -221,6 +243,8 @@ int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fsblock_t *firstblock, xfs_extlen_t total, struct xfs_bmbt_irec *mval, int *nmap, struct xfs_bmap_free *flist); +int xfs_bunmapi_cow (struct xfs_inode *ip,xfs_extnum_t *idx, +struct xfs_bmbt_irec *del); int xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip, xfs_fileoff_t bno, xfs_filblks_t len, int flags, xfs_extnum_t nexts, xfs_fsblock_t *firstblock,
libxfs/xfs_bmap_btree.c +1 -0
@@ -785,6 +785,7 @@ xfs_bmbt_init_cursor( {struct xfs_ifork *ifp =XFS_IFORK_PTR (ip, whichfork);struct xfs_btree_cur *cur; +ASSERT (whichfork !=XFS_COW_FORK ); cur =kmem_zone_zalloc (xfs_btree_cur_zone,KM_SLEEP );
libxfs/xfs_btree.c +6 -2
@@ -41,9 +41,10 @@ kmem_zone_t *xfs_btree_cur_zone;*/ static const __uint32_t xfs_magics[2 ][XFS_BTNUM_MAX ] = { {XFS_ABTB_MAGIC ,XFS_ABTC_MAGIC ,0 ,XFS_BMAP_MAGIC ,XFS_IBT_MAGIC , -XFS_FIBT_MAGIC }, +XFS_FIBT_MAGIC ,0 }, {XFS_ABTB_CRC_MAGIC ,XFS_ABTC_CRC_MAGIC ,XFS_RMAP_CRC_MAGIC , -XFS_BMAP_CRC_MAGIC ,XFS_IBT_CRC_MAGIC ,XFS_FIBT_CRC_MAGIC } +XFS_BMAP_CRC_MAGIC ,XFS_IBT_CRC_MAGIC ,XFS_FIBT_CRC_MAGIC , +XFS_REFC_CRC_MAGIC } };#define xfs_btree_magic (cur) \ xfs_magics[!!((cur)->bc_flags & XFS_BTREE_CRC_BLOCKS)][cur->bc_btnum]
@@ -1129,6 +1130,9 @@ xfs_btree_set_refs(case XFS_BTNUM_RMAP :xfs_buf_set_ref (bp,XFS_RMAP_BTREE_REF );break ; +case XFS_BTNUM_REFC : +xfs_buf_set_ref (bp,XFS_REFC_BTREE_REF ); +break ;default :ASSERT (0 ); }
libxfs/xfs_btree.h +7 -0
@@ -43,6 +43,7 @@ union xfs_btree_key {xfs_alloc_key_t alloc;struct xfs_inobt_key inobt;struct xfs_rmap_key rmap; +struct xfs_refcount_key refc; };union xfs_btree_rec {
@@ -51,6 +52,7 @@ union xfs_btree_rec {struct xfs_alloc_rec alloc;struct xfs_inobt_rec inobt;struct xfs_rmap_rec rmap; +struct xfs_refcount_rec refc; };/*
@@ -66,6 +68,7 @@ union xfs_btree_rec {#define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi)#define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi)#define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi) +#define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi)/* * For logging record fields.
@@ -98,6 +101,7 @@ do { \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_RMAP :__XFS_BTREE_STATS_INC (rmap, stat);break ; \ +case XFS_BTNUM_REFC :__XFS_BTREE_STATS_INC (refcbt, stat);break ; \case XFS_BTNUM_MAX :ASSERT (0 );/* fucking gcc */ ;break ; \ } \ }while (0 )
@@ -113,6 +117,7 @@ do { \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_RMAP :__XFS_BTREE_STATS_ADD (rmap, stat, val);break ; \ +case XFS_BTNUM_REFC :__XFS_BTREE_STATS_ADD (refcbt, stat, val);break ; \case XFS_BTNUM_MAX :ASSERT (0 );/* fucking gcc */ ;break ; \ } \ }while (0 )
@@ -205,6 +210,7 @@ typedef struct xfs_btree_curxfs_bmbt_irec_t b;xfs_inobt_rec_incore_t i;struct xfs_rmap_irec r; +struct xfs_refcount_irec rc; } bc_rec;/* current insert/search record value */ struct xfs_buf *bc_bufs[XFS_BTREE_MAXLEVELS ];/* buf ptr per level */ int bc_ptrs[XFS_BTREE_MAXLEVELS ];/* key/record # */
@@ -217,6 +223,7 @@ typedef struct xfs_btree_curunion {struct {/* needed for BNO, CNT, INO */ struct xfs_buf *agbp;/* agf/agi buffer pointer */ +struct xfs_bmap_free *flist;/* list to free after */ xfs_agnumber_t agno;/* ag number */ } a;struct {/* needed for BMAP */
libxfs/xfs_format.h +68 -3
114 lines not on this page · raw message
libxfs/xfs_fs.h +1 -0
@@ -67,6 +67,7 @@ struct fsxattr {#define XFS_XFLAG_EXTSZINHERIT 0x00001000/* inherit inode extent size */ #define XFS_XFLAG_NODEFRAG 0x00002000/* do not defragment */ #define XFS_XFLAG_FILESTREAM 0x00004000/* use filestream allocator */ +#define XFS_XFLAG_REFLINK 0x00008000/* file is reflinked */ #define XFS_XFLAG_HASATTR 0x80000000/* no DIFLAG for this */ /*
libxfs/xfs_inode_fork.c +68 -4
125 lines not on this page · raw message
libxfs/xfs_inode_fork.h +22 -6
@@ -92,7 +92,9 @@ typedef struct xfs_ifork {#define XFS_IFORK_PTR (ip,w) \ ((w) == XFS_DATA_FORK ? \ &(ip)->i_df : \ - (ip)->i_afp) + ((w) == XFS_ATTR_FORK ? \ + (ip)->i_afp : \ + (ip)->i_cowfp))#define XFS_IFORK_DSIZE (ip) \ (XFS_IFORK_Q(ip) ? \ XFS_IFORK_BOFF(ip) : \
@@ -105,26 +107,38 @@ typedef struct xfs_ifork {#define XFS_IFORK_SIZE (ip,w) \ ((w) == XFS_DATA_FORK ? \ XFS_IFORK_DSIZE(ip) : \ - XFS_IFORK_ASIZE(ip)) + ((w) == XFS_ATTR_FORK ? \ + XFS_IFORK_ASIZE(ip) : \ + 0))#define XFS_IFORK_FORMAT (ip,w) \ ((w) == XFS_DATA_FORK ? \ (ip)->i_d.di_format : \ - (ip)->i_d.di_aformat) + ((w) == XFS_ATTR_FORK ? \ + (ip)->i_d.di_aformat : \ + (ip)->i_cformat))#define XFS_IFORK_FMT_SET (ip,w,n) \ ((w) == XFS_DATA_FORK ? \ ((ip)->i_d.di_format = (n)) : \ - ((ip)->i_d.di_aformat = (n))) + ((w) == XFS_ATTR_FORK ? \ + ((ip)->i_d.di_aformat = (n)) : \ + ((ip)->i_cformat = (n))))#define XFS_IFORK_NEXTENTS (ip,w) \ ((w) == XFS_DATA_FORK ? \ (ip)->i_d.di_nextents : \ - (ip)->i_d.di_anextents) + ((w) == XFS_ATTR_FORK ? \ + (ip)->i_d.di_anextents : \ + (ip)->i_cnextents))#define XFS_IFORK_NEXT_SET (ip,w,n) \ ((w) == XFS_DATA_FORK ? \ ((ip)->i_d.di_nextents = (n)) : \ - ((ip)->i_d.di_anextents = (n))) + ((w) == XFS_ATTR_FORK ? \ + ((ip)->i_d.di_anextents = (n)) : \ + ((ip)->i_cnextents = (n))))#define XFS_IFORK_MAXEXT (ip, w) \ (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t)) +xfs_ifork_t *XFS_IEXT_STATE_TO_FORK (struct xfs_inode *ip,int state); +int xfs_iformat_fork (struct xfs_inode *,struct xfs_dinode *);void xfs_iflush_fork (struct xfs_inode *,struct xfs_dinode *,struct xfs_inode_log_item *,int );
@@ -168,4 +182,6 @@ void xfs_iext_irec_update_extoffs(struct xfs_ifork *, int, int);extern struct kmem_zone *xfs_ifork_zone; +extern void xfs_ifork_init_cow (struct xfs_inode *ip); +#endif /* __XFS_INODE_FORK_H__ */
libxfs/xfs_perag_pool.c new file +378 -0
378 lines not on this page · raw message
libxfs/xfs_perag_pool.h new file +47 -0
47 lines not on this page · raw message
libxfs/xfs_refcount_btree.c new file +576 -0
576 lines not on this page · raw message
libxfs/xfs_refcount_btree.h new file +71 -0
71 lines not on this page · raw message
libxfs/xfs_rmap.c +2 -0
@@ -1073,6 +1073,8 @@ __xfs_rmap_add(if (!xfs_sb_version_hasrmapbt (&mp->m_sb))return 0 ; +if (ri->ri_whichfork ==XFS_COW_FORK ) +return 0 ; new =kmem_zalloc (sizeof (struct xfs_rmap_intent ),KM_SLEEP |KM_NOFS ); *new = *ri;
libxfs/xfs_sb.c +9 -0
@@ -34,6 +34,8 @@#include "xfs_alloc_btree.h" #include "xfs_ialloc_btree.h" #include "xfs_rmap_btree.h" +#include "xfs_bmap.h" +#include "xfs_refcount_btree.h" /* * Physical superblock buffer manipulations. Shared with libxfs in userspace.
@@ -717,6 +719,13 @@ xfs_sb_mount_common( mp->m_rmap_mnr[0 ] = mp->m_rmap_mxr[0 ] /2 ; mp->m_rmap_mnr[1 ] = mp->m_rmap_mxr[1 ] /2 ; + mp->m_refc_mxr[0 ] =xfs_refcountbt_maxrecs (mp, sbp->sb_blocksize, + true); + mp->m_refc_mxr[1 ] =xfs_refcountbt_maxrecs (mp, sbp->sb_blocksize, + false); + mp->m_refc_mnr[0 ] = mp->m_refc_mxr[0 ] /2 ; + mp->m_refc_mnr[1 ] = mp->m_refc_mxr[1 ] /2 ; + mp->m_bsize =XFS_FSB_TO_BB (mp,1 ); mp->m_ialloc_inos = (int )MAX ((__uint16_t )XFS_INODES_PER_CHUNK , sbp->sb_inopblock);
libxfs/xfs_shared.h +2 -0
@@ -39,6 +39,7 @@ extern const struct xfs_buf_ops xfs_agf_buf_ops;extern const struct xfs_buf_ops xfs_agfl_buf_ops;extern const struct xfs_buf_ops xfs_allocbt_buf_ops;extern const struct xfs_buf_ops xfs_rmapbt_buf_ops; +extern const struct xfs_buf_ops xfs_refcountbt_buf_ops;extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;extern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;extern const struct xfs_buf_ops xfs_bmbt_buf_ops;
@@ -216,6 +217,7 @@ int xfs_log_calc_minimum_size(struct xfs_mount *);#define XFS_INO_REF 2#define XFS_ATTR_BTREE_REF 1#define XFS_DQUOT_REF 1 +#define XFS_REFC_BTREE_REF 1/* * Flags for xfs_trans_ichgtime().
libxfs/xfs_types.h +2 -1
@@ -93,6 +93,7 @@ typedef __int64_t xfs_sfiloff_t; /* signed block number in a file */*/ #define XFS_DATA_FORK 0#define XFS_ATTR_FORK 1 +#define XFS_COW_FORK 2/* * Min numbers of data/attr fork btree root pointers.
@@ -112,7 +113,7 @@ typedef enum {typedef enum { XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi, - XFS_BTNUM_INOi, XFS_BTNUM_FINOi,XFS_BTNUM_MAX + XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi,XFS_BTNUM_MAX }xfs_btnum_t ;struct xfs_name {
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 40/53 xfs_db: dump refcount btree data
In reply to Darrick J. WongAdd the ability to walk and dump the refcount btree in xfs_db.
--- db/agf.c | 10 ++++++++-- db/btblock.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ db/btblock.h | 5 +++++ db/field.c | 9 +++++++++ db/field.h | 4 ++++ db/inode.c | 3 +++ db/sb.c | 2 ++ db/type.c | 5 +++++ db/type.h | 2 +- man/man8/xfs_db.8 | 45 ++++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 131 insertions(+), 4 deletions(-)
db/agf.c +8 -2
@@ -47,7 +47,7 @@ const field_t agf_flds[] = { { "versionnum", FLDT_UINT32D, OI(OFF(versionnum)), C1, 0, TYP_NONE }, { "seqno", FLDT_AGNUMBER, OI(OFF(seqno)), C1, 0, TYP_NONE }, { "length", FLDT_AGBLOCK, OI(OFF(length)), C1, 0, TYP_NONE }, - { "roots", FLDT_AGBLOCK, OI(OFF(roots)), CI(XFS_BTNUM_AGF), + { "roots", FLDT_AGBLOCK, OI(OFF(roots)), CI(XFS_BTNUM_AGF) + 1, FLD_ARRAY|FLD_SKIPALL, TYP_NONE }, { "bnoroot", FLDT_AGBLOCK, OI(OFF(roots) + XFS_BTNUM_BNO * SZ(roots[XFS_BTNUM_BNO])), C1, 0,
@@ -58,7 +58,10 @@ const field_t agf_flds[] = { {"rmaproot" ,FLDT_AGBLOCKNZ ,OI (OFF (roots) +XFS_BTNUM_RMAP *SZ (roots[XFS_BTNUM_RMAP ])),C1 ,0 , TYP_RMAPBT }, - { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF), + { "refcntroot", FLDT_AGBLOCKNZ, +OI (OFF (refcount_root)),C1 ,0 , + TYP_REFCBT }, + { "levels", FLDT_UINT32D, OI(OFF(levels)), CI(XFS_BTNUM_AGF) + 1, FLD_ARRAY|FLD_SKIPALL, TYP_NONE }, { "bnolevel", FLDT_UINT32D, OI(OFF(levels) + XFS_BTNUM_BNO * SZ(levels[XFS_BTNUM_BNO])), C1, 0,
@@ -69,6 +72,9 @@ const field_t agf_flds[] = { {"rmaplevel" ,FLDT_UINT32D ,OI (OFF (levels) +XFS_BTNUM_RMAP *SZ (levels[XFS_BTNUM_RMAP ])),C1 ,0 , TYP_NONE }, + { "refcntlevel", FLDT_UINT32D, +OI (OFF (refcount_level)),C1 ,0 , + TYP_NONE }, { "flfirst", FLDT_UINT32D, OI(OFF(flfirst)), C1, 0, TYP_NONE }, { "fllast", FLDT_UINT32D, OI(OFF(fllast)), C1, 0, TYP_NONE }, { "flcount", FLDT_UINT32D, OI(OFF(flcount)), C1, 0, TYP_NONE },
db/btblock.c +50 -0
59 lines not on this page · raw message
db/btblock.h +5 -0
@@ -59,4 +59,9 @@ extern const struct field rmapbt_crc_hfld[];extern const struct field rmapbt_key_flds[];extern const struct field rmapbt_rec_flds[]; +extern const struct field refcbt_crc_flds[]; +extern const struct field refcbt_crc_hfld[]; +extern const struct field refcbt_key_flds[]; +extern const struct field refcbt_rec_flds[]; +extern int btblock_size (void *obj,int startoff,int idx);
db/field.c +9 -0
@@ -183,6 +183,15 @@ const ftattr_t ftattrtab[] = { {FLDT_RMAPBTREC ,"rmapbtrec" , fp_sarray, (char *)rmapbt_rec_flds, SI(bitsz(struct xfs_rmap_rec)), 0, NULL, rmapbt_rec_flds }, + { FLDT_REFCBT_CRC, "refcntbt", NULL, (char *)refcbt_crc_flds, btblock_size, + FTARG_SIZE, NULL, refcbt_crc_flds }, + { FLDT_REFCBTKEY, "refcntbtkey", fp_sarray, (char *)refcbt_key_flds, + SI(bitsz(struct xfs_refcount_key)), 0, NULL, refcbt_key_flds }, + { FLDT_REFCBTPTR, "refcntbtptr", fp_num, "%u", SI(bitsz(xfs_refcount_ptr_t)), + 0, fa_agblock, NULL }, + { FLDT_REFCBTREC, "refcntbtrec", fp_sarray, (char *)refcbt_rec_flds, + SI(bitsz(struct xfs_refcount_rec)), 0, NULL, refcbt_rec_flds }, +/* CRC field */ { FLDT_CRC, "crc", fp_crc, "%#x (%s)", SI(bitsz(__uint32_t)), 0, NULL, NULL },
db/field.h +4 -0
@@ -89,6 +89,10 @@ typedef enum fldt {FLDT_RMAPBTKEY ,FLDT_RMAPBTPTR ,FLDT_RMAPBTREC , +FLDT_REFCBT_CRC , +FLDT_REFCBTKEY , +FLDT_REFCBTPTR , +FLDT_REFCBTREC ,/* CRC field type */ FLDT_CRC,
db/inode.c +3 -0
@@ -175,6 +175,9 @@ const field_t inode_v3_flds[] = { { "crtime", FLDT_TIMESTAMP, OI(COFF(crtime)), C1, 0, TYP_NONE }, { "inumber", FLDT_INO, OI(COFF(ino)), C1, 0, TYP_NONE }, { "uuid", FLDT_UUID, OI(COFF(uuid)), C1, 0, TYP_NONE }, + { "reflink", FLDT_UINT1, +OI (COFF (flags2) +bitsz (__uint64_t) -XFS_DIFLAG2_REFLINK_BIT -1 ),C1 , + 0, TYP_NONE }, { NULL } };
db/sb.c +2 -0
@@ -694,6 +694,8 @@ version_string(strcat (s,",SPARSE_INODES" );if (xfs_sb_version_hasmetauuid (sbp))strcat (s,",META_UUID" ); +if (xfs_sb_version_hasreflink (sbp)) +strcat (s,",REFLINK" );return s; }
db/type.c +5 -0
@@ -59,6 +59,7 @@ static const typ_t __typtab[] = { { TYP_BNOBT, "bnobt", handle_struct, bnobt_hfld, NULL }, { TYP_CNTBT, "cntbt", handle_struct, cntbt_hfld, NULL }, { TYP_RMAPBT, NULL }, + { TYP_REFCBT, NULL }, { TYP_DATA, "data", handle_block, NULL, NULL }, { TYP_DIR2, "dir2", handle_struct, dir2_hfld, NULL }, { TYP_DQBLK, "dqblk", handle_struct, dqblk_hfld, NULL },
@@ -91,6 +92,8 @@ static const typ_t __typtab_crc[] = { &xfs_allocbt_buf_ops }, {TYP_RMAPBT ,"rmapbt" , handle_struct, rmapbt_crc_hfld, &xfs_rmapbt_buf_ops }, + { TYP_REFCBT, "refcntbt", handle_struct, refcbt_crc_hfld, + &xfs_refcountbt_buf_ops }, { TYP_DATA, "data", handle_block, NULL, NULL }, { TYP_DIR2, "dir3", handle_struct, dir3_hfld, &xfs_dir3_db_buf_ops },
@@ -129,6 +132,8 @@ static const typ_t __typtab_spcrc[] = { &xfs_allocbt_buf_ops }, {TYP_RMAPBT ,"rmapbt" , handle_struct, rmapbt_crc_hfld, &xfs_rmapbt_buf_ops }, + { TYP_REFCBT, "refcntbt", handle_struct, refcbt_crc_hfld, + &xfs_refcountbt_buf_ops }, { TYP_DATA, "data", handle_block, NULL, NULL }, { TYP_DIR2, "dir3", handle_struct, dir3_hfld, &xfs_dir3_db_buf_ops },
db/type.h +1 -1
@@ -24,7 +24,7 @@ struct field; typedef enum typnm { TYP_AGF, TYP_AGFL, TYP_AGI, TYP_ATTR, TYP_BMAPBTA, - TYP_BMAPBTD, TYP_BNOBT, TYP_CNTBT, TYP_RMAPBT, TYP_DATA, + TYP_BMAPBTD, TYP_BNOBT, TYP_CNTBT, TYP_RMAPBT, TYP_REFCBT, TYP_DATA, TYP_DIR2, TYP_DQBLK, TYP_INOBT, TYP_INODATA, TYP_INODE, TYP_LOG, TYP_RTBITMAP, TYP_RTSUMMARY, TYP_SB, TYP_SYMLINK, TYP_TEXT, TYP_FINOBT, TYP_NONE
man/man8/xfs_db.8 +44 -1
57 lines not on this page · raw message
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 41/53 xfs_db: add support for checking the refcount btree
In reply to Darrick J. WongDo some basic checks of the refcount btree. xfs_repair will have to check that the reference counts match the various bmbt mappings.
--- db/check.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 128 insertions(+), 8 deletions(-)
db/check.c +128 -8
@@ -44,7 +44,8 @@ typedef enum {DBM_FREE1 ,DBM_FREE2 ,DBM_FREELIST ,DBM_INODE ,DBM_LOG ,DBM_MISSING ,DBM_QUOTA ,DBM_RTBITMAP ,DBM_RTDATA ,DBM_RTFREE ,DBM_RTSUM ,DBM_SB , -DBM_SYMLINK ,DBM_BTFINO ,DBM_BTRMAP , +DBM_SYMLINK ,DBM_BTFINO ,DBM_BTRMAP ,DBM_BTREFC , +DBM_RLDATA , DBM_NDBM } dbm_t;
@@ -52,7 +53,8 @@ typedef struct inodata {struct inodata *next;nlink_t link_set;nlink_t link_add; -char isdir; + char isdir:1; + char isreflink:1;char security;char ilist;xfs_ino_t ino;
@@ -172,6 +174,8 @@ static const char *typename[] = {"symlink" ,"btfino" ,"btrmap" , +"btrefcnt" , +"rldata" , NULL };static int verbose;
@@ -229,7 +233,8 @@ static int blocktrash_f(int argc, char **argv);static int blockuse_f (int argc,char **argv);static int check_blist (xfs_fsblock_t bno);static void check_dbmap (xfs_agnumber_t agno,xfs_agblock_t agbno, -xfs_extlen_t len,dbm_t type); +xfs_extlen_t len,dbm_t type, +int ignore_reflink);static int check_inomap (xfs_agnumber_t agno,xfs_agblock_t agbno,xfs_extlen_t len,xfs_ino_t c_ino);static void check_linkcounts (xfs_agnumber_t agno);
@@ -353,6 +358,9 @@ static void scanfunc_fino(struct xfs_btree_block *block, int level,static void scanfunc_rmap (struct xfs_btree_block *block,int level,struct xfs_agf *agf,xfs_agblock_t bno,int isroot); +static void scanfunc_refcnt (struct xfs_btree_block *block,int level, +struct xfs_agf *agf,xfs_agblock_t bno, +int isroot);static void set_dbmap (xfs_agnumber_t agno,xfs_agblock_t agbno,xfs_extlen_t len,dbm_t type,xfs_agnumber_t c_agno,xfs_agblock_t c_agbno);
@@ -1055,6 +1063,7 @@ blocktrash_f( (1 <<DBM_SYMLINK ) | (1 <<DBM_BTFINO ) | (1 <<DBM_BTRMAP ) | + (1 <<DBM_BTREFC ) | (1 <<DBM_SB );while ((c =getopt (argc, argv,"0123n:o:s:t:x:y:z" )) !=EOF ) {switch (c) {
@@ -1291,18 +1300,25 @@ check_dbmap(xfs_agnumber_t agno, xfs_agblock_t agbno, xfs_extlen_t len, - dbm_t type) + dbm_t type, + int ignore_reflink) { xfs_extlen_t i;char *p; +dbm_t d;for (i =0 , p = &dbmap[agno][agbno]; i < len; i++, p++) { + d = (dbm_t)*p; +if (ignore_reflink && (d ==DBM_UNKNOWN || d ==DBM_DATA || + d ==DBM_RLDATA )) +continue ;if ((dbm_t)*p != type) { -if (!sflag ||CHECK_BLISTA (agno, agbno + i)) +if (!sflag ||CHECK_BLISTA (agno, agbno + i)) {dbprintf (_ ("block %u/%u expected type %s got " "%s\n" ), agno, agbno + i, typename[type], typename[(dbm_t)*p]); + } error++; } }
@@ -1336,7 +1352,7 @@ check_inomap(return 0 ; }for (i =0 , rval =1 , idp = &inomap[agno][agbno]; i < len; i++, idp++) { -if (*idp) { +if (*idp && !(*idp)->isreflink) {if (!sflag || (*idp)->ilist ||CHECK_BLISTA (agno, agbno + i)) dbprintf(_("block %u/%u claimed by inode %lld, "
@@ -1542,6 +1558,26 @@ check_rrange(return 1 ; } +/* +* We don't check the accuracy of reference counts -- all we do is ensure +* that a data block never crosses with non-data blocks. repair can check +* those kinds of things. +* +* So with that in mind, if we're setting a block to be data or rldata, +* don't complain so long as the block is currently unknown, data, or rldata. +* Don't let blocks downgrade from rldata -> data. +*/ +static bool +is_reflink ( +dbm_t type2) +{ +if (!xfs_sb_version_hasreflink (&mp->m_sb)) +return false; +if (type2 ==DBM_DATA || type2 ==DBM_RLDATA ) +return true; +return false; +} + static void check_set_dbmap( xfs_agnumber_t agno,
@@ -1561,10 +1597,15 @@ check_set_dbmap( agbno, agbno + len - 1, c_agno, c_agbno);return ; } -check_dbmap (agno, agbno, len, type1); +check_dbmap (agno, agbno, len, type1,is_reflink (type2)); mayprint = verbose | blist_size;for (i =0 , p = &dbmap[agno][agbno]; i < len; i++, p++) { - *p = (char )type2; +if (*p ==DBM_RLDATA && type2 ==DBM_DATA ) + ;/* do nothing */ +if (*p ==DBM_DATA && type2 ==DBM_DATA ) + *p = (char )DBM_RLDATA ; +else + *p = (char )type2;if (mayprint && (verbose ||CHECK_BLISTA (agno, agbno + i)))dbprintf (_ ("setting block %u/%u to %s\n" ), agno, agbno + i, typename[type2]);
@@ -2806,6 +2847,7 @@ process_inode( type =DBM_UNKNOWN ;break ; } + id->isreflink = !!(idic.di_flags2 &XFS_DIFLAG2_REFLINK );if (idic.di_version ==1 )setlink_inode (id, idic.di_onlink, type ==DBM_DIR , security);else {
@@ -3918,6 +3960,12 @@ scan_ag(be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]), 1, scanfunc_rmap, TYP_RMAPBT); } +if (agf->agf_refcount_root) { +scan_sbtree (agf, +be32_to_cpu (agf->agf_refcount_root), +be32_to_cpu (agf->agf_refcount_level), +1 , scanfunc_refcnt,TYP_REFCBT ); + } scan_sbtree(agf, be32_to_cpu(agi->agi_root), be32_to_cpu(agi->agi_level),
@@ -4741,6 +4789,78 @@ scanfunc_rmap( }static void +scanfunc_refcnt ( +struct xfs_btree_block *block, +int level, +struct xfs_agf *agf, +xfs_agblock_t bno, +int isroot) +{ +xfs_agnumber_t seqno =be32_to_cpu (agf->agf_seqno); +int i; +xfs_refcount_ptr_t *pp; +struct xfs_refcount_rec *rp; +xfs_agblock_t lastblock; + +if (be32_to_cpu (block->bb_magic) !=XFS_REFC_CRC_MAGIC ) { +dbprintf (_ ("bad magic # %#x in refcntbt block %u/%u\n" ), +be32_to_cpu (block->bb_magic), seqno, bno); + serious_error++; +return ; + } +if (be16_to_cpu (block->bb_level) != level) { +if (!sflag) +dbprintf (_ ("expected level %d got %d in refcntbt block " +"%u/%u\n" ), + level,be16_to_cpu (block->bb_level), seqno, bno); + error++; + } +set_dbmap (seqno, bno,1 ,DBM_BTREFC , seqno, bno); +if (level ==0 ) { +if (be16_to_cpu (block->bb_numrecs) > mp->m_refc_mxr[0 ] || + (isroot ==0 &&be16_to_cpu (block->bb_numrecs) < mp->m_refc_mnr[0 ])) { +dbprintf (_ ("bad btree nrecs (%u, min=%u, max=%u) in " +"refcntbt block %u/%u\n" ), +be16_to_cpu (block->bb_numrecs), mp->m_refc_mnr[0 ], + mp->m_refc_mxr[0 ], seqno, bno); + serious_error++; +return ; + } + rp =XFS_REFCOUNT_REC_ADDR (block,1 ); + lastblock =0 ; +for (i =0 ; i <be16_to_cpu (block->bb_numrecs); i++) { +set_dbmap (seqno,be32_to_cpu (rp[i].rc_startblock), +be32_to_cpu (rp[i].rc_blockcount),DBM_RLDATA , + seqno, bno); +if (be32_to_cpu (rp[i].rc_startblock) < lastblock) { +dbprintf (_ ( +"out-of-order refcnt btree record %d (%u %u) block %u/%u\n" ), + i,be32_to_cpu (rp[i].rc_startblock), +be32_to_cpu (rp[i].rc_startblock), +be32_to_cpu (agf->agf_seqno), bno); + }else { + lastblock =be32_to_cpu (rp[i].rc_startblock) + +be32_to_cpu (rp[i].rc_blockcount); + } + } +return ; + } +if (be16_to_cpu (block->bb_numrecs) > mp->m_refc_mxr[1 ] || + (isroot ==0 &&be16_to_cpu (block->bb_numrecs) < mp->m_refc_mnr[1 ])) { +dbprintf (_ ("bad btree nrecs (%u, min=%u, max=%u) in refcntbt " +"block %u/%u\n" ), +be16_to_cpu (block->bb_numrecs), mp->m_refc_mnr[1 ], + mp->m_refc_mxr[1 ], seqno, bno); + serious_error++; +return ; + } + pp =XFS_REFCOUNT_PTR_ADDR (block,1 , mp->m_refc_mxr[1 ]); +for (i =0 ; i <be16_to_cpu (block->bb_numrecs); i++) +scan_sbtree (agf,be32_to_cpu (pp[i]), level,0 , scanfunc_refcnt, +TYP_REFCBT ); +} + +static void set_dbmap( xfs_agnumber_t agno, xfs_agblock_t agbno,
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 42/53 xfs_db: metadump should copy the refcount btree too
In reply to Darrick J. WongTeach metadump to copy the refcount btree.
--- db/metadump.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
db/metadump.c +74 -0
@@ -596,6 +596,78 @@ copy_rmap_btree(return scan_btree (agno, root, levels,TYP_RMAPBT , agf, scanfunc_rmapbt); } +static int +scanfunc_refcntbt ( +struct xfs_btree_block *block, +xfs_agnumber_t agno, +xfs_agblock_t agbno, +int level, +typnm_t btype, +void *arg) +{ +xfs_refcount_ptr_t *pp; +int i; +int numrecs; + +if (level ==0 ) +return 1 ; + + numrecs =be16_to_cpu (block->bb_numrecs); +if (numrecs > mp->m_refc_mxr[1 ]) { +if (show_warnings) +print_warning ("invalid numrecs (%u) in %s block %u/%u" , + numrecs, typtab[btype].name, agno, agbno); +return 1 ; + } + + pp =XFS_REFCOUNT_PTR_ADDR (block,1 , mp->m_refc_mxr[1 ]); +for (i =0 ; i < numrecs; i++) { +if (!valid_bno (agno,be32_to_cpu (pp[i]))) { +if (show_warnings) +print_warning ("invalid block number (%u/%u) " +"in %s block %u/%u" , + agno,be32_to_cpu (pp[i]), + typtab[btype].name, agno, agbno); +continue ; + } +if (!scan_btree (agno,be32_to_cpu (pp[i]), level, btype, arg, + scanfunc_refcntbt)) +return 0 ; + } +return 1 ; +} + +static int +copy_refcount_btree ( +xfs_agnumber_t agno, +struct xfs_agf *agf) +{ +xfs_agblock_t root; +int levels; + +if (!xfs_sb_version_hasreflink (&mp->m_sb)) +return 1 ; + + root =be32_to_cpu (agf->agf_refcount_root); + levels =be32_to_cpu (agf->agf_refcount_level); + +/* validate root and levels before processing the tree */ +if (root ==0 || root > mp->m_sb.sb_agblocks) { +if (show_warnings) +print_warning ("invalid block number (%u) in refcntbt " +"root in agf %u" , root, agno); +return 1 ; + } +if (levels >=XFS_BTREE_MAXLEVELS ) { +if (show_warnings) +print_warning ("invalid level (%u) in refcntbt root " +"in agf %u" , levels, agno); +return 1 ; + } + +return scan_btree (agno, root, levels,TYP_REFCBT , agf, scanfunc_refcntbt); +} +/* filename and extended attribute obfuscation routines */ struct name_ent {
@@ -2506,6 +2578,8 @@ scan_ag( goto pop_out;if (!copy_rmap_btree (agno, agf)) goto pop_out; +if (!copy_refcount_btree (agno, agf)) + goto pop_out; }/* copy inode btrees and the inodes and their associated metadata */
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 43/53 xfs_growfs: report the presence of the reflink feature
In reply to Darrick J. WongReport the presence of the reflink feature in xfs_info.
--- growfs/xfs_growfs.c | 12 +++++++++--- libxfs/xfs_fs.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-)
growfs/xfs_growfs.c +9 -3
@@ -59,12 +59,14 @@ report_info( int ftype_enabled, int finobt_enabled, int spinodes, - int rmapbt_enabled) + int rmapbt_enabled, + int reflink_enabled) { printf(_("meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n" " =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n" " =%-22s crc=%-8u finobt=%u spinodes=%u rmapbt=%u\n" +" =%-22s reflink=%u\n" "data =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n" " =%-22s sunit=%-6u swidth=%u blks\n" "naming =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
@@ -75,6 +77,7 @@ report_info( mntpoint, geo.inodesize, geo.agcount, geo.agblocks,"" , geo.sectsize, attrversion, projid32bit,"" , crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled, +"" , reflink_enabled,"" , geo.blocksize, (unsigned long long )geo.datablocks, geo.imaxpct, "", geo.sunit, geo.swidth,
@@ -129,6 +132,7 @@ main(int argc, char **argv)int finobt_enabled;/* free inode btree */ int spinodes;int rmapbt_enabled; +int reflink_enabled; progname =basename (argv[0 ]);setlocale (LC_ALL ,"" );
@@ -253,12 +257,13 @@ main(int argc, char **argv) finobt_enabled = geo.flags &XFS_FSOP_GEOM_FLAGS_FINOBT ?1 :0 ; spinodes = geo.flags &XFS_FSOP_GEOM_FLAGS_SPINODES ?1 :0 ; rmapbt_enabled = geo.flags &XFS_FSOP_GEOM_FLAGS_RMAPBT ?1 :0 ; + reflink_enabled = geo.flags &XFS_FSOP_GEOM_FLAGS_REFLINK ?1 :0 ;if (nflag) {report_info (geo, datadev, isint, logdev, rtdev, lazycount, dirversion, logversion, attrversion, projid32bit, crcs_enabled, ci, ftype_enabled, finobt_enabled, spinodes, - rmapbt_enabled); + rmapbt_enabled, reflink_enabled);exit (0 ); }
@@ -296,7 +301,8 @@ main(int argc, char **argv)report_info (geo, datadev, isint, logdev, rtdev, lazycount, dirversion, logversion, attrversion, projid32bit, crcs_enabled, ci, ftype_enabled, - finobt_enabled, spinodes, rmapbt_enabled); + finobt_enabled, spinodes, rmapbt_enabled, + reflink_enabled); ddsize = xi.dsize; dlsize = ( xi.logBBsize? xi.logBBsize :
libxfs/xfs_fs.h +2 -1
@@ -241,7 +241,8 @@ typedef struct xfs_fsop_resblks {#define XFS_FSOP_GEOM_FLAGS_FTYPE 0x10000/* inode directory types */ #define XFS_FSOP_GEOM_FLAGS_FINOBT 0x20000/* free inode btree */ #define XFS_FSOP_GEOM_FLAGS_SPINODES 0x40000/* sparse inode chunks */ -#define XFS_FSOP_GEOM_FLAGS_RMAPBT 0x80000/* reverse-mapping btree */ +#define XFS_FSOP_GEOM_FLAGS_RMAPBT 0x80000/* reverse mapping btree */ +#define XFS_FSOP_GEOM_FLAGS_REFLINK 0x100000/* files can share blocks */ /* * Minimum and maximum sizes need for growth checks.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 44/53 xfs_repair: check the existing refcount btree
In reply to Darrick J. WongSpot-check the refcount btree for obvious errors, and mark the refcount btree blocks as such.
--- repair/incore.h | 3 + repair/scan.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++ repair/xfs_repair.c | 2 + 3 files changed, 189 insertions(+), 1 deletion(-)
repair/incore.h +2 -1
@@ -106,7 +106,8 @@ typedef struct rt_extent_tree_node {#define XR_E_INUSE_FS1 9/* used by fs ag header or log (rmap btree) */ #define XR_E_INO1 10/* used by inodes (marked by rmap btree) */ #define XR_E_FS_MAP1 11/* used by fs space/inode maps (rmap btree) */ -#define XR_E_BAD_STATE 12 +#define XR_E_REFC 12/* used by fs ag reference count btree */ +#define XR_E_BAD_STATE 13/* separate state bit, OR'ed into high (4th) bit of ex_state field */
repair/scan.c +185 -0
209 lines not on this page · raw message
repair/xfs_repair.c +2 -0
@@ -422,6 +422,8 @@ calc_mkfs(xfs_mount_t *mp) fino_bno +=min (2 , mp->m_ag_maxlevels); fino_bno++; } +if (xfs_sb_version_hasreflink (&mp->m_sb)) + fino_bno++;/* * If the log is allocated in the first allocation group we need to
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 45/53 xfs_repair: handle multiple owners of data blocks
In reply to Darrick J. WongIf reflink is enabled, don't freak out if there are multiple owners of a given block; that's just a sign that each of those owners are reflink files.
--- repair/dinode.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/scan.c | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 2 deletions(-)
repair/dinode.c +53 -0
@@ -722,6 +722,9 @@ _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n"* checking each entry without setting the * block bitmap */ +if (type ==XR_INO_DATA && +xfs_sb_version_hasreflink (&mp->m_sb)) + goto skip_dup;if (search_dup_extent (agno, agbno, ebno)) { do_warn( _("%s fork in ino %" PRIu64 " claims dup extent, "
@@ -731,6 +734,7 @@ _("%s fork in ino %" PRIu64 " claims dup extent, " irec.br_blockcount); goto done; } +skip_dup: *tot += irec.br_blockcount;continue ; }
@@ -770,6 +774,9 @@ _("%s fork in inode %" PRIu64 " claims metadata block %" PRIu64 "\n"),case XR_E_INUSE :case XR_E_MULT :set_bmap_ext (agno, agbno, blen,XR_E_MULT ); +if (type ==XR_INO_DATA && +xfs_sb_version_hasreflink (&mp->m_sb)) +break ;do_warn (_ ("%s fork in %s inode %" PRIu64" claims used block %" PRIu64"\n" ), forkname, ftype, ino, b);
@@ -2460,6 +2467,52 @@ _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"), } } +/* +* check that we only have valid flags2 set, and those that are set make +* sense. +*/ +if (dino->di_version >=3 ) { +uint16_t flags =be16_to_cpu (dino->di_flags); +uint64_t flags2 =be64_to_cpu (dino->di_flags2); + +if (flags2 & ~XFS_DIFLAG2_ANY ) { +if (!uncertain) { +do_warn ( +_ ("Bad flags2 set in inode %" PRIu64"\n" ), + lino); + } + flags2 &=XFS_DIFLAG2_ANY ; + } + +if ((flags2 &XFS_DIFLAG2_REFLINK ) && + (flags & (XFS_DIFLAG_REALTIME |XFS_DIFLAG_RTINHERIT ))) { +if (!uncertain) { +do_warn ( +_ ("Cannot have a reflinked realtime inode %" PRIu64"\n" ), + lino); + } + goto clear_bad_out; + } + +if ((flags2 &XFS_DIFLAG2_REFLINK ) && + !xfs_sb_version_hasreflink (&mp->m_sb)) { +if (!uncertain) { +do_warn ( +_ ("inode %" PRIu64" is marked reflinked but file system does not support reflink\n" ), + lino); + } + goto clear_bad_out; + } +if (!verify_mode && flags2 !=be64_to_cpu (dino->di_flags2)) { +if (!no_modify) { +do_warn (_ ("fixing bad flags2.\n" )); + dino->di_flags2 =cpu_to_be64 (flags2); + *dirty =1 ; + }else +do_warn (_ ("would fix bad flags2.\n" )); + } + } +if (verify_mode)return retval;
repair/scan.c +38 -2
@@ -783,7 +783,29 @@ ino_issparse(return xfs_inobt_is_sparse_disk (rp, offset); } - + +static bool +rmap_in_order ( +xfs_agblock_t b, +xfs_agblock_t lastblock, +int64_t owner, +int64_t lastowner, +int64_t offset, +int64_t lastoffset) +{ +if (b > lastblock) +return true; +else if (b < lastblock) +return false; + +if (owner > lastowner) +return true; +else if (owner < lastowner) +return false; + +return offset > lastoffset; +} + static void scan_rmapbt( struct xfs_btree_block *block,
@@ -910,7 +932,12 @@ advance: }else {bool bad; - bad = b <= lastblock; +if (xfs_sb_version_hasreflink (&mp->m_sb)) + bad = !rmap_in_order (b, lastblock, + owner, lastowner, + offset, lastoffset); +else + bad = b <= lastblock;if (bad) do_warn( _("out-of-order rmap btree record %d (%u %"PRId64" %"PRIx64" %u) block %u/%u\n"),
@@ -997,6 +1024,15 @@ _("in use block (%d,%d-%d) mismatch in %s tree, state - %d,%" PRIx64 "\n"),* be caught later. */ break ; +case XR_E_INUSE1 : +/* +* multiple inode owners are ok with +* reflink enabled +*/ +if (xfs_sb_version_hasreflink (&mp->m_sb) && + !XFS_RMAP_NON_INODE_OWNER (owner)) +break ; +/* fall through */ default : do_warn( _("unknown block (%d,%d-%d) mismatch on %s tree, state - %d,%" PRIx64 "\n"),
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 46/53 xfs_repair: process reverse-mapping data into refcount data
In reply to Darrick J. WongTake all the reverse-mapping data we've acquired and use it to generate reference count data. This data is used in phase 5 to rebuild the refcount btree.
--- repair/phase4.c | 27 ++++++ repair/rmap.c | 236 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 2 3 files changed, 263 insertions(+), 2 deletions(-)
repair/phase4.c +26 -1
@@ -183,6 +183,21 @@ _("%s while checking reverse-mappings"), }static void +compute_ag_refcounts ( +work_queue_t *wq, +xfs_agnumber_t agno, +void *arg) +{ +int error; + + error =compute_refcounts (wq->mp, agno); +if (error) +do_error ( +_ ("%s while computing reference count records.\n" ), +strerror (-error)); +} + +static void process_rmap_data (struct xfs_mount *mp) {
@@ -196,6 +211,14 @@ process_rmap_data(for (i =0 ; i < mp->m_sb.sb_agcount; i++)queue_work (&wq, check_rmap_btrees, i,NULL );destroy_work_queue (&wq); + +if (!xfs_sb_version_hasreflink (&mp->m_sb)) +return ; + +create_work_queue (&wq, mp,libxfs_nproc ()); +for (i =0 ; i < mp->m_sb.sb_agcount; i++) +queue_work (&wq, compute_ag_refcounts, i,NULL ); +destroy_work_queue (&wq); }void
@@ -349,7 +372,9 @@ phase4(xfs_mount_t *mp)/* * Process all the reverse-mapping data that we collected. This -* involves checking the rmap data against the btree. +* involves checking the rmap data against the btree, computing +* reference counts based on the rmap data, and checking the counts +* against the refcount btree. */ process_rmap_data (mp);
repair/rmap.c +235 -1
266 lines not on this page · raw message
repair/rmap.h +2 -0
@@ -39,6 +39,8 @@ extern int init_rmap_cursor(xfs_agnumber_t, struct xfs_slab_cursor **);extern void rmap_avoid_check (void );extern int check_rmaps (struct xfs_mount *,xfs_agnumber_t ); +extern int compute_refcounts (struct xfs_mount *,xfs_agnumber_t ); +extern void fix_freelist (struct xfs_mount *,xfs_agnumber_t ,bool );extern void rmap_store_agflcount (struct xfs_mount *,xfs_agnumber_t ,int );
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 47/53 xfs_repair: record reflink inode state
In reply to Darrick J. WongRecord the state of the per-inode reflink flag, so that we can compare against the rmap data and update the flags accordingly. Clear the (reflink) state if we clear the inode.
--- repair/dino_chunks.c | 1 + repair/dinode.c | 6 ++++++ repair/incore.h | 38 ++++++++++++++++++++++++++++++++++++++ repair/incore_ino.c | 2 ++ repair/rmap.c | 32 ++++++++++++++++++++++++++++++++ repair/rmap.h | 3 +++ 6 files changed, 82 insertions(+)
repair/dino_chunks.c +1 -0
@@ -931,6 +931,7 @@ next_readbuf:do_warn (_ ("would have cleared inode %" PRIu64"\n" ), ino); } +clear_inode_was_rl (ino_rec, irec_offset); } process_next:
repair/dinode.c +6 -0
@@ -2608,6 +2608,12 @@ _("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64 ", "), goto clear_bad_out;/* +* record the state of the reflink flag +*/ +if (collect_rmaps) +record_inode_reflink_flag (mp, dino, agno, ino, lino); + +/* * check data fork -- if it's bad, clear the inode */ if (process_inode_data_fork(mp, agno, ino, dino, type, dirty,
repair/incore.h +38 -0
@@ -283,6 +283,8 @@ typedef struct ino_tree_node {__uint64_t ir_sparse;/* sparse inode bitmask */ __uint64_t ino_confirmed;/* confirmed bitmask */ __uint64_t ino_isa_dir;/* bit == 1 if a directory */ +__uint64_t ino_was_rl;/* bit == 1 if reflink flag set */ +__uint64_t ino_is_rl;/* bit == 1 if reflink flag should be set */ __uint8_t nlink_size;union ino_nlink disk_nlinks;/* on-disk nlinks, set in P3 */ union {
@@ -494,6 +496,42 @@ static inline bool is_inode_sparse(struct ino_tree_node *irec, int offset) }/* +* set/clear/test was inode marked as reflinked +*/ +static inline void set_inode_was_rl (struct ino_tree_node *irec,int offset) +{ + irec->ino_was_rl |=IREC_MASK (offset); +} + +static inline void clear_inode_was_rl (struct ino_tree_node *irec,int offset) +{ + irec->ino_was_rl &= ~IREC_MASK (offset); +} + +static inline int inode_was_rl (struct ino_tree_node *irec,int offset) +{ +return (irec->ino_was_rl &IREC_MASK (offset)) !=0 ; +} + +/* +* set/clear/test should inode be marked as reflinked +*/ +static inline void set_inode_is_rl (struct ino_tree_node *irec,int offset) +{ + irec->ino_is_rl |=IREC_MASK (offset); +} + +static inline void clear_inode_is_rl (struct ino_tree_node *irec,int offset) +{ + irec->ino_is_rl &= ~IREC_MASK (offset); +} + +static inline int inode_is_rl (struct ino_tree_node *irec,int offset) +{ +return (irec->ino_is_rl &IREC_MASK (offset)) !=0 ; +} + +/* * add_inode_reached() is set on inode I only if I has been reached * by an inode P claiming to be the parent and if I is a directory, * the .. link in the I says that P is I's parent.
repair/incore_ino.c +2 -0
@@ -257,6 +257,8 @@ alloc_ino_node( irec->ino_startnum = starting_ino; irec->ino_confirmed =0 ; irec->ino_isa_dir =0 ; + irec->ino_was_rl =0 ; + irec->ino_is_rl =0 ; irec->ir_free = (xfs_inofree_t) -1 ; irec->ir_sparse =0 ; irec->ino_un.ex_data =NULL ;
repair/rmap.c +32 -0
@@ -1001,6 +1001,38 @@ err:return 0 ; } +/* +* record_inode_reflink_flag() -- Record that an inode had the reflink flag +* set when repair started. The inode reflink +* flag will be adjusted as necessary. +* @mp: XFS mount object. +* @dino: On-disk inode. +* @agno: AG number of the inode. +* @ino: AG inode number. +* @lino: Full inode number. +*/ +void +record_inode_reflink_flag ( +struct xfs_mount *mp, +struct xfs_dinode *dino, +xfs_agnumber_t agno, +xfs_agino_t ino, +xfs_ino_t lino) +{ +struct ino_tree_node *irec; +int off; + +ASSERT (XFS_AGINO_TO_INO (mp, agno, ino) ==be64_to_cpu (dino->di_ino)); +if (!(be64_to_cpu (dino->di_flags2) &XFS_DIFLAG2_REFLINK )) +return ; + irec =find_inode_rec (mp, agno, ino); + off =get_inode_offset (mp, lino, irec); +ASSERT (!inode_was_rl (irec, off)); +set_inode_was_rl (irec, off); +dbg_printf ("set was_rl lino=%llu was=0x%llx\n" , + (unsigned long long )lino, (unsigned long long )irec->ino_was_rl); +} +/** * fix_freelist() - Regenerate the AGFL, so that we don't run out of it while * rebuilding the rmapbt.
repair/rmap.h +3 -0
@@ -41,6 +41,9 @@ extern int check_rmaps(struct xfs_mount *, xfs_agnumber_t);extern int compute_refcounts (struct xfs_mount *,xfs_agnumber_t ); +extern void record_inode_reflink_flag (struct xfs_mount *,struct xfs_dinode *, +xfs_agnumber_t ,xfs_agino_t ,xfs_ino_t ); +extern void fix_freelist (struct xfs_mount *,xfs_agnumber_t ,bool );extern void rmap_store_agflcount (struct xfs_mount *,xfs_agnumber_t ,int );
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 48/53 xfs_repair: fix inode reflink flags
In reply to Darrick J. WongWhile we're computing reference counts, record which inodes actually share blocks with other files and fix the flags as necessary.
--- repair/phase4.c | 20 ++++++++ repair/rmap.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 1 3 files changed, 157 insertions(+)
repair/phase4.c +20 -0
@@ -198,6 +198,21 @@ _("%s while computing reference count records.\n"), }static void +process_inode_reflink_flags ( +struct work_queue *wq, +xfs_agnumber_t agno, +void *arg) +{ +int error; + + error =fix_inode_reflink_flags (wq->mp, agno); +if (error) +do_error ( +_ ("%s while fixing inode reflink flags.\n" ), +strerror (-error)); +} + +static void process_rmap_data (struct xfs_mount *mp) {
@@ -219,6 +234,11 @@ process_rmap_data(for (i =0 ; i < mp->m_sb.sb_agcount; i++)queue_work (&wq, compute_ag_refcounts, i,NULL );destroy_work_queue (&wq); + +create_work_queue (&wq, mp,libxfs_nproc ()); +for (i =0 ; i < mp->m_sb.sb_agcount; i++) +queue_work (&wq, process_inode_reflink_flags, i,NULL ); +destroy_work_queue (&wq); }void
repair/rmap.c +136 -0
160 lines not on this page · raw message
repair/rmap.h +1 -0
@@ -43,6 +43,7 @@ extern int compute_refcounts(struct xfs_mount *, xfs_agnumber_t);extern void record_inode_reflink_flag (struct xfs_mount *,struct xfs_dinode *,xfs_agnumber_t ,xfs_agino_t ,xfs_ino_t ); +extern int fix_inode_reflink_flags (struct xfs_mount *,xfs_agnumber_t );extern void fix_freelist (struct xfs_mount *,xfs_agnumber_t ,bool );extern void rmap_store_agflcount (struct xfs_mount *,xfs_agnumber_t ,int );
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 49/53 xfs_repair: check the refcount btree against our observed reference counts when -n
In reply to Darrick J. WongCheck the observed reference counts against whatever's in the refcount btree for discrepancies.
--- repair/phase4.c | 20 ++++++++ repair/rmap.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ repair/rmap.h | 4 ++ repair/scan.c | 2 + 4 files changed, 161 insertions(+)
repair/phase4.c +20 -0
@@ -213,6 +213,21 @@ _("%s while fixing inode reflink flags.\n"), }static void +check_refcount_btrees ( +work_queue_t *wq, +xfs_agnumber_t agno, +void *arg) +{ +int error; + + error =check_refcounts (wq->mp, agno); +if (error) +do_error ( +_ ("%s while checking reference counts" ), +strerror (-error)); +} + +static void process_rmap_data (struct xfs_mount *mp) {
@@ -239,6 +254,11 @@ process_rmap_data(for (i =0 ; i < mp->m_sb.sb_agcount; i++)queue_work (&wq, process_inode_reflink_flags, i,NULL );destroy_work_queue (&wq); + +create_work_queue (&wq, mp,libxfs_nproc ()); +for (i =0 ; i < mp->m_sb.sb_agcount; i++) +queue_work (&wq, check_refcount_btrees, i,NULL ); +destroy_work_queue (&wq); }void
repair/rmap.c +135 -0
147 lines not on this page · raw message
repair/rmap.h +4 -0
@@ -40,6 +40,10 @@ extern void rmap_avoid_check(void);extern int check_rmaps (struct xfs_mount *,xfs_agnumber_t );extern int compute_refcounts (struct xfs_mount *,xfs_agnumber_t ); +extern size_t refcount_record_count (struct xfs_mount *,xfs_agnumber_t ); +extern int init_refcount_cursor (xfs_agnumber_t ,struct xfs_slab_cursor **); +extern void refcount_avoid_check (void ); +extern int check_refcounts (struct xfs_mount *,xfs_agnumber_t );extern void record_inode_reflink_flag (struct xfs_mount *,struct xfs_dinode *,xfs_agnumber_t ,xfs_agino_t ,xfs_ino_t );
repair/scan.c +2 -0
@@ -1257,6 +1257,8 @@ _("%s btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), } } out: +if (suspect) +refcount_avoid_check ();return ; }
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 50/53 xfs_repair: rebuild the refcount btree
In reply to Darrick J. WongRebuild the refcount btree with the reference count data we assembled during phase 4.
--- repair/phase5.c | 309 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 307 insertions(+), 2 deletions(-)
repair/phase5.c +307 -2
@@ -1624,6 +1624,290 @@ _("Insufficient memory to construct reverse-map cursor."));free_slab_cursor (&rmap_cur); } +/* rebuild the refcount tree */ + +#define XR_REFCOUNTBT_BLOCK_MAXRECS (mp, level) \ + ((mp)->m_refc_mxr[(level) != 0]) + +/* +* we don't have to worry here about how chewing up free extents +* may perturb things because reflink tree building happens before +* freespace tree building. +*/ +static void +init_refc_cursor (xfs_mount_t *mp,xfs_agnumber_t agno,bt_status_t *btree_curs) +{ +size_t num_recs; +int level; +bt_stat_level_t *lptr; +bt_stat_level_t *p_lptr; +xfs_extlen_t blocks_allocated; + +if (!xfs_sb_version_hasreflink (&mp->m_sb)) { +memset (btree_curs,0 ,sizeof (bt_status_t)); +return ; + } + + lptr = &btree_curs->level[0 ]; + btree_curs->init =1 ; + btree_curs->owner =XFS_RMAP_OWN_REFC ; + +/* +* build up statistics +*/ + num_recs =refcount_record_count (mp, agno); +if (num_recs ==0 ) { +/* +* easy corner-case -- no refcount records +*/ + lptr->num_blocks =1 ; + lptr->modulo =0 ; + lptr->num_recs_pb =0 ; + lptr->num_recs_tot =0 ; + + btree_curs->num_levels =1 ; + btree_curs->num_tot_blocks = btree_curs->num_free_blocks =1 ; + +setup_cursor (mp, agno, btree_curs); + +return ; + } + + blocks_allocated = lptr->num_blocks =howmany (num_recs, +XR_REFCOUNTBT_BLOCK_MAXRECS (mp,0 )); + + lptr->modulo = num_recs % lptr->num_blocks; + lptr->num_recs_pb = num_recs / lptr->num_blocks; + lptr->num_recs_tot = num_recs; + level =1 ; + +if (lptr->num_blocks >1 ) { +for (; btree_curs->level[level-1 ].num_blocks >1 + && level <XFS_BTREE_MAXLEVELS ; + level++) { + lptr = &btree_curs->level[level]; + p_lptr = &btree_curs->level[level -1 ]; + lptr->num_blocks =howmany (p_lptr->num_blocks, +XR_REFCOUNTBT_BLOCK_MAXRECS (mp, level)); + lptr->modulo = p_lptr->num_blocks % lptr->num_blocks; + lptr->num_recs_pb = p_lptr->num_blocks + / lptr->num_blocks; + lptr->num_recs_tot = p_lptr->num_blocks; + + blocks_allocated += lptr->num_blocks; + } + } +ASSERT (lptr->num_blocks ==1 ); + btree_curs->num_levels = level; + + btree_curs->num_tot_blocks = btree_curs->num_free_blocks + = blocks_allocated; + +setup_cursor (mp, agno, btree_curs); +} + +static void +prop_refc_cursor (xfs_mount_t *mp,xfs_agnumber_t agno,bt_status_t *btree_curs, +xfs_agblock_t startbno,int level) +{ +struct xfs_btree_block *bt_hdr; +struct xfs_refcount_key *bt_key; +xfs_refcount_ptr_t *bt_ptr; +xfs_agblock_t agbno; +bt_stat_level_t *lptr; + + level++; + +if (level >= btree_curs->num_levels) +return ; + + lptr = &btree_curs->level[level]; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); + +if (be16_to_cpu (bt_hdr->bb_numrecs) ==0 ) { +/* +* this only happens once to initialize the +* first path up the left side of the tree +* where the agbno's are already set up +*/ +prop_refc_cursor (mp, agno, btree_curs, startbno, level); + } + +if (be16_to_cpu (bt_hdr->bb_numrecs) == + lptr->num_recs_pb + (lptr->modulo >0 )) { +/* +* write out current prev block, grab us a new block, +* and set the rightsib pointer of current block +*/ +#ifdef XR_BLD_INO_TRACE +fprintf (stderr," ino prop agbno %d " , lptr->prev_agbno); +#endif +if (lptr->prev_agbno !=NULLAGBLOCK ) { +ASSERT (lptr->prev_buf_p !=NULL ); +libxfs_writebuf (lptr->prev_buf_p,0 ); + } + lptr->prev_agbno = lptr->agbno; + lptr->prev_buf_p = lptr->buf_p; + agbno =get_next_blockaddr (agno, level, btree_curs); + + bt_hdr->bb_u.s.bb_rightsib =cpu_to_be32 (agbno); + + lptr->buf_p =libxfs_getbuf (mp->m_dev, +XFS_AGB_TO_DADDR (mp, agno, agbno), +XFS_FSB_TO_BB (mp,1 )); + lptr->agbno = agbno; + +if (lptr->modulo) + lptr->modulo--; + +/* +* initialize block header +*/ + lptr->buf_p->b_ops = &xfs_refcountbt_buf_ops; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); +memset (bt_hdr,0 , mp->m_sb.sb_blocksize); +xfs_btree_init_block (mp, lptr->buf_p,XFS_REFC_CRC_MAGIC , + level,0 , agno, +XFS_BTREE_CRC_BLOCKS ); + + bt_hdr->bb_u.s.bb_leftsib =cpu_to_be32 (lptr->prev_agbno); + +/* +* propagate extent record for first extent in new block up +*/ +prop_refc_cursor (mp, agno, btree_curs, startbno, level); + } +/* +* add inode info to current block +*/ +be16_add_cpu (&bt_hdr->bb_numrecs,1 ); + + bt_key =XFS_REFCOUNT_KEY_ADDR (bt_hdr, +be16_to_cpu (bt_hdr->bb_numrecs)); + bt_ptr =XFS_REFCOUNT_PTR_ADDR (bt_hdr, +be16_to_cpu (bt_hdr->bb_numrecs), + mp->m_refc_mxr[1 ]); + + bt_key->rc_startblock =cpu_to_be32 (startbno); + *bt_ptr =cpu_to_be32 (btree_curs->level[level-1 ].agbno); +} + +/* +* rebuilds a refcount btree given a cursor. +*/ +static void +build_refcount_tree (xfs_mount_t *mp,xfs_agnumber_t agno,bt_status_t *btree_curs) +{ +xfs_agnumber_t i; +xfs_agblock_t j; +xfs_agblock_t agbno; +struct xfs_btree_block *bt_hdr; +struct xfs_refcount_irec *refc_rec; +struct xfs_slab_cursor *refc_cur; +struct xfs_refcount_rec *bt_rec; +struct bt_stat_level *lptr; +int level = btree_curs->num_levels; +int error; + +for (i =0 ; i < level; i++) { + lptr = &btree_curs->level[i]; + + agbno =get_next_blockaddr (agno, i, btree_curs); + lptr->buf_p =libxfs_getbuf (mp->m_dev, +XFS_AGB_TO_DADDR (mp, agno, agbno), +XFS_FSB_TO_BB (mp,1 )); + +if (i == btree_curs->num_levels -1 ) + btree_curs->root = agbno; + + lptr->agbno = agbno; + lptr->prev_agbno =NULLAGBLOCK ; + lptr->prev_buf_p =NULL ; +/* +* initialize block header +*/ + + lptr->buf_p->b_ops = &xfs_refcountbt_buf_ops; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); +memset (bt_hdr,0 , mp->m_sb.sb_blocksize); +xfs_btree_init_block (mp, lptr->buf_p,XFS_REFC_CRC_MAGIC , + i,0 , agno, +XFS_BTREE_CRC_BLOCKS ); + } + +/* +* run along leaf, setting up records. as we have to switch +* blocks, call the prop_refc_cursor routine to set up the new +* pointers for the parent. that can recurse up to the root +* if required. set the sibling pointers for leaf level here. +*/ + error =init_refcount_cursor (agno, &refc_cur); +if (error) +do_error ( +_ ("Insufficient memory to construct refcount cursor." )); + refc_rec =pop_slab_cursor (refc_cur); + lptr = &btree_curs->level[0 ]; + +for (i =0 ; i < lptr->num_blocks; i++) { +/* +* block initialization, lay in block header +*/ + lptr->buf_p->b_ops = &xfs_refcountbt_buf_ops; + bt_hdr =XFS_BUF_TO_BLOCK (lptr->buf_p); +memset (bt_hdr,0 , mp->m_sb.sb_blocksize); +xfs_btree_init_block (mp, lptr->buf_p,XFS_REFC_CRC_MAGIC , +0 ,0 , agno, +XFS_BTREE_CRC_BLOCKS ); + + bt_hdr->bb_u.s.bb_leftsib =cpu_to_be32 (lptr->prev_agbno); + bt_hdr->bb_numrecs =cpu_to_be16 (lptr->num_recs_pb + + (lptr->modulo >0 )); + +if (lptr->modulo >0 ) + lptr->modulo--; + +if (lptr->num_recs_pb >0 ) +prop_refc_cursor (mp, agno, btree_curs, + refc_rec->rc_startblock,0 ); + + bt_rec = (struct xfs_refcount_rec *) + ((char *)bt_hdr +XFS_REFCOUNT_BLOCK_LEN ); +for (j =0 ; j <be16_to_cpu (bt_hdr->bb_numrecs); j++) { +ASSERT (refc_rec !=NULL ); + bt_rec[j].rc_startblock = +cpu_to_be32 (refc_rec->rc_startblock); + bt_rec[j].rc_blockcount = +cpu_to_be32 (refc_rec->rc_blockcount); + bt_rec[j].rc_refcount =cpu_to_be32 (refc_rec->rc_refcount); + + refc_rec =pop_slab_cursor (refc_cur); + } + +if (refc_rec !=NULL ) { +/* +* get next leaf level block +*/ +if (lptr->prev_buf_p !=NULL ) { +#ifdef XR_BLD_RL_TRACE +fprintf (stderr,"writing refcntbt agbno %u\n" , + lptr->prev_agbno); +#endif +ASSERT (lptr->prev_agbno !=NULLAGBLOCK ); +libxfs_writebuf (lptr->prev_buf_p,0 ); + } + lptr->prev_buf_p = lptr->buf_p; + lptr->prev_agbno = lptr->agbno; + lptr->agbno =get_next_blockaddr (agno,0 , btree_curs); + bt_hdr->bb_u.s.bb_rightsib =cpu_to_be32 (lptr->agbno); + + lptr->buf_p =libxfs_getbuf (mp->m_dev, +XFS_AGB_TO_DADDR (mp, agno, lptr->agbno), +XFS_FSB_TO_BB (mp,1 )); + } + } +free_slab_cursor (&refc_cur); +} +/* * build both the agf and the agfl for an agno given both * btree cursors.
@@ -1637,7 +1921,8 @@ build_agf_agfl(xfs_mount_t *mp,bt_status_t *bcnt_bt, xfs_extlen_t freeblks, /* # free blocks in tree */ int lostblocks, /* # blocks that will be lost */ - bt_status_t *rmap_bt) + bt_status_t *rmap_bt, + bt_status_t *refcnt_bt) { extent_tree_node_t *ext_ptr;xfs_buf_t *agf_buf, *agfl_buf;
@@ -1679,6 +1964,8 @@ build_agf_agfl(xfs_mount_t *mp, agf->agf_roots[XFS_BTNUM_RMAP ] =cpu_to_be32 (rmap_bt->root); agf->agf_levels[XFS_BTNUM_RMAP ] =cpu_to_be32 (rmap_bt->num_levels); agf->agf_freeblks =cpu_to_be32 (freeblks); + agf->agf_refcount_root =cpu_to_be32 (refcnt_bt->root); + agf->agf_refcount_level =cpu_to_be32 (refcnt_bt->num_levels);/* * Count and record the number of btree blocks consumed if required.
@@ -1796,6 +2083,10 @@ build_agf_agfl(xfs_mount_t *mp,ASSERT (be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNOi]) !=be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNTi])); +ASSERT (be32_to_cpu (agf->agf_refcount_root) != +be32_to_cpu (agf->agf_roots[XFS_BTNUM_BNOi])); +ASSERT (be32_to_cpu (agf->agf_refcount_root) != +be32_to_cpu (agf->agf_roots[XFS_BTNUM_CNTi]));libxfs_writebuf (agf_buf,0 );
@@ -1865,6 +2156,7 @@ phase5_func(bt_status_t ino_btree_curs;bt_status_t fino_btree_curs;bt_status_t rmap_btree_curs; +bt_status_t refcnt_btree_curs;int extra_blocks =0 ;uint num_freeblocks;xfs_extlen_t freeblks1;
@@ -1927,6 +2219,12 @@ phase5_func(*/ init_rmapbt_cursor (mp, agno, &rmap_btree_curs); +/* +* Set up the btree cursors for the on-disk refcount btrees, +* which includes pre-allocating all required blocks. +*/ +init_refc_cursor (mp, agno, &refcnt_btree_curs); + num_extents =count_bno_extents_blocks (agno, &num_freeblocks);/* * lose two blocks per AG -- the space tree roots
@@ -2020,12 +2318,17 @@ phase5_func( rmap_btree_curs.num_free_blocks) - 1; } +if (xfs_sb_version_hasreflink (&mp->m_sb)) { +build_refcount_tree (mp, agno, &refcnt_btree_curs); +write_cursor (&refcnt_btree_curs); + } +/* * set up agf and agfl */ build_agf_agfl (mp, agno, &bno_btree_curs, &bcnt_btree_curs, freeblks1, extra_blocks, - &rmap_btree_curs); + &rmap_btree_curs, &refcnt_btree_curs);/* * build inode allocation tree. */
@@ -2056,6 +2359,8 @@ phase5_func(finish_cursor (&ino_btree_curs);if (xfs_sb_version_hasrmapbt (&mp->m_sb))finish_cursor (&rmap_btree_curs); +if (xfs_sb_version_hasreflink (&mp->m_sb)) +finish_cursor (&refcnt_btree_curs);if (xfs_sb_version_hasfinobt (&mp->m_sb))finish_cursor (&fino_btree_curs);finish_cursor (&bcnt_btree_curs);
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 51/53 mkfs.xfs: format reflink enabled filesystems
In reply to Darrick J. WongCreate the refcount btree at mkfs time and set the feature flag.
--- man/man8/mkfs.xfs.8 | 28 +++++++++++++++++++++++ mkfs/xfs_mkfs.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 5 deletions(-)
man/man8/mkfs.xfs.8 +28 -0
@@ -193,6 +193,34 @@ for filesystems created with the (default) option set. When the option .B \-m crc=0 is used, the reverse mapping btree feature is not supported and is disabled. +.TP +.BI reflink= value +This option enables the use of a separate reference count btree index in each +allocation group. The value is either 0 to disable the feature, or 1 to create +a reference count btree in each allocation group. +.IP +The reference count btree enables the sharing of physical extents between +the data forks of different files, which is commonly known as "reflink". +Unlike traditional Unix filesystems which assume that every inode and +logical block pair map to a unique physical block, a reflink-capable +XFS filesystem removes the uniqueness requirement, allowing up to four +billion arbitrary inode/logical block pairs to map to a physical block. +If a program tries to write to a multiply-referenced block in a file, the write +will be redirected to a new block, and that file's logical-to-physical +mapping will be changed to the new block ("copy on write"). This feature +enables the creation of per-file snapshots and deduplication. It is only +available for the data forks of regular files. +.IP +By default, +.B mkfs.xfs +will not create reference count btrees and therefore will not enable the +reflink feature. This feature is only available for filesystems created with +the (default) +.B \-m crc=1 +option set. When the option +.B \-m crc=0 +is used, the reference count btree feature is not supported and reflink is +disabled. .RE .TP .BI \-d " data_section_options"
mkfs/xfs_mkfs.c +57 -5
136 lines not on this page · raw message
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 52/53 libxfs: try to prevent failed rmap btree expansion during cow
In reply to Darrick J. WongIt's possible, if reflink and rmap are both enabled, for CoW to create a lot of small mappings that cause an rmap btree expansion to run out of space. If both are enabled, keep the AGFL fully stocked at all times, refuse to CoW if we start to run out of space in the AGFL, and hope that's good enough.
--- libxfs/xfs_alloc.c | 8 ++++++++ repair/xfs_repair.c | 5 +++++ 2 files changed, 13 insertions(+)
libxfs/xfs_alloc.c +8 -0
@@ -1997,6 +1997,14 @@ xfs_alloc_min_freelist( min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_RMAPi] +1 , mp->m_ag_maxlevels); +/* +* The rmapbt can explode if we have reflink enabled and someone +* creates a lot of small mappings... so max out the AGFL to try +* to prevent that. +*/ +if (xfs_sb_version_hasrmapbt (&mp->m_sb) && +xfs_sb_version_hasreflink (&mp->m_sb)) + min_free =XFS_AGFL_SIZE (mp) - min_free;return min_free; }
repair/xfs_repair.c +5 -0
@@ -424,6 +424,11 @@ calc_mkfs(xfs_mount_t *mp) }if (xfs_sb_version_hasreflink (&mp->m_sb)) fino_bno++; +if (xfs_sb_version_hasrmapbt (&mp->m_sb) && +xfs_sb_version_hasreflink (&mp->m_sb)) { + fino_bno =XFS_AGFL_SIZE (mp) + (fino_bno - + (6 *min (2 , mp->m_ag_maxlevels))); + }/* * If the log is allocated in the first allocation group we need to
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v4 53/53 mkfs: hack around not having enough log blocks
In reply to Darrick J. WongUnder some circumstances I don't yet understand, mkfs underestimates the minimum log size and the kernel refuses to mount. Put in a crude hack so that this doesn't happen.
DO NOT APPLY!!!
--- mkfs/xfs_mkfs.c | 1 + 1 file changed, 1 insertion(+)
mkfs/xfs_mkfs.c +1 -0
@@ -2444,6 +2444,7 @@ an AG size that is one stripe unit smaller, for example %llu.\n"), logversion, lsunit);ASSERT (min_logblocks); min_logblocks =MAX (XFS_MIN_LOG_BLOCKS , min_logblocks); +if (min_logblocks <860 ) min_logblocks =860 ;if (!logsize && dblocks >= (1024 *1024 *1024 ) >> blocklog) min_logblocks =MAX (min_logblocks,XFS_MIN_LOG_BYTES >>blocklog);if (logsize && xi.logBBsize >0 && logblocks >DTOBT (xi.logBBsize)) {
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs