1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef __LUSTRE_LU_OBJECT_H
24 #define __LUSTRE_LU_OBJECT_H
31 #include <lustre/lustre_idl.h>
33 #include <libcfs/libcfs.h>
36 * Layered objects support for CMD3/C5.
40 struct proc_dir_entry;
45 * lu_* data-types represent server-side entities shared by data and meta-data
50 * 0. support for layering.
52 * Server side object is split into layers, one per device in the
53 * corresponding device stack. Individual layer is represented by struct
54 * lu_object. Compound layered object --- by struct lu_object_header. Most
55 * interface functions take lu_object as an argument and operate on the
56 * whole compound object. This decision was made due to the following
59 * - it's envisaged that lu_object will be used much more often than
62 * - we want lower (non-top) layers to be able to initiate operations
63 * on the whole object.
65 * Generic code supports layering more complex than simple stacking, e.g.,
66 * it is possible that at some layer object "spawns" multiple sub-objects
69 * 1. fid-based identification.
71 * Compound object is uniquely identified by its fid. Objects are indexed
72 * by their fids (hash table is used for index).
74 * 2. caching and life-cycle management.
76 * Object's life-time is controlled by reference counting. When reference
77 * count drops to 0, object is returned to cache. Cached objects still
78 * retain their identity (i.e., fid), and can be recovered from cache.
80 * Objects are kept in the global LRU list, and lu_site_purge() function
81 * can be used to reclaim given number of unused objects from the tail of
84 * 3. avoiding recursion.
86 * Generic code tries to replace recursion through layers by iterations
87 * where possible. Additionally to the end of reducing stack consumption,
88 * data, when practically possible, are allocated through lu_context_key
89 * interface rather than on stack.
96 struct lu_object_header;
101 * Operations common for data and meta-data devices.
103 struct lu_device_operations {
105 * Object creation protocol.
107 * Due to design goal of avoiding recursion, object creation (see
108 * lu_object_alloc()) is somewhat involved:
110 * - first, ->ldo_object_alloc() method of the top-level device
111 * in the stack is called. It should allocate top level object
112 * (including lu_object_header), but without any lower-layer
115 * - then lu_object_alloc() sets fid in the header of newly created
118 * - then ->loo_object_init() (a method from struct
119 * lu_object_operations) is called. It has to allocate lower-layer
120 * object(s). To do this, ->loo_object_init() calls
121 * ldo_object_alloc() of the lower-layer device(s).
123 * - for all new objects allocated by ->loo_object_init() (and
124 * inserted into object stack), ->loo_object_init() is called again
125 * repeatedly, until no new objects are created.
130 * Allocate object for the given device (without lower-layer
131 * parts). This is called by ->loo_object_init() from the parent
132 * layer, and should setup at least ->lo_dev and ->lo_ops fields of
133 * resulting lu_object.
135 * postcondition: ergo(!IS_ERR(result), result->lo_dev == d &&
136 * result->lo_ops != NULL);
138 struct lu_object *(*ldo_object_alloc)(const struct lu_env *env,
139 const struct lu_object_header *h,
140 struct lu_device *d);
142 * process config specific for device
144 int (*ldo_process_config)(const struct lu_env *env,
145 struct lu_device *, struct lustre_cfg *);
146 int (*ldo_recovery_complete)(const struct lu_env *,
152 * Type of "printer" function used by ->loo_object_print() method.
154 * Printer function is needed to provide some flexibility in (semi-)debugging
155 * output: possible implementations: printk, CDEBUG, sysfs/seq_file
157 typedef int (*lu_printer_t)(const struct lu_env *env,
158 void *cookie, const char *format, ...)
159 __attribute__ ((format (printf, 3, 4)));
162 * Operations specific for particular lu_object.
164 struct lu_object_operations {
167 * Allocate lower-layer parts of the object by calling
168 * ->ldo_object_alloc() of the corresponding underlying device.
170 * This method is called once for each object inserted into object
171 * stack. It's responsibility of this method to insert lower-layer
172 * object(s) it create into appropriate places of object stack.
174 int (*loo_object_init)(const struct lu_env *env,
175 struct lu_object *o);
177 * Called (in top-to-bottom order) during object allocation after all
178 * layers were allocated and initialized. Can be used to perform
179 * initialization depending on lower layers.
181 int (*loo_object_start)(const struct lu_env *env,
182 struct lu_object *o);
184 * Called before ->loo_object_free() to signal that object is being
185 * destroyed. Dual to ->loo_object_init().
187 void (*loo_object_delete)(const struct lu_env *env,
188 struct lu_object *o);
191 * Dual to ->ldo_object_alloc(). Called when object is removed from
194 void (*loo_object_free)(const struct lu_env *env,
195 struct lu_object *o);
198 * Called when last active reference to the object is released (and
199 * object returns to the cache). This method is optional.
201 void (*loo_object_release)(const struct lu_env *env,
202 struct lu_object *o);
204 * Debugging helper. Print given object.
206 int (*loo_object_print)(const struct lu_env *env, void *cookie,
207 lu_printer_t p, const struct lu_object *o);
209 * Optional debugging method. Returns true iff method is internally
212 int (*loo_object_invariant)(const struct lu_object *o);
218 struct lu_device_type;
221 * Device: a layer in the server side abstraction stacking.
225 * reference count. This is incremented, in particular, on each object
226 * created at this layer.
228 * XXX which means that atomic_t is probably too small.
232 * Pointer to device type. Never modified once set.
234 struct lu_device_type *ld_type;
236 * Operation vector for this device.
238 struct lu_device_operations *ld_ops;
240 * Stack this device belongs to.
242 struct lu_site *ld_site;
243 struct proc_dir_entry *ld_proc_entry;
245 /* XXX: temporary back pointer into obd. */
246 struct obd_device *ld_obd;
249 struct lu_device_type_operations;
252 * Tag bits for device type. They are used to distinguish certain groups of
256 /* this is meta-data device */
257 LU_DEVICE_MD = (1 << 0),
258 /* this is data device */
259 LU_DEVICE_DT = (1 << 1)
265 struct lu_device_type {
267 * Tag bits. Taken from enum lu_device_tag. Never modified once set.
271 * Name of this class. Unique system-wide. Never modified once set.
275 * Operations for this type.
277 struct lu_device_type_operations *ldt_ops;
279 * XXX: temporary pointer to associated obd_type.
281 struct obd_type *ldt_obd_type;
283 * XXX: temporary: context tags used by obd_*() calls.
289 * Operations on a device type.
291 struct lu_device_type_operations {
293 * Allocate new device.
295 struct lu_device *(*ldto_device_alloc)(const struct lu_env *env,
296 struct lu_device_type *t,
297 struct lustre_cfg *lcfg);
299 * Free device. Dual to ->ldto_device_alloc(). Returns pointer to
300 * the next device in the stack.
302 struct lu_device *(*ldto_device_free)(const struct lu_env *,
306 * Initialize the devices after allocation
308 int (*ldto_device_init)(const struct lu_env *env,
309 struct lu_device *, const char *,
312 * Finalize device. Dual to ->ldto_device_init(). Returns pointer to
313 * the next device in the stack.
315 struct lu_device *(*ldto_device_fini)(const struct lu_env *env,
319 * Initialize device type. This is called on module load.
321 int (*ldto_init)(struct lu_device_type *t);
323 * Finalize device type. Dual to ->ldto_init(). Called on module
326 void (*ldto_fini)(struct lu_device_type *t);
330 * Flags for the object layers.
332 enum lu_object_flags {
334 * this flags is set if ->loo_object_init() has been called for this
335 * layer. Used by lu_object_alloc().
337 LU_OBJECT_ALLOCATED = (1 << 0)
341 * Common object attributes.
357 LA_BLKSIZE = 1 << 12,
361 __u64 la_size; /* size in bytes */
362 __u64 la_mtime; /* modification time in seconds since Epoch */
363 __u64 la_atime; /* access time in seconds since Epoch */
364 __u64 la_ctime; /* change time in seconds since Epoch */
365 __u64 la_blocks; /* 512-byte blocks allocated to object */
366 __u32 la_mode; /* permission bits and file type */
367 __u32 la_uid; /* owner id */
368 __u32 la_gid; /* group id */
369 __u32 la_flags; /* object flags */
370 __u32 la_nlink; /* number of persistent references to this
372 __u32 la_blkbits; /* blk bits of the object*/
373 __u32 la_blksize; /* blk size of the object*/
375 __u32 la_rdev; /* real device */
376 __u64 la_valid; /* valid bits */
380 * Layer in the layered object.
384 * Header for this object.
386 struct lu_object_header *lo_header;
388 * Device for this layer.
390 struct lu_device *lo_dev;
392 * Operations for this object.
394 struct lu_object_operations *lo_ops;
396 * Linkage into list of all layers.
398 struct list_head lo_linkage;
400 * Depth. Top level layer depth is 0.
404 * Flags from enum lu_object_flags.
406 unsigned long lo_flags;
409 enum lu_object_header_flags {
411 * Don't keep this object in cache. Object will be destroyed as soon
412 * as last reference to it is released. This flag cannot be cleared
415 LU_OBJECT_HEARD_BANSHEE = 0
418 enum lu_object_header_attr {
419 LOHA_EXISTS = 1 << 0,
420 LOHA_REMOTE = 1 << 1,
422 * UNIX file type is stored in S_IFMT bits.
424 LOHA_FT_START = 1 << 12, /* S_IFIFO */
425 LOHA_FT_END = 1 << 15, /* S_IFREG */
429 * "Compound" object, consisting of multiple layers.
431 * Compound object with given fid is unique with given lu_site.
433 * Note, that object does *not* necessary correspond to the real object in the
434 * persistent storage: object is an anchor for locking and method calling, so
435 * it is created for things like not-yet-existing child created by mkdir or
436 * create calls. ->loo_exists() can be used to check whether object is backed
437 * by persistent storage entity.
439 struct lu_object_header {
441 * Object flags from enum lu_object_header_flags. Set and checked
444 unsigned long loh_flags;
446 * Object reference count. Protected by site guard lock.
450 * Fid, uniquely identifying this object.
452 struct lu_fid loh_fid;
454 * Common object attributes, cached for efficiency. From enum
455 * lu_object_header_attr.
459 * Linkage into per-site hash table. Protected by site guard lock.
461 struct hlist_node loh_hash;
463 * Linkage into per-site LRU list. Protected by site guard lock.
465 struct list_head loh_lru;
467 * Linkage into list of layers. Never modified once set (except lately
468 * during object destruction). No locking is necessary.
470 struct list_head loh_layers;
476 * lu_site is a "compartment" within which objects are unique, and LRU
477 * discipline is maintained.
479 * lu_site exists so that multiple layered stacks can co-exist in the same
482 * lu_site has the same relation to lu_device as lu_object_header to
489 * - ->ls_hash hash table (and its linkages in objects);
491 * - ->ls_lru list (and its linkages in objects);
493 * - 0/1 transitions of object ->loh_ref reference count;
499 * Hash-table where objects are indexed by fid.
501 struct hlist_head *ls_hash;
503 * Bit-mask for hash-table size.
507 * Order of hash-table.
511 * Number of buckets in the hash-table.
516 * LRU list, updated on each access to object. Protected by
519 * "Cold" end of LRU is ->ls_lru.next. Accessed object are moved to
520 * the ->ls_lru.prev (this is due to the non-existence of
521 * list_for_each_entry_safe_reverse()).
523 struct list_head ls_lru;
525 * Total number of objects in this site. Protected by ->ls_guard.
529 * Total number of objects in this site with reference counter greater
530 * than 0. Protected by ->ls_guard.
535 * Top-level device for this stack.
537 struct lu_device *ls_top_dev;
539 * mds number of this site.
543 * Fid location database
545 struct lu_server_fld *ls_server_fld;
546 struct lu_client_fld *ls_client_fld;
551 struct lu_server_seq *ls_server_seq;
554 * Controller Seq Manager
556 struct lu_server_seq *ls_control_seq;
557 struct obd_export *ls_control_exp;
562 struct lu_client_seq *ls_client_seq;
564 /* statistical counters. Protected by nothing, races are accepted. */
570 * Number of hash-table entry checks made.
572 * ->s_cache_check / (->s_cache_miss + ->s_cache_hit)
574 * is an average number of hash slots inspected during single
578 /* raced cache insertions */
584 * Linkage into global list of sites.
586 struct list_head ls_linkage;
587 struct lprocfs_stats *ls_time_stats;
591 * Constructors/destructors.
595 * Initialize site @s, with @d as the top level device.
597 int lu_site_init(struct lu_site *s, struct lu_device *d);
599 * Finalize @s and release its resources.
601 void lu_site_fini(struct lu_site *s);
604 * Called when initialization of stack for this site is completed.
606 int lu_site_init_finish(struct lu_site *s);
609 * Acquire additional reference on device @d
611 void lu_device_get(struct lu_device *d);
613 * Release reference on device @d.
615 void lu_device_put(struct lu_device *d);
618 * Initialize device @d of type @t.
620 int lu_device_init(struct lu_device *d, struct lu_device_type *t);
622 * Finalize device @d.
624 void lu_device_fini(struct lu_device *d);
627 * Initialize compound object.
629 int lu_object_header_init(struct lu_object_header *h);
631 * Finalize compound object.
633 void lu_object_header_fini(struct lu_object_header *h);
636 * Initialize object @o that is part of compound object @h and was created by
639 int lu_object_init(struct lu_object *o,
640 struct lu_object_header *h, struct lu_device *d);
642 * Finalize object and release its resources.
644 void lu_object_fini(struct lu_object *o);
646 * Add object @o as first layer of compound object @h.
648 * This is typically called by the ->ldo_object_alloc() method of top-level
651 void lu_object_add_top(struct lu_object_header *h, struct lu_object *o);
653 * Add object @o as a layer of compound object, going after @before.1
655 * This is typically called by the ->ldo_object_alloc() method of
658 void lu_object_add(struct lu_object *before, struct lu_object *o);
661 * Caching and reference counting.
665 * Acquire additional reference to the given object. This function is used to
666 * attain additional reference. To acquire initial reference use
669 static inline void lu_object_get(struct lu_object *o)
671 LASSERT(atomic_read(&o->lo_header->loh_ref) > 0);
672 atomic_inc(&o->lo_header->loh_ref);
676 * Return true of object will not be cached after last reference to it is
679 static inline int lu_object_is_dying(const struct lu_object_header *h)
681 return test_bit(LU_OBJECT_HEARD_BANSHEE, &h->loh_flags);
685 * Decrease reference counter on object. If last reference is freed, return
686 * object to the cache, unless lu_object_is_dying(o) holds. In the latter
687 * case, free object immediately.
689 void lu_object_put(const struct lu_env *env,
690 struct lu_object *o);
693 * Free @nr objects from the cold end of the site LRU list.
695 int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr);
698 * Print all objects in @s.
700 void lu_site_print(const struct lu_env *env, struct lu_site *s, void *cookie,
701 lu_printer_t printer);
703 * Search cache for an object with the fid @f. If such object is found, return
704 * it. Otherwise, create new object, insert it into cache and return it. In
705 * any case, additional reference is acquired on the returned object.
707 struct lu_object *lu_object_find(const struct lu_env *env,
708 struct lu_site *s, const struct lu_fid *f);
715 * First (topmost) sub-object of given compound object
717 static inline struct lu_object *lu_object_top(struct lu_object_header *h)
719 LASSERT(!list_empty(&h->loh_layers));
720 return container_of0(h->loh_layers.next, struct lu_object, lo_linkage);
724 * Next sub-object in the layering
726 static inline struct lu_object *lu_object_next(const struct lu_object *o)
728 return container_of0(o->lo_linkage.next, struct lu_object, lo_linkage);
732 * Pointer to the fid of this object.
734 static inline const struct lu_fid *lu_object_fid(const struct lu_object *o)
736 return &o->lo_header->loh_fid;
740 * return device operations vector for this object
742 static inline struct lu_device_operations *
743 lu_object_ops(const struct lu_object *o)
745 return o->lo_dev->ld_ops;
749 * Given a compound object, find its slice, corresponding to the device type
752 struct lu_object *lu_object_locate(struct lu_object_header *h,
753 struct lu_device_type *dtype);
755 struct lu_cdebug_print_info {
758 const char *lpi_file;
764 * Printer function emitting messages through libcfs_debug_msg().
766 int lu_cdebug_printer(const struct lu_env *env,
767 void *cookie, const char *format, ...);
769 #define DECLARE_LU_CDEBUG_PRINT_INFO(var, mask) \
770 struct lu_cdebug_print_info var = { \
771 .lpi_subsys = DEBUG_SUBSYSTEM, \
772 .lpi_mask = (mask), \
773 .lpi_file = __FILE__, \
774 .lpi_fn = __FUNCTION__, \
775 .lpi_line = __LINE__ \
779 * Print object description followed by user-supplied message.
781 #define LU_OBJECT_DEBUG(mask, env, object, format, ...) \
783 static DECLARE_LU_CDEBUG_PRINT_INFO(__info, mask); \
785 lu_object_print(env, &__info, lu_cdebug_printer, object); \
786 CDEBUG(mask, format , ## __VA_ARGS__); \
790 * Print human readable representation of the @o to the @f.
792 void lu_object_print(const struct lu_env *env, void *cookie,
793 lu_printer_t printer, const struct lu_object *o);
796 * Check object consistency.
798 int lu_object_invariant(const struct lu_object *o);
801 * Finalize and free devices in the device stack.
803 void lu_stack_fini(const struct lu_env *env, struct lu_device *top);
806 * Returns 1 iff object @o exists on the stable storage,
807 * returns -1 iff object @o is on remote server.
809 static inline int lu_object_exists(const struct lu_object *o)
813 attr = o->lo_header->loh_attr;
814 if (attr & LOHA_REMOTE)
816 else if (attr & LOHA_EXISTS)
822 static inline int lu_object_assert_exists(const struct lu_object *o)
824 return lu_object_exists(o) != 0;
827 static inline int lu_object_assert_not_exists(const struct lu_object *o)
829 return lu_object_exists(o) <= 0;
833 * Attr of this object.
835 static inline __u32 lu_object_attr(const struct lu_object *o)
837 LASSERT(lu_object_exists(o) > 0);
838 return o->lo_header->loh_attr;
842 /* input params, should be filled out by mdt */
843 __u64 rp_hash; /* hash */
844 int rp_count; /* count in bytes */
845 int rp_npages; /* number of pages */
846 struct page **rp_pages; /* pointers to pages */
849 enum lu_xattr_flags {
850 LU_XATTR_REPLACE = (1 << 0),
851 LU_XATTR_CREATE = (1 << 1)
854 /* For lu_context health-checks */
855 enum lu_context_state {
863 * lu_context. Execution context for lu_object methods. Currently associated
866 * All lu_object methods, except device and device type methods (called during
867 * system initialization and shutdown) are executed "within" some
868 * lu_context. This means, that pointer to some "current" lu_context is passed
869 * as an argument to all methods.
871 * All service ptlrpc threads create lu_context as part of their
872 * initialization. It is possible to create "stand-alone" context for other
873 * execution environments (like system calls).
875 * lu_object methods mainly use lu_context through lu_context_key interface
876 * that allows each layer to associate arbitrary pieces of data with each
877 * context (see pthread_key_create(3) for similar interface).
882 * Theoretically we'd want to use lu_objects and lu_contexts on the
883 * client side too. On the other hand, we don't want to allocate
884 * values of server-side keys for the client contexts and vice versa.
886 * To achieve this, set of tags in introduced. Contexts and keys are
887 * marked with tags. Key value are created only for context whose set
888 * of tags has non-empty intersection with one for key. Tags are taken
889 * from enum lu_context_tag.
893 * Pointer to the home service thread. NULL for other execution
896 struct ptlrpc_thread *lc_thread;
898 * Pointer to an array with key values. Internal implementation
902 enum lu_context_state lc_state;
906 * lu_context_key interface. Similar to pthread_key.
909 enum lu_context_tag {
911 * Thread on md server
913 LCT_MD_THREAD = 1 << 0,
915 * Thread on dt server
917 LCT_DT_THREAD = 1 << 1,
919 * Context for transaction handle
921 LCT_TX_HANDLE = 1 << 2,
925 LCT_CL_THREAD = 1 << 3,
927 * Per-request session on server
929 LCT_SESSION = 1 << 4,
931 * Don't add references for modules creating key values in that context.
932 * This is only for contexts used internally by lu_object framework.
936 * Contexts usable in cache shrinker thread.
938 LCT_SHRINKER = LCT_MD_THREAD|LCT_DT_THREAD|LCT_CL_THREAD|LCT_NOREF
942 * Key. Represents per-context value slot.
944 struct lu_context_key {
946 * Set of tags for which values of this key are to be instantiated.
950 * Value constructor. This is called when new value is created for a
951 * context. Returns pointer to new value of error pointer.
953 void *(*lct_init)(const struct lu_context *ctx,
954 struct lu_context_key *key);
956 * Value destructor. Called when context with previously allocated
957 * value of this slot is destroyed. @data is a value that was returned
958 * by a matching call to ->lct_init().
960 void (*lct_fini)(const struct lu_context *ctx,
961 struct lu_context_key *key, void *data);
963 * Optional method called on lu_context_exit() for all allocated
964 * keys. Can be used by debugging code checking that locks are
967 void (*lct_exit)(const struct lu_context *ctx,
968 struct lu_context_key *key, void *data);
970 * Internal implementation detail: index within ->lc_value[] reserved
975 * Internal implementation detail: number of values created for this
980 * Internal implementation detail: module for this key.
982 struct module *lct_owner;
985 #define LU_KEY_INIT(mod, type) \
986 static void* mod##_key_init(const struct lu_context *ctx, \
987 struct lu_context_key *key) \
991 CLASSERT(CFS_PAGE_SIZE >= sizeof (*value)); \
993 OBD_ALLOC_PTR(value); \
995 value = ERR_PTR(-ENOMEM); \
999 struct __##mod##__dummy_init {;} /* semicolon catcher */
1001 #define LU_KEY_FINI(mod, type) \
1002 static void mod##_key_fini(const struct lu_context *ctx, \
1003 struct lu_context_key *key, void* data) \
1005 type *info = data; \
1007 OBD_FREE_PTR(info); \
1009 struct __##mod##__dummy_fini {;} /* semicolon catcher */
1011 #define LU_KEY_INIT_FINI(mod, type) \
1012 LU_KEY_INIT(mod,type); \
1013 LU_KEY_FINI(mod,type)
1015 #define LU_CONTEXT_KEY_DEFINE(mod, tags) \
1016 struct lu_context_key mod##_thread_key = { \
1018 .lct_init = mod##_key_init, \
1019 .lct_fini = mod##_key_fini \
1022 #define LU_CONTEXT_KEY_INIT(key) \
1024 (key)->lct_owner = THIS_MODULE; \
1031 int lu_context_key_register(struct lu_context_key *key);
1035 void lu_context_key_degister(struct lu_context_key *key);
1037 #define LU_KEY_REGISTER_GENERIC(mod) \
1038 static int mod##_key_register_generic(struct lu_context_key *k, ...) \
1040 struct lu_context_key* key = k; \
1044 va_start(args, k); \
1047 LU_CONTEXT_KEY_INIT(key); \
1048 result = lu_context_key_register(key); \
1051 key = va_arg(args, struct lu_context_key*); \
1052 } while (key != NULL); \
1057 va_start(args, k); \
1058 while (k != key) { \
1059 lu_context_key_degister(k); \
1060 k = va_arg(args, struct lu_context_key*); \
1068 #define LU_KEY_DEGISTER_GENERIC(mod) \
1069 static void mod##_key_degister_generic(struct lu_context_key *k, ...) \
1073 va_start(args, k); \
1076 lu_context_key_degister(k); \
1077 k = va_arg(args, struct lu_context_key*); \
1078 } while (k != NULL); \
1083 #define LU_TYPE_INIT(mod, ...) \
1084 LU_KEY_REGISTER_GENERIC(mod) \
1085 static int mod##_type_init(struct lu_device_type *t) \
1087 return mod##_key_register_generic(__VA_ARGS__, NULL); \
1089 struct __##mod##_dummy_type_init {;}
1091 #define LU_TYPE_FINI(mod, ...) \
1092 LU_KEY_DEGISTER_GENERIC(mod) \
1093 static void mod##_type_fini(struct lu_device_type *t) \
1095 mod##_key_degister_generic(__VA_ARGS__, NULL); \
1097 struct __##mod##_dummy_type_fini {;}
1099 #define LU_TYPE_INIT_FINI(mod, ...) \
1100 LU_TYPE_INIT(mod, __VA_ARGS__); \
1101 LU_TYPE_FINI(mod, __VA_ARGS__)
1104 * Return value associated with key @key in context @ctx.
1106 void *lu_context_key_get(const struct lu_context *ctx,
1107 struct lu_context_key *key);
1110 * Initialize context data-structure. Create values for all keys.
1112 int lu_context_init(struct lu_context *ctx, __u32 tags);
1114 * Finalize context data-structure. Destroy key values.
1116 void lu_context_fini(struct lu_context *ctx);
1119 * Called before entering context.
1121 void lu_context_enter(struct lu_context *ctx);
1123 * Called after exiting from @ctx
1125 void lu_context_exit(struct lu_context *ctx);
1128 * Allocate for context all missing keys that were registered after context
1131 int lu_context_refill(const struct lu_context *ctx);
1138 * "Local" context, used to store data instead of stack.
1140 struct lu_context le_ctx;
1142 * "Session" context for per-request data.
1144 struct lu_context *le_ses;
1147 int lu_env_init(struct lu_env *env, struct lu_context *ses, __u32 tags);
1148 void lu_env_fini(struct lu_env *env);
1151 * Common name structure to be passed around for various name related methods.
1159 * Common buffer structure to be passed around for various xattr_{s,g}et()
1167 extern struct lu_buf LU_BUF_NULL; /* null buffer */
1169 #define DLUBUF "(%p %z)"
1170 #define PLUBUF(buf) (buf)->lb_buf, (buf)->lb_len
1172 * One-time initializers, called at obdclass module initialization, not
1177 * Initialization of global lu_* data.
1179 int lu_global_init(void);
1182 * Dual to lu_global_init().
1184 void lu_global_fini(void);
1187 LU_TIME_FIND_LOOKUP,
1189 LU_TIME_FIND_INSERT,
1193 extern const char *lu_time_names[LU_TIME_NR];
1195 #endif /* __LUSTRE_LU_OBJECT_H */