lxcfs/0008-diskstats-support-devicemapper-device.patch

163 lines
5.5 KiB
Diff
Raw Normal View History

From 21c359672300c687ad9b1f28c4c1be4ca00f590a Mon Sep 17 00:00:00 2001
From: vegbir <yangjiaqi16@huawei.com>
Date: Wed, 12 Jul 2023 08:31:21 +0000
Subject: [PATCH 08/16] diskstats support devicemapper device
Signed-off-by: vegbir <yangjiaqi16@huawei.com>
---
src/proc_fuse.c | 99 ++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 77 insertions(+), 22 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index dfcd72c..f68212d 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -638,6 +638,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)
+{
+ // 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
+}
+
struct lxcfs_diskstats {
unsigned int major; /* 1 - major number */
unsigned int minor; /* 2 - minor mumber */
@@ -680,6 +689,7 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
size_t linelen = 0, total_len = 0;
int i = 0;
int ret;
2019-11-06 19:42:23 +08:00
+ char tmp_dev_name[72];
if (offset) {
size_t left;
@@ -747,6 +757,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;
memset(stats.dev_name, 0, sizeof(stats.dev_name));
i = sscanf(line, "%u %u %71s", &stats.major, &stats.minor, stats.dev_name);
@@ -757,9 +768,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;
+ }
+
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);
@@ -800,27 +816,28 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
if (stats.read || stats.write || stats.read_merged || stats.write_merged ||
stats.read_sectors || stats.write_sectors || stats.read_ticks ||
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" /* major, minor */
- " %s" /* dev_name */
- " %" PRIu64 /* read */
- " %" PRIu64 /* read_merged */
- " %" PRIu64 /* read_sectors */
- " %" PRIu64 /* read_ticks */
- " %" PRIu64 /* write */
- " %" PRIu64 /* write_merged */
- " %" PRIu64 /* write_sectors */
- " %" PRIu64 /* write_ticks */
- " %" PRIu64 /* ios_pgr */
- " %" PRIu64 /* total_ticks */
- " %" PRIu64 /* rq_ticks */
- " %" PRIu64 /* discard_merged */
- " %" PRIu64 /* discard_sectors */
- " %" PRIu64 /* discard_ticks */
- "\n",
+ stats.discard_merged || stats.discard_sectors || stats.discard_ticks) {
+ 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,
@@ -838,8 +855,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
+ } 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;
+ }
2019-11-06 19:42:23 +08:00
l = snprintf(cache, cache_size, "%s", lbuf);
if (l < 0) {
--
2.41.0