[CRIU] [crtools-bot for Kinsbursky Stanislav ] restorer: Move vma flags ANON bit manipulations to restore_mapping()

Cyrill Gorcunov gorcunov at openvz.org
Fri Feb 17 06:55:24 EST 2012


The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
------>
commit e1cac86bf8aac0dfbdc60d4d7dd978cc6004a27a
Author: Kinsbursky Stanislav <skinsbursky at openvz.org>
Date:   Fri Feb 17 15:37:21 2012 +0400

    restorer: Move vma flags ANON bit manipulations to restore_mapping()
    
    This looks clearer, because this check has nothing with SYSV IPC
    mappings. Also we don't modify the vma_entry itself anymore but
    operate with local 'flags' copy.
    
    Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
    [gorcunov@: A few tune ups]
    Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 restorer.c |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/restorer.c b/restorer.c
index 3eb5e35..78c5e54 100644
--- a/restorer.c
+++ b/restorer.c
@@ -289,13 +289,23 @@ err:
 
 static u64 restore_mapping(const struct vma_entry *vma_entry)
 {
-	int prot;
+	int prot	= vma_entry->prot;
+	int flags	= vma_entry->flags | MAP_FIXED;
 
 	if (vma_entry_is(vma_entry, VMA_AREA_SYSVIPC))
 		return sys_shmat(vma_entry->fd, (void *)vma_entry->start,
 				 (vma_entry->prot & PROT_WRITE) ? 0 : SHM_RDONLY);
 
-	prot = vma_entry->prot;
+	/*
+	 * Restore or shared mappings are tricky, since
+	 * we open anonymous mapping via map_files/
+	 * MAP_ANONYMOUS should be eliminated so fd would
+	 * be taken into account by a kernel.
+	 */
+	if (vma_entry_is(vma_entry, VMA_ANON_SHARED)) {
+		if (vma_entry->fd != -1UL)
+			flags &= ~MAP_ANONYMOUS;
+	}
 
 	/* A mapping of file with MAP_SHARED is up to date */
 	if (vma_entry->fd == -1 || !(vma_entry->flags & MAP_SHARED))
@@ -308,8 +318,7 @@ static u64 restore_mapping(const struct vma_entry *vma_entry)
 	 */
 	return sys_mmap((void *)vma_entry->start,
 			vma_entry_len(vma_entry),
-			prot,
-			vma_entry->flags | MAP_FIXED,
+			prot, flags,
 			vma_entry->fd,
 			vma_entry->pgoff);
 }
@@ -401,17 +410,6 @@ long restore_task(struct task_restore_core_args *args)
 		if (!vma_entry_is(vma_entry, VMA_AREA_REGULAR))
 			continue;
 
-		/*
-		 * Restore or shared mappings are tricky, since
-		 * we open anonymous mapping via map_files/
-		 * MAP_ANONYMOUS should be eliminated so fd would
-		 * be taken into account by a kernel.
-		 */
-		if (vma_entry_is(vma_entry, VMA_ANON_SHARED)) {
-			if (vma_entry->fd != -1UL)
-				vma_entry->flags &= ~MAP_ANONYMOUS;
-		}
-
 		va = restore_mapping(vma_entry);
 
 		if (va != vma_entry->start) {


More information about the CRIU mailing list