Allow cluster-wide flock
Subsystems (2)
I missed Ken's original mail this morning, so apologies for breaking the thread...
So I have 2 comments:
Firstly, it would be nice to throw out the existing wait loop in sys_flock(), and replace it with a call to this new flock_lock_file_wait(). I suppose that can be done in a separate cleanup patch, though...
More importantly, though, I'm concerned that the overloading of f_op->lock() may break behaviour on NFS and CIFS.
NFS currently has a test in nfs_lock() that causes it to return -ENOLCK if the argument is not a posix lock. I'm planning on changing that by implementing a proper flock(), but we need an interim solution that doesn't change existing behaviour for people.
Any comment on the effects on CIFS, Steven?
One solution that I've already suggested to Ken & co is to use a separate f_op->flock() call. That would be my preference, since the filesystems have to treat flock and posix locks differently anyway.
Alternatively, we're going to have to fix up NFS at least (CIFS?) before this patch can be applied to the mainline kernel.
Cheers,
Trond
Quoted 10 lines · Trond Myklebust
...
Firstly, it would be nice to throw out the existing wait loop insys_flock(), and replace it with a call to this newflock_lock_file_wait(). I suppose that can be done in a separate cleanup patch, though...
...
One solution that I've already suggested to Ken & co is to use a separatef_op->flock()call. That would be my preference, since the filesystems have to treat flock and posix locks differently anyway.
...
Thanks for the suggestions. Below is a patch that implements both of them.
fs/locks.c +8 -20
@@ -1392,24 +1392,12 @@ asmlinkage long sys_flock(unsigned int fif (error) goto out_free; -if (filp->f_op && filp->f_op->lock) { - error = filp->f_op->lock (filp, - (can_sleep) ?F_SETLKW :F_SETLK , - lock); - goto out_free; - } - -for (;;) { - error =flock_lock_file (filp, lock); -if ((error != -EAGAIN ) || !can_sleep) -break ; - error =wait_event_interruptible (lock->fl_wait, !lock->fl_next); -if (!error) -continue ; - -locks_delete_block (lock); -break ; - } +if (filp->f_op && filp->f_op->flock) + error = filp->f_op->flock (filp, + (can_sleep) ?F_SETLKW :F_SETLK , + lock); +else + error =flock_lock_file_wait (filp, lock); out_free:if (list_empty (&lock->fl_link)) {
@@ -1766,10 +1754,10 @@ void locks_remove_flock(struct file *filif (!inode->i_flock)return ; -if (filp->f_op && filp->f_op->lock) { +if (filp->f_op && filp->f_op->flock) {struct file_lock fl = { .fl_flags =FL_FLOCK , .fl_type =F_UNLCK }; - filp->f_op->lock (filp,F_SETLKW , &fl); + filp->f_op->flock (filp,F_SETLKW , &fl); }lock_kernel ();
include/linux/fs.h +1 -0
@@ -983,6 +983,7 @@ struct file_operations {unsigned long (*get_unmapped_area)(struct file *,unsigned long ,unsigned long ,unsigned long ,unsigned long );int (*check_flags)(int );int (*dir_notify)(struct file *filp,unsigned long arg); +int (*flock) (struct file *,int ,struct file_lock *); };struct inode_operations {
Signature · 1 line
Ken Preslan <[email protected]>