[CRIU] [PATCH 04/19] files: Add force_master argument to collect_desc_fle()
Kirill Tkhai
ktkhai at virtuozzo.com
Tue Jan 30 18:41:29 MSK 2018
This functional allows to make a fle a master on
the time of collection. We will use it to add fake
files when we need to do this after add_fake_fds_masters().
This will be used to add second end of socketpair as
a fake fle (as the first end is placed in the right
place, we will force add the second end there).
See next patches.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/files.c | 24 ++++++++++++++++++------
criu/include/files.h | 3 ++-
criu/sk-unix.c | 2 +-
3 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/criu/files.c b/criu/files.c
index 8f6d50e92..835d434e0 100644
--- a/criu/files.c
+++ b/criu/files.c
@@ -772,14 +772,12 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
return fle;
}
-static void collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_desc *fdesc)
+static void __collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_desc *fdesc)
{
struct fdinfo_list_entry *le;
struct ns_id *task_ns = NULL;
bool first = true;
- new_le->desc = fdesc;
-
/*
* First fle in fdesc->fd_info_head list (i.e., master)
* must have enough permissions to restore file.
@@ -821,15 +819,29 @@ static void collect_desc_fle(struct fdinfo_list_entry *new_le, struct file_desc
list_add_tail(&new_le->desc_list, &le->desc_list);
}
+static void collect_desc_fle(struct fdinfo_list_entry *new_le,
+ struct file_desc *fdesc, bool force_master)
+{
+ new_le->desc = fdesc;
+
+ if (!force_master)
+ __collect_desc_fle(new_le, fdesc);
+ else {
+ /* Link as first entry */
+ list_add(&new_le->desc_list, &fdesc->fd_info_head);
+ }
+}
+
struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e,
- struct rst_info *rst_info, struct file_desc *fdesc, bool fake)
+ struct rst_info *rst_info, struct file_desc *fdesc,
+ bool fake, bool force_master)
{
struct fdinfo_list_entry *new_le;
new_le = alloc_fle(pid, e);
if (new_le) {
new_le->fake = (!!fake);
- collect_desc_fle(new_le, fdesc);
+ collect_desc_fle(new_le, fdesc, force_master);
collect_task_fd(new_le, rst_info);
}
@@ -849,7 +861,7 @@ int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake)
return -1;
}
- if (!collect_fd_to(pid, e, rst_info, fdesc, fake))
+ if (!collect_fd_to(pid, e, rst_info, fdesc, fake, false))
return -1;
return 0;
diff --git a/criu/include/files.h b/criu/include/files.h
index bd4ab8470..52ad10734 100644
--- a/criu/include/files.h
+++ b/criu/include/files.h
@@ -121,7 +121,8 @@ struct file_desc_ops {
int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool ghost);
struct fdinfo_list_entry *collect_fd_to(int pid, FdinfoEntry *e,
- struct rst_info *rst_info, struct file_desc *fdesc, bool fake);
+ struct rst_info *rst_info, struct file_desc *fdesc,
+ bool fake, bool force_master);
unsigned int find_unused_fd(struct pstree_item *, int hint_fd);
struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd);
diff --git a/criu/sk-unix.c b/criu/sk-unix.c
index b461f1c14..917d5ce6a 100644
--- a/criu/sk-unix.c
+++ b/criu/sk-unix.c
@@ -895,7 +895,7 @@ static struct fdinfo_list_entry *get_fle_for_scm(struct file_desc *tgt,
* Make this fle fake, so that files collecting engine
* closes them at the end.
*/
- return collect_fd_to(vpid(owner), e, rsti(owner), tgt, true);
+ return collect_fd_to(vpid(owner), e, rsti(owner), tgt, true, false);
}
int unix_note_scm_rights(int id_for, uint32_t *file_ids, int *fds, int n_ids)
More information about the CRIU
mailing list