Date: Thu, 21 Jul 2005 12:26:05 -0700 (PDT) From: Matthew Dillon <dillon@apollo.backplane.com> To: Igor Shmukler <igor.shmukler@gmail.com> Cc: hackers@freebsd.org, fs@freebsd.org Subject: Re: per file lock list Message-ID: <200507211926.j6LJQ55D071115@apollo.backplane.com> References: <6533c1c9050721121030016b7d@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
: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>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507211926.j6LJQ55D071115>