Skip to content

Commit 2536413

Browse files
piastrysmfrench
authored andcommitted
CIFS: Move create code use ops struct
Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org> Signed-off-by: Steve French <smfrench@gmail.com>
1 parent b7546bc commit 2536413

3 files changed

Lines changed: 58 additions & 49 deletions

File tree

‎fs/cifs/dir.c‎

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,18 @@ check_name(struct dentry *direntry)
160160
static int
161161
cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
162162
struct tcon_link *tlink, unsigned oflags, umode_t mode,
163-
__u32 *oplock, __u16 *fileHandle, int *created)
163+
__u32 *oplock, struct cifs_fid *fid, int *created)
164164
{
165165
int rc = -ENOENT;
166166
int create_options = CREATE_NOT_DIR;
167-
int desiredAccess;
167+
int desired_access;
168168
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
169169
struct cifs_tcon *tcon = tlink_tcon(tlink);
170170
char *full_path = NULL;
171171
FILE_ALL_INFO *buf = NULL;
172172
struct inode *newinode = NULL;
173173
int disposition;
174+
struct TCP_Server_Info *server = tcon->ses->server;
174175

175176
*oplock = 0;
176177
if (tcon->ses->server->oplocks)
@@ -185,8 +186,8 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
185186
if (tcon->unix_ext && cap_unix(tcon->ses) && !tcon->broken_posix_open &&
186187
(CIFS_UNIX_POSIX_PATH_OPS_CAP &
187188
le64_to_cpu(tcon->fsUnixInfo.Capability))) {
188-
rc = cifs_posix_open(full_path, &newinode,
189-
inode->i_sb, mode, oflags, oplock, fileHandle, xid);
189+
rc = cifs_posix_open(full_path, &newinode, inode->i_sb, mode,
190+
oflags, oplock, &fid->netfid, xid);
190191
switch (rc) {
191192
case 0:
192193
if (newinode == NULL) {
@@ -202,7 +203,7 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
202203
* close it and proceed as if it were a normal
203204
* lookup.
204205
*/
205-
CIFSSMBClose(xid, tcon, *fileHandle);
206+
CIFSSMBClose(xid, tcon, fid->netfid);
206207
goto cifs_create_get_file_info;
207208
}
208209
/* success, no need to query */
@@ -244,11 +245,11 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
244245
*/
245246
}
246247

247-
desiredAccess = 0;
248+
desired_access = 0;
248249
if (OPEN_FMODE(oflags) & FMODE_READ)
249-
desiredAccess |= GENERIC_READ; /* is this too little? */
250+
desired_access |= GENERIC_READ; /* is this too little? */
250251
if (OPEN_FMODE(oflags) & FMODE_WRITE)
251-
desiredAccess |= GENERIC_WRITE;
252+
desired_access |= GENERIC_WRITE;
252253

253254
disposition = FILE_OVERWRITE_IF;
254255
if ((oflags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
@@ -260,8 +261,15 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
260261
else
261262
cFYI(1, "Create flag not set in create function");
262263

263-
/* BB add processing to set equivalent of mode - e.g. via CreateX with
264-
ACLs */
264+
/*
265+
* BB add processing to set equivalent of mode - e.g. via CreateX with
266+
* ACLs
267+
*/
268+
269+
if (!server->ops->open) {
270+
rc = -ENOSYS;
271+
goto out;
272+
}
265273

266274
buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
267275
if (buf == NULL) {
@@ -279,28 +287,18 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
279287
if (backup_cred(cifs_sb))
280288
create_options |= CREATE_OPEN_BACKUP_INTENT;
281289

282-
if (tcon->ses->capabilities & CAP_NT_SMBS)
283-
rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
284-
desiredAccess, create_options,
285-
fileHandle, oplock, buf, cifs_sb->local_nls,
286-
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
287-
else
288-
rc = -EIO; /* no NT SMB support fall into legacy open below */
289-
290-
if (rc == -EIO) {
291-
/* old server, retry the open legacy style */
292-
rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
293-
desiredAccess, create_options,
294-
fileHandle, oplock, buf, cifs_sb->local_nls,
295-
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
296-
}
290+
rc = server->ops->open(xid, tcon, full_path, disposition,
291+
desired_access, create_options, fid, oplock,
292+
buf, cifs_sb);
297293
if (rc) {
298294
cFYI(1, "cifs_create returned 0x%x", rc);
299295
goto out;
300296
}
301297

302-
/* If Open reported that we actually created a file
303-
then we now have to set the mode if possible */
298+
/*
299+
* If Open reported that we actually created a file then we now have to
300+
* set the mode if possible.
301+
*/
304302
if ((tcon->unix_ext) && (*oplock & CIFS_CREATE_ACTION)) {
305303
struct cifs_unix_set_info_args args = {
306304
.mode = mode,
@@ -321,11 +319,13 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
321319
args.uid = NO_CHANGE_64;
322320
args.gid = NO_CHANGE_64;
323321
}
324-
CIFSSMBUnixSetFileInfo(xid, tcon, &args, *fileHandle,
325-
current->tgid);
322+
CIFSSMBUnixSetFileInfo(xid, tcon, &args, fid->netfid,
323+
current->tgid);
326324
} else {
327-
/* BB implement mode setting via Windows security
328-
descriptors e.g. */
325+
/*
326+
* BB implement mode setting via Windows security
327+
* descriptors e.g.
328+
*/
329329
/* CIFSSMBWinSetPerms(xid,tcon,path,mode,-1,-1,nls);*/
330330

331331
/* Could set r/o dos attribute if mode & 0222 == 0 */
@@ -334,11 +334,11 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
334334
cifs_create_get_file_info:
335335
/* server might mask mode so we have to query for it */
336336
if (tcon->unix_ext)
337-
rc = cifs_get_inode_info_unix(&newinode, full_path,
338-
inode->i_sb, xid);
337+
rc = cifs_get_inode_info_unix(&newinode, full_path, inode->i_sb,
338+
xid);
339339
else {
340-
rc = cifs_get_inode_info(&newinode, full_path, buf,
341-
inode->i_sb, xid, fileHandle);
340+
rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
341+
xid, &fid->netfid);
342342
if (newinode) {
343343
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
344344
newinode->i_mode = mode;
@@ -356,7 +356,8 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
356356
cifs_create_set_dentry:
357357
if (rc != 0) {
358358
cFYI(1, "Create worked, get_inode_info failed rc = %d", rc);
359-
CIFSSMBClose(xid, tcon, *fileHandle);
359+
if (server->ops->close)
360+
server->ops->close(xid, tcon, fid);
360361
goto out;
361362
}
362363
d_drop(direntry);
@@ -377,6 +378,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
377378
unsigned int xid;
378379
struct tcon_link *tlink;
379380
struct cifs_tcon *tcon;
381+
struct TCP_Server_Info *server;
380382
struct cifs_fid fid;
381383
__u32 oplock;
382384
struct cifsFileInfo *file_info;
@@ -414,22 +416,25 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
414416
goto out_free_xid;
415417

416418
tcon = tlink_tcon(tlink);
419+
server = tcon->ses->server;
417420

418421
rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
419-
&oplock, &fid.netfid, opened);
422+
&oplock, &fid, opened);
420423

421424
if (rc)
422425
goto out;
423426

424427
rc = finish_open(file, direntry, generic_file_open, opened);
425428
if (rc) {
426-
CIFSSMBClose(xid, tcon, fid.netfid);
429+
if (server->ops->close)
430+
server->ops->close(xid, tcon, &fid);
427431
goto out;
428432
}
429433

430434
file_info = cifs_new_fileinfo(&fid, file, tlink, oplock);
431435
if (file_info == NULL) {
432-
CIFSSMBClose(xid, tcon, fid.netfid);
436+
if (server->ops->close)
437+
server->ops->close(xid, tcon, &fid);
433438
rc = -ENOMEM;
434439
}
435440

@@ -454,7 +459,9 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode,
454459
*/
455460
unsigned oflags = O_EXCL | O_CREAT | O_RDWR;
456461
struct tcon_link *tlink;
457-
__u16 fileHandle;
462+
struct cifs_tcon *tcon;
463+
struct TCP_Server_Info *server;
464+
struct cifs_fid fid;
458465
__u32 oplock;
459466
int created = FILE_CREATED;
460467

@@ -467,9 +474,11 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode,
467474
goto out_free_xid;
468475

469476
rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
470-
&oplock, &fileHandle, &created);
471-
if (!rc)
472-
CIFSSMBClose(xid, tlink_tcon(tlink), fileHandle);
477+
&oplock, &fid, &created);
478+
tcon = tlink_tcon(tlink);
479+
server = tcon->ses->server;
480+
if (!rc && server->ops->close)
481+
server->ops->close(xid, tcon, &fid);
473482

474483
cifs_put_tlink(tlink);
475484
out_free_xid:

‎fs/cifs/file.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
312312
if (list_empty(&cifsi->openFileList)) {
313313
cFYI(1, "closing last open instance for inode %p",
314314
cifs_file->dentry->d_inode);
315-
316-
/* in strict cache mode we need invalidate mapping on the last
317-
close because it may cause a error when we open this file
318-
again and get at least level II oplock */
315+
/*
316+
* In strict cache mode we need invalidate mapping on the last
317+
* close because it may cause a error when we open this file
318+
* again and get at least level II oplock.
319+
*/
319320
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO)
320321
CIFS_I(inode)->invalid_mapping = true;
321-
322322
cifs_set_oplock_level(cifsi, 0);
323323
}
324324
spin_unlock(&cifs_file_list_lock);

‎fs/cifs/smb1ops.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ cifs_open_file(const unsigned int xid, struct cifs_tcon *tcon, const char *path,
622622
{
623623
if (!(tcon->ses->capabilities & CAP_NT_SMBS))
624624
return SMBLegacyOpen(xid, tcon, path, disposition,
625-
desired_access, CREATE_NOT_DIR,
625+
desired_access, create_options,
626626
&fid->netfid, oplock, buf,
627627
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
628628
& CIFS_MOUNT_MAP_SPECIAL_CHR);

0 commit comments

Comments
 (0)