From: Lei Feng Date: Wed, 18 Aug 2021 09:19:46 +0000 (+0800) Subject: EX-3050 lipe: lpcc_purge supports version and revision X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=29e237ea547b0bf372d653761808261c54d2d97d;p=fs%2Flustre-release.git EX-3050 lipe: lpcc_purge supports version and revision Print unified lipe version and revision in lpcc_purge --version command and stats dumpfile. Change-Id: I78e500d4f765b638662a90f21f4e5d7ebd2209e2 Signed-off-by: Lei Feng Test-Parameters: trivial Reviewed-on: https://review.whamcloud.com/44699 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lipe/src/lpcc_purge.c b/lipe/src/lpcc_purge.c index 28f1122..0738d21 100644 --- a/lipe/src/lpcc_purge.c +++ b/lipe/src/lpcc_purge.c @@ -21,6 +21,7 @@ #include "debug.h" #include "lipe_object_attrs.h" +#include "lipe_version.h" #include "policy.h" @@ -43,6 +44,7 @@ #define OPT_LOG_LEVEL 4 #define OPT_MAX_SCAN_SECS 5 #define OPT_PIDFILE 6 +#define OPT_VERSION 7 #define LPCC_PURGE_LOG(level, fmt, ...) \ llapi_error((level) | LLAPI_MSG_NO_ERRNO, 0, fmt, ##__VA_ARGS__) @@ -244,6 +246,12 @@ static void lpcc_purge_dump_config_stats(FILE *f) json_object *j_all = json_object_new_object(); + /* version and revision */ + snprintf(buff, ARRAY_SIZE(buff), "%s-%s", PACKAGE_VERSION, LIPE_RELEASE); + json_object_object_add(j_all, "version", json_object_new_string(buff)); + json_object_object_add(j_all, "revison", json_object_new_string(LIPE_REVISION)); + + /* time, fsname, and cache usage */ curr = time(NULL); ctime_r(&curr, buff); buff[strlen(buff) - 1] = '\0'; @@ -258,6 +266,7 @@ static void lpcc_purge_dump_config_stats(FILE *f) usage = lpcc_purge_get_fs_usage(opt.o_cache); json_object_object_add(j_all, "cache_usage", json_object_new_double(usage)); + /* configuration */ json_object *j_config = json_object_new_object(); json_object_object_add(j_config, "mount", json_object_new_string(opt.o_mount)); json_object_object_add(j_config, "cache", json_object_new_string(opt.o_cache)); @@ -272,6 +281,7 @@ static void lpcc_purge_dump_config_stats(FILE *f) json_object_object_add(j_config, "log_level", json_object_new_string(log_level_to_str(llapi_msg_get_level()))); json_object_object_add(j_all, "config", j_config); + /* stats */ json_object *j_stats = json_object_new_object(); json_object_object_add(j_stats, "scan_times", json_object_new_int64(stats.s_scan_times)); json_object_object_add(j_stats, "total_purged_objs", json_object_new_int64(stats.s_total_purged_objs)); @@ -289,6 +299,7 @@ static void lpcc_purge_dump_config_stats(FILE *f) json_object_object_add(j_stats, "purged_objs", json_object_new_int64(stats.s_purged_objs)); json_object_object_add(j_all, "stats", j_stats); + /* convert the JSON object to string and print to file */ const char *str = json_object_to_json_string_ext(j_all, JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED | @@ -335,6 +346,7 @@ static void usage(void) "\t --pidfile=FILE, the pidfile name (default: /var/run/lpcc_purge-RWID.pid)\n" "\t --clear-hashdir, clear empty hash dir after detaching file\n" "\t --dry-run, scan once but do not detach file really\n" + "\t --version, print version information and exit\n" "\t-h, --help, print this help message\n", program_invocation_short_name, @@ -365,6 +377,7 @@ static struct option long_options[] = { { "pidfile", required_argument, NULL, OPT_PIDFILE}, { "clear-hashdir", no_argument, NULL, OPT_CLEAR_HASHDIR}, { "max-scan-secs", required_argument, NULL, OPT_MAX_SCAN_SECS}, + { "version", no_argument, NULL, OPT_VERSION}, { "help", no_argument, NULL, 'h' }, { NULL } }; @@ -626,6 +639,9 @@ static void lpcc_purge_process_opt(int c, char *optarg) } opt.o_max_scan_secs = value; break; + case OPT_VERSION: + lipe_version(); + exit(0); default: llapi_error(LLAPI_MSG_FATAL, -EINVAL, "invalid argument: '%s'",