Skip to content

Commit f83709b

Browse files
Paulo Alcantarasmfrench
authored andcommitted
smb: client: get rid of smb311_posix_query_path_info()
Merge smb311_posix_query_path_info into ->query_path_info() to get rid of duplicate code. Signed-off-by: Paulo Alcantara <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 858e748 commit f83709b

File tree

2 files changed

+36
-83
lines changed

2 files changed

+36
-83
lines changed

fs/smb/client/inode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ static int smb311_posix_get_fattr(struct cifs_open_info_data *data,
13121312
const unsigned int xid)
13131313
{
13141314
struct cifs_open_info_data tmp_data = {};
1315+
struct TCP_Server_Info *server;
13151316
struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
13161317
struct cifs_tcon *tcon;
13171318
struct tcon_link *tlink;
@@ -1322,12 +1323,13 @@ static int smb311_posix_get_fattr(struct cifs_open_info_data *data,
13221323
if (IS_ERR(tlink))
13231324
return PTR_ERR(tlink);
13241325
tcon = tlink_tcon(tlink);
1326+
server = tcon->ses->server;
13251327

13261328
/*
13271329
* 1. Fetch file metadata if not provided (data)
13281330
*/
13291331
if (!data) {
1330-
rc = smb311_posix_query_path_info(xid, tcon, cifs_sb,
1332+
rc = server->ops->query_path_info(xid, tcon, cifs_sb,
13311333
full_path, &tmp_data);
13321334
data = &tmp_data;
13331335
}

fs/smb/client/smb2inode.c

Lines changed: 33 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -678,28 +678,44 @@ int smb2_query_path_info(const unsigned int xid,
678678
struct smb2_hdr *hdr;
679679
struct kvec in_iov[2], out_iov[3] = {};
680680
int out_buftype[3] = {};
681-
int cmds[2] = { SMB2_OP_QUERY_INFO, };
681+
int cmds[2];
682682
bool islink;
683683
int i, num_cmds;
684684
int rc, rc2;
685685

686686
data->adjust_tz = false;
687687
data->reparse_point = false;
688688

689-
if (strcmp(full_path, ""))
690-
rc = -ENOENT;
691-
else
692-
rc = open_cached_dir(xid, tcon, full_path, cifs_sb, false, &cfid);
693-
/* If it is a root and its handle is cached then use it */
694-
if (!rc) {
695-
if (cfid->file_all_info_is_valid) {
696-
memcpy(&data->fi, &cfid->file_all_info, sizeof(data->fi));
689+
/*
690+
* BB TODO: Add support for using cached root handle in SMB3.1.1 POSIX.
691+
* Create SMB2_query_posix_info worker function to do non-compounded
692+
* query when we already have an open file handle for this. For now this
693+
* is fast enough (always using the compounded version).
694+
*/
695+
if (!tcon->posix_extensions) {
696+
if (*full_path) {
697+
rc = -ENOENT;
697698
} else {
698-
rc = SMB2_query_info(xid, tcon, cfid->fid.persistent_fid,
699-
cfid->fid.volatile_fid, &data->fi);
699+
rc = open_cached_dir(xid, tcon, full_path,
700+
cifs_sb, false, &cfid);
700701
}
701-
close_cached_dir(cfid);
702-
return rc;
702+
/* If it is a root and its handle is cached then use it */
703+
if (!rc) {
704+
if (cfid->file_all_info_is_valid) {
705+
memcpy(&data->fi, &cfid->file_all_info,
706+
sizeof(data->fi));
707+
} else {
708+
rc = SMB2_query_info(xid, tcon,
709+
cfid->fid.persistent_fid,
710+
cfid->fid.volatile_fid,
711+
&data->fi);
712+
}
713+
close_cached_dir(cfid);
714+
return rc;
715+
}
716+
cmds[0] = SMB2_OP_QUERY_INFO;
717+
} else {
718+
cmds[0] = SMB2_OP_POSIX_QUERY_INFO;
703719
}
704720

705721
in_iov[0].iov_base = data;
@@ -722,6 +738,10 @@ int smb2_query_path_info(const unsigned int xid,
722738
switch (rc) {
723739
case 0:
724740
case -EOPNOTSUPP:
741+
/*
742+
* BB TODO: When support for special files added to Samba
743+
* re-verify this path.
744+
*/
725745
rc = parse_create_response(data, cifs_sb, &out_iov[0]);
726746
if (rc || !data->reparse_point)
727747
goto out;
@@ -761,75 +781,6 @@ int smb2_query_path_info(const unsigned int xid,
761781
return rc;
762782
}
763783

764-
int smb311_posix_query_path_info(const unsigned int xid,
765-
struct cifs_tcon *tcon,
766-
struct cifs_sb_info *cifs_sb,
767-
const char *full_path,
768-
struct cifs_open_info_data *data)
769-
{
770-
int rc;
771-
__u32 create_options = 0;
772-
struct cifsFileInfo *cfile;
773-
struct kvec in_iov[2], out_iov[3] = {};
774-
int out_buftype[3] = {};
775-
int cmds[2] = { SMB2_OP_POSIX_QUERY_INFO, };
776-
int i, num_cmds;
777-
778-
data->adjust_tz = false;
779-
data->reparse_point = false;
780-
781-
/*
782-
* BB TODO: Add support for using the cached root handle.
783-
* Create SMB2_query_posix_info worker function to do non-compounded query
784-
* when we already have an open file handle for this. For now this is fast enough
785-
* (always using the compounded version).
786-
*/
787-
in_iov[0].iov_base = data;
788-
in_iov[0].iov_len = sizeof(*data);
789-
in_iov[1] = in_iov[0];
790-
791-
cifs_get_readable_path(tcon, full_path, &cfile);
792-
rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
793-
FILE_READ_ATTRIBUTES, FILE_OPEN,
794-
create_options, ACL_NO_MODE, in_iov,
795-
cmds, 1, cfile, out_iov, out_buftype);
796-
/*
797-
* If first iov is unset, then SMB session was dropped or we've got a
798-
* cached open file (@cfile).
799-
*/
800-
if (!out_iov[0].iov_base || out_buftype[0] == CIFS_NO_BUFFER)
801-
goto out;
802-
803-
switch (rc) {
804-
case 0:
805-
case -EOPNOTSUPP:
806-
/* BB TODO: When support for special files added to Samba re-verify this path */
807-
rc = parse_create_response(data, cifs_sb, &out_iov[0]);
808-
if (rc || !data->reparse_point)
809-
goto out;
810-
811-
if (data->reparse.tag == IO_REPARSE_TAG_SYMLINK) {
812-
/* symlink already parsed in create response */
813-
num_cmds = 1;
814-
} else {
815-
cmds[1] = SMB2_OP_GET_REPARSE;
816-
num_cmds = 2;
817-
}
818-
create_options |= OPEN_REPARSE_POINT;
819-
cifs_get_readable_path(tcon, full_path, &cfile);
820-
rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
821-
FILE_READ_ATTRIBUTES, FILE_OPEN,
822-
create_options, ACL_NO_MODE, in_iov,
823-
cmds, num_cmds, cfile, NULL, NULL);
824-
break;
825-
}
826-
827-
out:
828-
for (i = 0; i < ARRAY_SIZE(out_buftype); i++)
829-
free_rsp_buf(out_buftype[i], out_iov[i].iov_base);
830-
return rc;
831-
}
832-
833784
int
834785
smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode,
835786
struct cifs_tcon *tcon, const char *name,

0 commit comments

Comments
 (0)