From eda1e5fdbd6fdf3ccf5063b728073a5c3ea92ed3 Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Sun, 12 Apr 2020 20:53:54 +0300 Subject: [PATCH] mount: add mntinfo_add_list_before helper for adding to mntinfo list Use this helper everywhere instead of manually adding mounts to the head of the list, this way it is much easier to track all places where we do add to mntinfo list. Signed-off-by: Alexander Mikhalitsyn (Virtuozzo) Cherry-picked from Virtuozzo criu: https://src.openvz.org/projects/OVZ/repos/criu/commits/7bca9397b Changes: skip hunk adding root_yard_mp to the list because root yard has not fully initialized mountinfo structure (can break code which uses mntinfo fallback in lookup_nsid_by_mnt_id), let's only have real mounts in mntinfo list. Also skip cr_time mount from mntinfo list for the same reason. Signed-off-by: Pavel Tikhomirov --- criu/include/mount.h | 3 +++ criu/mount.c | 11 +++++++---- criu/proc_parse.c | 6 ++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/criu/include/mount.h b/criu/include/mount.h index b959d131c..f180fe58d 100644 --- a/criu/include/mount.h +++ b/criu/include/mount.h @@ -90,6 +90,9 @@ struct mount_info { }; extern struct mount_info *mntinfo; + +extern void mntinfo_add_list_before(struct mount_info **head, struct mount_info *new); + extern struct ns_desc mnt_ns_desc; #ifdef CONFIG_BINFMT_MISC_VIRTUALIZED extern int collect_binfmt_misc(void); diff --git a/criu/mount.c b/criu/mount.c index c301aaeeb..7035d992a 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -127,6 +127,12 @@ static void mntinfo_add_list(struct mount_info *new) } } +void mntinfo_add_list_before(struct mount_info **head, struct mount_info *new) +{ + new->next = *head; + *head = new; +} + static struct mount_info *__lookup_overlayfs(struct mount_info *list, char *rpath, unsigned int st_dev, unsigned int st_ino, unsigned int mnt_id) { @@ -1527,8 +1533,6 @@ static __maybe_unused int add_cr_time_mount(struct mount_info *root, char *fsnam mi->nsid = parent->nsid; mi->parent = parent; mi->parent_mnt_id = parent->mnt_id; - mi->next = parent->next; - parent->next = mi; list_add(&mi->siblings, &parent->children); pr_info("Add cr-time mountpoint %s with parent %s(%u)\n", mi->mountpoint, parent->mountpoint, parent->mnt_id); return 0; @@ -3015,8 +3019,7 @@ static int collect_mnt_from_image(struct mount_info **head, struct mount_info ** goto err; pm->nsid = nsid; - pm->next = *head; - *head = pm; + mntinfo_add_list_before(head, pm); if (!*tail) *tail = pm; diff --git a/criu/proc_parse.c b/criu/proc_parse.c index f7abd4d52..7955d50a6 100644 --- a/criu/proc_parse.c +++ b/criu/proc_parse.c @@ -1651,10 +1651,8 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump) if (fsname) free(fsname); - if (new) { - new->next = list; - list = new; - } + if (new) + mntinfo_add_list_before(&list, new); if (ret) goto err;