Commit de8318c3 authored by Kirill Tkhai's avatar Kirill Tkhai Committed by Andrei Vagin

files: Add force_master argument to collect_desc_fle()

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: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent de27a7c6
...@@ -760,27 +760,39 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe) ...@@ -760,27 +760,39 @@ static struct fdinfo_list_entry *alloc_fle(int pid, FdinfoEntry *fe)
return fle; 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 fdinfo_list_entry *le;
new_le->desc = fdesc;
list_for_each_entry(le, &fdesc->fd_info_head, desc_list) list_for_each_entry(le, &fdesc->fd_info_head, desc_list)
if (pid_rst_prio(new_le->pid, le->pid)) if (pid_rst_prio(new_le->pid, le->pid))
break; break;
list_add_tail(&new_le->desc_list, &le->desc_list); 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 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; struct fdinfo_list_entry *new_le;
new_le = alloc_fle(pid, e); new_le = alloc_fle(pid, e);
if (new_le) { if (new_le) {
new_le->fake = (!!fake); 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); collect_task_fd(new_le, rst_info);
} }
...@@ -800,7 +812,7 @@ int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake) ...@@ -800,7 +812,7 @@ int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool fake)
return -1; 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 -1;
return 0; return 0;
......
...@@ -114,7 +114,8 @@ struct file_desc_ops { ...@@ -114,7 +114,8 @@ struct file_desc_ops {
int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info, bool ghost); 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 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); unsigned int find_unused_fd(struct pstree_item *, int hint_fd);
struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd); struct fdinfo_list_entry *find_used_fd(struct pstree_item *, int fd);
......
...@@ -895,7 +895,7 @@ static struct fdinfo_list_entry *get_fle_for_scm(struct file_desc *tgt, ...@@ -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 * Make this fle fake, so that files collecting engine
* closes them at the end. * 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) int unix_note_scm_rights(int id_for, uint32_t *file_ids, int *fds, int n_ids)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment