[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 int create_options = CREATE_NOT_DIR; 282 int oplock = 0; 283 int oflags; 284 /* 285 * BB below access is probably too much for mknod to request 286 * but we have to do query and setpathinfo so requesting ··· 329 negotation. EREMOTE indicates DFS junction, which is not 330 handled in posix open */ 331 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) && 337 (rc != -EOPNOTSUPP)) /* path not found or net err */ 338 goto cifs_create_out; 339 /* else fallthrough to retry, using older open call, this is ··· 467 if ((nd == NULL) || (!(nd->flags & LOOKUP_OPEN))) { 468 /* mknod case - do not leave file open */ 469 CIFSSMBClose(xid, tcon, fileHandle); 470 - } else if (newinode) { 471 cifs_fill_fileinfo(newinode, fileHandle, 472 cifs_sb->tcon, write_only); 473 }
··· 281 int create_options = CREATE_NOT_DIR; 282 int oplock = 0; 283 int oflags; 284 + bool posix_create = false; 285 /* 286 * BB below access is probably too much for mknod to request 287 * but we have to do query and setpathinfo so requesting ··· 328 negotation. EREMOTE indicates DFS junction, which is not 329 handled in posix open */ 330 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) && 338 (rc != -EOPNOTSUPP)) /* path not found or net err */ 339 goto cifs_create_out; 340 /* else fallthrough to retry, using older open call, this is ··· 464 if ((nd == NULL) || (!(nd->flags & LOOKUP_OPEN))) { 465 /* mknod case - do not leave file open */ 466 CIFSSMBClose(xid, tcon, fileHandle); 467 + } else if (!(posix_create) && (newinode)) { 468 cifs_fill_fileinfo(newinode, fileHandle, 469 cifs_sb->tcon, write_only); 470 }
-14
fs/cifs/file.c
··· 129 struct file *file, struct cifsInodeInfo *pCifsInode, 130 struct cifsFileInfo *pCifsFile, int oplock, u16 netfid) 131 { 132 - struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); 133 - /* struct timespec temp; */ /* BB REMOVEME BB */ 134 135 file->private_data = kmalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); 136 if (file->private_data == NULL) 137 return -ENOMEM; 138 pCifsFile = cifs_init_private(file->private_data, inode, file, netfid); 139 write_lock(&GlobalSMBSeslock); 140 - list_add(&pCifsFile->tlist, &cifs_sb->tcon->openFileList); 141 142 pCifsInode = CIFS_I(file->f_path.dentry->d_inode); 143 if (pCifsInode == NULL) { 144 write_unlock(&GlobalSMBSeslock); 145 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 } 158 159 if (pCifsInode->clientCanCacheRead) {
··· 129 struct file *file, struct cifsInodeInfo *pCifsInode, 130 struct cifsFileInfo *pCifsFile, int oplock, u16 netfid) 131 { 132 133 file->private_data = kmalloc(sizeof(struct cifsFileInfo), GFP_KERNEL); 134 if (file->private_data == NULL) 135 return -ENOMEM; 136 pCifsFile = cifs_init_private(file->private_data, inode, file, netfid); 137 write_lock(&GlobalSMBSeslock); 138 139 pCifsInode = CIFS_I(file->f_path.dentry->d_inode); 140 if (pCifsInode == NULL) { 141 write_unlock(&GlobalSMBSeslock); 142 return -EINVAL; 143 } 144 145 if (pCifsInode->clientCanCacheRead) {