[CIFS] Fix double list addition in cifs posix open code

Remove adding open file entry twice to lists in the file
Do not fill file info twice in case of posix opens and creates

Signed-off-by: Shirish Pargaonkar <shirishp@us.ibm.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>

+9 -20
+9 -6
fs/cifs/dir.c
··· 281 281 int create_options = CREATE_NOT_DIR; 282 282 int oplock = 0; 283 283 int oflags; 284 + bool posix_create = false; 284 285 /* 285 286 * BB below access is probably too much for mknod to request 286 287 * but we have to do query and setpathinfo so requesting ··· 329 328 negotation. EREMOTE indicates DFS junction, which is not 330 329 handled in posix open */ 331 330 332 - if ((rc == 0) && (newinode == NULL)) 333 - goto cifs_create_get_file_info; /* query inode info */ 334 - else if (rc == 0) /* success, no need to query */ 335 - goto cifs_create_set_dentry; 336 - else if ((rc != -EIO) && (rc != -EREMOTE) && 331 + if (rc == 0) { 332 + posix_create = true; 333 + if (newinode == NULL) /* query inode info */ 334 + goto cifs_create_get_file_info; 335 + else /* success, no need to query */ 336 + goto cifs_create_set_dentry; 337 + } else if ((rc != -EIO) && (rc != -EREMOTE) && 337 338 (rc != -EOPNOTSUPP)) /* path not found or net err */ 338 339 goto cifs_create_out; 339 340 /* else fallthrough to retry, using older open call, this is ··· 467 464 if ((nd == NULL) || (!(nd->flags & LOOKUP_OPEN))) { 468 465 /* mknod case - do not leave file open */ 469 466 CIFSSMBClose(xid, tcon, fileHandle); 470 - } else if (newinode) { 467 + } else if (!(posix_create) && (newinode)) { 471 468 cifs_fill_fileinfo(newinode, fileHandle, 472 469 cifs_sb->tcon, write_only); 473 470 }
-14
fs/cifs/file.c
··· 129 129 struct file *file, struct cifsInodeInfo *pCifsInode, 130 130 struct cifsFileInfo *pCifsFile, int oplock, u16 netfid) 131 131 { 132 - struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 133 - /* struct timespec temp; */ /* BB REMOVEME BB */ 134 132 135 133 file->private_data = kmalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); 136 134 if (file->private_data == NULL) 137 135 return -ENOMEM; 138 136 pCifsFile = cifs_init_private(file->private_data, inode, file, netfid); 139 137 write_lock(&GlobalSMBSeslock); 140 - list_add(&pCifsFile->tlist, &cifs_sb->tcon->openFileList); 141 138 142 139 pCifsInode = CIFS_I(file->f_path.dentry->d_inode); 143 140 if (pCifsInode == NULL) { 144 141 write_unlock(&GlobalSMBSeslock); 145 142 return -EINVAL; 146 - } 147 - 148 - /* want handles we can use to read with first 149 - in the list so we do not have to walk the 150 - list to search for one in write_begin */ 151 - if ((file->f_flags & O_ACCMODE) == O_WRONLY) { 152 - list_add_tail(&pCifsFile->flist, 153 - &pCifsInode->openFileList); 154 - } else { 155 - list_add(&pCifsFile->flist, 156 - &pCifsInode->openFileList); 157 143 } 158 144 159 145 if (pCifsInode->clientCanCacheRead) {