per file lock list

Igor Shmukler igor.shmukler at gmail.com
Mon Aug 1 18:02:48 GMT 2005


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 problem...

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 at 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 given file?
> :
> :Thank you in advance.
> 
>     You can use F_GETLK to iterate through all posix locks held on a file.
>     From man fcntl:
> 
>      F_GETLK    Get the first lock that blocks the lock description pointed to
>                 by the third argument, arg, taken as a pointer to a struct
>                 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 created,
>                 the structure is left unchanged by this function call except
>                 for the lock type which is set to F_UNLCK.
> 
>     So what you do is you specify a lock description that covers the whole
>     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 that
>     there are no more locks.
> 
>                                         -Matt
>                                         Matthew Dillon
>                                         <dillon at backplane.com>
>


More information about the freebsd-fs mailing list