From b1c77ec8dc1314c1538a163be21cbb3ff414a99a Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Mon, 15 Mar 2021 23:38:06 +0900 Subject: [PATCH] DDN-1956 audit: laudit.conf groks mount point Add a new field to laudit.conf, named "mount", that represents the mount path of the file system to retrieve audit information from. Change-Id: Ic02dc39e9a4e23286916bae92e9ee7a963406e3f Signed-off-by: Sebastien Buisson Reviewed-on: https://review.whamcloud.com/46906 Tested-by: jenkins Tested-by: Maloo Reviewed-by: John L. Hammond --- lipe/laudit.conf.example | 3 ++- lipe/man/laudit.conf.5 | 6 +++++- lipe/src/laudit-report.c | 36 ++++++++++++++++++++++++++++++------ lipe/src/laudit.c | 30 +++++++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/lipe/laudit.conf.example b/lipe/laudit.conf.example index 2be58297..aca7eb8 100644 --- a/lipe/laudit.conf.example +++ b/lipe/laudit.conf.example @@ -1,5 +1,6 @@ { - "fs_name": "lustre", + "fs_name": "testfs", + "mount": "/mnt/lustre/testfs", "dump_path": "/mnt/audit", "mdts": [ {"mdt_idx": 0, "reader_id": "cl1"}, diff --git a/lipe/man/laudit.conf.5 b/lipe/man/laudit.conf.5 index 4b311cf..2f4388e 100644 --- a/lipe/man/laudit.conf.5 +++ b/lipe/man/laudit.conf.5 @@ -18,6 +18,9 @@ is in JSON format. .B fs_name gives the name of the file system to retrieve audit information from. .PP +.B mount +gives the mount path of the file system to retrieve audit information from. +.PP .B dump_path is the path where to dump audit records. .PP @@ -44,7 +47,8 @@ limits the number of entries processed before interrupting the daemon. Process w Here is an example of laudit configuration file: .RS { - "fs_name": "lustre", + "fs_name": "testfs", + "mount": "/mnt/lustre/testfs", "dump_path": "/mnt/audit", "mdts": [ {"mdt_idx": 0, "reader_id": "cl1"}, diff --git a/lipe/src/laudit-report.c b/lipe/src/laudit-report.c index 637dbef..a21ca1b 100644 --- a/lipe/src/laudit-report.c +++ b/lipe/src/laudit-report.c @@ -33,6 +33,7 @@ struct mdt_desc { #define MAX_MDTS 256 struct audit_config { char fs_name[9]; + char mount[PATH_MAX + 1]; char dump_path[PATH_MAX + 1]; int parse_interval_sec; int sync_every_n_entries; @@ -96,7 +97,8 @@ void printinfo(char *format, ...) /* config file is in JSON format, of the form: * { - * "fs_name": "mylustre", + * "fs_name": "testfs", + * "mount": "/mnt/lustre/testfs", * "dump_path": "/mnt/audit1", * "mdts": [ * {"mdt_idx": "0", "reader_id": "cl1"}, @@ -109,7 +111,7 @@ void printinfo(char *format, ...) */ static int get_config(char *cfg_file) { - struct json_object *root, *fs_name, *dump_path, *mdts; + struct json_object *root, *fs_name, *mount, *dump_path, *mdts; struct json_object *parse_interval_sec, *sync_every_n_entries; struct json_object *max_syncs_before_sleep; int i; @@ -144,6 +146,27 @@ static int get_config(char *cfg_file) goto out; } + rc = json_object_object_get_ex(root, "mount", &mount); + if (!rc) { + fprintf(stderr, + "%s config error: %s does not have a mount entry\n", + progname, cfg_file); + goto out; + } + if (!json_object_is_type(mount, json_type_string)) { + fprintf(stderr, + "%s config error: mount is not a string\n", + progname); + goto out; + } + if (snprintf(cfg.mount, sizeof(cfg.mount), "%s", + json_object_get_string(mount)) >= sizeof(cfg.mount)) { + fprintf(stderr, + "%s config error: mount is too long\n", + progname); + goto out; + } + rc = json_object_object_get_ex(root, "dump_path", &dump_path); if (!rc) { fprintf(stderr, @@ -316,6 +339,7 @@ static void dump_config(void) return; printf("FS name: %s\n", cfg.fs_name); + printf("Mount path: %s\n", cfg.mount); printf("Dump path: %s\n", cfg.dump_path); for (idx = 0; idx < MAX_MDTS; idx++) { @@ -768,13 +792,13 @@ int browse_files_fid(char *file_to_audit, bool use_as_basename) if (strcmp(file_to_audit, base) == 0) { matches = true; - printinfo("\t%s /%s/%s\n", ep->d_name, - cfg.fs_name, line); + printinfo("\t%s %s/%s\n", ep->d_name, + cfg.mount, line); break; } } else { if (strcmp(line, file_to_audit + - strlen(cfg.fs_name) + 2) == 0) { + strlen(cfg.mount) + 1) == 0) { rc = get_audit_for_file(ep->d_name, user_to_audit); break; @@ -814,7 +838,7 @@ int find_fid_and_get_audit(char *file_to_audit, char *user_to_audit) char main_dir[PATH_MAX + 1]; int rc = 0; - rc = snprintf(main_dir, sizeof(main_dir), "/%s/", cfg.fs_name); + rc = snprintf(main_dir, sizeof(main_dir), "%s/", cfg.mount); if (rc >= sizeof(main_dir)) rc = -ENAMETOOLONG; if (rc < 0) { diff --git a/lipe/src/laudit.c b/lipe/src/laudit.c index 5c3bffe..23c43a8 100644 --- a/lipe/src/laudit.c +++ b/lipe/src/laudit.c @@ -47,6 +47,7 @@ struct mdt_desc { #define MAX_MDTS 256 struct audit_config { char fs_name[9]; + char mount[PATH_MAX + 1]; char dump_path[PATH_MAX + 1]; int parse_interval_sec; int sync_every_n_entries; @@ -189,6 +190,7 @@ void sig_stop_parsing(int signal) /* config file is in JSON format, of the form: * { * "fs_name": "mylustre", + * "mount": "/mnt/lustre/testfs", * "dump_path": "/mnt/audit1", * "mdts": [ * {"mdt_idx": "0", "reader_id": "cl1"}, @@ -201,7 +203,7 @@ void sig_stop_parsing(int signal) */ static int get_config(char *cfg_file) { - struct json_object *root, *fs_name, *dump_path, *mdts; + struct json_object *root, *fs_name, *mount, *dump_path, *mdts; struct json_object *parse_interval_sec, *sync_every_n_entries; struct json_object *max_syncs_before_sleep; int i; @@ -236,6 +238,27 @@ static int get_config(char *cfg_file) goto out; } + rc = json_object_object_get_ex(root, "mount", &mount); + if (!rc) { + fprintf(stderr, + "%s config error: %s does not have a mount entry\n", + progname, cfg_file); + goto out; + } + if (!json_object_is_type(mount, json_type_string)) { + fprintf(stderr, + "%s config error: mount is not a string\n", + progname); + goto out; + } + if (snprintf(cfg.mount, sizeof(cfg.mount), "%s", + json_object_get_string(mount)) >= sizeof(cfg.mount)) { + fprintf(stderr, + "%s config error: mount is too long\n", + progname); + goto out; + } + rc = json_object_object_get_ex(root, "dump_path", &dump_path); if (!rc) { fprintf(stderr, @@ -407,6 +430,7 @@ static void dump_config(void) return; printf("FS name: %s\n", cfg.fs_name); + printf("Mount path: %s\n", cfg.mount); printf("Dump path: %s\n", cfg.dump_path); for (idx = 0; idx < MAX_MDTS; idx++) { @@ -476,7 +500,7 @@ static int sanity_config(void) int sz_max; FILE *fp; - rc = snprintf(rootpath, sizeof(rootpath), "/%s", cfg.fs_name); + rc = snprintf(rootpath, sizeof(rootpath), "%s", cfg.mount); if (rc >= sizeof(rootpath)) rc = -ENAMETOOLONG; if (rc < 0) @@ -711,7 +735,7 @@ static int get_path_info(char *name, int namelen, char *tfidstr, char *pfidstr, rc = snprintf(tfid_pathinfo, sizeof(tfid_pathinfo), - "/%s/", cfg.fs_name); + "%s/", cfg.mount); if (rc >= sizeof(tfid_pathinfo)) rc = -ENAMETOOLONG; if (rc < 0) -- 1.8.3.1