Skip to content

Commit 7e46361

Browse files
committed
Merge patch series "vfs: require filesystems to explicitly opt-in to lease support"
Jeff Layton <jlayton@kernel.org> says: Yesterday, I sent patches to fix how directory delegation support is handled on filesystems where the should be disabled [1]. That set is appropriate for v6.19. For v7.0, I want to make lease support be more opt-in, rather than opt-out: For historical reasons, when ->setlease() file_operation is set to NULL, the default is to use the kernel-internal lease implementation. This means that if you want to disable them, you need to explicitly set the ->setlease() file_operation to simple_nosetlease() or the equivalent. This has caused a number of problems over the years as some filesystems have inadvertantly allowed leases to be acquired simply by having left it set to NULL. It would be better if filesystems had to opt-in to lease support, particularly with the advent of directory delegations. This series has sets the ->setlease() operation in a pile of existing local filesystems to generic_setlease() and then changes kernel_setlease() to return -EINVAL when the setlease() operation is not set. With this change, new filesystems will need to explicitly set the ->setlease() operations in order to provide lease and delegation support. I mainly focused on filesystems that are NFS exportable, since NFS and SMB are the main users of file leases, and they tend to end up exporting the same filesystem types. Let me know if I've missed any. [1]: https://lore.kernel.org/linux-fsdevel/20260107-setlease-6-19-v1-0-85f034abcc57@kernel.org/ * patches from https://patch.msgid.link/20260108-setlease-6-20-v1-0-ea4dec9b67fa@kernel.org: (24 commits) fs: remove simple_nosetlease() filelock: default to returning -EINVAL when ->setlease operation is NULL xfs: add setlease file operation ufs: add setlease file operation udf: add setlease file operation tmpfs: add setlease file operation squashfs: add setlease file operation overlayfs: add setlease file operation orangefs: add setlease file operation ocfs2: add setlease file operation ntfs3: add setlease file operation nilfs2: add setlease file operation jfs: add setlease file operation jffs2: add setlease file operation gfs2: add a setlease file operation fat: add setlease file operation f2fs: add setlease file operation exfat: add setlease file operation ext4: add setlease file operation ext2: add setlease file operation ... Link: https://patch.msgid.link/20260108-setlease-6-20-v1-0-ea4dec9b67fa@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
2 parents 7d42f2b + 51e4911 commit 7e46361

File tree

61 files changed

+116
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+116
-42
lines changed

Documentation/filesystems/porting.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,3 +1334,12 @@ end_creating() and the parent will be unlocked precisely when necessary.
13341334

13351335
kill_litter_super() is gone; convert to DCACHE_PERSISTENT use (as all
13361336
in-tree filesystems have done).
1337+
1338+
---
1339+
1340+
**mandatory**
1341+
1342+
The ->setlease() file_operation must now be explicitly set in order to provide
1343+
support for leases. When set to NULL, the kernel will now return -EINVAL to
1344+
attempts to set a lease. Filesystems that wish to use the kernel-internal lease
1345+
implementation should set it to generic_setlease().

Documentation/filesystems/vfs.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,12 @@ otherwise noted.
11801180
method is used by the splice(2) system call
11811181

11821182
``setlease``
1183-
called by the VFS to set or release a file lock lease. setlease
1184-
implementations should call generic_setlease to record or remove
1185-
the lease in the inode after setting it.
1183+
called by the VFS to set or release a file lock lease. Local
1184+
filesystems that wish to use the kernel-internal lease implementation
1185+
should set this to generic_setlease(). Other setlease implementations
1186+
should call generic_setlease() to record or remove the lease in the inode
1187+
after setting it. When set to NULL, attempts to set or remove a lease will
1188+
return -EINVAL.
11861189

11871190
``fallocate``
11881191
called by the VFS to preallocate blocks or punch a hole.

fs/9p/vfs_dir.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ const struct file_operations v9fs_dir_operations = {
242242
.iterate_shared = v9fs_dir_readdir,
243243
.open = v9fs_file_open,
244244
.release = v9fs_dir_release,
245-
.setlease = simple_nosetlease,
246245
};
247246

248247
const struct file_operations v9fs_dir_operations_dotl = {
@@ -252,5 +251,4 @@ const struct file_operations v9fs_dir_operations_dotl = {
252251
.open = v9fs_file_open,
253252
.release = v9fs_dir_release,
254253
.fsync = v9fs_file_fsync_dotl,
255-
.setlease = simple_nosetlease,
256254
};

fs/9p/vfs_file.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ const struct file_operations v9fs_file_operations = {
517517
.splice_read = v9fs_file_splice_read,
518518
.splice_write = iter_file_splice_write,
519519
.fsync = v9fs_file_fsync,
520-
.setlease = simple_nosetlease,
521520
};
522521

523522
const struct file_operations v9fs_file_operations_dotl = {
@@ -532,5 +531,4 @@ const struct file_operations v9fs_file_operations_dotl = {
532531
.splice_read = v9fs_file_splice_read,
533532
.splice_write = iter_file_splice_write,
534533
.fsync = v9fs_file_fsync_dotl,
535-
.setlease = simple_nosetlease,
536534
};

fs/affs/dir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include <linux/iversion.h>
18+
#include <linux/filelock.h>
1819
#include "affs.h"
1920

2021
struct affs_dir_data {
@@ -55,6 +56,7 @@ const struct file_operations affs_dir_operations = {
5556
.iterate_shared = affs_readdir,
5657
.fsync = affs_file_fsync,
5758
.release = affs_dir_release,
59+
.setlease = generic_setlease,
5860
};
5961

6062
/*

fs/affs/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <linux/uio.h>
1717
#include <linux/blkdev.h>
18+
#include <linux/filelock.h>
1819
#include <linux/mpage.h>
1920
#include "affs.h"
2021

@@ -1008,6 +1009,7 @@ const struct file_operations affs_file_operations = {
10081009
.release = affs_file_release,
10091010
.fsync = affs_file_fsync,
10101011
.splice_read = filemap_splice_read,
1012+
.setlease = generic_setlease,
10111013
};
10121014

10131015
const struct inode_operations affs_file_inode_operations = {

fs/befs/linuxvfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/fs_context.h>
1515
#include <linux/fs_parser.h>
1616
#include <linux/errno.h>
17+
#include <linux/filelock.h>
1718
#include <linux/stat.h>
1819
#include <linux/nls.h>
1920
#include <linux/buffer_head.h>
@@ -79,6 +80,7 @@ static const struct file_operations befs_dir_operations = {
7980
.read = generic_read_dir,
8081
.iterate_shared = befs_readdir,
8182
.llseek = generic_file_llseek,
83+
.setlease = generic_setlease,
8284
};
8385

8486
static const struct inode_operations befs_dir_inode_operations = {

fs/btrfs/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/string.h>
1111
#include <linux/backing-dev.h>
1212
#include <linux/falloc.h>
13+
#include <linux/filelock.h>
1314
#include <linux/writeback.h>
1415
#include <linux/compat.h>
1516
#include <linux/slab.h>
@@ -3867,6 +3868,7 @@ const struct file_operations btrfs_file_operations = {
38673868
.remap_file_range = btrfs_remap_file_range,
38683869
.uring_cmd = btrfs_uring_cmd,
38693870
.fop_flags = FOP_BUFFER_RASYNC | FOP_BUFFER_WASYNC,
3871+
.setlease = generic_setlease,
38703872
};
38713873

38723874
int btrfs_fdatawrite_range(struct btrfs_inode *inode, loff_t start, loff_t end)

fs/btrfs/inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/bio.h>
99
#include <linux/blk-cgroup.h>
1010
#include <linux/file.h>
11+
#include <linux/filelock.h>
1112
#include <linux/fs.h>
1213
#include <linux/fs_struct.h>
1314
#include <linux/pagemap.h>
@@ -10596,6 +10597,7 @@ static const struct file_operations btrfs_dir_file_operations = {
1059610597
#endif
1059710598
.release = btrfs_release_file,
1059810599
.fsync = btrfs_sync_file,
10600+
.setlease = generic_setlease,
1059910601
};
1060010602

1060110603
/*

fs/ceph/dir.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,15 +2214,13 @@ const struct file_operations ceph_dir_fops = {
22142214
.fsync = ceph_fsync,
22152215
.lock = ceph_lock,
22162216
.flock = ceph_flock,
2217-
.setlease = simple_nosetlease,
22182217
};
22192218

22202219
const struct file_operations ceph_snapdir_fops = {
22212220
.iterate_shared = shared_ceph_readdir,
22222221
.llseek = ceph_dir_llseek,
22232222
.open = ceph_open,
22242223
.release = ceph_release,
2225-
.setlease = simple_nosetlease,
22262224
};
22272225

22282226
const struct inode_operations ceph_dir_iops = {

0 commit comments

Comments
 (0)