Whamcloud - gitweb
new export for mgc , mgs
authorlincent <lincent>
Tue, 2 Aug 2005 14:17:13 +0000 (14:17 +0000)
committerlincent <lincent>
Tue, 2 Aug 2005 14:17:13 +0000 (14:17 +0000)
lustre/ldlm/ldlm_lib.c
lustre/ldlm/ldlm_lockd.c

index 7338654..5155c7c 100644 (file)
@@ -177,6 +177,207 @@ out:
         RETURN(rc);
 }
 
+/*mgc_obd_setup for mount-conf*/
+int mgc_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
+{
+        struct lustre_cfg* lcfg = buf;
+        struct mgc_obd *mgc = &obddev->u.mgc;
+        struct obd_import *imp;
+        struct obd_uuid server_uuid;
+        int rq_portal, rp_portal, connect_op;
+        char *name = obddev->obd_type->typ_name;
+        int rc;
+        ENTRY;
+
+        if (!strcmp(name, LUSTRE_MGC_NAME)) {
+                rq_portal = MGS_REQUEST_PORTAL;
+                rp_portal = MGC_REPLY_PORTAL;
+                connect_op = MGS_CONNECT;
+        } else {
+                CERROR("wrong client OBD type \"%s\", can't setup\n",
+                       name);
+                RETURN(-EINVAL);
+        }
+
+        if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
+                CERROR("requires a TARGET UUID\n");
+                RETURN(-EINVAL);
+        }
+
+        if (LUSTRE_CFG_BUFLEN(lcfg, 1) > 37) {
+                CERROR("client UUID must be less than 38 characters\n");
+                RETURN(-EINVAL);
+        }
+
+        if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) {
+                CERROR("setup requires a SERVER UUID\n");
+                RETURN(-EINVAL);
+        }
+
+        if (LUSTRE_CFG_BUFLEN(lcfg, 2) > 37) {
+                CERROR("target UUID must be less than 38 characters\n");
+                RETURN(-EINVAL);
+        }
+
+        sema_init(&mgc->cl_sem, 1);
+        mgc->cl_conn_count = 0;
+        memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
+               min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
+                     sizeof(server_uuid)));
+
+        rc = ldlm_get_ref();
+        if (rc) {
+                CERROR("ldlm_get_ref failed: %d\n", rc);
+                GOTO(err, rc);
+        }
+
+        ptlrpc_init_client(rq_portal, rp_portal, name,
+                           &obddev->obd_ldlm_client);
+
+        imp = class_new_import();
+        if (imp == NULL)
+                GOTO(err_ldlm, rc = -ENOENT);
+        imp->imp_client = &obddev->obd_ldlm_client;
+        imp->imp_obd = obddev;
+        imp->imp_connect_op = connect_op;
+        imp->imp_generation = 0;
+        imp->imp_initial_recov = 1;
+        INIT_LIST_HEAD(&imp->imp_pinger_chain);
+        memcpy(imp->imp_target_uuid.uuid, lustre_cfg_buf(lcfg, 1),
+               LUSTRE_CFG_BUFLEN(lcfg, 1));
+        class_import_put(imp);
+
+        rc = client_import_add_conn(imp, &server_uuid, 1);
+        if (rc) {
+                CERROR("can't add initial connection\n");
+                GOTO(err_import, rc);
+        }
+
+        mgc->cl_import = imp;
+
+        RETURN(rc);
+
+err_import:
+        class_destroy_import(imp);
+err_ldlm:
+        ldlm_put_ref(0);
+err:
+        RETURN(rc);
+}
+
+/*mgc_obd_cleaup for mount-conf*/
+int mgc_obd_cleanup(struct obd_device *obddev)
+{
+        struct mgc_obd *mgc = &obddev->u.mgc;
+
+        if (!mgc->cl_import)
+                RETURN(-EINVAL);
+
+        class_destroy_import(mgc->cl_import);
+        mgc->cl_import = NULL;
+
+        ldlm_put_ref(obddev->obd_force);
+
+        RETURN(0);
+}
+
+/* mgc_connect_import for mount-conf*/
+int mgc_connect_import(struct lustre_handle *dlm_handle,
+                       struct obd_device *obd, struct obd_uuid *cluuid,
+                       struct obd_connect_data *data)
+{
+        struct mgc_obd *cli = &obd->u.mgc;
+        struct obd_import *imp = mgc->cl_import;
+        struct obd_export *exp;
+        int rc;
+        ENTRY;
+
+        down(&mgc->cl_sem);
+        rc = class_connect(dlm_handle, obd, cluuid);
+        if (rc)
+                GOTO(out_sem, rc);
+
+        mgc->cl_conn_count++;
+        if (mgc->cl_conn_count > 1)
+                GOTO(out_sem, rc);
+        exp = class_conn2export(dlm_handle);
+
+        imp->imp_dlm_handle = *dlm_handle;
+        rc = ptlrpc_init_import(imp);
+        if (rc != 0) 
+                GOTO(out_disco, rc);
+
+        if (data)
+                memcpy(&imp->imp_connect_data, data, sizeof(*data));
+        rc = ptlrpc_connect_import(imp, NULL);
+        if (rc != 0) {
+                LASSERT (imp->imp_state == LUSTRE_IMP_DISCON);
+                GOTO(out_disco, rc);
+        }
+        LASSERT(exp->exp_connection);
+
+        ptlrpc_pinger_add_import(imp);
+        EXIT;
+
+        if (rc) {
+out_disco:
+                mgc->cl_conn_count--;
+                class_disconnect(exp);
+        } else {
+                class_export_put(exp);
+        }
+out_sem:
+        up(&mgc->cl_sem);
+        return rc;
+}
+
+/* mgc_disconnect_export for mount-conf*/
+int mgc_disconnect_export(struct obd_export *exp)
+{
+        struct obd_device *obd = class_exp2obd(exp);
+        struct mgc_obd *mgc = &obd->u.mgc;
+        struct obd_import *imp = mgc->cl_import;
+        int rc = 0, err;
+        ENTRY;
+
+        if (!obd) {
+                CERROR("invalid export for disconnect: exp %p cookie "LPX64"\n",
+                       exp, exp ? exp->exp_handle.h_cookie : -1);
+                RETURN(-EINVAL);
+        }
+
+        down(&mgc->cl_sem);
+        if (!mgc->cl_conn_count) {
+                CERROR("disconnecting disconnected device (%s)\n",
+                       obd->obd_name);
+                GOTO(out_sem, rc = -EINVAL);
+        }
+
+        mgc->cl_conn_count--;
+        if (mgc->cl_conn_count)
+                GOTO(out_no_disconnect, rc = 0);
+
+        /* Some non-replayable imports (MDS's OSCs) are pinged, so just
+         * delete it regardless.  (It's safe to delete an import that was
+         * never added.) */
+        (void)ptlrpc_pinger_del_import(imp);
+
+        /* Yeah, obd_no_recov also (mainly) means "forced shutdown". */
+        if (obd->obd_no_recov)
+                ptlrpc_invalidate_import(imp);
+        else
+                rc = ptlrpc_disconnect_import(imp);
+
+        EXIT;
+ out_no_disconnect:
+        err = class_disconnect(exp);
+        if (!rc && err)
+                rc = err;
+ out_sem:
+        up(&mgc->cl_sem);
+        RETURN(rc);
+}
+
 int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
 {
         struct lustre_cfg* lcfg = buf;
index 875fcd6..90f43af 100644 (file)
@@ -1668,6 +1668,10 @@ EXPORT_SYMBOL(client_obd_setup);
 EXPORT_SYMBOL(client_obd_cleanup);
 EXPORT_SYMBOL(client_connect_import);
 EXPORT_SYMBOL(client_disconnect_export);
+EXPORT_SYMBOL(mgc_obd_setup);
+EXPORT_SYMBOL(mgc_obd_cleanup);
+EXPORT_SYMBOL(mgc_connect_import);
+EXPORT_SYMBOL(mgc_disconnect_export);
 EXPORT_SYMBOL(target_abort_recovery);
 EXPORT_SYMBOL(target_cleanup_recovery);
 EXPORT_SYMBOL(target_handle_connect);