Page MenuHomeFreeBSD

pwd_mkdb opens files with O_SYNC instead of calling fsync
ClosedPublic

Authored by dwmalone on Feb 4 2016, 9:53 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 14 2024, 7:10 PM
Unknown Object (File)
Feb 17 2024, 2:35 PM
Unknown Object (File)
Dec 4 2023, 1:53 PM
Unknown Object (File)
Nov 15 2023, 3:38 PM
Unknown Object (File)
Oct 28 2023, 7:14 AM
Unknown Object (File)
Sep 13 2023, 12:36 PM
Unknown Object (File)
Sep 13 2023, 9:54 AM
Unknown Object (File)
Aug 26 2023, 2:16 PM
Subscribers

Details

Summary

The right fix for this shouldn't be the use of O_SYNC, but calling
fsync before the files are moved into place (plus calling fsync on
the directory, which is a good idea).

In fact, pwd_mkdb calls the close method on the db, which the man
page for dbopen claims should flush the file. However, looking at
the sync and close methods in lib/libc/db/hash, it seems the code
for flushing is missing, which is probably the real bug here.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dwmalone retitled this revision from to pwd_mkdb opens files with O_SYNC instead of calling fsync.
dwmalone updated this object.
dwmalone edited the test plan for this revision. (Show Details)
dwmalone added reviewers: garga, gnn, bapt.

I had assumed that buffers are flushed before the file is closed (there is a comment to that effect in hash.c:hdestroy() but I have not looked at this code in detail).

In my tests, the db file came out identical with or without O_SYNC.

BTW: There is one further command that uses dbopen(..., O_SYNC) and can be sped up by a significant factor (25.5 seconds --> 0.6 seconds in my tests with the full termcap file) and that command is cap_mkdb.

ARC does not like me and since its a trivial change I just point you at src/usr.bin/cap_mkdb/cap_mkdb.c line 122. Please update the diff to include the removal of O_SYNC from that file to.

looks ok to me, and from my testing it does the job. @garga can you confirm that is also fixes the issue you found?

vangyzen added a reviewer: vangyzen.
vangyzen added a subscriber: vangyzen.
vangyzen added inline comments.
lib/libc/db/hash/hash.c
426 ↗(On Diff #12999)

This is good, but you might consider calling _fsync() at the end of flush_meta(), instead of duplicating the call in these two places.

This revision is now accepted and ready to land.Feb 11 2016, 5:27 PM

I've committed it to pfSense and we will run batch scripts to validate if the original issue is not back. I'll return ASAP

garga edited edge metadata.

After over 1000 power cycles we were not able to reproduce original bug.

Great - I'll commit it in the next day or two, and ask for permission to MFC.

This revision was automatically updated to reflect the committed changes.

Both fsync and close may return an error (EIO). I think it'd be nice to check for it here as well.