[CRIU] [PATCH RFC 19/30] files: Add fdinfo_list_entry::stage
Kirill Tkhai
ktkhai at virtuozzo.com
Tue Nov 1 07:33:29 PDT 2016
Add fle stages. Set a stage after every operation.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/eventpoll.c | 3 +++
criu/files.c | 13 ++++++++++---
criu/include/files.h | 11 +++++++++++
criu/sk-unix.c | 9 ++++++++-
4 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/criu/eventpoll.c b/criu/eventpoll.c
index 88076db..0608c43 100644
--- a/criu/eventpoll.c
+++ b/criu/eventpoll.c
@@ -115,6 +115,7 @@ const struct fdtype_ops eventpoll_dump_ops = {
static int eventpoll_open(struct file_desc *d)
{
+ struct fdinfo_list_entry *fle = file_master(d);
struct eventpoll_file_info *info;
int tmp;
@@ -135,6 +136,8 @@ static int eventpoll_open(struct file_desc *d)
goto err_close;
}
+ fle->stage = FLE_MAY_BE_POLLED;
+
return tmp;
err_close:
close(tmp);
diff --git a/criu/files.c b/criu/files.c
index 97e3d49..415476c 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -978,12 +978,16 @@ static int post_open_fd(int pid, struct fdinfo_list_entry *fle)
return -1;
}
if (!is_service_fd(fle->fe->fd, CTL_TTY_OFF))
- return 0;
+ goto out;
}
if (!d->ops->post_open)
- return 0;
- return d->ops->post_open(d, fle->fe->fd);
+ goto out;
+ if (d->ops->post_open(d, fle->fe->fd))
+ return -1;
+out:
+ fle->stage = FLE_RESTORED;
+ return 0;
}
@@ -1031,6 +1035,9 @@ static int open_fd(int pid, struct fdinfo_list_entry *fle)
return -1;
}
+ if (fle->stage < FLE_OPEN)
+ fle->stage = FLE_OPEN;
+
return serve_out_fd(pid, fle->fe->fd, d);
}
diff --git a/criu/include/files.h b/criu/include/files.h
index 7de61d8..44143ef 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -64,6 +64,15 @@ extern int fill_fdlink(int lfd, const struct fd_parms *p, struct fd_link *link);
struct file_desc;
+enum {
+ FLE_INITIALIZED,
+ FLE_OPEN,
+ FLE_BOUND,
+ FLE_LISTEN,
+ FLE_MAY_BE_POLLED,
+ FLE_RESTORED,
+};
+
struct fdinfo_list_entry {
struct list_head desc_list; /* To chain on @fd_info_head */
struct file_desc *desc; /* Associated file descriptor */
@@ -72,6 +81,7 @@ struct fdinfo_list_entry {
int pid;
FdinfoEntry *fe;
u8 received:1;
+ u8 stage:3;
};
static inline void fle_init(struct fdinfo_list_entry *fle, int pid, FdinfoEntry *fe)
@@ -79,6 +89,7 @@ static inline void fle_init(struct fdinfo_list_entry *fle, int pid, FdinfoEntry
fle->pid = pid;
fle->fe = fe;
fle->received = 0;
+ fle->stage = FLE_INITIALIZED;
}
/* reports whether fd_a takes prio over fd_b */
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index 403f805..041293a 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -925,6 +925,7 @@ static int post_open_unix_sk(struct file_desc *d, int fd)
static int bind_unix_sk(int sk, struct unix_sk_info *ui)
{
+ struct fdinfo_list_entry *fle;
struct sockaddr_un addr;
int cwd_fd = -1;
int ret = -1;
@@ -1024,8 +1025,11 @@ static int bind_unix_sk(int sk, struct unix_sk_info *ui)
}
}
- if (ui->ue->state != TCP_LISTEN)
+ if (ui->ue->state != TCP_LISTEN) {
futex_set_and_wake(&ui->prepared, 1);
+ fle = file_master(&ui->d);
+ fle->stage = FLE_BOUND;
+ }
ret = 0;
done:
@@ -1108,6 +1112,7 @@ static int open_unixsk_pair_slave(struct unix_sk_info *ui)
static int open_unixsk_standalone(struct unix_sk_info *ui)
{
+ struct fdinfo_list_entry *fle;
int sk;
pr_info("Opening standalone socket (id %#x ino %#x peer %#x)\n",
@@ -1234,6 +1239,8 @@ static int open_unixsk_standalone(struct unix_sk_info *ui)
return -1;
}
futex_set_and_wake(&ui->prepared, 1);
+ fle = file_master(&ui->d);
+ fle->stage = FLE_LISTEN;
}
out:
if (rst_file_params(sk, ui->ue->fown, ui->ue->flags))
More information about the CRIU
mailing list