Commit 5a13e2bf authored by Stephen Rothwell's avatar Stephen Rothwell Committed by Linus Torvalds

[PATCH] fs/locks.c: add and use IS_{POSIX, FLOCK, LEASE} macros

Another trivial part of a Matthew Wilcox patch.  This just
defines macros for distinguishing the differnet types of locks.
parent 6176eeb2
...@@ -126,6 +126,10 @@ ...@@ -126,6 +126,10 @@
#include <asm/semaphore.h> #include <asm/semaphore.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#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)
int leases_enable = 1; int leases_enable = 1;
int lease_break_time = 45; int lease_break_time = 45;
...@@ -561,8 +565,7 @@ static int posix_locks_conflict(struct file_lock *caller_fl, struct file_lock *s ...@@ -561,8 +565,7 @@ static int posix_locks_conflict(struct file_lock *caller_fl, struct file_lock *s
/* POSIX locks owned by the same process do not conflict with /* POSIX locks owned by the same process do not conflict with
* each other. * each other.
*/ */
if (!(sys_fl->fl_flags & FL_POSIX) || if (!IS_POSIX(sys_fl) || locks_same_owner(caller_fl, sys_fl))
locks_same_owner(caller_fl, sys_fl))
return (0); return (0);
/* Check whether they overlap */ /* Check whether they overlap */
...@@ -580,8 +583,7 @@ static int flock_locks_conflict(struct file_lock *caller_fl, struct file_lock *s ...@@ -580,8 +583,7 @@ static int flock_locks_conflict(struct file_lock *caller_fl, struct file_lock *s
/* FLOCK locks referring to the same filp do not conflict with /* FLOCK locks referring to the same filp do not conflict with
* each other. * each other.
*/ */
if (!(sys_fl->fl_flags & FL_FLOCK) || if (!IS_FLOCK(sys_fl) || (caller_fl->fl_file == sys_fl->fl_file))
(caller_fl->fl_file == sys_fl->fl_file))
return (0); return (0);
#ifdef MSNFS #ifdef MSNFS
if ((caller_fl->fl_type & LOCK_MAND) || (sys_fl->fl_type & LOCK_MAND)) if ((caller_fl->fl_type & LOCK_MAND) || (sys_fl->fl_type & LOCK_MAND))
...@@ -634,7 +636,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl) ...@@ -634,7 +636,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
lock_kernel(); lock_kernel();
for (cfl = filp->f_dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { for (cfl = filp->f_dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) {
if (!(cfl->fl_flags & FL_POSIX)) if (!IS_POSIX(cfl))
continue; continue;
if (posix_locks_conflict(cfl, fl)) if (posix_locks_conflict(cfl, fl))
break; break;
...@@ -696,7 +698,7 @@ int locks_mandatory_locked(struct inode *inode) ...@@ -696,7 +698,7 @@ int locks_mandatory_locked(struct inode *inode)
*/ */
lock_kernel(); lock_kernel();
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
if (!(fl->fl_flags & FL_POSIX)) if (!IS_POSIX(fl))
continue; continue;
if (fl->fl_owner != owner) if (fl->fl_owner != owner)
break; break;
...@@ -732,7 +734,7 @@ int locks_mandatory_area(int read_write, struct inode *inode, ...@@ -732,7 +734,7 @@ int locks_mandatory_area(int read_write, struct inode *inode,
* the proposed read/write. * the proposed read/write.
*/ */
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
if (!(fl->fl_flags & FL_POSIX)) if (!IS_POSIX(fl))
continue; continue;
if (fl->fl_start > new_fl->fl_end) if (fl->fl_start > new_fl->fl_end)
break; break;
...@@ -790,7 +792,7 @@ static int flock_lock_file(struct file *filp, unsigned int lock_type, ...@@ -790,7 +792,7 @@ static int flock_lock_file(struct file *filp, unsigned int lock_type,
search: search:
change = 0; change = 0;
before = &inode->i_flock; before = &inode->i_flock;
while (((fl = *before) != NULL) && (fl->fl_flags & FL_FLOCK)) { while (((fl = *before) != NULL) && IS_FLOCK(fl)) {
if (filp == fl->fl_file) { if (filp == fl->fl_file) {
if (lock_type == fl->fl_type) if (lock_type == fl->fl_type)
goto out; goto out;
...@@ -815,7 +817,7 @@ static int flock_lock_file(struct file *filp, unsigned int lock_type, ...@@ -815,7 +817,7 @@ static int flock_lock_file(struct file *filp, unsigned int lock_type,
goto out; goto out;
repeat: repeat:
for (fl = inode->i_flock; (fl != NULL) && (fl->fl_flags & FL_FLOCK); for (fl = inode->i_flock; (fl != NULL) && IS_FLOCK(fl);
fl = fl->fl_next) { fl = fl->fl_next) {
if (!flock_locks_conflict(new_fl, fl)) if (!flock_locks_conflict(new_fl, fl))
continue; continue;
...@@ -880,7 +882,7 @@ int posix_lock_file(struct file *filp, struct file_lock *caller, ...@@ -880,7 +882,7 @@ int posix_lock_file(struct file *filp, struct file_lock *caller,
if (caller->fl_type != F_UNLCK) { if (caller->fl_type != F_UNLCK) {
repeat: repeat:
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
if (!(fl->fl_flags & FL_POSIX)) if (!IS_POSIX(fl))
continue; continue;
if (!posix_locks_conflict(caller, fl)) if (!posix_locks_conflict(caller, fl))
continue; continue;
...@@ -909,7 +911,7 @@ int posix_lock_file(struct file *filp, struct file_lock *caller, ...@@ -909,7 +911,7 @@ int posix_lock_file(struct file *filp, struct file_lock *caller,
/* First skip locks owned by other processes. /* First skip locks owned by other processes.
*/ */
while ((fl = *before) && (!(fl->fl_flags & FL_POSIX) || while ((fl = *before) && (!IS_POSIX(fl) ||
!locks_same_owner(caller, fl))) { !locks_same_owner(caller, fl))) {
before = &fl->fl_next; before = &fl->fl_next;
} }
...@@ -1085,7 +1087,7 @@ int __get_lease(struct inode *inode, unsigned int mode) ...@@ -1085,7 +1087,7 @@ int __get_lease(struct inode *inode, unsigned int mode)
if (error != 0) if (error != 0)
goto out; goto out;
flock = inode->i_flock; flock = inode->i_flock;
if (!(flock && (flock->fl_flags & FL_LEASE))) if (!(flock && IS_LEASE(flock)))
goto out; goto out;
} while (flock->fl_type & F_INPROGRESS); } while (flock->fl_type & F_INPROGRESS);
} }
...@@ -1110,7 +1112,7 @@ int __get_lease(struct inode *inode, unsigned int mode) ...@@ -1110,7 +1112,7 @@ int __get_lease(struct inode *inode, unsigned int mode)
do { do {
fl->fl_type = future; fl->fl_type = future;
fl = fl->fl_next; fl = fl->fl_next;
} while (fl != NULL && (fl->fl_flags & FL_LEASE)); } while (fl != NULL && IS_LEASE(fl));
kill_fasync(&flock->fl_fasync, SIGIO, POLL_MSG); kill_fasync(&flock->fl_fasync, SIGIO, POLL_MSG);
...@@ -1131,7 +1133,7 @@ int __get_lease(struct inode *inode, unsigned int mode) ...@@ -1131,7 +1133,7 @@ int __get_lease(struct inode *inode, unsigned int mode)
printk(KERN_WARNING "lease timed out\n"); printk(KERN_WARNING "lease timed out\n");
} else if (error > 0) { } else if (error > 0) {
flock = inode->i_flock; flock = inode->i_flock;
if (flock && (flock->fl_flags & FL_LEASE)) if (flock && IS_LEASE(flock))
goto restart; goto restart;
error = 0; error = 0;
} }
...@@ -1154,7 +1156,7 @@ int __get_lease(struct inode *inode, unsigned int mode) ...@@ -1154,7 +1156,7 @@ int __get_lease(struct inode *inode, unsigned int mode)
time_t lease_get_mtime(struct inode *inode) time_t lease_get_mtime(struct inode *inode)
{ {
struct file_lock *flock = inode->i_flock; struct file_lock *flock = inode->i_flock;
if (flock && (flock->fl_flags & FL_LEASE) && (flock->fl_type & F_WRLCK)) if (flock && IS_LEASE(flock) && (flock->fl_type & F_WRLCK))
return CURRENT_TIME; return CURRENT_TIME;
return inode->i_mtime; return inode->i_mtime;
} }
...@@ -1177,7 +1179,7 @@ int fcntl_getlease(struct file *filp) ...@@ -1177,7 +1179,7 @@ int fcntl_getlease(struct file *filp)
struct file_lock *fl; struct file_lock *fl;
fl = filp->f_dentry->d_inode->i_flock; fl = filp->f_dentry->d_inode->i_flock;
if ((fl == NULL) || ((fl->fl_flags & FL_LEASE) == 0)) if ((fl == NULL) || !IS_LEASE(fl))
return F_UNLCK; return F_UNLCK;
return fl->fl_type & ~F_INPROGRESS; return fl->fl_type & ~F_INPROGRESS;
} }
...@@ -1243,7 +1245,7 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg) ...@@ -1243,7 +1245,7 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
lock_kernel(); lock_kernel();
while ((fl = *before) != NULL) { while ((fl = *before) != NULL) {
if (fl->fl_flags != FL_LEASE) if (!IS_LEASE(fl))
break; break;
if (fl->fl_file == filp) if (fl->fl_file == filp)
my_before = before; my_before = before;
...@@ -1646,7 +1648,7 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner) ...@@ -1646,7 +1648,7 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)
lock_kernel(); lock_kernel();
before = &inode->i_flock; before = &inode->i_flock;
while ((fl = *before) != NULL) { while ((fl = *before) != NULL) {
if ((fl->fl_flags & FL_POSIX) && fl->fl_owner == owner) { if (IS_POSIX(fl) && fl->fl_owner == owner) {
locks_unlock_delete(before); locks_unlock_delete(before);
before = &inode->i_flock; before = &inode->i_flock;
continue; continue;
...@@ -1672,8 +1674,7 @@ void locks_remove_flock(struct file *filp) ...@@ -1672,8 +1674,7 @@ void locks_remove_flock(struct file *filp)
before = &inode->i_flock; before = &inode->i_flock;
while ((fl = *before) != NULL) { while ((fl = *before) != NULL) {
if ((fl->fl_flags & (FL_FLOCK|FL_LEASE)) if ((IS_FLOCK(fl) || IS_LEASE(fl)) && (fl->fl_file == filp)) {
&& (fl->fl_file == filp)) {
locks_delete_lock(before, 0); locks_delete_lock(before, 0);
continue; continue;
} }
...@@ -1716,21 +1717,21 @@ static void lock_get_status(char* out, struct file_lock *fl, int id, char *pfx) ...@@ -1716,21 +1717,21 @@ static void lock_get_status(char* out, struct file_lock *fl, int id, char *pfx)
inode = fl->fl_file->f_dentry->d_inode; inode = fl->fl_file->f_dentry->d_inode;
out += sprintf(out, "%d:%s ", id, pfx); out += sprintf(out, "%d:%s ", id, pfx);
if (fl->fl_flags & FL_POSIX) { if (IS_POSIX(fl)) {
out += sprintf(out, "%6s %s ", out += sprintf(out, "%6s %s ",
(fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ", (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ",
(inode == NULL) ? "*NOINODE*" : (inode == NULL) ? "*NOINODE*" :
(IS_MANDLOCK(inode) && (IS_MANDLOCK(inode) &&
(inode->i_mode & (S_IXGRP | S_ISGID)) == S_ISGID) ? (inode->i_mode & (S_IXGRP | S_ISGID)) == S_ISGID) ?
"MANDATORY" : "ADVISORY "); "MANDATORY" : "ADVISORY ");
} else if (fl->fl_flags & FL_FLOCK) { } else if (IS_FLOCK(fl)) {
#ifdef MSNFS #ifdef MSNFS
if (fl->fl_type & LOCK_MAND) { if (fl->fl_type & LOCK_MAND) {
out += sprintf(out, "FLOCK MSNFS "); out += sprintf(out, "FLOCK MSNFS ");
} else } else
#endif #endif
out += sprintf(out, "FLOCK ADVISORY "); out += sprintf(out, "FLOCK ADVISORY ");
} else if (fl->fl_flags & FL_LEASE) { } else if (IS_LEASE(fl)) {
out += sprintf(out, "LEASE MANDATORY "); out += sprintf(out, "LEASE MANDATORY ");
} else { } else {
out += sprintf(out, "UNKNOWN UNKNOWN "); out += sprintf(out, "UNKNOWN UNKNOWN ");
...@@ -1844,12 +1845,12 @@ int lock_may_read(struct inode *inode, loff_t start, unsigned long len) ...@@ -1844,12 +1845,12 @@ int lock_may_read(struct inode *inode, loff_t start, unsigned long len)
int result = 1; int result = 1;
lock_kernel(); lock_kernel();
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
if (fl->fl_flags == FL_POSIX) { if (IS_POSIX(fl)) {
if (fl->fl_type == F_RDLCK) if (fl->fl_type == F_RDLCK)
continue; continue;
if ((fl->fl_end < start) || (fl->fl_start > (start + len))) if ((fl->fl_end < start) || (fl->fl_start > (start + len)))
continue; continue;
} else if (fl->fl_flags == FL_FLOCK) { } else if (IS_FLOCK(fl)) {
if (!(fl->fl_type & LOCK_MAND)) if (!(fl->fl_type & LOCK_MAND))
continue; continue;
if (fl->fl_type & LOCK_READ) if (fl->fl_type & LOCK_READ)
...@@ -1882,10 +1883,10 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len) ...@@ -1882,10 +1883,10 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len)
int result = 1; int result = 1;
lock_kernel(); lock_kernel();
for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) { for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
if (fl->fl_flags == FL_POSIX) { if (IS_POSIX(fl)) {
if ((fl->fl_end < start) || (fl->fl_start > (start + len))) if ((fl->fl_end < start) || (fl->fl_start > (start + len)))
continue; continue;
} else if (fl->fl_flags == FL_FLOCK) { } else if (IS_FLOCK(fl)) {
if (!(fl->fl_type & LOCK_MAND)) if (!(fl->fl_type & LOCK_MAND))
continue; continue;
if (fl->fl_type & LOCK_WRITE) if (fl->fl_type & LOCK_WRITE)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment