Bug 271105 - ext2fs can not mount disks with 4K native sector size
Summary: ext2fs can not mount disks with 4K native sector size
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.2-STABLE
Hardware: amd64 Any
: --- Affects Some People
Assignee: Fedor Uporov
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2023-04-27 20:31 UTC by bolvan
Modified: 2023-05-21 05:21 UTC (History)
4 users (show)

See Also:


Attachments
Add more printfs to mount path (40.51 KB, text/plain)
2023-04-29 15:00 UTC, Fedor Uporov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description bolvan 2023-04-27 20:31:22 UTC
mount -t ext2fs /dev/nvd0p3 /mnt/linux
mount: /dev/nvd0p3: Invalid argument

It worked well until I moved linux parftition to nvme disk with 4K native sector size. nvme's usually can be formatted with either 512 or 4096 sector size. by default they come with 512 sector size.

tune2fs, e2fsck from BSD work well. linux mounts this partition without any problems.
I can successfully mount msdos and ntfs partitions from that drive in FreeBSD

Googling this case I found someone experiencing same bug with a 4k native disk
Comment 1 Fedor Uporov freebsd_committer freebsd_triage 2023-04-29 05:03:43 UTC
Could you please, provide dmesg output, when you do mount and get error.
If nothing will be seen in dmesg, could you please run dtrace with next command:
% dtrace -n 'ext2fs::vfsops:* {  printf("%s",stringof(arg0));  }'
and try mount again.
Comment 2 bolvan 2023-04-29 06:42:22 UTC
dmesg is empty

dtrace -n 'ext2fs::vfsops:* {  printf("%s",stringof(arg0));  }'

did not output anything except 

dtrace: description 'ext2fs::vfsops:* ' matched 3 probes
Comment 3 Fedor Uporov freebsd_committer freebsd_triage 2023-04-29 09:22:24 UTC
Ok, there is some number of EINVAL returns from mount path, which are not logged.

Do you have ability to rebuild ext2fs kernel module?

I will provide diff with some number of printfs, and instructions, how to rebuild it and load from /usr/src.
Comment 4 bolvan 2023-04-29 09:40:53 UTC
OK, I'll try
Comment 5 Robert Clausecker freebsd_committer freebsd_triage 2023-04-29 12:14:15 UTC
ext2fs also has trouble with file systems larger than 2 TiB.  Could this be related?
Comment 6 bolvan 2023-04-29 12:51:50 UTC
Actually it's easy to reproduce in qemu


qemu-img.exe create -f raw test.raw 1G
qemu-img.exe create -f raw test2.raw 1G

qemu-system-x86_64.exe -drive format=qcow2,file=f.qcow2 -drive format=raw,file=test.raw,id=D24,if=none -device nvme,drive=D24,serial=1234,physical_block_size=4096,logical_block_size=4096  -drive format=raw,file=test2.raw,id=D25,if=none -device nvme,drive=D25,serial=1235,physical_block_size=512,logical_block_size=512   -m 4096

f.qcow2 contains freebsd
test.raw has 4096 sector size
test2.raw has 512 sector size

mke2fs on both nvd0 and nvd1
mount first fails
mount second succeeds
Comment 7 Fedor Uporov freebsd_committer freebsd_triage 2023-04-29 15:00:15 UTC
Created attachment 241856 [details]
Add more printfs to mount path
Comment 8 Fedor Uporov freebsd_committer freebsd_triage 2023-04-29 15:00:47 UTC
Hope, I am understand correctly, where EINVAL come from, but need to be sure, that qemu and hw nvme issues are identical.

Could you please download the attached file.
And do next steps:

% md5sum ./ext2_vfsops.c
1f7a613c27331abf391cb4ab6b99f434  ./ext2_vfsops.c
% cp /usr/src/sys/fs/ext2fs/ext2_vfsops.c cp /usr/src/sys/fs/ext2fs/ext2_vfsops.c_bkp
% cp ./ext2_vfsops.c /usr/src/sys/fs/ext2fs/
% cd /usr/src/sys/modules/ext2fs
% make clean ; make
% find / -name ext2fs.ko
# The ext2fs.ko in the /usr/obj directory should be right module
% kldload /usr/obj/path/to/ext2fs.ko

Try to mount nvme drive and do dmesg, if everything is right, you should see "==== ext2_mount(+)"
Please send me everything below this line
Comment 9 bolvan 2023-04-29 15:40:23 UTC
(In reply to Fedor Uporov from comment #8)

ext2_mountfs():SBSIZE:1024:4096,err=EINVAL
==== ext2_mountfs(): err=22
Comment 10 Fedor Uporov freebsd_committer freebsd_triage 2023-04-29 15:52:18 UTC
Ok, it is what I expected. Now I have clean issue definition.
I do not have tests to verify disks with 4k sectors, it is time to add it.
Thank you for participation and fast replies.
It need some time to fix it.
Comment 11 Fedor Uporov freebsd_committer freebsd_triage 2023-04-29 15:54:15 UTC
(In reply to Robert Clausecker from comment #5)
If the drive have 4k sectors size, should be.
If not, could you please provide more detailed description.
Comment 12 bolvan 2023-04-29 16:56:51 UTC
(In reply to Robert Clausecker from comment #5)

I tested this in qemu.
qcow2 format allows to create drives large then available disk space
I found no problem mounting 2.8T ext2 fs on a 512 sector size disk
Comment 13 Graham Perrin freebsd_committer freebsd_triage 2023-04-29 17:47:40 UTC
Triage: fs@ no longer the assignee, is now a cc recipient.
Comment 14 Robert Clausecker freebsd_committer freebsd_triage 2023-04-29 17:53:15 UTC
(In reply to Fedor Uporov from comment #11)

If you have a disk of more than 2 TiB and do IO on it, the kernel randomly crashes.  The disk needs to be somewhat full for the problem to trigger.  I think it only happens when files are accessed that are allocated beyond the 2 TiB mark.
Comment 15 commit-hook freebsd_committer freebsd_triage 2023-05-21 05:21:25 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=50be18cc77b25891306f64192bf6f75e55d8903c

commit 50be18cc77b25891306f64192bf6f75e55d8903c
Author:     Fedor Uporov <fsu@FreeBSD.org>
AuthorDate: 2023-05-08 16:14:02 +0000
Commit:     Fedor Uporov <fsu@FreeBSD.org>
CommitDate: 2023-05-21 05:17:47 +0000

    ext2fs: Add large sectorsize disks support

    The ext2fs does not support disks with sectorsize more 512 bytes.
    The main issue is in reading/writing superblock, which is not aligned
    with 4k value. Reimplement the superblock reading logic to make it
    indifferent to disk logical sector size. The logical sector size
    more then page size is not supported, like it is doing on Linux side.

    PR:             271105
    Reported by:    k(at)vodka.home.kg
    Reviewed by:    pfg
    MFC after:      2 week
    Differential Revision:  https://reviews.freebsd.org/D40047

 sys/fs/ext2fs/ext2_vfsops.c | 48 ++++++++++++++++++++++++---------------------
 sys/fs/ext2fs/fs.h          |  6 ++++--
 2 files changed, 30 insertions(+), 24 deletions(-)