From 8c3c81fb787ab0a0152ebf497d1b4aef480bb82f Mon Sep 17 00:00:00 2001 From: Ben Evans Date: Mon, 7 Aug 2017 14:41:03 -0500 Subject: [PATCH] LU-9855 obdclass: Code cleanup Remove uuid.c, and rewrite class_uuid_unparse Remove always-on #defines and #ifdefs Unwrap DECLARE_LU_VARS and remove #define Rewrite CL_ENV_INC and DEC Rewrite cs_page_inc/dec and cs_pagestate_inc/dec Unwrap lustre_(get|put)_group_info #defines Remove D_KUC #define Signed-off-by: Ben Evans Change-Id: I1ebaa47dbf749cedcf3d33028906a35caf7db694 Reviewed-on: https://review.whamcloud.com/28458 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Dmitry Eremin Reviewed-by: Patrick Farrell Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/include/obd_class.h | 43 +++++++++++------------- lustre/obdclass/Makefile.in | 2 +- lustre/obdclass/cl_object.c | 55 ++++++++++++++++--------------- lustre/obdclass/cl_page.c | 60 +++++++++++++++++++++------------- lustre/obdclass/class_obd.c | 5 --- lustre/obdclass/idmap.c | 14 ++------ lustre/obdclass/kernelcomm.c | 7 ++-- lustre/obdclass/uuid.c | 78 -------------------------------------------- 8 files changed, 93 insertions(+), 171 deletions(-) delete mode 100644 lustre/obdclass/uuid.c diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index 969912e..92d1273 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -573,18 +573,14 @@ static inline int obd_set_info_async(const struct lu_env *env, * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence, * obd_precleanup() and obd_cleanup() call both lu_device and obd operations. */ - -#define DECLARE_LU_VARS(ldt, d) \ - struct lu_device_type *ldt; \ - struct lu_device *d - static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg) { int rc; - DECLARE_LU_VARS(ldt, d); + struct lu_device_type *ldt = obd->obd_type->typ_lu; + struct lu_device *d; + ENTRY; - ldt = obd->obd_type->typ_lu; if (ldt != NULL) { struct lu_context session_ctx; struct lu_env env; @@ -618,12 +614,11 @@ static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg) static inline int obd_precleanup(struct obd_device *obd) { int rc; - DECLARE_LU_VARS(ldt, d); + struct lu_device_type *ldt = obd->obd_type->typ_lu; + struct lu_device *d = obd->obd_lu_dev; + ENTRY; - OBD_CHECK_DEV(obd); - ldt = obd->obd_type->typ_lu; - d = obd->obd_lu_dev; if (ldt != NULL && d != NULL) { struct lu_env env; @@ -643,13 +638,10 @@ static inline int obd_precleanup(struct obd_device *obd) static inline int obd_cleanup(struct obd_device *obd) { int rc; - DECLARE_LU_VARS(ldt, d); - ENTRY; - - OBD_CHECK_DEV(obd); + struct lu_device_type *ldt = obd->obd_type->typ_lu; + struct lu_device *d = obd->obd_lu_dev; - ldt = obd->obd_type->typ_lu; - d = obd->obd_lu_dev; + ENTRY; if (ldt != NULL && d != NULL) { struct lu_env env; @@ -692,14 +684,12 @@ static inline int obd_process_config(struct obd_device *obd, int datalen, void *data) { int rc; - DECLARE_LU_VARS(ldt, d); - ENTRY; + struct lu_device_type *ldt = obd->obd_type->typ_lu; + struct lu_device *d = obd->obd_lu_dev; - OBD_CHECK_DEV(obd); + ENTRY; obd->obd_process_conf = 1; - ldt = obd->obd_type->typ_lu; - d = obd->obd_lu_dev; if (ldt != NULL && d != NULL) { struct lu_env env; @@ -1698,9 +1688,14 @@ int lustre_check_exclusion(struct super_block *sb, char *svname); extern int obd_sysctl_init(void); extern void obd_sysctl_clean(void); -/* uuid.c */ typedef __u8 class_uuid_t[16]; -void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out); +static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out) +{ + snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-" + "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9], + uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]); +} /* lustre_peer.c */ int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index); diff --git a/lustre/obdclass/Makefile.in b/lustre/obdclass/Makefile.in index 3ab3240..10ba72a 100644 --- a/lustre/obdclass/Makefile.in +++ b/lustre/obdclass/Makefile.in @@ -6,7 +6,7 @@ obdclass-linux-objs := $(addprefix linux/,$(obdclass-linux-objs)) default: all obdclass-all-objs := llog.o llog_cat.o llog_obd.o llog_swab.o llog_osd.o -obdclass-all-objs += class_obd.o debug.o genops.o uuid.o llog_ioctl.o +obdclass-all-objs += class_obd.o debug.o genops.o llog_ioctl.o obdclass-all-objs += lprocfs_status.o lprocfs_counters.o obdclass-all-objs += lustre_handles.o lustre_peer.o local_storage.o obdclass-all-objs += statfs_pack.o obdo.o obd_config.o obd_mount.o diff --git a/lustre/obdclass/cl_object.c b/lustre/obdclass/cl_object.c index ddf97fc..7f651bc 100644 --- a/lustre/obdclass/cl_object.c +++ b/lustre/obdclass/cl_object.c @@ -595,17 +595,20 @@ struct cl_env { void *ce_debug; }; +static void cl_env_inc(enum cache_stats_item item) +{ #ifdef CONFIG_DEBUG_PAGESTATE_TRACKING -#define CL_ENV_INC(counter) atomic_inc(&cl_env_stats.cs_stats[CS_##counter]) - -#define CL_ENV_DEC(counter) do { \ - LASSERT(atomic_read(&cl_env_stats.cs_stats[CS_##counter]) > 0); \ - atomic_dec(&cl_env_stats.cs_stats[CS_##counter]); \ -} while (0) -#else -#define CL_ENV_INC(counter) -#define CL_ENV_DEC(counter) + atomic_inc(&cl_env_stats.cs_stats[item]); #endif +} + +static void cl_env_dec(enum cache_stats_item item) +{ +#ifdef CONFIG_DEBUG_PAGESTATE_TRACKING + LASSERT(atomic_read(&cl_env_stats.cs_stats[item]) > 0); + atomic_dec(&cl_env_stats.cs_stats[item]); +#endif +} static void cl_env_init0(struct cl_env *cle, void *debug) { @@ -615,7 +618,7 @@ static void cl_env_init0(struct cl_env *cle, void *debug) cle->ce_ref = 1; cle->ce_debug = debug; - CL_ENV_INC(busy); + cl_env_inc(CS_busy); } static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug) @@ -645,8 +648,8 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug) OBD_SLAB_FREE_PTR(cle, cl_env_kmem); env = ERR_PTR(rc); } else { - CL_ENV_INC(create); - CL_ENV_INC(total); + cl_env_inc(CS_create); + cl_env_inc(CS_total); } } else env = ERR_PTR(-ENOMEM); @@ -655,10 +658,10 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug) static void cl_env_fini(struct cl_env *cle) { - CL_ENV_DEC(total); - lu_context_fini(&cle->ce_lu.le_ctx); - lu_context_fini(&cle->ce_ses); - OBD_SLAB_FREE_PTR(cle, cl_env_kmem); + cl_env_dec(CS_total); + lu_context_fini(&cle->ce_lu.le_ctx); + lu_context_fini(&cle->ce_ses); + OBD_SLAB_FREE_PTR(cle, cl_env_kmem); } static struct lu_env *cl_env_obtain(void *debug) @@ -814,15 +817,15 @@ void cl_env_put(struct lu_env *env, __u16 *refcheck) if (--cle->ce_ref == 0) { int cpu = get_cpu(); - CL_ENV_DEC(busy); - cle->ce_debug = NULL; - cl_env_exit(cle); - /* - * Don't bother to take a lock here. - * - * Return environment to the cache only when it was allocated - * with the standard tags. - */ + cl_env_dec(CS_busy); + cle->ce_debug = NULL; + cl_env_exit(cle); + /* + * Don't bother to take a lock here. + * + * Return environment to the cache only when it was allocated + * with the standard tags. + */ if (cl_envs[cpu].cec_count < cl_envs_cached_max && (env->le_ctx.lc_tags & ~LCT_HAS_EXIT) == LCT_CL_THREAD && (env->le_ses->lc_tags & ~LCT_HAS_EXIT) == LCT_SESSION) { @@ -951,7 +954,7 @@ void cl_env_percpu_put(struct lu_env *env) cle->ce_ref--; LASSERT(cle->ce_ref == 0); - CL_ENV_DEC(busy); + cl_env_dec(CS_busy); cle->ce_debug = NULL; put_cpu(); diff --git a/lustre/obdclass/cl_page.c b/lustre/obdclass/cl_page.c index 74f9225..f3e0cc5 100644 --- a/lustre/obdclass/cl_page.c +++ b/lustre/obdclass/cl_page.c @@ -74,21 +74,37 @@ static void cl_page_delete0(const struct lu_env *env, struct cl_page *pg); #endif /* !CONFIG_LUSTRE_DEBUG_EXPENSIVE_CHECK */ /* Disable page statistic by default due to huge performance penalty. */ +static void cs_page_inc(const struct cl_object *obj, + enum cache_stats_item item) +{ #ifdef CONFIG_DEBUG_PAGESTATE_TRACKING -#define CS_PAGE_INC(o, item) \ - atomic_inc(&cl_object_site(o)->cs_pages.cs_stats[CS_##item]) -#define CS_PAGE_DEC(o, item) \ - atomic_dec(&cl_object_site(o)->cs_pages.cs_stats[CS_##item]) -#define CS_PAGESTATE_INC(o, state) \ - atomic_inc(&cl_object_site(o)->cs_pages_state[state]) -#define CS_PAGESTATE_DEC(o, state) \ - atomic_dec(&cl_object_site(o)->cs_pages_state[state]) -#else -#define CS_PAGE_INC(o, item) -#define CS_PAGE_DEC(o, item) -#define CS_PAGESTATE_INC(o, state) -#define CS_PAGESTATE_DEC(o, state) + atomic_inc(&cl_object_site(obj)->cs_pages.cs_stats[item]); #endif +} + +static void cs_page_dec(const struct cl_object *obj, + enum cache_stats_item item) +{ +#ifdef CONFIG_DEBUG_PAGESTATE_TRACKING + atomic_dec(&cl_object_site(obj)->cs_pages.cs_stats[item]); +#endif +} + +static void cs_pagestate_inc(const struct cl_object *obj, + enum cl_page_state state) +{ +#ifdef CONFIG_DEBUG_PAGESTATE_TRACKING + atomic_inc(&cl_object_site(obj)->cs_pages_state[state]); +#endif +} + +static void cs_pagestate_dec(const struct cl_object *obj, + enum cl_page_state state) +{ +#ifdef CONFIG_DEBUG_PAGESTATE_TRACKING + atomic_dec(&cl_object_site(obj)->cs_pages_state[state]); +#endif +} /** * Internal version of cl_page_get(). @@ -145,8 +161,8 @@ static void cl_page_free(const struct lu_env *env, struct cl_page *page) if (unlikely(slice->cpl_ops->cpo_fini != NULL)) slice->cpl_ops->cpo_fini(env, slice); } - CS_PAGE_DEC(obj, total); - CS_PAGESTATE_DEC(obj, page->cp_state); + cs_page_dec(obj, CS_total); + cs_pagestate_dec(obj, page->cp_state); lu_object_ref_del_at(&obj->co_lu, &page->cp_obj_ref, "cl_page", page); cl_object_put(env, obj); lu_ref_fini(&page->cp_reference); @@ -203,9 +219,9 @@ struct cl_page *cl_page_alloc(const struct lu_env *env, } } if (result == 0) { - CS_PAGE_INC(o, total); - CS_PAGE_INC(o, create); - CS_PAGESTATE_DEC(o, CPS_CACHED); + cs_page_inc(o, CS_total); + cs_page_inc(o, CS_create); + cs_pagestate_dec(o, CPS_CACHED); } } else { page = ERR_PTR(-ENOMEM); @@ -238,7 +254,7 @@ struct cl_page *cl_page_find(const struct lu_env *env, ENTRY; hdr = cl_object_header(o); - CS_PAGE_INC(o, lookup); + cs_page_inc(o, CS_lookup); CDEBUG(D_PAGE, "%lu@"DFID" %p %lx %d\n", idx, PFID(&hdr->coh_lu.loh_fid), vmpage, vmpage->private, type); @@ -258,7 +274,7 @@ struct cl_page *cl_page_find(const struct lu_env *env, */ page = cl_vmpage_page(vmpage, o); if (page != NULL) { - CS_PAGE_INC(o, hit); + cs_page_inc(o, CS_hit); RETURN(page); } } @@ -328,8 +344,8 @@ static void cl_page_state_set0(const struct lu_env *env, PASSERT(env, page, page->cp_state == old); PASSERT(env, page, equi(state == CPS_OWNED, page->cp_owner != NULL)); - CS_PAGESTATE_DEC(page->cp_obj, page->cp_state); - CS_PAGESTATE_INC(page->cp_obj, state); + cs_pagestate_dec(page->cp_obj, page->cp_state); + cs_pagestate_inc(page->cp_obj, state); cl_page_state_set_trust(page, state); EXIT; } diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index bbb9096..6648a0e 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -347,8 +347,6 @@ out: RETURN(err); } /* class_handle_ioctl */ -#define OBD_INIT_CHECK -#ifdef OBD_INIT_CHECK static int obd_init_checks(void) { __u64 u64val, div64val; @@ -414,9 +412,6 @@ static int obd_init_checks(void) return ret; } -#else -#define obd_init_checks() do {} while(0) -#endif static int __init obdclass_init(void) { diff --git a/lustre/obdclass/idmap.c b/lustre/obdclass/idmap.c index b45c6d6..021d0d6 100644 --- a/lustre/obdclass/idmap.c +++ b/lustre/obdclass/idmap.c @@ -47,15 +47,6 @@ #include #include -#define lustre_get_group_info(group_info) do { \ - atomic_inc(&(group_info)->usage); \ -} while (0) - -#define lustre_put_group_info(group_info) do { \ - if (atomic_dec_and_test(&(group_info)->usage)) \ - groups_free(group_info); \ -} while (0) - /* * groups_search() is copied from linux kernel! * A simple bsearch. @@ -162,9 +153,10 @@ int lustre_in_group_p(struct lu_ucred *mu, gid_t grp) if (!group_info) return 0; - lustre_get_group_info(group_info); + atomic_inc(&group_info->usage); rc = lustre_groups_search(group_info, grp); - lustre_put_group_info(group_info); + if (atomic_dec_and_test(&group_info->usage)) + groups_free(group_info); } return rc; } diff --git a/lustre/obdclass/kernelcomm.c b/lustre/obdclass/kernelcomm.c index 9e4b84c..ccd982c 100644 --- a/lustre/obdclass/kernelcomm.c +++ b/lustre/obdclass/kernelcomm.c @@ -35,7 +35,6 @@ */ #define DEBUG_SUBSYSTEM S_CLASS -#define D_KUC D_OTHER #include #include @@ -88,7 +87,7 @@ int libcfs_kkuc_msg_put(struct file *filp, void *payload) if (rc < 0) CWARN("message send failed (%d)\n", rc); else - CDEBUG(D_KUC, "Sent message rc=%d, fp=%p\n", rc, filp); + CDEBUG(D_HSM, "Sent message rc=%d, fp=%p\n", rc, filp); return rc; } @@ -155,7 +154,7 @@ int libcfs_kkuc_group_add(struct file *filp, int uid, int group, list_add(®->kr_chain, &kkuc_groups[group]); up_write(&kg_sem); - CDEBUG(D_KUC, "Added uid=%d fp=%p to group %d\n", uid, filp, group); + CDEBUG(D_HSM, "Added uid=%d fp=%p to group %d\n", uid, filp, group); return 0; } @@ -186,7 +185,7 @@ int libcfs_kkuc_group_rem(int uid, int group) list_for_each_entry_safe(reg, next, &kkuc_groups[group], kr_chain) { if ((uid == 0) || (uid == reg->kr_uid)) { list_del(®->kr_chain); - CDEBUG(D_KUC, "Removed uid=%d fp=%p from group %d\n", + CDEBUG(D_HSM, "Removed uid=%d fp=%p from group %d\n", reg->kr_uid, reg->kr_fp, group); if (reg->kr_fp != NULL) fput(reg->kr_fp); diff --git a/lustre/obdclass/uuid.c b/lustre/obdclass/uuid.c deleted file mode 100644 index cc00926..0000000 --- a/lustre/obdclass/uuid.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * GPL HEADER START - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 only, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License version 2 for more details (a copy is included - * in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU General Public License - * version 2 along with this program; If not, see - * http://www.gnu.org/licenses/gpl-2.0.html - * - * GPL HEADER END - */ -/* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. - * Use is subject to license terms. - * - * Copyright (c) 2014, Intel Corporation. - */ -/* - * This file is part of Lustre, http://www.lustre.org/ - * Lustre is a trademark of Sun Microsystems, Inc. - * - * lustre/obdclass/uuid.c - * - * Public include file for the UUID library - */ - -#define DEBUG_SUBSYSTEM S_CLASS - -#include -#include -#include - -static inline size_t consume(size_t nob, __u8 **ptr) -{ - size_t value; - - LASSERT(nob <= sizeof(value)); - - for (value = 0; nob > 0; --nob) - value = (value << 8) | *((*ptr)++); - return value; -} - -#define CONSUME(val, ptr) (val) = consume(sizeof(val), (ptr)) - -static void uuid_unpack(class_uuid_t in, __u16 *uu, size_t nr) -{ - __u8 *ptr = in; - - LASSERT(nr * sizeof(*uu) == sizeof(class_uuid_t)); - - while (nr-- > 0) - CONSUME(uu[nr], &ptr); -} - -void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out) -{ - /* uu as an array of __u16's */ - __u16 uuid[sizeof(class_uuid_t) / sizeof(__u16)]; - - CLASSERT(ARRAY_SIZE(uuid) == 8); - - uuid_unpack(uu, uuid, ARRAY_SIZE(uuid)); - sprintf(out->uuid, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], uuid[6], uuid[7]); -} -EXPORT_SYMBOL(class_uuid_unparse); -- 1.8.3.1