Whamcloud - gitweb
b81b21d0503caeb63e84235de9767e89bc9e850c
[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         __u64 a_mask;
102 };
103 typedef int (*audit_get_op)(struct inode *, void *, struct audit_priv *,
104                             char *, __u32*);
105
106 struct hook_msg {
107         struct dentry * dentry;
108
109 };
110
111 struct hook_link_msg {
112         struct dentry * dentry;
113         struct dentry * new_dentry;
114 };
115 struct hook_unlink_msg {
116         struct dentry * dentry;
117         int mode;
118 };
119
120 struct hook_symlink_msg {
121         struct dentry * dentry;
122         int tgt_len;
123         char * symname;
124 };
125
126 struct hook_rename_msg {
127         struct dentry * dentry;
128         struct inode * old_dir;
129         struct inode * new_dir;
130         struct dentry * new_dentry;
131 };
132
133 struct hook_readdir_msg {
134         struct dentry * dentry;
135         struct file * filp;
136         void * dirent;
137         filldir_t filldir;
138 };
139
140 struct hook_write_msg {
141         struct dentry * dentry;
142         size_t count;
143         loff_t pos;
144 };
145
146 struct hook_attr_msg {
147         struct dentry * dentry;
148         struct iattr *attr;
149 };
150
151 struct hook_xattr_msg {
152         char * name;
153         char *buffer;
154         int  buffer_size;
155 };
156
157 struct hook_rw_msg {
158         int write;
159         struct lustre_id *id;
160 };
161
162 void smfs_pre_hook (struct inode*, hook_op, void*);
163 void smfs_post_hook(struct inode*, hook_op, void*, int);
164
165 #define SMFS_PRE_HOOK(inode, op, msg) smfs_pre_hook (inode, op, msg)
166 #define SMFS_POST_HOOK(inode, op, msg, rc) smfs_post_hook(inode, op, msg, rc)
167
168 #define PLG_EXIT        0
169 #define PLG_TRANS_SIZE  1
170 #define PLG_TEST_INODE  2
171 #define PLG_SET_INODE   3
172 #define PLG_START       4
173 #define PLG_STOP        5
174 #define PLG_SET_INFO    6
175 #define PLG_HELPER_MAX  7
176
177 struct plg_hmsg {
178         __u32 data;
179         __u32 result;        
180 };
181
182 struct plg_info_msg {
183         char * key;
184         void * val;
185 };
186 int smfs_helper (struct super_block *, int, void *);
187 #define SMFS_PLG_HELP(sb, op, data) smfs_helper(sb, op, data)
188
189 int smfs_register_plugin(struct super_block *, struct smfs_plugin *);
190 struct smfs_plugin * smfs_deregister_plugin(struct super_block *, int);
191
192 int smfs_init_dummy(struct super_block *);
193 int smfs_init_kml(struct super_block *);
194 int smfs_init_lru(struct super_block *);
195 int smfs_init_cow(struct super_block *);
196 int smfs_init_audit(struct super_block *);
197 //int audit_mds_op(hook_op, struct inode *, void *, struct audit_priv *);
198 int audit_client_log(struct super_block*, struct audit_msg *);
199 int audit_mds_setup(struct obd_device *, struct super_block *, struct audit_priv *);
200 int audit_ost_setup(struct obd_device *, struct super_block *, struct audit_priv *);
201 int smfs_set_audit(struct super_block *, struct inode *, __u64 *);
202 int smfs_get_audit(struct super_block *, struct inode *,
203                    struct inode *,  __u64 *);
204
205 static inline int audit_rec_from_id (char **pbuf, struct lustre_id * id)
206 {
207         struct audit_id_record * rec = (void*)(*pbuf);
208         int len = sizeof(*rec);
209
210         rec->au_num = id_ino(id);
211         rec->au_fid = id_fid(id);
212         rec->au_gen = id_gen(id);
213         rec->au_type = id_type(id);
214         rec->au_mds = id_group(id);
215         
216         *pbuf += len;
217         return len;
218 }
219
220 static inline int audit_fill_name_rec (char **pbuf, const char * name, int nlen) 
221 {
222         struct audit_name_record * n_rec = (void*)(*pbuf);
223         int len = sizeof(*n_rec) + nlen;
224         
225         memcpy(n_rec->name, name, nlen);
226         n_rec->name_len = nlen;
227
228         *pbuf += len;
229         return len;
230 }
231
232 #endif