From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Wilcox Subject: lockd's interactions with locks.c Date: Thu, 1 Aug 2002 02:28:21 +0100 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20020801022821.E3797@parcelfarce.linux.theplanet.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: To: linux-fsdevel@vger.kernel.org, neilb@cse.unsw.edu.au, nfs-devel@linux.kernel.org, trond.myklebust@fys.uio.no, okir@monad.swb.de Content-Disposition: inline List-Id: linux-fsdevel.vger.kernel.org There's no-one specifically listed as maintaining lockd, so i'm cc'ing everyone involved with NFS. It's clearly a good idea to remove the BKL from the file locking code -- we have user-provokable O(n^2) behaviour in there; let's limit the damage to this subsystem. There are other good cleanups I want to do that influence this too. Let's look at the current code in nlmsvc_lock(). We do (paraphrased): if (!(conflock = posix_test_lock(&file->f_file, &lock->fl))) { error = posix_lock_file(&file->f_file, &lock->fl, 0); ... } if (posix_locks_deadlock(&lock->fl, conflock)) return nlm_deadlock; nlmsvc_insert_block(block, NLM_NEVER); if (list_empty(&block->b_call.a_args.lock.fl.fl_block)) posix_block_lock(conflock, &block->b_call.a_args.lock.fl); Now, unless we export a lock from locks.c that lockd can grab around all this, we're pretty much hosed. I believe that lockd runs with the BKL at this point, so there's no race currently. Here's my preferred alternative (untested, i want to get comments on the idea): if (wait) lock->fl.fl_flags |= FL_SLEEP; again: error = posix_lock_file(&file->f_file, &lock->fl, 0); if (!error) return 0; if (!wait && error != -EAGAIN) return error; grab_lockd_blocking_lock(); nlmsvc_insert_block(block, NLM_NEVER); have_been_woken_up_already = ...; release_lockd_blocking_lock(); if (have_been_woken_up_already) goto again; return error; notice we've now got _one_ call into locks.c instead of 4. comments? you can see a modified locks.c (which is also known-buggy) which supports the FL_SLEEP semantics at http://ftp.linux.org.uk/pub/linux/willy/patches/flock-2.5.22/flock-A.diff -- Revolutions do not require corporate support.