diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-10-01 17:41:11 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@citi.umich.edu> | 2007-10-09 18:32:46 -0400 |
commit | a16877ca9cec211708a161057a7cbfbf2cbc3a53 (patch) | |
tree | a114bfe588af58047b1eb2aa1f57ac4b890c01a6 | |
parent | 98257af5a2ad0c5b502ebd07094d9fd8ce87acef (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>
-rw-r--r-- | fs/locks.c | 14 | ||||
-rw-r--r-- | fs/nfsd/nfs4state.c | 2 | ||||
-rw-r--r-- | fs/nfsd/vfs.c | 2 | ||||
-rw-r--r-- | fs/read_write.c | 2 | ||||
-rw-r--r-- | include/linux/fs.h | 21 |
5 files changed, 24 insertions, 17 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 "); |
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 3f559700788f..3c028b9c6e0e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
@@ -2044,7 +2044,7 @@ static inline int | |||
2044 | io_during_grace_disallowed(struct inode *inode, int flags) | 2044 | io_during_grace_disallowed(struct inode *inode, int flags) |
2045 | { | 2045 | { |
2046 | return nfs4_in_grace() && (flags & (RD_STATE | WR_STATE)) | 2046 | return nfs4_in_grace() && (flags & (RD_STATE | WR_STATE)) |
2047 | && MANDATORY_LOCK(inode); | 2047 | && mandatory_lock(inode); |
2048 | } | 2048 | } |
2049 | 2049 | ||
2050 | /* | 2050 | /* |
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index 7867151ebb83..9152f87eea18 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c | |||
@@ -65,7 +65,7 @@ | |||
65 | * locks on them because there is no way to know if the accesser has | 65 | * locks on them because there is no way to know if the accesser has |
66 | * the lock. | 66 | * the lock. |
67 | */ | 67 | */ |
68 | #define IS_ISMNDLK(i) (S_ISREG((i)->i_mode) && MANDATORY_LOCK(i)) | 68 | #define IS_ISMNDLK(i) (S_ISREG((i)->i_mode) && mandatory_lock(i)) |
69 | 69 | ||
70 | /* | 70 | /* |
71 | * This is a cache of readahead params that help us choose the proper | 71 | * This is a cache of readahead params that help us choose the proper |
diff --git a/fs/read_write.c b/fs/read_write.c index 507ddff48a9a..124693e8d3fa 100644 --- a/fs/read_write.c +++ b/fs/read_write.c | |||
@@ -205,7 +205,7 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count | |||
205 | if (unlikely((pos < 0) || (loff_t) (pos + count) < 0)) | 205 | if (unlikely((pos < 0) || (loff_t) (pos + count) < 0)) |
206 | goto Einval; | 206 | goto Einval; |
207 | 207 | ||
208 | if (unlikely(inode->i_flock && MANDATORY_LOCK(inode))) { | 208 | if (unlikely(inode->i_flock && mandatory_lock(inode))) { |
209 | int retval = locks_mandatory_area( | 209 | int retval = locks_mandatory_area( |
210 | read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE, | 210 | read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE, |
211 | inode, file, pos, count); | 211 | inode, file, pos, count); |
diff --git a/include/linux/fs.h b/include/linux/fs.h index 16421f662a7a..f5075e0e7301 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h | |||
@@ -1369,12 +1369,25 @@ extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size | |||
1369 | * Candidates for mandatory locking have the setgid bit set | 1369 | * Candidates for mandatory locking have the setgid bit set |
1370 | * but no group execute bit - an otherwise meaningless combination. | 1370 | * but no group execute bit - an otherwise meaningless combination. |
1371 | */ | 1371 | */ |
1372 | #define MANDATORY_LOCK(inode) \ | 1372 | |
1373 | (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) | 1373 | static inline int __mandatory_lock(struct inode *ino) |
1374 | { | ||
1375 | return (ino->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID; | ||
1376 | } | ||
1377 | |||
1378 | /* | ||
1379 | * ... and these candidates should be on MS_MANDLOCK mounted fs, | ||
1380 | * otherwise these will be advisory locks | ||
1381 | */ | ||
1382 | |||
1383 | static inline int mandatory_lock(struct inode *ino) | ||
1384 | { | ||
1385 | return IS_MANDLOCK(ino) && __mandatory_lock(ino); | ||
1386 | } | ||
1374 | 1387 | ||
1375 | static inline int locks_verify_locked(struct inode *inode) | 1388 | static inline int locks_verify_locked(struct inode *inode) |
1376 | { | 1389 | { |
1377 | if (MANDATORY_LOCK(inode)) | 1390 | if (mandatory_lock(inode)) |
1378 | return locks_mandatory_locked(inode); | 1391 | return locks_mandatory_locked(inode); |
1379 | return 0; | 1392 | return 0; |
1380 | } | 1393 | } |
@@ -1385,7 +1398,7 @@ static inline int locks_verify_truncate(struct inode *inode, | |||
1385 | struct file *filp, | 1398 | struct file *filp, |
1386 | loff_t size) | 1399 | loff_t size) |
1387 | { | 1400 | { |
1388 | if (inode->i_flock && MANDATORY_LOCK(inode)) | 1401 | if (inode->i_flock && mandatory_lock(inode)) |
1389 | return locks_mandatory_area( | 1402 | return locks_mandatory_area( |
1390 | FLOCK_VERIFY_WRITE, inode, filp, | 1403 | FLOCK_VERIFY_WRITE, inode, filp, |
1391 | size < inode->i_size ? size : inode->i_size, | 1404 | size < inode->i_size ? size : inode->i_size, |