From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 6 23:19:36 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E6E5FA17 for ; Mon, 6 Apr 2015 23:19:36 +0000 (UTC) Received: from mail-pd0-x22d.google.com (mail-pd0-x22d.google.com [IPv6:2607:f8b0:400e:c02::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B015467B for ; Mon, 6 Apr 2015 23:19:36 +0000 (UTC) Received: by pdbqa5 with SMTP id qa5so1828330pdb.1 for ; Mon, 06 Apr 2015 16:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=v5cgoaHNW+VNLTDCXJ4qTcYoVZaFhR1OP5H0eBSgx/U=; b=dJx9WCmTjGWPQ7mrAjm+qQD7vyaxb8lnsjvKjK4AfhSMK5/r15m8keI9V4CM6Z+2Ao 49rNCJit7tmTXlfMtnOVWghcuNGcTc/SstIDGfus7wUhjs69HByojHJwd1LRP8uGax/A 8W46cGau41qFb6cnzuM0PLC7ESlF12bs2AusJUT9dbloxpcQVi8A/poOR9k0f3taq5V1 ieO62Qphj7rkncxTmodWbkHqLyO079A7InthVAVKDwdR1ZmaBoLWvP2LAaWp0cPB7bmc fF0PmaJa8+/GKe6y19yHupWiC512+o9JnCXMrZzL123op1UnucIZy62qgpygUa6CoF2E bhVw== X-Received: by 10.66.147.103 with SMTP id tj7mr31403401pab.85.1428362376247; Mon, 06 Apr 2015 16:19:36 -0700 (PDT) Received: from [192.168.1.188] (173-26-46-90.client.mchsi.com. [173.26.46.90]) by mx.google.com with ESMTPSA id mt11sm5800680pbc.20.2015.04.06.16.19.34 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Apr 2015 16:19:34 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) Subject: Re: lockf() vs. flock() -- lockf() not locking? From: Guy Helmer In-Reply-To: Date: Mon, 6 Apr 2015 18:19:32 -0500 Content-Transfer-Encoding: quoted-printable Message-Id: <38FF4CA2-5116-4168-AC6D-DD6A60AEAB3D@gmail.com> References: <3950D855-0F4E-49E0-A388-4C7ED102B68B@gmail.com> To: Conrad Meyer X-Mailer: Apple Mail (2.2070.6) Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Apr 2015 23:19:37 -0000 > On Apr 6, 2015, at 4:51 PM, Conrad Meyer wrote: >=20 > On Mon, Apr 6, 2015 at 5:18 PM, Guy Helmer = wrote: >> =46rom my reading of the lockf(3) man page and reviewing the = implementation in lib/libc/gen/lockf.c, and corresponding code in = sys/kern/kern_descrip.c, it appears the lockf() call should be = successfully obtaining an advisory lock over the whole file like a = successful flock() did. However, I have a stress test that quickly = corrupts the target file using the lockf() implementation, and the test = fails to cause corruption using the flock() implementation. I=E2=80=99ve = instrumented the code, and it's clear that multiple processes are = simultaneously in the block of code after the =E2=80=9Clockf(fd, F_LOCK, = 0)=E2=80=9D line. >>=20 >> Am I missing something obvious? Any ideas? >=20 >=20 > We have switched from a whole file lock to a range lock. I think it > should still make access exclusive, so this sounds like a bug. But > just note that it is a slightly different mutual exclusion mechanism. >=20 > Are the locked files on NFS? No, this involves files on local filesystems. Regards, Guy