Whamcloud - gitweb
DDN-1956 audit: laudit.conf groks mount point
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 15 Mar 2021 14:38:06 +0000 (23:38 +0900)
committerJohn L. Hammond <jhammond@whamcloud.com>
Fri, 25 Mar 2022 19:59:12 +0000 (19:59 +0000)
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 <sbuisson@ddn.com>
Reviewed-on: https://review.whamcloud.com/46906
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
lipe/laudit.conf.example
lipe/man/laudit.conf.5
lipe/src/laudit-report.c
lipe/src/laudit.c

index 2be5829..aca7eb8 100644 (file)
@@ -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"},
index 4b311cf..2f4388e 100644 (file)
@@ -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"},
index 637dbef..a21ca1b 100644 (file)
@@ -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) {
index 5c3bffe..23c43a8 100644 (file)
@@ -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)