• How to know when a fuse filesystem is properly unmounted

    From Tim Woodall@21:1/5 to All on Mon May 19 20:30:01 2025
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From songbird@21:1/5 to Tim Woodall on Tue May 20 00:20:01 2025
    Tim Woodall wrote:
    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




    sync should do it, but there are important details to check
    which i hope are explained by the man page or the referenced
    items at the bottom:


    "BUGS
    Persistence guarantees vary per system. See the system calls below for
    more details.

    AUTHOR
    Written by Jim Meyering and Giuseppe Scrivano.

    REPORTING BUGS
    GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
    Report any translation bugs to <https://translationproject.org/team/>

    SEE ALSO
    fdatasync(2), fsync(2), sync(2), syncfs(2)

    Full documentation <https://www.gnu.org/software/coreutils/sync>
    or available locally via: info '(coreutils) sync invocation'
    "

    songbird

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Woodall@21:1/5 to songbird on Tue May 20 19:50:01 2025
    On Mon, 19 May 2025, songbird wrote:

    Tim Woodall wrote:
    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.


    sync should do it, but there are important details to check
    which i hope are explained by the man page or the referenced
    items at the bottom:

    I tried sync but it didn't work - the key problem is that when you call fusermount -u, that returns while the fuse2fs program is still writing
    stuff. In one case I have it takes 90s to complete writing all the
    changes before it exits after it's unmounted.

    I tried running fuse2fs in the foreground, backgrounding it in bash, and
    doing a wait <pid> but that didn't work either. However, I didn't think
    to also include a sync.

    I've added an --inuse=<file> option that is created when fuse2fs starts
    and is unlinked as the very last thing before it exits and I've also
    included a sync after the inuse file disappears and that seems to have
    fixed the issue (my full test hasn't finished yet - takes over 30
    minutes)

    Your email gave me the hint to try wait and sync. Although I don't think
    the sync should be necessary as we're writing to the file in userspace.
    Perhaps the --inuse change is more reliable than wait pid in bash (I
    will try without the sync to see once this test is completed)

    Thanks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)