1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/smfs/audit_mds.c
5 * Lustre filesystem audit part for MDS
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
25 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_SM
30 #include <linux/kmod.h>
31 #include <linux/init.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"
43 static int audit_ost_get_id(struct inode * inode, struct lustre_id * id)
45 struct fsfilt_operations *fsfilt = S2SMI(inode->i_sb)->sm_fsfilt;
48 if(fsfilt->fs_get_md(inode, id, sizeof(*id), EA_SID) <= 0)
53 static int audit_ost_create_rec(struct inode * parent, void * arg,
54 struct audit_priv * priv, char * buffer,
57 struct hook_msg * msg = arg;
58 struct audit_record * rec = (void*)buffer;
59 char * pbuf = buffer + sizeof(*rec);
60 struct inode * inode = msg->dentry->d_inode;
62 int len = sizeof(*rec);
64 if (audit_ost_get_id(inode, &id) < 0)
65 CERROR("Cannot get lustre id from object EA\n");
67 rec->opcode = AUDIT_CREATE;
68 len += audit_rec_from_id(&pbuf, &id);
69 *type = SMFS_AUDIT_GEN_REC;
73 static int audit_ost_unlink_rec(struct inode * parent, void * arg,
74 struct audit_priv * priv, char * buffer,
77 struct hook_unlink_msg * msg = arg;
78 struct inode * inode = msg->dentry->d_inode;
79 struct audit_record * rec = (void*)buffer;
80 char * pbuf = buffer + sizeof(*rec);
81 int len = sizeof(*rec);
84 if (audit_ost_get_id(inode, &id) < 0)
85 CERROR("Cannot get lustre id from object EA\n");
87 rec->opcode = AUDIT_UNLINK;
88 len += audit_rec_from_id(&pbuf, &id);
89 //len += audit_fill_id_rec(&pbuf, parent);
90 *type = SMFS_AUDIT_GEN_REC;
95 int static audit_ost_setattr_rec(struct inode * inode, void * arg,
96 struct audit_priv * priv, char * buffer,
99 //struct hook_attr_msg * msg = arg;
100 struct audit_record * rec = (void*)buffer;
101 char * pbuf = buffer + sizeof(*rec);
102 int len = sizeof(*rec);
105 if (audit_ost_get_id(inode, &id) < 0)
106 CERROR("Cannot get lustre id from object EA\n");
108 rec->opcode = AUDIT_SETATTR;
109 len += audit_rec_from_id(&pbuf, &id);
110 *type = SMFS_AUDIT_GEN_REC;
115 int static audit_ost_rw_rec(struct inode * inode, void * arg,
116 struct audit_priv * priv, char * buffer,
119 struct hook_rw_msg * msg = arg;
120 struct audit_record * rec = (void*)buffer;
121 char * pbuf = buffer + sizeof(*rec);
122 int len = sizeof(*rec);
125 if (audit_ost_get_id(inode, &id) < 0)
126 CERROR("Cannot get lustre id from object EA\n");
128 rec->opcode = msg->write ? AUDIT_WRITE : AUDIT_READ;
129 len += audit_rec_from_id(&pbuf, &id);
130 *type = SMFS_AUDIT_GEN_REC;
135 static audit_get_op audit_ost_record[HOOK_MAX] = {
136 [HOOK_SI_READ] audit_ost_rw_rec,
137 [HOOK_SI_WRITE] audit_ost_rw_rec,
138 [HOOK_READ] audit_ost_rw_rec,
139 [HOOK_WRITE] audit_ost_rw_rec,
140 [HOOK_CREATE] NULL, /* audit_ost_create_rec, */
141 [HOOK_UNLINK] audit_ost_unlink_rec,
142 [HOOK_SETATTR] audit_ost_setattr_rec,
143 [HOOK_F_SETATTR] audit_ost_setattr_rec
146 int audit_ost_setup(struct obd_device * obd, struct super_block *sb,
147 struct audit_priv *priv)
150 struct smfs_super_info * smb = S2SMI(sb);
151 struct llog_ctxt **ctxt = &priv->audit_ctxt;
153 //this will do OBD_ALLOC() for ctxt
154 rc = llog_catalog_setup(ctxt, AUDIT_OST_NAME, smb->smsi_exp,
155 smb->smsi_ctxt, smb->sm_fsfilt,
156 smb->smsi_logs_dir, smb->smsi_objects_dir);
158 /* export audit llog ctxt */
160 (*ctxt)->loc_idx = LLOG_AUDIT_ORIG_CTXT;
161 (*ctxt)->loc_obd = obd;
162 (*ctxt)->loc_llogs = &obd->obd_llogs;
163 (*ctxt)->loc_llogs->llog_ctxt[LLOG_AUDIT_ORIG_CTXT] = *ctxt;
166 priv->audit_get_record = audit_ost_record;