From 6a23cab853e943c340088fc5f2eddcb8d8d2b4f9 Mon Sep 17 00:00:00 2001 From: lasers Date: Fri, 10 Aug 2018 09:47:19 -0500 Subject: [PATCH] diskio.cc: Allow 'partuuid' label usage (#598) * diskio.cc: Allow 'partuuid' label usage * diskio.cc: Merge the if block to strncmp() --- doc/variables.xml | 6 +++--- src/diskio.cc | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 0b6564b6..e09c74d9 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -908,9 +908,9 @@ Displays current disk IO. Device is optional, and - takes the form of sda for /dev/sda. A block device label can - be specified with label:foo. Individual partitions are also - allowed. + takes the form of sda for /dev/sda. A block device label can + be specified with label:foo and a block device partuuid can + be specified with partuuid:40000000-01. diff --git a/src/diskio.cc b/src/diskio.cc index fb590f03..5208865b 100644 --- a/src/diskio.cc +++ b/src/diskio.cc @@ -60,6 +60,7 @@ struct diskio_stat *prepare_diskio_stat(const char *s) { device_s(text_buffer_size.get(*state)); struct diskio_stat *cur = &stats; char *rpbuf; + char rpbuf2[256]; if (s == nullptr) { return &stats; @@ -68,7 +69,12 @@ struct diskio_stat *prepare_diskio_stat(const char *s) { if (strncmp(s, "label:", 6) == 0) { snprintf(&(device_name[0]), text_buffer_size.get(*state), "/dev/disk/by-label/%s", s + 6); + rpbuf = realpath(&(device_name[0]), nullptr); + } else if (0 == (strncmp(s, "partuuid:", 9))) { + snprintf(&(device_name[0]), text_buffer_size.get(*state), + "/dev/disk/by-partuuid/%s", s + 9); rpbuf = realpath(&device_name[0], nullptr); + snprintf(rpbuf2, 255, "%s", rpbuf); } else { rpbuf = realpath(s, nullptr); } @@ -92,12 +98,18 @@ struct diskio_stat *prepare_diskio_stat(const char *s) { * On Solaris we currently don't use the name of disk's special file so * this test is useless. */ - snprintf(&(stat_name[0]), text_buffer_size.get(*state), "/dev/%s", - &(device_name[0])); - if ((stat(&(stat_name[0]), &sb) != 0) || !S_ISBLK(sb.st_mode)) { - NORM_ERR("diskio device '%s' does not exist", &device_s[0]); + if (strncmp(s, "label:", 6) == 0) { + snprintf(&(stat_name[0]), text_buffer_size.get(*state), "/dev/%s", + &(device_name[0])); + if ((stat(&(stat_name[0]), &sb) != 0) || !S_ISBLK(sb.st_mode)) { + NORM_ERR("diskio device '%s' does not exist", &device_s[0]); + } + } else if ((0 == (strncmp(s, "partuuid:", 9))) && + ((stat(rpbuf2, &sb) != 0) || !S_ISBLK(sb.st_mode))) { + NORM_ERR("diskio device '%s' does not exist", &device_s[0]); } + #endif /* lookup existing */