@@ -950,6 +950,7 @@ int target_handle_connect(struct ptlrpc_request *req)
950950 * reconnect case */
951951 struct lustre_handle conn ;
952952 struct lustre_handle * tmp ;
953+ struct obd_uuid tgtuuid ;
953954 struct obd_uuid cluuid ;
954955 char * str ;
955956 int rc = 0 ;
@@ -958,6 +959,7 @@ int target_handle_connect(struct ptlrpc_request *req)
958959 bool mds_conn = false, lw_client = false, initial_conn = false;
959960 bool mds_mds_conn = false;
960961 bool new_mds_mds_conn = false;
962+ bool target_referenced = false;
961963 struct obd_connect_data * data , * tmpdata ;
962964 int size , tmpsize ;
963965 lnet_nid_t * client_nid = NULL ;
@@ -971,7 +973,11 @@ int target_handle_connect(struct ptlrpc_request *req)
971973 GOTO (out , rc = - EINVAL );
972974 }
973975
974- target = class_dev_by_str (str );
976+ obd_str2uuid (& tgtuuid , str );
977+ target = class_uuid2obd (& tgtuuid );
978+ if (!target )
979+ target = class_name2obd (str );
980+
975981 if (!target ) {
976982 deuuidify (str , NULL , & target_start , & target_len );
977983 LCONSOLE_ERROR_MSG (0x137 , "%s: not available for connect "
@@ -983,9 +989,6 @@ int target_handle_connect(struct ptlrpc_request *req)
983989 }
984990
985991 spin_lock (& target -> obd_dev_lock );
986-
987- target -> obd_conn_inprogress ++ ;
988-
989992 if (target -> obd_stopping || !target -> obd_set_up ) {
990993 spin_unlock (& target -> obd_dev_lock );
991994
@@ -1007,6 +1010,13 @@ int target_handle_connect(struct ptlrpc_request *req)
10071010 GOTO (out , rc = - EAGAIN );
10081011 }
10091012
1013+ /* Make sure the target isn't cleaned up while we're here. Yes,
1014+ * there's still a race between the above check and our incref here.
1015+ * Really, class_uuid2obd should take the ref. */
1016+ class_incref (target , __func__ , current );
1017+ target_referenced = true;
1018+
1019+ target -> obd_conn_inprogress ++ ;
10101020 spin_unlock (& target -> obd_dev_lock );
10111021
10121022 str = req_capsule_client_get (& req -> rq_pill , & RMF_CLUUID );
@@ -1433,11 +1443,12 @@ int target_handle_connect(struct ptlrpc_request *req)
14331443
14341444 class_export_put (export );
14351445 }
1436- if (target != NULL ) {
1446+ if (target_referenced == true && target != NULL ) {
14371447 spin_lock (& target -> obd_dev_lock );
14381448 target -> obd_conn_inprogress -- ;
14391449 spin_unlock (& target -> obd_dev_lock );
1440- class_decref (target , "find" , current );
1450+
1451+ class_decref (target , __func__ , current );
14411452 }
14421453 req -> rq_status = rc ;
14431454 RETURN (rc );
0 commit comments