From: Andreas Dilger Date: Thu, 3 Dec 2020 09:40:35 +0000 (-0700) Subject: LU-14178 ldlm: return error from ldlm_namespace_new() X-Git-Tag: 2.14.51~142 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=e9c3b89bdacdb90332e386ae5ddff03cd8e977df LU-14178 ldlm: return error from ldlm_namespace_new() Return the underlying error in ldlm_namespace_new() from ldlm_namespace_sysfs_register() to the caller instead of NULL. Otherwise, the callers convert the NULL to -ENOMEM and this is incorrectly reported as an allocation error to the user. sysfs: cannot create duplicate filename '/fs/lustre/ldlm/namespaces/lustre-OST0002-osc-ffff89f33be70000' mount.lustre: mount mgs:/lfs at /lfs failed: Cannot allocate memory Change ldlm_namespace_new() to return errors via PTR_ERR() and change the callers to use IS_ERR(). Fix associated CERROR() messages to follow proper code style. Signed-off-by: Andreas Dilger Change-Id: I7d590c7242399549b32b1c4189e46ff8748c8096 Reviewed-on: https://review.whamcloud.com/40851 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Alex Zhuravlev Reviewed-by: James Simmons Reviewed-by: Neil Brown Reviewed-by: Oleg Drokin --- diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index cc7c81a..3626bda 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -578,10 +578,12 @@ int client_obd_setup(struct obd_device *obd, struct lustre_cfg *lcfg) LDLM_NAMESPACE_CLIENT, LDLM_NAMESPACE_GREEDY, ns_type); - if (obd->obd_namespace == NULL) { - CERROR("Unable to create client namespace - %s\n", - obd->obd_name); - GOTO(err_import, rc = -ENOMEM); + if (IS_ERR(obd->obd_namespace)) { + rc = PTR_ERR(obd->obd_namespace); + CERROR("%s: unable to create client namespace: rc = %d\n", + obd->obd_name, rc); + obd->obd_namespace = NULL; + GOTO(err_import, rc); } RETURN(rc); @@ -595,8 +597,8 @@ err: OBD_FREE(cli->cl_mod_tag_bitmap, BITS_TO_LONGS(OBD_MAX_RIF_MAX) * sizeof(long)); cli->cl_mod_tag_bitmap = NULL; - RETURN(rc); + RETURN(rc); } EXPORT_SYMBOL(client_obd_setup); diff --git a/lustre/ldlm/ldlm_resource.c b/lustre/ldlm/ldlm_resource.c index 0f4c9d4..1deddc9 100644 --- a/lustre/ldlm/ldlm_resource.c +++ b/lustre/ldlm/ldlm_resource.c @@ -896,19 +896,21 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, rc = ldlm_get_ref(); if (rc) { - CERROR("ldlm_get_ref failed: %d\n", rc); - RETURN(NULL); + CERROR("%s: ldlm_get_ref failed: rc = %d\n", name, rc); + RETURN(ERR_PTR(rc)); } if (ns_type >= ARRAY_SIZE(ldlm_ns_hash_defs) || ldlm_ns_hash_defs[ns_type].nsd_bkt_bits == 0) { - CERROR("Unknown type %d for ns %s\n", ns_type, name); - GOTO(out_ref, NULL); + rc = -EINVAL; + CERROR("%s: unknown namespace type %d: rc = %d\n", + name, ns_type, rc); + GOTO(out_ref, rc); } OBD_ALLOC_PTR(ns); if (!ns) - GOTO(out_ref, NULL); + GOTO(out_ref, rc = -ENOMEM); ns->ns_rs_hash = cfs_hash_create(name, ldlm_ns_hash_defs[ns_type].nsd_all_bits, @@ -922,15 +924,15 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, CFS_HASH_BIGNAME | CFS_HASH_SPIN_BKTLOCK | CFS_HASH_NO_ITEMREF); - if (ns->ns_rs_hash == NULL) - GOTO(out_ns, NULL); + if (!ns->ns_rs_hash) + GOTO(out_ns, rc = -ENOMEM); ns->ns_bucket_bits = ldlm_ns_hash_defs[ns_type].nsd_all_bits - ldlm_ns_hash_defs[ns_type].nsd_bkt_bits; OBD_ALLOC_PTR_ARRAY_LARGE(ns->ns_rs_buckets, 1 << ns->ns_bucket_bits); if (!ns->ns_rs_buckets) - goto out_hash; + GOTO(out_hash, rc = -ENOMEM); for (idx = 0; idx < (1 << ns->ns_bucket_bits); idx++) { struct ldlm_ns_bucket *nsb = &ns->ns_rs_buckets[idx]; @@ -946,7 +948,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, ns->ns_client = client; ns->ns_name = kstrdup(name, GFP_KERNEL); if (!ns->ns_name) - goto out_hash; + GOTO(out_hash, rc = -ENOMEM); INIT_LIST_HEAD(&ns->ns_list_chain); INIT_LIST_HEAD(&ns->ns_unused_list); @@ -976,20 +978,20 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, rc = ldlm_namespace_sysfs_register(ns); if (rc) { - CERROR("Can't initialize ns sysfs, rc %d\n", rc); + CERROR("%s: cannot initialize ns sysfs: rc = %d\n", name, rc); GOTO(out_hash, rc); } rc = ldlm_namespace_debugfs_register(ns); if (rc) { - CERROR("Can't initialize ns proc, rc %d\n", rc); + CERROR("%s: cannot initialize ns proc: rc = %d\n", name, rc); GOTO(out_sysfs, rc); } idx = ldlm_namespace_nr_read(client); rc = ldlm_pool_init(&ns->ns_pool, ns, idx, client); if (rc) { - CERROR("Can't initialize lock pool, rc %d\n", rc); + CERROR("%s: cannot initialize lock pool, rc = %d\n", name, rc); GOTO(out_proc, rc); } @@ -1008,7 +1010,7 @@ out_ns: OBD_FREE_PTR(ns); out_ref: ldlm_put_ref(); - RETURN(NULL); + RETURN(ERR_PTR(rc)); } EXPORT_SYMBOL(ldlm_namespace_new); diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index ced2362..598aec3 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -5755,8 +5755,13 @@ static int mdt_init0(const struct lu_env *env, struct mdt_device *m, LDLM_NAMESPACE_SERVER, LDLM_NAMESPACE_GREEDY, LDLM_NS_TYPE_MDT); - if (m->mdt_namespace == NULL) - GOTO(err_fini_seq, rc = -ENOMEM); + if (IS_ERR(m->mdt_namespace)) { + rc = PTR_ERR(m->mdt_namespace); + CERROR("%s: unable to create server namespace: rc = %d\n", + obd->obd_name, rc); + m->mdt_namespace = NULL; + GOTO(err_fini_seq, rc); + } m->mdt_namespace->ns_lvbp = m; m->mdt_namespace->ns_lvbo = &mdt_lvbo; diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 9da8271..b5ddf09 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -1282,8 +1282,13 @@ static int mgs_init0(const struct lu_env *env, struct mgs_device *mgs, LDLM_NAMESPACE_SERVER, LDLM_NAMESPACE_MODEST, LDLM_NS_TYPE_MGT); - if (obd->obd_namespace == NULL) - GOTO(err_ops, rc = -ENOMEM); + if (IS_ERR(obd->obd_namespace)) { + rc = PTR_ERR(obd->obd_namespace); + CERROR("%s: unable to create server namespace: rc = %d\n", + obd->obd_name, rc); + obd->obd_namespace = NULL; + GOTO(err_ops, rc); + } /* No recovery for MGCs */ obd->obd_replayable = 0; diff --git a/lustre/obdecho/echo.c b/lustre/obdecho/echo.c index a0675c5..d866b68 100644 --- a/lustre/obdecho/echo.c +++ b/lustre/obdecho/echo.c @@ -768,8 +768,13 @@ static int echo_srv_init0(const struct lu_env *env, LDLM_NAMESPACE_SERVER, LDLM_NAMESPACE_MODEST, LDLM_NS_TYPE_OST); - if (!obd->obd_namespace) - RETURN(-ENOMEM); + if (IS_ERR(obd->obd_namespace)) { + rc = PTR_ERR(obd->obd_namespace); + CERROR("%s: unable to create server namespace: rc = %d\n", + obd->obd_name, rc); + obd->obd_namespace = NULL; + RETURN(rc); + } obd->obd_vars = lprocfs_echo_obd_vars; if (!lprocfs_obd_setup(obd, true) && diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index 73364a0..63c6d1e 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -3008,8 +3008,13 @@ static int ofd_init0(const struct lu_env *env, struct ofd_device *m, LDLM_NAMESPACE_SERVER, LDLM_NAMESPACE_GREEDY, LDLM_NS_TYPE_OST); - if (m->ofd_namespace == NULL) - GOTO(err_fini_stack, rc = -ENOMEM); + if (IS_ERR(m->ofd_namespace)) { + rc = PTR_ERR(m->ofd_namespace); + CERROR("%s: unable to create server namespace: rc = %d\n", + obd->obd_name, rc); + m->ofd_namespace = NULL; + GOTO(err_fini_stack, rc); + } /* set obd_namespace for compatibility with old code */ obd->obd_namespace = m->ofd_namespace; ldlm_register_intent(m->ofd_namespace, ofd_intent_policy);