mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-06-21 15:43:21 +02:00
7e0e7bd60d
Pull misc vfs updates from Christian Brauner:
"Features:
- Reduce pipe->mutex contention by pre-allocating pages outside the
lock in anon_pipe_write().
anon_pipe_write() called alloc_page() once per page while holding
pipe->mutex. The allocation can sleep doing direct reclaim and runs
memcg charging, which extends the critical section and stalls any
concurrent reader on the same mutex. Now up to 8 pages are
pre-allocated before the mutex is taken, leftovers are recycled
into the per-pipe tmp_page[] cache before unlock, and any remainder
is released after unlock, keeping the allocator out of the critical
section on both sides. On a writers x readers sweep with 64KB
writes against a 1 MB pipe throughput improves 6-28% and average
write latency drops 5-22%; under memory pressure - when the cost of
holding the mutex across reclaim is highest - throughput improves
21-48% and latency drops 17-33%. The microbenchmark is added to
selftests.
- uaccess/sockptr: fix the ignored_trailing logic in
copy_struct_to_user() to behave as documented and the usize check
in copy_struct_from_sockptr() for user pointers, and add
copy_struct_{from,to}_bounce_buffer() and copy_struct_to_sockptr()
helpers for upcoming users (IPPROTO_SMBDIRECT, IPPROTO_QUIC).
- bpf: add a sleepable bpf_real_inode() kfunc that resolves the real
inode backing a dentry via d_real_inode(). On overlayfs the inode
attached to the dentry doesn't carry the underlying device
information; this is used by the filesystem restriction BPF program
that was merged into systemd.
- docs: add guidelines for submitting new filesystems, motivated by
the maintenance burden abandoned and untestable filesystems impose
on VFS developers, blocking infrastructure work like folio
conversions and iomap migration.
Fixes:
- libfs: set SB_I_NOEXEC and SB_I_NODEV by default in init_pseudo()
and drop the now-redundant assignments in callers. This began as a
one-line dma-buf fix for a path_noexec() warning; a pseudo
filesystem has no reason not to set SB_I_NOEXEC. All init_pseudo()
callers were audited: the only visible effect is on dma-buf where
SB_I_NOEXEC silences the warning.
- Handle set_blocksize() failures in legacy filesystems (bfs, hpfs,
qnx4, jfs, befs, affs, isofs, minix, ntfs3, omfs). Mounting a
device with a sector size > PAGE_SIZE crashed roughly half of them;
the rest had the same missing error handling pattern. Plus a
follow-up releasing the superblock buffer_head when setting the
minix v3 block size fails.
- mount: honour SB_NOUSER in the new mount API.
- fs/fcntl: fix a SOFTIRQ-unsafe lock order in fasync signaling by
switching the process-group paths of send_sigio() and send_sigurg()
from read_lock(&tasklist_lock) to RCU, matching the single-PID
path.
- vfs: add an FS_USERNS_DELEGATABLE flag and set it for NFS, fixing
delegated NFS mounts (fsopen() in a container with the mount
performed by a privileged daemon) that broke when non-init
s_user_ns was tied to FS_USERNS_MOUNT.
- selftests/namespaces: fix a hang in nsid_test where an unreaped
grandchild kept the TAP pipe write-end open, a waitpid(-1) race in
listns_efault_test, and a false FAIL on kernels without listns()
where the tests should SKIP.
- filelock: fix the break_lease() stub signature for
CONFIG_FILE_LOCKING=n.
- init/initramfs_test: wait for the async initramfs unpacking before
running; the test and do_populate_rootfs() share the parser state.
- fs/coredump: reduce redundant log noise in
validate_coredump_safety().
- iomap: pass the correct length to fserror_report_io() in
__iomap_write_begin().
- backing-file: fix the backing_file_open() kerneldoc.
Cleanups:
- initramfs: refactor the cpio hex header parsing to use hex2bin()
instead of the hand-rolled simple_strntoul() which is reverted, and
extend the initramfs KUnit tests to cover header fields with 0x
prefixes.
- Replace __get_free_pages() and friends with kmalloc()/kzalloc()
across quota, proc, ocfs2/dlm, nilfs2, nfs, nfsd, libfs, jfs, jbd2,
isofs, fuse, select, namespace, configfs, binfmt_misc, bfs, and the
do_mounts init code - part of the larger work of replacing page
allocator calls with kmalloc().
- Use clear_and_wake_up_bit() in unlock_buffer() and
journal_end_buffer_io_sync() instead of open-coding the sequence.
- Drop unused VFS exports: unexport drop_super_exclusive(), remove
start_removing_user_path_at(), and fold __start_removing_path()
into start_removing_path().
- fs/read_write: narrow the __kernel_write() export with
EXPORT_SYMBOL_FOR_MODULES().
- vfs: uapi: retire octal and hex constants in favor of (1 << n) for
the O_ flags. Finding a free bit for a new flag across the
architectures was needlessly hard with the mixed bases.
- dcache: add extra sanity checks of dead dentries in dentry_free()
via a new DENTRY_WARN_ONCE() that also prints d_flags.
- iov_iter: use kmemdup_array() in dup_iter() to harden the
allocation against multiplication overflow.
- fs/pipe: write to ->poll_usage only once.
- vfs: remove an always-taken if-branch in find_next_fd().
- dcache: use kmalloc_flex() for struct external_name in __d_alloc().
- namei: use QSTR() instead of QSTR_INIT() in path_pts().
- sync_file_range: delete dead S_ISLNK code.
- Comment fixes: retire a stale comment in fget_task_next() and fix
assorted spelling mistakes"
* tag 'vfs-7.2-rc1.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: (73 commits)
backing-file: fix backing_file_open() kerneldoc parameter
iomap: pass the correct len to fserror_report_io in __iomap_write_begin
vfs: add FS_USERNS_DELEGATABLE flag and set it for NFS
filelock: fix break_lease() stub signature for CONFIG_FILE_LOCKING=n
vfs: uapi: retire octal and hex numbers in favor of (1 << n) for O_ flags
bpf: add bpf_real_inode() kfunc
fs/read_write: Do not export __kernel_write() to the entire world
libfs: drop redundant SB_I_NOEXEC/SB_I_NODEV in init_pseudo() callers
libfs: set SB_I_NOEXEC and SB_I_NODEV by default in init_pseudo()
mount: honour SB_NOUSER in the new mount API
fs/fcntl: fix SOFTIRQ-unsafe lock order in fasync signaling
selftests/pipe: add pipe_bench microbenchmark
fs/pipe: pre-allocate pages outside pipe->mutex in anon_pipe_write
fs: retire stale comment in fget_task_next()
fs: fix spelling mistakes in comment
bfs: replace get_zeroed_page() with kzalloc()
binfmt_misc: replace __get_free_page() with kmalloc()
configfs: replace __get_free_pages() with kzalloc()
fs/namespace: use __getname() to allocate mntpath buffer
fs/select: replace __get_free_page() with kmalloc()
...
617 lines
16 KiB
C
617 lines
16 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_FILELOCK_H
|
|
#define _LINUX_FILELOCK_H
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#define FL_POSIX BIT(0) /* POSIX lock */
|
|
#define FL_FLOCK BIT(1) /* BSD lock */
|
|
#define FL_DELEG BIT(2) /* NFSv4 delegation */
|
|
#define FL_ACCESS BIT(3) /* not trying to lock, just looking */
|
|
#define FL_EXISTS BIT(4) /* when unlocking, test for existence */
|
|
#define FL_LEASE BIT(5) /* file lease */
|
|
#define FL_CLOSE BIT(6) /* unlock on close */
|
|
#define FL_SLEEP BIT(7) /* A blocking lock */
|
|
#define FL_DOWNGRADE_PENDING BIT(8) /* Lease is being downgraded */
|
|
#define FL_UNLOCK_PENDING BIT(9) /* Lease is being broken */
|
|
#define FL_OFDLCK BIT(10) /* POSIX lock "owned" by struct file */
|
|
#define FL_LAYOUT BIT(11) /* outstanding pNFS layout */
|
|
#define FL_RECLAIM BIT(12) /* reclaiming from a reboot server */
|
|
#define FL_IGN_DIR_CREATE BIT(13) /* ignore DIR_CREATE events */
|
|
#define FL_IGN_DIR_DELETE BIT(14) /* ignore DIR_DELETE events */
|
|
#define FL_IGN_DIR_RENAME BIT(15) /* ignore DIR_RENAME events */
|
|
|
|
#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
|
|
|
|
#define LEASE_BREAK_LEASE BIT(0) // break leases and delegations
|
|
#define LEASE_BREAK_DELEG BIT(1) // break delegations only
|
|
#define LEASE_BREAK_LAYOUT BIT(2) // break layouts only
|
|
#define LEASE_BREAK_NONBLOCK BIT(3) // non-blocking break
|
|
#define LEASE_BREAK_OPEN_RDONLY BIT(4) // readonly open event
|
|
#define LEASE_BREAK_DIR_CREATE BIT(5) // dir deleg create event
|
|
#define LEASE_BREAK_DIR_DELETE BIT(6) // dir deleg delete event
|
|
#define LEASE_BREAK_DIR_RENAME BIT(7) // dir deleg rename event
|
|
|
|
struct file_lock;
|
|
struct file_lease;
|
|
|
|
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_lock_expirable)(struct file_lock *cfl);
|
|
void (*lm_expire_lock)(void);
|
|
};
|
|
|
|
struct lease_manager_operations {
|
|
bool (*lm_break)(struct file_lease *);
|
|
int (*lm_change)(struct file_lease *, int, struct list_head *);
|
|
void (*lm_setup)(struct file_lease *, void **);
|
|
bool (*lm_breaker_owns_lease)(struct file_lease *);
|
|
int (*lm_open_conflict)(struct file *, int);
|
|
bool (*lm_breaker_timedout)(struct file_lease *fl);
|
|
};
|
|
|
|
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_core {
|
|
struct file_lock_core *flc_blocker; /* The lock that is blocking us */
|
|
struct list_head flc_list; /* link into file_lock_context */
|
|
struct hlist_node flc_link; /* node in global lists */
|
|
struct list_head flc_blocked_requests; /* list of requests with
|
|
* ->fl_blocker pointing here
|
|
*/
|
|
struct list_head flc_blocked_member; /* node in
|
|
* ->fl_blocker->fl_blocked_requests
|
|
*/
|
|
fl_owner_t flc_owner;
|
|
unsigned int flc_flags;
|
|
unsigned char flc_type;
|
|
pid_t flc_pid;
|
|
int flc_link_cpu; /* what cpu's list is this on? */
|
|
wait_queue_head_t flc_wait;
|
|
struct file *flc_file;
|
|
};
|
|
|
|
struct file_lock {
|
|
struct file_lock_core c;
|
|
loff_t fl_start;
|
|
loff_t fl_end;
|
|
|
|
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_lease {
|
|
struct file_lock_core c;
|
|
struct fasync_struct * fl_fasync; /* for lease break notifications */
|
|
/* for lease breaks: */
|
|
unsigned long fl_break_time;
|
|
unsigned long fl_downgrade_time;
|
|
const struct lease_manager_operations *fl_lmops; /* Callbacks for lease managers */
|
|
} __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;
|
|
};
|
|
|
|
#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, int arg);
|
|
int fcntl_getlease(struct file *filp);
|
|
int fcntl_setdeleg(unsigned int fd, struct file *filp, struct delegation *deleg);
|
|
int fcntl_getdeleg(struct file *filp, struct delegation *deleg);
|
|
|
|
static inline bool lock_is_unlock(struct file_lock *fl)
|
|
{
|
|
return fl->c.flc_type == F_UNLCK;
|
|
}
|
|
|
|
static inline bool lock_is_read(struct file_lock *fl)
|
|
{
|
|
return fl->c.flc_type == F_RDLCK;
|
|
}
|
|
|
|
static inline bool lock_is_write(struct file_lock *fl)
|
|
{
|
|
return fl->c.flc_type == F_WRLCK;
|
|
}
|
|
|
|
static inline void locks_wake_up_waiter(struct file_lock_core *flc)
|
|
{
|
|
wake_up(&flc->flc_wait);
|
|
}
|
|
|
|
static inline void locks_wake_up(struct file_lock *fl)
|
|
{
|
|
locks_wake_up_waiter(&fl->c);
|
|
}
|
|
|
|
static inline bool locks_can_async_lock(const struct file_operations *fops)
|
|
{
|
|
return !fops->lock || fops->fop_flags & FOP_ASYNC_LOCK;
|
|
}
|
|
|
|
/* 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);
|
|
|
|
void locks_init_lease(struct file_lease *);
|
|
void locks_free_lease(struct file_lease *fl);
|
|
struct file_lease *locks_alloc_lease(void);
|
|
int __break_lease(struct inode *inode, unsigned int flags);
|
|
void lease_get_mtime(struct inode *, struct timespec64 *time);
|
|
int generic_setlease(struct file *, int, struct file_lease **, void **priv);
|
|
int kernel_setlease(struct file *, int, struct file_lease **, void **);
|
|
int vfs_setlease(struct file *, int, struct file_lease **, void **);
|
|
int lease_modify(struct file_lease *, int, struct list_head *);
|
|
u32 inode_lease_ignore_mask(struct inode *inode);
|
|
|
|
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)
|
|
{
|
|
/*
|
|
* Paired with smp_store_release in locks_get_lock_context().
|
|
*
|
|
* Ensures ->i_flctx will be visible if we spotted the flag.
|
|
*/
|
|
if (likely(!(smp_load_acquire(&inode->i_opflags) & IOP_FLCTX)))
|
|
return NULL;
|
|
return READ_ONCE(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, int arg)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int fcntl_getlease(struct file *filp)
|
|
{
|
|
return F_UNLCK;
|
|
}
|
|
|
|
static inline int fcntl_setdeleg(unsigned int fd, struct file *filp, struct delegation *deleg)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int fcntl_getdeleg(struct file *filp, struct delegation *deleg)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline bool lock_is_unlock(struct file_lock *fl)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline bool lock_is_read(struct file_lock *fl)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline bool lock_is_write(struct file_lock *fl)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline void locks_wake_up(struct file_lock *fl)
|
|
{
|
|
}
|
|
|
|
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_init_lease(struct file_lease *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 flags)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline void lease_get_mtime(struct inode *inode,
|
|
struct timespec64 *time)
|
|
{
|
|
return;
|
|
}
|
|
|
|
static inline int generic_setlease(struct file *filp, int arg,
|
|
struct file_lease **flp, void **priv)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int kernel_setlease(struct file *filp, int arg,
|
|
struct file_lease **lease, void **priv)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int vfs_setlease(struct file *filp, int arg,
|
|
struct file_lease **lease, void **priv)
|
|
{
|
|
return -EINVAL;
|
|
}
|
|
|
|
static inline int lease_modify(struct file_lease *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 */
|
|
|
|
/* for walking lists of file_locks linked by fl_list */
|
|
#define for_each_file_lock(_fl, _head) list_for_each_entry(_fl, _head, c.flc_list)
|
|
|
|
static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl)
|
|
{
|
|
return locks_lock_inode_wait(file_inode(filp), fl);
|
|
}
|
|
|
|
#ifdef CONFIG_FILE_LOCKING
|
|
static inline unsigned int openmode_to_lease_flags(unsigned int mode)
|
|
{
|
|
unsigned int flags = 0;
|
|
|
|
if ((mode & O_ACCMODE) == O_RDONLY)
|
|
flags |= LEASE_BREAK_OPEN_RDONLY;
|
|
if (mode & O_NONBLOCK)
|
|
flags |= LEASE_BREAK_NONBLOCK;
|
|
return flags;
|
|
}
|
|
|
|
static inline int break_lease(struct inode *inode, unsigned int mode)
|
|
{
|
|
struct file_lock_context *flctx;
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
flctx = locks_inode_context(inode);
|
|
if (!flctx)
|
|
return 0;
|
|
smp_mb();
|
|
if (!list_empty_careful(&flctx->flc_lease))
|
|
return __break_lease(inode, LEASE_BREAK_LEASE | openmode_to_lease_flags(mode));
|
|
return 0;
|
|
}
|
|
|
|
static inline int break_deleg(struct inode *inode, unsigned int flags)
|
|
{
|
|
struct file_lock_context *flctx;
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
flctx = locks_inode_context(inode);
|
|
if (!flctx)
|
|
return 0;
|
|
smp_mb();
|
|
if (!list_empty_careful(&flctx->flc_lease)) {
|
|
flags |= LEASE_BREAK_DELEG;
|
|
return __break_lease(inode, flags);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
struct delegated_inode {
|
|
struct inode *di_inode;
|
|
};
|
|
|
|
static inline bool is_delegated(struct delegated_inode *di)
|
|
{
|
|
return di->di_inode;
|
|
}
|
|
|
|
/**
|
|
* try_break_deleg - do a non-blocking delegation break
|
|
* @inode: inode that should have its delegations broken
|
|
* @flags: extra LEASE_BREAK_* flags to pass to break_deleg()
|
|
* @di: returns pointer to delegated inode (may be NULL)
|
|
*
|
|
* Break delegations in a non-blocking fashion. If there are
|
|
* outstanding delegations and @di is set, then an extra reference
|
|
* will be taken on @inode and @di->di_inode will be populated so
|
|
* that it may be waited upon.
|
|
*
|
|
* Returns 0 if there is no need to wait or an error. If -EWOULDBLOCK
|
|
* is returned, then @di will be populated (if non-NULL).
|
|
*/
|
|
static inline int try_break_deleg(struct inode *inode, unsigned int flags,
|
|
struct delegated_inode *di)
|
|
{
|
|
int ret;
|
|
|
|
ret = break_deleg(inode, flags | LEASE_BREAK_NONBLOCK);
|
|
if (ret == -EWOULDBLOCK && di) {
|
|
di->di_inode = inode;
|
|
ihold(inode);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
static inline int break_deleg_wait(struct delegated_inode *di)
|
|
{
|
|
int ret;
|
|
|
|
ret = break_deleg(di->di_inode, 0);
|
|
iput(di->di_inode);
|
|
di->di_inode = NULL;
|
|
return ret;
|
|
}
|
|
|
|
static inline int break_layout(struct inode *inode, bool wait)
|
|
{
|
|
struct file_lock_context *flctx;
|
|
|
|
smp_mb();
|
|
flctx = locks_inode_context(inode);
|
|
if (flctx && !list_empty_careful(&flctx->flc_lease)) {
|
|
unsigned int flags = LEASE_BREAK_LAYOUT;
|
|
|
|
if (!wait)
|
|
flags |= LEASE_BREAK_NONBLOCK;
|
|
|
|
return __break_lease(inode, flags);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#else /* !CONFIG_FILE_LOCKING */
|
|
struct delegated_inode { };
|
|
|
|
static inline bool is_delegated(struct delegated_inode *di)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline int break_lease(struct inode *inode, unsigned int mode)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int break_deleg(struct inode *inode, unsigned int flags)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int try_break_deleg(struct inode *inode, unsigned int flags,
|
|
struct delegated_inode *delegated_inode)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static inline int break_deleg_wait(struct delegated_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 */
|