Merge tag 'm68knommu-for-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / fs / cifs / connect.c
index 1126923..121d8b4 100644 (file)
@@ -62,9 +62,7 @@
 #include "dfs_cache.h"
 #endif
 #include "fs_context.h"
-#ifdef CONFIG_CIFS_SWN_UPCALL
 #include "cifs_swn.h"
-#endif
 
 extern mempool_t *cifs_req_poolp;
 extern bool disable_legacy_dialects;
@@ -87,7 +85,6 @@ static void cifs_prune_tlinks(struct work_struct *work);
  *
  * This should be called with server->srv_mutex held.
  */
-#ifdef CONFIG_CIFS_DFS_UPCALL
 static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server)
 {
        int rc;
@@ -124,6 +121,7 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server)
        return !rc ? -1 : 0;
 }
 
+#ifdef CONFIG_CIFS_DFS_UPCALL
 /* These functions must be called with server->srv_mutex held */
 static void reconn_set_next_dfs_target(struct TCP_Server_Info *server,
                                       struct cifs_sb_info *cifs_sb,
@@ -314,25 +312,34 @@ cifs_reconnect(struct TCP_Server_Info *server)
 
                mutex_lock(&server->srv_mutex);
 
-#ifdef CONFIG_CIFS_SWN_UPCALL
-               if (server->use_swn_dstaddr) {
-                       server->dstaddr = server->swn_dstaddr;
-               } else {
-#endif
 
+               if (!cifs_swn_set_server_dstaddr(server)) {
 #ifdef CONFIG_CIFS_DFS_UPCALL
+               if (cifs_sb && cifs_sb->origin_fullpath)
                        /*
                         * Set up next DFS target server (if any) for reconnect. If DFS
                         * feature is disabled, then we will retry last server we
                         * connected to before.
                         */
                        reconn_set_next_dfs_target(server, cifs_sb, &tgt_list, &tgt_it);
+               else {
 #endif
+                       /*
+                        * Resolve the hostname again to make sure that IP address is up-to-date.
+                        */
+                       rc = reconn_set_ipaddr_from_hostname(server);
+                       if (rc) {
+                               cifs_dbg(FYI, "%s: failed to resolve hostname: %d\n",
+                                               __func__, rc);
+                       }
 
-#ifdef CONFIG_CIFS_SWN_UPCALL
+#ifdef CONFIG_CIFS_DFS_UPCALL
                }
 #endif
 
+
+               }
+
                if (cifs_rdma_enabled(server))
                        rc = smbd_reconnect(server);
                else
@@ -348,9 +355,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
                        if (server->tcpStatus != CifsExiting)
                                server->tcpStatus = CifsNeedNegotiate;
                        spin_unlock(&GlobalMid_Lock);
-#ifdef CONFIG_CIFS_SWN_UPCALL
-                       server->use_swn_dstaddr = false;
-#endif
+                       cifs_swn_reset_server_dstaddr(server);
                        mutex_unlock(&server->srv_mutex);
                }
        } while (server->tcpStatus == CifsNeedReconnect);
@@ -415,10 +420,8 @@ cifs_echo_request(struct work_struct *work)
                cifs_dbg(FYI, "Unable to send echo request to server: %s\n",
                         server->hostname);
 
-#ifdef CONFIG_CIFS_SWN_UPCALL
        /* Check witness registrations */
        cifs_swn_check();
-#endif
 
 requeue_echo:
        queue_delayed_work(cifsiod_wq, &server->echo, server->echo_interval);
@@ -741,7 +744,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
                spin_lock(&GlobalMid_Lock);
                list_for_each_safe(tmp, tmp2, &server->pending_mid_q) {
                        mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
-                       cifs_dbg(FYI, "Clearing mid 0x%llx\n", mid_entry->mid);
+                       cifs_dbg(FYI, "Clearing mid %llu\n", mid_entry->mid);
                        kref_get(&mid_entry->refcount);
                        mid_entry->mid_state = MID_SHUTDOWN;
                        list_move(&mid_entry->qhead, &dispose_list);
@@ -752,7 +755,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server)
                /* now walk dispose list and issue callbacks */
                list_for_each_safe(tmp, tmp2, &dispose_list) {
                        mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
-                       cifs_dbg(FYI, "Callback mid 0x%llx\n", mid_entry->mid);
+                       cifs_dbg(FYI, "Callback mid %llu\n", mid_entry->mid);
                        list_del_init(&mid_entry->qhead);
                        mid_entry->callback(mid_entry);
                        cifs_mid_q_entry_release(mid_entry);
@@ -1429,6 +1432,11 @@ smbd_connected:
        tcp_ses->min_offload = ctx->min_offload;
        tcp_ses->tcpStatus = CifsNeedNegotiate;
 
+       if ((ctx->max_credits < 20) || (ctx->max_credits > 60000))
+               tcp_ses->max_credits = SMB2_MAX_CREDITS_AVAILABLE;
+       else
+               tcp_ses->max_credits = ctx->max_credits;
+
        tcp_ses->nr_targets = 1;
        tcp_ses->ignore_signature = ctx->ignore_signature;
        /* thread spawned, put it on the list */
@@ -1770,9 +1778,7 @@ cifs_set_cifscreds(struct smb3_fs_context *ctx, struct cifs_ses *ses)
         * for the request.
         */
        if (is_domain && ses->domainName) {
-               ctx->domainname = kstrndup(ses->domainName,
-                                          strlen(ses->domainName),
-                                          GFP_KERNEL);
+               ctx->domainname = kstrdup(ses->domainName, GFP_KERNEL);
                if (!ctx->domainname) {
                        cifs_dbg(FYI, "Unable to allocate %zd bytes for domain\n",
                                 len);
@@ -1989,7 +1995,6 @@ cifs_put_tcon(struct cifs_tcon *tcon)
                return;
        }
 
-#ifdef CONFIG_CIFS_SWN_UPCALL
        if (tcon->use_witness) {
                int rc;
 
@@ -1999,7 +2004,6 @@ cifs_put_tcon(struct cifs_tcon *tcon)
                                        __func__, rc);
                }
        }
-#endif
 
        list_del_init(&tcon->tcon_list);
        spin_unlock(&cifs_tcp_ses_lock);
@@ -2161,9 +2165,9 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
                }
                tcon->use_resilient = true;
        }
-#ifdef CONFIG_CIFS_SWN_UPCALL
+
        tcon->use_witness = false;
-       if (ctx->witness) {
+       if (IS_ENABLED(CONFIG_CIFS_SWN_UPCALL) && ctx->witness) {
                if (ses->server->vals->protocol_id >= SMB30_PROT_ID) {
                        if (tcon->capabilities & SMB2_SHARE_CAP_CLUSTER) {
                                /*
@@ -2189,7 +2193,6 @@ cifs_get_tcon(struct cifs_ses *ses, struct smb3_fs_context *ctx)
                        goto out_fail;
                }
        }
-#endif
 
        /* If the user really knows what they are doing they can override */
        if (tcon->share_flags & SMB2_SHAREFLAG_NO_CACHING) {
@@ -2832,11 +2835,6 @@ static int mount_get_conns(struct smb3_fs_context *ctx, struct cifs_sb_info *cif
 
        *nserver = server;
 
-       if ((ctx->max_credits < 20) || (ctx->max_credits > 60000))
-               server->max_credits = SMB2_MAX_CREDITS_AVAILABLE;
-       else
-               server->max_credits = ctx->max_credits;
-
        /* get a reference to a SMB session */
        ses = cifs_get_smb_ses(server, ctx);
        if (IS_ERR(ses)) {
@@ -3411,8 +3409,7 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
                        goto error;
        }
        /* Save mount options */
-       mntdata = kstrndup(cifs_sb->ctx->mount_options,
-                          strlen(cifs_sb->ctx->mount_options), GFP_KERNEL);
+       mntdata = kstrdup(cifs_sb->ctx->mount_options, GFP_KERNEL);
        if (!mntdata) {
                rc = -ENOMEM;
                goto error;
@@ -3485,7 +3482,7 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
         * links, the prefix path is included in both and may be changed during reconnect.  See
         * cifs_tree_connect().
         */
-       cifs_sb->origin_fullpath = kstrndup(full_path, strlen(full_path), GFP_KERNEL);
+       cifs_sb->origin_fullpath = kstrdup(full_path, GFP_KERNEL);
        if (!cifs_sb->origin_fullpath) {
                rc = -ENOMEM;
                goto error;
@@ -3862,9 +3859,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid)
        ctx->sectype = master_tcon->ses->sectype;
        ctx->sign = master_tcon->ses->sign;
        ctx->seal = master_tcon->seal;
-#ifdef CONFIG_CIFS_SWN_UPCALL
        ctx->witness = master_tcon->use_witness;
-#endif
 
        rc = cifs_set_vol_auth(ctx, master_tcon->ses);
        if (rc) {