diff options
author | Alan Somers <asomers@FreeBSD.org> | 2016-11-18 16:07:08 +0000 |
---|---|---|
committer | Alan Somers <asomers@FreeBSD.org> | 2016-11-18 16:07:08 +0000 |
commit | b442f00957395ba59112d4d0e0eb4f71708d811b (patch) | |
tree | be77a1acfdc292061fba5f25273bf8c69b7d4e14 /libutil | |
parent | eaf8d4a9d903595d2f3a388ed56fd20b34d9f80b (diff) | |
download | pw-darwin-b442f00957395ba59112d4d0e0eb4f71708d811b.tar.gz pw-darwin-b442f00957395ba59112d4d0e0eb4f71708d811b.tar.zst pw-darwin-b442f00957395ba59112d4d0e0eb4f71708d811b.zip |
Speed up pw operations that edit /etc/group or /etc/passwd
r285050 fixed a bug in pw that could lead to /etc/passwd or /etc/group
corruption on power loss. However, it fixed it by opening those files with
O_SYNC, which is very slow, especially on ZFS. This change replaces O_SYNC
with appropriately placed fsync()s instead, which is much faster. Using a
ZFS tmpdir, the time to run pw's kyua tests drops from 245s to 35s.
Reviewed by: allanjude, bapt, vangyzen, garga
Tested on pfSense by: garga
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D8319
Diffstat (limited to 'libutil')
-rw-r--r-- | libutil/gr_util.c | 2 | ||||
-rw-r--r-- | libutil/pw_util.c | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/libutil/gr_util.c b/libutil/gr_util.c index 93b3eb2..6153209 100644 --- a/libutil/gr_util.c +++ b/libutil/gr_util.c @@ -141,7 +141,7 @@ gr_tmp(int mfd) errno = ENAMETOOLONG; return (-1); } - if ((tfd = mkostemp(tempname, O_SYNC)) == -1) + if ((tfd = mkostemp(tempname, 0)) == -1) return (-1); if (mfd != -1) { while ((nr = read(mfd, buf, sizeof(buf))) > 0) diff --git a/libutil/pw_util.c b/libutil/pw_util.c index 2838871..d790328 100644 --- a/libutil/pw_util.c +++ b/libutil/pw_util.c @@ -225,7 +225,7 @@ pw_tmp(int mfd) errno = ENAMETOOLONG; return (-1); } - if ((tfd = mkostemp(tempname, O_SYNC)) == -1) + if ((tfd = mkostemp(tempname, 0)) == -1) return (-1); if (mfd != -1) { while ((nr = read(mfd, buf, sizeof(buf))) > 0) |