X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Finclude%2Flu_ref.h;h=c7366c0481320efedf1dcced051dd7cdf8c9d36c;hp=41259301d7021c2b176e319bf5dd7293c89029e8;hb=7c99f67d9d39e8a037e830cf08a9df305e6d8da2;hpb=c0b9c99922da2f059d145e92f9636f37d1fea49e diff --git a/lustre/include/lu_ref.h b/lustre/include/lu_ref.h index 4125930..c7366c0 100644 --- a/lustre/include/lu_ref.h +++ b/lustre/include/lu_ref.h @@ -1,9 +1,9 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. +/* + * 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. @@ -26,7 +26,7 @@ #ifndef __LUSTRE_LU_REF_H #define __LUSTRE_LU_REF_H -#include +#include /** \defgroup lu_ref lu_ref * @@ -69,12 +69,12 @@ * * // current thread acquired a temporary reference to foo. * foo_get(foo); - * lu_ref_add(&foo->reference, __FUNCTION__, cfs_current()); + * lu_ref_add(&foo->reference, __FUNCTION__, current); * * ... * * // temporary reference is released. - * lu_ref_del(&foo->reference, __FUNCTION__, cfs_current()); + * lu_ref_del(&foo->reference, __FUNCTION__, current); * foo_put(foo); * \endcode * @@ -109,9 +109,6 @@ #ifdef USE_LU_REF -/* An incomplete type (defined locally in lu_ref.c) */ -struct lu_ref_link; - /** * Data-structure to keep track of references to a given object. This is used * for debugging. @@ -120,31 +117,81 @@ struct lu_ref_link; * etc.) refer to. */ struct lu_ref { - spinlock_t lf_guard; - struct list_head lf_list; - int lf_failed; + /** + * 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; }; -void lu_ref_init(struct lu_ref *ref); -void lu_ref_fini(struct lu_ref *ref); - -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); +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__) + +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 /* !USE_LU_REF */ -struct lu_ref {}; +struct lu_ref { +}; + +struct lu_ref_link { +}; static inline void lu_ref_init(struct lu_ref *ref) { @@ -154,18 +201,23 @@ 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) { - 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_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, @@ -196,6 +248,10 @@ static inline void lu_ref_global_fini(void) static inline void lu_ref_print(const struct lu_ref *ref) { } + +static inline void lu_ref_print_all(void) +{ +} #endif /* USE_LU_REF */ /** @} lu */