Author: asomers Date: Fri Nov 18 16:07:08 2016 New Revision: 308806 URL: https://svnweb.freebsd.org/changeset/base/308806
Log: 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 Modified: head/lib/libutil/gr_util.c head/lib/libutil/pw_util.c head/usr.sbin/pw/grupd.c head/usr.sbin/pw/pw_nis.c head/usr.sbin/pw/pwupd.c Modified: head/lib/libutil/gr_util.c ============================================================================== --- head/lib/libutil/gr_util.c Fri Nov 18 16:05:32 2016 (r308805) +++ head/lib/libutil/gr_util.c Fri Nov 18 16:07:08 2016 (r308806) @@ -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) Modified: head/lib/libutil/pw_util.c ============================================================================== --- head/lib/libutil/pw_util.c Fri Nov 18 16:05:32 2016 (r308805) +++ head/lib/libutil/pw_util.c Fri Nov 18 16:07:08 2016 (r308806) @@ -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) Modified: head/usr.sbin/pw/grupd.c ============================================================================== --- head/usr.sbin/pw/grupd.c Fri Nov 18 16:05:32 2016 (r308805) +++ head/usr.sbin/pw/grupd.c Fri Nov 18 16:07:08 2016 (r308806) @@ -77,6 +77,7 @@ gr_update(struct group * grp, char const close(tfd); err(1, "gr_copy()"); } + fsync(tfd); close(tfd); if (gr_mkdb() == -1) { gr_fini(); Modified: head/usr.sbin/pw/pw_nis.c ============================================================================== --- head/usr.sbin/pw/pw_nis.c Fri Nov 18 16:05:32 2016 (r308805) +++ head/usr.sbin/pw/pw_nis.c Fri Nov 18 16:07:08 2016 (r308806) @@ -67,6 +67,7 @@ pw_nisupdate(const char * path, struct p close(tfd); err(1, "pw_copy()"); } + fsync(tfd); close(tfd); if (chmod(pw_tempname(), 0644) == -1) err(1, "chmod()"); Modified: head/usr.sbin/pw/pwupd.c ============================================================================== --- head/usr.sbin/pw/pwupd.c Fri Nov 18 16:05:32 2016 (r308805) +++ head/usr.sbin/pw/pwupd.c Fri Nov 18 16:07:08 2016 (r308806) @@ -114,6 +114,7 @@ pw_update(struct passwd * pwd, char cons close(tfd); err(1, "pw_copy()"); } + fsync(tfd); close(tfd); /* * in case of deletion of a user, the whole database _______________________________________________ [email protected] mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "[email protected]"
