1 Star 0 Fork 9

wuzx/lxcfs

forked from src-openEuler/lxcfs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0008-diskstats-support-devicemapper-device.patch 6.07 KB
一键复制 编辑 原始数据 按行查看 历史
vegbir 提交于 2023-07-27 09:31 . upgrade to 5.0.4
From 0dded445efa7b53886081beab5b74facf0378287 Mon Sep 17 00:00:00 2001
From: vegbir <[email protected]>
Date: Thu, 27 Jul 2023 08:15:49 +0000
Subject: [PATCH 08/15] diskstats support devicemapper device
Signed-off-by: vegbir <[email protected]>
---
src/proc_fuse.c | 133 ++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 117 insertions(+), 16 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index e69e867..1f732ff 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -638,6 +638,15 @@ void free_devinfo_list(struct devinfo *ptr)
}
}
+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;
+}
+
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;
+ 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,
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';
+ 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);
@@ -801,26 +817,111 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.read_sectors || stats.write_sectors || stats.read_ticks ||
stats.write_ticks || stats.ios_pgr || stats.total_ticks || stats.rq_ticks || stats.discard ||
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 %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,
+ &stats.discard_merged,
+ &stats.discard_sectors,
+ &stats.discard_ticks);
+ }
+ ret = strnprintf(
+ lbuf,
+ sizeof(lbuf),
+ "%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 */
+ " %" PRIu64 /* discard_merged */
+ " %" PRIu64 /* discard_sectors */
+ " %" PRIu64 /* discard_ticks */
+ "\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,
+ stats.discard_merged,
+ stats.discard_sectors,
+ stats.discard_ticks);
+ if (ret < 0) {
+ lxcfs_error("Insufficient buffer for %u:%u %s diskstats",
+ stats.major, stats.minor, stats.dev_name);
+ continue;
+ }
+ } 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 %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,
+ &stats.discard_merged,
+ &stats.discard_sectors,
+ &stats.discard_ticks);
ret = strnprintf(
lbuf,
sizeof(lbuf),
"%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 */
- " %" PRIu64 /* discard_merged */
- " %" PRIu64 /* discard_sectors */
- " %" PRIu64 /* discard_ticks */
+ " %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 */
+ " %" PRIu64 /* discard_merged */
+ " %" PRIu64 /* discard_sectors */
+ " %" PRIu64 /* discard_ticks */
"\n",
stats.major,
stats.minor,
--
2.41.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzx065891/lxcfs.git
[email protected]:wuzx065891/lxcfs.git
wuzx065891
lxcfs
lxcfs
master

搜索帮助