From 9dffcdd2fa07520aab89edd15f627518d3f6cff2 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Wed, 2 Aug 2017 23:47:47 +0900 Subject: [PATCH] LU-9727 lustre: record if enable_audit is set on nodemap Record changelogs from a client only if it pertains to a nodemap on which enable_audit is set, and changelogs are activated. If client is not explicitely assigned to a nodemap, enable_audit value from default nodemap is used. Signed-off-by: Sebastien Buisson Change-Id: I31d361cfd8cc69db68b60298934cbbef4af0d75d Reviewed-on: https://review.whamcloud.com/28314 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Li Xi --- lustre/include/md_object.h | 1 + lustre/mdd/mdd_dir.c | 4 ++-- lustre/mdd/mdd_internal.h | 9 +++++++++ lustre/mdd/mdd_object.c | 4 ++-- lustre/mdt/mdt_coordinator.c | 2 ++ lustre/mdt/mdt_lib.c | 19 +++++++++++++++++++ 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lustre/include/md_object.h b/lustre/include/md_object.h index 545a827..e46c05e 100644 --- a/lustre/include/md_object.h +++ b/lustre/include/md_object.h @@ -676,6 +676,7 @@ struct lu_ucred { struct md_identity *uc_identity; char uc_jobid[LUSTRE_JOBID_SIZE]; lnet_nid_t uc_nid; + bool uc_enable_audit; }; struct lu_ucred *lu_ucred(const struct lu_env *env); diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index f783798..a8554f7 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -767,7 +767,7 @@ int mdd_declare_changelog_store(const struct lu_env *env, int rc; /* Not recording */ - if (!(mdd->mdd_cl.mc_flags & CLM_ON)) + if (!recording_changelog(env, mdd)) return 0; reclen = mdd_llog_record_calc_size(env, tname, sname); @@ -1109,7 +1109,7 @@ int mdd_changelog_ns_store(const struct lu_env *env, ENTRY; /* Not recording */ - if (!(mdd->mdd_cl.mc_flags & CLM_ON)) + if (!recording_changelog(env, mdd)) RETURN(0); if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0) diff --git a/lustre/mdd/mdd_internal.h b/lustre/mdd/mdd_internal.h index a8befd5..cc43611 100644 --- a/lustre/mdd/mdd_internal.h +++ b/lustre/mdd/mdd_internal.h @@ -742,4 +742,13 @@ int mdo_destroy(const struct lu_env *env, struct mdd_object *o, return dt_destroy(env, next, handle); } +static inline int recording_changelog(const struct lu_env *env, + struct mdd_device *mdd) +{ + const struct lu_ucred *uc = lu_ucred_check(env); + + return (mdd->mdd_cl.mc_flags & CLM_ON) && + (uc ? uc->uc_enable_audit : 1); +} + #endif diff --git a/lustre/mdd/mdd_object.c b/lustre/mdd/mdd_object.c index d0539fe..d55cfd7 100644 --- a/lustre/mdd/mdd_object.c +++ b/lustre/mdd/mdd_object.c @@ -923,7 +923,7 @@ int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd, LASSERT(handle != NULL); /* Not recording */ - if (!(mdd->mdd_cl.mc_flags & CLM_ON)) + if (!recording_changelog(env, mdd)) RETURN(0); if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0) RETURN(0); @@ -995,7 +995,7 @@ static int mdd_changelog(const struct lu_env *env, enum changelog_rec_type type, ENTRY; /* Not recording */ - if (!(mdd->mdd_cl.mc_flags & CLM_ON)) + if (!recording_changelog(env, mdd)) RETURN(0); if (!(mdd->mdd_cl.mc_mask & (1 << type))) RETURN(0); diff --git a/lustre/mdt/mdt_coordinator.c b/lustre/mdt/mdt_coordinator.c index 4c4fed3..6a7782e 100644 --- a/lustre/mdt/mdt_coordinator.c +++ b/lustre/mdt/mdt_coordinator.c @@ -948,6 +948,8 @@ static int hsm_init_ucred(struct lu_ucred *uc) uc->uc_umask = 0777; uc->uc_ginfo = NULL; uc->uc_identity = NULL; + /* always record internal HSM activity if also enabled globally */ + uc->uc_enable_audit = 1; RETURN(0); } diff --git a/lustre/mdt/mdt_lib.c b/lustre/mdt/mdt_lib.c index 70935d0..aa0c25c 100644 --- a/lustre/mdt/mdt_lib.c +++ b/lustre/mdt/mdt_lib.c @@ -149,6 +149,23 @@ static void ucred_set_nid(struct mdt_thread_info *info, struct lu_ucred *uc) uc->uc_nid = LNET_NID_ANY; } +static void ucred_set_audit_enabled(struct mdt_thread_info *info, + struct lu_ucred *uc) +{ + struct lu_nodemap *nodemap = NULL; + bool audit = true; + + if (info && info->mti_exp) { + nodemap = nodemap_get_from_exp(info->mti_exp); + if (nodemap && !IS_ERR(nodemap)) { + audit = nodemap->nmf_enable_audit; + nodemap_putref(nodemap); + } + } + + uc->uc_enable_audit = audit; +} + static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type, void *buf, bool drop_fs_cap) { @@ -308,6 +325,7 @@ static int new_init_ucred(struct mdt_thread_info *info, ucred_init_type_t type, ucred->uc_valid = UCRED_NEW; ucred_set_jobid(info, ucred); ucred_set_nid(info, ucred); + ucred_set_audit_enabled(info, ucred); EXIT; @@ -481,6 +499,7 @@ static int old_init_ucred_common(struct mdt_thread_info *info, uc->uc_valid = UCRED_OLD; ucred_set_jobid(info, uc); ucred_set_nid(info, uc); + ucred_set_audit_enabled(info, uc); EXIT; -- 1.8.3.1