[Devel] [PATCH RHEL7 COMMIT] ve/proc: increment position in "next" seq_operations callback

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jan 17 13:11:26 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1062.7.1.vz7.130.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.7.1.vz7.130.10
------>
commit 0a458a0598b47220432d0be867a4b79abb90e103
Author: Vasily Averin <vvs at virtuozzo.com>
Date:   Fri Jan 17 13:11:24 2020 +0300

    ve/proc: increment position in "next" seq_operations callback
    
    "next" callback of struct "seq_operations" should move the iterator
    forward to the next position in the sequence.
    
    Some Virtuozzo specific proc files skip such increment,
    and trigger incorrect file output.
    
     # q=;while read -r r;do echo "$((++q)) $r";done</proc/bc/resources
    
    https://bugs.openvz.org/browse/OVZ-7158
    
    Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
 drivers/net/venetdev.c          | 2 +-
 fs/ext4/extents_status.c        | 1 +
 kernel/bc/io_prio.c             | 6 +++---
 kernel/bc/proc.c                | 2 +-
 kernel/ve/vecalls.c             | 5 +++--
 kernel/ve/vznetstat/vznetstat.c | 2 +-
 kernel/ve/vzstat.c              | 1 +
 7 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/net/venetdev.c b/drivers/net/venetdev.c
index 28d06bca1f867..c4cb15883002e 100644
--- a/drivers/net/venetdev.c
+++ b/drivers/net/venetdev.c
@@ -842,6 +842,7 @@ static void *veip_seq_next(struct seq_file *m, void *v, loff_t *pos)
 	struct hlist_node *p;
 	int i;
 
+	(*pos)++;
 	if (v == SEQ_START_TOKEN)
 		goto find;
 
@@ -855,7 +856,6 @@ static void *veip_seq_next(struct seq_file *m, void *v, loff_t *pos)
 		if (p != NULL) {
 			m->private = (void *)(long)(i + 1);
 found:
-			(*pos)++;
 			return p;
 		}
 	}
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index ed1f63eef74c6..66babd97732d4 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1112,6 +1112,7 @@ static void *ext4_es_seq_shrinker_info_start(struct seq_file *seq, loff_t *pos)
 static void *
 ext4_es_seq_shrinker_info_next(struct seq_file *seq, void *v, loff_t *pos)
 {
+	(*pos)++;
 	return NULL;
 }
 
diff --git a/kernel/bc/io_prio.c b/kernel/bc/io_prio.c
index 16f5024c90bdf..31b4db7179032 100644
--- a/kernel/bc/io_prio.c
+++ b/kernel/bc/io_prio.c
@@ -91,10 +91,10 @@ static void *bc_iostat_next(struct seq_file *f, void *v, loff_t *ppos)
 {
 	struct user_beancounter *ub = v;
 
-	list_for_each_entry_continue_rcu(ub, &ub_list_head, ub_list) {
-		(*ppos)++;
+	(*ppos)++;
+	list_for_each_entry_continue_rcu(ub, &ub_list_head, ub_list)
 		return ub;
-	}
+
 	return NULL;
 }
 
diff --git a/kernel/bc/proc.c b/kernel/bc/proc.c
index efcfdbc9ee226..70ec6ff5f2163 100644
--- a/kernel/bc/proc.c
+++ b/kernel/bc/proc.c
@@ -242,6 +242,7 @@ static void *ub_next(struct seq_file *f, void *v, loff_t *ppos)
 	struct user_beancounter *ub, *ret = NULL;
 	struct user_beancounter *exec_ub;
 
+	(*ppos)++;
 	exec_ub = get_exec_ub();
 	ub = (struct user_beancounter *)v;
 	rcu_read_lock();
@@ -251,7 +252,6 @@ static void *ub_next(struct seq_file *f, void *v, loff_t *ppos)
 			continue;
 		if (!get_beancounter_rcu(ub))
 			continue;
-		(*ppos)++;
 		ret = ub;
 		break;
 	}
diff --git a/kernel/ve/vecalls.c b/kernel/ve/vecalls.c
index 5503bde290d29..6488fe8143f0c 100644
--- a/kernel/ve/vecalls.c
+++ b/kernel/ve/vecalls.c
@@ -318,9 +318,10 @@ EXPORT_SYMBOL(ve_seq_start);
 
 void *ve_seq_next(struct seq_file *m, void *v, loff_t *pos)
 {
-	if (!ve_is_super(get_exec_env()))
+	if (!ve_is_super(get_exec_env())) {
+		(*pos)++;
 		return NULL;
-	else
+	} else
 		return seq_list_next(v, &ve_list_head, pos);
 }
 EXPORT_SYMBOL(ve_seq_next);
diff --git a/kernel/ve/vznetstat/vznetstat.c b/kernel/ve/vznetstat/vznetstat.c
index 77309a34e166a..e0ca8d2fb027c 100644
--- a/kernel/ve/vznetstat/vznetstat.c
+++ b/kernel/ve/vznetstat/vznetstat.c
@@ -1033,10 +1033,10 @@ static void *stat_seq_next(struct seq_file *m, void *v, loff_t *pos)
 	struct venet_stat *ptr = (struct venet_stat *)v;
 	int hash;
 
+	(*pos)++;
 	if (!ve_is_super(get_exec_env()))
 		return NULL;
 	hash = stat_hash(ptr->veid);
-	(*pos)++;
 	return next_stat(&hash, ptr);
 }
 
diff --git a/kernel/ve/vzstat.c b/kernel/ve/vzstat.c
index 772e34e4c07ad..e4a3348f02769 100644
--- a/kernel/ve/vzstat.c
+++ b/kernel/ve/vzstat.c
@@ -620,6 +620,7 @@ static void *empty_seq_start(struct seq_file *m, loff_t *pos)
 
 static void *empty_seq_next(struct seq_file *m, void *v, loff_t *pos)
 {
+	(*pos)++;
 	return NULL;
 }
 



More information about the Devel mailing list