Commit 62cf23b9 authored by Pavel Emelyanov's avatar Pavel Emelyanov

files: Hide pslist selection logic into file desc handlers

Don't do explicit switch by file type in files.c and don't export
intimate knowledge of pty being master/slave. Use a file desc op
for that.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent e0b39c5f
...@@ -158,10 +158,16 @@ static int eventpoll_post_open(struct file_desc *d, int fd) ...@@ -158,10 +158,16 @@ 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)
{
return &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,
}; };
static int collect_one_epoll_tfd(void *o, ProtobufCMessage *msg) static int collect_one_epoll_tfd(void *o, ProtobufCMessage *msg)
......
...@@ -148,18 +148,12 @@ int rst_file_params(int fd, FownEntry *fown, int flags) ...@@ -148,18 +148,12 @@ int rst_file_params(int fd, FownEntry *fown, int flags)
return 0; return 0;
} }
static struct list_head *select_ps_list(int type, struct fdinfo_list_entry *le, struct rst_info *ri) static struct list_head *select_ps_list(struct file_desc *desc, struct rst_info *ri)
{ {
switch (type) { if (desc->ops->select_ps_list)
case FD_TYPES__EVENTPOLL: return desc->ops->select_ps_list(desc, ri);
return &ri->eventpoll; else
case FD_TYPES__TTY:
if (!tty_is_master(le))
return &ri->tty_slaves;
/* Fall through */
default:
return &ri->fds; 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)
...@@ -191,7 +185,7 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info) ...@@ -191,7 +185,7 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *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(e->type, new_le, rst_info)); list_add_tail(&new_le->ps_list, select_ps_list(fdesc, rst_info));
return 0; return 0;
} }
......
...@@ -48,6 +48,7 @@ struct file_desc_ops { ...@@ -48,6 +48,7 @@ struct file_desc_ops {
int (*open)(struct file_desc *d); int (*open)(struct file_desc *d);
int (*post_open)(struct file_desc *d, int fd); int (*post_open)(struct file_desc *d, int fd);
int (*want_transport)(FdinfoEntry *fe, struct file_desc *d); int (*want_transport)(FdinfoEntry *fe, struct file_desc *d);
struct list_head * (*select_ps_list)(struct file_desc *, struct rst_info *);
}; };
struct file_desc { struct file_desc {
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
extern int dump_tty(struct fd_parms *p, int lfd, const struct cr_fdset *set); extern int dump_tty(struct fd_parms *p, int lfd, const struct cr_fdset *set);
extern int collect_tty(void); extern int collect_tty(void);
extern int tty_is_master(struct fdinfo_list_entry *le);
extern int prepare_shared_tty(void); extern int prepare_shared_tty(void);
extern void tty_setup_slavery(void); extern void tty_setup_slavery(void);
......
...@@ -438,16 +438,6 @@ err: ...@@ -438,16 +438,6 @@ err:
return -1; return -1;
} }
/*
* Unix98 pty slave peers requires the master peers being
* opened early, this function test if it's master pty.
*/
int tty_is_master(struct fdinfo_list_entry *le)
{
struct tty_info *info = container_of(le->desc, struct tty_info, d);
return pty_is_master(info);
}
static int pty_open_slaves(struct tty_info *info) static int pty_open_slaves(struct tty_info *info)
{ {
int sock = -1, fd = -1, ret = -1; int sock = -1, fd = -1, ret = -1;
...@@ -616,11 +606,25 @@ static int tty_transport(FdinfoEntry *fe, struct file_desc *d) ...@@ -616,11 +606,25 @@ 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)
{
/*
* Unix98 pty slave peers requires the master peers being
* opened before them
*/
if (pty_is_master(container_of(d, struct tty_info, d)))
return &ri->fds;
else
return &ri->tty_slaves;
}
static struct file_desc_ops tty_desc_ops = { static struct file_desc_ops tty_desc_ops = {
.type = FD_TYPES__TTY, .type = FD_TYPES__TTY,
.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,
}; };
static int tty_find_restoring_task(struct tty_info *info) static int tty_find_restoring_task(struct tty_info *info)
......
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