sctp: Do not account for sizeof(struct sk_buff) in estimated rwnd
[pandora-kernel.git] / fs / cifs / file.c
index c1f063c..4dd9283 100644 (file)
@@ -645,20 +645,20 @@ int cifs_closedir(struct inode *inode, struct file *file)
 }
 
 static struct cifsLockInfo *
-cifs_lock_init(__u64 len, __u64 offset, __u8 type, __u16 netfid)
+cifs_lock_init(__u64 offset, __u64 length, __u8 type, __u16 netfid)
 {
-       struct cifsLockInfo *li =
+       struct cifsLockInfo *lock =
                kmalloc(sizeof(struct cifsLockInfo), GFP_KERNEL);
-       if (!li)
-               return li;
-       li->netfid = netfid;
-       li->offset = offset;
-       li->length = len;
-       li->type = type;
-       li->pid = current->tgid;
-       INIT_LIST_HEAD(&li->blist);
-       init_waitqueue_head(&li->block_q);
-       return li;
+       if (!lock)
+               return lock;
+       lock->offset = offset;
+       lock->length = length;
+       lock->type = type;
+       lock->netfid = netfid;
+       lock->pid = current->tgid;
+       INIT_LIST_HEAD(&lock->blist);
+       init_waitqueue_head(&lock->block_q);
+       return lock;
 }
 
 static void
@@ -672,7 +672,7 @@ cifs_del_lock_waiters(struct cifsLockInfo *lock)
 }
 
 static bool
-cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
+__cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
                        __u64 length, __u8 type, __u16 netfid,
                        struct cifsLockInfo **conf_lock)
 {
@@ -694,6 +694,21 @@ cifs_find_lock_conflict(struct cifsInodeInfo *cinode, __u64 offset,
        return false;
 }
 
+static bool
+cifs_find_lock_conflict(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
+                       struct cifsLockInfo **conf_lock)
+{
+       return __cifs_find_lock_conflict(cinode, lock->offset, lock->length,
+                                        lock->type, lock->netfid, conf_lock);
+}
+
+/*
+ * Check if there is another lock that prevents us to set the lock (mandatory
+ * style). If such a lock exists, update the flock structure with its
+ * properties. Otherwise, set the flock type to F_UNLCK if we can cache brlocks
+ * or leave it the same if we can't. Returns 0 if we don't need to request to
+ * the server or 1 otherwise.
+ */
 static int
 cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
               __u8 type, __u16 netfid, struct file_lock *flock)
@@ -704,8 +719,8 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
 
        mutex_lock(&cinode->lock_mutex);
 
-       exist = cifs_find_lock_conflict(cinode, offset, length, type, netfid,
-                                       &conf_lock);
+       exist = __cifs_find_lock_conflict(cinode, offset, length, type, netfid,
+                                         &conf_lock);
        if (exist) {
                flock->fl_start = conf_lock->offset;
                flock->fl_end = conf_lock->offset + conf_lock->length - 1;
@@ -723,40 +738,33 @@ cifs_lock_test(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
        return rc;
 }
 
-static int
-cifs_lock_add(struct cifsInodeInfo *cinode, __u64 len, __u64 offset,
-             __u8 type, __u16 netfid)
+static void
+cifs_lock_add(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock)
 {
-       struct cifsLockInfo *li;
-
-       li = cifs_lock_init(len, offset, type, netfid);
-       if (!li)
-               return -ENOMEM;
-
        mutex_lock(&cinode->lock_mutex);
-       list_add_tail(&li->llist, &cinode->llist);
+       list_add_tail(&lock->llist, &cinode->llist);
        mutex_unlock(&cinode->lock_mutex);
-       return 0;
 }
 
+/*
+ * Set the byte-range lock (mandatory style). Returns:
+ * 1) 0, if we set the lock and don't need to request to the server;
+ * 2) 1, if no locks prevent us but we need to request to the server;
+ * 3) -EACCESS, if there is a lock that prevents us and wait is false.
+ */
 static int
-cifs_lock_add_if(struct cifsInodeInfo *cinode, __u64 offset, __u64 length,
-                __u8 type, __u16 netfid, bool wait)
+cifs_lock_add_if(struct cifsInodeInfo *cinode, struct cifsLockInfo *lock,
+                bool wait)
 {
-       struct cifsLockInfo *lock, *conf_lock;
+       struct cifsLockInfo *conf_lock;
        bool exist;
        int rc = 0;
 
-       lock = cifs_lock_init(length, offset, type, netfid);
-       if (!lock)
-               return -ENOMEM;
-
 try_again:
        exist = false;
        mutex_lock(&cinode->lock_mutex);
 
-       exist = cifs_find_lock_conflict(cinode, offset, length, type, netfid,
-                                       &conf_lock);
+       exist = cifs_find_lock_conflict(cinode, lock, &conf_lock);
        if (!exist && cinode->can_cache_brlcks) {
                list_add_tail(&lock->llist, &cinode->llist);
                mutex_unlock(&cinode->lock_mutex);
@@ -775,17 +783,21 @@ try_again:
                                        (lock->blist.next == &lock->blist));
                if (!rc)
                        goto try_again;
-               else {
-                       mutex_lock(&cinode->lock_mutex);
-                       list_del_init(&lock->blist);
-               }
+               mutex_lock(&cinode->lock_mutex);
+               list_del_init(&lock->blist);
        }
 
-       kfree(lock);
        mutex_unlock(&cinode->lock_mutex);
        return rc;
 }
 
+/*
+ * Check if there is another lock that prevents us to set the lock (posix
+ * style). If such a lock exists, update the flock structure with its
+ * properties. Otherwise, set the flock type to F_UNLCK if we can cache brlocks
+ * or leave it the same if we can't. Returns 0 if we don't need to request to
+ * the server or 1 otherwise.
+ */
 static int
 cifs_posix_lock_test(struct file *file, struct file_lock *flock)
 {
@@ -808,6 +820,12 @@ cifs_posix_lock_test(struct file *file, struct file_lock *flock)
        return rc;
 }
 
+/*
+ * Set the byte-range lock (posix style). Returns:
+ * 1) 0, if we set the lock and don't need to request to the server;
+ * 2) 1, if we need to request to the server;
+ * 3) <0, if the error occurs while setting the lock.
+ */
 static int
 cifs_posix_lock_set(struct file *file, struct file_lock *flock)
 {
@@ -933,7 +951,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
                else
                        type = CIFS_WRLCK;
 
-               lck = cifs_lock_init(length, flock->fl_start, type,
+               lck = cifs_lock_init(flock->fl_start, length, type,
                                     cfile->netfid);
                if (!lck) {
                        rc = -ENOMEM;
@@ -1070,14 +1088,12 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type,
                if (rc != 0)
                        cERROR(1, "Error unlocking previously locked "
                                   "range %d during test of lock", rc);
-               rc = 0;
-               return rc;
+               return 0;
        }
 
        if (type & LOCKING_ANDX_SHARED_LOCK) {
                flock->fl_type = F_WRLCK;
-               rc = 0;
-               return rc;
+               return 0;
        }
 
        rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
@@ -1095,8 +1111,7 @@ cifs_getlk(struct file *file, struct file_lock *flock, __u8 type,
        } else
                flock->fl_type = F_WRLCK;
 
-       rc = 0;
-       return rc;
+       return 0;
 }
 
 static void
@@ -1254,20 +1269,26 @@ cifs_setlk(struct file *file,  struct file_lock *flock, __u8 type,
        }
 
        if (lock) {
-               rc = cifs_lock_add_if(cinode, flock->fl_start, length,
-                                     type, netfid, wait_flag);
+               struct cifsLockInfo *lock;
+
+               lock = cifs_lock_init(flock->fl_start, length, type, netfid);
+               if (!lock)
+                       return -ENOMEM;
+
+               rc = cifs_lock_add_if(cinode, lock, wait_flag);
                if (rc < 0)
-                       return rc;
-               else if (!rc)
+                       kfree(lock);
+               if (rc <= 0)
                        goto out;
 
                rc = CIFSSMBLock(xid, tcon, netfid, current->tgid, length,
                                 flock->fl_start, 0, 1, type, wait_flag, 0);
-               if (rc == 0) {
-                       /* For Windows locks we must store them. */
-                       rc = cifs_lock_add(cinode, length, flock->fl_start,
-                                          type, netfid);
+               if (rc) {
+                       kfree(lock);
+                       goto out;
                }
+
+               cifs_lock_add(cinode, lock);
        } else if (unlock)
                rc = cifs_unlock_range(cfile, flock, xid);