locks: convert posix locks to file_lock_context
authorJeff Layton <jlayton@primarydata.com>
Fri, 16 Jan 2015 20:05:55 +0000 (15:05 -0500)
committerJeff Layton <jeff.layton@primarydata.com>
Fri, 16 Jan 2015 21:08:16 +0000 (16:08 -0500)
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Acked-by: Christoph Hellwig <hch@lst.de>
fs/ceph/locks.c
fs/cifs/file.c
fs/lockd/svcsubs.c
fs/locks.c
fs/nfs/delegation.c
fs/nfs/nfs4state.c
fs/nfs/pagelist.c
fs/nfs/write.c
fs/nfsd/nfs4state.c
fs/read_write.c
include/linux/fs.h

index 917656e..19beeed 100644 (file)
@@ -253,18 +253,15 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
        *fcntl_count = 0;
        *flock_count = 0;
 
-       spin_lock(&inode->i_lock);
-       for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
-               if (lock->fl_flags & FL_POSIX)
-                       ++(*fcntl_count);
-       }
-
        ctx = inode->i_flctx;
        if (ctx) {
+               spin_lock(&inode->i_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(&inode->i_lock);
        }
-       spin_unlock(&inode->i_lock);
        dout("counted %d flock locks and %d fcntl locks",
             *flock_count, *fcntl_count);
 }
@@ -279,7 +276,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
                                int num_fcntl_locks, int num_flock_locks)
 {
        struct file_lock *lock;
-       struct file_lock_context *ctx;
+       struct file_lock_context *ctx = inode->i_flctx;
        int err = 0;
        int seen_fcntl = 0;
        int seen_flock = 0;
@@ -288,34 +285,31 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
        dout("encoding %d flock and %d fcntl locks", num_flock_locks,
             num_fcntl_locks);
 
+       if (!ctx)
+               return 0;
+
        spin_lock(&inode->i_lock);
-       for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
-               if (lock->fl_flags & FL_POSIX) {
-                       ++seen_fcntl;
-                       if (seen_fcntl > num_fcntl_locks) {
-                               err = -ENOSPC;
-                               goto fail;
-                       }
-                       err = lock_to_ceph_filelock(lock, &flocks[l]);
-                       if (err)
-                               goto fail;
-                       ++l;
+       list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
+               ++seen_fcntl;
+               if (seen_fcntl > num_fcntl_locks) {
+                       err = -ENOSPC;
+                       goto fail;
                }
+               err = lock_to_ceph_filelock(lock, &flocks[l]);
+               if (err)
+                       goto fail;
+               ++l;
        }
-
-       ctx = inode->i_flctx;
-       if (ctx) {
-               list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
-                       ++seen_flock;
-                       if (seen_flock > num_flock_locks) {
-                               err = -ENOSPC;
-                               goto fail;
-                       }
-                       err = lock_to_ceph_filelock(lock, &flocks[l]);
-                       if (err)
-                               goto fail;
-                       ++l;
+       list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
+               ++seen_flock;
+               if (seen_flock > num_flock_locks) {
+                       err = -ENOSPC;
+                       goto fail;
                }
+               err = lock_to_ceph_filelock(lock, &flocks[l]);
+               if (err)
+                       goto fail;
+               ++l;
        }
 fail:
        spin_unlock(&inode->i_lock);
index 96b7e9b..ea78f6f 100644 (file)
@@ -1109,11 +1109,6 @@ cifs_push_mandatory_locks(struct cifsFileInfo *cfile)
        return rc;
 }
 
-/* copied from fs/locks.c with a name change */
-#define cifs_for_each_lock(inode, lockp) \
-       for (lockp = &inode->i_flock; *lockp != NULL; \
-            lockp = &(*lockp)->fl_next)
-
 struct lock_to_push {
        struct list_head llist;
        __u64 offset;
@@ -1128,8 +1123,9 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
 {
        struct inode *inode = cfile->dentry->d_inode;
        struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
-       struct file_lock *flock, **before;
-       unsigned int count = 0, i = 0;
+       struct file_lock *flock;
+       struct file_lock_context *flctx = inode->i_flctx;
+       unsigned int count = 0, i;
        int rc = 0, xid, type;
        struct list_head locks_to_send, *el;
        struct lock_to_push *lck, *tmp;
@@ -1137,10 +1133,12 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
 
        xid = get_xid();
 
+       if (!flctx)
+               goto out;
+
        spin_lock(&inode->i_lock);
-       cifs_for_each_lock(inode, before) {
-               if ((*before)->fl_flags & FL_POSIX)
-                       count++;
+       list_for_each(el, &flctx->flc_posix) {
+               count++;
        }
        spin_unlock(&inode->i_lock);
 
@@ -1151,7 +1149,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
         * added to the list while we are holding cinode->lock_sem that
         * protects locking operations of this inode.
         */
-       for (; i < count; i++) {
+       for (i = 0; i < count; i++) {
                lck = kmalloc(sizeof(struct lock_to_push), GFP_KERNEL);
                if (!lck) {
                        rc = -ENOMEM;
@@ -1162,10 +1160,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
 
        el = locks_to_send.next;
        spin_lock(&inode->i_lock);
-       cifs_for_each_lock(inode, before) {
-               flock = *before;
-               if ((flock->fl_flags & FL_POSIX) == 0)
-                       continue;
+       list_for_each_entry(flock, &flctx->flc_posix, fl_list) {
                if (el == &locks_to_send) {
                        /*
                         * The list ended. We don't have enough allocated
@@ -1185,7 +1180,6 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
                lck->length = length;
                lck->type = type;
                lck->offset = flock->fl_start;
-               el = el->next;
        }
        spin_unlock(&inode->i_lock);
 
Simple merge
diff --cc fs/locks.c
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc fs/nfs/write.c
Simple merge
Simple merge
diff --cc fs/read_write.c
Simple merge
Simple merge