1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef __LUSTRE_LU_OBJECT_H
38 #define __LUSTRE_LU_OBJECT_H
45 #include <lustre/lustre_idl.h>
47 #include <libcfs/libcfs.h>
52 struct proc_dir_entry;
57 * lu_* data-types represent server-side entities shared by data and meta-data
62 * -# support for layering.
64 * Server side object is split into layers, one per device in the
65 * corresponding device stack. Individual layer is represented by struct
66 * lu_object. Compound layered object --- by struct lu_object_header. Most
67 * interface functions take lu_object as an argument and operate on the
68 * whole compound object. This decision was made due to the following
71 * - it's envisaged that lu_object will be used much more often than
74 * - we want lower (non-top) layers to be able to initiate operations
75 * on the whole object.
77 * Generic code supports layering more complex than simple stacking, e.g.,
78 * it is possible that at some layer object "spawns" multiple sub-objects
81 * -# fid-based identification.
83 * Compound object is uniquely identified by its fid. Objects are indexed
84 * by their fids (hash table is used for index).
86 * -# caching and life-cycle management.
88 * Object's life-time is controlled by reference counting. When reference
89 * count drops to 0, object is returned to cache. Cached objects still
90 * retain their identity (i.e., fid), and can be recovered from cache.
92 * Objects are kept in the global LRU list, and lu_site_purge() function
93 * can be used to reclaim given number of unused objects from the tail of
96 * -# avoiding recursion.
98 * Generic code tries to replace recursion through layers by iterations
99 * where possible. Additionally to the end of reducing stack consumption,
100 * data, when practically possible, are allocated through lu_context_key
101 * interface rather than on stack.
108 struct lu_object_header;
113 * Operations common for data and meta-data devices.
115 struct lu_device_operations {
117 * Allocate object for the given device (without lower-layer
118 * parts). This is called by lu_object_operations::loo_object_init()
119 * from the parent layer, and should setup at least lu_object::lo_dev
120 * and lu_object::lo_ops fields of resulting lu_object.
122 * Object creation protocol.
124 * Due to design goal of avoiding recursion, object creation (see
125 * lu_object_alloc()) is somewhat involved:
127 * - first, lu_device_operations::ldo_object_alloc() method of the
128 * top-level device in the stack is called. It should allocate top
129 * level object (including lu_object_header), but without any
130 * lower-layer sub-object(s).
132 * - then lu_object_alloc() sets fid in the header of newly created
135 * - then lu_object_operations::loo_object_init() is called. It has
136 * to allocate lower-layer object(s). To do this,
137 * lu_object_operations::loo_object_init() calls ldo_object_alloc()
138 * of the lower-layer device(s).
140 * - for all new objects allocated by
141 * lu_object_operations::loo_object_init() (and inserted into object
142 * stack), lu_object_operations::loo_object_init() is called again
143 * repeatedly, until no new objects are created.
145 * \post ergo(!IS_ERR(result), result->lo_dev == d &&
146 * result->lo_ops != NULL);
148 struct lu_object *(*ldo_object_alloc)(const struct lu_env *env,
149 const struct lu_object_header *h,
150 struct lu_device *d);
152 * process config specific for device.
154 int (*ldo_process_config)(const struct lu_env *env,
155 struct lu_device *, struct lustre_cfg *);
156 int (*ldo_recovery_complete)(const struct lu_env *,
162 * Type of "printer" function used by lu_object_operations::loo_object_print()
165 * Printer function is needed to provide some flexibility in (semi-)debugging
166 * output: possible implementations: printk, CDEBUG, sysfs/seq_file
168 typedef int (*lu_printer_t)(const struct lu_env *env,
169 void *cookie, const char *format, ...)
170 __attribute__ ((format (printf, 3, 4)));
173 * Operations specific for particular lu_object.
175 struct lu_object_operations {
178 * Allocate lower-layer parts of the object by calling
179 * lu_device_operations::ldo_object_alloc() of the corresponding
182 * This method is called once for each object inserted into object
183 * stack. It's responsibility of this method to insert lower-layer
184 * object(s) it create into appropriate places of object stack.
186 int (*loo_object_init)(const struct lu_env *env,
188 const struct lu_object_conf *conf);
190 * Called (in top-to-bottom order) during object allocation after all
191 * layers were allocated and initialized. Can be used to perform
192 * initialization depending on lower layers.
194 int (*loo_object_start)(const struct lu_env *env,
195 struct lu_object *o);
197 * Called before lu_object_operations::loo_object_free() to signal
198 * that object is being destroyed. Dual to
199 * lu_object_operations::loo_object_init().
201 void (*loo_object_delete)(const struct lu_env *env,
202 struct lu_object *o);
204 * Dual to lu_device_operations::ldo_object_alloc(). Called when
205 * object is removed from memory.
207 void (*loo_object_free)(const struct lu_env *env,
208 struct lu_object *o);
210 * Called when last active reference to the object is released (and
211 * object returns to the cache). This method is optional.
213 void (*loo_object_release)(const struct lu_env *env,
214 struct lu_object *o);
216 * Optional debugging helper. Print given object.
218 int (*loo_object_print)(const struct lu_env *env, void *cookie,
219 lu_printer_t p, const struct lu_object *o);
221 * Optional debugging method. Returns true iff method is internally
224 int (*loo_object_invariant)(const struct lu_object *o);
230 struct lu_device_type;
233 * Device: a layer in the server side abstraction stacking.
237 * reference count. This is incremented, in particular, on each object
238 * created at this layer.
240 * \todo XXX which means that atomic_t is probably too small.
244 * Pointer to device type. Never modified once set.
246 struct lu_device_type *ld_type;
248 * Operation vector for this device.
250 const struct lu_device_operations *ld_ops;
252 * Stack this device belongs to.
254 struct lu_site *ld_site;
255 struct proc_dir_entry *ld_proc_entry;
257 /** \todo XXX: temporary back pointer into obd. */
258 struct obd_device *ld_obd;
260 * A list of references to this object, for debugging.
262 struct lu_ref ld_reference;
265 struct lu_device_type_operations;
268 * Tag bits for device type. They are used to distinguish certain groups of
272 /** this is meta-data device */
273 LU_DEVICE_MD = (1 << 0),
274 /** this is data device */
275 LU_DEVICE_DT = (1 << 1),
276 /** data device in the client stack */
277 LU_DEVICE_CL = (1 << 2)
283 struct lu_device_type {
285 * Tag bits. Taken from enum lu_device_tag. Never modified once set.
289 * Name of this class. Unique system-wide. Never modified once set.
293 * Operations for this type.
295 const struct lu_device_type_operations *ldt_ops;
297 * \todo XXX: temporary pointer to associated obd_type.
299 struct obd_type *ldt_obd_type;
301 * \todo XXX: temporary: context tags used by obd_*() calls.
305 * Number of existing device type instances.
307 unsigned ldt_device_nr;
309 * Linkage into a global list of all device types.
311 * \see lu_device_types.
313 struct list_head ldt_linkage;
317 * Operations on a device type.
319 struct lu_device_type_operations {
321 * Allocate new device.
323 struct lu_device *(*ldto_device_alloc)(const struct lu_env *env,
324 struct lu_device_type *t,
325 struct lustre_cfg *lcfg);
327 * Free device. Dual to
328 * lu_device_type_operations::ldto_device_alloc(). Returns pointer to
329 * the next device in the stack.
331 struct lu_device *(*ldto_device_free)(const struct lu_env *,
335 * Initialize the devices after allocation
337 int (*ldto_device_init)(const struct lu_env *env,
338 struct lu_device *, const char *,
341 * Finalize device. Dual to
342 * lu_device_type_operations::ldto_device_init(). Returns pointer to
343 * the next device in the stack.
345 struct lu_device *(*ldto_device_fini)(const struct lu_env *env,
348 * Initialize device type. This is called on module load.
350 int (*ldto_init)(struct lu_device_type *t);
352 * Finalize device type. Dual to
353 * lu_device_type_operations::ldto_init(). Called on module unload.
355 void (*ldto_fini)(struct lu_device_type *t);
357 * Called when the first device is created.
359 void (*ldto_start)(struct lu_device_type *t);
361 * Called when number of devices drops to 0.
363 void (*ldto_stop)(struct lu_device_type *t);
367 * Flags for the object layers.
369 enum lu_object_flags {
371 * this flags is set if lu_object_operations::loo_object_init() has
372 * been called for this layer. Used by lu_object_alloc().
374 LU_OBJECT_ALLOCATED = (1 << 0)
378 * Common object attributes.
383 /** modification time in seconds since Epoch */
385 /** access time in seconds since Epoch */
387 /** change time in seconds since Epoch */
389 /** 512-byte blocks allocated to object */
391 /** permission bits and file type */
399 /** number of persistent references to this object */
401 /** blk bits of the object*/
403 /** blk size of the object*/
415 /** Bit-mask of valid attributes */
429 LA_BLKSIZE = 1 << 12,
433 * Layer in the layered object.
437 * Header for this object.
439 struct lu_object_header *lo_header;
441 * Device for this layer.
443 struct lu_device *lo_dev;
445 * Operations for this object.
447 struct lu_object_operations *lo_ops;
449 * Linkage into list of all layers.
451 struct list_head lo_linkage;
453 * Depth. Top level layer depth is 0.
457 * Flags from enum lu_object_flags.
459 unsigned long lo_flags;
462 enum lu_object_header_flags {
464 * Don't keep this object in cache. Object will be destroyed as soon
465 * as last reference to it is released. This flag cannot be cleared
468 LU_OBJECT_HEARD_BANSHEE = 0
471 enum lu_object_header_attr {
472 LOHA_EXISTS = 1 << 0,
473 LOHA_REMOTE = 1 << 1,
475 * UNIX file type is stored in S_IFMT bits.
477 LOHA_FT_START = 1 << 12, /* S_IFIFO */
478 LOHA_FT_END = 1 << 15, /* S_IFREG */
482 * "Compound" object, consisting of multiple layers.
484 * Compound object with given fid is unique with given lu_site.
486 * Note, that object does *not* necessary correspond to the real object in the
487 * persistent storage: object is an anchor for locking and method calling, so
488 * it is created for things like not-yet-existing child created by mkdir or
489 * create calls. lu_object_operations::loo_exists() can be used to check
490 * whether object is backed by persistent storage entity.
492 struct lu_object_header {
494 * Object flags from enum lu_object_header_flags. Set and checked
497 unsigned long loh_flags;
499 * Object reference count. Protected by lu_site::ls_guard.
503 * Fid, uniquely identifying this object.
505 struct lu_fid loh_fid;
507 * Common object attributes, cached for efficiency. From enum
508 * lu_object_header_attr.
512 * Linkage into per-site hash table. Protected by lu_site::ls_guard.
514 struct hlist_node loh_hash;
516 * Linkage into per-site LRU list. Protected by lu_site::ls_guard.
518 struct list_head loh_lru;
520 * Linkage into list of layers. Never modified once set (except lately
521 * during object destruction). No locking is necessary.
523 struct list_head loh_layers;
525 * A list of references to this object, for debugging.
527 struct lu_ref loh_reference;
533 * lu_site is a "compartment" within which objects are unique, and LRU
534 * discipline is maintained.
536 * lu_site exists so that multiple layered stacks can co-exist in the same
539 * lu_site has the same relation to lu_device as lu_object_header to
548 * - lu_site::ls_hash hash table (and its linkages in objects);
550 * - lu_site::ls_lru list (and its linkages in objects);
552 * - 0/1 transitions of object lu_object_header::loh_ref
559 * Hash-table where objects are indexed by fid.
561 struct hlist_head *ls_hash;
563 * Bit-mask for hash-table size.
567 * Order of hash-table.
571 * Number of buckets in the hash-table.
576 * LRU list, updated on each access to object. Protected by
579 * "Cold" end of LRU is lu_site::ls_lru.next. Accessed object are
580 * moved to the lu_site::ls_lru.prev (this is due to the non-existence
581 * of list_for_each_entry_safe_reverse()).
583 struct list_head ls_lru;
585 * Total number of objects in this site. Protected by
590 * Total number of objects in this site with reference counter greater
591 * than 0. Protected by lu_site::ls_guard.
596 * Top-level device for this stack.
598 struct lu_device *ls_top_dev;
600 * mds number of this site.
604 * Fid location database
606 struct lu_server_fld *ls_server_fld;
607 struct lu_client_fld *ls_client_fld;
612 struct lu_server_seq *ls_server_seq;
615 * Controller Seq Manager
617 struct lu_server_seq *ls_control_seq;
618 struct obd_export *ls_control_exp;
623 struct lu_client_seq *ls_client_seq;
625 /* statistical counters. Protected by nothing, races are accepted. */
631 * Number of hash-table entry checks made.
633 * ->s_cache_check / (->s_cache_miss + ->s_cache_hit)
635 * is an average number of hash slots inspected during single
639 /** Races with cache insertions. */
642 * Races with object destruction.
644 * \see lu_site::ls_marche_funebre.
646 __u32 s_cache_death_race;
651 * Linkage into global list of sites.
653 struct list_head ls_linkage;
654 struct lprocfs_stats *ls_time_stats;
658 * Constructors/destructors.
662 int lu_site_init (struct lu_site *s, struct lu_device *d);
663 void lu_site_fini (struct lu_site *s);
664 int lu_site_init_finish (struct lu_site *s);
665 void lu_stack_fini (const struct lu_env *env, struct lu_device *top);
666 void lu_device_get (struct lu_device *d);
667 void lu_device_put (struct lu_device *d);
668 int lu_device_init (struct lu_device *d, struct lu_device_type *t);
669 void lu_device_fini (struct lu_device *d);
670 int lu_object_header_init(struct lu_object_header *h);
671 void lu_object_header_fini(struct lu_object_header *h);
672 int lu_object_init (struct lu_object *o,
673 struct lu_object_header *h, struct lu_device *d);
674 void lu_object_fini (struct lu_object *o);
675 void lu_object_add_top (struct lu_object_header *h, struct lu_object *o);
676 void lu_object_add (struct lu_object *before, struct lu_object *o);
679 * Helpers to initialize and finalize device types.
682 int lu_device_type_init(struct lu_device_type *ldt);
683 void lu_device_type_fini(struct lu_device_type *ldt);
684 void lu_types_stop(void);
689 * Caching and reference counting.
694 * Acquire additional reference to the given object. This function is used to
695 * attain additional reference. To acquire initial reference use
698 static inline void lu_object_get(struct lu_object *o)
700 LASSERT(atomic_read(&o->lo_header->loh_ref) > 0);
701 atomic_inc(&o->lo_header->loh_ref);
705 * Return true of object will not be cached after last reference to it is
708 static inline int lu_object_is_dying(const struct lu_object_header *h)
710 return test_bit(LU_OBJECT_HEARD_BANSHEE, &h->loh_flags);
714 * Decrease reference counter on object. If last reference is freed, return
715 * object to the cache, unless lu_object_is_dying(o) holds. In the latter
716 * case, free object immediately.
718 void lu_object_put(const struct lu_env *env,
719 struct lu_object *o);
722 * Free @nr objects from the cold end of the site LRU list.
724 int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr);
727 * Print all objects in @s.
729 void lu_site_print(const struct lu_env *env, struct lu_site *s, void *cookie,
730 lu_printer_t printer);
732 * Search cache for an object with the fid @f. If such object is found, return
733 * it. Otherwise, create new object, insert it into cache and return it. In
734 * any case, additional reference is acquired on the returned object.
736 struct lu_object *lu_object_find(const struct lu_env *env,
737 struct lu_site *s, const struct lu_fid *f);
744 * First (topmost) sub-object of given compound object
746 static inline struct lu_object *lu_object_top(struct lu_object_header *h)
748 LASSERT(!list_empty(&h->loh_layers));
749 return container_of0(h->loh_layers.next, struct lu_object, lo_linkage);
753 * Next sub-object in the layering
755 static inline struct lu_object *lu_object_next(const struct lu_object *o)
757 return container_of0(o->lo_linkage.next, struct lu_object, lo_linkage);
761 * Pointer to the fid of this object.
763 static inline const struct lu_fid *lu_object_fid(const struct lu_object *o)
765 return &o->lo_header->loh_fid;
769 * return device operations vector for this object
771 static inline struct lu_device_operations *
772 lu_object_ops(const struct lu_object *o)
774 return o->lo_dev->ld_ops;
778 * Given a compound object, find its slice, corresponding to the device type
781 struct lu_object *lu_object_locate(struct lu_object_header *h,
782 struct lu_device_type *dtype);
784 struct lu_cdebug_print_info {
787 const char *lpi_file;
793 * Printer function emitting messages through libcfs_debug_msg().
795 int lu_cdebug_printer(const struct lu_env *env,
796 void *cookie, const char *format, ...);
798 #define DECLARE_LU_CDEBUG_PRINT_INFO(var, mask) \
799 struct lu_cdebug_print_info var = { \
800 .lpi_subsys = DEBUG_SUBSYSTEM, \
801 .lpi_mask = (mask), \
802 .lpi_file = __FILE__, \
803 .lpi_fn = __FUNCTION__, \
804 .lpi_line = __LINE__ \
808 * Print object description followed by user-supplied message.
810 #define LU_OBJECT_DEBUG(mask, env, object, format, ...) \
812 static DECLARE_LU_CDEBUG_PRINT_INFO(__info, mask); \
814 lu_object_print(env, &__info, lu_cdebug_printer, object); \
815 CDEBUG(mask, format , ## __VA_ARGS__); \
819 * Print human readable representation of the @o to the @f.
821 void lu_object_print(const struct lu_env *env, void *cookie,
822 lu_printer_t printer, const struct lu_object *o);
825 * Check object consistency.
827 int lu_object_invariant(const struct lu_object *o);
830 * Finalize and free devices in the device stack.
832 void lu_stack_fini(const struct lu_env *env, struct lu_device *top);
835 * Returns 1 iff object @o exists on the stable storage,
836 * returns -1 iff object @o is on remote server.
838 static inline int lu_object_exists(const struct lu_object *o)
842 attr = o->lo_header->loh_attr;
843 if (attr & LOHA_REMOTE)
845 else if (attr & LOHA_EXISTS)
851 static inline int lu_object_assert_exists(const struct lu_object *o)
853 return lu_object_exists(o) != 0;
856 static inline int lu_object_assert_not_exists(const struct lu_object *o)
858 return lu_object_exists(o) <= 0;
862 * Attr of this object.
864 static inline __u32 lu_object_attr(const struct lu_object *o)
866 LASSERT(lu_object_exists(o) > 0);
867 return o->lo_header->loh_attr;
871 /* input params, should be filled out by mdt */
872 __u64 rp_hash; /* hash */
873 int rp_count; /* count in bytes */
874 int rp_npages; /* number of pages */
875 struct page **rp_pages; /* pointers to pages */
878 enum lu_xattr_flags {
879 LU_XATTR_REPLACE = (1 << 0),
880 LU_XATTR_CREATE = (1 << 1)
888 /** For lu_context health-checks */
889 enum lu_context_state {
897 * lu_context. Execution context for lu_object methods. Currently associated
900 * All lu_object methods, except device and device type methods (called during
901 * system initialization and shutdown) are executed "within" some
902 * lu_context. This means, that pointer to some "current" lu_context is passed
903 * as an argument to all methods.
905 * All service ptlrpc threads create lu_context as part of their
906 * initialization. It is possible to create "stand-alone" context for other
907 * execution environments (like system calls).
909 * lu_object methods mainly use lu_context through lu_context_key interface
910 * that allows each layer to associate arbitrary pieces of data with each
911 * context (see pthread_key_create(3) for similar interface).
916 * Theoretically we'd want to use lu_objects and lu_contexts on the
917 * client side too. On the other hand, we don't want to allocate
918 * values of server-side keys for the client contexts and vice versa.
920 * To achieve this, set of tags in introduced. Contexts and keys are
921 * marked with tags. Key value are created only for context whose set
922 * of tags has non-empty intersection with one for key. Tags are taken
923 * from enum lu_context_tag.
927 * Pointer to the home service thread. NULL for other execution
930 struct ptlrpc_thread *lc_thread;
932 * Pointer to an array with key values. Internal implementation
936 enum lu_context_state lc_state;
940 * lu_context_key interface. Similar to pthread_key.
943 enum lu_context_tag {
945 * Thread on md server
947 LCT_MD_THREAD = 1 << 0,
949 * Thread on dt server
951 LCT_DT_THREAD = 1 << 1,
953 * Context for transaction handle
955 LCT_TX_HANDLE = 1 << 2,
959 LCT_CL_THREAD = 1 << 3,
961 * Per-request session on server
963 LCT_SESSION = 1 << 4,
965 * Don't add references for modules creating key values in that context.
966 * This is only for contexts used internally by lu_object framework.
970 * Contexts usable in cache shrinker thread.
972 LCT_SHRINKER = LCT_MD_THREAD|LCT_DT_THREAD|LCT_CL_THREAD|LCT_NOREF
976 * Key. Represents per-context value slot.
978 struct lu_context_key {
980 * Set of tags for which values of this key are to be instantiated.
984 * Value constructor. This is called when new value is created for a
985 * context. Returns pointer to new value of error pointer.
987 void *(*lct_init)(const struct lu_context *ctx,
988 struct lu_context_key *key);
990 * Value destructor. Called when context with previously allocated
991 * value of this slot is destroyed. @data is a value that was returned
992 * by a matching call to ->lct_init().
994 void (*lct_fini)(const struct lu_context *ctx,
995 struct lu_context_key *key, void *data);
997 * Optional method called on lu_context_exit() for all allocated
998 * keys. Can be used by debugging code checking that locks are
1001 void (*lct_exit)(const struct lu_context *ctx,
1002 struct lu_context_key *key, void *data);
1004 * Internal implementation detail: index within ->lc_value[] reserved
1009 * Internal implementation detail: number of values created for this
1014 * Internal implementation detail: module for this key.
1016 struct module *lct_owner;
1019 #define LU_KEY_INIT(mod, type) \
1020 static void* mod##_key_init(const struct lu_context *ctx, \
1021 struct lu_context_key *key) \
1025 CLASSERT(CFS_PAGE_SIZE >= sizeof (*value)); \
1027 OBD_ALLOC_PTR(value); \
1028 if (value == NULL) \
1029 value = ERR_PTR(-ENOMEM); \
1033 struct __##mod##__dummy_init {;} /* semicolon catcher */
1035 #define LU_KEY_FINI(mod, type) \
1036 static void mod##_key_fini(const struct lu_context *ctx, \
1037 struct lu_context_key *key, void* data) \
1039 type *info = data; \
1041 OBD_FREE_PTR(info); \
1043 struct __##mod##__dummy_fini {;} /* semicolon catcher */
1045 #define LU_KEY_INIT_FINI(mod, type) \
1046 LU_KEY_INIT(mod,type); \
1047 LU_KEY_FINI(mod,type)
1049 #define LU_CONTEXT_KEY_DEFINE(mod, tags) \
1050 struct lu_context_key mod##_thread_key = { \
1052 .lct_init = mod##_key_init, \
1053 .lct_fini = mod##_key_fini \
1056 #define LU_CONTEXT_KEY_INIT(key) \
1058 (key)->lct_owner = THIS_MODULE; \
1065 int lu_context_key_register(struct lu_context_key *key);
1069 void lu_context_key_degister(struct lu_context_key *key);
1071 #define LU_KEY_REGISTER_GENERIC(mod) \
1072 static int mod##_key_register_generic(struct lu_context_key *k, ...) \
1074 struct lu_context_key* key = k; \
1078 va_start(args, k); \
1081 LU_CONTEXT_KEY_INIT(key); \
1082 result = lu_context_key_register(key); \
1085 key = va_arg(args, struct lu_context_key*); \
1086 } while (key != NULL); \
1091 va_start(args, k); \
1092 while (k != key) { \
1093 lu_context_key_degister(k); \
1094 k = va_arg(args, struct lu_context_key*); \
1102 #define LU_KEY_DEGISTER_GENERIC(mod) \
1103 static void mod##_key_degister_generic(struct lu_context_key *k, ...) \
1107 va_start(args, k); \
1110 lu_context_key_degister(k); \
1111 k = va_arg(args, struct lu_context_key*); \
1112 } while (k != NULL); \
1117 #define LU_TYPE_INIT(mod, ...) \
1118 LU_KEY_REGISTER_GENERIC(mod) \
1119 static int mod##_type_init(struct lu_device_type *t) \
1121 return mod##_key_register_generic(__VA_ARGS__, NULL); \
1123 struct __##mod##_dummy_type_init {;}
1125 #define LU_TYPE_FINI(mod, ...) \
1126 LU_KEY_DEGISTER_GENERIC(mod) \
1127 static void mod##_type_fini(struct lu_device_type *t) \
1129 mod##_key_degister_generic(__VA_ARGS__, NULL); \
1131 struct __##mod##_dummy_type_fini {;}
1133 #define LU_TYPE_INIT_FINI(mod, ...) \
1134 LU_TYPE_INIT(mod, __VA_ARGS__); \
1135 LU_TYPE_FINI(mod, __VA_ARGS__)
1138 * Return value associated with key @key in context @ctx.
1140 void *lu_context_key_get(const struct lu_context *ctx,
1141 struct lu_context_key *key);
1144 * Initialize context data-structure. Create values for all keys.
1146 int lu_context_init(struct lu_context *ctx, __u32 tags);
1148 * Finalize context data-structure. Destroy key values.
1150 void lu_context_fini(struct lu_context *ctx);
1153 * Called before entering context.
1155 void lu_context_enter(struct lu_context *ctx);
1157 * Called after exiting from @ctx
1159 void lu_context_exit(struct lu_context *ctx);
1162 * Allocate for context all missing keys that were registered after context
1165 int lu_context_refill(const struct lu_context *ctx);
1172 * "Local" context, used to store data instead of stack.
1174 struct lu_context le_ctx;
1176 * "Session" context for per-request data.
1178 struct lu_context *le_ses;
1181 int lu_env_init(struct lu_env *env, struct lu_context *ses, __u32 tags);
1182 void lu_env_fini(struct lu_env *env);
1185 * Common name structure to be passed around for various name related methods.
1193 * Common buffer structure to be passed around for various xattr_{s,g}et()
1202 extern struct lu_buf LU_BUF_NULL;
1204 #define DLUBUF "(%p %z)"
1205 #define PLUBUF(buf) (buf)->lb_buf, (buf)->lb_len
1207 * One-time initializers, called at obdclass module initialization, not
1212 * Initialization of global lu_* data.
1214 int lu_global_init(void);
1217 * Dual to lu_global_init().
1219 void lu_global_fini(void);
1222 LU_TIME_FIND_LOOKUP,
1224 LU_TIME_FIND_INSERT,
1228 extern const char *lu_time_names[LU_TIME_NR];
1230 #endif /* __LUSTRE_LU_OBJECT_H */