+ rc = mdt_export_cleanup(exp);
+ class_export_put(exp);
+ RETURN(rc);
+}
+
+/* mds_connect copy */
+static int mdt_obd_connect(const struct lu_env *env,
+ struct obd_export **exp, struct obd_device *obd,
+ struct obd_uuid *cluuid,
+ struct obd_connect_data *data,
+ void *localdata)
+{
+ struct obd_export *lexp;
+ struct lustre_handle conn = { 0 };
+ struct mdt_device *mdt;
+ int rc;
+ lnet_nid_t *client_nid = localdata;
+ ENTRY;
+
+ LASSERT(env != NULL);
+ if (!exp || !obd || !cluuid)
+ RETURN(-EINVAL);
+
+ mdt = mdt_dev(obd->obd_lu_dev);
+
+ /*
+ * first, check whether the stack is ready to handle requests
+ * XXX: probably not very appropriate method is used now
+ * at some point we should find a better one
+ */
+ if (!test_bit(MDT_FL_SYNCED, &mdt->mdt_state) && data != NULL &&
+ !(data->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT)) {
+ rc = obd_get_info(env, mdt->mdt_child_exp,
+ sizeof(KEY_OSP_CONNECTED),
+ KEY_OSP_CONNECTED, NULL, NULL, NULL);
+ if (rc)
+ RETURN(-EAGAIN);
+ set_bit(MDT_FL_SYNCED, &mdt->mdt_state);
+ }
+
+ rc = class_connect(&conn, obd, cluuid);
+ if (rc)
+ RETURN(rc);
+
+ lexp = class_conn2export(&conn);
+ LASSERT(lexp != NULL);
+
+ rc = mdt_connect_internal(lexp, mdt, data);
+ if (rc == 0) {
+ struct lsd_client_data *lcd = lexp->exp_target_data.ted_lcd;
+
+ LASSERT(lcd);
+ memcpy(lcd->lcd_uuid, cluuid, sizeof lcd->lcd_uuid);
+ rc = tgt_client_new(env, lexp);
+ if (rc == 0) {
+ rc = nodemap_add_member(*client_nid, lexp);
+ if (rc != 0 && rc != -EEXIST)
+ goto out;
+
+ mdt_export_stats_init(obd, lexp, localdata);
+ }
+
+ /* For phase I, sync for cross-ref operation. */
+ spin_lock(&lexp->exp_lock);
+ lexp->exp_keep_sync = 1;
+ spin_unlock(&lexp->exp_lock);
+ }
+out:
+ if (rc != 0) {
+ class_disconnect(lexp);
+ *exp = NULL;
+ } else {
+ *exp = lexp;
+ }
+
+ RETURN(rc);
+}
+
+static int mdt_obd_reconnect(const struct lu_env *env,
+ struct obd_export *exp, struct obd_device *obd,
+ struct obd_uuid *cluuid,
+ struct obd_connect_data *data,
+ void *localdata)
+{
+ lnet_nid_t *client_nid = localdata;
+ int rc;
+ ENTRY;
+
+ if (exp == NULL || obd == NULL || cluuid == NULL)
+ RETURN(-EINVAL);
+
+ rc = mdt_connect_internal(exp, mdt_dev(obd->obd_lu_dev), data);
+ if (rc == 0) {
+ rc = nodemap_add_member(*client_nid, exp);
+ if (rc == 0 || rc == -EEXIST)
+ mdt_export_stats_init(obd, exp, localdata);
+ }
+
+ RETURN(rc);