From owner-freebsd-fs@FreeBSD.ORG Mon Aug 1 18:02:48 2005 Return-Path: X-Original-To: fs@freebsd.org Delivered-To: freebsd-fs@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 41D8816A420 for ; Mon, 1 Aug 2005 18:02:48 +0000 (GMT) (envelope-from igor.shmukler@gmail.com) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.201]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6987843D46 for ; Mon, 1 Aug 2005 18:02:47 +0000 (GMT) (envelope-from igor.shmukler@gmail.com) Received: by zproxy.gmail.com with SMTP id z6so690994nzd for ; Mon, 01 Aug 2005 11:02:46 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PPhtxqTVGfVQBMGpBCZUCnru+HU+1aqFyfZbfijvRUvg4YNVkhykOLSTyOar1JrbFxHbz5vTf3IEQqtlqHQQqLiuyHwdzrpU9ShHDALX60Y+kSeIzxLQSUuvlCEQmYRSxqsKgHHjZBR9SPINAfgsZikTxLsej1syEy5DvHV7Z4s= Received: by 10.36.37.12 with SMTP id k12mr4762913nzk; Mon, 01 Aug 2005 11:02:46 -0700 (PDT) Received: by 10.36.119.12 with HTTP; Mon, 1 Aug 2005 11:02:46 -0700 (PDT) Message-ID: <6533c1c905080111026f1f07ca@mail.gmail.com> Date: Mon, 1 Aug 2005 14:02:46 -0400 From: Igor Shmukler To: Matthew Dillon In-Reply-To: <200507211926.j6LJQ55D071115@apollo.backplane.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <6533c1c9050721121030016b7d@mail.gmail.com> <200507211926.j6LJQ55D071115@apollo.backplane.com> Cc: hackers@freebsd.org, fs@freebsd.org Subject: Re: per file lock list X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Igor Shmukler List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2005 18:02:48 -0000 Matt, Thank you very much for response. This is a general solution, but it not sufficient for our needs. I guess I should have been more clear while explaining what we need. We want list of these locks for a group of processes. We made an implementation based on your suggestion, but there is one proble= m... Unfortunately this method does not return all shared locks for a range. For example, if several processes have placed a shared lock on a range [1000 - 2000], F_GETLK returns a flock structure where l_pid field contains a pid of process that takes the lock first. While, we want to know all processes that takes this lock. Is there any way to retrieve such information without using of internal kernel structures (inode information)? Thank you in advance, igor On 7/21/05, Matthew Dillon wrote: > :Hi, > : > :We have a question: how to get all POSIX locks for a given file? > :.. > : > :As far as I know, existing API does not allow to retrieve all file > :locks. Therefore, we need to use kernel internal structures to get all > :... > :So the question: is there an elegant way to get the lock list for a give= n file? > : > :Thank you in advance. >=20 > You can use F_GETLK to iterate through all posix locks held on a file= . > From man fcntl: >=20 > F_GETLK Get the first lock that blocks the lock description point= ed to > by the third argument, arg, taken as a pointer to a struc= t > flock (see above). The information retrieved overwrites = the > information passed to fcntl() in the flock structure. If= no > lock is found that would prevent this lock from being cre= ated, > the structure is left unchanged by this function call exc= ept > for the lock type which is set to F_UNLCK. >=20 > So what you do is you specify a lock description that covers the whol= e > file and call F_GETLK. You then use the results to modify the lock > description to a range that starts just past the returned lock > for the next call. You continue iterating until F_GETLK tells you th= at > there are no more locks. >=20 > -Matt > Matthew Dillon > >