Design: should fflush() sync extents (it currently doesn't)
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 122
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
### System information
Type | Version/Name
--- | ---
Operating System | all
OS Version | all
Architecture | all
UnifyFS Version | all
### Describe the problem you're observing
I naively used `fflush()` instead of `fsync()` to sync the extents in a test program. It didn't sync the extents. After laminating the file, I could not read the contents. `fsync()` works though.
Should we make it so `fflush()` behaves the same as `fsync()`? They're not supposed to behave the same in POSIX (sync to OS buffers, vs sync to disk). Do we want to cheat and make `fflush()` sync out the extents too? The benefit would be that if you're using stream IO, you already have a file pointer, so it's easier to sync with `fflush()` than `fsync()`. However, you can always use `fileno()` to get the file descriptor from the file pointer, which you can then pass to `fsync()`.
### Describe how to reproduce the problem
This works:
```C
fp = fopen(path, "w");
rc = fwrite("hello world", 12, 1, fp);
rc = fclose(fp);
/* Sync the file with fsync */
fd = open(path, O_RDWR);
rc = fsync(fd);
close(fd);
/* Laminate it */
rc = chmod(path, 0444);
fp = fopen(path, "r");
fread(buf, sizeof(buf), 1, fp);
fclose(fp);
rc = strcmp("hello world", buf);
ok(rc == 0, "syncing a file with fsync works '%s': %s", buf, strerror(errno));
```
This does not:
```C
fp = fopen(path, "w");
rc = fwrite("hello world", 12, 1, fp);
rc = fflush(fp);
rc = fclose(fp);
/* Laminate it */
rc = chmod(path, 0444);
fp = fopen(path, "r");
fread(buf, sizeof(buf), 1, fp);
fclose(fp);
rc = strcmp("hello world", buf);
ok(rc == 0, "syncing a file with fflush works '%s': %s", buf, strerror(errno));
```
### Include any warning or errors or releveant debugging data
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two C examples in the issue and trace how fflush() and fsync() handle extents before and after lamination. The work is done when the project’s intended semantics are decided, the selected behavior is implemented, and coverage verifies the fflush() and fsync() cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100