Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ext4: add mext_check_validity() to do basic check

Currently, the basic validation checks during the move extent operation
are scattered across __ext4_ioctl() and ext4_move_extents(), which makes
the code somewhat disorganized. Introduce a new helper,
mext_check_validity(), to handle these checks. This change involves only
code relocation without any logical modifications.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Message-ID: <20251013015128.499308-7-yi.zhang@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Zhang Yi and committed by
Theodore Ts'o
22218516 c9570b66

+65 -47
-10
fs/ext4/ioctl.c
··· 1641 1641 if (!(fd_file(donor)->f_mode & FMODE_WRITE)) 1642 1642 return -EBADF; 1643 1643 1644 - if (ext4_has_feature_bigalloc(sb)) { 1645 - ext4_msg(sb, KERN_ERR, 1646 - "Online defrag not supported with bigalloc"); 1647 - return -EOPNOTSUPP; 1648 - } else if (IS_DAX(inode)) { 1649 - ext4_msg(sb, KERN_ERR, 1650 - "Online defrag not supported with DAX"); 1651 - return -EOPNOTSUPP; 1652 - } 1653 - 1654 1644 err = mnt_want_write_file(filp); 1655 1645 if (err) 1656 1646 return err;
+65 -37
fs/ext4/move_extent.c
··· 442 442 goto unlock_folios; 443 443 } 444 444 445 + /* 446 + * Check the validity of the basic filesystem environment and the 447 + * inodes' support status. 448 + */ 449 + static int mext_check_validity(struct inode *orig_inode, 450 + struct inode *donor_inode) 451 + { 452 + struct super_block *sb = orig_inode->i_sb; 453 + 454 + /* origin and donor should be different inodes */ 455 + if (orig_inode == donor_inode) { 456 + ext4_debug("ext4 move extent: The argument files should not be same inode [ino:orig %lu, donor %lu]\n", 457 + orig_inode->i_ino, donor_inode->i_ino); 458 + return -EINVAL; 459 + } 460 + 461 + /* origin and donor should belone to the same filesystem */ 462 + if (orig_inode->i_sb != donor_inode->i_sb) { 463 + ext4_debug("ext4 move extent: The argument files should be in same FS [ino:orig %lu, donor %lu]\n", 464 + orig_inode->i_ino, donor_inode->i_ino); 465 + return -EINVAL; 466 + } 467 + 468 + /* Regular file check */ 469 + if (!S_ISREG(orig_inode->i_mode) || !S_ISREG(donor_inode->i_mode)) { 470 + ext4_debug("ext4 move extent: The argument files should be regular file [ino:orig %lu, donor %lu]\n", 471 + orig_inode->i_ino, donor_inode->i_ino); 472 + return -EINVAL; 473 + } 474 + 475 + if (ext4_has_feature_bigalloc(sb)) { 476 + ext4_msg(sb, KERN_ERR, 477 + "Online defrag not supported with bigalloc"); 478 + return -EOPNOTSUPP; 479 + } 480 + 481 + if (IS_DAX(orig_inode)) { 482 + ext4_msg(sb, KERN_ERR, 483 + "Online defrag not supported with DAX"); 484 + return -EOPNOTSUPP; 485 + } 486 + 487 + /* 488 + * TODO: it's not obvious how to swap blocks for inodes with full 489 + * journaling enabled. 490 + */ 491 + if (ext4_should_journal_data(orig_inode) || 492 + ext4_should_journal_data(donor_inode)) { 493 + ext4_msg(sb, KERN_ERR, 494 + "Online defrag not supported with data journaling"); 495 + return -EOPNOTSUPP; 496 + } 497 + 498 + if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) { 499 + ext4_msg(sb, KERN_ERR, 500 + "Online defrag not supported for encrypted files"); 501 + return -EOPNOTSUPP; 502 + } 503 + 504 + return 0; 505 + } 506 + 445 507 /** 446 508 * mext_check_arguments - Check whether move extent can be done 447 509 * ··· 629 567 ext4_lblk_t d_start = donor_blk; 630 568 int ret; 631 569 632 - if (orig_inode->i_sb != donor_inode->i_sb) { 633 - ext4_debug("ext4 move extent: The argument files " 634 - "should be in same FS [ino:orig %lu, donor %lu]\n", 635 - orig_inode->i_ino, donor_inode->i_ino); 636 - return -EINVAL; 637 - } 638 - 639 - /* orig and donor should be different inodes */ 640 - if (orig_inode == donor_inode) { 641 - ext4_debug("ext4 move extent: The argument files should not " 642 - "be same inode [ino:orig %lu, donor %lu]\n", 643 - orig_inode->i_ino, donor_inode->i_ino); 644 - return -EINVAL; 645 - } 646 - 647 - /* Regular file check */ 648 - if (!S_ISREG(orig_inode->i_mode) || !S_ISREG(donor_inode->i_mode)) { 649 - ext4_debug("ext4 move extent: The argument files should be " 650 - "regular file [ino:orig %lu, donor %lu]\n", 651 - orig_inode->i_ino, donor_inode->i_ino); 652 - return -EINVAL; 653 - } 654 - 655 - /* TODO: it's not obvious how to swap blocks for inodes with full 656 - journaling enabled */ 657 - if (ext4_should_journal_data(orig_inode) || 658 - ext4_should_journal_data(donor_inode)) { 659 - ext4_msg(orig_inode->i_sb, KERN_ERR, 660 - "Online defrag not supported with data journaling"); 661 - return -EOPNOTSUPP; 662 - } 663 - 664 - if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) { 665 - ext4_msg(orig_inode->i_sb, KERN_ERR, 666 - "Online defrag not supported for encrypted files"); 667 - return -EOPNOTSUPP; 668 - } 570 + ret = mext_check_validity(orig_inode, donor_inode); 571 + if (ret) 572 + return ret; 669 573 670 574 /* Protect orig and donor inodes against a truncate */ 671 575 lock_two_nondirectories(orig_inode, donor_inode);