[Devel] [PATCH RHEL8 COMMIT] ve/proc/block: show /proc/diskstats inside a Container

Konstantin Khorenko khorenko at virtuozzo.com
Wed Jun 2 19:59:07 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.34
------>
commit 2b0080cf13831b23a5144eb61284fb7b04d97a9b
Author: Vasily Averin <vvs at virtuozzo.com>
Date:   Mon May 31 10:00:14 2021 +0300

    ve/proc/block: show /proc/diskstats inside a Container
    
    The proc file is virtualized, so it contains stats for only those block
    devices which are allowed by device cgroup related to the Container.
    
    https://jira.sw.ru/browse/PSBM-90491
    https://jira.sw.ru/browse/PSBM-92107
    
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
    
    (cherry picked from vz7 commit ded5965d1d58 ("ve/proc/block: show
    /proc/diskstats inside a Container"))
    
    Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
 block/genhd.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/block/genhd.c b/block/genhd.c
index 5d4363e4296a..aaf39b0b479f 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1463,6 +1463,7 @@ static const struct device_type disk_type = {
  */
 static int diskstats_show(struct seq_file *seqf, void *v)
 {
+	struct ve_struct *ve = get_exec_env();
 	struct gendisk *gp = v;
 	struct disk_part_iter piter;
 	struct hd_struct *hd;
@@ -1479,6 +1480,11 @@ static int diskstats_show(struct seq_file *seqf, void *v)
 
 	disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
 	while ((hd = disk_part_iter_next(&piter))) {
+		if (!ve_is_super(ve) &&
+			(devcgroup_device_permission(S_IFBLK, part_devt(hd),
+						     MAY_READ)))
+				continue;
+
 		inflight = part_in_flight(gp->queue, hd);
 		seq_printf(seqf, "%4d %7d %s "
 			   "%lu %lu %lu %u "
@@ -1518,7 +1524,7 @@ static const struct seq_operations diskstats_op = {
 
 static int __init proc_genhd_init(void)
 {
-	proc_create_seq("diskstats", 0, NULL, &diskstats_op);
+	proc_create_seq("diskstats", S_ISVTX, NULL, &diskstats_op);
 	proc_create_seq("partitions", S_ISVTX, NULL, &partitions_op);
 	return 0;
 }


More information about the Devel mailing list