-1

I ran into a strange problem where mkfs.ext4 won't work on loop devices backed by a temp file.

tmp_file="$(mktemp)"
fallocate -l 8M "$tmp_file"
loop="$(losetup --show -f "$tmp_file")"
mkfs.ext4 "$loop"

I tried dd if=/dev/zero and truncate as well. Same result. What's absurd is that the failure doesn't propagate up to the application layer. mkfs programs exit with 0, but the output file system is basically mangled. It's probably got something to do with buffered/delayed io.

Am I not allowed to do this? Or is it a bug? I could probably investigate further by reading kernel code, but I wanted to hear from the experts first.

Update Oops. Sorry. Kernel version: 5.7.10-201.fc32.x86_64

The kernel messages.

[ 3213.106709] blk_update_request: operation not supported error, dev loop6, sector 16256 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3213.107013] blk_update_request: operation not supported error, dev loop6, sector 196 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3213.108396] blk_update_request: operation not supported error, dev loop6, sector 708 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3213.110006] blk_update_request: operation not supported error, dev loop6, sector 160 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3213.110158] blk_update_request: operation not supported error, dev loop6, sector 166 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3213.110852] blk_update_request: operation not supported error, dev loop6, sector 710 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3223.152191] blk_update_request: operation not supported error, dev loop7, sector 16256 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3223.152619] blk_update_request: operation not supported error, dev loop7, sector 196 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3223.153694] blk_update_request: operation not supported error, dev loop7, sector 708 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3223.155495] blk_update_request: operation not supported error, dev loop7, sector 160 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3223.155670] blk_update_request: operation not supported error, dev loop7, sector 166 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3223.156233] blk_update_request: operation not supported error, dev loop7, sector 710 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3568.666245] blk_update_request: operation not supported error, dev loop6, sector 16256 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3568.666543] blk_update_request: operation not supported error, dev loop6, sector 196 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3568.667546] blk_update_request: operation not supported error, dev loop6, sector 708 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3568.669204] blk_update_request: operation not supported error, dev loop6, sector 160 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3568.669380] blk_update_request: operation not supported error, dev loop6, sector 166 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0
[ 3568.669974] blk_update_request: operation not supported error, dev loop6, sector 710 op 0x9:(WRITE_ZEROES) flags 0x1000800 phys_seg 0 prio class 0

Like I said, mkfs should run successfully. The error is silent.

  • I cannot reproduce your problem -- what you have there works for me. The mkfs.ext4 is successful and I can mount the loop device. Where are you seeing this error message? – Andy Dalton Aug 11 '20 at 01:08
  • @AndyDalton The bug's in the kernel, not the fs utils themselves. –  Aug 11 '20 at 03:31
  • 1
    What's the filesystem of the backing file? – frostschutz Aug 11 '20 at 05:24
  • It's interesting that your logs mention both loop6 and loop7. What is $loop in this case? – Andy Dalton Aug 11 '20 at 23:25
  • @AndyDalton I just ran that script a few times. Are you trying to troll me or are you really trying to help? –  Aug 11 '20 at 23:35
  • Please read the post or don't bother wasting comment spaces –  Aug 11 '20 at 23:36
  • I was trying to ascertain if the logs were directly related to what you are doing or if it was possible they were reporting about a different loop device. If you don't think I'm trying to help, then I'll stop trying. – Andy Dalton Aug 11 '20 at 23:44

1 Answers1

1

I just ran into what I believe is the same issue. I suspect that you isn't mktemp per-se, but that your /tmp is a tmpfs filesystem. Apparently tmpfs does not support FALLOC_FL_ZERO_RANGE. What's interesting is you can run mkfs.ext4 on a file on a tmpfs mount without issue. But when its a loop device backed by a file on the same tmpfs, troubles arise.

You should be able to work around this by using the -p option for mktemp setting TMPDIR to a path on a filesystem which does support zero range (most of your standard ones).

crass
  • 338
  • 1
  • 7