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>
50 * Layered objects support for CMD3/C5.
54 struct proc_dir_entry;
59 * lu_* data-types represent server-side entities shared by data and meta-data
64 * 0. support for layering.
66 * Server side object is split into layers, one per device in the
67 * corresponding device stack. Individual layer is represented by struct
68 * lu_object. Compound layered object --- by struct lu_object_header. Most
69 * interface functions take lu_object as an argument and operate on the
70 * whole compound object. This decision was made due to the following
73 * - it's envisaged that lu_object will be used much more often than
76 * - we want lower (non-top) layers to be able to initiate operations
77 * on the whole object.
79 * Generic code supports layering more complex than simple stacking, e.g.,
80 * it is possible that at some layer object "spawns" multiple sub-objects
83 * 1. fid-based identification.
85 * Compound object is uniquely identified by its fid. Objects are indexed
86 * by their fids (hash table is used for index).
88 * 2. caching and life-cycle management.
90 * Object's life-time is controlled by reference counting. When reference
91 * count drops to 0, object is returned to cache. Cached objects still
92 * retain their identity (i.e., fid), and can be recovered from cache.
94 * Objects are kept in the global LRU list, and lu_site_purge() function
95 * can be used to reclaim given number of unused objects from the tail of
98 * 3. avoiding recursion.
100 * Generic code tries to replace recursion through layers by iterations
101 * where possible. Additionally to the end of reducing stack consumption,
102 * data, when practically possible, are allocated through lu_context_key
103 * interface rather than on stack.
110 struct lu_object_header;
115 * Operations common for data and meta-data devices.
117 struct lu_device_operations {
119 * Object creation protocol.
121 * Due to design goal of avoiding recursion, object creation (see
122 * lu_object_alloc()) is somewhat involved:
124 * - first, ->ldo_object_alloc() method of the top-level device
125 * in the stack is called. It should allocate top level object
126 * (including lu_object_header), but without any lower-layer
129 * - then lu_object_alloc() sets fid in the header of newly created
132 * - then ->loo_object_init() (a method from struct
133 * lu_object_operations) is called. It has to allocate lower-layer
134 * object(s). To do this, ->loo_object_init() calls
135 * ldo_object_alloc() of the lower-layer device(s).
137 * - for all new objects allocated by ->loo_object_init() (and
138 * inserted into object stack), ->loo_object_init() is called again
139 * repeatedly, until no new objects are created.
144 * Allocate object for the given device (without lower-layer
145 * parts). This is called by ->loo_object_init() from the parent
146 * layer, and should setup at least ->lo_dev and ->lo_ops fields of
147 * resulting lu_object.
149 * postcondition: ergo(!IS_ERR(result), result->lo_dev == d &&
150 * result->lo_ops != NULL);
152 struct lu_object *(*ldo_object_alloc)(const struct lu_env *env,
153 const struct lu_object_header *h,
154 struct lu_device *d);
156 * process config specific for device
158 int (*ldo_process_config)(const struct lu_env *env,
159 struct lu_device *, struct lustre_cfg *);
160 int (*ldo_recovery_complete)(const struct lu_env *,
166 * Type of "printer" function used by ->loo_object_print() method.
168 * Printer function is needed to provide some flexibility in (semi-)debugging
169 * output: possible implementations: printk, CDEBUG, sysfs/seq_file
171 typedef int (*lu_printer_t)(const struct lu_env *env,
172 void *cookie, const char *format, ...)
173 __attribute__ ((format (printf, 3, 4)));
176 * Operations specific for particular lu_object.
178 struct lu_object_operations {
181 * Allocate lower-layer parts of the object by calling
182 * ->ldo_object_alloc() of the corresponding underlying device.
184 * This method is called once for each object inserted into object
185 * stack. It's responsibility of this method to insert lower-layer
186 * object(s) it create into appropriate places of object stack.
188 int (*loo_object_init)(const struct lu_env *env,
189 struct lu_object *o);
191 * Called (in top-to-bottom order) during object allocation after all
192 * layers were allocated and initialized. Can be used to perform
193 * initialization depending on lower layers.
195 int (*loo_object_start)(const struct lu_env *env,
196 struct lu_object *o);
198 * Called before ->loo_object_free() to signal that object is being
199 * destroyed. Dual to ->loo_object_init().
201 void (*loo_object_delete)(const struct lu_env *env,
202 struct lu_object *o);
205 * Dual to ->ldo_object_alloc(). Called when object is removed from
208 void (*loo_object_free)(const struct lu_env *env,
209 struct lu_object *o);
212 * Called when last active reference to the object is released (and
213 * object returns to the cache). This method is optional.
215 void (*loo_object_release)(const struct lu_env *env,
216 struct lu_object *o);
218 * Debugging helper. Print given object.
220 int (*loo_object_print)(const struct lu_env *env, void *cookie,
221 lu_printer_t p, const struct lu_object *o);
223 * Optional debugging method. Returns true iff method is internally
226 int (*loo_object_invariant)(const struct lu_object *o);
232 struct lu_device_type;
235 * Device: a layer in the server side abstraction stacking.
239 * reference count. This is incremented, in particular, on each object
240 * created at this layer.
242 * XXX which means that atomic_t is probably too small.
246 * Pointer to device type. Never modified once set.
248 struct lu_device_type *ld_type;
250 * Operation vector for this device.
252 struct lu_device_operations *ld_ops;
254 * Stack this device belongs to.
256 struct lu_site *ld_site;
257 struct proc_dir_entry *ld_proc_entry;
259 /* XXX: temporary back pointer into obd. */
260 struct obd_device *ld_obd;
263 struct lu_device_type_operations;
266 * Tag bits for device type. They are used to distinguish certain groups of
270 /* this is meta-data device */
271 LU_DEVICE_MD = (1 << 0),
272 /* this is data device */
273 LU_DEVICE_DT = (1 << 1)
279 struct lu_device_type {
281 * Tag bits. Taken from enum lu_device_tag. Never modified once set.
285 * Name of this class. Unique system-wide. Never modified once set.
289 * Operations for this type.
291 struct lu_device_type_operations *ldt_ops;
293 * XXX: temporary pointer to associated obd_type.
295 struct obd_type *ldt_obd_type;
297 * XXX: temporary: context tags used by obd_*() calls.
303 * Operations on a device type.
305 struct lu_device_type_operations {
307 * Allocate new device.
309 struct lu_device *(*ldto_device_alloc)(const struct lu_env *env,
310 struct lu_device_type *t,
311 struct lustre_cfg *lcfg);
313 * Free device. Dual to ->ldto_device_alloc(). Returns pointer to
314 * the next device in the stack.
316 struct lu_device *(*ldto_device_free)(const struct lu_env *,
320 * Initialize the devices after allocation
322 int (*ldto_device_init)(const struct lu_env *env,
323 struct lu_device *, const char *,
326 * Finalize device. Dual to ->ldto_device_init(). Returns pointer to
327 * the next device in the stack.
329 struct lu_device *(*ldto_device_fini)(const struct lu_env *env,
333 * Initialize device type. This is called on module load.
335 int (*ldto_init)(struct lu_device_type *t);
337 * Finalize device type. Dual to ->ldto_init(). Called on module
340 void (*ldto_fini)(struct lu_device_type *t);
344 * Flags for the object layers.
346 enum lu_object_flags {
348 * this flags is set if ->loo_object_init() has been called for this
349 * layer. Used by lu_object_alloc().
351 LU_OBJECT_ALLOCATED = (1 << 0)
355 * Common object attributes.
371 LA_BLKSIZE = 1 << 12,
375 __u64 la_size; /* size in bytes */
376 __u64 la_mtime; /* modification time in seconds since Epoch */
377 __u64 la_atime; /* access time in seconds since Epoch */
378 __u64 la_ctime; /* change time in seconds since Epoch */
379 __u64 la_blocks; /* 512-byte blocks allocated to object */
380 __u32 la_mode; /* permission bits and file type */
381 __u32 la_uid; /* owner id */
382 __u32 la_gid; /* group id */
383 __u32 la_flags; /* object flags */
384 __u32 la_nlink; /* number of persistent references to this
386 __u32 la_blkbits; /* blk bits of the object*/
387 __u32 la_blksize; /* blk size of the object*/
389 __u32 la_rdev; /* real device */
390 __u64 la_valid; /* valid bits */
394 * Layer in the layered object.
398 * Header for this object.
400 struct lu_object_header *lo_header;
402 * Device for this layer.
404 struct lu_device *lo_dev;
406 * Operations for this object.
408 struct lu_object_operations *lo_ops;
410 * Linkage into list of all layers.
412 struct list_head lo_linkage;
414 * Depth. Top level layer depth is 0.
418 * Flags from enum lu_object_flags.
420 unsigned long lo_flags;
423 enum lu_object_header_flags {
425 * Don't keep this object in cache. Object will be destroyed as soon
426 * as last reference to it is released. This flag cannot be cleared
429 LU_OBJECT_HEARD_BANSHEE = 0
432 enum lu_object_header_attr {
433 LOHA_EXISTS = 1 << 0,
434 LOHA_REMOTE = 1 << 1,
436 * UNIX file type is stored in S_IFMT bits.
438 LOHA_FT_START = 1 << 12, /* S_IFIFO */
439 LOHA_FT_END = 1 << 15, /* S_IFREG */
443 * "Compound" object, consisting of multiple layers.
445 * Compound object with given fid is unique with given lu_site.
447 * Note, that object does *not* necessary correspond to the real object in the
448 * persistent storage: object is an anchor for locking and method calling, so
449 * it is created for things like not-yet-existing child created by mkdir or
450 * create calls. ->loo_exists() can be used to check whether object is backed
451 * by persistent storage entity.
453 struct lu_object_header {
455 * Object flags from enum lu_object_header_flags. Set and checked
458 unsigned long loh_flags;
460 * Object reference count. Protected by site guard lock.
464 * Fid, uniquely identifying this object.
466 struct lu_fid loh_fid;
468 * Common object attributes, cached for efficiency. From enum
469 * lu_object_header_attr.
473 * Linkage into per-site hash table. Protected by site guard lock.
475 struct hlist_node loh_hash;
477 * Linkage into per-site LRU list. Protected by site guard lock.
479 struct list_head loh_lru;
481 * Linkage into list of layers. Never modified once set (except lately
482 * during object destruction). No locking is necessary.
484 struct list_head loh_layers;
490 * lu_site is a "compartment" within which objects are unique, and LRU
491 * discipline is maintained.
493 * lu_site exists so that multiple layered stacks can co-exist in the same
496 * lu_site has the same relation to lu_device as lu_object_header to
503 * - ->ls_hash hash table (and its linkages in objects);
505 * - ->ls_lru list (and its linkages in objects);
507 * - 0/1 transitions of object ->loh_ref reference count;
513 * Hash-table where objects are indexed by fid.
515 struct hlist_head *ls_hash;
517 * Bit-mask for hash-table size.
521 * Order of hash-table.
525 * Number of buckets in the hash-table.
530 * LRU list, updated on each access to object. Protected by
533 * "Cold" end of LRU is ->ls_lru.next. Accessed object are moved to
534 * the ->ls_lru.prev (this is due to the non-existence of
535 * list_for_each_entry_safe_reverse()).
537 struct list_head ls_lru;
539 * Total number of objects in this site. Protected by ->ls_guard.
543 * Total number of objects in this site with reference counter greater
544 * than 0. Protected by ->ls_guard.
549 * Top-level device for this stack.
551 struct lu_device *ls_top_dev;
553 * mds number of this site.
557 * Fid location database
559 struct lu_server_fld *ls_server_fld;
560 struct lu_client_fld *ls_client_fld;
565 struct lu_server_seq *ls_server_seq;
568 * Controller Seq Manager
570 struct lu_server_seq *ls_control_seq;
571 struct obd_export *ls_control_exp;
576 struct lu_client_seq *ls_client_seq;
578 /* statistical counters. Protected by nothing, races are accepted. */
584 * Number of hash-table entry checks made.
586 * ->s_cache_check / (->s_cache_miss + ->s_cache_hit)
588 * is an average number of hash slots inspected during single
592 /* raced cache insertions */
598 * Linkage into global list of sites.
600 struct list_head ls_linkage;
601 struct lprocfs_stats *ls_time_stats;
605 * Constructors/destructors.
609 * Initialize site @s, with @d as the top level device.
611 int lu_site_init(struct lu_site *s, struct lu_device *d);
613 * Finalize @s and release its resources.
615 void lu_site_fini(struct lu_site *s);
618 * Called when initialization of stack for this site is completed.
620 int lu_site_init_finish(struct lu_site *s);
623 * Acquire additional reference on device @d
625 void lu_device_get(struct lu_device *d);
627 * Release reference on device @d.
629 void lu_device_put(struct lu_device *d);
632 * Initialize device @d of type @t.
634 int lu_device_init(struct lu_device *d, struct lu_device_type *t);
636 * Finalize device @d.
638 void lu_device_fini(struct lu_device *d);
641 * Initialize compound object.
643 int lu_object_header_init(struct lu_object_header *h);
645 * Finalize compound object.
647 void lu_object_header_fini(struct lu_object_header *h);
650 * Initialize object @o that is part of compound object @h and was created by
653 int lu_object_init(struct lu_object *o,
654 struct lu_object_header *h, struct lu_device *d);
656 * Finalize object and release its resources.
658 void lu_object_fini(struct lu_object *o);
660 * Add object @o as first layer of compound object @h.
662 * This is typically called by the ->ldo_object_alloc() method of top-level
665 void lu_object_add_top(struct lu_object_header *h, struct lu_object *o);
667 * Add object @o as a layer of compound object, going after @before.1
669 * This is typically called by the ->ldo_object_alloc() method of
672 void lu_object_add(struct lu_object *before, struct lu_object *o);
675 * Caching and reference counting.
679 * Acquire additional reference to the given object. This function is used to
680 * attain additional reference. To acquire initial reference use
683 static inline void lu_object_get(struct lu_object *o)
685 LASSERT(atomic_read(&o->lo_header->loh_ref) > 0);
686 atomic_inc(&o->lo_header->loh_ref);
690 * Return true of object will not be cached after last reference to it is
693 static inline int lu_object_is_dying(const struct lu_object_header *h)
695 return test_bit(LU_OBJECT_HEARD_BANSHEE, &h->loh_flags);
699 * Decrease reference counter on object. If last reference is freed, return
700 * object to the cache, unless lu_object_is_dying(o) holds. In the latter
701 * case, free object immediately.
703 void lu_object_put(const struct lu_env *env,
704 struct lu_object *o);
707 * Free @nr objects from the cold end of the site LRU list.
709 int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr);
712 * Print all objects in @s.
714 void lu_site_print(const struct lu_env *env, struct lu_site *s, void *cookie,
715 lu_printer_t printer);
717 * Search cache for an object with the fid @f. If such object is found, return
718 * it. Otherwise, create new object, insert it into cache and return it. In
719 * any case, additional reference is acquired on the returned object.
721 struct lu_object *lu_object_find(const struct lu_env *env,
722 struct lu_site *s, const struct lu_fid *f);
729 * First (topmost) sub-object of given compound object
731 static inline struct lu_object *lu_object_top(struct lu_object_header *h)
733 LASSERT(!list_empty(&h->loh_layers));
734 return container_of0(h->loh_layers.next, struct lu_object, lo_linkage);
738 * Next sub-object in the layering
740 static inline struct lu_object *lu_object_next(const struct lu_object *o)
742 return container_of0(o->lo_linkage.next, struct lu_object, lo_linkage);
746 * Pointer to the fid of this object.
748 static inline const struct lu_fid *lu_object_fid(const struct lu_object *o)
750 return &o->lo_header->loh_fid;
754 * return device operations vector for this object
756 static inline struct lu_device_operations *
757 lu_object_ops(const struct lu_object *o)
759 return o->lo_dev->ld_ops;
763 * Given a compound object, find its slice, corresponding to the device type
766 struct lu_object *lu_object_locate(struct lu_object_header *h,
767 struct lu_device_type *dtype);
769 struct lu_cdebug_print_info {
772 const char *lpi_file;
778 * Printer function emitting messages through libcfs_debug_msg().
780 int lu_cdebug_printer(const struct lu_env *env,
781 void *cookie, const char *format, ...);
783 #define DECLARE_LU_CDEBUG_PRINT_INFO(var, mask) \
784 struct lu_cdebug_print_info var = { \
785 .lpi_subsys = DEBUG_SUBSYSTEM, \
786 .lpi_mask = (mask), \
787 .lpi_file = __FILE__, \
788 .lpi_fn = __FUNCTION__, \
789 .lpi_line = __LINE__ \
793 * Print object description followed by user-supplied message.
795 #define LU_OBJECT_DEBUG(mask, env, object, format, ...) \
797 static DECLARE_LU_CDEBUG_PRINT_INFO(__info, mask); \
799 lu_object_print(env, &__info, lu_cdebug_printer, object); \
800 CDEBUG(mask, format , ## __VA_ARGS__); \
804 * Print human readable representation of the @o to the @f.
806 void lu_object_print(const struct lu_env *env, void *cookie,
807 lu_printer_t printer, const struct lu_object *o);
810 * Check object consistency.
812 int lu_object_invariant(const struct lu_object *o);
815 * Finalize and free devices in the device stack.
817 void lu_stack_fini(const struct lu_env *env, struct lu_device *top);
820 * Returns 1 iff object @o exists on the stable storage,
821 * returns -1 iff object @o is on remote server.
823 static inline int lu_object_exists(const struct lu_object *o)
827 attr = o->lo_header->loh_attr;
828 if (attr & LOHA_REMOTE)
830 else if (attr & LOHA_EXISTS)
836 static inline int lu_object_assert_exists(const struct lu_object *o)
838 return lu_object_exists(o) != 0;
841 static inline int lu_object_assert_not_exists(const struct lu_object *o)
843 return lu_object_exists(o) <= 0;
847 * Attr of this object.
849 static inline __u32 lu_object_attr(const struct lu_object *o)
851 LASSERT(lu_object_exists(o) > 0);
852 return o->lo_header->loh_attr;
856 /* input params, should be filled out by mdt */
857 __u64 rp_hash; /* hash */
858 int rp_count; /* count in bytes */
859 int rp_npages; /* number of pages */
860 struct page **rp_pages; /* pointers to pages */
863 enum lu_xattr_flags {
864 LU_XATTR_REPLACE = (1 << 0),
865 LU_XATTR_CREATE = (1 << 1)
868 /* For lu_context health-checks */
869 enum lu_context_state {
877 * lu_context. Execution context for lu_object methods. Currently associated
880 * All lu_object methods, except device and device type methods (called during
881 * system initialization and shutdown) are executed "within" some
882 * lu_context. This means, that pointer to some "current" lu_context is passed
883 * as an argument to all methods.
885 * All service ptlrpc threads create lu_context as part of their
886 * initialization. It is possible to create "stand-alone" context for other
887 * execution environments (like system calls).
889 * lu_object methods mainly use lu_context through lu_context_key interface
890 * that allows each layer to associate arbitrary pieces of data with each
891 * context (see pthread_key_create(3) for similar interface).
896 * Theoretically we'd want to use lu_objects and lu_contexts on the
897 * client side too. On the other hand, we don't want to allocate
898 * values of server-side keys for the client contexts and vice versa.
900 * To achieve this, set of tags in introduced. Contexts and keys are
901 * marked with tags. Key value are created only for context whose set
902 * of tags has non-empty intersection with one for key. Tags are taken
903 * from enum lu_context_tag.
907 * Pointer to the home service thread. NULL for other execution
910 struct ptlrpc_thread *lc_thread;
912 * Pointer to an array with key values. Internal implementation
916 enum lu_context_state lc_state;
920 * lu_context_key interface. Similar to pthread_key.
923 enum lu_context_tag {
925 * Thread on md server
927 LCT_MD_THREAD = 1 << 0,
929 * Thread on dt server
931 LCT_DT_THREAD = 1 << 1,
933 * Context for transaction handle
935 LCT_TX_HANDLE = 1 << 2,
939 LCT_CL_THREAD = 1 << 3,
941 * Per-request session on server
943 LCT_SESSION = 1 << 4,
945 * Don't add references for modules creating key values in that context.
946 * This is only for contexts used internally by lu_object framework.
950 * Contexts usable in cache shrinker thread.
952 LCT_SHRINKER = LCT_MD_THREAD|LCT_DT_THREAD|LCT_CL_THREAD|LCT_NOREF
956 * Key. Represents per-context value slot.
958 struct lu_context_key {
960 * Set of tags for which values of this key are to be instantiated.
964 * Value constructor. This is called when new value is created for a
965 * context. Returns pointer to new value of error pointer.
967 void *(*lct_init)(const struct lu_context *ctx,
968 struct lu_context_key *key);
970 * Value destructor. Called when context with previously allocated
971 * value of this slot is destroyed. @data is a value that was returned
972 * by a matching call to ->lct_init().
974 void (*lct_fini)(const struct lu_context *ctx,
975 struct lu_context_key *key, void *data);
977 * Optional method called on lu_context_exit() for all allocated
978 * keys. Can be used by debugging code checking that locks are
981 void (*lct_exit)(const struct lu_context *ctx,
982 struct lu_context_key *key, void *data);
984 * Internal implementation detail: index within ->lc_value[] reserved
989 * Internal implementation detail: number of values created for this
994 * Internal implementation detail: module for this key.
996 struct module *lct_owner;
999 #define LU_KEY_INIT(mod, type) \
1000 static void* mod##_key_init(const struct lu_context *ctx, \
1001 struct lu_context_key *key) \
1005 CLASSERT(CFS_PAGE_SIZE >= sizeof (*value)); \
1007 OBD_ALLOC_PTR(value); \
1008 if (value == NULL) \
1009 value = ERR_PTR(-ENOMEM); \
1013 struct __##mod##__dummy_init {;} /* semicolon catcher */
1015 #define LU_KEY_FINI(mod, type) \
1016 static void mod##_key_fini(const struct lu_context *ctx, \
1017 struct lu_context_key *key, void* data) \
1019 type *info = data; \
1021 OBD_FREE_PTR(info); \
1023 struct __##mod##__dummy_fini {;} /* semicolon catcher */
1025 #define LU_KEY_INIT_FINI(mod, type) \
1026 LU_KEY_INIT(mod,type); \
1027 LU_KEY_FINI(mod,type)
1029 #define LU_CONTEXT_KEY_DEFINE(mod, tags) \
1030 struct lu_context_key mod##_thread_key = { \
1032 .lct_init = mod##_key_init, \
1033 .lct_fini = mod##_key_fini \
1036 #define LU_CONTEXT_KEY_INIT(key) \
1038 (key)->lct_owner = THIS_MODULE; \
1045 int lu_context_key_register(struct lu_context_key *key);
1049 void lu_context_key_degister(struct lu_context_key *key);
1051 #define LU_KEY_REGISTER_GENERIC(mod) \
1052 static int mod##_key_register_generic(struct lu_context_key *k, ...) \
1054 struct lu_context_key* key = k; \
1058 va_start(args, k); \
1061 LU_CONTEXT_KEY_INIT(key); \
1062 result = lu_context_key_register(key); \
1065 key = va_arg(args, struct lu_context_key*); \
1066 } while (key != NULL); \
1071 va_start(args, k); \
1072 while (k != key) { \
1073 lu_context_key_degister(k); \
1074 k = va_arg(args, struct lu_context_key*); \
1082 #define LU_KEY_DEGISTER_GENERIC(mod) \
1083 static void mod##_key_degister_generic(struct lu_context_key *k, ...) \
1087 va_start(args, k); \
1090 lu_context_key_degister(k); \
1091 k = va_arg(args, struct lu_context_key*); \
1092 } while (k != NULL); \
1097 #define LU_TYPE_INIT(mod, ...) \
1098 LU_KEY_REGISTER_GENERIC(mod) \
1099 static int mod##_type_init(struct lu_device_type *t) \
1101 return mod##_key_register_generic(__VA_ARGS__, NULL); \
1103 struct __##mod##_dummy_type_init {;}
1105 #define LU_TYPE_FINI(mod, ...) \
1106 LU_KEY_DEGISTER_GENERIC(mod) \
1107 static void mod##_type_fini(struct lu_device_type *t) \
1109 mod##_key_degister_generic(__VA_ARGS__, NULL); \
1111 struct __##mod##_dummy_type_fini {;}
1113 #define LU_TYPE_INIT_FINI(mod, ...) \
1114 LU_TYPE_INIT(mod, __VA_ARGS__); \
1115 LU_TYPE_FINI(mod, __VA_ARGS__)
1118 * Return value associated with key @key in context @ctx.
1120 void *lu_context_key_get(const struct lu_context *ctx,
1121 struct lu_context_key *key);
1124 * Initialize context data-structure. Create values for all keys.
1126 int lu_context_init(struct lu_context *ctx, __u32 tags);
1128 * Finalize context data-structure. Destroy key values.
1130 void lu_context_fini(struct lu_context *ctx);
1133 * Called before entering context.
1135 void lu_context_enter(struct lu_context *ctx);
1137 * Called after exiting from @ctx
1139 void lu_context_exit(struct lu_context *ctx);
1142 * Allocate for context all missing keys that were registered after context
1145 int lu_context_refill(const struct lu_context *ctx);
1152 * "Local" context, used to store data instead of stack.
1154 struct lu_context le_ctx;
1156 * "Session" context for per-request data.
1158 struct lu_context *le_ses;
1161 int lu_env_init(struct lu_env *env, struct lu_context *ses, __u32 tags);
1162 void lu_env_fini(struct lu_env *env);
1165 * Common name structure to be passed around for various name related methods.
1173 * Common buffer structure to be passed around for various xattr_{s,g}et()
1181 extern struct lu_buf LU_BUF_NULL; /* null buffer */
1183 #define DLUBUF "(%p %z)"
1184 #define PLUBUF(buf) (buf)->lb_buf, (buf)->lb_len
1186 * One-time initializers, called at obdclass module initialization, not
1191 * Initialization of global lu_* data.
1193 int lu_global_init(void);
1196 * Dual to lu_global_init().
1198 void lu_global_fini(void);
1201 LU_TIME_FIND_LOOKUP,
1203 LU_TIME_FIND_INSERT,
1207 extern const char *lu_time_names[LU_TIME_NR];
1209 #endif /* __LUSTRE_LU_OBJECT_H */