]> git.hungrycats.org Git - linux/commitdiff
[PATCH] fs/locks.c: add and use IS_{POSIX, FLOCK, LEASE} macros
authorStephen Rothwell <sfr@canb.auug.org.au>
Thu, 6 Jun 2002 02:26:57 +0000 (19:26 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Thu, 6 Jun 2002 02:26:57 +0000 (19:26 -0700)
Another trivial part of a Matthew Wilcox patch.  This just
defines macros for distinguishing the differnet types of locks.

fs/locks.c

index 93776fd4b4ae8b147b73f58b856d5b2407017308..bfaf05a2c18a2b750ce9d0320a81dc56de39ab46 100644 (file)
 #include <asm/semaphore.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 lease_break_time = 45;
 
@@ -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
         * each other.
         */
-       if (!(sys_fl->fl_flags & FL_POSIX) ||
-           locks_same_owner(caller_fl, sys_fl))
+       if (!IS_POSIX(sys_fl) || locks_same_owner(caller_fl, sys_fl))
                return (0);
 
        /* Check whether they overlap */
@@ -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
         * each other.
         */
-       if (!(sys_fl->fl_flags & FL_FLOCK) ||
-           (caller_fl->fl_file == sys_fl->fl_file))
+       if (!IS_FLOCK(sys_fl) || (caller_fl->fl_file == sys_fl->fl_file))
                return (0);
 #ifdef MSNFS
        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)
 
        lock_kernel();
        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;
                if (posix_locks_conflict(cfl, fl))
                        break;
@@ -696,7 +698,7 @@ int locks_mandatory_locked(struct inode *inode)
         */
        lock_kernel();
        for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
-               if (!(fl->fl_flags & FL_POSIX))
+               if (!IS_POSIX(fl))
                        continue;
                if (fl->fl_owner != owner)
                        break;
@@ -732,7 +734,7 @@ repeat:
         * the proposed read/write.
         */
        for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
-               if (!(fl->fl_flags & FL_POSIX))
+               if (!IS_POSIX(fl))
                        continue;
                if (fl->fl_start > new_fl->fl_end)
                        break;
@@ -790,7 +792,7 @@ static int flock_lock_file(struct file *filp, unsigned int lock_type,
 search:
        change = 0;
        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 (lock_type == fl->fl_type)
                                goto out;
@@ -815,7 +817,7 @@ search:
                goto out;
 
 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) {
                if (!flock_locks_conflict(new_fl, fl))
                        continue;
@@ -880,7 +882,7 @@ int posix_lock_file(struct file *filp, struct file_lock *caller,
        if (caller->fl_type != F_UNLCK) {
   repeat:
                for (fl = inode->i_flock; fl != NULL; fl = fl->fl_next) {
-                       if (!(fl->fl_flags & FL_POSIX))
+                       if (!IS_POSIX(fl))
                                continue;
                        if (!posix_locks_conflict(caller, fl))
                                continue;
@@ -909,7 +911,7 @@ int posix_lock_file(struct file *filp, struct file_lock *caller,
 
        /* 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))) {
                before = &fl->fl_next;
        }
@@ -1085,7 +1087,7 @@ int __get_lease(struct inode *inode, unsigned int mode)
                        if (error != 0)
                                goto out;
                        flock = inode->i_flock;
-                       if (!(flock && (flock->fl_flags & FL_LEASE)))
+                       if (!(flock && IS_LEASE(flock)))
                                goto out;
                } while (flock->fl_type & F_INPROGRESS);
        }
@@ -1110,7 +1112,7 @@ int __get_lease(struct inode *inode, unsigned int mode)
        do {
                fl->fl_type = future;
                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);
 
@@ -1131,7 +1133,7 @@ restart:
                printk(KERN_WARNING "lease timed out\n");
        } else if (error > 0) {
                flock = inode->i_flock;
-               if (flock && (flock->fl_flags & FL_LEASE))
+               if (flock && IS_LEASE(flock))
                        goto restart;
                error = 0;
        }
@@ -1154,7 +1156,7 @@ out:
 time_t lease_get_mtime(struct inode *inode)
 {
        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 inode->i_mtime;
 }
@@ -1177,7 +1179,7 @@ int fcntl_getlease(struct file *filp)
        struct file_lock *fl;
        
        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 fl->fl_type & ~F_INPROGRESS;
 }
@@ -1243,7 +1245,7 @@ int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
        lock_kernel();
 
        while ((fl = *before) != NULL) {
-               if (fl->fl_flags != FL_LEASE)
+               if (!IS_LEASE(fl))
                        break;
                if (fl->fl_file == filp)
                        my_before = before;
@@ -1646,7 +1648,7 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)
        lock_kernel();
        before = &inode->i_flock;
        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);
                        before = &inode->i_flock;
                        continue;
@@ -1672,8 +1674,7 @@ void locks_remove_flock(struct file *filp)
        before = &inode->i_flock;
 
        while ((fl = *before) != NULL) {
-               if ((fl->fl_flags & (FL_FLOCK|FL_LEASE))
-                   && (fl->fl_file == filp)) {
+               if ((IS_FLOCK(fl) || IS_LEASE(fl)) && (fl->fl_file == filp)) {
                        locks_delete_lock(before, 0);
                        continue;
                }
@@ -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;
 
        out += sprintf(out, "%d:%s ", id, pfx);
-       if (fl->fl_flags & FL_POSIX) {
+       if (IS_POSIX(fl)) {
                out += sprintf(out, "%6s %s ",
                             (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ",
                             (inode == NULL) ? "*NOINODE*" :
                             (IS_MANDLOCK(inode) &&
                              (inode->i_mode & (S_IXGRP | S_ISGID)) == S_ISGID) ?
                             "MANDATORY" : "ADVISORY ");
-       } else if (fl->fl_flags & FL_FLOCK) {
+       } else if (IS_FLOCK(fl)) {
 #ifdef MSNFS
                if (fl->fl_type & LOCK_MAND) {
                        out += sprintf(out, "FLOCK  MSNFS     ");
                } else
 #endif
                        out += sprintf(out, "FLOCK  ADVISORY  ");
-       } else if (fl->fl_flags & FL_LEASE) {
+       } else if (IS_LEASE(fl)) {
                out += sprintf(out, "LEASE  MANDATORY ");
        } else {
                out += sprintf(out, "UNKNOWN UNKNOWN  ");
@@ -1844,12 +1845,12 @@ int lock_may_read(struct inode *inode, loff_t start, unsigned long len)
        int result = 1;
        lock_kernel();
        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)
                                continue;
                        if ((fl->fl_end < start) || (fl->fl_start > (start + len)))
                                continue;
-               } else if (fl->fl_flags == FL_FLOCK) {
+               } else if (IS_FLOCK(fl)) {
                        if (!(fl->fl_type & LOCK_MAND))
                                continue;
                        if (fl->fl_type & LOCK_READ)
@@ -1882,10 +1883,10 @@ int lock_may_write(struct inode *inode, loff_t start, unsigned long len)
        int result = 1;
        lock_kernel();
        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)))
                                continue;
-               } else if (fl->fl_flags == FL_FLOCK) {
+               } else if (IS_FLOCK(fl)) {
                        if (!(fl->fl_type & LOCK_MAND))
                                continue;
                        if (fl->fl_type & LOCK_WRITE)