Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

filelock: move file locking definitions to separate header file

The file locking definitions have lived in fs.h since the dawn of time,
but they are only used by a small subset of the source files that
include it.

Move the file locking definitions to a new header file, and add the
appropriate #include directives to the source files that need them. By
doing this we trim down fs.h a bit and limit the amount of rebuilding
that has to be done when we make changes to the file locking APIs.

Reviewed-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: David Howells <dhowells@redhat.com>
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Acked-by: Chuck Lever <chuck.lever@oracle.com>
Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Acked-by: Steve French <stfrench@microsoft.com>
Acked-by: Al Viro <viro@zeniv.linux.org.uk>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Jeff Layton <jlayton@kernel.org>

+481 -429
+1
arch/arm/kernel/sys_oabi-compat.c
··· 73 73 #include <linux/syscalls.h> 74 74 #include <linux/errno.h> 75 75 #include <linux/fs.h> 76 + #include <linux/filelock.h> 76 77 #include <linux/cred.h> 77 78 #include <linux/fcntl.h> 78 79 #include <linux/eventpoll.h>
+1
fs/9p/vfs_file.c
··· 9 9 #include <linux/module.h> 10 10 #include <linux/errno.h> 11 11 #include <linux/fs.h> 12 + #include <linux/filelock.h> 12 13 #include <linux/sched.h> 13 14 #include <linux/file.h> 14 15 #include <linux/stat.h>
+1
fs/afs/internal.h
··· 9 9 #include <linux/kernel.h> 10 10 #include <linux/ktime.h> 11 11 #include <linux/fs.h> 12 + #include <linux/filelock.h> 12 13 #include <linux/pagemap.h> 13 14 #include <linux/rxrpc.h> 14 15 #include <linux/key.h>
+1
fs/attr.c
··· 14 14 #include <linux/capability.h> 15 15 #include <linux/fsnotify.h> 16 16 #include <linux/fcntl.h> 17 + #include <linux/filelock.h> 17 18 #include <linux/security.h> 18 19 #include <linux/evm.h> 19 20 #include <linux/ima.h>
+1
fs/ceph/caps.c
··· 9 9 #include <linux/wait.h> 10 10 #include <linux/writeback.h> 11 11 #include <linux/iversion.h> 12 + #include <linux/filelock.h> 12 13 13 14 #include "super.h" 14 15 #include "mds_client.h"
+1
fs/ceph/locks.c
··· 7 7 8 8 #include "super.h" 9 9 #include "mds_client.h" 10 + #include <linux/filelock.h> 10 11 #include <linux/ceph/pagelist.h> 11 12 12 13 static u64 lock_secret;
+1
fs/cifs/cifsfs.c
··· 12 12 13 13 #include <linux/module.h> 14 14 #include <linux/fs.h> 15 + #include <linux/filelock.h> 15 16 #include <linux/mount.h> 16 17 #include <linux/slab.h> 17 18 #include <linux/init.h>
+1
fs/cifs/cifsglob.h
··· 26 26 #include <uapi/linux/cifs/cifs_mount.h> 27 27 #include "../smbfs_common/smb2pdu.h" 28 28 #include "smb2pdu.h" 29 + #include <linux/filelock.h> 29 30 30 31 #define SMB_PATH_MAX 260 31 32 #define CIFS_PORT 445
+1
fs/cifs/cifssmb.c
··· 15 15 /* want to reuse a stale file handle and only the caller knows the file info */ 16 16 17 17 #include <linux/fs.h> 18 + #include <linux/filelock.h> 18 19 #include <linux/kernel.h> 19 20 #include <linux/vfs.h> 20 21 #include <linux/slab.h>
+1
fs/cifs/file.c
··· 9 9 * 10 10 */ 11 11 #include <linux/fs.h> 12 + #include <linux/filelock.h> 12 13 #include <linux/backing-dev.h> 13 14 #include <linux/stat.h> 14 15 #include <linux/fcntl.h>
+1
fs/cifs/smb2file.c
··· 7 7 * 8 8 */ 9 9 #include <linux/fs.h> 10 + #include <linux/filelock.h> 10 11 #include <linux/stat.h> 11 12 #include <linux/slab.h> 12 13 #include <linux/pagemap.h>
+1
fs/dlm/plock.c
··· 4 4 */ 5 5 6 6 #include <linux/fs.h> 7 + #include <linux/filelock.h> 7 8 #include <linux/miscdevice.h> 8 9 #include <linux/poll.h> 9 10 #include <linux/dlm.h>
+1
fs/fcntl.c
··· 10 10 #include <linux/mm.h> 11 11 #include <linux/sched/task.h> 12 12 #include <linux/fs.h> 13 + #include <linux/filelock.h> 13 14 #include <linux/file.h> 14 15 #include <linux/fdtable.h> 15 16 #include <linux/capability.h>
+1
fs/file_table.c
··· 13 13 #include <linux/init.h> 14 14 #include <linux/module.h> 15 15 #include <linux/fs.h> 16 + #include <linux/filelock.h> 16 17 #include <linux/security.h> 17 18 #include <linux/cred.h> 18 19 #include <linux/eventpoll.h>
+1
fs/fuse/file.c
··· 18 18 #include <linux/falloc.h> 19 19 #include <linux/uio.h> 20 20 #include <linux/fs.h> 21 + #include <linux/filelock.h> 21 22 22 23 static int fuse_send_open(struct fuse_mount *fm, u64 nodeid, 23 24 unsigned int open_flags, int opcode,
+1
fs/gfs2/file.c
··· 15 15 #include <linux/mm.h> 16 16 #include <linux/mount.h> 17 17 #include <linux/fs.h> 18 + #include <linux/filelock.h> 18 19 #include <linux/gfs2_ondisk.h> 19 20 #include <linux/falloc.h> 20 21 #include <linux/swap.h>
+1
fs/inode.c
··· 5 5 */ 6 6 #include <linux/export.h> 7 7 #include <linux/fs.h> 8 + #include <linux/filelock.h> 8 9 #include <linux/mm.h> 9 10 #include <linux/backing-dev.h> 10 11 #include <linux/hash.h>
+1
fs/ksmbd/smb2pdu.c
··· 12 12 #include <linux/ethtool.h> 13 13 #include <linux/falloc.h> 14 14 #include <linux/mount.h> 15 + #include <linux/filelock.h> 15 16 16 17 #include "glob.h" 17 18 #include "smbfsctl.h"
+1
fs/ksmbd/vfs.c
··· 6 6 7 7 #include <linux/kernel.h> 8 8 #include <linux/fs.h> 9 + #include <linux/filelock.h> 9 10 #include <linux/uaccess.h> 10 11 #include <linux/backing-dev.h> 11 12 #include <linux/writeback.h>
+1
fs/ksmbd/vfs_cache.c
··· 5 5 */ 6 6 7 7 #include <linux/fs.h> 8 + #include <linux/filelock.h> 8 9 #include <linux/slab.h> 9 10 #include <linux/vmalloc.h> 10 11
+1
fs/lockd/clntproc.c
··· 12 12 #include <linux/types.h> 13 13 #include <linux/errno.h> 14 14 #include <linux/fs.h> 15 + #include <linux/filelock.h> 15 16 #include <linux/nfs_fs.h> 16 17 #include <linux/utsname.h> 17 18 #include <linux/freezer.h>
+1
fs/lockd/netns.h
··· 3 3 #define __LOCKD_NETNS_H__ 4 4 5 5 #include <linux/fs.h> 6 + #include <linux/filelock.h> 6 7 #include <net/netns/generic.h> 7 8 8 9 struct lockd_net {
+1
fs/locks.c
··· 52 52 #include <linux/capability.h> 53 53 #include <linux/file.h> 54 54 #include <linux/fdtable.h> 55 + #include <linux/filelock.h> 55 56 #include <linux/fs.h> 56 57 #include <linux/init.h> 57 58 #include <linux/security.h>
+1
fs/namei.c
··· 20 20 #include <linux/kernel.h> 21 21 #include <linux/slab.h> 22 22 #include <linux/fs.h> 23 + #include <linux/filelock.h> 23 24 #include <linux/namei.h> 24 25 #include <linux/pagemap.h> 25 26 #include <linux/sched/mm.h>
+1
fs/nfs/file.c
··· 31 31 #include <linux/swap.h> 32 32 33 33 #include <linux/uaccess.h> 34 + #include <linux/filelock.h> 34 35 35 36 #include "delegation.h" 36 37 #include "internal.h"
+1
fs/nfs/nfs4_fs.h
··· 23 23 #define NFS4_MAX_LOOP_ON_RECOVER (10) 24 24 25 25 #include <linux/seqlock.h> 26 + #include <linux/filelock.h> 26 27 27 28 struct idmap; 28 29
+1
fs/nfs/pagelist.c
··· 21 21 #include <linux/nfs_page.h> 22 22 #include <linux/nfs_mount.h> 23 23 #include <linux/export.h> 24 + #include <linux/filelock.h> 24 25 25 26 #include "internal.h" 26 27 #include "pnfs.h"
+1
fs/nfs/write.c
··· 25 25 #include <linux/freezer.h> 26 26 #include <linux/wait.h> 27 27 #include <linux/iversion.h> 28 + #include <linux/filelock.h> 28 29 29 30 #include <linux/uaccess.h> 30 31 #include <linux/sched/mm.h>
+1
fs/nfs_common/grace.c
··· 9 9 #include <net/net_namespace.h> 10 10 #include <net/netns/generic.h> 11 11 #include <linux/fs.h> 12 + #include <linux/filelock.h> 12 13 13 14 static unsigned int grace_net_id; 14 15 static DEFINE_SPINLOCK(grace_lock);
+1
fs/nfsd/netns.h
··· 10 10 11 11 #include <net/net_namespace.h> 12 12 #include <net/netns/generic.h> 13 + #include <linux/filelock.h> 13 14 #include <linux/percpu_counter.h> 14 15 #include <linux/siphash.h> 15 16
+1
fs/ocfs2/locks.c
··· 8 8 */ 9 9 10 10 #include <linux/fs.h> 11 + #include <linux/filelock.h> 11 12 #include <linux/fcntl.h> 12 13 13 14 #include <cluster/masklog.h>
+1
fs/ocfs2/stack_user.c
··· 9 9 10 10 #include <linux/module.h> 11 11 #include <linux/fs.h> 12 + #include <linux/filelock.h> 12 13 #include <linux/miscdevice.h> 13 14 #include <linux/mutex.h> 14 15 #include <linux/slab.h>
+1
fs/open.c
··· 33 33 #include <linux/dnotify.h> 34 34 #include <linux/compat.h> 35 35 #include <linux/mnt_idmapping.h> 36 + #include <linux/filelock.h> 36 37 37 38 #include "internal.h" 38 39
+1
fs/orangefs/file.c
··· 14 14 #include "orangefs-kernel.h" 15 15 #include "orangefs-bufmap.h" 16 16 #include <linux/fs.h> 17 + #include <linux/filelock.h> 17 18 #include <linux/pagemap.h> 18 19 19 20 static int flush_racache(struct inode *inode)
+1
fs/posix_acl.c
··· 28 28 #include <linux/security.h> 29 29 #include <linux/evm.h> 30 30 #include <linux/fsnotify.h> 31 + #include <linux/filelock.h> 31 32 32 33 #include "internal.h" 33 34
+1
fs/proc/fd.c
··· 12 12 #include <linux/file.h> 13 13 #include <linux/seq_file.h> 14 14 #include <linux/fs.h> 15 + #include <linux/filelock.h> 15 16 16 17 #include <linux/proc_fs.h> 17 18
+1
fs/utimes.c
··· 7 7 #include <linux/uaccess.h> 8 8 #include <linux/compat.h> 9 9 #include <asm/unistd.h> 10 + #include <linux/filelock.h> 10 11 11 12 static bool nsec_valid(long nsec) 12 13 {
+1
fs/xattr.c
··· 9 9 Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com> 10 10 */ 11 11 #include <linux/fs.h> 12 + #include <linux/filelock.h> 12 13 #include <linux/slab.h> 13 14 #include <linux/file.h> 14 15 #include <linux/xattr.h>
+1
fs/xfs/xfs_linux.h
··· 34 34 #include <linux/module.h> 35 35 #include <linux/mutex.h> 36 36 #include <linux/file.h> 37 + #include <linux/filelock.h> 37 38 #include <linux/swap.h> 38 39 #include <linux/errno.h> 39 40 #include <linux/sched/signal.h>
+441
include/linux/filelock.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_FILELOCK_H 3 + #define _LINUX_FILELOCK_H 4 + 5 + #include <linux/fs.h> 6 + 7 + #define FL_POSIX 1 8 + #define FL_FLOCK 2 9 + #define FL_DELEG 4 /* NFSv4 delegation */ 10 + #define FL_ACCESS 8 /* not trying to lock, just looking */ 11 + #define FL_EXISTS 16 /* when unlocking, test for existence */ 12 + #define FL_LEASE 32 /* lease held on this file */ 13 + #define FL_CLOSE 64 /* unlock on close */ 14 + #define FL_SLEEP 128 /* A blocking lock */ 15 + #define FL_DOWNGRADE_PENDING 256 /* Lease is being downgraded */ 16 + #define FL_UNLOCK_PENDING 512 /* Lease is being broken */ 17 + #define FL_OFDLCK 1024 /* lock is "owned" by struct file */ 18 + #define FL_LAYOUT 2048 /* outstanding pNFS layout */ 19 + #define FL_RECLAIM 4096 /* reclaiming from a reboot server */ 20 + 21 + #define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE) 22 + 23 + /* 24 + * Special return value from posix_lock_file() and vfs_lock_file() for 25 + * asynchronous locking. 26 + */ 27 + #define FILE_LOCK_DEFERRED 1 28 + 29 + struct file_lock; 30 + 31 + struct file_lock_operations { 32 + void (*fl_copy_lock)(struct file_lock *, struct file_lock *); 33 + void (*fl_release_private)(struct file_lock *); 34 + }; 35 + 36 + struct lock_manager_operations { 37 + void *lm_mod_owner; 38 + fl_owner_t (*lm_get_owner)(fl_owner_t); 39 + void (*lm_put_owner)(fl_owner_t); 40 + void (*lm_notify)(struct file_lock *); /* unblock callback */ 41 + int (*lm_grant)(struct file_lock *, int); 42 + bool (*lm_break)(struct file_lock *); 43 + int (*lm_change)(struct file_lock *, int, struct list_head *); 44 + void (*lm_setup)(struct file_lock *, void **); 45 + bool (*lm_breaker_owns_lease)(struct file_lock *); 46 + bool (*lm_lock_expirable)(struct file_lock *cfl); 47 + void (*lm_expire_lock)(void); 48 + }; 49 + 50 + struct lock_manager { 51 + struct list_head list; 52 + /* 53 + * NFSv4 and up also want opens blocked during the grace period; 54 + * NLM doesn't care: 55 + */ 56 + bool block_opens; 57 + }; 58 + 59 + struct net; 60 + void locks_start_grace(struct net *, struct lock_manager *); 61 + void locks_end_grace(struct lock_manager *); 62 + bool locks_in_grace(struct net *); 63 + bool opens_in_grace(struct net *); 64 + 65 + /* 66 + * struct file_lock has a union that some filesystems use to track 67 + * their own private info. The NFS side of things is defined here: 68 + */ 69 + #include <linux/nfs_fs_i.h> 70 + 71 + /* 72 + * struct file_lock represents a generic "file lock". It's used to represent 73 + * POSIX byte range locks, BSD (flock) locks, and leases. It's important to 74 + * note that the same struct is used to represent both a request for a lock and 75 + * the lock itself, but the same object is never used for both. 76 + * 77 + * FIXME: should we create a separate "struct lock_request" to help distinguish 78 + * these two uses? 79 + * 80 + * The varous i_flctx lists are ordered by: 81 + * 82 + * 1) lock owner 83 + * 2) lock range start 84 + * 3) lock range end 85 + * 86 + * Obviously, the last two criteria only matter for POSIX locks. 87 + */ 88 + struct file_lock { 89 + struct file_lock *fl_blocker; /* The lock, that is blocking us */ 90 + struct list_head fl_list; /* link into file_lock_context */ 91 + struct hlist_node fl_link; /* node in global lists */ 92 + struct list_head fl_blocked_requests; /* list of requests with 93 + * ->fl_blocker pointing here 94 + */ 95 + struct list_head fl_blocked_member; /* node in 96 + * ->fl_blocker->fl_blocked_requests 97 + */ 98 + fl_owner_t fl_owner; 99 + unsigned int fl_flags; 100 + unsigned char fl_type; 101 + unsigned int fl_pid; 102 + int fl_link_cpu; /* what cpu's list is this on? */ 103 + wait_queue_head_t fl_wait; 104 + struct file *fl_file; 105 + loff_t fl_start; 106 + loff_t fl_end; 107 + 108 + struct fasync_struct * fl_fasync; /* for lease break notifications */ 109 + /* for lease breaks: */ 110 + unsigned long fl_break_time; 111 + unsigned long fl_downgrade_time; 112 + 113 + const struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ 114 + const struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ 115 + union { 116 + struct nfs_lock_info nfs_fl; 117 + struct nfs4_lock_info nfs4_fl; 118 + struct { 119 + struct list_head link; /* link in AFS vnode's pending_locks list */ 120 + int state; /* state of grant or error if -ve */ 121 + unsigned int debug_id; 122 + } afs; 123 + struct { 124 + struct inode *inode; 125 + } ceph; 126 + } fl_u; 127 + } __randomize_layout; 128 + 129 + struct file_lock_context { 130 + spinlock_t flc_lock; 131 + struct list_head flc_flock; 132 + struct list_head flc_posix; 133 + struct list_head flc_lease; 134 + }; 135 + 136 + #define locks_inode(f) file_inode(f) 137 + 138 + #ifdef CONFIG_FILE_LOCKING 139 + int fcntl_getlk(struct file *, unsigned int, struct flock *); 140 + int fcntl_setlk(unsigned int, struct file *, unsigned int, 141 + struct flock *); 142 + 143 + #if BITS_PER_LONG == 32 144 + int fcntl_getlk64(struct file *, unsigned int, struct flock64 *); 145 + int fcntl_setlk64(unsigned int, struct file *, unsigned int, 146 + struct flock64 *); 147 + #endif 148 + 149 + int fcntl_setlease(unsigned int fd, struct file *filp, long arg); 150 + int fcntl_getlease(struct file *filp); 151 + 152 + /* fs/locks.c */ 153 + void locks_free_lock_context(struct inode *inode); 154 + void locks_free_lock(struct file_lock *fl); 155 + void locks_init_lock(struct file_lock *); 156 + struct file_lock * locks_alloc_lock(void); 157 + void locks_copy_lock(struct file_lock *, struct file_lock *); 158 + void locks_copy_conflock(struct file_lock *, struct file_lock *); 159 + void locks_remove_posix(struct file *, fl_owner_t); 160 + void locks_remove_file(struct file *); 161 + void locks_release_private(struct file_lock *); 162 + void posix_test_lock(struct file *, struct file_lock *); 163 + int posix_lock_file(struct file *, struct file_lock *, struct file_lock *); 164 + int locks_delete_block(struct file_lock *); 165 + int vfs_test_lock(struct file *, struct file_lock *); 166 + int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *); 167 + int vfs_cancel_lock(struct file *filp, struct file_lock *fl); 168 + bool vfs_inode_has_locks(struct inode *inode); 169 + int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl); 170 + int __break_lease(struct inode *inode, unsigned int flags, unsigned int type); 171 + void lease_get_mtime(struct inode *, struct timespec64 *time); 172 + int generic_setlease(struct file *, long, struct file_lock **, void **priv); 173 + int vfs_setlease(struct file *, long, struct file_lock **, void **); 174 + int lease_modify(struct file_lock *, int, struct list_head *); 175 + 176 + struct notifier_block; 177 + int lease_register_notifier(struct notifier_block *); 178 + void lease_unregister_notifier(struct notifier_block *); 179 + 180 + struct files_struct; 181 + void show_fd_locks(struct seq_file *f, 182 + struct file *filp, struct files_struct *files); 183 + bool locks_owner_has_blockers(struct file_lock_context *flctx, 184 + fl_owner_t owner); 185 + 186 + static inline struct file_lock_context * 187 + locks_inode_context(const struct inode *inode) 188 + { 189 + return smp_load_acquire(&inode->i_flctx); 190 + } 191 + 192 + #else /* !CONFIG_FILE_LOCKING */ 193 + static inline int fcntl_getlk(struct file *file, unsigned int cmd, 194 + struct flock __user *user) 195 + { 196 + return -EINVAL; 197 + } 198 + 199 + static inline int fcntl_setlk(unsigned int fd, struct file *file, 200 + unsigned int cmd, struct flock __user *user) 201 + { 202 + return -EACCES; 203 + } 204 + 205 + #if BITS_PER_LONG == 32 206 + static inline int fcntl_getlk64(struct file *file, unsigned int cmd, 207 + struct flock64 *user) 208 + { 209 + return -EINVAL; 210 + } 211 + 212 + static inline int fcntl_setlk64(unsigned int fd, struct file *file, 213 + unsigned int cmd, struct flock64 *user) 214 + { 215 + return -EACCES; 216 + } 217 + #endif 218 + static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg) 219 + { 220 + return -EINVAL; 221 + } 222 + 223 + static inline int fcntl_getlease(struct file *filp) 224 + { 225 + return F_UNLCK; 226 + } 227 + 228 + static inline void 229 + locks_free_lock_context(struct inode *inode) 230 + { 231 + } 232 + 233 + static inline void locks_init_lock(struct file_lock *fl) 234 + { 235 + return; 236 + } 237 + 238 + static inline void locks_copy_conflock(struct file_lock *new, struct file_lock *fl) 239 + { 240 + return; 241 + } 242 + 243 + static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl) 244 + { 245 + return; 246 + } 247 + 248 + static inline void locks_remove_posix(struct file *filp, fl_owner_t owner) 249 + { 250 + return; 251 + } 252 + 253 + static inline void locks_remove_file(struct file *filp) 254 + { 255 + return; 256 + } 257 + 258 + static inline void posix_test_lock(struct file *filp, struct file_lock *fl) 259 + { 260 + return; 261 + } 262 + 263 + static inline int posix_lock_file(struct file *filp, struct file_lock *fl, 264 + struct file_lock *conflock) 265 + { 266 + return -ENOLCK; 267 + } 268 + 269 + static inline int locks_delete_block(struct file_lock *waiter) 270 + { 271 + return -ENOENT; 272 + } 273 + 274 + static inline int vfs_test_lock(struct file *filp, struct file_lock *fl) 275 + { 276 + return 0; 277 + } 278 + 279 + static inline int vfs_lock_file(struct file *filp, unsigned int cmd, 280 + struct file_lock *fl, struct file_lock *conf) 281 + { 282 + return -ENOLCK; 283 + } 284 + 285 + static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl) 286 + { 287 + return 0; 288 + } 289 + 290 + static inline bool vfs_inode_has_locks(struct inode *inode) 291 + { 292 + return false; 293 + } 294 + 295 + static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl) 296 + { 297 + return -ENOLCK; 298 + } 299 + 300 + static inline int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) 301 + { 302 + return 0; 303 + } 304 + 305 + static inline void lease_get_mtime(struct inode *inode, 306 + struct timespec64 *time) 307 + { 308 + return; 309 + } 310 + 311 + static inline int generic_setlease(struct file *filp, long arg, 312 + struct file_lock **flp, void **priv) 313 + { 314 + return -EINVAL; 315 + } 316 + 317 + static inline int vfs_setlease(struct file *filp, long arg, 318 + struct file_lock **lease, void **priv) 319 + { 320 + return -EINVAL; 321 + } 322 + 323 + static inline int lease_modify(struct file_lock *fl, int arg, 324 + struct list_head *dispose) 325 + { 326 + return -EINVAL; 327 + } 328 + 329 + struct files_struct; 330 + static inline void show_fd_locks(struct seq_file *f, 331 + struct file *filp, struct files_struct *files) {} 332 + static inline bool locks_owner_has_blockers(struct file_lock_context *flctx, 333 + fl_owner_t owner) 334 + { 335 + return false; 336 + } 337 + 338 + static inline struct file_lock_context * 339 + locks_inode_context(const struct inode *inode) 340 + { 341 + return NULL; 342 + } 343 + 344 + #endif /* !CONFIG_FILE_LOCKING */ 345 + 346 + static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl) 347 + { 348 + return locks_lock_inode_wait(locks_inode(filp), fl); 349 + } 350 + 351 + #ifdef CONFIG_FILE_LOCKING 352 + static inline int break_lease(struct inode *inode, unsigned int mode) 353 + { 354 + /* 355 + * Since this check is lockless, we must ensure that any refcounts 356 + * taken are done before checking i_flctx->flc_lease. Otherwise, we 357 + * could end up racing with tasks trying to set a new lease on this 358 + * file. 359 + */ 360 + smp_mb(); 361 + if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease)) 362 + return __break_lease(inode, mode, FL_LEASE); 363 + return 0; 364 + } 365 + 366 + static inline int break_deleg(struct inode *inode, unsigned int mode) 367 + { 368 + /* 369 + * Since this check is lockless, we must ensure that any refcounts 370 + * taken are done before checking i_flctx->flc_lease. Otherwise, we 371 + * could end up racing with tasks trying to set a new lease on this 372 + * file. 373 + */ 374 + smp_mb(); 375 + if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease)) 376 + return __break_lease(inode, mode, FL_DELEG); 377 + return 0; 378 + } 379 + 380 + static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode) 381 + { 382 + int ret; 383 + 384 + ret = break_deleg(inode, O_WRONLY|O_NONBLOCK); 385 + if (ret == -EWOULDBLOCK && delegated_inode) { 386 + *delegated_inode = inode; 387 + ihold(inode); 388 + } 389 + return ret; 390 + } 391 + 392 + static inline int break_deleg_wait(struct inode **delegated_inode) 393 + { 394 + int ret; 395 + 396 + ret = break_deleg(*delegated_inode, O_WRONLY); 397 + iput(*delegated_inode); 398 + *delegated_inode = NULL; 399 + return ret; 400 + } 401 + 402 + static inline int break_layout(struct inode *inode, bool wait) 403 + { 404 + smp_mb(); 405 + if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease)) 406 + return __break_lease(inode, 407 + wait ? O_WRONLY : O_WRONLY | O_NONBLOCK, 408 + FL_LAYOUT); 409 + return 0; 410 + } 411 + 412 + #else /* !CONFIG_FILE_LOCKING */ 413 + static inline int break_lease(struct inode *inode, unsigned int mode) 414 + { 415 + return 0; 416 + } 417 + 418 + static inline int break_deleg(struct inode *inode, unsigned int mode) 419 + { 420 + return 0; 421 + } 422 + 423 + static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode) 424 + { 425 + return 0; 426 + } 427 + 428 + static inline int break_deleg_wait(struct inode **delegated_inode) 429 + { 430 + BUG(); 431 + return 0; 432 + } 433 + 434 + static inline int break_layout(struct inode *inode, bool wait) 435 + { 436 + return 0; 437 + } 438 + 439 + #endif /* CONFIG_FILE_LOCKING */ 440 + 441 + #endif /* _LINUX_FILELOCK_H */
-429
include/linux/fs.h
··· 1003 1003 #define MAX_LFS_FILESIZE ((loff_t)LLONG_MAX) 1004 1004 #endif 1005 1005 1006 - #define FL_POSIX 1 1007 - #define FL_FLOCK 2 1008 - #define FL_DELEG 4 /* NFSv4 delegation */ 1009 - #define FL_ACCESS 8 /* not trying to lock, just looking */ 1010 - #define FL_EXISTS 16 /* when unlocking, test for existence */ 1011 - #define FL_LEASE 32 /* lease held on this file */ 1012 - #define FL_CLOSE 64 /* unlock on close */ 1013 - #define FL_SLEEP 128 /* A blocking lock */ 1014 - #define FL_DOWNGRADE_PENDING 256 /* Lease is being downgraded */ 1015 - #define FL_UNLOCK_PENDING 512 /* Lease is being broken */ 1016 - #define FL_OFDLCK 1024 /* lock is "owned" by struct file */ 1017 - #define FL_LAYOUT 2048 /* outstanding pNFS layout */ 1018 - #define FL_RECLAIM 4096 /* reclaiming from a reboot server */ 1019 - 1020 - #define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE) 1021 - 1022 - /* 1023 - * Special return value from posix_lock_file() and vfs_lock_file() for 1024 - * asynchronous locking. 1025 - */ 1026 - #define FILE_LOCK_DEFERRED 1 1027 - 1028 1006 /* legacy typedef, should eventually be removed */ 1029 1007 typedef void *fl_owner_t; 1030 1008 1031 1009 struct file_lock; 1032 - 1033 - struct file_lock_operations { 1034 - void (*fl_copy_lock)(struct file_lock *, struct file_lock *); 1035 - void (*fl_release_private)(struct file_lock *); 1036 - }; 1037 - 1038 - struct lock_manager_operations { 1039 - void *lm_mod_owner; 1040 - fl_owner_t (*lm_get_owner)(fl_owner_t); 1041 - void (*lm_put_owner)(fl_owner_t); 1042 - void (*lm_notify)(struct file_lock *); /* unblock callback */ 1043 - int (*lm_grant)(struct file_lock *, int); 1044 - bool (*lm_break)(struct file_lock *); 1045 - int (*lm_change)(struct file_lock *, int, struct list_head *); 1046 - void (*lm_setup)(struct file_lock *, void **); 1047 - bool (*lm_breaker_owns_lease)(struct file_lock *); 1048 - bool (*lm_lock_expirable)(struct file_lock *cfl); 1049 - void (*lm_expire_lock)(void); 1050 - }; 1051 - 1052 - struct lock_manager { 1053 - struct list_head list; 1054 - /* 1055 - * NFSv4 and up also want opens blocked during the grace period; 1056 - * NLM doesn't care: 1057 - */ 1058 - bool block_opens; 1059 - }; 1060 - 1061 - struct net; 1062 - void locks_start_grace(struct net *, struct lock_manager *); 1063 - void locks_end_grace(struct lock_manager *); 1064 - bool locks_in_grace(struct net *); 1065 - bool opens_in_grace(struct net *); 1066 - 1067 - /* that will die - we need it for nfs_lock_info */ 1068 - #include <linux/nfs_fs_i.h> 1069 - 1070 - /* 1071 - * struct file_lock represents a generic "file lock". It's used to represent 1072 - * POSIX byte range locks, BSD (flock) locks, and leases. It's important to 1073 - * note that the same struct is used to represent both a request for a lock and 1074 - * the lock itself, but the same object is never used for both. 1075 - * 1076 - * FIXME: should we create a separate "struct lock_request" to help distinguish 1077 - * these two uses? 1078 - * 1079 - * The varous i_flctx lists are ordered by: 1080 - * 1081 - * 1) lock owner 1082 - * 2) lock range start 1083 - * 3) lock range end 1084 - * 1085 - * Obviously, the last two criteria only matter for POSIX locks. 1086 - */ 1087 - struct file_lock { 1088 - struct file_lock *fl_blocker; /* The lock, that is blocking us */ 1089 - struct list_head fl_list; /* link into file_lock_context */ 1090 - struct hlist_node fl_link; /* node in global lists */ 1091 - struct list_head fl_blocked_requests; /* list of requests with 1092 - * ->fl_blocker pointing here 1093 - */ 1094 - struct list_head fl_blocked_member; /* node in 1095 - * ->fl_blocker->fl_blocked_requests 1096 - */ 1097 - fl_owner_t fl_owner; 1098 - unsigned int fl_flags; 1099 - unsigned char fl_type; 1100 - unsigned int fl_pid; 1101 - int fl_link_cpu; /* what cpu's list is this on? */ 1102 - wait_queue_head_t fl_wait; 1103 - struct file *fl_file; 1104 - loff_t fl_start; 1105 - loff_t fl_end; 1106 - 1107 - struct fasync_struct * fl_fasync; /* for lease break notifications */ 1108 - /* for lease breaks: */ 1109 - unsigned long fl_break_time; 1110 - unsigned long fl_downgrade_time; 1111 - 1112 - const struct file_lock_operations *fl_ops; /* Callbacks for filesystems */ 1113 - const struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */ 1114 - union { 1115 - struct nfs_lock_info nfs_fl; 1116 - struct nfs4_lock_info nfs4_fl; 1117 - struct { 1118 - struct list_head link; /* link in AFS vnode's pending_locks list */ 1119 - int state; /* state of grant or error if -ve */ 1120 - unsigned int debug_id; 1121 - } afs; 1122 - struct { 1123 - struct inode *inode; 1124 - } ceph; 1125 - } fl_u; 1126 - } __randomize_layout; 1127 - 1128 - struct file_lock_context { 1129 - spinlock_t flc_lock; 1130 - struct list_head flc_flock; 1131 - struct list_head flc_posix; 1132 - struct list_head flc_lease; 1133 - }; 1134 1010 1135 1011 /* The following constant reflects the upper bound of the file/locking space */ 1136 1012 #ifndef OFFSET_MAX ··· 1016 1140 1017 1141 extern void send_sigio(struct fown_struct *fown, int fd, int band); 1018 1142 1019 - #define locks_inode(f) file_inode(f) 1020 - 1021 - #ifdef CONFIG_FILE_LOCKING 1022 - extern int fcntl_getlk(struct file *, unsigned int, struct flock *); 1023 - extern int fcntl_setlk(unsigned int, struct file *, unsigned int, 1024 - struct flock *); 1025 - 1026 - #if BITS_PER_LONG == 32 1027 - extern int fcntl_getlk64(struct file *, unsigned int, struct flock64 *); 1028 - extern int fcntl_setlk64(unsigned int, struct file *, unsigned int, 1029 - struct flock64 *); 1030 - #endif 1031 - 1032 - extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); 1033 - extern int fcntl_getlease(struct file *filp); 1034 - 1035 - /* fs/locks.c */ 1036 - void locks_free_lock_context(struct inode *inode); 1037 - void locks_free_lock(struct file_lock *fl); 1038 - extern void locks_init_lock(struct file_lock *); 1039 - extern struct file_lock * locks_alloc_lock(void); 1040 - extern void locks_copy_lock(struct file_lock *, struct file_lock *); 1041 - extern void locks_copy_conflock(struct file_lock *, struct file_lock *); 1042 - extern void locks_remove_posix(struct file *, fl_owner_t); 1043 - extern void locks_remove_file(struct file *); 1044 - extern void locks_release_private(struct file_lock *); 1045 - extern void posix_test_lock(struct file *, struct file_lock *); 1046 - extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *); 1047 - extern int locks_delete_block(struct file_lock *); 1048 - extern int vfs_test_lock(struct file *, struct file_lock *); 1049 - extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *); 1050 - extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl); 1051 - bool vfs_inode_has_locks(struct inode *inode); 1052 - extern int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl); 1053 - extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type); 1054 - extern void lease_get_mtime(struct inode *, struct timespec64 *time); 1055 - extern int generic_setlease(struct file *, long, struct file_lock **, void **priv); 1056 - extern int vfs_setlease(struct file *, long, struct file_lock **, void **); 1057 - extern int lease_modify(struct file_lock *, int, struct list_head *); 1058 - 1059 - struct notifier_block; 1060 - extern int lease_register_notifier(struct notifier_block *); 1061 - extern void lease_unregister_notifier(struct notifier_block *); 1062 - 1063 - struct files_struct; 1064 - extern void show_fd_locks(struct seq_file *f, 1065 - struct file *filp, struct files_struct *files); 1066 - extern bool locks_owner_has_blockers(struct file_lock_context *flctx, 1067 - fl_owner_t owner); 1068 - 1069 - static inline struct file_lock_context * 1070 - locks_inode_context(const struct inode *inode) 1071 - { 1072 - return smp_load_acquire(&inode->i_flctx); 1073 - } 1074 - 1075 - #else /* !CONFIG_FILE_LOCKING */ 1076 - static inline int fcntl_getlk(struct file *file, unsigned int cmd, 1077 - struct flock __user *user) 1078 - { 1079 - return -EINVAL; 1080 - } 1081 - 1082 - static inline int fcntl_setlk(unsigned int fd, struct file *file, 1083 - unsigned int cmd, struct flock __user *user) 1084 - { 1085 - return -EACCES; 1086 - } 1087 - 1088 - #if BITS_PER_LONG == 32 1089 - static inline int fcntl_getlk64(struct file *file, unsigned int cmd, 1090 - struct flock64 *user) 1091 - { 1092 - return -EINVAL; 1093 - } 1094 - 1095 - static inline int fcntl_setlk64(unsigned int fd, struct file *file, 1096 - unsigned int cmd, struct flock64 *user) 1097 - { 1098 - return -EACCES; 1099 - } 1100 - #endif 1101 - static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg) 1102 - { 1103 - return -EINVAL; 1104 - } 1105 - 1106 - static inline int fcntl_getlease(struct file *filp) 1107 - { 1108 - return F_UNLCK; 1109 - } 1110 - 1111 - static inline void 1112 - locks_free_lock_context(struct inode *inode) 1113 - { 1114 - } 1115 - 1116 - static inline void locks_init_lock(struct file_lock *fl) 1117 - { 1118 - return; 1119 - } 1120 - 1121 - static inline void locks_copy_conflock(struct file_lock *new, struct file_lock *fl) 1122 - { 1123 - return; 1124 - } 1125 - 1126 - static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl) 1127 - { 1128 - return; 1129 - } 1130 - 1131 - static inline void locks_remove_posix(struct file *filp, fl_owner_t owner) 1132 - { 1133 - return; 1134 - } 1135 - 1136 - static inline void locks_remove_file(struct file *filp) 1137 - { 1138 - return; 1139 - } 1140 - 1141 - static inline void posix_test_lock(struct file *filp, struct file_lock *fl) 1142 - { 1143 - return; 1144 - } 1145 - 1146 - static inline int posix_lock_file(struct file *filp, struct file_lock *fl, 1147 - struct file_lock *conflock) 1148 - { 1149 - return -ENOLCK; 1150 - } 1151 - 1152 - static inline int locks_delete_block(struct file_lock *waiter) 1153 - { 1154 - return -ENOENT; 1155 - } 1156 - 1157 - static inline int vfs_test_lock(struct file *filp, struct file_lock *fl) 1158 - { 1159 - return 0; 1160 - } 1161 - 1162 - static inline int vfs_lock_file(struct file *filp, unsigned int cmd, 1163 - struct file_lock *fl, struct file_lock *conf) 1164 - { 1165 - return -ENOLCK; 1166 - } 1167 - 1168 - static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl) 1169 - { 1170 - return 0; 1171 - } 1172 - 1173 - static inline bool vfs_inode_has_locks(struct inode *inode) 1174 - { 1175 - return false; 1176 - } 1177 - 1178 - static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl) 1179 - { 1180 - return -ENOLCK; 1181 - } 1182 - 1183 - static inline int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) 1184 - { 1185 - return 0; 1186 - } 1187 - 1188 - static inline void lease_get_mtime(struct inode *inode, 1189 - struct timespec64 *time) 1190 - { 1191 - return; 1192 - } 1193 - 1194 - static inline int generic_setlease(struct file *filp, long arg, 1195 - struct file_lock **flp, void **priv) 1196 - { 1197 - return -EINVAL; 1198 - } 1199 - 1200 - static inline int vfs_setlease(struct file *filp, long arg, 1201 - struct file_lock **lease, void **priv) 1202 - { 1203 - return -EINVAL; 1204 - } 1205 - 1206 - static inline int lease_modify(struct file_lock *fl, int arg, 1207 - struct list_head *dispose) 1208 - { 1209 - return -EINVAL; 1210 - } 1211 - 1212 - struct files_struct; 1213 - static inline void show_fd_locks(struct seq_file *f, 1214 - struct file *filp, struct files_struct *files) {} 1215 - static inline bool locks_owner_has_blockers(struct file_lock_context *flctx, 1216 - fl_owner_t owner) 1217 - { 1218 - return false; 1219 - } 1220 - 1221 - static inline struct file_lock_context * 1222 - locks_inode_context(const struct inode *inode) 1223 - { 1224 - return NULL; 1225 - } 1226 - 1227 - #endif /* !CONFIG_FILE_LOCKING */ 1228 - 1229 1143 static inline struct inode *file_inode(const struct file *f) 1230 1144 { 1231 1145 return f->f_inode; ··· 1024 1358 static inline struct dentry *file_dentry(const struct file *file) 1025 1359 { 1026 1360 return d_real(file->f_path.dentry, file_inode(file)); 1027 - } 1028 - 1029 - static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl) 1030 - { 1031 - return locks_lock_inode_wait(locks_inode(filp), fl); 1032 1361 } 1033 1362 1034 1363 struct fasync_struct { ··· 2284 2623 extern struct kobject *fs_kobj; 2285 2624 2286 2625 #define MAX_RW_COUNT (INT_MAX & PAGE_MASK) 2287 - 2288 - #ifdef CONFIG_FILE_LOCKING 2289 - static inline int break_lease(struct inode *inode, unsigned int mode) 2290 - { 2291 - /* 2292 - * Since this check is lockless, we must ensure that any refcounts 2293 - * taken are done before checking i_flctx->flc_lease. Otherwise, we 2294 - * could end up racing with tasks trying to set a new lease on this 2295 - * file. 2296 - */ 2297 - smp_mb(); 2298 - if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease)) 2299 - return __break_lease(inode, mode, FL_LEASE); 2300 - return 0; 2301 - } 2302 - 2303 - static inline int break_deleg(struct inode *inode, unsigned int mode) 2304 - { 2305 - /* 2306 - * Since this check is lockless, we must ensure that any refcounts 2307 - * taken are done before checking i_flctx->flc_lease. Otherwise, we 2308 - * could end up racing with tasks trying to set a new lease on this 2309 - * file. 2310 - */ 2311 - smp_mb(); 2312 - if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease)) 2313 - return __break_lease(inode, mode, FL_DELEG); 2314 - return 0; 2315 - } 2316 - 2317 - static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode) 2318 - { 2319 - int ret; 2320 - 2321 - ret = break_deleg(inode, O_WRONLY|O_NONBLOCK); 2322 - if (ret == -EWOULDBLOCK && delegated_inode) { 2323 - *delegated_inode = inode; 2324 - ihold(inode); 2325 - } 2326 - return ret; 2327 - } 2328 - 2329 - static inline int break_deleg_wait(struct inode **delegated_inode) 2330 - { 2331 - int ret; 2332 - 2333 - ret = break_deleg(*delegated_inode, O_WRONLY); 2334 - iput(*delegated_inode); 2335 - *delegated_inode = NULL; 2336 - return ret; 2337 - } 2338 - 2339 - static inline int break_layout(struct inode *inode, bool wait) 2340 - { 2341 - smp_mb(); 2342 - if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease)) 2343 - return __break_lease(inode, 2344 - wait ? O_WRONLY : O_WRONLY | O_NONBLOCK, 2345 - FL_LAYOUT); 2346 - return 0; 2347 - } 2348 - 2349 - #else /* !CONFIG_FILE_LOCKING */ 2350 - static inline int break_lease(struct inode *inode, unsigned int mode) 2351 - { 2352 - return 0; 2353 - } 2354 - 2355 - static inline int break_deleg(struct inode *inode, unsigned int mode) 2356 - { 2357 - return 0; 2358 - } 2359 - 2360 - static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode) 2361 - { 2362 - return 0; 2363 - } 2364 - 2365 - static inline int break_deleg_wait(struct inode **delegated_inode) 2366 - { 2367 - BUG(); 2368 - return 0; 2369 - } 2370 - 2371 - static inline int break_layout(struct inode *inode, bool wait) 2372 - { 2373 - return 0; 2374 - } 2375 - 2376 - #endif /* CONFIG_FILE_LOCKING */ 2377 2626 2378 2627 /* fs/open.c */ 2379 2628 struct audit_names;
+1
include/linux/lockd/xdr.h
··· 11 11 #define LOCKD_XDR_H 12 12 13 13 #include <linux/fs.h> 14 + #include <linux/filelock.h> 14 15 #include <linux/nfs.h> 15 16 #include <linux/sunrpc/xdr.h> 16 17