Commit 3de41b80 authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Rework select_ps_list fdsec ops callback

For unlinked opened and mmaped files we'd need to
care about remaps, for this the callback with both
file_desc and fdinfo_list_entry will be required.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8a827ba4
...@@ -144,16 +144,17 @@ static int eventpoll_post_open(struct file_desc *d, int fd) ...@@ -144,16 +144,17 @@ static int eventpoll_post_open(struct file_desc *d, int fd)
return 0; return 0;
} }
static struct list_head *eventpoll_select_list(struct file_desc *d, struct rst_info *ri) static void eventpoll_collect_fd(struct file_desc *d,
struct fdinfo_list_entry *fle, struct rst_info *ri)
{ {
return &ri->eventpoll; list_add_tail(&fle->ps_list, &ri->eventpoll);
} }
static struct file_desc_ops desc_ops = { static struct file_desc_ops desc_ops = {
.type = FD_TYPES__EVENTPOLL, .type = FD_TYPES__EVENTPOLL,
.open = eventpoll_open, .open = eventpoll_open,
.post_open = eventpoll_post_open, .post_open = eventpoll_post_open,
.select_ps_list = eventpoll_select_list, .collect_fd = eventpoll_collect_fd,
}; };
static int collect_one_epoll_tfd(void *o, ProtobufCMessage *msg) static int collect_one_epoll_tfd(void *o, ProtobufCMessage *msg)
......
...@@ -533,14 +533,6 @@ int rst_file_params(int fd, FownEntry *fown, int flags) ...@@ -533,14 +533,6 @@ int rst_file_params(int fd, FownEntry *fown, int flags)
return 0; return 0;
} }
static struct list_head *select_ps_list(struct file_desc *desc, struct rst_info *ri)
{
if (desc->ops->select_ps_list)
return desc->ops->select_ps_list(desc, ri);
else
return &ri->fds;
}
static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info) static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
{ {
struct fdinfo_list_entry *le, *new_le; struct fdinfo_list_entry *le, *new_le;
...@@ -567,9 +559,13 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info) ...@@ -567,9 +559,13 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
if (pid_rst_prio(new_le->pid, le->pid)) if (pid_rst_prio(new_le->pid, le->pid))
break; break;
if (fdesc->ops->collect_fd)
fdesc->ops->collect_fd(fdesc, new_le, rst_info);
else
collect_gen_fd(new_le, rst_info);
list_add_tail(&new_le->desc_list, &le->desc_list); list_add_tail(&new_le->desc_list, &le->desc_list);
new_le->desc = fdesc; new_le->desc = fdesc;
list_add_tail(&new_le->ps_list, select_ps_list(fdesc, rst_info));
return 0; return 0;
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "list.h" #include "list.h"
#include "image.h" #include "image.h"
#include "pid.h" #include "pid.h"
#include "rst_info.h"
#include "protobuf/fdinfo.pb-c.h" #include "protobuf/fdinfo.pb-c.h"
#include "protobuf/fown.pb-c.h" #include "protobuf/fown.pb-c.h"
...@@ -96,12 +97,19 @@ struct file_desc_ops { ...@@ -96,12 +97,19 @@ struct file_desc_ops {
*/ */
int (*want_transport)(FdinfoEntry *fe, struct file_desc *d); int (*want_transport)(FdinfoEntry *fe, struct file_desc *d);
/* /*
* Helps determining sequence of different file types restore. * Called to collect a new fd before adding it on desc. Clients
* See the prepare_fds for details. * may chose to collect it to some specific rst_info list. See
* prepare_fds() for details.
*/ */
struct list_head * (*select_ps_list)(struct file_desc *, struct rst_info *); void (*collect_fd)(struct file_desc *, struct fdinfo_list_entry *,
struct rst_info *);
}; };
static inline void collect_gen_fd(struct fdinfo_list_entry *fle, struct rst_info *ri)
{
list_add_tail(&fle->ps_list, &ri->fds);
}
struct file_desc { struct file_desc {
u32 id; /* File id, unique */ u32 id; /* File id, unique */
struct hlist_node hash; /* Descriptor hashing and lookup */ struct hlist_node hash; /* Descriptor hashing and lookup */
......
...@@ -667,17 +667,22 @@ static int tty_transport(FdinfoEntry *fe, struct file_desc *d) ...@@ -667,17 +667,22 @@ static int tty_transport(FdinfoEntry *fe, struct file_desc *d)
return !info->create; return !info->create;
} }
static struct list_head *tty_select_pslist(struct file_desc *d, struct rst_info *ri) static void tty_collect_fd(struct file_desc *d, struct fdinfo_list_entry *fle,
struct rst_info *ri)
{ {
struct list_head *tgt;
/* /*
* Unix98 pty slave peers requires the master peers being * Unix98 pty slave peers requires the master peers being
* opened before them * opened before them
*/ */
if (pty_is_master(container_of(d, struct tty_info, d))) if (pty_is_master(container_of(d, struct tty_info, d)))
return &ri->fds; tgt = &ri->fds;
else else
return &ri->tty_slaves; tgt = &ri->tty_slaves;
list_add_tail(&fle->ps_list, tgt);
} }
static struct file_desc_ops tty_desc_ops = { static struct file_desc_ops tty_desc_ops = {
...@@ -685,7 +690,7 @@ static struct file_desc_ops tty_desc_ops = { ...@@ -685,7 +690,7 @@ static struct file_desc_ops tty_desc_ops = {
.open = tty_open, .open = tty_open,
.post_open = tty_restore_ctl_terminal, .post_open = tty_restore_ctl_terminal,
.want_transport = tty_transport, .want_transport = tty_transport,
.select_ps_list = tty_select_pslist, .collect_fd = tty_collect_fd,
}; };
static struct pstree_item *find_first_sid(int sid) static struct pstree_item *find_first_sid(int sid)
......
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