Skip to content

Commit

Permalink
Merge branch 'locks' of git://linux-nfs.org/~bfields/linux
Browse files Browse the repository at this point in the history
* 'locks' of git://linux-nfs.org/~bfields/linux:
  nfsd: remove IS_ISMNDLCK macro
  Rework /proc/locks via seq_files and seq_list helpers
  fs/locks.c: use list_for_each_entry() instead of list_for_each()
  NFS: clean up explicit check for mandatory locks
  AFS: clean up explicit check for mandatory locks
  9PFS: clean up explicit check for mandatory locks
  GFS2: clean up explicit check for mandatory locks
  Cleanup macros for distinguishing mandatory locks
  Documentation: move locks.txt in filesystems/
  locks: add warning about mandatory locking races
  Documentation: move mandatory locking documentation to filesystems/
  locks: Fix potential OOPS in generic_setlease()
  Use list_first_entry in locks_wake_up_blocks
  locks: fix flock_lock_file() comment
  Memory shortage can result in inconsistent flocks state
  locks: kill redundant local variable
  locks: reverse order of posix_locks_conflict() arguments
  • Loading branch information
Linus Torvalds committed Oct 15, 2007
2 parents e457f79 + 5e7fc43 commit 541010e
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 146 deletions.
6 changes: 1 addition & 5 deletions Documentation/00-INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fb/
feature-removal-schedule.txt
- list of files and features that are going to be removed.
filesystems/
- directory with info on the various filesystems that Linux supports.
- info on the vfs and the various filesystems that Linux supports.
firmware_class/
- request_firmware() hotplug interface info.
floppy.txt
Expand Down Expand Up @@ -230,8 +230,6 @@ local_ops.txt
- semantics and behavior of local atomic operations.
lockdep-design.txt
- documentation on the runtime locking correctness validator.
locks.txt
- info on file locking implementations, flock() vs. fcntl(), etc.
logo.gif
- full colour GIF image of Linux logo (penguin - Tux).
logo.txt
Expand All @@ -240,8 +238,6 @@ m68k/
- directory with info about Linux on Motorola 68k architecture.
magic-number.txt
- list of magic numbers used to mark/protect kernel data structures.
mandatory.txt
- info on the Linux implementation of Sys V mandatory file locking.
mca.txt
- info on supporting Micro Channel Architecture (e.g. PS/2) systems.
md.txt
Expand Down
4 changes: 4 additions & 0 deletions Documentation/filesystems/00-INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ isofs.txt
- info and mount options for the ISO 9660 (CDROM) filesystem.
jfs.txt
- info and mount options for the JFS filesystem.
locks.txt
- info on file locking implementations, flock() vs. fcntl(), etc.
mandatory-locking.txt
- info on the Linux implementation of Sys V mandatory file locking.
ncpfs.txt
- info on Novell Netware(tm) filesystem using NCP protocol.
ntfs.txt
Expand Down
10 changes: 5 additions & 5 deletions Documentation/locks.txt → Documentation/filesystems/locks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ fcntl(), with all the problems that implies.
1.3 Mandatory Locking As A Mount Option
---------------------------------------

Mandatory locking, as described in 'Documentation/mandatory.txt' was prior
to this release a general configuration option that was valid for all
mounted filesystems. This had a number of inherent dangers, not the least
of which was the ability to freeze an NFS server by asking it to read a
file for which a mandatory lock existed.
Mandatory locking, as described in 'Documentation/filesystems/mandatory.txt'
was prior to this release a general configuration option that was valid for
all mounted filesystems. This had a number of inherent dangers, not the
least of which was the ability to freeze an NFS server by asking it to read
a file for which a mandatory lock existed.

From this release of the kernel, mandatory locking can be turned on and off
on a per-filesystem basis, using the mount options 'mand' and 'nomand'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@
Andy Walker <andy@lysaker.kvaerner.no>

15 April 1996

(Updated September 2007)

0. Why you should avoid mandatory locking
-----------------------------------------

The Linux implementation is prey to a number of difficult-to-fix race
conditions which in practice make it not dependable:

- The write system call checks for a mandatory lock only once
at its start. It is therefore possible for a lock request to
be granted after this check but before the data is modified.
A process may then see file data change even while a mandatory
lock was held.
- Similarly, an exclusive lock may be granted on a file after
the kernel has decided to proceed with a read, but before the
read has actually completed, and the reading process may see
the file data in a state which should not have been visible
to it.
- Similar races make the claimed mutual exclusion between lock
and mmap similarly unreliable.

1. What is mandatory locking?
------------------------------
Expand Down
2 changes: 1 addition & 1 deletion fs/9p/vfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
P9_DPRINTK(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);

/* No mandatory locks */
if ((inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
if (__mandatory_lock(inode))
return -ENOLCK;

if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
Expand Down
3 changes: 1 addition & 2 deletions fs/afs/flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@ int afs_lock(struct file *file, int cmd, struct file_lock *fl)
(long long) fl->fl_start, (long long) fl->fl_end);

/* AFS doesn't support mandatory locks */
if ((vnode->vfs_inode.i_mode & (S_ISGID | S_IXGRP)) == S_ISGID &&
fl->fl_type != F_UNLCK)
if (__mandatory_lock(&vnode->vfs_inode) && fl->fl_type != F_UNLCK)
return -ENOLCK;

if (IS_GETLK(cmd))
Expand Down
4 changes: 2 additions & 2 deletions fs/gfs2/ops_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)

if (!(fl->fl_flags & FL_POSIX))
return -ENOLCK;
if ((ip->i_inode.i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
if (__mandatory_lock(&ip->i_inode))
return -ENOLCK;

if (sdp->sd_args.ar_localflocks) {
Expand Down Expand Up @@ -636,7 +636,7 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)

if (!(fl->fl_flags & FL_FLOCK))
return -ENOLCK;
if ((ip->i_inode.i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
if (__mandatory_lock(&ip->i_inode))
return -ENOLCK;

if (sdp->sd_args.ar_localflocks)
Expand Down
Loading

0 comments on commit 541010e

Please sign in to comment.