mount: use switch_ns_by_fd() instead of open_proc() + setns()

Submitted by Andrei Vagin on March 20, 2017, 11:28 p.m.

Details

Message ID 1490052534-31524-1-git-send-email-avagin@openvz.org
State Accepted
Series "mount: use switch_ns_by_fd() instead of open_proc() + setns()"
Headers show

Commit Message

Andrei Vagin March 20, 2017, 11:28 p.m.
From: Andrei Vagin <avagin@virtuozzo.com>

This function was added recently.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/mount.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index 6e5a4c6..339cc32 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -2877,15 +2877,7 @@  int depopulate_roots_yard(int mntns_fd, bool only_ghosts)
 		return -1;
 	}
 
-	old_ns = open_proc(PROC_SELF, "ns/mnt");
-	if (old_ns < 0) {
-		pr_perror("`- Can't keep old ns");
-		close(old_cwd);
-		return -1;
-	}
-	if (setns(mntns_fd, CLONE_NEWNS) < 0) {
-		pr_perror("`- Can't switch");
-		close(old_ns);
+	if (switch_ns_by_fd(mntns_fd, &mnt_ns_desc, &old_ns)) {
 		close(old_cwd);
 		return -1;
 	}
@@ -2896,11 +2888,8 @@  int depopulate_roots_yard(int mntns_fd, bool only_ghosts)
 	if (__depopulate_roots_yard())
 		ret = -1;
 
-	if (setns(old_ns, CLONE_NEWNS) < 0) {
-		pr_perror("Fail to switch back!");
+	if (restore_ns(old_ns, &mnt_ns_desc))
 		ret = -1;
-	}
-	close(old_ns);
 
 	if (fchdir(old_cwd)) {
 		pr_perror("Unable to restore cwd");

Comments

Andrey Vagin March 23, 2017, 10:11 p.m.
Applied

On Tue, Mar 21, 2017 at 02:28:54AM +0300, Andrei Vagin wrote:
> From: Andrei Vagin <avagin@virtuozzo.com>
> 
> This function was added recently.
> 
> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
> ---
>  criu/mount.c | 15 ++-------------
>  1 file changed, 2 insertions(+), 13 deletions(-)
> 
> diff --git a/criu/mount.c b/criu/mount.c
> index 6e5a4c6..339cc32 100644
> --- a/criu/mount.c
> +++ b/criu/mount.c
> @@ -2877,15 +2877,7 @@ int depopulate_roots_yard(int mntns_fd, bool only_ghosts)
>  		return -1;
>  	}
>  
> -	old_ns = open_proc(PROC_SELF, "ns/mnt");
> -	if (old_ns < 0) {
> -		pr_perror("`- Can't keep old ns");
> -		close(old_cwd);
> -		return -1;
> -	}
> -	if (setns(mntns_fd, CLONE_NEWNS) < 0) {
> -		pr_perror("`- Can't switch");
> -		close(old_ns);
> +	if (switch_ns_by_fd(mntns_fd, &mnt_ns_desc, &old_ns)) {
>  		close(old_cwd);
>  		return -1;
>  	}
> @@ -2896,11 +2888,8 @@ int depopulate_roots_yard(int mntns_fd, bool only_ghosts)
>  	if (__depopulate_roots_yard())
>  		ret = -1;
>  
> -	if (setns(old_ns, CLONE_NEWNS) < 0) {
> -		pr_perror("Fail to switch back!");
> +	if (restore_ns(old_ns, &mnt_ns_desc))
>  		ret = -1;
> -	}
> -	close(old_ns);
>  
>  	if (fchdir(old_cwd)) {
>  		pr_perror("Unable to restore cwd");
> -- 
> 2.7.4
>