[PR #1957] [MERGED] Fixed a bug that regular files could not be created by mknod #2272

Closed
opened 2026-03-04 02:04:40 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/s3fs-fuse/s3fs-fuse/pull/1957
Author: @ggtakec
Created: 6/10/2022
Status: Merged
Merged: 6/29/2022
Merged by: @gaul

Base: masterHead: fix_release_without_flush


📝 Commits (2)

  • a39224d Fixed a bug that regular files could not be created by mknod
  • 2b512a6 Fixed a bug that regular files could not be created by mknod

📊 Changes

9 files changed (+268 additions, -31 deletions)

View changed files

📝 .gitignore (+1 -0)
📝 src/fdcache_auto.cpp (+3 -3)
📝 src/fdcache_auto.h (+1 -1)
📝 src/fdcache_entity.cpp (+45 -23)
📝 src/fdcache_entity.h (+13 -2)
📝 src/s3fs.cpp (+8 -1)
📝 test/Makefile.am (+3 -1)
📝 test/integration-test-main.sh (+13 -0)
test/mknod_test.c (+181 -0)

📄 Description

Relevant Issue (if applicable)

#1934

Details

The touch command fails when the directory on which s3fs is mounted is mounted with NFS, by #1934.
As a result of investigating this, it turned out to be a bug.

Cause

FUSE calls the create(s3fs_sreate) hook when creating a regular file with mknod.
After that, flush(s3fs_flush) is not called because mknod is the trigger, and release(s3fs_release) closes the file handle.
After this, file attribute changes such as utimens are called.

Also, when creating a file such as a touch command, NFS does not call open/close, but calls mknod.

Due to the above operation of FUSE and NFS, to create a new file with zero file size by the touch command, create(s3fs_create) is called, and release(s3fs_release) is called without flush(s3fs_flush).

s3fs delays the creation of new zero file size files until flush(s3fs_flush). (you know #1640, #1655, #1780, etc.)
This does not take into account the call flow by mknod, so the pending file creation(and meta update) is not done.
After that, calling utimens will result in an error because the file has not been created.
Therefore, the touch command failed via NFS.

Fix

When release(s3fs_release) is called, if it is in the pending state(new file creation, meta information update), it has been modified to update them.
This allows you to create(touch command) regular files with mknod(from NFS).

I also added a test for mknod.
FUSE is called by create(s3fs_create) in the case of regular file creation, but by mknod(s3fs_mknod) in other cases.
Including these, I am making it possible to inspect with this test.
All mknod tests are bypassed on macos (because root privileges are required).
It will also be bypassed if you create a BLOCK device as well.

Remaining issues

It looks like mknod's non-regular file creation is supported, but it doesn't work correctly.
I think that BLOCK, FIFO and SOCK will not work.
As for CHARACTER, it may work, but it has not been implemented as a block device.
I will post new issue about it.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/s3fs-fuse/s3fs-fuse/pull/1957 **Author:** [@ggtakec](https://github.com/ggtakec) **Created:** 6/10/2022 **Status:** ✅ Merged **Merged:** 6/29/2022 **Merged by:** [@gaul](https://github.com/gaul) **Base:** `master` ← **Head:** `fix_release_without_flush` --- ### 📝 Commits (2) - [`a39224d`](https://github.com/s3fs-fuse/s3fs-fuse/commit/a39224d409bf69f73dbb27201315b1e456f00861) Fixed a bug that regular files could not be created by mknod - [`2b512a6`](https://github.com/s3fs-fuse/s3fs-fuse/commit/2b512a643543c2e01cc10a31fc0ab76a5f5aa274) Fixed a bug that regular files could not be created by mknod ### 📊 Changes **9 files changed** (+268 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+1 -0) 📝 `src/fdcache_auto.cpp` (+3 -3) 📝 `src/fdcache_auto.h` (+1 -1) 📝 `src/fdcache_entity.cpp` (+45 -23) 📝 `src/fdcache_entity.h` (+13 -2) 📝 `src/s3fs.cpp` (+8 -1) 📝 `test/Makefile.am` (+3 -1) 📝 `test/integration-test-main.sh` (+13 -0) ➕ `test/mknod_test.c` (+181 -0) </details> ### 📄 Description ### Relevant Issue (if applicable) #1934 ### Details The touch command fails when the directory on which s3fs is mounted is mounted with NFS, by #1934. As a result of investigating this, it turned out to be a bug. #### Cause FUSE calls the `create`(`s3fs_sreate`) hook when creating a regular file with mknod. After that, `flush`(`s3fs_flush`) is not called because mknod is the trigger, and `release`(`s3fs_release`) closes the file handle. After this, file attribute changes such as `utimens` are called. Also, when creating a file such as a `touch` command, NFS does not call `open`/`close`, but calls `mknod`. Due to the above operation of FUSE and NFS, to create a new file with zero file size by the `touch` command, `create`(`s3fs_create`) is called, and `release`(`s3fs_release`) is called without `flush`(`s3fs_flush`). s3fs delays the creation of new zero file size files until `flush`(`s3fs_flush`). (you know #1640, #1655, #1780, etc.) This does not take into account the call flow by mknod, so the pending file creation(and meta update) is not done. After that, calling `utimens` will result in an error because the file has not been created. Therefore, the touch command failed via NFS. #### Fix When `release`(`s3fs_release`) is called, if it is in the pending state(new file creation, meta information update), it has been modified to update them. This allows you to `create`(`touch` command) regular files with `mknod`(from NFS). I also added a test for `mknod`. FUSE is called by `create`(`s3fs_create`) in the case of regular file creation, but by `mknod`(`s3fs_mknod`) in other cases. Including these, I am making it possible to inspect with this test. All `mknod` tests are bypassed on macos (because root privileges are required). It will also be bypassed if you create a BLOCK device as well. #### Remaining issues It looks like mknod's non-regular file creation is supported, but it doesn't work correctly. I think that `BLOCK`, `FIFO` and `SOCK` will not work. As for `CHARACTER`, it may work, but it has not been implemented as a block device. I will post new issue about it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 02:04:40 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/s3fs-fuse#2272
No description provided.