filelock: split common fields into struct file_lock_core

In a future patch, we're going to split file leases into their own
structure. Since a lot of the underlying machinery uses the same fields
move those into a new file_lock_core, and embed that inside struct
file_lock.

For now, add some macros to ensure that we can continue to build while
the conversion is in progress.

Signed-off-by: Jeff Layton <jlayton@kernel.org>
Link: https://lore.kernel.org/r/20240131-flsplit-v3-17-c6129007ee8d@kernel.org
Reviewed-by: NeilBrown <neilb@suse.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
Jeff Layton 2024-01-31 18:01:58 -05:00 committed by Christian Brauner
parent 3d40f78169
commit a69ce85ec9
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
24 changed files with 65 additions and 23 deletions

View File

@ -9,6 +9,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/file.h> #include <linux/file.h>

View File

@ -9,6 +9,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/ktime.h> #include <linux/ktime.h>
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/rxrpc.h> #include <linux/rxrpc.h>

View File

@ -7,6 +7,7 @@
#include "super.h" #include "super.h"
#include "mds_client.h" #include "mds_client.h"
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/ceph/pagelist.h> #include <linux/ceph/pagelist.h>

View File

@ -4,6 +4,7 @@
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/poll.h> #include <linux/poll.h>

View File

@ -18,6 +18,7 @@
#include <linux/falloc.h> #include <linux/falloc.h>
#include <linux/uio.h> #include <linux/uio.h>
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/splice.h> #include <linux/splice.h>

View File

@ -15,6 +15,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/gfs2_ondisk.h> #include <linux/gfs2_ondisk.h>
#include <linux/falloc.h> #include <linux/falloc.h>

View File

@ -12,6 +12,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/nfs_fs.h> #include <linux/nfs_fs.h>
#include <linux/utsname.h> #include <linux/utsname.h>

View File

@ -48,6 +48,7 @@
* children. * children.
* *
*/ */
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/file.h> #include <linux/file.h>

View File

@ -31,6 +31,7 @@
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include "delegation.h" #include "delegation.h"

View File

@ -23,6 +23,7 @@
#define NFS4_MAX_LOOP_ON_RECOVER (10) #define NFS4_MAX_LOOP_ON_RECOVER (10)
#include <linux/seqlock.h> #include <linux/seqlock.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
struct idmap; struct idmap;

View File

@ -25,6 +25,7 @@
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/iversion.h> #include <linux/iversion.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>

View File

@ -10,6 +10,7 @@
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/netns/generic.h> #include <net/netns/generic.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/percpu_counter.h> #include <linux/percpu_counter.h>
#include <linux/siphash.h> #include <linux/siphash.h>

View File

@ -8,6 +8,7 @@
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/fcntl.h> #include <linux/fcntl.h>

View File

@ -9,6 +9,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/mutex.h> #include <linux/mutex.h>

View File

@ -26,6 +26,7 @@
#include <uapi/linux/cifs/cifs_mount.h> #include <uapi/linux/cifs/cifs_mount.h>
#include "../common/smb2pdu.h" #include "../common/smb2pdu.h"
#include "smb2pdu.h" #include "smb2pdu.h"
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#define SMB_PATH_MAX 260 #define SMB_PATH_MAX 260

View File

@ -15,6 +15,7 @@
/* want to reuse a stale file handle and only the caller knows the file info */ /* want to reuse a stale file handle and only the caller knows the file info */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/vfs.h> #include <linux/vfs.h>

View File

@ -9,6 +9,7 @@
* *
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>
#include <linux/stat.h> #include <linux/stat.h>

View File

@ -7,6 +7,7 @@
* *
*/ */
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/slab.h> #include <linux/slab.h>

View File

@ -12,6 +12,7 @@
#include <linux/ethtool.h> #include <linux/ethtool.h>
#include <linux/falloc.h> #include <linux/falloc.h>
#include <linux/mount.h> #include <linux/mount.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include "glob.h" #include "glob.h"

View File

@ -6,6 +6,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/backing-dev.h> #include <linux/backing-dev.h>

View File

@ -85,23 +85,28 @@ bool opens_in_grace(struct net *);
* *
* Obviously, the last two criteria only matter for POSIX locks. * 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 file_lock_core {
struct list_head fl_list; /* link into file_lock_context */ struct file_lock *flc_blocker; /* The lock that is blocking us */
struct hlist_node fl_link; /* node in global lists */ struct list_head flc_list; /* link into file_lock_context */
struct list_head fl_blocked_requests; /* list of requests with struct hlist_node flc_link; /* node in global lists */
struct list_head flc_blocked_requests; /* list of requests with
* ->fl_blocker pointing here * ->fl_blocker pointing here
*/ */
struct list_head fl_blocked_member; /* node in struct list_head flc_blocked_member; /* node in
* ->fl_blocker->fl_blocked_requests * ->fl_blocker->fl_blocked_requests
*/ */
fl_owner_t fl_owner; fl_owner_t flc_owner;
unsigned int fl_flags; unsigned int flc_flags;
unsigned char fl_type; unsigned char flc_type;
pid_t fl_pid; pid_t flc_pid;
int fl_link_cpu; /* what cpu's list is this on? */ int flc_link_cpu; /* what cpu's list is this on? */
wait_queue_head_t fl_wait; wait_queue_head_t flc_wait;
struct file *fl_file; struct file *flc_file;
};
struct file_lock {
struct file_lock_core c;
loff_t fl_start; loff_t fl_start;
loff_t fl_end; loff_t fl_end;
@ -126,6 +131,22 @@ struct file_lock {
} fl_u; } fl_u;
} __randomize_layout; } __randomize_layout;
/* Temporary macros to allow building during coccinelle conversion */
#ifdef _NEED_FILE_LOCK_FIELD_MACROS
#define fl_list c.flc_list
#define fl_blocker c.flc_blocker
#define fl_link c.flc_link
#define fl_blocked_requests c.flc_blocked_requests
#define fl_blocked_member c.flc_blocked_member
#define fl_owner c.flc_owner
#define fl_flags c.flc_flags
#define fl_type c.flc_type
#define fl_pid c.flc_pid
#define fl_link_cpu c.flc_link_cpu
#define fl_wait c.flc_wait
#define fl_file c.flc_file
#endif
struct file_lock_context { struct file_lock_context {
spinlock_t flc_lock; spinlock_t flc_lock;
struct list_head flc_flock; struct list_head flc_flock;
@ -149,26 +170,26 @@ int fcntl_getlease(struct file *filp);
static inline bool lock_is_unlock(struct file_lock *fl) static inline bool lock_is_unlock(struct file_lock *fl)
{ {
return fl->fl_type == F_UNLCK; return fl->c.flc_type == F_UNLCK;
} }
static inline bool lock_is_read(struct file_lock *fl) static inline bool lock_is_read(struct file_lock *fl)
{ {
return fl->fl_type == F_RDLCK; return fl->c.flc_type == F_RDLCK;
} }
static inline bool lock_is_write(struct file_lock *fl) static inline bool lock_is_write(struct file_lock *fl)
{ {
return fl->fl_type == F_WRLCK; return fl->c.flc_type == F_WRLCK;
} }
static inline void locks_wake_up(struct file_lock *fl) static inline void locks_wake_up(struct file_lock *fl)
{ {
wake_up(&fl->fl_wait); wake_up(&fl->c.flc_wait);
} }
/* for walking lists of file_locks linked by fl_list */ /* for walking lists of file_locks linked by fl_list */
#define for_each_file_lock(_fl, _head) list_for_each_entry(_fl, _head, fl_list) #define for_each_file_lock(_fl, _head) list_for_each_entry(_fl, _head, c.flc_list)
/* fs/locks.c */ /* fs/locks.c */
void locks_free_lock_context(struct inode *inode); void locks_free_lock_context(struct inode *inode);

View File

@ -11,6 +11,7 @@
#define LOCKD_XDR_H #define LOCKD_XDR_H
#include <linux/fs.h> #include <linux/fs.h>
#define _NEED_FILE_LOCK_FIELD_MACROS
#include <linux/filelock.h> #include <linux/filelock.h>
#include <linux/nfs.h> #include <linux/nfs.h>
#include <linux/sunrpc/xdr.h> #include <linux/sunrpc/xdr.h>