Skip to content

Commit d81b8a4

Browse files
piastrysmfrench
authored andcommitted
CIFS: Cleanup cifs open codepath
Rename CIFSSMBOpen to CIFS_open and make it take cifs_open_parms structure as a parm. Signed-off-by: Pavel Shilovsky <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 0360d60 commit d81b8a4

File tree

8 files changed

+174
-100
lines changed

8 files changed

+174
-100
lines changed

fs/cifs/cifsacl.c

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,10 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
895895
int oplock = 0;
896896
unsigned int xid;
897897
int rc, create_options = 0;
898-
__u16 fid;
899898
struct cifs_tcon *tcon;
900899
struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
900+
struct cifs_fid fid;
901+
struct cifs_open_parms oparms;
901902

902903
if (IS_ERR(tlink))
903904
return ERR_CAST(tlink);
@@ -908,12 +909,19 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
908909
if (backup_cred(cifs_sb))
909910
create_options |= CREATE_OPEN_BACKUP_INTENT;
910911

911-
rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, READ_CONTROL,
912-
create_options, &fid, &oplock, NULL, cifs_sb->local_nls,
913-
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
912+
oparms.tcon = tcon;
913+
oparms.cifs_sb = cifs_sb;
914+
oparms.desired_access = READ_CONTROL;
915+
oparms.create_options = create_options;
916+
oparms.disposition = FILE_OPEN;
917+
oparms.path = path;
918+
oparms.fid = &fid;
919+
oparms.reconnect = false;
920+
921+
rc = CIFS_open(xid, &oparms, &oplock, NULL);
914922
if (!rc) {
915-
rc = CIFSSMBGetCIFSACL(xid, tcon, fid, &pntsd, pacllen);
916-
CIFSSMBClose(xid, tcon, fid);
923+
rc = CIFSSMBGetCIFSACL(xid, tcon, fid.netfid, &pntsd, pacllen);
924+
CIFSSMBClose(xid, tcon, fid.netfid);
917925
}
918926

919927
cifs_put_tlink(tlink);
@@ -950,10 +958,11 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
950958
int oplock = 0;
951959
unsigned int xid;
952960
int rc, access_flags, create_options = 0;
953-
__u16 fid;
954961
struct cifs_tcon *tcon;
955962
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
956963
struct tcon_link *tlink = cifs_sb_tlink(cifs_sb);
964+
struct cifs_fid fid;
965+
struct cifs_open_parms oparms;
957966

958967
if (IS_ERR(tlink))
959968
return PTR_ERR(tlink);
@@ -969,18 +978,25 @@ int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
969978
else
970979
access_flags = WRITE_DAC;
971980

972-
rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, access_flags,
973-
create_options, &fid, &oplock, NULL, cifs_sb->local_nls,
974-
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
981+
oparms.tcon = tcon;
982+
oparms.cifs_sb = cifs_sb;
983+
oparms.desired_access = access_flags;
984+
oparms.create_options = create_options;
985+
oparms.disposition = FILE_OPEN;
986+
oparms.path = path;
987+
oparms.fid = &fid;
988+
oparms.reconnect = false;
989+
990+
rc = CIFS_open(xid, &oparms, &oplock, NULL);
975991
if (rc) {
976992
cifs_dbg(VFS, "Unable to open file to set ACL\n");
977993
goto out;
978994
}
979995

980-
rc = CIFSSMBSetCIFSACL(xid, tcon, fid, pnntsd, acllen, aclflag);
996+
rc = CIFSSMBSetCIFSACL(xid, tcon, fid.netfid, pnntsd, acllen, aclflag);
981997
cifs_dbg(NOISY, "SetCIFSACL rc = %d\n", rc);
982998

983-
CIFSSMBClose(xid, tcon, fid);
999+
CIFSSMBClose(xid, tcon, fid.netfid);
9841000
out:
9851001
free_xid(xid);
9861002
cifs_put_tlink(tlink);

fs/cifs/cifsproto.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,8 @@ extern int CIFSSMBQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
362362
const struct nls_table *nls_codepage);
363363
extern int CIFSSMB_set_compression(const unsigned int xid,
364364
struct cifs_tcon *tcon, __u16 fid);
365-
extern int CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon,
366-
const char *path, const int disposition,
367-
const int desired_access, const int create_options,
368-
__u16 *netfid, int *oplock, FILE_ALL_INFO *buf,
369-
const struct nls_table *nls, int remap);
365+
extern int CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms,
366+
int *oplock, FILE_ALL_INFO *buf);
370367
extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
371368
const char *fileName, const int disposition,
372369
const int access_flags, const int omode,

fs/cifs/cifssmb.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,17 +1273,23 @@ SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
12731273
}
12741274

12751275
int
1276-
CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon,
1277-
const char *path, const int disposition, const int desired_access,
1278-
const int create_options, __u16 *netfid, int *oplock,
1279-
FILE_ALL_INFO *buf, const struct nls_table *nls, int remap)
1276+
CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms, int *oplock,
1277+
FILE_ALL_INFO *buf)
12801278
{
12811279
int rc = -EACCES;
12821280
OPEN_REQ *req = NULL;
12831281
OPEN_RSP *rsp = NULL;
12841282
int bytes_returned;
12851283
int name_len;
12861284
__u16 count;
1285+
struct cifs_sb_info *cifs_sb = oparms->cifs_sb;
1286+
struct cifs_tcon *tcon = oparms->tcon;
1287+
int remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
1288+
const struct nls_table *nls = cifs_sb->local_nls;
1289+
int create_options = oparms->create_options;
1290+
int desired_access = oparms->desired_access;
1291+
int disposition = oparms->disposition;
1292+
const char *path = oparms->path;
12871293

12881294
openRetry:
12891295
rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **)&req,
@@ -1367,7 +1373,7 @@ CIFSSMBOpen(const unsigned int xid, struct cifs_tcon *tcon,
13671373
/* 1 byte no need to le_to_cpu */
13681374
*oplock = rsp->OplockLevel;
13691375
/* cifs fid stays in le */
1370-
*netfid = rsp->Fid;
1376+
oparms->fid->netfid = rsp->Fid;
13711377

13721378
/* Let caller know file was created so we can set the mode. */
13731379
/* Do we care about the CreateAction in any other cases? */

fs/cifs/dir.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,8 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
570570
char *full_path = NULL;
571571
struct inode *newinode = NULL;
572572
int oplock = 0;
573-
u16 netfid;
573+
struct cifs_fid fid;
574+
struct cifs_open_parms oparms;
574575
FILE_ALL_INFO *buf = NULL;
575576
unsigned int bytes_written;
576577
struct win_dev *pdev;
@@ -640,10 +641,16 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
640641
if (backup_cred(cifs_sb))
641642
create_options |= CREATE_OPEN_BACKUP_INTENT;
642643

643-
rc = CIFSSMBOpen(xid, tcon, full_path, FILE_CREATE,
644-
GENERIC_WRITE, create_options,
645-
&netfid, &oplock, buf, cifs_sb->local_nls,
646-
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
644+
oparms.tcon = tcon;
645+
oparms.cifs_sb = cifs_sb;
646+
oparms.desired_access = GENERIC_WRITE;
647+
oparms.create_options = create_options;
648+
oparms.disposition = FILE_CREATE;
649+
oparms.path = full_path;
650+
oparms.fid = &fid;
651+
oparms.reconnect = false;
652+
653+
rc = CIFS_open(xid, &oparms, &oplock, buf);
647654
if (rc)
648655
goto mknod_out;
649656

@@ -653,7 +660,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
653660
*/
654661

655662
pdev = (struct win_dev *)buf;
656-
io_parms.netfid = netfid;
663+
io_parms.netfid = fid.netfid;
657664
io_parms.pid = current->tgid;
658665
io_parms.tcon = tcon;
659666
io_parms.offset = 0;
@@ -671,7 +678,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, umode_t mode,
671678
rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, (char *)pdev,
672679
NULL, 0);
673680
} /* else if (S_ISFIFO) */
674-
CIFSSMBClose(xid, tcon, netfid);
681+
CIFSSMBClose(xid, tcon, fid.netfid);
675682
d_drop(direntry);
676683

677684
/* FIXME: add code here to set EAs */

fs/cifs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
678678

679679
/*
680680
* Can not refresh inode by passing in file_info buf to be returned by
681-
* CIFSSMBOpen and then calling get_inode_info with returned buf since
681+
* ops->open and then calling get_inode_info with returned buf since
682682
* file might have write behind data that needs to be flushed and server
683683
* version of file size can be stale. If we knew for sure that inode was
684684
* not dirty locally we could do this.

fs/cifs/inode.c

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,10 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
409409
{
410410
int rc;
411411
int oplock = 0;
412-
__u16 netfid;
413412
struct tcon_link *tlink;
414413
struct cifs_tcon *tcon;
414+
struct cifs_fid fid;
415+
struct cifs_open_parms oparms;
415416
struct cifs_io_parms io_parms;
416417
char buf[24];
417418
unsigned int bytes_read;
@@ -437,18 +438,23 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
437438
return PTR_ERR(tlink);
438439
tcon = tlink_tcon(tlink);
439440

440-
rc = CIFSSMBOpen(xid, tcon, path, FILE_OPEN, GENERIC_READ,
441-
CREATE_NOT_DIR, &netfid, &oplock, NULL,
442-
cifs_sb->local_nls,
443-
cifs_sb->mnt_cifs_flags &
444-
CIFS_MOUNT_MAP_SPECIAL_CHR);
441+
oparms.tcon = tcon;
442+
oparms.cifs_sb = cifs_sb;
443+
oparms.desired_access = GENERIC_READ;
444+
oparms.create_options = CREATE_NOT_DIR;
445+
oparms.disposition = FILE_OPEN;
446+
oparms.path = path;
447+
oparms.fid = &fid;
448+
oparms.reconnect = false;
449+
450+
rc = CIFS_open(xid, &oparms, &oplock, NULL);
445451
if (rc) {
446452
cifs_put_tlink(tlink);
447453
return rc;
448454
}
449455

450456
/* Read header */
451-
io_parms.netfid = netfid;
457+
io_parms.netfid = fid.netfid;
452458
io_parms.pid = current->tgid;
453459
io_parms.tcon = tcon;
454460
io_parms.offset = 0;
@@ -494,7 +500,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
494500
fattr->cf_dtype = DT_REG;
495501
rc = -EOPNOTSUPP; /* or some unknown SFU type */
496502
}
497-
CIFSSMBClose(xid, tcon, netfid);
503+
CIFSSMBClose(xid, tcon, fid.netfid);
498504
cifs_put_tlink(tlink);
499505
return rc;
500506
}
@@ -1035,7 +1041,8 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
10351041
{
10361042
int oplock = 0;
10371043
int rc;
1038-
__u16 netfid;
1044+
struct cifs_fid fid;
1045+
struct cifs_open_parms oparms;
10391046
struct inode *inode = dentry->d_inode;
10401047
struct cifsInodeInfo *cifsInode = CIFS_I(inode);
10411048
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
@@ -1058,10 +1065,16 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
10581065
goto out;
10591066
}
10601067

1061-
rc = CIFSSMBOpen(xid, tcon, full_path, FILE_OPEN,
1062-
DELETE|FILE_WRITE_ATTRIBUTES, CREATE_NOT_DIR,
1063-
&netfid, &oplock, NULL, cifs_sb->local_nls,
1064-
cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
1068+
oparms.tcon = tcon;
1069+
oparms.cifs_sb = cifs_sb;
1070+
oparms.desired_access = DELETE | FILE_WRITE_ATTRIBUTES;
1071+
oparms.create_options = CREATE_NOT_DIR;
1072+
oparms.disposition = FILE_OPEN;
1073+
oparms.path = full_path;
1074+
oparms.fid = &fid;
1075+
oparms.reconnect = false;
1076+
1077+
rc = CIFS_open(xid, &oparms, &oplock, NULL);
10651078
if (rc != 0)
10661079
goto out;
10671080

@@ -1082,7 +1095,7 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
10821095
goto out_close;
10831096
}
10841097
info_buf->Attributes = cpu_to_le32(dosattr);
1085-
rc = CIFSSMBSetFileInfo(xid, tcon, info_buf, netfid,
1098+
rc = CIFSSMBSetFileInfo(xid, tcon, info_buf, fid.netfid,
10861099
current->tgid);
10871100
/* although we would like to mark the file hidden
10881101
if that fails we will still try to rename it */
@@ -1093,7 +1106,8 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
10931106
}
10941107

10951108
/* rename the file */
1096-
rc = CIFSSMBRenameOpenFile(xid, tcon, netfid, NULL, cifs_sb->local_nls,
1109+
rc = CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, NULL,
1110+
cifs_sb->local_nls,
10971111
cifs_sb->mnt_cifs_flags &
10981112
CIFS_MOUNT_MAP_SPECIAL_CHR);
10991113
if (rc != 0) {
@@ -1103,7 +1117,7 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
11031117

11041118
/* try to set DELETE_ON_CLOSE */
11051119
if (!cifsInode->delete_pending) {
1106-
rc = CIFSSMBSetFileDisposition(xid, tcon, true, netfid,
1120+
rc = CIFSSMBSetFileDisposition(xid, tcon, true, fid.netfid,
11071121
current->tgid);
11081122
/*
11091123
* some samba versions return -ENOENT when we try to set the
@@ -1123,7 +1137,7 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
11231137
}
11241138

11251139
out_close:
1126-
CIFSSMBClose(xid, tcon, netfid);
1140+
CIFSSMBClose(xid, tcon, fid.netfid);
11271141
out:
11281142
kfree(info_buf);
11291143
cifs_put_tlink(tlink);
@@ -1135,13 +1149,13 @@ cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
11351149
* them anyway.
11361150
*/
11371151
undo_rename:
1138-
CIFSSMBRenameOpenFile(xid, tcon, netfid, dentry->d_name.name,
1152+
CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, dentry->d_name.name,
11391153
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
11401154
CIFS_MOUNT_MAP_SPECIAL_CHR);
11411155
undo_setattr:
11421156
if (dosattr != origattr) {
11431157
info_buf->Attributes = cpu_to_le32(origattr);
1144-
if (!CIFSSMBSetFileInfo(xid, tcon, info_buf, netfid,
1158+
if (!CIFSSMBSetFileInfo(xid, tcon, info_buf, fid.netfid,
11451159
current->tgid))
11461160
cifsInode->cifsAttrs = origattr;
11471161
}
@@ -1552,7 +1566,8 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
15521566
struct tcon_link *tlink;
15531567
struct cifs_tcon *tcon;
15541568
struct TCP_Server_Info *server;
1555-
__u16 srcfid;
1569+
struct cifs_fid fid;
1570+
struct cifs_open_parms oparms;
15561571
int oplock, rc;
15571572

15581573
tlink = cifs_sb_tlink(cifs_sb);
@@ -1579,17 +1594,23 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
15791594
if (to_dentry->d_parent != from_dentry->d_parent)
15801595
goto do_rename_exit;
15811596

1597+
oparms.tcon = tcon;
1598+
oparms.cifs_sb = cifs_sb;
15821599
/* open the file to be renamed -- we need DELETE perms */
1583-
rc = CIFSSMBOpen(xid, tcon, from_path, FILE_OPEN, DELETE,
1584-
CREATE_NOT_DIR, &srcfid, &oplock, NULL,
1585-
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
1586-
CIFS_MOUNT_MAP_SPECIAL_CHR);
1600+
oparms.desired_access = DELETE;
1601+
oparms.create_options = CREATE_NOT_DIR;
1602+
oparms.disposition = FILE_OPEN;
1603+
oparms.path = from_path;
1604+
oparms.fid = &fid;
1605+
oparms.reconnect = false;
1606+
1607+
rc = CIFS_open(xid, &oparms, &oplock, NULL);
15871608
if (rc == 0) {
1588-
rc = CIFSSMBRenameOpenFile(xid, tcon, srcfid,
1609+
rc = CIFSSMBRenameOpenFile(xid, tcon, fid.netfid,
15891610
(const char *) to_dentry->d_name.name,
15901611
cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
15911612
CIFS_MOUNT_MAP_SPECIAL_CHR);
1592-
CIFSSMBClose(xid, tcon, srcfid);
1613+
CIFSSMBClose(xid, tcon, fid.netfid);
15931614
}
15941615
do_rename_exit:
15951616
cifs_put_tlink(tlink);

0 commit comments

Comments
 (0)