filelock: move file locking definitions to separate header file
authorJeff Layton <jlayton@kernel.org>
Sun, 20 Nov 2022 14:15:34 +0000 (09:15 -0500)
committerJeff Layton <jlayton@kernel.org>
Wed, 11 Jan 2023 11:52:32 +0000 (06:52 -0500)
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>
42 files changed:
arch/arm/kernel/sys_oabi-compat.c
fs/9p/vfs_file.c
fs/afs/internal.h
fs/attr.c
fs/ceph/caps.c
fs/ceph/locks.c
fs/cifs/cifsfs.c
fs/cifs/cifsglob.h
fs/cifs/cifssmb.c
fs/cifs/file.c
fs/cifs/smb2file.c
fs/dlm/plock.c
fs/fcntl.c
fs/file_table.c
fs/fuse/file.c
fs/gfs2/file.c
fs/inode.c
fs/ksmbd/smb2pdu.c
fs/ksmbd/vfs.c
fs/ksmbd/vfs_cache.c
fs/lockd/clntproc.c
fs/lockd/netns.h
fs/locks.c
fs/namei.c
fs/nfs/file.c
fs/nfs/nfs4_fs.h
fs/nfs/pagelist.c
fs/nfs/write.c
fs/nfs_common/grace.c
fs/nfsd/netns.h
fs/ocfs2/locks.c
fs/ocfs2/stack_user.c
fs/open.c
fs/orangefs/file.c
fs/posix_acl.c
fs/proc/fd.c
fs/utimes.c
fs/xattr.c
fs/xfs/xfs_linux.h
include/linux/filelock.h [new file with mode: 0644]
include/linux/fs.h
include/linux/lockd/xdr.h

index 68112c172025c7a66fdebc8a32e8078f266beed9..006163195d67e486b9c7a3debc0d8626e53d6dfb 100644 (file)
@@ -73,6 +73,7 @@
 #include <linux/syscalls.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/cred.h>
 #include <linux/fcntl.h>
 #include <linux/eventpoll.h>
index b740017634ef154747f22473bdd8b883134cb607..b6ba229757818442b2a1db65692969f8421b3bc0 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/sched.h>
 #include <linux/file.h>
 #include <linux/stat.h>
index fd8567b98e2bba4d3c1dae156163a34e8cf464e6..2d6d7dae225a09dbf4525d37a7d4792a8081f8ef 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/kernel.h>
 #include <linux/ktime.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/pagemap.h>
 #include <linux/rxrpc.h>
 #include <linux/key.h>
index b45f30e516fad33ff4f58e3b15f1e754a724cef2..f3eb8e57b4514987d02aff6833e31a183b5ddbba 100644 (file)
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -14,6 +14,7 @@
 #include <linux/capability.h>
 #include <linux/fsnotify.h>
 #include <linux/fcntl.h>
+#include <linux/filelock.h>
 #include <linux/security.h>
 #include <linux/evm.h>
 #include <linux/ima.h>
index f75ad432f375f882abd478bd1fd585568c705721..2ce6cc443b48af60380a01185d22f712c0a69f99 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/wait.h>
 #include <linux/writeback.h>
 #include <linux/iversion.h>
+#include <linux/filelock.h>
 
 #include "super.h"
 #include "mds_client.h"
index 9c8dc8a55e7e13e05fed766ea8505aa6ae9c6b62..cb51c7e9c8e22cd5b3295ea902bb667905d2d17b 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "super.h"
 #include "mds_client.h"
+#include <linux/filelock.h>
 #include <linux/ceph/pagelist.h>
 
 static u64 lock_secret;
index 10e00c62492280a8b759875cfeea8b56a5ae72d7..f052f190b2e867d468b450c6a8dadb0131868d85 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/module.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/mount.h>
 #include <linux/slab.h>
 #include <linux/init.h>
index cfdd5bf701a1c6fb863a57d364e4603a2959b04b..cd8171a1c9a0973fffa8b4e409a056426fdf5187 100644 (file)
@@ -26,6 +26,7 @@
 #include <uapi/linux/cifs/cifs_mount.h>
 #include "../smbfs_common/smb2pdu.h"
 #include "smb2pdu.h"
+#include <linux/filelock.h>
 
 #define SMB_PATH_MAX 260
 #define CIFS_PORT 445
index 23f10e0d6e7e3935cc56325f85f36a0e009def28..60dd4e37030ab49131b2b86fdb44fe61282fe0c2 100644 (file)
@@ -15,6 +15,7 @@
  /* want to reuse a stale file handle and only the caller knows the file info */
 
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/kernel.h>
 #include <linux/vfs.h>
 #include <linux/slab.h>
index 22dfc1f8b4f12fb10801bd91c3c432d8559f18e9..1d9cc59d82592af25aeca01d782ad24b963fa2fd 100644 (file)
@@ -9,6 +9,7 @@
  *
  */
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/backing-dev.h>
 #include <linux/stat.h>
 #include <linux/fcntl.h>
index ba6cc50af390f22f2af0a83a1d939afbf9ea00a0..9f1dd04b555ad2001600ce5bd368bb8464f74821 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/pagemap.h>
index 737f185aad8dd1c8b82271c3819a7de319194cc3..ed4357e62f35f9b072c2f3a93c2ab75f9e2fab49 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/miscdevice.h>
 #include <linux/poll.h>
 #include <linux/dlm.h>
index 146c9ab0cd4b7c81e6f661205e79ae562da11cee..7852e946fdf4327824e65d1586668bec757485b4 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/mm.h>
 #include <linux/sched/task.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/file.h>
 #include <linux/fdtable.h>
 #include <linux/capability.h>
index dd88701e54a93aa33958d03b1dbca5715e290c92..372653b92617dd3c88112b5ac1038fd766ef4296 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/security.h>
 #include <linux/cred.h>
 #include <linux/eventpoll.h>
index 875314ee6f59a86f5d0a576cc3ccab3f05faa64b..1458412f24923fc925453abcc429e3e23581e8b1 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/falloc.h>
 #include <linux/uio.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 
 static int fuse_send_open(struct fuse_mount *fm, u64 nodeid,
                          unsigned int open_flags, int opcode,
index eea5be4fbf0eff056fb8e8600536abd6e94ca2b9..e8e20a716004a97bb2f339d3f01c349c8cb21a46 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/mm.h>
 #include <linux/mount.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/gfs2_ondisk.h>
 #include <linux/falloc.h>
 #include <linux/swap.h>
index f453eb58fd03de04b32837af37d4f0701e8ae16f..d02dd8f1e96714897d5061a3c5b022bfd53d3f8e 100644 (file)
@@ -5,6 +5,7 @@
  */
 #include <linux/export.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/mm.h>
 #include <linux/backing-dev.h>
 #include <linux/hash.h>
index 14d7f3599c6397a1dba915509b03a1644cc7ed2a..000a6648f1228aa73005db96dd878a5d80aec131 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/ethtool.h>
 #include <linux/falloc.h>
 #include <linux/mount.h>
+#include <linux/filelock.h>
 
 #include "glob.h"
 #include "smbfsctl.h"
index ff0e7a4fcd4de5df2892ca6de1f43319477be2cb..5851934dc85bc1a4ef82141f1efc3b32b162e79f 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <linux/kernel.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/uaccess.h>
 #include <linux/backing-dev.h>
 #include <linux/writeback.h>
index da9163b003503acb8085ff2fe5e7189a76658c45..552c3882a8f4aca5a74dffb77af202b3c6855c09 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 
index 99fffc9cb9585cdad7ae80336cac42674e818d5d..e875a3571c410e8ddfff862dc9d9b3dbe215b66e 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/nfs_fs.h>
 #include <linux/utsname.h>
 #include <linux/freezer.h>
index 5bec78c8e431ff0c512605025726e4882190529f..17432c445fe6f0841b3c821ca1c71babf4e50b7a 100644 (file)
@@ -3,6 +3,7 @@
 #define __LOCKD_NETNS_H__
 
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <net/netns/generic.h>
 
 struct lockd_net {
index 8f01bee1771597df6df2adb651dcc3d3a7e7fcec..a5cc90c958c901a6e2434df5b4f1f0e362f5b861 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/capability.h>
 #include <linux/file.h>
 #include <linux/fdtable.h>
+#include <linux/filelock.h>
 #include <linux/fs.h>
 #include <linux/init.h>
 #include <linux/security.h>
index 309ae6fc8c993b8057a560da88de4971fa004127..60a9d3ac941fc184f28e7e8a08b3bb110f8e08c1 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/namei.h>
 #include <linux/pagemap.h>
 #include <linux/sched/mm.h>
index d8ec889a4b3f761e9378adf325a2846f76555b73..b0f3c9339e706c8dd1897aaacec37b8a5a4e4d74 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/swap.h>
 
 #include <linux/uaccess.h>
+#include <linux/filelock.h>
 
 #include "delegation.h"
 #include "internal.h"
index 5edd1704f7359eb48c5fc769e977b891b10a9472..4c9f8bd866aba5dc6ca82a77a06eb107c1a5ff93 100644 (file)
@@ -23,6 +23,7 @@
 #define NFS4_MAX_LOOP_ON_RECOVER (10)
 
 #include <linux/seqlock.h>
+#include <linux/filelock.h>
 
 struct idmap;
 
index 16be6dae524f99c946a277aedde9c8d42f9332d8..779bfc37233c8aaad6e902377bdebcbff36a2ed5 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/nfs_page.h>
 #include <linux/nfs_mount.h>
 #include <linux/export.h>
+#include <linux/filelock.h>
 
 #include "internal.h"
 #include "pnfs.h"
index 80c240e50952217df66bda308787f02bd1eada15..1a80d548253ac12afd7ea5d7d7b69efae32fa33b 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/freezer.h>
 #include <linux/wait.h>
 #include <linux/iversion.h>
+#include <linux/filelock.h>
 
 #include <linux/uaccess.h>
 #include <linux/sched/mm.h>
index 0a9b72685f984857f3e7a04651f8c5ca2e2b631f..1479583fbb62333674970a6982beb314cb41061b 100644 (file)
@@ -9,6 +9,7 @@
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 
 static unsigned int grace_net_id;
 static DEFINE_SPINLOCK(grace_lock);
index 8c854ba3285bbcddfe62010dc6b93018fdc3927c..bc139401927daaebe16a2174ae6b69e84d8df42a 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
+#include <linux/filelock.h>
 #include <linux/percpu_counter.h>
 #include <linux/siphash.h>
 
index 73a3854b2afb941a3d26648b95775f5534d07aba..f37174e79fad4f377e76c04eec2a06c5f1f19f89 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/fcntl.h>
 
 #include <cluster/masklog.h>
index 64e6ddcfe329a85a329e587b83a7bd610ea18be2..05d4414d0c33f0e67bdfca0a34cc06945234ee80 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <linux/module.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/miscdevice.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
index 82c1a28b330897661229b6539a2befc031a6d0ce..9b1c08298a07b853a6642e6ef0b893baa51fb886 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -33,6 +33,7 @@
 #include <linux/dnotify.h>
 #include <linux/compat.h>
 #include <linux/mnt_idmapping.h>
+#include <linux/filelock.h>
 
 #include "internal.h"
 
index 167fa43b24f9a060a4603dbb2013d78bce5668b4..4ecb91a9bbebe4d4ed9a625735ef4864e775392d 100644 (file)
@@ -14,6 +14,7 @@
 #include "orangefs-kernel.h"
 #include "orangefs-bufmap.h"
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/pagemap.h>
 
 static int flush_racache(struct inode *inode)
index d7bc81fc084095c0415b08d5534dbe7581c5ddfb..d2271431f344248da3f30e8c344f680a28ed01fc 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/security.h>
 #include <linux/evm.h>
 #include <linux/fsnotify.h>
+#include <linux/filelock.h>
 
 #include "internal.h"
 
index fc46d6fe080c599fc5c68114b4962cd3ee11dab1..53e4919ef860b7a0da32ade8cadb55bdf4414895 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/file.h>
 #include <linux/seq_file.h>
 #include <linux/fs.h>
+#include <linux/filelock.h>
 
 #include <linux/proc_fs.h>
 
index 39f3560176359091a044a93e24096ef55b40fc76..00499e4ba9559357f56f99b33e7e9774ec1d5db6 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/uaccess.h>
 #include <linux/compat.h>
 #include <asm/unistd.h>
+#include <linux/filelock.h>
 
 static bool nsec_valid(long nsec)
 {
index adab9a70b53688659889842938059313e6983814..3fead374901bfc238f53e68ec2a5dd858ba1d63d 100644 (file)
@@ -9,6 +9,7 @@
   Copyright (c) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
  */
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/slab.h>
 #include <linux/file.h>
 #include <linux/xattr.h>
index f9878021e7d07dd4a4f06269d847eee14f20a0b8..e88f18f85e4b4f74559ef4930b4375ca7ff51236 100644 (file)
@@ -34,6 +34,7 @@ typedef __u32                 xfs_nlink_t;
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/file.h>
+#include <linux/filelock.h>
 #include <linux/swap.h>
 #include <linux/errno.h>
 #include <linux/sched/signal.h>
diff --git a/include/linux/filelock.h b/include/linux/filelock.h
new file mode 100644 (file)
index 0000000..dc5056a
--- /dev/null
@@ -0,0 +1,441 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_FILELOCK_H
+#define _LINUX_FILELOCK_H
+
+#include <linux/fs.h>
+
+#define FL_POSIX       1
+#define FL_FLOCK       2
+#define FL_DELEG       4       /* NFSv4 delegation */
+#define FL_ACCESS      8       /* not trying to lock, just looking */
+#define FL_EXISTS      16      /* when unlocking, test for existence */
+#define FL_LEASE       32      /* lease held on this file */
+#define FL_CLOSE       64      /* unlock on close */
+#define FL_SLEEP       128     /* A blocking lock */
+#define FL_DOWNGRADE_PENDING   256 /* Lease is being downgraded */
+#define FL_UNLOCK_PENDING      512 /* Lease is being broken */
+#define FL_OFDLCK      1024    /* lock is "owned" by struct file */
+#define FL_LAYOUT      2048    /* outstanding pNFS layout */
+#define FL_RECLAIM     4096    /* reclaiming from a reboot server */
+
+#define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)
+
+/*
+ * Special return value from posix_lock_file() and vfs_lock_file() for
+ * asynchronous locking.
+ */
+#define FILE_LOCK_DEFERRED 1
+
+struct file_lock;
+
+struct file_lock_operations {
+       void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
+       void (*fl_release_private)(struct file_lock *);
+};
+
+struct lock_manager_operations {
+       void *lm_mod_owner;
+       fl_owner_t (*lm_get_owner)(fl_owner_t);
+       void (*lm_put_owner)(fl_owner_t);
+       void (*lm_notify)(struct file_lock *);  /* unblock callback */
+       int (*lm_grant)(struct file_lock *, int);
+       bool (*lm_break)(struct file_lock *);
+       int (*lm_change)(struct file_lock *, int, struct list_head *);
+       void (*lm_setup)(struct file_lock *, void **);
+       bool (*lm_breaker_owns_lease)(struct file_lock *);
+       bool (*lm_lock_expirable)(struct file_lock *cfl);
+       void (*lm_expire_lock)(void);
+};
+
+struct lock_manager {
+       struct list_head list;
+       /*
+        * NFSv4 and up also want opens blocked during the grace period;
+        * NLM doesn't care:
+        */
+       bool block_opens;
+};
+
+struct net;
+void locks_start_grace(struct net *, struct lock_manager *);
+void locks_end_grace(struct lock_manager *);
+bool locks_in_grace(struct net *);
+bool opens_in_grace(struct net *);
+
+/*
+ * struct file_lock has a union that some filesystems use to track
+ * their own private info. The NFS side of things is defined here:
+ */
+#include <linux/nfs_fs_i.h>
+
+/*
+ * struct file_lock represents a generic "file lock". It's used to represent
+ * POSIX byte range locks, BSD (flock) locks, and leases. It's important to
+ * note that the same struct is used to represent both a request for a lock and
+ * the lock itself, but the same object is never used for both.
+ *
+ * FIXME: should we create a separate "struct lock_request" to help distinguish
+ * these two uses?
+ *
+ * The varous i_flctx lists are ordered by:
+ *
+ * 1) lock owner
+ * 2) lock range start
+ * 3) lock range end
+ *
+ * Obviously, the last two criteria only matter for POSIX locks.
+ */
+struct file_lock {
+       struct file_lock *fl_blocker;   /* The lock, that is blocking us */
+       struct list_head fl_list;       /* link into file_lock_context */
+       struct hlist_node fl_link;      /* node in global lists */
+       struct list_head fl_blocked_requests;   /* list of requests with
+                                                * ->fl_blocker pointing here
+                                                */
+       struct list_head fl_blocked_member;     /* node in
+                                                * ->fl_blocker->fl_blocked_requests
+                                                */
+       fl_owner_t fl_owner;
+       unsigned int fl_flags;
+       unsigned char fl_type;
+       unsigned int fl_pid;
+       int fl_link_cpu;                /* what cpu's list is this on? */
+       wait_queue_head_t fl_wait;
+       struct file *fl_file;
+       loff_t fl_start;
+       loff_t fl_end;
+
+       struct fasync_struct *  fl_fasync; /* for lease break notifications */
+       /* for lease breaks: */
+       unsigned long fl_break_time;
+       unsigned long fl_downgrade_time;
+
+       const struct file_lock_operations *fl_ops;      /* Callbacks for filesystems */
+       const struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */
+       union {
+               struct nfs_lock_info    nfs_fl;
+               struct nfs4_lock_info   nfs4_fl;
+               struct {
+                       struct list_head link;  /* link in AFS vnode's pending_locks list */
+                       int state;              /* state of grant or error if -ve */
+                       unsigned int    debug_id;
+               } afs;
+               struct {
+                       struct inode *inode;
+               } ceph;
+       } fl_u;
+} __randomize_layout;
+
+struct file_lock_context {
+       spinlock_t              flc_lock;
+       struct list_head        flc_flock;
+       struct list_head        flc_posix;
+       struct list_head        flc_lease;
+};
+
+#define locks_inode(f) file_inode(f)
+
+#ifdef CONFIG_FILE_LOCKING
+int fcntl_getlk(struct file *, unsigned int, struct flock *);
+int fcntl_setlk(unsigned int, struct file *, unsigned int,
+                       struct flock *);
+
+#if BITS_PER_LONG == 32
+int fcntl_getlk64(struct file *, unsigned int, struct flock64 *);
+int fcntl_setlk64(unsigned int, struct file *, unsigned int,
+                       struct flock64 *);
+#endif
+
+int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
+int fcntl_getlease(struct file *filp);
+
+/* fs/locks.c */
+void locks_free_lock_context(struct inode *inode);
+void locks_free_lock(struct file_lock *fl);
+void locks_init_lock(struct file_lock *);
+struct file_lock * locks_alloc_lock(void);
+void locks_copy_lock(struct file_lock *, struct file_lock *);
+void locks_copy_conflock(struct file_lock *, struct file_lock *);
+void locks_remove_posix(struct file *, fl_owner_t);
+void locks_remove_file(struct file *);
+void locks_release_private(struct file_lock *);
+void posix_test_lock(struct file *, struct file_lock *);
+int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
+int locks_delete_block(struct file_lock *);
+int vfs_test_lock(struct file *, struct file_lock *);
+int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
+int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
+bool vfs_inode_has_locks(struct inode *inode);
+int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
+int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
+void lease_get_mtime(struct inode *, struct timespec64 *time);
+int generic_setlease(struct file *, long, struct file_lock **, void **priv);
+int vfs_setlease(struct file *, long, struct file_lock **, void **);
+int lease_modify(struct file_lock *, int, struct list_head *);
+
+struct notifier_block;
+int lease_register_notifier(struct notifier_block *);
+void lease_unregister_notifier(struct notifier_block *);
+
+struct files_struct;
+void show_fd_locks(struct seq_file *f,
+                        struct file *filp, struct files_struct *files);
+bool locks_owner_has_blockers(struct file_lock_context *flctx,
+                       fl_owner_t owner);
+
+static inline struct file_lock_context *
+locks_inode_context(const struct inode *inode)
+{
+       return smp_load_acquire(&inode->i_flctx);
+}
+
+#else /* !CONFIG_FILE_LOCKING */
+static inline int fcntl_getlk(struct file *file, unsigned int cmd,
+                             struct flock __user *user)
+{
+       return -EINVAL;
+}
+
+static inline int fcntl_setlk(unsigned int fd, struct file *file,
+                             unsigned int cmd, struct flock __user *user)
+{
+       return -EACCES;
+}
+
+#if BITS_PER_LONG == 32
+static inline int fcntl_getlk64(struct file *file, unsigned int cmd,
+                               struct flock64 *user)
+{
+       return -EINVAL;
+}
+
+static inline int fcntl_setlk64(unsigned int fd, struct file *file,
+                               unsigned int cmd, struct flock64 *user)
+{
+       return -EACCES;
+}
+#endif
+static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
+{
+       return -EINVAL;
+}
+
+static inline int fcntl_getlease(struct file *filp)
+{
+       return F_UNLCK;
+}
+
+static inline void
+locks_free_lock_context(struct inode *inode)
+{
+}
+
+static inline void locks_init_lock(struct file_lock *fl)
+{
+       return;
+}
+
+static inline void locks_copy_conflock(struct file_lock *new, struct file_lock *fl)
+{
+       return;
+}
+
+static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl)
+{
+       return;
+}
+
+static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)
+{
+       return;
+}
+
+static inline void locks_remove_file(struct file *filp)
+{
+       return;
+}
+
+static inline void posix_test_lock(struct file *filp, struct file_lock *fl)
+{
+       return;
+}
+
+static inline int posix_lock_file(struct file *filp, struct file_lock *fl,
+                                 struct file_lock *conflock)
+{
+       return -ENOLCK;
+}
+
+static inline int locks_delete_block(struct file_lock *waiter)
+{
+       return -ENOENT;
+}
+
+static inline int vfs_test_lock(struct file *filp, struct file_lock *fl)
+{
+       return 0;
+}
+
+static inline int vfs_lock_file(struct file *filp, unsigned int cmd,
+                               struct file_lock *fl, struct file_lock *conf)
+{
+       return -ENOLCK;
+}
+
+static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
+{
+       return 0;
+}
+
+static inline bool vfs_inode_has_locks(struct inode *inode)
+{
+       return false;
+}
+
+static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
+{
+       return -ENOLCK;
+}
+
+static inline int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
+{
+       return 0;
+}
+
+static inline void lease_get_mtime(struct inode *inode,
+                                  struct timespec64 *time)
+{
+       return;
+}
+
+static inline int generic_setlease(struct file *filp, long arg,
+                                   struct file_lock **flp, void **priv)
+{
+       return -EINVAL;
+}
+
+static inline int vfs_setlease(struct file *filp, long arg,
+                              struct file_lock **lease, void **priv)
+{
+       return -EINVAL;
+}
+
+static inline int lease_modify(struct file_lock *fl, int arg,
+                              struct list_head *dispose)
+{
+       return -EINVAL;
+}
+
+struct files_struct;
+static inline void show_fd_locks(struct seq_file *f,
+                       struct file *filp, struct files_struct *files) {}
+static inline bool locks_owner_has_blockers(struct file_lock_context *flctx,
+                       fl_owner_t owner)
+{
+       return false;
+}
+
+static inline struct file_lock_context *
+locks_inode_context(const struct inode *inode)
+{
+       return NULL;
+}
+
+#endif /* !CONFIG_FILE_LOCKING */
+
+static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
+{
+       return locks_lock_inode_wait(locks_inode(filp), fl);
+}
+
+#ifdef CONFIG_FILE_LOCKING
+static inline int break_lease(struct inode *inode, unsigned int mode)
+{
+       /*
+        * Since this check is lockless, we must ensure that any refcounts
+        * taken are done before checking i_flctx->flc_lease. Otherwise, we
+        * could end up racing with tasks trying to set a new lease on this
+        * file.
+        */
+       smp_mb();
+       if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
+               return __break_lease(inode, mode, FL_LEASE);
+       return 0;
+}
+
+static inline int break_deleg(struct inode *inode, unsigned int mode)
+{
+       /*
+        * Since this check is lockless, we must ensure that any refcounts
+        * taken are done before checking i_flctx->flc_lease. Otherwise, we
+        * could end up racing with tasks trying to set a new lease on this
+        * file.
+        */
+       smp_mb();
+       if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
+               return __break_lease(inode, mode, FL_DELEG);
+       return 0;
+}
+
+static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
+{
+       int ret;
+
+       ret = break_deleg(inode, O_WRONLY|O_NONBLOCK);
+       if (ret == -EWOULDBLOCK && delegated_inode) {
+               *delegated_inode = inode;
+               ihold(inode);
+       }
+       return ret;
+}
+
+static inline int break_deleg_wait(struct inode **delegated_inode)
+{
+       int ret;
+
+       ret = break_deleg(*delegated_inode, O_WRONLY);
+       iput(*delegated_inode);
+       *delegated_inode = NULL;
+       return ret;
+}
+
+static inline int break_layout(struct inode *inode, bool wait)
+{
+       smp_mb();
+       if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
+               return __break_lease(inode,
+                               wait ? O_WRONLY : O_WRONLY | O_NONBLOCK,
+                               FL_LAYOUT);
+       return 0;
+}
+
+#else /* !CONFIG_FILE_LOCKING */
+static inline int break_lease(struct inode *inode, unsigned int mode)
+{
+       return 0;
+}
+
+static inline int break_deleg(struct inode *inode, unsigned int mode)
+{
+       return 0;
+}
+
+static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
+{
+       return 0;
+}
+
+static inline int break_deleg_wait(struct inode **delegated_inode)
+{
+       BUG();
+       return 0;
+}
+
+static inline int break_layout(struct inode *inode, bool wait)
+{
+       return 0;
+}
+
+#endif /* CONFIG_FILE_LOCKING */
+
+#endif /* _LINUX_FILELOCK_H */
index c1769a2c5d7082858e3fac64b261b5e5244d9b01..006278d84d2fd473a438ef12615e5a308c79725b 100644 (file)
@@ -1003,135 +1003,11 @@ static inline struct file *get_file(struct file *f)
 #define MAX_LFS_FILESIZE       ((loff_t)LLONG_MAX)
 #endif
 
-#define FL_POSIX       1
-#define FL_FLOCK       2
-#define FL_DELEG       4       /* NFSv4 delegation */
-#define FL_ACCESS      8       /* not trying to lock, just looking */
-#define FL_EXISTS      16      /* when unlocking, test for existence */
-#define FL_LEASE       32      /* lease held on this file */
-#define FL_CLOSE       64      /* unlock on close */
-#define FL_SLEEP       128     /* A blocking lock */
-#define FL_DOWNGRADE_PENDING   256 /* Lease is being downgraded */
-#define FL_UNLOCK_PENDING      512 /* Lease is being broken */
-#define FL_OFDLCK      1024    /* lock is "owned" by struct file */
-#define FL_LAYOUT      2048    /* outstanding pNFS layout */
-#define FL_RECLAIM     4096    /* reclaiming from a reboot server */
-
-#define FL_CLOSE_POSIX (FL_POSIX | FL_CLOSE)
-
-/*
- * Special return value from posix_lock_file() and vfs_lock_file() for
- * asynchronous locking.
- */
-#define FILE_LOCK_DEFERRED 1
-
 /* legacy typedef, should eventually be removed */
 typedef void *fl_owner_t;
 
 struct file_lock;
 
-struct file_lock_operations {
-       void (*fl_copy_lock)(struct file_lock *, struct file_lock *);
-       void (*fl_release_private)(struct file_lock *);
-};
-
-struct lock_manager_operations {
-       void *lm_mod_owner;
-       fl_owner_t (*lm_get_owner)(fl_owner_t);
-       void (*lm_put_owner)(fl_owner_t);
-       void (*lm_notify)(struct file_lock *);  /* unblock callback */
-       int (*lm_grant)(struct file_lock *, int);
-       bool (*lm_break)(struct file_lock *);
-       int (*lm_change)(struct file_lock *, int, struct list_head *);
-       void (*lm_setup)(struct file_lock *, void **);
-       bool (*lm_breaker_owns_lease)(struct file_lock *);
-       bool (*lm_lock_expirable)(struct file_lock *cfl);
-       void (*lm_expire_lock)(void);
-};
-
-struct lock_manager {
-       struct list_head list;
-       /*
-        * NFSv4 and up also want opens blocked during the grace period;
-        * NLM doesn't care:
-        */
-       bool block_opens;
-};
-
-struct net;
-void locks_start_grace(struct net *, struct lock_manager *);
-void locks_end_grace(struct lock_manager *);
-bool locks_in_grace(struct net *);
-bool opens_in_grace(struct net *);
-
-/* that will die - we need it for nfs_lock_info */
-#include <linux/nfs_fs_i.h>
-
-/*
- * struct file_lock represents a generic "file lock". It's used to represent
- * POSIX byte range locks, BSD (flock) locks, and leases. It's important to
- * note that the same struct is used to represent both a request for a lock and
- * the lock itself, but the same object is never used for both.
- *
- * FIXME: should we create a separate "struct lock_request" to help distinguish
- * these two uses?
- *
- * The varous i_flctx lists are ordered by:
- *
- * 1) lock owner
- * 2) lock range start
- * 3) lock range end
- *
- * Obviously, the last two criteria only matter for POSIX locks.
- */
-struct file_lock {
-       struct file_lock *fl_blocker;   /* The lock, that is blocking us */
-       struct list_head fl_list;       /* link into file_lock_context */
-       struct hlist_node fl_link;      /* node in global lists */
-       struct list_head fl_blocked_requests;   /* list of requests with
-                                                * ->fl_blocker pointing here
-                                                */
-       struct list_head fl_blocked_member;     /* node in
-                                                * ->fl_blocker->fl_blocked_requests
-                                                */
-       fl_owner_t fl_owner;
-       unsigned int fl_flags;
-       unsigned char fl_type;
-       unsigned int fl_pid;
-       int fl_link_cpu;                /* what cpu's list is this on? */
-       wait_queue_head_t fl_wait;
-       struct file *fl_file;
-       loff_t fl_start;
-       loff_t fl_end;
-
-       struct fasync_struct *  fl_fasync; /* for lease break notifications */
-       /* for lease breaks: */
-       unsigned long fl_break_time;
-       unsigned long fl_downgrade_time;
-
-       const struct file_lock_operations *fl_ops;      /* Callbacks for filesystems */
-       const struct lock_manager_operations *fl_lmops; /* Callbacks for lockmanagers */
-       union {
-               struct nfs_lock_info    nfs_fl;
-               struct nfs4_lock_info   nfs4_fl;
-               struct {
-                       struct list_head link;  /* link in AFS vnode's pending_locks list */
-                       int state;              /* state of grant or error if -ve */
-                       unsigned int    debug_id;
-               } afs;
-               struct {
-                       struct inode *inode;
-               } ceph;
-       } fl_u;
-} __randomize_layout;
-
-struct file_lock_context {
-       spinlock_t              flc_lock;
-       struct list_head        flc_flock;
-       struct list_head        flc_posix;
-       struct list_head        flc_lease;
-};
-
 /* The following constant reflects the upper bound of the file/locking space */
 #ifndef OFFSET_MAX
 #define OFFSET_MAX     type_max(loff_t)
@@ -1140,216 +1016,6 @@ struct file_lock_context {
 
 extern void send_sigio(struct fown_struct *fown, int fd, int band);
 
-#define locks_inode(f) file_inode(f)
-
-#ifdef CONFIG_FILE_LOCKING
-extern int fcntl_getlk(struct file *, unsigned int, struct flock *);
-extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
-                       struct flock *);
-
-#if BITS_PER_LONG == 32
-extern int fcntl_getlk64(struct file *, unsigned int, struct flock64 *);
-extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
-                       struct flock64 *);
-#endif
-
-extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
-extern int fcntl_getlease(struct file *filp);
-
-/* fs/locks.c */
-void locks_free_lock_context(struct inode *inode);
-void locks_free_lock(struct file_lock *fl);
-extern void locks_init_lock(struct file_lock *);
-extern struct file_lock * locks_alloc_lock(void);
-extern void locks_copy_lock(struct file_lock *, struct file_lock *);
-extern void locks_copy_conflock(struct file_lock *, struct file_lock *);
-extern void locks_remove_posix(struct file *, fl_owner_t);
-extern void locks_remove_file(struct file *);
-extern void locks_release_private(struct file_lock *);
-extern void posix_test_lock(struct file *, struct file_lock *);
-extern int posix_lock_file(struct file *, struct file_lock *, struct file_lock *);
-extern int locks_delete_block(struct file_lock *);
-extern int vfs_test_lock(struct file *, struct file_lock *);
-extern int vfs_lock_file(struct file *, unsigned int, struct file_lock *, struct file_lock *);
-extern int vfs_cancel_lock(struct file *filp, struct file_lock *fl);
-bool vfs_inode_has_locks(struct inode *inode);
-extern int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl);
-extern int __break_lease(struct inode *inode, unsigned int flags, unsigned int type);
-extern void lease_get_mtime(struct inode *, struct timespec64 *time);
-extern int generic_setlease(struct file *, long, struct file_lock **, void **priv);
-extern int vfs_setlease(struct file *, long, struct file_lock **, void **);
-extern int lease_modify(struct file_lock *, int, struct list_head *);
-
-struct notifier_block;
-extern int lease_register_notifier(struct notifier_block *);
-extern void lease_unregister_notifier(struct notifier_block *);
-
-struct files_struct;
-extern void show_fd_locks(struct seq_file *f,
-                        struct file *filp, struct files_struct *files);
-extern bool locks_owner_has_blockers(struct file_lock_context *flctx,
-                       fl_owner_t owner);
-
-static inline struct file_lock_context *
-locks_inode_context(const struct inode *inode)
-{
-       return smp_load_acquire(&inode->i_flctx);
-}
-
-#else /* !CONFIG_FILE_LOCKING */
-static inline int fcntl_getlk(struct file *file, unsigned int cmd,
-                             struct flock __user *user)
-{
-       return -EINVAL;
-}
-
-static inline int fcntl_setlk(unsigned int fd, struct file *file,
-                             unsigned int cmd, struct flock __user *user)
-{
-       return -EACCES;
-}
-
-#if BITS_PER_LONG == 32
-static inline int fcntl_getlk64(struct file *file, unsigned int cmd,
-                               struct flock64 *user)
-{
-       return -EINVAL;
-}
-
-static inline int fcntl_setlk64(unsigned int fd, struct file *file,
-                               unsigned int cmd, struct flock64 *user)
-{
-       return -EACCES;
-}
-#endif
-static inline int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
-{
-       return -EINVAL;
-}
-
-static inline int fcntl_getlease(struct file *filp)
-{
-       return F_UNLCK;
-}
-
-static inline void
-locks_free_lock_context(struct inode *inode)
-{
-}
-
-static inline void locks_init_lock(struct file_lock *fl)
-{
-       return;
-}
-
-static inline void locks_copy_conflock(struct file_lock *new, struct file_lock *fl)
-{
-       return;
-}
-
-static inline void locks_copy_lock(struct file_lock *new, struct file_lock *fl)
-{
-       return;
-}
-
-static inline void locks_remove_posix(struct file *filp, fl_owner_t owner)
-{
-       return;
-}
-
-static inline void locks_remove_file(struct file *filp)
-{
-       return;
-}
-
-static inline void posix_test_lock(struct file *filp, struct file_lock *fl)
-{
-       return;
-}
-
-static inline int posix_lock_file(struct file *filp, struct file_lock *fl,
-                                 struct file_lock *conflock)
-{
-       return -ENOLCK;
-}
-
-static inline int locks_delete_block(struct file_lock *waiter)
-{
-       return -ENOENT;
-}
-
-static inline int vfs_test_lock(struct file *filp, struct file_lock *fl)
-{
-       return 0;
-}
-
-static inline int vfs_lock_file(struct file *filp, unsigned int cmd,
-                               struct file_lock *fl, struct file_lock *conf)
-{
-       return -ENOLCK;
-}
-
-static inline int vfs_cancel_lock(struct file *filp, struct file_lock *fl)
-{
-       return 0;
-}
-
-static inline bool vfs_inode_has_locks(struct inode *inode)
-{
-       return false;
-}
-
-static inline int locks_lock_inode_wait(struct inode *inode, struct file_lock *fl)
-{
-       return -ENOLCK;
-}
-
-static inline int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
-{
-       return 0;
-}
-
-static inline void lease_get_mtime(struct inode *inode,
-                                  struct timespec64 *time)
-{
-       return;
-}
-
-static inline int generic_setlease(struct file *filp, long arg,
-                                   struct file_lock **flp, void **priv)
-{
-       return -EINVAL;
-}
-
-static inline int vfs_setlease(struct file *filp, long arg,
-                              struct file_lock **lease, void **priv)
-{
-       return -EINVAL;
-}
-
-static inline int lease_modify(struct file_lock *fl, int arg,
-                              struct list_head *dispose)
-{
-       return -EINVAL;
-}
-
-struct files_struct;
-static inline void show_fd_locks(struct seq_file *f,
-                       struct file *filp, struct files_struct *files) {}
-static inline bool locks_owner_has_blockers(struct file_lock_context *flctx,
-                       fl_owner_t owner)
-{
-       return false;
-}
-
-static inline struct file_lock_context *
-locks_inode_context(const struct inode *inode)
-{
-       return NULL;
-}
-
-#endif /* !CONFIG_FILE_LOCKING */
-
 static inline struct inode *file_inode(const struct file *f)
 {
        return f->f_inode;
@@ -1360,11 +1026,6 @@ static inline struct dentry *file_dentry(const struct file *file)
        return d_real(file->f_path.dentry, file_inode(file));
 }
 
-static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
-{
-       return locks_lock_inode_wait(locks_inode(filp), fl);
-}
-
 struct fasync_struct {
        rwlock_t                fa_lock;
        int                     magic;
@@ -2624,96 +2285,6 @@ extern struct kobject *fs_kobj;
 
 #define MAX_RW_COUNT (INT_MAX & PAGE_MASK)
 
-#ifdef CONFIG_FILE_LOCKING
-static inline int break_lease(struct inode *inode, unsigned int mode)
-{
-       /*
-        * Since this check is lockless, we must ensure that any refcounts
-        * taken are done before checking i_flctx->flc_lease. Otherwise, we
-        * could end up racing with tasks trying to set a new lease on this
-        * file.
-        */
-       smp_mb();
-       if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
-               return __break_lease(inode, mode, FL_LEASE);
-       return 0;
-}
-
-static inline int break_deleg(struct inode *inode, unsigned int mode)
-{
-       /*
-        * Since this check is lockless, we must ensure that any refcounts
-        * taken are done before checking i_flctx->flc_lease. Otherwise, we
-        * could end up racing with tasks trying to set a new lease on this
-        * file.
-        */
-       smp_mb();
-       if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
-               return __break_lease(inode, mode, FL_DELEG);
-       return 0;
-}
-
-static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
-{
-       int ret;
-
-       ret = break_deleg(inode, O_WRONLY|O_NONBLOCK);
-       if (ret == -EWOULDBLOCK && delegated_inode) {
-               *delegated_inode = inode;
-               ihold(inode);
-       }
-       return ret;
-}
-
-static inline int break_deleg_wait(struct inode **delegated_inode)
-{
-       int ret;
-
-       ret = break_deleg(*delegated_inode, O_WRONLY);
-       iput(*delegated_inode);
-       *delegated_inode = NULL;
-       return ret;
-}
-
-static inline int break_layout(struct inode *inode, bool wait)
-{
-       smp_mb();
-       if (inode->i_flctx && !list_empty_careful(&inode->i_flctx->flc_lease))
-               return __break_lease(inode,
-                               wait ? O_WRONLY : O_WRONLY | O_NONBLOCK,
-                               FL_LAYOUT);
-       return 0;
-}
-
-#else /* !CONFIG_FILE_LOCKING */
-static inline int break_lease(struct inode *inode, unsigned int mode)
-{
-       return 0;
-}
-
-static inline int break_deleg(struct inode *inode, unsigned int mode)
-{
-       return 0;
-}
-
-static inline int try_break_deleg(struct inode *inode, struct inode **delegated_inode)
-{
-       return 0;
-}
-
-static inline int break_deleg_wait(struct inode **delegated_inode)
-{
-       BUG();
-       return 0;
-}
-
-static inline int break_layout(struct inode *inode, bool wait)
-{
-       return 0;
-}
-
-#endif /* CONFIG_FILE_LOCKING */
-
 /* fs/open.c */
 struct audit_names;
 struct filename {
index 67e4a2c5500bdf93da2773c0252af0a7e00686df..b60fbcd8cdfad5a5e607eb0c456e3afd559e0ec2 100644 (file)
@@ -11,6 +11,7 @@
 #define LOCKD_XDR_H
 
 #include <linux/fs.h>
+#include <linux/filelock.h>
 #include <linux/nfs.h>
 #include <linux/sunrpc/xdr.h>