From owner-freebsd-fs@FreeBSD.ORG Wed Jul 11 18:14:15 2012 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BC64B106564A for ; Wed, 11 Jul 2012 18:14:15 +0000 (UTC) (envelope-from pho@holm.cc) Received: from relay02.pair.com (relay02.pair.com [209.68.5.16]) by mx1.freebsd.org (Postfix) with SMTP id 710338FC1E for ; Wed, 11 Jul 2012 18:14:15 +0000 (UTC) Received: (qmail 82469 invoked from network); 11 Jul 2012 18:07:34 -0000 Received: from 87.58.146.107 (HELO x2.osted.lan) (87.58.146.107) by relay02.pair.com with SMTP; 11 Jul 2012 18:07:34 -0000 X-pair-Authenticated: 87.58.146.107 Received: from x2.osted.lan (localhost [127.0.0.1]) by x2.osted.lan (8.14.5/8.14.5) with ESMTP id q6BI7WeG048085; Wed, 11 Jul 2012 20:07:32 +0200 (CEST) (envelope-from pho@x2.osted.lan) Received: (from pho@localhost) by x2.osted.lan (8.14.5/8.14.5/Submit) id q6BI7W7B048084; Wed, 11 Jul 2012 20:07:32 +0200 (CEST) (envelope-from pho) Date: Wed, 11 Jul 2012 20:07:32 +0200 From: Peter Holm To: John Baldwin Message-ID: <20120711180732.GA46834@x2.osted.lan> References: <201203071318.08241.jhb@freebsd.org> <201207091138.15655.jhb@freebsd.org> <20120709204007.GW2338@deviant.kiev.zoral.com.ua> <201207091648.32306.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201207091648.32306.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i Cc: freebsd-fs@freebsd.org Subject: Re: close() of an flock'd file is not atomic X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Jul 2012 18:14:15 -0000 On Mon, Jul 09, 2012 at 04:48:32PM -0400, John Baldwin wrote: > On Monday, July 09, 2012 4:40:07 pm Konstantin Belousov wrote: > > On Mon, Jul 09, 2012 at 11:38:15AM -0400, John Baldwin wrote: > > > Here now is the tested version of the actual fix after the vn_open_vnode() > > > changes were committed. This is hopefully easier to parse now. > > > > > > http://www.FreeBSD.org/~jhb/patches/flock_open_close4.patch > > > > Do you need atomic op to set FHASLOCK in vn_open_cred ? I do not think > > *fp can be shared with other thread there. > > Oh, that's true. I had just preserved it from the original code. > > > I thought that vrele() call in vn_closefile() would need a > > vn_start_write() or vn_start_secondary_write() dance around it, but > > now I believe it is not needed, since ufs_inactive() handles start of > > secondary writes on its own. Still, it would be good if Peter could test > > the patch with snapshotting load just be to safe there. > > Ok. I'm happy to have pho@ test it, but the test will have to use file > locking along with snapshots to exercise this case. > Verified your scenario on a pristine head and it fails like this: $ uname -a FreeBSD x4.osted.lan 10.0-CURRENT FreeBSD 10.0-CURRENT #0 r234951 $ /usr/bin/time -h ./flock_open_close.sh flock_open_close: execv(/mnt/test): Text file busy FAIL 3,79s real 0,24s user 0,78s sys $ Not a problem with your patch. The patch has further been stress tested for 24 hours without any problems showing up. - Peter