aboutsummaryrefslogtreecommitdiffstats
path: root/fs/locks.c
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-10-01 17:41:11 -0400
committerJ. Bruce Fields <bfields@citi.umich.edu>2007-10-09 18:32:46 -0400
commita16877ca9cec211708a161057a7cbfbf2cbc3a53 (patch)
treea114bfe588af58047b1eb2aa1f57ac4b890c01a6 /fs/locks.c
parent98257af5a2ad0c5b502ebd07094d9fd8ce87acef (diff)
Cleanup macros for distinguishing mandatory locks
The combination of S_ISGID bit set and S_IXGRP bit unset is used to mark the inode as "mandatory lockable" and there's a macro for this check called MANDATORY_LOCK(inode). However, fs/locks.c and some filesystems still perform the explicit i_mode checking. Besides, Andrew pointed out, that this macro is buggy itself, as it dereferences the inode arg twice. Convert this macro into static inline function and switch its users to it, making the code shorter and more readable. The __mandatory_lock() helper is to be used in places where the IS_MANDLOCK() for superblock is already known to be true. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Cc: Trond Myklebust <trond.myklebust@fys.uio.no> Cc: "J. Bruce Fields" <bfields@fieldses.org> Cc: David Howells <dhowells@redhat.com> Cc: Eric Van Hensbergen <ericvh@gmail.com> Cc: Ron Minnich <rminnich@sandia.gov> Cc: Latchesar Ionkov <lucho@ionkov.net> Cc: Steven Whitehouse <swhiteho@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'fs/locks.c')
-rw-r--r--fs/locks.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/fs/locks.c b/fs/locks.c
index 43dbc7f566fa..9a3fe0d8285b 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1119,7 +1119,7 @@ int locks_mandatory_area(int read_write, struct inode *inode,
1119 * If we've been sleeping someone might have 1119 * If we've been sleeping someone might have
1120 * changed the permissions behind our back. 1120 * changed the permissions behind our back.
1121 */ 1121 */
1122 if ((inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) 1122 if (__mandatory_lock(inode))
1123 continue; 1123 continue;
1124 } 1124 }
1125 1125
@@ -1761,9 +1761,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
1761 /* Don't allow mandatory locks on files that may be memory mapped 1761 /* Don't allow mandatory locks on files that may be memory mapped
1762 * and shared. 1762 * and shared.
1763 */ 1763 */
1764 if (IS_MANDLOCK(inode) && 1764 if (mandatory_lock(inode) && mapping_writably_mapped(filp->f_mapping)) {
1765 (inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID &&
1766 mapping_writably_mapped(filp->f_mapping)) {
1767 error = -EAGAIN; 1765 error = -EAGAIN;
1768 goto out; 1766 goto out;
1769 } 1767 }
@@ -1887,9 +1885,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
1887 /* Don't allow mandatory locks on files that may be memory mapped 1885 /* Don't allow mandatory locks on files that may be memory mapped
1888 * and shared. 1886 * and shared.
1889 */ 1887 */
1890 if (IS_MANDLOCK(inode) && 1888 if (mandatory_lock(inode) && mapping_writably_mapped(filp->f_mapping)) {
1891 (inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID &&
1892 mapping_writably_mapped(filp->f_mapping)) {
1893 error = -EAGAIN; 1889 error = -EAGAIN;
1894 goto out; 1890 goto out;
1895 } 1891 }
@@ -2083,9 +2079,7 @@ static void lock_get_status(char* out, struct file_lock *fl, int id, char *pfx)
2083 out += sprintf(out, "%6s %s ", 2079 out += sprintf(out, "%6s %s ",
2084 (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ", 2080 (fl->fl_flags & FL_ACCESS) ? "ACCESS" : "POSIX ",
2085 (inode == NULL) ? "*NOINODE*" : 2081 (inode == NULL) ? "*NOINODE*" :
2086 (IS_MANDLOCK(inode) && 2082 mandatory_lock(inode) ? "MANDATORY" : "ADVISORY ");
2087 (inode->i_mode & (S_IXGRP | S_ISGID)) == S_ISGID) ?
2088 "MANDATORY" : "ADVISORY ");
2089 } else if (IS_FLOCK(fl)) { 2083 } else if (IS_FLOCK(fl)) {
2090 if (fl->fl_type & LOCK_MAND) { 2084 if (fl->fl_type & LOCK_MAND) {
2091 out += sprintf(out, "FLOCK MSNFS "); 2085 out += sprintf(out, "FLOCK MSNFS ");