xref: /openbmc/linux/drivers/md/dm-audit.h (revision 2cc1ae48)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Creating audit records for mapped devices.
4  *
5  * Copyright (C) 2021 Fraunhofer AISEC. All rights reserved.
6  *
7  * Authors: Michael Weiß <michael.weiss@aisec.fraunhofer.de>
8  */
9 
10 #ifndef DM_AUDIT_H
11 #define DM_AUDIT_H
12 
13 #include <linux/device-mapper.h>
14 #include <linux/audit.h>
15 
16 #ifdef CONFIG_DM_AUDIT
17 void dm_audit_log_bio(const char *dm_msg_prefix, const char *op,
18 		      struct bio *bio, sector_t sector, int result);
19 
20 /*
21  * dm_audit_log_ti() is not intended to be used directly in dm modules,
22  * the wrapper functions below should be called by dm modules instead.
23  */
24 void dm_audit_log_ti(int audit_type, const char *dm_msg_prefix, const char *op,
25 		     struct dm_target *ti, int result);
26 
dm_audit_log_ctr(const char * dm_msg_prefix,struct dm_target * ti,int result)27 static inline void dm_audit_log_ctr(const char *dm_msg_prefix,
28 				    struct dm_target *ti, int result)
29 {
30 	dm_audit_log_ti(AUDIT_DM_CTRL, dm_msg_prefix, "ctr", ti, result);
31 }
32 
dm_audit_log_dtr(const char * dm_msg_prefix,struct dm_target * ti,int result)33 static inline void dm_audit_log_dtr(const char *dm_msg_prefix,
34 				    struct dm_target *ti, int result)
35 {
36 	dm_audit_log_ti(AUDIT_DM_CTRL, dm_msg_prefix, "dtr", ti, result);
37 }
38 
dm_audit_log_target(const char * dm_msg_prefix,const char * op,struct dm_target * ti,int result)39 static inline void dm_audit_log_target(const char *dm_msg_prefix, const char *op,
40 				       struct dm_target *ti, int result)
41 {
42 	dm_audit_log_ti(AUDIT_DM_EVENT, dm_msg_prefix, op, ti, result);
43 }
44 #else
dm_audit_log_bio(const char * dm_msg_prefix,const char * op,struct bio * bio,sector_t sector,int result)45 static inline void dm_audit_log_bio(const char *dm_msg_prefix, const char *op,
46 				    struct bio *bio, sector_t sector,
47 				    int result)
48 {
49 }
dm_audit_log_target(const char * dm_msg_prefix,const char * op,struct dm_target * ti,int result)50 static inline void dm_audit_log_target(const char *dm_msg_prefix,
51 				       const char *op, struct dm_target *ti,
52 				       int result)
53 {
54 }
dm_audit_log_ctr(const char * dm_msg_prefix,struct dm_target * ti,int result)55 static inline void dm_audit_log_ctr(const char *dm_msg_prefix,
56 				    struct dm_target *ti, int result)
57 {
58 }
59 
dm_audit_log_dtr(const char * dm_msg_prefix,struct dm_target * ti,int result)60 static inline void dm_audit_log_dtr(const char *dm_msg_prefix,
61 				    struct dm_target *ti, int result)
62 {
63 }
64 #endif
65 
66 #endif
67