From 5232d69194451ef92250751f0fc1fda5b74bbbbb Mon Sep 17 00:00:00 2001
From: huanghua <huanghua>
Date: Tue, 11 Mar 2008 06:01:26 +0000
Subject: [PATCH] Branch b1_6 b=14538 i=eric.mei i=yong.fan

- use lustre_msg_v2 for CONNECT
---
 lustre/ldlm/ldlm_lib.c   | 12 ++++++++++--
 lustre/obdclass/genops.c |  4 ++--
 lustre/ptlrpc/import.c   |  8 ++++++--
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c
index de4c8dc7b3..8a390abdbf 100644
--- a/lustre/ldlm/ldlm_lib.c
+++ b/lustre/ldlm/ldlm_lib.c
@@ -901,11 +901,19 @@ int target_handle_connect(struct ptlrpc_request *req, svc_handler_t handler)
         revimp->imp_remote_handle = conn;
         revimp->imp_dlm_fake = 1;
         revimp->imp_state = LUSTRE_IMP_FULL;
+
 set_flags:
-        if (lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_NEXT_VER) {
-                /* Client wants v2 */
+        if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V1 &&
+            lustre_msg_get_op_flags(req->rq_reqmsg) & MSG_CONNECT_NEXT_VER) {
                 revimp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
                 lustre_msg_add_op_flags(req->rq_repmsg, MSG_CONNECT_NEXT_VER);
+        } else {
+                /* unknown versions will be caught in
+                 * ptlrpc_handle_server_req_in->lustre_unpack_msg() */
+                revimp->imp_msg_magic = req->rq_reqmsg->lm_magic;
+        }
+
+        if (revimp->imp_msg_magic != LUSTRE_MSG_MAGIC_V1) {
                 if (export->exp_connect_flags & OBD_CONNECT_AT)
                         revimp->imp_msghdr_flags |= MSGHDR_AT_SUPPORT;
         }
diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c
index 472088bf2b..8bacf405ab 100644
--- a/lustre/obdclass/genops.c
+++ b/lustre/obdclass/genops.c
@@ -830,9 +830,9 @@ struct obd_import *class_new_import(struct obd_device *obd)
         class_handle_hash(&imp->imp_handle, import_handle_addref);
         init_imp_at(&imp->imp_at);
 
-        /* the default magic is V1, will be used in connect RPC, and
+        /* the default magic is V2, will be used in connect RPC, and
          * then adjusted according to the flags in request/reply. */
-        imp->imp_msg_magic = LUSTRE_MSG_MAGIC_V1;
+        imp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
 
         return imp;
 }
diff --git a/lustre/ptlrpc/import.c b/lustre/ptlrpc/import.c
index 98a2c45b39..4b96594cc3 100644
--- a/lustre/ptlrpc/import.c
+++ b/lustre/ptlrpc/import.c
@@ -516,7 +516,9 @@ int ptlrpc_connect_import(struct obd_import *imp, char *new_uuid)
 #ifndef __KERNEL__
         lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_LIBCLIENT);
 #endif
-        lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER);
+        if (imp->imp_msg_magic == LUSTRE_MSG_MAGIC_V1)
+                lustre_msg_add_op_flags(request->rq_reqmsg,
+                                        MSG_CONNECT_NEXT_VER);
 
         request->rq_send_state = LUSTRE_IMP_CONNECTING;
         /* Allow a slightly larger reply for future growth compatibility */
@@ -635,7 +637,9 @@ static int ptlrpc_connect_interpret(struct ptlrpc_request *request,
                         spin_unlock(&imp->imp_lock);
                 }
 
-                if (msg_flags & MSG_CONNECT_NEXT_VER) {
+                if ((request->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V1 &&
+                     msg_flags & MSG_CONNECT_NEXT_VER) ||
+                    request->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2) {
                         imp->imp_msg_magic = LUSTRE_MSG_MAGIC_V2;
                         CDEBUG(D_RPCTRACE, "connect to %s with lustre_msg_v2\n",
                                obd2cli_tgt(imp->imp_obd));
-- 
GitLab