Merge master.kernel.org:/home/rmk/linux-2.6-arm
[firefly-linux-kernel-4.4.55.git] / fs / cifs / inode.c
index ca3af4eafcb2f19834bb4c34c101e5caf95209e0..912d401600f6e2f7abce605c63e115372b9ecdaa 100644 (file)
@@ -962,7 +962,6 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
        struct cifsTconInfo *pTcon;
        char *full_path = NULL;
        int rc = -EACCES;
-       int found = FALSE;
        struct cifsFileInfo *open_file = NULL;
        FILE_BASIC_INFO time_buf;
        int set_time = FALSE;
@@ -970,7 +969,6 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
        __u64 uid = 0xFFFFFFFFFFFFFFFFULL;
        __u64 gid = 0xFFFFFFFFFFFFFFFFULL;
        struct cifsInodeInfo *cifsInode;
-       struct list_head *tmp;
 
        xid = GetXid();
 
@@ -995,7 +993,6 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
        filemap_fdatawait(direntry->d_inode->i_mapping);
 
        if (attrs->ia_valid & ATTR_SIZE) {
-               read_lock(&GlobalSMBSeslock);
                /* To avoid spurious oplock breaks from server, in the case of
                   inodes that we already have open, avoid doing path based
                   setting of file size if we can do it by handle.
@@ -1003,49 +1000,23 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
                   when the local oplock break takes longer to flush
                   writebehind data than the SMB timeout for the SetPathInfo
                   request would allow */
-               list_for_each(tmp, &cifsInode->openFileList) {
-                       open_file = list_entry(tmp, struct cifsFileInfo,
-                                              flist);
-                       /* We check if file is open for writing first */
-                       if ((open_file->pfile) &&
-                           ((open_file->pfile->f_flags & O_RDWR) ||
-                           (open_file->pfile->f_flags & O_WRONLY))) {
-                               if (open_file->invalidHandle == FALSE) {
-                                       /* we found a valid, writeable network
-                                          file handle to use to try to set the
-                                          file size */
-                                       __u16 nfid = open_file->netfid;
-                                       __u32 npid = open_file->pid;
-                                       read_unlock(&GlobalSMBSeslock);
-                                       found = TRUE;
-                                       rc = CIFSSMBSetFileSize(xid, pTcon,
-                                               attrs->ia_size, nfid, npid,
-                                               FALSE);
-                                       cFYI(1, ("SetFileSize by handle "
-                                                "(setattrs) rc = %d", rc));
-                                       /* Do not need reopen and retry on
-                                          EAGAIN since we will retry by
-                                          pathname below */
-
-                                       /* now that we found one valid file
-                                          handle no sense continuing to loop
-                                          trying others, so break here */
-                                       if(rc == -EINVAL) {
-                                               int bytes_written;
-                                               rc = CIFSSMBWrite(xid, pTcon,
-                                                       nfid, 0,
-                                                       attrs->ia_size, 
-                                                       &bytes_written, NULL,
-                                                       NULL, 1 /* 45 sec */);
-                                               cFYI(1,("wrt seteof rc %d",rc));
-                                       }
-                                       break;
-                               }
+               open_file = find_writable_file(cifsInode);
+               if (open_file) {
+                       __u16 nfid = open_file->netfid;
+                       __u32 npid = open_file->pid;
+                       rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size,
+                                               nfid, npid, FALSE);
+                       atomic_dec(&open_file->wrtPending);
+                       cFYI(1,("SetFSize for attrs rc = %d", rc));
+                       if(rc == -EINVAL) {
+                               int bytes_written;
+                               rc = CIFSSMBWrite(xid, pTcon,
+                                                 nfid, 0, attrs->ia_size,
+                                                 &bytes_written, NULL, NULL,
+                                                 1 /* 45 seconds */);
+                               cFYI(1,("Wrt seteof rc %d", rc));
                        }
                }
-               if (found == FALSE)
-                       read_unlock(&GlobalSMBSeslock);
-
                if (rc != 0) {
                        /* Set file size by pathname rather than by handle
                           either because no valid, writeable file handle for