Skip to content

Commit e084c1b

Browse files
author
Jeff Layton
committed
Revert "locks: keep a count of locks on the flctx lists"
This reverts commit 9bd0f45. Linus rightly pointed out that I failed to initialize the counters when adding them, so they don't work as expected. Just revert this patch for now. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
1 parent 1fa185e commit e084c1b

4 files changed

Lines changed: 33 additions & 38 deletions

File tree

‎fs/ceph/locks.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,20 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
245245
*/
246246
void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
247247
{
248+
struct file_lock *lock;
248249
struct file_lock_context *ctx;
249250

250251
*fcntl_count = 0;
251252
*flock_count = 0;
252253

253254
ctx = inode->i_flctx;
254255
if (ctx) {
255-
*fcntl_count = ctx->flc_posix_cnt;
256-
*flock_count = ctx->flc_flock_cnt;
256+
spin_lock(&ctx->flc_lock);
257+
list_for_each_entry(lock, &ctx->flc_posix, fl_list)
258+
++(*fcntl_count);
259+
list_for_each_entry(lock, &ctx->flc_flock, fl_list)
260+
++(*flock_count);
261+
spin_unlock(&ctx->flc_lock);
257262
}
258263
dout("counted %d flock locks and %d fcntl locks",
259264
*flock_count, *fcntl_count);

‎fs/cifs/file.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
11291129
struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
11301130
struct file_lock *flock;
11311131
struct file_lock_context *flctx = inode->i_flctx;
1132-
unsigned int i;
1132+
unsigned int count = 0, i;
11331133
int rc = 0, xid, type;
11341134
struct list_head locks_to_send, *el;
11351135
struct lock_to_push *lck, *tmp;
@@ -1140,14 +1140,20 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
11401140
if (!flctx)
11411141
goto out;
11421142

1143+
spin_lock(&flctx->flc_lock);
1144+
list_for_each(el, &flctx->flc_posix) {
1145+
count++;
1146+
}
1147+
spin_unlock(&flctx->flc_lock);
1148+
11431149
INIT_LIST_HEAD(&locks_to_send);
11441150

11451151
/*
1146-
* Allocating flc_posix_cnt locks is enough because no FL_POSIX locks
1147-
* can be added to the list while we are holding cinode->lock_sem that
1152+
* Allocating count locks is enough because no FL_POSIX locks can be
1153+
* added to the list while we are holding cinode->lock_sem that
11481154
* protects locking operations of this inode.
11491155
*/
1150-
for (i = 0; i < flctx->flc_posix_cnt; i++) {
1156+
for (i = 0; i < count; i++) {
11511157
lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL);
11521158
if (!lck) {
11531159
rc = -ENOMEM;

‎fs/locks.c‎

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -681,21 +681,18 @@ static void locks_wake_up_blocks(struct file_lock *blocker)
681681
}
682682

683683
static void
684-
locks_insert_lock_ctx(struct file_lock *fl, int *counter,
685-
struct list_head *before)
684+
locks_insert_lock_ctx(struct file_lock *fl, struct list_head *before)
686685
{
687686
fl->fl_nspid = get_pid(task_tgid(current));
688687
list_add_tail(&fl->fl_list, before);
689-
++*counter;
690688
locks_insert_global_locks(fl);
691689
}
692690

693691
static void
694-
locks_unlink_lock_ctx(struct file_lock *fl, int *counter)
692+
locks_unlink_lock_ctx(struct file_lock *fl)
695693
{
696694
locks_delete_global_locks(fl);
697695
list_del_init(&fl->fl_list);
698-
--*counter;
699696
if (fl->fl_nspid) {
700697
put_pid(fl->fl_nspid);
701698
fl->fl_nspid = NULL;
@@ -704,10 +701,9 @@ locks_unlink_lock_ctx(struct file_lock *fl, int *counter)
704701
}
705702

706703
static void
707-
locks_delete_lock_ctx(struct file_lock *fl, int *counter,
708-
struct list_head *dispose)
704+
locks_delete_lock_ctx(struct file_lock *fl, struct list_head *dispose)
709705
{
710-
locks_unlink_lock_ctx(fl, counter);
706+
locks_unlink_lock_ctx(fl);
711707
if (dispose)
712708
list_add(&fl->fl_list, dispose);
713709
else
@@ -895,7 +891,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
895891
if (request->fl_type == fl->fl_type)
896892
goto out;
897893
found = true;
898-
locks_delete_lock_ctx(fl, &ctx->flc_flock_cnt, &dispose);
894+
locks_delete_lock_ctx(fl, &dispose);
899895
break;
900896
}
901897

@@ -929,7 +925,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
929925
if (request->fl_flags & FL_ACCESS)
930926
goto out;
931927
locks_copy_lock(new_fl, request);
932-
locks_insert_lock_ctx(new_fl, &ctx->flc_flock_cnt, &ctx->flc_flock);
928+
locks_insert_lock_ctx(new_fl, &ctx->flc_flock);
933929
new_fl = NULL;
934930
error = 0;
935931

@@ -1046,8 +1042,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
10461042
else
10471043
request->fl_end = fl->fl_end;
10481044
if (added) {
1049-
locks_delete_lock_ctx(fl, &ctx->flc_posix_cnt,
1050-
&dispose);
1045+
locks_delete_lock_ctx(fl, &dispose);
10511046
continue;
10521047
}
10531048
request = fl;
@@ -1076,8 +1071,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
10761071
* one (This may happen several times).
10771072
*/
10781073
if (added) {
1079-
locks_delete_lock_ctx(fl,
1080-
&ctx->flc_posix_cnt, &dispose);
1074+
locks_delete_lock_ctx(fl, &dispose);
10811075
continue;
10821076
}
10831077
/*
@@ -1093,10 +1087,8 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
10931087
locks_copy_lock(new_fl, request);
10941088
request = new_fl;
10951089
new_fl = NULL;
1096-
locks_insert_lock_ctx(request,
1097-
&ctx->flc_posix_cnt, &fl->fl_list);
1098-
locks_delete_lock_ctx(fl,
1099-
&ctx->flc_posix_cnt, &dispose);
1090+
locks_insert_lock_ctx(request, &fl->fl_list);
1091+
locks_delete_lock_ctx(fl, &dispose);
11001092
added = true;
11011093
}
11021094
}
@@ -1124,8 +1116,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
11241116
goto out;
11251117
}
11261118
locks_copy_lock(new_fl, request);
1127-
locks_insert_lock_ctx(new_fl, &ctx->flc_posix_cnt,
1128-
&fl->fl_list);
1119+
locks_insert_lock_ctx(new_fl, &fl->fl_list);
11291120
new_fl = NULL;
11301121
}
11311122
if (right) {
@@ -1136,8 +1127,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
11361127
left = new_fl2;
11371128
new_fl2 = NULL;
11381129
locks_copy_lock(left, right);
1139-
locks_insert_lock_ctx(left, &ctx->flc_posix_cnt,
1140-
&fl->fl_list);
1130+
locks_insert_lock_ctx(left, &fl->fl_list);
11411131
}
11421132
right->fl_start = request->fl_end + 1;
11431133
locks_wake_up_blocks(right);
@@ -1321,7 +1311,6 @@ static void lease_clear_pending(struct file_lock *fl, int arg)
13211311
/* We already had a lease on this file; just change its type */
13221312
int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose)
13231313
{
1324-
struct file_lock_context *flctx;
13251314
int error = assign_type(fl, arg);
13261315

13271316
if (error)
@@ -1331,15 +1320,14 @@ int lease_modify(struct file_lock *fl, int arg, struct list_head *dispose)
13311320
if (arg == F_UNLCK) {
13321321
struct file *filp = fl->fl_file;
13331322

1334-
flctx = file_inode(filp)->i_flctx;
13351323
f_delown(filp);
13361324
filp->f_owner.signum = 0;
13371325
fasync_helper(0, fl->fl_file, 0, &fl->fl_fasync);
13381326
if (fl->fl_fasync != NULL) {
13391327
printk(KERN_ERR "locks_delete_lock: fasync == %p\n", fl->fl_fasync);
13401328
fl->fl_fasync = NULL;
13411329
}
1342-
locks_delete_lock_ctx(fl, &flctx->flc_lease_cnt, dispose);
1330+
locks_delete_lock_ctx(fl, dispose);
13431331
}
13441332
return 0;
13451333
}
@@ -1456,8 +1444,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
14561444
fl->fl_downgrade_time = break_time;
14571445
}
14581446
if (fl->fl_lmops->lm_break(fl))
1459-
locks_delete_lock_ctx(fl, &ctx->flc_lease_cnt,
1460-
&dispose);
1447+
locks_delete_lock_ctx(fl, &dispose);
14611448
}
14621449

14631450
if (list_empty(&ctx->flc_lease))
@@ -1697,7 +1684,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
16971684
if (!leases_enable)
16981685
goto out;
16991686

1700-
locks_insert_lock_ctx(lease, &ctx->flc_lease_cnt, &ctx->flc_lease);
1687+
locks_insert_lock_ctx(lease, &ctx->flc_lease);
17011688
/*
17021689
* The check in break_lease() is lockless. It's possible for another
17031690
* open to race in after we did the earlier check for a conflicting
@@ -1710,7 +1697,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
17101697
smp_mb();
17111698
error = check_conflicting_open(dentry, arg, lease->fl_flags);
17121699
if (error) {
1713-
locks_unlink_lock_ctx(lease, &ctx->flc_lease_cnt);
1700+
locks_unlink_lock_ctx(lease);
17141701
goto out;
17151702
}
17161703

‎include/linux/fs.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,6 @@ struct file_lock_context {
969969
struct list_head flc_flock;
970970
struct list_head flc_posix;
971971
struct list_head flc_lease;
972-
int flc_flock_cnt;
973-
int flc_posix_cnt;
974-
int flc_lease_cnt;
975972
};
976973

977974
/* The following constant reflects the upper bound of the file/locking space */

0 commit comments

Comments
 (0)