lxcfs/0023-proc-fix-proc-diskstats-output-format.patch
yangjiaqi 0ec657ffe7 lxcfs:sync with latest branch - master
0019-fix-dev-read-memory-leak-in-container.patch
0020-enable-cfs-option-to-show-correct-proc-cpuinfo-view.patch
0021-fix-pidfd_open-pidfd_send_signal-function-compilatio.patch
0022-cpuview-fix-possible-use-after-free-in-find_proc_sta.patch
0023-proc-fix-proc-diskstats-output-format.patch

Signed-off-by: yangjiaqi <yangjiaqi16@huawei.com>
(cherry picked from commit 6f7fa5fe1329e1a4cec21696c565e251d96a2178)
2023-05-26 16:37:50 +08:00

92 lines
3.5 KiB
Diff

From d928f8d073f87fdacaf9e93b616f5b84695036e3 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Wed, 22 Mar 2023 15:31:34 +0800
Subject: [PATCH] proc: fix /proc/diskstats output format
---
src/proc_fuse.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/proc_fuse.c b/src/proc_fuse.c
index fe81cad..ce22974 100644
--- a/src/proc_fuse.c
+++ b/src/proc_fuse.c
@@ -784,10 +784,10 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
memset(lbuf, 0, 256);
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.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\n",
+ 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,
@@ -802,11 +802,12 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
&stats.ios_pgr,
&stats.total_ticks,
&stats.rq_ticks,
+ &stats.discard,
&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",
+ ret = snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
stats.major,
stats.minor,
stats.dev_name,
@@ -821,11 +822,17 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.ios_pgr,
stats.total_ticks,
stats.rq_ticks,
+ stats.discard,
stats.discard_merged,
stats.discard_sectors,
stats.discard_ticks);
+ if(ret >= 256) {
+ 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\n",
+ 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,
@@ -840,10 +847,11 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
&stats.ios_pgr,
&stats.total_ticks,
&stats.rq_ticks,
+ &stats.discard,
&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",
+ ret = snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n",
stats.major,
stats.minor,
stats.dev_name,
@@ -858,9 +866,15 @@ static int proc_diskstats_read(char *buf, size_t size, off_t offset,
stats.ios_pgr,
stats.total_ticks,
stats.rq_ticks,
+ stats.discard,
stats.discard_merged,
stats.discard_sectors,
stats.discard_ticks);
+ if(ret >= 256) {
+ lxcfs_error("Insufficient buffer for %u:%u %s diskstats",
+ stats.major, stats.minor, stats.dev_name);
+ continue;
+ }
} else {
continue;
}
--
2.30.0