Lines Matching refs:ses
71 * Resolve hostname and set ip addr in tcp ses. Useful for hostnames that may
148 * @server: the tcp ses for which reconnect is needed
156 struct cifs_ses *ses;
172 list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
173 spin_lock(&ses->chan_lock);
174 for (i = 0; i < ses->chan_count; i++) {
175 if (!ses->chans[i].server)
178 spin_lock(&ses->chans[i].server->srv_lock);
179 if (ses->chans[i].server->tcpStatus != CifsExiting)
180 ses->chans[i].server->tcpStatus = CifsNeedReconnect;
181 spin_unlock(&ses->chans[i].server->srv_lock);
183 spin_unlock(&ses->chan_lock);
194 * @server: the tcp ses for which reconnect is needed
203 struct cifs_ses *ses, *nses;
229 list_for_each_entry_safe(ses, nses, &pserver->smb_ses_list, smb_ses_list) {
231 spin_lock(&ses->chan_lock);
232 if (cifs_ses_get_chan_index(ses, server) ==
234 spin_unlock(&ses->chan_lock);
238 if (!cifs_chan_is_iface_active(ses, server)) {
239 spin_unlock(&ses->chan_lock);
240 cifs_chan_update_iface(ses, server);
241 spin_lock(&ses->chan_lock);
244 if (!mark_smb_session && cifs_chan_needs_reconnect(ses, server)) {
245 spin_unlock(&ses->chan_lock);
250 CIFS_SET_ALL_CHANS_NEED_RECONNECT(ses);
252 cifs_chan_set_need_reconnect(ses, server);
255 __func__, ses->chans_need_reconnect);
258 if (!mark_smb_session && !CIFS_ALL_CHANS_NEED_RECONNECT(ses)) {
259 spin_unlock(&ses->chan_lock);
262 spin_unlock(&ses->chan_lock);
264 spin_lock(&ses->ses_lock);
265 ses->ses_status = SES_NEED_RECON;
266 spin_unlock(&ses->ses_lock);
268 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
276 if (ses->tcon_ipc) {
277 ses->tcon_ipc->need_reconnect = true;
278 spin_lock(&ses->tcon_ipc->tc_lock);
279 ses->tcon_ipc->status = TID_NEED_RECON;
280 spin_unlock(&ses->tcon_ipc->tc_lock);
1587 * Skip ses channels since they're only handled in lower layers
1844 static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx)
1847 ctx->sectype != ses->sectype)
1854 if (ses->chan_max < ctx->max_channels)
1857 switch (ses->sectype) {
1859 if (!uid_eq(ctx->cred_uid, ses->cred_uid))
1864 if (ses->user_name == NULL) {
1871 if (strncmp(ses->user_name,
1876 ses->password != NULL &&
1877 strncmp(ses->password,
1883 if (strcmp(ctx->local_nls->charset, ses->local_nls->charset))
1891 * @ses: smb session to issue the request on
1899 cifs_setup_ipc(struct cifs_ses *ses, struct smb3_fs_context *ctx)
1905 struct TCP_Server_Info *server = ses->server;
1931 tcon->ses = ses;
1934 rc = server->ops->tree_connect(xid, ses, unc, tcon, ctx->local_nls);
1948 ses->tcon_ipc = tcon;
1955 * @ses: smb session to unmount the IPC from
1966 cifs_free_ipc(struct cifs_ses *ses)
1968 struct cifs_tcon *tcon = ses->tcon_ipc;
1974 ses->tcon_ipc = NULL;
1981 struct cifs_ses *ses, *ret = NULL;
1984 list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
1985 spin_lock(&ses->ses_lock);
1986 if (ses->ses_status == SES_EXITING) {
1987 spin_unlock(&ses->ses_lock);
1990 spin_lock(&ses->chan_lock);
1991 if (match_session(ses, ctx)) {
1992 spin_unlock(&ses->chan_lock);
1993 spin_unlock(&ses->ses_lock);
1994 ret = ses;
1997 spin_unlock(&ses->chan_lock);
1998 spin_unlock(&ses->ses_lock);
2006 void __cifs_put_smb_ses(struct cifs_ses *ses)
2010 struct TCP_Server_Info *server = ses->server;
2012 spin_lock(&ses->ses_lock);
2013 if (ses->ses_status == SES_EXITING) {
2014 spin_unlock(&ses->ses_lock);
2017 spin_unlock(&ses->ses_lock);
2019 cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count);
2021 "%s: ses ipc: %s\n", __func__, ses->tcon_ipc ? ses->tcon_ipc->tree_name : "NONE");
2024 if (--ses->ses_count > 0) {
2028 spin_lock(&ses->ses_lock);
2029 if (ses->ses_status == SES_GOOD)
2030 ses->ses_status = SES_EXITING;
2031 spin_unlock(&ses->ses_lock);
2035 WARN_ON(ses->ses_count < 0);
2037 spin_lock(&ses->ses_lock);
2038 if (ses->ses_status == SES_EXITING && server->ops->logoff) {
2039 spin_unlock(&ses->ses_lock);
2040 cifs_free_ipc(ses);
2042 rc = server->ops->logoff(xid, ses);
2048 spin_unlock(&ses->ses_lock);
2049 cifs_free_ipc(ses);
2053 list_del_init(&ses->smb_ses_list);
2056 chan_count = ses->chan_count;
2063 if (ses->chans[i].iface) {
2064 kref_put(&ses->chans[i].iface->refcount, release_iface);
2065 ses->chans[i].iface = NULL;
2067 cifs_put_tcp_session(ses->chans[i].server, 0);
2068 ses->chans[i].server = NULL;
2073 if (ses->chans[0].iface) {
2074 kref_put(&ses->chans[0].iface->refcount, release_iface);
2075 ses->chans[0].server = NULL;
2078 sesInfoFree(ses);
2089 cifs_set_cifscreds(struct smb3_fs_context *ctx, struct cifs_ses *ses)
2097 struct TCP_Server_Info *server = ses->server;
2126 if (!ses->domainName) {
2133 sprintf(desc, "cifs:d:%s", ses->domainName);
2202 if (is_domain && ses->domainName) {
2203 ctx->domainname = kstrdup(ses->domainName, GFP_KERNEL);
2216 strscpy(ctx->workstation_name, ses->workstation_name, sizeof(ctx->workstation_name));
2229 struct cifs_ses *ses __attribute__((unused)))
2249 struct cifs_ses *ses;
2255 ses = cifs_find_smb_ses(server, ctx);
2256 if (ses) {
2258 ses->ses_status);
2260 spin_lock(&ses->chan_lock);
2261 if (cifs_chan_needs_reconnect(ses, server)) {
2262 spin_unlock(&ses->chan_lock);
2265 mutex_lock(&ses->session_mutex);
2266 rc = cifs_negotiate_protocol(xid, ses, server);
2268 mutex_unlock(&ses->session_mutex);
2269 /* problem -- put our ses reference */
2270 cifs_put_smb_ses(ses);
2275 rc = cifs_setup_session(xid, ses, server,
2278 mutex_unlock(&ses->session_mutex);
2280 cifs_put_smb_ses(ses);
2284 mutex_unlock(&ses->session_mutex);
2286 spin_lock(&ses->chan_lock);
2288 spin_unlock(&ses->chan_lock);
2290 /* existing SMB ses has a server reference already */
2293 return ses;
2299 ses = sesInfoAlloc();
2300 if (ses == NULL)
2304 ses->server = server;
2306 sprintf(ses->ip_addr, "%pI6", &addr6->sin6_addr);
2308 sprintf(ses->ip_addr, "%pI4", &addr->sin_addr);
2311 ses->user_name = kstrdup(ctx->username, GFP_KERNEL);
2312 if (!ses->user_name)
2318 ses->password = kstrdup(ctx->password, GFP_KERNEL);
2319 if (!ses->password)
2323 ses->domainName = kstrdup(ctx->domainname, GFP_KERNEL);
2324 if (!ses->domainName)
2328 strscpy(ses->workstation_name, ctx->workstation_name, sizeof(ses->workstation_name));
2331 ses->domainAuto = ctx->domainauto;
2332 ses->cred_uid = ctx->cred_uid;
2333 ses->linux_uid = ctx->linux_uid;
2335 ses->sectype = ctx->sectype;
2336 ses->sign = ctx->sign;
2337 ses->local_nls = load_nls(ctx->local_nls->charset);
2340 spin_lock(&ses->chan_lock);
2341 ses->chans[0].server = server;
2342 ses->chan_count = 1;
2343 ses->chan_max = ctx->multichannel ? ctx->max_channels:1;
2344 ses->chans_need_reconnect = 1;
2345 spin_unlock(&ses->chan_lock);
2347 mutex_lock(&ses->session_mutex);
2348 rc = cifs_negotiate_protocol(xid, ses, server);
2350 rc = cifs_setup_session(xid, ses, server, ctx->local_nls);
2351 mutex_unlock(&ses->session_mutex);
2354 spin_lock(&ses->chan_lock);
2355 memcpy(ses->chans[0].signkey, ses->smb3signingkey,
2356 sizeof(ses->smb3signingkey));
2357 spin_unlock(&ses->chan_lock);
2368 ses->dfs_root_ses = ctx->dfs_root_ses;
2369 if (ses->dfs_root_ses)
2370 ses->dfs_root_ses->ses_count++;
2371 list_add(&ses->smb_ses_list, &server->smb_ses_list);
2374 cifs_setup_ipc(ses, ctx);
2378 return ses;
2381 sesInfoFree(ses);
2389 struct TCP_Server_Info *server = tcon->ses->server;
2417 cifs_find_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
2422 list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
2441 struct cifs_ses *ses;
2450 ses = tcon->ses;
2485 if (ses->server->ops->tree_disconnect)
2486 ses->server->ops->tree_disconnect(xid, tcon);
2491 cifs_put_smb_ses(ses);
2495 * cifs_get_tcon - get a tcon matching @ctx data from @ses
2496 * @ses: smb session to issue the request on
2500 * - ses refcount is the number of tcon using the session.
2503 * we already got a session reference (ses refcount +1).
2513 * identical ses refcount (no new tcon). Because of (1) we need to
2514 * decrement the ses refcount.
2517 cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
2523 tcon = cifs_find_tcon(ses, ctx);
2527 * decrement extra ses reference gotten by caller (case b)
2530 cifs_put_smb_ses(ses);
2534 if (!ses->server->ops->tree_connect) {
2539 if (ses->server->dialect >= SMB20_PROT_ID &&
2540 (ses->server->capabilities & SMB2_GLOBAL_CAP_DIRECTORY_LEASING))
2552 if (ses->server->vals->protocol_id == 0) {
2562 if (ses->server->vals->protocol_id == 0) {
2571 tcon->ses = ses;
2581 if (ses->server->vals->protocol_id == 0) {
2586 } else if (tcon->ses->server->capabilities &
2597 if (ses->server->posix_ext_supported) {
2600 } else if ((ses->server->vals->protocol_id == SMB311_PROT_ID) ||
2601 (strcmp(ses->server->vals->version_string,
2603 (strcmp(ses->server->vals->version_string,
2617 rc = ses->server->ops->tree_connect(xid, ses, ctx->UNC, tcon,
2627 if (ses->server->vals->protocol_id == 0) {
2632 } else if (ses->server->capabilities &
2642 && (ses->server->capabilities & SMB2_GLOBAL_CAP_PERSISTENT_HANDLES)
2647 if (ses->server->vals->protocol_id == 0) {
2658 if (ses->server->vals->protocol_id >= SMB30_PROT_ID) {
2693 if (ses->server->vals->protocol_id == 0) {
2718 if (ses->server->dialect >= SMB30_PROT_ID &&
2719 (ses->server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) {
2728 list_add(&tcon->tcon_list, &ses->tcon_list);
2835 struct cifs_ses *ses;
2857 ses = tcon->ses;
2858 tcp_srv = ses->server;
2863 spin_lock(&ses->ses_lock);
2864 spin_lock(&ses->chan_lock);
2867 !match_session(ses, ctx) ||
2877 spin_unlock(&ses->chan_lock);
2878 spin_unlock(&ses->ses_lock);
3310 else if (mnt_ctx->ses)
3311 cifs_put_smb_ses(mnt_ctx->ses);
3322 struct cifs_ses *ses = NULL;
3343 ses = cifs_get_smb_ses(server, ctx);
3344 if (IS_ERR(ses)) {
3345 rc = PTR_ERR(ses);
3346 ses = NULL;
3350 if ((ctx->persistent == true) && (!(ses->server->capabilities &
3359 mnt_ctx->ses = ses;
3373 if (WARN_ON_ONCE(!mnt_ctx || !mnt_ctx->server || !mnt_ctx->ses || !mnt_ctx->fs_ctx ||
3383 tcon = cifs_get_tcon(mnt_ctx->ses, ctx);
3396 if (cap_unix(tcon->ses)) {
3402 spin_lock(&tcon->ses->server->srv_lock);
3403 if ((tcon->ses->server->tcpStatus == CifsNeedReconnect) &&
3406 spin_unlock(&tcon->ses->server->srv_lock);
3410 spin_unlock(&tcon->ses->server->srv_lock);
3464 static int mount_setup_tlink(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses,
3474 tlink->tl_uid = ses->linux_uid;
3615 cifs_try_adding_channels(mnt_ctx.ses);
3616 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
3648 rc = mount_setup_tlink(cifs_sb, mnt_ctx.ses, mnt_ctx.tcon);
3665 CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
3678 if (ses == NULL)
3690 smb_buffer->Mid = get_next_mid(ses->server);
3691 smb_buffer->Uid = ses->Suid;
3704 if (ses->server->sign)
3707 if (ses->capabilities & CAP_STATUS32) {
3710 if (ses->capabilities & CAP_DFS) {
3713 if (ses->capabilities & CAP_UNICODE) {
3732 rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length,
3824 cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses,
3850 rc = server->ops->negotiate(xid, ses, server);
3869 cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
3879 spin_lock(&ses->ses_lock);
3881 __func__, ses->chans_need_reconnect);
3883 if (ses->ses_status != SES_GOOD &&
3884 ses->ses_status != SES_NEW &&
3885 ses->ses_status != SES_NEED_RECON) {
3886 spin_unlock(&ses->ses_lock);
3891 spin_lock(&ses->chan_lock);
3892 if (CIFS_ALL_CHANS_GOOD(ses)) {
3893 if (ses->ses_status == SES_NEED_RECON)
3894 ses->ses_status = SES_GOOD;
3895 spin_unlock(&ses->chan_lock);
3896 spin_unlock(&ses->ses_lock);
3900 cifs_chan_set_in_reconnect(ses, server);
3901 is_binding = !CIFS_ALL_CHANS_NEED_RECONNECT(ses);
3902 spin_unlock(&ses->chan_lock);
3905 ses->ses_status = SES_IN_SETUP;
3908 ses->iface_last_update = 0;
3910 spin_unlock(&ses->ses_lock);
3912 /* update ses ip_addr only for primary chan */
3915 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI6", &addr6->sin6_addr);
3917 scnprintf(ses->ip_addr, sizeof(ses->ip_addr), "%pI4", &addr->sin_addr);
3921 ses->capabilities = server->capabilities;
3923 ses->capabilities &= (~server->vals->cap_unix);
3925 if (ses->auth_key.response) {
3927 ses->auth_key.response);
3928 kfree_sensitive(ses->auth_key.response);
3929 ses->auth_key.response = NULL;
3930 ses->auth_key.len = 0;
3938 rc = server->ops->sess_setup(xid, ses, server, nls_info);
3942 spin_lock(&ses->ses_lock);
3943 if (ses->ses_status == SES_IN_SETUP)
3944 ses->ses_status = SES_NEED_RECON;
3945 spin_lock(&ses->chan_lock);
3946 cifs_chan_clear_in_reconnect(ses, server);
3947 spin_unlock(&ses->chan_lock);
3948 spin_unlock(&ses->ses_lock);
3950 spin_lock(&ses->ses_lock);
3951 if (ses->ses_status == SES_IN_SETUP)
3952 ses->ses_status = SES_GOOD;
3953 spin_lock(&ses->chan_lock);
3954 cifs_chan_clear_in_reconnect(ses, server);
3955 cifs_chan_clear_need_reconnect(ses, server);
3956 spin_unlock(&ses->chan_lock);
3957 spin_unlock(&ses->ses_lock);
3964 cifs_set_vol_auth(struct smb3_fs_context *ctx, struct cifs_ses *ses)
3966 ctx->sectype = ses->sectype;
3972 return cifs_set_cifscreds(ctx, ses);
3980 struct cifs_ses *ses;
4002 ctx->sectype = master_tcon->ses->sectype;
4003 ctx->sign = master_tcon->ses->sign;
4007 rc = cifs_set_vol_auth(ctx, master_tcon->ses);
4015 ++master_tcon->ses->server->srv_count;
4018 ses = cifs_get_smb_ses(master_tcon->ses->server, ctx);
4019 if (IS_ERR(ses)) {
4020 tcon = (struct cifs_tcon *)ses;
4021 cifs_put_tcp_session(master_tcon->ses->server, 0);
4025 tcon = cifs_get_tcon(ses, ctx);
4027 cifs_put_smb_ses(ses);
4032 if (cap_unix(ses))
4231 const struct smb_version_operations *ops = tcon->ses->server->ops;
4254 rc = ops->tree_connect(xid, tcon->ses, tcon->tree_name, tcon, nlsc);