Skip to content

Commit 565674d

Browse files
metze-sambasmfrench
authored andcommitted
cifs: merge __{cifs,smb2}_reconnect[_tcon]() into cifs_tree_connect()
They were identical execpt to CIFSTCon() vs. SMB2_tcon(). These are also available via ops->tree_connect(). Signed-off-by: Stefan Metzmacher <[email protected]> Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Reviewed-by: Aurelien Aptel <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 1a0e7f7 commit 565674d

File tree

4 files changed

+105
-223
lines changed

4 files changed

+105
-223
lines changed

fs/cifs/cifsproto.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ extern void cifs_move_llist(struct list_head *source, struct list_head *dest);
272272
extern void cifs_free_llist(struct list_head *llist);
273273
extern void cifs_del_lock_waiters(struct cifsLockInfo *lock);
274274

275+
extern int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon,
276+
const struct nls_table *nlsc);
277+
275278
extern int cifs_negotiate_protocol(const unsigned int xid,
276279
struct cifs_ses *ses);
277280
extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,

fs/cifs/cifssmb.c

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -124,116 +124,6 @@ cifs_mark_open_files_invalid(struct cifs_tcon *tcon)
124124
*/
125125
}
126126

127-
#ifdef CONFIG_CIFS_DFS_UPCALL
128-
static int __cifs_reconnect_tcon(const struct nls_table *nlsc,
129-
struct cifs_tcon *tcon)
130-
{
131-
int rc;
132-
struct TCP_Server_Info *server = tcon->ses->server;
133-
struct dfs_cache_tgt_list tl;
134-
struct dfs_cache_tgt_iterator *it = NULL;
135-
char *tree;
136-
const char *tcp_host;
137-
size_t tcp_host_len;
138-
const char *dfs_host;
139-
size_t dfs_host_len;
140-
141-
tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL);
142-
if (!tree)
143-
return -ENOMEM;
144-
145-
if (!tcon->dfs_path) {
146-
if (tcon->ipc) {
147-
scnprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$",
148-
server->hostname);
149-
rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc);
150-
} else {
151-
rc = CIFSTCon(0, tcon->ses, tcon->treeName, tcon, nlsc);
152-
}
153-
goto out;
154-
}
155-
156-
rc = dfs_cache_noreq_find(tcon->dfs_path + 1, NULL, &tl);
157-
if (rc)
158-
goto out;
159-
160-
extract_unc_hostname(server->hostname, &tcp_host, &tcp_host_len);
161-
162-
for (it = dfs_cache_get_tgt_iterator(&tl); it;
163-
it = dfs_cache_get_next_tgt(&tl, it)) {
164-
const char *share, *prefix;
165-
size_t share_len, prefix_len;
166-
bool target_match;
167-
168-
rc = dfs_cache_get_tgt_share(it, &share, &share_len, &prefix,
169-
&prefix_len);
170-
if (rc) {
171-
cifs_dbg(VFS, "%s: failed to parse target share %d\n",
172-
__func__, rc);
173-
continue;
174-
}
175-
176-
extract_unc_hostname(share, &dfs_host, &dfs_host_len);
177-
178-
if (dfs_host_len != tcp_host_len
179-
|| strncasecmp(dfs_host, tcp_host, dfs_host_len) != 0) {
180-
cifs_dbg(FYI, "%s: %.*s doesn't match %.*s\n",
181-
__func__,
182-
(int)dfs_host_len, dfs_host,
183-
(int)tcp_host_len, tcp_host);
184-
185-
rc = match_target_ip(server, dfs_host, dfs_host_len,
186-
&target_match);
187-
if (rc) {
188-
cifs_dbg(VFS, "%s: failed to match target ip: %d\n",
189-
__func__, rc);
190-
break;
191-
}
192-
193-
if (!target_match) {
194-
cifs_dbg(FYI, "%s: skipping target\n", __func__);
195-
continue;
196-
}
197-
}
198-
199-
if (tcon->ipc) {
200-
scnprintf(tree, MAX_TREE_SIZE, "\\\\%.*s\\IPC$",
201-
(int)share_len, share);
202-
rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc);
203-
} else {
204-
scnprintf(tree, MAX_TREE_SIZE, "\\%.*s", (int)share_len,
205-
share);
206-
rc = CIFSTCon(0, tcon->ses, tree, tcon, nlsc);
207-
if (!rc) {
208-
rc = update_super_prepath(tcon, prefix,
209-
prefix_len);
210-
break;
211-
}
212-
}
213-
if (rc == -EREMOTE)
214-
break;
215-
}
216-
217-
if (!rc) {
218-
if (it)
219-
rc = dfs_cache_noreq_update_tgthint(tcon->dfs_path + 1,
220-
it);
221-
else
222-
rc = -ENOENT;
223-
}
224-
dfs_cache_free_tgts(&tl);
225-
out:
226-
kfree(tree);
227-
return rc;
228-
}
229-
#else
230-
static inline int __cifs_reconnect_tcon(const struct nls_table *nlsc,
231-
struct cifs_tcon *tcon)
232-
{
233-
return CIFSTCon(0, tcon->ses, tcon->treeName, tcon, nlsc);
234-
}
235-
#endif
236-
237127
/* reconnect the socket, tcon, and smb session if needed */
238128
static int
239129
cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
@@ -338,7 +228,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command)
338228
}
339229

340230
cifs_mark_open_files_invalid(tcon);
341-
rc = __cifs_reconnect_tcon(nls_codepage, tcon);
231+
rc = cifs_tree_connect(0, tcon, nls_codepage);
342232
mutex_unlock(&ses->session_mutex);
343233
cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc);
344234

fs/cifs/connect.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5532,3 +5532,103 @@ cifs_prune_tlinks(struct work_struct *work)
55325532
queue_delayed_work(cifsiod_wq, &cifs_sb->prune_tlinks,
55335533
TLINK_IDLE_EXPIRE);
55345534
}
5535+
5536+
#ifdef CONFIG_CIFS_DFS_UPCALL
5537+
int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const struct nls_table *nlsc)
5538+
{
5539+
int rc;
5540+
struct TCP_Server_Info *server = tcon->ses->server;
5541+
const struct smb_version_operations *ops = server->ops;
5542+
struct dfs_cache_tgt_list tl;
5543+
struct dfs_cache_tgt_iterator *it = NULL;
5544+
char *tree;
5545+
const char *tcp_host;
5546+
size_t tcp_host_len;
5547+
const char *dfs_host;
5548+
size_t dfs_host_len;
5549+
5550+
tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL);
5551+
if (!tree)
5552+
return -ENOMEM;
5553+
5554+
if (!tcon->dfs_path) {
5555+
if (tcon->ipc) {
5556+
scnprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$", server->hostname);
5557+
rc = ops->tree_connect(xid, tcon->ses, tree, tcon, nlsc);
5558+
} else {
5559+
rc = ops->tree_connect(xid, tcon->ses, tcon->treeName, tcon, nlsc);
5560+
}
5561+
goto out;
5562+
}
5563+
5564+
rc = dfs_cache_noreq_find(tcon->dfs_path + 1, NULL, &tl);
5565+
if (rc)
5566+
goto out;
5567+
5568+
extract_unc_hostname(server->hostname, &tcp_host, &tcp_host_len);
5569+
5570+
for (it = dfs_cache_get_tgt_iterator(&tl); it; it = dfs_cache_get_next_tgt(&tl, it)) {
5571+
const char *share, *prefix;
5572+
size_t share_len, prefix_len;
5573+
bool target_match;
5574+
5575+
rc = dfs_cache_get_tgt_share(it, &share, &share_len, &prefix, &prefix_len);
5576+
if (rc) {
5577+
cifs_dbg(VFS, "%s: failed to parse target share %d\n",
5578+
__func__, rc);
5579+
continue;
5580+
}
5581+
5582+
extract_unc_hostname(share, &dfs_host, &dfs_host_len);
5583+
5584+
if (dfs_host_len != tcp_host_len
5585+
|| strncasecmp(dfs_host, tcp_host, dfs_host_len) != 0) {
5586+
cifs_dbg(FYI, "%s: %.*s doesn't match %.*s\n", __func__, (int)dfs_host_len,
5587+
dfs_host, (int)tcp_host_len, tcp_host);
5588+
5589+
rc = match_target_ip(server, dfs_host, dfs_host_len, &target_match);
5590+
if (rc) {
5591+
cifs_dbg(VFS, "%s: failed to match target ip: %d\n", __func__, rc);
5592+
break;
5593+
}
5594+
5595+
if (!target_match) {
5596+
cifs_dbg(FYI, "%s: skipping target\n", __func__);
5597+
continue;
5598+
}
5599+
}
5600+
5601+
if (tcon->ipc) {
5602+
scnprintf(tree, MAX_TREE_SIZE, "\\\\%.*s\\IPC$", (int)share_len, share);
5603+
rc = ops->tree_connect(xid, tcon->ses, tree, tcon, nlsc);
5604+
} else {
5605+
scnprintf(tree, MAX_TREE_SIZE, "\\%.*s", (int)share_len, share);
5606+
rc = ops->tree_connect(xid, tcon->ses, tree, tcon, nlsc);
5607+
if (!rc) {
5608+
rc = update_super_prepath(tcon, prefix, prefix_len);
5609+
break;
5610+
}
5611+
}
5612+
if (rc == -EREMOTE)
5613+
break;
5614+
}
5615+
5616+
if (!rc) {
5617+
if (it)
5618+
rc = dfs_cache_noreq_update_tgthint(tcon->dfs_path + 1, it);
5619+
else
5620+
rc = -ENOENT;
5621+
}
5622+
dfs_cache_free_tgts(&tl);
5623+
out:
5624+
kfree(tree);
5625+
return rc;
5626+
}
5627+
#else
5628+
int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const struct nls_table *nlsc)
5629+
{
5630+
const struct smb_version_operations *ops = tcon->ses->server->ops;
5631+
5632+
return ops->tree_connect(xid, tcon->ses, tcon->treeName, tcon, nlsc);
5633+
}
5634+
#endif

fs/cifs/smb2pdu.c

Lines changed: 1 addition & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -152,117 +152,6 @@ smb2_hdr_assemble(struct smb2_sync_hdr *shdr, __le16 smb2_cmd,
152152
return;
153153
}
154154

155-
#ifdef CONFIG_CIFS_DFS_UPCALL
156-
static int __smb2_reconnect(const struct nls_table *nlsc,
157-
struct cifs_tcon *tcon)
158-
{
159-
int rc;
160-
struct TCP_Server_Info *server = tcon->ses->server;
161-
struct dfs_cache_tgt_list tl;
162-
struct dfs_cache_tgt_iterator *it = NULL;
163-
char *tree;
164-
const char *tcp_host;
165-
size_t tcp_host_len;
166-
const char *dfs_host;
167-
size_t dfs_host_len;
168-
169-
tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL);
170-
if (!tree)
171-
return -ENOMEM;
172-
173-
if (!tcon->dfs_path) {
174-
if (tcon->ipc) {
175-
scnprintf(tree, MAX_TREE_SIZE, "\\\\%s\\IPC$",
176-
server->hostname);
177-
rc = SMB2_tcon(0, tcon->ses, tree, tcon, nlsc);
178-
} else {
179-
rc = SMB2_tcon(0, tcon->ses, tcon->treeName, tcon,
180-
nlsc);
181-
}
182-
goto out;
183-
}
184-
185-
rc = dfs_cache_noreq_find(tcon->dfs_path + 1, NULL, &tl);
186-
if (rc)
187-
goto out;
188-
189-
extract_unc_hostname(server->hostname, &tcp_host, &tcp_host_len);
190-
191-
for (it = dfs_cache_get_tgt_iterator(&tl); it;
192-
it = dfs_cache_get_next_tgt(&tl, it)) {
193-
const char *share, *prefix;
194-
size_t share_len, prefix_len;
195-
bool target_match;
196-
197-
rc = dfs_cache_get_tgt_share(it, &share, &share_len, &prefix,
198-
&prefix_len);
199-
if (rc) {
200-
cifs_dbg(VFS, "%s: failed to parse target share %d\n",
201-
__func__, rc);
202-
continue;
203-
}
204-
205-
extract_unc_hostname(share, &dfs_host, &dfs_host_len);
206-
207-
if (dfs_host_len != tcp_host_len
208-
|| strncasecmp(dfs_host, tcp_host, dfs_host_len) != 0) {
209-
cifs_dbg(FYI, "%s: %.*s doesn't match %.*s\n",
210-
__func__,
211-
(int)dfs_host_len, dfs_host,
212-
(int)tcp_host_len, tcp_host);
213-
214-
rc = match_target_ip(server, dfs_host, dfs_host_len,
215-
&target_match);
216-
if (rc) {
217-
cifs_dbg(VFS, "%s: failed to match target ip: %d\n",
218-
__func__, rc);
219-
break;
220-
}
221-
222-
if (!target_match) {
223-
cifs_dbg(FYI, "%s: skipping target\n", __func__);
224-
continue;
225-
}
226-
}
227-
228-
if (tcon->ipc) {
229-
scnprintf(tree, MAX_TREE_SIZE, "\\\\%.*s\\IPC$",
230-
(int)share_len, share);
231-
rc = SMB2_tcon(0, tcon->ses, tree, tcon, nlsc);
232-
} else {
233-
scnprintf(tree, MAX_TREE_SIZE, "\\%.*s", (int)share_len,
234-
share);
235-
rc = SMB2_tcon(0, tcon->ses, tree, tcon, nlsc);
236-
if (!rc) {
237-
rc = update_super_prepath(tcon, prefix,
238-
prefix_len);
239-
break;
240-
}
241-
}
242-
if (rc == -EREMOTE)
243-
break;
244-
}
245-
246-
if (!rc) {
247-
if (it)
248-
rc = dfs_cache_noreq_update_tgthint(tcon->dfs_path + 1,
249-
it);
250-
else
251-
rc = -ENOENT;
252-
}
253-
dfs_cache_free_tgts(&tl);
254-
out:
255-
kfree(tree);
256-
return rc;
257-
}
258-
#else
259-
static inline int __smb2_reconnect(const struct nls_table *nlsc,
260-
struct cifs_tcon *tcon)
261-
{
262-
return SMB2_tcon(0, tcon->ses, tcon->treeName, tcon, nlsc);
263-
}
264-
#endif
265-
266155
static int
267156
smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
268157
struct TCP_Server_Info *server)
@@ -409,7 +298,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
409298
if (tcon->use_persistent)
410299
tcon->need_reopen_files = true;
411300

412-
rc = __smb2_reconnect(nls_codepage, tcon);
301+
rc = cifs_tree_connect(0, tcon, nls_codepage);
413302
mutex_unlock(&tcon->ses->session_mutex);
414303

415304
cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc);

0 commit comments

Comments
 (0)