@@ -367,6 +367,51 @@ xfs_rmap_lookup_le_range(
367
367
return error ;
368
368
}
369
369
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
+
370
415
/*
371
416
* Find the extent in the rmap btree and remove it.
372
417
*
@@ -468,33 +513,16 @@ xfs_rmap_unmap(
468
513
goto out_done ;
469
514
}
470
515
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
-
475
516
/* Make sure the extent we found covers the entire freeing range. */
476
517
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 );
483
520
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 ;
498
526
499
527
if (ltrec .rm_startblock == bno && ltrec .rm_blockcount == len ) {
500
528
/* exact match, simply remove the record from rmap tree */
0 commit comments