[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: per file lock list
From:       Matthew Dillon <dillon () apollo ! backplane ! com>
Date:       2005-07-21 19:26:05
Message-ID: 200507211926.j6LJQ55D071115 () apollo ! backplane ! com
[Download RAW message or body]

: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@backplane.com>
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic