Date: Fri, 21 Oct 2016 14:36:33 -0600 From: Alan Somers <asomers@freebsd.org> To: Don Lewis <truckman@freebsd.org> Cc: Renato Botelho <garga@freebsd.org>, "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: <CAOtMX2juTB5u6O9-fbYKPDuwhyxAZToBjQ4YxPBUcOgZ_DXAQw@mail.gmail.com> In-Reply-To: <201610132306.u9DN6Aod023917@gw.catspoiler.org> References: <CAOtMX2gnLugXB%2BBuuM%2Bsfs3DB%2BtAsA9NpkA-e0uerDXH2eKa0Q@mail.gmail.com> <201610132306.u9DN6Aod023917@gw.catspoiler.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Oct 13, 2016 at 5:06 PM, Don Lewis <truckman@freebsd.org> wrote: > On 13 Oct, Alan Somers wrote: >> 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 > > pwd_mkdb was fixed back in February with by switching to fsync() in > r295925. It looks like libutil was not fixed, though. https://reviews.freebsd.org/D8319
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2juTB5u6O9-fbYKPDuwhyxAZToBjQ4YxPBUcOgZ_DXAQw>