X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fosp%2Flwp_dev.c;h=a73973a495c823536d63fab5a484ffa74bf78242;hp=8b1653ee8fda9757eff369ebe03c75c84974df8b;hb=294e507d34de0d7990ec507334f71ff1d1a7db01;hpb=11db1a551172f596d1d284e8496530f9ce24ac81 diff --git a/lustre/osp/lwp_dev.c b/lustre/osp/lwp_dev.c index 8b1653e..a73973a 100644 --- a/lustre/osp/lwp_dev.c +++ b/lustre/osp/lwp_dev.c @@ -37,6 +37,7 @@ #include #include #include +#include struct lwp_device { struct lu_device lpd_dev; @@ -56,40 +57,17 @@ static inline struct lu_device *lwp2lu_dev(struct lwp_device *d) 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; @@ -97,23 +75,22 @@ static int lwp_setup(const struct lu_env *env, struct lwp_device *lwp, 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); @@ -138,17 +115,16 @@ out: 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; @@ -168,12 +144,11 @@ int lwp_disconnect(struct lwp_device *d) /* 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); @@ -269,7 +244,7 @@ static struct lu_device *lwp_device_free(const struct lu_env *env, struct lwp_device *m = lu2lwp_dev(lu); ENTRY; - if (cfs_atomic_read(&lu->ld_ref) && lu->ld_site) { + 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); } @@ -321,8 +296,6 @@ static struct lu_device *lwp_device_fini(const struct lu_env *env, 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); @@ -353,8 +326,9 @@ static int lwp_obd_connect(const struct lu_env *env, struct obd_export **exp, 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; @@ -362,9 +336,11 @@ static int lwp_obd_connect(const struct lu_env *env, struct obd_export **exp, 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; @@ -373,8 +349,10 @@ static int lwp_obd_connect(const struct lu_env *env, struct obd_export **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; @@ -386,15 +364,26 @@ static int lwp_obd_connect(const struct lu_env *env, struct obd_export **exp, 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)