cifs: Split the smb3_add_credits tracepoint
[linux-block.git] / fs / cifs / connect.c
index 9964c363432254573df2020e84e7fc5ff27fbc6e..902e8c6c0f9c27890690515d3886fcb85a555026 100644 (file)
@@ -245,7 +245,7 @@ cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server,
 
                list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
                        tcon->need_reconnect = true;
-                       tcon->tidStatus = CifsNeedReconnect;
+                       tcon->status = TID_NEED_RECON;
                }
                if (ses->tcon_ipc)
                        ses->tcon_ipc->need_reconnect = true;
@@ -453,9 +453,7 @@ static int reconnect_target_unlocked(struct TCP_Server_Info *server, struct dfs_
        return rc;
 }
 
-static int
-reconnect_dfs_server(struct TCP_Server_Info *server,
-                    bool mark_smb_session)
+static int reconnect_dfs_server(struct TCP_Server_Info *server)
 {
        int rc = 0;
        const char *refpath = server->current_fullpath + 1;
@@ -479,7 +477,12 @@ reconnect_dfs_server(struct TCP_Server_Info *server,
        if (!cifs_tcp_ses_needs_reconnect(server, num_targets))
                return 0;
 
-       cifs_mark_tcp_ses_conns_for_reconnect(server, mark_smb_session);
+       /*
+        * Unconditionally mark all sessions & tcons for reconnect as we might be connecting to a
+        * different server or share during failover.  It could be improved by adding some logic to
+        * only do that in case it connects to a different server or share, though.
+        */
+       cifs_mark_tcp_ses_conns_for_reconnect(server, true);
 
        cifs_abort_connection(server);
 
@@ -537,7 +540,7 @@ int cifs_reconnect(struct TCP_Server_Info *server, bool mark_smb_session)
        }
        spin_unlock(&cifs_tcp_ses_lock);
 
-       return reconnect_dfs_server(server, mark_smb_session);
+       return reconnect_dfs_server(server);
 }
 #else
 int cifs_reconnect(struct TCP_Server_Info *server, bool mark_smb_session)
@@ -1046,7 +1049,7 @@ smb2_add_credits_from_hdr(char *buffer, struct TCP_Server_Info *server)
                spin_unlock(&server->req_lock);
                wake_up(&server->request_q);
 
-               trace_smb3_add_credits(server->CurrentMid,
+               trace_smb3_hdr_credits(server->CurrentMid,
                                server->conn_id, server->hostname, scredits,
                                le16_to_cpu(shdr->CreditRequest), in_flight);
                cifs_server_dbg(FYI, "%s: added %u credits total=%d\n",
@@ -2207,7 +2210,7 @@ get_ses_fail:
 
 static int match_tcon(struct cifs_tcon *tcon, struct smb3_fs_context *ctx)
 {
-       if (tcon->tidStatus == CifsExiting)
+       if (tcon->status == TID_EXITING)
                return 0;
        if (strncmp(tcon->treeName, ctx->UNC, MAX_TREE_SIZE))
                return 0;
@@ -3513,6 +3516,9 @@ static int connect_dfs_target(struct mount_ctx *mnt_ctx, const char *full_path,
        struct cifs_sb_info *cifs_sb = mnt_ctx->cifs_sb;
        char *oldmnt = cifs_sb->ctx->mount_options;
 
+       cifs_dbg(FYI, "%s: full_path=%s ref_path=%s target=%s\n", __func__, full_path, ref_path,
+                dfs_cache_get_tgt_name(tit));
+
        rc = dfs_cache_get_tgt_referral(ref_path, tit, &ref);
        if (rc)
                goto out;
@@ -3611,13 +3617,18 @@ static int __follow_dfs_link(struct mount_ctx *mnt_ctx)
        if (rc)
                goto out;
 
-       /* Try all dfs link targets */
+       /* Try all dfs link targets.  If an I/O fails from currently connected DFS target with an
+        * error other than STATUS_PATH_NOT_COVERED (-EREMOTE), then retry it from other targets as
+        * specified in MS-DFSC "3.1.5.2 I/O Operation to Target Fails with an Error Other Than
+        * STATUS_PATH_NOT_COVERED."
+        */
        for (rc = -ENOENT, tit = dfs_cache_get_tgt_iterator(&tl);
             tit; tit = dfs_cache_get_next_tgt(&tl, tit)) {
                rc = connect_dfs_target(mnt_ctx, full_path, mnt_ctx->leaf_fullpath + 1, tit);
                if (!rc) {
                        rc = is_path_remote(mnt_ctx);
-                       break;
+                       if (!rc || rc == -EREMOTE)
+                               break;
                }
        }
 
@@ -3691,7 +3702,7 @@ int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx)
                goto error;
 
        rc = is_path_remote(&mnt_ctx);
-       if (rc == -EREMOTE)
+       if (rc)
                rc = follow_dfs_link(&mnt_ctx);
        if (rc)
                goto error;
@@ -4457,7 +4468,7 @@ static int tree_connect_dfs_target(const unsigned int xid, struct cifs_tcon *tco
         */
        if (rc && server->current_fullpath != server->origin_fullpath) {
                server->current_fullpath = server->origin_fullpath;
-               cifs_reconnect(tcon->ses->server, true);
+               cifs_signal_cifsd_for_reconnect(server, true);
        }
 
        dfs_cache_free_tgts(tl);
@@ -4478,12 +4489,12 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
        /* only send once per connect */
        spin_lock(&cifs_tcp_ses_lock);
        if (tcon->ses->status != CifsGood ||
-           (tcon->tidStatus != CifsNew &&
-           tcon->tidStatus != CifsNeedTcon)) {
+           (tcon->status != TID_NEW &&
+           tcon->status != TID_NEED_TCON)) {
                spin_unlock(&cifs_tcp_ses_lock);
                return 0;
        }
-       tcon->tidStatus = CifsInTcon;
+       tcon->status = TID_IN_TCON;
        spin_unlock(&cifs_tcp_ses_lock);
 
        tree = kzalloc(MAX_TREE_SIZE, GFP_KERNEL);
@@ -4524,13 +4535,13 @@ out:
 
        if (rc) {
                spin_lock(&cifs_tcp_ses_lock);
-               if (tcon->tidStatus == CifsInTcon)
-                       tcon->tidStatus = CifsNeedTcon;
+               if (tcon->status == TID_IN_TCON)
+                       tcon->status = TID_NEED_TCON;
                spin_unlock(&cifs_tcp_ses_lock);
        } else {
                spin_lock(&cifs_tcp_ses_lock);
-               if (tcon->tidStatus == CifsInTcon)
-                       tcon->tidStatus = CifsGood;
+               if (tcon->status == TID_IN_TCON)
+                       tcon->status = TID_GOOD;
                spin_unlock(&cifs_tcp_ses_lock);
                tcon->need_reconnect = false;
        }
@@ -4546,24 +4557,24 @@ int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon, const stru
        /* only send once per connect */
        spin_lock(&cifs_tcp_ses_lock);
        if (tcon->ses->status != CifsGood ||
-           (tcon->tidStatus != CifsNew &&
-           tcon->tidStatus != CifsNeedTcon)) {
+           (tcon->status != TID_NEW &&
+           tcon->status != TID_NEED_TCON)) {
                spin_unlock(&cifs_tcp_ses_lock);
                return 0;
        }
-       tcon->tidStatus = CifsInTcon;
+       tcon->status = TID_IN_TCON;
        spin_unlock(&cifs_tcp_ses_lock);
 
        rc = ops->tree_connect(xid, tcon->ses, tcon->treeName, tcon, nlsc);
        if (rc) {
                spin_lock(&cifs_tcp_ses_lock);
-               if (tcon->tidStatus == CifsInTcon)
-                       tcon->tidStatus = CifsNeedTcon;
+               if (tcon->status == TID_IN_TCON)
+                       tcon->status = TID_NEED_TCON;
                spin_unlock(&cifs_tcp_ses_lock);
        } else {
                spin_lock(&cifs_tcp_ses_lock);
-               if (tcon->tidStatus == CifsInTcon)
-                       tcon->tidStatus = CifsGood;
+               if (tcon->status == TID_IN_TCON)
+                       tcon->status = TID_GOOD;
                spin_unlock(&cifs_tcp_ses_lock);
                tcon->need_reconnect = false;
        }