Skip to content

Commit 348a04a

Browse files
Paulo Alcantarasmfrench
authored andcommitted
smb: client: get rid of dfs code dep in namespace.c
Make namespace.c being built without requiring CONFIG_CIFS_DFS_UPCALL=y by moving set_dest_addr() to dfs.c and call it at the beginning of dfs_mount_share() so it can chase the DFS link starting from the correct server in @ctx->dstaddr. Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 0a04993 commit 348a04a

File tree

7 files changed

+57
-72
lines changed

7 files changed

+57
-72
lines changed

fs/smb/client/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ cifs-y := trace.o cifsfs.o cifs_debug.o connect.o dir.o file.o \
1111
readdir.o ioctl.o sess.o export.o unc.o winucase.o \
1212
smb2ops.o smb2maperror.o smb2transport.o \
1313
smb2misc.o smb2pdu.o smb2inode.o smb2file.o cifsacl.o fs_context.o \
14-
dns_resolve.o cifs_spnego_negtokeninit.asn1.o asn1.o
14+
dns_resolve.o cifs_spnego_negtokeninit.asn1.o asn1.o \
15+
namespace.o
1516

1617
$(obj)/asn1.o: $(obj)/cifs_spnego_negtokeninit.asn1.h
1718

@@ -21,7 +22,7 @@ cifs-$(CONFIG_CIFS_XATTR) += xattr.o
2122

2223
cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
2324

24-
cifs-$(CONFIG_CIFS_DFS_UPCALL) += namespace.o dfs_cache.o dfs.o
25+
cifs-$(CONFIG_CIFS_DFS_UPCALL) += dfs_cache.o dfs.o
2526

2627
cifs-$(CONFIG_CIFS_SWN_UPCALL) += netlink.o cifs_swn.o
2728

fs/smb/client/cifsfs.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,7 @@ extern void cifs_pages_write_redirty(struct inode *inode, loff_t start, unsigned
118118
extern const struct dentry_operations cifs_dentry_ops;
119119
extern const struct dentry_operations cifs_ci_dentry_ops;
120120

121-
#ifdef CONFIG_CIFS_DFS_UPCALL
122121
extern struct vfsmount *cifs_d_automount(struct path *path);
123-
#else
124-
static inline struct vfsmount *cifs_d_automount(struct path *path)
125-
{
126-
return ERR_PTR(-EREMOTE);
127-
}
128-
#endif
129122

130123
/* Functions related to symlinks */
131124
extern const char *cifs_get_link(struct dentry *, struct inode *,

fs/smb/client/cifsproto.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,7 @@ extern void cifs_put_tcp_session(struct TCP_Server_Info *server,
295295
int from_reconnect);
296296
extern void cifs_put_tcon(struct cifs_tcon *tcon);
297297

298-
#if IS_ENABLED(CONFIG_CIFS_DFS_UPCALL)
299298
extern void cifs_release_automount_timer(void);
300-
#else /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */
301-
#define cifs_release_automount_timer() do { } while (0)
302-
#endif /* ! IS_ENABLED(CONFIG_CIFS_DFS_UPCALL) */
303299

304300
void cifs_proc_init(void);
305301
void cifs_proc_clean(void);

fs/smb/client/dfs.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,28 @@ static int __dfs_mount_share(struct cifs_mount_ctx *mnt_ctx)
263263
return rc;
264264
}
265265

266+
/* Resolve UNC hostname in @ctx->source and set ip addr in @ctx->dstaddr */
267+
static int update_fs_context_dstaddr(struct smb3_fs_context *ctx)
268+
{
269+
struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr;
270+
int rc;
271+
272+
rc = dns_resolve_server_name_to_ip(ctx->source, addr, NULL);
273+
if (!rc)
274+
cifs_set_port(addr, ctx->port);
275+
return rc;
276+
}
277+
266278
int dfs_mount_share(struct cifs_mount_ctx *mnt_ctx, bool *isdfs)
267279
{
268280
struct smb3_fs_context *ctx = mnt_ctx->fs_ctx;
269281
bool nodfs = ctx->nodfs;
270282
int rc;
271283

284+
rc = update_fs_context_dstaddr(ctx);
285+
if (rc)
286+
return rc;
287+
272288
*isdfs = false;
273289
rc = get_session(mnt_ctx, NULL);
274290
if (rc)

fs/smb/client/dfs.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -138,43 +138,6 @@ static inline int dfs_get_referral(struct cifs_mount_ctx *mnt_ctx, const char *p
138138
cifs_remap(cifs_sb), path, ref, tl);
139139
}
140140

141-
/* Return DFS full path out of a dentry set for automount */
142-
static inline char *dfs_get_automount_devname(struct dentry *dentry, void *page)
143-
{
144-
struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
145-
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
146-
size_t len;
147-
char *s;
148-
149-
spin_lock(&tcon->tc_lock);
150-
if (unlikely(!tcon->origin_fullpath)) {
151-
spin_unlock(&tcon->tc_lock);
152-
return ERR_PTR(-EREMOTE);
153-
}
154-
spin_unlock(&tcon->tc_lock);
155-
156-
s = dentry_path_raw(dentry, page, PATH_MAX);
157-
if (IS_ERR(s))
158-
return s;
159-
/* for root, we want "" */
160-
if (!s[1])
161-
s++;
162-
163-
spin_lock(&tcon->tc_lock);
164-
len = strlen(tcon->origin_fullpath);
165-
if (s < (char *)page + len) {
166-
spin_unlock(&tcon->tc_lock);
167-
return ERR_PTR(-ENAMETOOLONG);
168-
}
169-
170-
s -= len;
171-
memcpy(s, tcon->origin_fullpath, len);
172-
spin_unlock(&tcon->tc_lock);
173-
convert_delimiter(s, '/');
174-
175-
return s;
176-
}
177-
178141
static inline void dfs_put_root_smb_sessions(struct list_head *head)
179142
{
180143
struct dfs_root_ses *root, *tmp;

fs/smb/client/inode.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,9 @@ static void cifs_set_ops(struct inode *inode)
5858
inode->i_data.a_ops = &cifs_addr_ops;
5959
break;
6060
case S_IFDIR:
61-
#ifdef CONFIG_CIFS_DFS_UPCALL
6261
if (IS_AUTOMOUNT(inode)) {
6362
inode->i_op = &cifs_namespace_inode_operations;
6463
} else {
65-
#else /* NO DFS support, treat as a directory */
66-
{
67-
#endif
6864
inode->i_op = &cifs_dir_inode_ops;
6965
inode->i_fop = &cifs_dir_ops;
7066
}

fs/smb/client/namespace.c

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Copyright (C) International Business Machines Corp., 2008
77
* Author(s): Igor Mammedov ([email protected])
88
* Steve French ([email protected])
9+
* Copyright (c) 2023 Paulo Alcantara <[email protected]>
910
*/
1011

1112
#include <linux/dcache.h>
@@ -18,9 +19,7 @@
1819
#include "cifsglob.h"
1920
#include "cifsproto.h"
2021
#include "cifsfs.h"
21-
#include "dns_resolve.h"
2222
#include "cifs_debug.h"
23-
#include "dfs.h"
2423
#include "fs_context.h"
2524

2625
static LIST_HEAD(cifs_automount_list);
@@ -118,15 +117,41 @@ cifs_build_devname(char *nodename, const char *prepath)
118117
return dev;
119118
}
120119

121-
static int set_dest_addr(struct smb3_fs_context *ctx)
120+
/* Return full path out of a dentry set for automount */
121+
static char *automount_fullpath(struct dentry *dentry, void *page)
122122
{
123-
struct sockaddr *addr = (struct sockaddr *)&ctx->dstaddr;
124-
int rc;
123+
struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
124+
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
125+
size_t len;
126+
char *s;
127+
128+
spin_lock(&tcon->tc_lock);
129+
if (unlikely(!tcon->origin_fullpath)) {
130+
spin_unlock(&tcon->tc_lock);
131+
return ERR_PTR(-EREMOTE);
132+
}
133+
spin_unlock(&tcon->tc_lock);
134+
135+
s = dentry_path_raw(dentry, page, PATH_MAX);
136+
if (IS_ERR(s))
137+
return s;
138+
/* for root, we want "" */
139+
if (!s[1])
140+
s++;
141+
142+
spin_lock(&tcon->tc_lock);
143+
len = strlen(tcon->origin_fullpath);
144+
if (s < (char *)page + len) {
145+
spin_unlock(&tcon->tc_lock);
146+
return ERR_PTR(-ENAMETOOLONG);
147+
}
125148

126-
rc = dns_resolve_server_name_to_ip(ctx->source, addr, NULL);
127-
if (!rc)
128-
cifs_set_port(addr, ctx->port);
129-
return rc;
149+
s -= len;
150+
memcpy(s, tcon->origin_fullpath, len);
151+
spin_unlock(&tcon->tc_lock);
152+
convert_delimiter(s, '/');
153+
154+
return s;
130155
}
131156

132157
/*
@@ -166,7 +191,7 @@ static struct vfsmount *cifs_do_automount(struct path *path)
166191
ctx = smb3_fc2context(fc);
167192

168193
page = alloc_dentry_path();
169-
full_path = dfs_get_automount_devname(mntpt, page);
194+
full_path = automount_fullpath(mntpt, page);
170195
if (IS_ERR(full_path)) {
171196
mnt = ERR_CAST(full_path);
172197
goto out;
@@ -196,15 +221,10 @@ static struct vfsmount *cifs_do_automount(struct path *path)
196221
ctx->source = NULL;
197222
goto out;
198223
}
199-
cifs_dbg(FYI, "%s: ctx: source=%s UNC=%s prepath=%s dstaddr=%pISpc\n",
200-
__func__, ctx->source, ctx->UNC, ctx->prepath, &ctx->dstaddr);
201-
202-
rc = set_dest_addr(ctx);
203-
if (!rc)
204-
mnt = fc_mount(fc);
205-
else
206-
mnt = ERR_PTR(rc);
224+
cifs_dbg(FYI, "%s: ctx: source=%s UNC=%s prepath=%s\n",
225+
__func__, ctx->source, ctx->UNC, ctx->prepath);
207226

227+
mnt = fc_mount(fc);
208228
out:
209229
put_fs_context(fc);
210230
free_dentry_path(page);

0 commit comments

Comments
 (0)