Allow cluster-wide flock
Subsystems (2)
PATCH 1/1 Allow cluster-wide flock
Hi,
Below is a patch that lets a cluster filesystem (such as GFS) implement flock across a the cluster. Please apply.
Thanks!
fs/locks.c +40 -0
@@ -1318,6 +1318,33 @@ out_unlock: }/** +* flock_lock_file_wait - Apply a FLOCK-style lock to a file +* @filp: The file to apply the lock to +* @fl: The lock to be applied +* +* Add a FLOCK style lock to a file. +*/ +int flock_lock_file_wait (struct file *filp,struct file_lock *fl) +{ +int error; +might_sleep (); +for (;;) { + error =flock_lock_file (filp, fl); +if ((error != -EAGAIN ) || !(fl->fl_flags &FL_SLEEP )) +break ; + error =wait_event_interruptible (fl->fl_wait, !fl->fl_next); +if (!error) +continue ; + +locks_delete_block (fl); +break ; + } +return error; +} + +EXPORT_SYMBOL (flock_lock_file_wait); + +/** * sys_flock: - flock() system call. * @fd: the file descriptor to lock. * @cmd: the type of lock to apply.
@@ -1365,6 +1392,13 @@ 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)
@@ -1732,6 +1766,12 @@ void locks_remove_flock(struct file *filif (!inode->i_flock)return ; +if (filp->f_op && filp->f_op->lock) { +struct file_lock fl = { .fl_flags =FL_FLOCK , + .fl_type =F_UNLCK }; + filp->f_op->lock (filp,F_SETLKW , &fl); + } +lock_kernel (); before = &inode->i_flock;
include/linux/fs.h +1 -0
@@ -697,6 +697,7 @@ extern int posix_lock_file_wait(struct fextern void posix_block_lock (struct file_lock *,struct file_lock *);extern void posix_unblock_lock (struct file *,struct file_lock *);extern int posix_locks_deadlock (struct file_lock *,struct file_lock *); +extern int flock_lock_file_wait (struct file *filp,struct file_lock *fl);extern int __break_lease (struct inode *inode,unsigned int flags);extern void lease_get_mtime (struct inode *,struct timespec *time);extern int lock_may_read (struct inode *,loff_t start,unsigned long count);
Quoted 4 lines · Ken Preslan
Hi,
Below is a patch that lets a cluster filesystem (such as GFS) implement flock across a the cluster. Please apply.
flock affects local node only traditionally and applications expect high performance from it. Our documentation merely says
flock(2) does not lock files over NFS. Use fcntl(2) instead:
that does
work over NFS, given a sufficiently recent version of Linux
and a
server which supports locking.
I'm not sure how we should count GFS but other than noting a need to think about it I see no problems with a cluster being "local"