[CRIU] [PATCH 01/12] dump: new fd_entry structure introduced
Kinsbursky Stanislav
skinsbursky at openvz.org
Fri Mar 23 12:23:11 EDT 2012
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
This structure represents how fdinfo_entry will be looking at the end.
I.e. it's temporary.
Without it it's impossible to split this huge code pile into safe-bisectable
pieces.
This structure will be removed at the ot the series.
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
cr-dump.c | 12 +++++++-----
cr-show.c | 2 +-
files.c | 32 ++++++++++++++++----------------
include/image.h | 9 +++++++--
restorer.c | 2 +-
5 files changed, 32 insertions(+), 25 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index 10f3ac2..42d0c97 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -120,28 +120,30 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
if (do_close_lfd)
close(lfd);
- e.type = p->type;
e.len = len;
e.flags = p->flags;
e.pos = p->pos;
e.addr = p->fd_name;
- e.id = FD_ID_INVALID;
- if (likely(!fd_is_special(&e))) {
+ e.fde.type = p->type;
+ e.fde.fd = (u32)p->fd_name;
+ e.fde.id = FD_ID_INVALID;
+
+ if (likely(!fd_is_special(&e.fde))) {
struct fd_id_entry *entry;
/*
* Make sure the union is still correlate with structure
* we write to disk.
*/
- BUILD_BUG_ON(sizeof(entry->u.key) != sizeof(e.id));
+ BUILD_BUG_ON(sizeof(entry->u.key) != sizeof(e.fde.id));
entry = fd_id_entry_collect((u32)p->id, p->pid, p->fd_name);
if (!entry)
goto err;
/* Now it might have completely new ID here */
- e.id = entry->u.id;
+ e.fde.id = entry->u.id;
}
pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n",
diff --git a/cr-show.c b/cr-show.c
index 3832b49..f976030 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -69,7 +69,7 @@ static void show_files(int fd_files)
pr_msg("type: %02x len: %02x flags: %4x pos: %8x "
"addr: %16lx id: %16lx",
- e.type, e.len, e.flags, e.pos, e.addr, e.id);
+ e.fde.type, e.len, e.flags, e.pos, e.addr, e.fde.id);
if (e.len) {
int ret = read(fd_files, local_buf, e.len);
diff --git a/files.c b/files.c
index 23eec54..88eae74 100644
--- a/files.c
+++ b/files.c
@@ -77,7 +77,7 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
struct fdinfo_desc *desc;
pr_info("Collect fdinfo pid=%d fd=%ld id=%16lx\n",
- pid, e->addr, e->id);
+ pid, e->addr, e->fde.id);
nr_fdinfo_list++;
if ((nr_fdinfo_list) * sizeof(struct fdinfo_list_entry) >= 4096) {
@@ -92,7 +92,7 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
for (i = 0; i < nr_fdinfo_descs; i++) {
desc = &fdinfo_descs[i];
- if (desc->id != e->id)
+ if (desc->id != e->fde.id)
continue;
fdinfo_descs[i].users++;
@@ -115,8 +115,8 @@ static int collect_fd(int pid, struct fdinfo_entry *e)
desc = &fdinfo_descs[nr_fdinfo_descs];
memzero(desc, sizeof(*desc));
- desc->id = e->id;
- desc->addr = e->addr;
+ desc->id = e->fde.id;
+ desc->addr = e->fde.fd;
desc->pid = pid;
desc->users = 1;
INIT_LIST_HEAD(&desc->list);
@@ -150,7 +150,7 @@ int prepare_fd_pid(int pid)
if (e.len)
lseek(fdinfo_fd, e.len, SEEK_CUR);
- if (fd_is_special(&e))
+ if (fd_is_special(&e.fde))
continue;
ret = collect_fd(pid, &e);
@@ -249,7 +249,7 @@ static int open_transport_fd(int pid, struct fdinfo_entry *fe,
transport_name_gen(&saddr, &sun_len, getpid(), fe->addr);
pr_info("\t%d: Create transport fd for %lx type %d namelen %d users %d\n", pid,
- (unsigned long)fe->addr, fe->type, fe->len, fi->users);
+ (unsigned long)fe->addr, fe->fde.type, fe->len, fi->users);
fle = find_fdinfo_list_entry(pid, fe->addr, fi);
@@ -304,7 +304,7 @@ static int open_fd(int pid, struct fdinfo_entry *fe,
cr_wait_set(&fi->real_pid, getpid());
pr_info("\t%d: Create fd for %lx type %d namelen %d users %d\n", pid,
- (unsigned long)fe->addr, fe->type, fe->len, fi->users);
+ (unsigned long)fe->addr, fe->fde.type, fe->len, fi->users);
list_for_each_entry(fle, &fi->list, list) {
int len;
@@ -350,7 +350,7 @@ static int receive_fd(int pid, struct fdinfo_entry *fe, struct fdinfo_desc *fi)
}
pr_info("\t%d: Receive fd for %lx type %d namelen %d users %d\n", pid,
- (unsigned long)fe->addr, fe->type, fe->len, fi->users);
+ (unsigned long)fe->addr, fe->fde.type, fe->len, fi->users);
tmp = recv_fd(fe->addr);
if (tmp < 0) {
@@ -394,15 +394,15 @@ static int open_fdinfo(int pid, struct fdinfo_entry *fe, int *fdinfo_fd, int sta
u32 mag;
int ret = 0;
- struct fdinfo_desc *fi = find_fd(fe->id);
+ struct fdinfo_desc *fi = find_fd(fe->fde.id);
if (move_img_fd(fdinfo_fd, (int)fe->addr))
return -1;
pr_info("\t%d: Got fd for %lx type %d namelen %d users %d\n", pid,
- (unsigned long)fe->addr, fe->type, fe->len, fi->users);
+ (unsigned long)fe->addr, fe->fde.type, fe->len, fi->users);
- BUG_ON(fe->type != FDINFO_REG);
+ BUG_ON(fe->fde.type != FDINFO_REG);
switch (state) {
@@ -428,14 +428,14 @@ static int open_special_fdinfo(int pid, struct fdinfo_entry *fe,
return 0;
}
- if (fe->type == FDINFO_MAP)
+ if (fe->fde.type == FDINFO_MAP)
return open_fmap(pid, fe, fdinfo_fd);
- if (fe->type == FDINFO_CWD)
+ if (fe->fde.type == FDINFO_CWD)
return restore_cwd(fe, fdinfo_fd);
- if (fe->type == FDINFO_EXE)
+ if (fe->fde.type == FDINFO_EXE)
return restore_exe_early(fe, fdinfo_fd);
- pr_info("%d: fe->type: %d\n", pid, fe->type);
+ pr_info("%d: fe->type: %d\n", pid, fe->fde.type);
BUG_ON(1);
return -1;
}
@@ -468,7 +468,7 @@ int prepare_fds(int pid)
if (ret <= 0)
break;
- if (fd_is_special(&fe))
+ if (fd_is_special(&fe.fde))
ret = open_special_fdinfo(pid, &fe,
fdinfo_fd, state);
else {
diff --git a/include/image.h b/include/image.h
index 5bcfffd..6ff984a 100644
--- a/include/image.h
+++ b/include/image.h
@@ -40,13 +40,18 @@
#define PAGE_RSS 1
#define PAGE_ANON 2
-struct fdinfo_entry {
+struct fd_entry {
+ u64 id;
+ u32 fd;
u8 type;
+} __packed;
+
+struct fdinfo_entry {
+ struct fd_entry fde;
u8 len;
u16 flags;
u32 pos;
u64 addr;
- u64 id;
u8 name[0];
} __packed;
diff --git a/restorer.c b/restorer.c
index 78b0584..c572025 100644
--- a/restorer.c
+++ b/restorer.c
@@ -249,7 +249,7 @@ static long restore_self_exe_late(struct task_restore_core_args *args)
goto err;
}
- if (fe.type == FDINFO_EXE)
+ if (fe.fde.type == FDINFO_EXE)
break;
if (fe.len)
More information about the CRIU
mailing list