Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Aug 2005 14:02:46 -0400
From:      Igor Shmukler <igor.shmukler@gmail.com>
To:        Matthew Dillon <dillon@apollo.backplane.com>
Cc:        hackers@freebsd.org, fs@freebsd.org
Subject:   Re: per file lock list
Message-ID:  <6533c1c905080111026f1f07ca@mail.gmail.com>
In-Reply-To: <200507211926.j6LJQ55D071115@apollo.backplane.com>
References:  <6533c1c9050721121030016b7d@mail.gmail.com> <200507211926.j6LJQ55D071115@apollo.backplane.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <dillon@apollo.backplane.com> 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
>                                         <dillon@backplane.com>
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6533c1c905080111026f1f07ca>