1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * smfs data structures.
22 * See also lustre_idl.h for wire formats of requests.
29 #include <linux/lustre_audit.h>
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)
40 #define SMFS_SET(flags, mask) (flags |= mask)
41 #define SMFS_IS(flags, mask) (flags & mask)
42 #define SMFS_CLEAR(flags, mask) (flags &= ~mask)
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);
78 struct list_head plg_list;
81 smfs_plg_hook plg_pre_op;
82 smfs_plg_hook plg_post_op;
83 smfs_plg_func plg_helper;
85 int (* plg_exit)(struct super_block *, void *);
87 /* KML plugin stuff */
88 #define KML_LOG_NAME "smfs_kml"
91 /* llog pack function */
92 int (*pack_fn)(int, char *, struct dentry *,
93 struct inode *, void *, void *);
97 struct llog_ctxt *audit_ctxt;
98 void * audit_get_record;
103 typedef int (*audit_get_op)(struct inode *, void *, struct audit_priv *,
107 struct dentry * dentry;
111 struct hook_link_msg {
112 struct dentry * dentry;
113 struct dentry * new_dentry;
115 struct hook_unlink_msg {
116 struct dentry * dentry;
120 struct hook_symlink_msg {
121 struct dentry * dentry;
126 struct hook_rename_msg {
127 struct dentry * dentry;
128 struct inode * old_dir;
129 struct inode * new_dir;
130 struct dentry * new_dentry;
133 struct hook_readdir_msg {
134 struct dentry * dentry;
140 struct hook_write_msg {
141 struct dentry * dentry;
146 struct hook_attr_msg {
147 struct dentry * dentry;
151 struct hook_xattr_msg {
159 struct lustre_id *id;
162 void smfs_pre_hook (struct inode*, hook_op, void*);
163 void smfs_post_hook(struct inode*, hook_op, void*, int);
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)
169 #define PLG_TRANS_SIZE 1
170 #define PLG_TEST_INODE 2
171 #define PLG_SET_INODE 3
174 #define PLG_SET_INFO 6
175 #define PLG_HELPER_MAX 7
182 struct plg_info_msg {
186 int smfs_helper (struct super_block *, int, void *);
187 #define SMFS_PLG_HELP(sb, op, data) smfs_helper(sb, op, data)
189 int smfs_register_plugin(struct super_block *, struct smfs_plugin *);
190 struct smfs_plugin * smfs_deregister_plugin(struct super_block *, int);
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 *);
205 static inline int audit_rec_from_id (char **pbuf, struct lustre_id * id)
207 struct audit_id_record * rec = (void*)(*pbuf);
208 int len = sizeof(*rec);
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);
220 static inline int audit_fill_id_rec (char **pbuf, struct inode * inode)
222 struct fsfilt_operations *fsfilt = I2FOPS(inode);
223 struct audit_id_record * rec = (void*)(*pbuf);
224 int len = sizeof(*rec);
225 struct lustre_fid fid;
228 rec->au_num = inode->i_ino;
229 rec->au_type = (S_IFMT & inode->i_mode);
230 rec->au_gen = inode->i_generation;
233 rc = fsfilt->fs_get_md(I2CI(inode), &fid, sizeof(fid), EA_SID);
235 rec->au_fid = fid.lf_id;
236 rec->au_mds = fid.lf_group;
243 static inline int audit_fill_name_rec (char **pbuf, const char * name, int nlen)
245 struct audit_name_record * n_rec = (void*)(*pbuf);
246 int len = sizeof(*n_rec) + nlen;
248 memcpy(n_rec->name, name, nlen);
249 n_rec->name_len = nlen;