xfsprogs: libxfs sync v6.17
cover xfsprogs: libxfs sync v6.17
Hey all,
This is libxfs sync with v6.17.
Manual modifications diff in attachment.
Signature · 1 line
- Andrey
db/attrset.c +1 -5
@@ -823,11 +823,7 @@return 0 ; } - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf (_ ("failed to allocate empty transaction\n" )); -return 0 ; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_iget (mp,NULL , iocur_top->ino,0 , &ip);if (error) {
db/dquot.c +1 -3
@@ -92,9 +92,7 @@xfs_ino_t ret =NULLFSINO ;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -return NULLFSINO ; + tp =libxfs_trans_alloc_empty (mp);if (xfs_has_metadir (mp)) { error = -libxfs_dqinode_load_parent (tp, &dp);
db/fsmap.c +1 -7
@@ -133,13 +133,7 @@struct xfs_btree_cur *bt_cur;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf ( -_ ("Cannot alloc transaction to look up rtgroup %u rmap inode\n" ), -rtg_rgno (rtg)); -return error; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load_parent (tp);if (error) {
db/info.c +1 -7
@@ -174,13 +174,7 @@xfs_filblks_t used =0 ;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf ( -_ ("Cannot alloc transaction to look up rtgroup %u rmap inode\n" ), -rtg_rgno (rtg)); -return ; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load_parent (tp);if (error) {
db/metadump.c +1 -1
@@ -2989,7 +2989,7 @@if (metadump.obfuscate) {struct xfs_sb *sb = iocur_top->data;memset (sb->sb_fname,'L' , -min (strlen (sb->sb_fname),sizeof (sb->sb_fname))); +strnlen (sb->sb_fname,sizeof (sb->sb_fname))); iocur_top->need_crc =1 ; }if (write_buf (iocur_top))
db/namei.c +1 -3
@@ -94,9 +94,7 @@unsigned int i;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -return error; + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_iget (mp, tp, ino,0 , &dp);if (error)
db/rdump.c +1 -6
@@ -926,15 +926,10 @@set_cur_inode (mp->m_sb.sb_rootino); } - ret = -libxfs_trans_alloc_empty (mp, &tp); -if (ret) { -dbprintf (_ ("allocating state: %s\n" ),strerror (ret)); - goto out_pbuf; - } + tp =libxfs_trans_alloc_empty (mp); ret =rdump_file (tp, iocur_top->ino, destdir, pbuf);libxfs_trans_cancel (tp); -out_pbuf:free (pbuf);return ret; }
include/platform_defs.h +13 -0
@@ -294,4 +294,17 @@ __a > __b ? (__a - __b) : (__b - __a); \ }) +#define cmp_int (l, r) ((l > r) - (l < r)) + +#if __has_attribute (__nonstring__) +# define __nonstring __attribute__((__nonstring__)) +#else +# define __nonstring +#endif + +struct kvec { +void *iov_base; +size_t iov_len; +}; +#endif /* __XFS_PLATFORM_DEFS_H__ */
include/xfs_trans.h +1 -1
@@ -98,7 +98,7 @@ struct xfs_trans **tpp, int *nospace_error);int libxfs_trans_alloc_rollable (struct xfs_mount *mp,uint blocks,struct xfs_trans **tpp); -int libxfs_trans_alloc_empty (struct xfs_mount *mp,struct xfs_trans **tpp); +struct xfs_trans *libxfs_trans_alloc_empty (struct xfs_mount *mp);int libxfs_trans_commit (struct xfs_trans *);void libxfs_trans_cancel (struct xfs_trans *); int libxfs_trans_reserve_more(struct xfs_trans *tp, uint blocks,
libxfs/inode.c +1 -3
@@ -258,9 +258,7 @@struct xfs_trans *tp;int error; - error =libxfs_trans_alloc_empty (mp, &tp); -if (error) -return error; + tp =libxfs_trans_alloc_empty (mp); error =libxfs_trans_metafile_iget (tp, ino, metafile_type, ipp);libxfs_trans_cancel (tp);
libxfs/trans.c +22 -15
@@ -247,18 +247,12 @@return error; } -int -libxfs_trans_alloc ( +static inline struct xfs_trans * +__libxfs_trans_alloc (struct xfs_mount *mp, -struct xfs_trans_res *resp, -unsigned int blocks, -unsigned int rtextents, -unsigned int flags, -struct xfs_trans **tpp) - +uint flags) {struct xfs_trans *tp; -int error; tp =kmem_cache_zalloc (xfs_trans_cache,0 ); tp->t_mountp = mp;
@@ -266,6 +260,22 @@INIT_LIST_HEAD (&tp->t_dfops); tp->t_highest_agno =NULLAGNUMBER ; +return tp; +} + +int +libxfs_trans_alloc ( +struct xfs_mount *mp, +struct xfs_trans_res *resp, +unsigned int blocks, +unsigned int rtextents, +unsigned int flags, +struct xfs_trans **tpp) + +{ +struct xfs_trans *tp =__libxfs_trans_alloc (mp, flags); +int error; + error =xfs_trans_reserve (tp, resp, blocks, rtextents);if (error) {xfs_trans_cancel (tp);
@@ -290,14 +300,11 @@* Note the zero-length reservation; this transaction MUST be cancelled * without any dirty data. */ -int +struct xfs_trans *libxfs_trans_alloc_empty ( -struct xfs_mount *mp, -struct xfs_trans **tpp) +struct xfs_mount *mp) { -struct xfs_trans_res resv = {0 }; - -return xfs_trans_alloc (mp, &resv,0 ,0 ,XFS_TRANS_NO_WRITECOUNT , tpp); +return __libxfs_trans_alloc (mp,XFS_TRANS_NO_WRITECOUNT ); }/*
libxlog/xfs_log_recover.c +7 -7
@@ -1034,13 +1034,13 @@ item = list_entry(trans->r_itemq.prev, struct xlog_recover_item, ri_list); - old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; - old_len = item->ri_buf[item->ri_cnt-1 ].i_len; + old_ptr = item->ri_buf[item->ri_cnt-1 ].iov_base; + old_len = item->ri_buf[item->ri_cnt-1 ].iov_len; ptr =krealloc (old_ptr, len+old_len,0 );memcpy (&ptr[old_len], dp, len);/* d, s, l */ - item->ri_buf[item->ri_cnt-1 ].i_len += len; - item->ri_buf[item->ri_cnt-1 ].i_addr = ptr; + item->ri_buf[item->ri_cnt-1 ].iov_len += len; + item->ri_buf[item->ri_cnt-1 ].iov_base = ptr;trace_xfs_log_recover_item_add_cont (log, trans, item,0 );return 0 ; }
@@ -1117,8 +1117,8 @@ }ASSERT (item->ri_total > item->ri_cnt);/* Description region is ri_buf[0] */ - item->ri_buf[item->ri_cnt].i_addr = ptr; - item->ri_buf[item->ri_cnt].i_len = len; + item->ri_buf[item->ri_cnt].iov_base = ptr; + item->ri_buf[item->ri_cnt].iov_len = len; item->ri_cnt++;trace_xfs_log_recover_item_add (log, trans, item,0 );return 0 ;
@@ -1140,7 +1140,7 @@/* Free the regions in the item. */ list_del (&item->ri_list);for (i =0 ; i < item->ri_cnt; i++) -kfree (item->ri_buf[i].i_addr); +kfree (item->ri_buf[i].iov_base);/* Free the item itself */ kfree (item->ri_buf);kfree (item);
logprint/log_print_all.c +30 -29
144 lines not on this page · raw message
logprint/log_redo.c +26 -26
148 lines not on this page · raw message
repair/phase2.c +1 -5
@@ -296,11 +296,7 @@* there while we try to make a per-AG reservation with the new * geometry. */ - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error ( -_ ("Cannot reserve resources for upgrade check, err=%d.\n" ), - error); + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_ialloc_read_agi (pag, tp,0 , &agi_bp);if (error)
repair/pptr.c +2 -2
@@ -1217,7 +1217,7 @@ fscan->have_garbage = false; fscan->nr_file_pptrs =0 ; -libxfs_trans_alloc_empty (ip->i_mount, &tp); + tp =libxfs_trans_alloc_empty (ip->i_mount); error =xattr_walk (tp, ip, examine_xattr, fscan);if (tp)libxfs_trans_cancel (tp);
@@ -1417,7 +1417,7 @@do_error ("init garbage pptr names failed: %s\n" ,strerror (error)); -libxfs_trans_alloc_empty (ip->i_mount, &tp); + tp =libxfs_trans_alloc_empty (ip->i_mount); error =xattr_walk (tp, ip, erase_pptrs, &fscan);if (tp)libxfs_trans_cancel (tp);
repair/quotacheck.c +2 -7
@@ -437,9 +437,7 @@if (!dquots || !chkd_flags)return ; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("could not alloc transaction to open quota file\n" )); + tp =libxfs_trans_alloc_empty (mp); ino =get_quota_inode (type); error = -libxfs_trans_metafile_iget (tp, ino, metafile_type, &ip);
@@ -679,9 +677,7 @@struct xfs_inode *dp =NULL ;int error, err2; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out; + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_dqinode_load_parent (tp, &dp);if (error)
@@ -698,7 +694,6 @@libxfs_irele (dp); out_cancel:libxfs_trans_cancel (tp); -out:if (error) {switch (error) {case EFSCORRUPTED :
repair/rcbag.c +2 -6
@@ -95,9 +95,7 @@int has;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for refcount bag update\n" )); + tp =libxfs_trans_alloc_empty (mp); cur =rcbagbt_mem_cursor (mp, tp, &bag->xfbtree); error =rcbagbt_lookup_eq (cur, rmap, &has);
@@ -217,9 +215,7 @@int has;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for refcount bag update\n" )); + tp =libxfs_trans_alloc_empty (mp);/* go to the right edge of the tree */ cur =rcbagbt_mem_cursor (mp, tp, &bag->xfbtree);
repair/rcbag_btree.c +6 -6
@@ -46,8 +46,8 @@ bag_rec->rbg_refcount = bag_irec->rbg_refcount; } -STATIC int64_t -rcbagbt_key_diff ( +STATIC int +rcbagbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -72,8 +72,8 @@return 0 ; } -STATIC int64_t -rcbagbt_diff_two_keys( +STATIC int +rcbagbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -220,9 +220,9 @@ .init_key_from_rec = rcbagbt_init_key_from_rec, .init_rec_from_cur = rcbagbt_init_rec_from_cur, .init_ptr_from_cur = xfbtree_init_ptr_from_cur, - .key_diff = rcbagbt_key_diff, + .cmp_key_with_cur = rcbagbt_cmp_key_with_cur, .buf_ops = &rcbagbt_mem_buf_ops, - .diff_two_keys = rcbagbt_diff_two_keys, + .cmp_two_keys = rcbagbt_cmp_two_keys, .keys_inorder = rcbagbt_keys_inorder, .recs_inorder = rcbagbt_recs_inorder, };
repair/rmap.c +1 -3
@@ -323,9 +323,7 @@int error; xfbt = &rmaps_for_group (isrt, agno)->ar_xfbtree; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for in-memory rmap update\n" )); + tp =libxfs_trans_alloc_empty (mp); error =rmap_init_mem_cursor (mp, tp, isrt, agno, &rmcur);if (error)
repair/rt.c +2 -8
@@ -301,10 +301,7 @@if (rtg->rtg_inodes[type]) goto out_rtg; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out_rtg; - + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load (rtg, type, tp);if (error)
@@ -497,9 +494,7 @@int error, err2;int i; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out; + tp =libxfs_trans_alloc_empty (mp);if (xfs_has_rtgroups (mp) && mp->m_sb.sb_rgcount >0 ) { error = -libxfs_rtginode_load_parent (tp);if (error)
@@ -516,7 +511,6 @@ out_cancel:libxfs_trans_cancel (tp); -out:if (xfs_has_rtgroups (mp) && error) {/* * Old xfs_repair didn't complain if rtbitmaps didn't load
scrub/inodes.c +0 -2
@@ -197,8 +197,6 @@return seen_mask; } -#define cmp_int (l, r) ((l > r) - (l < r)) -/* Compare two bulkstat records by inumber. */ static int compare_bstat(
PATCH 1/11 xfs: rename diff_two_keys routines
Source kernel commit: edce172444b4f489715a3df2e5d50893e74ce3da
One may think that diff_two_keys routines are used to compute the actual difference between the arguments but they return a result of a three-way-comparison of the passed operands. So it looks more appropriate to denote them as cmp_two_keys.
Found by Linux Verification Center (linuxtesting.org).
--- libxfs/xfs_alloc_btree.c | 8 ++++---- libxfs/xfs_bmap_btree.c | 4 ++-- libxfs/xfs_btree.c | 2 +- libxfs/xfs_btree.h | 26 +++++++++++++------------- libxfs/xfs_ialloc_btree.c | 6 +++--- libxfs/xfs_refcount_btree.c | 4 ++-- libxfs/xfs_rmap_btree.c | 6 +++--- libxfs/xfs_rtrefcount_btree.c | 4 ++-- libxfs/xfs_rtrmap_btree.c | 6 +++--- repair/rcbag_btree.c | 4 ++-- 10 files changed, 35 insertions(+), 35 deletions(-)
libxfs/xfs_alloc_btree.c +4 -4
@@ -212,7 +212,7 @@ } STATIC int64_t -xfs_bnobt_diff_two_keys( +xfs_bnobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -225,7 +225,7 @@ } STATIC int64_t -xfs_cntbt_diff_two_keys( +xfs_cntbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -438,7 +438,7 @@ .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, .key_diff = xfs_bnobt_key_diff, .buf_ops = &xfs_bnobt_buf_ops, - .diff_two_keys = xfs_bnobt_diff_two_keys, + .cmp_two_keys = xfs_bnobt_cmp_two_keys, .keys_inorder = xfs_bnobt_keys_inorder, .recs_inorder = xfs_bnobt_recs_inorder, .keys_contiguous = xfs_allocbt_keys_contiguous,
@@ -468,7 +468,7 @@ .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, .key_diff = xfs_cntbt_key_diff, .buf_ops = &xfs_cntbt_buf_ops, - .diff_two_keys = xfs_cntbt_diff_two_keys, + .cmp_two_keys = xfs_cntbt_cmp_two_keys, .keys_inorder = xfs_cntbt_keys_inorder, .recs_inorder = xfs_cntbt_recs_inorder, .keys_contiguous = NULL, /* not needed right now */
libxfs/xfs_bmap_btree.c +2 -2
@@ -378,7 +378,7 @@ } STATIC int64_t -xfs_bmbt_diff_two_keys( +xfs_bmbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -647,7 +647,7 @@ .init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec, .init_rec_from_cur = xfs_bmbt_init_rec_from_cur, .key_diff = xfs_bmbt_key_diff, - .diff_two_keys = xfs_bmbt_diff_two_keys, + .cmp_two_keys = xfs_bmbt_cmp_two_keys, .buf_ops = &xfs_bmbt_buf_ops, .keys_inorder = xfs_bmbt_keys_inorder, .recs_inorder = xfs_bmbt_recs_inorder,
libxfs/xfs_btree.c +1 -1
@@ -5055,7 +5055,7 @@int error;ASSERT (cur->bc_ops->init_high_key_from_rec); -ASSERT (cur->bc_ops->diff_two_keys); +ASSERT (cur->bc_ops->cmp_two_keys);/* * Find the leftmost record. The btree cursor must be set
libxfs/xfs_btree.h +13 -13
@@ -176,15 +176,15 @@ const union xfs_btree_key *key);/* -* Difference between key2 and key1 -- positive if key1 > key2, -* negative if key1 < key2, and zero if equal. If the @mask parameter -* is non NULL, each key field to be used in the comparison must -* contain a nonzero value. +* Compare key1 and key2 -- positive if key1 > key2, negative if +* key1 < key2, and zero if equal. If the @mask parameter is non NULL, +* each key field to be used in the comparison must contain a nonzero +* value. */ -int64_t (*diff_two_keys)(struct xfs_btree_cur *cur, -const union xfs_btree_key *key1, -const union xfs_btree_key *key2, -const union xfs_btree_key *mask); +int64_t (*cmp_two_keys)(struct xfs_btree_cur *cur, +const union xfs_btree_key *key1, +const union xfs_btree_key *key2, +const union xfs_btree_key *mask);const struct xfs_buf_ops *buf_ops;
@@ -546,7 +546,7 @@const union xfs_btree_key *key1, const union xfs_btree_key *key2) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, NULL) < 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, NULL) < 0; } static inline bool
@@ -555,7 +555,7 @@const union xfs_btree_key *key1, const union xfs_btree_key *key2) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, NULL) > 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, NULL) > 0; } static inline bool
@@ -564,7 +564,7 @@const union xfs_btree_key *key1, const union xfs_btree_key *key2) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, NULL) == 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, NULL) == 0; } static inline bool
@@ -602,7 +602,7 @@const union xfs_btree_key *key2, const union xfs_btree_key *mask) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, mask) < 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, mask) < 0; } static inline bool
@@ -612,7 +612,7 @@const union xfs_btree_key *key2, const union xfs_btree_key *mask) { - return cur->bc_ops->diff_two_keys(cur, key1, key2, mask) > 0; + return cur->bc_ops->cmp_two_keys(cur, key1, key2, mask) > 0; } static inline bool
libxfs/xfs_ialloc_btree.c +3 -3
@@ -274,7 +274,7 @@ } STATIC int64_t -xfs_inobt_diff_two_keys( +xfs_inobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -431,7 +431,7 @@ .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur, .key_diff = xfs_inobt_key_diff, .buf_ops = &xfs_inobt_buf_ops, - .diff_two_keys = xfs_inobt_diff_two_keys, + .cmp_two_keys = xfs_inobt_cmp_two_keys, .keys_inorder = xfs_inobt_keys_inorder, .recs_inorder = xfs_inobt_recs_inorder, .keys_contiguous = xfs_inobt_keys_contiguous,
@@ -461,7 +461,7 @@ .init_ptr_from_cur = xfs_finobt_init_ptr_from_cur, .key_diff = xfs_inobt_key_diff, .buf_ops = &xfs_finobt_buf_ops, - .diff_two_keys = xfs_inobt_diff_two_keys, + .cmp_two_keys = xfs_inobt_cmp_two_keys, .keys_inorder = xfs_inobt_keys_inorder, .recs_inorder = xfs_inobt_recs_inorder, .keys_contiguous = xfs_inobt_keys_contiguous,
libxfs/xfs_refcount_btree.c +2 -2
@@ -188,7 +188,7 @@ } STATIC int64_t -xfs_refcountbt_diff_two_keys( +xfs_refcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -340,7 +340,7 @@ .init_ptr_from_cur = xfs_refcountbt_init_ptr_from_cur, .key_diff = xfs_refcountbt_key_diff, .buf_ops = &xfs_refcountbt_buf_ops, - .diff_two_keys = xfs_refcountbt_diff_two_keys, + .cmp_two_keys = xfs_refcountbt_cmp_two_keys, .keys_inorder = xfs_refcountbt_keys_inorder, .recs_inorder = xfs_refcountbt_recs_inorder, .keys_contiguous = xfs_refcountbt_keys_contiguous,
libxfs/xfs_rmap_btree.c +3 -3
@@ -273,7 +273,7 @@ } STATIC int64_t -xfs_rmapbt_diff_two_keys( +xfs_rmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -516,7 +516,7 @@ .init_ptr_from_cur = xfs_rmapbt_init_ptr_from_cur, .key_diff = xfs_rmapbt_key_diff, .buf_ops = &xfs_rmapbt_buf_ops, - .diff_two_keys = xfs_rmapbt_diff_two_keys, + .cmp_two_keys = xfs_rmapbt_cmp_two_keys, .keys_inorder = xfs_rmapbt_keys_inorder, .recs_inorder = xfs_rmapbt_recs_inorder, .keys_contiguous = xfs_rmapbt_keys_contiguous,
@@ -633,7 +633,7 @@ .init_ptr_from_cur = xfbtree_init_ptr_from_cur, .key_diff = xfs_rmapbt_key_diff, .buf_ops = &xfs_rmapbt_mem_buf_ops, - .diff_two_keys = xfs_rmapbt_diff_two_keys, + .cmp_two_keys = xfs_rmapbt_cmp_two_keys, .keys_inorder = xfs_rmapbt_keys_inorder, .recs_inorder = xfs_rmapbt_recs_inorder, .keys_contiguous = xfs_rmapbt_keys_contiguous,
libxfs/xfs_rtrefcount_btree.c +2 -2
@@ -169,7 +169,7 @@ } STATIC int64_t -xfs_rtrefcountbt_diff_two_keys( +xfs_rtrefcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -387,7 +387,7 @@ .init_ptr_from_cur = xfs_rtrefcountbt_init_ptr_from_cur, .key_diff = xfs_rtrefcountbt_key_diff, .buf_ops = &xfs_rtrefcountbt_buf_ops, - .diff_two_keys = xfs_rtrefcountbt_diff_two_keys, + .cmp_two_keys = xfs_rtrefcountbt_cmp_two_keys, .keys_inorder = xfs_rtrefcountbt_keys_inorder, .recs_inorder = xfs_rtrefcountbt_recs_inorder, .keys_contiguous = xfs_rtrefcountbt_keys_contiguous,
libxfs/xfs_rtrmap_btree.c +3 -3
@@ -215,7 +215,7 @@ } STATIC int64_t -xfs_rtrmapbt_diff_two_keys( +xfs_rtrmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -512,7 +512,7 @@ .init_ptr_from_cur = xfs_rtrmapbt_init_ptr_from_cur, .key_diff = xfs_rtrmapbt_key_diff, .buf_ops = &xfs_rtrmapbt_buf_ops, - .diff_two_keys = xfs_rtrmapbt_diff_two_keys, + .cmp_two_keys = xfs_rtrmapbt_cmp_two_keys, .keys_inorder = xfs_rtrmapbt_keys_inorder, .recs_inorder = xfs_rtrmapbt_recs_inorder, .keys_contiguous = xfs_rtrmapbt_keys_contiguous,
@@ -621,7 +621,7 @@ .init_ptr_from_cur = xfbtree_init_ptr_from_cur, .key_diff = xfs_rtrmapbt_key_diff, .buf_ops = &xfs_rtrmapbt_mem_buf_ops, - .diff_two_keys = xfs_rtrmapbt_diff_two_keys, + .cmp_two_keys = xfs_rtrmapbt_cmp_two_keys, .keys_inorder = xfs_rtrmapbt_keys_inorder, .recs_inorder = xfs_rtrmapbt_recs_inorder, .keys_contiguous = xfs_rtrmapbt_keys_contiguous,
repair/rcbag_btree.c +2 -2
@@ -73,7 +73,7 @@ } STATIC int64_t -rcbagbt_diff_two_keys( +rcbagbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,
@@ -222,7 +222,7 @@ .init_ptr_from_cur = xfbtree_init_ptr_from_cur, .key_diff = rcbagbt_key_diff, .buf_ops = &rcbagbt_mem_buf_ops, - .diff_two_keys = rcbagbt_diff_two_keys, + .cmp_two_keys = rcbagbt_cmp_two_keys, .keys_inorder = rcbagbt_keys_inorder, .recs_inorder = rcbagbt_recs_inorder, };
PATCH 2/11 xfs: rename key_diff routines
In reply to Andrey AlbershteynSource kernel commit: 82b63ee160016096436aa026a27c8d85d40f3fb1
key_diff routines compare a key value with a cursor value. Make the naming to be a bit more self-descriptive.
Found by Linux Verification Center (linuxtesting.org).
--- libxfs/xfs_alloc_btree.c | 8 ++++---- libxfs/xfs_bmap_btree.c | 4 ++-- libxfs/xfs_btree.c | 2 +- libxfs/xfs_btree.h | 9 ++++++--- libxfs/xfs_ialloc_btree.c | 6 +++--- libxfs/xfs_refcount_btree.c | 4 ++-- libxfs/xfs_rmap_btree.c | 6 +++--- libxfs/xfs_rtrefcount_btree.c | 4 ++-- libxfs/xfs_rtrmap_btree.c | 6 +++--- repair/rcbag_btree.c | 4 ++-- 10 files changed, 28 insertions(+), 25 deletions(-)
libxfs/xfs_alloc_btree.c +4 -4
@@ -185,7 +185,7 @@ } STATIC int64_t -xfs_bnobt_key_diff ( +xfs_bnobt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -196,7 +196,7 @@ } STATIC int64_t -xfs_cntbt_key_diff ( +xfs_cntbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -436,7 +436,7 @@ .init_high_key_from_rec = xfs_bnobt_init_high_key_from_rec, .init_rec_from_cur = xfs_allocbt_init_rec_from_cur, .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, - .key_diff = xfs_bnobt_key_diff, + .cmp_key_with_cur = xfs_bnobt_cmp_key_with_cur, .buf_ops = &xfs_bnobt_buf_ops, .cmp_two_keys = xfs_bnobt_cmp_two_keys, .keys_inorder = xfs_bnobt_keys_inorder,
@@ -466,7 +466,7 @@ .init_high_key_from_rec = xfs_cntbt_init_high_key_from_rec, .init_rec_from_cur = xfs_allocbt_init_rec_from_cur, .init_ptr_from_cur = xfs_allocbt_init_ptr_from_cur, - .key_diff = xfs_cntbt_key_diff, + .cmp_key_with_cur = xfs_cntbt_cmp_key_with_cur, .buf_ops = &xfs_cntbt_buf_ops, .cmp_two_keys = xfs_cntbt_cmp_two_keys, .keys_inorder = xfs_cntbt_keys_inorder,
libxfs/xfs_bmap_btree.c +2 -2
@@ -369,7 +369,7 @@ } STATIC int64_t -xfs_bmbt_key_diff ( +xfs_bmbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -646,7 +646,7 @@ .init_key_from_rec = xfs_bmbt_init_key_from_rec, .init_high_key_from_rec = xfs_bmbt_init_high_key_from_rec, .init_rec_from_cur = xfs_bmbt_init_rec_from_cur, - .key_diff = xfs_bmbt_key_diff, + .cmp_key_with_cur = xfs_bmbt_cmp_key_with_cur, .cmp_two_keys = xfs_bmbt_cmp_two_keys, .buf_ops = &xfs_bmbt_buf_ops, .keys_inorder = xfs_bmbt_keys_inorder,
libxfs/xfs_btree.c +1 -1
@@ -2067,7 +2067,7 @@* - greater than, move left * - equal, we're done */ - diff = cur->bc_ops->key_diff (cur, kp); + diff = cur->bc_ops->cmp_key_with_cur (cur, kp);if (diff <0 ) low = keyno +1 ;else if (diff >0 )
libxfs/xfs_btree.h +6 -3
@@ -171,9 +171,12 @@void (*init_high_key_from_rec)(union xfs_btree_key *key,const union xfs_btree_rec *rec); -/* difference between key value and cursor value */ -int64_t (*key_diff)(struct xfs_btree_cur *cur, -const union xfs_btree_key *key); +/* +* Compare key value and cursor value -- positive if key > cur, +* negative if key < cur, and zero if equal. +*/ +int64_t (*cmp_key_with_cur)(struct xfs_btree_cur *cur, +const union xfs_btree_key *key);/* * Compare key1 and key2 -- positive if key1 > key2, negative if
libxfs/xfs_ialloc_btree.c +3 -3
@@ -265,7 +265,7 @@ } STATIC int64_t -xfs_inobt_key_diff ( +xfs_inobt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -429,7 +429,7 @@ .init_high_key_from_rec = xfs_inobt_init_high_key_from_rec, .init_rec_from_cur = xfs_inobt_init_rec_from_cur, .init_ptr_from_cur = xfs_inobt_init_ptr_from_cur, - .key_diff = xfs_inobt_key_diff, + .cmp_key_with_cur = xfs_inobt_cmp_key_with_cur, .buf_ops = &xfs_inobt_buf_ops, .cmp_two_keys = xfs_inobt_cmp_two_keys, .keys_inorder = xfs_inobt_keys_inorder,
@@ -459,7 +459,7 @@ .init_high_key_from_rec = xfs_inobt_init_high_key_from_rec, .init_rec_from_cur = xfs_inobt_init_rec_from_cur, .init_ptr_from_cur = xfs_finobt_init_ptr_from_cur, - .key_diff = xfs_inobt_key_diff, + .cmp_key_with_cur = xfs_inobt_cmp_key_with_cur, .buf_ops = &xfs_finobt_buf_ops, .cmp_two_keys = xfs_inobt_cmp_two_keys, .keys_inorder = xfs_inobt_keys_inorder,
libxfs/xfs_refcount_btree.c +2 -2
@@ -174,7 +174,7 @@ } STATIC int64_t -xfs_refcountbt_key_diff ( +xfs_refcountbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -338,7 +338,7 @@ .init_high_key_from_rec = xfs_refcountbt_init_high_key_from_rec, .init_rec_from_cur = xfs_refcountbt_init_rec_from_cur, .init_ptr_from_cur = xfs_refcountbt_init_ptr_from_cur, - .key_diff = xfs_refcountbt_key_diff, + .cmp_key_with_cur = xfs_refcountbt_cmp_key_with_cur, .buf_ops = &xfs_refcountbt_buf_ops, .cmp_two_keys = xfs_refcountbt_cmp_two_keys, .keys_inorder = xfs_refcountbt_keys_inorder,
libxfs/xfs_rmap_btree.c +3 -3
@@ -243,7 +243,7 @@ } STATIC int64_t -xfs_rmapbt_key_diff ( +xfs_rmapbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -514,7 +514,7 @@ .init_high_key_from_rec = xfs_rmapbt_init_high_key_from_rec, .init_rec_from_cur = xfs_rmapbt_init_rec_from_cur, .init_ptr_from_cur = xfs_rmapbt_init_ptr_from_cur, - .key_diff = xfs_rmapbt_key_diff, + .cmp_key_with_cur = xfs_rmapbt_cmp_key_with_cur, .buf_ops = &xfs_rmapbt_buf_ops, .cmp_two_keys = xfs_rmapbt_cmp_two_keys, .keys_inorder = xfs_rmapbt_keys_inorder,
@@ -631,7 +631,7 @@ .init_high_key_from_rec = xfs_rmapbt_init_high_key_from_rec, .init_rec_from_cur = xfs_rmapbt_init_rec_from_cur, .init_ptr_from_cur = xfbtree_init_ptr_from_cur, - .key_diff = xfs_rmapbt_key_diff, + .cmp_key_with_cur = xfs_rmapbt_cmp_key_with_cur, .buf_ops = &xfs_rmapbt_mem_buf_ops, .cmp_two_keys = xfs_rmapbt_cmp_two_keys, .keys_inorder = xfs_rmapbt_keys_inorder,
libxfs/xfs_rtrefcount_btree.c +2 -2
@@ -155,7 +155,7 @@ } STATIC int64_t -xfs_rtrefcountbt_key_diff ( +xfs_rtrefcountbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -385,7 +385,7 @@ .init_high_key_from_rec = xfs_rtrefcountbt_init_high_key_from_rec, .init_rec_from_cur = xfs_rtrefcountbt_init_rec_from_cur, .init_ptr_from_cur = xfs_rtrefcountbt_init_ptr_from_cur, - .key_diff = xfs_rtrefcountbt_key_diff, + .cmp_key_with_cur = xfs_rtrefcountbt_cmp_key_with_cur, .buf_ops = &xfs_rtrefcountbt_buf_ops, .cmp_two_keys = xfs_rtrefcountbt_cmp_two_keys, .keys_inorder = xfs_rtrefcountbt_keys_inorder,
libxfs/xfs_rtrmap_btree.c +3 -3
@@ -185,7 +185,7 @@ } STATIC int64_t -xfs_rtrmapbt_key_diff ( +xfs_rtrmapbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -510,7 +510,7 @@ .init_high_key_from_rec = xfs_rtrmapbt_init_high_key_from_rec, .init_rec_from_cur = xfs_rtrmapbt_init_rec_from_cur, .init_ptr_from_cur = xfs_rtrmapbt_init_ptr_from_cur, - .key_diff = xfs_rtrmapbt_key_diff, + .cmp_key_with_cur = xfs_rtrmapbt_cmp_key_with_cur, .buf_ops = &xfs_rtrmapbt_buf_ops, .cmp_two_keys = xfs_rtrmapbt_cmp_two_keys, .keys_inorder = xfs_rtrmapbt_keys_inorder,
@@ -619,7 +619,7 @@ .init_high_key_from_rec = xfs_rtrmapbt_init_high_key_from_rec, .init_rec_from_cur = xfs_rtrmapbt_init_rec_from_cur, .init_ptr_from_cur = xfbtree_init_ptr_from_cur, - .key_diff = xfs_rtrmapbt_key_diff, + .cmp_key_with_cur = xfs_rtrmapbt_cmp_key_with_cur, .buf_ops = &xfs_rtrmapbt_mem_buf_ops, .cmp_two_keys = xfs_rtrmapbt_cmp_two_keys, .keys_inorder = xfs_rtrmapbt_keys_inorder,
repair/rcbag_btree.c +2 -2
@@ -47,7 +47,7 @@ } STATIC int64_t -rcbagbt_key_diff ( +rcbagbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {
@@ -220,7 +220,7 @@ .init_key_from_rec = rcbagbt_init_key_from_rec, .init_rec_from_cur = rcbagbt_init_rec_from_cur, .init_ptr_from_cur = xfbtree_init_ptr_from_cur, - .key_diff = rcbagbt_key_diff, + .cmp_key_with_cur = rcbagbt_cmp_key_with_cur, .buf_ops = &rcbagbt_mem_buf_ops, .cmp_two_keys = rcbagbt_cmp_two_keys, .keys_inorder = rcbagbt_keys_inorder,
PATCH 3/11 xfs: refactor cmp_two_keys routines to take advantage of cmp_int()
In reply to Andrey AlbershteynSource kernel commit: 3b583adf55c649d5ba37bcd1ca87644b0bc10b86
The net value of these functions is to determine the result of a three-way-comparison between operands of the same type.
Simplify the code using cmp_int() to eliminate potential errors with opencoded casts and subtractions. This also means we can change the return value type of cmp_two_keys routines from int64_t to int and make the interface a bit clearer.
Found by Linux Verification Center (linuxtesting.org).
--- include/platform_defs.h | 2 ++ libxfs/xfs_alloc_btree.c | 21 ++++++++------------- libxfs/xfs_bmap_btree.c | 18 +++--------------- libxfs/xfs_btree.h | 2 +- libxfs/xfs_ialloc_btree.c | 6 +++--- libxfs/xfs_refcount_btree.c | 6 +++--- libxfs/xfs_rmap_btree.c | 29 ++++++++++++----------------- libxfs/xfs_rtrefcount_btree.c | 6 +++--- libxfs/xfs_rtrmap_btree.c | 29 ++++++++++++----------------- repair/rcbag_btree.c | 2 +- scrub/inodes.c | 2 -- 11 files changed, 48 insertions(+), 75 deletions(-)
include/platform_defs.h +2 -0
@@ -294,4 +294,6 @@ __a > __b ? (__a - __b) : (__b - __a); \ }) +#define cmp_int (l, r) ((l > r) - (l < r)) +#endif /* __XFS_PLATFORM_DEFS_H__ */
libxfs/xfs_alloc_btree.c +8 -13
@@ -211,7 +211,7 @@return (int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; } -STATIC int64_t +STATIC int xfs_bnobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
@@ -220,29 +220,24 @@ {ASSERT (!mask || mask->alloc.ar_startblock); -return (int64_t )be32_to_cpu (k1->alloc.ar_startblock) - -be32_to_cpu (k2->alloc.ar_startblock); +return cmp_int (be32_to_cpu (k1->alloc.ar_startblock), +be32_to_cpu (k2->alloc.ar_startblock)); } -STATIC int64_t +STATIC intxfs_cntbt_cmp_two_keys (struct xfs_btree_cur *cur,const union xfs_btree_key *k1,const union xfs_btree_key *k2,const union xfs_btree_key *mask) { -int64_t diff; -ASSERT (!mask || (mask->alloc.ar_blockcount && mask->alloc.ar_startblock)); - diff =be32_to_cpu (k1->alloc.ar_blockcount) - -be32_to_cpu (k2->alloc.ar_blockcount); -if (diff) -return diff; - -return be32_to_cpu (k1->alloc.ar_startblock) - -be32_to_cpu (k2->alloc.ar_startblock); +return cmp_int (be32_to_cpu (k1->alloc.ar_blockcount), +be32_to_cpu (k2->alloc.ar_blockcount)) ?: +cmp_int (be32_to_cpu (k1->alloc.ar_startblock), +be32_to_cpu (k2->alloc.ar_startblock)); } static xfs_failaddr_t
libxfs/xfs_bmap_btree.c +3 -15
@@ -377,29 +377,17 @@ cur->bc_rec.b.br_startoff; } -STATIC int64_t +STATIC intxfs_bmbt_cmp_two_keys (struct xfs_btree_cur *cur,const union xfs_btree_key *k1,const union xfs_btree_key *k2,const union xfs_btree_key *mask) { -uint64_t a =be64_to_cpu (k1->bmbt.br_startoff); -uint64_t b =be64_to_cpu (k2->bmbt.br_startoff); -ASSERT (!mask || mask->bmbt.br_startoff); -/* -* Note: This routine previously casted a and b to int64 and subtracted -* them to generate a result. This lead to problems if b was the -* "maximum" key value (all ones) being signed incorrectly, hence this -* somewhat less efficient version. -*/ -if (a > b) -return 1 ; -if (b > a) -return -1 ; -return 0 ; +return cmp_int (be64_to_cpu (k1->bmbt.br_startoff), +be64_to_cpu (k2->bmbt.br_startoff)); } static xfs_failaddr_t
libxfs/xfs_btree.h +1 -1
@@ -184,7 +184,7 @@* each key field to be used in the comparison must contain a nonzero * value. */ -int64_t (*cmp_two_keys)(struct xfs_btree_cur *cur, +int (*cmp_two_keys)(struct xfs_btree_cur *cur,const union xfs_btree_key *key1,const union xfs_btree_key *key2,const union xfs_btree_key *mask);
libxfs/xfs_ialloc_btree.c +3 -3
@@ -273,7 +273,7 @@ cur->bc_rec.i.ir_startino; } -STATIC int64_t +STATIC int xfs_inobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
@@ -282,8 +282,8 @@ {ASSERT (!mask || mask->inobt.ir_startino); -return (int64_t )be32_to_cpu (k1->inobt.ir_startino) - -be32_to_cpu (k2->inobt.ir_startino); +return cmp_int (be32_to_cpu (k1->inobt.ir_startino), +be32_to_cpu (k2->inobt.ir_startino)); } static xfs_failaddr_t
libxfs/xfs_refcount_btree.c +3 -3
@@ -187,7 +187,7 @@return (int64_t )be32_to_cpu (kp->rc_startblock) - start; } -STATIC int64_t +STATIC int xfs_refcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
@@ -196,8 +196,8 @@ {ASSERT (!mask || mask->refc.rc_startblock); -return (int64_t )be32_to_cpu (k1->refc.rc_startblock) - -be32_to_cpu (k2->refc.rc_startblock); +return cmp_int (be32_to_cpu (k1->refc.rc_startblock), +be32_to_cpu (k2->refc.rc_startblock)); }STATIC xfs_failaddr_t
libxfs/xfs_rmap_btree.c +12 -17
@@ -272,7 +272,7 @@return 0 ; } -STATIC int64_t +STATIC int xfs_rmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
@@ -281,36 +281,31 @@ {const struct xfs_rmap_key *kp1 = &k1->rmap;const struct xfs_rmap_key *kp2 = &k2->rmap; -int64_t d; -__u64 x, y; +int d;/* Doesn't make sense to mask off the physical space part */ ASSERT (!mask || mask->rmap.rm_startblock); - d = (int64_t )be32_to_cpu (kp1->rm_startblock) - -be32_to_cpu (kp2->rm_startblock); + d =cmp_int (be32_to_cpu (kp1->rm_startblock), +be32_to_cpu (kp2->rm_startblock));if (d)return d;if (!mask || mask->rmap.rm_owner) { - x =be64_to_cpu (kp1->rm_owner); - y =be64_to_cpu (kp2->rm_owner); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (be64_to_cpu (kp1->rm_owner), +be64_to_cpu (kp2->rm_owner)); +if (d) +return d; }if (!mask || mask->rmap.rm_offset) {/* Doesn't make sense to allow offset but not owner */ ASSERT (!mask || mask->rmap.rm_owner); - x =offset_keymask (be64_to_cpu (kp1->rm_offset)); - y =offset_keymask (be64_to_cpu (kp2->rm_offset)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (offset_keymask (be64_to_cpu (kp1->rm_offset)), +offset_keymask (be64_to_cpu (kp2->rm_offset))); +if (d) +return d; }return 0 ;
libxfs/xfs_rtrefcount_btree.c +3 -3
@@ -168,7 +168,7 @@return (int64_t )be32_to_cpu (kp->rc_startblock) - start; } -STATIC int64_t +STATIC int xfs_rtrefcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
@@ -177,8 +177,8 @@ {ASSERT (!mask || mask->refc.rc_startblock); -return (int64_t )be32_to_cpu (k1->refc.rc_startblock) - -be32_to_cpu (k2->refc.rc_startblock); +return cmp_int (be32_to_cpu (k1->refc.rc_startblock), +be32_to_cpu (k2->refc.rc_startblock)); } static xfs_failaddr_t
libxfs/xfs_rtrmap_btree.c +12 -17
@@ -214,7 +214,7 @@return 0 ; } -STATIC int64_t +STATIC int xfs_rtrmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
@@ -223,36 +223,31 @@ {const struct xfs_rmap_key *kp1 = &k1->rmap;const struct xfs_rmap_key *kp2 = &k2->rmap; -int64_t d; -__u64 x, y; +int d;/* Doesn't make sense to mask off the physical space part */ ASSERT (!mask || mask->rmap.rm_startblock); - d = (int64_t )be32_to_cpu (kp1->rm_startblock) - -be32_to_cpu (kp2->rm_startblock); + d =cmp_int (be32_to_cpu (kp1->rm_startblock), +be32_to_cpu (kp2->rm_startblock));if (d)return d;if (!mask || mask->rmap.rm_owner) { - x =be64_to_cpu (kp1->rm_owner); - y =be64_to_cpu (kp2->rm_owner); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (be64_to_cpu (kp1->rm_owner), +be64_to_cpu (kp2->rm_owner)); +if (d) +return d; }if (!mask || mask->rmap.rm_offset) {/* Doesn't make sense to allow offset but not owner */ ASSERT (!mask || mask->rmap.rm_owner); - x =offset_keymask (be64_to_cpu (kp1->rm_offset)); - y =offset_keymask (be64_to_cpu (kp2->rm_offset)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (offset_keymask (be64_to_cpu (kp1->rm_offset)), +offset_keymask (be64_to_cpu (kp2->rm_offset))); +if (d) +return d; }return 0 ;
repair/rcbag_btree.c +1 -1
@@ -72,7 +72,7 @@return 0 ; } -STATIC int64_t +STATIC int rcbagbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
scrub/inodes.c +0 -2
@@ -197,8 +197,6 @@return seen_mask; } -#define cmp_int (l, r) ((l > r) - (l < r)) -/* Compare two bulkstat records by inumber. */ static int compare_bstat(
Re: [PATCH 3/11] [PATCH] xfs: refactor cmp_two_keys routines to take advantage of cmp_int()
Quoted 341 lines · Fedor Pchelkin
Source kernel commit:
3b583adf55c649d5ba37bcd1ca87644b0bc10b86The net value of these functions is to determine the result of a three-way-comparison between operands of the same type.
Simplify the code using
cmp_int()to eliminate potential errors with opencoded casts and subtractions. This also means we can change the return value type ofcmp_two_keysroutines fromint64_tto int and make the interface a bit clearer.Found by Linux Verification Center (linuxtesting.org).
Suggested-by Darrick J. Wong <[email protected]>Signed-off-by Fedor Pchelkin <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Carlos Maiolino <[email protected]>Signed-off-by Andrey Albershteyn <[email protected]>--- include/platform_defs.h | 2 ++ libxfs/xfs_alloc_btree.c | 21 ++++++++------------- libxfs/xfs_bmap_btree.c | 18 +++--------------- libxfs/xfs_btree.h | 2 +- libxfs/xfs_ialloc_btree.c | 6 +++--- libxfs/xfs_refcount_btree.c | 6 +++--- libxfs/xfs_rmap_btree.c | 29 ++++++++++++----------------- libxfs/xfs_rtrefcount_btree.c | 6 +++--- libxfs/xfs_rtrmap_btree.c | 29 ++++++++++++----------------- repair/rcbag_btree.c | 2 +- scrub/inodes.c | 2 -- 11 files changed, 48 insertions(+), 75 deletions(-)include/platform_defs.h +2
-0@@ -294,4 +294,6 @@ __a > __b ? (__a - __b) : (__b - __a); \ }) +#define cmp_int (l, r) ((l > r) - (l < r)) +#endif /* __XFS_PLATFORM_DEFS_H__ */ libxfs/xfs_alloc_btree.c +8
-13@@ -211,7 +211,7 @@return (int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; } -STATIC int64_t +STATIC int xfs_bnobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,@@ -220,29 +220,24 @@ {ASSERT (!mask || mask->alloc.ar_startblock); -return (int64_t )be32_to_cpu (k1->alloc.ar_startblock) - -be32_to_cpu (k2->alloc.ar_startblock); +return cmp_int (be32_to_cpu (k1->alloc.ar_startblock), +be32_to_cpu (k2->alloc.ar_startblock)); } -STATIC int64_t +STATIC intxfs_cntbt_cmp_two_keys (struct xfs_btree_cur *cur,const union xfs_btree_key *k1,const union xfs_btree_key *k2,const union xfs_btree_key *mask) { -int64_t diff; -ASSERT (!mask || (mask->alloc.ar_blockcount && mask->alloc.ar_startblock)); - diff =be32_to_cpu (k1->alloc.ar_blockcount) - -be32_to_cpu (k2->alloc.ar_blockcount); -if (diff) -return diff; - -return be32_to_cpu (k1->alloc.ar_startblock) - -be32_to_cpu (k2->alloc.ar_startblock); +return cmp_int (be32_to_cpu (k1->alloc.ar_blockcount), +be32_to_cpu (k2->alloc.ar_blockcount)) ?: +cmp_int (be32_to_cpu (k1->alloc.ar_startblock), +be32_to_cpu (k2->alloc.ar_startblock)); } static xfs_failaddr_tlibxfs/xfs_bmap_btree.c +3
-15@@ -377,29 +377,17 @@ cur->bc_rec.b.br_startoff; } -STATIC int64_t +STATIC intxfs_bmbt_cmp_two_keys (struct xfs_btree_cur *cur,const union xfs_btree_key *k1,const union xfs_btree_key *k2,const union xfs_btree_key *mask) { -uint64_t a =be64_to_cpu (k1->bmbt.br_startoff); -uint64_t b =be64_to_cpu (k2->bmbt.br_startoff); -ASSERT (!mask || mask->bmbt.br_startoff); -/* -* Note: This routine previously casted a and b to int64 and subtracted -* them to generate a result. This lead to problems if b was the -* "maximum" key value (all ones) being signed incorrectly, hence this -* somewhat less efficient version. -*/ -if (a > b) -return 1 ; -if (b > a) -return -1 ; -return 0 ; +return cmp_int (be64_to_cpu (k1->bmbt.br_startoff), +be64_to_cpu (k2->bmbt.br_startoff)); } static xfs_failaddr_tlibxfs/xfs_btree.h +1
-1@@ -184,7 +184,7 @@* each key field to be used in the comparison must contain a nonzero * value. */ -int64_t (*cmp_two_keys)(struct xfs_btree_cur *cur, +int (*cmp_two_keys)(struct xfs_btree_cur *cur,const union xfs_btree_key *key1,const union xfs_btree_key *key2,const union xfs_btree_key *mask);libxfs/xfs_ialloc_btree.c +3
-3@@ -273,7 +273,7 @@ cur->bc_rec.i.ir_startino; } -STATIC int64_t +STATIC int xfs_inobt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,@@ -282,8 +282,8 @@ {ASSERT (!mask || mask->inobt.ir_startino); -return (int64_t )be32_to_cpu (k1->inobt.ir_startino) - -be32_to_cpu (k2->inobt.ir_startino); +return cmp_int (be32_to_cpu (k1->inobt.ir_startino), +be32_to_cpu (k2->inobt.ir_startino)); } static xfs_failaddr_tlibxfs/xfs_refcount_btree.c +3
-3@@ -187,7 +187,7 @@return (int64_t )be32_to_cpu (kp->rc_startblock) - start; } -STATIC int64_t +STATIC int xfs_refcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,@@ -196,8 +196,8 @@ {ASSERT (!mask || mask->refc.rc_startblock); -return (int64_t )be32_to_cpu (k1->refc.rc_startblock) - -be32_to_cpu (k2->refc.rc_startblock); +return cmp_int (be32_to_cpu (k1->refc.rc_startblock), +be32_to_cpu (k2->refc.rc_startblock)); }STATIC xfs_failaddr_tlibxfs/xfs_rmap_btree.c +12
-17@@ -272,7 +272,7 @@return 0 ; } -STATIC int64_t +STATIC int xfs_rmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,@@ -281,36 +281,31 @@ {const struct xfs_rmap_key *kp1 = &k1->rmap;const struct xfs_rmap_key *kp2 = &k2->rmap; -int64_t d; -__u64 x, y; +int d;/* Doesn't make sense to mask off the physical space part */ ASSERT (!mask || mask->rmap.rm_startblock); - d = (int64_t )be32_to_cpu (kp1->rm_startblock) - -be32_to_cpu (kp2->rm_startblock); + d =cmp_int (be32_to_cpu (kp1->rm_startblock), +be32_to_cpu (kp2->rm_startblock));if (d)return d;if (!mask || mask->rmap.rm_owner) { - x =be64_to_cpu (kp1->rm_owner); - y =be64_to_cpu (kp2->rm_owner); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (be64_to_cpu (kp1->rm_owner), +be64_to_cpu (kp2->rm_owner)); +if (d) +return d; }if (!mask || mask->rmap.rm_offset) {/* Doesn't make sense to allow offset but not owner */ ASSERT (!mask || mask->rmap.rm_owner); - x =offset_keymask (be64_to_cpu (kp1->rm_offset)); - y =offset_keymask (be64_to_cpu (kp2->rm_offset)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (offset_keymask (be64_to_cpu (kp1->rm_offset)), +offset_keymask (be64_to_cpu (kp2->rm_offset))); +if (d) +return d; }return 0 ;libxfs/xfs_rtrefcount_btree.c +3
-3@@ -168,7 +168,7 @@return (int64_t )be32_to_cpu (kp->rc_startblock) - start; } -STATIC int64_t +STATIC int xfs_rtrefcountbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,@@ -177,8 +177,8 @@ {ASSERT (!mask || mask->refc.rc_startblock); -return (int64_t )be32_to_cpu (k1->refc.rc_startblock) - -be32_to_cpu (k2->refc.rc_startblock); +return cmp_int (be32_to_cpu (k1->refc.rc_startblock), +be32_to_cpu (k2->refc.rc_startblock)); } static xfs_failaddr_tlibxfs/xfs_rtrmap_btree.c +12
-17@@ -214,7 +214,7 @@return 0 ; } -STATIC int64_t +STATIC int xfs_rtrmapbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,@@ -223,36 +223,31 @@ {const struct xfs_rmap_key *kp1 = &k1->rmap;const struct xfs_rmap_key *kp2 = &k2->rmap; -int64_t d; -__u64 x, y; +int d;/* Doesn't make sense to mask off the physical space part */ ASSERT (!mask || mask->rmap.rm_startblock); - d = (int64_t )be32_to_cpu (kp1->rm_startblock) - -be32_to_cpu (kp2->rm_startblock); + d =cmp_int (be32_to_cpu (kp1->rm_startblock), +be32_to_cpu (kp2->rm_startblock));if (d)return d;if (!mask || mask->rmap.rm_owner) { - x =be64_to_cpu (kp1->rm_owner); - y =be64_to_cpu (kp2->rm_owner); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (be64_to_cpu (kp1->rm_owner), +be64_to_cpu (kp2->rm_owner)); +if (d) +return d; }if (!mask || mask->rmap.rm_offset) {/* Doesn't make sense to allow offset but not owner */ ASSERT (!mask || mask->rmap.rm_owner); - x =offset_keymask (be64_to_cpu (kp1->rm_offset)); - y =offset_keymask (be64_to_cpu (kp2->rm_offset)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; + d =cmp_int (offset_keymask (be64_to_cpu (kp1->rm_offset)), +offset_keymask (be64_to_cpu (kp2->rm_offset))); +if (d) +return d; }return 0 ;repair/rcbag_btree.c +0
-0
repair/rcbag_btree.c line 78
Quoted 8 lines
repair/rcbag_btree.c +1
-1@@ -72,7 +72,7 @@return 0 ; } -STATIC int64_t +STATIC int rcbagbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1,
Dumb nit: You could port this one too:
@@ -81,25 +81,19 @@ rcbagbt_cmp_two_keys(
{
const struct rcbag_key *kp1 = (const struct rcbag_key *)k1;
const struct rcbag_key *kp2 = (const struct rcbag_key *)k2;
+ int d;
ASSERT(mask == NULL);
- if (kp1->rbg_startblock > kp2->rbg_startblock)
- return 1;
- if (kp1->rbg_startblock < kp2->rbg_startblock)
- return -1;
-
- if (kp1->rbg_blockcount > kp2->rbg_blockcount)
- return 1;
- if (kp1->rbg_blockcount < kp2->rbg_blockcount)
- return -1;
+ d = cmp_int(kp1->rbg_startblock, kp2->rbg_startblock);
+ if (d)
+ return d;
- if (kp1->rbg_ino > kp2->rbg_ino)
- return 1;
- if (kp1->rbg_ino < kp2->rbg_ino)
- return -1;
+ d = cmp_int(kp1->rbg_blockcount, kp2->rbg_blockcount);
+ if (d)
+ return d;
- return 0;
+ return cmp_int(kp1->rbg_ino, kp2->rbg_ino);
}
STATIC int
--D
Quoted 13 lines
scrub/inodes.c +0
-2@@ -197,8 +197,6 @@return seen_mask; } -#define cmp_int (l, r) ((l > r) - (l < r)) -/* Compare two bulkstat records by inumber. */ static int compare_bstat(
PATCH 4/11 xfs: refactor cmp_key_with_cur routines to take advantage of cmp_int()
In reply to Andrey AlbershteynSource kernel commit: 734b871d6cf7d4f815bb1eff8c808289079701c2
The net value of these functions is to determine the result of a three-way-comparison between operands of the same type.
Simplify the code using cmp_int() to eliminate potential errors with opencoded casts and subtractions. This also means we can change the return value type of cmp_key_with_cur routines from int64_t to int and make the interface a bit clearer.
Found by Linux Verification Center (linuxtesting.org).
--- libxfs/xfs_alloc_btree.c | 17 +++++++---------- libxfs/xfs_bmap_btree.c | 6 +++--- libxfs/xfs_btree.h | 2 +- libxfs/xfs_ialloc_btree.c | 6 +++--- libxfs/xfs_refcount_btree.c | 4 ++-- libxfs/xfs_rmap_btree.c | 28 ++++++---------------------- libxfs/xfs_rtrefcount_btree.c | 4 ++-- libxfs/xfs_rtrmap_btree.c | 28 ++++++---------------------- repair/rcbag_btree.c | 2 +- 9 files changed, 31 insertions(+), 66 deletions(-)
libxfs/xfs_alloc_btree.c +7 -10
@@ -184,7 +184,7 @@ ptr->s = agf->agf_cnt_root; } -STATIC int64_t +STATIC intxfs_bnobt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)
@@ -192,23 +192,20 @@struct xfs_alloc_rec_incore *rec = &cur->bc_rec.a;const struct xfs_alloc_rec *kp = &key->alloc; -return (int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; +return cmp_int (be32_to_cpu (kp->ar_startblock), + rec->ar_startblock); } -STATIC int64_t +STATIC intxfs_cntbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {struct xfs_alloc_rec_incore *rec = &cur->bc_rec.a;const struct xfs_alloc_rec *kp = &key->alloc; -int64_t diff; - - diff = (int64_t )be32_to_cpu (kp->ar_blockcount) - rec->ar_blockcount; -if (diff) -return diff; - -return (int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; + +return cmp_int (be32_to_cpu (kp->ar_blockcount), rec->ar_blockcount) ?: +cmp_int (be32_to_cpu (kp->ar_startblock), rec->ar_startblock); }STATIC int
libxfs/xfs_bmap_btree.c +3 -3
@@ -368,13 +368,13 @@xfs_bmbt_disk_set_all (&rec->bmbt, &cur->bc_rec.b); } -STATIC int64_t +STATIC intxfs_bmbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) { -return (int64_t )be64_to_cpu (key->bmbt.br_startoff) - - cur->bc_rec.b.br_startoff; +return cmp_int (be64_to_cpu (key->bmbt.br_startoff), + cur->bc_rec.b.br_startoff); }STATIC int
libxfs/xfs_btree.h +1 -1
@@ -175,7 +175,7 @@* Compare key value and cursor value -- positive if key > cur, * negative if key < cur, and zero if equal. */ -int64_t (*cmp_key_with_cur)(struct xfs_btree_cur *cur, +int (*cmp_key_with_cur)(struct xfs_btree_cur *cur,const union xfs_btree_key *key);/*
libxfs/xfs_ialloc_btree.c +3 -3
@@ -264,13 +264,13 @@ ptr->s = agi->agi_free_root; } -STATIC int64_t +STATIC intxfs_inobt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) { -return (int64_t )be32_to_cpu (key->inobt.ir_startino) - - cur->bc_rec.i.ir_startino; +return cmp_int (be32_to_cpu (key->inobt.ir_startino), + cur->bc_rec.i.ir_startino); }STATIC int
libxfs/xfs_refcount_btree.c +2 -2
@@ -173,7 +173,7 @@ ptr->s = agf->agf_refcount_root; } -STATIC int64_t +STATIC intxfs_refcountbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)
@@ -184,7 +184,7 @@ start =xfs_refcount_encode_startblock (irec->rc_startblock, irec->rc_domain); -return (int64_t )be32_to_cpu (kp->rc_startblock) - start; +return cmp_int (be32_to_cpu (kp->rc_startblock), start); }STATIC int
libxfs/xfs_rmap_btree.c +6 -22
@@ -242,34 +242,18 @@return offset & ~XFS_RMAP_OFF_UNWRITTEN ; } -STATIC int64_t +STATIC intxfs_rmapbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {struct xfs_rmap_irec *rec = &cur->bc_rec.r;const struct xfs_rmap_key *kp = &key->rmap; -__u64 x, y; -int64_t d; - - d = (int64_t )be32_to_cpu (kp->rm_startblock) - rec->rm_startblock; -if (d) -return d; - - x =be64_to_cpu (kp->rm_owner); - y = rec->rm_owner; -if (x > y) -return 1 ; -else if (y > x) -return -1 ; - - x =offset_keymask (be64_to_cpu (kp->rm_offset)); - y =offset_keymask (xfs_rmap_irec_offset_pack (rec)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; -return 0 ; + +return cmp_int (be32_to_cpu (kp->rm_startblock), rec->rm_startblock) ?: +cmp_int (be64_to_cpu (kp->rm_owner), rec->rm_owner) ?: +cmp_int (offset_keymask (be64_to_cpu (kp->rm_offset)), +offset_keymask (xfs_rmap_irec_offset_pack (rec))); }STATIC int
libxfs/xfs_rtrefcount_btree.c +2 -2
@@ -154,7 +154,7 @@ ptr->l =0 ; } -STATIC int64_t +STATIC intxfs_rtrefcountbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)
@@ -165,7 +165,7 @@ start =xfs_refcount_encode_startblock (irec->rc_startblock, irec->rc_domain); -return (int64_t )be32_to_cpu (kp->rc_startblock) - start; +return cmp_int (be32_to_cpu (kp->rc_startblock), start); }STATIC int
libxfs/xfs_rtrmap_btree.c +6 -22
@@ -184,34 +184,18 @@return offset & ~XFS_RMAP_OFF_UNWRITTEN ; } -STATIC int64_t +STATIC intxfs_rtrmapbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {struct xfs_rmap_irec *rec = &cur->bc_rec.r;const struct xfs_rmap_key *kp = &key->rmap; -__u64 x, y; -int64_t d; - - d = (int64_t )be32_to_cpu (kp->rm_startblock) - rec->rm_startblock; -if (d) -return d; - - x =be64_to_cpu (kp->rm_owner); - y = rec->rm_owner; -if (x > y) -return 1 ; -else if (y > x) -return -1 ; - - x =offset_keymask (be64_to_cpu (kp->rm_offset)); - y =offset_keymask (xfs_rmap_irec_offset_pack (rec)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; -return 0 ; + +return cmp_int (be32_to_cpu (kp->rm_startblock), rec->rm_startblock) ?: +cmp_int (be64_to_cpu (kp->rm_owner), rec->rm_owner) ?: +cmp_int (offset_keymask (be64_to_cpu (kp->rm_offset)), +offset_keymask (xfs_rmap_irec_offset_pack (rec))); }STATIC int
repair/rcbag_btree.c +1 -1
@@ -46,7 +46,7 @@ bag_rec->rbg_refcount = bag_irec->rbg_refcount; } -STATIC int64_t +STATIC intrcbagbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)
Re: [PATCH 4/11] [PATCH] xfs: refactor cmp_key_with_cur routines to take advantage of cmp_int()
Quoted 266 lines · Fedor Pchelkin
Source kernel commit:
734b871d6cf7d4f815bb1eff8c808289079701c2The net value of these functions is to determine the result of a three-way-comparison between operands of the same type.
Simplify the code using
cmp_int()to eliminate potential errors with opencoded casts and subtractions. This also means we can change the return value type ofcmp_key_with_curroutines fromint64_tto int and make the interface a bit clearer.Found by Linux Verification Center (linuxtesting.org).
Suggested-by Darrick J. Wong <[email protected]>Signed-off-by Fedor Pchelkin <[email protected]>Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Carlos Maiolino <[email protected]>Signed-off-by Andrey Albershteyn <[email protected]>--- libxfs/xfs_alloc_btree.c | 17 +++++++---------- libxfs/xfs_bmap_btree.c | 6 +++--- libxfs/xfs_btree.h | 2 +- libxfs/xfs_ialloc_btree.c | 6 +++--- libxfs/xfs_refcount_btree.c | 4 ++-- libxfs/xfs_rmap_btree.c | 28 ++++++---------------------- libxfs/xfs_rtrefcount_btree.c | 4 ++-- libxfs/xfs_rtrmap_btree.c | 28 ++++++---------------------- repair/rcbag_btree.c | 2 +- 9 files changed, 31 insertions(+), 66 deletions(-)libxfs/xfs_alloc_btree.c +7
-10@@ -184,7 +184,7 @@ ptr->s = agf->agf_cnt_root; } -STATIC int64_t +STATIC intxfs_bnobt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)@@ -192,23 +192,20 @@struct xfs_alloc_rec_incore *rec = &cur->bc_rec.a;const struct xfs_alloc_rec *kp = &key->alloc; -return (int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; +return cmp_int (be32_to_cpu (kp->ar_startblock), + rec->ar_startblock); } -STATIC int64_t +STATIC intxfs_cntbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {struct xfs_alloc_rec_incore *rec = &cur->bc_rec.a;const struct xfs_alloc_rec *kp = &key->alloc; -int64_t diff; - - diff = (int64_t )be32_to_cpu (kp->ar_blockcount) - rec->ar_blockcount; -if (diff) -return diff; - -return (int64_t )be32_to_cpu (kp->ar_startblock) - rec->ar_startblock; + +return cmp_int (be32_to_cpu (kp->ar_blockcount), rec->ar_blockcount) ?: +cmp_int (be32_to_cpu (kp->ar_startblock), rec->ar_startblock); }STATIC intlibxfs/xfs_bmap_btree.c +3
-3@@ -368,13 +368,13 @@xfs_bmbt_disk_set_all (&rec->bmbt, &cur->bc_rec.b); } -STATIC int64_t +STATIC intxfs_bmbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) { -return (int64_t )be64_to_cpu (key->bmbt.br_startoff) - - cur->bc_rec.b.br_startoff; +return cmp_int (be64_to_cpu (key->bmbt.br_startoff), + cur->bc_rec.b.br_startoff); }STATIC intlibxfs/xfs_btree.h +1
-1@@ -175,7 +175,7 @@* Compare key value and cursor value -- positive if key > cur, * negative if key < cur, and zero if equal. */ -int64_t (*cmp_key_with_cur)(struct xfs_btree_cur *cur, +int (*cmp_key_with_cur)(struct xfs_btree_cur *cur,const union xfs_btree_key *key);/* libxfs/xfs_ialloc_btree.c +3
-3@@ -264,13 +264,13 @@ ptr->s = agi->agi_free_root; } -STATIC int64_t +STATIC intxfs_inobt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) { -return (int64_t )be32_to_cpu (key->inobt.ir_startino) - - cur->bc_rec.i.ir_startino; +return cmp_int (be32_to_cpu (key->inobt.ir_startino), + cur->bc_rec.i.ir_startino); }STATIC intlibxfs/xfs_refcount_btree.c +2
-2@@ -173,7 +173,7 @@ ptr->s = agf->agf_refcount_root; } -STATIC int64_t +STATIC intxfs_refcountbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)@@ -184,7 +184,7 @@ start =xfs_refcount_encode_startblock (irec->rc_startblock, irec->rc_domain); -return (int64_t )be32_to_cpu (kp->rc_startblock) - start; +return cmp_int (be32_to_cpu (kp->rc_startblock), start); }STATIC intlibxfs/xfs_rmap_btree.c +6
-22@@ -242,34 +242,18 @@return offset & ~XFS_RMAP_OFF_UNWRITTEN ; } -STATIC int64_t +STATIC intxfs_rmapbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {struct xfs_rmap_irec *rec = &cur->bc_rec.r;const struct xfs_rmap_key *kp = &key->rmap; -__u64 x, y; -int64_t d; - - d = (int64_t )be32_to_cpu (kp->rm_startblock) - rec->rm_startblock; -if (d) -return d; - - x =be64_to_cpu (kp->rm_owner); - y = rec->rm_owner; -if (x > y) -return 1 ; -else if (y > x) -return -1 ; - - x =offset_keymask (be64_to_cpu (kp->rm_offset)); - y =offset_keymask (xfs_rmap_irec_offset_pack (rec)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; -return 0 ; + +return cmp_int (be32_to_cpu (kp->rm_startblock), rec->rm_startblock) ?: +cmp_int (be64_to_cpu (kp->rm_owner), rec->rm_owner) ?: +cmp_int (offset_keymask (be64_to_cpu (kp->rm_offset)), +offset_keymask (xfs_rmap_irec_offset_pack (rec))); }STATIC intlibxfs/xfs_rtrefcount_btree.c +2
-2@@ -154,7 +154,7 @@ ptr->l =0 ; } -STATIC int64_t +STATIC intxfs_rtrefcountbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)@@ -165,7 +165,7 @@ start =xfs_refcount_encode_startblock (irec->rc_startblock, irec->rc_domain); -return (int64_t )be32_to_cpu (kp->rc_startblock) - start; +return cmp_int (be32_to_cpu (kp->rc_startblock), start); }STATIC intlibxfs/xfs_rtrmap_btree.c +6
-22@@ -184,34 +184,18 @@return offset & ~XFS_RMAP_OFF_UNWRITTEN ; } -STATIC int64_t +STATIC intxfs_rtrmapbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {struct xfs_rmap_irec *rec = &cur->bc_rec.r;const struct xfs_rmap_key *kp = &key->rmap; -__u64 x, y; -int64_t d; - - d = (int64_t )be32_to_cpu (kp->rm_startblock) - rec->rm_startblock; -if (d) -return d; - - x =be64_to_cpu (kp->rm_owner); - y = rec->rm_owner; -if (x > y) -return 1 ; -else if (y > x) -return -1 ; - - x =offset_keymask (be64_to_cpu (kp->rm_offset)); - y =offset_keymask (xfs_rmap_irec_offset_pack (rec)); -if (x > y) -return 1 ; -else if (y > x) -return -1 ; -return 0 ; + +return cmp_int (be32_to_cpu (kp->rm_startblock), rec->rm_startblock) ?: +cmp_int (be64_to_cpu (kp->rm_owner), rec->rm_owner) ?: +cmp_int (offset_keymask (be64_to_cpu (kp->rm_offset)), +offset_keymask (xfs_rmap_irec_offset_pack (rec))); }STATIC intrepair/rcbag_btree.c +0
-0
repair/rcbag_btree.c line 52
Quoted 8 lines
repair/rcbag_btree.c +1
-1@@ -46,7 +46,7 @@ bag_rec->rbg_refcount = bag_irec->rbg_refcount; } -STATIC int64_t +STATIC intrcbagbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key)
Same here, this could be ported to cmp_int.
--D
PATCH 5/11 xfs: use a proper variable name and type for storing a comparison result
In reply to Andrey AlbershteynSource kernel commit: 2717eb35185581988799bb0d5179409978f36a90
Perhaps that's just my silly imagination but 'diff' doesn't look good for the name of a variable to hold a result of a three-way-comparison (-1, 0, 1) which is what ->cmp_key_with_cur() does. It implies to contain an actual difference between the two integer variables but that's not true anymore after recent refactoring.
Declaring it as int64_t is also misleading now. Plain integer type is more than enough.
Found by Linux Verification Center (linuxtesting.org).
--- libxfs/xfs_btree.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
libxfs/xfs_btree.c +12 -11
@@ -1982,7 +1982,7 @@ int *stat) /* success/failure */ {struct xfs_btree_block *block;/* current btree block */ -int64_t diff;/* difference for the current key */ +int cmp_r;/* current key comparison result */ int error;/* error return value */ int keyno;/* current key number */ int level;/* level in the btree */
@@ -2010,13 +2010,13 @@* on the lookup record, then follow the corresponding block * pointer down to the next level. */ -for (level = cur->bc_nlevels -1 , diff =1 ; level >=0 ; level--) { +for (level = cur->bc_nlevels -1 , cmp_r =1 ; level >=0 ; level--) {/* Get the block we need to do the lookup on. */ error =xfs_btree_lookup_get_block (cur, level, pp, &block);if (error) goto error0; -if (diff ==0 ) { +if (cmp_r ==0 ) {/* * If we already had a key match at a higher level, we * know we need to use the first entry in this block.
@@ -2062,15 +2062,16 @@ keyno, block, &key);/* -* Compute difference to get next direction: +* Compute comparison result to get next +* direction: * - less than, move right * - greater than, move left * - equal, we're done */ - diff = cur->bc_ops->cmp_key_with_cur (cur, kp); -if (diff <0 ) + cmp_r = cur->bc_ops->cmp_key_with_cur (cur, kp); +if (cmp_r <0 ) low = keyno +1 ; -else if (diff >0 ) +else if (cmp_r >0 ) high = keyno -1 ;else break ;
@@ -2086,7 +2087,7 @@* If we moved left, need the previous key number, * unless there isn't one. */ -if (diff >0 && --keyno <1 ) +if (cmp_r >0 && --keyno <1 ) keyno =1 ; pp =xfs_btree_ptr_addr (cur, keyno, block);
@@ -2099,7 +2100,7 @@ }/* Done with the search. See if we need to adjust the results. */ -if (dir !=XFS_LOOKUP_LE && diff <0 ) { +if (dir !=XFS_LOOKUP_LE && cmp_r <0 ) { keyno++;/* * If ge search and we went off the end of the block, but it's
@@ -2122,14 +2123,14 @@ *stat =1 ;return 0 ; } - }else if (dir ==XFS_LOOKUP_LE && diff >0 ) + }else if (dir ==XFS_LOOKUP_LE && cmp_r >0 ) keyno--; cur->bc_levels[0 ].ptr = keyno;/* Return if we succeeded or not. */ if (keyno ==0 || keyno >xfs_btree_get_numrecs (block)) *stat =0 ; -else if (dir !=XFS_LOOKUP_EQ || diff ==0 ) +else if (dir !=XFS_LOOKUP_EQ || cmp_r ==0 ) *stat =1 ;else *stat =0 ;
PATCH 6/11 xfs: refactor xfs_btree_diff_two_ptrs() to take advantage of cmp_int()
In reply to Andrey AlbershteynSource kernel commit: ce6cce46aff79423f47680ee65e8f12191a50605
Use cmp_int() to yield the result of a three-way-comparison instead of performing subtractions with extra casts. Thus also rename the function to make its name clearer in purpose.
Found by Linux Verification Center (linuxtesting.org).
--- libxfs/xfs_btree.c | 8 ++++---- libxfs/xfs_btree.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-)
libxfs/xfs_btree.c +4 -4
@@ -5350,15 +5350,15 @@ }/* Compare two btree pointers. */ -int64_t -xfs_btree_diff_two_ptrs ( +int +xfs_btree_cmp_two_ptrs (struct xfs_btree_cur *cur,const union xfs_btree_ptr *a,const union xfs_btree_ptr *b) {if (cur->bc_ops->ptr_len ==XFS_BTREE_LONG_PTR_LEN ) -return (int64_t )be64_to_cpu (a->l) -be64_to_cpu (b->l); -return (int64_t )be32_to_cpu (a->s) -be32_to_cpu (b->s); +return cmp_int (be64_to_cpu (a->l),be64_to_cpu (b->l)); +return cmp_int (be32_to_cpu (a->s),be32_to_cpu (b->s)); }struct xfs_btree_has_records {
libxfs/xfs_btree.h +3 -3
@@ -519,9 +519,9 @@ int level, struct xfs_buf **bpp);bool xfs_btree_ptr_is_null (struct xfs_btree_cur *cur,const union xfs_btree_ptr *ptr); -int64_t xfs_btree_diff_two_ptrs (struct xfs_btree_cur *cur, -const union xfs_btree_ptr *a, -const union xfs_btree_ptr *b); +int xfs_btree_cmp_two_ptrs (struct xfs_btree_cur *cur, +const union xfs_btree_ptr *a, +const union xfs_btree_ptr *b);void xfs_btree_get_sibling (struct xfs_btree_cur *cur,struct xfs_btree_block *block,union xfs_btree_ptr *ptr,int lr);
PATCH 7/11 xfs: return the allocated transaction from xfs_trans_alloc_empty
In reply to Andrey AlbershteynSource kernel commit: d8e1ea43e5a314bc01ec059ce93396639dcf9112
xfs_trans_alloc_empty can't return errors, so return the allocated transaction directly instead of an output double pointer argument.
--- db/attrset.c | 6 +----- db/dquot.c | 4 +--- db/fsmap.c | 8 +------- db/info.c | 8 +------- db/namei.c | 4 +--- db/rdump.c | 7 +------ include/xfs_trans.h | 2 +- libxfs/inode.c | 4 +--- libxfs/trans.c | 37 ++++++++++++++++++++++--------------- libxfs/xfs_refcount.c | 4 +--- repair/phase2.c | 6 +----- repair/pptr.c | 4 ++-- repair/quotacheck.c | 9 ++------- repair/rcbag.c | 8 ++------ repair/rmap.c | 4 +--- repair/rt.c | 10 ++-------- 16 files changed, 41 insertions(+), 84 deletions(-)
db/attrset.c +1 -5
@@ -823,11 +823,7 @@return 0 ; } - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf (_ ("failed to allocate empty transaction\n" )); -return 0 ; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_iget (mp,NULL , iocur_top->ino,0 , &ip);if (error) {
db/dquot.c +1 -3
@@ -92,9 +92,7 @@xfs_ino_t ret =NULLFSINO ;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -return NULLFSINO ; + tp =libxfs_trans_alloc_empty (mp);if (xfs_has_metadir (mp)) { error = -libxfs_dqinode_load_parent (tp, &dp);
db/fsmap.c +1 -7
@@ -133,13 +133,7 @@struct xfs_btree_cur *bt_cur;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf ( -_ ("Cannot alloc transaction to look up rtgroup %u rmap inode\n" ), -rtg_rgno (rtg)); -return error; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load_parent (tp);if (error) {
db/info.c +1 -7
@@ -174,13 +174,7 @@xfs_filblks_t used =0 ;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf ( -_ ("Cannot alloc transaction to look up rtgroup %u rmap inode\n" ), -rtg_rgno (rtg)); -return ; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load_parent (tp);if (error) {
db/namei.c +1 -3
@@ -94,9 +94,7 @@unsigned int i;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -return error; + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_iget (mp, tp, ino,0 , &dp);if (error)
db/rdump.c +1 -6
@@ -926,15 +926,10 @@set_cur_inode (mp->m_sb.sb_rootino); } - ret = -libxfs_trans_alloc_empty (mp, &tp); -if (ret) { -dbprintf (_ ("allocating state: %s\n" ),strerror (ret)); - goto out_pbuf; - } + tp =libxfs_trans_alloc_empty (mp); ret =rdump_file (tp, iocur_top->ino, destdir, pbuf);libxfs_trans_cancel (tp); -out_pbuf:free (pbuf);return ret; }
include/xfs_trans.h +1 -1
@@ -98,7 +98,7 @@ struct xfs_trans **tpp, int *nospace_error);int libxfs_trans_alloc_rollable (struct xfs_mount *mp,uint blocks,struct xfs_trans **tpp); -int libxfs_trans_alloc_empty (struct xfs_mount *mp,struct xfs_trans **tpp); +struct xfs_trans *libxfs_trans_alloc_empty (struct xfs_mount *mp);int libxfs_trans_commit (struct xfs_trans *);void libxfs_trans_cancel (struct xfs_trans *); int libxfs_trans_reserve_more(struct xfs_trans *tp, uint blocks,
libxfs/inode.c +1 -3
@@ -258,9 +258,7 @@struct xfs_trans *tp;int error; - error =libxfs_trans_alloc_empty (mp, &tp); -if (error) -return error; + tp =libxfs_trans_alloc_empty (mp); error =libxfs_trans_metafile_iget (tp, ino, metafile_type, ipp);libxfs_trans_cancel (tp);
libxfs/trans.c +22 -15
@@ -247,18 +247,12 @@return error; } -int -libxfs_trans_alloc ( +static inline struct xfs_trans * +__libxfs_trans_alloc (struct xfs_mount *mp, -struct xfs_trans_res *resp, -unsigned int blocks, -unsigned int rtextents, -unsigned int flags, -struct xfs_trans **tpp) - +uint flags) {struct xfs_trans *tp; -int error; tp =kmem_cache_zalloc (xfs_trans_cache,0 ); tp->t_mountp = mp;
@@ -266,6 +260,22 @@INIT_LIST_HEAD (&tp->t_dfops); tp->t_highest_agno =NULLAGNUMBER ; +return tp; +} + +int +libxfs_trans_alloc ( +struct xfs_mount *mp, +struct xfs_trans_res *resp, +unsigned int blocks, +unsigned int rtextents, +unsigned int flags, +struct xfs_trans **tpp) + +{ +struct xfs_trans *tp =__libxfs_trans_alloc (mp, flags); +int error; + error =xfs_trans_reserve (tp, resp, blocks, rtextents);if (error) {xfs_trans_cancel (tp);
@@ -290,14 +300,11 @@* Note the zero-length reservation; this transaction MUST be cancelled * without any dirty data. */ -int +struct xfs_trans *libxfs_trans_alloc_empty ( -struct xfs_mount *mp, -struct xfs_trans **tpp) +struct xfs_mount *mp) { -struct xfs_trans_res resv = {0 }; - -return xfs_trans_alloc (mp, &resv,0 ,0 ,XFS_TRANS_NO_WRITECOUNT , tpp); +return __libxfs_trans_alloc (mp,XFS_TRANS_NO_WRITECOUNT ); }/*
libxfs/xfs_refcount.c +1 -3
@@ -2097,9 +2097,7 @@* recording the CoW debris we cancel the (empty) transaction * and everything goes away cleanly. */ - error =xfs_trans_alloc_empty (mp, &tp); -if (error) -return error; + tp =xfs_trans_alloc_empty (mp);if (isrt) {xfs_rtgroup_lock (to_rtg (xg),XFS_RTGLOCK_REFCOUNT );
repair/phase2.c +1 -5
@@ -296,11 +296,7 @@* there while we try to make a per-AG reservation with the new * geometry. */ - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error ( -_ ("Cannot reserve resources for upgrade check, err=%d.\n" ), - error); + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_ialloc_read_agi (pag, tp,0 , &agi_bp);if (error)
repair/pptr.c +2 -2
@@ -1217,7 +1217,7 @@ fscan->have_garbage = false; fscan->nr_file_pptrs =0 ; -libxfs_trans_alloc_empty (ip->i_mount, &tp); + tp =libxfs_trans_alloc_empty (ip->i_mount); error =xattr_walk (tp, ip, examine_xattr, fscan);if (tp)libxfs_trans_cancel (tp);
@@ -1417,7 +1417,7 @@do_error ("init garbage pptr names failed: %s\n" ,strerror (error)); -libxfs_trans_alloc_empty (ip->i_mount, &tp); + tp =libxfs_trans_alloc_empty (ip->i_mount); error =xattr_walk (tp, ip, erase_pptrs, &fscan);if (tp)libxfs_trans_cancel (tp);
repair/quotacheck.c +2 -7
@@ -437,9 +437,7 @@if (!dquots || !chkd_flags)return ; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("could not alloc transaction to open quota file\n" )); + tp =libxfs_trans_alloc_empty (mp); ino =get_quota_inode (type); error = -libxfs_trans_metafile_iget (tp, ino, metafile_type, &ip);
@@ -679,9 +677,7 @@struct xfs_inode *dp =NULL ;int error, err2; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out; + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_dqinode_load_parent (tp, &dp);if (error)
@@ -698,7 +694,6 @@libxfs_irele (dp); out_cancel:libxfs_trans_cancel (tp); -out:if (error) {switch (error) {case EFSCORRUPTED :
repair/rcbag.c +2 -6
@@ -95,9 +95,7 @@int has;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for refcount bag update\n" )); + tp =libxfs_trans_alloc_empty (mp); cur =rcbagbt_mem_cursor (mp, tp, &bag->xfbtree); error =rcbagbt_lookup_eq (cur, rmap, &has);
@@ -217,9 +215,7 @@int has;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for refcount bag update\n" )); + tp =libxfs_trans_alloc_empty (mp);/* go to the right edge of the tree */ cur =rcbagbt_mem_cursor (mp, tp, &bag->xfbtree);
repair/rmap.c +1 -3
@@ -323,9 +323,7 @@int error; xfbt = &rmaps_for_group (isrt, agno)->ar_xfbtree; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for in-memory rmap update\n" )); + tp =libxfs_trans_alloc_empty (mp); error =rmap_init_mem_cursor (mp, tp, isrt, agno, &rmcur);if (error)
repair/rt.c +2 -8
@@ -301,10 +301,7 @@if (rtg->rtg_inodes[type]) goto out_rtg; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out_rtg; - + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load (rtg, type, tp);if (error)
@@ -497,9 +494,7 @@int error, err2;int i; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out; + tp =libxfs_trans_alloc_empty (mp);if (xfs_has_rtgroups (mp) && mp->m_sb.sb_rgcount >0 ) { error = -libxfs_rtginode_load_parent (tp);if (error)
@@ -516,7 +511,6 @@ out_cancel:libxfs_trans_cancel (tp); -out:if (xfs_has_rtgroups (mp) && error) {/* * Old xfs_repair didn't complain if rtbitmaps didn't load
PATCH 8/11 xfs: improve the xg_active_ref check in xfs_group_free
In reply to Andrey AlbershteynSource kernel commit: 59655147ec34fb72cc090ca4ee688ece05ffac56
Split up the XFS_IS_CORRUPT statement so that it immediately shows if the reference counter overflowed or underflowed.
I ran into this quite a bit when developing the zoned allocator, and had to reapply the patch for some work recently. We might as well just apply it upstream given that freeing group is far removed from performance critical code.
--- libxfs/xfs_group.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libxfs/xfs_group.c +2 -1
@@ -170,7 +170,8 @@/* drop the mount's active reference */ xfs_group_rele (xg); -XFS_IS_CORRUPT (mp,atomic_read (&xg->xg_active_ref) !=0 ); +XFS_IS_CORRUPT (mp,atomic_read (&xg->xg_active_ref) >0 ); +XFS_IS_CORRUPT (mp,atomic_read (&xg->xg_active_ref) <0 );kfree_rcu_mightsleep (xg); }
PATCH 9/11 fs/xfs: replace strncpy with memtostr_pad()
In reply to Andrey AlbershteynSource kernel commit: f4a3f01e8e451fb3cb444a95a59964f4bc746902
Replace the deprecated strncpy() with memtostr_pad(). This also avoids the need for separate zeroing using memset(). Mark sb_fname buffer with __nonstring as its size is XFSLABEL_MAX and so no terminating NULL for sb_fname.
--- db/metadump.c | 2 +- include/platform_defs.h | 6 ++++++ libxfs/xfs_format.h | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-)
db/metadump.c +1 -1
@@ -2989,7 +2989,7 @@if (metadump.obfuscate) {struct xfs_sb *sb = iocur_top->data;memset (sb->sb_fname,'L' , -min (strlen (sb->sb_fname),sizeof (sb->sb_fname))); +strnlen (sb->sb_fname,sizeof (sb->sb_fname))); iocur_top->need_crc =1 ; }if (write_buf (iocur_top))
include/platform_defs.h +6 -0
@@ -296,4 +296,10 @@#define cmp_int (l, r) ((l > r) - (l < r)) +#if __has_attribute (__nonstring__) +# define __nonstring __attribute__((__nonstring__)) +#else +# define __nonstring +#endif +#endif /* __XFS_PLATFORM_DEFS_H__ */
libxfs/xfs_format.h +1 -1
@@ -112,7 +112,7 @@uint16_t sb_sectsize;/* volume sector size, bytes */ uint16_t sb_inodesize;/* inode size, bytes */ uint16_t sb_inopblock;/* inodes per block */ -char sb_fname[XFSLABEL_MAX ];/* file system name */ + char sb_fname[XFSLABEL_MAX] __nonstring; /* file system name */uint8_t sb_blocklog;/* log2 of sb_blocksize */ uint8_t sb_sectlog;/* log2 of sb_sectsize */ uint8_t sb_inodelog;/* log2 of sb_inodesize */
PATCH 10/11 xfs: don't use a xfs_log_iovec for ri_buf in log recovery
In reply to Andrey AlbershteynSource kernel commit: ded74fddcaf685a9440c5612f7831d0c4c1473ca
ri_buf just holds a pointer/len pair and is not a log iovec used for writing to the log. Switch to use a kvec instead.
--- include/platform_defs.h | 5 ++++ libxfs/xfs_log_recover.h | 4 +-- libxlog/xfs_log_recover.c | 14 +++++------ logprint/log_print_all.c | 59 ++++++++++++++++++++++++------------------------- logprint/log_redo.c | 52 +++++++++++++++++++++---------------------- 5 files changed, 70 insertions(+), 64 deletions(-)
include/platform_defs.h +5 -0
@@ -302,4 +302,9 @@# define __nonstring#endif +struct kvec { +void *iov_base; +size_t iov_len; +}; +#endif /* __XFS_PLATFORM_DEFS_H__ */
libxfs/xfs_log_recover.h +2 -2
@@ -104,7 +104,7 @@struct list_head ri_list;int ri_cnt;/* count of regions found */ int ri_total;/* total regions */ -struct xfs_log_iovec *ri_buf;/* ptr to regions buffer */ +struct kvec *ri_buf;/* ptr to regions buffer */ const struct xlog_recover_item_ops *ri_ops; };
@@ -117,7 +117,7 @@struct list_head r_itemq;/* q for items */ }; -#define ITEM_TYPE (i) (*(unsigned short *)(i)->ri_buf[0].i_addr) +#define ITEM_TYPE (i) (*(unsigned short *)(i)->ri_buf[0].iov_base)#define XLOG_RECOVER_CRCPASS 0#define XLOG_RECOVER_PASS1 1
libxlog/xfs_log_recover.c +7 -7
@@ -1034,13 +1034,13 @@ item = list_entry(trans->r_itemq.prev, struct xlog_recover_item, ri_list); - old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; - old_len = item->ri_buf[item->ri_cnt-1 ].i_len; + old_ptr = item->ri_buf[item->ri_cnt-1 ].iov_base; + old_len = item->ri_buf[item->ri_cnt-1 ].iov_len; ptr =krealloc (old_ptr, len+old_len,0 );memcpy (&ptr[old_len], dp, len);/* d, s, l */ - item->ri_buf[item->ri_cnt-1 ].i_len += len; - item->ri_buf[item->ri_cnt-1 ].i_addr = ptr; + item->ri_buf[item->ri_cnt-1 ].iov_len += len; + item->ri_buf[item->ri_cnt-1 ].iov_base = ptr;trace_xfs_log_recover_item_add_cont (log, trans, item,0 );return 0 ; }
@@ -1117,8 +1117,8 @@ }ASSERT (item->ri_total > item->ri_cnt);/* Description region is ri_buf[0] */ - item->ri_buf[item->ri_cnt].i_addr = ptr; - item->ri_buf[item->ri_cnt].i_len = len; + item->ri_buf[item->ri_cnt].iov_base = ptr; + item->ri_buf[item->ri_cnt].iov_len = len; item->ri_cnt++;trace_xfs_log_recover_item_add (log, trans, item,0 );return 0 ;
@@ -1140,7 +1140,7 @@/* Free the regions in the item. */ list_del (&item->ri_list);for (i =0 ; i < item->ri_cnt; i++) -kfree (item->ri_buf[i].i_addr); +kfree (item->ri_buf[i].iov_base);/* Free the item itself */ kfree (item->ri_buf);kfree (item);
logprint/log_print_all.c +30 -29
144 lines not on this page · raw message
logprint/log_redo.c +26 -26
148 lines not on this page · raw message
PATCH 11/11 xfs: do not propagate ENODATA disk errors into xattr code
In reply to Andrey AlbershteynSource kernel commit: ae668cd567a6a7622bc813ee0bb61c42bed61ba7
ENODATA (aka ENOATTR) has a very specific meaning in the xfs xattr code; namely, that the requested attribute name could not be found.
However, a medium error from disk may also return ENODATA. At best, this medium error may escape to userspace as "attribute not found" when in fact it's an IO (disk) error.
At worst, we may oops in xfs_attr_leaf_get() when we do:
error = xfs_attr_leaf_hasname(args, &bp);
if (error == -ENOATTR) {xfs_trans_brelse(args->trans, bp);
return error;
}
because an ENODATA/ENOATTR error from disk leaves us with a null bp, and the xfs_trans_brelse will then null-deref it.
As discussed on the list, we really need to modify the lower level IO functions to trap all disk errors and ensure that we don't let unique errors like this leak up into higher xfs functions - many like this should be remapped to EIO.
However, this patch directly addresses a reported bug in the xattr code, and should be safe to backport to stable kernels. A larger-scope patch to handle more unique errors at lower levels can follow later.
(Note, prior to 07120f1abdff we did not oops, but we did return the wrong error code to userspace.)
--- libxfs/xfs_attr_remote.c | 7 +++++++ libxfs/xfs_da_btree.c | 6 ++++++ 2 files changed, 13 insertions(+), 0 deletions(-)
libxfs/xfs_attr_remote.c +7 -0
@@ -434,6 +434,13 @@ 0, &bp, &xfs_attr3_rmt_buf_ops);if (xfs_metadata_is_sick (error))xfs_dirattr_mark_sick (args->dp,XFS_ATTR_FORK ); +/* +* ENODATA from disk implies a disk medium failure; +* ENODATA for xattrs means attribute not found, so +* disambiguate that here. +*/ +if (error == -ENODATA ) + error = -EIO ;if (error)return error;
libxfs/xfs_da_btree.c +6 -0
@@ -2829,6 +2829,12 @@ &bp, ops);if (xfs_metadata_is_sick (error))xfs_dirattr_mark_sick (dp, whichfork); +/* +* ENODATA from disk implies a disk medium failure; ENODATA for +* xattrs means attribute not found, so disambiguate that here. +*/ +if (error == -ENODATA && whichfork ==XFS_ATTR_FORK ) + error = -EIO ;if (error) goto out_free;
Quoted 5 lines · Andrey Albershteyn
Hey all,
This is libxfs sync with v6.17.
Manual modifications diff in attachment.
For everything except patches 3-4,
--D
Quoted 806 lines
Signature · 2 lines
-- - Andreydb/attrset.c +1
-5@@ -823,11 +823,7 @@return 0 ; } - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf (_ ("failed to allocate empty transaction\n" )); -return 0 ; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_iget (mp,NULL , iocur_top->ino,0 , &ip);if (error) {db/dquot.c +1
-3@@ -92,9 +92,7 @@xfs_ino_t ret =NULLFSINO ;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -return NULLFSINO ; + tp =libxfs_trans_alloc_empty (mp);if (xfs_has_metadir (mp)) { error = -libxfs_dqinode_load_parent (tp, &dp);db/fsmap.c +1
-7@@ -133,13 +133,7 @@struct xfs_btree_cur *bt_cur;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf ( -_ ("Cannot alloc transaction to look up rtgroup %u rmap inode\n" ), -rtg_rgno (rtg)); -return error; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load_parent (tp);if (error) {db/info.c +1
-7@@ -174,13 +174,7 @@xfs_filblks_t used =0 ;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) { -dbprintf ( -_ ("Cannot alloc transaction to look up rtgroup %u rmap inode\n" ), -rtg_rgno (rtg)); -return ; - } + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load_parent (tp);if (error) {db/metadump.c +1
-1@@ -2989,7 +2989,7 @@if (metadump.obfuscate) {struct xfs_sb *sb = iocur_top->data;memset (sb->sb_fname,'L' , -min (strlen (sb->sb_fname),sizeof (sb->sb_fname))); +strnlen (sb->sb_fname,sizeof (sb->sb_fname))); iocur_top->need_crc =1 ; }if (write_buf (iocur_top))db/namei.c +1
-3@@ -94,9 +94,7 @@unsigned int i;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -return error; + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_iget (mp, tp, ino,0 , &dp);if (error)db/rdump.c +1
-6@@ -926,15 +926,10 @@set_cur_inode (mp->m_sb.sb_rootino); } - ret = -libxfs_trans_alloc_empty (mp, &tp); -if (ret) { -dbprintf (_ ("allocating state: %s\n" ),strerror (ret)); - goto out_pbuf; - } + tp =libxfs_trans_alloc_empty (mp); ret =rdump_file (tp, iocur_top->ino, destdir, pbuf);libxfs_trans_cancel (tp); -out_pbuf:free (pbuf);return ret; }include/platform_defs.h +13
-0@@ -294,4 +294,17 @@ __a > __b ? (__a - __b) : (__b - __a); \ }) +#define cmp_int (l, r) ((l > r) - (l < r)) + +#if __has_attribute (__nonstring__) +# define __nonstring __attribute__((__nonstring__)) +#else +# define __nonstring +#endif + +struct kvec { +void *iov_base; +size_t iov_len; +}; +#endif /* __XFS_PLATFORM_DEFS_H__ */ include/xfs_trans.h +1
-1@@ -98,7 +98,7 @@ struct xfs_trans **tpp, int *nospace_error);int libxfs_trans_alloc_rollable (struct xfs_mount *mp,uint blocks,struct xfs_trans **tpp); -int libxfs_trans_alloc_empty (struct xfs_mount *mp,struct xfs_trans **tpp); +struct xfs_trans *libxfs_trans_alloc_empty (struct xfs_mount *mp);int libxfs_trans_commit (struct xfs_trans *);void libxfs_trans_cancel (struct xfs_trans *); int libxfs_trans_reserve_more(struct xfs_trans *tp, uint blocks,libxfs/inode.c +1
-3@@ -258,9 +258,7 @@struct xfs_trans *tp;int error; - error =libxfs_trans_alloc_empty (mp, &tp); -if (error) -return error; + tp =libxfs_trans_alloc_empty (mp); error =libxfs_trans_metafile_iget (tp, ino, metafile_type, ipp);libxfs_trans_cancel (tp);libxfs/trans.c +22
-15@@ -247,18 +247,12 @@return error; } -int -libxfs_trans_alloc ( +static inline struct xfs_trans * +__libxfs_trans_alloc (struct xfs_mount *mp, -struct xfs_trans_res *resp, -unsigned int blocks, -unsigned int rtextents, -unsigned int flags, -struct xfs_trans **tpp) - +uint flags) {struct xfs_trans *tp; -int error; tp =kmem_cache_zalloc (xfs_trans_cache,0 ); tp->t_mountp = mp;@@ -266,6 +260,22 @@INIT_LIST_HEAD (&tp->t_dfops); tp->t_highest_agno =NULLAGNUMBER ; +return tp; +} + +int +libxfs_trans_alloc ( +struct xfs_mount *mp, +struct xfs_trans_res *resp, +unsigned int blocks, +unsigned int rtextents, +unsigned int flags, +struct xfs_trans **tpp) + +{ +struct xfs_trans *tp =__libxfs_trans_alloc (mp, flags); +int error; + error =xfs_trans_reserve (tp, resp, blocks, rtextents);if (error) {xfs_trans_cancel (tp);@@ -290,14 +300,11 @@* Note the zero-length reservation; this transaction MUST be cancelled * without any dirty data. */ -int +struct xfs_trans *libxfs_trans_alloc_empty ( -struct xfs_mount *mp, -struct xfs_trans **tpp) +struct xfs_mount *mp) { -struct xfs_trans_res resv = {0 }; - -return xfs_trans_alloc (mp, &resv,0 ,0 ,XFS_TRANS_NO_WRITECOUNT , tpp); +return __libxfs_trans_alloc (mp,XFS_TRANS_NO_WRITECOUNT ); }/* libxlog/xfs_log_recover.c +7
-7@@ -1034,13 +1034,13 @@ item = list_entry(trans->r_itemq.prev, struct xlog_recover_item, ri_list); - old_ptr = item->ri_buf[item->ri_cnt-1 ].i_addr; - old_len = item->ri_buf[item->ri_cnt-1 ].i_len; + old_ptr = item->ri_buf[item->ri_cnt-1 ].iov_base; + old_len = item->ri_buf[item->ri_cnt-1 ].iov_len; ptr =krealloc (old_ptr, len+old_len,0 );memcpy (&ptr[old_len], dp, len);/* d, s, l */ - item->ri_buf[item->ri_cnt-1 ].i_len += len; - item->ri_buf[item->ri_cnt-1 ].i_addr = ptr; + item->ri_buf[item->ri_cnt-1 ].iov_len += len; + item->ri_buf[item->ri_cnt-1 ].iov_base = ptr;trace_xfs_log_recover_item_add_cont (log, trans, item,0 );return 0 ; }@@ -1117,8 +1117,8 @@ }ASSERT (item->ri_total > item->ri_cnt);/* Description region is ri_buf[0] */ - item->ri_buf[item->ri_cnt].i_addr = ptr; - item->ri_buf[item->ri_cnt].i_len = len; + item->ri_buf[item->ri_cnt].iov_base = ptr; + item->ri_buf[item->ri_cnt].iov_len = len; item->ri_cnt++;trace_xfs_log_recover_item_add (log, trans, item,0 );return 0 ;@@ -1140,7 +1140,7 @@/* Free the regions in the item. */ list_del (&item->ri_list);for (i =0 ; i < item->ri_cnt; i++) -kfree (item->ri_buf[i].i_addr); +kfree (item->ri_buf[i].iov_base);/* Free the item itself */ kfree (item->ri_buf);kfree (item);logprint/log_print_all.c +30
-29@@ -78,7 +78,7 @@xfs_daddr_t blkno;struct xfs_disk_dquot *ddq; - f = (xfs_buf_log_format_t *)item->ri_buf[0 ].i_addr; + f = (xfs_buf_log_format_t *)item->ri_buf[0 ].iov_base;printf (" " );ASSERT (f->blf_type ==XFS_LI_BUF ); printf(_("BUF: #regs:%d start blkno:0x%llx len:%d bmap size:%d flags:0x%x\n"),@@ -87,8 +87,8 @@ num = f->blf_size-1 ; i =1 ;while (num-- >0 ) { - p = item->ri_buf[i].i_addr; - len = item->ri_buf[i].i_len; + p = item->ri_buf[i].iov_base; + len = item->ri_buf[i].iov_len; i++;if (blkno ==0 ) {/* super block */ struct xfs_dsb *dsb = (struct xfs_dsb *)p;@@ -185,7 +185,7 @@ {xfs_qoff_logformat_t *qoff_f; - qoff_f = (xfs_qoff_logformat_t *)item->ri_buf[0 ].i_addr; + qoff_f = (xfs_qoff_logformat_t *)item->ri_buf[0 ].iov_base;ASSERT (qoff_f);printf (_ ("\tQUOTAOFF: #regs:%d type:" ), qoff_f->qf_size);@@ -205,10 +205,10 @@xfs_dq_logformat_t *f;struct xfs_disk_dquot *d; - f = (xfs_dq_logformat_t *)item->ri_buf[0 ].i_addr; + f = (xfs_dq_logformat_t *)item->ri_buf[0 ].iov_base;ASSERT (f);ASSERT (f->qlf_len ==1 ); - d = (struct xfs_disk_dquot *)item->ri_buf[1 ].i_addr; + d = (struct xfs_disk_dquot *)item->ri_buf[1 ].iov_base;printf (_ ("\tDQUOT: #regs:%d blkno:%lld boffset:%u id: %d\n" ), f->qlf_size, (long long )f->qlf_blkno, f->qlf_boffset, f->qlf_id);if (!print_quota)@@ -288,21 +288,22 @@int hasdata;int hasattr; -ASSERT (item->ri_buf[0 ].i_len ==sizeof (struct xfs_inode_log_format_32 ) || - item->ri_buf[0 ].i_len ==sizeof (struct xfs_inode_log_format )); - f =xfs_inode_item_format_convert (item->ri_buf[0 ].i_addr, item->ri_buf[0 ].i_len, &f_buf); +ASSERT (item->ri_buf[0 ].iov_len ==sizeof (struct xfs_inode_log_format_32 ) || + item->ri_buf[0 ].iov_len ==sizeof (struct xfs_inode_log_format )); + f =xfs_inode_item_format_convert (item->ri_buf[0 ].iov_base, + item->ri_buf[0 ].iov_len, &f_buf);printf (_ (" INODE: #regs:%d ino:0x%llx flags:0x%x dsize:%d\n" ), - f->ilf_size, (unsigned long long )f->ilf_ino, f->ilf_fields, - f->ilf_dsize); + f->ilf_size, (unsigned long long )f->ilf_ino, f->ilf_fields, + f->ilf_dsize);/* core inode comes 2nd */ /* ASSERT len vs xfs_log_dinode_size() for V3 or V2 inodes */ -ASSERT (item->ri_buf[1 ].i_len == +ASSERT (item->ri_buf[1 ].iov_len == offsetof(struct xfs_log_dinode , di_next_unlinked) || - item->ri_buf[1 ].i_len ==sizeof (struct xfs_log_dinode )); + item->ri_buf[1 ].iov_len ==sizeof (struct xfs_log_dinode ));xlog_recover_print_inode_core ((struct xfs_log_dinode *) - item->ri_buf[1 ].i_addr); + item->ri_buf[1 ].iov_base); hasdata = (f->ilf_fields &XFS_ILOG_DFORK ) !=0 ; hasattr = (f->ilf_fields &XFS_ILOG_AFORK ) !=0 ;@@ -312,22 +313,22 @@ASSERT (f->ilf_size ==3 + hasattr);printf (_ (" DATA FORK EXTENTS inode data:\n" ));if (print_inode && print_data) -xlog_recover_print_data (item->ri_buf[2 ].i_addr, - item->ri_buf[2 ].i_len); +xlog_recover_print_data (item->ri_buf[2 ].iov_base, + item->ri_buf[2 ].iov_len);break ;case XFS_ILOG_DBROOT :ASSERT (f->ilf_size ==3 + hasattr);printf (_ (" DATA FORK BTREE inode data:\n" ));if (print_inode && print_data) -xlog_recover_print_data (item->ri_buf[2 ].i_addr, - item->ri_buf[2 ].i_len); +xlog_recover_print_data (item->ri_buf[2 ].iov_base, + item->ri_buf[2 ].iov_len);break ;case XFS_ILOG_DDATA :ASSERT (f->ilf_size ==3 + hasattr);printf (_ (" DATA FORK LOCAL inode data:\n" ));if (print_inode && print_data) -xlog_recover_print_data (item->ri_buf[2 ].i_addr, - item->ri_buf[2 ].i_len); +xlog_recover_print_data (item->ri_buf[2 ].iov_base, + item->ri_buf[2 ].iov_len);break ;case XFS_ILOG_DEV :ASSERT (f->ilf_size ==2 + hasattr);@@ -353,24 +354,24 @@printf (_ (" ATTR FORK EXTENTS inode data:\n" ));if (print_inode && print_data)xlog_recover_print_data ( - item->ri_buf[attr_index].i_addr, - item->ri_buf[attr_index].i_len); + item->ri_buf[attr_index].iov_base, + item->ri_buf[attr_index].iov_len);break ;case XFS_ILOG_ABROOT :ASSERT (f->ilf_size ==3 + hasdata);printf (_ (" ATTR FORK BTREE inode data:\n" ));if (print_inode && print_data)xlog_recover_print_data ( - item->ri_buf[attr_index].i_addr, - item->ri_buf[attr_index].i_len); + item->ri_buf[attr_index].iov_base, + item->ri_buf[attr_index].iov_len);break ;case XFS_ILOG_ADATA :ASSERT (f->ilf_size ==3 + hasdata);printf (_ (" ATTR FORK LOCAL inode data:\n" ));if (print_inode && print_data)xlog_recover_print_data ( - item->ri_buf[attr_index].i_addr, - item->ri_buf[attr_index].i_len); + item->ri_buf[attr_index].iov_base, + item->ri_buf[attr_index].iov_len);break ;default :xlog_panic ("%s: illegal inode log flag" , __FUNCTION__);@@ -385,7 +386,7 @@ {struct xfs_icreate_log *icl; - icl = (struct xfs_icreate_log *)item->ri_buf[0 ].i_addr; + icl = (struct xfs_icreate_log *)item->ri_buf[0 ].iov_base; printf(_(" ICR: #ag: %d agbno: 0x%x len: %d\n" " cnt: %d isize: %d gen: 0x%x\n"),@@ -549,8 +550,8 @@*/ printf (_ (": cnt:%d total:%d " ), item->ri_cnt, item->ri_total);for (i=0 ; i<item->ri_cnt; i++) { -printf (_ ("a:0x%lx len:%d " ), - (long )item->ri_buf[i].i_addr, item->ri_buf[i].i_len); +printf (_ ("a:0x%lx len:%zu " ), + (long )item->ri_buf[i].iov_base, item->ri_buf[i].iov_len); }printf ("\n" );xlog_recover_print_logitem (item);logprint/log_redo.c +26
-26@@ -143,8 +143,8 @@int i;uint src_len, dst_len; - src_f = (xfs_efi_log_format_t *)item->ri_buf[0 ].i_addr; - src_len = item->ri_buf[0 ].i_len; + src_f = (xfs_efi_log_format_t *)item->ri_buf[0 ].iov_base; + src_len = item->ri_buf[0 ].iov_len;/* * An xfs_efi_log_format structure contains a variable length array * as the last field. @@ -229,7 +229,7 @@const char *item_name ="EFD?" ;xfs_efd_log_format_t *f; - f = (xfs_efd_log_format_t *)item->ri_buf[0 ].i_addr; + f = (xfs_efd_log_format_t *)item->ri_buf[0 ].iov_base;switch (f->efd_type) {case XFS_LI_EFD : item_name ="EFD" ;break ;@@ -355,8 +355,8 @@char *src_f;uint src_len; - src_f = item->ri_buf[0 ].i_addr; - src_len = item->ri_buf[0 ].i_len; + src_f = item->ri_buf[0 ].iov_base; + src_len = item->ri_buf[0 ].iov_len;xlog_print_trans_rui (&src_f, src_len,0 ); }@@ -406,7 +406,7 @@ {char *f; - f = item->ri_buf[0 ].i_addr; + f = item->ri_buf[0 ].iov_base;xlog_print_trans_rud (&f,sizeof (struct xfs_rud_log_format )); }@@ -516,8 +516,8 @@char *src_f;uint src_len; - src_f = item->ri_buf[0 ].i_addr; - src_len = item->ri_buf[0 ].i_len; + src_f = item->ri_buf[0 ].iov_base; + src_len = item->ri_buf[0 ].iov_len;xlog_print_trans_cui (&src_f, src_len,0 ); }@@ -563,7 +563,7 @@ {char *f; - f = item->ri_buf[0 ].i_addr; + f = item->ri_buf[0 ].iov_base;xlog_print_trans_cud (&f,sizeof (struct xfs_cud_log_format )); }@@ -667,8 +667,8 @@char *src_f;uint src_len; - src_f = item->ri_buf[0 ].i_addr; - src_len = item->ri_buf[0 ].i_len; + src_f = item->ri_buf[0 ].iov_base; + src_len = item->ri_buf[0 ].iov_len;xlog_print_trans_bui (&src_f, src_len,0 ); }@@ -707,7 +707,7 @@ {char *f; - f = item->ri_buf[0 ].i_addr; + f = item->ri_buf[0 ].iov_base;xlog_print_trans_bud (&f,sizeof (struct xfs_bud_log_format )); }@@ -954,8 +954,8 @@unsigned int new_value_len =0 ;int region =0 ; - src_f = (struct xfs_attri_log_format *)item->ri_buf[0 ].i_addr; - src_len = item->ri_buf[region].i_len; + src_f = (struct xfs_attri_log_format *)item->ri_buf[0 ].iov_base; + src_len = item->ri_buf[region].iov_len;/* * An xfs_attri_log_format structure contains a attribute name and @@ -996,17 +996,17 @@if (name_len >0 ) { region++;printf (_ ("ATTRI: name len:%u\n" ), name_len); -print_or_dump ((char *)item->ri_buf[region].i_addr, +print_or_dump ((char *)item->ri_buf[region].iov_base, name_len); - name_ptr = item->ri_buf[region].i_addr; + name_ptr = item->ri_buf[region].iov_base; }if (new_name_len >0 ) { region++;printf (_ ("ATTRI: newname len:%u\n" ), new_name_len); -print_or_dump ((char *)item->ri_buf[region].i_addr, +print_or_dump ((char *)item->ri_buf[region].iov_base, new_name_len); - new_name_ptr = item->ri_buf[region].i_addr; + new_name_ptr = item->ri_buf[region].iov_base; }if (value_len >0 ) {@@ -1014,8 +1014,8 @@ region++;printf (_ ("ATTRI: value len:%u\n" ), value_len); -print_or_dump ((char *)item->ri_buf[region].i_addr, len); - value_ptr = item->ri_buf[region].i_addr; +print_or_dump ((char *)item->ri_buf[region].iov_base, len); + value_ptr = item->ri_buf[region].iov_base; }if (new_value_len >0 ) {@@ -1023,8 +1023,8 @@ region++;printf (_ ("ATTRI: newvalue len:%u\n" ), new_value_len); -print_or_dump ((char *)item->ri_buf[region].i_addr, len); - new_value_ptr = item->ri_buf[region].i_addr; +print_or_dump ((char *)item->ri_buf[region].iov_base, len); + new_value_ptr = item->ri_buf[region].iov_base; }if (src_f->alfi_attr_filter &XFS_ATTR_PARENT )@@ -1065,7 +1065,7 @@ {struct xfs_attrd_log_format *f; - f = (struct xfs_attrd_log_format *)item->ri_buf[0 ].i_addr; + f = (struct xfs_attrd_log_format *)item->ri_buf[0 ].iov_base; printf(_(" ATTRD: #regs: %d id: 0x%llx\n"), f->alfd_size,@@ -1156,8 +1156,8 @@char *src_f;uint src_len; - src_f = item->ri_buf[0 ].i_addr; - src_len = item->ri_buf[0 ].i_len; + src_f = item->ri_buf[0 ].iov_base; + src_len = item->ri_buf[0 ].iov_len;xlog_print_trans_xmi (&src_f, src_len,0 ); }@@ -1196,6 +1196,6 @@ {char *f; - f = item->ri_buf[0 ].i_addr; + f = item->ri_buf[0 ].iov_base;xlog_print_trans_xmd (&f,sizeof (struct xfs_xmd_log_format )); }repair/phase2.c +1
-5@@ -296,11 +296,7 @@* there while we try to make a per-AG reservation with the new * geometry. */ - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error ( -_ ("Cannot reserve resources for upgrade check, err=%d.\n" ), - error); + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_ialloc_read_agi (pag, tp,0 , &agi_bp);if (error)repair/pptr.c +2
-2@@ -1217,7 +1217,7 @@ fscan->have_garbage = false; fscan->nr_file_pptrs =0 ; -libxfs_trans_alloc_empty (ip->i_mount, &tp); + tp =libxfs_trans_alloc_empty (ip->i_mount); error =xattr_walk (tp, ip, examine_xattr, fscan);if (tp)libxfs_trans_cancel (tp);@@ -1417,7 +1417,7 @@do_error ("init garbage pptr names failed: %s\n" ,strerror (error)); -libxfs_trans_alloc_empty (ip->i_mount, &tp); + tp =libxfs_trans_alloc_empty (ip->i_mount); error =xattr_walk (tp, ip, erase_pptrs, &fscan);if (tp)libxfs_trans_cancel (tp);repair/quotacheck.c +2
-7@@ -437,9 +437,7 @@if (!dquots || !chkd_flags)return ; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("could not alloc transaction to open quota file\n" )); + tp =libxfs_trans_alloc_empty (mp); ino =get_quota_inode (type); error = -libxfs_trans_metafile_iget (tp, ino, metafile_type, &ip);@@ -679,9 +677,7 @@struct xfs_inode *dp =NULL ;int error, err2; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out; + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_dqinode_load_parent (tp, &dp);if (error)@@ -698,7 +694,6 @@libxfs_irele (dp); out_cancel:libxfs_trans_cancel (tp); -out:if (error) {switch (error) {case EFSCORRUPTED :repair/rcbag.c +2
-6@@ -95,9 +95,7 @@int has;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for refcount bag update\n" )); + tp =libxfs_trans_alloc_empty (mp); cur =rcbagbt_mem_cursor (mp, tp, &bag->xfbtree); error =rcbagbt_lookup_eq (cur, rmap, &has);@@ -217,9 +215,7 @@int has;int error; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for refcount bag update\n" )); + tp =libxfs_trans_alloc_empty (mp);/* go to the right edge of the tree */ cur =rcbagbt_mem_cursor (mp, tp, &bag->xfbtree);repair/rcbag_btree.c +6
-6@@ -46,8 +46,8 @@ bag_rec->rbg_refcount = bag_irec->rbg_refcount; } -STATIC int64_t -rcbagbt_key_diff ( +STATIC int +rcbagbt_cmp_key_with_cur (struct xfs_btree_cur *cur,const union xfs_btree_key *key) {@@ -72,8 +72,8 @@return 0 ; } -STATIC int64_t -rcbagbt_diff_two_keys( +STATIC int +rcbagbt_cmp_two_keys( struct xfs_btree_cur *cur, const union xfs_btree_key *k1, const union xfs_btree_key *k2,@@ -220,9 +220,9 @@ .init_key_from_rec = rcbagbt_init_key_from_rec, .init_rec_from_cur = rcbagbt_init_rec_from_cur, .init_ptr_from_cur = xfbtree_init_ptr_from_cur, - .key_diff = rcbagbt_key_diff, + .cmp_key_with_cur = rcbagbt_cmp_key_with_cur, .buf_ops = &rcbagbt_mem_buf_ops, - .diff_two_keys = rcbagbt_diff_two_keys, + .cmp_two_keys = rcbagbt_cmp_two_keys, .keys_inorder = rcbagbt_keys_inorder, .recs_inorder = rcbagbt_recs_inorder, };repair/rmap.c +1
-3@@ -323,9 +323,7 @@int error; xfbt = &rmaps_for_group (isrt, agno)->ar_xfbtree; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) -do_error (_ ("allocating tx for in-memory rmap update\n" )); + tp =libxfs_trans_alloc_empty (mp); error =rmap_init_mem_cursor (mp, tp, isrt, agno, &rmcur);if (error)repair/rt.c +2
-8@@ -301,10 +301,7 @@if (rtg->rtg_inodes[type]) goto out_rtg; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out_rtg; - + tp =libxfs_trans_alloc_empty (mp); error = -libxfs_rtginode_load (rtg, type, tp);if (error)@@ -497,9 +494,7 @@int error, err2;int i; - error = -libxfs_trans_alloc_empty (mp, &tp); -if (error) - goto out; + tp =libxfs_trans_alloc_empty (mp);if (xfs_has_rtgroups (mp) && mp->m_sb.sb_rgcount >0 ) { error = -libxfs_rtginode_load_parent (tp);if (error)@@ -516,7 +511,6 @@ out_cancel:libxfs_trans_cancel (tp); -out:if (xfs_has_rtgroups (mp) && error) {/* * Old xfs_repair didn't complain if rtbitmaps didn't load scrub/inodes.c +0
-2@@ -197,8 +197,6 @@return seen_mask; } -#define cmp_int (l, r) ((l > r) - (l < r)) -/* Compare two bulkstat records by inumber. */ static int compare_bstat(