File locking related fixes for v3.20 (pile #2)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABAgAGBQJU48n/AAoJEAAOaEEZVoIVtbsP/iWEnnP4ZIY8Bai32mQAVgdm C20aftlQvtrNWOf9SSjFIZGQDLeExk2RTZMbkJhCS4SkVjdB38mST/mBglFO5MLc xarz2FcAApOYAu6d2qkfze3KuCQHq4xPhDs0C2WLf0ENUOeE2nFAZcOccL2VyJvW RQF0AslWVhhvbaCnIpmDFx5SnL+yOuMcVJOMO5g3HPjbW8oaZWQuvjTCRxdAI2tk CZBZIfyve0KH6WSGHQkAlH5PU3myV3XHgZ4UHqM1nBLF0L2LyRARXGfnbzBcS+G9 kgX/L7ohwI/VXG9MvD2IyQ7fpMyV60tHmDQBR3eqaxs4OKPD4p2c62LahGtUSxM7 B9+WX6pypj14MQS96iVtQEHgqGDixQbmIjq+EslwvzqPZR77nYOPmDRP+sWsmok1 tNRy8WizZPC45SO9gs7LzZQF1eFTMyalW5IZTh4UbwWRjGjJRtpdEmFSWyN6jLuL iJnhe39g+sQOqyPPcP6SxcZiCnLj0Y5utrDRwIMM03kKugfC80id+RDTw8I1uQ/p Bmch6FoGvn3jFB0O1OAxp6ZbB5KwdKBgNPfzpoK+D7kjKJSWH1tZkFpfSvINKx9g yxVahQkHVy9TFPY0uhA6j/IwNZ3c+wdRZ5lbpMKMS46LRvzGc3zNSCn5e6dWOBA2 GS+K2xmkLo1pRuYv96f9 =Gn2o -----END PGP SIGNATURE----- Merge tag 'locks-v3.20-2' of git://git.samba.org/jlayton/linux Pull file locking fixes from Jeff Layton: "A small set of patches to fix problems with the recent file locking changes that we discussed earlier this week" " * tag 'locks-v3.20-2' of git://git.samba.org/jlayton/linux: locks: fix list insertion when lock is split in two locks: remove conditional lock release in middle of flock_lock_file locks: only remove leases associated with the file being closed Revert "locks: keep a count of locks on the flctx lists"
This commit is contained in:
Коммит
b2b89ebfc0
|
@ -245,6 +245,7 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
|
|||
*/
|
||||
void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
|
||||
{
|
||||
struct file_lock *lock;
|
||||
struct file_lock_context *ctx;
|
||||
|
||||
*fcntl_count = 0;
|
||||
|
@ -252,8 +253,12 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
|
|||
|
||||
ctx = inode->i_flctx;
|
||||
if (ctx) {
|
||||
*fcntl_count = ctx->flc_posix_cnt;
|
||||
*flock_count = ctx->flc_flock_cnt;
|
||||
spin_lock(&ctx->flc_lock);
|
||||
list_for_each_entry(lock, &ctx->flc_posix, fl_list)
|
||||
++(*fcntl_count);
|
||||
list_for_each_entry(lock, &ctx->flc_flock, fl_list)
|
||||
++(*flock_count);
|
||||
spin_unlock(&ctx->flc_lock);
|
||||
}
|
||||
dout("counted %d flock locks and %d fcntl locks",
|
||||
*flock_count, *fcntl_count);
|
||||
|
|
|
@ -1129,7 +1129,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
|
|||
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
|
||||
struct file_lock *flock;
|
||||
struct file_lock_context *flctx = inode->i_flctx;
|
||||
unsigned int i;
|
||||
unsigned int count = 0, i;
|
||||
int rc = 0, xid, type;
|
||||
struct list_head locks_to_send, *el;
|
||||
struct lock_to_push *lck, *tmp;
|
||||
|
@ -1140,14 +1140,20 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
|
|||
if (!flctx)
|
||||
goto out;
|
||||
|
||||
spin_lock(&flctx->flc_lock);
|
||||
list_for_each(el, &flctx->flc_posix) {
|
||||
count++;
|
||||
}
|
||||
spin_unlock(&flctx->flc_lock);
|
||||
|
||||
INIT_LIST_HEAD(&locks_to_send);
|
||||
|
||||
/*
|
||||
* Allocating flc_posix_cnt locks is enough because no FL_POSIX locks
|
||||
* can be added to the list while we are holding cinode->lock_sem that
|
||||
* Allocating count locks is enough because no FL_POSIX locks can be
|
||||
* added to the list while we are holding cinode->lock_sem that
|
||||
* protects locking operations of this inode.
|
||||
*/
|
||||
for (i = 0; i < flctx->flc_posix_cnt; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL);
|
||||
if (!lck) {
|
||||
rc = -ENOMEM;
|
||||
|
|
59
fs/locks.c
59
fs/locks.c
|
@ -681,21 +681,18 @@ static void locks_wake_up_blocks(struct file_lock *blocker)
|
|||
}
|
||||
|
||||
static void
|
||||
locks_insert_lock_ctx(struct file_lock *fl, int *counter,
|
||||
struct list_head *before)
|
||||
locks_insert_lock_ctx(struct file_lock *fl, struct list_head *before)
|
||||
{
|
||||
fl->fl_nspid = get_pid(task_tgid(current));
|
||||
list_add_tail(&fl->fl_list, before);
|
||||
++*counter;
|
||||
locks_insert_global_locks(fl);
|
||||
}
|
||||
|
||||
static void
|
||||
locks_unlink_lock_ctx(struct file_lock *fl, int *counter)
|
||||
locks_unlink_lock_ctx(struct file_lock *fl)
|
||||
{
|
||||
locks_delete_global_locks(fl);
|
||||
list_del_init(&fl->fl_list);
|
||||
--*counter;
|
||||
if (fl->fl_nspid) {
|
||||
put_pid(fl->fl_nspid);
|
||||
fl->fl_nspid = NULL;
|
||||
|
@ -704,10 +701,9 @@ locks_unlink_lock_ctx(struct file_lock *fl, int *counter)
|
|||
}
|
||||
|
||||
static void
|
||||
locks_delete_lock_ctx(struct file_lock *fl, int *counter,
|
||||
struct list_head *dispose)
|
||||
locks_delete_lock_ctx(struct file_lock *fl, struct list_head *dispose)
|
||||
{
|
||||
locks_unlink_lock_ctx(fl, counter);
|
||||
locks_unlink_lock_ctx(fl);
|
||||
if (dispose)
|
||||
list_add(&fl->fl_list, dispose);
|
||||
else
|
||||
|
@ -895,7 +891,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
|
|||
if (request->fl_type == fl->fl_type)
|
||||
goto out;
|
||||
found = true;
|
||||
locks_delete_lock_ctx(fl, &ctx->flc_flock_cnt, &dispose);
|
||||
locks_delete_lock_ctx(fl, &dispose);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -905,16 +901,6 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
|
|||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* If a higher-priority process was blocked on the old file lock,
|
||||
* give it the opportunity to lock the file.
|
||||
*/
|
||||
if (found) {
|
||||
spin_unlock(&ctx->flc_lock);
|
||||
cond_resched();
|
||||
spin_lock(&ctx->flc_lock);
|
||||
}
|
||||
|
||||
find_conflict:
|
||||
list_for_each_entry(fl, &ctx->flc_flock, fl_list) {
|
||||
if (!flock_locks_conflict(request, fl))
|
||||
|
@ -929,7 +915,7 @@ find_conflict:
|
|||
if (request->fl_flags & FL_ACCESS)
|
||||
goto out;
|
||||
locks_copy_lock(new_fl, request);
|
||||
locks_insert_lock_ctx(new_fl, &ctx->flc_flock_cnt, &ctx->flc_flock);
|
||||
locks_insert_lock_ctx(new_fl, &ctx->flc_flock);
|
||||
new_fl = NULL;
|
||||
error = 0;
|
||||
|
||||
|
@ -1046,8 +1032,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
|
|||
else
|
||||
request->fl_end = fl->fl_end;
|
||||
if (added) {
|
||||
locks_delete_lock_ctx(fl, &ctx->flc_posix_cnt,
|
||||
&dispose);
|
||||
locks_delete_lock_ctx(fl, &dispose);
|
||||
continue;
|
||||
}
|
||||
request = fl;
|
||||
|
@ -1076,8 +1061,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
|
|||
* one (This may happen several times).
|
||||
*/
|
||||
if (added) {
|
||||
locks_delete_lock_ctx(fl,
|
||||
&ctx->flc_posix_cnt, &dispose);
|
||||
locks_delete_lock_ctx(fl, &dispose);
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
|
@ -1093,10 +1077,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
|
|||
locks_copy_lock(new_fl, request);
|
||||
request = new_fl;
|
||||
new_fl = NULL;
|
||||
locks_insert_lock_ctx(request,
|
||||
&ctx->flc_posix_cnt, &fl->fl_list);
|
||||
locks_delete_lock_ctx(fl,
|
||||
&ctx->flc_posix_cnt, &dispose);
|
||||
locks_insert_lock_ctx(request, &fl->fl_list);
|
||||
locks_delete_lock_ctx(fl, &dispose);
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
@ -1124,8 +1106,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
|
|||
goto out;
|
||||
}
|
||||
locks_copy_lock(new_fl, request);
|
||||
locks_insert_lock_ctx(new_fl, &ctx->flc_posix_cnt,
|
||||
&fl->fl_list);
|
||||
locks_insert_lock_ctx(new_fl, &fl->fl_list);
|
||||
fl = new_fl;
|
||||
new_fl = NULL;
|
||||
}
|
||||
if (right) {
|
||||
|
@ -1136,8 +1118,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
|
|||
left = new_fl2;
|
||||
new_fl2 = NULL;
|
||||
locks_copy_lock(left, right);
|
||||
locks_insert_lock_ctx(left, &ctx->flc_posix_cnt,
|
||||
&fl->fl_list);
|
||||
locks_insert_lock_ctx(left, &fl->fl_list);
|
||||
}
|
||||
right->fl_start = request->fl_end + 1;
|
||||
locks_wake_up_blocks(right);
|
||||
|
@ -1321,7 +1302,6 @@ static void lease_clear_pending(struct file_lock *fl, int arg)
|
|||
/* We already had a lease on this file; just change its type */
|
||||
int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose)
|
||||
{
|
||||
struct file_lock_context *flctx;
|
||||
int error = assign_type(fl, arg);
|
||||
|
||||
if (error)
|
||||
|
@ -1331,7 +1311,6 @@ int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose)
|
|||
if (arg == F_UNLCK) {
|
||||
struct file *filp = fl->fl_file;
|
||||
|
||||
flctx = file_inode(filp)->i_flctx;
|
||||
f_delown(filp);
|
||||
filp->f_owner.signum = 0;
|
||||
fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync);
|
||||
|
@ -1339,7 +1318,7 @@ int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose)
|
|||
printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync);
|
||||
fl->fl_fasync = NULL;
|
||||
}
|
||||
locks_delete_lock_ctx(fl, &flctx->flc_lease_cnt, dispose);
|
||||
locks_delete_lock_ctx(fl, dispose);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1456,8 +1435,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
|
|||
fl->fl_downgrade_time = break_time;
|
||||
}
|
||||
if (fl->fl_lmops->lm_break(fl))
|
||||
locks_delete_lock_ctx(fl, &ctx->flc_lease_cnt,
|
||||
&dispose);
|
||||
locks_delete_lock_ctx(fl, &dispose);
|
||||
}
|
||||
|
||||
if (list_empty(&ctx->flc_lease))
|
||||
|
@ -1697,7 +1675,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
|
|||
if (!leases_enable)
|
||||
goto out;
|
||||
|
||||
locks_insert_lock_ctx(lease, &ctx->flc_lease_cnt, &ctx->flc_lease);
|
||||
locks_insert_lock_ctx(lease, &ctx->flc_lease);
|
||||
/*
|
||||
* The check in break_lease() is lockless. It's possible for another
|
||||
* open to race in after we did the earlier check for a conflicting
|
||||
|
@ -1710,7 +1688,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
|
|||
smp_mb();
|
||||
error = check_conflicting_open(dentry, arg, lease->fl_flags);
|
||||
if (error) {
|
||||
locks_unlink_lock_ctx(lease, &ctx->flc_lease_cnt);
|
||||
locks_unlink_lock_ctx(lease);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
@ -2448,7 +2426,8 @@ locks_remove_lease(struct file *filp)
|
|||
|
||||
spin_lock(&ctx->flc_lock);
|
||||
list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list)
|
||||
lease_modify(fl, F_UNLCK, &dispose);
|
||||
if (filp == fl->fl_file)
|
||||
lease_modify(fl, F_UNLCK, &dispose);
|
||||
spin_unlock(&ctx->flc_lock);
|
||||
locks_dispose_list(&dispose);
|
||||
}
|
||||
|
|
|
@ -968,9 +968,6 @@ struct file_lock_context {
|
|||
struct list_head flc_flock;
|
||||
struct list_head flc_posix;
|
||||
struct list_head flc_lease;
|
||||
int flc_flock_cnt;
|
||||
int flc_posix_cnt;
|
||||
int flc_lease_cnt;
|
||||
};
|
||||
|
||||
/* The following constant reflects the upper bound of the file/locking space */
|
||||
|
|
Загрузка…
Ссылка в новой задаче