X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Finclude%2Flu_ref.h;h=7b368c297ff13d15ea3b51dfb95d4f6dd45600a0;hb=ab0a6a9a066a7b175ff48b9b679ba0fb59416f9b;hp=571278a708bf79a2bba767e8a561e3e9ba5215eb;hpb=0f8dca08a4f68cba82c2c822998ecc309d3b7aaf;p=fs%2Flustre-release.git diff --git a/lustre/include/lu_ref.h b/lustre/include/lu_ref.h index 571278a..7b368c2 100644 --- a/lustre/include/lu_ref.h +++ b/lustre/include/lu_ref.h @@ -1,9 +1,10 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +// SPDX-License-Identifier: GPL-2.0 +/* * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * + * Copyright (c) 2012, 2013, Intel Corporation. + * * Author: Nikita Danilov * * This file is part of Lustre, http://www.lustre.org. @@ -17,16 +18,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * */ #ifndef __LUSTRE_LU_REF_H #define __LUSTRE_LU_REF_H -#include +#include /** \defgroup lu_ref lu_ref * @@ -36,11 +33,11 @@ * who acquired references to instance of struct foo, add lu_ref field to it: * * \code - * struct foo { - * atomic_t foo_refcount; - * struct lu_ref foo_reference; - * ... - * }; + * struct foo { + * atomic_t foo_refcount; + * struct lu_ref foo_reference; + * ... + * }; * \endcode * * foo::foo_reference has to be initialized by calling @@ -54,28 +51,28 @@ * usages are: * * \code - * struct bar *bar; + * struct bar *bar; * - * // bar owns a reference to foo. - * bar->bar_foo = foo_get(foo); - * lu_ref_add(&foo->foo_reference, "bar", bar); + * // bar owns a reference to foo. + * bar->bar_foo = foo_get(foo); + * lu_ref_add(&foo->foo_reference, "bar", bar); * - * ... + * ... * - * // reference from bar to foo is released. - * lu_ref_del(&foo->foo_reference, "bar", bar); - * foo_put(bar->bar_foo); + * // reference from bar to foo is released. + * lu_ref_del(&foo->foo_reference, "bar", bar); + * foo_put(bar->bar_foo); * * - * // current thread acquired a temporary reference to foo. - * foo_get(foo); - * lu_ref_add(&foo->reference, __FUNCTION__, cfs_current()); + * // current thread acquired a temporary reference to foo. + * foo_get(foo); + * lu_ref_add(&foo->reference, __func__, current); * - * ... + * ... * - * // temporary reference is released. - * lu_ref_del(&foo->reference, __FUNCTION__, cfs_current()); - * foo_put(foo); + * // temporary reference is released. + * lu_ref_del(&foo->reference, __func__, current); + * foo_put(foo); * \endcode * * \e Et \e cetera. Often it makes sense to include lu_ref_add() and @@ -91,15 +88,15 @@ * lu_ref_del_at(): * * \code - * // There is a large number of bar's for a single foo. - * bar->bar_foo = foo_get(foo); - * bar->bar_foo_ref = lu_ref_add(&foo->foo_reference, "bar", bar); + * // There is a large number of bar's for a single foo. + * bar->bar_foo = foo_get(foo); + * bar->bar_foo_ref = lu_ref_add(&foo->foo_reference, "bar", bar); * - * ... + * ... * - * // reference from bar to foo is released. - * lu_ref_del_at(&foo->foo_reference, bar->bar_foo_ref, "bar", bar); - * foo_put(bar->bar_foo); + * // reference from bar to foo is released. + * lu_ref_del_at(&foo->foo_reference, bar->bar_foo_ref, "bar", bar); + * foo_put(bar->bar_foo); * \endcode * * lu_ref interface degrades gracefully in case of memory shortages. @@ -107,10 +104,7 @@ * @{ */ -#ifdef USE_LU_REF - -/* An incomplete type (defined locally in lu_ref.c) */ -struct lu_ref_link; +#ifdef CONFIG_LUSTRE_DEBUG_LU_REF /** * Data-structure to keep track of references to a given object. This is used @@ -120,62 +114,81 @@ struct lu_ref_link; * etc.) refer to. */ struct lu_ref { - /** - * Spin-lock protecting lu_ref::lf_list. - */ - cfs_spinlock_t lf_guard; - /** - * List of all outstanding references (each represented by struct - * lu_ref_link), pointing to this object. - */ - cfs_list_t lf_list; - /** - * # of links. - */ - short lf_refs; - /** - * Flag set when lu_ref_add() failed to allocate lu_ref_link. It is - * used to mask spurious failure of the following lu_ref_del(). - */ - short lf_failed; - /** - * flags - attribute for the lu_ref, for pad and future use. - */ - short lf_flags; - /** - * Where was I initialized? - */ - short lf_line; - const char *lf_func; - /** - * Linkage into a global list of all lu_ref's (lu_ref_refs). - */ - cfs_list_t lf_linkage; + /** + * Spin-lock protecting lu_ref::lf_list. + */ + spinlock_t lf_guard; + /** + * List of all outstanding references (each represented by struct + * lu_ref_link), pointing to this object. + */ + struct list_head lf_list; + /** + * # of links. + */ + short lf_refs; + /** + * Flag set when lu_ref_add() failed to allocate lu_ref_link. It is + * used to mask spurious failure of the following lu_ref_del(). + */ + short lf_failed; + /** + * flags - attribute for the lu_ref, for pad and future use. + */ + short lf_flags; + /** + * Where was I initialized? + */ + short lf_line; + const char *lf_func; + /** + * Linkage into a global list of all lu_ref's (lu_ref_refs). + */ + struct list_head lf_linkage; +}; + +struct lu_ref_link { + struct lu_ref *ll_ref; + struct list_head ll_linkage; + const char *ll_scope; + const void *ll_source; }; void lu_ref_init_loc(struct lu_ref *ref, const char *func, const int line); -void lu_ref_fini (struct lu_ref *ref); -#define lu_ref_init(ref) lu_ref_init_loc(ref, __FUNCTION__, __LINE__) - -struct lu_ref_link *lu_ref_add (struct lu_ref *ref, const char *scope, - const void *source); -struct lu_ref_link *lu_ref_add_atomic(struct lu_ref *ref, const char *scope, - const void *source); -void lu_ref_del (struct lu_ref *ref, const char *scope, - const void *source); -void lu_ref_set_at (struct lu_ref *ref, - struct lu_ref_link *link, - const char *scope, const void *source0, - const void *source1); -void lu_ref_del_at (struct lu_ref *ref, - struct lu_ref_link *link, - const char *scope, const void *source); -void lu_ref_print (const struct lu_ref *ref); -void lu_ref_print_all (void); - -#else /* !USE_LU_REF */ - -struct lu_ref {}; +void lu_ref_fini(struct lu_ref *ref); +#define lu_ref_init(ref) lu_ref_init_loc(ref, __func__, __LINE__) + +void lu_ref_add(struct lu_ref *ref, const char *scope, const void *source); + +void lu_ref_add_atomic(struct lu_ref *ref, const char *scope, + const void *source); + +void lu_ref_add_at(struct lu_ref *ref, struct lu_ref_link *link, + const char *scope, const void *source); + +void lu_ref_del(struct lu_ref *ref, const char *scope, const void *source); + +void lu_ref_set_at(struct lu_ref *ref, struct lu_ref_link *link, + const char *scope, const void *source0, const void *source1); + +void lu_ref_del_at(struct lu_ref *ref, struct lu_ref_link *link, + const char *scope, const void *source); + +void lu_ref_print(const struct lu_ref *ref); + +void lu_ref_print_all(void); + +int lu_ref_global_init(void); + +void lu_ref_global_fini(void); + +#else /* !CONFIG_LUSTRE_DEBUG_LU_REF */ + +struct lu_ref { +}; + +struct lu_ref_link { +}; static inline void lu_ref_init(struct lu_ref *ref) { @@ -185,39 +198,44 @@ static inline void lu_ref_fini(struct lu_ref *ref) { } -static inline struct lu_ref_link *lu_ref_add(struct lu_ref *ref, - const char *scope, - const void *source) +static inline void lu_ref_add(struct lu_ref *ref, + const char *scope, + const void *source) +{ +} + +static inline void lu_ref_add_atomic(struct lu_ref *ref, + const char *scope, + const void *source) { - return NULL; } -static inline struct lu_ref_link *lu_ref_add_atomic(struct lu_ref *ref, - const char *scope, - const void *source) +static inline void lu_ref_add_at(struct lu_ref *ref, + struct lu_ref_link *link, + const char *scope, + const void *source) { - return NULL; } static inline void lu_ref_del(struct lu_ref *ref, const char *scope, - const void *source) + const void *source) { } static inline void lu_ref_set_at(struct lu_ref *ref, struct lu_ref_link *link, - const char *scope, const void *source0, - const void *source1) + const char *scope, const void *source0, + const void *source1) { } static inline void lu_ref_del_at(struct lu_ref *ref, struct lu_ref_link *link, - const char *scope, const void *source) + const char *scope, const void *source) { } static inline int lu_ref_global_init(void) { - return 0; + return 0; } static inline void lu_ref_global_fini(void) @@ -231,7 +249,7 @@ static inline void lu_ref_print(const struct lu_ref *ref) static inline void lu_ref_print_all(void) { } -#endif /* USE_LU_REF */ +#endif /* CONFIG_LUSTRE_DEBUG_LU_REF */ /** @} lu */