Skip to content

Commit

Permalink
fs: remove mandatory file locking support
Browse files Browse the repository at this point in the history
We added CONFIG_MANDATORY_FILE_LOCKING in 2015, and soon after turned it
off in Fedora and RHEL8. Several other distros have followed suit.

I've heard of one problem in all that time: Someone migrated from an
older distro that supported "-o mand" to one that didn't, and the host
had a fstab entry with "mand" in it which broke on reboot. They didn't
actually _use_ mandatory locking so they just removed the mount option
and moved on.

This patch rips out mandatory locking support wholesale from the kernel,
along with the Kconfig option and the Documentation file. It also
changes the mount code to ignore the "mand" mount option instead of
erroring out, and to throw a big, ugly warning.

Signed-off-by: Jeff Layton <[email protected]>
  • Loading branch information
jtlayton committed Aug 23, 2021
1 parent 2f488f6 commit f7e33bd
Show file tree
Hide file tree
Showing 19 changed files with 15 additions and 521 deletions.
188 changes: 0 additions & 188 deletions Documentation/filesystems/mandatory-locking.rst

This file was deleted.

13 changes: 0 additions & 13 deletions fs/9p/vfs_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)

p9_debug(P9_DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);

/* No mandatory locks */
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
return -ENOLCK;

if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
filemap_write_and_wait(inode->i_mapping);
invalidate_mapping_pages(&inode->i_data, 0, -1);
Expand Down Expand Up @@ -312,10 +308,6 @@ static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl)
p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
filp, cmd, fl, filp);

/* No mandatory locks */
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
goto out_err;

if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
filemap_write_and_wait(inode->i_mapping);
invalidate_mapping_pages(&inode->i_data, 0, -1);
Expand All @@ -327,7 +319,6 @@ static int v9fs_file_lock_dotl(struct file *filp, int cmd, struct file_lock *fl)
ret = v9fs_file_getlock(filp, fl);
else
ret = -EINVAL;
out_err:
return ret;
}

Expand All @@ -348,10 +339,6 @@ static int v9fs_file_flock_dotl(struct file *filp, int cmd,
p9_debug(P9_DEBUG_VFS, "filp: %p cmd:%d lock: %p name: %pD\n",
filp, cmd, fl, filp);

/* No mandatory locks */
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
goto out_err;

if (!(fl->fl_flags & FL_FLOCK))
goto out_err;

Expand Down
10 changes: 0 additions & 10 deletions fs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ config FILE_LOCKING
for filesystems like NFS and for the flock() system
call. Disabling this option saves about 11k.

config MANDATORY_FILE_LOCKING
bool "Enable Mandatory file locking"
depends on FILE_LOCKING
default y
help
This option enables files appropriately marked files on appropriely
mounted filesystems to support mandatory locking.

To the best of my knowledge this is dead code that no one cares about.

source "fs/crypto/Kconfig"

source "fs/verity/Kconfig"
Expand Down
4 changes: 0 additions & 4 deletions fs/afs/flock.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,6 @@ int afs_lock(struct file *file, int cmd, struct file_lock *fl)
fl->fl_type, fl->fl_flags,
(long long) fl->fl_start, (long long) fl->fl_end);

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

if (IS_GETLK(cmd))
return afs_do_getlk(file, fl);

Expand Down
3 changes: 0 additions & 3 deletions fs/ceph/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)

if (!(fl->fl_flags & FL_POSIX))
return -ENOLCK;
/* No mandatory locks */
if (__mandatory_lock(file->f_mapping->host) && fl->fl_type != F_UNLCK)
return -ENOLCK;

dout("ceph_lock, fl_owner: %p\n", fl->fl_owner);

Expand Down
3 changes: 0 additions & 3 deletions fs/gfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,9 +1237,6 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)

if (!(fl->fl_flags & FL_POSIX))
return -ENOLCK;
if (__mandatory_lock(&ip->i_inode) && fl->fl_type != F_UNLCK)
return -ENOLCK;

if (cmd == F_CANCELLK) {
/* Hack: */
cmd = F_SETLK;
Expand Down
Loading

0 comments on commit f7e33bd

Please sign in to comment.