From owner-freebsd-hackers@FreeBSD.ORG Mon Apr 6 21:51:55 2015 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id CEA7B114 for ; Mon, 6 Apr 2015 21:51:55 +0000 (UTC) Received: from mail-vn0-x233.google.com (mail-vn0-x233.google.com [IPv6:2607:f8b0:400c:c0f::233]) (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 84638BF3 for ; Mon, 6 Apr 2015 21:51:55 +0000 (UTC) Received: by vnbf129 with SMTP id f129so4319192vnb.9 for ; Mon, 06 Apr 2015 14:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=vjboXBSBqU0CspE5PSQhEhivfy8VjHEBPrKkj6lB7J4=; b=VOaJTV4gHbJrqZU4Xn4jeT4feXvG9sT3h0ZFglB+uyoVPksN4kXStq5cJw7eIQ7iqk KFnkiaqXpraPZXgSXjXA/wdT4dlsukwaa0wqnB8+npAvPXYu4ypCRd22tmOxbkbSVxOs CSZ7RVMUt1IDCPOzNGwIsczUQbsKZXV2NinG9fqRk/THZhVMqZ8m4+pPPriulTwEqSMM v6rcKttNYzL8ZqNtUUZeg0b0iHpdCPUJZ0Fen0U8mlwYq5tOkTB0LTApuaMCHKznn+ZE CwjXmImmeVzac/JK9C0hbgUBT9+xet/drcDEIfoY9TKFGM4JW1JSujzRhtFmwK7WV7ER ZDMg== MIME-Version: 1.0 X-Received: by 10.53.7.72 with SMTP id da8mr11119391vdd.58.1428357114627; Mon, 06 Apr 2015 14:51:54 -0700 (PDT) Received: by 10.52.164.104 with HTTP; Mon, 6 Apr 2015 14:51:54 -0700 (PDT) In-Reply-To: <3950D855-0F4E-49E0-A388-4C7ED102B68B@gmail.com> References: <3950D855-0F4E-49E0-A388-4C7ED102B68B@gmail.com> Date: Mon, 6 Apr 2015 17:51:54 -0400 Message-ID: Subject: Re: lockf() vs. flock() -- lockf() not locking? From: Conrad Meyer To: Guy Helmer Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 21:51:55 -0000 On Mon, Apr 6, 2015 at 5:18 PM, Guy Helmer wrote: > From 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 s= tress test that quickly corrupts the target file using the lockf() implemen= tation, and the test fails to cause corruption using the flock() implementa= tion. I=E2=80=99ve instrumented the code, and it's clear that multiple proc= esses are simultaneously in the block of code after the =E2=80=9Clockf(fd, = F_LOCK, 0)=E2=80=9D line. > > Am I missing something obvious? Any ideas? 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. Are the locked files on NFS? Best, Conrad