From owner-svn-src-stable@freebsd.org Fri Dec 16 20:10:57 2016 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6BB70C838D5; Fri, 16 Dec 2016 20:10:57 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2C8B02D3; Fri, 16 Dec 2016 20:10:57 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBGKAu2Z067235; Fri, 16 Dec 2016 20:10:56 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBGKAtxr067229; Fri, 16 Dec 2016 20:10:55 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201612162010.uBGKAtxr067229@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Fri, 16 Dec 2016 20:10:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r310173 - in stable/10: lib/libutil usr.sbin/pw X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2016 20:10:57 -0000 Author: asomers Date: Fri Dec 16 20:10:55 2016 New Revision: 310173 URL: https://svnweb.freebsd.org/changeset/base/310173 Log: MFC r308806 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. Modified: stable/10/lib/libutil/gr_util.c stable/10/lib/libutil/pw_util.c stable/10/usr.sbin/pw/grupd.c stable/10/usr.sbin/pw/pw_nis.c stable/10/usr.sbin/pw/pwupd.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libutil/gr_util.c ============================================================================== --- stable/10/lib/libutil/gr_util.c Fri Dec 16 20:04:56 2016 (r310172) +++ stable/10/lib/libutil/gr_util.c Fri Dec 16 20:10:55 2016 (r310173) @@ -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: stable/10/lib/libutil/pw_util.c ============================================================================== --- stable/10/lib/libutil/pw_util.c Fri Dec 16 20:04:56 2016 (r310172) +++ stable/10/lib/libutil/pw_util.c Fri Dec 16 20:10:55 2016 (r310173) @@ -226,7 +226,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: stable/10/usr.sbin/pw/grupd.c ============================================================================== --- stable/10/usr.sbin/pw/grupd.c Fri Dec 16 20:04:56 2016 (r310172) +++ stable/10/usr.sbin/pw/grupd.c Fri Dec 16 20:10:55 2016 (r310173) @@ -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: stable/10/usr.sbin/pw/pw_nis.c ============================================================================== --- stable/10/usr.sbin/pw/pw_nis.c Fri Dec 16 20:04:56 2016 (r310172) +++ stable/10/usr.sbin/pw/pw_nis.c Fri Dec 16 20:10:55 2016 (r310173) @@ -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: stable/10/usr.sbin/pw/pwupd.c ============================================================================== --- stable/10/usr.sbin/pw/pwupd.c Fri Dec 16 20:04:56 2016 (r310172) +++ stable/10/usr.sbin/pw/pwupd.c Fri Dec 16 20:10:55 2016 (r310173) @@ -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