[Devel] [PATCH RHEL8 COMMIT] ms/list: introduce list_for_each_continue()

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 22 12:55:15 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.47
------>
commit 1dcac9e6bcec528dbc1d1f75266b9d85e0d011ad
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Tue Jun 22 12:55:15 2021 +0300

    ms/list: introduce list_for_each_continue()
    
    Patch-set description:
    We see a race when reading mountinfo from criu line-by-line. When we
    read mountinfo line-by-line and some mounts which were already printed
    were umounted before printing next mounts we can see some of next mounts
    skipped from output (consequent cat /proc/<pid>/mountinfo shows them).
    This leads to situations where the mount tree is inconsistend without
    those missing mounts and criu fails.
    
    So mountinfo printing based on numeric position in mounts list is racy.
    We can switch to new mainstream approach witch adds mountinfo "cursor"
    to mount namespace mounts list so that even if some mounts are deleted
    from the list, we can still continue reading next mounts after "cursor"
    consistently.
    
    Original patch description:
    From: Pavel Begunkov <asml.silence at gmail.com>
    
    As other *continue() helpers, this continues iteration from a given
    position.
    
    Signed-off-by: Pavel Begunkov <asml.silence at gmail.com>
    Signed-off-by: Jens Axboe <axboe at kernel.dk>
    
    https://jira.sw.ru/browse/PSBM-125812
    (cherry-picked from ms commit 28ca0d6d39ab1d01c86762c82a585b7cedd2920c)
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    (cherry-picked from vz7 commit d97fb1c6695090cad8cce767cd056d46dc4f7af2)
    https://jira.sw.ru/browse/PSBM-127858
    Signed-off-by: Valeriy Vdovin <valeriy.vdovin at virtuozzo.com>
---
 include/linux/list.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/linux/list.h b/include/linux/list.h
index 602f47e316a4..4c4e0696c4e9 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -538,6 +538,16 @@ static inline void list_splice_tail_init(struct list_head *list,
 #define list_for_each(pos, head) \
 	for (pos = (head)->next; pos != (head); pos = pos->next)
 
+/**
+ * list_for_each_continue - continue iteration over a list
+ * @pos:       the &struct list_head to use as a loop cursor.
+ * @head:      the head for your list.
+ *
+ * Continue to iterate over a list, continuing after the current position.
+ */
+#define list_for_each_continue(pos, head) \
+	for (pos = pos->next; pos != (head); pos = pos->next)
+
 /**
  * list_for_each_prev	-	iterate over a list backwards
  * @pos:	the &struct list_head to use as a loop cursor.


More information about the Devel mailing list