Skip to content

Commit 68c58e9

Browse files
committed
xfs: only skip rmap owner checks for unknown-owner rmap removal
For rmap removal, refactor the rmap owner checks into a separate function, then skip the checks if we are performing an unknown-owner removal. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 33df3a9 commit 68c58e9

File tree

1 file changed

+52
-24
lines changed

1 file changed

+52
-24
lines changed

fs/xfs/libxfs/xfs_rmap.c

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,51 @@ xfs_rmap_lookup_le_range(
367367
return error;
368368
}
369369

370+
/*
371+
* Perform all the relevant owner checks for a removal op. If we're doing an
372+
* unknown-owner removal then we have no owner information to check.
373+
*/
374+
static int
375+
xfs_rmap_free_check_owner(
376+
struct xfs_mount *mp,
377+
uint64_t ltoff,
378+
struct xfs_rmap_irec *rec,
379+
xfs_fsblock_t bno,
380+
xfs_filblks_t len,
381+
uint64_t owner,
382+
uint64_t offset,
383+
unsigned int flags)
384+
{
385+
int error = 0;
386+
387+
if (owner == XFS_RMAP_OWN_UNKNOWN)
388+
return 0;
389+
390+
/* Make sure the unwritten flag matches. */
391+
XFS_WANT_CORRUPTED_GOTO(mp, (flags & XFS_RMAP_UNWRITTEN) ==
392+
(rec->rm_flags & XFS_RMAP_UNWRITTEN), out);
393+
394+
/* Make sure the owner matches what we expect to find in the tree. */
395+
XFS_WANT_CORRUPTED_GOTO(mp, owner == rec->rm_owner, out);
396+
397+
/* Check the offset, if necessary. */
398+
if (XFS_RMAP_NON_INODE_OWNER(owner))
399+
goto out;
400+
401+
if (flags & XFS_RMAP_BMBT_BLOCK) {
402+
XFS_WANT_CORRUPTED_GOTO(mp, rec->rm_flags & XFS_RMAP_BMBT_BLOCK,
403+
out);
404+
} else {
405+
XFS_WANT_CORRUPTED_GOTO(mp, rec->rm_offset <= offset, out);
406+
XFS_WANT_CORRUPTED_GOTO(mp,
407+
ltoff + rec->rm_blockcount >= offset + len,
408+
out);
409+
}
410+
411+
out:
412+
return error;
413+
}
414+
370415
/*
371416
* Find the extent in the rmap btree and remove it.
372417
*
@@ -468,33 +513,16 @@ xfs_rmap_unmap(
468513
goto out_done;
469514
}
470515

471-
/* Make sure the unwritten flag matches. */
472-
XFS_WANT_CORRUPTED_GOTO(mp, (flags & XFS_RMAP_UNWRITTEN) ==
473-
(ltrec.rm_flags & XFS_RMAP_UNWRITTEN), out_error);
474-
475516
/* Make sure the extent we found covers the entire freeing range. */
476517
XFS_WANT_CORRUPTED_GOTO(mp, ltrec.rm_startblock <= bno &&
477-
ltrec.rm_startblock + ltrec.rm_blockcount >=
478-
bno + len, out_error);
479-
480-
/* Make sure the owner matches what we expect to find in the tree. */
481-
XFS_WANT_CORRUPTED_GOTO(mp, owner == ltrec.rm_owner ||
482-
XFS_RMAP_NON_INODE_OWNER(owner), out_error);
518+
ltrec.rm_startblock + ltrec.rm_blockcount >=
519+
bno + len, out_error);
483520

484-
/* Check the offset, if necessary. */
485-
if (!XFS_RMAP_NON_INODE_OWNER(owner)) {
486-
if (flags & XFS_RMAP_BMBT_BLOCK) {
487-
XFS_WANT_CORRUPTED_GOTO(mp,
488-
ltrec.rm_flags & XFS_RMAP_BMBT_BLOCK,
489-
out_error);
490-
} else {
491-
XFS_WANT_CORRUPTED_GOTO(mp,
492-
ltrec.rm_offset <= offset, out_error);
493-
XFS_WANT_CORRUPTED_GOTO(mp,
494-
ltoff + ltrec.rm_blockcount >= offset + len,
495-
out_error);
496-
}
497-
}
521+
/* Check owner information. */
522+
error = xfs_rmap_free_check_owner(mp, ltoff, &ltrec, bno, len, owner,
523+
offset, flags);
524+
if (error)
525+
goto out_error;
498526

499527
if (ltrec.rm_startblock == bno && ltrec.rm_blockcount == len) {
500528
/* exact match, simply remove the record from rmap tree */

0 commit comments

Comments
 (0)