Whamcloud - gitweb
LU-3285 merge: 'dom' branch merging
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
index 9a5d25d..1641161 100644 (file)
@@ -56,6 +56,7 @@
 #include <uapi/linux/lustre/lustre_param.h>
 #include <lustre_swab.h>
 #include <obd_class.h>
+#include <lustre_osc.h>
 
 #include "mdc_internal.h"
 
@@ -2239,14 +2240,6 @@ static int mdc_set_info_async(const struct lu_env *env,
                                        keylen, key, vallen, val, set);
                 RETURN(rc);
         }
-        if (KEY_IS(KEY_SPTLRPC_CONF)) {
-                sptlrpc_conf_client_adapt(exp->exp_obd);
-                RETURN(0);
-        }
-        if (KEY_IS(KEY_FLUSH_CTX)) {
-                sptlrpc_import_flush_my_ctx(imp);
-                RETURN(0);
-        }
         if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
                 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
                                        keylen, key, vallen, val, set);
@@ -2264,8 +2257,8 @@ static int mdc_set_info_async(const struct lu_env *env,
                RETURN(0);
        }
 
-       CERROR("Unknown key %s\n", (char *)key);
-       RETURN(-EINVAL);
+       rc = osc_set_info_async(env, exp, keylen, key, vallen, val, set);
+       RETURN(rc);
 }
 
 static int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
@@ -2344,14 +2337,19 @@ static int mdc_fsync(struct obd_export *exp, const struct lu_fid *fid,
 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
                            enum obd_import_event event)
 {
+       struct client_obd *cli = &obd->u.cli;
        int rc = 0;
 
        LASSERT(imp->imp_obd == obd);
 
        switch (event) {
-
-       case IMP_EVENT_INACTIVE: {
-               struct client_obd *cli = &obd->u.cli;
+       case IMP_EVENT_DISCON:
+               spin_lock(&cli->cl_loi_list_lock);
+               cli->cl_avail_grant = 0;
+               cli->cl_lost_grant = 0;
+               spin_unlock(&cli->cl_loi_list_lock);
+               break;
+       case IMP_EVENT_INACTIVE:
                /*
                 * Flush current sequence to make client obtain new one
                 * from server in case of disconnect/reconnect.
@@ -2363,12 +2361,28 @@ static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
 
                rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE);
                break;
-       }
        case IMP_EVENT_INVALIDATE: {
                struct ldlm_namespace *ns = obd->obd_namespace;
+               struct lu_env *env;
+               __u16 refcheck;
 
                ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
 
+               env = cl_env_get(&refcheck);
+               if (!IS_ERR(env)) {
+                       /* Reset grants. All pages go to failing rpcs due to
+                        * the invalid import.
+                        */
+                       osc_io_unplug(env, cli, NULL);
+
+                       cfs_hash_for_each_nolock(ns->ns_rs_hash,
+                                                osc_ldlm_resource_invalidate,
+                                                env, 0);
+                       cl_env_put(env, &refcheck);
+                       ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
+               } else {
+                       rc = PTR_ERR(env);
+               }
                break;
        }
        case IMP_EVENT_ACTIVE:
@@ -2377,10 +2391,15 @@ static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
                if (rc == 0)
                        rc = mdc_kuc_reregister(imp);
                break;
-       case IMP_EVENT_OCD:
+       case IMP_EVENT_OCD: {
+               struct obd_connect_data *ocd = &imp->imp_connect_data;
+
+               if (OCD_HAS_FLAG(ocd, GRANT))
+                       osc_init_grant(cli, ocd);
+
                rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD);
                break;
-       case IMP_EVENT_DISCON:
+       }
        case IMP_EVENT_DEACTIVATE:
        case IMP_EVENT_ACTIVATE:
                break;
@@ -2477,23 +2496,22 @@ static void mdc_llog_finish(struct obd_device *obd)
        EXIT;
 }
 
-static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
+int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
 {
-       int                             rc;
+       int rc;
+
        ENTRY;
 
-       rc = ptlrpcd_addref();
+       rc = osc_setup_common(obd, cfg);
        if (rc < 0)
                RETURN(rc);
 
-        rc = client_obd_setup(obd, cfg);
-        if (rc)
-               GOTO(err_ptlrpcd_decref, rc);
 #ifdef CONFIG_PROC_FS
        obd->obd_vars = lprocfs_mdc_obd_vars;
        lprocfs_obd_setup(obd, false);
        lprocfs_alloc_md_stats(obd, 0);
 #endif
+
        sptlrpc_lprocfs_cliobd_attach(obd);
        ptlrpc_lprocfs_register_obd(obd);
 
@@ -2505,26 +2523,27 @@ static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
         if (rc) {
                 CERROR("%s: failed to setup llogging subsystems: rc = %d\n",
                       obd->obd_name, rc);
-               GOTO(err_mdc_cleanup, rc);
+               GOTO(err_llog_cleanup, rc);
         }
 
        rc = mdc_changelog_cdev_init(obd);
        if (rc) {
                CERROR("%s: failed to setup changelog char device: rc = %d\n",
                       obd->obd_name, rc);
-               GOTO(err_mdc_cleanup, rc);
+               GOTO(err_changelog_cleanup, rc);
        }
 
-       EXIT;
-err_mdc_cleanup:
-       if (rc)
-               client_obd_cleanup(obd);
+       RETURN(rc);
 
-err_ptlrpcd_decref:
-       if (rc)
-               ptlrpcd_decref();
+err_changelog_cleanup:
+       mdc_llog_finish(obd);
+err_llog_cleanup:
+       ptlrpc_lprocfs_unregister_obd(obd);
+       lprocfs_obd_cleanup(obd);
+       lprocfs_free_md_stats(obd);
 
-        return rc;
+       osc_cleanup_common(obd);
+       return rc;
 }
 
 /* Initialize the default and maximum LOV EA sizes.  This allows
@@ -2555,6 +2574,8 @@ static int mdc_precleanup(struct obd_device *obd)
 {
        ENTRY;
 
+       osc_precleanup_common(obd);
+
        /* Failsafe, ok if racy */
        if (obd->obd_type->typ_refcnt <= 1)
                libcfs_kkuc_group_rem(0, KUC_GRP_HSM);
@@ -2571,15 +2592,15 @@ static int mdc_precleanup(struct obd_device *obd)
 
 static int mdc_cleanup(struct obd_device *obd)
 {
-        ptlrpcd_decref();
-
-        return client_obd_cleanup(obd);
+       return osc_cleanup_common(obd);
 }
 
-static int mdc_process_config(struct obd_device *obd, size_t len, void *buf)
+int mdc_process_config(struct obd_device *obd, size_t len, void *buf)
 {
-        struct lustre_cfg *lcfg = buf;
-       int rc = class_process_proc_param(PARAM_MDC, obd->obd_vars, lcfg, obd);
+       struct lustre_cfg *lcfg = buf;
+       int rc;
+
+       rc = class_process_proc_param(PARAM_MDC, obd->obd_vars, lcfg, obd);
        return (rc > 0 ? 0: rc);
 }
 
@@ -2591,7 +2612,8 @@ static struct obd_ops mdc_obd_ops = {
         .o_add_conn         = client_import_add_conn,
         .o_del_conn         = client_import_del_conn,
         .o_connect          = client_connect_import,
-        .o_disconnect       = client_disconnect_export,
+       .o_reconnect        = osc_reconnect,
+       .o_disconnect       = osc_disconnect,
         .o_iocontrol        = mdc_iocontrol,
         .o_set_info_async   = mdc_set_info_async,
         .o_statfs           = mdc_statfs,
@@ -2637,7 +2659,7 @@ static struct md_ops mdc_md_ops = {
 static int __init mdc_init(void)
 {
        return class_register_type(&mdc_obd_ops, &mdc_md_ops, true, NULL,
-                                  LUSTRE_MDC_NAME, NULL);
+                                  LUSTRE_MDC_NAME, &mdc_device_type);
 }
 
 static void __exit mdc_exit(void)