Whamcloud - gitweb
- b_hd_audit landing
[fs/lustre-release.git] / lustre / smfs / audit_ost.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/smfs/audit_mds.c
5  *  Lustre filesystem audit part for MDS
6  *
7  *  Copyright (C) 2004 Cluster File Systems, Inc.
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 #ifndef EXPORT_SYMTAB
25 # define EXPORT_SYMTAB
26 #endif
27
28 #define DEBUG_SUBSYSTEM S_SM
29
30 #include <linux/kmod.h>
31 #include <linux/init.h>
32 #include <linux/fs.h>
33 #include <linux/slab.h>
34 #include <linux/obd_class.h>
35 #include <linux/obd.h>
36 #include <linux/lustre_lib.h>
37 #include <linux/lustre_log.h>
38 #include <linux/lustre_fsfilt.h>
39 #include <linux/lustre_smfs.h>
40 #include <linux/lustre_audit.h>
41 #include "smfs_internal.h"
42
43 static int audit_ost_create_rec(struct inode * parent, void * arg,
44                                 struct audit_priv * priv, char * buffer,
45                                 __u32 * type)
46 {
47         struct hook_msg * msg = arg;
48         struct audit_record * rec = (void*)buffer;
49         char * pbuf = buffer + sizeof(*rec); 
50         struct inode * inode = msg->dentry->d_inode;
51         int len = sizeof(*rec);
52
53         //TODO: useless until lustre inode id is in EA
54         rec->opcode = AUDIT_CREATE;
55         len += audit_fill_id_rec(&pbuf, inode);
56         *type = SMFS_AUDIT_GEN_REC;
57         return len;
58 }
59
60 static int audit_ost_unlink_rec(struct inode * parent, void * arg,
61                                 struct audit_priv * priv, char * buffer,
62                                 __u32 *type)
63 {
64         struct hook_unlink_msg * msg = arg;
65         struct inode * inode = msg->dentry->d_inode;
66         struct audit_record * rec = (void*)buffer;
67         char * pbuf = buffer + sizeof(*rec);
68         int len = sizeof(*rec);
69         
70         //TODO: useless until lustre inode id is in EA
71         rec->opcode = AUDIT_UNLINK;                
72         len += audit_fill_id_rec(&pbuf, inode);
73         len += audit_fill_id_rec(&pbuf, parent);
74         *type = SMFS_AUDIT_GEN_REC;
75         
76         return len;        
77 }
78
79 int static audit_ost_setattr_rec(struct inode * inode, void * arg, 
80                                  struct audit_priv * priv, char * buffer,
81                                  __u32 *type)
82 {
83         //struct hook_attr_msg * msg = arg;
84         struct audit_record * rec = (void*)buffer;
85         char * pbuf = buffer + sizeof(*rec);
86         int len = sizeof(*rec);
87         
88         //TODO: useless until lustre inode id is in EA
89         rec->opcode = AUDIT_SETATTR;
90         len += audit_fill_id_rec(&pbuf, inode);
91         *type = SMFS_AUDIT_GEN_REC;
92                 
93         return len;
94 }
95
96 int static audit_ost_rw_rec(struct inode * inode, void * arg, 
97                             struct audit_priv * priv, char * buffer,
98                             __u32 * type)
99 {
100         struct hook_rw_msg * msg = arg;
101         struct audit_record * rec = (void*)buffer;
102         char * pbuf = buffer + sizeof(*rec); 
103         int len = sizeof(*rec);
104
105         rec->opcode = msg->write ? AUDIT_WRITE : AUDIT_READ;
106         len += audit_rec_from_id(&pbuf, msg->id);
107         *type = SMFS_AUDIT_GEN_REC;
108         
109         return len;
110 }
111
112 static audit_get_op audit_ost_record[HOOK_MAX] = {
113         [HOOK_SI_READ]      audit_ost_rw_rec,
114         [HOOK_SI_WRITE]     audit_ost_rw_rec,
115         [HOOK_CREATE]       audit_ost_create_rec,
116         [HOOK_UNLINK]       audit_ost_unlink_rec,
117         [HOOK_SETATTR]      audit_ost_setattr_rec,
118         [HOOK_F_SETATTR]    audit_ost_setattr_rec
119 };
120
121 int audit_ost_setup(struct obd_device * obd, struct super_block *sb,
122                     struct audit_priv *priv) 
123 {
124         int rc;
125         struct smfs_super_info * smb = S2SMI(sb);
126         struct llog_ctxt **ctxt = &priv->audit_ctxt;
127         
128         //this will do OBD_ALLOC() for ctxt
129         rc = llog_catalog_setup(ctxt, AUDIT_OST_NAME, smb->smsi_exp,
130                                 smb->smsi_ctxt, smb->sm_fsfilt,
131                                 smb->smsi_logs_dir, smb->smsi_objects_dir);
132         
133         /* export audit llog ctxt */
134         if (*ctxt) {
135                 (*ctxt)->loc_idx = LLOG_AUDIT_ORIG_CTXT;
136                 (*ctxt)->loc_obd = obd;
137                 (*ctxt)->loc_llogs = &obd->obd_llogs;
138                 (*ctxt)->loc_llogs->llog_ctxt[LLOG_AUDIT_ORIG_CTXT] = *ctxt;
139         }
140         
141         priv->audit_get_record = audit_ost_record;
142         return 0;
143 }