Whamcloud - gitweb
current branches now use lnet from HEAD
[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_get_id(struct inode * inode, struct lustre_id * id) 
44 {
45         struct fsfilt_operations *fsfilt = S2SMI(inode->i_sb)->sm_fsfilt;
46         
47         ENTRY;
48         if(fsfilt->fs_get_md(inode, id, sizeof(*id), EA_SID) <= 0)
49                 RETURN(-ENODATA);
50
51         RETURN(0);        
52 }
53 #if 0
54 static int audit_ost_create_rec(struct inode * parent, void * arg,
55                                 struct audit_priv * priv, char * buffer,
56                                 __u32 * type)
57 {
58         struct hook_msg * msg = arg;
59         struct audit_record * rec = (void*)buffer;
60         char * pbuf = buffer + sizeof(*rec); 
61         struct inode * inode = msg->dentry->d_inode;
62         struct lustre_id id;
63         int len = sizeof(*rec);
64
65         if (audit_ost_get_id(inode, &id) < 0) 
66                 CERROR("Cannot get lustre id from object EA\n");
67
68         rec->opcode = AUDIT_CREATE;
69         len += audit_rec_from_id(&pbuf, &id);
70         *type = SMFS_AUDIT_GEN_REC;
71         return len;
72 }
73
74 static int audit_ost_unlink_rec(struct inode * parent, void * arg,
75                                 struct audit_priv * priv, char * buffer,
76                                 __u32 *type)
77 {
78         struct hook_unlink_msg * msg = arg;
79         struct inode * inode = msg->dentry->d_inode;
80         struct audit_record * rec = (void*)buffer;
81         char * pbuf = buffer + sizeof(*rec);
82         int len = sizeof(*rec);
83         struct lustre_id id;
84         
85         if (audit_ost_get_id(inode, &id) < 0) 
86                 CERROR("Cannot get lustre id from object EA\n");
87
88         rec->opcode = AUDIT_UNLINK;
89         len += audit_rec_from_id(&pbuf, &id);
90         //len += audit_fill_id_rec(&pbuf, parent);
91         *type = SMFS_AUDIT_GEN_REC;
92         
93         return len;        
94 }
95
96 int static audit_ost_setattr_rec(struct inode * inode, void * arg, 
97                                  struct audit_priv * priv, char * buffer,
98                                  __u32 *type)
99 {
100         //struct hook_attr_msg * msg = arg;
101         struct audit_record * rec = (void*)buffer;
102         char * pbuf = buffer + sizeof(*rec);
103         int len = sizeof(*rec);
104         struct lustre_id id;
105         
106         if (audit_ost_get_id(inode, &id) < 0) 
107                 CERROR("Cannot get lustre id from object EA\n");
108
109         rec->opcode = AUDIT_SETATTR;
110         len += audit_rec_from_id(&pbuf, &id);
111         *type = SMFS_AUDIT_GEN_REC;
112                 
113         return len;
114 }
115 #endif
116 int static audit_ost_rw_rec(struct inode * inode, void * arg, 
117                             struct audit_priv * priv, char * buffer,
118                             __u32 * type)
119 {
120         struct hook_rw_msg * msg = arg;
121         struct audit_record * rec = (void*)buffer;
122         char * pbuf = buffer + sizeof(*rec); 
123         int len = sizeof(*rec);
124         struct lustre_id id;
125
126         if (audit_ost_get_id(inode, &id) < 0) 
127                 CERROR("Cannot get lustre id from object EA\n");
128
129         rec->opcode = msg->write ? AUDIT_WRITE : AUDIT_READ;
130         len += audit_rec_from_id(&pbuf, &id);
131         *type = SMFS_AUDIT_GEN_REC;
132         
133         return len;
134 }
135
136 static audit_get_op audit_ost_record[HOOK_MAX] = {
137         [HOOK_SI_READ]      audit_ost_rw_rec,
138         [HOOK_SI_WRITE]     audit_ost_rw_rec,
139         [HOOK_READ]         audit_ost_rw_rec,
140         [HOOK_WRITE]        audit_ost_rw_rec,
141         [HOOK_CREATE]       NULL, /* audit_ost_create_rec, */
142         [HOOK_UNLINK]       NULL, //audit_ost_unlink_rec,
143         [HOOK_SETATTR]      NULL, //audit_ost_setattr_rec,
144         [HOOK_F_SETATTR]    NULL, //audit_ost_setattr_rec
145 };
146
147 int audit_ost_setup(struct obd_device * obd, struct super_block *sb,
148                     struct audit_priv *priv) 
149 {
150         int rc;
151         struct smfs_super_info * smb = S2SMI(sb);
152         struct llog_ctxt **ctxt = &priv->audit_ctxt;
153         
154         //this will do OBD_ALLOC() for ctxt
155         rc = llog_catalog_setup(ctxt, AUDIT_OST_NAME, smb->smsi_exp,
156                                 smb->smsi_ctxt, smb->sm_fsfilt,
157                                 smb->smsi_logs_dir, smb->smsi_objects_dir);
158         
159         /* export audit llog ctxt */
160         if (*ctxt) {
161                 (*ctxt)->loc_idx = LLOG_AUDIT_ORIG_CTXT;
162                 (*ctxt)->loc_obd = obd;
163                 (*ctxt)->loc_llogs = &obd->obd_llogs;
164                 (*ctxt)->loc_llogs->llog_ctxt[LLOG_AUDIT_ORIG_CTXT] = *ctxt;
165         }
166         
167         priv->audit_get_record = audit_ost_record;
168         return 0;
169 }