svn commit: r285050 - in head: lib/libutil usr.sbin/pwd_mkdb
Alan Somers
asomers at freebsd.org
Fri Oct 21 20:36:35 UTC 2016
On Thu, Oct 13, 2016 at 5:06 PM, Don Lewis <truckman at freebsd.org> wrote:
> On 13 Oct, Alan Somers wrote:
>> On Thu, Jul 2, 2015 at 11:31 AM, Renato Botelho <garga at 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
More information about the svn-src-all
mailing list