* GPL HEADER END
*/
/*
- * Copyright (c) 2012 Intel Corporation
+ * Copyright (c) 2013, Intel Corporation.
* Use is subject to license terms.
*
* lustre/osp/lwp_dev.c
* Author: <di.wang@intel.com>
* Author: <yawei.niu@intel.com>
*/
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
#define DEBUG_SUBSYSTEM S_OST
#include <obd_class.h>
#include <lustre_param.h>
#include <lustre_log.h>
+#include <libcfs/libcfs_string.h>
struct lwp_device {
struct lu_device lpd_dev;
return &d->lpd_dev;
}
-static int lwp_name2fsname(char *lwpname, char *fsname)
-{
- char *ptr;
-
- LASSERT(lwpname != NULL);
- LASSERT(fsname != NULL);
-
- sprintf(fsname, "-%s-", LUSTRE_LWP_NAME);
-
- ptr = strstr(lwpname, fsname);
- if (ptr == NULL)
- return -EINVAL;
-
- while (*(--ptr) != '-') {
- if (ptr == lwpname)
- return -EINVAL;
- }
-
- strncpy(fsname, lwpname, ptr - lwpname);
- fsname[ptr - lwpname] = '\0';
-
- return 0;
-}
-
static int lwp_setup(const struct lu_env *env, struct lwp_device *lwp,
char *nidstring)
{
struct lustre_cfg_bufs *bufs = NULL;
struct lustre_cfg *lcfg = NULL;
- char *lwpname = lwp->lpd_obd->obd_name;
- char *fsname = NULL;
+ char *lwp_name = lwp->lpd_obd->obd_name;
char *server_uuid = NULL;
+ char *ptr;
class_uuid_t uuid;
struct obd_import *imp;
+ int len = strlen(lwp_name);
int rc;
ENTRY;
if (bufs == NULL)
RETURN(-ENOMEM);
- OBD_ALLOC(fsname, strlen(lwpname));
- if (fsname == NULL)
+ OBD_ALLOC(server_uuid, len);
+ if (server_uuid == NULL)
GOTO(out, rc = -ENOMEM);
- rc = lwp_name2fsname(lwpname, fsname);
- if (rc) {
- CERROR("%s: failed to get fsname from lwpname. %d\n",
- lwpname, rc);
- GOTO(out, rc);
+ snprintf(server_uuid, len, "-%s-", LUSTRE_LWP_NAME);
+ ptr = cfs_strrstr(lwp_name, server_uuid);
+ if (ptr == NULL) {
+ CERROR("%s: failed to get server_uuid from lwp_name: rc = %d\n",
+ lwp_name, -EINVAL);
+ GOTO(out, rc = -EINVAL);
}
- OBD_ALLOC(server_uuid, strlen(fsname) + 15);
- if (server_uuid == NULL)
- GOTO(out, rc = -ENOMEM);
-
- sprintf(server_uuid, "%s-MDT0000_UUID", fsname);
- lustre_cfg_bufs_reset(bufs, lwpname);
+ strncpy(server_uuid, lwp_name, ptr - lwp_name);
+ server_uuid[ptr - lwp_name] = '\0';
+ strncat(server_uuid, "_UUID", len - 1);
+ lustre_cfg_bufs_reset(bufs, lwp_name);
lustre_cfg_bufs_set_string(bufs, 1, server_uuid);
lustre_cfg_bufs_set_string(bufs, 2, nidstring);
lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
if (bufs != NULL)
OBD_FREE_PTR(bufs);
if (server_uuid != NULL)
- OBD_FREE(server_uuid, strlen(fsname) + 15);
- if (fsname != NULL)
- OBD_FREE(fsname, strlen(lwpname));
+ OBD_FREE(server_uuid, len);
if (lcfg != NULL)
lustre_cfg_free(lcfg);
if (rc)
client_obd_cleanup(lwp->lpd_obd);
+
RETURN(rc);
}
-int lwp_disconnect(struct lwp_device *d)
+static int lwp_disconnect(struct lwp_device *d)
{
struct obd_import *imp;
int 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);
-
+ ptlrpc_pinger_del_import(imp);
rc = ptlrpc_disconnect_import(imp, 0);
- if (rc && rc != -ETIMEDOUT)
- CERROR("%s: can't disconnect: rc = %d\n",
- d->lpd_obd->obd_name, rc);
+ if (rc != 0)
+ CWARN("%s: can't disconnect: rc = %d\n",
+ d->lpd_obd->obd_name, rc);
ptlrpc_invalidate_import(imp);
imp->imp_rq_pool = NULL;
}
- obd_cleanup_client_import(m->lpd_obd);
-
LASSERT(m->lpd_obd);
ptlrpc_lprocfs_unregister_obd(m->lpd_obd);
lprocfs_obd_cleanup(m->lpd_obd);
struct obd_connect_data *data, void *localdata)
{
struct lwp_device *lwp = lu2lwp_dev(obd->obd_lu_dev);
+ struct client_obd *cli = &lwp->lpd_obd->u.cli;
+ struct obd_import *imp = cli->cl_import;
struct obd_connect_data *ocd;
- struct obd_import *imp;
struct lustre_handle conn;
int rc;
CDEBUG(D_CONFIG, "connect #%d\n", lwp->lpd_connects);
+ *exp = NULL;
+ down_write(&cli->cl_sem);
rc = class_connect(&conn, obd, cluuid);
- if (rc)
- RETURN(rc);
+ if (rc != 0)
+ GOTO(out_sem, rc);
*exp = class_conn2export(&conn);
lwp->lpd_exp = *exp;
lwp->lpd_connects++;
LASSERT(lwp->lpd_connects == 1);
- imp = lwp->lpd_obd->u.cli.cl_import;
imp->imp_dlm_handle = conn;
+ rc = ptlrpc_init_import(imp);
+ if (rc != 0)
+ GOTO(out_dis, rc);
LASSERT(data != NULL);
ocd = &imp->imp_connect_data;
imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
rc = ptlrpc_connect_import(imp);
- if (rc) {
+ if (rc != 0) {
CERROR("%s: can't connect obd: rc = %d\n", obd->obd_name, rc);
- GOTO(out, rc);
+ GOTO(out_dis, rc);
}
ptlrpc_pinger_add_import(imp);
-out:
- RETURN(rc);
+ GOTO(out_dis, rc = 0);
+
+out_dis:
+ if (rc != 0) {
+ class_disconnect(*exp);
+ *exp = NULL;
+ lwp->lpd_exp = NULL;
+ }
+
+out_sem:
+ up_write(&cli->cl_sem);
+
+ return rc;
}
static int lwp_obd_disconnect(struct obd_export *exp)