Skip to content

Commit 6d3ea7e

Browse files
committed
CIFS: Make use of common cifs_build_path_to_root for CIFS and SMB2
because the is no difference here. This also adds support of prefixpath mount option for SMB2. Signed-off-by: Pavel Shilovsky <piastry@etersoft.ru> Reviewed-by: Jeff Layton <jlayton@redhat.com> Signed-off-by: Steve French <smfrench@gmail.com>
1 parent e5e69ab commit 6d3ea7e

7 files changed

Lines changed: 44 additions & 68 deletions

File tree

‎fs/cifs/cifsfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ cifs_get_root(struct smb_vol *vol, struct super_block *sb)
539539
char *s, *p;
540540
char sep;
541541

542-
full_path = build_path_to_root(vol, cifs_sb,
543-
cifs_sb_master_tcon(cifs_sb));
542+
full_path = cifs_build_path_to_root(vol, cifs_sb,
543+
cifs_sb_master_tcon(cifs_sb));
544544
if (full_path == NULL)
545545
return ERR_PTR(-ENOMEM);
546546

‎fs/cifs/cifsglob.h‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,6 @@ struct smb_version_operations {
280280
/* set attributes */
281281
int (*set_file_info)(struct inode *, const char *, FILE_BASIC_INFO *,
282282
const unsigned int);
283-
/* build a full path to the root of the mount */
284-
char * (*build_path_to_root)(struct smb_vol *, struct cifs_sb_info *,
285-
struct cifs_tcon *);
286283
/* check if we can send an echo or nor */
287284
bool (*can_echo)(struct TCP_Server_Info *);
288285
/* send echo request */
@@ -1084,15 +1081,6 @@ convert_delimiter(char *path, char delim)
10841081
}
10851082
}
10861083

1087-
static inline char *
1088-
build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
1089-
struct cifs_tcon *tcon)
1090-
{
1091-
if (!vol->ops->build_path_to_root)
1092-
return NULL;
1093-
return vol->ops->build_path_to_root(vol, cifs_sb, tcon);
1094-
}
1095-
10961084
#ifdef CONFIG_CIFS_STATS
10971085
#define cifs_stats_inc atomic_inc
10981086

‎fs/cifs/cifsproto.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ extern int init_cifs_idmap(void);
6060
extern void exit_cifs_idmap(void);
6161
extern void cifs_destroy_idmaptrees(void);
6262
extern char *build_path_from_dentry(struct dentry *);
63+
extern char *cifs_build_path_to_root(struct smb_vol *vol,
64+
struct cifs_sb_info *cifs_sb,
65+
struct cifs_tcon *tcon);
6366
extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
6467
extern char *cifs_compose_mount_options(const char *sb_mountdata,
6568
const char *fullpath, const struct dfs_info3_param *ref,

‎fs/cifs/connect.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,8 +3261,10 @@ cifs_cleanup_volume_info(struct smb_vol *volume_info)
32613261

32623262

32633263
#ifdef CONFIG_CIFS_DFS_UPCALL
3264-
/* build_path_to_root returns full path to root when
3265-
* we do not have an exiting connection (tcon) */
3264+
/*
3265+
* cifs_build_path_to_root returns full path to root when we do not have an
3266+
* exiting connection (tcon)
3267+
*/
32663268
static char *
32673269
build_unc_path_to_root(const struct smb_vol *vol,
32683270
const struct cifs_sb_info *cifs_sb)
@@ -3518,8 +3520,10 @@ cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *volume_info)
35183520
rc = -ENOSYS;
35193521
goto mount_fail_check;
35203522
}
3521-
/* build_path_to_root works only when we have a valid tcon */
3522-
full_path = build_path_to_root(volume_info, cifs_sb, tcon);
3523+
/*
3524+
* cifs_build_path_to_root works only when we have a valid tcon
3525+
*/
3526+
full_path = cifs_build_path_to_root(volume_info, cifs_sb, tcon);
35233527
if (full_path == NULL) {
35243528
rc = -ENOMEM;
35253529
goto mount_fail_check;

‎fs/cifs/dir.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,37 @@ renew_parental_timestamps(struct dentry *direntry)
4444
} while (!IS_ROOT(direntry));
4545
}
4646

47+
char *
48+
cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
49+
struct cifs_tcon *tcon)
50+
{
51+
int pplen = vol->prepath ? strlen(vol->prepath) : 0;
52+
int dfsplen;
53+
char *full_path = NULL;
54+
55+
/* if no prefix path, simply set path to the root of share to "" */
56+
if (pplen == 0) {
57+
full_path = kzalloc(1, GFP_KERNEL);
58+
return full_path;
59+
}
60+
61+
if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
62+
dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
63+
else
64+
dfsplen = 0;
65+
66+
full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
67+
if (full_path == NULL)
68+
return full_path;
69+
70+
if (dfsplen)
71+
strncpy(full_path, tcon->treeName, dfsplen);
72+
strncpy(full_path + dfsplen, vol->prepath, pplen);
73+
convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
74+
full_path[dfsplen + pplen] = 0; /* add trailing null */
75+
return full_path;
76+
}
77+
4778
/* Note: caller must free return buffer */
4879
char *
4980
build_path_from_dentry(struct dentry *direntry)

‎fs/cifs/smb1ops.c‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -575,37 +575,6 @@ cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
575575
return CIFSSMBQFileInfo(xid, tcon, fid->netfid, data);
576576
}
577577

578-
static char *
579-
cifs_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
580-
struct cifs_tcon *tcon)
581-
{
582-
int pplen = vol->prepath ? strlen(vol->prepath) : 0;
583-
int dfsplen;
584-
char *full_path = NULL;
585-
586-
/* if no prefix path, simply set path to the root of share to "" */
587-
if (pplen == 0) {
588-
full_path = kzalloc(1, GFP_KERNEL);
589-
return full_path;
590-
}
591-
592-
if (tcon->Flags & SMB_SHARE_IS_IN_DFS)
593-
dfsplen = strnlen(tcon->treeName, MAX_TREE_SIZE + 1);
594-
else
595-
dfsplen = 0;
596-
597-
full_path = kmalloc(dfsplen + pplen + 1, GFP_KERNEL);
598-
if (full_path == NULL)
599-
return full_path;
600-
601-
if (dfsplen)
602-
strncpy(full_path, tcon->treeName, dfsplen);
603-
strncpy(full_path + dfsplen, vol->prepath, pplen);
604-
convert_delimiter(full_path, CIFS_DIR_SEP(cifs_sb));
605-
full_path[dfsplen + pplen] = 0; /* add trailing null */
606-
return full_path;
607-
}
608-
609578
static void
610579
cifs_clear_stats(struct cifs_tcon *tcon)
611580
{
@@ -943,7 +912,6 @@ struct smb_version_operations smb1_operations = {
943912
.set_path_size = CIFSSMBSetEOF,
944913
.set_file_size = CIFSSMBSetFileSize,
945914
.set_file_info = smb_set_file_info,
946-
.build_path_to_root = cifs_build_path_to_root,
947915
.echo = CIFSSMBEcho,
948916
.mkdir = CIFSSMBMkDir,
949917
.mkdir_setinfo = cifs_mkdir_setinfo,

‎fs/cifs/smb2ops.c‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -262,23 +262,6 @@ smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
262262
return rc;
263263
}
264264

265-
static char *
266-
smb2_build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
267-
struct cifs_tcon *tcon)
268-
{
269-
int pplen = vol->prepath ? strlen(vol->prepath) : 0;
270-
char *full_path = NULL;
271-
272-
/* if no prefix path, simply set path to the root of share to "" */
273-
if (pplen == 0) {
274-
full_path = kzalloc(2, GFP_KERNEL);
275-
return full_path;
276-
}
277-
278-
cERROR(1, "prefixpath is not supported for SMB2 now");
279-
return NULL;
280-
}
281-
282265
static bool
283266
smb2_can_echo(struct TCP_Server_Info *server)
284267
{
@@ -613,7 +596,6 @@ struct smb_version_operations smb21_operations = {
613596
.set_path_size = smb2_set_path_size,
614597
.set_file_size = smb2_set_file_size,
615598
.set_file_info = smb2_set_file_info,
616-
.build_path_to_root = smb2_build_path_to_root,
617599
.mkdir = smb2_mkdir,
618600
.mkdir_setinfo = smb2_mkdir_setinfo,
619601
.rmdir = smb2_rmdir,

0 commit comments

Comments
 (0)