Whamcloud - gitweb
LU-7950 osp: Remove assigned but not used variable
[fs/lustre-release.git] / lustre / osp / lwp_dev.c
index dccfef4..b28f32c 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2013, 2014, Intel Corporation.
+ * Copyright (c) 2013, 2015, Intel Corporation.
  * Use is subject to license terms.
  *
  * lustre/osp/lwp_dev.c
@@ -42,6 +42,7 @@
 #include <obd_class.h>
 #include <lustre_param.h>
 #include <lustre_log.h>
+#include <linux/kthread.h>
 
 #include "osp_internal.h"
 
@@ -50,6 +51,7 @@ struct lwp_device {
        struct obd_device      *lpd_obd;   /* corresponding OBD device */
        struct obd_uuid         lpd_cluuid;/* UUID of LWP */
        struct obd_export      *lpd_exp;   /* export of LWP */
+       struct ptlrpc_thread    lpd_notify_thread; /* notify thread */
        int                     lpd_connects; /* use count, 0 or 1 */
 };
 
@@ -87,6 +89,9 @@ static int lwp_setup(const struct lu_env *env, struct lwp_device *lwp,
        int                      rc;
        ENTRY;
 
+       thread_set_flags(&lwp->lpd_notify_thread, SVC_STOPPED);
+       init_waitqueue_head(&lwp->lpd_notify_thread.t_ctl_waitq);
+
        OBD_ALLOC_PTR(bufs);
        if (bufs == NULL)
                RETURN(-ENOMEM);
@@ -353,21 +358,19 @@ static struct lu_device *lwp_device_alloc(const struct lu_env *env,
 static struct lu_device *lwp_device_fini(const struct lu_env *env,
                                         struct lu_device *ludev)
 {
-       struct lwp_device *m = lu2lwp_dev(ludev);
-       struct obd_import *imp;
-       int                rc;
+       struct lwp_device       *m = lu2lwp_dev(ludev);
+       struct ptlrpc_thread    *thread = &m->lpd_notify_thread;
+       struct l_wait_info       lwi = { 0 };
+       int                      rc;
        ENTRY;
 
+       if (!thread_is_stopped(thread))
+               l_wait_event(thread->t_ctl_waitq, thread_is_stopped(thread),
+                            &lwi);
+
        if (m->lpd_exp != NULL)
                class_disconnect(m->lpd_exp);
 
-       imp = m->lpd_obd->u.cli.cl_import;
-
-       if (imp->imp_rq_pool) {
-               ptlrpc_free_rq_pool(imp->imp_rq_pool);
-               imp->imp_rq_pool = NULL;
-       }
-
        LASSERT(m->lpd_obd);
        ptlrpc_lprocfs_unregister_obd(m->lpd_obd);
        lprocfs_obd_cleanup(m->lpd_obd);
@@ -393,6 +396,65 @@ struct lu_device_type lwp_device_type = {
        .ldt_ctx_tags = LCT_MD_THREAD
 };
 
+static int lwp_notify_main(void *args)
+{
+       struct obd_export       *exp = (struct obd_export *)args;
+       struct lwp_device       *lwp;
+       struct ptlrpc_thread    *thread;
+
+       LASSERT(exp != NULL);
+       lwp = lu2lwp_dev(exp->exp_obd->obd_lu_dev);
+       thread = &lwp->lpd_notify_thread;
+
+       thread_set_flags(thread, SVC_RUNNING);
+       wake_up(&thread->t_ctl_waitq);
+
+       lustre_notify_lwp_list(exp);
+
+       thread_set_flags(thread, SVC_STOPPED);
+       wake_up(&thread->t_ctl_waitq);
+       return 0;
+}
+
+/*
+ * Some notify callbacks may cause deadlock in failover
+ * scenario, so we have to start thread to run callbacks
+ * asynchronously. See LU-6273.
+ */
+static void lwp_notify_users(struct obd_export *exp)
+{
+       struct lwp_device       *lwp;
+       struct ptlrpc_thread    *thread;
+       struct task_struct      *task;
+       struct l_wait_info       lwi = { 0 };
+       char                     name[MTI_NAME_MAXLEN];
+
+       LASSERT(exp != NULL);
+       lwp = lu2lwp_dev(exp->exp_obd->obd_lu_dev);
+       thread = &lwp->lpd_notify_thread;
+
+       snprintf(name, MTI_NAME_MAXLEN, "lwp_notify_%s",
+                exp->exp_obd->obd_name);
+
+       /* Notify happens only on LWP setup, so there shouldn't
+        * be notify thread running */
+       if (!thread_is_stopped(thread)) {
+               CERROR("LWP notify thread: %s wasn't stopped\n", name);
+               return;
+       }
+
+       task = kthread_run(lwp_notify_main, exp, name);
+       if (IS_ERR(task)) {
+               thread_set_flags(thread, SVC_STOPPED);
+               CERROR("Failed to start LWP notify thread:%s. %lu\n",
+                      name, PTR_ERR(task));
+       }
+
+       l_wait_event(thread->t_ctl_waitq,
+                    thread_is_running(thread) || thread_is_stopped(thread),
+                    &lwi);
+}
+
 /**
  * Implementation of OBD device operations obd_ops::o_connect.
  *
@@ -448,6 +510,7 @@ static int lwp_obd_connect(const struct lu_env *env, struct obd_export **exp,
 
        ocd->ocd_version = LUSTRE_VERSION_CODE;
        imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
+       imp->imp_connect_flags2_orig = ocd->ocd_connect_flags2;
 
        rc = ptlrpc_connect_import(imp);
        if (rc != 0) {
@@ -469,6 +532,9 @@ out_dis:
 out_sem:
        up_write(&cli->cl_sem);
 
+       if (rc == 0)
+               lwp_notify_users(*exp);
+
        return rc;
 }
 
@@ -533,6 +599,23 @@ static int lwp_import_event(struct obd_device *obd, struct obd_import *imp,
        return 0;
 }
 
+static int lwp_set_info_async(const struct lu_env *env,
+                             struct obd_export *exp,
+                             u32 keylen, void *key,
+                             u32 vallen, void *val,
+                             struct ptlrpc_request_set *set)
+{
+       ENTRY;
+
+       if (KEY_IS(KEY_SPTLRPC_CONF)) {
+               sptlrpc_conf_client_adapt(exp->exp_obd);
+               RETURN(0);
+       }
+
+       CERROR("Unknown key %s\n", (char *)key);
+       RETURN(-EINVAL);
+}
+
 struct obd_ops lwp_obd_device_ops = {
        .o_owner        = THIS_MODULE,
        .o_add_conn     = client_import_add_conn,
@@ -540,4 +623,5 @@ struct obd_ops lwp_obd_device_ops = {
        .o_connect      = lwp_obd_connect,
        .o_disconnect   = lwp_obd_disconnect,
        .o_import_event = lwp_import_event,
+       .o_set_info_async   = lwp_set_info_async,
 };