Revert "locks: keep a count of locks on the flctx lists"
authorJeff Layton <jeff.layton@primarydata.com>
Mon, 16 Feb 2015 19:32:03 +0000 (14:32 -0500)
committerJeff Layton <jeff.layton@primarydata.com>
Mon, 16 Feb 2015 19:32:03 +0000 (14:32 -0500)
This reverts commit 9bd0f45b7037fcfa8b575c7e27d0431d6e6dc3bb.

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>
fs/ceph/locks.c
fs/cifs/file.c
fs/locks.c
include/linux/fs.h

index 06ea5cd..4347039 100644 (file)
@@ -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);
index 8fe1f7a..a94b3e6 100644 (file)
@@ -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;
diff --cc fs/locks.c
Simple merge
Simple merge