From 5a7e314b167b740f9c5f9f0cd4e00e1542498e19 Mon Sep 17 00:00:00 2001 From: Vitaliy Kuznetsov Date: Fri, 1 Sep 2023 20:06:18 +0400 Subject: [PATCH] EX-8180 lipe: Fix typos, code style, size display in stats This patch fixes grammatical errors, incorrect display of statistics in some reports due to incorrect size alignment, indentation and alignment up to 80 characters where possible. Renamed some types and variable names. Added additional help information. Test-Parameters: trivial testlist=sanity-lipe-scan3 Signed-off-by: Vitaliy Kuznetsov Change-Id: I97692f006391ddfa5b6e474936e2a8edde69d8c8 Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/52221 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Patrick Farrell Reviewed-by: Andreas Dilger --- lipe/man/lipe_find3.1 | 11 +- lipe/src/lipe_scan3/ls3_main.c | 3 + lipe/src/lipe_scan3/ls3_scan.c | 4 + lipe/src/lipe_scan3/ls3_scan.h | 5 +- lipe/src/lipe_scan3/ls3_stats.c | 1307 +++++++++++++++++++++------------------ lipe/src/lipe_scan3/ls3_stats.h | 68 +- 6 files changed, 762 insertions(+), 636 deletions(-) diff --git a/lipe/man/lipe_find3.1 b/lipe/man/lipe_find3.1 index 6df62ae..74c9a2a 100644 --- a/lipe/man/lipe_find3.1 +++ b/lipe/man/lipe_find3.1 @@ -308,10 +308,13 @@ removed by the time the directory is encountered. .IP "\-collect-fsize-stats \fIreport_name\fR" Collect statistics about file size, and create file with report. -Save detailed statistics to a file, which can be used -when building visual schemes, and graphs. After specifying the option, -must specify the full correct path with the new file name that will -be created after finishing lipe_find3. +Save detailed statistics to a file, which can be used when building visual +schemes, and graphs. This also supports all filters lipe_find3 has. +For example, you can collect statistics on files for a specific user, +on a specific modification time, size, file name and other available +parameters in files. +After specifying the option, must specify the full correct +path with the new file name that will be created after finishing lipe_find3. The files sizes report file can be generated in 4 output options (out,yaml,json,csv). To specify the desired type of report, you need to specify the extension from the available ones (out, yaml, json, csv) in diff --git a/lipe/src/lipe_scan3/ls3_main.c b/lipe/src/lipe_scan3/ls3_main.c index caf9d24..bd58057 100644 --- a/lipe/src/lipe_scan3/ls3_main.c +++ b/lipe/src/lipe_scan3/ls3_main.c @@ -1017,6 +1017,9 @@ SCM_DEFINE(ls3_scm_collect_fsize_stats, LS3_COLLECT_STATS, 0, 1, 0, struct ls3_instance *li = ls3_instance(); reports_with_stats->device_path = xstrdup(li->li_device_path); reports_with_stats->device_name = xstrdup(li->li_device_name); + reports_with_stats->block_size = li->block_size; + reports_with_stats->inodes_count = li->inodes_count; + reports_with_stats->free_inodes_count = li->free_inodes_count; reports_with_stats->client_mount_path = xstrdup(li->li_client_mount_path); reports_with_stats->device_is_mdt = li->li_device_is_mdt; /* else OST */ diff --git a/lipe/src/lipe_scan3/ls3_scan.c b/lipe/src/lipe_scan3/ls3_scan.c index 670d112..08256ec 100644 --- a/lipe/src/lipe_scan3/ls3_scan.c +++ b/lipe/src/lipe_scan3/ls3_scan.c @@ -1266,6 +1266,7 @@ int ls3_scan(const char *device_path, struct ls3_instance li = { .li_device_path = xstrdup(device_path), .li_client_mount_fd = -1, + .block_size = 4096, /* Default 4k, but will also read below in code */ .li_scm_device_path = scm_from_latin1_string(device_path), .li_scm_device_name = scm_from_latin1_string(""), .li_scm_fsname = scm_from_latin1_string(""), @@ -1314,6 +1315,9 @@ retry_open: goto out; } + li.block_size = EXT2_BLOCK_SIZE(fs->super); + li.inodes_count = fs->super->s_inodes_count; + li.free_inodes_count = fs->super->s_free_inodes_count; li.li_device_name = xstrndup((const char *)fs->super->s_volume_name, sizeof(fs->super->s_volume_name)); LS3_DEBUG_S(li.li_device_name); diff --git a/lipe/src/lipe_scan3/ls3_scan.h b/lipe/src/lipe_scan3/ls3_scan.h index ffaf611..cc7cc38 100644 --- a/lipe/src/lipe_scan3/ls3_scan.h +++ b/lipe/src/lipe_scan3/ls3_scan.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include "ls3_object_attrs.h" @@ -29,7 +30,6 @@ struct lipe_object { struct lipe_object_ldiskfs lo_ldiskfs; } u; }; - struct ls3_instance { char *li_device_path; char *li_device_name; @@ -39,6 +39,9 @@ struct ls3_instance { int li_client_mount_fd; enum ls3_object_attr_bit li_required_attrs; unsigned int li_ext2_flags; + uint32_t block_size; + uint32_t inodes_count; + uint32_t free_inodes_count; const char *li_io_options; SCM li_scm_policy_thunk; SCM li_scm_device_path; diff --git a/lipe/src/lipe_scan3/ls3_stats.c b/lipe/src/lipe_scan3/ls3_stats.c index bb80c6d..b33ce23 100644 --- a/lipe/src/lipe_scan3/ls3_stats.c +++ b/lipe/src/lipe_scan3/ls3_stats.c @@ -38,34 +38,6 @@ int ls3_stats_get_range_index(uint64_t num) return (int)floor(log2(num)); } -/* Returns the size of the device in bytes if successful; otherwise, 0. - * - * @device_path: The path of the device. - */ -uint64_t ls3_stats_get_dev_size(const char* device_path) -{ - int device_fd = open(device_path, O_RDONLY); - - if (device_fd >= 0) { - uint64_t dev_size; - int res; - - res = ioctl(device_fd, BLKGETSIZE64, &dev_size); - if (res >= 0) - return dev_size; - else - LS3_ERROR("error obtaining device size: %s\n", - strerror(errno)); - - close(device_fd); - } else { - LS3_ERROR("error opening device %s for read size: %s\n", - device_path, strerror(errno)); - } - - return 0; -} - /* ls3_stats_get_day_diff - Calculates the time difference in * days between a given timestamp and the current real-time. * @@ -128,15 +100,15 @@ static void ls3_stats_remove_extension_in_file(char *file_path) static void ls3_stats_change_extension_in_file(int bit_extension) { - const ls3_stats_extension_mapping *map_ext = ext_mappings; + const ls3_stats_extension_mapping *ext = ext_mappings; - for (map_ext = ext_mappings; map_ext->extension_name != NULL; ++map_ext) { - if (map_ext->extension_value & bit_extension) { + for (ext = ext_mappings; ext->extension_name != NULL; ++ext) { + if (ext->extension_value & bit_extension) { char buffer[256]; snprintf(buffer, sizeof(buffer), "%s.%s", reports_with_stats->report_file_name, - map_ext->extension_name); + ext->extension_name); if (reports_with_stats->format_report_file_name) free(reports_with_stats->format_report_file_name); @@ -150,9 +122,9 @@ static void ls3_stats_change_extension_in_file(int bit_extension) static void ls3_stats_get_report_extension(char *fileName) { - const ls3_stats_extension_mapping *map_ext = ext_mappings; + const ls3_stats_extension_mapping *ext = ext_mappings; char *dot = strrchr(fileName, '.'); - char extension[5]; /* Don't need more 5 symbols */ + char extension[5]; /* Don't need more 5 symbols */ bool marker; int i; @@ -160,7 +132,7 @@ static void ls3_stats_get_report_extension(char *fileName) /* By default if filename not have extension */ reports_with_stats->report_extension |= LS3_STATS_FILE_EXTENSION_ALL; - return; + return; } strncpy(extension, dot+1, sizeof(extension)-1); @@ -168,10 +140,10 @@ static void ls3_stats_get_report_extension(char *fileName) for(i = 0; extension[i]; i++) extension[i] = tolower((unsigned char)extension[i]); - for (map_ext = ext_mappings; map_ext->extension_name != NULL; ++map_ext) { - if (strcmp(extension, map_ext->extension_name) == 0) { + for (ext = ext_mappings; ext->extension_name != NULL; ++ext) { + if (strcmp(extension, ext->extension_name) == 0) { reports_with_stats->report_extension |= - map_ext->extension_value; + ext->extension_value; marker = true; break; } @@ -186,6 +158,7 @@ static void ls3_stats_get_report_extension(char *fileName) static FILE* ls3_stats_open_file(char *file_name) { FILE *file = fopen(file_name, "w"); + if (file == NULL) LS3_FATAL("error opening file for save stats: %s\n", file_name); @@ -238,7 +211,8 @@ static void ls3_stats_prepare_file(void) strftime(file_name_buffer, sizeof(file_name_buffer), DEFAULT_DIR_FOR_REPORTS "file_size_report.%Y-%m-%d-%H:%M:%S.out", timeinfo); - reports_with_stats->report_file_name = xstrdup(file_name_buffer); + reports_with_stats->report_file_name = + xstrdup(file_name_buffer); } ls3_stats_get_report_extension(reports_with_stats->report_file_name); @@ -250,36 +224,40 @@ static ls3_stats_val_type ls3_stats_get_value_type( { switch (report_type) { - case LS3_STATS_FILES_SIZE: - case LS3_STATS_CAPACITY_USED: - case LS3_STATS_DIRECTORY_SIZE_KB: - case LS3_STATS_EQUAL_OVERHEAD: - case LS3_STATS_STORAGE_SET_SIZE_BY_USER: - case LS3_STATS_STORAGE_SET_SIZE_BY_GROUP: - case LS3_STATS_STORAGE_SET_SIZE_BY_PROJID: - case LS3_STATS_STRIPE_SIZE: - return LS3_STATS_VALUE_TYPE_KB; - case LS3_STATS_TIME_SINCE_LAST_MOD_RF: - case LS3_STATS_TIME_SINCE_LAST_CREATION_RF: - case LS3_STATS_TIME_SINCE_LAST_ACCESS_RF: - case LS3_STATS_TIME_SINCE_LAST_MD_MOD_RF: - return LS3_STATS_VALUE_TYPE_DAYS; - case LS3_STATS_FILENAME_LENGTH: - return LS3_STATS_VALUE_TYPE_CHARS; - case LS3_STATS_DIRECTORY_SIZE_ENTRIES: - return LS3_STATS_VALUE_TYPE_ENTRIES; - case LS3_STATS_FILES_EMPLOYING_DOM: - case LS3_STATS_TOTAL_COUNT_REPORT: - return LS3_STATS_VALUE_TYPE_ERROR; - case LS3_STATS_POSITIVE_OVERHEAD: - case LS3_STATS_NEGATIVE_OVERHEAD: - return LS3_STATS_VALUE_TYPE_BYTES; - case LS3_STATS_LINK_COUNT: - return LS3_STATS_VALUE_TYPE_LINKS; - case LS3_STATS_STRIPE_COUNT: - return LS3_STATS_VALUE_TYPE_STRIPE; - case LS3_STATS_MIRROR_COUNT: - return LS3_STATS_VALUE_TYPE_MIRROR; + case LS3_STATS_TYPE_FILES_SIZE: + case LS3_STATS_TYPE_CAPACITY_USED: + case LS3_STATS_TYPE_DIRECTORY_SIZE_KB: + case LS3_STATS_TYPE_EQUAL_OVERHEAD: + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_USER: + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_GROUP: + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_PROJID: + case LS3_STATS_TYPE_COMPRESSION_RATIO: + case LS3_STATS_TYPE_STRIPE_SIZE: + case LS3_STATS_TYPE_POSITIVE_OVERHEAD: + case LS3_STATS_TYPE_NEGATIVE_OVERHEAD: + return LS3_STATS_VALUE_TYPE_KB; + case LS3_STATS_TYPE_TIME_SINCE_LAST_MOD_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_CREATION_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_ACCESS_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_MD_MOD_RF: + return LS3_STATS_VALUE_TYPE_DAYS; + case LS3_STATS_TYPE_FILENAME_LENGTH: + case LS3_STATS_TYPE_SYMLINK_TARGET_LENGTH: + return LS3_STATS_VALUE_TYPE_CHARS; + case LS3_STATS_TYPE_DIRECTORY_SIZE_ENTRIES: + return LS3_STATS_VALUE_TYPE_ENTRIES; + case LS3_STATS_TYPE_FILES_EMPLOYING_DOM: + case LS3_STATS_TYPE_TOTAL_COUNT_REPORT: + return LS3_STATS_VALUE_TYPE_ERROR; +/* case LS3_STATS_TYPE_POSITIVE_OVERHEAD: + case LS3_STATS_TYPE_NEGATIVE_OVERHEAD: + return LS3_STATS_VALUE_TYPE_BYTES; */ + case LS3_STATS_TYPE_LINK_COUNT: + return LS3_STATS_VALUE_TYPE_LINKS; + case LS3_STATS_TYPE_STRIPE_COUNT: + return LS3_STATS_VALUE_TYPE_STRIPE; + case LS3_STATS_TYPE_MIRROR_COUNT: + return LS3_STATS_VALUE_TYPE_MIRROR; } return LS3_STATS_VALUE_TYPE_ERROR; @@ -290,25 +268,25 @@ static char *ls3_stats_get_str_value_type(ls3_stats_val_type num_type) { switch (num_type) { - case LS3_STATS_VALUE_TYPE_ERROR: - case LS3_STATS_VALUE_TYPE_EMPTY: - return ""; - case LS3_STATS_VALUE_TYPE_KB: - return "KB"; - case LS3_STATS_VALUE_TYPE_ENTRIES: - return "Entries"; - case LS3_STATS_VALUE_TYPE_CHARS: - return "Chars"; - case LS3_STATS_VALUE_TYPE_LINKS: - return "Links"; - case LS3_STATS_VALUE_TYPE_DAYS: - return "Days"; - case LS3_STATS_VALUE_TYPE_BYTES: - return "Bytes"; - case LS3_STATS_VALUE_TYPE_STRIPE: - return "Stripe"; - case LS3_STATS_VALUE_TYPE_MIRROR: - return "Mirror"; + case LS3_STATS_VALUE_TYPE_ERROR: + case LS3_STATS_VALUE_TYPE_EMPTY: + return ""; + case LS3_STATS_VALUE_TYPE_KB: + return "KB"; + case LS3_STATS_VALUE_TYPE_ENTRIES: + return "Entries"; + case LS3_STATS_VALUE_TYPE_CHARS: + return "Chars"; + case LS3_STATS_VALUE_TYPE_LINKS: + return "Links"; + case LS3_STATS_VALUE_TYPE_DAYS: + return "Days"; + case LS3_STATS_VALUE_TYPE_BYTES: + return "Bytes"; + case LS3_STATS_VALUE_TYPE_STRIPE: + return "Stripe"; + case LS3_STATS_VALUE_TYPE_MIRROR: + return "Mirror"; } return ""; @@ -318,53 +296,56 @@ static char *ls3_stats_get_title_text(ls3_stats_report_type report_type) { switch (report_type) { - case LS3_STATS_FILES_SIZE: - return "Files Size"; - case LS3_STATS_CAPACITY_USED: - return "Capacity used (Regualr file's space used on disk)"; - case LS3_STATS_EQUAL_OVERHEAD: - return "Equal overhead (Files whose capacity used is" - " equal to their size)"; - case LS3_STATS_POSITIVE_OVERHEAD: - return "Positive overhead (Files whose capacity used is" - " larger than or equal to its size)"; - case LS3_STATS_NEGATIVE_OVERHEAD: - return "Negative overhead (Files whose size is larger" - " than capacity used.)"; - case LS3_STATS_DIRECTORY_SIZE_KB: - return "Directory size (KB's)"; - case LS3_STATS_TIME_SINCE_LAST_CREATION_RF: - return "Time since creation [crtime](Regular files)"; - case LS3_STATS_TIME_SINCE_LAST_MOD_RF: - return "Time since last modification [mtime](Regular files)"; - case LS3_STATS_TIME_SINCE_LAST_MD_MOD_RF: - return "Time since last metadata modification [ctime]"; - case LS3_STATS_TIME_SINCE_LAST_ACCESS_RF: - return "Time since last access [atime](Regular files)"; - case LS3_STATS_FILENAME_LENGTH: - return "Filename length (Includes regular files, " - "dirs, symlinks and special files)"; - case LS3_STATS_DIRECTORY_SIZE_ENTRIES: - return "Directory size (entries)"; - case LS3_STATS_FILES_EMPLOYING_DOM: - return "Files employing DoM"; - case LS3_STATS_STORAGE_SET_SIZE_BY_USER: - return "Storage size (all directories and files) by user"; - case LS3_STATS_STORAGE_SET_SIZE_BY_GROUP: - return "Storage size (all directories and files) by group"; - case LS3_STATS_STORAGE_SET_SIZE_BY_PROJID: - return "Storage size (all directories and files)" - " by project ID"; - case LS3_STATS_LINK_COUNT: - return "Link count (of regular files)"; - case LS3_STATS_STRIPE_COUNT: - return "Stripe count (of regular files)"; - case LS3_STATS_STRIPE_SIZE: - return "Stripe size (of regular files)"; - case LS3_STATS_MIRROR_COUNT: - return "Mirror count (of regular files)"; - case LS3_STATS_TOTAL_COUNT_REPORT: - return ""; + case LS3_STATS_TYPE_FILES_SIZE: + return "Files Size"; + case LS3_STATS_TYPE_CAPACITY_USED: + return "Capacity used (Regular file's space used on disk)"; + case LS3_STATS_TYPE_EQUAL_OVERHEAD: + return "Equal overhead (Files whose capacity used is " + "equal to their size)"; + case LS3_STATS_TYPE_POSITIVE_OVERHEAD: + return "Positive overhead (Files whose capacity used is " + "larger than or equal to its size)"; + case LS3_STATS_TYPE_NEGATIVE_OVERHEAD: + return "Negative overhead (Files whose size is larger " + "than capacity used.)"; + case LS3_STATS_TYPE_DIRECTORY_SIZE_KB: + return "Directory size (KB)"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_CREATION_RF: + return "Time since creation [crtime](Regular files)"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_MOD_RF: + return "Time since last modification [mtime](Regular files)"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_MD_MOD_RF: + return "Time since last metadata modification [ctime]"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_ACCESS_RF: + return "Time since last access [atime](Regular files)"; + case LS3_STATS_TYPE_FILENAME_LENGTH: + return "Filename length (Includes regular files, " + "dirs, symlinks and special files)"; + case LS3_STATS_TYPE_DIRECTORY_SIZE_ENTRIES: + return "Directory size (entries)"; + case LS3_STATS_TYPE_FILES_EMPLOYING_DOM: + return "Files employing DoM"; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_USER: + return "Storage size (all directories and files) by user"; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_GROUP: + return "Storage size (all directories and files) by group"; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_PROJID: + return "Storage size (all directories and files) by project ID"; + case LS3_STATS_TYPE_LINK_COUNT: + return "Link count (of regular files)"; + case LS3_STATS_TYPE_STRIPE_COUNT: + return "Stripe count (of regular files)"; + case LS3_STATS_TYPE_STRIPE_SIZE: + return "Stripe size (of regular files)"; + case LS3_STATS_TYPE_MIRROR_COUNT: + return "Mirror count (of regular files)"; + case LS3_STATS_TYPE_COMPRESSION_RATIO: + return "Compress ratio (of regular files)"; + case LS3_STATS_TYPE_SYMLINK_TARGET_LENGTH: + return "Symlink target length"; + case LS3_STATS_TYPE_TOTAL_COUNT_REPORT: + return ""; } return ""; @@ -374,270 +355,347 @@ static char *ls3_stats_get_header_text(ls3_stats_report_type report_type) { switch (report_type) { - case LS3_STATS_FILES_SIZE: - return "\n\nFiles Size:\n" - "0 - Size range;\n1 - Count of files in range;\n2 -" - " Number of files in range as a percent of total" - " number of files;\n3 - Number of files in this" - " range or smaller as a % of total # of files;\n" - "4 - Total size of files in range;\n5 - Total size of" - " files in range as a % of total size of files;\n" - "6 - Total size of files in this range or smaller" - " as a % of total size of files;\n7 - Minimum value " - "in range;\n8 - Maximum value in range.\n"; - case LS3_STATS_CAPACITY_USED: - return "\n\nCapacity used (Regualr file's space used on disk):\n" - "0 - Size range;\n1 - Count of files in range;\n2 - Number of" - " files in range as a percent of total number of" - " files;\n3 - Number of files in this range or smaller" - " as a % of total # of file;\n4 - Total capacity used" - " in range;\n5 - Total capacity used in range as" - " a % of total capacity used;\n6 - Total capacity" - " used in this range or smaller as a % of" - " total capacity;\n7 - Minimum value in range;\n" - "8 - Maximum value in range.\n"; - case LS3_STATS_EQUAL_OVERHEAD: - return "\n\nEqual overhead (Files whose usable capacity is" - " equal to their size):\n0 - Size range;\n" - "1 - Count of files in range;\n2 - Number" - " of files in range as a percent of total number of" - " files;\n3 - Number of files in this range or" - " smaller as a % of total # of files;\n4 - Total" - " kilobytes that overflowed in range;\n5 - Total kilobytes" - " that overflowed in this range as a % of total" - " kilobytes that overflowed;\n6 - Total kilobytes that" - " overflowed in this range or smaller as a % of" - " total kilobytes that overflowed;\n7 - Minimum value " - "in range;\n8 - Maximum value in range.\n"; - case LS3_STATS_POSITIVE_OVERHEAD: - return "\n\nPositive overhead (Files whose capacity used is" - " larger than to its size):\n0 - Range of difference" - " sizes;\n1 - Count of files in range;\n2 - Number" - " of files in range as a percent of total number of" - " files;\n3 - Number of files in this range or" - " smaller as a % of total # of files;\n4 - Total" - " bytes that overflowed in range;\n5 - Total bytes" - " that overflowed in this range as a % of total" - " bytes that overflowed;\n6 - Total bytes that" - " overflowed in this range or smaller as a % of" - " total bytes that overflowed;\n7 - Minimum value " - "in range;\n8 - Maximum value in range.\n"; - case LS3_STATS_NEGATIVE_OVERHEAD: - return "\n\nNegative overhead (Files whose size is larger" - " than capacity used.):\n0 - Range of difference" - " sizes;\n1 - Count of files in range;\n2 - Number" - " of files in range as a percent of total number of" - " files;\n3 - Number of files in this range or" - " smaller as a % of total # of files;\n4 - Total" - " bytes that underflowed in range;\n5 - Total bytes" - " that underflowed in this range as a % of total" - " bytes that underflowed;\n6 - Total bytes that" - " underflowed in this range or smaller as a % of" - " total bytes that underflowed;\n7 - Minimum value " - "in range;\n8 - Maximum value in range.\n"; - case LS3_STATS_DIRECTORY_SIZE_KB: - return "\n\nDirectory size (KB's):\n0 - Range of dir sizes;" - " \n1 - Count of directories in range;\n2 - Number" - " of files in dirs as a percent of total number of" - " dirs;\n3 - Number of dirs in this range or" - " smaller as a % of total # of dirs;\n4 - Total size of" - " dirs in range;\n5 - Total size of dirs in range as a" - " % of total size of dirs;\n6 - Total size of dirs in" - " this range or smaller as a % of total size of dirs;" - "\n7 - Minimum value in range;\n" - "8 - Maximum value in range.\n"; - case LS3_STATS_TIME_SINCE_LAST_CREATION_RF: - return "\n\nTime since creation [crtime](Regular files):\n" - "0 - Range in days;\n1 - Count of files in range;\n" - "2 - Number of files in range as a % of total" - " number of files;\n3 - Number of files in this" - " range or smaller as a % of total number of" - " files;\n4 - Total kilobytes that underflowed in range;\n" - "5 - Total of age in range, total age in range as" - " a % of total age of all files;\n6 - total age in" - " this range or smaller as a % of total age of" - " all files;\n7 - Minimum value in range;\n" - "8 - Maximum value in range.\n"; - case LS3_STATS_TIME_SINCE_LAST_MOD_RF: - return "\n\nTime since last modification [mtime](Regular files):\n" - "0 - Range in days;\n1 - Count of files in range;\n" - "2 - Number of files in range as a % of total" - " number of files;\n3 - Number of files in this" - " range or smaller as a % of total number of" - " files;\n4 - Total kilobytes that underflowed in range;\n" - "5 - Total of age in range, total age in range as" - " a % of total age of all files;\n6 - total age in" - " this range or smaller as a % of total age of" - " all files;\n7 - Minimum value in range;\n8 -" - " Maximum value in range.\n"; - case LS3_STATS_TIME_SINCE_LAST_MD_MOD_RF: - return "\n\nTime since last metadata modification [ctime]" - " (Regular files):\n0 - Range in days;\n1 - Count" - " of files in range;\n2 - Number of files in range" - " as a % of total number of files;\n3 - Number of" - " files in this range or smaller as a % of total number of" - " files;\n4 - Total kilobytes that underflowed in range;\n" - "5 - Total of age in range, total age in range as" - " a % of total age of all files;\n6 - total age in" - " this range or smaller as a % of total age of" - " all files;\n7 - Minimum value in range;\n8 -" - " Maximum value in range.\n"; - case LS3_STATS_TIME_SINCE_LAST_ACCESS_RF: - return "\n\nTime since last access [atime](Regular files):\n" - "0 - Range in days;\n1 - Count of files in range;\n" - "2 - Number of files in range as a % of total" - " number of files;\n3 - Number of files in this" - " range or smaller as a % of total number of" - " files;\n4 - Total kilobytes that underflowed in range;\n" - "5 - Total of age in range, total age in range as" - " a % of total age of all files;\n6 - total age in" - " this range or smaller as a % of total age of" - " all files;\n7 - Minimum value in range;\n8 -" - " Maximum value in range.\n"; - case LS3_STATS_FILENAME_LENGTH: - return "\n\nFilename length (Includes regular files," - " dirs, symlinks and special files):\n0 - Range" - " of filename lengths;\n1 - Count of files in range;\n" - "2 - Count of files in range as a % of total number" - " of files;\n3 - Number of files in this range or" - " smaller as a % of total # of files;\n" - "4 - Total chars of filenames in range;\n" - "5 - Total chars of filenames in range as a % of" - " total number of chars of filenames;\n6 - Total" - " number of chars of filenames in this range or" - " smaller as a % of total number bytes of filenames;\n" - "7 - Minimum value in range;\n8 -" - " Maximum value in range.\n"; - case LS3_STATS_DIRECTORY_SIZE_ENTRIES: - return "\n\nDirectory size (entries):\n0 - Range of entries;\n" - "1 - Count of directories in range;\n2 - Number of dirs in" - " range as a % of total num of dirs;\n3 - Number of dirs" - " in this range or smaller as a % total number of dirs;\n" - "4 - Total entries in range;\n5 - Number of entries in" - " range as a % of total number of entries;\n6 - Number of" - " entries in this range or smaller as a % of total number" - " of entries;\n7 - Minimum value in range;\n8 -" - " Maximum value in range.\n"; - case LS3_STATS_STORAGE_SET_SIZE_BY_USER: - return "\n\nStorage size by user (all directories and" - " files):\n0 - User ID (name);\n1 - Count of files for user" - ";\n2 - Number of files for user as a percent of total" - " number of files;\n3 - Number of files for user as a % of" - " total # of files;\n4 - Total size of files for user;\n5" - " - Total size of files for user as a % of total size of" - " files;\n6 - Total size of files for user or smaller" - " as a % of total size of files;\n7 - Minimum size " - "for user;\n8 - Maximum size for user.\n"; - case LS3_STATS_STORAGE_SET_SIZE_BY_GROUP: - return "\n\nStorage size by group (all directories and" - " files):\n0 - Group ID (name);\n1 - Count of files for group" - ";\n2 - Number of files for group as a percent of total" - " number of files;\n3 - Number of files for group as a % of" - " total # of files;\n4 - Total size of files for group;\n5" - " - Total size of files for group as a % of total size of" - " files;\n6 - Total size of files for group or smaller" - " as a % of total size of files;\n7 - Minimum size " - "for group;\n8 - Maximum size for group.\n"; - case LS3_STATS_STORAGE_SET_SIZE_BY_PROJID: - return "\n\nStorage size by projid (all directories and" - " files):\n0 - Project ID;\n1 - Count of files for projid" - ";\n2 - Number of files for projid as a percent of total" - " number of files;\n3 - Number of files for projid as a % of" - " total # of files;\n4 - Total size of files for projid;\n5" - " - Total size of files for projid as a % of total size of" - " files;\n6 - Total size of files for projid or smaller" - " as a % of total size of files;\n7 - Minimum size " - "for projid;\n8 - Maximum size for projid.\n"; - case LS3_STATS_LINK_COUNT: - return "\n\nLink count (of regular files):\n0 - Range of link" - " counts;\n1 - Count of files in range;\n2 - Number of files" - " in range as a % of total files;\n3 - Number of files in" - " this range or smaller as a % of total files;\n4 - Total" - " links in range;\n5 - Total links in range as a % of total" - " links;\n6 - Total links in this range or smaller as a % of" - " total links;\n7 - Minimum value in range;\n" - "8 - Maximum value in range.\n"; - case LS3_STATS_STRIPE_COUNT: - return "\n\nStripe count (of regular files):\n0 - Range of stripe" - " count;\n1 - Count of files in range;\n2 - Number of files" - " in range as a % of total files;\n3 - Number of files in" - " this range as a % of total files;\n4 - Total" - " stripe in range;\n5 - Total stripe in range as a % of total" - " stripe;\n6 - Total stripe in this range as a" - " % of total stripe;\n7 - Minimum value in range;\n" - "8 - Maximum value in range.\n"; - case LS3_STATS_STRIPE_SIZE: - return "\n\nStripe size (of regular files):\n0 - Stripe" - " size;\n1 - Count of files with stripe size;\n2 - Number" - " of files with stripe size as a % of total files;\n3" - " - Number of files with this stripe size as a % of" - " total files;\n4 - Total file size with this stripe" - " size;\n5 - Total file size with stripe size as a % of" - " total size;\n6 - Total file size with this stripe size or" - " smaller as a % of total file;\n7 - Minimum value with this" - " stripe size;\n8 - Maximum value with this stripe size.\n"; - case LS3_STATS_MIRROR_COUNT: - return "\n\nMirror count (of regular files):\n0 - Range of mirror" - " count;\n1 - Count of files in range;\n2 - Number of files" - " in range as a % of total files;\n3 - Number of files in" - " this range as a % of total files;\n4 - Total" - " mirror in range;\n5 - Total mirror in range as a % of total" - " mirror;\n6 - Total mirror in this range as a" - " % of total mirror;\n7 - Minimum value in range;\n" - "8 - Maximum value in range.\n"; - case LS3_STATS_FILES_EMPLOYING_DOM: - case LS3_STATS_TOTAL_COUNT_REPORT: - return ""; + case LS3_STATS_TYPE_FILES_SIZE: + return "\n\nFiles Size:\n" + "0 - Size range;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a percent of total " + "number of files;\n" + "3 - Number of files in this range or smaller as a % " + "of total # of files;\n" + "4 - Total size of files in range;\n" + "5 - Total size of files in range as a % of total " + "size of files;\n" + "6 - Total size of files in this range or smaller as " + "a % of total size of files;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_CAPACITY_USED: + return "\n\nCapacity used (Regular files space used on disk):\n" + "0 - Size range;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a percent of total " + "number of files;\n" + "3 - Number of files in this range or smaller as a % of " + "total # of file;\n" + "4 - Total capacity used in range;\n" + "5 - Total capacity used in range as a % of total " + "capacity used;\n" + "6 - Total capacity used in this range or smaller as " + "a % of total capacity;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_EQUAL_OVERHEAD: + return "\n\nEqual overhead (Files whose usable capacity is " + "equal to their size):\n" + "0 - Size range;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a percent of total " + "number of files;\n" + "3 - Number of files in this range or smaller as a % of " + "total # of files;\n" + "4 - Total kilobytes that overflowed in range;\n" + "5 - Total kilobytes that overflowed in this range as " + "a % of total kilobytes that overflowed;\n" + "6 - Total kilobytes that overflowed in this range or " + "smaller as a % of total kilobytes " + "that overflowed;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_POSITIVE_OVERHEAD: + return "\n\nPositive overhead (Files whose capacity used is " + "larger than to its size):\n" + "0 - Range of difference sizes;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a percent of total " + "number of files;\n" + "3 - Number of files in this range or smaller as a % of " + "total # of files;\n" + "4 - Total bytes that overflowed in range;\n" + "5 - Total bytes that overflowed in this range as a % " + "of total bytes that overflowed;\n" + "6 - Total bytes that overflowed in this range or " + "smaller as a % of total bytes that overflowed;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_NEGATIVE_OVERHEAD: + return "\n\nNegative overhead (Files whose size is larger than " + "capacity used.):\n" + "0 - Range of difference sizes;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a percent of total " + "number of files;\n" + "3 - Number of files in this range or smaller as a % of " + "total # of files;\n" + "4 - Total bytes that underflowed in range;\n" + "5 - Total bytes that underflowed in this range as a % " + "of total bytes that underflowed;\n" + "6 - Total bytes that underflowed in this range or " + "smaller as a % of total bytes that underflowed;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_DIRECTORY_SIZE_KB: + return "\n\nDirectory size (KB):\n" + "0 - Range of dir sizes;\n" + "1 - Count of directories in range;\n" + "2 - Number of files in dirs as a percent of total " + "number of dirs;\n" + "3 - Number of dirs in this range or smaller as a % of " + "total # of dirs;\n" + "4 - Total size of dirs in range;\n" + "5 - Total size of dirs in range as a % of total size " + "of dirs;\n" + "6 - Total size of dirs in this range or smaller as a % " + "of total size of dirs;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_CREATION_RF: + return "\n\nTime since creation [crtime](Regular files):\n" + "0 - Range in days;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a % of total number " + "of files;\n" + "3 - Number of files in this range or smaller as a % " + "of total number of files;\n" + "4 - Total kilobytes that underflowed in range;\n" + "5 - Total of age in range, total age in range as a % " + "of total age of all files;\n" + "6 - total age in this range or smaller as a % of " + "total age of all files;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_MOD_RF: + return "\n\nTime since last modification [mtime] " + "(Regular files):\n" + "0 - Range in days;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a % of total number " + "of files;\n" + "3 - Number of files in this range or smaller as a % " + "of total number of files;\n" + "4 - Total kilobytes that underflowed in range;\n" + "5 - Total of age in range, total age in range as a % " + "of total age of all files;\n" + "6 - total age in this range or smaller as a % of total " + "age of all files;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_MD_MOD_RF: + return "\n\nTime since last metadata modification [ctime] " + "(Regular files):\n" + "0 - Range in days;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a % of total number " + "of files;\n" + "3 - Number of files in this range or smaller as a % " + "of total number of files;\n" + "4 - Total kilobytes that underflowed in range;\n" + "5 - Total of age in range, total age in range as a % " + "of total age of all files;\n" + "6 - total age in this range or smaller as a % of total " + "age of all files;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_TIME_SINCE_LAST_ACCESS_RF: + return "\n\nTime since last access [atime](Regular files):\n" + "0 - Range in days;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a % of total number " + "of files;\n" + "3 - Number of files in this range or smaller as a % " + "of total number of files;\n" + "4 - Total kilobytes that underflowed in range;\n" + "5 - Total of age in range, total age in range as a % " + "of total age of all files;\n" + "6 - total age in this range or smaller as a % of total " + "age of all files;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_FILENAME_LENGTH: + return "\n\nFilename length (Includes regular files, dirs, " + "symlinks and special files):\n" + "0 - Range of filename lengths;\n" + "1 - Count of files in range;\n" + "2 - Count of files in range as a % of total number " + "of files;\n" + "3 - Number of files in this range or smaller as a % " + "of total # of files;\n" + "4 - Total chars of filenames in range;\n" + "5 - Total chars of filenames in range as a % of total " + "number of chars of filenames;\n" + "6 - Total number of chars of filenames in this range " + "or smaller as a % of total number bytes " + "of filenames;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_DIRECTORY_SIZE_ENTRIES: + return "\n\nDirectory size (entries):\n" + "0 - Range of entries;\n" + "1 - Count of directories in range;\n" + "2 - Number of dirs in range as a % of total " + "num of dirs;\n" + "3 - Number of dirs in this range or smaller as " + "a % total number of dirs;\n" + "4 - Total entries in range;\n" + "5 - Number of entries in range as a % of total number " + "of entries;\n" + "6 - Number of entries in this range or smaller as a % " + "of total number of entries;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_USER: + return "\n\nStorage size by user (Regular files):\n" + "0 - User ID (name);\n" + "1 - Count of files for user;\n" + "2 - Number of files for user as a percent of total " + "number of files;\n" + "3 - Number of files for user as a % of total # " + "of files;\n" + "4 - Total size of files for user;\n" + "5 - Total size of files for user as a % of total size " + "of files;\n" + "6 - Total size of files for user or smaller as a % of " + "total size of files;\n" + "7 - Minimum size for user;\n" + "8 - Maximum size for user.\n"; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_GROUP: + return "\n\nStorage size by group (Regular files):\n" + "0 - Group ID (name);\n" + "1 - Count of files for group;\n" + "2 - Number of files for group as a percent of total " + "number of files;\n" + "3 - Number of files for group as a % of " + "total # of files;\n" + "4 - Total size of files for group;\n" + "5 - Total size of files for group as a % of total " + "size of files;\n" + "6 - Total size of files for group or smaller as " + "a % of total size of files;\n" + "7 - Minimum size for group;\n" + "8 - Maximum size for group.\n"; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_PROJID: + return "\n\nStorage size by projid (Regular files):\n" + "0 - Project ID;\n" + "1 - Count of files for projid;\n" + "2 - Number of files for projid as a percent of total " + "number of files;\n" + "3 - Number of files for projid as a % of " + "total # of files;\n" + "4 - Total size of files for projid;\n" + "5 - Total size of files for projid as a % of total " + "size of files;\n" + "6 - Total size of files for projid or smaller as a % " + "of total size of files;\n" + "7 - Minimum size for projid;\n" + "8 - Maximum size for projid.\n"; + case LS3_STATS_TYPE_LINK_COUNT: + return "\n\nLink count (of regular files):\n" + "0 - Range of link counts;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a % of total files;\n" + "3 - Number of files in this range or smaller as " + "a % of total files;\n" + "4 - Total links in range;\n" + "5 - Total links in range as a % of total links;\n" + "6 - Total links in this range or smaller as " + "a % of total links;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_STRIPE_COUNT: + return "\n\nStripe count (of regular files):\n" + "0 - Range of stripe count;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a % of total files;\n" + "3 - Number of files in this range as a % of " + "total files;\n" + "4 - Total stripe in range;\n" + "5 - Total stripe in range as a % of total stripe;\n" + "6 - Total stripe in this range as a % " + "of total stripe;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_STRIPE_SIZE: + return "\n\nStripe size (of regular files):\n" + "0 - Stripe size;\n" + "1 - Count of files with stripe size;\n" + "2 - Number of files with stripe size as a % " + "of total files;\n" + "3 - Number of files with this stripe size as a % " + "of total files;\n" + "4 - Total file size with this stripe size;\n" + "5 - Total file size with stripe size as a % " + "of total size;\n" + "6 - Total file size with this stripe size or smaller " + "as a % of total file;\n" + "7 - Minimum value with this stripe size;\n" + "8 - Maximum value with this stripe size.\n"; + case LS3_STATS_TYPE_MIRROR_COUNT: + return "\n\nMirror count (of regular files):\n" + "0 - Range of mirror count;\n" + "1 - Count of files in range;\n" + "2 - Number of files in range as a % of total files;\n" + "3 - Number of files in this range as a % " + "of total files;\n" + "4 - Total mirror in range;\n" + "5 - Total mirror in range as a % of total mirror;\n" + "6 - Total mirror in this range as a % of " + "total mirror;\n" + "7 - Minimum value in range;\n" + "8 - Maximum value in range.\n"; + case LS3_STATS_TYPE_FILES_EMPLOYING_DOM: + case LS3_STATS_TYPE_SYMLINK_TARGET_LENGTH: + case LS3_STATS_TYPE_COMPRESSION_RATIO: + case LS3_STATS_TYPE_TOTAL_COUNT_REPORT: + return ""; } return ""; } static void ls3_stats_get_range_str(struct range_report_template *range_ptr, - char str[30], int range, ls3_stats_report_type r_type, char *value_ts) + char *str, size_t strlen, int range, ls3_stats_report_type r_type, + char *value_ts) { - int size_str = 30; - /* Different type of "range" field */ switch (r_type) { - case LS3_STATS_STORAGE_SET_SIZE_BY_USER: - snprintf(str, size_str, - "%10lu (%14s)", range_ptr->rrt_id, - ls3_stats_get_username_from_uid(range_ptr->rrt_id)); - break; - case LS3_STATS_STORAGE_SET_SIZE_BY_GROUP: - snprintf(str, size_str, - "%10lu (%14s)", range_ptr->rrt_id, - ls3_stats_get_groupname_from_gid(range_ptr->rrt_id)); - break; - case LS3_STATS_STORAGE_SET_SIZE_BY_PROJID: - snprintf(str, size_str, "%26lu ", range_ptr->rrt_id); - break; - case LS3_STATS_STRIPE_SIZE: - snprintf(str, size_str, "%18lu %7s ", range_ptr->rrt_id, - value_ts); - break; - case LS3_STATS_MIRROR_COUNT: - snprintf(str, size_str, "%26lu ", range_ptr->rrt_id); - break; - case LS3_STATS_TIME_SINCE_LAST_ACCESS_RF: - case LS3_STATS_TIME_SINCE_LAST_CREATION_RF: - case LS3_STATS_TIME_SINCE_LAST_MD_MOD_RF: - case LS3_STATS_TIME_SINCE_LAST_MOD_RF: - if (range_ptr->range_start >= 16384) - snprintf(str, size_str, - " Never changed "); - else - snprintf(str, size_str, - "%8lu - %8lu %7s", - range_ptr->range_start, - range_ptr->range_end, value_ts); - break; - default: - snprintf(str, size_str, - "%8lu - %8lu %7s", range_ptr->range_start, - range_ptr->range_end, value_ts); - break; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_USER: + snprintf(str, strlen, + "%10lu (%14s)", range_ptr->rrt_id, + ls3_stats_get_username_from_uid(range_ptr->rrt_id)); + break; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_GROUP: + snprintf(str, strlen, + "%10lu (%14s)", range_ptr->rrt_id, + ls3_stats_get_groupname_from_gid(range_ptr->rrt_id)); + break; + case LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_PROJID: + snprintf(str, strlen, "%26lu ", range_ptr->rrt_id); + break; + case LS3_STATS_TYPE_STRIPE_SIZE: + snprintf(str, strlen, "%18lu %7s ", range_ptr->rrt_id, + value_ts); + break; + case LS3_STATS_TYPE_MIRROR_COUNT: + snprintf(str, strlen, "%26lu ", range_ptr->rrt_id); + break; + case LS3_STATS_TYPE_TIME_SINCE_LAST_ACCESS_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_CREATION_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_MD_MOD_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_MOD_RF: + if (range_ptr->range_start >= 16384) + snprintf(str, strlen, + " Never changed "); + else + snprintf(str, strlen, + "%8lu - %8lu %7s", + range_ptr->range_start, + range_ptr->range_end, value_ts); + break; + default: + snprintf(str, strlen, + "%8lu - %8lu %7s", range_ptr->range_start, + range_ptr->range_end, value_ts); + break; } } @@ -668,35 +726,35 @@ static void json_add_field_with_value(json_object* jobj, * @param buffer Output buffer to store the resulting date-time string. * @param seconds Number of seconds since the epoch. */ -static void ls3_stats_get_time_str(char *buffer, uint64_t seconds) +static void ls3_stats_get_time_str(char *buffer, size_t buff_len, + uint64_t seconds) { time_t l_access; struct tm* la_time; - int buffer_size = 20; l_access = (time_t)seconds; la_time = localtime(&l_access); if (seconds == 0) - strncpy(buffer, "Files never opened", buffer_size); + strncpy(buffer, "Files never opened", buff_len); else - strftime(buffer, buffer_size, "%Y-%m-%d-%H:%M:%S", la_time); + strftime(buffer, buff_len, "%Y-%m-%d-%H:%M:%S", la_time); } static char* ls3_stats_get_title_for_user_report(ls3_stats_users_reports rtype) { switch (rtype) { - case LS3_STATS_USERS_REPORTS_MOD_RF: - return "Time since last modification (mtime)"; - case LS3_STATS_USERS_REPORTS_MD_MOD_RF: - return "Time since last metadata modification (ctime)"; - case LS3_STATS_USERS_REPORTS_CREATION_RF: - return "Time since creation (crtime)"; - case LS3_STATS_USERS_REPORTS_ACCESS_RF: - return "Time since last access (atime)"; - case LS3_STATS_USERS_REPORTS_COUNTER: - default: - return ""; + case LS3_STATS_USERS_REPORTS_MOD_RF: + return "Time since last modification (mtime)"; + case LS3_STATS_USERS_REPORTS_MD_MOD_RF: + return "Time since last metadata modification (ctime)"; + case LS3_STATS_USERS_REPORTS_CREATION_RF: + return "Time since creation (crtime)"; + case LS3_STATS_USERS_REPORTS_ACCESS_RF: + return "Time since last access (atime)"; + case LS3_STATS_USERS_REPORTS_COUNTER: + default: + return ""; } } @@ -716,26 +774,37 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) int i, j, k; json_object_object_add(jobj_main, "LIPEStatsVersion", - json_object_new_double(LS3_STATS_VERSION)); + json_object_new_double(LS3_STATS_VERSION)); + json_object_object_add(jobj_main, "CreateTime", - json_object_new_string(f_time)); + json_object_new_string(f_time)); + json_object_object_add(jobj_main, "ProcessedFiles", - json_object_new_int64(reports_with_stats->total_count_files)); + json_object_new_int64(reports_with_stats->total_count_files)); + json_object_object_add(jobj_main, "ProcessingTimeSecs", - json_object_new_double(e_time)); + json_object_new_double(e_time)); + json_object_object_add(jobj_main, "DevicePath", - json_object_new_string(reports_with_stats->device_path)); + json_object_new_string(reports_with_stats->device_path)); + json_object_object_add(jobj_main, "DeviceName", - json_object_new_string(reports_with_stats->device_name)); + json_object_new_string(reports_with_stats->device_name)); + json_object_object_add(jobj_main, "DeviceType", - json_object_new_string(reports_with_stats->device_is_mdt ? - "MDT" : "OST")); - json_object_object_add(jobj_main, "DeviceSizeInKB", - json_object_new_int64(reports_with_stats->device_size >> 10)); + json_object_new_string(reports_with_stats->device_is_mdt ? + "MDT" : "OST")); + + json_object_object_add(jobj_main, "InodesCountOnDevice", + json_object_new_int(reports_with_stats->inodes_count)); + + json_object_object_add(jobj_main, "FreeInodesCountOnDevice", + json_object_new_int(reports_with_stats->free_inodes_count)); + json_object_object_add(jobj_main, "ClientMountPath", - json_object_new_string(reports_with_stats->client_mount_path)); + json_object_new_string(reports_with_stats->client_mount_path)); - for (i = 0; i < LS3_STATS_TOTAL_COUNT_REPORT; i++) { + for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) { struct json_object *jobj_report; struct json_object *jobj_general; struct json_object *jobj_ranges; @@ -745,10 +814,12 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) LS3_FATAL("Unable to access the report data: %d\n", i); if (report_ptr->files_count == 0) - continue; /* Nothing for print */ + continue; /* Nothing for print */ - value_ts = ls3_stats_get_str_value_type(report_ptr->value_type); - second_value_ts = ls3_stats_get_str_value_type(report_ptr->second_value_type); + value_ts = + ls3_stats_get_str_value_type(report_ptr->value_type); + second_value_ts = + ls3_stats_get_str_value_type(report_ptr->second_value_type); title_text = ls3_stats_get_title_text(i); jobj_report = json_object_new_object(); @@ -756,23 +827,29 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) jobj_ranges = json_object_new_array(); json_object_object_add(jobj_general, "Title", - json_object_new_string(title_text)); + json_object_new_string(title_text)); + json_object_object_add(jobj_general, "Count", json_object_new_int64(report_ptr->files_count)); + json_add_field_with_value(jobj_general, "Min", - report_ptr->min, value_ts, LS3_STATS_EMPTY_VALUE); + report_ptr->rt_min, value_ts, LS3_STATS_EMPTY_VALUE); + json_add_field_with_value(jobj_general, "Max", - report_ptr->max, value_ts, LS3_STATS_EMPTY_VALUE); + report_ptr->rt_max, value_ts, LS3_STATS_EMPTY_VALUE); + json_add_field_with_value(jobj_general, "Avg", - report_ptr->avg, value_ts, LS3_STATS_EMPTY_VALUE); + report_ptr->rt_avg, value_ts, LS3_STATS_EMPTY_VALUE); + json_add_field_with_value(jobj_general, "Total", report_ptr->total_value, (second_value_ts[0] != '\0') ? second_value_ts : value_ts, LS3_STATS_EMPTY_VALUE); for (j = 0; j < report_ptr->count_ranges; j++) { - struct json_object *jobj_range = json_object_new_object(); - char range_t[30]; + struct json_object *jobj_range = + json_object_new_object(); + char range_t[30]; /* size in 30 byte enough */ range_ptr = report_ptr->fs_ranges[j]; if (range_ptr == NULL) @@ -781,7 +858,8 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) if (range_ptr->count_in_range == 0) continue; /* Nothing for print */ - ls3_stats_get_range_str(range_ptr, range_t, j, i, value_ts); + ls3_stats_get_range_str(range_ptr, range_t, + sizeof(range_t), j, i,value_ts); json_object_object_add(jobj_range, "RangeID", json_object_new_int(j)); @@ -790,12 +868,12 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) json_object_new_string(range_t)); json_object_object_add(jobj_range, "CountInRange", - json_object_new_int64( - range_ptr->count_in_range)); + json_object_new_int64(range_ptr->count_in_range)); - json_add_field_with_value(jobj_range, "PercentageInRange", - LS3_STATS_EMPTY_VALUE , - "", range_ptr->percentage); + json_add_field_with_value(jobj_range, + "PercentageInRange", + LS3_STATS_EMPTY_VALUE, "", + range_ptr->percentage); json_add_field_with_value(jobj_range, "CumulativePercentageInRange", @@ -808,9 +886,10 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) second_value_ts : value_ts, LS3_STATS_EMPTY_VALUE); - json_add_field_with_value(jobj_range, "PercentTotalInRange", - LS3_STATS_EMPTY_VALUE , - "", range_ptr->percent_in_range); + json_add_field_with_value(jobj_range, + "PercentTotalInRange", + LS3_STATS_EMPTY_VALUE, "", + range_ptr->percent_in_range); json_add_field_with_value(jobj_range, "PercentCumulativeTotalInRange", @@ -818,11 +897,11 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) range_ptr->percent_cumulative_in_range); json_add_field_with_value(jobj_range, "MinValueInRange", - range_ptr->min, value_ts, + range_ptr->rrt_min, value_ts, LS3_STATS_EMPTY_VALUE); json_add_field_with_value(jobj_range, "MaxValueInRange", - range_ptr->max, value_ts, + range_ptr->rrt_max, value_ts, LS3_STATS_EMPTY_VALUE); json_object_array_add(jobj_ranges, jobj_range); @@ -871,32 +950,40 @@ static void ls3_stats_print_to_json(const char *f_time, double e_time) json_object_new_string(title_text)); for (k = 0; k < report_ptr->count_ranges; k++) { - struct json_object *jobj_range = json_object_new_object(); + struct json_object *jobj_range = + json_object_new_object(); char buffer[20]; range_ptr = report_ptr->fs_ranges[k]; if (range_ptr == NULL) continue; - ls3_stats_get_time_str(buffer, range_ptr->last_time_access); + ls3_stats_get_time_str(buffer, sizeof(buffer), + range_ptr->last_time_access); json_object_object_add(jobj_range, "RangeDayStart", - json_object_new_int64(range_ptr->range_start)); + json_object_new_int64( + range_ptr->range_start)); json_object_object_add(jobj_range, "RangeDayEnd", - json_object_new_int64(range_ptr->range_end)); + json_object_new_int64( + range_ptr->range_end)); json_object_object_add(jobj_range, "CountFilesInRange", - json_object_new_int64(range_ptr->count_in_range)); + json_object_new_int64( + range_ptr->count_in_range)); json_object_object_add(jobj_range, "MinSizeKB", - json_object_new_int64(range_ptr->min)); + json_object_new_int64( + range_ptr->rrt_min)); json_object_object_add(jobj_range, "MaxSizeKB", - json_object_new_int64(range_ptr->min)); + json_object_new_int64( + range_ptr->rrt_max)); json_object_object_add(jobj_range, "TotalSizeInRangeKB", - json_object_new_int64(range_ptr->total_in_range)); + json_object_new_int64( + range_ptr->total_in_range)); json_object_object_add(jobj_range, "LastTimeAccess", json_object_new_string(buffer)); @@ -945,17 +1032,19 @@ static void ls3_stats_print_to_yaml(const char *f_time, double e_time) "DevicePath: %s\n" "DeviceName: %s\n" "ClientMountPath: %s\n" - "DeviceSizeInKB: %lu\n" + "Inodes count on device: %u\n" + "Free inodes count on device: %u\n" "DeviceType: %s\n", LS3_STATS_VERSION, f_time, reports_with_stats->total_count_files, e_time, reports_with_stats->device_path, reports_with_stats->device_name, reports_with_stats->client_mount_path, - reports_with_stats->device_size >> 10, + reports_with_stats->inodes_count, + reports_with_stats->free_inodes_count, reports_with_stats->device_is_mdt ? "MDT" : "OST"); - for (i = 0; i < LS3_STATS_TOTAL_COUNT_REPORT; i++) { + for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) { char *title_text; report_ptr = reports_with_stats->reports[i]; @@ -980,15 +1069,15 @@ static void ls3_stats_print_to_yaml(const char *f_time, double e_time) " Total: %lu %s\n" " Ranges:\n", title_text, report_ptr->files_count, - report_ptr->min, value_ts, - report_ptr->max, value_ts, - report_ptr->avg, value_ts, + report_ptr->rt_min, value_ts, + report_ptr->rt_max, value_ts, + report_ptr->rt_avg, value_ts, report_ptr->total_value, (second_value_ts[0] != '\0') ? second_value_ts : value_ts); for (j = 0; j < report_ptr->count_ranges; j++) { - char range_t[30]; + char range_t[30]; /* size in 30 byte enough */ range_ptr = report_ptr->fs_ranges[j]; if (range_ptr == NULL) @@ -998,7 +1087,9 @@ static void ls3_stats_print_to_yaml(const char *f_time, double e_time) continue; /* Nothing for print */ /* Different type of "range" field */ - ls3_stats_get_range_str(range_ptr, range_t, j, i, value_ts); + ls3_stats_get_range_str(range_ptr, range_t, + sizeof(range_t), + j, i, value_ts); fprintf(yaml_fd, " - RangeID: %i\n" @@ -1015,11 +1106,12 @@ static void ls3_stats_print_to_yaml(const char *f_time, double e_time) range_ptr->count_in_range, range_ptr->percentage, range_ptr->cumulative_percentage, range_ptr->total_in_range, - (second_value_ts[0] != '\0') ? second_value_ts : value_ts, + (second_value_ts[0] != '\0') ? + second_value_ts : value_ts, range_ptr->percent_in_range, range_ptr->percent_cumulative_in_range, - range_ptr->min, value_ts, - range_ptr->max, value_ts); + range_ptr->rrt_min, value_ts, + range_ptr->rrt_max, value_ts); } } @@ -1057,7 +1149,7 @@ static void ls3_stats_print_to_yaml(const char *f_time, double e_time) if (range_ptr == NULL) continue; - ls3_stats_get_time_str(buffer, + ls3_stats_get_time_str(buffer, sizeof(buffer), range_ptr->last_time_access); fprintf(yaml_fd, " RangeStart: %lu %s\n" @@ -1070,8 +1162,8 @@ static void ls3_stats_print_to_yaml(const char *f_time, double e_time) range_ptr->range_start, value_ts, range_ptr->range_end, value_ts, range_ptr->count_in_range, - range_ptr->min, second_value_ts, - range_ptr->max, second_value_ts, + range_ptr->rrt_min, second_value_ts, + range_ptr->rrt_max, second_value_ts, range_ptr->total_in_range, second_value_ts, buffer); } @@ -1101,18 +1193,19 @@ static void ls3_stats_print_to_out(const char *f_time, double e_time) "Device path: %s\n" "Device name: %s\n" "Device type: %s\n" - "Device size in KB: %lu\n" - "Client mount path: %s\n" - "RESULTS MAY BE INCOMPLETE\n\n", + "Inodes count on device: %u\n" + "Free inodes count on device: %u\n" + "Client mount path: %s\n\n", LS3_STATS_VERSION, f_time, reports_with_stats->total_count_files, e_time, reports_with_stats->device_path, reports_with_stats->device_name, reports_with_stats->device_is_mdt ? "MDT" : "OST", - reports_with_stats->device_size >> 10, + reports_with_stats->inodes_count, + reports_with_stats->free_inodes_count, reports_with_stats->client_mount_path); - for (i = 0; i < LS3_STATS_TOTAL_COUNT_REPORT; i++) { + for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) { char *header_text; report_ptr = reports_with_stats->reports[i]; @@ -1120,7 +1213,7 @@ static void ls3_stats_print_to_out(const char *f_time, double e_time) LS3_FATAL("Unable to access the report data: %d\n", i); if (report_ptr->files_count == 0) - continue; /* Nothing for print */ + continue; /* Nothing for print */ value_ts = ls3_stats_get_str_value_type(report_ptr->value_type); second_value_ts = @@ -1130,18 +1223,18 @@ static void ls3_stats_print_to_out(const char *f_time, double e_time) fprintf(out_fd, "%s\nGeneral: Count: %lu | Min value in ranges:" " %lu %s | Max value in ranges: %lu %s| Average value in ranges:" " %lu %s | Total value: %lu %s\n\n", - header_text, report_ptr->files_count, report_ptr->min, - value_ts, report_ptr->max, value_ts, report_ptr->avg, - value_ts, report_ptr->total_value, + header_text, report_ptr->files_count, report_ptr->rt_min, + value_ts, report_ptr->rt_max, value_ts, + report_ptr->rt_avg, value_ts, report_ptr->total_value, (second_value_ts[0] != '\0') ? second_value_ts : value_ts); - fprintf(out_fd, "[------------- %1d ------------] [---- %1d -----]" - " [-- %1d --] [------- %1d --------] [-------- %1d --------]" - " [-- %1d --] [------- %1d --------] [-------- %1d --------]" - " [-------- %1d --------]\n", 0, 1, 2, 3, 4, 5, 6, 7, 8); + fprintf(out_fd, "[------------- 0 ------------] [---- 1 -----]" + " [-- 2 --] [------- 3 --------] [-------- 4 --------]" + " [-- 5 --] [------- 6 --------] [-------- 7 --------]" + " [-------- 8 --------]\n"); for (j = 0; j < report_ptr->count_ranges; j++) { - char range_t[30]; + char range_t[30]; /* size in 30 byte enough */ range_ptr = report_ptr->fs_ranges[j]; if (range_ptr == NULL) @@ -1151,7 +1244,9 @@ static void ls3_stats_print_to_out(const char *f_time, double e_time) continue; /* Nothing for print */ /* Different type of "range" field */ - ls3_stats_get_range_str(range_ptr, range_t, j, i, value_ts); + ls3_stats_get_range_str(range_ptr, range_t, + sizeof(range_t), + j, i, value_ts); fprintf(out_fd, "[ %s] [ %11lu] [%6.2f%%]" " [%6.2f%% cumulative] [%11lu %7s] [%6.2f%%]" @@ -1160,11 +1255,12 @@ static void ls3_stats_print_to_out(const char *f_time, double e_time) range_ptr->percentage, range_ptr->cumulative_percentage, range_ptr->total_in_range, - (second_value_ts[0] != '\0') ? second_value_ts : value_ts, + (second_value_ts[0] != '\0') ? + second_value_ts : value_ts, range_ptr->percent_in_range, range_ptr->percent_cumulative_in_range, - range_ptr->min, value_ts, - range_ptr->max, value_ts); + range_ptr->rrt_min, value_ts, + range_ptr->rrt_max, value_ts); } fprintf(out_fd, "[----------------------------] [------------]" @@ -1216,7 +1312,7 @@ static void ls3_stats_print_to_out(const char *f_time, double e_time) if (range_ptr == NULL) continue; - ls3_stats_get_time_str(buffer, + ls3_stats_get_time_str(buffer, sizeof(buffer), range_ptr->last_time_access); fprintf(out_fd, "[ %8lu - %8lu %7s] [ %11lu ]" @@ -1225,8 +1321,8 @@ static void ls3_stats_print_to_out(const char *f_time, double e_time) range_ptr->range_start, range_ptr->range_end, value_ts, range_ptr->count_in_range, - range_ptr->min, second_value_ts, - range_ptr->max, second_value_ts, + range_ptr->rrt_min, second_value_ts, + range_ptr->rrt_max, second_value_ts, range_ptr->total_in_range, second_value_ts, buffer); } @@ -1257,17 +1353,19 @@ static void ls3_stats_print_to_csv(const char *f_time, double e_time) "Device path [%s]\n" "Device name [%s]\n" "Device type [%s]\n" - "Device size in KB [%lu]\n" + "Inodes count on device [%u]\n" + "Free inodes count on device [%u]\n" "Client mount path [%s]\n\n", LS3_STATS_VERSION, f_time, reports_with_stats->total_count_files, e_time, reports_with_stats->device_path, reports_with_stats->device_name, reports_with_stats->device_is_mdt ? "MDT" : "OST", - reports_with_stats->device_size >> 10, + reports_with_stats->inodes_count, + reports_with_stats->free_inodes_count, reports_with_stats->client_mount_path); - for (i = 0; i < LS3_STATS_TOTAL_COUNT_REPORT; i++) { + for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) { char *value_ts; char *title_text; char *second_value_ts; @@ -1288,17 +1386,19 @@ static void ls3_stats_print_to_csv(const char *f_time, double e_time) fprintf(csv_fd, "General,\nCount,%lu\nMinValueInRanges,%lu,%s\n" "MaxValueInRanges,%lu,%s\nAverageValueInRanges,%lu,%s\n" "TotalValue,%lu,%s\n\n", - report_ptr->files_count, report_ptr->min, - value_ts, report_ptr->max, value_ts, report_ptr->avg, - value_ts, report_ptr->total_value, - (second_value_ts[0] != '\0') ? second_value_ts : value_ts); + report_ptr->files_count, report_ptr->rt_min, + value_ts, report_ptr->rt_max, value_ts, + report_ptr->rt_avg, value_ts, report_ptr->total_value, + (second_value_ts[0] != '\0') ? + second_value_ts : value_ts); fprintf(csv_fd, "Range,RangeCount," - "RangePercentage,RangeCumulativePercentage,TotalInRange," - "PercentInRange,PercentCumulativeInRange,RangeMin,RangeMax\n"); + "RangePercentage,RangeCumulativePercentage," + "TotalInRange,PercentInRange,PercentCumulativeInRange," + "RangeMin,RangeMax\n"); for (j = 0; j < report_ptr->count_ranges; j++) { - char range_t[30]; + char range_t[30]; /* size in 30 byte enough */ range_ptr = report_ptr->fs_ranges[j]; if (range_ptr == NULL) @@ -1308,14 +1408,21 @@ static void ls3_stats_print_to_csv(const char *f_time, double e_time) continue; /* Nothing for print */ /* Different type of "range" field */ - ls3_stats_get_range_str(range_ptr, range_t, j, i, value_ts); - fprintf(csv_fd, "%s,%lu,%.2f,%.2f,%lu %s,%.2f,%.2f,%lu %s,%lu %s\n", - range_t, range_ptr->count_in_range, range_ptr->percentage, - range_ptr->cumulative_percentage, range_ptr->total_in_range, - (second_value_ts[0] != '\0') ? second_value_ts : value_ts, + ls3_stats_get_range_str(range_ptr, range_t, + sizeof(range_t), + j, i, value_ts); + fprintf(csv_fd, "%s,%lu,%.2f,%.2f,%lu %s,%.2f,%.2f," + "%lu %s,%lu %s\n", + range_t, range_ptr->count_in_range, + range_ptr->percentage, + range_ptr->cumulative_percentage, + range_ptr->total_in_range, + (second_value_ts[0] != '\0') ? + second_value_ts : value_ts, range_ptr->percent_in_range, range_ptr->percent_cumulative_in_range, - range_ptr->min, value_ts, range_ptr->max, value_ts); + range_ptr->rrt_min, value_ts, + range_ptr->rrt_max, value_ts); } fprintf(csv_fd, "\n"); fprintf(csv_fd, "--------------------------------------------" @@ -1342,8 +1449,9 @@ static void ls3_stats_print_to_csv(const char *f_time, double e_time) LS3_FATAL("Unable to access the user report data: %d\n", j); fprintf(csv_fd, "\n%s\n", title ); - fprintf(csv_fd, "RangeDayStart,RangeDayEnd,CountFilesInRange," - "MinSizeKB,MaxSizeKB,TotalSizeInRangeKB,LastTimeAccess\n"); + fprintf(csv_fd, "RangeDayStart,RangeDayEnd," + "CountFilesInRange,MinSizeKB,MaxSizeKB," + "TotalSizeInRangeKB,LastTimeAccess\n"); for (k = 0; k < report_ptr->count_ranges; k++) { char buffer[20]; @@ -1352,14 +1460,14 @@ static void ls3_stats_print_to_csv(const char *f_time, double e_time) if (range_ptr == NULL) continue; - ls3_stats_get_time_str(buffer, + ls3_stats_get_time_str(buffer, sizeof(buffer), range_ptr->last_time_access); fprintf(csv_fd, "%lu,%lu,%lu,%lu,%lu,%lu,%s\n", range_ptr->range_start, range_ptr->range_end, range_ptr->count_in_range, - range_ptr->min, range_ptr->max, + range_ptr->rrt_min, range_ptr->rrt_max, range_ptr->total_in_range, buffer); } } @@ -1416,7 +1524,7 @@ void ls3_stats_calculate_values(void) struct report_template *report_ptr; struct range_report_template *range_ptr; - for (i = 0; i < LS3_STATS_TOTAL_COUNT_REPORT; i++) { + for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) { double cumulative_percentage = 0; double percent_cumulative_in_range = 0; @@ -1427,11 +1535,11 @@ void ls3_stats_calculate_values(void) if (report_ptr->files_count == 0) continue; - if (i == LS3_STATS_FILES_SIZE) + if (i == LS3_STATS_TYPE_FILES_SIZE) reports_with_stats->total_count_files = report_ptr->files_count; - report_ptr->avg = + report_ptr->rt_avg = report_ptr->total_value / report_ptr->files_count; for (j = 0; j < report_ptr->count_ranges; j++) { @@ -1463,10 +1571,6 @@ void ls3_stats_calculate_values(void) range_ptr->percent_in_range; } } - - if (reports_with_stats->device_path) - reports_with_stats->device_size = - ls3_stats_get_dev_size(reports_with_stats->device_path); } static struct range_report_template *ls3_stats_get_new_range_ptr(uint64_t res) @@ -1474,7 +1578,7 @@ static struct range_report_template *ls3_stats_get_new_range_ptr(uint64_t res) struct range_report_template *range_ptr; range_ptr = xcalloc(1, sizeof(struct range_report_template)); - range_ptr->min = UINT64_MAX; + range_ptr->rrt_min = UINT64_MAX; if (res >= 2) { range_ptr->range_start = (int)pow(2, floor(log2(res))); range_ptr->range_end = range_ptr->range_start * 2; @@ -1492,9 +1596,9 @@ static struct report_template *ls3_stats_get_new_report_ptr(void) xcalloc(1, sizeof(struct report_template)); report_ptr->count_ranges = LS3_STATS_COUNT_RANGE_BY_DEFAULT; - report_ptr->min = UINT64_MAX; + report_ptr->rt_min = UINT64_MAX; report_ptr->total_value = 0; - report_ptr->curent_max_range = pow(2, report_ptr->count_ranges); + report_ptr->current_max_range = pow(2, report_ptr->count_ranges); report_ptr->fs_ranges = (struct range_report_template**)xcalloc( report_ptr->count_ranges, sizeof(struct range_report_template*)); @@ -1538,32 +1642,32 @@ static void ls3_stats_update_range(ls3_stats_report_type report_type, value_type = ls3_stats_get_value_type(report_type); switch (value_type) { - case LS3_STATS_VALUE_TYPE_KB: - result_range_value = range_value >> 10; - break; - case LS3_STATS_VALUE_TYPE_DAYS: - result_range_value = ls3_stats_get_day_diff(range_value); - result_second_value = second_value >> 10; - report_ptr->second_value_type = LS3_STATS_VALUE_TYPE_KB; - break; - default: - result_range_value = range_value; - report_ptr->second_value_type = - LS3_STATS_VALUE_TYPE_EMPTY; - result_second_value = 0; - break; + case LS3_STATS_VALUE_TYPE_KB: + result_range_value = range_value >> 10; + break; + case LS3_STATS_VALUE_TYPE_DAYS: + result_range_value = ls3_stats_get_day_diff(range_value); + result_second_value = second_value >> 10; + report_ptr->second_value_type = LS3_STATS_VALUE_TYPE_KB; + break; + default: + result_range_value = range_value; + report_ptr->second_value_type = + LS3_STATS_VALUE_TYPE_EMPTY; + result_second_value = 0; + break; } report_ptr->value_type = value_type; index_range = ls3_stats_get_range_index(result_range_value); pthread_mutex_lock(&report_ptr->report_template_mutex); - if (result_range_value < report_ptr->min) - report_ptr->min = result_range_value; + if (result_range_value < report_ptr->rt_min) + report_ptr->rt_min = result_range_value; - if (result_range_value > report_ptr->max) { - report_ptr->max = result_range_value; - report_ptr->curent_max_range = pow(2, report_ptr->max); + if (result_range_value > report_ptr->rt_max) { + report_ptr->rt_max = result_range_value; + report_ptr->current_max_range = pow(2, report_ptr->rt_max); if (index_range > report_ptr->count_ranges - 1) ls3_stats_expand_num_of_ranges(report_ptr, index_range); @@ -1577,30 +1681,30 @@ static void ls3_stats_update_range(ls3_stats_report_type report_type, switch (report_type) { - case LS3_STATS_TIME_SINCE_LAST_MOD_RF: - case LS3_STATS_TIME_SINCE_LAST_MD_MOD_RF: - case LS3_STATS_TIME_SINCE_LAST_ACCESS_RF: - case LS3_STATS_TIME_SINCE_LAST_CREATION_RF: - /* When the range is time and the value - * is expressed in size */ - range_ptr->total_in_range += result_second_value; - report_ptr->total_value += result_second_value; - break; - default: - /* When range and value have same type for print */ - range_ptr->total_in_range += result_range_value; - report_ptr->total_value += result_range_value; - break; + case LS3_STATS_TYPE_TIME_SINCE_LAST_MOD_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_MD_MOD_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_ACCESS_RF: + case LS3_STATS_TYPE_TIME_SINCE_LAST_CREATION_RF: + /* When the range is time and the value + * is expressed in size */ + range_ptr->total_in_range += result_second_value; + report_ptr->total_value += result_second_value; + break; + default: + /* When range and value have same type for print */ + range_ptr->total_in_range += result_range_value; + report_ptr->total_value += result_range_value; + break; } range_ptr->count_in_range++; report_ptr->files_count++; - if (result_range_value < range_ptr->min) - range_ptr->min = result_range_value; + if (result_range_value < range_ptr->rrt_min) + range_ptr->rrt_min = result_range_value; - if (result_range_value > range_ptr->max) - range_ptr->max = result_range_value; + if (result_range_value > range_ptr->rrt_max) + range_ptr->rrt_max = result_range_value; pthread_mutex_unlock(&report_ptr->report_template_mutex); @@ -1641,9 +1745,9 @@ static void ls3_stats_update_range_with_id(ls3_stats_report_type report_type, if (!report_ptr) LS3_FATAL("Unable to access the report data: %d\n", report_type); - /* LS3_STATS_STRIPE_SIZE Will display in KB + /* LS3_STATS_TYPE_STRIPE_SIZE Will display in KB * (+ exception redundant pointer allocations) */ - if (report_type == LS3_STATS_STRIPE_SIZE) + if (report_type == LS3_STATS_TYPE_STRIPE_SIZE) local_id = local_id >> 10; /* Get size in KB (here it's only for users & groups) */ @@ -1651,12 +1755,12 @@ static void ls3_stats_update_range_with_id(ls3_stats_report_type report_type, report_ptr->value_type = LS3_STATS_VALUE_TYPE_KB; pthread_mutex_lock(&report_ptr->report_template_mutex); - if (result_second_value < report_ptr->min) - report_ptr->min = result_second_value; + if (result_second_value < report_ptr->rt_min) + report_ptr->rt_min = result_second_value; - if (result_second_value > report_ptr->max) { - report_ptr->max = result_second_value; - report_ptr->curent_max_range = local_id; + if (result_second_value > report_ptr->rt_max) { + report_ptr->rt_max = result_second_value; + report_ptr->current_max_range = local_id; } range_ptr = ls3_stats_find_id_in_ranges(local_id, report_ptr); @@ -1673,8 +1777,7 @@ static void ls3_stats_update_range_with_id(ls3_stats_report_type report_type, range_ptr = report_ptr->fs_ranges[current_index]; if (!range_ptr) { - range_ptr = - ls3_stats_get_new_range_ptr(LS3_STATS_EMPTY_VALUE); + range_ptr = ls3_stats_get_new_range_ptr(LS3_STATS_EMPTY_VALUE); range_ptr->rrt_id = local_id; report_ptr->fs_ranges[current_index] = range_ptr; } @@ -1686,11 +1789,11 @@ static void ls3_stats_update_range_with_id(ls3_stats_report_type report_type, report_ptr->total_value += result_second_value; report_ptr->files_count++; - if (result_second_value < range_ptr->min) - range_ptr->min = result_second_value; + if (result_second_value < range_ptr->rrt_min) + range_ptr->rrt_min = result_second_value; - if (result_second_value > range_ptr->max) - range_ptr->max = result_second_value; + if (result_second_value > range_ptr->rrt_max) + range_ptr->rrt_max = result_second_value; pthread_mutex_unlock(&report_ptr->report_template_mutex); } @@ -1834,12 +1937,12 @@ static void ls3_stats_update_user_report_range(ls3_stats_users_reports report_ty index_range = ls3_stats_get_range_index(result_range_value); pthread_mutex_lock(&report_ptr->report_template_mutex); - if (result_range_value < report_ptr->min) - report_ptr->min = result_range_value; + if (result_range_value < report_ptr->rt_min) + report_ptr->rt_min = result_range_value; - if (result_range_value > report_ptr->max) { - report_ptr->max = result_range_value; - report_ptr->curent_max_range = pow(2, report_ptr->max); + if (result_range_value > report_ptr->rt_max) { + report_ptr->rt_max = result_range_value; + report_ptr->current_max_range = pow(2, report_ptr->rt_max); if (index_range > report_ptr->count_ranges - 1) ls3_stats_expand_num_of_ranges(report_ptr, index_range); @@ -1859,11 +1962,11 @@ static void ls3_stats_update_user_report_range(ls3_stats_users_reports report_ty if (range > range_ptr->last_time_access) range_ptr->last_time_access = range; - if (result_second_value < range_ptr->min) - range_ptr->min = result_second_value; + if (result_second_value < range_ptr->rrt_min) + range_ptr->rrt_min = result_second_value; - if (result_second_value > range_ptr->max) - range_ptr->max = result_second_value; + if (result_second_value > range_ptr->rrt_id) + range_ptr->rrt_max = result_second_value; pthread_mutex_unlock(&report_ptr->report_template_mutex); } @@ -1873,33 +1976,41 @@ int ls3_stats_update_info(struct ls3_object_attrs *loa_all) { struct lipe_path_entry *lpe; uint64_t allocate_file_size = 0; - uint64_t alligned_size = 0; /* relative to block size */ - uint16_t block_size = 512; const char *file_name; - allocate_file_size = loa_all->loa_blocks * block_size; - alligned_size = loa_all->loa_size + block_size - 1; + /* loa_all->loa_blocks is taken from the inode and reflects the . + * number of 512B blocks. Since in the blocks_from_inode() + * function we get the value from inode->i_blocks which is equal + * to the number of blocks with a size of 512B */ + allocate_file_size = loa_all->loa_blocks * 512; + /* It is likely that loa_all->loa_size is also aligned to a + * block of 512 bytes somewhere in EXT2_I_SIZE(inode)... + * For this reason, we do not align the size. */ + + if (allocate_file_size == 0 && loa_all->loa_size == 0) + /* Skip this, TODO: reports_with_stats->error_counter++ */ + return 0; /* In most cases loa_all->loa_blocks is not available on MDT. */ if (!reports_with_stats->device_is_mdt) { /* Get equal overhead (Files whose size is equal * than capacity used. */ - if (allocate_file_size == alligned_size) - ls3_stats_update_range(LS3_STATS_EQUAL_OVERHEAD, + if (allocate_file_size == loa_all->loa_size) + ls3_stats_update_range(LS3_STATS_TYPE_EQUAL_OVERHEAD, loa_all->loa_size, LS3_STATS_EMPTY_VALUE); /* Get positive overhead (Files whose capacity used is * larger than to its size. */ - else if (allocate_file_size - alligned_size > 0) - ls3_stats_update_range(LS3_STATS_POSITIVE_OVERHEAD, + else if (allocate_file_size > loa_all->loa_size) + ls3_stats_update_range(LS3_STATS_TYPE_POSITIVE_OVERHEAD, allocate_file_size - loa_all->loa_size, LS3_STATS_EMPTY_VALUE); /* Get negative overhead (Files whose size is larger than * capacity used. Includes directories, symlinks and * regular files). */ - else if (alligned_size - allocate_file_size > 0) - ls3_stats_update_range(LS3_STATS_NEGATIVE_OVERHEAD, + else + ls3_stats_update_range(LS3_STATS_TYPE_NEGATIVE_OVERHEAD, loa_all->loa_size - allocate_file_size, LS3_STATS_EMPTY_VALUE); @@ -1909,7 +2020,7 @@ int ls3_stats_update_info(struct ls3_object_attrs *loa_all) * and special files) */ lipe_list_for_each_entry(lpe, &loa_all->loa_paths, lpe_linkage) { file_name = ls3_stats_get_filename_from_path(lpe->lpe_path); - ls3_stats_update_range(LS3_STATS_FILENAME_LENGTH, + ls3_stats_update_range(LS3_STATS_TYPE_FILENAME_LENGTH, (int16_t)strlen(file_name), LS3_STATS_EMPTY_VALUE); } @@ -1918,23 +2029,23 @@ int ls3_stats_update_info(struct ls3_object_attrs *loa_all) if (!(loa_all->loa_mode & S_IFREG)) return 0; - ls3_stats_update_range(LS3_STATS_FILES_SIZE, loa_all->loa_size, + ls3_stats_update_range(LS3_STATS_TYPE_FILES_SIZE, loa_all->loa_size, LS3_STATS_EMPTY_VALUE); - ls3_stats_update_range(LS3_STATS_TIME_SINCE_LAST_MOD_RF, + ls3_stats_update_range(LS3_STATS_TYPE_TIME_SINCE_LAST_MOD_RF, loa_all->loa_mtime, loa_all->loa_size); - ls3_stats_update_range(LS3_STATS_TIME_SINCE_LAST_MD_MOD_RF, + ls3_stats_update_range(LS3_STATS_TYPE_TIME_SINCE_LAST_MD_MOD_RF, loa_all->loa_ctime, loa_all->loa_size); - ls3_stats_update_range(LS3_STATS_TIME_SINCE_LAST_CREATION_RF, + ls3_stats_update_range(LS3_STATS_TYPE_TIME_SINCE_LAST_CREATION_RF, loa_all->loa_crtime, loa_all->loa_size); - ls3_stats_update_range(LS3_STATS_TIME_SINCE_LAST_ACCESS_RF, + ls3_stats_update_range(LS3_STATS_TYPE_TIME_SINCE_LAST_ACCESS_RF, loa_all->loa_atime, loa_all->loa_size); - ls3_stats_update_range_with_id(LS3_STATS_STORAGE_SET_SIZE_BY_USER, + ls3_stats_update_range_with_id(LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_USER, loa_all->loa_uid, loa_all->loa_size); - ls3_stats_update_range_with_id(LS3_STATS_STORAGE_SET_SIZE_BY_GROUP, + ls3_stats_update_range_with_id(LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_GROUP, loa_all->loa_gid, loa_all->loa_size); - ls3_stats_update_range_with_id(LS3_STATS_STORAGE_SET_SIZE_BY_PROJID, + ls3_stats_update_range_with_id(LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_PROJID, loa_all->loa_projid, loa_all->loa_size); ls3_stats_update_user_report_range(LS3_STATS_USERS_REPORTS_MOD_RF, @@ -1982,13 +2093,13 @@ int ls3_stats_update_info(struct ls3_object_attrs *loa_all) if (rc < 0) return -1; - ls3_stats_update_range(LS3_STATS_STRIPE_COUNT, stripe_count, + ls3_stats_update_range(LS3_STATS_TYPE_STRIPE_COUNT, stripe_count, LS3_STATS_EMPTY_VALUE); - ls3_stats_update_range_with_id(LS3_STATS_MIRROR_COUNT, + ls3_stats_update_range_with_id(LS3_STATS_TYPE_MIRROR_COUNT, mirror_count, loa_all->loa_size); - ls3_stats_update_range_with_id(LS3_STATS_STRIPE_SIZE, + ls3_stats_update_range_with_id(LS3_STATS_TYPE_STRIPE_SIZE, stripe_size, loa_all->loa_size); /* TODO: Get info about compression (lvl/type/chunk_log_bits) @@ -1999,15 +2110,15 @@ int ls3_stats_update_info(struct ls3_object_attrs *loa_all) ptr_filter_fid = loa_all->loa_filter_fid; ptr_ost_layout = ptr_filter_fid.ff_layout; - ls3_stats_update_range(LS3_STATS_STRIPE_COUNT, + ls3_stats_update_range(LS3_STATS_TYPE_STRIPE_COUNT, ptr_ost_layout.ol_stripe_count, LS3_STATS_EMPTY_VALUE); - ls3_stats_update_range_with_id(LS3_STATS_STRIPE_SIZE, + ls3_stats_update_range_with_id(LS3_STATS_TYPE_STRIPE_SIZE, ptr_ost_layout.ol_stripe_size, loa_all->loa_size); - ls3_stats_update_range(LS3_STATS_CAPACITY_USED, + ls3_stats_update_range(LS3_STATS_TYPE_CAPACITY_USED, allocate_file_size, LS3_STATS_EMPTY_VALUE); } @@ -2020,7 +2131,7 @@ void ls3_stats_init(void) int i; reports_with_stats = xcalloc(1, sizeof(struct fstats_report)); - for (i = 0; i < LS3_STATS_TOTAL_COUNT_REPORT; i++) { + for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) { struct report_template *report_ptr = ls3_stats_get_new_report_ptr(); @@ -2033,10 +2144,8 @@ void ls3_stats_init(void) (struct ls3_stats_user_report_template**)xcalloc( reports_with_stats->max_count_users_in_report, sizeof(struct ls3_stats_user_report_template*)); - reports_with_stats->last_user_idx_in_array = 0; - - reports_with_stats->device_size = 0; + reports_with_stats->last_user_idx_in_array = 0; reports_with_stats->start_time = time(NULL); pthread_mutex_init(&reports_with_stats->user_rt_mutex, NULL); } @@ -2045,7 +2154,7 @@ void ls3_stats_destroy(void) { int i, j, k; - for (i = 0; i < LS3_STATS_TOTAL_COUNT_REPORT; i++) { + for (i = 0; i < LS3_STATS_TYPE_TOTAL_COUNT_REPORT; i++) { struct report_template *report_ptr = reports_with_stats->reports[i]; diff --git a/lipe/src/lipe_scan3/ls3_stats.h b/lipe/src/lipe_scan3/ls3_stats.h index e414d76..c2ced90 100644 --- a/lipe/src/lipe_scan3/ls3_stats.h +++ b/lipe/src/lipe_scan3/ls3_stats.h @@ -50,27 +50,29 @@ typedef struct { } ls3_stats_extension_mapping; typedef enum { - LS3_STATS_FILES_SIZE = 0, - LS3_STATS_CAPACITY_USED, - LS3_STATS_EQUAL_OVERHEAD, - LS3_STATS_POSITIVE_OVERHEAD, - LS3_STATS_NEGATIVE_OVERHEAD, - LS3_STATS_DIRECTORY_SIZE_ENTRIES, - LS3_STATS_DIRECTORY_SIZE_KB, - LS3_STATS_LINK_COUNT, - LS3_STATS_FILENAME_LENGTH, - LS3_STATS_TIME_SINCE_LAST_MOD_RF, - LS3_STATS_TIME_SINCE_LAST_MD_MOD_RF, - LS3_STATS_TIME_SINCE_LAST_CREATION_RF, - LS3_STATS_TIME_SINCE_LAST_ACCESS_RF, - LS3_STATS_FILES_EMPLOYING_DOM, - LS3_STATS_STORAGE_SET_SIZE_BY_USER, - LS3_STATS_STORAGE_SET_SIZE_BY_GROUP, - LS3_STATS_STORAGE_SET_SIZE_BY_PROJID, - LS3_STATS_STRIPE_COUNT, - LS3_STATS_STRIPE_SIZE, - LS3_STATS_MIRROR_COUNT, - LS3_STATS_TOTAL_COUNT_REPORT /* Should always be the last */ + LS3_STATS_TYPE_FILES_SIZE = 0, + LS3_STATS_TYPE_CAPACITY_USED, + LS3_STATS_TYPE_EQUAL_OVERHEAD, + LS3_STATS_TYPE_POSITIVE_OVERHEAD, + LS3_STATS_TYPE_NEGATIVE_OVERHEAD, + LS3_STATS_TYPE_COMPRESSION_RATIO, + LS3_STATS_TYPE_DIRECTORY_SIZE_ENTRIES, + LS3_STATS_TYPE_DIRECTORY_SIZE_KB, + LS3_STATS_TYPE_LINK_COUNT, + LS3_STATS_TYPE_FILENAME_LENGTH, + LS3_STATS_TYPE_SYMLINK_TARGET_LENGTH, + LS3_STATS_TYPE_TIME_SINCE_LAST_MOD_RF, + LS3_STATS_TYPE_TIME_SINCE_LAST_MD_MOD_RF, + LS3_STATS_TYPE_TIME_SINCE_LAST_CREATION_RF, + LS3_STATS_TYPE_TIME_SINCE_LAST_ACCESS_RF, + LS3_STATS_TYPE_FILES_EMPLOYING_DOM, + LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_USER, + LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_GROUP, + LS3_STATS_TYPE_STORAGE_SET_SIZE_BY_PROJID, + LS3_STATS_TYPE_STRIPE_COUNT, + LS3_STATS_TYPE_STRIPE_SIZE, + LS3_STATS_TYPE_MIRROR_COUNT, + LS3_STATS_TYPE_TOTAL_COUNT_REPORT /* Should always be the last */ } ls3_stats_report_type; typedef enum { @@ -90,10 +92,10 @@ struct range_report_template { uint64_t rrt_id; /* UID/GID/PRJID/StripeSize */ uint64_t range_start; uint64_t range_end; - uint64_t count_in_range; - uint64_t total_in_range; - uint64_t min; - uint64_t max; + uint64_t count_in_range; /* Count object in range */ + uint64_t total_in_range; /* Total value in range (size) */ + uint64_t rrt_min; + uint64_t rrt_max; /* last_time_access - only for users time report. * Displays the last modified date of the files in the range */ uint64_t last_time_access; @@ -107,11 +109,11 @@ struct report_template { pthread_mutex_t report_template_mutex; uint64_t files_count; /* total files count in report */ uint64_t total_value; /* size/chars/... in all range */ - uint64_t min; - uint64_t max; - uint64_t avg; + uint64_t rt_min; + uint64_t rt_max; + uint64_t rt_avg; uint64_t last_idx_in_fs_ranges; /* current last idx in fs_ranges */ - unsigned int curent_max_range; + unsigned int current_max_range; unsigned int count_ranges; ls3_stats_val_type value_type; /* KB/entries/chars/links/days */ ls3_stats_val_type second_value_type; /* KB/entries/chars/links/days */ @@ -133,17 +135,20 @@ struct fstats_report { pthread_mutex_t user_rt_mutex; time_t start_time; uint64_t total_count_files; - uint64_t device_size; /* In bytes */ uint64_t max_count_users_in_report; /* current max array size */ uint64_t last_user_idx_in_array; /* current last idx in array */ + uint32_t inodes_count; + uint32_t free_inodes_count; + unsigned int block_size; /* from ext2_filsys */ int report_extension; /* bitmap for extension */ + int error_counter; /* When can't get object size */ char *report_file_name; char *format_report_file_name; char *device_path; char *device_name; char *client_mount_path; bool device_is_mdt; - struct report_template *reports[LS3_STATS_TOTAL_COUNT_REPORT]; + struct report_template *reports[LS3_STATS_TYPE_TOTAL_COUNT_REPORT]; struct ls3_stats_user_report_template **users_reports; }; @@ -151,7 +156,6 @@ struct fstats_report *reports_with_stats; void ls3_stats_init(void); void ls3_stats_destroy(void); int ls3_stats_get_range_index(uint64_t num); -uint64_t ls3_stats_get_dev_size(const char* device_path); int ls3_stats_update_info(struct ls3_object_attrs *loa_all); void ls3_stats_calculate_values(void); void ls3_stats_printf(void); -- 1.8.3.1