@cryptotaxi247 / netdata-1 / commits / febffe605

make sure physical disks are listed in /sys/block/

Costa Tsaousis (ktsaou) committed Oct 26, 2017 at 23:07 UTC febffe60581566bc44b7ef36ca6a2ecacfccdae9
1 file changed +20 -5
src/proc_diskstats.c
+20 -5
@@ -2,6 +2,7 @@
2
3 #define RRD_TYPE_DISK "disk"
4
5 +#define DISK_TYPE_UNKNOWN 0
6 #define DISK_TYPE_PHYSICAL 1
7 #define DISK_TYPE_PARTITION 2
8 #define DISK_TYPE_CONTAINER 3
@@ -74,7 +75,8 @@ static struct disk {
75
76 static char *path_to_get_hw_sector_size = NULL;
77 static char *path_to_get_hw_sector_size_partitions = NULL;
77 -static char *path_to_find_block_device = NULL;
78 +static char *path_to_sys_dev_block_major_minor_string = NULL;
79 +static char *path_to_sys_block_device = NULL;
80 static char *path_to_device_mapper = NULL;
81
82 static inline char *get_disk_name(unsigned long major, unsigned long minor, char *disk) {
@@ -159,7 +161,7 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
161 d->device = strdupz(disk);
162 d->major = major;
163 d->minor = minor;
162 - d->type = DISK_TYPE_PHYSICAL; // Default type. Changed later if not correct.
164 + d->type = DISK_TYPE_UNKNOWN; // Default type. Changed later if not correct.
165 d->configured = 0;
166 d->sector_size = 512; // the default, will be changed below
167 d->next = NULL;
@@ -176,14 +178,20 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
178 // find if it is a partition
179 // by checking if /sys/dev/block/MAJOR:MINOR/partition is readable.
180 char buffer[FILENAME_MAX + 1];
179 - snprintfz(buffer, FILENAME_MAX, path_to_find_block_device, major, minor, "partition");
181 +
182 + snprintfz(buffer, FILENAME_MAX, path_to_sys_block_device, disk);
183 + if(likely(access(buffer, R_OK) == 0)) {
184 + d->type = DISK_TYPE_PHYSICAL;
185 + }
186 +
187 + snprintfz(buffer, FILENAME_MAX, path_to_sys_dev_block_major_minor_string, major, minor, "partition");
188 if(likely(access(buffer, R_OK) == 0)) {
189 d->type = DISK_TYPE_PARTITION;
190 }
191 else {
192 // find if it is a container
193 // by checking if /sys/dev/block/MAJOR:MINOR/slaves has entries
186 - snprintfz(buffer, FILENAME_MAX, path_to_find_block_device, major, minor, "slaves/");
194 + snprintfz(buffer, FILENAME_MAX, path_to_sys_dev_block_major_minor_string, major, minor, "slaves/");
195 DIR *dirp = opendir(buffer);
196 if(likely(dirp != NULL)) {
197 struct dirent *dp;
@@ -321,8 +329,11 @@ int do_proc_diskstats(int update_every, usec_t dt) {
329
330 char buffer[FILENAME_MAX + 1];
331
332 + snprintfz(buffer, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/block/%s");
333 + path_to_sys_block_device = config_get(CONFIG_SECTION_DISKSTATS, "path to get block device", buffer);
334 +
335 snprintfz(buffer, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/dev/block/%lu:%lu/%s");
325 - path_to_find_block_device = config_get(CONFIG_SECTION_DISKSTATS, "path to get block device infos", buffer);
336 + path_to_sys_dev_block_major_minor_string = config_get(CONFIG_SECTION_DISKSTATS, "path to get block device infos", buffer);
337
338 snprintfz(buffer, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/block/%s/queue/hw_sector_size");
339 path_to_get_hw_sector_size = config_get(CONFIG_SECTION_DISKSTATS, "path to get h/w sector size", buffer);
@@ -481,6 +492,10 @@ int do_proc_diskstats(int update_every, usec_t dt) {
492 // based on the type of disk
493
494 switch(d->type) {
495 + default:
496 + case DISK_TYPE_UNKNOWN:
497 + break;
498 +
499 case DISK_TYPE_PHYSICAL:
500 def_performance = global_enable_performance_for_physical_disks;
501 break;