Date: Thu, 13 Oct 2016 15:42:31 -0600 From: Alan Somers <asomers@freebsd.org> To: Renato Botelho <garga@freebsd.org> Cc: "src-committers@freebsd.org" <src-committers@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "svn-src-head@freebsd.org" <svn-src-head@freebsd.org> Subject: Re: svn commit: r285050 - in head: lib/libutil usr.sbin/pwd_mkdb Message-ID: <CAOtMX2gnLugXB%2BBuuM%2Bsfs3DB%2BtAsA9NpkA-e0uerDXH2eKa0Q@mail.gmail.com> In-Reply-To: <201507021731.t62HV074085188@repo.freebsd.org> References: <201507021731.t62HV074085188@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Jul 2, 2015 at 11:31 AM, Renato Botelho <garga@freebsd.org> wrote: > Author: garga (ports committer) > Date: Thu Jul 2 17:30:59 2015 > New Revision: 285050 > URL: https://svnweb.freebsd.org/changeset/base/285050 > > Log: > When passwd or group information is changed (by pw, vipw, chpass, ...) > temporary file is created and then a rename() call move it to official file. > This operation didn't have any check to make sure data was written to disk > and if a power cycle happens system could end up with a 0 length passwd > or group database. > > There is a pfSense bug with more infor about it: > > https://redmine.pfsense.org/issues/4523 > > The following changes were made to protect passwd and group operations: > > * lib/libutil/gr_util.c: > - Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file > - After rename(), fsync() call on directory for faster result > > * lib/libutil/pw_util.c > - Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file > > * usr.sbin/pwd_mkdb/pwd_mkdb.c > - Added O_SYNC flag on dbopen() calls > - After rename(), fsync() call on directory for faster result > > * lib/libutil/pw_util.3 > - pw_lock() returns a file descriptor to master password file on success > > Differential Revision: https://reviews.freebsd.org/D2978 > Approved by: bapt > Sponsored by: Netgate > > Modified: > head/lib/libutil/gr_util.c > head/lib/libutil/pw_util.3 > head/lib/libutil/pw_util.c > head/usr.sbin/pwd_mkdb/pwd_mkdb.c This change is making certain pw operations very slow on ZFS root systems. The problem is that when you open a file with O_SYNC, every single write(2) call turns into a zil_commit on ZFS, which is fairly expensive. Did you consider using fsync(2) on the temporary files instead of opening them with O_SYNC? I just tried that now, and I see a considerable speedup when running the tests in /usr/tests/usr.sbin/pw: Using O_SYNC, as CURRENT does: 4 minutes 5.2 seconds No synchronous operations at all: 49.5 seconds Using fsync(2): 56.0 seconds -Alan
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2gnLugXB%2BBuuM%2Bsfs3DB%2BtAsA9NpkA-e0uerDXH2eKa0Q>