Linux Kernel
3.7.1
|
#include <linux/capability.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/security.h>
#include <linux/slab.h>
#include <linux/syscalls.h>
#include <linux/time.h>
#include <linux/rcupdate.h>
#include <linux/pid_namespace.h>
#include <asm/uaccess.h>
Go to the source code of this file.
Macros | |
#define | IS_POSIX(fl) (fl->fl_flags & FL_POSIX) |
#define | IS_FLOCK(fl) (fl->fl_flags & FL_FLOCK) |
#define | IS_LEASE(fl) (fl->fl_flags & FL_LEASE) |
#define | for_each_lock(inode, lockp) for (lockp = &inode->i_flock; *lockp != NULL; lockp = &(*lockp)->fl_next) |
#define | MAX_DEADLK_ITERATIONS 10 |
Variables | |
int | leases_enable = 1 |
int | lease_break_time = 45 |
__break_lease - revoke all outstanding leases on file : the inode of the file to return : the open mode (read or write)
break_lease (inlined for speed) has checked there already is at least some kind of lock (maybe a lease) on this file. Leases are broken on a call to open() or truncate(). This function can sleep unless you specified O_NONBLOCK to your open().
core_initcall | ( | filelock_init | ) |
EXPORT_SYMBOL | ( | locks_free_lock | ) |
EXPORT_SYMBOL | ( | locks_init_lock | ) |
EXPORT_SYMBOL | ( | __locks_copy_lock | ) |
EXPORT_SYMBOL | ( | locks_copy_lock | ) |
EXPORT_SYMBOL | ( | locks_delete_block | ) |
EXPORT_SYMBOL | ( | posix_test_lock | ) |
EXPORT_SYMBOL | ( | posix_lock_file | ) |
EXPORT_SYMBOL | ( | posix_lock_file_wait | ) |
EXPORT_SYMBOL | ( | locks_mandatory_area | ) |
EXPORT_SYMBOL | ( | lease_modify | ) |
EXPORT_SYMBOL | ( | __break_lease | ) |
EXPORT_SYMBOL | ( | lease_get_mtime | ) |
EXPORT_SYMBOL | ( | generic_setlease | ) |
EXPORT_SYMBOL | ( | flock_lock_file_wait | ) |
EXPORT_SYMBOL | ( | locks_remove_posix | ) |
EXPORT_SYMBOL | ( | posix_unblock_lock | ) |
EXPORT_SYMBOL | ( | lock_may_read | ) |
EXPORT_SYMBOL | ( | lock_may_write | ) |
EXPORT_SYMBOL_GPL | ( | lock_flocks | ) |
EXPORT_SYMBOL_GPL | ( | unlock_flocks | ) |
EXPORT_SYMBOL_GPL | ( | locks_alloc_lock | ) |
EXPORT_SYMBOL_GPL | ( | locks_release_private | ) |
EXPORT_SYMBOL_GPL | ( | vfs_setlease | ) |
EXPORT_SYMBOL_GPL | ( | vfs_test_lock | ) |
EXPORT_SYMBOL_GPL | ( | vfs_lock_file | ) |
EXPORT_SYMBOL_GPL | ( | vfs_cancel_lock | ) |
fcntl_getlease - Enquire what lease is currently active : the file
The value returned by this function will be one of (if no lease break is pending):
F_RDLCK to indicate a shared lease is held.
F_WRLCK to indicate an exclusive lease is held.
F_UNLCK to indicate no lease is held.
(if a lease break is pending):
F_RDLCK to indicate an exclusive lease needs to be changed to a shared lease (or removed).
F_UNLCK to indicate the lease needs to be removed.
XXX: sfr & willy disagree over whether F_INPROGRESS should be returned to userspace.
lease_get_mtime - get the last modified time of an inode : the inode : pointer to a timespec which will contain the last modified time
This is to force NFS clients to flush their caches for files with exclusive leases. The justification is that if someone has an exclusive lease, then they could be modifying it.
lock_may_read - checks that the region is free of locks : the inode that is being read : the first byte to read : the number of bytes to read
Emulates Windows locking requirements. Whole-file mandatory locks (share modes) can prohibit a read and byte-range POSIX locks can prohibit a read if they overlap.
N.B. this function is only ever called from knfsd and ownership of locks is never checked.
lock_may_write - checks that the region is free of locks : the inode that is being written : the first byte to write : the number of bytes to write
Emulates Windows locking requirements. Whole-file mandatory locks (share modes) can prohibit a write and byte-range POSIX locks can prohibit a write if they overlap.
N.B. this function is only ever called from knfsd and ownership of locks is never checked.
int locks_mandatory_area | ( | int | read_write, |
struct inode * | inode, | ||
struct file * | filp, | ||
loff_t | offset, | ||
size_t | count | ||
) |
locks_mandatory_area - Check for a conflicting lock : FLOCK_VERIFY_WRITE for exclusive access, FLOCK_VERIFY_READ for shared : the file to check : how the file was opened (if it was) : start of area to check : length of area to check
Searches the inode's list of locks to find any POSIX locks which conflict. This function is called from rw_verify_area() and locks_verify_truncate().
void locks_remove_posix | ( | struct file * | filp, |
fl_owner_t | owner | ||
) |
posix_lock_file - Apply a POSIX-style lock to a file : The file to apply the lock to : The lock to be applied : Place to return a copy of the conflicting lock, if found.
Add a POSIX style lock to a file. We merge adjacent & overlapping locks whenever possible. POSIX locks are sorted by owner task, then by starting address
Note that if called with an FL_EXISTS argument, the caller may determine whether or not a lock was successfully freed by testing the return value for -ENOENT.
sys_flock: - flock() system call. : the file descriptor to lock. : the type of lock to apply.
Apply a FL_FLOCK style lock to an open file descriptor. The can be one of
LOCK_SH – a shared lock.
LOCK_EX – an exclusive lock.
LOCK_UN – remove an existing lock.
LOCK_MAND – a `mandatory' flock. This exists to emulate Windows Share Modes.
LOCK_MAND can be combined with LOCK_READ or LOCK_WRITE to allow other processes read and write access respectively.
int vfs_lock_file | ( | struct file * | filp, |
unsigned int | cmd, | ||
struct file_lock * | fl, | ||
struct file_lock * | conf | ||
) |
vfs_lock_file - file byte range lock : The file to apply the lock to : type of locking operation (F_SETLK, F_GETLK, etc.) : The lock to be applied : Place to return a copy of the conflicting lock, if found.
A caller that doesn't care about the conflicting lock may pass NULL as the final argument.
If the filesystem defines a private ->lock() method, then will be left unchanged; so a caller that cares should initialize it to some acceptable default.
To avoid blocking kernel daemons, such as lockd, that need to acquire POSIX locks, the ->lock() interface may return asynchronously, before the lock has been granted or denied by the underlying filesystem, if (and only if) lm_grant is set. Callers expecting ->lock() to return asynchronously will only use F_SETLK, not F_SETLKW; they will set FL_SLEEP if (and only if) the request is for a blocking lock. When ->lock() does return asynchronously, it must return FILE_LOCK_DEFERRED, and call ->lm_grant() when the lock request completes. If the request is for non-blocking lock the file system should return FILE_LOCK_DEFERRED then try to get the lock and call the callback routine with the result. If the request timed out the callback routine will return a nonzero return code and the file system should release the lock. The file system is also responsible to keep a corresponding posix lock when it grants a lock so the VFS can find out which locks are locally held and do the correct lock cleanup when required. The underlying filesystem must not drop the kernel lock or call ->lm_grant() before returning to the caller with a FILE_LOCK_DEFERRED return code.
vfs_setlease - sets a lease on an open file : file pointer
Call this to establish a lease on the file. The (*lease)->fl_lmops->lm_break operation must be set; if not, break_lease will oops!
This will call the filesystem's setlease file method, if defined. Note that there is no getlease method; instead, the filesystem setlease method should call back to setlease() to add a lease to the inode's lease list, where fcntl_getlease() can find it. Since fcntl_getlease() only reports whether the current task holds a lease, a cluster filesystem need only do this for leases held by processes on this node.
There is also no break_lease method; filesystems that handle their own leases should break leases themselves from the filesystem's open, create, and (on truncate) setattr methods.
Warning: the only current setlease methods exist only to disable leases in certain cases. More vfs changes may be required to allow a full filesystem lease implementation.