2021-11-27 15:55:20 +08:00
|
|
|
From 784830ba0066dae7a181df2b82795dda57427127 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: yangjiaqi <yangjiaqi16@huawei.com>
|
|
|
|
|
Date: Tue, 30 Nov 2021 15:23:01 +0800
|
|
|
|
|
Subject: [PATCH 10/17] diskstats-support-devicemapper-device
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
src/proc_fuse.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
|
|
1 file changed, 55 insertions(+), 1 deletion(-)
|
|
|
|
|
|
2020-08-28 15:17:28 +08:00
|
|
|
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
|
2021-11-27 15:55:20 +08:00
|
|
|
index c6c32c7..a613688 100644
|
2020-08-28 15:17:28 +08:00
|
|
|
--- a/src/proc_fuse.c
|
|
|
|
|
+++ b/src/proc_fuse.c
|
2021-11-27 15:55:20 +08:00
|
|
|
@@ -611,6 +611,15 @@ void free_devinfo_list(struct devinfo *ptr)
|
2019-11-06 19:42:23 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+static bool need_record_diskstats(unsigned int major, unsigned int minor)
|
|
|
|
|
+{
|
2021-11-27 15:55:20 +08:00
|
|
|
+ // support device which major is 253 and 252
|
|
|
|
|
+ if (major == 253 || major == 252) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
2019-11-06 19:42:23 +08:00
|
|
|
+}
|
|
|
|
|
+
|
2021-11-27 15:55:20 +08:00
|
|
|
struct lxcfs_diskstats {
|
|
|
|
|
unsigned int major; /* 1 - major number */
|
|
|
|
|
unsigned int minor; /* 2 - minor mumber */
|
|
|
|
|
@@ -653,6 +662,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
|
|
|
|
|
size_t linelen = 0, total_len = 0;
|
2020-08-28 15:17:28 +08:00
|
|
|
int i = 0;
|
|
|
|
|
int ret;
|
2019-11-06 19:42:23 +08:00
|
|
|
+ char tmp_dev_name[72];
|
2020-08-28 15:17:28 +08:00
|
|
|
|
|
|
|
|
if (offset) {
|
2021-11-27 15:55:20 +08:00
|
|
|
size_t left;
|
|
|
|
|
@@ -720,6 +730,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
|
2019-11-06 19:42:23 +08:00
|
|
|
while (getline(&line, &linelen, f) != -1) {
|
|
|
|
|
ssize_t l;
|
|
|
|
|
char lbuf[256];
|
|
|
|
|
+ bool match = false;
|
|
|
|
|
|
2021-11-27 15:55:20 +08:00
|
|
|
memset(stats.dev_name, 0, sizeof(stats.dev_name));
|
|
|
|
|
i = sscanf(line, "%u %u %71s", &stats.major, &stats.minor, stats.dev_name);
|
|
|
|
|
@@ -729,9 +740,14 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
|
|
|
|
|
if (stats.major == ptr->major && stats.minor == ptr->minor) {
|
|
|
|
|
snprintf(stats.dev_name, sizeof(stats.dev_name), "%s", ptr->name);
|
|
|
|
|
stats.dev_name[71] = '\0';
|
2019-11-06 19:42:23 +08:00
|
|
|
+ match = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (!match) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
2021-11-27 15:55:20 +08:00
|
|
|
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Read", &stats.read);
|
|
|
|
|
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Write", &stats.write);
|
|
|
|
|
get_blkio_io_value(io_serviced_str, stats.major, stats.minor, "Discard", &stats.discard);
|
|
|
|
|
@@ -791,8 +807,46 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
|
|
|
|
|
stats.discard_merged,
|
|
|
|
|
stats.discard_sectors,
|
|
|
|
|
stats.discard_ticks);
|
2019-11-06 19:42:23 +08:00
|
|
|
- else
|
2021-11-27 15:55:20 +08:00
|
|
|
+ else if (need_record_diskstats(stats.major, stats.minor)) {
|
|
|
|
|
+ sscanf(line, "%u %u %71s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
|
|
|
|
|
+ &stats.major,
|
|
|
|
|
+ &stats.minor,
|
|
|
|
|
+ tmp_dev_name,
|
|
|
|
|
+ &stats.read,
|
|
|
|
|
+ &stats.read_merged,
|
|
|
|
|
+ &stats.read_sectors,
|
|
|
|
|
+ &stats.read_ticks,
|
|
|
|
|
+ &stats.write,
|
|
|
|
|
+ &stats.write_merged,
|
|
|
|
|
+ &stats.write_sectors,
|
|
|
|
|
+ &stats.write_ticks,
|
|
|
|
|
+ &stats.ios_pgr,
|
|
|
|
|
+ &stats.total_ticks,
|
|
|
|
|
+ &stats.rq_ticks,
|
|
|
|
|
+ &stats.discard_merged,
|
|
|
|
|
+ &stats.discard_sectors,
|
|
|
|
|
+ &stats.discard_ticks);
|
|
|
|
|
+ snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
|
|
|
|
|
+ stats.major,
|
|
|
|
|
+ stats.minor,
|
|
|
|
|
+ stats.dev_name,
|
|
|
|
|
+ stats.read,
|
|
|
|
|
+ stats.read_merged,
|
|
|
|
|
+ stats.read_sectors,
|
|
|
|
|
+ stats.read_ticks,
|
|
|
|
|
+ stats.write,
|
|
|
|
|
+ stats.write_merged,
|
|
|
|
|
+ stats.write_sectors,
|
|
|
|
|
+ stats.write_ticks,
|
|
|
|
|
+ stats.ios_pgr,
|
|
|
|
|
+ stats.total_ticks,
|
|
|
|
|
+ stats.rq_ticks,
|
|
|
|
|
+ stats.discard_merged,
|
|
|
|
|
+ stats.discard_sectors,
|
|
|
|
|
+ stats.discard_ticks);
|
|
|
|
|
+ } else {
|
2019-11-06 19:42:23 +08:00
|
|
|
continue;
|
2021-11-27 15:55:20 +08:00
|
|
|
+ }
|
2019-11-06 19:42:23 +08:00
|
|
|
|
|
|
|
|
l = snprintf(cache, cache_size, "%s", lbuf);
|
|
|
|
|
if (l < 0) {
|
2021-11-27 15:55:20 +08:00
|
|
|
--
|
|
|
|
|
2.27.0
|
|
|
|
|
|