Whamcloud - gitweb
current branches now use lnet from HEAD
[fs/lustre-release.git] / lustre / smfs / smfs_api.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  *   smfs data structures.
22  *   See also lustre_idl.h for wire formats of requests.
23  *
24  */
25
26 #ifndef __SMFS_API_H
27 #define __SMFS_API_H
28
29 #include <linux/lustre_audit.h>
30
31 /* SMFS plugin stuff */
32 #define SMFS_PLG_KML    0x0001L
33 #define SMFS_PLG_LRU    0x0004L
34 #define SMFS_PLG_COW    0x0020L
35 #define SMFS_PLG_UNDO   0x0100L
36 #define SMFS_PLG_AUDIT  0x0200L
37 #define SMFS_PLG_DUMMY  0x1000L
38 #define SMFS_PLG_ALL    (~0L)
39
40 #define SMFS_SET(flags, mask) (flags |= mask)
41 #define SMFS_IS(flags, mask) (flags & mask)
42 #define SMFS_CLEAR(flags, mask) (flags &= ~mask)
43
44 typedef enum { 
45         HOOK_CREATE = 1,
46         HOOK_LOOKUP,
47         HOOK_LINK,
48         HOOK_UNLINK,
49         HOOK_SYMLINK,
50         HOOK_READLINK,
51         HOOK_MKDIR,
52         HOOK_RMDIR,
53         HOOK_MKNOD,
54         HOOK_RENAME,
55         HOOK_SETATTR,
56         HOOK_GETATTR,
57         HOOK_WRITE,
58         HOOK_READ,
59         HOOK_READDIR,
60         HOOK_F_SETATTR,
61         HOOK_SETXATTR,
62         HOOK_GETXATTR,
63         HOOK_REMOVEXATTR,
64         HOOK_LISTXATTR,
65         HOOK_F_SETXATTR,
66         HOOK_SI_READ,
67         HOOK_SI_WRITE,
68         HOOK_SPECIAL,
69         HOOK_MAX
70 } hook_op;
71
72 typedef int (*smfs_plg_hook)(hook_op hook_code, struct inode *,
73                              void *arg, int rc, void * priv);
74 typedef int (*smfs_plg_func)(int help_code, struct super_block *,
75                              void *arg, void * priv);
76
77 struct smfs_plugin {
78         struct list_head plg_list;
79         int              plg_type;
80
81         smfs_plg_hook    plg_pre_op;
82         smfs_plg_hook    plg_post_op;
83         smfs_plg_func    plg_helper;
84         void *           plg_private;
85         int (* plg_exit)(struct super_block *, void *);
86 };
87 /* KML plugin stuff */
88 #define KML_LOG_NAME    "smfs_kml"
89
90 struct kml_priv {
91         /* llog pack function */
92         int (*pack_fn)(int, char *, struct dentry *,
93                         struct inode *, void *, void *);
94 };
95
96 struct audit_priv {
97         struct llog_ctxt *audit_ctxt;
98         void * audit_get_record;
99         void * au_id2name;
100         int result;
101         int audit_null; //to prevent output to syslog. just for testing overhead
102         __u64 a_mask;
103 };
104
105 typedef int (*audit_get_op)(struct inode *, void *, struct audit_priv *,
106                             char *, __u32*);
107
108 struct hook_msg {
109         struct dentry * dentry;
110
111 };
112
113 struct hook_link_msg {
114         struct dentry * dentry;
115         struct dentry * new_dentry;
116 };
117 struct hook_unlink_msg {
118         struct dentry * dentry;
119         int mode;
120 };
121
122 struct hook_symlink_msg {
123         struct dentry * dentry;
124         int tgt_len;
125         char * symname;
126 };
127
128 struct hook_rename_msg {
129         struct dentry * dentry;
130         struct inode * old_dir;
131         struct inode * new_dir;
132         struct dentry * new_dentry;
133 };
134
135 struct hook_readdir_msg {
136         struct dentry * dentry;
137         struct file * filp;
138         void * dirent;
139         filldir_t filldir;
140 };
141
142 struct hook_write_msg {
143         struct dentry * dentry;
144         size_t count;
145         loff_t pos;
146 };
147
148 struct hook_attr_msg {
149         struct dentry * dentry;
150         struct iattr *attr;
151 };
152
153 struct hook_xattr_msg {
154         char * name;
155         char *buffer;
156         int  buffer_size;
157 };
158
159 struct hook_rw_msg {
160         int write;
161         struct lustre_id *id;
162 };
163
164 void smfs_pre_hook (struct inode*, hook_op, void*);
165 void smfs_post_hook(struct inode*, hook_op, void*, int);
166
167 #define SMFS_PRE_HOOK(inode, op, msg) smfs_pre_hook (inode, op, msg)
168 #define SMFS_POST_HOOK(inode, op, msg, rc) smfs_post_hook(inode, op, msg, rc)
169
170 #define PLG_EXIT        0
171 #define PLG_TRANS_SIZE  1
172 #define PLG_TEST_INODE  2
173 #define PLG_SET_INODE   3
174 #define PLG_START       4
175 #define PLG_STOP        5
176 #define PLG_SET_INFO    6
177 #define PLG_HELPER_MAX  7
178
179 struct plg_hmsg {
180         __u32 data;
181         __u32 result;        
182 };
183
184 struct plg_info_msg {
185         char * key;
186         void * val;
187 };
188 int smfs_helper (struct super_block *, int, void *);
189 #define SMFS_PLG_HELP(sb, op, data) smfs_helper(sb, op, data)
190
191 int smfs_register_plugin(struct super_block *, struct smfs_plugin *);
192 struct smfs_plugin * smfs_deregister_plugin(struct super_block *, int);
193
194 int smfs_init_dummy(struct super_block *);
195 int smfs_init_kml(struct super_block *);
196 int smfs_init_lru(struct super_block *);
197 int smfs_init_cow(struct super_block *);
198 int smfs_init_audit(struct super_block *);
199 //int audit_mds_op(hook_op, struct inode *, void *, struct audit_priv *);
200 int audit_client_log(struct super_block*, struct audit_msg *);
201 int audit_mds_setup(struct obd_device *, struct super_block *, struct audit_priv *);
202 int audit_ost_setup(struct obd_device *, struct super_block *, struct audit_priv *);
203 int smfs_set_audit(struct super_block *, struct inode *, __u64 *);
204 int smfs_get_audit(struct super_block *, struct inode *,
205                    struct inode *,  __u64 *);
206
207 static inline int audit_rec_from_id (char **pbuf, struct lustre_id * id)
208 {
209         struct audit_id_record * rec = (void*)(*pbuf);
210         int len = sizeof(*rec);
211
212         rec->au_num = id_ino(id);
213         rec->au_fid = id_fid(id);
214         rec->au_gen = id_gen(id);
215         rec->au_type = id_type(id);
216         rec->au_mds = id_group(id);
217         
218         *pbuf += len;
219         return len;
220 }
221
222 static inline int audit_fill_name_rec (char **pbuf, const char * name, int nlen) 
223 {
224         struct audit_name_record * n_rec = (void*)(*pbuf);
225         int len = sizeof(*n_rec) + nlen;
226         
227         memcpy(n_rec->name, name, nlen);
228         n_rec->name_len = nlen;
229
230         *pbuf += len;
231         return len;
232 }
233
234 #endif