X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdisk.c;h=0095777fbc4df0c3c428f6f107c3382440927264;hp=cfda63513ba75fa70e7753c482e4a36553afb2ef;hb=0a2172433970559cc70821e64778ce88a76b040c;hpb=9f7bed1cfdc00ff9e9160dd2ce01c6156362d450 diff --git a/src/disk.c b/src/disk.c index cfda6351..0095777f 100644 --- a/src/disk.c +++ b/src/disk.c @@ -120,6 +120,9 @@ static struct gmesh geom_tree; /* #endif KERNEL_FREEBSD */ #elif HAVE_LIBKSTAT +#if HAVE_KSTAT_H +#include +#endif #define MAX_NUMDISK 1024 extern kstat_ctl_t *kc; static kstat_t *ksp[MAX_NUMDISK]; @@ -139,7 +142,7 @@ static int pnumdisk; #error "No applicable input method." #endif -#if HAVE_LIBUDEV +#if HAVE_UDEV_H #include static char *conf_udev_name_attr = NULL; @@ -156,7 +159,7 @@ static int disk_config(const char *key, const char *value) { if (ignorelist == NULL) ignorelist = ignorelist_create(/* invert = */ 1); if (ignorelist == NULL) - return (1); + return 1; if (strcasecmp("Disk", key) == 0) { ignorelist_add(ignorelist, value); @@ -173,22 +176,22 @@ static int disk_config(const char *key, const char *value) { "on Mach / Mac OS X and will be ignored."); #endif } else if (strcasecmp("UdevNameAttr", key) == 0) { -#if HAVE_LIBUDEV +#if HAVE_UDEV_H if (conf_udev_name_attr != NULL) { free(conf_udev_name_attr); conf_udev_name_attr = NULL; } if ((conf_udev_name_attr = strdup(value)) == NULL) - return (1); + return 1; #else WARNING("disk plugin: The \"UdevNameAttr\" option is only supported " "if collectd is built with libudev support"); #endif } else { - return (-1); + return -1; } - return (0); + return 0; } /* int disk_config */ static int disk_init(void) { @@ -204,20 +207,20 @@ static int disk_init(void) { if (status != kIOReturnSuccess) { ERROR("IOMasterPort failed: %s", mach_error_string(status)); io_master_port = MACH_PORT_NULL; - return (-1); + return -1; } /* #endif HAVE_IOKIT_IOKITLIB_H */ #elif KERNEL_LINUX -#if HAVE_LIBUDEV +#if HAVE_UDEV_H if (conf_udev_name_attr != NULL) { handle_udev = udev_new(); if (handle_udev == NULL) { ERROR("disk plugin: udev_new() failed!"); - return (-1); + return -1; } } -#endif /* HAVE_LIBUDEV */ +#endif /* HAVE_UDEV_H */ /* #endif KERNEL_LINUX */ #elif KERNEL_FREEBSD @@ -226,12 +229,12 @@ static int disk_init(void) { rv = geom_gettree(&geom_tree); if (rv != 0) { ERROR("geom_gettree() failed, returned %d", rv); - return (-1); + return -1; } rv = geom_stats_open(); if (rv != 0) { ERROR("geom_stats_open() failed, returned %d", rv); - return (-1); + return -1; } /* #endif KERNEL_FREEBSD */ @@ -241,7 +244,7 @@ static int disk_init(void) { numdisk = 0; if (kc == NULL) - return (-1); + return -1; for (numdisk = 0, ksp_chain = kc->kc_chain; (numdisk < MAX_NUMDISK) && (ksp_chain != NULL); @@ -255,17 +258,17 @@ static int disk_init(void) { } #endif /* HAVE_LIBKSTAT */ - return (0); + return 0; } /* int disk_init */ static int disk_shutdown(void) { #if KERNEL_LINUX -#if HAVE_LIBUDEV +#if HAVE_UDEV_H if (handle_udev != NULL) udev_unref(handle_udev); -#endif /* HAVE_LIBUDEV */ +#endif /* HAVE_UDEV_H */ #endif /* KERNEL_LINUX */ - return (0); + return 0; } /* int disk_shutdown */ static void disk_submit(const char *plugin_instance, const char *type, @@ -321,11 +324,11 @@ static counter_t disk_calc_time_incr(counter_t delta_time, double avg_time = ((double)delta_time) / ((double)delta_ops); double avg_time_incr = interval * avg_time; - return ((counter_t)(avg_time_incr + .5)); + return (counter_t)(avg_time_incr + .5); } #endif -#if HAVE_LIBUDEV +#if HAVE_UDEV_H /** * Attempt to provide an rename disk instance from an assigned udev attribute. * @@ -363,7 +366,7 @@ static signed long long dict_get_value(CFDictionaryRef dict, const char *key) { kCFStringEncodingASCII); if (key_obj == NULL) { DEBUG("CFStringCreateWithCString (%s) failed.", key); - return (-1LL); + return -1LL; } /* get => we don't need to release (== free) the object */ @@ -373,15 +376,15 @@ static signed long long dict_get_value(CFDictionaryRef dict, const char *key) { if (val_obj == NULL) { DEBUG("CFDictionaryGetValue (%s) failed.", key); - return (-1LL); + return -1LL; } if (!CFNumberGetValue(val_obj, kCFNumberSInt64Type, &val_int)) { DEBUG("CFNumberGetValue (%s) failed.", key); - return (-1LL); + return -1LL; } - return (val_int); + return val_int; } #endif /* HAVE_IOKIT_IOKITLIB_H */ @@ -408,7 +411,7 @@ static int disk_read(void) { io_master_port, IOServiceMatching(kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) { ERROR("disk plugin: IOServiceGetMatchingServices failed."); - return (-1); + return -1; } while ((disk = IOIteratorNext(disk_list)) != 0) { @@ -490,11 +493,10 @@ static int disk_read(void) { sstrncpy(disk_name, props_disk_name_bsd, sizeof(disk_name)); else { ERROR("disk plugin: can't find bsd disk name."); - ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, - disk_minor); + snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); } } else - ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); + snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); DEBUG("disk plugin: disk_name = \"%s\"", disk_name); @@ -551,7 +553,7 @@ static int disk_read(void) { snap = geom_stats_snapshot_get(); if (snap == NULL) { ERROR("disk plugin: geom_stats_snapshot_get() failed."); - return (-1); + return -1; } /* Check if we have dirty read from this snapshot */ @@ -568,7 +570,7 @@ static int disk_read(void) { if (geom_gettree(&geom_tree) != 0) { ERROR("disk plugin: geom_gettree() failed"); geom_stats_snapshot_free(snap); - return (-1); + return -1; } geom_id = geom_lookupid(&geom_tree, snap_iter->id); } @@ -682,7 +684,7 @@ static int disk_read(void) { fh = fopen("/proc/partitions", "r"); if (fh == NULL) { ERROR("disk plugin: fopen (/proc/{diskstats,partitions}) failed."); - return (-1); + return -1; } /* Kernel is 2.4.* */ @@ -842,7 +844,7 @@ static int disk_read(void) { output_name = disk_name; -#if HAVE_LIBUDEV +#if HAVE_UDEV_H char *alt_name = NULL; if (conf_udev_name_attr != NULL) { alt_name = @@ -853,7 +855,7 @@ static int disk_read(void) { #endif if (ignorelist_match(ignorelist, output_name) != 0) { -#if HAVE_LIBUDEV +#if HAVE_UDEV_H /* release udev-based alternate name, if allocated */ sfree(alt_name); #endif @@ -879,7 +881,7 @@ static int disk_read(void) { submit_io_time(output_name, io_time, weighted_time); } /* if (is_disk) */ -#if HAVE_LIBUDEV +#if HAVE_UDEV_H /* release udev-based alternate name, if allocated */ sfree(alt_name); #endif @@ -910,7 +912,7 @@ static int disk_read(void) { static kstat_io_t kio; if (kc == NULL) - return (-1); + return -1; for (int i = 0; i < numdisk; i++) { if (kstat_read(kc, ksp[i], &kio) == -1) @@ -946,7 +948,7 @@ static int disk_read(void) { char name[DATA_MAX_NAME_LEN]; if ((ds = sg_get_disk_io_stats(&disks)) == NULL) - return (0); + return 0; for (int counter = 0; counter < disks; counter++) { strncpy(name, ds->disk_name, sizeof(name)); @@ -977,7 +979,7 @@ static int disk_read(void) { char errbuf[1024]; WARNING("disk plugin: perfstat_disk: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + return -1; } if (numdisk != pnumdisk || stat_disk == NULL) { @@ -993,7 +995,7 @@ static int disk_read(void) { char errbuf[1024]; WARNING("disk plugin: perfstat_disk : %s", sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + return -1; } for (int i = 0; i < rnumdisk; i++) { @@ -1020,7 +1022,7 @@ static int disk_read(void) { } #endif /* defined(HAVE_PERFSTAT) */ - return (0); + return 0; } /* int disk_read */ void module_register(void) {