xfs: metadata CRCs, second batch
cover xfs: metadata CRCs, second batch
Hi folks,
This is the second version of the kernel support for metadata CRCs. This builds on the first batch posted here:
http://oss.sgi.com/archives/xfs/2013-01/msg00328.html
I won't write everything I wrote in that description again, so I'll just focus on what is new in this series:
- based on xfs_bmap.c rearrangement patch
- fixed up a couple of bugs and comments noted by Ben
- fixed a significant number of bugs, including the dquot recovery problem and some symlink issues on 512 byte block size filesystems.
- added support for directories and attributes
- moved the superblock CRC addition and enablment patch to the end of the series.
Things that are still missing from this version:
- remote attribute CRCs
- directory/attribute buffer type tracking for log recovery
- DT_* type fields in the directory entries
- storage of attributes larger than 256 bytes in shortform attribute forks.
The fact that directory/attr buffer type tracking is missing means this code simply won't work right now with CRCs enabled. My mainfocus so far is getting all the structural changes to the code in place without causing regressions. In general, the directory/attr code changes are along the lines of:
- CRC enabled directories are named as "dir3", btree nodes "da3" and attribute trees are "attr3".
- functions that support both attr/attr3 and dir2/dir3 types are renamed to attr3/dir3/da3 so it is obvious that they can support both types. This may not be 100% consistent through the patches yet - I didn't settle name change until a bit into the directory conversion. The directory code needs cleaning up, and will be done as an additional patch.
- header sizes change, so access to data types after the header need to be abstracted. this is done by helper functions rather tan direct dereference of a structure type.
- header sizes change, so that access to certain header fields need ot be abstracted. This is done in most cases by introducing an "in-core header" type and to/from disk translation functions. This has removed a *lot* of endian swapping from the code.
- code has been modified to use abtract access functions, and in some cases pass in-core headers around when child functions also modify headers. In some cases, logging of header has been pulled up into the parent functions that own the incore header structure.
- much of the function declarations has been reformatted to be consistent with the rest of the XFS code. Every time I touched a function name I reformatted the parameters and the local variable declarations inside the functions.
While the changes to the directory/attr code look complex, but really they are mostly mechanical changes. i.e. the same change done over and over again. There are places that I know that I've missed changing, and these will be corrected in followup patches as I start testing with CRCs enabled.
In terms of testing, this series passes xfstests on several machines with 512 byte and 4k block size filesystems using existing tools (i.e. no CRC support) without any new regressions being introduced. It survives repeated fsmark runs on 100TB filesystems, and so seems fairly robust when used with existing tools and filesystems.
Diffstat for the series:
$ git diff --stat 2292716.. fs/xfs/Makefile | 5 +- fs/xfs/xfs_ag.h | 56 +- fs/xfs/xfs_alloc.c | 199 +- fs/xfs/xfs_alloc_btree.c | 105 +- fs/xfs/xfs_alloc_btree.h | 12 +- fs/xfs/xfs_attr.c | 158 +- fs/xfs/xfs_attr_leaf.c | 1769 +++++---- fs/xfs/xfs_attr_leaf.h | 121 +- fs/xfs/xfs_bmap.c | 9214 +++++++++++++++++++++++------------------------ fs/xfs/xfs_bmap_btree.c | 110 +- fs/xfs/xfs_bmap_btree.h | 19 +- fs/xfs/xfs_btree.c | 256 +- fs/xfs/xfs_btree.h | 64 +- fs/xfs/xfs_buf_item.h | 36 +- fs/xfs/xfs_da_btree.c | 1426 +++++--- fs/xfs/xfs_da_btree.h | 121 +- fs/xfs/xfs_dinode.h | 43 +- fs/xfs/xfs_dir2_block.c | 161 +- fs/xfs/xfs_dir2_data.c | 257 +- fs/xfs/xfs_dir2_format.h | 249 +- fs/xfs/xfs_dir2_leaf.c | 845 +++-- fs/xfs/xfs_dir2_node.c | 972 +++-- fs/xfs/xfs_dir2_priv.h | 48 +- fs/xfs/xfs_dquot.c | 112 +- fs/xfs/xfs_file.c | 2 +- fs/xfs/xfs_fsops.c | 34 +- fs/xfs/xfs_ialloc.c | 80 +- fs/xfs/xfs_ialloc_btree.c | 87 +- fs/xfs/xfs_ialloc_btree.h | 9 +- fs/xfs/xfs_inode.c | 212 +- fs/xfs/xfs_inode.h | 31 +- fs/xfs/xfs_inode_item.c | 2 +- fs/xfs/xfs_log_recover.c | 118 +- fs/xfs/xfs_mount.c | 97 +- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_qm.c | 23 +- fs/xfs/xfs_qm.h | 2 + fs/xfs/xfs_quota.h | 11 +- fs/xfs/xfs_sb.h | 100 +- fs/xfs/xfs_trace.c | 2 +- fs/xfs/xfs_trans.h | 2 + fs/xfs/xfs_trans_buf.c | 34 +- fs/xfs/xfs_vnodeops.c | 480 +-- 43 files changed, 9830 insertions(+), 7855 deletions(-)
So you can see most of the change is in xfs_bmap.c and the directory code. Without the first xfs_bmap.c patch, it is about half that size and the majority comes from the directory and attribute changes.
43 files changed, 5315 insertions(+), 3206 deletions(-)
Reviews, testing, etc. welcome!
Cheers,
Dave.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 1/16 xfs: rearrange some code in xfs_bmap for better locality
From: Dave Chinner <[email protected]>
xfs_bmap.c is a big file, and some of the related code is spread all throughout the file requiring function prototypes for static function and jumping all through the file to follow a single call path. Rearrange the code so that:
a) related functionality is grouped together; and
b) functions are grouped in call dependency order
While the diffstat is large, there are no code changes in the patch; it is just moving the functionality around and removing the function prototypes at the top of the file. The resulting layout of the code is as follows (top of file to bottom):
- miscellaneous helper functions
- extent tree block counting routines
- debug/sanity checking code
- bmap free list manipulation functions
- inode fork format manipulation functions
- internal/external extent tree seach functions
- extent tree manipulation functions used during allocation
- functions used during extent read/allocate/removal operations (i.e. xfs_bmapi_write, xfs_bmapi_read, xfs_bunmapi and xfs_getbmap)
This means that following logic paths through the bmapi code is much simpler - most of the code relevant to a specific operation is now clustered together rather than spread all over the file....
--- fs/xfs/xfs_bmap.c |10659 ++++++++++++++++++++++++++--------------------------- 1 file changed, 5261 insertions(+), 5398 deletions(-)
fs/xfs/xfs_bmap.c +5261 -5398
@@ -52,175 +52,72 @@kmem_zone_t *xfs_bmap_free_item_zone;/* -* Prototypes for internal bmap routines. +* Miscellaneous helper functions */ -#ifdef DEBUG -STATIC void -xfs_bmap_check_leaf_extents ( -struct xfs_btree_cur *cur, -struct xfs_inode *ip, -int whichfork); -#else -#define xfs_bmap_check_leaf_extents (cur, ip, whichfork) do { } while (0) -#endif - - -/* -* Called from xfs_bmap_add_attrfork to handle extents format files. -*/ -STATIC int /* error */ -xfs_bmap_add_attrfork_extents ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fsblock_t *firstblock,/* first block allocated */ -xfs_bmap_free_t *flist,/* blocks to free at commit */ -int *flags);/* inode logging flags */ - -/* -* Called from xfs_bmap_add_attrfork to handle local format files. -*/ -STATIC int /* error */ -xfs_bmap_add_attrfork_local ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fsblock_t *firstblock,/* first block allocated */ -xfs_bmap_free_t *flist,/* blocks to free at commit */ -int *flags);/* inode logging flags */ - -/* -* xfs_bmap_alloc is called by xfs_bmapi to allocate an extent for a file. -* It figures out where to ask the underlying allocator to put the new extent. -*/ -STATIC int /* error */ -xfs_bmap_alloc ( -xfs_bmalloca_t *ap);/* bmap alloc argument struct */ - -/* -* Transform a btree format file with only one leaf node, where the -* extents list will fit in the inode, into an extents format file. -* Since the file extents are already in-core, all we have to do is -* give up the space for the btree root and pitch the leaf block. -*/ -STATIC int /* error */ -xfs_bmap_btree_to_extents ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_btree_cur_t *cur,/* btree cursor */ -int *logflagsp,/* inode logging flags */ -int whichfork);/* data or attr fork */ - -/* -* Remove the entry "free" from the free item list. Prev points to the -* previous entry, unless "free" is the head of the list. -*/ -STATIC void -xfs_bmap_del_free ( -xfs_bmap_free_t *flist,/* free item list header */ -xfs_bmap_free_item_t *prev,/* previous item on list, if any */ -xfs_bmap_free_item_t *free);/* list item to be freed */ - -/* -* Convert an extents-format file into a btree-format file. -* The new file will have a root block (in the inode) and a single child block. -*/ -STATIC int /* error */ -xfs_bmap_extents_to_btree ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fsblock_t *firstblock,/* first-block-allocated */ -xfs_bmap_free_t *flist,/* blocks freed in xaction */ -xfs_btree_cur_t **curp,/* cursor returned to caller */ -int wasdel,/* converting a delayed alloc */ -int *logflagsp,/* inode logging flags */ -int whichfork);/* data or attr fork */ - -/* -* Convert a local file to an extents file. -* This code is sort of bogus, since the file data needs to get -* logged so it won't be lost. The bmap-level manipulations are ok, though. -*/ -STATIC int /* error */ -xfs_bmap_local_to_extents ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fsblock_t *firstblock,/* first block allocated in xaction */ -xfs_extlen_t total,/* total blocks needed by transaction */ -int *logflagsp,/* inode logging flags */ -int whichfork,/* data or attr fork */ -void (*init_fn)(struct xfs_buf *bp, -struct xfs_inode *ip, -struct xfs_ifork *ifp)); - -/* -* Search the extents list for the inode, for the extent containing bno. -* If bno lies in a hole, point to the next entry. If bno lies past eof, -* *eofp will be set, and *prevp will contain the last entry (null if none). -* Else, *lastxp will be set to the index of the found -* entry; *gotp will contain the entry. -*/ -STATIC xfs_bmbt_rec_host_t * /* pointer to found extent entry */ -xfs_bmap_search_extents ( -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fileoff_t bno,/* block number searched for */ -int whichfork,/* data or attr fork */ -int *eofp,/* out: end of file found */ -xfs_extnum_t *lastxp,/* out: last extent index */ -xfs_bmbt_irec_t *gotp,/* out: extent entry found */ -xfs_bmbt_irec_t *prevp);/* out: previous extent entry found */ - -/* -* Compute the worst-case number of indirect blocks that will be used -* for ip's delayed extent of length "len". -*/ -STATIC xfs_filblks_t -xfs_bmap_worst_indlen ( -xfs_inode_t *ip,/* incore inode pointer */ -xfs_filblks_t len);/* delayed extent length */ - -#ifdef DEBUG /* -* Perform various validation checks on the values being returned -* from xfs_bmapi(). +* Compute and fill in the value of the maximum depth of a bmap btree +* in this filesystem. Done once, during mount. */ -STATIC void -xfs_bmap_validate_ret ( -xfs_fileoff_t bno, -xfs_filblks_t len, -int flags, -xfs_bmbt_irec_t *mval, -int nmap, -int ret_nmap); -#else -#define xfs_bmap_validate_ret (bno,len,flags,mval,onmap,nmap) -#endif /* DEBUG */ - -STATIC int -xfs_bmap_count_tree ( -xfs_mount_t *mp, -xfs_trans_t *tp, -xfs_ifork_t *ifp, -xfs_fsblock_t blockno, -int levelin, -int *count); - -STATIC void -xfs_bmap_count_leaves ( -xfs_ifork_t *ifp, -xfs_extnum_t idx, -int numrecs, -int *count); +void +xfs_bmap_compute_maxlevels ( +xfs_mount_t *mp,/* file system mount structure */ +int whichfork)/* data or attr fork */ +{ +int level;/* btree level */ +uint maxblocks;/* max blocks at this level */ +uint maxleafents;/* max leaf entries possible */ +int maxrootrecs;/* max records in root block */ +int minleafrecs;/* min records in leaf block */ +int minnoderecs;/* min records in node block */ +int sz;/* root block size */ -STATIC void -xfs_bmap_disk_count_leaves ( -struct xfs_mount *mp, -struct xfs_btree_block *block, -int numrecs, -int *count); +/* +* The maximum number of extents in a file, hence the maximum +* number of leaf entries, is controlled by the type of di_nextents +* (a signed 32-bit number, xfs_extnum_t), or by di_anextents +* (a signed 16-bit number, xfs_aextnum_t). +* +* Note that we can no longer assume that if we are in ATTR1 that +* the fork offset of all the inodes will be +* (xfs_default_attroffset(ip) >> 3) because we could have mounted +* with ATTR2 and then mounted back with ATTR1, keeping the +* di_forkoff's fixed but probably at various positions. Therefore, +* for both ATTR1 and ATTR2 we have to assume the worst case scenario +* of a minimum size available. +*/ +if (whichfork ==XFS_DATA_FORK ) { + maxleafents =MAXEXTNUM ; + sz =XFS_BMDR_SPACE_CALC (MINDBTPTRS ); + }else { + maxleafents =MAXAEXTNUM ; + sz =XFS_BMDR_SPACE_CALC (MINABTPTRS ); + } + maxrootrecs =xfs_bmdr_maxrecs (mp, sz,0 ); + minleafrecs = mp->m_bmap_dmnr[0 ]; + minnoderecs = mp->m_bmap_dmnr[1 ]; + maxblocks = (maxleafents + minleafrecs -1 ) / minleafrecs; +for (level =1 ; maxblocks >1 ; level++) { +if (maxblocks <= maxrootrecs) + maxblocks =1 ; +else + maxblocks = (maxblocks + minnoderecs -1 ) / minnoderecs; + } + mp->m_bm_maxlevels[whichfork] = level; +}/* -* Bmap internal routines. +* Convert the given file system block to a disk block. We have to treat it +* differently based on whether the file is a real time file or not, because the +* bmap code does. */ +xfs_daddr_t +xfs_fsb_to_db (struct xfs_inode *ip,xfs_fsblock_t fsb) +{ +return (XFS_IS_REALTIME_INODE (ip) ? \ + (xfs_daddr_t )XFS_FSB_TO_BB ((ip)->i_mount, (fsb)) : \ +XFS_FSB_TO_DADDR ((ip)->i_mount, (fsb))); +} STATIC int /* error */ xfs_bmbt_lookup_eq(
@@ -290,5935 +187,5914 @@ xfs_bmbt_update( }/* -* Called from xfs_bmap_add_attrfork to handle btree format files. +* Compute the worst-case number of indirect blocks that will be used +* for ip's delayed extent of length "len". */ -STATIC int /* error */ -xfs_bmap_add_attrfork_btree ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fsblock_t *firstblock,/* first block allocated */ -xfs_bmap_free_t *flist,/* blocks to free at commit */ -int *flags)/* inode logging flags */ +STATIC xfs_filblks_t +xfs_bmap_worst_indlen ( +xfs_inode_t *ip,/* incore inode pointer */ +xfs_filblks_t len)/* delayed extent length */ { -xfs_btree_cur_t *cur;/* btree cursor */ -int error;/* error return value */ -xfs_mount_t *mp;/* file system mount struct */ -int stat;/* newroot status */ +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; -if (ip->i_df.if_broot_bytes <=XFS_IFORK_DSIZE (ip)) - *flags |=XFS_ILOG_DBROOT ; -else { - cur =xfs_bmbt_init_cursor (mp, tp, ip,XFS_DATA_FORK ); - cur->bc_private.b.flist = flist; - cur->bc_private.b.firstblock = *firstblock; -if ((error =xfs_bmbt_lookup_ge (cur,0 ,0 ,0 , &stat))) - goto error0; -/* must be at least one entry */ -XFS_WANT_CORRUPTED_GOTO (stat ==1 , error0); -if ((error =xfs_btree_new_iroot (cur, flags, &stat))) - goto error0; -if (stat ==0 ) { -xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); -return XFS_ERROR (ENOSPC ); - } - *firstblock = cur->bc_private.b.firstblock; - cur->bc_private.b.allocated =0 ; -xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); + 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 ]; } -return 0 ; -error0: -xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); -return error; +return rval; }/* -* Called from xfs_bmap_add_attrfork to handle extents format files. +* Calculate the default attribute fork offset for newly created inodes. */ -STATIC int /* error */ -xfs_bmap_add_attrfork_extents ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fsblock_t *firstblock,/* first block allocated */ -xfs_bmap_free_t *flist,/* blocks to free at commit */ -int *flags)/* inode logging flags */ +uint +xfs_default_attroffset ( +struct xfs_inode *ip) { -xfs_btree_cur_t *cur;/* bmap btree cursor */ -int error;/* error return value */ +struct xfs_mount *mp = ip->i_mount; +uint offset; -if (ip->i_d.di_nextents *sizeof (xfs_bmbt_rec_t) <=XFS_IFORK_DSIZE (ip)) -return 0 ; - cur =NULL ; - error =xfs_bmap_extents_to_btree (tp, ip, firstblock, flist, &cur,0 , - flags,XFS_DATA_FORK ); -if (cur) { - cur->bc_private.b.allocated =0 ; -xfs_btree_del_cursor (cur, - error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); +if (mp->m_sb.sb_inodesize ==256 ) { + offset =XFS_LITINO (mp) - +XFS_BMDR_SPACE_CALC (MINABTPTRS ); + }else { + offset =XFS_BMDR_SPACE_CALC (6 *MINABTPTRS ); } -return error; + +ASSERT (offset <XFS_LITINO (mp)); +return offset; }/* -* Block initialisation functions for local to extent format conversion. -* As these get more complex, they will be moved to the relevant files, -* but for now they are too simple to worry about. +* Helper routine to reset inode di_forkoff field when switching +* attribute fork from local to extent format - we reset it where +* possible to make space available for inline data fork extents. */ STATIC void -xfs_bmap_local_to_extents_init_fn ( -struct xfs_buf *bp, -struct xfs_inode *ip, -struct xfs_ifork *ifp) +xfs_bmap_forkoff_reset ( +xfs_mount_t *mp, +xfs_inode_t *ip, +int whichfork) { - bp->b_ops = &xfs_bmbt_buf_ops; -memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes); +if (whichfork ==XFS_ATTR_FORK && + ip->i_d.di_format !=XFS_DINODE_FMT_DEV && + ip->i_d.di_format !=XFS_DINODE_FMT_UUID && + ip->i_d.di_format !=XFS_DINODE_FMT_BTREE ) { +uint dfl_forkoff =xfs_default_attroffset (ip) >>3 ; + +if (dfl_forkoff > ip->i_d.di_forkoff) + ip->i_d.di_forkoff = dfl_forkoff; + } } +/* +* Extent tree block counting routines. +*/ + +/* +* Count leaf blocks given a range of extent records. +*/ STATIC void -xfs_symlink_local_to_remote ( -struct xfs_buf *bp, -struct xfs_inode *ip, -struct xfs_ifork *ifp) +xfs_bmap_count_leaves ( +xfs_ifork_t *ifp, +xfs_extnum_t idx, +int numrecs, +int *count) { -/* remote symlink blocks are not verifiable until CRCs come along */ - bp->b_ops =NULL ; -memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes); +int b; + +for (b =0 ; b < numrecs; b++) { +xfs_bmbt_rec_host_t *frp =xfs_iext_get_ext (ifp, idx + b); + *count +=xfs_bmbt_get_blockcount (frp); + } }/* -* Called from xfs_bmap_add_attrfork to handle local format files. Each -* different data fork content type needs a different callout to do the -* conversion. Some are basic and only require special block initialisation -* callouts for the data formating, others (directories) are so specialised they -* handle everything themselves. -* -* XXX (dgc): investigate whether directory conversion can use the generic -* formatting callout. It should be possible - it's just a very complex -* formatter. it would also require passing the transaction through to the init -* function. +* Count leaf blocks given a range of extent records originally +* in btree format. */ -STATIC int /* error */ -xfs_bmap_add_attrfork_local ( -xfs_trans_t *tp,/* transaction pointer */ -xfs_inode_t *ip,/* incore inode pointer */ -xfs_fsblock_t *firstblock,/* first block allocated */ -xfs_bmap_free_t *flist,/* blocks to free at commit */ -int *flags)/* inode logging flags */ +STATIC void +xfs_bmap_disk_count_leaves ( +struct xfs_mount *mp, +struct xfs_btree_block *block, +int numrecs, +int *count) { -xfs_da_args_t dargs;/* args for dir/attr code */ - -if (ip->i_df.if_bytes <=XFS_IFORK_DSIZE (ip)) -return 0 ; +int b; +xfs_bmbt_rec_t *frp; -if (S_ISDIR (ip->i_d.di_mode)) { -memset (&dargs,0 ,sizeof (dargs)); - dargs.dp = ip; - dargs.firstblock = firstblock; - dargs.flist = flist; - dargs.total = ip->i_mount->m_dirblkfsbs; - dargs.whichfork =XFS_DATA_FORK ; - dargs.trans = tp; -return xfs_dir2_sf_to_block (&dargs); +for (b =1 ; b <= numrecs; b++) { + frp =XFS_BMBT_REC_ADDR (mp, block, b); + *count +=xfs_bmbt_disk_get_blockcount (frp); } - -if (S_ISLNK (ip->i_d.di_mode)) -return xfs_bmap_local_to_extents (tp, ip, firstblock,1 , - flags,XFS_DATA_FORK , - xfs_symlink_local_to_remote); - -return xfs_bmap_local_to_extents (tp, ip, firstblock,1 , flags, -XFS_DATA_FORK , - xfs_bmap_local_to_extents_init_fn); }/* -* Convert a delayed allocation to a real allocation. +* Recursively walks each level of a btree +* to count total fsblocks is use. */ -STATIC int /* error */ -xfs_bmap_add_extent_delay_real ( -struct xfs_bmalloca *bma) +STATIC int /* error */ +xfs_bmap_count_tree ( +xfs_mount_t *mp,/* file system mount point */ +xfs_trans_t *tp,/* transaction pointer */ +xfs_ifork_t *ifp,/* inode fork pointer */ +xfs_fsblock_t blockno,/* file system block number */ +int levelin,/* level in btree */ +int *count)/* Count of blocks */ { -struct xfs_bmbt_irec *new = &bma->got; -int diff;/* temp value */ -xfs_bmbt_rec_host_t *ep;/* extent entry for idx */ -int error;/* error return value */ -int i;/* temp state */ -xfs_ifork_t *ifp;/* inode fork pointer */ -xfs_fileoff_t new_endoff;/* end offset of new entry */ -xfs_bmbt_irec_t r[3 ];/* neighbor extent entries */ -/* left is 0, right is 1, prev is 2 */ -int rval=0 ;/* return value (logging flags) */ -int state =0 ;/* state bits, accessed thru macros */ -xfs_filblks_t da_new;/* new count del alloc blocks used */ -xfs_filblks_t da_old;/* old count del alloc blocks used */ -xfs_filblks_t temp=0 ;/* value for da_new calculations */ -xfs_filblks_t temp2=0 ;/* value for da_new calculations */ -int tmp_rval;/* partial logging flags */ +int error; +xfs_buf_t *bp, *nbp; +int level = levelin; +__be64 *pp; +xfs_fsblock_t bno = blockno; +xfs_fsblock_t nextbno; +struct xfs_btree_block *block, *nextblock; +int numrecs; - ifp =XFS_IFORK_PTR (bma->ip,XFS_DATA_FORK ); + error =xfs_btree_read_bufl (mp, tp, bno,0 , &bp,XFS_BMAP_BTREE_REF , + &xfs_bmbt_buf_ops); +if (error) +return error; + *count +=1 ; + block =XFS_BUF_TO_BLOCK (bp); -ASSERT (bma->idx >=0 ); -ASSERT (bma->idx <= ifp->if_bytes /sizeof (struct xfs_bmbt_rec )); -ASSERT (!isnullstartblock (new->br_startblock)); -ASSERT (!bma->cur || - (bma->cur->bc_private.b.flags &XFS_BTCUR_BPRV_WASDEL )); +if (--level) { +/* Not at node above leaves, count this level of nodes */ + nextbno =be64_to_cpu (block->bb_u.l.bb_rightsib); +while (nextbno !=NULLFSBLOCK ) { + error =xfs_btree_read_bufl (mp, tp, nextbno,0 , &nbp, +XFS_BMAP_BTREE_REF , + &xfs_bmbt_buf_ops); +if (error) +return error; + *count +=1 ; + nextblock =XFS_BUF_TO_BLOCK (nbp); + nextbno =be64_to_cpu (nextblock->bb_u.l.bb_rightsib); +xfs_trans_brelse (tp, nbp); + } -XFS_STATS_INC (xs_add_exlist); +/* Dive to the next level */ + pp =XFS_BMBT_PTR_ADDR (mp, block,1 , mp->m_bmap_dmxr[1 ]); + bno =be64_to_cpu (*pp); +if (unlikely ((error = +xfs_bmap_count_tree (mp, tp, ifp, bno, level, count)) <0 )) { +xfs_trans_brelse (tp, bp); +XFS_ERROR_REPORT ("xfs_bmap_count_tree(1)" , +XFS_ERRLEVEL_LOW , mp); +return XFS_ERROR (EFSCORRUPTED ); + } +xfs_trans_brelse (tp, bp); + }else { +/* count all level 1 nodes and their leaves */ +for (;;) { + nextbno =be64_to_cpu (block->bb_u.l.bb_rightsib); + numrecs =be16_to_cpu (block->bb_numrecs); +xfs_bmap_disk_count_leaves (mp, block, numrecs, count); +xfs_trans_brelse (tp, bp); +if (nextbno ==NULLFSBLOCK ) +break ; + bno = nextbno; + error =xfs_btree_read_bufl (mp, tp, bno,0 , &bp, +XFS_BMAP_BTREE_REF , + &xfs_bmbt_buf_ops); +if (error) +return error; + *count +=1 ; + block =XFS_BUF_TO_BLOCK (bp); + } + } +return 0 ; +} -#define LEFT r[0] -#define RIGHT r[1] -#define PREV r[2] +/* +* Count fsblocks of the given fork. +*/ +int /* error */ +xfs_bmap_count_blocks ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode */ +int whichfork,/* data or attr fork */ +int *count)/* out: count of blocks */ +{ +struct xfs_btree_block *block;/* current btree block */ +xfs_fsblock_t bno;/* block # of "block" */ +xfs_ifork_t *ifp;/* fork structure */ +int level;/* btree level, for checking */ +xfs_mount_t *mp;/* file system mount structure */ +__be64 *pp;/* pointer to block address */ + + bno =NULLFSBLOCK ; + mp = ip->i_mount; + ifp =XFS_IFORK_PTR (ip, whichfork); +if (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_EXTENTS ) { +xfs_bmap_count_leaves (ifp,0 , + ifp->if_bytes / (uint )sizeof (xfs_bmbt_rec_t), + count); +return 0 ; + }/* -* Set up a bunch of variables to make the tests simpler. +* Root level must use BMAP_BROOT_PTR_ADDR macro to get ptr out. */ - ep =xfs_iext_get_ext (ifp, bma->idx); -xfs_bmbt_get_all (ep, &PREV ); - new_endoff = new->br_startoff + new->br_blockcount; -ASSERT (PREV .br_startoff <= new->br_startoff); -ASSERT (PREV .br_startoff +PREV .br_blockcount >= new_endoff); + block = ifp->if_broot; + level =be16_to_cpu (block->bb_level); +ASSERT (level >0 ); + pp =XFS_BMAP_BROOT_PTR_ADDR (mp, block,1 , ifp->if_broot_bytes); + bno =be64_to_cpu (*pp); +ASSERT (bno !=NULLDFSBNO ); +ASSERT (XFS_FSB_TO_AGNO (mp, bno) < mp->m_sb.sb_agcount); +ASSERT (XFS_FSB_TO_AGBNO (mp, bno) < mp->m_sb.sb_agblocks); - da_old =startblockval (PREV .br_startblock); - da_new =0 ; +if (unlikely (xfs_bmap_count_tree (mp, tp, ifp, bno, level, count) <0 )) { +XFS_ERROR_REPORT ("xfs_bmap_count_blocks(2)" ,XFS_ERRLEVEL_LOW , + mp); +return XFS_ERROR (EFSCORRUPTED ); + } -/* -* Set flags determining what part of the previous delayed allocation -* extent is being replaced by a real allocation. -*/ -if (PREV .br_startoff == new->br_startoff) - state |=BMAP_LEFT_FILLING ; -if (PREV .br_startoff +PREV .br_blockcount == new_endoff) - state |=BMAP_RIGHT_FILLING ; +return 0 ; +} -/* -* Check and set flags if this segment has a left neighbor. -* Don't set contiguous if the combined extent would be too large. -*/ -if (bma->idx >0 ) { - state |=BMAP_LEFT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, bma->idx -1 ), &LEFT ); +/* +* Debug/sanity checking code +*/ -if (isnullstartblock (LEFT .br_startblock)) - state |=BMAP_LEFT_DELAY ; - } +STATIC int +xfs_bmap_sanity_check ( +struct xfs_mount *mp, +struct xfs_buf *bp, +int level) +{ +struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); -if ((state &BMAP_LEFT_VALID ) && !(state &BMAP_LEFT_DELAY ) && -LEFT .br_startoff +LEFT .br_blockcount == new->br_startoff && -LEFT .br_startblock +LEFT .br_blockcount == new->br_startblock && -LEFT .br_state == new->br_state && -LEFT .br_blockcount + new->br_blockcount <=MAXEXTLEN ) - state |=BMAP_LEFT_CONTIG ; +if (block->bb_magic !=cpu_to_be32 (XFS_BMAP_MAGIC ) || +be16_to_cpu (block->bb_level) != level || +be16_to_cpu (block->bb_numrecs) ==0 || +be16_to_cpu (block->bb_numrecs) > mp->m_bmap_dmxr[level !=0 ]) +return 0 ; +return 1 ; +} -/* -* Check and set flags if this segment has a right neighbor. -* 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 ) { - state |=BMAP_RIGHT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, bma->idx +1 ), &RIGHT ); +#ifdef DEBUG +STATIC struct xfs_buf * +xfs_bmap_get_bp ( +struct xfs_btree_cur *cur, +xfs_fsblock_t bno) +{ +struct xfs_log_item_desc *lidp; +int i; -if (isnullstartblock (RIGHT .br_startblock)) - state |=BMAP_RIGHT_DELAY ; +if (!cur) +return NULL ; + +for (i =0 ; i <XFS_BTREE_MAXLEVELS ; i++) { +if (!cur->bc_bufs[i]) +break ; +if (XFS_BUF_ADDR (cur->bc_bufs[i]) == bno) +return cur->bc_bufs[i]; } -if ((state &BMAP_RIGHT_VALID ) && !(state &BMAP_RIGHT_DELAY ) && - new_endoff ==RIGHT .br_startoff && - new->br_startblock + new->br_blockcount ==RIGHT .br_startblock && - new->br_state ==RIGHT .br_state && - new->br_blockcount +RIGHT .br_blockcount <=MAXEXTLEN && - ((state & (BMAP_LEFT_CONTIG |BMAP_LEFT_FILLING | -BMAP_RIGHT_FILLING )) != - (BMAP_LEFT_CONTIG |BMAP_LEFT_FILLING | -BMAP_RIGHT_FILLING ) || -LEFT .br_blockcount + new->br_blockcount +RIGHT .br_blockcount - <=MAXEXTLEN )) - state |=BMAP_RIGHT_CONTIG ; +/* Chase down all the log items to see if the bp is there */ +list_for_each_entry (lidp, &cur->bc_tp->t_items, lid_trans) { +struct xfs_buf_log_item *bip; + bip = (struct xfs_buf_log_item *)lidp->lid_item; +if (bip->bli_item.li_type ==XFS_LI_BUF && +XFS_BUF_ADDR (bip->bli_buf) == bno) +return bip->bli_buf; + } - error =0 ; -/* -* Switch out based on the FILLING and CONTIG state bits. -*/ -switch (state & (BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG | -BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG )) { -case BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG | -BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG : -/* -* Filling in all of a previously delayed allocation extent. -* The left and right neighbors are both contiguous with new. -*/ - bma->idx--; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, bma->idx), -LEFT .br_blockcount +PREV .br_blockcount + -RIGHT .br_blockcount); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +return NULL ; +} -xfs_iext_remove (bma->ip, bma->idx +1 ,2 , state); - bma->ip->i_d.di_nextents--; -if (bma->cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; - error =xfs_bmbt_lookup_eq (bma->cur,RIGHT .br_startoff, -RIGHT .br_startblock, -RIGHT .br_blockcount, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_btree_delete (bma->cur, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_btree_decrement (bma->cur,0 , &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_bmbt_update (bma->cur,LEFT .br_startoff, -LEFT .br_startblock, -LEFT .br_blockcount + -PREV .br_blockcount + -RIGHT .br_blockcount,LEFT .br_state); -if (error) - goto done; - } -break ; +STATIC void +xfs_check_block ( +struct xfs_btree_block *block, +xfs_mount_t *mp, +int root, +short sz) +{ +int i, j, dmxr; +__be64 *pp, *thispa;/* pointer to block address */ +xfs_bmbt_key_t *prevp, *keyp; -case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING |BMAP_LEFT_CONTIG : -/* -* Filling in all of a previously delayed allocation extent. -* The left neighbor is contiguous, the right is not. -*/ - bma->idx--; +ASSERT (be16_to_cpu (block->bb_level) >0 ); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, bma->idx), -LEFT .br_blockcount +PREV .br_blockcount); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); + prevp =NULL ; +for ( i =1 ; i <=xfs_btree_get_numrecs (block); i++) { + dmxr = mp->m_bmap_dmxr[0 ]; + keyp =XFS_BMBT_KEY_ADDR (mp, block, i); -xfs_iext_remove (bma->ip, bma->idx +1 ,1 , state); -if (bma->cur ==NULL ) - rval =XFS_ILOG_DEXT ; -else { - rval =0 ; - error =xfs_bmbt_lookup_eq (bma->cur,LEFT .br_startoff, -LEFT .br_startblock,LEFT .br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_bmbt_update (bma->cur,LEFT .br_startoff, -LEFT .br_startblock, -LEFT .br_blockcount + -PREV .br_blockcount,LEFT .br_state); -if (error) - goto done; +if (prevp) { +ASSERT (be64_to_cpu (prevp->br_startoff) < +be64_to_cpu (keyp->br_startoff)); } -break ; + prevp = keyp; -case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG :/* -* Filling in all of a previously delayed allocation extent. -* The right neighbor is contiguous, the left is not. +* Compare the block numbers to see if there are dups. */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_startblock (ep, new->br_startblock); -xfs_bmbt_set_blockcount (ep, -PREV .br_blockcount +RIGHT .br_blockcount); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +if (root) + pp =XFS_BMAP_BROOT_PTR_ADDR (mp, block, i, sz); +else + pp =XFS_BMBT_PTR_ADDR (mp, block, i, dmxr); -xfs_iext_remove (bma->ip, bma->idx +1 ,1 , state); -if (bma->cur ==NULL ) - rval =XFS_ILOG_DEXT ; -else { - rval =0 ; - error =xfs_bmbt_lookup_eq (bma->cur,RIGHT .br_startoff, -RIGHT .br_startblock, -RIGHT .br_blockcount, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_bmbt_update (bma->cur,PREV .br_startoff, - new->br_startblock, -PREV .br_blockcount + -RIGHT .br_blockcount,PREV .br_state); -if (error) - goto done; +for (j = i+1 ; j <=be16_to_cpu (block->bb_numrecs); j++) { +if (root) + thispa =XFS_BMAP_BROOT_PTR_ADDR (mp, block, j, sz); +else + thispa =XFS_BMBT_PTR_ADDR (mp, block, j, dmxr); +if (*thispa == *pp) { +xfs_warn (mp,"%s: thispa(%d) == pp(%d) %Ld" , + __func__, j, i, + (unsigned long long )be64_to_cpu (*thispa)); +panic ("%s: ptrs are equal in node\n" , + __func__); + } } -break ; + } +} -case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING : -/* -* Filling in all of a previously delayed allocation extent. -* Neither the left nor right neighbors are contiguous with -* the new one. -*/ -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_startblock (ep, new->br_startblock); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); +/* +* Check that the extents for the inode ip are in the right order in all +* btree leaves. +*/ - bma->ip->i_d.di_nextents++; -if (bma->cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; - error =xfs_bmbt_lookup_eq (bma->cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==0 , done); - bma->cur->bc_rec.b.br_state =XFS_EXT_NORM ; - error =xfs_btree_insert (bma->cur, &i); +STATIC void +xfs_bmap_check_leaf_extents ( +xfs_btree_cur_t *cur,/* btree cursor or null */ +xfs_inode_t *ip,/* incore inode pointer */ +int whichfork)/* data or attr fork */ +{ +struct xfs_btree_block *block;/* current btree block */ +xfs_fsblock_t bno;/* block # of "block" */ +xfs_buf_t *bp;/* buffer for "block" */ +int error;/* error return value */ +xfs_extnum_t i=0 , j;/* index into the extents list */ +xfs_ifork_t *ifp;/* fork structure */ +int level;/* btree level, for checking */ +xfs_mount_t *mp;/* file system mount structure */ +__be64 *pp;/* pointer to block address */ +xfs_bmbt_rec_t *ep;/* pointer to current extent */ +xfs_bmbt_rec_t last = {0 ,0 };/* last extent in prev block */ +xfs_bmbt_rec_t *nextp;/* pointer to next extent */ +int bp_release =0 ; + +if (XFS_IFORK_FORMAT (ip, whichfork) !=XFS_DINODE_FMT_BTREE ) { +return ; + } + + bno =NULLFSBLOCK ; + mp = ip->i_mount; + ifp =XFS_IFORK_PTR (ip, whichfork); + block = ifp->if_broot; +/* +* Root level must use BMAP_BROOT_PTR_ADDR macro to get ptr out. +*/ + level =be16_to_cpu (block->bb_level); +ASSERT (level >0 ); +xfs_check_block (block, mp,1 , ifp->if_broot_bytes); + pp =XFS_BMAP_BROOT_PTR_ADDR (mp, block,1 , ifp->if_broot_bytes); + bno =be64_to_cpu (*pp); + +ASSERT (bno !=NULLDFSBNO ); +ASSERT (XFS_FSB_TO_AGNO (mp, bno) < mp->m_sb.sb_agcount); +ASSERT (XFS_FSB_TO_AGBNO (mp, bno) < mp->m_sb.sb_agblocks); + +/* +* Go down the tree until leaf level is reached, following the first +* pointer (leftmost) at each level. +*/ +while (level-- >0 ) { +/* See if buf is in cur first */ + bp_release =0 ; + bp =xfs_bmap_get_bp (cur,XFS_FSB_TO_DADDR (mp, bno)); +if (!bp) { + bp_release =1 ; + error =xfs_btree_read_bufl (mp,NULL , bno,0 , &bp, +XFS_BMAP_BTREE_REF , + &xfs_bmbt_buf_ops);if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); + goto error_norelse; } -break ; + block =XFS_BUF_TO_BLOCK (bp); +XFS_WANT_CORRUPTED_GOTO ( +xfs_bmap_sanity_check (mp, bp, level), + error0); +if (level ==0 ) +break ; -case BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG :/* -* Filling in the first part of a previous delayed allocation. -* The left neighbor is contiguous. +* Check this block for basic sanity (increasing keys and +* no duplicate blocks). */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx -1 , state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, bma->idx -1 ), -LEFT .br_blockcount + new->br_blockcount); -xfs_bmbt_set_startoff (ep, -PREV .br_startoff + new->br_blockcount); -trace_xfs_bmap_post_update (bma->ip, bma->idx -1 , state, _THIS_IP_); - temp =PREV .br_blockcount - new->br_blockcount; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (ep, temp); -if (bma->cur ==NULL ) - rval =XFS_ILOG_DEXT ; -else { - rval =0 ; - error =xfs_bmbt_lookup_eq (bma->cur,LEFT .br_startoff, -LEFT .br_startblock,LEFT .br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_bmbt_update (bma->cur,LEFT .br_startoff, -LEFT .br_startblock, -LEFT .br_blockcount + - new->br_blockcount, -LEFT .br_state); -if (error) - goto done; +xfs_check_block (block, mp,0 ,0 ); + pp =XFS_BMBT_PTR_ADDR (mp, block,1 , mp->m_bmap_dmxr[1 ]); + bno =be64_to_cpu (*pp); +XFS_WANT_CORRUPTED_GOTO (XFS_FSB_SANITY_CHECK (mp, bno), error0); +if (bp_release) { + bp_release =0 ; +xfs_trans_brelse (NULL , bp); } - da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp), -startblockval (PREV .br_startblock)); -xfs_bmbt_set_startblock (ep,nullstartblock (da_new)); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); + } - bma->idx--; -break ; +/* +* Here with bp and block set to the leftmost leaf node in the tree. +*/ + i =0 ; + +/* +* Loop over all leaf nodes checking that all extents are in the right order. +*/ +for (;;) { +xfs_fsblock_t nextbno; +xfs_extnum_t num_recs; + + + num_recs =xfs_btree_get_numrecs (block); -case BMAP_LEFT_FILLING :/* -* Filling in the first part of a previous delayed allocation. -* The left neighbor is not contiguous. +* Read-ahead the next leaf block, if any. */ -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_startoff (ep, new_endoff); - temp =PREV .br_blockcount - new->br_blockcount; -xfs_bmbt_set_blockcount (ep, temp); -xfs_iext_insert (bma->ip, bma->idx,1 , new, state); - bma->ip->i_d.di_nextents++; -if (bma->cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; - error =xfs_bmbt_lookup_eq (bma->cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==0 , done); - bma->cur->bc_rec.b.br_state =XFS_EXT_NORM ; - error =xfs_btree_insert (bma->cur, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - } -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { - error =xfs_bmap_extents_to_btree (bma->tp, bma->ip, - bma->firstblock, bma->flist, - &bma->cur,1 , &tmp_rval,XFS_DATA_FORK ); - rval |= tmp_rval; -if (error) - goto done; - } - da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp), -startblockval (PREV .br_startblock) - - (bma->cur ? bma->cur->bc_private.b.allocated :0 )); - ep =xfs_iext_get_ext (ifp, bma->idx +1 ); -xfs_bmbt_set_startblock (ep,nullstartblock (da_new)); -trace_xfs_bmap_post_update (bma->ip, bma->idx +1 , state, _THIS_IP_); -break ; + nextbno =be64_to_cpu (block->bb_u.l.bb_rightsib); -case BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG :/* -* Filling in the last part of a previous delayed allocation. -* The right neighbor is contiguous with the new allocation. +* Check all the extents to make sure they are OK. +* If we had a previous block, the last entry should +* conform with the first entry in this one. */ - temp =PREV .br_blockcount - new->br_blockcount; -trace_xfs_bmap_pre_update (bma->ip, bma->idx +1 , state, _THIS_IP_); -xfs_bmbt_set_blockcount (ep, temp); -xfs_bmbt_set_allf (xfs_iext_get_ext (ifp, bma->idx +1 ), - new->br_startoff, new->br_startblock, - new->br_blockcount +RIGHT .br_blockcount, -RIGHT .br_state); -trace_xfs_bmap_post_update (bma->ip, bma->idx +1 , state, _THIS_IP_); -if (bma->cur ==NULL ) - rval =XFS_ILOG_DEXT ; -else { - rval =0 ; - error =xfs_bmbt_lookup_eq (bma->cur,RIGHT .br_startoff, -RIGHT .br_startblock, -RIGHT .br_blockcount, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_bmbt_update (bma->cur, new->br_startoff, - new->br_startblock, - new->br_blockcount + -RIGHT .br_blockcount, -RIGHT .br_state); -if (error) - goto done; - } - - da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp), -startblockval (PREV .br_startblock)); -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_startblock (ep,nullstartblock (da_new)); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); - bma->idx++; -break ; + ep =XFS_BMBT_REC_ADDR (mp, block,1 ); +if (i) { +ASSERT (xfs_bmbt_disk_get_startoff (&last) + +xfs_bmbt_disk_get_blockcount (&last) <= +xfs_bmbt_disk_get_startoff (ep)); + } +for (j =1 ; j < num_recs; j++) { + nextp =XFS_BMBT_REC_ADDR (mp, block, j +1 ); +ASSERT (xfs_bmbt_disk_get_startoff (ep) + +xfs_bmbt_disk_get_blockcount (ep) <= +xfs_bmbt_disk_get_startoff (nextp)); + ep = nextp; + } -case BMAP_RIGHT_FILLING : + last = *ep; + i += num_recs; +if (bp_release) { + bp_release =0 ; +xfs_trans_brelse (NULL , bp); + } + bno = nextbno;/* -* Filling in the last part of a previous delayed allocation. -* The right neighbor is not contiguous. +* If we've reached the end, stop. */ - temp =PREV .br_blockcount - new->br_blockcount; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (ep, temp); -xfs_iext_insert (bma->ip, bma->idx +1 ,1 , new, state); - bma->ip->i_d.di_nextents++; -if (bma->cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; - error =xfs_bmbt_lookup_eq (bma->cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==0 , done); - bma->cur->bc_rec.b.br_state =XFS_EXT_NORM ; - error =xfs_btree_insert (bma->cur, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - } - -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { - error =xfs_bmap_extents_to_btree (bma->tp, bma->ip, - bma->firstblock, bma->flist, &bma->cur,1 , - &tmp_rval,XFS_DATA_FORK ); - rval |= tmp_rval; -if (error) - goto done; - } - da_new =XFS_FILBLKS_MIN (xfs_bmap_worst_indlen (bma->ip, temp), -startblockval (PREV .br_startblock) - - (bma->cur ? bma->cur->bc_private.b.allocated :0 )); - ep =xfs_iext_get_ext (ifp, bma->idx); -xfs_bmbt_set_startblock (ep,nullstartblock (da_new)); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); - - bma->idx++; -break ; - -case 0 : -/* -* Filling in the middle part of a previous delayed allocation. -* Contiguity is impossible here. -* This case is avoided almost all the time. -* -* We start with a delayed allocation: -* -* +ddddddddddddddddddddddddddddddddddddddddddddddddddddddd+ -* PREV @ idx -* -* and we are allocating: -* +rrrrrrrrrrrrrrrrr+ -* new -* -* and we set it up for insertion as: -* +ddddddddddddddddddd+rrrrrrrrrrrrrrrrr+ddddddddddddddddd+ -* new -* PREV @ idx LEFT RIGHT -* inserted at idx + 1 -*/ - temp = new->br_startoff -PREV .br_startoff; - temp2 =PREV .br_startoff +PREV .br_blockcount - new_endoff; -trace_xfs_bmap_pre_update (bma->ip, bma->idx,0 , _THIS_IP_); -xfs_bmbt_set_blockcount (ep, temp);/* truncate PREV */ -LEFT = *new; -RIGHT .br_state =PREV .br_state; -RIGHT .br_startblock =nullstartblock ( - (int )xfs_bmap_worst_indlen (bma->ip, temp2)); -RIGHT .br_startoff = new_endoff; -RIGHT .br_blockcount = temp2; -/* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */ -xfs_iext_insert (bma->ip, bma->idx +1 ,2 , &LEFT , state); - bma->ip->i_d.di_nextents++; -if (bma->cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; - error =xfs_bmbt_lookup_eq (bma->cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==0 , done); - bma->cur->bc_rec.b.br_state =XFS_EXT_NORM ; - error =xfs_btree_insert (bma->cur, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - } +if (bno ==NULLFSBLOCK ) +break ; -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { - error =xfs_bmap_extents_to_btree (bma->tp, bma->ip, - bma->firstblock, bma->flist, &bma->cur, -1 , &tmp_rval,XFS_DATA_FORK ); - rval |= tmp_rval; -if (error) - goto done; - } - temp =xfs_bmap_worst_indlen (bma->ip, temp); - temp2 =xfs_bmap_worst_indlen (bma->ip, temp2); - diff = (int )(temp + temp2 -startblockval (PREV .br_startblock) - - (bma->cur ? bma->cur->bc_private.b.allocated :0 )); -if (diff >0 ) { - error =xfs_icsb_modify_counters (bma->ip->i_mount, -XFS_SBS_FDBLOCKS , - -((int64_t )diff),0 ); -ASSERT (!error); + bp_release =0 ; + bp =xfs_bmap_get_bp (cur,XFS_FSB_TO_DADDR (mp, bno)); +if (!bp) { + bp_release =1 ; + error =xfs_btree_read_bufl (mp,NULL , bno,0 , &bp, +XFS_BMAP_BTREE_REF , + &xfs_bmbt_buf_ops);if (error) - goto done; + goto error_norelse; } - - ep =xfs_iext_get_ext (ifp, bma->idx); -xfs_bmbt_set_startblock (ep,nullstartblock ((int )temp)); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); -trace_xfs_bmap_pre_update (bma->ip, bma->idx +2 , state, _THIS_IP_); -xfs_bmbt_set_startblock (xfs_iext_get_ext (ifp, bma->idx +2 ), -nullstartblock ((int )temp2)); -trace_xfs_bmap_post_update (bma->ip, bma->idx +2 , state, _THIS_IP_); - - bma->idx++; - da_new = temp + temp2; -break ; - -case BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -case BMAP_RIGHT_FILLING |BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -case BMAP_LEFT_FILLING |BMAP_RIGHT_CONTIG : -case BMAP_RIGHT_FILLING |BMAP_LEFT_CONTIG : -case BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -case BMAP_LEFT_CONTIG : -case BMAP_RIGHT_CONTIG : -/* -* These cases are all impossible. -*/ -ASSERT (0 ); - } - -/* convert to a btree if necessary */ -if (xfs_bmap_needs_btree (bma->ip,XFS_DATA_FORK )) { -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 ); - bma->logflags |= tmp_logflags; -if (error) - goto done; + block =XFS_BUF_TO_BLOCK (bp); } - -/* adjust for changes in reserved delayed indirect blocks */ -if (da_old || da_new) { - temp = da_new; -if (bma->cur) - temp += bma->cur->bc_private.b.allocated; -ASSERT (temp <= da_old); -if (temp < da_old) -xfs_icsb_modify_counters (bma->ip->i_mount, -XFS_SBS_FDBLOCKS , - (int64_t )(da_old - temp),0 ); +if (bp_release) { + bp_release =0 ; +xfs_trans_brelse (NULL , bp); } +return ; -/* clear out the allocated field, done with it now in any case. */ -if (bma->cur) - bma->cur->bc_private.b.allocated =0 ; - -xfs_bmap_check_leaf_extents (bma->cur, bma->ip,XFS_DATA_FORK ); -done: - bma->logflags |= rval; -return error; -#undef LEFT -#undef RIGHT -#undef PREV +error0: +xfs_warn (mp,"%s: at error0" , __func__); +if (bp_release) +xfs_trans_brelse (NULL , bp); +error_norelse: +xfs_warn (mp,"%s: BAD after btree leaves for %d extents" , + __func__, i); +panic ("%s: CORRUPTED BTREE OR SOMETHING" , __func__); +return ; }/* -* Convert an unwritten allocation to a real allocation or vice versa. +* Add bmap trace insert entries for all the contents of the extent records. */ -STATIC int /* error */ -xfs_bmap_add_extent_unwritten_real ( -struct xfs_trans *tp, -xfs_inode_t *ip,/* incore inode pointer */ -xfs_extnum_t *idx,/* extent number to update/insert */ -xfs_btree_cur_t **curp,/* if *curp is null, not a btree */ -xfs_bmbt_irec_t *new,/* new data to add to file extents */ -xfs_fsblock_t *first,/* pointer to firstblock variable */ -xfs_bmap_free_t *flist,/* list of extents to be freed */ -int *logflagsp)/* inode logging flags */ +void +xfs_bmap_trace_exlist ( +xfs_inode_t *ip,/* incore inode pointer */ +xfs_extnum_t cnt,/* count of entries in the list */ +int whichfork,/* data or attr fork */ +unsigned long caller_ip) { -xfs_btree_cur_t *cur;/* btree cursor */ -xfs_bmbt_rec_host_t *ep;/* extent entry for idx */ -int error;/* error return value */ -int i;/* temp state */ -xfs_ifork_t *ifp;/* inode fork pointer */ -xfs_fileoff_t new_endoff;/* end offset of new entry */ -xfs_exntst_t newext;/* new extent state */ -xfs_exntst_t oldext;/* old extent state */ -xfs_bmbt_irec_t r[3 ];/* neighbor extent entries */ -/* left is 0, right is 1, prev is 2 */ -int rval=0 ;/* return value (logging flags) */ -int state =0 ;/* state bits, accessed thru macros */ - - *logflagsp =0 ; +xfs_extnum_t idx;/* extent record index */ +xfs_ifork_t *ifp;/* inode fork pointer */ +int state =0 ; - cur = *curp; - ifp =XFS_IFORK_PTR (ip,XFS_DATA_FORK ); +if (whichfork ==XFS_ATTR_FORK ) + state |=BMAP_ATTRFORK ; -ASSERT (*idx >=0 ); -ASSERT (*idx <= ifp->if_bytes /sizeof (struct xfs_bmbt_rec )); -ASSERT (!isnullstartblock (new->br_startblock)); + ifp =XFS_IFORK_PTR (ip, whichfork); +ASSERT (cnt == (ifp->if_bytes / (uint )sizeof (xfs_bmbt_rec_t))); +for (idx =0 ; idx < cnt; idx++) +trace_xfs_extlist (ip, idx, whichfork, caller_ip); +} -XFS_STATS_INC (xs_add_exlist); +/* +* Validate that the bmbt_irecs being returned from bmapi are valid +* given the callers original parameters. Specifically check the +* ranges of the returned irecs to ensure that they only extent beyond +* the given parameters if the XFS_BMAPI_ENTIRE flag was set. +*/ +STATIC void +xfs_bmap_validate_ret ( +xfs_fileoff_t bno, +xfs_filblks_t len, +int flags, +xfs_bmbt_irec_t *mval, +int nmap, +int ret_nmap) +{ +int i;/* index to map values */ -#define LEFT r[0] -#define RIGHT r[1] -#define PREV r[2] +ASSERT (ret_nmap <= nmap); -/* -* Set up a bunch of variables to make the tests simpler. -*/ - error =0 ; - ep =xfs_iext_get_ext (ifp, *idx); -xfs_bmbt_get_all (ep, &PREV ); - newext = new->br_state; - oldext = (newext ==XFS_EXT_UNWRITTEN ) ? -XFS_EXT_NORM :XFS_EXT_UNWRITTEN ; -ASSERT (PREV .br_state == oldext); - new_endoff = new->br_startoff + new->br_blockcount; -ASSERT (PREV .br_startoff <= new->br_startoff); -ASSERT (PREV .br_startoff +PREV .br_blockcount >= new_endoff); +for (i =0 ; i < ret_nmap; i++) { +ASSERT (mval[i].br_blockcount >0 ); +if (!(flags &XFS_BMAPI_ENTIRE )) { +ASSERT (mval[i].br_startoff >= bno); +ASSERT (mval[i].br_blockcount <= len); +ASSERT (mval[i].br_startoff + mval[i].br_blockcount <= + bno + len); + }else { +ASSERT (mval[i].br_startoff < bno + len); +ASSERT (mval[i].br_startoff + mval[i].br_blockcount > + bno); + } +ASSERT (i ==0 || + mval[i -1 ].br_startoff + mval[i -1 ].br_blockcount == + mval[i].br_startoff); +ASSERT (mval[i].br_startblock !=DELAYSTARTBLOCK && + mval[i].br_startblock !=HOLESTARTBLOCK ); +ASSERT (mval[i].br_state ==XFS_EXT_NORM || + mval[i].br_state ==XFS_EXT_UNWRITTEN ); + } +} -/* -* Set flags determining what part of the previous oldext allocation -* extent is being replaced by a newext allocation. -*/ -if (PREV .br_startoff == new->br_startoff) - state |=BMAP_LEFT_FILLING ; -if (PREV .br_startoff +PREV .br_blockcount == new_endoff) - state |=BMAP_RIGHT_FILLING ; +#else +#define xfs_bmap_check_leaf_extents (cur, ip, whichfork) do { } while (0) +#define xfs_bmap_validate_ret (bno,len,flags,mval,onmap,nmap) +#endif /* DEBUG */ -/* -* Check and set flags if this segment has a left neighbor. -* Don't set contiguous if the combined extent would be too large. -*/ -if (*idx >0 ) { - state |=BMAP_LEFT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, *idx -1 ), &LEFT ); +/* +* bmap free list manipulation functions +*/ -if (isnullstartblock (LEFT .br_startblock)) - state |=BMAP_LEFT_DELAY ; +/* +* Add the extent to the list of extents to be free at transaction end. +* The list is maintained sorted (by block number). +*/ +void +xfs_bmap_add_free ( +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_bmap_free_item_t *cur;/* current (next) element */ +xfs_bmap_free_item_t *new;/* new element */ +xfs_bmap_free_item_t *prev;/* previous element */ +#ifdef DEBUG +xfs_agnumber_t agno; +xfs_agblock_t agbno; + +ASSERT (bno !=NULLFSBLOCK ); +ASSERT (len >0 ); +ASSERT (len <=MAXEXTLEN ); +ASSERT (!isnullstartblock (bno)); + agno =XFS_FSB_TO_AGNO (mp, bno); + agbno =XFS_FSB_TO_AGBNO (mp, bno); +ASSERT (agno < mp->m_sb.sb_agcount); +ASSERT (agbno < mp->m_sb.sb_agblocks); +ASSERT (len < mp->m_sb.sb_agblocks); +ASSERT (agbno + len <= mp->m_sb.sb_agblocks); +#endif +ASSERT (xfs_bmap_free_item_zone !=NULL ); + new =kmem_zone_alloc (xfs_bmap_free_item_zone,KM_SLEEP ); + new->xbfi_startblock = bno; + new->xbfi_blockcount = (xfs_extlen_t )len; +for (prev =NULL , cur = flist->xbf_first; + cur !=NULL ; + prev = cur, cur = cur->xbfi_next) { +if (cur->xbfi_startblock >= bno) +break ; } +if (prev) + prev->xbfi_next = new; +else + flist->xbf_first = new; + new->xbfi_next = cur; + flist->xbf_count++; +} -if ((state &BMAP_LEFT_VALID ) && !(state &BMAP_LEFT_DELAY ) && -LEFT .br_startoff +LEFT .br_blockcount == new->br_startoff && -LEFT .br_startblock +LEFT .br_blockcount == new->br_startblock && -LEFT .br_state == newext && -LEFT .br_blockcount + new->br_blockcount <=MAXEXTLEN ) - state |=BMAP_LEFT_CONTIG ; +/* +* Remove the entry "free" from the free item list. Prev points to the +* previous entry, unless "free" is the head of the list. +*/ +STATIC void +xfs_bmap_del_free ( +xfs_bmap_free_t *flist,/* free item list header */ +xfs_bmap_free_item_t *prev,/* previous item on list, if any */ +xfs_bmap_free_item_t *free)/* list item to be freed */ +{ +if (prev) + prev->xbfi_next = free->xbfi_next; +else + flist->xbf_first = free->xbfi_next; + flist->xbf_count--; +kmem_zone_free (xfs_bmap_free_item_zone, free); +} + + +/* +* Routine to be called at transaction's end by xfs_bmapi, xfs_bunmapi +* caller. Frees all the extents that need freeing, which must be done +* last due to locking considerations. We never free any extents in +* the first transaction. +* +* Return 1 if the given transaction was committed and a new one +* started, and 0 otherwise in the committed parameter. +*/ +int /* error */ +xfs_bmap_finish ( +xfs_trans_t **tp,/* transaction pointer addr */ +xfs_bmap_free_t *flist,/* i/o: list extents to free */ +int *committed)/* xact committed or not */ +{ +xfs_efd_log_item_t *efd;/* extent free data */ +xfs_efi_log_item_t *efi;/* extent free intention */ +int error;/* error return value */ +xfs_bmap_free_item_t *free;/* free extent item */ +unsigned int logres;/* new log reservation */ +unsigned int logcount;/* new log count */ +xfs_mount_t *mp;/* filesystem mount structure */ +xfs_bmap_free_item_t *next;/* next item on free list */ +xfs_trans_t *ntp;/* new transaction pointer */ +ASSERT ((*tp)->t_flags &XFS_TRANS_PERM_LOG_RES ); +if (flist->xbf_count ==0 ) { + *committed =0 ; +return 0 ; + } + ntp = *tp; + efi =xfs_trans_get_efi (ntp, flist->xbf_count); +for (free = flist->xbf_first; free; free = free->xbfi_next) +xfs_trans_log_efi_extent (ntp, efi, free->xbfi_startblock, + free->xbfi_blockcount); + logres = ntp->t_log_res; + logcount = ntp->t_log_count; + ntp =xfs_trans_dup (*tp); + error =xfs_trans_commit (*tp,0 ); + *tp = ntp; + *committed =1 ;/* -* Check and set flags if this segment has a right neighbor. -* Don't set contiguous if the combined extent would be too large. -* Also check for all-three-contiguous being too large. +* We have a new transaction, so we should return committed=1, +* even though we're returning an error. */ -if (*idx < ip->i_df.if_bytes / (uint )sizeof (xfs_bmbt_rec_t) -1 ) { - state |=BMAP_RIGHT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, *idx +1 ), &RIGHT ); -if (isnullstartblock (RIGHT .br_startblock)) - state |=BMAP_RIGHT_DELAY ; - } - -if ((state &BMAP_RIGHT_VALID ) && !(state &BMAP_RIGHT_DELAY ) && - new_endoff ==RIGHT .br_startoff && - new->br_startblock + new->br_blockcount ==RIGHT .br_startblock && - newext ==RIGHT .br_state && - new->br_blockcount +RIGHT .br_blockcount <=MAXEXTLEN && - ((state & (BMAP_LEFT_CONTIG |BMAP_LEFT_FILLING | -BMAP_RIGHT_FILLING )) != - (BMAP_LEFT_CONTIG |BMAP_LEFT_FILLING | -BMAP_RIGHT_FILLING ) || -LEFT .br_blockcount + new->br_blockcount +RIGHT .br_blockcount - <=MAXEXTLEN )) - state |=BMAP_RIGHT_CONTIG ; +if (error) +return error;/* -* Switch out based on the FILLING and CONTIG state bits. +* transaction commit worked ok so we can drop the extra ticket +* reference that we gained in xfs_trans_dup() */ -switch (state & (BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG | -BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG )) { -case BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG | -BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG : -/* -* Setting all of a previous oldext extent to newext. -* The left and right neighbors are both contiguous with new. -*/ - --*idx; +xfs_log_ticket_put (ntp->t_ticket); -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, *idx), -LEFT .br_blockcount +PREV .br_blockcount + -RIGHT .br_blockcount); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +if ((error =xfs_trans_reserve (ntp,0 , logres,0 ,XFS_TRANS_PERM_LOG_RES , + logcount))) +return error; + efd =xfs_trans_get_efd (ntp, efi, flist->xbf_count); +for (free = flist->xbf_first; free !=NULL ; free = next) { + next = free->xbfi_next; +if ((error =xfs_free_extent (ntp, free->xbfi_startblock, + free->xbfi_blockcount))) { +/* +* The bmap free list will be cleaned up at a +* higher level. The EFI will be canceled when +* this transaction is aborted. +* Need to force shutdown here to make sure it +* happens, since this transaction may not be +* dirty yet. +*/ + mp = ntp->t_mountp; +if (!XFS_FORCED_SHUTDOWN (mp)) +xfs_force_shutdown (mp, + (error ==EFSCORRUPTED ) ? +SHUTDOWN_CORRUPT_INCORE : +SHUTDOWN_META_IO_ERROR ); +return error; + } +xfs_trans_log_efd_extent (ntp, efd, free->xbfi_startblock, + free->xbfi_blockcount); +xfs_bmap_del_free (flist,NULL , free); + } +return 0 ; +} -xfs_iext_remove (ip, *idx +1 ,2 , state); - ip->i_d.di_nextents -=2 ; -if (cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; -if ((error =xfs_bmbt_lookup_eq (cur,RIGHT .br_startoff, -RIGHT .br_startblock, -RIGHT .br_blockcount, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_delete (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_decrement (cur,0 , &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_delete (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_decrement (cur,0 , &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur,LEFT .br_startoff, -LEFT .br_startblock, -LEFT .br_blockcount +PREV .br_blockcount + -RIGHT .br_blockcount,LEFT .br_state))) - goto done; - } -break ; - -case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING |BMAP_LEFT_CONTIG : -/* -* Setting all of a previous oldext extent to newext. -* The left neighbor is contiguous, the right is not. -*/ - --*idx; +/* +* Free up any items left in the list. +*/ +void +xfs_bmap_cancel ( +xfs_bmap_free_t *flist)/* list of bmap_free_items */ +{ +xfs_bmap_free_item_t *free;/* free list item */ +xfs_bmap_free_item_t *next; -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, *idx), -LEFT .br_blockcount +PREV .br_blockcount); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +if (flist->xbf_count ==0 ) +return ; +ASSERT (flist->xbf_first !=NULL ); +for (free = flist->xbf_first; free; free = next) { + next = free->xbfi_next; +xfs_bmap_del_free (flist,NULL , free); + } +ASSERT (flist->xbf_count ==0 ); +} -xfs_iext_remove (ip, *idx +1 ,1 , state); - ip->i_d.di_nextents--; -if (cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; -if ((error =xfs_bmbt_lookup_eq (cur,PREV .br_startoff, -PREV .br_startblock,PREV .br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_delete (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_decrement (cur,0 , &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur,LEFT .br_startoff, -LEFT .br_startblock, -LEFT .br_blockcount +PREV .br_blockcount, -LEFT .br_state))) - goto done; - } -break ; +/* +* Inode fork format manipulation functions +*/ -case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG : -/* -* Setting all of a previous oldext extent to newext. -* The right neighbor is contiguous, the left is not. -*/ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (ep, -PREV .br_blockcount +RIGHT .br_blockcount); -xfs_bmbt_set_state (ep, newext); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); -xfs_iext_remove (ip, *idx +1 ,1 , state); - ip->i_d.di_nextents--; -if (cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; -if ((error =xfs_bmbt_lookup_eq (cur,RIGHT .br_startoff, -RIGHT .br_startblock, -RIGHT .br_blockcount, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_delete (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_btree_decrement (cur,0 , &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur, new->br_startoff, - new->br_startblock, - new->br_blockcount +RIGHT .br_blockcount, - newext))) - goto done; - } -break ; +/* +* Transform a btree format file with only one leaf node, where the +* extents list will fit in the inode, into an extents format file. +* Since the file extents are already in-core, all we have to do is +* give up the space for the btree root and pitch the leaf block. +*/ +STATIC int /* error */ +xfs_bmap_btree_to_extents ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode pointer */ +xfs_btree_cur_t *cur,/* btree cursor */ +int *logflagsp,/* inode logging flags */ +int whichfork)/* data or attr fork */ +{ +/* REFERENCED */ +struct xfs_btree_block *cblock;/* child btree block */ +xfs_fsblock_t cbno;/* child block number */ +xfs_buf_t *cbp;/* child block's buffer */ +int error;/* error return value */ +xfs_ifork_t *ifp;/* inode fork data */ +xfs_mount_t *mp;/* mount point structure */ +__be64 *pp;/* ptr to block address */ +struct xfs_btree_block *rblock;/* root btree block */ -case BMAP_LEFT_FILLING |BMAP_RIGHT_FILLING : -/* -* Setting all of a previous oldext extent to newext. -* Neither the left nor right neighbors are contiguous with -* the new one. -*/ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_state (ep, newext); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); + mp = ip->i_mount; + ifp =XFS_IFORK_PTR (ip, whichfork); +ASSERT (ifp->if_flags &XFS_IFEXTENTS ); +ASSERT (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_BTREE ); + rblock = ifp->if_broot; +ASSERT (be16_to_cpu (rblock->bb_level) ==1 ); +ASSERT (be16_to_cpu (rblock->bb_numrecs) ==1 ); +ASSERT (xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes,0 ) ==1 ); + pp =XFS_BMAP_BROOT_PTR_ADDR (mp, rblock,1 , ifp->if_broot_bytes); + cbno =be64_to_cpu (*pp); + *logflagsp =0 ; +#ifdef DEBUG +if ((error =xfs_btree_check_lptr (cur, cbno,1 ))) +return error; +#endif + error =xfs_btree_read_bufl (mp, tp, cbno,0 , &cbp,XFS_BMAP_BTREE_REF , + &xfs_bmbt_buf_ops); +if (error) +return error; + 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); + ip->i_d.di_nblocks--; +xfs_trans_mod_dquot_byino (tp, ip,XFS_TRANS_DQ_BCOUNT ,-1L ); +xfs_trans_binval (tp, cbp); +if (cur->bc_bufs[0 ] == cbp) + cur->bc_bufs[0 ] =NULL ; +xfs_iroot_realloc (ip,-1 , whichfork); +ASSERT (ifp->if_broot ==NULL ); +ASSERT ((ifp->if_flags &XFS_IFBROOT ) ==0 ); +XFS_IFORK_FMT_SET (ip, whichfork,XFS_DINODE_FMT_EXTENTS ); + *logflagsp =XFS_ILOG_CORE |xfs_ilog_fext (whichfork); +return 0 ; +} -if (cur ==NULL ) - rval =XFS_ILOG_DEXT ; -else { - rval =0 ; -if ((error =xfs_bmbt_lookup_eq (cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - newext))) - goto done; - } -break ; +/* +* Convert an extents-format file into a btree-format file. +* The new file will have a root block (in the inode) and a single child block. +*/ +STATIC int /* error */ +xfs_bmap_extents_to_btree ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode pointer */ +xfs_fsblock_t *firstblock,/* first-block-allocated */ +xfs_bmap_free_t *flist,/* blocks freed in xaction */ +xfs_btree_cur_t **curp,/* cursor returned to caller */ +int wasdel,/* converting a delayed alloc */ +int *logflagsp,/* inode logging flags */ +int whichfork)/* data or attr fork */ +{ +struct xfs_btree_block *ablock;/* allocated (child) bt block */ +xfs_buf_t *abp;/* buffer for ablock */ +xfs_alloc_arg_t args;/* allocation arguments */ +xfs_bmbt_rec_t *arp;/* child record pointer */ +struct xfs_btree_block *block;/* btree root block */ +xfs_btree_cur_t *cur;/* bmap btree cursor */ +xfs_bmbt_rec_host_t *ep;/* extent record pointer */ +int error;/* error return value */ +xfs_extnum_t i, cnt;/* extent record index */ +xfs_ifork_t *ifp;/* inode fork pointer */ +xfs_bmbt_key_t *kp;/* root block key pointer */ +xfs_mount_t *mp;/* mount structure */ +xfs_extnum_t nextents;/* number of file extents */ +xfs_bmbt_ptr_t *pp;/* root block address pointer */ -case BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG : -/* -* Setting the first part of a previous oldext extent to newext. -* The left neighbor is contiguous. -*/ -trace_xfs_bmap_pre_update (ip, *idx -1 , state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, *idx -1 ), -LEFT .br_blockcount + new->br_blockcount); -xfs_bmbt_set_startoff (ep, -PREV .br_startoff + new->br_blockcount); -trace_xfs_bmap_post_update (ip, *idx -1 , state, _THIS_IP_); + ifp =XFS_IFORK_PTR (ip, whichfork); +ASSERT (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_EXTENTS ); -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_startblock (ep, - new->br_startblock + new->br_blockcount); -xfs_bmbt_set_blockcount (ep, -PREV .br_blockcount - new->br_blockcount); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +/* +* Make space in the inode incore. +*/ +xfs_iroot_realloc (ip,1 , whichfork); + ifp->if_flags |=XFS_IFBROOT ; - --*idx; +/* +* Fill in the root. +*/ + block = ifp->if_broot; + block->bb_magic =cpu_to_be32 (XFS_BMAP_MAGIC ); + block->bb_level =cpu_to_be16 (1 ); + block->bb_numrecs =cpu_to_be16 (1 ); + block->bb_u.l.bb_leftsib =cpu_to_be64 (NULLDFSBNO ); + block->bb_u.l.bb_rightsib =cpu_to_be64 (NULLDFSBNO ); -if (cur ==NULL ) - rval =XFS_ILOG_DEXT ; -else { - rval =0 ; -if ((error =xfs_bmbt_lookup_eq (cur,PREV .br_startoff, -PREV .br_startblock,PREV .br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur, -PREV .br_startoff + new->br_blockcount, -PREV .br_startblock + new->br_blockcount, -PREV .br_blockcount - new->br_blockcount, - oldext))) - goto done; -if ((error =xfs_btree_decrement (cur,0 , &i))) - goto done; - error =xfs_bmbt_update (cur,LEFT .br_startoff, -LEFT .br_startblock, -LEFT .br_blockcount + new->br_blockcount, -LEFT .br_state); -if (error) - goto done; - } -break ; - -case BMAP_LEFT_FILLING : -/* -* Setting the first part of a previous oldext extent to newext. -* The left neighbor is not contiguous. -*/ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -ASSERT (ep &&xfs_bmbt_get_state (ep) == oldext); -xfs_bmbt_set_startoff (ep, new_endoff); -xfs_bmbt_set_blockcount (ep, -PREV .br_blockcount - new->br_blockcount); -xfs_bmbt_set_startblock (ep, - new->br_startblock + new->br_blockcount); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); - -xfs_iext_insert (ip, *idx,1 , new, state); - ip->i_d.di_nextents++; -if (cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; -if ((error =xfs_bmbt_lookup_eq (cur,PREV .br_startoff, -PREV .br_startblock,PREV .br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur, -PREV .br_startoff + new->br_blockcount, -PREV .br_startblock + new->br_blockcount, -PREV .br_blockcount - new->br_blockcount, - oldext))) - goto done; - cur->bc_rec.b = *new; -if ((error =xfs_btree_insert (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); +/* +* Need a cursor. Can't allocate until bb_level is filled in. +*/ + mp = ip->i_mount; + cur =xfs_bmbt_init_cursor (mp, tp, ip, whichfork); + cur->bc_private.b.firstblock = *firstblock; + cur->bc_private.b.flist = flist; + cur->bc_private.b.flags = wasdel ?XFS_BTCUR_BPRV_WASDEL :0 ; +/* +* Convert to a btree with two levels, one record in root. +*/ +XFS_IFORK_FMT_SET (ip, whichfork,XFS_DINODE_FMT_BTREE ); +memset (&args,0 ,sizeof (args)); + args.tp = tp; + args.mp = mp; + args.firstblock = *firstblock; +if (*firstblock ==NULLFSBLOCK ) { + args.type =XFS_ALLOCTYPE_START_BNO ; + args.fsbno =XFS_INO_TO_FSB (mp, ip->i_ino); + }else if (flist->xbf_low) { + args.type =XFS_ALLOCTYPE_START_BNO ; + args.fsbno = *firstblock; + }else { + args.type =XFS_ALLOCTYPE_NEAR_BNO ; + args.fsbno = *firstblock; + } + args.minlen = args.maxlen = args.prod =1 ; + args.wasdel = wasdel; + *logflagsp =0 ; +if ((error =xfs_alloc_vextent (&args))) { +xfs_iroot_realloc (ip,-1 , whichfork); +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +return error; + } +/* +* Allocation can't fail, the space was reserved. +*/ +ASSERT (args.fsbno !=NULLFSBLOCK ); +ASSERT (*firstblock ==NULLFSBLOCK || + args.agno ==XFS_FSB_TO_AGNO (mp, *firstblock) || + (flist->xbf_low && + args.agno >XFS_FSB_TO_AGNO (mp, *firstblock))); + *firstblock = cur->bc_private.b.firstblock = args.fsbno; + cur->bc_private.b.allocated++; + ip->i_d.di_nblocks++; +xfs_trans_mod_dquot_byino (tp, ip,XFS_TRANS_DQ_BCOUNT ,1L ); + abp =xfs_btree_get_bufl (mp, tp, args.fsbno,0 ); +/* +* Fill in the child block. +*/ + abp->b_ops = &xfs_bmbt_buf_ops; + ablock =XFS_BUF_TO_BLOCK (abp); + ablock->bb_magic =cpu_to_be32 (XFS_BMAP_MAGIC ); + ablock->bb_level =0 ; + ablock->bb_u.l.bb_leftsib =cpu_to_be64 (NULLDFSBNO ); + ablock->bb_u.l.bb_rightsib =cpu_to_be64 (NULLDFSBNO ); + arp =XFS_BMBT_REC_ADDR (mp, ablock,1 ); + nextents = ifp->if_bytes / (uint )sizeof (xfs_bmbt_rec_t); +for (cnt = i =0 ; i < nextents; i++) { + ep =xfs_iext_get_ext (ifp, i); +if (!isnullstartblock (xfs_bmbt_get_startblock (ep))) { + arp->l0 =cpu_to_be64 (ep->l0); + arp->l1 =cpu_to_be64 (ep->l1); + arp++; cnt++; } -break ; + } +ASSERT (cnt ==XFS_IFORK_NEXTENTS (ip, whichfork)); +xfs_btree_set_numrecs (ablock, cnt); -case BMAP_RIGHT_FILLING |BMAP_RIGHT_CONTIG : -/* -* Setting the last part of a previous oldext extent to newext. -* The right neighbor is contiguous with the new allocation. -*/ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (ep, -PREV .br_blockcount - new->br_blockcount); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +/* +* Fill in the root key and pointer. +*/ + kp =XFS_BMBT_KEY_ADDR (mp, block,1 ); + arp =XFS_BMBT_REC_ADDR (mp, ablock,1 ); + kp->br_startoff =cpu_to_be64 (xfs_bmbt_disk_get_startoff (arp)); + pp =XFS_BMBT_PTR_ADDR (mp, block,1 ,xfs_bmbt_get_maxrecs (cur, +be16_to_cpu (block->bb_level))); + *pp =cpu_to_be64 (args.fsbno); - ++*idx; +/* +* Do all this logging at the end so that +* the root is at the right level. +*/ +xfs_btree_log_block (cur, abp,XFS_BB_ALL_BITS ); +xfs_btree_log_recs (cur, abp,1 ,be16_to_cpu (ablock->bb_numrecs)); +ASSERT (*curp ==NULL ); + *curp = cur; + *logflagsp =XFS_ILOG_CORE |xfs_ilog_fbroot (whichfork); +return 0 ; +} -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_allf (xfs_iext_get_ext (ifp, *idx), - new->br_startoff, new->br_startblock, - new->br_blockcount +RIGHT .br_blockcount, newext); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +/* +* Convert a local file to an extents file. +* This code is out of bounds for data forks of regular files, +* since the file data needs to get logged so things will stay consistent. +* (The bmap-level manipulations are ok, though). +*/ +STATIC int /* error */ +xfs_bmap_local_to_extents ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode pointer */ +xfs_fsblock_t *firstblock,/* first block allocated in xaction */ +xfs_extlen_t total,/* total blocks needed by transaction */ +int *logflagsp,/* inode logging flags */ +int whichfork, +void (*init_fn)(struct xfs_buf *bp, +struct xfs_inode *ip, +struct xfs_ifork *ifp)) +{ +int error;/* error return value */ +int flags;/* logging flags returned */ +xfs_ifork_t *ifp;/* inode fork pointer */ -if (cur ==NULL ) - rval =XFS_ILOG_DEXT ; -else { - rval =0 ; -if ((error =xfs_bmbt_lookup_eq (cur,PREV .br_startoff, -PREV .br_startblock, -PREV .br_blockcount, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur,PREV .br_startoff, -PREV .br_startblock, -PREV .br_blockcount - new->br_blockcount, - oldext))) - goto done; -if ((error =xfs_btree_increment (cur,0 , &i))) - goto done; -if ((error =xfs_bmbt_update (cur, new->br_startoff, - new->br_startblock, - new->br_blockcount +RIGHT .br_blockcount, - newext))) - goto done; - } -break ; +/* +* We don't want to deal with the case of keeping inode data inline yet. +* So sending the data fork of a regular inode is invalid. +*/ +ASSERT (!(S_ISREG (ip->i_d.di_mode) && whichfork ==XFS_DATA_FORK )); + ifp =XFS_IFORK_PTR (ip, whichfork); +ASSERT (XFS_IFORK_FORMAT (ip, whichfork) ==XFS_DINODE_FMT_LOCAL ); + flags =0 ; + error =0 ; +if (ifp->if_bytes) { +xfs_alloc_arg_t args;/* allocation arguments */ +xfs_buf_t *bp;/* buffer for extent block */ +xfs_bmbt_rec_host_t *ep;/* extent record pointer */ -case BMAP_RIGHT_FILLING : +ASSERT ((ifp->if_flags & + (XFS_IFINLINE |XFS_IFEXTENTS |XFS_IFEXTIREC )) ==XFS_IFINLINE ); +memset (&args,0 ,sizeof (args)); + args.tp = tp; + args.mp = ip->i_mount; + args.firstblock = *firstblock;/* -* Setting the last part of a previous oldext extent to newext. -* The right neighbor is not contiguous. +* Allocate a block. We know we need only one, since the +* file currently fits in an inode. */ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (ep, -PREV .br_blockcount - new->br_blockcount); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +if (*firstblock ==NULLFSBLOCK ) { + args.fsbno =XFS_INO_TO_FSB (args.mp, ip->i_ino); + args.type =XFS_ALLOCTYPE_START_BNO ; + }else { + args.fsbno = *firstblock; + args.type =XFS_ALLOCTYPE_NEAR_BNO ; + } + args.total = total; + args.minlen = args.maxlen = args.prod =1 ; + error =xfs_alloc_vextent (&args); +if (error) + goto done; - ++*idx; -xfs_iext_insert (ip, *idx,1 , new, state); +/* Can't fail, the space was reserved. */ +ASSERT (args.fsbno !=NULLFSBLOCK ); +ASSERT (args.len ==1 ); + *firstblock = args.fsbno; + bp =xfs_btree_get_bufl (args.mp, tp, args.fsbno,0 ); - ip->i_d.di_nextents++; -if (cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; -if ((error =xfs_bmbt_lookup_eq (cur,PREV .br_startoff, -PREV .br_startblock,PREV .br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -if ((error =xfs_bmbt_update (cur,PREV .br_startoff, -PREV .br_startblock, -PREV .br_blockcount - new->br_blockcount, - oldext))) - goto done; -if ((error =xfs_bmbt_lookup_eq (cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==0 , done); - cur->bc_rec.b.br_state =XFS_EXT_NORM ; -if ((error =xfs_btree_insert (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - } -break ; - -case 0 : -/* -* Setting the middle part of a previous oldext extent to -* newext. Contiguity is impossible here. -* One extent becomes three extents. -*/ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (ep, - new->br_startoff -PREV .br_startoff); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +/* initialise the block and copy the data */ +init_fn (bp, ip, ifp); - r[0 ] = *new; - r[1 ].br_startoff = new_endoff; - r[1 ].br_blockcount = -PREV .br_startoff +PREV .br_blockcount - new_endoff; - r[1 ].br_startblock = new->br_startblock + new->br_blockcount; - r[1 ].br_state = oldext; +/* account for the change in fork size and log everything */ +xfs_trans_log_buf (tp, bp,0 , ifp->if_bytes -1 ); +xfs_bmap_forkoff_reset (args.mp, ip, whichfork); +xfs_idata_realloc (ip, -ifp->if_bytes, whichfork); +xfs_iext_add (ifp,0 ,1 ); + ep =xfs_iext_get_ext (ifp,0 ); +xfs_bmbt_set_allf (ep,0 , args.fsbno,1 ,XFS_EXT_NORM ); +trace_xfs_bmap_post_update (ip,0 , + whichfork ==XFS_ATTR_FORK ?BMAP_ATTRFORK :0 , + _THIS_IP_); +XFS_IFORK_NEXT_SET (ip, whichfork,1 ); + ip->i_d.di_nblocks =1 ; +xfs_trans_mod_dquot_byino (tp, ip, +XFS_TRANS_DQ_BCOUNT ,1L ); + flags |=xfs_ilog_fext (whichfork); + }else { +ASSERT (XFS_IFORK_NEXTENTS (ip, whichfork) ==0 ); +xfs_bmap_forkoff_reset (ip->i_mount, ip, whichfork); + } + ifp->if_flags &= ~XFS_IFINLINE ; + ifp->if_flags |=XFS_IFEXTENTS ; +XFS_IFORK_FMT_SET (ip, whichfork,XFS_DINODE_FMT_EXTENTS ); + flags |=XFS_ILOG_CORE ; +done: + *logflagsp = flags; +return error; +} - ++*idx; -xfs_iext_insert (ip, *idx,2 , &r[0 ], state); +/* +* Called from xfs_bmap_add_attrfork to handle btree format files. +*/ +STATIC int /* error */ +xfs_bmap_add_attrfork_btree ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode pointer */ +xfs_fsblock_t *firstblock,/* first block allocated */ +xfs_bmap_free_t *flist,/* blocks to free at commit */ +int *flags)/* inode logging flags */ +{ +xfs_btree_cur_t *cur;/* btree cursor */ +int error;/* error return value */ +xfs_mount_t *mp;/* file system mount struct */ +int stat;/* newroot status */ - ip->i_d.di_nextents +=2 ; -if (cur ==NULL ) - rval =XFS_ILOG_CORE |XFS_ILOG_DEXT ; -else { - rval =XFS_ILOG_CORE ; -if ((error =xfs_bmbt_lookup_eq (cur,PREV .br_startoff, -PREV .br_startblock,PREV .br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -/* new right extent - oldext */ -if ((error =xfs_bmbt_update (cur, r[1 ].br_startoff, - r[1 ].br_startblock, r[1 ].br_blockcount, - r[1 ].br_state))) - goto done; -/* new left extent - oldext */ - cur->bc_rec.b =PREV ; - cur->bc_rec.b.br_blockcount = - new->br_startoff -PREV .br_startoff; -if ((error =xfs_btree_insert (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); -/* -* Reset the cursor to the position of the new extent -* we are about to insert as we can't trust it after -* the previous insert. -*/ -if ((error =xfs_bmbt_lookup_eq (cur, new->br_startoff, - new->br_startblock, new->br_blockcount, - &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==0 , done); -/* new middle extent - newext */ - cur->bc_rec.b.br_state = new->br_state; -if ((error =xfs_btree_insert (cur, &i))) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); + mp = ip->i_mount; +if (ip->i_df.if_broot_bytes <=XFS_IFORK_DSIZE (ip)) + *flags |=XFS_ILOG_DBROOT ; +else { + cur =xfs_bmbt_init_cursor (mp, tp, ip,XFS_DATA_FORK ); + cur->bc_private.b.flist = flist; + cur->bc_private.b.firstblock = *firstblock; +if ((error =xfs_bmbt_lookup_ge (cur,0 ,0 ,0 , &stat))) + goto error0; +/* must be at least one entry */ +XFS_WANT_CORRUPTED_GOTO (stat ==1 , error0); +if ((error =xfs_btree_new_iroot (cur, flags, &stat))) + goto error0; +if (stat ==0 ) { +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); +return XFS_ERROR (ENOSPC ); } -break ; - -case BMAP_LEFT_FILLING |BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -case BMAP_RIGHT_FILLING |BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -case BMAP_LEFT_FILLING |BMAP_RIGHT_CONTIG : -case BMAP_RIGHT_FILLING |BMAP_LEFT_CONTIG : -case BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -case BMAP_LEFT_CONTIG : -case BMAP_RIGHT_CONTIG : -/* -* These cases are all impossible. -*/ -ASSERT (0 ); + *firstblock = cur->bc_private.b.firstblock; + cur->bc_private.b.allocated =0 ; +xfs_btree_del_cursor (cur,XFS_BTREE_NOERROR ); } +return 0 ; +error0: +xfs_btree_del_cursor (cur,XFS_BTREE_ERROR ); +return error; +} -/* convert to a btree if necessary */ -if (xfs_bmap_needs_btree (ip,XFS_DATA_FORK )) { -int tmp_logflags;/* partial log flag return val */ - -ASSERT (cur ==NULL ); - error =xfs_bmap_extents_to_btree (tp, ip, first, flist, &cur, -0 , &tmp_logflags,XFS_DATA_FORK ); - *logflagsp |= tmp_logflags; -if (error) - goto done; - } +/* +* Called from xfs_bmap_add_attrfork to handle extents format files. +*/ +STATIC int /* error */ +xfs_bmap_add_attrfork_extents ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode pointer */ +xfs_fsblock_t *firstblock,/* first block allocated */ +xfs_bmap_free_t *flist,/* blocks to free at commit */ +int *flags)/* inode logging flags */ +{ +xfs_btree_cur_t *cur;/* bmap btree cursor */ +int error;/* error return value */ -/* clear out the allocated field, done with it now in any case. */ +if (ip->i_d.di_nextents *sizeof (xfs_bmbt_rec_t) <=XFS_IFORK_DSIZE (ip)) +return 0 ; + cur =NULL ; + error =xfs_bmap_extents_to_btree (tp, ip, firstblock, flist, &cur,0 , + flags,XFS_DATA_FORK );if (cur) { cur->bc_private.b.allocated =0 ; - *curp = cur; +xfs_btree_del_cursor (cur, + error ?XFS_BTREE_ERROR :XFS_BTREE_NOERROR ); } - -xfs_bmap_check_leaf_extents (*curp, ip,XFS_DATA_FORK ); -done: - *logflagsp |= rval;return error; -#undef LEFT -#undef RIGHT -#undef PREV }/* -* Convert a hole to a delayed allocation. +* Block initialisation functions for local to extent format conversion. +* As these get more complex, they will be moved to the relevant files, +* but for now they are too simple to worry about. */ STATIC void -xfs_bmap_add_extent_hole_delay ( -xfs_inode_t *ip,/* incore inode pointer */ -xfs_extnum_t *idx,/* extent number to update/insert */ -xfs_bmbt_irec_t *new)/* new data to add to file extents */ +xfs_bmap_local_to_extents_init_fn ( +struct xfs_buf *bp, +struct xfs_inode *ip, +struct xfs_ifork *ifp) { -xfs_ifork_t *ifp;/* inode fork pointer */ -xfs_bmbt_irec_t left;/* left neighbor extent entry */ -xfs_filblks_t newlen=0 ;/* new indirect size */ -xfs_filblks_t oldlen=0 ;/* old indirect size */ -xfs_bmbt_irec_t right;/* right neighbor extent entry */ -int state;/* state bits, accessed thru macros */ -xfs_filblks_t temp=0 ;/* temp for indirect calculations */ + bp->b_ops = &xfs_bmbt_buf_ops; +memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes); +} - ifp =XFS_IFORK_PTR (ip,XFS_DATA_FORK ); - state =0 ; -ASSERT (isnullstartblock (new->br_startblock)); +STATIC void +xfs_symlink_local_to_remote ( +struct xfs_buf *bp, +struct xfs_inode *ip, +struct xfs_ifork *ifp) +{ +/* remote symlink blocks are not verifiable until CRCs come along */ + bp->b_ops =NULL ; +memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes); +} -/* -* Check and set flags if this segment has a left neighbor -*/ -if (*idx >0 ) { - state |=BMAP_LEFT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, *idx -1 ), &left); +/* +* Called from xfs_bmap_add_attrfork to handle local format files. Each +* different data fork content type needs a different callout to do the +* conversion. Some are basic and only require special block initialisation +* callouts for the data formating, others (directories) are so specialised they +* handle everything themselves. +* +* XXX (dgc): investigate whether directory conversion can use the generic +* formatting callout. It should be possible - it's just a very complex +* formatter. it would also require passing the transaction through to the init +* function. +*/ +STATIC int /* error */ +xfs_bmap_add_attrfork_local ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode pointer */ +xfs_fsblock_t *firstblock,/* first block allocated */ +xfs_bmap_free_t *flist,/* blocks to free at commit */ +int *flags)/* inode logging flags */ +{ +xfs_da_args_t dargs;/* args for dir/attr code */ -if (isnullstartblock (left.br_startblock)) - state |=BMAP_LEFT_DELAY ; - } - -/* -* Check and set flags if the current (right) segment exists. -* If it doesn't exist, we're converting the hole at end-of-file. -*/ -if (*idx < ip->i_df.if_bytes / (uint )sizeof (xfs_bmbt_rec_t)) { - state |=BMAP_RIGHT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, *idx), &right); +if (ip->i_df.if_bytes <=XFS_IFORK_DSIZE (ip)) +return 0 ; -if (isnullstartblock (right.br_startblock)) - state |=BMAP_RIGHT_DELAY ; +if (S_ISDIR (ip->i_d.di_mode)) { +memset (&dargs,0 ,sizeof (dargs)); + dargs.dp = ip; + dargs.firstblock = firstblock; + dargs.flist = flist; + dargs.total = ip->i_mount->m_dirblkfsbs; + dargs.whichfork =XFS_DATA_FORK ; + dargs.trans = tp; +return xfs_dir2_sf_to_block (&dargs); } -/* -* Set contiguity flags on the left and right neighbors. -* Don't let extents get too large, even if the pieces are contiguous. -*/ -if ((state &BMAP_LEFT_VALID ) && (state &BMAP_LEFT_DELAY ) && - left.br_startoff + left.br_blockcount == new->br_startoff && - left.br_blockcount + new->br_blockcount <=MAXEXTLEN ) - state |=BMAP_LEFT_CONTIG ; - -if ((state &BMAP_RIGHT_VALID ) && (state &BMAP_RIGHT_DELAY ) && - new->br_startoff + new->br_blockcount == right.br_startoff && - new->br_blockcount + right.br_blockcount <=MAXEXTLEN && - (!(state &BMAP_LEFT_CONTIG ) || - (left.br_blockcount + new->br_blockcount + - right.br_blockcount <=MAXEXTLEN ))) - state |=BMAP_RIGHT_CONTIG ; +if (S_ISLNK (ip->i_d.di_mode)) +return xfs_bmap_local_to_extents (tp, ip, firstblock,1 , + flags,XFS_DATA_FORK , + xfs_symlink_local_to_remote); -/* -* Switch out based on the contiguity flags. -*/ -switch (state & (BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG )) { -case BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -/* -* New allocation is contiguous with delayed allocations -* on the left and on the right. -* Merge all three into a single extent record. -*/ - --*idx; - temp = left.br_blockcount + new->br_blockcount + - right.br_blockcount; +return xfs_bmap_local_to_extents (tp, ip, firstblock,1 , flags, +XFS_DATA_FORK , + xfs_bmap_local_to_extents_init_fn); +} -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, *idx), temp); - oldlen =startblockval (left.br_startblock) + -startblockval (new->br_startblock) + -startblockval (right.br_startblock); - newlen =xfs_bmap_worst_indlen (ip, temp); -xfs_bmbt_set_startblock (xfs_iext_get_ext (ifp, *idx), -nullstartblock ((int )newlen)); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +/* +* Convert inode from non-attributed to attributed. +* Must not be in a transaction, ip must not be locked. +*/ +int /* error code */ +xfs_bmap_add_attrfork ( +xfs_inode_t *ip,/* incore inode pointer */ +int size,/* space new attribute needs */ +int rsvd)/* xact may use reserved blks */ +{ +xfs_fsblock_t firstblock;/* 1st block/ag allocated */ +xfs_bmap_free_t flist;/* freed extent records */ +xfs_mount_t *mp;/* mount structure */ +xfs_trans_t *tp;/* transaction pointer */ +int blks;/* space reservation */ +int version =1 ;/* superblock attr version */ +int committed;/* xaction was committed */ +int logflags;/* logging flags */ +int error;/* error return value */ -xfs_iext_remove (ip, *idx +1 ,1 , state); -break ; +ASSERT (XFS_IFORK_Q (ip) ==0 ); -case BMAP_LEFT_CONTIG : + mp = ip->i_mount; +ASSERT (!XFS_NOT_DQATTACHED (mp, ip)); + tp =xfs_trans_alloc (mp,XFS_TRANS_ADDAFORK ); + blks =XFS_ADDAFORK_SPACE_RES (mp); +if (rsvd) + tp->t_flags |=XFS_TRANS_RESERVE ; +if ((error =xfs_trans_reserve (tp, blks,XFS_ADDAFORK_LOG_RES (mp),0 , +XFS_TRANS_PERM_LOG_RES ,XFS_ADDAFORK_LOG_COUNT ))) + goto error0; +xfs_ilock (ip,XFS_ILOCK_EXCL ); + error =xfs_trans_reserve_quota_nblks (tp, ip, blks,0 , rsvd ? +XFS_QMOPT_RES_REGBLKS |XFS_QMOPT_FORCE_RES : +XFS_QMOPT_RES_REGBLKS ); +if (error) { +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES ); +return error; + } +if (XFS_IFORK_Q (ip)) + goto error1; +if (ip->i_d.di_aformat !=XFS_DINODE_FMT_EXTENTS ) {/* -* New allocation is contiguous with a delayed allocation -* on the left. -* Merge the new allocation with the left neighbor. +* For inodes coming from pre-6.2 filesystems. */ - --*idx; - temp = left.br_blockcount + new->br_blockcount; +ASSERT (ip->i_d.di_aformat ==0 ); + ip->i_d.di_aformat =XFS_DINODE_FMT_EXTENTS ; + } +ASSERT (ip->i_d.di_anextents ==0 ); -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, *idx), temp); - oldlen =startblockval (left.br_startblock) + -startblockval (new->br_startblock); - newlen =xfs_bmap_worst_indlen (ip, temp); -xfs_bmbt_set_startblock (xfs_iext_get_ext (ifp, *idx), -nullstartblock ((int )newlen)); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); -break ; +xfs_trans_ijoin (tp, ip,XFS_ILOCK_EXCL ); +xfs_trans_log_inode (tp, ip,XFS_ILOG_CORE ); -case BMAP_RIGHT_CONTIG : -/* -* New allocation is contiguous with a delayed allocation -* on the right. -* Merge the new allocation with the right neighbor. -*/ -trace_xfs_bmap_pre_update (ip, *idx, state, _THIS_IP_); - temp = new->br_blockcount + right.br_blockcount; - oldlen =startblockval (new->br_startblock) + -startblockval (right.br_startblock); - newlen =xfs_bmap_worst_indlen (ip, temp); -xfs_bmbt_set_allf (xfs_iext_get_ext (ifp, *idx), - new->br_startoff, -nullstartblock ((int )newlen), temp, right.br_state); -trace_xfs_bmap_post_update (ip, *idx, state, _THIS_IP_); +switch (ip->i_d.di_format) { +case XFS_DINODE_FMT_DEV : + ip->i_d.di_forkoff =roundup (sizeof (xfs_dev_t),8 ) >>3 ; +break ; +case XFS_DINODE_FMT_UUID : + ip->i_d.di_forkoff =roundup (sizeof (uuid_t),8 ) >>3 ; +break ; +case XFS_DINODE_FMT_LOCAL : +case XFS_DINODE_FMT_EXTENTS : +case XFS_DINODE_FMT_BTREE : + ip->i_d.di_forkoff =xfs_attr_shortform_bytesfit (ip, size); +if (!ip->i_d.di_forkoff) + ip->i_d.di_forkoff =xfs_default_attroffset (ip) >>3 ; +else if (mp->m_flags &XFS_MOUNT_ATTR2 ) + version =2 ;break ; +default : +ASSERT (0 ); + error =XFS_ERROR (EINVAL ); + goto error1; + } -case 0 : -/* -* New allocation is not contiguous with another -* delayed allocation. -* Insert a new entry. -*/ - oldlen = newlen =0 ; -xfs_iext_insert (ip, *idx,1 , new, state); +ASSERT (ip->i_afp ==NULL ); + ip->i_afp =kmem_zone_zalloc (xfs_ifork_zone,KM_SLEEP ); + ip->i_afp->if_flags =XFS_IFEXTENTS ; + logflags =0 ; +xfs_bmap_init (&flist, &firstblock); +switch (ip->i_d.di_format) { +case XFS_DINODE_FMT_LOCAL : + error =xfs_bmap_add_attrfork_local (tp, ip, &firstblock, &flist, + &logflags); +break ; +case XFS_DINODE_FMT_EXTENTS : + error =xfs_bmap_add_attrfork_extents (tp, ip, &firstblock, + &flist, &logflags); +break ; +case XFS_DINODE_FMT_BTREE : + error =xfs_bmap_add_attrfork_btree (tp, ip, &firstblock, &flist, + &logflags); +break ; +default : + error =0 ;break ; } -if (oldlen != newlen) { -ASSERT (oldlen > newlen); -xfs_icsb_modify_counters (ip->i_mount,XFS_SBS_FDBLOCKS , - (int64_t )(oldlen - newlen),0 ); -/* -* Nothing to do for disk quota accounting here. -*/ +if (logflags) +xfs_trans_log_inode (tp, ip, logflags); +if (error) + goto error2; +if (!xfs_sb_version_hasattr (&mp->m_sb) || + (!xfs_sb_version_hasattr2 (&mp->m_sb) && version ==2 )) { +__int64_t sbfields =0 ; + +spin_lock (&mp->m_sb_lock); +if (!xfs_sb_version_hasattr (&mp->m_sb)) { +xfs_sb_version_addattr (&mp->m_sb); + sbfields |=XFS_SB_VERSIONNUM ; + } +if (!xfs_sb_version_hasattr2 (&mp->m_sb) && version ==2 ) { +xfs_sb_version_addattr2 (&mp->m_sb); + sbfields |= (XFS_SB_VERSIONNUM |XFS_SB_FEATURES2 ); + } +if (sbfields) { +spin_unlock (&mp->m_sb_lock); +xfs_mod_sb (tp, sbfields); + }else +spin_unlock (&mp->m_sb_lock); } + + error =xfs_bmap_finish (&tp, &flist, &committed); +if (error) + goto error2; +return xfs_trans_commit (tp,XFS_TRANS_RELEASE_LOG_RES ); +error2: +xfs_bmap_cancel (&flist); +error1: +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +error0: +xfs_trans_cancel (tp,XFS_TRANS_RELEASE_LOG_RES |XFS_TRANS_ABORT ); +return error; }/* -* Convert a hole to a real allocation. +* Internal and external extent tree search functions. */ -STATIC int /* error */ -xfs_bmap_add_extent_hole_real ( -struct xfs_bmalloca *bma, -int whichfork) -{ -struct xfs_bmbt_irec *new = &bma->got; -int error;/* error return value */ -int i;/* temp state */ -xfs_ifork_t *ifp;/* inode fork pointer */ -xfs_bmbt_irec_t left;/* left neighbor extent entry */ -xfs_bmbt_irec_t right;/* right neighbor extent entry */ -int rval=0 ;/* return value (logging flags) */ -int state;/* state bits, accessed thru macros */ - - ifp =XFS_IFORK_PTR (bma->ip, whichfork); -ASSERT (bma->idx >=0 ); -ASSERT (bma->idx <= ifp->if_bytes /sizeof (struct xfs_bmbt_rec )); -ASSERT (!isnullstartblock (new->br_startblock)); -ASSERT (!bma->cur || - !(bma->cur->bc_private.b.flags &XFS_BTCUR_BPRV_WASDEL )); - -XFS_STATS_INC (xs_add_exlist); - - state =0 ; -if (whichfork ==XFS_ATTR_FORK ) - state |=BMAP_ATTRFORK ; +/* +* Read in the extents to if_extents. +* All inode fields are set up by caller, we just traverse the btree +* and copy the records in. If the file system cannot contain unwritten +* extents, the records are checked for no "state" flags. +*/ +int /* error */ +xfs_bmap_read_extents ( +xfs_trans_t *tp,/* transaction pointer */ +xfs_inode_t *ip,/* incore inode */ +int whichfork)/* data or attr fork */ +{ +struct xfs_btree_block *block;/* current btree block */ +xfs_fsblock_t bno;/* block # of "block" */ +xfs_buf_t *bp;/* buffer for "block" */ +int error;/* error return value */ +xfs_exntfmt_t exntf;/* XFS_EXTFMT_NOSTATE, if checking */ +xfs_extnum_t i, j;/* index into the extents list */ +xfs_ifork_t *ifp;/* fork structure */ +int level;/* btree level, for checking */ +xfs_mount_t *mp;/* file system mount structure */ +__be64 *pp;/* pointer to block address */ +/* REFERENCED */ +xfs_extnum_t room;/* number of entries there's room for */ + bno =NULLFSBLOCK ; + mp = ip->i_mount; + ifp =XFS_IFORK_PTR (ip, whichfork); + exntf = (whichfork !=XFS_DATA_FORK ) ?XFS_EXTFMT_NOSTATE : +XFS_EXTFMT_INODE (ip); + block = ifp->if_broot;/* -* Check and set flags if this segment has a left neighbor. +* Root level must use BMAP_BROOT_PTR_ADDR macro to get ptr out. */ -if (bma->idx >0 ) { - state |=BMAP_LEFT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, bma->idx -1 ), &left); -if (isnullstartblock (left.br_startblock)) - state |=BMAP_LEFT_DELAY ; - } - + level =be16_to_cpu (block->bb_level); +ASSERT (level >0 ); + pp =XFS_BMAP_BROOT_PTR_ADDR (mp, block,1 , ifp->if_broot_bytes); + bno =be64_to_cpu (*pp); +ASSERT (bno !=NULLDFSBNO ); +ASSERT (XFS_FSB_TO_AGNO (mp, bno) < mp->m_sb.sb_agcount); +ASSERT (XFS_FSB_TO_AGBNO (mp, bno) < mp->m_sb.sb_agblocks);/* -* Check and set flags if this segment has a current value. -* Not true if we're inserting into the "hole" at eof. +* Go down the tree until leaf level is reached, following the first +* pointer (leftmost) at each level. */ -if (bma->idx < ifp->if_bytes / (uint )sizeof (xfs_bmbt_rec_t)) { - state |=BMAP_RIGHT_VALID ; -xfs_bmbt_get_all (xfs_iext_get_ext (ifp, bma->idx), &right); -if (isnullstartblock (right.br_startblock)) - state |=BMAP_RIGHT_DELAY ; +while (level-- >0 ) { + error =xfs_btree_read_bufl (mp, tp, bno,0 , &bp, +XFS_BMAP_BTREE_REF , &xfs_bmbt_buf_ops); +if (error) +return error; + block =XFS_BUF_TO_BLOCK (bp); +XFS_WANT_CORRUPTED_GOTO ( +xfs_bmap_sanity_check (mp, bp, level), + error0); +if (level ==0 ) +break ; + pp =XFS_BMBT_PTR_ADDR (mp, block,1 , mp->m_bmap_dmxr[1 ]); + bno =be64_to_cpu (*pp); +XFS_WANT_CORRUPTED_GOTO (XFS_FSB_SANITY_CHECK (mp, bno), error0); +xfs_trans_brelse (tp, bp); } -/* -* We're inserting a real allocation between "left" and "right". -* Set the contiguity flags. Don't let extents get too large. +* Here with bp and block set to the leftmost leaf node in the tree. */ -if ((state &BMAP_LEFT_VALID ) && !(state &BMAP_LEFT_DELAY ) && - left.br_startoff + left.br_blockcount == new->br_startoff && - left.br_startblock + left.br_blockcount == new->br_startblock && - left.br_state == new->br_state && - left.br_blockcount + new->br_blockcount <=MAXEXTLEN ) - state |=BMAP_LEFT_CONTIG ; - -if ((state &BMAP_RIGHT_VALID ) && !(state &BMAP_RIGHT_DELAY ) && - new->br_startoff + new->br_blockcount == right.br_startoff && - new->br_startblock + new->br_blockcount == right.br_startblock && - new->br_state == right.br_state && - new->br_blockcount + right.br_blockcount <=MAXEXTLEN && - (!(state &BMAP_LEFT_CONTIG ) || - left.br_blockcount + new->br_blockcount + - right.br_blockcount <=MAXEXTLEN )) - state |=BMAP_RIGHT_CONTIG ; - - error =0 ; + room = ifp->if_bytes / (uint )sizeof (xfs_bmbt_rec_t); + i =0 ;/* -* Select which case we're in here, and implement it. +* Loop over all leaf nodes. Copy information to the extent records. */ -switch (state & (BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG )) { -case BMAP_LEFT_CONTIG |BMAP_RIGHT_CONTIG : -/* -* New allocation is contiguous with real allocations on the -* left and on the right. -* Merge all three into a single extent record. -*/ - --bma->idx; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, bma->idx), - left.br_blockcount + new->br_blockcount + - right.br_blockcount); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); - -xfs_iext_remove (bma->ip, bma->idx +1 ,1 , state); +for (;;) { +xfs_bmbt_rec_t *frp; +xfs_fsblock_t nextbno; +xfs_extnum_t num_recs; +xfs_extnum_t start; -XFS_IFORK_NEXT_SET (bma->ip, whichfork, -XFS_IFORK_NEXTENTS (bma->ip, whichfork) -1 ); -if (bma->cur ==NULL ) { - rval =XFS_ILOG_CORE |xfs_ilog_fext (whichfork); - }else { - rval =XFS_ILOG_CORE ; - error =xfs_bmbt_lookup_eq (bma->cur, right.br_startoff, - right.br_startblock, right.br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_btree_delete (bma->cur, &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_btree_decrement (bma->cur,0 , &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_bmbt_update (bma->cur, left.br_startoff, - left.br_startblock, - left.br_blockcount + - new->br_blockcount + - right.br_blockcount, - left.br_state); -if (error) - goto done; + num_recs =xfs_btree_get_numrecs (block); +if (unlikely (i + num_recs > room)) { +ASSERT (i + num_recs <= room); +xfs_warn (ip->i_mount, +"corrupt dinode %Lu, (btree extents)." , + (unsigned long long ) ip->i_ino); +XFS_CORRUPTION_ERROR ("xfs_bmap_read_extents(1)" , +XFS_ERRLEVEL_LOW , ip->i_mount, block); + goto error0; } -break ; - -case BMAP_LEFT_CONTIG : +XFS_WANT_CORRUPTED_GOTO ( +xfs_bmap_sanity_check (mp, bp,0 ), + error0);/* -* New allocation is contiguous with a real allocation -* on the left. -* Merge the new allocation with the left neighbor. +* Read-ahead the next leaf block, if any. */ - --bma->idx; -trace_xfs_bmap_pre_update (bma->ip, bma->idx, state, _THIS_IP_); -xfs_bmbt_set_blockcount (xfs_iext_get_ext (ifp, bma->idx), - left.br_blockcount + new->br_blockcount); -trace_xfs_bmap_post_update (bma->ip, bma->idx, state, _THIS_IP_); - -if (bma->cur ==NULL ) { - rval =xfs_ilog_fext (whichfork); - }else { - rval =0 ; - error =xfs_bmbt_lookup_eq (bma->cur, left.br_startoff, - left.br_startblock, left.br_blockcount, - &i); -if (error) - goto done; -XFS_WANT_CORRUPTED_GOTO (i ==1 , done); - error =xfs_bmbt_update (bma->cur, left.br_startoff, - left.br_startblock, - left.br_blockcount + - new->br_blockcount, - left.br_state); -if (error) - goto done; - } -break ; - -case BMAP_RIGHT_CONTIG : + nextbno =be64_to_cpu (block->bb_u.l.bb_rightsib); +if (nextbno !=NULLFSBLOCK ) +xfs_btree_reada_bufl (mp, nextbno,1 , + &xfs_bmbt_buf_ops);/* -* New allocation is contiguous with a real allocation -* on the right. -* Merge the new allocation with the right neighbor. +* Copy records into the extent records.
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Part of the diff is not shown here. View the raw message.
Re: [PATCH 01/16] xfs: rearrange some code in xfs_bmap for better locality
Quoted 26 lines · Dave Chinner
From: Dave Chinner<[email protected]>
xfs_bmap.cis a big file, and some of the related code is spread all throughout the file requiring function prototypes for static function and jumping all through the file to follow a single call path. Rearrange the code so that:a) related functionality is grouped together; and
b) functions are grouped in call dependency orderWhile the diffstat is large, there are no code changes in the patch; it is just moving the functionality around and removing the function prototypes at the top of the file. The resulting layout of the code is as follows (top of file to bottom):
- miscellaneous helper functions
- extent tree block counting routines
- debug/sanity checking code
- bmap free list manipulation functions
- inode fork format manipulation functions
- internal/external extent tree seach functions
- extent tree manipulation functions used during allocation
- functions used during extent read/allocate/removal operations (i.e.xfs_bmapi_write,xfs_bmapi_read,xfs_bunmapiandxfs_getbmap)
Quoted 6 lines
This means that following logic paths through the bmapi code is much simpler - most of the code relevant to a specific operation is now clustered together rather than spread all over the file....
Signed-off-by Dave Chinner<[email protected]>---
Same as the previous post:
http://oss.sgi.com/archives/xfs/2013-02/msg00132.html
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Ben Myers
AppliedRe: [PATCH 01/16] xfs: rearrange some code in xfs_bmap for better locality
In reply to Dave ChinnerQuoted 26 lines · Dave Chinner
From: Dave Chinner <[email protected]>
xfs_bmap.cis a big file, and some of the related code is spread all throughout the file requiring function prototypes for static function and jumping all through the file to follow a single call path. Rearrange the code so that:a) related functionality is grouped together; and
b) functions are grouped in call dependency orderWhile the diffstat is large, there are no code changes in the patch; it is just moving the functionality around and removing the function prototypes at the top of the file. The resulting layout of the code is as follows (top of file to bottom):
- miscellaneous helper functions
- extent tree block counting routines
- debug/sanity checking code
- bmap free list manipulation functions
- inode fork format manipulation functions
- internal/external extent tree seach functions
- extent tree manipulation functions used during allocation
- functions used during extent read/allocate/removal operations (i.e.xfs_bmapi_write,xfs_bmapi_read,xfs_bunmapiandxfs_getbmap)
Quoted 5 lines
This means that following logic paths through the bmapi code is much simpler - most of the code relevant to a specific operation is now clustered together rather than spread all over the file....
Signed-off-by Dave Chinner <[email protected]>
Applied.
-Ben
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 2/16 xfs: take inode version into account in XFS_LITINO
In reply to Dave ChinnerFrom: Christoph Hellwig <[email protected]>
Add a version argument to XFS_LITINO so that it can return different values depending on the inode version. This is required for the upcoming v3 inodes with a larger fixed layout dinode.
--- fs/xfs/xfs_attr_leaf.c | 6 ++++-- fs/xfs/xfs_bmap.c | 4 ++-- fs/xfs/xfs_dinode.h | 6 +++--- fs/xfs/xfs_inode.h | 5 +++-- fs/xfs/xfs_vnodeops.c | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-)
fs/xfs/xfs_attr_leaf.c +4 -2
@@ -172,7 +172,8 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)int dsize;xfs_mount_t *mp = dp->i_mount; - offset = (XFS_LITINO (mp) - bytes) >>3 ;/* rounded down */ +/* rounded down */ + offset = (XFS_LITINO (mp, dp->i_d.di_version) - bytes) >>3 ;switch (dp->i_d.di_format) {case XFS_DINODE_FMT_DEV :
@@ -243,7 +244,8 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes) minforkoff =roundup (minforkoff,8 ) >>3 ;/* attr fork btree root can have at least this many key/ptr pairs */ - maxforkoff =XFS_LITINO (mp) -XFS_BMDR_SPACE_CALC (MINABTPTRS ); + maxforkoff =XFS_LITINO (mp, dp->i_d.di_version) - +XFS_BMDR_SPACE_CALC (MINABTPTRS ); maxforkoff = maxforkoff >>3 ;/* rounded down */ if (offset >= maxforkoff)
fs/xfs/xfs_bmap.c +2 -2
@@ -228,13 +228,13 @@ xfs_default_attroffset(uint offset;if (mp->m_sb.sb_inodesize ==256 ) { - offset =XFS_LITINO (mp) - + offset =XFS_LITINO (mp, ip->i_d.di_version) -XFS_BMDR_SPACE_CALC (MINABTPTRS ); }else { offset =XFS_BMDR_SPACE_CALC (6 *MINABTPTRS ); } -ASSERT (offset <XFS_LITINO (mp)); +ASSERT (offset <XFS_LITINO (mp, ip->i_d.di_version));return offset; }
fs/xfs/xfs_dinode.h +3 -3
@@ -104,7 +104,7 @@ typedef enum xfs_dinode_fmt {/* * Inode size for given fs. */ -#define XFS_LITINO (mp) \ +#define XFS_LITINO (mp, version) \ ((int)(((mp)->m_sb.sb_inodesize) - sizeof(struct xfs_dinode)))#define XFS_BROOT_SIZE_ADJ \
@@ -119,10 +119,10 @@ typedef enum xfs_dinode_fmt {#define XFS_DFORK_DSIZE (dip,mp) \ (XFS_DFORK_Q(dip) ? \ XFS_DFORK_BOFF(dip) : \ - XFS_LITINO(mp)) + XFS_LITINO(mp, (dip)->di_version))#define XFS_DFORK_ASIZE (dip,mp) \ (XFS_DFORK_Q(dip) ? \ - XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : \ + XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \ 0)#define XFS_DFORK_SIZE (dip,mp,w) \ ((w) == XFS_DATA_FORK ? \
fs/xfs/xfs_inode.h +3 -2
@@ -180,10 +180,11 @@ typedef struct xfs_icdinode {#define XFS_IFORK_DSIZE (ip) \ (XFS_IFORK_Q(ip) ? \ XFS_IFORK_BOFF(ip) : \ - XFS_LITINO((ip)->i_mount)) + XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))#define XFS_IFORK_ASIZE (ip) \ (XFS_IFORK_Q(ip) ? \ - XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : \ + XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \ + XFS_IFORK_BOFF(ip) : \ 0)#define XFS_IFORK_SIZE (ip,w) \ ((w) == XFS_DATA_FORK ? \
fs/xfs/xfs_vnodeops.c +1 -1
@@ -1420,7 +1420,7 @@ xfs_symlink(* The symlink will fit into the inode data fork? * There can't be any attributes so we get the whole variable part. */ -if (pathlen <=XFS_LITINO (mp)) +if (pathlen <=XFS_LITINO (mp, dp->i_d.di_version)) fs_blocks =0 ;else fs_blocks =XFS_B_TO_FSB (mp, pathlen);
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 3/16 xfs: add support for large btree blocks
In reply to Dave ChinnerFrom: Christoph Hellwig <[email protected]>
Add support for larger btree blocks that contains a CRC32C checksum, a filesystem uuid and block number for detecting filesystem consistency and out of place writes.
[[email protected]] Also include an owner field to allow reverse mappings to be implemented for improved repairability and a LSN field to so that log recovery can easily determine the last modification that made it to disk for each buffer.
[[email protected]] Add buffer log format flags to indicate the type of buffer to recovery so that we don't have to do blind magic number tests to determine what the buffer is.
[[email protected]] Modified to fit into the verifier structure.
--- fs/xfs/xfs_alloc_btree.c | 105 +++++++++++++------ fs/xfs/xfs_alloc_btree.h | 12 ++- fs/xfs/xfs_attr_leaf.c | 2 +- fs/xfs/xfs_bmap.c | 47 ++++++--- fs/xfs/xfs_bmap_btree.c | 110 +++++++++++++------ fs/xfs/xfs_bmap_btree.h | 19 ++-- fs/xfs/xfs_btree.c | 256 +++++++++++++++++++++++++++++++++++++-------- fs/xfs/xfs_btree.h | 64 ++++++++++-- fs/xfs/xfs_buf_item.h | 24 ++++- fs/xfs/xfs_dinode.h | 4 +- fs/xfs/xfs_fsops.c | 23 +++- fs/xfs/xfs_ialloc_btree.c | 87 ++++++++++----- fs/xfs/xfs_ialloc_btree.h | 9 +- fs/xfs/xfs_inode.c | 33 +++--- fs/xfs/xfs_log_recover.c | 28 +++++ fs/xfs/xfs_trans.h | 2 + fs/xfs/xfs_trans_buf.c | 29 +++-- 17 files changed, 645 insertions(+), 209 deletions(-)
fs/xfs/xfs_alloc_btree.c +73 -32
@@ -33,6 +33,7 @@#include "xfs_extent_busy.h" #include "xfs_error.h" #include "xfs_trace.h" +#include "xfs_cksum.h" STATIC struct xfs_btree_cur *
@@ -272,7 +273,7 @@ xfs_allocbt_key_diff(return (__int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; } -static void +static bool xfs_allocbt_verify (struct xfs_buf *bp) {
@@ -280,66 +281,103 @@ xfs_allocbt_verify(struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_perag *pag = bp->b_pag;unsigned int level; -int sblock_ok;/* block passes checks */ /* * magic number and level verification * -* During growfs operations, we can't verify the exact level as the -* perag is not fully initialised and hence not attached to the buffer. -* In this case, check against the maximum tree depth. +* During growfs operations, we can't verify the exact level or owner as +* the perag is not fully initialised and hence not attached to the +* buffer. In this case, check against the maximum tree depth. +* +* Similarly, during log recovery we will have a perag structure +* attached, but the agf information will not yet have been initialised +* from the on disk AGF. Again, we can only check against maximum limits +* in this case. */ level =be16_to_cpu (block->bb_level);switch (block->bb_magic) { +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_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) +return false; +/* fall through */ case cpu_to_be32 (XFS_ABTB_MAGIC ): -if (pag) - sblock_ok = level < pag->pagf_levels[XFS_BTNUM_BNOi]; -else - sblock_ok = level < mp->m_ag_maxlevels; +if (pag && pag->pagf_init) { +if (level >= pag->pagf_levels[XFS_BTNUM_BNOi]) +return false; + }else if (level >= mp->m_ag_maxlevels) +return false;break ; +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_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) +return false; +/* fall through */ case cpu_to_be32 (XFS_ABTC_MAGIC ): -if (pag) - sblock_ok = level < pag->pagf_levels[XFS_BTNUM_CNTi]; -else - sblock_ok = level < mp->m_ag_maxlevels; +if (pag && pag->pagf_init) { +if (level >= pag->pagf_levels[XFS_BTNUM_CNTi]) +return false; + }else if (level >= mp->m_ag_maxlevels) +return false;break ;default : - sblock_ok =0 ; -break ; +return false; }/* numrecs verification */ - sblock_ok = sblock_ok && -be16_to_cpu (block->bb_numrecs) <= mp->m_alloc_mxr[level !=0 ]; +if (be16_to_cpu (block->bb_numrecs) > mp->m_alloc_mxr[level !=0 ]) +return false;/* sibling pointer verification */ - sblock_ok = sblock_ok && - (block->bb_u.s.bb_leftsib ==cpu_to_be32 (NULLAGBLOCK ) || -be32_to_cpu (block->bb_u.s.bb_leftsib) < mp->m_sb.sb_agblocks) && - block->bb_u.s.bb_leftsib && - (block->bb_u.s.bb_rightsib ==cpu_to_be32 (NULLAGBLOCK ) || -be32_to_cpu (block->bb_u.s.bb_rightsib) < mp->m_sb.sb_agblocks) && - block->bb_u.s.bb_rightsib; - -if (!sblock_ok) { -trace_xfs_btree_corrupt (bp, _RET_IP_); -XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, block); -xfs_buf_ioerror (bp,EFSCORRUPTED ); - } +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; }static void xfs_allocbt_read_verify (struct xfs_buf *bp) { -xfs_allocbt_verify (bp); +if (!(xfs_btree_sblock_verify_crc (bp) && +xfs_allocbt_verify (bp))) { +trace_xfs_btree_corrupt (bp, _RET_IP_); +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , + bp->b_target->bt_mount, bp->b_addr); +xfs_buf_ioerror (bp,EFSCORRUPTED ); + } }static void xfs_allocbt_write_verify (struct xfs_buf *bp) { -xfs_allocbt_verify (bp); +if (!xfs_allocbt_verify (bp)) { +trace_xfs_btree_corrupt (bp, _RET_IP_); +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , + bp->b_target->bt_mount, bp->b_addr); +xfs_buf_ioerror (bp,EFSCORRUPTED ); + } +xfs_btree_sblock_calc_crc (bp); + }const struct xfs_buf_ops xfs_allocbt_buf_ops = {
@@ -444,6 +482,9 @@ xfs_allocbt_init_cursor( cur->bc_private.a.agbp = agbp; cur->bc_private.a.agno = agno; +if (xfs_sb_version_hascrc (&mp->m_sb)) + cur->bc_flags |=XFS_BTREE_CRC_BLOCKS ; +return cur; }
fs/xfs/xfs_alloc_btree.h +7 -5
@@ -31,8 +31,10 @@ struct xfs_mount;* by blockcount and blockno. All blocks look the same to make the code * simpler; if we have time later, we'll make the optimizations. */ -#define XFS_ABTB_MAGIC 0x41425442/* 'ABTB' for bno tree */ -#define XFS_ABTC_MAGIC 0x41425443/* 'ABTC' for cnt tree */ +#define XFS_ABTB_MAGIC 0x41425442/* 'ABTB' for bno tree */ +#define XFS_ABTB_CRC_MAGIC 0x41423342/* 'AB3B' */ +#define XFS_ABTC_MAGIC 0x41425443/* 'ABTC' for cnt tree */ +#define XFS_ABTC_CRC_MAGIC 0x41423343/* 'AB3C' */ /* * Data record/key structure
@@ -59,10 +61,10 @@ typedef __be32 xfs_alloc_ptr_t;/* * Btree block header size depends on a superblock flag. -* -* (not quite yet, but soon) */ -#define XFS_ALLOC_BLOCK_LEN (mp) XFS_BTREE_SBLOCK_LEN +#define XFS_ALLOC_BLOCK_LEN (mp) \ + (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ + XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN)/* * Record, key, and pointer address macros for btree blocks.
fs/xfs/xfs_attr_leaf.c +1 -1
@@ -232,7 +232,7 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)return 0 ;return dp->i_d.di_forkoff; } - dsize =XFS_BMAP_BROOT_SPACE (dp->i_df.if_broot); + dsize =XFS_BMAP_BROOT_SPACE (mp, dp->i_df.if_broot);break ; }
fs/xfs/xfs_bmap.c +31 -16
112 lines not on this page · raw message
fs/xfs/xfs_bmap_btree.c +78 -32
180 lines not on this page · raw message
fs/xfs/xfs_bmap_btree.h +10 -9
@@ -18,7 +18,8 @@#ifndef __XFS_BMAP_BTREE_H__#define __XFS_BMAP_BTREE_H__ -#define XFS_BMAP_MAGIC 0x424d4150/* 'BMAP' */ +#define XFS_BMAP_MAGIC 0x424d4150/* 'BMAP' */ +#define XFS_BMAP_CRC_MAGIC 0x424d4133/* 'BMA3' */ struct xfs_btree_cur ;struct xfs_btree_block ;
@@ -136,10 +137,10 @@ typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;/* * Btree block header size depends on a superblock flag. -* -* (not quite yet, but soon) */ -#define XFS_BMBT_BLOCK_LEN (mp) XFS_BTREE_LBLOCK_LEN +#define XFS_BMBT_BLOCK_LEN (mp) \ + (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ + XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN)#define XFS_BMBT_REC_ADDR (mp, block, index) \ ((xfs_bmbt_rec_t *) \
@@ -186,12 +187,12 @@ typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;#define XFS_BMAP_BROOT_PTR_ADDR (mp, bb, i, sz) \ XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0)) -#define XFS_BMAP_BROOT_SPACE_CALC (nrecs) \ - (int)(XFS_BTREE_LBLOCK_LEN + \ +#define XFS_BMAP_BROOT_SPACE_CALC (mp, nrecs) \ + (int)(XFS_BMBT_BLOCK_LEN(mp) + \ ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) -#define XFS_BMAP_BROOT_SPACE (bb) \ - (XFS_BMAP_BROOT_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs))) +#define XFS_BMAP_BROOT_SPACE (mp, bb) \ + (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))#define XFS_BMDR_SPACE_CALC (nrecs) \ (int)(sizeof(xfs_bmdr_block_t) + \ ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
@@ -204,7 +205,7 @@ typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;/* * Prototypes for xfs_bmap.c to call. */ -extern void xfs_bmdr_to_bmbt (struct xfs_mount *,xfs_bmdr_block_t *,int , +extern void xfs_bmdr_to_bmbt (struct xfs_inode *,xfs_bmdr_block_t *,int ,struct xfs_btree_block *,int );extern void xfs_bmbt_get_all (xfs_bmbt_rec_host_t *r,xfs_bmbt_irec_t *s);extern xfs_filblks_t xfs_bmbt_get_blockcount (xfs_bmbt_rec_host_t *r);
fs/xfs/xfs_btree.c +211 -45
412 lines not on this page · raw message
fs/xfs/xfs_btree.h +55 -9
115 lines not on this page · raw message
fs/xfs/xfs_buf_item.h +19 -5
@@ -24,19 +24,33 @@ extern kmem_zone_t *xfs_buf_item_zone;* This flag indicates that the buffer contains on disk inodes * and requires special recovery handling. */ -#define XFS_BLF_INODE_BUF 0x1 +#define XFS_BLF_INODE_BUF (1<<0)/* * This flag indicates that the buffer should not be replayed * during recovery because its blocks are being freed. */ -#define XFS_BLF_CANCEL 0x2 +#define XFS_BLF_CANCEL (1<<1) +/* * This flag indicates that the buffer contains on disk * user or group dquots and may require special recovery handling. */ -#define XFS_BLF_UDQUOT_BUF 0x4 -#define XFS_BLF_PDQUOT_BUF 0x8 -#define XFS_BLF_GDQUOT_BUF 0x10 +#define XFS_BLF_UDQUOT_BUF (1<<2) +#define XFS_BLF_PDQUOT_BUF (1<<3) +#define XFS_BLF_GDQUOT_BUF (1<<4) + +/* +* all buffers now need flags to tell recovery where the magic number +* is so that it can verify and calculate the CRCs on the buffer correctly +* once the changes have been replayed into the buffer. +*/ +#define XFS_BLF_BTREE_BUF (1<<5) + +#define XFS_BLF_TYPE_MASK \ + (XFS_BLF_UDQUOT_BUF | \ + XFS_BLF_PDQUOT_BUF | \ + XFS_BLF_GDQUOT_BUF | \ + XFS_BLF_BTREE_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_dinode.h +2 -2
@@ -107,8 +107,8 @@ typedef enum xfs_dinode_fmt {#define XFS_LITINO (mp, version) \ ((int)(((mp)->m_sb.sb_inodesize) - sizeof(struct xfs_dinode))) -#define XFS_BROOT_SIZE_ADJ \ - (XFS_BTREE_LBLOCK_LEN - sizeof(xfs_bmdr_block_t)) +#define XFS_BROOT_SIZE_ADJ (ip) \ + (XFS_BMBT_BLOCK_LEN((ip)->i_mount) - sizeof(xfs_bmdr_block_t))/* * Inode data & attribute fork sizes, per inode.
fs/xfs/xfs_fsops.c +20 -3
@@ -316,7 +316,13 @@ xfs_growfs_data_private( goto error0; } -xfs_btree_init_block (mp, bp,XFS_ABTB_MAGIC ,0 ,1 ,0 ); +if (xfs_sb_version_hascrc (&mp->m_sb)) +xfs_btree_init_block (mp, bp,XFS_ABTB_CRC_MAGIC ,0 ,1 , + agno,XFS_BTREE_CRC_BLOCKS ); +else +xfs_btree_init_block (mp, bp,XFS_ABTB_MAGIC ,0 ,1 , + agno,0 ); + arec =XFS_ALLOC_REC_ADDR (mp,XFS_BUF_TO_BLOCK (bp),1 ); arec->ar_startblock =cpu_to_be32 (XFS_PREALLOC_BLOCKS (mp)); arec->ar_blockcount = cpu_to_be32(
@@ -339,7 +345,13 @@ xfs_growfs_data_private( goto error0; } -xfs_btree_init_block (mp, bp,XFS_ABTC_MAGIC ,0 ,1 ,0 ); +if (xfs_sb_version_hascrc (&mp->m_sb)) +xfs_btree_init_block (mp, bp,XFS_ABTC_CRC_MAGIC ,0 ,1 , + agno,XFS_BTREE_CRC_BLOCKS ); +else +xfs_btree_init_block (mp, bp,XFS_ABTC_MAGIC ,0 ,1 , + agno,0 ); + arec =XFS_ALLOC_REC_ADDR (mp,XFS_BUF_TO_BLOCK (bp),1 ); arec->ar_startblock =cpu_to_be32 (XFS_PREALLOC_BLOCKS (mp)); arec->ar_blockcount = cpu_to_be32(
@@ -363,7 +375,12 @@ xfs_growfs_data_private( goto error0; } -xfs_btree_init_block (mp, bp,XFS_IBT_MAGIC ,0 ,0 ,0 ); +if (xfs_sb_version_hascrc (&mp->m_sb)) +xfs_btree_init_block (mp, bp,XFS_IBT_CRC_MAGIC ,0 ,0 , + agno,XFS_BTREE_CRC_BLOCKS ); +else +xfs_btree_init_block (mp, bp,XFS_IBT_MAGIC ,0 ,0 , + agno,0 ); error =xfs_bwrite (bp);xfs_buf_relse (bp);
fs/xfs/xfs_ialloc_btree.c +63 -24
127 lines not on this page · raw message
fs/xfs/xfs_ialloc_btree.h +5 -4
@@ -29,7 +29,8 @@ struct xfs_mount;/* * There is a btree for the inode map per allocation group. */ -#define XFS_IBT_MAGIC 0x49414254/* 'IABT' */ +#define XFS_IBT_MAGIC 0x49414254/* 'IABT' */ +#define XFS_IBT_CRC_MAGIC 0x49414233/* 'IAB3' */ typedef __uint64_t xfs_inofree_t ;#define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
@@ -76,10 +77,10 @@ typedef __be32 xfs_inobt_ptr_t;/* * Btree block header size depends on a superblock flag. -* -* (not quite yet, but soon) */ -#define XFS_INOBT_BLOCK_LEN (mp) XFS_BTREE_SBLOCK_LEN +#define XFS_INOBT_BLOCK_LEN (mp) \ + (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ + XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN)/* * Record, key, and pointer address macros for btree blocks.
fs/xfs/xfs_inode.c +17 -16
@@ -786,6 +786,7 @@ xfs_iformat_btree( xfs_dinode_t *dip, int whichfork) { +struct xfs_mount *mp = ip->i_mount;xfs_bmdr_block_t *dfp;xfs_ifork_t *ifp;/* REFERENCED */
@@ -794,7 +795,7 @@ xfs_iformat_btree( ifp =XFS_IFORK_PTR (ip, whichfork); dfp = (xfs_bmdr_block_t *)XFS_DFORK_PTR (dip, whichfork); - size =XFS_BMAP_BROOT_SPACE (dfp); + size =XFS_BMAP_BROOT_SPACE (mp, dfp); nrecs =be16_to_cpu (dfp->bb_numrecs);/*
@@ -805,14 +806,14 @@ xfs_iformat_btree(* blocks. */ if (unlikely (XFS_IFORK_NEXTENTS (ip, whichfork) <= -XFS_IFORK_MAXEXT (ip, whichfork) || +XFS_IFORK_MAXEXT (ip, whichfork) ||XFS_BMDR_SPACE_CALC (nrecs) > -XFS_DFORK_SIZE (dip, ip->i_mount, whichfork) || +XFS_DFORK_SIZE (dip, mp, whichfork) ||XFS_IFORK_NEXTENTS (ip, whichfork) > ip->i_d.di_nblocks)) { -xfs_warn (ip->i_mount,"corrupt inode %Lu (btree)." , - (unsigned long long ) ip->i_ino); +xfs_warn (mp,"corrupt inode %Lu (btree)." , + (unsigned long long ) ip->i_ino);XFS_CORRUPTION_ERROR ("xfs_iformat_btree" ,XFS_ERRLEVEL_LOW , - ip->i_mount, dip); + mp, dip);return XFS_ERROR (EFSCORRUPTED ); }
@@ -823,8 +824,7 @@ xfs_iformat_btree(* Copy and convert from the on-disk structure * to the in-memory structure. */ -xfs_bmdr_to_bmbt (ip->i_mount, dfp, -XFS_DFORK_SIZE (dip, ip->i_mount, whichfork), +xfs_bmdr_to_bmbt (ip, dfp,XFS_DFORK_SIZE (dip, ip->i_mount, whichfork), ifp->if_broot, size); ifp->if_flags &= ~XFS_IFEXTENTS ; ifp->if_flags |=XFS_IFBROOT ;
@@ -2037,7 +2037,7 @@ xfs_iroot_realloc(* allocate it now and get out. */ if (ifp->if_broot_bytes ==0 ) { - new_size = (size_t )XFS_BMAP_BROOT_SPACE_CALC (rec_diff); + new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, rec_diff); ifp->if_broot =kmem_alloc (new_size,KM_SLEEP |KM_NOFS ); ifp->if_broot_bytes = (int )new_size;return ;
@@ -2051,9 +2051,9 @@ xfs_iroot_realloc(*/ cur_max =xfs_bmbt_maxrecs (mp, ifp->if_broot_bytes,0 ); new_max = cur_max + rec_diff; - new_size = (size_t )XFS_BMAP_BROOT_SPACE_CALC (new_max); + new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, new_max); ifp->if_broot =kmem_realloc (ifp->if_broot, new_size, - (size_t )XFS_BMAP_BROOT_SPACE_CALC (cur_max),/* old size */ +XFS_BMAP_BROOT_SPACE_CALC (mp, cur_max),KM_SLEEP |KM_NOFS ); op = (char *)XFS_BMAP_BROOT_PTR_ADDR (mp, ifp->if_broot,1 , ifp->if_broot_bytes);
@@ -2061,7 +2061,7 @@ xfs_iroot_realloc( (int)new_size); ifp->if_broot_bytes = (int )new_size;ASSERT (ifp->if_broot_bytes <= -XFS_IFORK_SIZE (ip, whichfork) +XFS_BROOT_SIZE_ADJ ); +XFS_IFORK_SIZE (ip, whichfork) +XFS_BROOT_SIZE_ADJ (ip));memmove (np, op, cur_max * (uint )sizeof (xfs_dfsbno_t));return ; }
@@ -2076,7 +2076,7 @@ xfs_iroot_realloc( new_max = cur_max + rec_diff;ASSERT (new_max >=0 );if (new_max >0 ) - new_size = (size_t )XFS_BMAP_BROOT_SPACE_CALC (new_max); + new_size =XFS_BMAP_BROOT_SPACE_CALC (mp, new_max);else new_size =0 ;if (new_size >0 ) {
@@ -2084,7 +2084,8 @@ xfs_iroot_realloc(/* * First copy over the btree block header. */ -memcpy (new_broot, ifp->if_broot,XFS_BTREE_LBLOCK_LEN ); +memcpy (new_broot, ifp->if_broot, +XFS_BMBT_BLOCK_LEN (ip->i_mount)); }else { new_broot =NULL ; ifp->if_flags &= ~XFS_IFBROOT ;
@@ -2114,7 +2115,7 @@ xfs_iroot_realloc( ifp->if_broot = new_broot; ifp->if_broot_bytes = (int )new_size;ASSERT (ifp->if_broot_bytes <= -XFS_IFORK_SIZE (ip, whichfork) +XFS_BROOT_SIZE_ADJ ); +XFS_IFORK_SIZE (ip, whichfork) +XFS_BROOT_SIZE_ADJ (ip));return ; }
@@ -2427,7 +2428,7 @@ xfs_iflush_fork(ASSERT (ifp->if_broot !=NULL );ASSERT (ifp->if_broot_bytes <= (XFS_IFORK_SIZE (ip, whichfork) + -XFS_BROOT_SIZE_ADJ )); +XFS_BROOT_SIZE_ADJ (ip)));xfs_bmbt_to_bmdr (mp, ifp->if_broot, ifp->if_broot_bytes, (xfs_bmdr_block_t *)cp,XFS_DFORK_SIZE (dip, mp, whichfork));
fs/xfs/xfs_log_recover.c +28 -0
@@ -29,6 +29,7 @@#include "xfs_bmap_btree.h" #include "xfs_alloc_btree.h" #include "xfs_ialloc_btree.h" +#include "xfs_btree.h" #include "xfs_dinode.h" #include "xfs_inode.h" #include "xfs_inode_item.h"
@@ -1929,6 +1930,33 @@ xlog_recover_do_reg_buffer(/* Shouldn't be any more regions */ ASSERT (i == item->ri_total); + +switch (buf_f->blf_flags &XFS_BLF_TYPE_MASK ) { +case XFS_BLF_BTREE_BUF : +switch (be32_to_cpu (*(__be32 *)bp->b_addr)) { +case XFS_ABTB_CRC_MAGIC : +case XFS_ABTC_CRC_MAGIC : +case XFS_ABTB_MAGIC : +case XFS_ABTC_MAGIC : + bp->b_ops = &xfs_allocbt_buf_ops; +break ; +case XFS_IBT_CRC_MAGIC : +case XFS_IBT_MAGIC : + bp->b_ops = &xfs_inobt_buf_ops; +break ; +case XFS_BMAP_CRC_MAGIC : +case XFS_BMAP_MAGIC : + bp->b_ops = &xfs_bmbt_buf_ops; +break ; +default : +xfs_warn (mp,"Bad btree block magic!" ); +ASSERT (0 ); +break ; + } +break ; +default : +break ; + } }/*
fs/xfs/xfs_trans.h +2 -0
@@ -505,6 +505,8 @@ void xfs_trans_inode_buf(xfs_trans_t *, struct xfs_buf *);void xfs_trans_stale_inode_buf (xfs_trans_t *,struct xfs_buf *);void xfs_trans_dquot_buf (xfs_trans_t *,struct xfs_buf *,uint );void xfs_trans_inode_alloc_buf (xfs_trans_t *,struct xfs_buf *); +void xfs_trans_buf_set_type (struct xfs_trans *,struct xfs_buf *, +uint );void xfs_trans_ichgtime (struct xfs_trans *,struct xfs_inode *,int );void xfs_trans_ijoin (struct xfs_trans *,struct xfs_inode *,uint );void xfs_trans_log_buf (xfs_trans_t *,struct xfs_buf *,uint ,uint );
fs/xfs/xfs_trans_buf.c +23 -6
@@ -659,6 +659,7 @@ xfs_trans_binval(ASSERT (XFS_BUF_ISSTALE (bp));ASSERT (!(bip->bli_flags & (XFS_BLI_LOGGED |XFS_BLI_DIRTY )));ASSERT (!(bip->__bli_format.blf_flags &XFS_BLF_INODE_BUF )); +ASSERT (!(bip->__bli_format.blf_flags &XFS_BLF_TYPE_MASK ));ASSERT (bip->__bli_format.blf_flags &XFS_BLF_CANCEL );ASSERT (bip->bli_item.li_desc->lid_flags &XFS_LID_DIRTY );ASSERT (tp->t_flags &XFS_TRANS_DIRTY );
@@ -671,6 +672,7 @@ xfs_trans_binval( bip->bli_flags &= ~(XFS_BLI_INODE_BUF |XFS_BLI_LOGGED |XFS_BLI_DIRTY ); bip->__bli_format.blf_flags &= ~XFS_BLF_INODE_BUF ; bip->__bli_format.blf_flags |=XFS_BLF_CANCEL ; + bip->__bli_format.blf_flags &= ~XFS_BLF_TYPE_MASK ;for (i =0 ; i < bip->bli_format_count; i++) {memset (bip->bli_formats[i].blf_data_map,0 , (bip->bli_formats[i].blf_map_size *sizeof (uint)));
@@ -751,6 +753,26 @@ xfs_trans_inode_alloc_buf( bip->bli_flags |=XFS_BLI_INODE_ALLOC_BUF ; } +/* +* Set the type of the buffer for log recovery so that it can correctly identify +* and hence attach the correct buffer ops to the buffer after replay. +*/ +void +xfs_trans_buf_set_type ( +struct xfs_trans *tp, +struct xfs_buf *bp, +uint type) +{ +struct xfs_buf_log_item *bip = bp->b_fspriv; + +ASSERT (bp->b_transp == tp); +ASSERT (bip !=NULL ); +ASSERT (atomic_read (&bip->bli_refcount) >0 ); +ASSERT ((type &XFS_BLF_TYPE_MASK ) !=0 ); + + bip->__bli_format.blf_flags &= ~XFS_BLF_TYPE_MASK ; + bip->__bli_format.blf_flags |= type; +}/* * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
@@ -769,14 +791,9 @@ xfs_trans_dquot_buf( xfs_buf_t *bp, uint type) { -xfs_buf_log_item_t *bip = bp->b_fspriv; - -ASSERT (bp->b_transp == tp); -ASSERT (bip !=NULL );ASSERT (type ==XFS_BLF_UDQUOT_BUF || type ==XFS_BLF_PDQUOT_BUF || type ==XFS_BLF_GDQUOT_BUF ); -ASSERT (atomic_read (&bip->bli_refcount) >0 ); - bip->__bli_format.blf_flags |= type; +xfs_trans_buf_set_type (tp, bp, type); }
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 4/16 xfs: add CRC checks to the AGF
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
The AGF already has some self identifying fields (e.g. the sequence number) so we only need to add the uuid to it to identify the filesystem it belongs to. The location is fixed based on the sequence number, so there's no need to add a block number, either.
Hence the only additional fields are the CRC and LSN fields. These are unlogged, so place some space between the end of the logged fields and them so that future expansion of the AGF for logged fields can be placed adjacent to the existing logged fields and hence not complicate the field-derived range based logging we currently have.
Based originally on a patch from myself, modified further by Christoph Hellwig and then modified again to fit into the verifier structure with additional fields by myself. The multiple signed-off-by tags indicate the age and history of this patch.
--- fs/xfs/xfs_ag.h | 23 +++++++++++-- fs/xfs/xfs_alloc.c | 80 ++++++++++++++++++++++++++++++++-------------- fs/xfs/xfs_buf_item.h | 4 ++- fs/xfs/xfs_fsops.c | 3 ++ fs/xfs/xfs_log_recover.c | 8 +++++ 5 files changed, 91 insertions(+), 27 deletions(-)
fs/xfs/xfs_ag.h +21 -2
@@ -63,12 +63,29 @@ typedef struct xfs_agf {__be32 agf_spare0;/* spare field */ __be32 agf_levels[XFS_BTNUM_AGF ];/* btree levels */ __be32 agf_spare1;/* spare field */ +__be32 agf_flfirst;/* first freelist block's index */ __be32 agf_fllast;/* last freelist block's index */ __be32 agf_flcount;/* count of blocks in freelist */ __be32 agf_freeblks;/* total free blocks */ +__be32 agf_longest;/* longest free space */ __be32 agf_btreeblks;/* # of blocks held in AGF btrees */ +uuid_t agf_uuid;/* uuid of filesystem */ + +/* +* reserve some contiguous space for future logged fields before we add +* the unlogged fields. This makes the range logging via flags and +* structure offsets much simpler. +*/ +__be64 agf_spare64[16 ]; + +/* unlogged fields, written during buffer writeback. */ +__be64 agf_lsn;/* last write sequence */ +__be32 agf_crc;/* crc of agf sector */ +__be32 agf_spare2; + +/* structure must be padded to 64 bit alignment */ } xfs_agf_t;#define XFS_AGF_MAGICNUM 0x00000001
@@ -83,7 +100,8 @@ typedef struct xfs_agf {#define XFS_AGF_FREEBLKS 0x00000200#define XFS_AGF_LONGEST 0x00000400#define XFS_AGF_BTREEBLKS 0x00000800 -#define XFS_AGF_NUM_BITS 12 +#define XFS_AGF_UUID 0x00001000 +#define XFS_AGF_NUM_BITS 13#define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)#define XFS_AGF_FLAGS \
@@ -98,7 +116,8 @@ typedef struct xfs_agf { { XFS_AGF_FLCOUNT, "FLCOUNT" }, \ { XFS_AGF_FREEBLKS, "FREEBLKS" }, \ { XFS_AGF_LONGEST, "LONGEST" }, \ - { XFS_AGF_BTREEBLKS, "BTREEBLKS" } + { XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \ + { XFS_AGF_UUID, "UUID" } /* disk block (xfs_daddr_t) in the AG */ #define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
fs/xfs/xfs_alloc.c +56 -24
129 lines not on this page · raw message
fs/xfs/xfs_buf_item.h +3 -1
@@ -45,12 +45,14 @@ extern kmem_zone_t *xfs_buf_item_zone;* once the changes have been replayed into the buffer. */ #define XFS_BLF_BTREE_BUF (1<<5) +#define XFS_BLF_AGF_BUF (1<<6)#define XFS_BLF_TYPE_MASK \ (XFS_BLF_UDQUOT_BUF | \ XFS_BLF_PDQUOT_BUF | \ XFS_BLF_GDQUOT_BUF | \ - XFS_BLF_BTREE_BUF) + XFS_BLF_BTREE_BUF | \ + XFS_BLF_AGF_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_fsops.c +3 -0
@@ -247,6 +247,9 @@ xfs_growfs_data_private( tmpsize = agsize -XFS_PREALLOC_BLOCKS (mp); agf->agf_freeblks =cpu_to_be32 (tmpsize); agf->agf_longest =cpu_to_be32 (tmpsize); +if (xfs_sb_version_hascrc (&mp->m_sb)) +uuid_copy (&agf->agf_uuid, &mp->m_sb.sb_uuid); + error =xfs_bwrite (bp);xfs_buf_relse (bp);if (error)
fs/xfs/xfs_log_recover.c +8 -0
@@ -1954,6 +1954,14 @@ xlog_recover_do_reg_buffer(break ; }break ; +case XFS_BLF_AGF_BUF : +if (*(__be32 *)bp->b_addr !=cpu_to_be32 (XFS_AGF_MAGIC )) { +xfs_warn (mp,"Bad AGF block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_agf_buf_ops; +break ;default :break ; }
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 5/16 xfs: add CRC checks to the AGFL
In reply to Dave ChinnerFrom: Christoph Hellwig <[email protected]>
Add CRC checks, location information and a magic number to the AGFL. Previously the AGFL was just a block containing nothing but the free block pointers. The new AGFL has a real header with the usual boilerplate instead, so that we can verify it's not corrupted and written into the right place.
[[email protected]] Added LSN field, reworked significantly to fit into new verifier structure and growfs structure, enabled full verifier functionality now there is a header to verify and we can guarantee an initialised AGFL.
--- fs/xfs/xfs_ag.h | 25 +++++++++- fs/xfs/xfs_alloc.c | 119 ++++++++++++++++++++++++++++++---------------- fs/xfs/xfs_buf_item.h | 4 +- fs/xfs/xfs_fsops.c | 5 ++ fs/xfs/xfs_log_recover.c | 10 ++++ 5 files changed, 119 insertions(+), 44 deletions(-)
fs/xfs/xfs_ag.h +23 -2
@@ -30,6 +30,7 @@ struct xfs_trans;#define XFS_AGF_MAGIC 0x58414746/* 'XAGF' */ #define XFS_AGI_MAGIC 0x58414749/* 'XAGI' */ +#define XFS_AGFL_MAGIC 0x5841464c/* 'XAFL' */ #define XFS_AGF_VERSION 1#define XFS_AGI_VERSION 1
@@ -190,11 +191,31 @@ extern const struct xfs_buf_ops xfs_agi_buf_ops;*/ #define XFS_AGFL_DADDR (mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))#define XFS_AGFL_BLOCK (mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp)) -#define XFS_AGFL_SIZE (mp) ((mp)->m_sb.sb_sectsize / sizeof(xfs_agblock_t))#define XFS_BUF_TO_AGFL (bp) ((xfs_agfl_t *)((bp)->b_addr)) +#define XFS_BUF_TO_AGFL_BNO (mp, bp) \ + (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ + &(XFS_BUF_TO_AGFL(bp)->agfl_bno[0]) : \ + (__be32 *)(bp)->b_addr) + +/* +* Size of the AGFL. For CRC-enabled filesystes we steal a couple of +* slots in the beginning of the block for a proper header with the +* location information and CRC. +*/ +#define XFS_AGFL_SIZE (mp) \ + (((mp)->m_sb.sb_sectsize - \ + (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ + sizeof(struct xfs_agfl) : 0)) / \ + sizeof(xfs_agblock_t)) +typedef struct xfs_agfl { -__be32 agfl_bno[1 ];/* actually XFS_AGFL_SIZE(mp) */ +__be32 agfl_magicnum; +__be32 agfl_seqno; +uuid_t agfl_uuid; +__be64 agfl_lsn; +__be32 agfl_crc; +__be32 agfl_bno[];/* actually XFS_AGFL_SIZE(mp) */ }xfs_agfl_t ;/*
fs/xfs/xfs_alloc.c +78 -41
196 lines not on this page · raw message
fs/xfs/xfs_buf_item.h +3 -1
@@ -46,13 +46,15 @@ extern kmem_zone_t *xfs_buf_item_zone;*/ #define XFS_BLF_BTREE_BUF (1<<5)#define XFS_BLF_AGF_BUF (1<<6) +#define XFS_BLF_AGFL_BUF (1<<7)#define XFS_BLF_TYPE_MASK \ (XFS_BLF_UDQUOT_BUF | \ XFS_BLF_PDQUOT_BUF | \ XFS_BLF_GDQUOT_BUF | \ XFS_BLF_BTREE_BUF | \ - XFS_BLF_AGF_BUF) + XFS_BLF_AGF_BUF | \ + XFS_BLF_AGFL_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_fsops.c +5 -0
@@ -268,6 +268,11 @@ xfs_growfs_data_private( } agfl =XFS_BUF_TO_AGFL (bp); +if (xfs_sb_version_hascrc (&mp->m_sb)) { + agfl->agfl_magicnum =cpu_to_be32 (XFS_AGFL_MAGIC ); + agfl->agfl_seqno =cpu_to_be32 (agno); +uuid_copy (&agfl->agfl_uuid, &mp->m_sb.sb_uuid); + }for (bucket =0 ; bucket <XFS_AGFL_SIZE (mp); bucket++) agfl->agfl_bno[bucket] =cpu_to_be32 (NULLAGBLOCK );
fs/xfs/xfs_log_recover.c +10 -0
@@ -1962,6 +1962,16 @@ xlog_recover_do_reg_buffer( } bp->b_ops = &xfs_agf_buf_ops;break ; +case XFS_BLF_AGFL_BUF : +if (!xfs_sb_version_hascrc (&mp->m_sb)) +break ; +if (*(__be32 *)bp->b_addr !=cpu_to_be32 (XFS_AGFL_MAGIC )) { +xfs_warn (mp,"Bad AGFL block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_agfl_buf_ops; +break ;default :break ; }
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 05/16] xfs: add CRC checks to the AGFL
Hi Dave,
Quoted 51 lines · Dave Chinner
From: Christoph Hellwig <[email protected]>
Add CRC checks, location information and a magic number to the AGFL. Previously the AGFL was just a block containing nothing but the free block pointers. The new AGFL has a real header with the usual boilerplate instead, so that we can verify it's not corrupted and written into the right place.
[[email protected]] Added LSN field, reworked significantly to fit into new verifier structure and growfs structure, enabled full verifier functionality now there is a header to verify and we can guarantee an initialised AGFL.
Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Dave Chinner <[email protected]>--- fs/xfs/xfs_ag.h | 25 +++++++++- fs/xfs/xfs_alloc.c | 119 ++++++++++++++++++++++++++++++---------------- fs/xfs/xfs_buf_item.h | 4 +- fs/xfs/xfs_fsops.c | 5 ++ fs/xfs/xfs_log_recover.c | 10 ++++ 5 files changed, 119 insertions(+), 44 deletions(-)fs/xfs/xfs_ag.h +10
-1@@ -30,6 +30,7 @@ struct xfs_trans;#define XFS_AGF_MAGIC 0x58414746/* 'XAGF' */ #define XFS_AGI_MAGIC 0x58414749/* 'XAGI' */ +#define XFS_AGFL_MAGIC 0x5841464c/* 'XAFL' */ #define XFS_AGF_VERSION 1#define XFS_AGI_VERSION 1@@ -190,11 +191,31 @@ extern const struct xfs_buf_ops xfs_agi_buf_ops;*/ #define XFS_AGFL_DADDR (mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))#define XFS_AGFL_BLOCK (mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp)) -#define XFS_AGFL_SIZE (mp) ((mp)->m_sb.sb_sectsize / sizeof(xfs_agblock_t))#define XFS_BUF_TO_AGFL (bp) ((xfs_agfl_t *)((bp)->b_addr)) +#define XFS_BUF_TO_AGFL_BNO (mp, bp) \ + (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ + &(XFS_BUF_TO_AGFL(bp)->agfl_bno[0]) : \ + (__be32 *)(bp)->b_addr) + +/* +* Size of the AGFL. For CRC-enabled filesystes we steal a couple of +* slots in the beginning of the block for a proper header with the +* location information and CRC.
fs/xfs/xfs_ag.h extern const struct xfs_buf_ops xfs_agi_buf_ops; · line 213
Quoted 10 lines
fs/xfs/xfs_ag.h +8
-1+*/ +#define XFS_AGFL_SIZE (mp) \ + (((mp)->m_sb.sb_sectsize - \ + (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ + sizeof(struct xfs_agfl) : 0)) / \ + sizeof(xfs_agblock_t)) + typedef struct xfs_agfl { - __be32 agfl_bno[1]; /* actually XFS_AGFL_SIZE(mp) */ + __be32 agfl_magicnum;
+ __be32 agfl_versionnum;
Now would be a good time to add this, and it would be consistent with the AGF and AGI structures. There is no shortage of agfl slots according to my calculation, and this might be helpful for xfsrepair later.
-Ben
fs/xfs/xfs_ag.h extern const struct xfs_buf_ops xfs_agi_buf_ops; · line 219
Quoted 6 lines
fs/xfs/xfs_ag.h +5
-0+__be32 agfl_seqno; +uuid_t agfl_uuid; +__be64 agfl_lsn; +__be32 agfl_crc; +__be32 agfl_bno[];/* actually XFS_AGFL_SIZE(mp) */ } xfs_agfl_t;
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 6/16 xfs: add CRC checks to the AGI
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
Same set of changes made to the AGF need to be made to the AGI. This patch has a similar history to the AGF, hence a similar sign-off chain.
--- fs/xfs/xfs_ag.h | 8 +++++++ fs/xfs/xfs_buf_item.h | 4 +++- fs/xfs/xfs_fsops.c | 3 +++ fs/xfs/xfs_ialloc.c | 57 ++++++++++++++++++++++++++++++++++------------ fs/xfs/xfs_log_recover.c | 8 +++++++ 5 files changed, 65 insertions(+), 15 deletions(-)
fs/xfs/xfs_ag.h +8 -0
@@ -152,6 +152,7 @@ typedef struct xfs_agi {__be32 agi_root;/* root of inode btree */ __be32 agi_level;/* levels in inode btree */ __be32 agi_freecount;/* number of free inodes */ +__be32 agi_newino;/* new inode just allocated */ __be32 agi_dirino;/* last directory inode chunk */ /*
@@ -159,6 +160,13 @@ typedef struct xfs_agi {* still being referenced. */ __be32 agi_unlinked[XFS_AGI_UNLINKED_BUCKETS ]; + +uuid_t agi_uuid;/* uuid of filesystem */ +__be32 agi_crc;/* crc of agi sector */ +__be32 agi_pad32; +__be64 agi_lsn;/* last write sequence */ + +/* structure must be padded to 64 bit alignment */ } xfs_agi_t;#define XFS_AGI_MAGICNUM 0x00000001
fs/xfs/xfs_buf_item.h +3 -1
@@ -47,6 +47,7 @@ extern kmem_zone_t *xfs_buf_item_zone;#define XFS_BLF_BTREE_BUF (1<<5)#define XFS_BLF_AGF_BUF (1<<6)#define XFS_BLF_AGFL_BUF (1<<7) +#define XFS_BLF_AGI_BUF (1<<8)#define XFS_BLF_TYPE_MASK \ (XFS_BLF_UDQUOT_BUF | \
@@ -54,7 +55,8 @@ extern kmem_zone_t *xfs_buf_item_zone; XFS_BLF_GDQUOT_BUF | \ XFS_BLF_BTREE_BUF | \ XFS_BLF_AGF_BUF | \ - XFS_BLF_AGFL_BUF) + XFS_BLF_AGFL_BUF | \ + XFS_BLF_AGI_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_fsops.c +3 -0
@@ -304,8 +304,11 @@ xfs_growfs_data_private( agi->agi_freecount =0 ; agi->agi_newino =cpu_to_be32 (NULLAGINO ); agi->agi_dirino =cpu_to_be32 (NULLAGINO ); +if (xfs_sb_version_hascrc (&mp->m_sb)) +uuid_copy (&agi->agi_uuid, &mp->m_sb.sb_uuid);for (bucket =0 ; bucket <XFS_AGI_UNLINKED_BUCKETS ; bucket++) agi->agi_unlinked[bucket] =cpu_to_be32 (NULLAGINO ); + error =xfs_bwrite (bp);xfs_buf_relse (bp);if (error)
fs/xfs/xfs_ialloc.c +43 -14
104 lines not on this page · raw message
fs/xfs/xfs_log_recover.c +8 -0
@@ -1972,6 +1972,14 @@ xlog_recover_do_reg_buffer( } bp->b_ops = &xfs_agfl_buf_ops;break ; +case XFS_BLF_AGI_BUF : +if (*(__be32 *)bp->b_addr !=cpu_to_be32 (XFS_AGI_MAGIC )) { +xfs_warn (mp,"Bad AGI block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_agi_buf_ops; +break ;default :break ; }
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 7/16 xfs: add CRC checks for quota blocks
In reply to Dave ChinnerFrom: Christoph Hellwig <[email protected]>
Use the reserved space in struct xfs_dqblk to store a UUID and a crc for the quota blocks.
[[email protected]] Add a LSN field and update for current verifier infrastructure.
--- fs/xfs/xfs_dquot.c | 112 ++++++++++++++++++++++++++++++++++++++++------ fs/xfs/xfs_log_recover.c | 10 +++++ fs/xfs/xfs_qm.c | 23 ++++++++-- fs/xfs/xfs_qm.h | 2 + fs/xfs/xfs_quota.h | 11 ++++- 5 files changed, 141 insertions(+), 17 deletions(-)
fs/xfs/xfs_dquot.c +99 -13
@@ -36,6 +36,7 @@#include "xfs_trans_space.h" #include "xfs_trans_priv.h" #include "xfs_qm.h" +#include "xfs_cksum.h" #include "xfs_trace.h" /*
@@ -239,6 +240,8 @@ xfs_qm_init_dquot_blk( d->dd_diskdq.d_version =XFS_DQUOT_VERSION ; d->dd_diskdq.d_id =cpu_to_be32 (curid); d->dd_diskdq.d_flags = type; +if (xfs_sb_version_hascrc (&mp->m_sb)) +uuid_copy (&d->dd_uuid, &mp->m_sb.sb_uuid); } xfs_trans_dquot_buf(tp, bp,
@@ -248,25 +251,87 @@ xfs_qm_init_dquot_blk(xfs_trans_log_buf (tp, bp,0 ,BBTOB (q->qi_dqchunklen) -1 ); } -static void +STATIC void +xfs_dquot_buf_calc_crc ( +struct xfs_mount *mp, +struct xfs_buf *bp) +{ +struct xfs_dqblk *d = (struct xfs_dqblk *)bp->b_addr; +int i; + +if (!xfs_sb_version_hascrc (&mp->m_sb)) +return ; + +for (i =0 ; i < mp->m_quotainfo->qi_dqperchunk; i++, d++) { +xfs_update_cksum ((char *)d,sizeof (struct xfs_dqblk ), + offsetof(struct xfs_dqblk , dd_crc)); + } +} + +STATIC bool +xfs_dquot_buf_verify_crc ( +struct xfs_mount *mp, +struct xfs_buf *bp) +{ +struct xfs_dqblk *d = (struct xfs_dqblk *)bp->b_addr; +int ndquots; +int i; + +if (!xfs_sb_version_hascrc (&mp->m_sb)) +return true; + +/* +* if we are in log recovery, the quota subsystem has not been +* initialised so we have no quotainfo structure. In that case, we need +* to manually calculate the number of dquots in the buffer. +*/ +if (mp->m_quotainfo) + ndquots = mp->m_quotainfo->qi_dqperchunk; +else + ndquots =xfs_qm_calc_dquots_per_chunk (mp, +XFS_BB_TO_FSB (mp, bp->b_length)); + +for (i =0 ; i < ndquots; i++, d++) { +if (!xfs_verify_cksum ((char *)d,sizeof (struct xfs_dqblk ), + offsetof(struct xfs_dqblk , dd_crc))) +return false; +if (!uuid_equal (&d->dd_uuid, &mp->m_sb.sb_uuid)) +return false; + } + +return true; +} + +STATIC boolxfs_dquot_buf_verify ( +struct xfs_mount *mp,struct xfs_buf *bp) { -struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_dqblk *d = (struct xfs_dqblk *)bp->b_addr; -struct xfs_disk_dquot *ddq;xfs_dqid_t id =0 ; +int ndquots;int i;/* +* if we are in log recovery, the quota subsystem has not been +* initialised so we have no quotainfo structure. In that case, we need +* to manually calculate the number of dquots in the buffer. +*/ +if (mp->m_quotainfo) + ndquots = mp->m_quotainfo->qi_dqperchunk; +else + ndquots =xfs_qm_calc_dquots_per_chunk (mp, bp->b_length); + +/* * On the first read of the buffer, verify that each dquot is valid. * We don't know what the id of the dquot is supposed to be, just that * they should be increasing monotonically within the buffer. If the * first id is corrupt, then it will fail on the second dquot in the * buffer so corruptions could point to the wrong dquot in this case. */ -for (i =0 ; i < mp->m_quotainfo->qi_dqperchunk; i++) { -int error; +for (i =0 ; i < ndquots; i++) { +struct xfs_disk_dquot *ddq; +int error; ddq = &d[i].dd_diskdq;
@@ -274,27 +339,37 @@ xfs_dquot_buf_verify( id =be32_to_cpu (ddq->d_id); error =xfs_qm_dqcheck (mp, ddq, id + i,0 ,XFS_QMOPT_DOWARN , -"xfs_dquot_read_verify" ); -if (error) { -XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, d); -xfs_buf_ioerror (bp,EFSCORRUPTED ); -break ; - } +"xfs_dquot_buf_verify" ); +if (error) +return false; } +return true; }static void xfs_dquot_buf_read_verify (struct xfs_buf *bp) { -xfs_dquot_buf_verify (bp); +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify_crc (mp, bp) || !xfs_dquot_buf_verify (mp, bp)) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, bp->b_addr); +xfs_buf_ioerror (bp,EFSCORRUPTED ); + } }void xfs_dquot_buf_write_verify (struct xfs_buf *bp) { -xfs_dquot_buf_verify (bp); +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify (mp, bp)) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, bp->b_addr); +xfs_buf_ioerror (bp,EFSCORRUPTED ); +return ; + } +xfs_dquot_buf_calc_crc (mp, bp); }const struct xfs_buf_ops xfs_dquot_buf_ops = {
@@ -1035,6 +1110,17 @@ xfs_qm_dqflush( &dqp->q_logitem.qli_item.li_lsn);/* +* copy the lsn into the on-disk dquot now while we have the in memory +* dquot here. This can't be done later in the write verifier as we +* can't get access to the log item at that point in time. +*/ +if (xfs_sb_version_hascrc (&mp->m_sb)) { +struct xfs_dqblk *dqb = (struct xfs_dqblk *)ddqp; + + dqb->dd_lsn =cpu_to_be64 (dqp->q_logitem.qli_item.li_lsn); + } + +/* * Attach an iodone routine so that we can remove this dquot from the * AIL and release the flush lock once the dquot is synced to disk. */
fs/xfs/xfs_log_recover.c +10 -0
@@ -1980,6 +1980,16 @@ xlog_recover_do_reg_buffer( } bp->b_ops = &xfs_agi_buf_ops;break ; +case XFS_BLF_UDQUOT_BUF : +case XFS_BLF_PDQUOT_BUF : +case XFS_BLF_GDQUOT_BUF : +if (*(__be16 *)bp->b_addr !=cpu_to_be16 (XFS_DQUOT_MAGIC )) { +xfs_warn (mp,"Bad DQUOT block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_dquot_buf_ops; +break ;default :break ; }
fs/xfs/xfs_qm.c +20 -3
@@ -617,6 +617,20 @@ xfs_qm_dqdetach( } } +int +xfs_qm_calc_dquots_per_chunk ( +struct xfs_mount *mp, +unsigned int nbblks)/* basic block units */ +{ +unsigned int ndquots; + +ASSERT (nbblks >0 ); + ndquots =BBTOB (nbblks); +do_div (ndquots,sizeof (xfs_dqblk_t)); + +return ndquots; +} +/* * This initializes all the quota information that's kept in the * mount structure
@@ -656,9 +670,8 @@ xfs_qm_init_quotainfo(/* Precalc some constants */ qinf->qi_dqchunklen =XFS_FSB_TO_BB (mp,XFS_DQUOT_CLUSTER_SIZE_FSB ); -ASSERT (qinf->qi_dqchunklen); - qinf->qi_dqperchunk =BBTOB (qinf->qi_dqchunklen); -do_div (qinf->qi_dqperchunk,sizeof (xfs_dqblk_t)); + qinf->qi_dqperchunk =xfs_qm_calc_dquots_per_chunk (mp, + qinf->qi_dqchunklen); mp->m_qflags |= (mp->m_sb.sb_qflags &XFS_ALL_QUOTA_CHKD );
@@ -897,6 +910,10 @@ xfs_qm_dqiter_bufs(if (error)break ; +/* +* XXX(hch): need to figure out if it makes sense to validate +* the CRC here. +*/ xfs_qm_reset_dqcounts (mp, bp, firstid, type);xfs_buf_delwri_queue (bp, buffer_list);xfs_buf_relse (bp);
fs/xfs/xfs_qm.h +2 -0
@@ -75,6 +75,8 @@ typedef struct xfs_quotainfo { &((qi)->qi_gquota_tree)) +extern int xfs_qm_calc_dquots_per_chunk (struct xfs_mount *mp, +unsigned int nbblks);extern void xfs_trans_mod_dquot (xfs_trans_t *,xfs_dquot_t *,uint ,long );extern int xfs_trans_reserve_quota_bydquots (xfs_trans_t *,xfs_mount_t *,xfs_dquot_t *,xfs_dquot_t *,long ,long ,uint );
fs/xfs/xfs_quota.h +10 -1
@@ -77,7 +77,14 @@ typedef struct xfs_disk_dquot {*/ typedef struct xfs_dqblk {xfs_disk_dquot_t dd_diskdq;/* portion that lives incore as well */ -char dd_fill[32 ];/* filling for posterity */ +char dd_fill[4 ];/* filling for posterity */ + +/* +* These two are only present on filesystems with the CRC bits set. +*/ +__be32 dd_crc;/* checksum */ +__be64 dd_lsn;/* last modification in log */ +uuid_t dd_uuid;/* location information */ }xfs_dqblk_t ;/*
@@ -380,5 +387,7 @@ extern int xfs_qm_dqcheck(struct xfs_mount *, xfs_disk_dquot_t *, xfs_dqid_t, uint, uint, char *);extern int xfs_mount_reset_sbqflags (struct xfs_mount *); +extern const struct xfs_buf_ops xfs_dquot_buf_ops; +#endif /* __KERNEL__ */ #endif /* __XFS_QUOTA_H__ */
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 07/16] xfs: add CRC checks for quota blocks
Hi Dave,
Quoted 10 lines · Dave Chinner
From: Christoph Hellwig <[email protected]>
Use the reserved space in struct
xfs_dqblkto store a UUID and a crc for the quota blocks.[[email protected]] Add a LSN field and update for current verifier infrastructure.
Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Dave Chinner <[email protected]>
Been over this and it looks fine.
fs/xfs/xfs_qm.c xfs_qm_dqiter_bufs( · line 916
Quoted 8 lines
fs/xfs/xfs_qm.c +4
-0@@ -897,6 +910,10 @@ xfs_qm_dqiter_bufs(if (error)break ; +/* +* XXX(hch): need to figure out if it makes sense to validate +* the CRC here. +*/
What's you're opinion on this?
-Ben
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 07/16] xfs: add CRC checks for quota blocks
Quoted 20 lines · Ben Myers
Hi Dave,
Quoted 10 lines · Dave Chinner
From: Christoph Hellwig <[email protected]>
Use the reserved space in struct
xfs_dqblkto store a UUID and a crc for the quota blocks.[[email protected]] Add a LSN field and update for current verifier infrastructure.
Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Dave Chinner <[email protected]>Been over this and it looks fine.
Quoted 4 lines
fs/xfs/xfs_qm.c +0
-0@@ -897,6 +910,10 @@ xfs_qm_dqiter_bufs(if (error)break ;
Quoted 6 lines
fs/xfs/xfs_qm.c xfs_qm_dqiter_bufs( · line 916
Quoted 4 lines
fs/xfs/xfs_qm.c +4
-0+/* +* XXX(hch): need to figure out if it makes sense to validate +* the CRC here. +*/ What's you're opinion on this?
I did actually change the code to validate the CRC here via the call to xfs_trans_read_buf(.... &xfs_dquot_buf_ops) above. i.e. the read verifier will do CRC validation of the buffer.
The comment is still relevant, however, because it's not exactly clear what the best approach to do here if we get a CRC failure. That would indicate some kind of corruption that we weren't expecting, and quite possibly a corruption that rewriting the dquot can't fix. So without knowing what kind of corruption is typical here, I don't know what the best approach to take here is.
So effectively what I've done is add CRC validation so that we'll get people telling us about problems (because the quotacheck will abort and there will be a stack trace in the log). If it turns out that corrupted quota files is a common problem that quotacheck encounters we can gather the corpses, do post-mortem analysis of the failures and then revisit the code appropriately with that knowledge in hand.
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 8/16 xfs: add version 3 inode format with CRCs
In reply to Dave ChinnerFrom: Christoph Hellwig <[email protected]>
Add a new inode version with a larger core. The primary objective is to allow for a crc of the inode, and location information (uuid and ino) to verify it was written in the right place. We also extend it by:
a creation time (for Samba); a changecount (for NFSv4); a flush sequence (in LSN format for recovery); an additional inode flags field; and some additional padding.
These additional fields are not implemented yet, but already laid out in the structure.
[[email protected]] Added LSN and flags field, some factoring and rework to capture all the necessary information in the crc calculation.
--- fs/xfs/xfs_buf_item.h | 4 +- fs/xfs/xfs_dinode.h | 33 +++++++-- fs/xfs/xfs_ialloc.c | 23 +++++- fs/xfs/xfs_inode.c | 179 ++++++++++++++++++++++++++++++++-------------- fs/xfs/xfs_inode.h | 26 +++++++ fs/xfs/xfs_inode_item.c | 2 +- fs/xfs/xfs_log_recover.c | 35 +++++++-- fs/xfs/xfs_trans_buf.c | 5 +- 8 files changed, 237 insertions(+), 70 deletions(-)
fs/xfs/xfs_buf_item.h +3 -1
@@ -48,6 +48,7 @@ extern kmem_zone_t *xfs_buf_item_zone;#define XFS_BLF_AGF_BUF (1<<6)#define XFS_BLF_AGFL_BUF (1<<7)#define XFS_BLF_AGI_BUF (1<<8) +#define XFS_BLF_DINO_BUF (1<<9)#define XFS_BLF_TYPE_MASK \ (XFS_BLF_UDQUOT_BUF | \
@@ -56,7 +57,8 @@ extern kmem_zone_t *xfs_buf_item_zone; XFS_BLF_BTREE_BUF | \ XFS_BLF_AGF_BUF | \ XFS_BLF_AGFL_BUF | \ - XFS_BLF_AGI_BUF) + XFS_BLF_AGI_BUF | \ + XFS_BLF_DINO_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_dinode.h +29 -4
@@ -19,7 +19,7 @@#define __XFS_DINODE_H__#define XFS_DINODE_MAGIC 0x494e/* 'IN' */ -#define XFS_DINODE_GOOD_VERSION (v) (((v) == 1 || (v) == 2)) +#define XFS_DINODE_GOOD_VERSION (v) ((v) >= 1 && (v) <= 3) typedef struct xfs_timestamp { __be32 t_sec; /* timestamp seconds */
@@ -70,11 +70,36 @@ typedef struct xfs_dinode {/* di_next_unlinked is the only non-core field in the old dinode */ __be32 di_next_unlinked;/* agi unlinked list ptr */ -} __attribute__((packed)) xfs_dinode_t; + +/* start of the extended dinode, writable fields */ +__be32 di_crc;/* CRC of the inode */ +__be64 di_changecount;/* number of attribute changes */ +__be64 di_lsn;/* flush sequence */ +__be64 di_flags2;/* more random flags */ +__u8 di_pad2[16 ];/* more padding for future expansion */ + +/* fields only written to during inode creation */ +xfs_timestamp_t di_crtime;/* time created */ +__be64 di_ino;/* inode number */ +uuid_t di_uuid;/* UUID of the filesystem */ + +/* structure must be padded to 64 bit alignment */ +} xfs_dinode_t;#define DI_MAX_FLUSH 0xffff/* +* Size of the core inode on disk. Version 1 and 2 inodes have +* the same size, but version 3 has grown a few additional fields. +*/ +static inline uint xfs_dinode_size (int version) +{ +if (version ==3 ) +return sizeof (struct xfs_dinode ); +return offsetof(struct xfs_dinode , di_crc); +} + +/* * The 32 bit link count in the inode theoretically maxes out at UINT_MAX. * Since the pathconf interface is signed, we use 2^31 - 1 instead. * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
@@ -105,7 +130,7 @@ typedef enum xfs_dinode_fmt {* Inode size for given fs. */ #define XFS_LITINO (mp, version) \ - ((int)(((mp)->m_sb.sb_inodesize) - sizeof(struct xfs_dinode))) + ((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version)))#define XFS_BROOT_SIZE_ADJ (ip) \ (XFS_BMBT_BLOCK_LEN((ip)->i_mount) - sizeof(xfs_bmdr_block_t))
@@ -133,7 +158,7 @@ typedef enum xfs_dinode_fmt {* Return pointers to the data or attribute forks. */ #define XFS_DFORK_DPTR (dip) \ - ((char *)(dip) + sizeof(struct xfs_dinode)) + ((char *)dip + xfs_dinode_size(dip->di_version))#define XFS_DFORK_APTR (dip) \ (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip))#define XFS_DFORK_PTR (dip,w) \
fs/xfs/xfs_ialloc.c +21 -2
@@ -167,6 +167,7 @@ xfs_ialloc_inode_init(int version;int i, j;xfs_daddr_t d; +xfs_ino_t ino =0 ;/* * Loop over the new block(s), filling in the inodes.
@@ -190,8 +191,18 @@ xfs_ialloc_inode_init(* the new inode format, then use the new inode version. Otherwise * use the old version so that old kernels will continue to be * able to use the file system. +* +* For v3 inodes, we also need to write the inode number into the inode, +* so calculate the first inode number of the chunk here as +* XFS_OFFBNO_TO_AGINO() only works on filesystem block boundaries, not +* cluster boundaries and so cannot be used in the cluster buffer loop +* below. */ -if (xfs_sb_version_hasnlink (&mp->m_sb)) +if (xfs_sb_version_hascrc (&mp->m_sb)) { + version =3 ; + ino =XFS_AGINO_TO_INO (mp, agno, +XFS_OFFBNO_TO_AGINO (mp, agbno,0 )); + }else if (xfs_sb_version_hasnlink (&mp->m_sb)) version =2 ;else version =1 ;
@@ -217,13 +228,21 @@ xfs_ialloc_inode_init(xfs_buf_zero (fbuf,0 , ninodes << mp->m_sb.sb_inodelog);for (i =0 ; i < ninodes; i++) {int ioffset = i << mp->m_sb.sb_inodelog; -uint isize =sizeof (struct xfs_dinode ); +uint isize =xfs_dinode_size (version); free =xfs_make_iptr (mp, fbuf, i); free->di_magic =cpu_to_be16 (XFS_DINODE_MAGIC ); free->di_version = version; free->di_gen =cpu_to_be32 (gen); free->di_next_unlinked =cpu_to_be32 (NULLAGINO ); + +if (version ==3 ) { + free->di_ino =cpu_to_be64 (ino); + ino++; +uuid_copy (&free->di_uuid, &mp->m_sb.sb_uuid); +xfs_dinode_calc_crc (mp, free); + } +xfs_trans_log_buf (tp, fbuf, ioffset, ioffset + isize -1 ); }xfs_trans_inode_alloc_buf (tp, fbuf);
fs/xfs/xfs_inode.c +125 -54
272 lines not on this page · raw message
fs/xfs/xfs_inode.h +26 -0
@@ -150,13 +150,38 @@ typedef struct xfs_icdinode {__uint16_t di_dmstate;/* DMIG state info */ __uint16_t di_flags;/* random flags, XFS_DIFLAG_... */ __uint32_t di_gen;/* generation number */ + +/* di_next_unlinked is the only non-core field in the old dinode */ +xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */ + +/* start of the extended dinode, writable fields */ +__uint32_t di_crc;/* CRC of the inode */ +__uint64_t di_changecount;/* number of attribute changes */ +xfs_lsn_t di_lsn;/* flush sequence */ +__uint64_t di_flags2;/* more random flags */ +__uint8_t di_pad2[16 ];/* more padding for future expansion */ + +/* fields only written to during inode creation */ +xfs_ictimestamp_t di_crtime;/* time created */ +xfs_ino_t di_ino;/* inode number */ +uuid_t di_uuid;/* UUID of the filesystem */ + +/* structure must be padded to 64 bit alignment */ } xfs_icdinode_t; +static inline uint xfs_icdinode_size (int version) +{ +if (version ==3 ) +return sizeof (struct xfs_icdinode ); +return offsetof(struct xfs_icdinode , di_next_unlinked); +} +/* * Flags for xfs_ichgtime(). */ #define XFS_ICHGTIME_MOD 0x1/* data fork modification timestamp */ #define XFS_ICHGTIME_CHG 0x2/* inode field change timestamp */ +#define XFS_ICHGTIME_CREATE 0x4/* inode create timestamp */ /* * Per-fork incore inode flags.
@@ -556,6 +581,7 @@ int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *, struct xfs_buf **, uint, uint);int xfs_iread (struct xfs_mount *,struct xfs_trans *,struct xfs_inode *,uint ); +void xfs_dinode_calc_crc (struct xfs_mount *,struct xfs_dinode *);void xfs_dinode_to_disk (struct xfs_dinode *,struct xfs_icdinode *);void xfs_idestroy_fork (struct xfs_inode *,int );
fs/xfs/xfs_inode_item.c +1 -1
@@ -179,7 +179,7 @@ xfs_inode_item_format( nvecs =1 ; vecp->i_addr = &ip->i_d; - vecp->i_len =sizeof (struct xfs_icdinode ); + vecp->i_len =xfs_icdinode_size (ip->i_d.di_version); vecp->i_type =XLOG_REG_TYPE_ICORE ; vecp++; nvecs++;
fs/xfs/xfs_log_recover.c +28 -7
@@ -1787,6 +1787,7 @@ xlog_recover_do_inode_buffer(xfs_agino_t *buffer_nextp;trace_xfs_log_recover_buf_inode_buf (mp->m_log, buf_f); + bp->b_ops = &xfs_inode_buf_ops; inodes_per_buf =BBTOB (bp->b_io_length) >> mp->m_sb.sb_inodelog;for (i =0 ; i < inodes_per_buf; i++) {
@@ -1931,6 +1932,9 @@ xlog_recover_do_reg_buffer(/* Shouldn't be any more regions */ ASSERT (i == item->ri_total); +/* Shouldn't be any more regions */ +ASSERT (i == item->ri_total); +switch (buf_f->blf_flags &XFS_BLF_TYPE_MASK ) {case XFS_BLF_BTREE_BUF :switch (be32_to_cpu (*(__be32 *)bp->b_addr)) {
@@ -1990,6 +1994,18 @@ xlog_recover_do_reg_buffer( } bp->b_ops = &xfs_dquot_buf_ops;break ; +case XFS_BLF_DINO_BUF : +/* +* we get here with inode allocation buffers, not buffers that +* track unlinked list changes. +*/ +if (*(__be16 *)bp->b_addr !=cpu_to_be16 (XFS_DINODE_MAGIC )) { +xfs_warn (mp,"Bad INODE block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_inode_buf_ops; +break ;default :break ; }
@@ -2278,6 +2294,7 @@ xlog_recover_inode_pass2(int attr_index;uint fields;xfs_icdinode_t *dicp; +uint isize;int need_free =0 ;if (item->ri_buf[0 ].i_len ==sizeof (xfs_inode_log_format_t)) {
@@ -2303,7 +2320,7 @@ xlog_recover_inode_pass2(trace_xfs_log_recover_inode_recover (log, in_f); bp =xfs_buf_read (mp->m_ddev_targp, in_f->ilf_blkno, in_f->ilf_len,0 , -NULL ); + &xfs_inode_buf_ops);if (!bp) { error =ENOMEM ; goto error;
@@ -2414,7 +2431,8 @@ xlog_recover_inode_pass2( error =EFSCORRUPTED ; goto error; } -if (unlikely (item->ri_buf[1 ].i_len >sizeof (struct xfs_icdinode ))) { + isize =xfs_icdinode_size (dicp->di_version); +if (unlikely (item->ri_buf[1 ].i_len > isize)) {XFS_CORRUPTION_ERROR ("xlog_recover_inode_pass2(7)" ,XFS_ERRLEVEL_LOW , mp, dicp);xfs_buf_relse (bp);
@@ -2426,13 +2444,13 @@ xlog_recover_inode_pass2( }/* The core is in in-core format */ -xfs_dinode_to_disk (dip, item->ri_buf[1 ].i_addr); +xfs_dinode_to_disk (dip, dicp);/* the rest is in on-disk format */ -if (item->ri_buf[1 ].i_len >sizeof (struct xfs_icdinode )) { -memcpy ((xfs_caddr_t ) dip +sizeof (struct xfs_icdinode ), - item->ri_buf[1 ].i_addr +sizeof (struct xfs_icdinode ), - item->ri_buf[1 ].i_len -sizeof (struct xfs_icdinode )); +if (item->ri_buf[1 ].i_len > isize) { +memcpy ((char *)dip + isize, + item->ri_buf[1 ].i_addr + isize, + item->ri_buf[1 ].i_len - isize); } fields = in_f->ilf_fields;
@@ -2516,6 +2534,9 @@ xlog_recover_inode_pass2( } write_inode_buffer: +/* re-generate the checksum. */ +xfs_dinode_calc_crc (log->l_mp, dip); +ASSERT (bp->b_target->bt_mount == mp); bp->b_iodone = xlog_recover_iodone;xfs_buf_delwri_queue (bp, buffer_list);
fs/xfs/xfs_trans_buf.c +4 -1
@@ -704,12 +704,13 @@ xfs_trans_inode_buf(ASSERT (atomic_read (&bip->bli_refcount) >0 ); bip->bli_flags |=XFS_BLI_INODE_BUF ; +xfs_trans_buf_set_type (tp, bp,XFS_BLF_DINO_BUF ); }/* * This call is used to indicate that the buffer is going to * be staled and was an inode buffer. This means it gets -* special processing during unpin - where any inodes +* special processing during unpin - where any inodes * associated with the buffer should be removed from ail. * There is also special processing during recovery, * any replay of the inodes in the buffer needs to be
@@ -728,6 +729,7 @@ xfs_trans_stale_inode_buf( bip->bli_flags |=XFS_BLI_STALE_INODE ; bip->bli_item.li_cb = xfs_buf_iodone; +xfs_trans_buf_set_type (tp, bp,XFS_BLF_DINO_BUF ); }/*
@@ -751,6 +753,7 @@ xfs_trans_inode_alloc_buf(ASSERT (atomic_read (&bip->bli_refcount) >0 ); bip->bli_flags |=XFS_BLI_INODE_ALLOC_BUF ; +xfs_trans_buf_set_type (tp, bp,XFS_BLF_DINO_BUF ); }/*
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 9/16 xfs: add CRC checks to remote symlinks
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
Add a header to the remote symlink block, containing location and owner information, as well as CRCs and LSN fields. This requires verifiers to be added to the remote symlink buffers for CRC enabled filesystems.
This also fixes a bug reading multiple block symlinks, where the second block overwrites the first block when copying out the link name.
--- fs/xfs/Makefile | 5 +- fs/xfs/xfs_bmap.c | 21 +- fs/xfs/xfs_buf_item.h | 4 +- fs/xfs/xfs_log_recover.c | 9 + fs/xfs/xfs_vnodeops.c | 480 +--------------------------------------------- 5 files changed, 25 insertions(+), 494 deletions(-)
fs/xfs/Makefile +3 -2
@@ -45,11 +45,11 @@ xfs-y += xfs_aops.o \ xfs_itable.o \ xfs_message.o \ xfs_mru_cache.o \ - xfs_super.o \ - xfs_xattr.o \ xfs_rename.o \ + xfs_super.o \ xfs_utils.o \ xfs_vnodeops.o \ + xfs_xattr.o \ kmem.o \ uuid.o
@@ -73,6 +73,7 @@ xfs-y += xfs_alloc.o \ xfs_inode.o \ xfs_log_recover.o \ xfs_mount.o \ + xfs_symlink.o \ xfs_trans.o # low-level transaction/log code
fs/xfs/xfs_bmap.c +6 -15
@@ -47,6 +47,7 @@#include "xfs_filestream.h" #include "xfs_vnodeops.h" #include "xfs_trace.h" +#include "xfs_symlink.h" kmem_zone_t *xfs_bmap_free_item_zone;
@@ -1321,9 +1322,10 @@ xfs_bmap_add_attrfork_extents( }/* -* Block initialisation functions for local to extent format conversion. -* As these get more complex, they will be moved to the relevant files, -* but for now they are too simple to worry about. +* Block initialisation function for local to extent format conversion. +* +* This shouldn't actually be called by anyone, so make sure debug kernels cause +* a noticable failure. */ STATIC void xfs_bmap_local_to_extents_init_fn(
@@ -1332,23 +1334,12 @@ xfs_bmap_local_to_extents_init_fn(struct xfs_inode *ip, struct xfs_ifork *ifp) { + ASSERT(0); bp->b_ops = &xfs_bmbt_buf_ops;memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes);xfs_trans_buf_set_type (tp, bp,XFS_BLF_BTREE_BUF ); } -STATIC void -xfs_symlink_local_to_remote ( -struct xfs_trans *tp, -struct xfs_buf *bp, -struct xfs_inode *ip, -struct xfs_ifork *ifp) -{ -/* remote symlink blocks are not verifiable until CRCs come along */ - bp->b_ops =NULL ; -memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes); -} -/* * Called from xfs_bmap_add_attrfork to handle local format files. Each * different data fork content type needs a different callout to do the
fs/xfs/xfs_buf_item.h +3 -1
@@ -49,6 +49,7 @@ extern kmem_zone_t *xfs_buf_item_zone;#define XFS_BLF_AGFL_BUF (1<<7)#define XFS_BLF_AGI_BUF (1<<8)#define XFS_BLF_DINO_BUF (1<<9) +#define XFS_BLF_SYMLINK_BUF (1<<10)#define XFS_BLF_TYPE_MASK \ (XFS_BLF_UDQUOT_BUF | \
@@ -58,7 +59,8 @@ extern kmem_zone_t *xfs_buf_item_zone; XFS_BLF_AGF_BUF | \ XFS_BLF_AGFL_BUF | \ XFS_BLF_AGI_BUF | \ - XFS_BLF_DINO_BUF) + XFS_BLF_DINO_BUF | \ + XFS_BLF_SYMLINK_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_log_recover.c +9 -0
@@ -45,6 +45,7 @@#include "xfs_cksum.h" #include "xfs_trace.h" #include "xfs_icache.h" +#include "xfs_symlink.h" STATIC int xlog_find_zeroed(
@@ -2006,6 +2007,14 @@ xlog_recover_do_reg_buffer( } bp->b_ops = &xfs_inode_buf_ops;break ; +case XFS_BLF_SYMLINK_BUF : +if (*(__be32 *)bp->b_addr !=cpu_to_be32 (XFS_SYMLINK_MAGIC )) { +xfs_warn (mp,"Bad symlink block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_symlink_buf_ops; +break ;default :break ; }
fs/xfs/xfs_vnodeops.c +4 -476
504 lines not on this page · raw message
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH 09/16] xfs: add CRC checks to remote symlinks
Quoted 10 lines · Dave Chinner
From: Dave Chinner <[email protected]>
Add a header to the remote symlink block, containing location and owner information, as well as CRCs and LSN fields. This requires verifiers to be added to the remote symlink buffers for CRC enabled filesystems.
This also fixes a bug reading multiple block symlinks, where the second block overwrites the first block when copying out the link name.
Quoted 8 lines
Signed-off-by Dave Chinner <[email protected]>--- fs/xfs/Makefile | 5 +- fs/xfs/xfs_bmap.c | 21 +- fs/xfs/xfs_buf_item.h | 4 +- fs/xfs/xfs_log_recover.c | 9 + fs/xfs/xfs_vnodeops.c | 480 +--------------------------------------------- 5 files changed, 25 insertions(+), 494 deletions(-)
I just noticed this is missing two new files (insert grumble about guilt forgetting added files when a patch is force applied because of conflicts).
The correct version is below (diffstat += 770 lines)...
-Dave.
Signature · 25 lines
Dave Chinner [email protected] xfs: add CRC checks to remote symlinks From: Dave Chinner <[email protected]> Add a header to the remote symlink block, containing location and owner information, as well as CRCs and LSN fields. This requires verifiers to be added to the remote symlink buffers for CRC enabled filesystems. This also fixes a bug reading multiple block symlinks, where the second block overwrites the first block when copying out the link name. Signed-off-by: Dave Chinner <[email protected]> --- fs/xfs/Makefile | 5 +- fs/xfs/xfs_bmap.c | 21 +- fs/xfs/xfs_buf_item.h | 4 +- fs/xfs/xfs_log_recover.c | 9 + fs/xfs/xfs_symlink.c | 719 ++++++++++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_symlink.h | 53 ++++ fs/xfs/xfs_vnodeops.c | 480 +------------------------------ 7 files changed, 797 insertions(+), 494 deletions(-)
fs/xfs/Makefile +3 -2
@@ -45,11 +45,11 @@ xfs-y += xfs_aops.o \ xfs_itable.o \ xfs_message.o \ xfs_mru_cache.o \ - xfs_super.o \ - xfs_xattr.o \ xfs_rename.o \ + xfs_super.o \ xfs_utils.o \ xfs_vnodeops.o \ + xfs_xattr.o \ kmem.o \ uuid.o
@@ -73,6 +73,7 @@ xfs-y += xfs_alloc.o \ xfs_inode.o \ xfs_log_recover.o \ xfs_mount.o \ + xfs_symlink.o \ xfs_trans.o # low-level transaction/log code
fs/xfs/xfs_bmap.c +6 -15
@@ -47,6 +47,7 @@#include "xfs_filestream.h" #include "xfs_vnodeops.h" #include "xfs_trace.h" +#include "xfs_symlink.h" kmem_zone_t *xfs_bmap_free_item_zone;
@@ -1321,9 +1322,10 @@ xfs_bmap_add_attrfork_extents( }/* -* Block initialisation functions for local to extent format conversion. -* As these get more complex, they will be moved to the relevant files, -* but for now they are too simple to worry about. +* Block initialisation function for local to extent format conversion. +* +* This shouldn't actually be called by anyone, so make sure debug kernels cause +* a noticable failure. */ STATIC void xfs_bmap_local_to_extents_init_fn(
@@ -1332,23 +1334,12 @@ xfs_bmap_local_to_extents_init_fn(struct xfs_inode *ip, struct xfs_ifork *ifp) { + ASSERT(0); bp->b_ops = &xfs_bmbt_buf_ops;memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes);xfs_trans_buf_set_type (tp, bp,XFS_BLF_BTREE_BUF ); } -STATIC void -xfs_symlink_local_to_remote ( -struct xfs_trans *tp, -struct xfs_buf *bp, -struct xfs_inode *ip, -struct xfs_ifork *ifp) -{ -/* remote symlink blocks are not verifiable until CRCs come along */ - bp->b_ops =NULL ; -memcpy (bp->b_addr, ifp->if_u1.if_data, ifp->if_bytes); -} -/* * Called from xfs_bmap_add_attrfork to handle local format files. Each * different data fork content type needs a different callout to do the
fs/xfs/xfs_buf_item.h +3 -1
@@ -49,6 +49,7 @@ extern kmem_zone_t *xfs_buf_item_zone;#define XFS_BLF_AGFL_BUF (1<<7)#define XFS_BLF_AGI_BUF (1<<8)#define XFS_BLF_DINO_BUF (1<<9) +#define XFS_BLF_SYMLINK_BUF (1<<10)#define XFS_BLF_TYPE_MASK \ (XFS_BLF_UDQUOT_BUF | \
@@ -58,7 +59,8 @@ extern kmem_zone_t *xfs_buf_item_zone; XFS_BLF_AGF_BUF | \ XFS_BLF_AGFL_BUF | \ XFS_BLF_AGI_BUF | \ - XFS_BLF_DINO_BUF) + XFS_BLF_DINO_BUF | \ + XFS_BLF_SYMLINK_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_log_recover.c +9 -0
@@ -45,6 +45,7 @@#include "xfs_cksum.h" #include "xfs_trace.h" #include "xfs_icache.h" +#include "xfs_symlink.h" STATIC int xlog_find_zeroed(
@@ -2006,6 +2007,14 @@ xlog_recover_do_reg_buffer( } bp->b_ops = &xfs_inode_buf_ops;break ; +case XFS_BLF_SYMLINK_BUF : +if (*(__be32 *)bp->b_addr !=cpu_to_be32 (XFS_SYMLINK_MAGIC )) { +xfs_warn (mp,"Bad symlink block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_symlink_buf_ops; +break ;default :break ; }
fs/xfs/xfs_symlink.c new file +719 -0
719 lines not on this page · raw message
fs/xfs/xfs_symlink.h new file +53 -0
53 lines not on this page · raw message
fs/xfs/xfs_vnodeops.c +4 -476
504 lines not on this page · raw message
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH 10/16 xfs: add CRC checks to block format directory blocks
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
Now that directory buffers are made from a single struct xfs_buf, we can add CRC calculation and checking callbacks. While there, add all the fields to the on disk structures for future functionality such as d_type support, uuids, block numbers, owner inode, etc.
To distinguish between the different on disk formats, change the magic numbers for the new format directory blocks.
--- fs/xfs/xfs_dir2_block.c | 124 +++++++++++++++++++++++++----------- fs/xfs/xfs_dir2_data.c | 157 ++++++++++++++++++++++++++++------------------ fs/xfs/xfs_dir2_format.h | 134 +++++++++++++++++++++++++++++++++++++++ fs/xfs/xfs_dir2_leaf.c | 6 +- fs/xfs/xfs_dir2_node.c | 2 +- fs/xfs/xfs_dir2_priv.h | 4 +- fs/xfs/xfs_log_recover.c | 2 + 7 files changed, 327 insertions(+), 102 deletions(-)
fs/xfs/xfs_dir2_block.c +88 -36
@@ -28,11 +28,13 @@#include "xfs_dinode.h" #include "xfs_inode.h" #include "xfs_inode_item.h" +#include "xfs_buf_item.h" #include "xfs_dir2.h" #include "xfs_dir2_format.h" #include "xfs_dir2_priv.h" #include "xfs_error.h" #include "xfs_trace.h" +#include "xfs_cksum.h" /* * Local function prototypes.
@@ -56,44 +58,74 @@ xfs_dir_startup(void) xfs_dir_hash_dotdot =xfs_da_hashname ((unsigned char *)".." ,2 ); } -static void -xfs_dir2_block_verify ( +static bool +xfs_dir3_block_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; -struct xfs_dir2_data_hdr *hdr = bp->b_addr; -int block_ok =0 ; - - block_ok = hdr->magic ==cpu_to_be32 (XFS_DIR2_BLOCK_MAGIC ); - block_ok = block_ok &&__xfs_dir2_data_check (NULL , bp) ==0 ; - -if (!block_ok) { -XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, hdr); -xfs_buf_ioerror (bp,EFSCORRUPTED ); +struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; + +if (xfs_sb_version_hascrc (&mp->m_sb)) { +if (hdr3->magic !=be32_to_cpu (XFS_DIR3_BLOCK_MAGIC )) +return false; +if (!uuid_equal (&hdr3->uuid, &mp->m_sb.sb_uuid)) +return false; +if (be64_to_cpu (hdr3->blkno) != bp->b_bn) +return false; + }else { +if (hdr3->magic !=be32_to_cpu (XFS_DIR2_BLOCK_MAGIC )) +return false; } +if (__xfs_dir2_data_check (NULL , bp)) +return false; +return true; }static void -xfs_dir2_block_read_verify ( +xfs_dir3_block_read_verify (struct xfs_buf *bp) { -xfs_dir2_block_verify (bp); +struct xfs_mount *mp = bp->b_target->bt_mount; + +if ((xfs_sb_version_hascrc (&mp->m_sb) && + !xfs_verify_cksum (bp->b_addr,BBTOB (bp->b_length), +XFS_DIR3_DATA_CRC_OFF )) || + !xfs_dir3_block_verify (bp)) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, bp->b_addr); +xfs_buf_ioerror (bp,EFSCORRUPTED ); + } }static void -xfs_dir2_block_write_verify ( +xfs_dir3_block_write_verify (struct xfs_buf *bp) { -xfs_dir2_block_verify (bp); +struct xfs_mount *mp = bp->b_target->bt_mount; +struct xfs_buf_log_item *bip = bp->b_fspriv; +struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; + +if (!xfs_dir3_block_verify (bp)) { +XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, bp->b_addr); +xfs_buf_ioerror (bp,EFSCORRUPTED ); +return ; + } + +if (!xfs_sb_version_hascrc (&mp->m_sb)) +return ; + +if (bip) + hdr3->lsn =cpu_to_be64 (bip->bli_item.li_lsn); + +xfs_update_cksum (bp->b_addr,BBTOB (bp->b_length),XFS_DIR3_DATA_CRC_OFF ); } -const struct xfs_buf_ops xfs_dir2_block_buf_ops = { - .verify_read = xfs_dir2_block_read_verify, - .verify_write = xfs_dir2_block_write_verify, +const struct xfs_buf_ops xfs_dir3_block_buf_ops = { + .verify_read = xfs_dir3_block_read_verify, + .verify_write = xfs_dir3_block_write_verify, };static int -xfs_dir2_block_read ( +xfs_dir3_block_read (struct xfs_trans *tp,struct xfs_inode *dp,struct xfs_buf **bpp)
@@ -101,7 +133,29 @@ xfs_dir2_block_read(struct xfs_mount *mp = dp->i_mount;return xfs_da_read_buf (tp, dp, mp->m_dirdatablk,-1 , bpp, -XFS_DATA_FORK , &xfs_dir2_block_buf_ops); +XFS_DATA_FORK , &xfs_dir3_block_buf_ops); +} + +static void +xfs_dir3_block_init ( +struct xfs_mount *mp, +struct xfs_buf *bp, +struct xfs_inode *dp) +{ +struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; + + bp->b_ops = &xfs_dir3_block_buf_ops; + +if (xfs_sb_version_hascrc (&mp->m_sb)) { +memset (hdr3,0 ,sizeof (*hdr3)); + hdr3->magic =cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC ); + hdr3->blkno =cpu_to_be64 (bp->b_bn); + hdr3->owner =cpu_to_be64 (dp->i_ino); +uuid_copy (&hdr3->uuid, &mp->m_sb.sb_uuid); +return ; + + } + hdr3->magic =cpu_to_be32 (XFS_DIR2_BLOCK_MAGIC ); } static void
@@ -121,7 +175,7 @@ xfs_dir2_block_need_space(struct xfs_dir2_data_unused *enddup =NULL ; *compact =0 ; - bf = hdr->bestfree; + bf =xfs_dir3_data_bestfree_p (hdr);/* * If there are stale entries we'll use one for the leaf.
@@ -303,7 +357,7 @@ xfs_dir2_block_addname( mp = dp->i_mount;/* Read the (one and only) directory block into bp. */ - error =xfs_dir2_block_read (tp, dp, &bp); + error =xfs_dir3_block_read (tp, dp, &bp);if (error)return error;
@@ -531,7 +585,7 @@ xfs_dir2_block_getdents(if (xfs_dir2_dataptr_to_db (mp, *offset) > mp->m_dirdatablk)return 0 ; - error =xfs_dir2_block_read (NULL , dp, &bp); + error =xfs_dir3_block_read (NULL , dp, &bp);if (error)return error;
@@ -711,7 +765,7 @@ xfs_dir2_block_lookup_int( tp = args->trans; mp = dp->i_mount; - error =xfs_dir2_block_read (tp, dp, &bp); + error =xfs_dir3_block_read (tp, dp, &bp);if (error)return error;
@@ -1014,8 +1068,8 @@ xfs_dir2_leaf_to_block(/* * Start converting it to block form. */ - dbp->b_ops = &xfs_dir2_block_buf_ops; - hdr->magic =cpu_to_be32 (XFS_DIR2_BLOCK_MAGIC ); +xfs_dir3_block_init (mp, dbp, dp); + needlog =1 ; needscan =0 ;/*
@@ -1137,16 +1191,16 @@ xfs_dir2_sf_to_block(return error; }/* -* Initialize the data block. +* Initialize the data block, then convert it to block format. */ - error =xfs_dir2_data_init (args, blkno, &bp); + error =xfs_dir3_data_init (args, blkno, &bp);if (error) {kmem_free (sfp);return error; } - bp->b_ops = &xfs_dir2_block_buf_ops; +xfs_dir3_block_init (mp, bp, dp); hdr = bp->b_addr; - hdr->magic =cpu_to_be32 (XFS_DIR2_BLOCK_MAGIC ); +/* * Compute size of block "tail" area. */
@@ -1156,7 +1210,7 @@ xfs_dir2_sf_to_block(* The whole thing is initialized to free by the init routine. * Say we're using the leaf and tail area. */ - dup = (xfs_dir2_data_unused_t *)(hdr +1 ); + dup =xfs_dir3_data_unused_p (hdr); needlog = needscan =0 ;xfs_dir2_data_use_free (tp, bp, dup, mp->m_dirblksize - i, i, &needlog, &needscan);
@@ -1178,8 +1232,7 @@ xfs_dir2_sf_to_block(/* * Create entry for . */ - dep = (xfs_dir2_data_entry_t *) - ((char *)hdr +XFS_DIR2_DATA_DOT_OFFSET ); + dep =xfs_dir3_data_dot_entry_p (hdr); dep->inumber =cpu_to_be64 (dp->i_ino); dep->namelen =1 ; dep->name[0 ] ='.' ;
@@ -1192,8 +1245,7 @@ xfs_dir2_sf_to_block(/* * Create entry for .. */ - dep = (xfs_dir2_data_entry_t *) - ((char *)hdr +XFS_DIR2_DATA_DOTDOT_OFFSET ); + dep =xfs_dir3_data_dotdot_entry_p (hdr); dep->inumber =cpu_to_be64 (xfs_dir2_sf_get_parent_ino (sfp)); dep->namelen =2 ; dep->name[0 ] = dep->name[1 ] ='.' ;
@@ -1203,7 +1255,7 @@ xfs_dir2_sf_to_block( blp[1 ].hashval =cpu_to_be32 (xfs_dir_hash_dotdot); blp[1 ].address =cpu_to_be32 (xfs_dir2_byte_to_dataptr (mp, (char *)dep - (char *)hdr)); - offset =XFS_DIR2_DATA_FIRST_OFFSET ; + offset =xfs_dir3_data_first_offset (hdr);/* * Loop over existing entries, stuff them in. */
fs/xfs/xfs_dir2_data.c +96 -61
401 lines not on this page · raw message
fs/xfs/xfs_dir2_format.h +134 -0
152 lines not on this page · raw message
fs/xfs/xfs_dir2_leaf.c +4 -2
@@ -149,6 +149,7 @@ xfs_dir2_block_to_leaf(int needlog;/* need to log block header */ int needscan;/* need to rescan bestfree */ xfs_trans_t *tp;/* transaction pointer */ +struct xfs_dir2_data_free *bf;trace_xfs_dir2_block_to_leaf (args);
@@ -177,6 +178,7 @@ xfs_dir2_block_to_leaf(xfs_dir2_data_check (dp, dbp); btp =xfs_dir2_block_tail_p (mp, hdr); blp =xfs_dir2_block_leaf_p (btp); + bf =xfs_dir3_data_bestfree_p (hdr);/* * Set the counts in the leaf header. */
@@ -212,7 +214,7 @@ xfs_dir2_block_to_leaf( ltp =xfs_dir2_leaf_tail_p (mp, leaf); ltp->bestcount =cpu_to_be32 (1 ); bestsp =xfs_dir2_leaf_bests_p (ltp); - bestsp[0 ] = hdr->bestfree[0 ].length; + bestsp[0 ] = bf[0 ].length;/* * Log the data header and leaf bests table. */
@@ -544,7 +546,7 @@ xfs_dir2_leaf_addname(/* * Initialize the block. */ -if ((error =xfs_dir2_data_init (args, use_block, &dbp))) { +if ((error =xfs_dir3_data_init (args, use_block, &dbp))) {xfs_trans_brelse (tp, lbp);return error; }
fs/xfs/xfs_dir2_node.c +1 -1
@@ -1588,7 +1588,7 @@ xfs_dir2_node_addname_int(if (unlikely ((error =xfs_dir2_grow_inode (args,XFS_DIR2_DATA_SPACE , &dbno)) || - (error =xfs_dir2_data_init (args, dbno, &dbp)))) + (error =xfs_dir3_data_init (args, dbno, &dbp))))return error;/*
fs/xfs/xfs_dir2_priv.h +2 -2
@@ -30,7 +30,7 @@ extern int xfs_dir_cilookup_result(struct xfs_da_args *args, const unsigned char *name, int len);/* xfs_dir2_block.c */ -extern const struct xfs_buf_ops xfs_dir2_block_buf_ops; +extern const struct xfs_buf_ops xfs_dir3_block_buf_ops;extern int xfs_dir2_block_addname (struct xfs_da_args *args); extern int xfs_dir2_block_getdents(struct xfs_inode *dp, void *dirent,
@@ -61,7 +61,7 @@ xfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_unused *dup, int *loghead);extern void xfs_dir2_data_freescan (struct xfs_mount *mp,struct xfs_dir2_data_hdr *hdr,int *loghead); -extern int xfs_dir2_data_init (struct xfs_da_args *args,xfs_dir2_db_t blkno, +extern int xfs_dir3_data_init (struct xfs_da_args *args,xfs_dir2_db_t blkno,struct xfs_buf **bpp);extern void xfs_dir2_data_log_entry (struct xfs_trans *tp,struct xfs_buf *bp,struct xfs_dir2_data_entry *dep);
fs/xfs/xfs_log_recover.c +2 -0
@@ -1877,6 +1877,7 @@ xlog_recover_do_reg_buffer(int bit;int nbits;int error; +struct xfs_da_blkinfo *info;trace_xfs_log_recover_buf_reg_buf (mp->m_log, buf_f);
@@ -1936,6 +1937,7 @@ xlog_recover_do_reg_buffer(/* Shouldn't be any more regions */ ASSERT (i == item->ri_total); + info = bp->b_addr;switch (buf_f->blf_flags &XFS_BLF_TYPE_MASK ) {case XFS_BLF_BTREE_BUF :switch (be32_to_cpu (*(__be32 *)bp->b_addr)) {
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 11/16 xfs: add CRC checking to dir2 free blocks
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
This addition follows the same pattern as the dir2 block CRCs, but with a few differences. The main difference is that the free block header is different between the v2 and v3 formats, so an "in-core" free block header has been added and _todisk/_from_disk functions used to abstract the differences in structure format from the code. This is similar to the on-disk superblock versus the in-core superblock setup. The in-core strucutre is populated when the buffer is read from disk, all the in memory checks and modifications are done on the in-core version of the structure which is written back to the buffer before the buffer is logged.
--- fs/xfs/xfs_dir2_format.h | 52 ++++- fs/xfs/xfs_dir2_leaf.c | 2 +- fs/xfs/xfs_dir2_node.c | 475 +++++++++++++++++++++++++++++++--------------- 3 files changed, 373 insertions(+), 156 deletions(-)
fs/xfs/xfs_dir2_format.h +48 -4
@@ -65,6 +65,7 @@#define XFS_DIR3_BLOCK_MAGIC 0x58444233/* XDB3: single block dirs */ #define XFS_DIR3_DATA_MAGIC 0x58444433/* XDD3: multiblock dirs */ +#define XFS_DIR3_FREE_MAGIC 0x58444633/* XDF3: free index blocks */ /* * Byte offset in data block and shortform entry.
@@ -654,19 +655,62 @@ typedef struct xfs_dir2_free {/* unused entries are -1 */ } xfs_dir2_free_t; -static inline int xfs_dir2_free_max_bests (struct xfs_mount *mp) +struct xfs_dir3_free_hdr { +struct xfs_dir3_blk_hdr hdr; +__be32 firstdb;/* db of first entry */ +__be32 nvalid;/* count of valid entries */ +__be32 nused;/* count of used entries */ +}; + +struct xfs_dir3_free { +struct xfs_dir3_free_hdr hdr; +__be16 bests[];/* best free counts */ +/* unused entries are -1 */ +}; + +#define XFS_DIR3_FREE_CRC_OFF offsetof(struct xfs_dir3_free, hdr.hdr.crc) + +/* +* In core version of the free block header, abstracted away from on-disk format +* differences. Use this in the code, and convert to/from the disk version using +* xfs_dir3_free_hdr_from_disk/xfs_dir3_free_hdr_to_disk. +*/ +struct xfs_dir3_icfree_hdr { +__uint32_t magic; +__uint32_t firstdb; +__uint32_t nvalid; +__uint32_t nused; + +}; + +static inline int +xfs_dir3_free_hdr_size (struct xfs_mount *mp) +{ +if (xfs_sb_version_hascrc (&mp->m_sb)) +return sizeof (struct xfs_dir3_free_hdr ); +return sizeof (struct xfs_dir2_free_hdr ); +} + +static inline int +xfs_dir3_free_max_bests (struct xfs_mount *mp) { -return (mp->m_dirblksize -sizeof (struct xfs_dir2_free_hdr )) / +return (mp->m_dirblksize -xfs_dir3_free_hdr_size (mp)) /sizeof (xfs_dir2_data_off_t); } +static inline __be16 * +xfs_dir3_free_bests_p (struct xfs_mount *mp,struct xfs_dir2_free *free) +{ +return (__be16 *)((char *)free +xfs_dir3_free_hdr_size (mp)); +} +/* * Convert data space db to the corresponding free db. */ static inline xfs_dir2_db_t xfs_dir2_db_to_fdb (struct xfs_mount *mp,xfs_dir2_db_t db) { -return XFS_DIR2_FREE_FIRSTDB (mp) + db /xfs_dir2_free_max_bests (mp); +return XFS_DIR2_FREE_FIRSTDB (mp) + db /xfs_dir3_free_max_bests (mp); }/*
@@ -675,7 +719,7 @@ xfs_dir2_db_to_fdb(struct xfs_mount *mp, xfs_dir2_db_t db)static inline int xfs_dir2_db_to_fdindex (struct xfs_mount *mp,xfs_dir2_db_t db) { -return db %xfs_dir2_free_max_bests (mp); +return db %xfs_dir3_free_max_bests (mp); }/*
fs/xfs/xfs_dir2_leaf.c +1 -1
@@ -1971,7 +1971,7 @@ xfs_dir2_node_to_leaf(/* * Set up the leaf bests table. */ -memcpy (xfs_dir2_leaf_bests_p (ltp), free->bests, +memcpy (xfs_dir2_leaf_bests_p (ltp),xfs_dir3_free_bests_p (mp, free),be32_to_cpu (ltp->bestcount) *sizeof (xfs_dir2_data_off_t));xfs_dir2_leaf_log_bests (tp, lbp,0 ,be32_to_cpu (ltp->bestcount) -1 );xfs_dir2_leaf_log_tail (tp, lbp);
fs/xfs/xfs_dir2_node.c +324 -151
754 lines not on this page · raw message
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 12/16 xfs: add CRC checking to dir2 data blocks
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
This addition follows the same pattern as the dir2 block CRCs.
--- fs/xfs/xfs_dir2_block.c | 22 +++++----- fs/xfs/xfs_dir2_data.c | 100 ++++++++++++++++++++++++++++++++-------------- fs/xfs/xfs_dir2_format.h | 9 +++-- fs/xfs/xfs_dir2_leaf.c | 64 ++++++++++++++++------------- fs/xfs/xfs_dir2_node.c | 36 ++++++++++------- fs/xfs/xfs_dir2_priv.h | 12 +++--- fs/xfs/xfs_file.c | 2 +- 7 files changed, 153 insertions(+), 92 deletions(-)
fs/xfs/xfs_dir2_block.c +12 -10
@@ -76,7 +76,7 @@ xfs_dir3_block_verify(if (hdr3->magic !=be32_to_cpu (XFS_DIR2_BLOCK_MAGIC ))return false; } -if (__xfs_dir2_data_check (NULL , bp)) +if (__xfs_dir3_data_check (NULL , bp))return false;return true; }
@@ -552,7 +552,7 @@ xfs_dir2_block_addname(xfs_dir2_data_log_header (tp, bp);xfs_dir2_block_log_tail (tp, bp);xfs_dir2_data_log_entry (tp, bp, dep); -xfs_dir2_data_check (dp, bp); +xfs_dir3_data_check (dp, bp);return 0 ; }
@@ -595,7 +595,7 @@ xfs_dir2_block_getdents(*/ wantoff =xfs_dir2_dataptr_to_off (mp, *offset); hdr = bp->b_addr; -xfs_dir2_data_check (dp, bp); +xfs_dir3_data_check (dp, bp);/* * Set up values for the loop. */
@@ -719,7 +719,7 @@ xfs_dir2_block_lookup( dp = args->dp; mp = dp->i_mount; hdr = bp->b_addr; -xfs_dir2_data_check (dp, bp); +xfs_dir3_data_check (dp, bp); btp =xfs_dir2_block_tail_p (mp, hdr); blp =xfs_dir2_block_leaf_p (btp);/*
@@ -770,7 +770,7 @@ xfs_dir2_block_lookup_int(return error; hdr = bp->b_addr; -xfs_dir2_data_check (dp, bp); +xfs_dir3_data_check (dp, bp); btp =xfs_dir2_block_tail_p (mp, hdr); blp =xfs_dir2_block_leaf_p (btp);/*
@@ -907,7 +907,7 @@ xfs_dir2_block_removename(xfs_dir2_data_freescan (mp, hdr, &needlog);if (needlog)xfs_dir2_data_log_header (tp, bp); -xfs_dir2_data_check (dp, bp); +xfs_dir3_data_check (dp, bp);/* * See if the size as a shortform is good enough. */
@@ -964,7 +964,7 @@ xfs_dir2_block_replace(*/ dep->inumber =cpu_to_be64 (args->inumber);xfs_dir2_data_log_entry (args->trans, bp, dep); -xfs_dir2_data_check (dp, bp); +xfs_dir3_data_check (dp, bp);return 0 ; }
@@ -1042,12 +1042,14 @@ xfs_dir2_leaf_to_block(* Read the data block if we don't already have it, give up if it fails. */ if (!dbp) { - error =xfs_dir2_data_read (tp, dp, mp->m_dirdatablk,-1 , &dbp); + error =xfs_dir3_data_read (tp, dp, mp->m_dirdatablk,-1 , &dbp);if (error)return error; } hdr = dbp->b_addr; -ASSERT (hdr->magic ==cpu_to_be32 (XFS_DIR2_DATA_MAGIC )); +ASSERT (hdr->magic ==cpu_to_be32 (XFS_DIR2_DATA_MAGIC ) || + hdr->magic ==cpu_to_be32 (XFS_DIR3_DATA_MAGIC )); +/* * Size of the "leaf" area in the block. */
@@ -1325,6 +1327,6 @@ xfs_dir2_sf_to_block(ASSERT (needscan ==0 );xfs_dir2_block_log_leaf (tp, bp,0 ,be32_to_cpu (btp->count) -1 );xfs_dir2_block_log_tail (tp, bp); -xfs_dir2_data_check (dp, bp); +xfs_dir3_data_check (dp, bp);return 0 ; }
fs/xfs/xfs_dir2_data.c +70 -30
230 lines not on this page · raw message
fs/xfs/xfs_dir2_format.h +6 -3
@@ -282,7 +282,8 @@ struct xfs_dir3_data_hdr {static inline struct xfs_dir2_data_free *xfs_dir3_data_bestfree_p (struct xfs_dir2_data_hdr *hdr) { -if (hdr->magic ==cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) { +if (hdr->magic ==cpu_to_be32 (XFS_DIR3_DATA_MAGIC ) || + hdr->magic ==cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) {struct xfs_dir3_data_hdr *hdr3 = (struct xfs_dir3_data_hdr *)hdr;return hdr3->best_free; }
@@ -347,7 +348,8 @@ xfs_dir2_data_unused_tag_p(struct xfs_dir2_data_unused *dup)static inline struct xfs_dir2_data_unused *xfs_dir3_data_unused_p (struct xfs_dir2_data_hdr *hdr) { -if (hdr->magic ==cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) { +if (hdr->magic ==cpu_to_be32 (XFS_DIR3_DATA_MAGIC ) || + hdr->magic ==cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) {return (struct xfs_dir2_data_unused *) ((char *)hdr +sizeof (struct xfs_dir3_data_hdr )); }
@@ -358,7 +360,8 @@ xfs_dir3_data_unused_p(struct xfs_dir2_data_hdr *hdr)static inline size_t xfs_dir3_data_entry_offset (struct xfs_dir2_data_hdr *hdr) { -if (hdr->magic ==cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) +if (hdr->magic ==cpu_to_be32 (XFS_DIR3_DATA_MAGIC ) || + hdr->magic ==cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC ))return sizeof (struct xfs_dir3_data_hdr );return sizeof (struct xfs_dir2_data_hdr ); }
fs/xfs/xfs_dir2_leaf.c +37 -27
208 lines not on this page · raw message
fs/xfs/xfs_dir2_node.c +21 -15
@@ -753,13 +753,13 @@ xfs_dir2_leafn_lookup_for_entry(ASSERT (state->extravalid); curbp = state->extrablk.bp; }else { - error =xfs_dir2_data_read (tp, dp, + error =xfs_dir3_data_read (tp, dp,xfs_dir2_db_to_da (mp, newdb),-1 , &curbp);if (error)return error; } -xfs_dir2_data_check (dp, curbp); +xfs_dir3_data_check (dp, curbp); curdb = newdb; }/*
@@ -787,7 +787,7 @@ xfs_dir2_leafn_lookup_for_entry( state->extrablk.index = (int )((char *)dep - (char *)curbp->b_addr); state->extrablk.magic =XFS_DIR2_DATA_MAGIC ; - curbp->b_ops = &xfs_dir2_data_buf_ops; + curbp->b_ops = &xfs_dir3_data_buf_ops;if (cmp ==XFS_CMP_EXACT )return XFS_ERROR (EEXIST ); }
@@ -802,7 +802,7 @@ xfs_dir2_leafn_lookup_for_entry( state->extrablk.index =-1 ; state->extrablk.blkno = curdb; state->extrablk.magic =XFS_DIR2_DATA_MAGIC ; - curbp->b_ops = &xfs_dir2_data_buf_ops; + curbp->b_ops = &xfs_dir3_data_buf_ops; }else {/* If the curbp is not the CI match block, drop it */ if (state->extrablk.bp != curbp)
@@ -1152,6 +1152,7 @@ xfs_dir2_leafn_remove(int needlog;/* need to log data header */ int needscan;/* need to rescan data frees */ xfs_trans_t *tp;/* transaction pointer */ +struct xfs_dir2_data_free *bf;/* bestfree table */ trace_xfs_dir2_leafn_remove (args, index);
@@ -1186,7 +1187,8 @@ xfs_dir2_leafn_remove( dbp = dblk->bp; hdr = dbp->b_addr; dep = (xfs_dir2_data_entry_t *)((char *)hdr + off); - longest =be16_to_cpu (hdr->bestfree[0 ].length); + bf =xfs_dir3_data_bestfree_p (hdr); + longest =be16_to_cpu (bf[0 ].length); needlog = needscan =0 ;xfs_dir2_data_make_free (tp, dbp, off,xfs_dir2_data_entsize (dep->namelen), &needlog, &needscan);
@@ -1198,12 +1200,12 @@ xfs_dir2_leafn_remove(xfs_dir2_data_freescan (mp, hdr, &needlog);if (needlog)xfs_dir2_data_log_header (tp, dbp); -xfs_dir2_data_check (dp, dbp); +xfs_dir3_data_check (dp, dbp);/* * If the longest data block freespace changes, need to update * the corresponding freeblock entry. */ -if (longest <be16_to_cpu (hdr->bestfree[0 ].length)) { +if (longest <be16_to_cpu (bf[0 ].length)) {int error;/* error return value */ struct xfs_buf *fbp;/* freeblock buffer */ xfs_dir2_db_t fdb;/* freeblock block number */
@@ -1233,7 +1235,7 @@ xfs_dir2_leafn_remove(* Calculate which entry we need to fix. */ findex =xfs_dir2_db_to_fdindex (mp, db); - longest =be16_to_cpu (hdr->bestfree[0 ].length); + longest =be16_to_cpu (bf[0 ].length);/* * If the data block is now empty we can get rid of it * (usually).
@@ -1612,6 +1614,7 @@ xfs_dir2_node_addname_int(xfs_trans_t *tp;/* transaction pointer */ __be16 *bests;struct xfs_dir3_icfree_hdr freehdr; +struct xfs_dir2_data_free *bf; dp = args->dp; mp = dp->i_mount;
@@ -1869,7 +1872,8 @@ xfs_dir2_node_addname_int(* change again. */ hdr = dbp->b_addr; - bests[findex] = hdr->bestfree[0 ].length; + bf =xfs_dir3_data_bestfree_p (hdr); + bests[findex] = bf[0 ].length; logfree =1 ; }/*
@@ -1885,19 +1889,20 @@ xfs_dir2_node_addname_int(/* * Read the data block in. */ - error =xfs_dir2_data_read (tp, dp,xfs_dir2_db_to_da (mp, dbno), + error =xfs_dir3_data_read (tp, dp,xfs_dir2_db_to_da (mp, dbno),-1 , &dbp);if (error)return error; hdr = dbp->b_addr; + bf =xfs_dir3_data_bestfree_p (hdr); logfree =0 ; } -ASSERT (be16_to_cpu (hdr->bestfree[0 ].length) >= length); +ASSERT (be16_to_cpu (bf[0 ].length) >= length);/* * Point to the existing unused space. */ dup = (xfs_dir2_data_unused_t *) - ((char *)hdr +be16_to_cpu (hdr->bestfree[0 ].offset)); + ((char *)hdr +be16_to_cpu (bf[0 ].offset)); needscan = needlog =0 ;/* * Mark the first part of the unused space, inuse for us.
@@ -1929,8 +1934,8 @@ xfs_dir2_node_addname_int(* If the freespace entry is now wrong, update it. */ bests =xfs_dir3_free_bests_p (mp, free);/* gcc is so stupid */ -if (be16_to_cpu (bests[findex]) !=be16_to_cpu (hdr->bestfree[0 ].length)) { - bests[findex] = hdr->bestfree[0 ].length; +if (be16_to_cpu (bests[findex]) !=be16_to_cpu (bf[0 ].length)) { + bests[findex] = bf[0 ].length; logfree =1 ; }/*
@@ -2120,7 +2125,8 @@ xfs_dir2_node_replace(* Point to the data entry. */ hdr = state->extrablk.bp->b_addr; -ASSERT (hdr->magic ==cpu_to_be32 (XFS_DIR2_DATA_MAGIC )); +ASSERT (hdr->magic ==cpu_to_be32 (XFS_DIR2_DATA_MAGIC ) || + hdr->magic ==cpu_to_be32 (XFS_DIR3_DATA_MAGIC )); dep = (xfs_dir2_data_entry_t *) ((char *)hdr +xfs_dir2_dataptr_to_off (state->mp,be32_to_cpu (lep->address)));
fs/xfs/xfs_dir2_priv.h +6 -6
@@ -43,17 +43,17 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,/* xfs_dir2_data.c */ #ifdef DEBUG -#define xfs_dir2_data_check (dp,bp) __xfs_dir2_data_check(dp, bp); +#define xfs_dir3_data_check (dp,bp) __xfs_dir3_data_check(dp, bp);#else -#define xfs_dir2_data_check (dp,bp) +#define xfs_dir3_data_check (dp,bp)#endif -extern const struct xfs_buf_ops xfs_dir2_data_buf_ops; +extern const struct xfs_buf_ops xfs_dir3_data_buf_ops; -extern int __xfs_dir2_data_check (struct xfs_inode *dp,struct xfs_buf *bp); -extern int xfs_dir2_data_read (struct xfs_trans *tp,struct xfs_inode *dp, +extern int __xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp); +extern int xfs_dir3_data_read (struct xfs_trans *tp,struct xfs_inode *dp,xfs_dablk_t bno,xfs_daddr_t mapped_bno,struct xfs_buf **bpp); -extern int xfs_dir2_data_readahead (struct xfs_trans *tp,struct xfs_inode *dp, +extern int xfs_dir3_data_readahead (struct xfs_trans *tp,struct xfs_inode *dp,xfs_dablk_t bno,xfs_daddr_t mapped_bno); extern struct xfs_dir2_data_free *
fs/xfs/xfs_file.c +1 -1
@@ -915,7 +915,7 @@ xfs_dir_open(*/ mode =xfs_ilock_map_shared (ip);if (ip->i_d.di_nextents >0 ) -xfs_dir2_data_readahead (NULL , ip,0 ,-1 ); +xfs_dir3_data_readahead (NULL , ip,0 ,-1 );xfs_iunlock (ip, mode);return 0 ; }
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 13/16 xfs: add CRC checking to dir2 leaf blocks
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
This addition follows the same pattern as the dir2 block CRCs. Seeing as both LEAF1 and LEAFN types need to changed at the same time, this is a pretty large amount of change. leaf block headers neeed to be abstracted away from the on-disk structures (struct xfs_dir3_icleaf_hdr), as do the base leaf entry locations.
This header abstract allows the in-core header and leaf entry location to be passed around instead of the leaf block itself. This saves a lot of converting individual variables from on-disk format to host format where they are used, so there's a good chance that the compiler will be able to produce much more optimal code as it's not having to byteswap variables all over the place.
--- fs/xfs/xfs_da_btree.c | 42 ++- fs/xfs/xfs_da_btree.h | 19 ++ fs/xfs/xfs_dir2_block.c | 17 +- fs/xfs/xfs_dir2_format.h | 60 +++- fs/xfs/xfs_dir2_leaf.c | 777 +++++++++++++++++++++++++++++----------------- fs/xfs/xfs_dir2_node.c | 455 +++++++++++++++------------ fs/xfs/xfs_dir2_priv.h | 32 +- 7 files changed, 889 insertions(+), 513 deletions(-)
fs/xfs/xfs_da_btree.c +32 -10
@@ -139,7 +139,8 @@ xfs_da_node_read_verify( bp->b_ops->verify_read (bp);return ;case XFS_DIR2_LEAFN_MAGIC : - bp->b_ops = &xfs_dir2_leafn_buf_ops; +case XFS_DIR3_LEAFN_MAGIC : + bp->b_ops = &xfs_dir3_leafn_buf_ops; bp->b_ops->verify_read (bp);return ;default :
@@ -396,11 +397,18 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, size = (int )((char *)&oldroot->btree[be16_to_cpu (oldroot->hdr.count)] - (char *)oldroot); }else { -ASSERT (oldroot->hdr.info.magic ==cpu_to_be16 (XFS_DIR2_LEAFN_MAGIC )); +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_dir2_leaf_entry *ents; + leaf = (xfs_dir2_leaf_t *)oldroot; - size = (int )((char *)&leaf->ents[be16_to_cpu (leaf->hdr.count)] - - (char *)leaf); +xfs_dir3_leaf_hdr_from_disk (&leafhdr, leaf); + ents =xfs_dir3_leaf_ents_p (leaf); + +ASSERT (leafhdr.magic ==XFS_DIR2_LEAFN_MAGIC || + leafhdr.magic ==XFS_DIR3_LEAFN_MAGIC ); + size = (int )((char *)&ents[leafhdr.count] - (char *)leaf); } +/* XXX: can't just copy CRC headers from one block to another */ memcpy (node, oldroot, size);xfs_trans_log_buf (tp, bp,0 , size -1 );
@@ -424,7 +432,8 @@ xfs_da_root_split(xfs_da_state_t *state, xfs_da_state_blk_t *blk1, node->hdr.count =cpu_to_be16 (2 );#ifdef DEBUG -if (oldroot->hdr.info.magic ==cpu_to_be16 (XFS_DIR2_LEAFN_MAGIC )) { +if (oldroot->hdr.info.magic ==cpu_to_be16 (XFS_DIR2_LEAFN_MAGIC ) || + oldroot->hdr.info.magic ==cpu_to_be16 (XFS_DIR3_LEAFN_MAGIC )) {ASSERT (blk1->blkno >= mp->m_dirleafblk && blk1->blkno < mp->m_dirfreeblk); ASSERT(blk2->blkno >= mp->m_dirleafblk &&
@@ -782,6 +791,7 @@ xfs_da_blkinfo_onlychild_validate(struct xfs_da_blkinfo *blkinfo, __u16 level)if (level ==1 ) {ASSERT (magic ==cpu_to_be16 (XFS_DIR2_LEAFN_MAGIC ) || + magic ==cpu_to_be16 (XFS_DIR3_LEAFN_MAGIC ) || magic ==cpu_to_be16 (XFS_ATTR_LEAF_MAGIC )); }else ASSERT (magic ==cpu_to_be16 (XFS_DA_NODE_MAGIC ));
@@ -1565,6 +1575,7 @@ xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, info = blk->bp->b_addr;ASSERT (info->magic ==cpu_to_be16 (XFS_DA_NODE_MAGIC ) || info->magic ==cpu_to_be16 (XFS_DIR2_LEAFN_MAGIC ) || + info->magic ==cpu_to_be16 (XFS_DIR3_LEAFN_MAGIC ) || info->magic ==cpu_to_be16 (XFS_ATTR_LEAF_MAGIC )); blk->magic =be16_to_cpu (info->magic);if (blk->magic ==XFS_DA_NODE_MAGIC ) {
@@ -1588,8 +1599,7 @@ xfs_da_path_shift(xfs_da_state_t *state, xfs_da_state_path_t *path, NULL);break ;default : -ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC || - blk->magic ==XFS_DIR2_LEAFN_MAGIC ); +ASSERT (0 );break ; } }
@@ -1833,10 +1843,16 @@ xfs_da_swap_lastblock(/* * Get values from the moved block. */ -if (dead_info->magic ==cpu_to_be16 (XFS_DIR2_LEAFN_MAGIC )) { +if (dead_info->magic ==cpu_to_be16 (XFS_DIR2_LEAFN_MAGIC ) || + dead_info->magic ==cpu_to_be16 (XFS_DIR3_LEAFN_MAGIC )) { +struct xfs_dir3_icleaf_hdr leafhdr; +struct xfs_dir2_leaf_entry *ents; + dead_leaf2 = (xfs_dir2_leaf_t *)dead_info; +xfs_dir3_leaf_hdr_from_disk (&leafhdr, dead_leaf2); + ents =xfs_dir3_leaf_ents_p (dead_leaf2); dead_level =0 ; - dead_hash =be32_to_cpu (dead_leaf2->ents[be16_to_cpu (dead_leaf2->hdr.count) -1 ].hashval); + dead_hash =be32_to_cpu (ents[leafhdr.count -1 ].hashval); }else {ASSERT (dead_info->magic ==cpu_to_be16 (XFS_DA_NODE_MAGIC )); dead_node = (xfs_da_intnode_t *)dead_info;
@@ -2282,9 +2298,15 @@ xfs_da_read_buf( (magic != XFS_ATTR_LEAF_MAGIC) && (magic != XFS_DIR2_LEAF1_MAGIC) && (magic != XFS_DIR2_LEAFN_MAGIC) && + (magic != XFS_DIR3_LEAFN_MAGIC) && (magic1 != XFS_DIR2_BLOCK_MAGIC) && + (magic1 != XFS_DIR3_BLOCK_MAGIC) && (magic1 != XFS_DIR2_DATA_MAGIC) && - (free->hdr.magic != cpu_to_be32(XFS_DIR2_FREE_MAGIC)), + (magic1 != XFS_DIR3_DATA_MAGIC) && + (free->hdr.magic != + cpu_to_be32(XFS_DIR2_FREE_MAGIC)) && + (free->hdr.magic != + cpu_to_be32(XFS_DIR3_FREE_MAGIC)), mp, XFS_ERRTAG_DA_READ_BUF, XFS_RANDOM_DA_READ_BUF))) {trace_xfs_da_btree_corrupt (bp, _RET_IP_);
fs/xfs/xfs_da_btree.h +19 -0
@@ -47,6 +47,25 @@ typedef struct xfs_da_blkinfo { } xfs_da_blkinfo_t;/* +* CRC enabled directory structure types +* +* The headers change size for the additional verification information, but +* otherwise the tree layouts and contents are unchanged. +*/ +#define XFS_DIR3_LEAF1_MAGIC 0x3df1/* magic number: v2 dirlf single blks */ +#define XFS_DIR3_LEAFN_MAGIC 0x3dff/* magic number: v2 dirlf multi blks */ + +struct xfs_da3_blkinfo { +/* XXX: check packing due to size of xfs_da_blkinfo */ +struct xfs_da_blkinfo hdr; +__be32 crc;/* CRC of block */ +__be64 blkno;/* first block of the buffer */ +__be64 lsn;/* sequence number of last write */ +uuid_t uuid;/* filesystem we belong to */ +__be64 owner;/* inode that owns the block */ +}; + +/* * This is the structure of the root and intermediate nodes in the Btree. * The leaf nodes are defined above. *
fs/xfs/xfs_dir2_block.c +11 -6
@@ -1012,6 +1012,8 @@ xfs_dir2_leaf_to_block(__be16 *tagp;/* end of entry (tag) */ int to;/* block/leaf to index */ xfs_trans_t *tp;/* transaction pointer */ +struct xfs_dir2_leaf_entry *ents; +struct xfs_dir3_icleaf_hdr leafhdr;trace_xfs_dir2_leaf_to_block (args);
@@ -1019,8 +1021,12 @@ xfs_dir2_leaf_to_block( tp = args->trans; mp = dp->i_mount; leaf = lbp->b_addr; -ASSERT (leaf->hdr.info.magic ==cpu_to_be16 (XFS_DIR2_LEAF1_MAGIC )); +xfs_dir3_leaf_hdr_from_disk (&leafhdr, leaf); + ents =xfs_dir3_leaf_ents_p (leaf); ltp =xfs_dir2_leaf_tail_p (mp, leaf); + +ASSERT (leafhdr.magic ==XFS_DIR2_LEAF1_MAGIC || + leafhdr.magic ==XFS_DIR3_LEAF1_MAGIC );/* * If there are data blocks other than the first one, take this * opportunity to remove trailing empty data blocks that may have
@@ -1083,18 +1089,17 @@ xfs_dir2_leaf_to_block(* Initialize the block tail. */ btp =xfs_dir2_block_tail_p (mp, hdr); - btp->count =cpu_to_be32 (be16_to_cpu (leaf->hdr.count) -be16_to_cpu (leaf->hdr.stale)); + btp->count =cpu_to_be32 (leafhdr.count - leafhdr.stale); btp->stale =0 ;xfs_dir2_block_log_tail (tp, dbp);/* * Initialize the block leaf area. We compact out stale entries. */ lep =xfs_dir2_block_leaf_p (btp); -for (from = to =0 ; from <be16_to_cpu (leaf->hdr.count); from++) { -if (leaf->ents[from].address == -cpu_to_be32 (XFS_DIR2_NULL_DATAPTR )) +for (from = to =0 ; from < leafhdr.count; from++) { +if (ents[from].address ==cpu_to_be32 (XFS_DIR2_NULL_DATAPTR ))continue ; - lep[to++] = leaf->ents[from]; + lep[to++] = ents[from]; }ASSERT (to ==be32_to_cpu (btp->count));xfs_dir2_block_log_leaf (tp, dbp,0 ,be32_to_cpu (btp->count) -1 );
fs/xfs/xfs_dir2_format.h +53 -7
88 lines not on this page · raw message
fs/xfs/xfs_dir2_leaf.c +492 -285
1,341 lines not on this page · raw message
fs/xfs/xfs_dir2_node.c +262 -193
776 lines not on this page · raw message
fs/xfs/xfs_dir2_priv.h +20 -12
@@ -77,24 +77,25 @@ extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_buf *bp, xfs_dir2_data_aoff_t len, int *needlogp, int *needscanp);/* xfs_dir2_leaf.c */ -extern const struct xfs_buf_ops xfs_dir2_leafn_buf_ops; +extern const struct xfs_buf_ops xfs_dir3_leafn_buf_ops; -extern int xfs_dir2_leafn_read (struct xfs_trans *tp,struct xfs_inode *dp, +extern int xfs_dir3_leafn_read (struct xfs_trans *tp,struct xfs_inode *dp,xfs_dablk_t fbno,xfs_daddr_t mappedbno,struct xfs_buf **bpp);extern int xfs_dir2_block_to_leaf (struct xfs_da_args *args,struct xfs_buf *dbp);extern int xfs_dir2_leaf_addname (struct xfs_da_args *args); -extern void xfs_dir2_leaf_compact (struct xfs_da_args *args, -struct xfs_buf *bp); -extern void xfs_dir2_leaf_compact_x1 (struct xfs_buf *bp,int *indexp, +extern void xfs_dir3_leaf_compact (struct xfs_da_args *args, +struct xfs_dir3_icleaf_hdr *leafhdr,struct xfs_buf *bp); +extern void xfs_dir3_leaf_compact_x1 (struct xfs_dir3_icleaf_hdr *leafhdr, +struct xfs_dir2_leaf_entry *ents,int *indexp,int *lowstalep,int *highstalep,int *lowlogp,int *highlogp);extern int xfs_dir2_leaf_getdents (struct xfs_inode *dp,void *dirent,size_t bufsize,xfs_off_t *offset,filldir_t filldir); -extern int xfs_dir2_leaf_init (struct xfs_da_args *args,xfs_dir2_db_t bno, -struct xfs_buf **bpp,int magic); -extern void xfs_dir2_leaf_log_ents (struct xfs_trans *tp,struct xfs_buf *bp, +extern int xfs_dir3_leaf_get_buf (struct xfs_da_args *args,xfs_dir2_db_t bno, +struct xfs_buf **bpp,__uint16_t magic); +extern void xfs_dir3_leaf_log_ents (struct xfs_trans *tp,struct xfs_buf *bp,int first,int last); -extern void xfs_dir2_leaf_log_header (struct xfs_trans *tp, +extern void xfs_dir3_leaf_log_header (struct xfs_trans *tp,struct xfs_buf *bp);extern int xfs_dir2_leaf_lookup (struct xfs_da_args *args);extern int xfs_dir2_leaf_removename (struct xfs_da_args *args);
@@ -104,11 +105,18 @@ extern int xfs_dir2_leaf_search_hash(struct xfs_da_args *args,extern int xfs_dir2_leaf_trim_data (struct xfs_da_args *args,struct xfs_buf *lbp,xfs_dir2_db_t db);extern struct xfs_dir2_leaf_entry * -xfs_dir2_leaf_find_entry (struct xfs_dir2_leaf *leaf,int index,int compact, -int lowstale,int highstale, -int *lfloglow,int *lfloghigh); +xfs_dir3_leaf_find_entry (struct xfs_dir3_icleaf_hdr *leafhdr, +struct xfs_dir2_leaf_entry *ents,int index,int compact, +int lowstale,int highstale,int *lfloglow,int *lfloghigh);extern int xfs_dir2_node_to_leaf (struct xfs_da_state *state); +extern void xfs_dir3_leaf_hdr_from_disk (struct xfs_dir3_icleaf_hdr *to, +struct xfs_dir2_leaf *from); +extern void xfs_dir3_leaf_hdr_to_disk (struct xfs_dir2_leaf *to, +struct xfs_dir3_icleaf_hdr *from); +extern bool xfs_dir3_leaf_check_int (struct xfs_mount *mp, +struct xfs_dir3_icleaf_hdr *hdr,struct xfs_dir2_leaf *leaf); +/* xfs_dir2_node.c */ extern int xfs_dir2_leaf_to_node (struct xfs_da_args *args,struct xfs_buf *lbp);
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 14/16 xfs: add CRCs to dir2/da node blocks
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
--- fs/xfs/xfs_attr.c | 33 +- fs/xfs/xfs_attr_leaf.c | 29 +- fs/xfs/xfs_bmap.c | 1 + fs/xfs/xfs_da_btree.c | 1372 +++++++++++++++++++++++++++++------------------- fs/xfs/xfs_da_btree.h | 105 +++- fs/xfs/xfs_dir2_node.c | 26 +- fs/xfs/xfs_trace.c | 2 +- 7 files changed, 955 insertions(+), 613 deletions(-)
fs/xfs/xfs_attr.c +16 -17
@@ -15,7 +15,6 @@* along with this program; if not, write the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "xfs.h" #include "xfs_fs.h" #include "xfs_types.h"
@@ -25,6 +24,7 @@#include "xfs_sb.h" #include "xfs_ag.h" #include "xfs_mount.h" +#include "xfs_error.h" #include "xfs_da_btree.h" #include "xfs_bmap_btree.h" #include "xfs_attr_sf.h"
@@ -35,7 +35,6 @@#include "xfs_bmap.h" #include "xfs_attr.h" #include "xfs_attr_leaf.h" -#include "xfs_error.h" #include "xfs_quota.h" #include "xfs_trans_space.h" #include "xfs_vnodeops.h"
@@ -1236,7 +1235,7 @@ restart:* Search to see if name already exists, and get back a pointer * to where it should go. */ - error =xfs_da_node_lookup_int (state, &retval); + error =xfs_da3_node_lookup_int (state, &retval);if (error) goto out; blk = &state->path.blk[ state->path.active-1 ];
@@ -1307,7 +1306,7 @@ restart:* in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields. */ xfs_bmap_init (args->flist, args->firstblock); - error =xfs_da_split (state); + error =xfs_da3_split (state);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, &committed);
@@ -1329,7 +1328,7 @@ restart:/* * Addition succeeded, update Btree hashvals. */ -xfs_da_fixhashpath (state, &state->path); +xfs_da3_fixhashpath (state, &state->path); }/*
@@ -1400,7 +1399,7 @@ restart: state->blocksize = state->mp->m_sb.sb_blocksize; state->node_ents = state->mp->m_attr_node_ents; state->inleaf =0 ; - error =xfs_da_node_lookup_int (state, &retval); + error =xfs_da3_node_lookup_int (state, &retval);if (error) goto out;
@@ -1410,14 +1409,14 @@ restart: blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); error =xfs_attr_leaf_remove (blk->bp, args); -xfs_da_fixhashpath (state, &state->path); +xfs_da3_fixhashpath (state, &state->path);/* * Check to see if the tree needs to be collapsed. */ if (retval && (state->path.active >1 )) {xfs_bmap_init (args->flist, args->firstblock); - error =xfs_da_join (state); + error =xfs_da3_join (state);if (!error) { error = xfs_bmap_finish(&args->trans, args->flist,
@@ -1495,7 +1494,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)/* * Search to see if name exists, and get back a pointer to it. */ - error =xfs_da_node_lookup_int (state, &retval); + error =xfs_da3_node_lookup_int (state, &retval);if (error || (retval !=EEXIST )) {if (error ==0 ) error = retval;
@@ -1546,14 +1545,14 @@ xfs_attr_node_removename(xfs_da_args_t *args) blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); retval =xfs_attr_leaf_remove (blk->bp, args); -xfs_da_fixhashpath (state, &state->path); +xfs_da3_fixhashpath (state, &state->path);/* * Check to see if the tree needs to be collapsed. */ if (retval && (state->path.active >1 )) {xfs_bmap_init (args->flist, args->firstblock); - error =xfs_da_join (state); + error =xfs_da3_join (state);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, &committed);
@@ -1699,7 +1698,7 @@ xfs_attr_refillstate(xfs_da_state_t *state)ASSERT ((path->active >=0 ) && (path->active <XFS_DA_NODE_MAXDEPTH ));for (blk = path->blk, level =0 ; level < path->active; blk++, level++) {if (blk->disk_blkno) { - error =xfs_da_node_read (state->args->trans, + error =xfs_da3_node_read (state->args->trans, state->args->dp, blk->blkno, blk->disk_blkno, &blk->bp,XFS_ATTR_FORK );
@@ -1718,7 +1717,7 @@ xfs_attr_refillstate(xfs_da_state_t *state)ASSERT ((path->active >=0 ) && (path->active <XFS_DA_NODE_MAXDEPTH ));for (blk = path->blk, level =0 ; level < path->active; blk++, level++) {if (blk->disk_blkno) { - error =xfs_da_node_read (state->args->trans, + error =xfs_da3_node_read (state->args->trans, state->args->dp, blk->blkno, blk->disk_blkno, &blk->bp,XFS_ATTR_FORK );
@@ -1758,7 +1757,7 @@ xfs_attr_node_get(xfs_da_args_t *args)/* * Search to see if name exists, and get back a pointer to it. */ - error =xfs_da_node_lookup_int (state, &retval); + error =xfs_da3_node_lookup_int (state, &retval);if (error) { retval = error; }else if (retval ==EEXIST ) {
@@ -1810,7 +1809,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)*/ bp =NULL ;if (cursor->blkno >0 ) { - error =xfs_da_node_read (NULL , context->dp, cursor->blkno,-1 , + error =xfs_da3_node_read (NULL , context->dp, cursor->blkno,-1 , &bp,XFS_ATTR_FORK );if ((error !=0 ) && (error !=EFSCORRUPTED ))return (error);
@@ -1852,7 +1851,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)if (bp ==NULL ) { cursor->blkno =0 ;for (;;) { - error =xfs_da_node_read (NULL , context->dp, + error =xfs_da3_node_read (NULL , context->dp, cursor->blkno,-1 , &bp,XFS_ATTR_FORK );if (error)
@@ -1870,7 +1869,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)xfs_trans_brelse (NULL , bp);return (XFS_ERROR (EFSCORRUPTED )); } - btree = node->btree; + btree =xfs_da3_node_tree_p (node);for (i =0 ; i <be16_to_cpu (node->hdr.count); btree++, i++) { if (cursor->hashval
fs/xfs/xfs_attr_leaf.c +16 -13
@@ -910,6 +910,7 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)struct xfs_buf *bp1, *bp2;xfs_dablk_t blkno;int error; +struct xfs_da_node_entry *btree;trace_xfs_attr_leaf_to_node (args);
@@ -935,16 +936,16 @@ xfs_attr_leaf_to_node(xfs_da_args_t *args)/* * Set up the new root node. */ - error =xfs_da_node_create (args,0 ,1 , &bp1,XFS_ATTR_FORK ); + error =xfs_da3_node_create (args,0 ,1 , &bp1,XFS_ATTR_FORK );if (error) goto out; node = bp1->b_addr; leaf = bp2->b_addr;ASSERT (leaf->hdr.info.magic ==cpu_to_be16 (XFS_ATTR_LEAF_MAGIC ));/* both on-disk, don't endian-flip twice */ - node->btree[0 ].hashval = - leaf->entries[be16_to_cpu (leaf->hdr.count)-1 ].hashval; - node->btree[0 ].before =cpu_to_be32 (blkno); + btree =xfs_da3_node_tree_p (node); + btree[0 ].hashval = leaf->entries[be16_to_cpu (leaf->hdr.count)-1 ].hashval; + btree[0 ].before =cpu_to_be32 (blkno); node->hdr.count =cpu_to_be16 (1 );xfs_trans_log_buf (args->trans, bp1,0 ,XFS_LBSIZE (dp->i_mount) -1 ); error =0 ;
@@ -1032,7 +1033,7 @@ xfs_attr_leaf_split(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk,* NOTE: rebalance() currently depends on the 2nd block being empty. */ xfs_attr_leaf_rebalance (state, oldblk, newblk); - error =xfs_da_blk_link (state, oldblk, newblk); + error =xfs_da3_blk_link (state, oldblk, newblk);if (error)return (error);
@@ -1660,7 +1661,7 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)*/ forward = (info->forw !=0 );memcpy (&state->altpath, &state->path,sizeof (state->path)); - error =xfs_da_path_shift (state, &state->altpath, forward, + error =xfs_da3_path_shift (state, &state->altpath, forward,0 , &retval);if (error)return (error);
@@ -1717,10 +1718,10 @@ xfs_attr_leaf_toosmall(xfs_da_state_t *state, int *action)*/ memcpy (&state->altpath, &state->path,sizeof (state->path));if (blkno < blk->blkno) { - error =xfs_da_path_shift (state, &state->altpath, forward, + error =xfs_da3_path_shift (state, &state->altpath, forward,0 , &retval); }else { - error =xfs_da_path_shift (state, &state->path, forward, + error =xfs_da3_path_shift (state, &state->path, forward,0 , &retval); }if (error)
@@ -2783,7 +2784,7 @@ xfs_attr_root_inactive(xfs_trans_t **trans, xfs_inode_t *dp)* the extents in reverse order the extent containing * block 0 must still be there. */ - error =xfs_da_node_read (*trans, dp,0 ,-1 , &bp,XFS_ATTR_FORK ); + error =xfs_da3_node_read (*trans, dp,0 ,-1 , &bp,XFS_ATTR_FORK );if (error)return (error); blkno =XFS_BUF_ADDR (bp);
@@ -2836,6 +2837,7 @@ xfs_attr_node_inactive(xfs_daddr_t parent_blkno, child_blkno;int error, count, i;struct xfs_buf *child_bp; +struct xfs_da_node_entry *btree;/* * Since this code is recursive (gasp!) we must protect ourselves.
@@ -2853,7 +2855,8 @@ xfs_attr_node_inactive(xfs_trans_brelse (*trans, bp);return (0 ); } - child_fsb =be32_to_cpu (node->btree[0 ].before); + btree =xfs_da3_node_tree_p (node); + child_fsb =be32_to_cpu (btree[0 ].before);xfs_trans_brelse (*trans, bp);/* no locks for later trans */ /*
@@ -2868,7 +2871,7 @@ xfs_attr_node_inactive(* traversal of the tree so we may deal with many blocks * before we come back to this one. */ - error =xfs_da_node_read (*trans, dp, child_fsb,-2 , &child_bp, + error =xfs_da3_node_read (*trans, dp, child_fsb,-2 , &child_bp,XFS_ATTR_FORK );if (error)return (error);
@@ -2909,11 +2912,11 @@ xfs_attr_node_inactive(* child block number. */ if ((i+1 ) < count) { - error =xfs_da_node_read (*trans, dp,0 , parent_blkno, + error =xfs_da3_node_read (*trans, dp,0 , parent_blkno, &bp,XFS_ATTR_FORK );if (error)return (error); - child_fsb =be32_to_cpu (node->btree[i+1 ].before); + child_fsb =be32_to_cpu (btree[i+1 ].before);xfs_trans_brelse (*trans, bp); }/*
fs/xfs/xfs_bmap.c +1 -0
@@ -25,6 +25,7 @@#include "xfs_sb.h" #include "xfs_ag.h" #include "xfs_dir2.h" +#include "xfs_mount.h" #include "xfs_da_btree.h" #include "xfs_bmap_btree.h" #include "xfs_alloc_btree.h"
fs/xfs/xfs_da_btree.c +827 -545
2,127 lines not on this page · raw message
fs/xfs/xfs_da_btree.h +81 -24
149 lines not on this page · raw message
fs/xfs/xfs_dir2_node.c +13 -13
@@ -1361,7 +1361,7 @@ xfs_dir2_leafn_split(* block into the leaves. */ xfs_dir2_leafn_rebalance (state, oldblk, newblk); - error =xfs_da_blk_link (state, oldblk, newblk); + error =xfs_da3_blk_link (state, oldblk, newblk);if (error) {return error; }
@@ -1443,7 +1443,7 @@ xfs_dir2_leafn_toosmall(*/ forward = (leafhdr.forw !=0 );memcpy (&state->altpath, &state->path,sizeof (state->path)); - error =xfs_da_path_shift (state, &state->altpath, forward,0 , + error =xfs_da3_path_shift (state, &state->altpath, forward,0 , &rval);if (error)return error;
@@ -1505,10 +1505,10 @@ xfs_dir2_leafn_toosmall(*/ memcpy (&state->altpath, &state->path,sizeof (state->path));if (blkno < blk->blkno) - error =xfs_da_path_shift (state, &state->altpath, forward,0 , + error =xfs_da3_path_shift (state, &state->altpath, forward,0 , &rval);else - error =xfs_da_path_shift (state, &state->path, forward,0 , + error =xfs_da3_path_shift (state, &state->path, forward,0 , &rval);if (error) {return error;
@@ -1604,7 +1604,7 @@ xfs_dir2_node_addname(* Look up the name. We're not supposed to find it, but * this gives us the insertion point. */ - error =xfs_da_node_lookup_int (state, &rval); + error =xfs_da3_node_lookup_int (state, &rval);if (error) rval = error;if (rval !=ENOENT ) {
@@ -1630,7 +1630,7 @@ xfs_dir2_node_addname(* It worked, fix the hash values up the btree. */ if (!(args->op_flags &XFS_DA_OP_JUSTCHECK )) -xfs_da_fixhashpath (state, &state->path); +xfs_da3_fixhashpath (state, &state->path); }else {/* * It didn't work, we need to split the leaf block.
@@ -1642,7 +1642,7 @@ xfs_dir2_node_addname(/* * Split the leaf block and insert the new entry. */ - rval =xfs_da_split (state); + rval =xfs_da3_split (state); } done:xfs_da_state_free (state);
@@ -2020,7 +2020,7 @@ xfs_dir2_node_addname_int(/* * Lookup an entry in a node-format directory. -* All the real work happens in xfs_da_node_lookup_int. +* All the real work happens in xfs_da3_node_lookup_int. * The only real output is the inode number of the entry. */ int /* error */
@@ -2045,7 +2045,7 @@ xfs_dir2_node_lookup(/* * Fill in the path to the entry in the cursor. */ - error =xfs_da_node_lookup_int (state, &rval); + error =xfs_da3_node_lookup_int (state, &rval);if (error) rval = error;else if (rval ==ENOENT && args->cmpresult ==XFS_CMP_CASE ) {
@@ -2100,7 +2100,7 @@ xfs_dir2_node_removename(/* * Look up the entry we're deleting, set up the cursor. */ - error =xfs_da_node_lookup_int (state, &rval); + error =xfs_da3_node_lookup_int (state, &rval);if (error) rval = error;/*
@@ -2124,12 +2124,12 @@ xfs_dir2_node_removename(/* * Fix the hash values up the btree. */ -xfs_da_fixhashpath (state, &state->path); +xfs_da3_fixhashpath (state, &state->path);/* * If we need to join leaf blocks, do it. */ if (rval && state->path.active >1 ) - error =xfs_da_join (state); + error =xfs_da3_join (state);/* * If no errors so far, try conversion to leaf format. */
@@ -2171,7 +2171,7 @@ xfs_dir2_node_replace(/* * Lookup the entry to change in the btree. */ - error =xfs_da_node_lookup_int (state, &rval); + error =xfs_da3_node_lookup_int (state, &rval);if (error) { rval = error; }
fs/xfs/xfs_trace.c +1 -1
@@ -22,7 +22,6 @@#include "xfs_trans.h" #include "xfs_sb.h" #include "xfs_ag.h" -#include "xfs_da_btree.h" #include "xfs_bmap_btree.h" #include "xfs_alloc_btree.h" #include "xfs_ialloc_btree.h"
@@ -30,6 +29,7 @@#include "xfs_inode.h" #include "xfs_btree.h" #include "xfs_mount.h" +#include "xfs_da_btree.h" #include "xfs_ialloc.h" #include "xfs_itable.h" #include "xfs_alloc.h"
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
PATCH 15/16 xfs: add CRCs to attr leaf blocks
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
--- fs/xfs/xfs_attr.c | 125 ++-- fs/xfs/xfs_attr_leaf.c | 1738 +++++++++++++++++++++++++++--------------------- fs/xfs/xfs_attr_leaf.h | 121 +++- fs/xfs/xfs_da_btree.c | 18 +- fs/xfs/xfs_da_btree.h | 1 + 5 files changed, 1163 insertions(+), 840 deletions(-)
fs/xfs/xfs_attr.c +69 -56
@@ -819,7 +819,7 @@ xfs_attr_inactive(xfs_inode_t *dp) error =0 ; goto out; } - error =xfs_attr_root_inactive (&trans, dp); + error =xfs_attr3_root_inactive (&trans, dp);if (error) goto out;
@@ -905,7 +905,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)*/ dp = args->dp; args->blkno =0 ; - error =xfs_attr_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp);if (error)return error;
@@ -913,14 +913,14 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)* Look up the given attribute in the leaf block. Figure out if * the given flags produce an error or call for an atomic rename. */ - retval =xfs_attr_leaf_lookup_int (bp, args); + retval =xfs_attr3_leaf_lookup_int (bp, args);if ((args->flags &ATTR_REPLACE ) && (retval ==ENOATTR )) {xfs_trans_brelse (args->trans, bp); -return (retval); +return retval; }else if (retval ==EEXIST ) {if (args->flags &ATTR_CREATE ) {/* pure create op */ xfs_trans_brelse (args->trans, bp); -return (retval); +return retval; }trace_xfs_attr_leaf_replace (args);
@@ -936,7 +936,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)* Add the attribute to the leaf block, transitioning to a Btree * if required. */ - retval =xfs_attr_leaf_add (bp, args); + retval =xfs_attr3_leaf_add (bp, args);if (retval ==ENOSPC ) {/* * Promote the attribute list to the Btree format, then
@@ -944,7 +944,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)* can manage its own transactions. */ xfs_bmap_init (args->flist, args->firstblock); - error =xfs_attr_leaf_to_node (args); + error =xfs_attr3_leaf_to_node (args);if (!error) { error =xfs_bmap_finish (&args->trans, args->flist, &committed);
@@ -1009,7 +1009,7 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)* In a separate transaction, set the incomplete flag on the * "old" attr and clear the incomplete flag on the "new" attr. */ - error =xfs_attr_leaf_flipflags (args); + error =xfs_attr3_leaf_flipflags (args);if (error)return (error);
@@ -1031,19 +1031,19 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)* Read in the block containing the "old" attr, then * remove the "old" attr from that block (neat, huh!) */ - error =xfs_attr_leaf_read (args->trans, args->dp, args->blkno, + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp);if (error)return error; -xfs_attr_leaf_remove (bp, args); +xfs_attr3_leaf_remove (bp, args);/* * If the result is small enough, shrink it all into the inode. */ if ((forkoff =xfs_attr_shortform_allfit (bp, dp))) {xfs_bmap_init (args->flist, args->firstblock); - error =xfs_attr_leaf_to_shortform (bp, args, forkoff); + error =xfs_attr3_leaf_to_shortform (bp, args, forkoff);/* bp is gone due to xfs_da_shrink_inode */ if (!error) { error = xfs_bmap_finish(&args->trans,
@@ -1075,9 +1075,9 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)/* * Added a "remote" value, just clear the incomplete flag. */ - error =xfs_attr_leaf_clearflag (args); + error =xfs_attr3_leaf_clearflag (args); } -return (error); +return error; }/*
@@ -1100,24 +1100,24 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)*/ dp = args->dp; args->blkno =0 ; - error =xfs_attr_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp);if (error)return error; - error =xfs_attr_leaf_lookup_int (bp, args); + error =xfs_attr3_leaf_lookup_int (bp, args);if (error ==ENOATTR ) {xfs_trans_brelse (args->trans, bp); -return (error); +return error; } -xfs_attr_leaf_remove (bp, args); +xfs_attr3_leaf_remove (bp, args);/* * If the result is small enough, shrink it all into the inode. */ if ((forkoff =xfs_attr_shortform_allfit (bp, dp))) {xfs_bmap_init (args->flist, args->firstblock); - error =xfs_attr_leaf_to_shortform (bp, args, forkoff); + error =xfs_attr3_leaf_to_shortform (bp, args, forkoff);/* bp is gone due to xfs_da_shrink_inode */ if (!error) { error = xfs_bmap_finish(&args->trans, args->flist,
@@ -1127,7 +1127,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)ASSERT (committed); args->trans =NULL ;xfs_bmap_cancel (args->flist); -return (error); +return error; }/*
@@ -1137,7 +1137,7 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)if (committed)xfs_trans_ijoin (args->trans, dp,0 ); } -return (0 ); +return 0 ; }/*
@@ -1155,21 +1155,21 @@ xfs_attr_leaf_get(xfs_da_args_t *args)trace_xfs_attr_leaf_get (args); args->blkno =0 ; - error =xfs_attr_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp, args->blkno,-1 , &bp);if (error)return error; - error =xfs_attr_leaf_lookup_int (bp, args); + error =xfs_attr3_leaf_lookup_int (bp, args);if (error !=EEXIST ) {xfs_trans_brelse (args->trans, bp); -return (error); +return error; } - error =xfs_attr_leaf_getvalue (bp, args); + error =xfs_attr3_leaf_getvalue (bp, args);xfs_trans_brelse (args->trans, bp);if (!error && (args->rmtblkno >0 ) && !(args->flags &ATTR_KERNOVAL )) { error =xfs_attr_rmtval_get (args); } -return (error); +return error; }/*
@@ -1184,11 +1184,11 @@ xfs_attr_leaf_list(xfs_attr_list_context_t *context)trace_xfs_attr_leaf_list (context); context->cursor->blkno =0 ; - error =xfs_attr_leaf_read (NULL , context->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (NULL , context->dp,0 ,-1 , &bp);if (error)return XFS_ERROR (error); - error =xfs_attr_leaf_list_int (bp, context); + error =xfs_attr3_leaf_list_int (bp, context);xfs_trans_brelse (NULL , bp);return XFS_ERROR (error); }
@@ -1257,7 +1257,7 @@ restart: args->rmtblkcnt =0 ; } - retval =xfs_attr_leaf_add (blk->bp, state->args); + retval =xfs_attr3_leaf_add (blk->bp, state->args);if (retval ==ENOSPC ) {if (state->path.active ==1 ) {/*
@@ -1267,7 +1267,7 @@ restart:*/ xfs_da_state_free (state);xfs_bmap_init (args->flist, args->firstblock); - error =xfs_attr_leaf_to_node (args); + error =xfs_attr3_leaf_to_node (args);if (!error) { error = xfs_bmap_finish(&args->trans, args->flist,
@@ -1369,7 +1369,7 @@ restart:* In a separate transaction, set the incomplete flag on the * "old" attr and clear the incomplete flag on the "new" attr. */ - error =xfs_attr_leaf_flipflags (args); + error =xfs_attr3_leaf_flipflags (args);if (error) goto out;
@@ -1408,7 +1408,7 @@ restart:*/ blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - error =xfs_attr_leaf_remove (blk->bp, args); + error =xfs_attr3_leaf_remove (blk->bp, args);xfs_da3_fixhashpath (state, &state->path);/*
@@ -1449,7 +1449,7 @@ restart:/* * Added a "remote" value, just clear the incomplete flag. */ - error =xfs_attr_leaf_clearflag (args); + error =xfs_attr3_leaf_clearflag (args);if (error) goto out; }
@@ -1523,7 +1523,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)* Mark the attribute as INCOMPLETE, then bunmapi() the * remote value. */ - error =xfs_attr_leaf_setflag (args); + error =xfs_attr3_leaf_setflag (args);if (error) goto out; error =xfs_attr_rmtval_remove (args);
@@ -1544,7 +1544,7 @@ xfs_attr_node_removename(xfs_da_args_t *args)*/ blk = &state->path.blk[ state->path.active-1 ];ASSERT (blk->magic ==XFS_ATTR_LEAF_MAGIC ); - retval =xfs_attr_leaf_remove (blk->bp, args); + retval =xfs_attr3_leaf_remove (blk->bp, args);xfs_da3_fixhashpath (state, &state->path);/*
@@ -1590,13 +1590,13 @@ xfs_attr_node_removename(xfs_da_args_t *args)ASSERT (state->path.blk[0 ].bp); state->path.blk[0 ].bp =NULL ; - error =xfs_attr_leaf_read (args->trans, args->dp,0 ,-1 , &bp); + error =xfs_attr3_leaf_read (args->trans, args->dp,0 ,-1 , &bp);if (error) goto out;if ((forkoff =xfs_attr_shortform_allfit (bp, dp))) {xfs_bmap_init (args->flist, args->firstblock); - error =xfs_attr_leaf_to_shortform (bp, args, forkoff); + error =xfs_attr3_leaf_to_shortform (bp, args, forkoff);/* bp is gone due to xfs_da_shrink_inode */ if (!error) { error = xfs_bmap_finish(&args->trans,
@@ -1768,7 +1768,7 @@ xfs_attr_node_get(xfs_da_args_t *args)/* * Get the value, local or "remote" */ - retval =xfs_attr_leaf_getvalue (blk->bp, args); + retval =xfs_attr3_leaf_getvalue (blk->bp, args);if (!retval && (args->rmtblkno >0 ) && !(args->flags &ATTR_KERNOVAL )) { retval =xfs_attr_rmtval_get (args);
@@ -1793,7 +1793,9 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)attrlist_cursor_kern_t *cursor;xfs_attr_leafblock_t *leaf;xfs_da_intnode_t *node; -xfs_da_node_entry_t *btree; +struct xfs_attr3_icleaf_hdr leafhdr; +struct xfs_da3_icnode_hdr nodehdr; +struct xfs_da_node_entry *btree;int error, i;struct xfs_buf *bp;
@@ -1814,22 +1816,28 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)if ((error !=0 ) && (error !=EFSCORRUPTED ))return (error);if (bp) { +struct xfs_attr_leaf_entry *entries; + node = bp->b_addr;switch (be16_to_cpu (node->hdr.info.magic)) {case XFS_DA_NODE_MAGIC : +case XFS_DA3_NODE_MAGIC :trace_xfs_attr_list_wrong_blk (context);xfs_trans_brelse (NULL , bp); bp =NULL ;break ;case XFS_ATTR_LEAF_MAGIC : +case XFS_ATTR3_LEAF_MAGIC : leaf = bp->b_addr; -if (cursor->hashval >be32_to_cpu (leaf->entries[ -be16_to_cpu (leaf->hdr.count)-1 ].hashval)) { +xfs_attr3_leaf_hdr_from_disk (&leafhdr, leaf); + entries =xfs_attr3_leaf_entryp (leaf); +if (cursor->hashval >be32_to_cpu ( + entries[leafhdr.count -1 ].hashval)) {trace_xfs_attr_list_wrong_blk (context);xfs_trans_brelse (NULL , bp); bp =NULL ; - }else if (cursor->hashval <= -be32_to_cpu (leaf->entries[0 ].hashval)) { + }else if (cursor->hashval <=be32_to_cpu ( + entries[0 ].hashval)) {trace_xfs_attr_list_wrong_blk (context);xfs_trans_brelse (NULL , bp); bp =NULL ;
@@ -1851,27 +1859,31 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)if (bp ==NULL ) { cursor->blkno =0 ;for (;;) { +__uint16_t magic; + error =xfs_da3_node_read (NULL , context->dp, cursor->blkno,-1 , &bp,XFS_ATTR_FORK );if (error)return (error); node = bp->b_addr; -if (node->hdr.info.magic == -cpu_to_be16 (XFS_ATTR_LEAF_MAGIC )) + magic =be16_to_cpu (node->hdr.info.magic); +if (magic ==XFS_ATTR_LEAF_MAGIC || + magic ==XFS_ATTR3_LEAF_MAGIC )break ; -if (unlikely (node->hdr.info.magic != -cpu_to_be16 (XFS_DA_NODE_MAGIC ))) { +if (magic !=XFS_DA_NODE_MAGIC && + magic !=XFS_DA3_NODE_MAGIC ) {XFS_CORRUPTION_ERROR ("xfs_attr_node_list(3)" ,XFS_ERRLEVEL_LOW , context->dp->i_mount, node);xfs_trans_brelse (NULL , bp); -return (XFS_ERROR (EFSCORRUPTED )); +return XFS_ERROR (EFSCORRUPTED ); } + +xfs_da3_node_hdr_from_disk (&nodehdr, node); btree =xfs_da3_node_tree_p (node); -for (i =0 ; i <be16_to_cpu (node->hdr.count); - btree++, i++) { +for (i =0 ; i < nodehdr.count; btree++, i++) {if (cursor->hashval <=be32_to_cpu (btree->hashval)) { cursor->blkno =be32_to_cpu (btree->before);
@@ -1880,9 +1892,9 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)break ; } } -if (i ==be16_to_cpu (node->hdr.count)) { +if (i == nodehdr.count) {xfs_trans_brelse (NULL , bp); -return (0 ); +return 0 ; }xfs_trans_brelse (NULL , bp); }
@@ -1896,22 +1908,23 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)*/ for (;;) { leaf = bp->b_addr; - error =xfs_attr_leaf_list_int (bp, context); + error =xfs_attr3_leaf_list_int (bp, context);if (error) {xfs_trans_brelse (NULL , bp);return error; } -if (context->seen_enough || leaf->hdr.info.forw ==0 ) +xfs_attr3_leaf_hdr_from_disk (&leafhdr, leaf); +if (context->seen_enough || leafhdr.forw ==0 )break ; - cursor->blkno =be32_to_cpu (leaf->hdr.info.forw); + cursor->blkno = leafhdr.forw;xfs_trans_brelse (NULL , bp); - error =xfs_attr_leaf_read (NULL , context->dp, cursor->blkno,-1 , + error =xfs_attr3_leaf_read (NULL , context->dp, cursor->blkno,-1 , &bp);if (error)return error; }xfs_trans_brelse (NULL , bp); -return (0 ); +return 0 ; }
fs/xfs/xfs_attr_leaf.c +989 -749
2,628 lines not on this page · raw message
fs/xfs/xfs_attr_leaf.h +94 -27
121 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Part of the diff is not shown here. View the raw message.
PATCH 16/16 xfs: add CRC checks to the superblock
In reply to Dave ChinnerFrom: Dave Chinner <[email protected]>
With the addition of CRCs, there is such a wide and varied change to the on disk format that it makes sense to bump the superblock version number rather than try to use feature bits for all the new functionality.
This commit introduces all the new superblock fields needed for all the new functionality: feature masks similar to ext4, separate project quota inodes, a LSN field for recovery and the CRC field.
This commit does not bump the superblock version number, however. That will be done as a separate commit at the end of the series after all the new functionality is present so we switch it all on in one commit. This means that we can slowly introduce the changes without them being active and hence maintain bisectability of the tree.
This patch is based on a patch originally written by myself back from SGI days, which was subsequently modified by Christoph Hellwig. There is relatively little of that patch remaining, but the history of the patch still should be acknowledged here.
--- fs/xfs/xfs_buf_item.h | 4 +- fs/xfs/xfs_log_recover.c | 8 ++++ fs/xfs/xfs_mount.c | 97 ++++++++++++++++++++++++++++++++++++-------- fs/xfs/xfs_mount.h | 1 + fs/xfs/xfs_sb.h | 100 ++++++++++++++++++++++++++++++++-------------- 5 files changed, 164 insertions(+), 46 deletions(-)
fs/xfs/xfs_buf_item.h +3 -1
@@ -50,6 +50,7 @@ extern kmem_zone_t *xfs_buf_item_zone;#define XFS_BLF_AGI_BUF (1<<8)#define XFS_BLF_DINO_BUF (1<<9)#define XFS_BLF_SYMLINK_BUF (1<<10) +#define XFS_BLF_SB_BUF (1<<11)#define XFS_BLF_TYPE_MASK \ (XFS_BLF_UDQUOT_BUF | \
@@ -60,7 +61,8 @@ extern kmem_zone_t *xfs_buf_item_zone; XFS_BLF_AGFL_BUF | \ XFS_BLF_AGI_BUF | \ XFS_BLF_DINO_BUF | \ - XFS_BLF_SYMLINK_BUF) + XFS_BLF_SYMLINK_BUF | \ + XFS_BLF_SB_BUF)#define XFS_BLF_CHUNK 128#define XFS_BLF_SHIFT 7
fs/xfs/xfs_log_recover.c +8 -0
@@ -2017,6 +2017,14 @@ xlog_recover_do_reg_buffer( } bp->b_ops = &xfs_symlink_buf_ops;break ; +case XFS_BLF_SB_BUF : +if (*(__be32 *)bp->b_addr !=cpu_to_be32 (XFS_SB_MAGIC )) { +xfs_warn (mp,"Bad SB block magic!" ); +ASSERT (0 ); +break ; + } + bp->b_ops = &xfs_sb_buf_ops; +break ;default :break ; }
fs/xfs/xfs_mount.c +81 -16
186 lines not on this page · raw message
fs/xfs/xfs_mount.h +1 -0
@@ -392,6 +392,7 @@ extern void xfs_set_low_space_thresholds(struct xfs_mount *);#endif /* __KERNEL__ */ +extern void xfs_sb_calc_crc (struct xfs_buf *);extern void xfs_mod_sb (struct xfs_trans *,__int64_t );extern int xfs_initialize_perag (struct xfs_mount *,xfs_agnumber_t ,xfs_agnumber_t *);
fs/xfs/xfs_sb.h +71 -29
229 lines not on this page · raw message
Signature · 6 lines
1.7.10 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs