Commit b38777df authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

eventpoll: Add checkpoint/restore v2

v2:
 - Move everything into eventpoll.[ch]
 - Use rst_file_params
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 580d3b02
...@@ -52,6 +52,7 @@ OBJS += ipc_ns.o ...@@ -52,6 +52,7 @@ OBJS += ipc_ns.o
OBJS += netfilter.o OBJS += netfilter.o
OBJS += shmem.o OBJS += shmem.o
OBJS += eventfd.o OBJS += eventfd.o
OBJS += eventpoll.o
DEPS := $(patsubst %.o,%.d,$(OBJS)) DEPS := $(patsubst %.o,%.d,$(OBJS))
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "shmem.h" #include "shmem.h"
#include "sk-inet.h" #include "sk-inet.h"
#include "eventfd.h" #include "eventfd.h"
#include "eventpoll.h"
#ifndef CONFIG_X86_64 #ifndef CONFIG_X86_64
# error No x86-32 support yet # error No x86-32 support yet
...@@ -325,6 +326,9 @@ static int do_dump_gen_file(const struct fd_parms *p, int lfd, ...@@ -325,6 +326,9 @@ static int do_dump_gen_file(const struct fd_parms *p, int lfd,
case FDINFO_EVENTFD: case FDINFO_EVENTFD:
ret = dump_one_eventfd(lfd, e.id, p); ret = dump_one_eventfd(lfd, e.id, p);
break; break;
case FDINFO_EVENTPOLL:
ret = dump_one_eventpoll(lfd, e.id, p);
break;
default: default:
ret = dump_one_reg_file(lfd, e.id, p); ret = dump_one_reg_file(lfd, e.id, p);
break; break;
...@@ -464,6 +468,13 @@ static int dump_eventfd(struct fd_parms *p, int lfd, const struct cr_fdset *set) ...@@ -464,6 +468,13 @@ static int dump_eventfd(struct fd_parms *p, int lfd, const struct cr_fdset *set)
return do_dump_gen_file(p, lfd, set); return do_dump_gen_file(p, lfd, set);
} }
static int dump_eventpoll(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
p->id = MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos);
p->type = FDINFO_EVENTPOLL;
return do_dump_gen_file(p, lfd, set);
}
static int dump_one_file(pid_t pid, int fd, int lfd, char fd_flags, static int dump_one_file(pid_t pid, int fd, int lfd, char fd_flags,
const struct cr_fdset *cr_fdset) const struct cr_fdset *cr_fdset)
{ {
...@@ -489,6 +500,8 @@ static int dump_one_file(pid_t pid, int fd, int lfd, char fd_flags, ...@@ -489,6 +500,8 @@ static int dump_one_file(pid_t pid, int fd, int lfd, char fd_flags,
if (is_anon_inode(&statfs)) { if (is_anon_inode(&statfs)) {
if (is_eventfd_link(lfd)) if (is_eventfd_link(lfd))
return dump_eventfd(&p, lfd, cr_fdset); return dump_eventfd(&p, lfd, cr_fdset);
else if (is_eventpoll_link(lfd))
return dump_eventpoll(&p, lfd, cr_fdset);
} }
if (S_ISREG(p.stat.st_mode) || if (S_ISREG(p.stat.st_mode) ||
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "pipes.h" #include "pipes.h"
#include "sk-inet.h" #include "sk-inet.h"
#include "eventfd.h" #include "eventfd.h"
#include "eventpoll.h"
#include "proc_parse.h" #include "proc_parse.h"
#include "restorer-blob.h" #include "restorer-blob.h"
#include "crtools.h" #include "crtools.h"
...@@ -166,6 +167,9 @@ static int prepare_shared(void) ...@@ -166,6 +167,9 @@ static int prepare_shared(void)
if (collect_eventfd()) if (collect_eventfd())
return -1; return -1;
if (collect_eventpoll())
return -1;
list_for_each_entry(pi, &tasks, list) { list_for_each_entry(pi, &tasks, list) {
ret = prepare_shmem_pid(pi->pid); ret = prepare_shmem_pid(pi->pid);
if (ret < 0) if (ret < 0)
......
...@@ -63,6 +63,7 @@ static char *fdtype2s(u8 type) ...@@ -63,6 +63,7 @@ static char *fdtype2s(u8 type)
[FDINFO_PIPE] = "pipe", [FDINFO_PIPE] = "pipe",
[FDINFO_UNIXSK] = "usk", [FDINFO_UNIXSK] = "usk",
[FDINFO_EVENTFD] = "efd", [FDINFO_EVENTFD] = "efd",
[FDINFO_EVENTPOLL] = "epl",
}; };
if (type > FDINFO_UND && type < FD_INFO_MAX) if (type > FDINFO_UND && type < FD_INFO_MAX)
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "files.h" #include "files.h"
#include "sk-inet.h" #include "sk-inet.h"
#include "eventfd.h" #include "eventfd.h"
#include "eventpoll.h"
struct cr_options opts; struct cr_options opts;
...@@ -71,6 +72,20 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = { ...@@ -71,6 +72,20 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = {
.show = show_eventfds, .show = show_eventfds,
}, },
/* eventpoll */
[CR_FD_EVENTPOLL] = {
.fmt = FMT_FNAME_EVENTPOLL,
.magic = EVENTPOLL_MAGIC,
.show = show_eventpoll,
},
/* eventpoll target file descriptors */
[CR_FD_EVENTPOLL_TFD] = {
.fmt = FMT_FNAME_EVENTPOLL_TFD,
.magic = EVENTPOLL_TFD_MAGIC,
.show = show_eventpoll_tfd,
},
/* core data, such as regs and vmas and such */ /* core data, such as regs and vmas and such */
[CR_FD_CORE] = { [CR_FD_CORE] = {
.fmt = FMT_FNAME_CORE, .fmt = FMT_FNAME_CORE,
......
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/epoll.h>
#include "compiler.h"
#include "types.h"
#include "eventpoll.h"
#include "crtools.h"
#include "image.h"
#include "util.h"
#include "log.h"
struct eventpoll_file_info {
struct eventpoll_file_entry efe;
struct file_desc d;
};
struct eventpoll_tfd_file_info {
struct eventpoll_tfd_entry tdefe;
struct list_head list;
};
static LIST_HEAD(eventpoll_tfds);
/* Checks if file desciptor @lfd is eventfd */
int is_eventpoll_link(int lfd)
{
char link[PATH_MAX], path[32];
ssize_t ret;
snprintf(path, sizeof(path), "/proc/self/fd/%d", lfd);
ret = readlink(path, link, sizeof(link));
if (ret < 0) {
pr_perror("Can't read link of fd %d\n", lfd);
return 0;
}
link[ret] = 0;
if (!strcmp(link, "anon_inode:[eventpoll]"))
return 1;
return 0;
}
static void pr_info_eventpoll_tfd(char *action, struct eventpoll_tfd_entry *e)
{
pr_info("%seventpoll-tfd: id %#08x tfd %#08x events %#08x data %#016lx\n",
action, e->id, e->tfd, e->events, e->data);
}
static void pr_info_eventpoll(char *action, struct eventpoll_file_entry *e)
{
pr_info("%seventpoll: id %#08x flags %#04x\n", action, e->id, e->flags);
}
void show_eventpoll_tfd(int fd, struct cr_options *o)
{
struct eventpoll_tfd_entry e;
pr_img_head(CR_FD_EVENTPOLL_TFD);
while (1) {
int ret;
ret = read_img_eof(fd, &e);
if (ret <= 0)
goto out;
pr_msg("id: %#08x tfd %#08x events %#08x data %#016lx\n",
e.id, e.tfd, e.events, e.data);
}
out:
pr_img_tail(CR_FD_EVENTPOLL_TFD);
}
void show_eventpoll(int fd, struct cr_options *o)
{
struct eventpoll_file_entry e;
pr_img_head(CR_FD_EVENTPOLL);
while (1) {
int ret;
ret = read_img_eof(fd, &e);
if (ret <= 0)
goto out;
pr_msg("id: %#08x flags %#04x ",
e.id, e.flags);
show_fown_cont(&e.fown);
pr_msg("\n");
}
out:
pr_img_tail(CR_FD_EVENTPOLL);
}
int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
{
int image_fd = fdset_fd(glob_fdset, CR_FD_EVENTPOLL);
int image_tfd = fdset_fd(glob_fdset, CR_FD_EVENTPOLL_TFD);
struct eventpoll_file_entry e;
struct eventpoll_tfd_entry efd;
char buf[PAGE_SIZE], *tok;
int ret, fdinfo;
snprintf(buf, sizeof(buf), "/proc/self/fdinfo/%d", lfd);
fdinfo = open(buf, O_RDONLY);
if (fdinfo < 0) {
pr_perror("Can't open %d (%d)", p->fd, lfd);
return -1;
}
ret = read(fdinfo, buf, sizeof(buf));
close(fdinfo);
if (ret <= 0) {
pr_perror("Reading eventpoll from %d (%d) failed", p->fd, lfd);
return -1;
}
e.id = id;
e.flags = p->flags;
e.fown = p->fown;
pr_info_eventpoll("Dumping ", &e);
if (write_img(image_fd, &e))
return -1;
tok = strstr(buf, "tfd:");
if (!tok)
goto parsing_err;
tok = strtok(tok, "\n");
while (tok) {
efd.id = id;
if (sscanf(tok, "tfd: %8d events: %8x data: %16lx",
&efd.tfd, &efd.events, &efd.data) != 3)
goto parsing_err;
tok = strtok(NULL, "\n");
pr_info_eventpoll_tfd("Dumping: ", &efd);
if (write_img(image_tfd, &efd))
return -1;
}
return 0;
parsing_err:
pr_err("Parsing error %d (%d)", p->fd, lfd);
return -1;
}
static int eventpoll_open(struct file_desc *d)
{
struct eventpoll_tfd_file_info *td_info;
struct eventpoll_file_info *info;
int tmp, ret;
info = container_of(d, struct eventpoll_file_info, d);
tmp = epoll_create(1);
if (tmp < 0) {
pr_perror("Can't create epoll %#08x",
info->efe.id);
return -1;
}
if (rst_file_params(tmp, &info->efe.fown, info->efe.flags)) {
pr_perror("Can't restore file params on epoll %#08x",
info->efe.id);
goto err_close;
}
list_for_each_entry(td_info, &eventpoll_tfds, list) {
struct epoll_event event;
if (td_info->tdefe.id != info->efe.id)
continue;
event.events = td_info->tdefe.events;
event.data.u64 = td_info->tdefe.data;
ret = epoll_ctl(tmp, EPOLL_CTL_ADD, td_info->tdefe.tfd, &event);
if (ret) {
pr_perror("Can't add event on %#08x", info->efe.id);
goto err_close;
}
}
return tmp;
err_close:
close(tmp);
return -1;
}
static struct file_desc_ops desc_ops = {
.open = eventpoll_open,
};
int collect_eventpoll(void)
{
int image_fd;
int ret = -1;
image_fd = open_image_ro(CR_FD_EVENTPOLL_TFD);
if (image_fd < 0)
return -1;
while (1) {
struct eventpoll_tfd_file_info *info;
info = xmalloc(sizeof(*info));
if (!info)
goto err;
ret = read_img_eof(image_fd, &info->tdefe);
if (ret < 0)
goto err;
else if (!ret)
break;
INIT_LIST_HEAD(&info->list);
list_add(&info->list, &eventpoll_tfds);
pr_info_eventpoll_tfd("Collected ", &info->tdefe);
}
close_safe(&image_fd);
image_fd = open_image_ro(CR_FD_EVENTPOLL);
if (image_fd < 0)
return -1;
while (1) {
struct eventpoll_file_info *info;
info = xmalloc(sizeof(*info));
if (!info)
goto err;
ret = read_img_eof(image_fd, &info->efe);
if (ret < 0)
goto err;
else if (!ret)
break;
pr_info_eventpoll("Collected ", &info->efe);
file_desc_add(&info->d, FDINFO_EVENTPOLL, info->efe.id, &desc_ops);
}
err:
close_safe(&image_fd);
return ret;
}
...@@ -56,6 +56,8 @@ enum { ...@@ -56,6 +56,8 @@ enum {
CR_FD_PIPES_DATA, CR_FD_PIPES_DATA,
CR_FD_REMAP_FPATH, CR_FD_REMAP_FPATH,
CR_FD_EVENTFD, CR_FD_EVENTFD,
CR_FD_EVENTPOLL,
CR_FD_EVENTPOLL_TFD,
_CR_FD_GLOB_TO, _CR_FD_GLOB_TO,
CR_FD_MAX CR_FD_MAX
...@@ -122,6 +124,8 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX]; ...@@ -122,6 +124,8 @@ extern struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX];
#define FMT_FNAME_UNIXSK "unixsk.img" #define FMT_FNAME_UNIXSK "unixsk.img"
#define FMT_FNAME_INETSK "inetsk.img" #define FMT_FNAME_INETSK "inetsk.img"
#define FMT_FNAME_EVENTFD "eventfd.img" #define FMT_FNAME_EVENTFD "eventfd.img"
#define FMT_FNAME_EVENTPOLL "eventpoll.img"
#define FMT_FNAME_EVENTPOLL_TFD "eventpoll-tfd.img"
#define FMT_FNAME_ITIMERS "itimers-%d.img" #define FMT_FNAME_ITIMERS "itimers-%d.img"
#define FMT_FNAME_CREDS "creds-%d.img" #define FMT_FNAME_CREDS "creds-%d.img"
#define FMT_FNAME_UTSNS "utsns-%d.img" #define FMT_FNAME_UTSNS "utsns-%d.img"
......
#ifndef EVENTPOLL_H__
#define EVENTPOLL_H__
#include <sys/types.h>
#include <unistd.h>
#include "compiler.h"
#include "types.h"
#include "files.h"
#include "crtools.h"
extern int is_eventpoll_link(int lfd);
extern int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p);
extern int collect_eventpoll(void);
extern void show_eventpoll(int fd, struct cr_options *o);
extern void show_eventpoll_tfd(int fd, struct cr_options *o);
#endif /* EVENTPOLL_H__ */
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#define GHOST_FILE_MAGIC 0x52583605 /* Oryol */ #define GHOST_FILE_MAGIC 0x52583605 /* Oryol */
#define TCP_STREAM_MAGIC 0x51465506 /* Orenburg */ #define TCP_STREAM_MAGIC 0x51465506 /* Orenburg */
#define EVENTFD_MAGIC 0x44523722 /* Anapa */ #define EVENTFD_MAGIC 0x44523722 /* Anapa */
#define EVENTPOLL_MAGIC 0x45023858 /* Krasnodar */
#define EVENTPOLL_TFD_MAGIC 0x44433746 /* Novorossiysk */
#define PIPEFS_MAGIC 0x50495045 #define PIPEFS_MAGIC 0x50495045
...@@ -44,6 +46,7 @@ enum fd_types { ...@@ -44,6 +46,7 @@ enum fd_types {
FDINFO_INETSK, FDINFO_INETSK,
FDINFO_UNIXSK, FDINFO_UNIXSK,
FDINFO_EVENTFD, FDINFO_EVENTFD,
FDINFO_EVENTPOLL,
FD_INFO_MAX FD_INFO_MAX
}; };
...@@ -93,6 +96,19 @@ struct eventfd_file_entry { ...@@ -93,6 +96,19 @@ struct eventfd_file_entry {
u64 counter; u64 counter;
} __packed; } __packed;
struct eventpoll_tfd_entry {
u32 id;
u32 tfd;
u32 events;
u64 data;
} __packed;
struct eventpoll_file_entry {
u32 id;
u32 flags;
fown_t fown;
} __packed;
struct fdinfo_entry { struct fdinfo_entry {
u32 fd; u32 fd;
u8 type; u8 type;
......
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