From 5c545633369d9b382a74145d8e202e675b5e8356 Mon Sep 17 00:00:00 2001 From: tappro Date: Wed, 14 Sep 2005 11:43:30 +0000 Subject: [PATCH] b=8654 add audit flushing by demand. lctl flush_audit will flush audit messages to syslog --- lustre/include/linux/lustre_audit.h | 1 + lustre/llite/llite_audit.c | 3 +++ lustre/lmv/lmv_obd.c | 3 ++- lustre/smfs/audit.c | 9 ++++++++ lustre/smfs/audit_transfer.c | 41 +++++++++++++++++++++++-------------- lustre/utils/lctl.c | 25 ++++++++++++++++++++++ 6 files changed, 66 insertions(+), 16 deletions(-) diff --git a/lustre/include/linux/lustre_audit.h b/lustre/include/linux/lustre_audit.h index c605e3f..bb545d1 100644 --- a/lustre/include/linux/lustre_audit.h +++ b/lustre/include/linux/lustre_audit.h @@ -54,6 +54,7 @@ typedef enum { #define AUDIT_FAIL AUDIT_MAX #define AUDIT_DIR (AUDIT_MAX + 1) #define AUDIT_FS (AUDIT_MAX + 2) +#define AUDIT_SYNC (AUDIT_MAX + 3) #define AUD_BIT(a) (1 << a) diff --git a/lustre/llite/llite_audit.c b/lustre/llite/llite_audit.c index c09107a..e5e3f4c 100644 --- a/lustre/llite/llite_audit.c +++ b/lustre/llite/llite_audit.c @@ -54,6 +54,9 @@ int ll_set_audit(struct inode * inode, __u64 arg) sbi->ll_audit_mask = arg; exp = ll_i2dtexp(inode); rc = obd_set_info(exp, 5, "audit", sizeof(msg), &msg); + } else if (IS_AUDIT_OP(arg, AUDIT_SYNC)) { + exp = ll_i2dtexp(inode); + rc = obd_set_info(exp, 5, "audit", sizeof(msg), &msg); } else { lli->lli_audit_mask = arg; } diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 361a5fe..6532ec7 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -2128,7 +2128,8 @@ int lmv_set_info(struct obd_export *exp, obd_count keylen, int i; LASSERT(mds < lmv->desc.ld_tgt_count); - if (IS_AUDIT_OP(msg->attr, AUDIT_FS)) { + if (IS_AUDIT_OP(msg->attr, AUDIT_FS) || + IS_AUDIT_OP(msg->attr, AUDIT_SYNC)) { //FS audit, send message to all mds for (i = 0; i < lmv->desc.ld_tgt_count;i++) { obd_set_info(lmv->tgts[i].ltd_exp, diff --git a/lustre/smfs/audit.c b/lustre/smfs/audit.c index bd6e2c2..73a6c35 100644 --- a/lustre/smfs/audit.c +++ b/lustre/smfs/audit.c @@ -283,6 +283,15 @@ int smfs_set_audit(struct super_block * sb, struct inode * inode, ENTRY; + if (IS_AUDIT_OP((*mask), AUDIT_SYNC)) { + struct audit_priv *priv; + + priv = smfs_get_plg_priv(S2SMI(sb), SMFS_PLG_AUDIT); + if (priv) + audit_notify(priv->audit_ctxt->loc_handle, NULL); + //to wait for flush + return audit_notify(NULL, NULL); + } if (IS_AUDIT_OP((*mask), AUDIT_FS)) return smfs_set_fs_audit(sb, mask); diff --git a/lustre/smfs/audit_transfer.c b/lustre/smfs/audit_transfer.c index 59db856..d971430 100644 --- a/lustre/smfs/audit_transfer.c +++ b/lustre/smfs/audit_transfer.c @@ -60,9 +60,25 @@ static DECLARE_MUTEX(transferd_sem); static int transferd_users = 0; char *buf = NULL; +static int transferd_check(struct transferd_ctl *tc) +{ + int rc = 0; + ENTRY; + + if (test_bit(TRANSFERD_STOP, &tc->tc_flags)) + RETURN(1); + + spin_lock(&tc->tc_lock); + rc = list_empty(&tc->tc_list) ? 0 : 1; + spin_unlock(&tc->tc_lock); + + RETURN(rc); +} + int audit_notify(struct llog_handle *llh, void * arg) { struct transfer_item *ti; + struct list_head tmp_list; ENTRY; down(&transferd_sem); @@ -90,6 +106,13 @@ int audit_notify(struct llog_handle *llh, void * arg) spin_unlock(&transferd_tc.tc_lock); wake_up(&transferd_tc.tc_waitq); + + if (llh == NULL) /* demand to flush list */ + { + struct l_wait_info lwi = { 0 }; + l_wait_event(transferd_tc.tc_waitq, + transferd_check(&transferd_tc), &lwi); + } RETURN(0); } @@ -235,6 +258,9 @@ static int audit_transfer(struct transfer_item *ti) struct llog_handle *llh = ti->ti_llh; int rc = 0; ENTRY; + + if (!llh) + RETURN(0); rc = llog_cat_process(llh, (llog_cb_t)&transfer_cb, ti->id2name); if (rc) @@ -243,21 +269,6 @@ static int audit_transfer(struct transfer_item *ti) RETURN(0); } -static int transferd_check(struct transferd_ctl *tc) -{ - int rc = 0; - ENTRY; - - if (test_bit(TRANSFERD_STOP, &tc->tc_flags)) - RETURN(1); - - spin_lock(&tc->tc_lock); - rc = list_empty(&tc->tc_list) ? 0 : 1; - spin_unlock(&tc->tc_lock); - - RETURN(rc); -} - static int transferd(void *arg) { struct transferd_ctl *tc = arg; diff --git a/lustre/utils/lctl.c b/lustre/utils/lctl.c index 8a3cfcf..042b41e 100644 --- a/lustre/utils/lctl.c +++ b/lustre/utils/lctl.c @@ -201,6 +201,29 @@ static int jt_set_fsaudit(int argc, char **argv) return set_audit(argc, argv, 1); } +static int jt_flush_audit(int argc, char **argv) +{ + __u64 mask = 0; + int rc, fd; + + if (argc != 2) + return CMD_HELP; + + //open file/dir + fd = open(argv[1], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "can't open: %s: %s\n", argv[1], + strerror(rc = errno)); + return -1; + } + + SET_AUDIT_OP(mask, AUDIT_SYNC); + + rc = ioctl(fd, LL_IOC_AUDIT, mask); + close(fd); + return rc; +} + /* * XXX Should not belong to here */ @@ -487,6 +510,8 @@ command_t cmdlist[] = { "usage: audit type operations filename\n"}, {"fs_audit", jt_set_fsaudit, 0, "usage: fs_audit type operations mountpoint\n"}, + {"flush_audit", jt_flush_audit, 0, + "usage: flush_audit mountpoin\n"}, {"lsync", jt_obd_reint_sync, 0, "usage: lsync\n"}, {"cache_on", jt_obd_cache_on, 0, -- 1.8.3.1