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_create_rec(struct inode * parent, void * arg,
44 struct audit_priv * priv, char * buffer,
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);
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;
60 static int audit_ost_unlink_rec(struct inode * parent, void * arg,
61 struct audit_priv * priv, char * buffer,
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);
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;
79 int static audit_ost_setattr_rec(struct inode * inode, void * arg,
80 struct audit_priv * priv, char * buffer,
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);
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;
96 int static audit_ost_rw_rec(struct inode * inode, void * arg,
97 struct audit_priv * priv, char * buffer,
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);
105 rec->opcode = msg->write ? AUDIT_WRITE : AUDIT_READ;
106 len += audit_rec_from_id(&pbuf, msg->id);
107 *type = SMFS_AUDIT_GEN_REC;
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
121 int audit_ost_setup(struct obd_device * obd, struct super_block *sb,
122 struct audit_priv *priv)
125 struct smfs_super_info * smb = S2SMI(sb);
126 struct llog_ctxt **ctxt = &priv->audit_ctxt;
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);
133 /* export audit llog 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;
141 priv->audit_get_record = audit_ost_record;