X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdisk.c;h=a07288d13336958f232e9616f93e10084bedcf08;hb=0a8741b9061f8df4a78a448c021612db06e17425;hp=255d4db6076d905210e7fd1628217c05bcaf6db1;hpb=6d01a00ee1fee1a5f8b78d2925d9b4e6979a5c3a;p=collectd.git diff --git a/src/disk.c b/src/disk.c index 255d4db6..a07288d1 100644 --- a/src/disk.c +++ b/src/disk.c @@ -22,6 +22,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" #include "utils_ignorelist.h" @@ -127,7 +128,7 @@ static int numdisk = 0; /* #endif HAVE_LIBKSTAT */ #elif defined(HAVE_LIBSTATGRAB) -/* #endif HAVE_LIBKSTATGRAB */ +/* #endif HAVE_LIBSTATGRAB */ #elif HAVE_PERFSTAT static perfstat_disk_t * stat_disk; @@ -296,15 +297,14 @@ static void disk_submit (const char *plugin_instance, const char *type, derive_t read, derive_t write) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].derive = read; - values[1].derive = write; + value_t values[] = { + { .derive = read }, + { .derive = write }, + }; vl.values = values; - vl.values_len = 2; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); @@ -316,15 +316,14 @@ static void disk_submit (const char *plugin_instance, #if KERNEL_FREEBSD || KERNEL_LINUX static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time) { - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].derive = io_time; - values[1].derive = weighted_time; + value_t values[] = { + { .derive = io_time }, + { .derive = weighted_time }, + }; vl.values = values; - vl.values_len = 2; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "disk_io_time", sizeof (vl.type)); @@ -336,14 +335,10 @@ static void submit_io_time (char const *plugin_instance, derive_t io_time, deriv #if KERNEL_LINUX static void submit_in_progress (char const *disk_name, gauge_t in_progress) { - value_t v; value_list_t vl = VALUE_LIST_INIT; - v.gauge = in_progress; - - vl.values = &v; + vl.values = &(value_t) { .gauge = in_progress }; vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, disk_name, sizeof (vl.plugin_instance)); sstrncpy (vl.type, "pending_operations", sizeof (vl.type)); @@ -351,7 +346,6 @@ static void submit_in_progress (char const *disk_name, gauge_t in_progress) plugin_dispatch_values (&vl); } - static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops) { double interval = CDTIME_T_TO_DOUBLE (plugin_get_interval ()); @@ -893,7 +887,13 @@ static int disk_read (void) #endif if (ignorelist_match (ignorelist, output_name) != 0) + { +#if HAVE_LIBUDEV + /* release udev-based alternate name, if allocated */ + sfree (alt_name); +#endif continue; + } if ((ds->read_bytes != 0) || (ds->write_bytes != 0)) disk_submit (output_name, "disk_octets", @@ -947,12 +947,11 @@ static int disk_read (void) # error "kstat_io_t does not have the required members" # endif static kstat_io_t kio; - int i; if (kc == NULL) return (-1); - for (i = 0; i < numdisk; i++) + for (int i = 0; i < numdisk; i++) { if (kstat_read (kc, ksp[i], &kio) == -1) continue; @@ -990,13 +989,12 @@ static int disk_read (void) # else int disks; #endif - int counter; char name[DATA_MAX_NAME_LEN]; if ((ds = sg_get_disk_io_stats(&disks)) == NULL) return (0); - for (counter=0; counter < disks; counter++) { + for (int counter = 0; counter < disks; counter++) { strncpy(name, ds->disk_name, sizeof(name)); name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */ @@ -1019,7 +1017,6 @@ static int disk_read (void) derive_t write_ops; perfstat_id_t firstpath; int rnumdisk; - int i; if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0) { @@ -1045,7 +1042,7 @@ static int disk_read (void) return (-1); } - for (i = 0; i < rnumdisk; i++) + for (int i = 0; i < rnumdisk; i++) { if (ignorelist_match (ignorelist, stat_disk[i].name) != 0) continue;