From: Vyacheslav Kovalevsky <slava.kovalevskiy.2014@gmail.com>
To: konishi.ryusuke@gmail.com, slava@dubeyko.com
Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: File system corruption after writing to unlinked file and using fdatasync on the file if system crashes
Date: Wed, 11 Mar 2026 16:01:27 +0300 [thread overview]
Message-ID: <31ee60a7-4b23-4dce-99f6-b86c8c8cc53e@gmail.com> (raw)
Detailed description
====================
Hello, there seems to be an issue with NILFS2 crash behavior:
1. Create new file and truncate to some length.
2. Unlink the file but keep the file descriptor open.
3. Make new empty directory.
4. Sync file system.
5. Write some data to the file.
6. Apply fdatasync() to the file.
After system crash (e.g. power failure) mounting file system results in
error message `Stale file handle`. See details below.
System info
===========
Linux version 7.0-rc2, also tested on 6.19.2
nilfs-tools version 2.2.11
How to reproduce
================
```
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
int status;
int file_fd;
status =
open("file", O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IROTH |
S_IXOTH);
printf("OPEN: %d\n", status);
file_fd = status;
status = ftruncate(file_fd, 1000);
printf("FTRUNCATE: %d\n", status);
status = unlink("file");
printf("UNLINK: %d\n", status);
status = mkdir("dir", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
printf("MKDIR: %d\n", status);
sync();
status = write(file_fd, "Test data!", 10);
printf("WRITE: %d\n", status);
status = fdatasync(file_fd); // everything is fine if using fsync()
instead...
printf("FDATASYNC: %d\n", status);
}
// file system is unmountable after crash
// `mount` output:
// mount.nilfs2: Error while mounting /dev/vdb on /mnt/fstest: Stale
file handle
// `dmesg` output:
// [ 29.941736] NILFS (vdb): mounting unchecked fs
// [ 29.953605] NILFS (vdb): error -116 recovering data block (ino=11,
block-offset=0)
// [ 29.953609] NILFS (vdb): error -116 roll-forwarding partial
segment at blocknr = 26
```
Steps:
1. Create and mount new NILFS2 file system in default configuration.
2. Change directory to root of the file system and run the compiled test.
3. Cause hard system crash (e.g. QEMU `system_reset` command).
4. Remount file system after crash.
5. Observe that mount fails.
next reply other threads:[~2026-03-11 13:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 13:01 Vyacheslav Kovalevsky [this message]
2026-03-11 17:39 ` File system corruption after writing to unlinked file and using fdatasync on the file if system crashes Viacheslav Dubeyko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31ee60a7-4b23-4dce-99f6-b86c8c8cc53e@gmail.com \
--to=slava.kovalevskiy.2014@gmail.com \
--cc=konishi.ryusuke@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=slava@dubeyko.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox