Skip to content

Commit 45409c3

Browse files
Liu Huaavagin
authored andcommitted
mount: use swich_mnt_ns/restore_mnt_ns helpers to simplify code
Signed-off-by: Liu Hua <weldonliu@tencent.com>
1 parent f79d15c commit 45409c3

1 file changed

Lines changed: 3 additions & 19 deletions

File tree

criu/mount.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,13 +1358,8 @@ int open_mountpoint(struct mount_info *pm)
13581358
* In both cases we can't do the thing from criu's mount namespace, so
13591359
* we need to switch to mount's mount namespace, and later switch back.
13601360
*/
1361-
cwd_fd = open(".", O_DIRECTORY);
1362-
if (cwd_fd < 0) {
1363-
pr_perror("Unable to open cwd");
1364-
return -1;
1365-
}
13661361

1367-
if (switch_ns(pm->nsid->ns_pid, &mnt_ns_desc, &ns_old) < 0)
1362+
if (switch_mnt_ns(pm->nsid->ns_pid, &ns_old, &cwd_fd) < 0)
13681363
goto err;
13691364

13701365
if (!mnt_is_overmounted(pm)) {
@@ -1406,28 +1401,17 @@ int open_mountpoint(struct mount_info *pm)
14061401
}
14071402
}
14081403

1409-
if (restore_ns(ns_old, &mnt_ns_desc)) {
1404+
if (restore_mnt_ns(ns_old, &cwd_fd)) {
14101405
ns_old = -1;
14111406
goto err;
14121407
}
14131408

1414-
if (fchdir(cwd_fd)) {
1415-
pr_perror("Unable to restore cwd");
1416-
close(cwd_fd);
1417-
close(fd);
1418-
return -1;
1419-
}
1420-
close(cwd_fd);
1421-
14221409
return __open_mountpoint(pm, fd);
14231410
err:
14241411
if (ns_old >= 0)
14251412
/* coverity[check_return] */
1426-
restore_ns(ns_old, &mnt_ns_desc);
1413+
restore_mnt_ns(ns_old, &cwd_fd);
14271414
close_safe(&fd);
1428-
if (fchdir(cwd_fd))
1429-
pr_perror("Unable to restore cwd");
1430-
close(cwd_fd);
14311415
return -1;
14321416
}
14331417

0 commit comments

Comments
 (0)