From 3de41b80707db3fbc6a132a04df518819f58f595 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 5 Feb 2014 15:55:29 +0400 Subject: [PATCH] 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: Pavel Emelyanov --- eventpoll.c | 7 ++++--- files.c | 14 +++++--------- include/files.h | 14 +++++++++++--- tty.c | 13 +++++++++---- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/eventpoll.c b/eventpoll.c index 603890093..88b331f1a 100644 --- a/eventpoll.c +++ b/eventpoll.c @@ -144,16 +144,17 @@ static int eventpoll_post_open(struct file_desc *d, int fd) 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 = { .type = FD_TYPES__EVENTPOLL, .open = eventpoll_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) diff --git a/files.c b/files.c index 363703f79..8159b72c2 100644 --- a/files.c +++ b/files.c @@ -533,14 +533,6 @@ int rst_file_params(int fd, FownEntry *fown, int flags) 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) { struct fdinfo_list_entry *le, *new_le; @@ -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)) 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); new_le->desc = fdesc; - list_add_tail(&new_le->ps_list, select_ps_list(fdesc, rst_info)); return 0; } diff --git a/include/files.h b/include/files.h index 6a6995536..88fba39ac 100644 --- a/include/files.h +++ b/include/files.h @@ -8,6 +8,7 @@ #include "list.h" #include "image.h" #include "pid.h" +#include "rst_info.h" #include "protobuf/fdinfo.pb-c.h" #include "protobuf/fown.pb-c.h" @@ -96,12 +97,19 @@ struct file_desc_ops { */ int (*want_transport)(FdinfoEntry *fe, struct file_desc *d); /* - * Helps determining sequence of different file types restore. - * See the prepare_fds for details. + * Called to collect a new fd before adding it on desc. Clients + * 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 { u32 id; /* File id, unique */ struct hlist_node hash; /* Descriptor hashing and lookup */ diff --git a/tty.c b/tty.c index 2ad76cbbf..5fca74c33 100644 --- a/tty.c +++ b/tty.c @@ -667,17 +667,22 @@ static int tty_transport(FdinfoEntry *fe, struct file_desc *d) 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 * opened before them */ if (pty_is_master(container_of(d, struct tty_info, d))) - return &ri->fds; + tgt = &ri->fds; else - return &ri->tty_slaves; + tgt = &ri->tty_slaves; + + list_add_tail(&fle->ps_list, tgt); } static struct file_desc_ops tty_desc_ops = { @@ -685,7 +690,7 @@ static struct file_desc_ops tty_desc_ops = { .open = tty_open, .post_open = tty_restore_ctl_terminal, .want_transport = tty_transport, - .select_ps_list = tty_select_pslist, + .collect_fd = tty_collect_fd, }; static struct pstree_item *find_first_sid(int sid)