[CRIU] [PATCH 21/27] restore: look up root for each file
Andrey Vagin
avagin at openvz.org
Thu Apr 10 04:04:04 PDT 2014
mntns is looked up by mnt_id, then /proc/NS_PID/root is opened.
This part will be optimized in the "mount: add a fast path for
mntns_collect_root" patch and /proc/NS_PID/root will be opened,
only if NS_PID is not the same as in the previous case.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
files-reg.c | 20 ++++++++++++++++++--
include/proc_parse.h | 1 +
mount.c | 1 +
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/files-reg.c b/files-reg.c
index fba683b..8a1cf47 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -23,6 +23,7 @@
#include "fs-magic.h"
#include "asm/atomic.h"
#include "namespaces.h"
+#include "proc_parse.h"
#include "protobuf.h"
#include "protobuf/regfile.pb-c.h"
@@ -615,9 +616,22 @@ int open_path(struct file_desc *d,
struct reg_file_info *rfi;
int tmp;
char *orig_path = NULL;
+ struct mount_info *m;
rfi = container_of(d, struct reg_file_info, d);
+ if (rfi->rfe->mnt_id >= 0) {
+ m = lookup_mnt_id(rfi->rfe->mnt_id);
+ if (m == NULL) {
+ pr_err("Unable to look up the %d mntns: %s\n",
+ rfi->rfe->mnt_id, rfi->path);
+ return -1;
+ }
+
+ if (mntns_collect_root(m->nsid->pid))
+ return -1;
+ }
+
if (rfi->remap) {
mutex_lock(ghost_file_mutex);
if (rfi_remap(rfi) < 0) {
@@ -679,9 +693,11 @@ int open_path(struct file_desc *d,
static int do_open_reg_noseek_flags(struct reg_file_info *rfi, void *arg)
{
u32 flags = *(u32 *)arg;
- int fd;
+ int fd, mntns_root;
+
+ mntns_root = get_service_fd(ROOT_FD_OFF);
- fd = open(rfi->path, flags);
+ fd = openat(mntns_root, rfi->path, flags);
if (fd < 0) {
pr_perror("Can't open file %s on restore", rfi->path);
return fd;
diff --git a/include/proc_parse.h b/include/proc_parse.h
index e516cae..fbcf901 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -116,6 +116,7 @@ struct mount_info {
int is_file;
bool is_ns_root;
struct mount_info *next;
+ struct ns_id *nsid;
/* tree linkage */
struct mount_info *parent;
diff --git a/mount.c b/mount.c
index d606022..cc1c9cf 100644
--- a/mount.c
+++ b/mount.c
@@ -1474,6 +1474,7 @@ static int collect_mnt_from_image(struct mount_info **pms, struct ns_id *nsid)
if (!pm)
goto err;
+ pm->nsid = nsid;
pm->next = *pms;
*pms = pm;
--
1.8.5.3
More information about the CRIU
mailing list