aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSteve French <sfrench@us.ibm.com>2009-05-21 18:21:53 -0400
committerSteve French <sfrench@us.ibm.com>2009-05-21 18:38:08 -0400
commit703a3b8e5c01cf6fb33c6d8dc99905f889a4e992 (patch)
tree56b6f7bd0379efc28fd488b15fe121a03d092f3d /fs
parent5805977e63a36ad56594a623f3bd2bebcb7db233 (diff)
[CIFS] fix posix open regression
Posix open code was not properly adding the file to the list of open files. Fix allocating cifsFileInfo more than once, and adding twice to flist and tlist. Also fix mode setting to be done in one place in these paths. Signed-off-by: Steve French <sfrench@us.ibm.com> Reviewed-by: Shirish Pargaonkar <shirishp@us.ibm.com> Tested-by: Jeff Layton <jlayton@redhat.com> Tested-by: Luca Tettamanti <kronos.it@gmail.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/cifs/dir.c14
-rw-r--r--fs/cifs/file.c66
2 files changed, 44 insertions, 36 deletions
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 11431ed72a7f..f49d684edd96 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -225,6 +225,7 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
225 if (!(oflags & FMODE_READ)) 225 if (!(oflags & FMODE_READ))
226 write_only = true; 226 write_only = true;
227 227
228 mode &= ~current_umask();
228 rc = CIFSPOSIXCreate(xid, cifs_sb->tcon, posix_flags, mode, 229 rc = CIFSPOSIXCreate(xid, cifs_sb->tcon, posix_flags, mode,
229 pnetfid, presp_data, &oplock, full_path, 230 pnetfid, presp_data, &oplock, full_path,
230 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 231 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
@@ -310,7 +311,6 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
310 return -ENOMEM; 311 return -ENOMEM;
311 } 312 }
312 313
313 mode &= ~current_umask();
314 if (oplockEnabled) 314 if (oplockEnabled)
315 oplock = REQ_OPLOCK; 315 oplock = REQ_OPLOCK;
316 316
@@ -336,7 +336,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
336 else /* success, no need to query */ 336 else /* success, no need to query */
337 goto cifs_create_set_dentry; 337 goto cifs_create_set_dentry;
338 } else if ((rc != -EIO) && (rc != -EREMOTE) && 338 } else if ((rc != -EIO) && (rc != -EREMOTE) &&
339 (rc != -EOPNOTSUPP)) /* path not found or net err */ 339 (rc != -EOPNOTSUPP) && (rc != -EINVAL))
340 goto cifs_create_out; 340 goto cifs_create_out;
341 /* else fallthrough to retry, using older open call, this is 341 /* else fallthrough to retry, using older open call, this is
342 case where server does not support this SMB level, and 342 case where server does not support this SMB level, and
@@ -609,7 +609,6 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
609 int xid; 609 int xid;
610 int rc = 0; /* to get around spurious gcc warning, set to zero here */ 610 int rc = 0; /* to get around spurious gcc warning, set to zero here */
611 int oplock = 0; 611 int oplock = 0;
612 int mode;
613 __u16 fileHandle = 0; 612 __u16 fileHandle = 0;
614 bool posix_open = false; 613 bool posix_open = false;
615 struct cifs_sb_info *cifs_sb; 614 struct cifs_sb_info *cifs_sb;
@@ -660,13 +659,12 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
660 659
661 if (pTcon->unix_ext) { 660 if (pTcon->unix_ext) {
662 if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY)) && 661 if (!(nd->flags & (LOOKUP_PARENT | LOOKUP_DIRECTORY)) &&
663 (nd->flags & LOOKUP_OPEN)) { 662 (nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open) {
664 if (!((nd->intent.open.flags & O_CREAT) && 663 if (!((nd->intent.open.flags & O_CREAT) &&
665 (nd->intent.open.flags & O_EXCL))) { 664 (nd->intent.open.flags & O_EXCL))) {
666 mode = nd->intent.open.create_mode &
667 ~current_umask();
668 rc = cifs_posix_open(full_path, &newInode, 665 rc = cifs_posix_open(full_path, &newInode,
669 parent_dir_inode->i_sb, mode, 666 parent_dir_inode->i_sb,
667 nd->intent.open.create_mode,
670 nd->intent.open.flags, &oplock, 668 nd->intent.open.flags, &oplock,
671 &fileHandle, xid); 669 &fileHandle, xid);
672 /* 670 /*
@@ -681,6 +679,8 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
681 */ 679 */
682 if ((rc != -EINVAL) && (rc != -EOPNOTSUPP)) 680 if ((rc != -EINVAL) && (rc != -EOPNOTSUPP))
683 posix_open = true; 681 posix_open = true;
682 else
683 pTcon->broken_posix_open = true;
684 } 684 }
685 } 685 }
686 if (!posix_open) 686 if (!posix_open)
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 38c06f826575..302ea15f02e6 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -130,10 +130,6 @@ static inline int cifs_posix_open_inode_helper(struct inode *inode,
130 struct cifsFileInfo *pCifsFile, int oplock, u16 netfid) 130 struct cifsFileInfo *pCifsFile, int oplock, u16 netfid)
131{ 131{
132 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); 133 write_lock(&GlobalSMBSeslock);
138 134
139 pCifsInode = CIFS_I(file->f_path.dentry->d_inode); 135 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
@@ -184,6 +180,38 @@ psx_client_can_cache:
184 return 0; 180 return 0;
185} 181}
186 182
183static struct cifsFileInfo *
184cifs_fill_filedata(struct file *file)
185{
186 struct list_head *tmp;
187 struct cifsFileInfo *pCifsFile = NULL;
188 struct cifsInodeInfo *pCifsInode = NULL;
189
190 /* search inode for this file and fill in file->private_data */
191 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
192 read_lock(&GlobalSMBSeslock);
193 list_for_each(tmp, &pCifsInode->openFileList) {
194 pCifsFile = list_entry(tmp, struct cifsFileInfo, flist);
195 if ((pCifsFile->pfile == NULL) &&
196 (pCifsFile->pid == current->tgid)) {
197 /* mode set in cifs_create */
198
199 /* needed for writepage */
200 pCifsFile->pfile = file;
201 file->private_data = pCifsFile;
202 break;
203 }
204 }
205 read_unlock(&GlobalSMBSeslock);
206
207 if (file->private_data != NULL) {
208 return pCifsFile;
209 } else if ((file->f_flags & O_CREAT) && (file->f_flags & O_EXCL))
210 cERROR(1, ("could not find file instance for "
211 "new file %p", file));
212 return NULL;
213}
214
187/* all arguments to this function must be checked for validity in caller */ 215/* all arguments to this function must be checked for validity in caller */
188static inline int cifs_open_inode_helper(struct inode *inode, struct file *file, 216static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
189 struct cifsInodeInfo *pCifsInode, struct cifsFileInfo *pCifsFile, 217 struct cifsInodeInfo *pCifsInode, struct cifsFileInfo *pCifsFile,
@@ -258,7 +286,6 @@ int cifs_open(struct inode *inode, struct file *file)
258 struct cifsTconInfo *tcon; 286 struct cifsTconInfo *tcon;
259 struct cifsFileInfo *pCifsFile; 287 struct cifsFileInfo *pCifsFile;
260 struct cifsInodeInfo *pCifsInode; 288 struct cifsInodeInfo *pCifsInode;
261 struct list_head *tmp;
262 char *full_path = NULL; 289 char *full_path = NULL;
263 int desiredAccess; 290 int desiredAccess;
264 int disposition; 291 int disposition;
@@ -270,32 +297,12 @@ int cifs_open(struct inode *inode, struct file *file)
270 cifs_sb = CIFS_SB(inode->i_sb); 297 cifs_sb = CIFS_SB(inode->i_sb);
271 tcon = cifs_sb->tcon; 298 tcon = cifs_sb->tcon;
272 299
273 /* search inode for this file and fill in file->private_data */
274 pCifsInode = CIFS_I(file->f_path.dentry->d_inode); 300 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
275 read_lock(&GlobalSMBSeslock); 301 pCifsFile = cifs_fill_filedata(file);
276 list_for_each(tmp, &pCifsInode->openFileList) { 302 if (pCifsFile) {
277 pCifsFile = list_entry(tmp, struct cifsFileInfo,
278 flist);
279 if ((pCifsFile->pfile == NULL) &&
280 (pCifsFile->pid == current->tgid)) {
281 /* mode set in cifs_create */
282
283 /* needed for writepage */
284 pCifsFile->pfile = file;
285
286 file->private_data = pCifsFile;
287 break;
288 }
289 }
290 read_unlock(&GlobalSMBSeslock);
291
292 if (file->private_data != NULL) {
293 rc = 0;
294 FreeXid(xid); 303 FreeXid(xid);
295 return rc; 304 return 0;
296 } else if ((file->f_flags & O_CREAT) && (file->f_flags & O_EXCL)) 305 }
297 cERROR(1, ("could not find file instance for "
298 "new file %p", file));
299 306
300 full_path = build_path_from_dentry(file->f_path.dentry); 307 full_path = build_path_from_dentry(file->f_path.dentry);
301 if (full_path == NULL) { 308 if (full_path == NULL) {
@@ -325,6 +332,7 @@ int cifs_open(struct inode *inode, struct file *file)
325 /* no need for special case handling of setting mode 332 /* no need for special case handling of setting mode
326 on read only files needed here */ 333 on read only files needed here */
327 334
335 pCifsFile = cifs_fill_filedata(file);
328 cifs_posix_open_inode_helper(inode, file, pCifsInode, 336 cifs_posix_open_inode_helper(inode, file, pCifsInode,
329 pCifsFile, oplock, netfid); 337 pCifsFile, oplock, netfid);
330 goto out; 338 goto out;