Whamcloud - gitweb
b=5881
[fs/lustre-release.git] / lustre / smfs / smfs_api.h
1 /* SMFS plugin stuff */
2 #define SMFS_PLG_DUMMY  0x0001L
3 #define SMFS_PLG_KML    0x0002L
4 #define SMFS_PLG_LRU    0x0004L
5 #define SMFS_PLG_COW    0x0008L
6
7 #define SMFS_SET_PLG(flags, mask) (flags |= mask)
8 #define SMFS_IS_PLG(flags, mask) (flags & mask)
9 #define SMFS_CLEAR_PLG(flags, mask) (flags &= ~mask)
10
11 typedef int (*smfs_plg_hook)(int hook_code, struct inode *,
12                              void *arg, int rc, void * priv);
13 typedef int (*smfs_plg_func)(int help_code, struct super_block *,
14                              void *arg, void * priv);
15
16 struct smfs_plugin {
17         struct list_head plg_list;
18         int              plg_type;
19
20         smfs_plg_hook    plg_pre_op;
21         smfs_plg_hook    plg_post_op;
22         smfs_plg_func    plg_helper;
23         void *           plg_private;
24 };
25
26 #define HOOK_CREATE       1
27 #define HOOK_LOOKUP       2
28 #define HOOK_LINK         3
29 #define HOOK_UNLINK       4
30 #define HOOK_SYMLINK      5
31 #define HOOK_MKDIR        6
32 #define HOOK_RMDIR        7
33 #define HOOK_MKNOD        8
34 #define HOOK_RENAME       9
35 #define HOOK_SETATTR      10
36 #define HOOK_WRITE        11
37 #define HOOK_READDIR      12
38 #define HOOK_MAX          13
39
40 struct hook_msg {
41         struct dentry * dentry;
42 };
43
44 struct hook_unlink_msg {
45         struct dentry * dentry;
46         int mode;
47 };
48
49 struct hook_symlink_msg {
50         struct dentry * dentry;
51         int tgt_len;
52         char * symname;
53 };
54
55 struct hook_rename_msg {
56         struct dentry * dentry;
57         struct inode * new_dir;
58         struct dentry * new_dentry;
59 };
60
61 struct hook_readdir_msg {
62         struct dentry * dentry;
63         struct file * filp;
64         void * dirent;
65         filldir_t filldir;
66 };
67
68 struct hook_write_msg {
69         struct dentry * dentry;
70         size_t count;
71         loff_t pos;
72 };
73
74 struct hook_setattr_msg {
75         struct dentry * dentry;
76         struct iattr *attr;
77 };
78
79 #define SMFS_PRE_HOOK(inode, op, msg)                        \
80 do {                                                         \
81         struct smfs_super_info *smb = S2SMI(inode->i_sb);    \
82         struct list_head *hlist = &smb->smsi_plg_list;       \
83         struct smfs_plugin *plg;                             \
84                                                              \
85         list_for_each_entry(plg, hlist, plg_list) {          \
86                 if (plg->plg_pre_op)                         \
87                         plg->plg_pre_op(op, inode, msg, 0,   \
88                                         plg->plg_private);   \
89         }                                                    \
90 } while(0)
91
92 #define SMFS_POST_HOOK(inode, op, msg, rc)                   \
93 do {                                                         \
94         struct smfs_super_info *smb = S2SMI(inode->i_sb);    \
95         struct list_head *hlist = &smb->smsi_plg_list;       \
96         struct smfs_plugin *plg;                             \
97                                                              \
98         list_for_each_entry(plg, hlist, plg_list) {          \
99                 if (plg->plg_post_op)                        \
100                         plg->plg_post_op(op, inode, msg, rc, \
101                                          plg->plg_private);  \
102         }                                                    \
103 } while(0)
104
105 #define PLG_EXIT        0
106 #define PLG_TRANS_SIZE  1
107 #define PLG_TEST_INODE  2
108 #define PLG_SET_INODE   3
109 #define PLG_HELPER_MAX  4
110
111 #define SMFS_PLG_HELP(sb, op, data)                              \
112 do {                                                             \
113         struct list_head *hlist = &S2SMI(sb)->smsi_plg_list;     \
114         struct smfs_plugin *plugin, *tmp;                        \
115                                                                  \
116         list_for_each_entry_safe(plugin, tmp, hlist, plg_list) { \
117                 if (plugin->plg_helper)                          \
118                         plugin->plg_helper(op, sb, data,         \
119                                            plugin->plg_private); \
120         }                                                        \
121 } while(0)
122
123 int smfs_register_plugin(struct super_block *, struct smfs_plugin *);
124 void * smfs_deregister_plugin(struct super_block *, int);
125
126 int smfs_init_dummy(struct super_block *);
127 int smfs_init_kml(struct super_block *);
128 int smfs_init_lru(struct super_block *);
129 int smfs_init_cow(struct super_block *);
130