From 4842774e71694f5e096bdc70e067aac3aec4971d Mon Sep 17 00:00:00 2001 From: Mikhail Pershin Date: Sun, 20 May 2012 18:05:26 +0400 Subject: [PATCH] LU-1406 ofd: add connect functions Patch adds connect functions and export init/fini Signed-off-by: Mikhail Pershin Change-Id: I6535d37845863c269dc279c6acc8be8bb8c54432 Reviewed-on: http://review.whamcloud.com/2855 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- lustre/ofd/ofd_dev.c | 24 +++- lustre/ofd/ofd_internal.h | 7 ++ lustre/ofd/ofd_obd.c | 285 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 313 insertions(+), 3 deletions(-) diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index 0eef6a4..345189d 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -340,6 +340,9 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, obd->u.obt.obt_magic = OBT_MAGIC; + cfs_rwlock_init(&obd->u.filter.fo_sptlrpc_lock); + sptlrpc_rule_set_init(&obd->u.filter.fo_sptlrpc_rset); + m->ofd_dt_dev.dd_lu_dev.ld_ops = &ofd_lu_ops; m->ofd_dt_dev.dd_lu_dev.ld_obd = obd; /* set this lu_device to obd, because error handling need it */ @@ -372,6 +375,15 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, GOTO(err_lu_site, rc); } + m->ofd_namespace = ldlm_namespace_new(obd, info->fti_u.name, + LDLM_NAMESPACE_SERVER, + LDLM_NAMESPACE_GREEDY, + LDLM_NS_TYPE_OST); + if (m->ofd_namespace == NULL) + GOTO(err_fini_stack, rc = -ENOMEM); + /* set obd_namespace for compatibility with old code */ + obd->obd_namespace = m->ofd_namespace; + dt_conf_get(env, m->ofd_osd, &m->ofd_dt_conf); rc = ofd_start(env, &m->ofd_dt_dev.dd_lu_dev); @@ -380,7 +392,7 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, rc = lut_init(env, &m->ofd_lut, obd, m->ofd_osd); if (rc) - GOTO(err_fini_stack, rc); + GOTO(err_free_ns, rc); rc = ofd_fs_setup(env, m, obd); if (rc) @@ -398,6 +410,9 @@ err_fs_cleanup: ofd_fs_cleanup(env, m); err_fini_lut: lut_fini(env, &m->ofd_lut); +err_free_ns: + ldlm_namespace_free(m->ofd_namespace, 0, obd->obd_force); + obd->obd_namespace = m->ofd_namespace = NULL; err_fini_stack: ofd_stack_fini(env, m, &m->ofd_osd->dd_lu_dev); err_lu_site: @@ -418,6 +433,12 @@ static void ofd_fini(const struct lu_env *env, struct ofd_device *m) lut_fini(env, &m->ofd_lut); ofd_fs_cleanup(env, m); + if (m->ofd_namespace != NULL) { + ldlm_namespace_free(m->ofd_namespace, NULL, + d->ld_obd->obd_force); + d->ld_obd->obd_namespace = m->ofd_namespace = NULL; + } + ofd_stack_fini(env, m, m->ofd_site.ls_top_dev); lu_site_fini(&m->ofd_site); LASSERT(cfs_atomic_read(&d->ld_ref) == 0); @@ -474,6 +495,7 @@ static void ofd_key_exit(const struct lu_context *ctx, struct ofd_thread_info *info = data; info->fti_env = NULL; + info->fti_exp = NULL; } struct lu_context_key ofd_thread_key = { diff --git a/lustre/ofd/ofd_internal.h b/lustre/ofd/ofd_internal.h index b263676..515a944 100644 --- a/lustre/ofd/ofd_internal.h +++ b/lustre/ofd/ofd_internal.h @@ -52,6 +52,8 @@ struct ofd_device { struct dt_device ofd_dt_dev; struct dt_device *ofd_osd; struct dt_device_param ofd_dt_conf; + /* DLM name-space for meta-data locks maintained by this server */ + struct ldlm_namespace *ofd_namespace; /* last_rcvd file */ struct lu_target ofd_lut; @@ -106,6 +108,7 @@ static inline struct ofd_object *ofd_obj(struct lu_object *o) struct ofd_thread_info { const struct lu_env *fti_env; + struct obd_export *fti_exp; struct lu_fid fti_fid; struct lu_attr fti_attr; union { @@ -133,6 +136,8 @@ extern struct lu_context_key ofd_thread_key; extern struct obd_ops ofd_obd_ops; /* ofd_fs.c */ +obd_id ofd_last_id(struct ofd_device *ofd, obd_seq seq); +int ofd_group_load(const struct lu_env *env, struct ofd_device *ofd, int); int ofd_fs_setup(const struct lu_env *env, struct ofd_device *ofd, struct obd_device *obd); void ofd_fs_cleanup(const struct lu_env *env, struct ofd_device *ofd); @@ -158,9 +163,11 @@ static inline struct ofd_thread_info * ofd_info_init(const struct lu_env *env, info = lu_context_key_get(&env->le_ctx, &ofd_thread_key); LASSERT(info); + LASSERT(info->fti_exp == NULL); LASSERT(info->fti_env == NULL); info->fti_env = env; + info->fti_exp = exp; return info; } diff --git a/lustre/ofd/ofd_obd.c b/lustre/ofd/ofd_obd.c index 7dd9390..2ff9c17 100644 --- a/lustre/ofd/ofd_obd.c +++ b/lustre/ofd/ofd_obd.c @@ -43,6 +43,281 @@ #define DEBUG_SUBSYSTEM S_FILTER #include "ofd_internal.h" +#include + +static int ofd_parse_connect_data(const struct lu_env *env, + struct obd_export *exp, + struct obd_connect_data *data) +{ + struct ofd_device *ofd = ofd_exp(exp); + + if (!data) + RETURN(0); + + CDEBUG(D_RPCTRACE, "%s: cli %s/%p ocd_connect_flags: "LPX64 + " ocd_version: %x ocd_grant: %d ocd_index: %u\n", + exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp, + data->ocd_connect_flags, data->ocd_version, + data->ocd_grant, data->ocd_index); + + data->ocd_connect_flags &= OST_CONNECT_SUPPORTED; + exp->exp_connect_flags = data->ocd_connect_flags; + data->ocd_version = LUSTRE_VERSION_CODE; + + /* Kindly make sure the SKIP_ORPHAN flag is from MDS. */ + if (data->ocd_connect_flags & OBD_CONNECT_MDS) + CDEBUG(D_HA, "%s: Received MDS connection for group %u\n", + exp->exp_obd->obd_name, data->ocd_group); + else if (data->ocd_connect_flags & OBD_CONNECT_SKIP_ORPHAN) + RETURN(-EPROTO); + + if (data->ocd_connect_flags & OBD_CONNECT_INDEX) { + struct lr_server_data *lsd = &ofd->ofd_lut.lut_lsd; + int index = lsd->lsd_ost_index; + + if (!(lsd->lsd_feature_compat & OBD_COMPAT_OST)) { + /* this will only happen on the first connect */ + lsd->lsd_ost_index = data->ocd_index; + lsd->lsd_feature_compat |= OBD_COMPAT_OST; + /* sync is not needed here as lut_client_add will + * set exp_need_sync flag */ + lut_server_data_update(env, &ofd->ofd_lut, 0); + } else if (index != data->ocd_index) { + LCONSOLE_ERROR_MSG(0x136, "Connection from %s to index" + " %u doesn't match actual OST index" + " %u in last_rcvd file, bad " + "configuration?\n", + obd_export_nid2str(exp), index, + data->ocd_index); + RETURN(-EBADF); + } + } + + if (OBD_FAIL_CHECK(OBD_FAIL_OST_BRW_SIZE)) { + data->ocd_brw_size = 65536; + } else if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE) { + data->ocd_brw_size = min(data->ocd_brw_size, + (__u32)(PTLRPC_MAX_BRW_PAGES << CFS_PAGE_SHIFT)); + if (data->ocd_brw_size == 0) { + CERROR("%s: cli %s/%p ocd_connect_flags: "LPX64 + " ocd_version: %x ocd_grant: %d ocd_index: %u " + "ocd_brw_size is unexpectedly zero, " + "network data corruption?" + "Refusing connection of this client\n", + exp->exp_obd->obd_name, + exp->exp_client_uuid.uuid, + exp, data->ocd_connect_flags, data->ocd_version, + data->ocd_grant, data->ocd_index); + RETURN(-EPROTO); + } + } + + if (data->ocd_connect_flags & OBD_CONNECT_CKSUM) { + __u32 cksum_types = data->ocd_cksum_types; + + /* The client set in ocd_cksum_types the checksum types it + * supports. We have to mask off the algorithms that we don't + * support */ + data->ocd_cksum_types &= cksum_types_supported(); + + if (unlikely(data->ocd_cksum_types == 0)) { + CERROR("%s: Connect with checksum support but no " + "ocd_cksum_types is set\n", + exp->exp_obd->obd_name); + RETURN(-EPROTO); + } + + CDEBUG(D_RPCTRACE, "%s: cli %s supports cksum type %x, return " + "%x\n", exp->exp_obd->obd_name, obd_export_nid2str(exp), + cksum_types, data->ocd_cksum_types); + } else { + /* This client does not support OBD_CONNECT_CKSUM + * fall back to CRC32 */ + CDEBUG(D_RPCTRACE, "%s: cli %s does not support " + "OBD_CONNECT_CKSUM, CRC32 will be used\n", + exp->exp_obd->obd_name, obd_export_nid2str(exp)); + } + + if (data->ocd_connect_flags & OBD_CONNECT_MAXBYTES) + data->ocd_maxbytes = ofd->ofd_dt_conf.ddp_maxbytes; + + RETURN(0); +} + +static int ofd_obd_reconnect(const struct lu_env *env, struct obd_export *exp, + struct obd_device *obd, struct obd_uuid *cluuid, + struct obd_connect_data *data, void *localdata) +{ + int rc; + + ENTRY; + + if (exp == NULL || obd == NULL || cluuid == NULL) + RETURN(-EINVAL); + + rc = lu_env_refill((struct lu_env *)env); + if (rc != 0) { + CERROR("Failure to refill session: '%d'\n", rc); + RETURN(rc); + } + + ofd_info_init(env, exp); + rc = ofd_parse_connect_data(env, exp, data); + + RETURN(rc); +} + +static int ofd_obd_connect(const struct lu_env *env, struct obd_export **_exp, + struct obd_device *obd, struct obd_uuid *cluuid, + struct obd_connect_data *data, void *localdata) +{ + struct obd_export *exp; + struct ofd_device *ofd; + struct lustre_handle conn = { 0 }; + int rc, group; + + ENTRY; + + if (_exp == NULL || obd == NULL || cluuid == NULL) + RETURN(-EINVAL); + + ofd = ofd_dev(obd->obd_lu_dev); + + rc = class_connect(&conn, obd, cluuid); + if (rc) + RETURN(rc); + + exp = class_conn2export(&conn); + LASSERT(exp != NULL); + + rc = lu_env_refill((struct lu_env *)env); + if (rc != 0) { + CERROR("Failure to refill session: '%d'\n", rc); + GOTO(out, rc); + } + + ofd_info_init(env, exp); + + rc = ofd_parse_connect_data(env, exp, data); + if (rc) + GOTO(out, rc); + + ofd_export_stats_init(ofd, exp, localdata); + group = data->ocd_group; + if (obd->obd_replayable) { + struct tg_export_data *ted = &exp->exp_target_data; + + memcpy(ted->ted_lcd->lcd_uuid, cluuid, + sizeof(ted->ted_lcd->lcd_uuid)); + rc = lut_client_new(env, exp); + if (rc != 0) + GOTO(out, rc); + } + if (group == 0) + GOTO(out, rc = 0); + + /* init new group */ + if (group > ofd->ofd_max_group) { + ofd->ofd_max_group = group; + rc = ofd_group_load(env, ofd, group); + } +out: + if (rc != 0) { + class_disconnect(exp); + *_exp = NULL; + } else { + *_exp = exp; + } + RETURN(rc); +} + +static int ofd_obd_disconnect(struct obd_export *exp) +{ + struct lu_env env; + int rc; + + ENTRY; + + LASSERT(exp); + class_export_get(exp); + + rc = server_disconnect_export(exp); + + rc = lu_env_init(&env, LCT_DT_THREAD); + if (rc) + RETURN(rc); + + /* Do not erase record for recoverable client. */ + if (exp->exp_obd->obd_replayable && + (!exp->exp_obd->obd_fail || exp->exp_failed)) + lut_client_del(&env, exp); + lu_env_fini(&env); + + class_export_put(exp); + RETURN(rc); +} + +static int ofd_init_export(struct obd_export *exp) +{ + int rc; + + cfs_spin_lock_init(&exp->exp_filter_data.fed_lock); + CFS_INIT_LIST_HEAD(&exp->exp_filter_data.fed_mod_list); + cfs_spin_lock(&exp->exp_lock); + exp->exp_connecting = 1; + cfs_spin_unlock(&exp->exp_lock); + + /* self-export doesn't need client data and ldlm initialization */ + if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid, + &exp->exp_client_uuid))) + return 0; + + rc = lut_client_alloc(exp); + if (rc == 0) + ldlm_init_export(exp); + if (rc) + CERROR("%s: Can't initialize export: rc %d\n", + exp->exp_obd->obd_name, rc); + return rc; +} + +static int ofd_destroy_export(struct obd_export *exp) +{ + if (exp->exp_filter_data.fed_pending) + CERROR("%s: cli %s/%p has %lu pending on destroyed export" + "\n", exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, + exp, exp->exp_filter_data.fed_pending); + + target_destroy_export(exp); + + if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid, + &exp->exp_client_uuid))) + return 0; + + ldlm_destroy_export(exp); + lut_client_free(exp); + + LASSERT(cfs_list_empty(&exp->exp_filter_data.fed_mod_list)); + return 0; +} + +int ofd_obd_postrecov(struct obd_device *obd) +{ + struct lu_env env; + struct lu_device *ldev = obd->obd_lu_dev; + int rc; + + ENTRY; + + rc = lu_env_init(&env, LCT_DT_THREAD); + if (rc) + RETURN(rc); + ofd_info_init(&env, obd->obd_self_export); + + rc = ldev->ld_ops->ldo_recovery_complete(&env, ldev); + lu_env_fini(&env); + RETURN(rc); +} static int ofd_obd_notify(struct obd_device *obd, struct obd_device *unused, enum obd_notify_event ev, void *data) @@ -62,6 +337,12 @@ static int ofd_obd_notify(struct obd_device *obd, struct obd_device *unused, } struct obd_ops ofd_obd_ops = { - .o_owner = THIS_MODULE, - .o_notify = ofd_obd_notify, + .o_owner = THIS_MODULE, + .o_connect = ofd_obd_connect, + .o_reconnect = ofd_obd_reconnect, + .o_disconnect = ofd_obd_disconnect, + .o_init_export = ofd_init_export, + .o_destroy_export = ofd_destroy_export, + .o_postrecov = ofd_obd_postrecov, + .o_notify = ofd_obd_notify, }; -- 1.8.3.1