X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnetapp.c;h=e83a475388e5704ac39486a027f502accfcb352a;hb=7535ee83bf0b12a168cee3c70e5fb97ed6dfc96c;hp=dbf028507bcb20d3621fbca9cb823a14b4272fa8;hpb=063a5e75b36173e89ffa18d32d47509f6ef968ec;p=collectd.git diff --git a/src/netapp.c b/src/netapp.c index dbf02850..e83a4753 100644 --- a/src/netapp.c +++ b/src/netapp.c @@ -617,7 +617,7 @@ static data_volume_perf_t *get_volume_perf (cfg_volume_perf_t *cvp, /* {{{ */ static int submit_values (const char *host, /* {{{ */ const char *plugin_inst, const char *type, const char *type_inst, - value_t *values, int values_len, + value_t *values, size_t values_len, cdtime_t timestamp, cdtime_t interval) { value_list_t vl = VALUE_LIST_INIT; @@ -649,50 +649,42 @@ static int submit_two_derive (const char *host, const char *plugin_inst, /* {{{ const char *type, const char *type_inst, derive_t val0, derive_t val1, cdtime_t timestamp, cdtime_t interval) { - value_t values[2]; - - values[0].derive = val0; - values[1].derive = val1; + value_t values[] = { + { .derive = val0 }, + { .derive = val1 }, + }; return (submit_values (host, plugin_inst, type, type_inst, - values, 2, timestamp, interval)); + values, STATIC_ARRAY_SIZE (values), timestamp, interval)); } /* }}} int submit_two_derive */ static int submit_derive (const char *host, const char *plugin_inst, /* {{{ */ const char *type, const char *type_inst, derive_t counter, cdtime_t timestamp, cdtime_t interval) { - value_t v; - - v.derive = counter; - return (submit_values (host, plugin_inst, type, type_inst, - &v, 1, timestamp, interval)); + &(value_t) { .derive = counter }, 1, timestamp, interval)); } /* }}} int submit_derive */ static int submit_two_gauge (const char *host, const char *plugin_inst, /* {{{ */ const char *type, const char *type_inst, gauge_t val0, gauge_t val1, cdtime_t timestamp, cdtime_t interval) { - value_t values[2]; - - values[0].gauge = val0; - values[1].gauge = val1; + value_t values[] = { + { .gauge = val0 }, + { .gauge = val1 }, + }; return (submit_values (host, plugin_inst, type, type_inst, - values, 2, timestamp, interval)); + values, STATIC_ARRAY_SIZE (values), timestamp, interval)); } /* }}} int submit_two_gauge */ static int submit_double (const char *host, const char *plugin_inst, /* {{{ */ const char *type, const char *type_inst, double d, cdtime_t timestamp, cdtime_t interval) { - value_t v; - - v.gauge = (gauge_t) d; - return (submit_values (host, plugin_inst, type, type_inst, - &v, 1, timestamp, interval)); + &(value_t) { .gauge = counter }, 1, timestamp, interval)); } /* }}} int submit_uint64 */ /* Calculate hit ratio from old and new counters and submit the resulting @@ -707,7 +699,7 @@ static int submit_cache_ratio (const char *host, /* {{{ */ cdtime_t timestamp, cdtime_t interval) { - value_t v; + value_t v = { .gauge = NAN }; if ((new_hits >= old_hits) && (new_misses >= old_misses)) { uint64_t hits; @@ -717,8 +709,6 @@ static int submit_cache_ratio (const char *host, /* {{{ */ misses = new_misses - old_misses; v.gauge = 100.0 * ((gauge_t) hits) / ((gauge_t) (hits + misses)); - } else { - v.gauge = NAN; } return (submit_values (host, plugin_inst, "cache_ratio", type_inst, @@ -894,7 +884,6 @@ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* const char *plugin_inst; na_elem_t *instances; - na_elem_t *counter; na_elem_iter_t counter_iter; perf_data.timestamp = cna_child_get_cdtime (data); @@ -919,7 +908,7 @@ static int cna_handle_wafl_data (const char *hostname, cfg_wafl_t *cfg_wafl, /* /* Iterate over all counters */ counter_iter = na_child_iterator (na_elem_child (instances, "counters")); - for (counter = na_iterator_next (&counter_iter); + for (na_elem_t *counter = na_iterator_next (&counter_iter); counter != NULL; counter = na_iterator_next (&counter_iter)) { @@ -1055,7 +1044,6 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ { cdtime_t timestamp; na_elem_t *instances; - na_elem_t *instance; na_elem_iter_t instance_iter; disk_t *worst_disk = NULL; @@ -1075,7 +1063,7 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ /* Iterate over all children */ instance_iter = na_child_iterator (instances); - for (instance = na_iterator_next (&instance_iter); + for (na_elem_t *instance = na_iterator_next (&instance_iter); instance != NULL; instance = na_iterator_next(&instance_iter)) { @@ -1083,7 +1071,6 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ disk_t new_data = { 0 }; na_elem_iter_t counter_iterator; - na_elem_t *counter; new_data.timestamp = timestamp; new_data.disk_busy_percent = NAN; @@ -1094,7 +1081,7 @@ static int cna_handle_disk_data (const char *hostname, /* {{{ */ /* Look for the "disk_busy" and "base_for_disk_busy" counters */ counter_iterator = na_child_iterator(na_elem_child(instance, "counters")); - for (counter = na_iterator_next(&counter_iterator); + for (na_elem_t *counter = na_iterator_next(&counter_iterator); counter != NULL; counter = na_iterator_next(&counter_iterator)) { @@ -1251,7 +1238,6 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ cdtime_t timestamp; na_elem_t *elem_instances; na_elem_iter_t iter_instances; - na_elem_t *elem_instance; timestamp = cna_child_get_cdtime (data); @@ -1265,7 +1251,7 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ } iter_instances = na_child_iterator (elem_instances); - for (elem_instance = na_iterator_next(&iter_instances); + for (na_elem_t *elem_instance = na_iterator_next(&iter_instances); elem_instance != NULL; elem_instance = na_iterator_next(&iter_instances)) { @@ -1276,7 +1262,6 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ na_elem_t *elem_counters; na_elem_iter_t iter_counters; - na_elem_t *elem_counter; perf_data.timestamp = timestamp; @@ -1294,7 +1279,7 @@ static int cna_handle_volume_perf_data (const char *hostname, /* {{{ */ continue; iter_counters = na_child_iterator (elem_counters); - for (elem_counter = na_iterator_next(&iter_counters); + for (na_elem_t *elem_counter = na_iterator_next(&iter_counters); elem_counter != NULL; elem_counter = na_iterator_next(&iter_counters)) { @@ -1419,9 +1404,7 @@ static int cna_query_volume_perf (host_config_t *host) /* {{{ */ static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */ cfg_volume_usage_t *cfg_volume, int interval) { - data_volume_usage_t *v; - - for (v = cfg_volume->volumes; v != NULL; v = v->next) + for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next) { char plugin_instance[DATA_MAX_NAME_LEN]; @@ -1542,7 +1525,7 @@ static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */ data_volume_usage_t *v) { uint64_t snap_used = 0, value; - na_elem_t *data, *elem_snap, *elem_snapshots; + na_elem_t *data, *elem_snapshots; na_elem_iter_t iter_snap; data = na_server_invoke_elem(host->srv, v->snap_query); @@ -1574,7 +1557,7 @@ static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */ } iter_snap = na_child_iterator (elem_snapshots); - for (elem_snap = na_iterator_next (&iter_snap); + for (na_elem_t *elem_snap = na_iterator_next (&iter_snap); elem_snap != NULL; elem_snap = na_iterator_next (&iter_snap)) { @@ -1689,7 +1672,6 @@ static void cna_handle_volume_sis_saved (const host_config_t *host, /* {{{ */ static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */ cfg_volume_usage_t *cfg_volume, na_elem_t *data) { - na_elem_t *elem_volume; na_elem_t *elem_volumes; na_elem_iter_t iter_volume; @@ -1703,7 +1685,7 @@ static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */ } iter_volume = na_child_iterator (elem_volumes); - for (elem_volume = na_iterator_next (&iter_volume); + for (na_elem_t *elem_volume = na_iterator_next (&iter_volume); elem_volume != NULL; elem_volume = na_iterator_next (&iter_volume)) { @@ -1827,7 +1809,6 @@ static int cna_query_volume_usage (host_config_t *host) /* {{{ */ static int cna_handle_quota_data (const host_config_t *host, /* {{{ */ cfg_quota_t *cfg_quota, na_elem_t *data) { - na_elem_t *elem_quota; na_elem_t *elem_quotas; na_elem_iter_t iter_quota; @@ -1841,7 +1822,7 @@ static int cna_handle_quota_data (const host_config_t *host, /* {{{ */ } iter_quota = na_child_iterator (elem_quotas); - for (elem_quota = na_iterator_next (&iter_quota); + for (na_elem_t *elem_quota = na_iterator_next (&iter_quota); elem_quota != NULL; elem_quota = na_iterator_next (&iter_quota)) { @@ -1953,7 +1934,6 @@ static int cna_query_quota (host_config_t *host) /* {{{ */ static int cna_handle_snapvault_data (const char *hostname, /* {{{ */ cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval) { - na_elem_t *status; na_elem_iter_t status_iter; status = na_elem_child (data, "status-list"); @@ -1963,7 +1943,7 @@ static int cna_handle_snapvault_data (const char *hostname, /* {{{ */ } status_iter = na_child_iterator (status); - for (status = na_iterator_next (&status_iter); + for (na_elem_t *status = na_iterator_next (&status_iter); status != NULL; status = na_iterator_next (&status_iter)) { @@ -2013,7 +1993,6 @@ static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */ const char *tag; uint32_t records_count; - uint32_t i; records_count = na_child_get_uint32 (data, "records", UINT32_MAX); if (records_count == UINT32_MAX) @@ -2025,7 +2004,7 @@ static int cna_handle_snapvault_iter (host_config_t *host, /* {{{ */ DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag); - for (i = 0; i < records_count; ++i) { + for (uint32_t i = 0; i < records_count; ++i) { na_elem_t *elem; elem = na_server_invoke (host->srv, @@ -2114,7 +2093,6 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */ cfg_system_t *cfg_system, na_elem_t *data, int interval) { na_elem_t *instances; - na_elem_t *counter; na_elem_iter_t counter_iter; derive_t disk_read = 0, disk_written = 0; @@ -2146,7 +2124,7 @@ static int cna_handle_system_data (const char *hostname, /* {{{ */ } counter_iter = na_child_iterator (na_elem_child (instances, "counters")); - for (counter = na_iterator_next (&counter_iter); + for (na_elem_t *counter = na_iterator_next (&counter_iter); counter != NULL; counter = na_iterator_next (&counter_iter)) { @@ -2391,7 +2369,6 @@ static int cna_config_volume_performance (host_config_t *host, /* {{{ */ const oconfig_item_t *ci) { cfg_volume_perf_t *cfg_volume_perf; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2434,7 +2411,7 @@ static int cna_config_volume_performance (host_config_t *host, /* {{{ */ } cfg_volume_perf = host->cfg_volume_perf; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; /* if (!item || !item->key || !*item->key) continue; */ @@ -2518,7 +2495,6 @@ static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */ { cfg_quota_t *cfg_quota; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2534,7 +2510,7 @@ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */ } cfg_quota = host->cfg_quota; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp (item->key, "Interval") == 0) @@ -2550,7 +2526,6 @@ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */ /* Corresponds to a block */ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */ cfg_disk_t *cfg_disk; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2570,7 +2545,7 @@ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */ } cfg_disk = host->cfg_disk; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; /* if (!item || !item->key || !*item->key) continue; */ @@ -2595,7 +2570,6 @@ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */ static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */ { cfg_wafl_t *cfg_wafl; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2613,7 +2587,7 @@ static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */ } cfg_wafl = host->cfg_wafl; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp(item->key, "Interval") == 0) @@ -2663,7 +2637,6 @@ static int cna_config_volume_usage(host_config_t *host, /* {{{ */ const oconfig_item_t *ci) { cfg_volume_usage_t *cfg_volume_usage; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2697,7 +2670,7 @@ static int cna_config_volume_usage(host_config_t *host, /* {{{ */ } cfg_volume_usage = host->cfg_volume_usage; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; /* if (!item || !item->key || !*item->key) continue; */ @@ -2724,7 +2697,6 @@ static int cna_config_snapvault (host_config_t *host, /* {{{ */ const oconfig_item_t *ci) { cfg_snapvault_t *cfg_snapvault; - int i; if ((host == NULL) || (ci == NULL)) return EINVAL; @@ -2741,7 +2713,7 @@ static int cna_config_snapvault (host_config_t *host, /* {{{ */ cfg_snapvault = host->cfg_snapvault; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp (item->key, "Interval") == 0) @@ -2759,7 +2731,6 @@ static int cna_config_system (host_config_t *host, /* {{{ */ oconfig_item_t *ci) { cfg_system_t *cfg_system; - int i; if ((host == NULL) || (ci == NULL)) return (EINVAL); @@ -2778,7 +2749,7 @@ static int cna_config_system (host_config_t *host, /* {{{ */ } cfg_system = host->cfg_system; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *item = ci->children + i; if (strcasecmp(item->key, "Interval") == 0) { @@ -2891,7 +2862,6 @@ static int cna_read (user_data_t *ud); static int cna_register_host (host_config_t *host) /* {{{ */ { char cb_name[256]; - user_data_t ud = { 0 }; if (host->vfiler) ssnprintf (cb_name, sizeof (cb_name), "netapp-%s-%s", @@ -2899,13 +2869,13 @@ static int cna_register_host (host_config_t *host) /* {{{ */ else ssnprintf (cb_name, sizeof (cb_name), "netapp-%s", host->name); - ud.data = host; - ud.free_func = (void (*) (void *)) free_host_config; - plugin_register_complex_read (/* group = */ NULL, cb_name, /* callback = */ cna_read, /* interval = */ host->interval, - /* user data = */ &ud); + &(user_data_t) { + .data = host, + .free_func = (void *) free_host_config, + }); return (0); } /* }}} int cna_register_host */ @@ -2916,7 +2886,6 @@ static int cna_config_host (host_config_t *host, /* {{{ */ oconfig_item_t *item; _Bool is_vfiler = 0; int status; - int i; if (! strcasecmp (ci->key, "VFiler")) is_vfiler = 1; @@ -2930,7 +2899,7 @@ static int cna_config_host (host_config_t *host, /* {{{ */ if (status != 0) return (1); - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { item = ci->children + i; status = 0; @@ -3139,10 +3108,9 @@ static int cna_read (user_data_t *ud) { /* {{{ */ } /* }}} int cna_read */ static int cna_config (oconfig_item_t *ci) { /* {{{ */ - int i; oconfig_item_t *item; - for (i = 0; i < ci->children_num; ++i) { + for (int i = 0; i < ci->children_num; ++i) { item = ci->children + i; if (strcasecmp(item->key, "Host") == 0)