Short script below that shows my problem.
fusermount -u (and umount) both return before all the data is written
out to the backing file on a fuse FS. Is there any way to tell when this
is complete? I tried running fuse in the foreground and then doing a
wait $PID but that didn't help, I still needed the sleep.
At least on my system, with a fs of 50G it always unmounts quickly
enough for the e2fsck to pass, at 500G it sometimes does, and at 5T it
seems to always fail without the sleep (which can probably be a bit
shorter than 30s but I haven't bothered to try to work out exactly how
much shorter it can safely be.
Tim.
#!/bin/bash
set -e
ROOT=mount
DEV=container_mount/pv1
rm -f container
rm -fr container_mount
rm -fr mount
mkdir -p container_mount
# create a container fs that can hold a 5T sparse file
truncate -s 3G container
/sbin/mke2fs -t ext4 -O \
none,has_journal,ext_attr,dir_index,filetype,extent,64bit,flex_bg,sparse_super,large_file,huge_file,dir_nlink,extra_is
-b 4096 container
fuse2fs -o fakeroot container container_mount
mkdir -p "$ROOT"
echo "truncate $(date)"
truncate -s 5T "${DEV}"
echo "mke2fs $(date)"
/sbin/mkfs.ext4 -N 1000000 -O \
none,has_journal,ext_attr,dir_index,filetype,extent,64bit,flex_bg,sparse_super,large_file,huge_file,dir_nlink,extra_is
-b 1024 "$DEV"
echo "fuse2fs ${DEV} ${ROOT} $(date)"
fuse2fs -o fakeroot "$DEV" "$ROOT"
echo "make filler $(date)"
touch "${ROOT}/filler"
echo "fusermount -u $ROOT $(date)"
fusermount -u "$ROOT"
### How can I avoid this step
echo "sleeping"
sleep 30
/sbin/e2fsck -f "$DEV" || true
fusermount -u container_mount
rm container
rmdir $ROOT
rmdir container_mount
exit 0