locks: keep a count of locks on the flctx lists
authorJeff Layton <jlayton@primarydata.com>
Fri, 16 Jan 2015 20:05:57 +0000 (15:05 -0500)
committerJeff Layton <jeff.layton@primarydata.com>
Fri, 16 Jan 2015 21:08:50 +0000 (16:08 -0500)
This makes things a bit more efficient in the cifs and ceph lock
pushing code.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Acked-by: Christoph Hellwig <hch@lst.de>
fs/ceph/locks.c
fs/cifs/file.c
fs/locks.c
include/linux/fs.h

index 0303da8..06ea5cd 100644 (file)
@@ -242,12 +242,9 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)
 /*
  * Fills in the passed counter variables, so you can prepare pagelist metadata
  * before calling ceph_encode_locks.
- *
- * FIXME: add counters to struct file_lock_context so we don't need to do this?
  */
 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;
@@ -255,12 +252,8 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
 
        ctx = inode->i_flctx;
        if (ctx) {
-               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);
+               *fcntl_count = ctx->flc_posix_cnt;
+               *flock_count = ctx->flc_flock_cnt;
        }
        dout("counted %d flock locks and %d fcntl locks",
             *flock_count, *fcntl_count);
index b65166e..8c2ca6f 100644 (file)
@@ -1125,7 +1125,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 count = 0, i;
+       unsigned int i;
        int rc = 0, xid, type;
        struct list_head locks_to_send, *el;
        struct lock_to_push *lck, *tmp;
@@ -1136,20 +1136,14 @@ 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 count locks is enough because no FL_POSIX locks can be
-        * added to the list while we are holding cinode->lock_sem that
+        * 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
         * protects locking operations of this inode.
         */
-       for (i = 0; i < count; i++) {
+       for (i = 0; i < flctx->flc_posix_cnt; i++) {
                lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL);
                if (!lck) {
                        rc = -ENOMEM;
diff --cc fs/locks.c
Simple merge
Simple merge