Skip to content

Commit

Permalink
Update functons used to count number of FC hosts
Browse files Browse the repository at this point in the history
Update/improve functions used to count number of FC hosts:
1) Move code used to count hosts from sa_wrap.c to its normal location
(count.c).
2) Preallocate FC host structures to take into account a possibly
dynamically registerd host. No structures are allocated only if
/sys/class/fc_host directory is not found.

Signed-off-by: Sebastien GODARD <[email protected]>
  • Loading branch information
sysstat committed Apr 12, 2015
1 parent a3797b1 commit a187f65
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
33 changes: 33 additions & 0 deletions count.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,38 @@ int get_filesystem_nr(void)
return fs;
}

/*
***************************************************************************
* Find number of fibre channel hosts in /sys/class/fc_host/.
*
* RETURNS:
* Number of FC hosts.
* Return -1 if directory doesn't exist in sysfs.
***************************************************************************
*/
int get_fchost_nr(void)
{
DIR *dir;
struct dirent *drd;
int fc = 0;

if ((dir = opendir(SYSFS_FCHOST)) == NULL) {
/* Directory non-existent */
return -1;
}

while ((drd = readdir(dir)) != NULL) {

if (!strncmp(drd->d_name, "host", 4)) {
fc++;
}
}

/* Close directory */
closedir(dir);

return fc;
}

/*------------------ END: FUNCTIONS USED BY SADC ONLY ---------------------*/
#endif /* SOURCE_SADC */
2 changes: 2 additions & 0 deletions count.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ extern int
get_usb_nr(void);
extern int
get_filesystem_nr(void);
extern int
get_fchost_nr(void);

#endif /* _COUNT_H */
4 changes: 4 additions & 0 deletions json_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2184,6 +2184,10 @@ __print_funct_t json_print_fchost_stats(struct activity *a, int curr, int tab,
sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize);
sfcp = (struct stats_fchost *) ((char *) a->buf[!curr] + i * a->msize);

if (!sfcc->fchost_name[0])
/* We are at the end of the list */
break;

if (sep)
printf(",\n");

Expand Down
4 changes: 4 additions & 0 deletions pr_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,10 @@ __print_funct_t print_fchost_stats(struct activity *a, int prev, int curr,
sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize);
sfcp = (struct stats_fchost *) ((char *) a->buf[prev] + i * a->msize);

if (!sfcc->fchost_name[0])
/* We are at the end of the list */
break;

printf("%-11s %9.2f %9.2f %9.2f %9.2f %s\n", timestamp[curr],
S_VALUE(sfcp->f_rxframes, sfcc->f_rxframes, itv),
S_VALUE(sfcp->f_txframes, sfcc->f_txframes, itv),
Expand Down
1 change: 1 addition & 0 deletions prealloc.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
#define NR_FREQ_PREALLOC (0 * @PREALLOC_FACTOR@)
#define NR_USB_PREALLOC (5 * @PREALLOC_FACTOR@)
#define NR_FILESYSTEM_PREALLOC (3 * @PREALLOC_FACTOR@)
#define NR_FCHOST_PREALLOC (1 * @PREALLOC_FACTOR@)

#endif /* _PREALLOC_H */
4 changes: 4 additions & 0 deletions rndr_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,6 +2940,10 @@ __print_funct_t render_fchost_stats(struct activity *a, int isdb, char *pre,
sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize);
sfcp = (struct stats_fchost *) ((char *) a->buf[!curr] + i * a->msize);

if (!sfcc->fchost_name[0])
/* We are at the end of the list */
break;

render(isdb, pre, PT_NOFLAG ,
"%s\tfch_rxf/s",
"%s",
Expand Down
18 changes: 5 additions & 13 deletions sa_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ __nr_t wrap_get_filesystem_nr(struct activity *a)

/*
***************************************************************************
* Get number of FC hosts
* Get number of FC hosts.
*
* IN:
* @a Activity structure.
Expand All @@ -1140,19 +1140,11 @@ __nr_t wrap_get_filesystem_nr(struct activity *a)
*/
__nr_t wrap_get_fchost_nr(struct activity *a)
{
DIR *dir;
struct dirent *drd;
__nr_t n = 0;

if ((dir = opendir(SYSFS_FCHOST)) == NULL) {
return 0;
}

while ((drd = readdir(dir)) != NULL)
if (strncmp(drd->d_name,"host",4)==0)
n++;

closedir(dir);
if ((n = get_fchost_nr()) >= 0)
/* Return a positive number even if no FC hosts have been found */
return n + NR_FCHOST_PREALLOC;

return n;
return 0;
}
4 changes: 4 additions & 0 deletions xml_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,10 @@ __print_funct_t xml_print_fchost_stats(struct activity *a, int curr, int tab,
sfcc = (struct stats_fchost *) ((char *) a->buf[curr] + i * a->msize);
sfcp = (struct stats_fchost *) ((char *) a->buf[!curr] + i * a->msize);

if (!sfcc->fchost_name[0])
/* We are at the end of the list */
break;

xprintf(tab, "<fchost name=\"%s\" "
"rxframes=\"%.2f\" "
"txframes=\"%.2f\" "
Expand Down

0 comments on commit a187f65

Please sign in to comment.