* Directory is not persisted after removing another directory and creating a hard linked symlink with the same name if system crashes
@ 2026-03-03 13:30 Vyacheslav Kovalevsky
2026-03-03 17:22 ` Filipe Manana
0 siblings, 1 reply; 2+ messages in thread
From: Vyacheslav Kovalevsky @ 2026-03-03 13:30 UTC (permalink / raw)
To: clm, dsterba; +Cc: linux-btrfs, linux-kernel
Detailed description
====================
Hello, there seems to be an issue with btrfs crash behavior:
1. Create new directory `foo`, sync, then remove the directory.
2. Create new directories `dir1` and `dir2`.
3. Create new symlink named `foo` (NOTE: must have the same name as the
removed directory).
4. Create new (hard) link to the symlink inside `dir2` (NOTE: this is
also important).
5. Sync directory `dir2`.
6. Sync root directory.
Directory `dir1` will be missing even though it was synced in the last step.
System info
===========
Linux version 7.0-rc2, also tested on 6.19.2
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 dir_fd;
int root_fd;
status = mkdir("foo", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
printf("MKDIR: %d\n", status);
sync();
status = rmdir("foo");
printf("RMDIR: %d\n", status);
status = mkdir("dir1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
printf("MKDIR: %d\n", status);
status = mkdir("dir2", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
printf("MKDIR: %d\n", status);
status = symlink("bar", "foo");
printf("SYMLINK: %d\n", status);
status = link("foo", "dir2/link");
printf("LINK: %d\n", status);
status = open("dir2", O_RDONLY);
printf("OPEN: %d\n", status);
dir_fd = status;
status = fsync(dir_fd);
printf("FSYNC: %d\n", status);
status = open(".", O_RDONLY);
printf("OPEN: %d\n", status);
root_fd = status;
status = fsync(root_fd);
printf("FSYNC: %d\n", status);
}
// after crash `dir1` is missing
```
Steps:
1. Create and mount new btrfs 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 directory `dir1` is missing.
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: Directory is not persisted after removing another directory and creating a hard linked symlink with the same name if system crashes
2026-03-03 13:30 Directory is not persisted after removing another directory and creating a hard linked symlink with the same name if system crashes Vyacheslav Kovalevsky
@ 2026-03-03 17:22 ` Filipe Manana
0 siblings, 0 replies; 2+ messages in thread
From: Filipe Manana @ 2026-03-03 17:22 UTC (permalink / raw)
To: Vyacheslav Kovalevsky; +Cc: clm, dsterba, linux-btrfs, linux-kernel
On Tue, Mar 3, 2026 at 1:32 PM Vyacheslav Kovalevsky
<slava.kovalevskiy.2014@gmail.com> wrote:
>
> Detailed description
> ====================
>
> Hello, there seems to be an issue with btrfs crash behavior:
>
> 1. Create new directory `foo`, sync, then remove the directory.
> 2. Create new directories `dir1` and `dir2`.
> 3. Create new symlink named `foo` (NOTE: must have the same name as the
> removed directory).
It doesn't need to be a symlink, a regular file is enough.
Fix here: https://lore.kernel.org/linux-btrfs/9a367f025abf4ea19c96aead75d206e129b2c56e.1772558089.git.fdmanana@suse.com/
Btw, I think you may have sent a message with one of the longest subjects ever.
Thanks.
> 4. Create new (hard) link to the symlink inside `dir2` (NOTE: this is
> also important).
> 5. Sync directory `dir2`.
> 6. Sync root directory.
>
> Directory `dir1` will be missing even though it was synced in the last step.
>
>
> System info
> ===========
>
> Linux version 7.0-rc2, also tested on 6.19.2
>
>
> 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 dir_fd;
> int root_fd;
>
> status = mkdir("foo", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
> printf("MKDIR: %d\n", status);
>
> sync();
>
> status = rmdir("foo");
> printf("RMDIR: %d\n", status);
>
> status = mkdir("dir1", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
> printf("MKDIR: %d\n", status);
>
> status = mkdir("dir2", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
> printf("MKDIR: %d\n", status);
>
> status = symlink("bar", "foo");
> printf("SYMLINK: %d\n", status);
>
> status = link("foo", "dir2/link");
> printf("LINK: %d\n", status);
>
> status = open("dir2", O_RDONLY);
> printf("OPEN: %d\n", status);
> dir_fd = status;
>
> status = fsync(dir_fd);
> printf("FSYNC: %d\n", status);
>
> status = open(".", O_RDONLY);
> printf("OPEN: %d\n", status);
> root_fd = status;
>
> status = fsync(root_fd);
> printf("FSYNC: %d\n", status);
> }
> // after crash `dir1` is missing
> ```
>
> Steps:
>
> 1. Create and mount new btrfs 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 directory `dir1` is missing.
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-03 17:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03 13:30 Directory is not persisted after removing another directory and creating a hard linked symlink with the same name if system crashes Vyacheslav Kovalevsky
2026-03-03 17:22 ` Filipe Manana
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox