[Devel] [PATCH VZ10 1/2] vzstat: cleanup proc entry creation code

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Thu Sep 4 06:11:23 MSK 2025


Replace single proc file open-coded implementation through proc_create
with shorter and simplier proc_create_single. Can do this because
empty_seq_* ops are equivalents of single_* ops.

While on it also remove single-return "fail_lat" label in accordance
with the codding-style.

https://virtuozzo.atlassian.net/browse/VSTOR-106081
Fixes: 7751c70f38d2a ("vzstat: Add vzstat module and kstat interfaces")
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 kernel/ve/vzstat.c | 99 ++--------------------------------------------
 1 file changed, 4 insertions(+), 95 deletions(-)

diff --git a/kernel/ve/vzstat.c b/kernel/ve/vzstat.c
index ed8ae00677591..8420adba3af5f 100644
--- a/kernel/ve/vzstat.c
+++ b/kernel/ve/vzstat.c
@@ -599,53 +599,6 @@ static int vzstat_mon_loop(void* data)
 	return 0;
 }
 
-/*
- * ------------------------------------------------------------------------
- * default sequential files methods
- * ------------------------------------------------------------------------
- */
-static void *empty_seq_start(struct seq_file *m, loff_t *pos)
-{
-	if (*pos == 0)
-		return (void*)1;
-	else
-		return NULL;
-}
-
-static void *empty_seq_next(struct seq_file *m, void *v, loff_t *pos)
-{
-	(*pos)++;
-	return NULL;
-}
-
-static void empty_seq_stop(struct seq_file *m, void *v)
-{
-}
-
-/*
- * ------------------------------------------------------------------------
- * /proc/vz/latency sequential file methods
- * ------------------------------------------------------------------------
- */
-static struct seq_operations latency_seq_op = {
-	start:	empty_seq_start,
-	next:	empty_seq_next,
-	stop:	empty_seq_stop,
-	show:	latency_seq_show
-};
-
-static int latency_open(struct inode *inode, struct file *file)
-{
-	return seq_open(file, &latency_seq_op);
-}
-
-static struct proc_ops proc_latency_operations = {
-	.proc_open = latency_open,
-	.proc_read = seq_read,
-	.proc_lseek = seq_lseek,
-	.proc_release = seq_release,
-};
-
 /*
  * ------------------------------------------------------------------------
  * /proc/vz/stats sequential file methods
@@ -668,49 +621,6 @@ static int stats_seq_show(struct seq_file *m, void *v)
 	return 0;
 }
 
-static struct seq_operations stats_seq_op = {
-	start:	empty_seq_start,
-	next:	empty_seq_next,
-	stop:	empty_seq_stop,
-	show:	stats_seq_show
-};
-
-static int stats_open(struct inode *inode, struct file *file)
-{
-	return seq_open(file, &stats_seq_op);
-}
-
-static struct proc_ops proc_stats_operations = {
-	.proc_open = stats_open,
-	.proc_read = seq_read,
-	.proc_lseek = seq_lseek,
-	.proc_release = seq_release,
-};
-
-/*
- * ------------------------------------------------------------------------
- * /proc/vz/mmperf sequential file methods
- * ------------------------------------------------------------------------
- */
-static struct seq_operations mmperf_seq_op = {
-	start:	empty_seq_start,
-	next:	empty_seq_next,
-	stop:	empty_seq_stop,
-	show:	mmperf_seq_show
-};
-
-static int mmperf_open(struct inode *inode, struct file *file)
-{
-	return seq_open(file, &mmperf_seq_op);
-}
-
-static struct proc_ops proc_mmperf_operations = {
-	.proc_open = mmperf_open,
-	.proc_read = seq_read,
-	.proc_lseek = seq_lseek,
-	.proc_release = seq_release,
-};
-
 /*
  * ------------------------------------------------------------------------
  * module init/exit code
@@ -721,19 +631,19 @@ static int __init vzstat_mon_init(void)
 {
 	struct proc_dir_entry *entry;
 
-	entry = proc_create("latency", S_IRUGO, proc_vz_dir, &proc_latency_operations);
+	entry = proc_create_single("latency", S_IRUGO, proc_vz_dir, latency_seq_show);
 	if (entry == NULL) {
 		printk(KERN_WARNING "VZSTAT: can't make proc entry\n");
-		goto fail_lat;
+		return -EBUSY;
 	}
 
-	entry = proc_create("stats", S_IRUGO, proc_vz_dir, &proc_stats_operations);
+	entry = proc_create_single("stats", S_IRUGO, proc_vz_dir, stats_seq_show);
 	if (!entry) {
 		printk(KERN_WARNING "VZSTAT: can't make proc entry\n");
 		goto fail_stat;
 	}
 
-	entry = proc_create("mmperf", S_IRUGO, proc_vz_dir, &proc_mmperf_operations);
+	entry = proc_create_single("mmperf", S_IRUGO, proc_vz_dir, mmperf_seq_show);
 	if (!entry) {
 		printk(KERN_WARNING "VZSTAT: can't make proc entry\n");
 		goto fail_perf;
@@ -753,7 +663,6 @@ static int __init vzstat_mon_init(void)
 	remove_proc_entry("stats", proc_vz_dir);
 fail_stat:
 	remove_proc_entry("latency", proc_vz_dir);
-fail_lat:
 	return -EBUSY;
 }
 
-- 
2.50.1



More information about the Devel mailing list