Re: Directory is not persisted after writing to the file within directory if system crashes

From: Vyacheslav Kovalevsky
Date: Sat Oct 25 2025 - 05:49:56 EST


On 24/10/2025 19:17, Filipe Manana wrote:
I converted that to a test case for fstests and couldn't reproduce,
"dir", "file1" and "dir/file2" exist after the power failure.

The conversion for fstests:

#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2025 SUSE S.A. All Rights Reserved.
#
# FS QA Test 780
#
# what am I here for?
#
. ./common/preamble
_begin_fstest auto quick log

_cleanup()
{
_cleanup_flakey
cd /
rm -r -f $tmp.*
}

. ./common/filter
. ./common/dmflakey

_require_scratch
_require_dm_target flakey

rm -f $seqres.full
On 24/10/2025 19:17, Filipe Manana wrote:
_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
_require_metadata_journaling $SCRATCH_DEV
_init_flakey
_mount_flakey

touch $SCRATCH_MNT/file1

_scratch_sync

mkdir $SCRATCH_MNT/dir
echo -n "hello world" > $SCRATCH_MNT/file1
ln $SCRATCH_MNT/file1 $SCRATCH_MNT/dir/file2

$XFS_IO_PROG -c "fsync" $SCRATCH_MNT/

# Simulate a power failure and then mount again the filesystem to replay the
# journal/log.
_flakey_drop_and_remount

ls -R $SCRATCH_MNT/ | _filter_scratch

_unmount_flakey

# success, all done
_exit 0

I think the line with `echo` may not be the correct translation:
> echo -n "hello world" > $SCRATCH_MNT/file1

In the original test, the file was opened with `O_SYNC` flag, if you remove it, the directory will be there when the system crashes. I also forgot to close the file after the `creat` call in the original test, may be important as well.

The test itself is quite weird (why would `dir` be gone after seemingly unrelated operation?), any detail can matter.

Please run the original test with a real system crash. I will also double check everything on my side.