forked from luck/tmp_suning_uos_patched
xfs: introduce the xfs_iext_cursor abstraction
Add a new xfs_iext_cursor structure to hide the direct extent map index manipulations. In addition to the existing lookup/get/insert/ remove and update routines new primitives to get the first and last extent cursor, as well as moving up and down by one extent are provided. Also new are convenience to increment/decrement the cursor and retreive the new extent, as well as to peek into the previous/next extent without updating the cursor and last but not least a macro to iterate over all extents in a fork. [darrick: rename for_each_iext to for_each_xfs_iext] Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
parent
906abed501
commit
b2b1712a64
File diff suppressed because it is too large
Load Diff
|
@ -43,7 +43,7 @@ struct xfs_bmalloca {
|
|||
xfs_fsblock_t blkno; /* starting block of new extent */
|
||||
|
||||
struct xfs_btree_cur *cur; /* btree cursor */
|
||||
xfs_extnum_t idx; /* current extent index */
|
||||
struct xfs_iext_cursor icur; /* incore extent cursor */
|
||||
int nallocs;/* number of extents alloc'd */
|
||||
int logflags;/* flags for transaction logging */
|
||||
|
||||
|
@ -216,10 +216,11 @@ int xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip,
|
|||
xfs_extnum_t nexts, xfs_fsblock_t *firstblock,
|
||||
struct xfs_defer_ops *dfops, int *done);
|
||||
int xfs_bmap_del_extent_delay(struct xfs_inode *ip, int whichfork,
|
||||
xfs_extnum_t *idx, struct xfs_bmbt_irec *got,
|
||||
struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *got,
|
||||
struct xfs_bmbt_irec *del);
|
||||
void xfs_bmap_del_extent_cow(struct xfs_inode *ip,
|
||||
struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *got,
|
||||
struct xfs_bmbt_irec *del);
|
||||
void xfs_bmap_del_extent_cow(struct xfs_inode *ip, xfs_extnum_t *idx,
|
||||
struct xfs_bmbt_irec *got, struct xfs_bmbt_irec *del);
|
||||
uint xfs_default_attroffset(struct xfs_inode *ip);
|
||||
int xfs_bmap_collapse_extents(struct xfs_trans *tp, struct xfs_inode *ip,
|
||||
xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb,
|
||||
|
@ -232,7 +233,8 @@ int xfs_bmap_insert_extents(struct xfs_trans *tp, struct xfs_inode *ip,
|
|||
int xfs_bmap_split_extent(struct xfs_inode *ip, xfs_fileoff_t split_offset);
|
||||
int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork,
|
||||
xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,
|
||||
struct xfs_bmbt_irec *got, xfs_extnum_t *lastx, int eof);
|
||||
struct xfs_bmbt_irec *got, struct xfs_iext_cursor *cur,
|
||||
int eof);
|
||||
|
||||
enum xfs_bmap_intent_type {
|
||||
XFS_BMAP_MAP = 1,
|
||||
|
|
|
@ -343,6 +343,7 @@ xfs_iformat_extents(
|
|||
int state = xfs_bmap_fork_to_state(whichfork);
|
||||
int nex = XFS_DFORK_NEXTENTS(dip, whichfork);
|
||||
int size = nex * sizeof(xfs_bmbt_rec_t);
|
||||
struct xfs_iext_cursor icur;
|
||||
struct xfs_bmbt_rec *dp;
|
||||
int i;
|
||||
|
||||
|
@ -369,16 +370,21 @@ xfs_iformat_extents(
|
|||
ifp->if_bytes = size;
|
||||
if (size) {
|
||||
dp = (xfs_bmbt_rec_t *) XFS_DFORK_PTR(dip, whichfork);
|
||||
|
||||
xfs_iext_first(ifp, &icur);
|
||||
for (i = 0; i < nex; i++, dp++) {
|
||||
xfs_bmbt_rec_host_t *ep = xfs_iext_get_ext(ifp, i);
|
||||
|
||||
if (!xfs_bmbt_validate_extent(mp, whichfork, dp)) {
|
||||
XFS_ERROR_REPORT("xfs_iformat_extents(2)",
|
||||
XFS_ERRLEVEL_LOW, mp);
|
||||
return -EFSCORRUPTED;
|
||||
}
|
||||
|
||||
ep->l0 = get_unaligned_be64(&dp->l0);
|
||||
ep->l1 = get_unaligned_be64(&dp->l1);
|
||||
trace_xfs_read_extent(ip, i, state, _THIS_IP_);
|
||||
trace_xfs_read_extent(ip, &icur, state, _THIS_IP_);
|
||||
xfs_iext_next(ifp, &icur);
|
||||
}
|
||||
}
|
||||
ifp->if_flags |= XFS_IFEXTENTS;
|
||||
|
@ -739,17 +745,18 @@ xfs_iextents_copy(
|
|||
{
|
||||
int state = xfs_bmap_fork_to_state(whichfork);
|
||||
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
|
||||
struct xfs_iext_cursor icur;
|
||||
struct xfs_bmbt_irec rec;
|
||||
int copied = 0, i = 0;
|
||||
int copied = 0;
|
||||
|
||||
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL | XFS_ILOCK_SHARED));
|
||||
ASSERT(ifp->if_bytes > 0);
|
||||
|
||||
while (xfs_iext_get_extent(ifp, i++, &rec)) {
|
||||
for_each_xfs_iext(ifp, &icur, &rec) {
|
||||
if (isnullstartblock(rec.br_startblock))
|
||||
continue;
|
||||
xfs_bmbt_disk_set_all(dp, &rec);
|
||||
trace_xfs_write_extent(ip, i, state, _RET_IP_);
|
||||
trace_xfs_write_extent(ip, &icur, state, _RET_IP_);
|
||||
ASSERT(xfs_bmbt_validate_extent(ip->i_mount, whichfork, dp));
|
||||
copied += sizeof(struct xfs_bmbt_rec);
|
||||
dp++;
|
||||
|
@ -894,7 +901,7 @@ xfs_iext_state_to_fork(
|
|||
void
|
||||
xfs_iext_insert(
|
||||
xfs_inode_t *ip, /* incore inode pointer */
|
||||
xfs_extnum_t idx, /* starting index of new items */
|
||||
struct xfs_iext_cursor *cur,
|
||||
xfs_extnum_t count, /* number of inserted items */
|
||||
xfs_bmbt_irec_t *new, /* items to insert */
|
||||
int state) /* type of extent conversion */
|
||||
|
@ -902,12 +909,12 @@ xfs_iext_insert(
|
|||
xfs_ifork_t *ifp = xfs_iext_state_to_fork(ip, state);
|
||||
xfs_extnum_t i; /* extent record index */
|
||||
|
||||
trace_xfs_iext_insert(ip, idx, new, state, _RET_IP_);
|
||||
trace_xfs_iext_insert(ip, cur->idx, new, state, _RET_IP_);
|
||||
|
||||
ASSERT(ifp->if_flags & XFS_IFEXTENTS);
|
||||
xfs_iext_add(ifp, idx, count);
|
||||
for (i = idx; i < idx + count; i++, new++)
|
||||
xfs_bmbt_set_all(xfs_iext_get_ext(ifp, i), new);
|
||||
xfs_iext_add(ifp, cur->idx, count);
|
||||
for (i = 0; i < count; i++, new++)
|
||||
xfs_bmbt_set_all(xfs_iext_get_ext(ifp, cur->idx + i), new);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1145,7 +1152,7 @@ xfs_iext_add_indirect_multi(
|
|||
void
|
||||
xfs_iext_remove(
|
||||
xfs_inode_t *ip, /* incore inode pointer */
|
||||
xfs_extnum_t idx, /* index to begin removing exts */
|
||||
struct xfs_iext_cursor *cur,
|
||||
int ext_diff, /* number of extents to remove */
|
||||
int state) /* type of extent conversion */
|
||||
{
|
||||
|
@ -1153,7 +1160,7 @@ xfs_iext_remove(
|
|||
xfs_extnum_t nextents; /* number of extents in file */
|
||||
int new_size; /* size of extents after removal */
|
||||
|
||||
trace_xfs_iext_remove(ip, idx, state, _RET_IP_);
|
||||
trace_xfs_iext_remove(ip, cur, state, _RET_IP_);
|
||||
|
||||
ASSERT(ext_diff > 0);
|
||||
nextents = xfs_iext_count(ifp);
|
||||
|
@ -1162,11 +1169,11 @@ xfs_iext_remove(
|
|||
if (new_size == 0) {
|
||||
xfs_iext_destroy(ifp);
|
||||
} else if (ifp->if_flags & XFS_IFEXTIREC) {
|
||||
xfs_iext_remove_indirect(ifp, idx, ext_diff);
|
||||
xfs_iext_remove_indirect(ifp, cur->idx, ext_diff);
|
||||
} else if (ifp->if_real_bytes) {
|
||||
xfs_iext_remove_direct(ifp, idx, ext_diff);
|
||||
xfs_iext_remove_direct(ifp, cur->idx, ext_diff);
|
||||
} else {
|
||||
xfs_iext_remove_inline(ifp, idx, ext_diff);
|
||||
xfs_iext_remove_inline(ifp, cur->idx, ext_diff);
|
||||
}
|
||||
ifp->if_bytes = new_size;
|
||||
}
|
||||
|
@ -1913,26 +1920,26 @@ xfs_ifork_init_cow(
|
|||
* Lookup the extent covering bno.
|
||||
*
|
||||
* If there is an extent covering bno return the extent index, and store the
|
||||
* expanded extent structure in *gotp, and the extent index in *idx.
|
||||
* expanded extent structure in *gotp, and the extent cursor in *cur.
|
||||
* If there is no extent covering bno, but there is an extent after it (e.g.
|
||||
* it lies in a hole) return that extent in *gotp and its index in *idx
|
||||
* it lies in a hole) return that extent in *gotp and its cursor in *cur
|
||||
* instead.
|
||||
* If bno is beyond the last extent return false, and return the index after
|
||||
* the last valid index in *idxp.
|
||||
* If bno is beyond the last extent return false, and return an invalid
|
||||
* cursor value.
|
||||
*/
|
||||
bool
|
||||
xfs_iext_lookup_extent(
|
||||
struct xfs_inode *ip,
|
||||
struct xfs_ifork *ifp,
|
||||
xfs_fileoff_t bno,
|
||||
xfs_extnum_t *idxp,
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
struct xfs_bmbt_rec_host *ep;
|
||||
|
||||
XFS_STATS_INC(ip->i_mount, xs_look_exlist);
|
||||
|
||||
ep = xfs_iext_bno_to_ext(ifp, bno, idxp);
|
||||
ep = xfs_iext_bno_to_ext(ifp, bno, &cur->idx);
|
||||
if (!ep)
|
||||
return false;
|
||||
xfs_bmbt_get_all(ep, gotp);
|
||||
|
@ -1948,31 +1955,31 @@ xfs_iext_lookup_extent_before(
|
|||
struct xfs_inode *ip,
|
||||
struct xfs_ifork *ifp,
|
||||
xfs_fileoff_t *end,
|
||||
xfs_extnum_t *idxp,
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
if (xfs_iext_lookup_extent(ip, ifp, *end - 1, idxp, gotp) &&
|
||||
if (xfs_iext_lookup_extent(ip, ifp, *end - 1, cur, gotp) &&
|
||||
gotp->br_startoff <= *end - 1)
|
||||
return true;
|
||||
if (!xfs_iext_get_extent(ifp, --*idxp, gotp))
|
||||
if (!xfs_iext_prev_extent(ifp, cur, gotp))
|
||||
return false;
|
||||
*end = gotp->br_startoff + gotp->br_blockcount;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true if there is an extent at index idx, and return the expanded
|
||||
* extent structure at idx in that case. Else return false.
|
||||
* Return true if the cursor points at an extent and return the extent structure
|
||||
* in gotp. Else return false.
|
||||
*/
|
||||
bool
|
||||
xfs_iext_get_extent(
|
||||
struct xfs_ifork *ifp,
|
||||
xfs_extnum_t idx,
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
if (idx < 0 || idx >= xfs_iext_count(ifp))
|
||||
if (cur->idx < 0 || cur->idx >= xfs_iext_count(ifp))
|
||||
return false;
|
||||
xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), gotp);
|
||||
xfs_bmbt_get_all(xfs_iext_get_ext(ifp, cur->idx), gotp);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1980,15 +1987,15 @@ void
|
|||
xfs_iext_update_extent(
|
||||
struct xfs_inode *ip,
|
||||
int state,
|
||||
xfs_extnum_t idx,
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
struct xfs_ifork *ifp = xfs_iext_state_to_fork(ip, state);
|
||||
|
||||
ASSERT(idx >= 0);
|
||||
ASSERT(idx < xfs_iext_count(ifp));
|
||||
ASSERT(cur->idx >= 0);
|
||||
ASSERT(cur->idx < xfs_iext_count(ifp));
|
||||
|
||||
trace_xfs_bmap_pre_update(ip, idx, state, _RET_IP_);
|
||||
xfs_bmbt_set_all(xfs_iext_get_ext(ifp, idx), gotp);
|
||||
trace_xfs_bmap_post_update(ip, idx, state, _RET_IP_);
|
||||
trace_xfs_bmap_pre_update(ip, cur, state, _RET_IP_);
|
||||
xfs_bmbt_set_all(xfs_iext_get_ext(ifp, cur->idx), gotp);
|
||||
trace_xfs_bmap_post_update(ip, cur, state, _RET_IP_);
|
||||
}
|
||||
|
|
|
@ -151,12 +151,13 @@ void xfs_init_local_fork(struct xfs_inode *, int, const void *, int);
|
|||
struct xfs_bmbt_rec_host *
|
||||
xfs_iext_get_ext(struct xfs_ifork *, xfs_extnum_t);
|
||||
xfs_extnum_t xfs_iext_count(struct xfs_ifork *);
|
||||
void xfs_iext_insert(struct xfs_inode *, xfs_extnum_t, xfs_extnum_t,
|
||||
struct xfs_bmbt_irec *, int);
|
||||
void xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur,
|
||||
xfs_extnum_t, struct xfs_bmbt_irec *, int);
|
||||
void xfs_iext_add(struct xfs_ifork *, xfs_extnum_t, int);
|
||||
void xfs_iext_add_indirect_multi(struct xfs_ifork *, int,
|
||||
xfs_extnum_t, int);
|
||||
void xfs_iext_remove(struct xfs_inode *, xfs_extnum_t, int, int);
|
||||
void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
|
||||
int, int);
|
||||
void xfs_iext_remove_inline(struct xfs_ifork *, xfs_extnum_t, int);
|
||||
void xfs_iext_remove_direct(struct xfs_ifork *, xfs_extnum_t, int);
|
||||
void xfs_iext_remove_indirect(struct xfs_ifork *, xfs_extnum_t, int);
|
||||
|
@ -182,15 +183,85 @@ void xfs_iext_irec_update_extoffs(struct xfs_ifork *, int, int);
|
|||
|
||||
bool xfs_iext_lookup_extent(struct xfs_inode *ip,
|
||||
struct xfs_ifork *ifp, xfs_fileoff_t bno,
|
||||
xfs_extnum_t *idxp, struct xfs_bmbt_irec *gotp);
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp);
|
||||
bool xfs_iext_lookup_extent_before(struct xfs_inode *ip,
|
||||
struct xfs_ifork *ifp, xfs_fileoff_t *end,
|
||||
xfs_extnum_t *idxp, struct xfs_bmbt_irec *gotp);
|
||||
|
||||
bool xfs_iext_get_extent(struct xfs_ifork *ifp, xfs_extnum_t idx,
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp);
|
||||
bool xfs_iext_get_extent(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp);
|
||||
void xfs_iext_update_extent(struct xfs_inode *ip, int state,
|
||||
xfs_extnum_t idx, struct xfs_bmbt_irec *gotp);
|
||||
struct xfs_iext_cursor *cur,
|
||||
struct xfs_bmbt_irec *gotp);
|
||||
|
||||
static inline void xfs_iext_first(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur)
|
||||
{
|
||||
cur->idx = 0;
|
||||
}
|
||||
|
||||
static inline void xfs_iext_last(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur)
|
||||
{
|
||||
cur->idx = xfs_iext_count(ifp) - 1;
|
||||
}
|
||||
|
||||
static inline void xfs_iext_next(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur)
|
||||
{
|
||||
cur->idx++;
|
||||
}
|
||||
|
||||
static inline void xfs_iext_prev(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur)
|
||||
{
|
||||
cur->idx--;
|
||||
}
|
||||
|
||||
static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
xfs_iext_next(ifp, cur);
|
||||
return xfs_iext_get_extent(ifp, cur, gotp);
|
||||
}
|
||||
|
||||
static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
xfs_iext_prev(ifp, cur);
|
||||
return xfs_iext_get_extent(ifp, cur, gotp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the extent after cur in gotp without updating the cursor.
|
||||
*/
|
||||
static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
struct xfs_iext_cursor ncur = *cur;
|
||||
|
||||
xfs_iext_next(ifp, &ncur);
|
||||
return xfs_iext_get_extent(ifp, &ncur, gotp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the extent before cur in gotp without updating the cursor.
|
||||
*/
|
||||
static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp,
|
||||
struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
|
||||
{
|
||||
struct xfs_iext_cursor ncur = *cur;
|
||||
|
||||
xfs_iext_prev(ifp, &ncur);
|
||||
return xfs_iext_get_extent(ifp, &ncur, gotp);
|
||||
}
|
||||
|
||||
#define for_each_xfs_iext(ifp, ext, got) \
|
||||
for (xfs_iext_first((ifp), (ext)); \
|
||||
xfs_iext_get_extent((ifp), (ext), (got)); \
|
||||
xfs_iext_next((ifp), (ext)))
|
||||
|
||||
extern struct kmem_zone *xfs_ifork_zone;
|
||||
|
||||
|
|
|
@ -142,5 +142,8 @@ typedef uint32_t xfs_dqid_t;
|
|||
#define XFS_NBWORD (1 << XFS_NBWORDLOG)
|
||||
#define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1)
|
||||
|
||||
struct xfs_iext_cursor {
|
||||
xfs_extnum_t idx;
|
||||
};
|
||||
|
||||
#endif /* __XFS_TYPES_H__ */
|
||||
|
|
|
@ -237,7 +237,7 @@ xfs_scrub_bmap(
|
|||
struct xfs_inode *ip = sc->ip;
|
||||
struct xfs_ifork *ifp;
|
||||
xfs_fileoff_t endoff;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
bool found;
|
||||
int error = 0;
|
||||
|
||||
|
@ -317,9 +317,9 @@ xfs_scrub_bmap(
|
|||
/* Scrub extent records. */
|
||||
info.lastoff = 0;
|
||||
ifp = XFS_IFORK_PTR(ip, whichfork);
|
||||
for (found = xfs_iext_lookup_extent(ip, ifp, 0, &idx, &irec);
|
||||
for (found = xfs_iext_lookup_extent(ip, ifp, 0, &icur, &irec);
|
||||
found != 0;
|
||||
found = xfs_iext_get_extent(ifp, ++idx, &irec)) {
|
||||
found = xfs_iext_next_extent(ifp, &icur, &irec)) {
|
||||
if (xfs_scrub_should_terminate(sc, &error))
|
||||
break;
|
||||
if (isnullstartblock(irec.br_startblock))
|
||||
|
|
|
@ -614,7 +614,7 @@ xfs_scrub_directory_blocks(
|
|||
xfs_fileoff_t leaf_lblk;
|
||||
xfs_fileoff_t free_lblk;
|
||||
xfs_fileoff_t lblk;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
xfs_dablk_t dabno;
|
||||
bool found;
|
||||
int is_block = 0;
|
||||
|
@ -639,7 +639,7 @@ xfs_scrub_directory_blocks(
|
|||
goto out;
|
||||
|
||||
/* Iterate all the data extents in the directory... */
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &idx, &got);
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got);
|
||||
while (found) {
|
||||
/* Block directories only have a single block at offset 0. */
|
||||
if (is_block &&
|
||||
|
@ -676,17 +676,17 @@ xfs_scrub_directory_blocks(
|
|||
}
|
||||
dabno = got.br_startoff + got.br_blockcount;
|
||||
lblk = roundup(dabno, args.geo->fsbcount);
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &idx, &got);
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got);
|
||||
}
|
||||
|
||||
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
||||
goto out;
|
||||
|
||||
/* Look for a leaf1 block, which has free info. */
|
||||
if (xfs_iext_lookup_extent(sc->ip, ifp, leaf_lblk, &idx, &got) &&
|
||||
if (xfs_iext_lookup_extent(sc->ip, ifp, leaf_lblk, &icur, &got) &&
|
||||
got.br_startoff == leaf_lblk &&
|
||||
got.br_blockcount == args.geo->fsbcount &&
|
||||
!xfs_iext_get_extent(ifp, ++idx, &got)) {
|
||||
!xfs_iext_next_extent(ifp, &icur, &got)) {
|
||||
if (is_block) {
|
||||
xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk);
|
||||
goto out;
|
||||
|
@ -702,7 +702,7 @@ xfs_scrub_directory_blocks(
|
|||
|
||||
/* Scan for free blocks */
|
||||
lblk = free_lblk;
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &idx, &got);
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got);
|
||||
while (found) {
|
||||
/*
|
||||
* Dirs can't have blocks mapped above 2^32.
|
||||
|
@ -740,7 +740,7 @@ xfs_scrub_directory_blocks(
|
|||
}
|
||||
dabno = got.br_startoff + got.br_blockcount;
|
||||
lblk = roundup(dabno, args.geo->fsbcount);
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &idx, &got);
|
||||
found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got);
|
||||
}
|
||||
out:
|
||||
return error;
|
||||
|
|
|
@ -229,15 +229,17 @@ xfs_bmap_count_leaves(
|
|||
struct xfs_ifork *ifp,
|
||||
xfs_filblks_t *count)
|
||||
{
|
||||
struct xfs_iext_cursor icur;
|
||||
struct xfs_bmbt_irec got;
|
||||
xfs_extnum_t numrecs = 0, i = 0;
|
||||
xfs_extnum_t numrecs = 0;
|
||||
|
||||
while (xfs_iext_get_extent(ifp, i++, &got)) {
|
||||
for_each_xfs_iext(ifp, &icur, &got) {
|
||||
if (!isnullstartblock(got.br_startblock)) {
|
||||
*count += got.br_blockcount;
|
||||
numrecs++;
|
||||
}
|
||||
}
|
||||
|
||||
return numrecs;
|
||||
}
|
||||
|
||||
|
@ -525,7 +527,7 @@ xfs_getbmap(
|
|||
struct xfs_ifork *ifp;
|
||||
struct xfs_bmbt_irec got, rec;
|
||||
xfs_filblks_t len;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
|
||||
if (bmv->bmv_iflags & ~BMV_IF_VALID)
|
||||
return -EINVAL;
|
||||
|
@ -629,7 +631,7 @@ xfs_getbmap(
|
|||
goto out_unlock_ilock;
|
||||
}
|
||||
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, bno, &idx, &got)) {
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) {
|
||||
/*
|
||||
* Report a whole-file hole if the delalloc flag is set to
|
||||
* stay compatible with the old implementation.
|
||||
|
@ -668,7 +670,7 @@ xfs_getbmap(
|
|||
goto out_unlock_ilock;
|
||||
} while (xfs_getbmap_next_rec(&rec, bno));
|
||||
|
||||
if (!xfs_iext_get_extent(ifp, ++idx, &got)) {
|
||||
if (!xfs_iext_next_extent(ifp, &icur, &got)) {
|
||||
xfs_fileoff_t end = XFS_B_TO_FSB(mp, XFS_ISIZE(ip));
|
||||
|
||||
out[bmv->bmv_entries - 1].bmv_oflags |= BMV_OF_LAST;
|
||||
|
|
|
@ -266,7 +266,7 @@ xfs_dir2_leaf_readbuf(
|
|||
xfs_dablk_t next_ra;
|
||||
xfs_dablk_t map_off;
|
||||
xfs_dablk_t last_da;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
int ra_want;
|
||||
int error = 0;
|
||||
|
||||
|
@ -283,7 +283,7 @@ xfs_dir2_leaf_readbuf(
|
|||
*/
|
||||
last_da = xfs_dir2_byte_to_da(geo, XFS_DIR2_LEAF_OFFSET);
|
||||
map_off = xfs_dir2_db_to_da(geo, xfs_dir2_byte_to_db(geo, *cur_off));
|
||||
if (!xfs_iext_lookup_extent(dp, ifp, map_off, &idx, &map))
|
||||
if (!xfs_iext_lookup_extent(dp, ifp, map_off, &icur, &map))
|
||||
goto out;
|
||||
if (map.br_startoff >= last_da)
|
||||
goto out;
|
||||
|
@ -311,7 +311,7 @@ xfs_dir2_leaf_readbuf(
|
|||
if (next_ra >= last_da)
|
||||
goto out_no_ra;
|
||||
if (map.br_blockcount < geo->fsbcount &&
|
||||
!xfs_iext_get_extent(ifp, ++idx, &map))
|
||||
!xfs_iext_next_extent(ifp, &icur, &map))
|
||||
goto out_no_ra;
|
||||
if (map.br_startoff >= last_da)
|
||||
goto out_no_ra;
|
||||
|
@ -334,7 +334,7 @@ xfs_dir2_leaf_readbuf(
|
|||
ra_want -= geo->fsbcount;
|
||||
next_ra += geo->fsbcount;
|
||||
}
|
||||
if (!xfs_iext_get_extent(ifp, ++idx, &map)) {
|
||||
if (!xfs_iext_next_extent(ifp, &icur, &map)) {
|
||||
*ra_blk = last_da;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -703,7 +703,7 @@ xfs_dq_get_next_id(
|
|||
xfs_dqid_t next_id = *id + 1; /* simple advance */
|
||||
uint lock_flags;
|
||||
struct xfs_bmbt_irec got;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor cur;
|
||||
xfs_fsblock_t start;
|
||||
int error = 0;
|
||||
|
||||
|
@ -727,7 +727,7 @@ xfs_dq_get_next_id(
|
|||
return error;
|
||||
}
|
||||
|
||||
if (xfs_iext_lookup_extent(quotip, "ip->i_df, start, &idx, &got)) {
|
||||
if (xfs_iext_lookup_extent(quotip, "ip->i_df, start, &cur, &got)) {
|
||||
/* contiguous chunk, bump startoff for the id calculation */
|
||||
if (got.br_startoff < start)
|
||||
got.br_startoff = start;
|
||||
|
|
|
@ -390,7 +390,7 @@ xfs_iomap_prealloc_size(
|
|||
struct xfs_inode *ip,
|
||||
loff_t offset,
|
||||
loff_t count,
|
||||
xfs_extnum_t idx)
|
||||
struct xfs_iext_cursor *icur)
|
||||
{
|
||||
struct xfs_mount *mp = ip->i_mount;
|
||||
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
|
||||
|
@ -415,7 +415,7 @@ xfs_iomap_prealloc_size(
|
|||
*/
|
||||
if ((mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) ||
|
||||
XFS_ISIZE(ip) < XFS_FSB_TO_B(mp, mp->m_dalign) ||
|
||||
!xfs_iext_get_extent(ifp, idx - 1, &prev) ||
|
||||
!xfs_iext_peek_prev_extent(ifp, icur, &prev) ||
|
||||
prev.br_startoff + prev.br_blockcount < offset_fsb)
|
||||
return mp->m_writeio_blocks;
|
||||
|
||||
|
@ -533,7 +533,7 @@ xfs_file_iomap_begin_delay(
|
|||
xfs_fileoff_t end_fsb;
|
||||
int error = 0, eof = 0;
|
||||
struct xfs_bmbt_irec got;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
xfs_fsblock_t prealloc_blocks = 0;
|
||||
|
||||
ASSERT(!XFS_IS_REALTIME_INODE(ip));
|
||||
|
@ -558,7 +558,7 @@ xfs_file_iomap_begin_delay(
|
|||
goto out_unlock;
|
||||
}
|
||||
|
||||
eof = !xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got);
|
||||
eof = !xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got);
|
||||
if (!eof && got.br_startoff <= offset_fsb) {
|
||||
if (xfs_is_reflink_inode(ip)) {
|
||||
bool shared;
|
||||
|
@ -592,7 +592,8 @@ xfs_file_iomap_begin_delay(
|
|||
end_fsb = min(XFS_B_TO_FSB(mp, offset + count), maxbytes_fsb);
|
||||
|
||||
if (eof) {
|
||||
prealloc_blocks = xfs_iomap_prealloc_size(ip, offset, count, idx);
|
||||
prealloc_blocks = xfs_iomap_prealloc_size(ip, offset, count,
|
||||
&icur);
|
||||
if (prealloc_blocks) {
|
||||
xfs_extlen_t align;
|
||||
xfs_off_t end_offset;
|
||||
|
@ -614,7 +615,8 @@ xfs_file_iomap_begin_delay(
|
|||
|
||||
retry:
|
||||
error = xfs_bmapi_reserve_delalloc(ip, XFS_DATA_FORK, offset_fsb,
|
||||
end_fsb - offset_fsb, prealloc_blocks, &got, &idx, eof);
|
||||
end_fsb - offset_fsb, prealloc_blocks, &got, &icur,
|
||||
eof);
|
||||
switch (error) {
|
||||
case 0:
|
||||
break;
|
||||
|
|
|
@ -273,7 +273,7 @@ xfs_reflink_reserve_cow(
|
|||
struct xfs_bmbt_irec got;
|
||||
int error = 0;
|
||||
bool eof = false, trimmed;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
|
||||
/*
|
||||
* Search the COW fork extent list first. This serves two purposes:
|
||||
|
@ -284,7 +284,7 @@ xfs_reflink_reserve_cow(
|
|||
* tree.
|
||||
*/
|
||||
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, imap->br_startoff, &idx, &got))
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, imap->br_startoff, &icur, &got))
|
||||
eof = true;
|
||||
if (!eof && got.br_startoff <= imap->br_startoff) {
|
||||
trace_xfs_reflink_cow_found(ip, imap);
|
||||
|
@ -312,7 +312,7 @@ xfs_reflink_reserve_cow(
|
|||
return error;
|
||||
|
||||
error = xfs_bmapi_reserve_delalloc(ip, XFS_COW_FORK, imap->br_startoff,
|
||||
imap->br_blockcount, 0, &got, &idx, eof);
|
||||
imap->br_blockcount, 0, &got, &icur, eof);
|
||||
if (error == -ENOSPC || error == -EDQUOT)
|
||||
trace_xfs_reflink_cow_enospc(ip, imap);
|
||||
if (error)
|
||||
|
@ -359,16 +359,16 @@ xfs_reflink_convert_cow(
|
|||
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
|
||||
xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
|
||||
xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, offset + count);
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
bool found;
|
||||
int error = 0;
|
||||
|
||||
xfs_ilock(ip, XFS_ILOCK_EXCL);
|
||||
|
||||
/* Convert all the extents to real from unwritten. */
|
||||
for (found = xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got);
|
||||
for (found = xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got);
|
||||
found && got.br_startoff < end_fsb;
|
||||
found = xfs_iext_get_extent(ifp, ++idx, &got)) {
|
||||
found = xfs_iext_next_extent(ifp, &icur, &got)) {
|
||||
error = xfs_reflink_convert_cow_extent(ip, &got, offset_fsb,
|
||||
end_fsb - offset_fsb, &dfops);
|
||||
if (error)
|
||||
|
@ -399,7 +399,7 @@ xfs_reflink_allocate_cow(
|
|||
bool trimmed;
|
||||
xfs_filblks_t resaligned;
|
||||
xfs_extlen_t resblks = 0;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
|
||||
retry:
|
||||
ASSERT(xfs_is_reflink_inode(ip));
|
||||
|
@ -409,7 +409,7 @@ xfs_reflink_allocate_cow(
|
|||
* Even if the extent is not shared we might have a preallocation for
|
||||
* it in the COW fork. If so use it.
|
||||
*/
|
||||
if (xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &idx, &got) &&
|
||||
if (xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &got) &&
|
||||
got.br_startoff <= offset_fsb) {
|
||||
*shared = true;
|
||||
|
||||
|
@ -496,13 +496,13 @@ xfs_reflink_find_cow_mapping(
|
|||
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
|
||||
xfs_fileoff_t offset_fsb;
|
||||
struct xfs_bmbt_irec got;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
|
||||
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL | XFS_ILOCK_SHARED));
|
||||
ASSERT(xfs_is_reflink_inode(ip));
|
||||
|
||||
offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got))
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got))
|
||||
return false;
|
||||
if (got.br_startoff > offset_fsb)
|
||||
return false;
|
||||
|
@ -524,18 +524,18 @@ xfs_reflink_trim_irec_to_next_cow(
|
|||
{
|
||||
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
|
||||
struct xfs_bmbt_irec got;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
|
||||
if (!xfs_is_reflink_inode(ip))
|
||||
return;
|
||||
|
||||
/* Find the extent in the CoW fork. */
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got))
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got))
|
||||
return;
|
||||
|
||||
/* This is the extent before; try sliding up one. */
|
||||
if (got.br_startoff < offset_fsb) {
|
||||
if (!xfs_iext_get_extent(ifp, idx + 1, &got))
|
||||
if (!xfs_iext_next_extent(ifp, &icur, &got))
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -562,14 +562,14 @@ xfs_reflink_cancel_cow_blocks(
|
|||
{
|
||||
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
|
||||
struct xfs_bmbt_irec got, del;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
xfs_fsblock_t firstfsb;
|
||||
struct xfs_defer_ops dfops;
|
||||
int error = 0;
|
||||
|
||||
if (!xfs_is_reflink_inode(ip))
|
||||
return 0;
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &idx, &got))
|
||||
if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &icur, &got))
|
||||
return 0;
|
||||
|
||||
while (got.br_startoff < end_fsb) {
|
||||
|
@ -579,7 +579,7 @@ xfs_reflink_cancel_cow_blocks(
|
|||
|
||||
if (isnullstartblock(del.br_startblock)) {
|
||||
error = xfs_bmap_del_extent_delay(ip, XFS_COW_FORK,
|
||||
&idx, &got, &del);
|
||||
&icur, &got, &del);
|
||||
if (error)
|
||||
break;
|
||||
} else if (del.br_state == XFS_EXT_UNWRITTEN || cancel_real) {
|
||||
|
@ -610,10 +610,10 @@ xfs_reflink_cancel_cow_blocks(
|
|||
}
|
||||
|
||||
/* Remove the mapping from the CoW fork. */
|
||||
xfs_bmap_del_extent_cow(ip, &idx, &got, &del);
|
||||
xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
|
||||
}
|
||||
|
||||
if (!xfs_iext_get_extent(ifp, ++idx, &got))
|
||||
if (!xfs_iext_next_extent(ifp, &icur, &got))
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -698,7 +698,7 @@ xfs_reflink_end_cow(
|
|||
int error;
|
||||
unsigned int resblks;
|
||||
xfs_filblks_t rlen;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
|
||||
trace_xfs_reflink_end_cow(ip, offset, count);
|
||||
|
||||
|
@ -738,7 +738,7 @@ xfs_reflink_end_cow(
|
|||
* left by the time I/O completes for the loser of the race. In that
|
||||
* case we are done.
|
||||
*/
|
||||
if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &idx, &got))
|
||||
if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got))
|
||||
goto out_cancel;
|
||||
|
||||
/* Walk backwards until we're out of the I/O range... */
|
||||
|
@ -746,9 +746,9 @@ xfs_reflink_end_cow(
|
|||
del = got;
|
||||
xfs_trim_extent(&del, offset_fsb, end_fsb - offset_fsb);
|
||||
|
||||
/* Extent delete may have bumped idx forward */
|
||||
/* Extent delete may have bumped ext forward */
|
||||
if (!del.br_blockcount) {
|
||||
idx--;
|
||||
xfs_iext_prev(ifp, &icur);
|
||||
goto next_extent;
|
||||
}
|
||||
|
||||
|
@ -760,7 +760,7 @@ xfs_reflink_end_cow(
|
|||
* allocated but have not yet been involved in a write.
|
||||
*/
|
||||
if (got.br_state == XFS_EXT_UNWRITTEN) {
|
||||
idx--;
|
||||
xfs_iext_prev(ifp, &icur);
|
||||
goto next_extent;
|
||||
}
|
||||
|
||||
|
@ -791,14 +791,14 @@ xfs_reflink_end_cow(
|
|||
goto out_defer;
|
||||
|
||||
/* Remove the mapping from the CoW fork. */
|
||||
xfs_bmap_del_extent_cow(ip, &idx, &got, &del);
|
||||
xfs_bmap_del_extent_cow(ip, &icur, &got, &del);
|
||||
|
||||
xfs_defer_ijoin(&dfops, ip);
|
||||
error = xfs_defer_finish(&tp, &dfops);
|
||||
if (error)
|
||||
goto out_defer;
|
||||
next_extent:
|
||||
if (!xfs_iext_get_extent(ifp, idx, &got))
|
||||
if (!xfs_iext_get_extent(ifp, &icur, &got))
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1428,7 +1428,7 @@ xfs_reflink_inode_has_shared_extents(
|
|||
xfs_extlen_t aglen;
|
||||
xfs_agblock_t rbno;
|
||||
xfs_extlen_t rlen;
|
||||
xfs_extnum_t idx;
|
||||
struct xfs_iext_cursor icur;
|
||||
bool found;
|
||||
int error;
|
||||
|
||||
|
@ -1440,7 +1440,7 @@ xfs_reflink_inode_has_shared_extents(
|
|||
}
|
||||
|
||||
*has_shared = false;
|
||||
found = xfs_iext_lookup_extent(ip, ifp, 0, &idx, &got);
|
||||
found = xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got);
|
||||
while (found) {
|
||||
if (isnullstartblock(got.br_startblock) ||
|
||||
got.br_state != XFS_EXT_NORM)
|
||||
|
@ -1459,7 +1459,7 @@ xfs_reflink_inode_has_shared_extents(
|
|||
return 0;
|
||||
}
|
||||
next:
|
||||
found = xfs_iext_get_extent(ifp, ++idx, &got);
|
||||
found = xfs_iext_next_extent(ifp, &icur, &got);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -258,9 +258,9 @@ TRACE_EVENT(xfs_iext_insert,
|
|||
);
|
||||
|
||||
DECLARE_EVENT_CLASS(xfs_bmap_class,
|
||||
TP_PROTO(struct xfs_inode *ip, xfs_extnum_t idx, int state,
|
||||
TP_PROTO(struct xfs_inode *ip, struct xfs_iext_cursor *cur, int state,
|
||||
unsigned long caller_ip),
|
||||
TP_ARGS(ip, idx, state, caller_ip),
|
||||
TP_ARGS(ip, cur, state, caller_ip),
|
||||
TP_STRUCT__entry(
|
||||
__field(dev_t, dev)
|
||||
__field(xfs_ino_t, ino)
|
||||
|
@ -277,10 +277,10 @@ DECLARE_EVENT_CLASS(xfs_bmap_class,
|
|||
struct xfs_bmbt_irec r;
|
||||
|
||||
ifp = xfs_iext_state_to_fork(ip, state);
|
||||
xfs_iext_get_extent(ifp, idx, &r);
|
||||
xfs_iext_get_extent(ifp, cur, &r);
|
||||
__entry->dev = VFS_I(ip)->i_sb->s_dev;
|
||||
__entry->ino = ip->i_ino;
|
||||
__entry->idx = idx;
|
||||
__entry->idx = cur->idx;
|
||||
__entry->startoff = r.br_startoff;
|
||||
__entry->startblock = r.br_startblock;
|
||||
__entry->blockcount = r.br_blockcount;
|
||||
|
@ -303,9 +303,9 @@ DECLARE_EVENT_CLASS(xfs_bmap_class,
|
|||
|
||||
#define DEFINE_BMAP_EVENT(name) \
|
||||
DEFINE_EVENT(xfs_bmap_class, name, \
|
||||
TP_PROTO(struct xfs_inode *ip, xfs_extnum_t idx, int state, \
|
||||
TP_PROTO(struct xfs_inode *ip, struct xfs_iext_cursor *cur, int state, \
|
||||
unsigned long caller_ip), \
|
||||
TP_ARGS(ip, idx, state, caller_ip))
|
||||
TP_ARGS(ip, cur, state, caller_ip))
|
||||
DEFINE_BMAP_EVENT(xfs_iext_remove);
|
||||
DEFINE_BMAP_EVENT(xfs_bmap_pre_update);
|
||||
DEFINE_BMAP_EVENT(xfs_bmap_post_update);
|
||||
|
|
Loading…
Reference in New Issue
Block a user