On Thu, May 17, 2018 at 08:51:55PM -0700, Darrick J. Wong wrote: > From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> > > Add some helpers to assemble a list of fs block extents. Generally, > repair functions will iterate the rmapbt to make a list (1) of all > extents owned by the nominal owner of the metadata structure; then they > will iterate all other structures with the same rmap owner to make a > list (2) of active blocks; and finally we have a subtraction function to > subtract all the blocks in (2) from (1), with the result that (1) is now > a list of blocks that were owned by the old btree and must be disposed. > > Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> > --- > v2: document the design of how repair functions are supposed to work, > implement review comments > --- Much easier to understand now. Thanks! Reviewed-by: Dave Chinner <dchinner@xxxxxxxxxx> One thing for a followup patch, though. > +/* Collect a dead btree extent for later disposal. */ > +int > +xfs_repair_collect_btree_extent( > + struct xfs_scrub_context *sc, > + struct xfs_repair_extent_list *exlist, > + xfs_fsblock_t fsbno, > + xfs_extlen_t len) > +{ > + struct xfs_repair_extent *rex; > + > + trace_xfs_repair_collect_btree_extent(sc->mp, > + XFS_FSB_TO_AGNO(sc->mp, fsbno), > + XFS_FSB_TO_AGBNO(sc->mp, fsbno), len); > + > + rex = kmem_alloc(sizeof(struct xfs_repair_extent), KM_MAYFAIL); > + if (!rex) > + return -ENOMEM; > + > + INIT_LIST_HEAD(&rex->list); > + rex->fsbno = fsbno; > + rex->len = len; This allocation is repeated a couple of times. Single function to do it would be nice to encapsulate alloc+setup - something like rex = alloc_rex(fsbno, len) which returns NULL if it fails. > + case LEFT_ALIGNED | RIGHT_ALIGNED: > + /* Total overlap, just delete ex. */ > + lp = lp->next; > + list_del(&ex->list); > + kmem_free(ex); > + break; > + case 0: > + /* > + * Deleting from the middle: add the new right extent > + * and then shrink the left extent. > + */ > + newex = kmem_alloc(sizeof(struct xfs_repair_extent), > + KM_MAYFAIL); > + if (!newex) { > + error = -ENOMEM; > + goto out; > + } > + INIT_LIST_HEAD(&newex->list); > + newex->fsbno = sub_fsb + sub_len; > + newex->len = ex->fsbno + ex->len - newex->fsbno; This is the other place it is called... Cheers, Dave. -- Dave Chinner david@xxxxxxxxxxxxx -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html