* GPL HEADER END
*/
/*
- * Copyright (c) 2013, 2016, Intel Corporation.
+ * Copyright (c) 2013, 2017, Intel Corporation.
* Use is subject to license terms.
*
* lustre/osp/lwp_dev.c
struct lwp_device {
struct lu_device lpd_dev;
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 */
+ struct task_struct *lpd_notify_task; /* notify thread */
int lpd_connects; /* use count, 0 or 1 */
};
static inline struct lwp_device *lu2lwp_dev(struct lu_device *d)
{
- return container_of0(d, struct lwp_device, lpd_dev);
+ return container_of_safe(d, struct lwp_device, lpd_dev);
}
static inline struct lu_device *lwp2lu_dev(struct lwp_device *d)
char *lwp_name = lwp->lpd_obd->obd_name;
char *server_uuid = NULL;
char *ptr;
- class_uuid_t uuid;
+ int uuid_len = -1;
struct obd_import *imp;
int len = strlen(lwp_name) + 1;
int rc;
+ const char *lwp_marker = "-" LUSTRE_LWP_NAME "-";
ENTRY;
- thread_set_flags(&lwp->lpd_notify_thread, SVC_STOPPED);
- init_waitqueue_head(&lwp->lpd_notify_thread.t_ctl_waitq);
+ lwp->lpd_notify_task = NULL;
OBD_ALLOC_PTR(bufs);
if (bufs == NULL)
if (server_uuid == NULL)
GOTO(out, rc = -ENOMEM);
- snprintf(server_uuid, len, "-%s-", LUSTRE_LWP_NAME);
- ptr = cfs_strrstr(lwp_name, server_uuid);
- if (ptr == NULL) {
+ ptr = lwp_name;
+ while (ptr && (ptr = strstr(ptr+1, lwp_marker)) != NULL)
+ uuid_len = ptr - lwp_name;
+
+ if (uuid_len < 0) {
CERROR("%s: failed to get server_uuid from lwp_name: rc = %d\n",
lwp_name, -EINVAL);
GOTO(out, rc = -EINVAL);
}
- strncpy(server_uuid, lwp_name, ptr - lwp_name);
- server_uuid[ptr - lwp_name] = '\0';
+ strncpy(server_uuid, lwp_name, uuid_len);
strlcat(server_uuid, "_UUID", len);
lustre_cfg_bufs_reset(bufs, lwp_name);
lustre_cfg_bufs_set_string(bufs, 1, server_uuid);
imp = lwp->lpd_obd->u.cli.cl_import;
rc = ptlrpc_init_import(imp);
- if (rc)
- GOTO(out, rc);
-
- ll_generate_random_uuid(uuid);
- class_uuid_unparse(uuid, &lwp->lpd_cluuid);
out:
if (bufs != NULL)
OBD_FREE_PTR(bufs);
RETURN(rc);
}
- rc = lwp_setup(env, lwp, lustre_cfg_string(cfg, 1));
+ rc = lprocfs_obd_setup(lwp->lpd_obd, true);
if (rc) {
- CERROR("%s: setup lwp failed. %d\n",
+ CERROR("%s: lprocfs_obd_setup failed. %d\n",
lwp->lpd_obd->obd_name, rc);
ptlrpcd_decref();
RETURN(rc);
}
- rc = lprocfs_obd_setup(lwp->lpd_obd, true);
+ rc = lwp_setup(env, lwp, lustre_cfg_string(cfg, 1));
if (rc) {
- CERROR("%s: lprocfs_obd_setup failed. %d\n",
+ CERROR("%s: setup lwp failed. %d\n",
lwp->lpd_obd->obd_name, rc);
+ lprocfs_obd_cleanup(lwp->lpd_obd);
ptlrpcd_decref();
RETURN(rc);
}
struct lwp_device *m = lu2lwp_dev(lu);
ENTRY;
- if (atomic_read(&lu->ld_ref) && lu->ld_site) {
- LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_ERROR, NULL);
- lu_site_print(env, lu->ld_site, &msgdata, lu_cdebug_printer);
- }
+ lu_site_print(env, lu->ld_site, &lu->ld_ref, D_ERROR,
+ lu_cdebug_printer);
lu_device_fini(&m->lpd_dev);
OBD_FREE_PTR(m);
RETURN(NULL);
struct lu_device *ludev)
{
struct lwp_device *m = lu2lwp_dev(ludev);
- struct ptlrpc_thread *thread = &m->lpd_notify_thread;
- struct l_wait_info lwi = { 0 };
+ struct task_struct *task = NULL;
int rc;
ENTRY;
- if (!thread_is_stopped(thread))
- l_wait_event(thread->t_ctl_waitq, thread_is_stopped(thread),
- &lwi);
+ task = xchg(&m->lpd_notify_task, NULL);
+ if (task) {
+ kthread_stop(task);
+ class_export_put(m->lpd_exp);
+ }
if (m->lpd_exp != NULL)
class_disconnect(m->lpd_exp);
LASSERT(m->lpd_obd);
- ptlrpc_lprocfs_unregister_obd(m->lpd_obd);
-
rc = client_obd_cleanup(m->lpd_obd);
LASSERTF(rc == 0, "error %d\n", rc);
+ ptlrpc_lprocfs_unregister_obd(m->lpd_obd);
+
ptlrpcd_decref();
RETURN(NULL);
}
-static struct lu_device_type_operations lwp_device_type_ops = {
- .ldto_device_alloc = lwp_device_alloc,
- .ldto_device_free = lwp_device_free,
- .ldto_device_fini = lwp_device_fini
+static const struct lu_device_type_operations lwp_device_type_ops = {
+ .ldto_device_alloc = lwp_device_alloc,
+ .ldto_device_free = lwp_device_free,
+ .ldto_device_fini = lwp_device_fini
};
struct lu_device_type lwp_device_type = {
{
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);
+ if (xchg(&lwp->lpd_notify_task, NULL) == NULL)
+ /* lwp_device_fini() is waiting for me
+ * Note that the wakeup comes direct from
+ * kthread_stop, not from wake_up_var().
+ * lwp_device_fini() will call class_export_put().
+ */
+ wait_var_event(lwp, kthread_should_stop());
+ else
+ class_export_put(exp);
+
return 0;
}
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)) {
+ if (lwp->lpd_notify_task) {
CERROR("LWP notify thread: %s wasn't stopped\n", name);
return;
}
- task = kthread_run(lwp_notify_main, exp, name);
+ task = kthread_create(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));
+ } else {
+ lwp->lpd_notify_task = task;
+ class_export_get(exp);
+ wake_up_process(task);
}
-
- l_wait_event(thread->t_ctl_waitq,
- thread_is_running(thread) || thread_is_stopped(thread),
- &lwi);
}
/**
RETURN(-EINVAL);
}
-struct obd_ops lwp_obd_device_ops = {
+const struct obd_ops lwp_obd_device_ops = {
.o_owner = THIS_MODULE,
.o_add_conn = client_import_add_conn,
.o_del_conn = client_import_del_conn,