locks: implement "filp-private" (aka UNPOSIX) locks
v2 cover locks: implement "filp-private" (aka UNPOSIX) locks
This patchset is the second posting of this set. Here's an overview of the changes:
The inheritance semantics have been changed to be much more like BSD (aka flock()) locks. With this change, what we basically have are a hybrid of BSD and POSIX locks. They conflict with "classic" POSIX locks but are not noticed by flock() locks. OTOH, they act like flock locks with respect to inheritance and behavior when an fd is closed.
This change actually makes the patchset smaller. Instead of needing a bunch of special handling, we can simply consider these new locks to be a POSIX lock like any other and simply give them a different fl_owner value (that of the filp). This does mean that we need to add a new F_UNLCKP l_type value, but I think that's a reasonable thing to do anyway.
Note too that I've gone ahead and opened a request for the POSIX folks to consider adding this to the POSIX spec once we have something mergeable. They seem amenable to the idea but don't want to enshrine it into the standard until there's a real implementation of it:
http://austingroupbugs.net/view.php?id=768
The code changes are pretty straightforward, so my questions are pretty much the same as that in the last set. Cover letter from the v1 posting follows.
Comments and suggestions welcome...
-------------------------------[snip]------------------------------
At LSF this year, there was a discussion about the "wishlist" for userland file servers. One of the things brought up was the goofy and problematic behavior of POSIX locks when a file is closed. Boaz started a thread on it here:
http://permalink.gmane.org/gmane.linux.file-systems/73364
Userland fileservers often need to maintain more than one open file descriptor on a file. The POSIX spec says:
"All locks associated with a file for a given process shall be removed
when a file descriptor for that file is closed by that process or the process holding that file descriptor terminates."
This is problematic since you can't close any file descriptor without dropping all your POSIX locks. Most userland file servers therefore end up opening the file with more access than is really necessary, and keeping fd's open for longer than is necessary to work around this.
This patchset is a first stab at an approach to address this problem by adding two new l_type values -- F_RDLCKP and F_WRLCKP (the 'P' is short for "private" -- I'm open to changing that if you have a better mnemonic).
For all intents and purposes these lock types act just like their "non-P" counterpart. The difference is that they are only implicitly released when the fd against which they were acquired is closed. As a side effect, these locks cannot be merged with "non-P" locks since they have different semantics on close.
I've given this patchset some very basic smoke testing and it seems to do the right thing, but it is still pretty rough. If this looks reasonable I'll plan to do some documentation updates and will take a stab at trying to get these new lock types added to the POSIX spec (as HCH recommended).
At this point, my main questions are:
1) does this look useful, particularly for fileserver implementors?
2) does this look OK API-wise? We could consider different "cmd" values or even different syscalls, but I figured this makes it clearer that "P" and "non-P" locks will still conflict with one another.
Jeff Layton (5):
locks: consolidate checks for compatible filp->f_mode values in setlk
handlers
locks: rename locks_remove_flock to locks_remove_filp
locks: add new "private" lock type that is owned by the filp
locks: show private lock types in /proc/locks
locks: report l_pid as -1 for FL_FILP_PRIVATE locks
fs/file_table.c | 2 +- fs/locks.c | 102 ++++++++++++++++++++++----------------- include/linux/fs.h | 5 +- include/uapi/asm-generic/fcntl.h | 15 ++++++ 4 files changed, 78 insertions(+), 46 deletions(-)
Signature · 1 line
1.8.3.1
RFC PATCH v2 1/5 locks: consolidate checks for compatible filp->f_mode values in setlk handlers
Add a wrapper around assign_type that does this instead of duplicating this check in two places. This also fixes a minor wart in the code where we continue referring to the struct flock after converting it to struct file_lock.
--- fs/locks.c | 61 +++++++++++++++++++++++++------------------------------------ 1 file changed, 25 insertions(+), 36 deletions(-)
fs/locks.c +25 -36
@@ -344,6 +344,29 @@ static int assign_type(struct file_lock *fl, long type)return 0 ; } +static int posix_assign_type (struct file_lock *fl,long type) +{ +int err; + + err =assign_type (fl, type); +if (err) +return err; + +/* Ensure that fl->fl_filp has compatible f_mode */ +switch (fl->fl_type) { +case F_RDLCK : +if (!(fl->fl_file->f_mode &FMODE_READ )) +return -EBADF ; +break ; +case F_WRLCK : +if (!(fl->fl_file->f_mode &FMODE_WRITE )) +return -EBADF ; +break ; + } + +return 0 ; +} +/* Verify a "struct flock" and copy it to a "struct file_lock" as a POSIX * style lock. */
@@ -393,7 +416,7 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl, fl->fl_ops =NULL ; fl->fl_lmops =NULL ; -return assign_type (fl, l->l_type); +return posix_assign_type (fl, l->l_type); }#if BITS_PER_LONG ==32
@@ -439,7 +462,7 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl, fl->fl_ops =NULL ; fl->fl_lmops =NULL ; - return assign_type(fl, l->l_type); + return posix_assign_type(fl, l->l_type); }#endif
@@ -2016,23 +2039,6 @@ again: file_lock->fl_flags |=FL_SLEEP ; } - error = -EBADF ; -switch (flock.l_type) { -case F_RDLCK : -if (!(filp->f_mode &FMODE_READ )) - goto out; -break ; -case F_WRLCK : -if (!(filp->f_mode &FMODE_WRITE )) - goto out; -break ; -case F_UNLCK : -break ; -default : - error = -EINVAL ; - goto out; - } - error =do_lock_file_wait (filp, cmd, file_lock);/*
@@ -2134,23 +2140,6 @@ again: file_lock->fl_flags |=FL_SLEEP ; } - error = -EBADF ; -switch (flock.l_type) { -case F_RDLCK : -if (!(filp->f_mode &FMODE_READ )) - goto out; -break ; -case F_WRLCK : -if (!(filp->f_mode &FMODE_WRITE )) - goto out; -break ; -case F_UNLCK : -break ; -default : - error = -EINVAL ; - goto out; - } - error =do_lock_file_wait (filp, cmd, file_lock);/*
Signature · 1 line
1.8.3.1
RFC PATCH v2 2/5 locks: rename locks_remove_flock to locks_remove_filp
In reply to Jeff LaytonThis function currently removes leases in addition to flock locks, so the name is misleading. Rename it to locks_remove_filp to indicate that it removes locks that are associated with a particular filp.
--- fs/file_table.c | 2 +- fs/locks.c | 2 +- include/linux/fs.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
fs/file_table.c +1 -1
@@ -234,7 +234,7 @@ static void __fput(struct file *file)* in the file cleanup chain. */ eventpoll_release (file); -locks_remove_flock (file); +locks_remove_filp (file);if (unlikely (file->f_flags &FASYNC )) {if (file->f_op->fasync)
fs/locks.c +1 -1
@@ -2198,7 +2198,7 @@ EXPORT_SYMBOL(locks_remove_posix);/* * This function is called on the last close of an open file. */ -void locks_remove_flock (struct file *filp) +void locks_remove_filp (struct file *filp) {struct inode * inode =file_inode (filp);struct file_lock *fl;
include/linux/fs.h +2 -2
@@ -1012,7 +1012,7 @@ extern struct file_lock * locks_alloc_lock(void);extern void locks_copy_lock (struct file_lock *,struct file_lock *);extern void __locks_copy_lock (struct file_lock *,const struct file_lock *);extern void locks_remove_posix (struct file *,fl_owner_t ); -extern void locks_remove_flock (struct file *); +extern void locks_remove_filp (struct file *);extern void locks_release_private (struct file_lock *);extern void posix_test_lock (struct file *,struct file_lock *);extern int posix_lock_file (struct file *,struct file_lock *,struct file_lock *);
@@ -1083,7 +1083,7 @@ static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)return ; } -static inline void locks_remove_flock (struct file *filp) +static inline void locks_remove_filp (struct file *filp) {return ; }
Signature · 1 line
1.8.3.1
RFC PATCH v2 3/5 locks: add new "private" lock type that is owned by the filp
In reply to Jeff LaytonDue to some unfortunate history, POSIX locks have very strange and unhelpful semantics. The thing that usually catches people by surprise is that they are dropped whenever the process closes any file descriptor associated with the inode.
This is extremely problematic for people developing file servers that need to implement byte-range locks. Developers often need a "lock management" facility to ensure that file descriptors are not closed until all of the locks associated with the inode are finished.
This patchset adds a new type of lock that attempts to address this issue. These locks work just like "normal" POSIX read/write locks, but have semantics that are more like BSD locks with respect to inheritance and behavior on close.
This is implemented primarily by changing how fl_owner field is set for these locks. Instead of having them owned by the files_struct of the process, they are instead owned by the filp on which they were acquired. Thus, they are inherited across fork() and are only released when the last reference to a filp is put.
These new semantics prevent them from being merged with "classic" POSIX locks, even if they are acquired by the same process. These locks will also conflict with "classic" POSIX locks even if they are acquired by the same process or on the same file descriptor.
--- fs/locks.c | 22 +++++++++++++++++++++- include/uapi/asm-generic/fcntl.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-)
fs/locks.c +21 -1
@@ -348,6 +348,26 @@ static int posix_assign_type(struct file_lock *fl, long type) {int err; +/* +* FL_FILP_PRIVATE locks are "owned" by the filp upon which they were +* acquired, regardless of what task is dealing with them. Set the +* fl_owner appropriately. +*/ +switch (type) { +case F_RDLCKP : + type =F_RDLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; +case F_WRLCKP : + type =F_WRLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; +case F_UNLCKP : + type =F_UNLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; + } + err =assign_type (fl, type);if (err)return err;
@@ -2225,7 +2245,7 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl)) { +if (IS_FLOCK (fl) ||IS_POSIX (fl)) {locks_delete_lock (before);continue ; }
include/uapi/asm-generic/fcntl.h +15 -0
@@ -151,6 +151,21 @@ struct f_owner_ex {#define F_UNLCK 2#endif +/* +* fd "private" POSIX locks. +* +* Usually POSIX locks held by a process are released on *any* close and are +* not inherited across a fork(). +* +* These lock types will conflict with normal POSIX locks, but are "owned" +* by the fd, not the process. This means that they are inherited across +* fork() like BSD (flock) locks, and they are only closed when the last +* reference to the the filp against which were acquired is closed. +*/ +#define F_RDLCKP 5 +#define F_WRLCKP 6 +#define F_UNLCKP 7 +/* for old implementation of bsd flock () */ #ifndef F_EXLCK #define F_EXLCK 4/* or 3 */
Signature · 1 line
1.8.3.1
RFC PATCH v2 4/5 locks: show private lock types in /proc/locks
In reply to Jeff LaytonShow "private" locks in /proc/locks with a 'P' suffix. This does mean that we need to widen the column by one character.
Also, tighten up the check in locks_remove_filp() to ensure that only IS_FILP_PVT locks are removed there.
--- fs/locks.c | 15 +++++++++++---- include/linux/fs.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)
fs/locks.c +11 -4
@@ -135,6 +135,7 @@#define IS_POSIX (fl) (fl->fl_flags & FL_POSIX)#define IS_FLOCK (fl) (fl->fl_flags & FL_FLOCK)#define IS_LEASE (fl) (fl->fl_flags & (FL_LEASE|FL_DELEG)) +#define IS_FILP_PVT (fl) (fl->fl_flags & FL_FILP_PRIVATE)static bool lease_breaking (struct file_lock *fl) {
@@ -357,14 +358,17 @@ static int posix_assign_type(struct file_lock *fl, long type)case F_RDLCKP : type =F_RDLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_WRLCKP : type =F_WRLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_UNLCKP : type =F_UNLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ; }
@@ -2245,7 +2249,8 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl) ||IS_POSIX (fl)) { +if (IS_FLOCK (fl) || + (IS_POSIX (fl) &&IS_FILP_PVT (fl))) {locks_delete_lock (before);continue ; }
@@ -2345,13 +2350,15 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,seq_printf (f,"UNKNOWN UNKNOWN " ); }if (fl->fl_type &LOCK_MAND ) { -seq_printf (f,"%s " , +seq_printf (f,"%s " , (fl->fl_type &LOCK_READ ) ? (fl->fl_type &LOCK_WRITE ) ?"RW " :"READ " : (fl->fl_type &LOCK_WRITE ) ?"WRITE" :"NONE " ); + }else if (IS_FILP_PVT (fl)) { +seq_printf (f,"%s " , fl->fl_type ==F_WRLCK ?"WRITEP" :"READP " ); }else { -seq_printf (f,"%s " , - (lease_breaking (fl)) +seq_printf (f,"%s " , +lease_breaking (fl) ? (fl->fl_type ==F_UNLCK ) ?"UNLCK" :"READ " : (fl->fl_type ==F_WRLCK ) ?"WRITE" :"READ " ); }
include/linux/fs.h +1 -0
@@ -888,6 +888,7 @@ static inline int file_check_writeable(struct file *filp)#define FL_SLEEP 128/* A blocking lock */ #define FL_DOWNGRADE_PENDING 256/* Lease is being downgraded */ #define FL_UNLOCK_PENDING 512/* Lease is being broken */ +#define FL_FILP_PRIVATE 1024/* lock is private to the filp */ /* * Special return value from posix_lock_file() and vfs_lock_file() for
Signature · 1 line
1.8.3.1
RFC PATCH v2 5/5 locks: report l_pid as -1 for FL_FILP_PRIVATE locks
In reply to Jeff LaytonFL_FILP_PRIVATE locks are no longer tied to a particular PID, and are instead inheritable by child processes. Report a l_pid of '-1' for these sorts of locks since the pid is somewhat meaningless for them.
--- fs/locks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/locks.c +2 -2
@@ -1889,7 +1889,7 @@ EXPORT_SYMBOL_GPL(vfs_test_lock);static int posix_lock_to_flock (struct flock *flock,struct file_lock *fl) { - flock->l_pid = fl->fl_pid; + flock->l_pid =IS_FILP_PVT (fl) ?-1 : fl->fl_pid;#if BITS_PER_LONG ==32 /* * Make sure we can represent the posix lock via
@@ -1911,7 +1911,7 @@ static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)#if BITS_PER_LONG ==32 static void posix_lock_to_flock64 (struct flock64 *flock,struct file_lock *fl) { - flock->l_pid = fl->fl_pid; + flock->l_pid =IS_FILP_PVT (fl) ?-1 : fl->fl_pid; flock->l_start = fl->fl_start; flock->l_len = fl->fl_end ==OFFSET_MAX ?0 : fl->fl_end - fl->fl_start +1 ;
Signature · 1 line
1.8.3.1
RE: [RFC PATCH v2 5/5] locks: report l_pid as -1 for FL_FILP_PRIVATE locks
Quoted 1 line
FL_FILP_PRIVATElocks are no longer tied to a particular PID, and are
instead
Quoted 1 line
inheritable by child processes. Report a
l_pidof '-1' for these sorts of
locks
Quoted 1 line
since the pid is somewhat meaningless for them.
Hmm, I suppose in the case of a process that acquires a private lock, forks (passing the lock to the child process) and then exits, pid would be meaningless, but I wonder how common that case is compared to a multi-threaded process (especially a file server) that will hold many private locks, and not pass them to child processes (and exit)?
I.e. as a future user of this feature, I wonder if I'm going to want to know that THESE private locks are owned by Ganesha and THOSE are owned by Samba?
Frank
fs/locks.c EXPORT_SYMBOL_GPL(vfs_test_lock); · line 1890
Quoted 12 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/locks.c +0
-0@@ -1889,7 +1889,7 @@ EXPORT_SYMBOL_GPL(vfs_test_lock);static int posix_lock_to_flock (struct flock *flock,struct file_lock *fl)
{
Quoted 6 lines
fs/locks.c +1
-1- flock->l_pid = fl->fl_pid; + flock->l_pid =IS_FILP_PVT (fl) ?-1 : fl->fl_pid;#if BITS_PER_LONG ==32 /* * Make sure we can represent the posix lock via @@ -1911,7 +1911,7 @@ static int posix_lock_to_flock(struct flock *flock, struct
file_lock
*fl) #if
Quoted 10 lines
BITS_PER_LONG== 32 static voidposix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl){fs/locks.c +1
-2- flock->l_pid = fl->fl_pid; + flock->l_pid =IS_FILP_PVT (fl) ?-1 : fl->fl_pid; flock->l_start = fl->fl_start; flock->l_len = fl->fl_end ==OFFSET_MAX ?0 : fl->fl_end - fl->fl_start +1 ; --1.8.3.1
Quoted 2 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel"
in the
Quoted 2 lines
body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 5/5] locks: report l_pid as -1 for FL_FILP_PRIVATE locks
Quoted 12 lines · On Wed, 20 Nov 2013 09:55:18 -0800 "Frank Filz" <[email protected]> wrote:
Quoted 1 line
FL_FILP_PRIVATElocks are no longer tied to a particular PID, and areinstead
Quoted 1 line
inheritable by child processes. Report a
l_pidof '-1' for these sorts oflocks
Quoted 1 line
since the pid is somewhat meaningless for them.
Hmm, I suppose in the case of a process that acquires a private lock, forks (passing the lock to the child process) and then exits, pid would be meaningless, but I wonder how common that case is compared to a multi-threaded process (especially a file server) that will hold many private locks, and not pass them to child processes (and exit)?
Quoted 5 lines
I.e. as a future user of this feature, I wonder if I'm going to want to know that THESE private locks are owned by Ganesha and THOSE are owned by Samba?
Frank
A fair point.
FWIW, I took the idea of reporting '-1' from BSD, where POSIX and flock locks can apparently conflict. If a flock lock is held on a file and you do a F_GETLK request, then it will report '-1' for the l_pid. [1]
I sort of expect that we may need to eventually add an F_GETLK variant that gives more info. The main reason to do this here is that we need to put something semi-meaningful in that field for "classic" F_GETLK users.
[1]: hmm...probably should put that in the commit log message. I'll do
that for the next respin...
Quoted 36 lines
fs/locks.c EXPORT_SYMBOL_GPL(vfs_test_lock); · line 1890
Quoted 12 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/locks.c +0
-0@@ -1889,7 +1889,7 @@ EXPORT_SYMBOL_GPL(vfs_test_lock);static int posix_lock_to_flock (struct flock *flock,struct file_lock *fl){
Quoted 6 lines
fs/locks.c +1
-1- flock->l_pid = fl->fl_pid; + flock->l_pid =IS_FILP_PVT (fl) ?-1 : fl->fl_pid;#if BITS_PER_LONG ==32 /* * Make sure we can represent the posix lock via @@ -1911,7 +1911,7 @@ static int posix_lock_to_flock(struct flock *flock, struct
file_lock*fl) #if
Quoted 10 lines
BITS_PER_LONG== 32 static voidposix_lock_to_flock64(struct flock64 *flock, struct file_lock *fl){fs/locks.c +1
-2- flock->l_pid = fl->fl_pid; + flock->l_pid =IS_FILP_PVT (fl) ?-1 : fl->fl_pid; flock->l_start = fl->fl_start; flock->l_len = fl->fl_end ==OFFSET_MAX ?0 : fl->fl_end - fl->fl_start +1 ; --1.8.3.1
Quoted 2 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel"in the
Quoted 2 lines
body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Jeff Layton <[email protected]>
Re: [RFC PATCH v2 3/5] locks: add new "private" lock type that is owned by the filp
In reply to Jeff LaytonQuoted 50 lines · Jeff Layton
Due to some unfortunate history, POSIX locks have very strange and unhelpful semantics. The thing that usually catches people by surprise is that they are dropped whenever the process closes any file descriptor associated with the inode.
This is extremely problematic for people developing file servers that need to implement byte-range locks. Developers often need a "lock management" facility to ensure that file descriptors are not closed until all of the locks associated with the inode are finished.
This patchset adds a new type of lock that attempts to address this issue. These locks work just like "normal" POSIX read/write locks, but have semantics that are more like BSD locks with respect to inheritance and behavior on close.
This is implemented primarily by changing how
fl_ownerfield is set for these locks. Instead of having them owned by thefiles_structof the process, they are instead owned by the filp on which they were acquired. Thus, they are inherited acrossfork()and are only released when the last reference to a filp is put.These new semantics prevent them from being merged with "classic" POSIX locks, even if they are acquired by the same process. These locks will also conflict with "classic" POSIX locks even if they are acquired by the same process or on the same file descriptor.
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 22 +++++++++++++++++++++- include/uapi/asm-generic/fcntl.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-)fs/locks.c +10
-0@@ -348,6 +348,26 @@ static int posix_assign_type(struct file_lock *fl, long type) {int err; +/* +* FL_FILP_PRIVATE locks are "owned" by the filp upon which they were +* acquired, regardless of what task is dealing with them. Set the +* fl_owner appropriately. +*/ +switch (type) { +case F_RDLCKP : + type =F_RDLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ;
fs/locks.c static int posix_assign_type(struct file_lock *fl, long type) · line 370
Quoted 10 lines
fs/locks.c +10
-0+case F_WRLCKP : + type =F_WRLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; +case F_UNLCKP : + type =F_UNLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; + } +
After this fl_owner gets set to current->files in flock{64}_to_posix_lock and then reset here. That seems like a trap for the unwary reader.
Could you do something like rename this flock_to_posix_lock_common and move all the 32/64-bit-independent initialization here?
Looks like there's way more duplication than necessary between those two cases.
(Also, why do we have an fl_owner_t instead of using a void?)
--b.
Quoted 45 lines
fs/locks.c +1
-1err =assign_type (fl, type);if (err)return err;@@ -2225,7 +2245,7 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl)) { +if (IS_FLOCK (fl) ||IS_POSIX (fl)) {locks_delete_lock (before);continue ; }include/uapi/asm-generic/fcntl.h +15
-0@@ -151,6 +151,21 @@ struct f_owner_ex {#define F_UNLCK 2#endif +/* +* fd "private" POSIX locks. +* +* Usually POSIX locks held by a process are released on *any* close and are +* not inherited across a fork(). +* +* These lock types will conflict with normal POSIX locks, but are "owned" +* by the fd, not the process. This means that they are inherited across +* fork() like BSD (flock) locks, and they are only closed when the last +* reference to the the filp against which were acquired is closed. +*/ +#define F_RDLCKP 5 +#define F_WRLCKP 6 +#define F_UNLCKP 7 +/* for old implementation of bsd flock () */ #ifndef F_EXLCK #define F_EXLCK 4/* or 3 */ Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 3/5] locks: add new "private" lock type that is owned by the filp
Quoted 66 lines · On Wed, 20 Nov 2013 14:50:32 -0500 "J. Bruce Fields" <[email protected]>…
Quoted 50 lines · Jeff Layton
Due to some unfortunate history, POSIX locks have very strange and unhelpful semantics. The thing that usually catches people by surprise is that they are dropped whenever the process closes any file descriptor associated with the inode.
This is extremely problematic for people developing file servers that need to implement byte-range locks. Developers often need a "lock management" facility to ensure that file descriptors are not closed until all of the locks associated with the inode are finished.
This patchset adds a new type of lock that attempts to address this issue. These locks work just like "normal" POSIX read/write locks, but have semantics that are more like BSD locks with respect to inheritance and behavior on close.
This is implemented primarily by changing how
fl_ownerfield is set for these locks. Instead of having them owned by thefiles_structof the process, they are instead owned by the filp on which they were acquired. Thus, they are inherited acrossfork()and are only released when the last reference to a filp is put.These new semantics prevent them from being merged with "classic" POSIX locks, even if they are acquired by the same process. These locks will also conflict with "classic" POSIX locks even if they are acquired by the same process or on the same file descriptor.
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 22 +++++++++++++++++++++- include/uapi/asm-generic/fcntl.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-)fs/locks.c +10
-0@@ -348,6 +348,26 @@ static int posix_assign_type(struct file_lock *fl, long type) {int err; +/* +* FL_FILP_PRIVATE locks are "owned" by the filp upon which they were +* acquired, regardless of what task is dealing with them. Set the +* fl_owner appropriately. +*/ +switch (type) { +case F_RDLCKP : + type =F_RDLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ;fs/locks.c static int posix_assign_type(struct file_lock *fl, long type) · line 370
Quoted 10 lines
fs/locks.c +10
-0+case F_WRLCKP : + type =F_WRLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; +case F_UNLCKP : + type =F_UNLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; + } +After this
fl_ownergets set tocurrent->filesin flock{64}_to_posix_lock and then reset here. That seems like a trap for the unwary reader.
Quoted 6 lines
Could you do something like rename this
flock_to_posix_lock_commonand move all the 32/64-bit-independent initialization here?Looks like there's way more duplication than necessary between those two cases.
Good point. I'll look at doing some more cleanup in that direction on the next set.
Quoted 2 lines
(Also, why do we have an
fl_owner_tinstead of using a void?)
Another good point. As far as I can tell nothing uses fl_owner for anything but a generic ownership "cookie". The pointer is never actually dereferenced to get back to a files_struct, so a void pointer (or even an unsigned long) would make more sense there.
I'll look at that before sending out the next version of this.
Thanks,
Quoted 46 lines
Quoted 46 lines
fs/locks.c +1
-1err =assign_type (fl, type);if (err)return err;@@ -2225,7 +2245,7 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl)) { +if (IS_FLOCK (fl) ||IS_POSIX (fl)) {locks_delete_lock (before);continue ; }include/uapi/asm-generic/fcntl.h +15
-0@@ -151,6 +151,21 @@ struct f_owner_ex {#define F_UNLCK 2#endif +/* +* fd "private" POSIX locks. +* +* Usually POSIX locks held by a process are released on *any* close and are +* not inherited across a fork(). +* +* These lock types will conflict with normal POSIX locks, but are "owned" +* by the fd, not the process. This means that they are inherited across +* fork() like BSD (flock) locks, and they are only closed when the last +* reference to the the filp against which were acquired is closed. +*/ +#define F_RDLCKP 5 +#define F_WRLCKP 6 +#define F_UNLCKP 7 +/* for old implementation of bsd flock () */ #ifndef F_EXLCK #define F_EXLCK 4/* or 3 */ Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Jeff Layton <[email protected]>
Re: [RFC PATCH v2 4/5] locks: show private lock types in /proc/locks
In reply to Jeff LaytonQuoted 5 lines · Jeff Layton
Show "private" locks in
/proc/lockswith a 'P' suffix. This does mean that we need to widen the column by one character.Also, tighten up the check in
locks_remove_filp()to ensure that onlyIS_FILP_PVTlocks are removed there.
So that part belongs in the previous patch?
--b.
Quoted 85 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 15 +++++++++++---- include/linux/fs.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)fs/locks.c +11
-4@@ -135,6 +135,7 @@#define IS_POSIX (fl) (fl->fl_flags & FL_POSIX)#define IS_FLOCK (fl) (fl->fl_flags & FL_FLOCK)#define IS_LEASE (fl) (fl->fl_flags & (FL_LEASE|FL_DELEG)) +#define IS_FILP_PVT (fl) (fl->fl_flags & FL_FILP_PRIVATE)static bool lease_breaking (struct file_lock *fl) {@@ -357,14 +358,17 @@ static int posix_assign_type(struct file_lock *fl, long type)case F_RDLCKP : type =F_RDLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_WRLCKP : type =F_WRLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_UNLCKP : type =F_UNLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ; }@@ -2245,7 +2249,8 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl) ||IS_POSIX (fl)) { +if (IS_FLOCK (fl) || + (IS_POSIX (fl) &&IS_FILP_PVT (fl))) {locks_delete_lock (before);continue ; }@@ -2345,13 +2350,15 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,seq_printf (f,"UNKNOWN UNKNOWN " ); }if (fl->fl_type &LOCK_MAND ) { -seq_printf (f,"%s " , +seq_printf (f,"%s " , (fl->fl_type &LOCK_READ ) ? (fl->fl_type &LOCK_WRITE ) ?"RW " :"READ " : (fl->fl_type &LOCK_WRITE ) ?"WRITE" :"NONE " ); + }else if (IS_FILP_PVT (fl)) { +seq_printf (f,"%s " , fl->fl_type ==F_WRLCK ?"WRITEP" :"READP " ); }else { -seq_printf (f,"%s " , - (lease_breaking (fl)) +seq_printf (f,"%s " , +lease_breaking (fl) ? (fl->fl_type ==F_UNLCK ) ?"UNLCK" :"READ " : (fl->fl_type ==F_WRLCK ) ?"WRITE" :"READ " ); }include/linux/fs.h +1
-0@@ -888,6 +888,7 @@ static inline int file_check_writeable(struct file *filp)#define FL_SLEEP 128/* A blocking lock */ #define FL_DOWNGRADE_PENDING 256/* Lease is being downgraded */ #define FL_UNLOCK_PENDING 512/* Lease is being broken */ +#define FL_FILP_PRIVATE 1024/* lock is private to the filp */ /* * Special return value from posix_lock_file() and vfs_lock_file() for Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 4/5] locks: show private lock types in /proc/locks
Quoted 11 lines · On Wed, 20 Nov 2013 15:00:56 -0500 "J. Bruce Fields" <[email protected]>…
Quoted 5 lines · Jeff Layton
Show "private" locks in
/proc/lockswith a 'P' suffix. This does mean that we need to widen the column by one character.Also, tighten up the check in
locks_remove_filp()to ensure that onlyIS_FILP_PVTlocks are removed there.So that part belongs in the previous patch?
--b.
Well, it's not technically broken with it in this patch. The code should still basically work, but yeah it probably makes some sense to move that part into the previous patch. I'll fix in that in the next version.
Thanks,
Quoted 85 lines
Quoted 85 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 15 +++++++++++---- include/linux/fs.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)fs/locks.c +11
-4@@ -135,6 +135,7 @@#define IS_POSIX (fl) (fl->fl_flags & FL_POSIX)#define IS_FLOCK (fl) (fl->fl_flags & FL_FLOCK)#define IS_LEASE (fl) (fl->fl_flags & (FL_LEASE|FL_DELEG)) +#define IS_FILP_PVT (fl) (fl->fl_flags & FL_FILP_PRIVATE)static bool lease_breaking (struct file_lock *fl) {@@ -357,14 +358,17 @@ static int posix_assign_type(struct file_lock *fl, long type)case F_RDLCKP : type =F_RDLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_WRLCKP : type =F_WRLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_UNLCKP : type =F_UNLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ; }@@ -2245,7 +2249,8 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl) ||IS_POSIX (fl)) { +if (IS_FLOCK (fl) || + (IS_POSIX (fl) &&IS_FILP_PVT (fl))) {locks_delete_lock (before);continue ; }@@ -2345,13 +2350,15 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,seq_printf (f,"UNKNOWN UNKNOWN " ); }if (fl->fl_type &LOCK_MAND ) { -seq_printf (f,"%s " , +seq_printf (f,"%s " , (fl->fl_type &LOCK_READ ) ? (fl->fl_type &LOCK_WRITE ) ?"RW " :"READ " : (fl->fl_type &LOCK_WRITE ) ?"WRITE" :"NONE " ); + }else if (IS_FILP_PVT (fl)) { +seq_printf (f,"%s " , fl->fl_type ==F_WRLCK ?"WRITEP" :"READP " ); }else { -seq_printf (f,"%s " , - (lease_breaking (fl)) +seq_printf (f,"%s " , +lease_breaking (fl) ? (fl->fl_type ==F_UNLCK ) ?"UNLCK" :"READ " : (fl->fl_type ==F_WRLCK ) ?"WRITE" :"READ " ); }include/linux/fs.h +1
-0@@ -888,6 +888,7 @@ static inline int file_check_writeable(struct file *filp)#define FL_SLEEP 128/* A blocking lock */ #define FL_DOWNGRADE_PENDING 256/* Lease is being downgraded */ #define FL_UNLOCK_PENDING 512/* Lease is being broken */ +#define FL_FILP_PRIVATE 1024/* lock is private to the filp */ /* * Special return value from posix_lock_file() and vfs_lock_file() for Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Jeff Layton <[email protected]>
Re: [RFC PATCH v2 4/5] locks: show private lock types in /proc/locks
In reply to J. Bruce FieldsQuoted 8 lines · bfields
Quoted 5 lines · Jeff Layton
Show "private" locks in
/proc/lockswith a 'P' suffix. This does mean that we need to widen the column by one character.Also, tighten up the check in
locks_remove_filp()to ensure that onlyIS_FILP_PVTlocks are removed there.So that part belongs in the previous patch?
I think it's that previous patch that actually "turns on" the new user interface (so after that patch userspace will get a lock instead of -EINVAL or whatever).
Might be safest to delay doing that until the end of the series so as not to expose any partial implementation.
--b.
Quoted 88 lines
--b.
Quoted 85 lines
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 15 +++++++++++---- include/linux/fs.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)fs/locks.c +11
-4@@ -135,6 +135,7 @@#define IS_POSIX (fl) (fl->fl_flags & FL_POSIX)#define IS_FLOCK (fl) (fl->fl_flags & FL_FLOCK)#define IS_LEASE (fl) (fl->fl_flags & (FL_LEASE|FL_DELEG)) +#define IS_FILP_PVT (fl) (fl->fl_flags & FL_FILP_PRIVATE)static bool lease_breaking (struct file_lock *fl) {@@ -357,14 +358,17 @@ static int posix_assign_type(struct file_lock *fl, long type)case F_RDLCKP : type =F_RDLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_WRLCKP : type =F_WRLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ;case F_UNLCKP : type =F_UNLCK ; fl->fl_owner = (fl_owner_t )fl->fl_file; + fl->fl_flags |=FL_FILP_PRIVATE ;break ; }@@ -2245,7 +2249,8 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl) ||IS_POSIX (fl)) { +if (IS_FLOCK (fl) || + (IS_POSIX (fl) &&IS_FILP_PVT (fl))) {locks_delete_lock (before);continue ; }@@ -2345,13 +2350,15 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,seq_printf (f,"UNKNOWN UNKNOWN " ); }if (fl->fl_type &LOCK_MAND ) { -seq_printf (f,"%s " , +seq_printf (f,"%s " , (fl->fl_type &LOCK_READ ) ? (fl->fl_type &LOCK_WRITE ) ?"RW " :"READ " : (fl->fl_type &LOCK_WRITE ) ?"WRITE" :"NONE " ); + }else if (IS_FILP_PVT (fl)) { +seq_printf (f,"%s " , fl->fl_type ==F_WRLCK ?"WRITEP" :"READP " ); }else { -seq_printf (f,"%s " , - (lease_breaking (fl)) +seq_printf (f,"%s " , +lease_breaking (fl) ? (fl->fl_type ==F_UNLCK ) ?"UNLCK" :"READ " : (fl->fl_type ==F_WRLCK ) ?"WRITE" :"READ " ); }include/linux/fs.h +1
-0@@ -888,6 +888,7 @@ static inline int file_check_writeable(struct file *filp)#define FL_SLEEP 128/* A blocking lock */ #define FL_DOWNGRADE_PENDING 256/* Lease is being downgraded */ #define FL_UNLOCK_PENDING 512/* Lease is being broken */ +#define FL_FILP_PRIVATE 1024/* lock is private to the filp */ /* * Special return value from posix_lock_file() and vfs_lock_file() for Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC PATCH v2 1/5] locks: consolidate checks for compatible filp->f_mode values in setlk handlers
In reply to Jeff LaytonQuoted 4 lines · Jeff Layton
Add a wrapper around
assign_typethat does this instead of duplicating this check in two places. This also fixes a minor wart in the code where we continue referring to the struct flock after converting it to structfile_lock.
I don't think posix_assign_type is a good name for this helper, but as Bruce already pointed out more work is required in that area anyway.
Re: [RFC PATCH v2 2/5] locks: rename locks_remove_flock to locks_remove_filp
In reply to Jeff LaytonQuoted 3 lines · Jeff Layton
This function currently removes leases in addition to flock locks, so the name is misleading. Rename it to
locks_remove_filpto indicate that it removes locks that are associated with a particular filp.
s/filp/file/ please.
Re: [RFC PATCH v2 3/5] locks: add new "private" lock type that is owned by the filp
In reply to Jeff Laytons/FILP/FILE/
Re: [Nfs-ganesha-devel] [RFC PATCH v2 3/5] locks: add new "private" lock type that is owned by the filp
In reply to J. Bruce FieldsQuoted 66 lines · On Wed, 20 Nov 2013 14:50:32 -0500 "J. Bruce Fields" <[email protected]>…
Quoted 50 lines · Jeff Layton
Due to some unfortunate history, POSIX locks have very strange and unhelpful semantics. The thing that usually catches people by surprise is that they are dropped whenever the process closes any file descriptor associated with the inode.
This is extremely problematic for people developing file servers that need to implement byte-range locks. Developers often need a "lock management" facility to ensure that file descriptors are not closed until all of the locks associated with the inode are finished.
This patchset adds a new type of lock that attempts to address this issue. These locks work just like "normal" POSIX read/write locks, but have semantics that are more like BSD locks with respect to inheritance and behavior on close.
This is implemented primarily by changing how
fl_ownerfield is set for these locks. Instead of having them owned by thefiles_structof the process, they are instead owned by the filp on which they were acquired. Thus, they are inherited acrossfork()and are only released when the last reference to a filp is put.These new semantics prevent them from being merged with "classic" POSIX locks, even if they are acquired by the same process. These locks will also conflict with "classic" POSIX locks even if they are acquired by the same process or on the same file descriptor.
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 22 +++++++++++++++++++++- include/uapi/asm-generic/fcntl.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-)fs/locks.c +10
-0@@ -348,6 +348,26 @@ static int posix_assign_type(struct file_lock *fl, long type) {int err; +/* +* FL_FILP_PRIVATE locks are "owned" by the filp upon which they were +* acquired, regardless of what task is dealing with them. Set the +* fl_owner appropriately. +*/ +switch (type) { +case F_RDLCKP : + type =F_RDLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ;fs/locks.c static int posix_assign_type(struct file_lock *fl, long type) · line 370
Quoted 10 lines
fs/locks.c +10
-0+case F_WRLCKP : + type =F_WRLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; +case F_UNLCKP : + type =F_UNLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; + } +After this
fl_ownergets set tocurrent->filesin flock{64}_to_posix_lock and then reset here. That seems like a trap for the unwary reader.
Quoted 6 lines
Could you do something like rename this
flock_to_posix_lock_commonand move all the 32/64-bit-independent initialization here?Looks like there's way more duplication than necessary between those two cases.
Ok, finally got a chance to start looking at this again...
I agree that at first glance, it looks like there is a lot of duplication between flock_to_posix_lock and flock64_to_posix_lock, but the problem we have is that we need to initialize the file_locks with info from two different types of structs that were passed in from userland (flock and flock64).
I don't see a clean way to consolidate the two given that...
Quoted 60 lines
(Also, why do we have an
fl_owner_tinstead of using a void?)--b.
Quoted 45 lines
fs/locks.c +1
-1err =assign_type (fl, type);if (err)return err;@@ -2225,7 +2245,7 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl)) { +if (IS_FLOCK (fl) ||IS_POSIX (fl)) {locks_delete_lock (before);continue ; }include/uapi/asm-generic/fcntl.h +15
-0@@ -151,6 +151,21 @@ struct f_owner_ex {#define F_UNLCK 2#endif +/* +* fd "private" POSIX locks. +* +* Usually POSIX locks held by a process are released on *any* close and are +* not inherited across a fork(). +* +* These lock types will conflict with normal POSIX locks, but are "owned" +* by the fd, not the process. This means that they are inherited across +* fork() like BSD (flock) locks, and they are only closed when the last +* reference to the the filp against which were acquired is closed. +*/ +#define F_RDLCKP 5 +#define F_WRLCKP 6 +#define F_UNLCKP 7 +/* for old implementation of bsd flock () */ #ifndef F_EXLCK #define F_EXLCK 4/* or 3 */ Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Nfs-ganesha-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs-ganesha-devel
Signature · 1 line
Jeff Layton <[email protected]>
Re: [Nfs-ganesha-devel] [RFC PATCH v2 3/5] locks: add new "private" lock type that is owned by the filp
Quoted 78 lines · Jeff Layton
Quoted 66 lines · On Wed, 20 Nov 2013 14:50:32 -0500 "J. Bruce Fields" <[email protected]>…
Quoted 50 lines · Jeff Layton
Due to some unfortunate history, POSIX locks have very strange and unhelpful semantics. The thing that usually catches people by surprise is that they are dropped whenever the process closes any file descriptor associated with the inode.
This is extremely problematic for people developing file servers that need to implement byte-range locks. Developers often need a "lock management" facility to ensure that file descriptors are not closed until all of the locks associated with the inode are finished.
This patchset adds a new type of lock that attempts to address this issue. These locks work just like "normal" POSIX read/write locks, but have semantics that are more like BSD locks with respect to inheritance and behavior on close.
This is implemented primarily by changing how
fl_ownerfield is set for these locks. Instead of having them owned by thefiles_structof the process, they are instead owned by the filp on which they were acquired. Thus, they are inherited acrossfork()and are only released when the last reference to a filp is put.These new semantics prevent them from being merged with "classic" POSIX locks, even if they are acquired by the same process. These locks will also conflict with "classic" POSIX locks even if they are acquired by the same process or on the same file descriptor.
Signed-off-by Jeff Layton <[email protected]>--- fs/locks.c | 22 +++++++++++++++++++++- include/uapi/asm-generic/fcntl.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-)fs/locks.c +10
-0@@ -348,6 +348,26 @@ static int posix_assign_type(struct file_lock *fl, long type) {int err; +/* +* FL_FILP_PRIVATE locks are "owned" by the filp upon which they were +* acquired, regardless of what task is dealing with them. Set the +* fl_owner appropriately. +*/ +switch (type) { +case F_RDLCKP : + type =F_RDLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ;fs/locks.c static int posix_assign_type(struct file_lock *fl, long type) · line 370
Quoted 10 lines
fs/locks.c +10
-0+case F_WRLCKP : + type =F_WRLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; +case F_UNLCKP : + type =F_UNLCK ; + fl->fl_owner = (fl_owner_t )fl->fl_file; +break ; + } +After this
fl_ownergets set tocurrent->filesin flock{64}_to_posix_lock and then reset here. That seems like a trap for the unwary reader.Quoted 6 lines
Could you do something like rename this
flock_to_posix_lock_commonand move all the 32/64-bit-independent initialization here?Looks like there's way more duplication than necessary between those two cases.
Ok, finally got a chance to start looking at this again...
Quoted 7 lines
I agree that at first glance, it looks like there is a lot of duplication between
flock_to_posix_lockandflock64_to_posix_lock, but the problem we have is that we need to initialize thefile_lockswith info from two different types of structs that were passed in from userland (flock and flock64).I don't see a clean way to consolidate the two given that...
Doh, yes I overlooked that. Still seems like there should be more to do, but let me go look at your revised series....
--b.
Quoted 65 lines
Quoted 61 lines
(Also, why do we have an
fl_owner_tinstead of using a void?)--b.
Quoted 45 lines
fs/locks.c +1
-1err =assign_type (fl, type);if (err)return err;@@ -2225,7 +2245,7 @@ void locks_remove_filp(struct file *filp)while ((fl = *before) !=NULL ) {if (fl->fl_file == filp) { -if (IS_FLOCK (fl)) { +if (IS_FLOCK (fl) ||IS_POSIX (fl)) {locks_delete_lock (before);continue ; }include/uapi/asm-generic/fcntl.h +15
-0@@ -151,6 +151,21 @@ struct f_owner_ex {#define F_UNLCK 2#endif +/* +* fd "private" POSIX locks. +* +* Usually POSIX locks held by a process are released on *any* close and are +* not inherited across a fork(). +* +* These lock types will conflict with normal POSIX locks, but are "owned" +* by the fd, not the process. This means that they are inherited across +* fork() like BSD (flock) locks, and they are only closed when the last +* reference to the the filp against which were acquired is closed. +*/ +#define F_RDLCKP 5 +#define F_WRLCKP 6 +#define F_UNLCKP 7 +/* for old implementation of bsd flock () */ #ifndef F_EXLCK #define F_EXLCK 4/* or 3 */ Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation. Intel(R) Software Adrenaline delivers strategic insight and game-changing conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
Nfs-ganesha-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs-ganesha-develSignature · 1 line
Jeff Layton <[email protected]>