name veritas volume disk groups (#4150)
* name veritas volume disk groups; fixes #4116 * recursive naming of veritas volume groups and local volumes; fixes #4116 * added debugging info to trace it * positive depth should be given to /dev/vx/dsk not /dev/disk/by-id; fixes #4116 * removed debugging; added separator instead of duplicate name * add _ before the final component, when there is a prefix
Costa Tsaousis committed
Sep 13, 2018 at 11:36 UTC
46f715f57c37a749615f5a1298c9741a6ba55738
1 file changed
+78
-39
src/proc_diskstats.c
+78
-39
@@ -143,6 +143,7 @@ static char *path_to_sys_devices_virtual_block_device = NULL;
143
static char *path_to_device_mapper = NULL;
144
static char *path_to_device_label = NULL;
145
static char *path_to_device_id = NULL;
146
+static char *path_to_veritas_volume_groups = NULL;
147
static int name_disks_by_id = CONFIG_BOOLEAN_NO;
148
static int global_bcache_priority_stats_update_every = 0; // disabled by default
149
@@ -308,61 +309,95 @@ static inline int is_major_enabled(int major) {
309
return (int)major_configs[major];
310
}
311
311
-static inline int get_disk_name_from_path(const char *path, char *result, size_t result_size, unsigned long major, unsigned long minor, char *disk) {
312
- char filename[FILENAME_MAX + 1];
313
- int found = 0;
312
+static inline int get_disk_name_from_path(const char *path, char *result, size_t result_size, unsigned long major, unsigned long minor, char *disk, char *prefix, int depth) {
313
+ //info("DEVICE-MAPPER ('%s', %lu:%lu): examining directory '%s' (allowed depth %d).", disk, major, minor, path, depth);
314
315
- result_size--;
315
+ int found = 0;
316
317
DIR *dir = opendir(path);
318
if (!dir) {
319
- error("DEVICE-MAPPER ('%s', %lu:%lu): Cannot open directory '%s'. Disabling device-mapper support.", disk, major, minor, path);
320
- goto cleanup;
319
+ error("DEVICE-MAPPER ('%s', %lu:%lu): Cannot open directory '%s'.", disk, major, minor, path);
320
+ goto failed;
321
}
322
323
struct dirent *de = NULL;
324
while ((de = readdir(dir))) {
325
- if(de->d_type != DT_LNK) continue;
325
+ if(de->d_type == DT_DIR) {
326
+ if((de->d_name[0] == '.' && de->d_name[1] == '\0') || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0'))
327
+ continue;
328
327
- snprintfz(filename, FILENAME_MAX, "%s/%s", path, de->d_name);
328
- ssize_t len = readlink(filename, result, result_size);
329
- if(len <= 0) {
330
- error("DEVICE-MAPPER ('%s', %lu:%lu): Cannot read link '%s'.", disk, major, minor, filename);
331
- continue;
332
- }
329
+ if(depth <= 0) {
330
+ error("DEVICE-MAPPER ('%s', %lu:%lu): Depth limit reached for path '%s/%s'. Ignoring path.", disk, major, minor, path, de->d_name);
331
+ break;
332
+ }
333
+ else {
334
+ char *path_nested = NULL;
335
+ char *prefix_nested = NULL;
336
334
- result[len] = '\0';
335
- if(result[0] != '/')
336
- snprintfz(filename, FILENAME_MAX, "%s/%s", path, result);
337
- else
338
- strncpyz(filename, result, FILENAME_MAX);
337
+ {
338
+ char buffer[FILENAME_MAX + 1];
339
+ snprintfz(buffer, FILENAME_MAX, "%s/%s", path, de->d_name);
340
+ path_nested = strdupz(buffer);
341
340
- struct stat sb;
341
- if(stat(filename, &sb) == -1) {
342
- error("DEVICE-MAPPER ('%s', %lu:%lu): Cannot stat() file '%s'.", disk, major, minor, filename);
343
- continue;
344
- }
342
+ snprintfz(buffer, FILENAME_MAX, "%s%s%s", (prefix)?prefix:"", (prefix)?"_":"", de->d_name);
343
+ prefix_nested = strdupz(buffer);
344
+ }
345
346
- if((sb.st_mode & S_IFMT) != S_IFBLK) {
347
- // info("DEVICE-MAPPER ('%s', %lu:%lu): file '%s' is not a block device.", disk, major, minor, filename);
348
- continue;
349
- }
346
+ found = get_disk_name_from_path(path_nested, result, result_size, major, minor, disk, prefix_nested, depth - 1);
347
+ freez(path_nested);
348
+ freez(prefix_nested);
349
351
- if(major(sb.st_rdev) != major || minor(sb.st_rdev) != minor) {
352
- // info("DEVICE-MAPPER ('%s', %lu:%lu): filename '%s' does not match %lu:%lu.", disk, major, minor, filename, (unsigned long)major(sb.st_rdev), (unsigned long)minor(sb.st_rdev));
353
- continue;
350
+ if(found) break;
351
+ }
352
}
353
+ else if(de->d_type == DT_LNK || de->d_type == DT_BLK) {
354
+ char filename[FILENAME_MAX + 1];
355
+
356
+ if(de->d_type == DT_LNK) {
357
+ snprintfz(filename, FILENAME_MAX, "%s/%s", path, de->d_name);
358
+ ssize_t len = readlink(filename, result, result_size - 1);
359
+ if(len <= 0) {
360
+ error("DEVICE-MAPPER ('%s', %lu:%lu): Cannot read link '%s'.", disk, major, minor, filename);
361
+ continue;
362
+ }
363
+
364
+ result[len] = '\0';
365
+ if(result[0] != '/')
366
+ snprintfz(filename, FILENAME_MAX, "%s/%s", path, result);
367
+ else
368
+ strncpyz(filename, result, FILENAME_MAX);
369
+ }
370
+ else {
371
+ snprintfz(filename, FILENAME_MAX, "%s/%s", path, de->d_name);
372
+ }
373
+
374
+ struct stat sb;
375
+ if(stat(filename, &sb) == -1) {
376
+ error("DEVICE-MAPPER ('%s', %lu:%lu): Cannot stat() file '%s'.", disk, major, minor, filename);
377
+ continue;
378
+ }
379
356
- // info("DEVICE-MAPPER ('%s', %lu:%lu): filename '%s' matches.", disk, major, minor, filename);
380
+ if((sb.st_mode & S_IFMT) != S_IFBLK) {
381
+ //info("DEVICE-MAPPER ('%s', %lu:%lu): file '%s' is not a block device.", disk, major, minor, filename);
382
+ continue;
383
+ }
384
+
385
+ if(major(sb.st_rdev) != major || minor(sb.st_rdev) != minor) {
386
+ //info("DEVICE-MAPPER ('%s', %lu:%lu): filename '%s' does not match %lu:%lu.", disk, major, minor, filename, (unsigned long)major(sb.st_rdev), (unsigned long)minor(sb.st_rdev));
387
+ continue;
388
+ }
389
358
- strncpy(result, de->d_name, result_size);
359
- found = 1;
360
- break;
390
+ //info("DEVICE-MAPPER ('%s', %lu:%lu): filename '%s' matches.", disk, major, minor, filename);
391
+
392
+ snprintfz(result, result_size - 1, "%s%s%s", (prefix)?prefix:"", (prefix)?"_":"", de->d_name);
393
+ found = 1;
394
+ break;
395
+ }
396
}
397
closedir(dir);
398
399
365
-cleanup:
400
+failed:
401
402
if(!found)
403
result[0] = '\0';
@@ -373,10 +408,11 @@ cleanup:
408
static inline char *get_disk_name(unsigned long major, unsigned long minor, char *disk) {
409
char result[FILENAME_MAX + 1] = "";
410
376
- if(!path_to_device_mapper || !*path_to_device_mapper || !get_disk_name_from_path(path_to_device_mapper, result, FILENAME_MAX + 1, major, minor, disk))
377
- if(!path_to_device_label || !*path_to_device_label || !get_disk_name_from_path(path_to_device_label, result, FILENAME_MAX + 1, major, minor, disk))
378
- if(name_disks_by_id != CONFIG_BOOLEAN_YES || !path_to_device_id || !*path_to_device_id || !get_disk_name_from_path(path_to_device_id, result, FILENAME_MAX + 1, major, minor, disk))
379
- strncpy(result, disk, FILENAME_MAX);
411
+ if(!path_to_device_mapper || !*path_to_device_mapper || !get_disk_name_from_path(path_to_device_mapper, result, FILENAME_MAX + 1, major, minor, disk, NULL, 0))
412
+ if(!path_to_device_label || !*path_to_device_label || !get_disk_name_from_path(path_to_device_label, result, FILENAME_MAX + 1, major, minor, disk, NULL, 0))
413
+ if(!path_to_veritas_volume_groups || !*path_to_veritas_volume_groups || !get_disk_name_from_path(path_to_veritas_volume_groups, result, FILENAME_MAX + 1, major, minor, disk, "vx", 2))
414
+ if(name_disks_by_id != CONFIG_BOOLEAN_YES || !path_to_device_id || !*path_to_device_id || !get_disk_name_from_path(path_to_device_id, result, FILENAME_MAX + 1, major, minor, disk, NULL, 0))
415
+ strncpy(result, disk, FILENAME_MAX);
416
417
if(!result[0])
418
strncpy(result, disk, FILENAME_MAX);
@@ -790,6 +826,9 @@ int do_proc_diskstats(int update_every, usec_t dt) {
826
snprintfz(buffer, FILENAME_MAX, "%s/dev/disk/by-id", netdata_configured_host_prefix);
827
path_to_device_id = config_get(CONFIG_SECTION_DISKSTATS, "path to /dev/disk/by-id", buffer);
828
829
+ snprintfz(buffer, FILENAME_MAX, "%s/dev/vx/dsk", netdata_configured_host_prefix);
830
+ path_to_veritas_volume_groups = config_get(CONFIG_SECTION_DISKSTATS, "path to /dev/vx/dsk", buffer);
831
+
832
name_disks_by_id = config_get_boolean(CONFIG_SECTION_DISKSTATS, "name disks by id", name_disks_by_id);
833
834
excluded_disks = simple_pattern_create(