From 1fa911d3d1e5012b353bc025ddbff07ae737e283 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sat, 7 Nov 2020 09:20:18 +0100 Subject: [PATCH] sar: Make option -j work with filesystem statistics This patch makes it possible to display the persistent filename of the device (e.g. UUID instead of /dev/sda...) when displaying filesystems statistics (sar -F). Signed-off-by: Sebastien GODARD --- pr_stats.c | 10 ++++++---- sa.h | 2 ++ sa_common.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pr_stats.c b/pr_stats.c index cf61f61..0f88263 100644 --- a/pr_stats.c +++ b/pr_stats.c @@ -2720,6 +2720,7 @@ __print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int cu int i, j, j0, found; struct stats_filesystem *sfc, *sfp, *sfm; int unit = NO_UNIT; + char *dev_name; if (DISPLAY_UNIT(flags)) { /* Default values unit is B */ @@ -2734,10 +2735,12 @@ __print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int cu for (i = 0; i < a->nr[curr]; i++) { sfc = (struct stats_filesystem *) ((char *) a->buf[curr] + i * a->msize); + /* Get name to display (persistent or standard fs name, or mount point) */ + dev_name = get_fs_name_to_display(a, flags, sfc); + if (a->item_list != NULL) { /* A list of devices has been entered on the command line */ - if (!search_list_item(a->item_list, - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name)) + if (!search_list_item(a->item_list, dev_name)) /* Device not found */ continue; } @@ -2789,8 +2792,7 @@ __print_funct_t stub_print_filesystem_stats(struct activity *a, int prev, int cu cprintf_pc(DISPLAY_UNIT(flags), 1, 9, 2, sfc->f_files ? SP_VALUE(sfc->f_ffree, sfc->f_files, sfc->f_files) : 0.0); - cprintf_in(IS_STR, " %s\n", - DISPLAY_MOUNT(a->opt_flags) ? sfc->mountp : sfc->fs_name, 0); + cprintf_in(IS_STR, " %s\n", dev_name, 0); } if (!dispavg) { diff --git a/sa.h b/sa.h index 8b586a2..14626d8 100644 --- a/sa.h +++ b/sa.h @@ -1503,6 +1503,8 @@ char *get_sa_devname (unsigned int, unsigned int, unsigned long long [], unsigned int, uint64_t); void get_file_timestamp_struct (uint64_t, struct tm *, struct file_header *); +char *get_fs_name_to_display + (struct activity *, uint64_t, struct stats_filesystem *); unsigned long long get_global_cpu_statistics (struct activity *, int, int, uint64_t, unsigned char []); void get_global_soft_statistics diff --git a/sa_common.c b/sa_common.c index eb32a91..d39a57d 100644 --- a/sa_common.c +++ b/sa_common.c @@ -3307,4 +3307,38 @@ void get_global_soft_statistics(struct activity *a, int prev, int curr, ssnp_all->flow_limit += ssnp->flow_limit; } } + +/* + *************************************************************************** + * Get filesystem name to display. This may be either the persistent name + * if requested by the user, the standard filesystem name (e.g. /dev/sda1, + * /dev/sdb3, etc.) or the mount point. This is used when displaying + * filesystem statistics: sar -F or sadf -- -F). + * + * IN: + * @a Activity structure. + * @flags Flags for common options and system state. + * @st_fs Statistics for current filesystem. + * + * RETURNS: + * Filesystem name to display. + *************************************************************************** + */ +char *get_fs_name_to_display(struct activity *a, uint64_t flags, struct stats_filesystem *st_fs) +{ + char *pname = NULL, *persist_dev_name; + char fname[MAX_FS_LEN]; + + if (DISPLAY_PERSIST_NAME_S(flags) && !DISPLAY_MOUNT(a->opt_flags)) { + strncpy(fname, st_fs->fs_name, sizeof(fname)); + fname[sizeof(fname) - 1] = '\0'; + if ((persist_dev_name = get_persistent_name_from_pretty(basename(fname))) != NULL) { + pname = persist_dev_name; + } + } + if (!pname) { + pname = DISPLAY_MOUNT(a->opt_flags) ? st_fs->mountp : st_fs->fs_name; + } + return pname; +} #endif /* SOURCE_SADC undefined */ -- 2.40.0