ltp icon indicating copy to clipboard operation
ltp copied to clipboard

ioctl_fiemap01: expects EBADR but ext2 returns EINVAL — false failure

Open quantienvu opened this issue 6 months ago • 5 comments

Summary: When running ioctl_fiemap01 on ext2, the test fails because it expects EBADR (53) when passing an invalid FIEMAP structure, but the kernel returns EINVAL (22) instead.

This behavior is consistent across different kernel versions. Other filesystems like ext3/ext4 return EBADR as expected, but ext2 uses generic_block_fiemap() which returns EINVAL on invalid input.

Environment:

  • Kernel: 6.1.x
  • FS under test: ext2 (via loop device)
  • Test: ioctl_fiemap01
  • LTP version: 20250530

Could you help check this issue? On ext2, the test expects EBADR but gets EINVAL. Maybe FIEMAP behaves differently. Let me know if you need logs. Thanks!

quantienvu avatar Jun 05 '25 07:06 quantienvu

@quantienvu which kernel driver is this? I think that ext2 is in most cases mounted by the ext4 driver these days and that works as expected. If you are mounting ext2 with the ext2 driver the EINVAL return would likely mean that the ioctl() is not implemented there and we need to skip the test in that case.

metan-ucw avatar Jun 06 '25 09:06 metan-ucw

Hi @metan-ucw,

The kernel driver in use here is the ext2 driver.

tst_test.c:1888: TINFO: === Testing on ext2 ===
tst_test.c:1217: TINFO: Formatting /dev/loop0 with ext2 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
[ 8973.513371] operation not supported error, dev loop0, sector 614272 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.525454] operation not supported error, dev loop0, sector 524 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.538160] operation not supported error, dev loop0, sector 16908 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.551116] operation not supported error, dev loop0, sector 32774 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.564186] operation not supported error, dev loop0, sector 49676 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.577098] operation not supported error, dev loop0, sector 65542 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.589845] operation not supported error, dev loop0, sector 82444 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.602803] operation not supported error, dev loop0, sector 98310 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.615818] operation not supported error, dev loop0, sector 115212 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
[ 8973.628900] operation not supported error, dev loop0, sector 131078 op 0x9:(WRITE_ZEROES) flags 0x8000800 phys_seg 0 prio class 2
tst_test.c:1229: [ 8973.695905] ext2 filesystem being mounted at /tmp/ltp-OdxB14K1ZX/LTP_ioctRZZxV/mntpoint supports timestamps until 2038 (0x7fffffff)
TINFO: Mounting /dev/loop0 to /tmp/ltp-OdxB14K1ZX/LTP_ioctRZZxV/mntpoint fstyp=ext2 flags=0
ioctl_fiemap01.c:74: TFAIL: ioctl(fd, FS_IOC_FIEMAP, fiemap) expected EBADR: EINVAL (22)
ioctl_fiemap01.c:77: TFAIL: ioctl(fd, FS_IOC_FIEMAP, fiemap) failed: EINVAL (22)
ioctl_fiemap01.c:79: TPASS: Expect: Empty file should have 0 extends mapped
ioctl_fiemap01.c:86: TPASS: ioctl(fd, FS_IOC_FIEMAP, fiemap) passed
ioctl_fiemap01.c:41: TPASS: Expect: extent fm_mapped_extents is 1
ioctl_fiemap01.c:50: TPASS: (extent->fe_flags & fe_mask) == fe_flags (1)
ioctl_fiemap01.c:51: TPASS: Expect: fe_physical > 1
ioctl_fiemap01.c:52: TPASS: extent->fe_length == fe_length (1024)
ioctl_fiemap01.c:96: TPASS: ioctl(fd, FS_IOC_FIEMAP, fiemap) passed
ioctl_fiemap01.c:41: TPASS: Expect: extent fm_mapped_extents is 3
ioctl_fiemap01.c:50: TPASS: (extent->fe_flags & fe_mask) == fe_flags (0)
ioctl_fiemap01.c:51: TPASS: Expect: fe_physical > 1
ioctl_fiemap01.c:52: TPASS: extent->fe_length == fe_length (1024)
ioctl_fiemap01.c:50: TPASS: (extent->fe_flags & fe_mask) == fe_flags (0)
ioctl_fiemap01.c:51: TPASS: Expect: fe_physical > 1
ioctl_fiemap01.c:52: TPASS: extent->fe_length == fe_length (1024)
ioctl_fiemap01.c:50: TPASS: (extent->fe_flags & fe_mask) == fe_flags (1)
ioctl_fiemap01.c:51: TPASS: Expect: fe_physical > 1
ioctl_fiemap01.c:52: TPASS: extent->fe_length == fe_length (1024)
tst_test.c:1888: TINFO: === Testing on ext3 ===
tst_test.c:1217: TINFO: Formatting /dev/loop0 with ext3 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1229: TINFO: Mount[ 8974.006617] EXT4-fs (loop0): mounting ext3 file system using the ext4 subsystem
[ 8974.020659] EXT4-fs (loop0): mounted filesystem with ordered data mode. Quota mode: none.

The kernel returns EINVAL because ext2 uses iomap_fiemap(), and when passed invalid input, it returns -EINVAL. This differs from ext4, which has its own fiemap implementation that returns -EBADR as expected.

Could you help confirm if the test should expect EINVAL for ext2, or if this is something worth handling differently in the test framework?

quantienvu avatar Jun 06 '25 11:06 quantienvu

ext2 seems support fiemap and implement in ext2_fiemap, will check the logic of kernel.

coolgw avatar Jun 11 '25 08:06 coolgw

In following function the len will be 0 if no any file in filesystem, then will trigger EINVAL within iomap_fiemap, either we workaround this or fix this from kernel side.

int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
                u64 start, u64 len)
{
        int ret;

        inode_lock(inode);
        len = min_t(u64, len, i_size_read(inode));
        ret = iomap_fiemap(inode, fieinfo, start, len, &ext2_iomap_ops);
        inode_unlock(inode);

        return ret;
}

coolgw avatar Jun 11 '25 10:06 coolgw

https://lore.kernel.org/all/[email protected]/

coolgw avatar Jun 12 '25 02:06 coolgw

If I'm looking right the kernel patch has been accepted into 6.16.

metan-ucw avatar Sep 15 '25 14:09 metan-ucw