From 1a974c02f209ac5fbaac25d27e35220e324d9fe9 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 10 Oct 2007 04:40:52 +0000 Subject: [PATCH] make iostats functions usable with device path --- src/os/linux/linux_sigar.c | 41 ++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 9572a257..f3c8fdff 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -1174,7 +1174,8 @@ int sigar_file_system_list_get(sigar_t *sigar, return SIGAR_OK; } -#define FSDEV_IS_DEV(dev) strnEQ(dev, "/dev/", 5) +#define FSDEV_PREFIX "/dev/" +#define FSDEV_IS_DEV(dev) strnEQ(dev, FSDEV_PREFIX, 5) #define ST_MAJOR(sb) major((sb).st_rdev) #define ST_MINOR(sb) minor((sb).st_rdev) @@ -1190,8 +1191,23 @@ static iodev_t *get_fsdev(sigar_t *sigar, struct stat sb; sigar_uint64_t id; sigar_file_system_list_t fslist; - int i, status; + int i, status, is_dev=0; int debug = SIGAR_LOG_IS_DEBUG(sigar); + char dev_name[SIGAR_FS_NAME_LEN]; + + if (!sigar->fsdev) { + sigar->fsdev = sigar_cache_new(15); + } + + if (*dirname != '/') { + snprintf(dev_name, sizeof(dev_name), + FSDEV_PREFIX "%s", dirname); + dirname = dev_name; + is_dev = 1; + } + else if (FSDEV_IS_DEV(dirname)) { + is_dev = 1; + } if (stat(dirname, &sb) < 0) { if (debug) { @@ -1202,10 +1218,11 @@ static iodev_t *get_fsdev(sigar_t *sigar, return NULL; } - id = SIGAR_FSDEV_ID(sb); - - if (!sigar->fsdev) { - sigar->fsdev = sigar_cache_new(15); + if (is_dev) { + id = sb.st_rdev; + } + else { + id = SIGAR_FSDEV_ID(sb); } entry = sigar_cache_get(sigar->fsdev, id); @@ -1214,6 +1231,18 @@ static iodev_t *get_fsdev(sigar_t *sigar, return (iodev_t *)entry->value; } + if (is_dev) { + iodev_t *iodev; + entry->value = iodev = malloc(sizeof(*iodev)); + SIGAR_ZERO(iodev); + SIGAR_SSTRCPY(iodev->name, dirname); + if (debug) { + sigar_log_printf(sigar, SIGAR_LOG_DEBUG, + "[fsdev] %s is_dev=true", dirname); + } + return iodev; + } + status = sigar_file_system_list_get(sigar, &fslist); if (status != SIGAR_OK) {