+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);
+ class_export_get(exp);
+
+ 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);
+
+ class_export_put(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.
+ *
+ * Create export for LWP, and connect to target server.
+ *
+ * \param[in] env the environment passed by caller
+ * \param[out] exp export for the connection to be established
+ * \param[in] obd OBD device to perform the connect on
+ * \param[in] cluuid UUID of the OBD device
+ * \param[in] data connect data containing compatibility flags
+ * \param[in] localdata not used
+ *
+ * \retval 0 on success
+ * \retval negative number on error
+ */