]> granicus.if.org Git - sysstat/commitdiff
Update functons used to count number of FC hosts
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 12 Apr 2015 13:15:54 +0000 (15:15 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 12 Apr 2015 13:15:54 +0000 (15:15 +0200)
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 <sysstat@users.noreply.github.com>
count.c
count.h
json_stats.c
pr_stats.c
prealloc.in
rndr_stats.c
sa_wrap.c
xml_stats.c

diff --git a/count.c b/count.c
index 956d52a08ccc86efe473ecd115f3125f59b98eea..4d0b616b457585f27a48ecd99548b88003c3fd37 100644 (file)
--- a/count.c
+++ b/count.c
@@ -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 */
diff --git a/count.h b/count.h
index 454eccff0ab2778f85df1726ad9b9fec6a7bdb6b..7158c7ac2c5d287fe38dafc23b9b2e685edc8246 100644 (file)
--- a/count.h
+++ b/count.h
@@ -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 */
index 0218807793611bb52dbffd927f750240206402a4..8e6ec84fa51bbdc5c59f7454313b57455da6ca76 100644 (file)
@@ -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");
 
index 5a6547d37c596cfb49aac8308cc51600e421b93f..7e52927195c4be0ef8e4db466a24d9ebdc19f2d8 100644 (file)
@@ -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),
index 5dd47bb2b9c14feab3bab20c39e43dc4ce101604..c1f5eab273b7cd7e0126513e57de2f3744850849 100644 (file)
@@ -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 */
index 4aea4ebd8b666057e77072cee82a85fae9bdcb45..82576a85995fd5bfe463c93c1a453a0a4008e3bc 100644 (file)
@@ -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",
index bde84fdcb44f6f1767ff89ccd9b9d3da160473a2..66b71dafa7739489a33a5e1c70434da1ded8261c 100644 (file)
--- a/sa_wrap.c
+++ b/sa_wrap.c
@@ -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.
@@ -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;
 }
index dda5cb8397e46b0da0390b0a10f6c0b6ae783f84..d6db67db4da09429f00002b93b86c3b32d9f850d 100644 (file)
@@ -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\" "