Whamcloud - gitweb
b=15625
[fs/lustre-release.git] / lustre / include / lustre_handles.h
1 #ifndef __LUSTRE_HANDLES_H_
2 #define __LUSTRE_HANDLES_H_
3
4 #if defined(__linux__)
5 #include <linux/lustre_handles.h>
6 #elif defined(__APPLE__)
7 #include <darwin/lustre_handles.h>
8 #elif defined(__WINNT__)
9 #include <winnt/lustre_handles.h>
10 #else
11 #error Unsupported operating system.
12 #endif
13
14 typedef void (*portals_handle_addref_cb)(void *object);
15
16 /* These handles are most easily used by having them appear at the very top of
17  * whatever object that you want to make handles for.  ie:
18  *
19  * struct ldlm_lock {
20  *         struct portals_handle handle;
21  *         ...
22  * };
23  *
24  * Now you're able to assign the results of cookie2handle directly to an
25  * ldlm_lock.  If it's not at the top, you'll want to hack up a macro that
26  * uses some offsetof() magic. */
27
28 struct portals_handle {
29         struct list_head h_link;
30         __u64 h_cookie;
31         portals_handle_addref_cb h_addref;
32
33         /* newly added fields to handle the RCU issue. -jxiong */
34         spinlock_t h_lock;
35         void *h_ptr;
36         void (*h_free_cb)(void *, size_t);
37         struct rcu_head h_rcu;
38         unsigned int h_size;
39         __u8 h_in:1;
40         __u8 h_unused[3];
41 };
42 #define RCU2HANDLE(rcu)    container_of(rcu, struct portals_handle, h_rcu)
43
44 /* handles.c */
45
46 /* Add a handle to the hash table */
47 void class_handle_hash(struct portals_handle *, portals_handle_addref_cb);
48 void class_handle_unhash(struct portals_handle *);
49 void class_handle_hash_back(struct portals_handle *);
50 void *class_handle2object(__u64 cookie);
51 void class_handle_free_cb(struct rcu_head *);
52 int class_handle_init(void);
53 void class_handle_cleanup(void);
54
55 #endif