mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 01:51:51 +00:00
fdinfo: Make fdinfo.type be an enum
This types specifies a strict set of what is hidden behind the fd. Thus these numbers should be in the description of the fdinfo message. Plus protobuf makes shure nothing else will be there. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
dffd0aa65f
commit
9fc1d6bbeb
@ -161,7 +161,7 @@ static int check_fdinfo_eventfd(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = parse_fdinfo(fd, FDINFO_EVENTFD, check_one_fdinfo, &proc_cnt);
|
ret = parse_fdinfo(fd, FD_TYPES__EVENTFD, check_one_fdinfo, &proc_cnt);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -209,7 +209,7 @@ static int check_fdinfo_eventpoll(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = parse_fdinfo(efd, FDINFO_EVENTPOLL, check_one_epoll, &proc_fd);
|
ret = parse_fdinfo(efd, FD_TYPES__EVENTPOLL, check_one_epoll, &proc_fd);
|
||||||
close(efd);
|
close(efd);
|
||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
close(pfd[1]);
|
close(pfd[1]);
|
||||||
@ -251,7 +251,7 @@ static int check_fdinfo_inotify(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = parse_fdinfo(ifd, FDINFO_INOTIFY, check_one_inotify, &proc_wd);
|
ret = parse_fdinfo(ifd, FD_TYPES__INOTIFY, check_one_inotify, &proc_wd);
|
||||||
close(ifd);
|
close(ifd);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -74,11 +74,11 @@ static int dump_eventfd_entry(union fdinfo_entries *e, void *arg)
|
|||||||
static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
|
static int dump_one_eventfd(int lfd, u32 id, const struct fd_parms *p)
|
||||||
{
|
{
|
||||||
struct eventfd_dump_arg da = { .id = id, .p = p, };
|
struct eventfd_dump_arg da = { .id = id, .p = p, };
|
||||||
return parse_fdinfo(lfd, FDINFO_EVENTFD, dump_eventfd_entry, &da);
|
return parse_fdinfo(lfd, FD_TYPES__EVENTFD, dump_eventfd_entry, &da);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops eventfd_ops = {
|
static const struct fdtype_ops eventfd_ops = {
|
||||||
.type = FDINFO_EVENTFD,
|
.type = FD_TYPES__EVENTFD,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_eventfd,
|
.dump = dump_one_eventfd,
|
||||||
};
|
};
|
||||||
@ -116,7 +116,7 @@ err_close:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct file_desc_ops eventfd_desc_ops = {
|
static struct file_desc_ops eventfd_desc_ops = {
|
||||||
.type = FDINFO_EVENTFD,
|
.type = FD_TYPES__EVENTFD,
|
||||||
.open = eventfd_open,
|
.open = eventfd_open,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -86,11 +86,11 @@ static int dump_one_eventpoll(int lfd, u32 id, const struct fd_parms *p)
|
|||||||
&e, eventpoll_file_entry))
|
&e, eventpoll_file_entry))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return parse_fdinfo(lfd, FDINFO_EVENTPOLL, dump_eventpoll_entry, &id);
|
return parse_fdinfo(lfd, FD_TYPES__EVENTPOLL, dump_eventpoll_entry, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops eventpoll_ops = {
|
static const struct fdtype_ops eventpoll_ops = {
|
||||||
.type = FDINFO_EVENTPOLL,
|
.type = FD_TYPES__EVENTPOLL,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_eventpoll,
|
.dump = dump_one_eventpoll,
|
||||||
};
|
};
|
||||||
@ -144,7 +144,7 @@ err_close:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct file_desc_ops desc_ops = {
|
static struct file_desc_ops desc_ops = {
|
||||||
.type = FDINFO_EVENTPOLL,
|
.type = FD_TYPES__EVENTPOLL,
|
||||||
.open = eventpoll_open,
|
.open = eventpoll_open,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
4
fifo.c
4
fifo.c
@ -64,7 +64,7 @@ static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops fifo_ops = {
|
static const struct fdtype_ops fifo_ops = {
|
||||||
.type = FDINFO_FIFO,
|
.type = FD_TYPES__FIFO,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_fifo,
|
.dump = dump_one_fifo,
|
||||||
};
|
};
|
||||||
@ -119,7 +119,7 @@ static int open_fifo_fd(struct file_desc *d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct file_desc_ops fifo_desc_ops = {
|
static struct file_desc_ops fifo_desc_ops = {
|
||||||
.type = FDINFO_FIFO,
|
.type = FD_TYPES__FIFO,
|
||||||
.open = open_fifo_fd,
|
.open = open_fifo_fd,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ static int collect_remaps(void)
|
|||||||
goto tail;
|
goto tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdesc = find_file_desc_raw(FDINFO_REG, rfe->orig_id);
|
fdesc = find_file_desc_raw(FD_TYPES__REG, rfe->orig_id);
|
||||||
if (fdesc == NULL) {
|
if (fdesc == NULL) {
|
||||||
pr_err("Remap for non existing file %#x\n",
|
pr_err("Remap for non existing file %#x\n",
|
||||||
rfe->orig_id);
|
rfe->orig_id);
|
||||||
@ -335,7 +335,7 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops regfile_ops = {
|
static const struct fdtype_ops regfile_ops = {
|
||||||
.type = FDINFO_REG,
|
.type = FD_TYPES__REG,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_reg_file,
|
.dump = dump_one_reg_file,
|
||||||
};
|
};
|
||||||
@ -380,7 +380,7 @@ int open_path_by_id(u32 id, int (*open_cb)(struct reg_file_info *, void *), void
|
|||||||
{
|
{
|
||||||
struct file_desc *fd;
|
struct file_desc *fd;
|
||||||
|
|
||||||
fd = find_file_desc_raw(FDINFO_REG, id);
|
fd = find_file_desc_raw(FD_TYPES__REG, id);
|
||||||
if (fd == NULL) {
|
if (fd == NULL) {
|
||||||
pr_perror("Can't find regfile for %#x\n", id);
|
pr_perror("Can't find regfile for %#x\n", id);
|
||||||
return -1;
|
return -1;
|
||||||
@ -418,7 +418,7 @@ int open_reg_by_id(u32 id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct file_desc_ops reg_desc_ops = {
|
static struct file_desc_ops reg_desc_ops = {
|
||||||
.type = FDINFO_REG,
|
.type = FD_TYPES__REG,
|
||||||
.open = open_fe_fd,
|
.open = open_fe_fd,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
files.c
2
files.c
@ -186,7 +186,7 @@ static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
|
|||||||
list_add_tail(&le->desc_list, &l->desc_list);
|
list_add_tail(&le->desc_list, &l->desc_list);
|
||||||
le->desc = fdesc;
|
le->desc = fdesc;
|
||||||
|
|
||||||
if (unlikely(le->fe->type == FDINFO_EVENTPOLL))
|
if (unlikely(le->fe->type == FD_TYPES__EVENTPOLL))
|
||||||
list_add_tail(&le->ps_list, &rst_info->eventpoll);
|
list_add_tail(&le->ps_list, &rst_info->eventpoll);
|
||||||
else
|
else
|
||||||
list_add_tail(&le->ps_list, &rst_info->fds);
|
list_add_tail(&le->ps_list, &rst_info->fds);
|
||||||
|
@ -43,20 +43,6 @@
|
|||||||
#define INOTIFY_WD_MAGIC 0x54562009 /* Svetlogorsk (Rauschen) */
|
#define INOTIFY_WD_MAGIC 0x54562009 /* Svetlogorsk (Rauschen) */
|
||||||
#define MOUNTPOINTS_MAGIC 0x55563928 /* Petushki */
|
#define MOUNTPOINTS_MAGIC 0x55563928 /* Petushki */
|
||||||
|
|
||||||
enum fd_types {
|
|
||||||
FDINFO_UND,
|
|
||||||
FDINFO_REG,
|
|
||||||
FDINFO_PIPE,
|
|
||||||
FDINFO_FIFO,
|
|
||||||
FDINFO_INETSK,
|
|
||||||
FDINFO_UNIXSK,
|
|
||||||
FDINFO_EVENTFD,
|
|
||||||
FDINFO_EVENTPOLL,
|
|
||||||
FDINFO_INOTIFY,
|
|
||||||
|
|
||||||
FD_INFO_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
#define PAGE_IMAGE_SIZE 4096
|
#define PAGE_IMAGE_SIZE 4096
|
||||||
#define PAGE_RSS 1
|
#define PAGE_RSS 1
|
||||||
#define PAGE_ANON 2
|
#define PAGE_ANON 2
|
||||||
|
@ -92,11 +92,11 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
|
|||||||
if (pb_write(fdset_fd(glob_fdset, CR_FD_INOTIFY), &ie, inotify_file_entry))
|
if (pb_write(fdset_fd(glob_fdset, CR_FD_INOTIFY), &ie, inotify_file_entry))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return parse_fdinfo(lfd, FDINFO_INOTIFY, dump_inotify_entry, &id);
|
return parse_fdinfo(lfd, FD_TYPES__INOTIFY, dump_inotify_entry, &id);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops inotify_ops = {
|
static const struct fdtype_ops inotify_ops = {
|
||||||
.type = FDINFO_INOTIFY,
|
.type = FD_TYPES__INOTIFY,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_inotify,
|
.dump = dump_one_inotify,
|
||||||
};
|
};
|
||||||
@ -195,7 +195,7 @@ static int open_inotify_fd(struct file_desc *d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct file_desc_ops desc_ops = {
|
static struct file_desc_ops desc_ops = {
|
||||||
.type = FDINFO_INOTIFY,
|
.type = FD_TYPES__INOTIFY,
|
||||||
.open = open_inotify_fd,
|
.open = open_inotify_fd,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
4
pipes.c
4
pipes.c
@ -303,7 +303,7 @@ static int want_transport(FdinfoEntry *fe, struct file_desc *d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct file_desc_ops pipe_desc_ops = {
|
static struct file_desc_ops pipe_desc_ops = {
|
||||||
.type = FDINFO_PIPE,
|
.type = FD_TYPES__PIPE,
|
||||||
.open = open_pipe,
|
.open = open_pipe,
|
||||||
.want_transport = want_transport,
|
.want_transport = want_transport,
|
||||||
};
|
};
|
||||||
@ -446,7 +446,7 @@ static int dump_one_pipe(int lfd, u32 id, const struct fd_parms *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops pipe_ops = {
|
static const struct fdtype_ops pipe_ops = {
|
||||||
.type = FDINFO_PIPE,
|
.type = FD_TYPES__PIPE,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_pipe,
|
.dump = dump_one_pipe,
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "proc_parse.h"
|
#include "proc_parse.h"
|
||||||
#include "protobuf.h"
|
#include "protobuf.h"
|
||||||
|
#include "protobuf/fdinfo.pb-c.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -731,7 +732,7 @@ int parse_fdinfo(int fd, int type,
|
|||||||
if (fdinfo_field(str, "eventfd-count")) {
|
if (fdinfo_field(str, "eventfd-count")) {
|
||||||
eventfd_file_entry__init(&entry.efd);
|
eventfd_file_entry__init(&entry.efd);
|
||||||
|
|
||||||
if (type != FDINFO_EVENTFD)
|
if (type != FD_TYPES__EVENTFD)
|
||||||
goto parse_err;
|
goto parse_err;
|
||||||
ret = sscanf(str, "eventfd-count: %lx",
|
ret = sscanf(str, "eventfd-count: %lx",
|
||||||
&entry.efd.counter);
|
&entry.efd.counter);
|
||||||
@ -745,7 +746,7 @@ int parse_fdinfo(int fd, int type,
|
|||||||
if (fdinfo_field(str, "tfd")) {
|
if (fdinfo_field(str, "tfd")) {
|
||||||
eventpoll_tfd_entry__init(&entry.epl);
|
eventpoll_tfd_entry__init(&entry.epl);
|
||||||
|
|
||||||
if (type != FDINFO_EVENTPOLL)
|
if (type != FD_TYPES__EVENTPOLL)
|
||||||
goto parse_err;
|
goto parse_err;
|
||||||
ret = sscanf(str, "tfd: %d events: %x data: %lx",
|
ret = sscanf(str, "tfd: %d events: %x data: %lx",
|
||||||
&entry.epl.tfd, &entry.epl.events, &entry.epl.data);
|
&entry.epl.tfd, &entry.epl.events, &entry.epl.data);
|
||||||
@ -763,7 +764,7 @@ int parse_fdinfo(int fd, int type,
|
|||||||
inotify_wd_entry__init(&entry.ify);
|
inotify_wd_entry__init(&entry.ify);
|
||||||
entry.ify.f_handle = &f_handle;
|
entry.ify.f_handle = &f_handle;
|
||||||
|
|
||||||
if (type != FDINFO_INOTIFY)
|
if (type != FD_TYPES__INOTIFY)
|
||||||
goto parse_err;
|
goto parse_err;
|
||||||
ret = sscanf(str,
|
ret = sscanf(str,
|
||||||
"inotify wd: %8d ino: %16lx sdev: %8x "
|
"inotify wd: %8d ino: %16lx sdev: %8x "
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
|
enum fd_types {
|
||||||
|
UND = 0;
|
||||||
|
REG = 1;
|
||||||
|
PIPE = 2;
|
||||||
|
FIFO = 3;
|
||||||
|
INETSK = 4;
|
||||||
|
UNIXSK = 5;
|
||||||
|
EVENTFD = 6;
|
||||||
|
EVENTPOLL = 7;
|
||||||
|
INOTIFY = 8;
|
||||||
|
}
|
||||||
|
|
||||||
message fdinfo_entry {
|
message fdinfo_entry {
|
||||||
required uint32 id = 1;
|
required uint32 id = 1;
|
||||||
required uint32 flags = 2;
|
required uint32 flags = 2;
|
||||||
required uint32 type = 3;
|
required fd_types type = 3;
|
||||||
required uint32 fd = 4;
|
required uint32 fd = 4;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops inet_dump_ops = {
|
static const struct fdtype_ops inet_dump_ops = {
|
||||||
.type = FDINFO_INETSK,
|
.type = FD_TYPES__INETSK,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_inet_fd,
|
.dump = dump_one_inet_fd,
|
||||||
};
|
};
|
||||||
@ -288,7 +288,7 @@ static bool is_bound(struct inet_sk_info *ii)
|
|||||||
static int open_inet_sk(struct file_desc *d);
|
static int open_inet_sk(struct file_desc *d);
|
||||||
|
|
||||||
static struct file_desc_ops inet_desc_ops = {
|
static struct file_desc_ops inet_desc_ops = {
|
||||||
.type = FDINFO_INETSK,
|
.type = FD_TYPES__INETSK,
|
||||||
.open = open_inet_sk,
|
.open = open_inet_sk,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct fdtype_ops unix_dump_ops = {
|
static const struct fdtype_ops unix_dump_ops = {
|
||||||
.type = FDINFO_UNIXSK,
|
.type = FD_TYPES__UNIXSK,
|
||||||
.make_gen_id = make_gen_id,
|
.make_gen_id = make_gen_id,
|
||||||
.dump = dump_one_unix_fd,
|
.dump = dump_one_unix_fd,
|
||||||
};
|
};
|
||||||
@ -709,7 +709,7 @@ static int open_unix_sk(struct file_desc *d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct file_desc_ops unix_desc_ops = {
|
static struct file_desc_ops unix_desc_ops = {
|
||||||
.type = FDINFO_UNIXSK,
|
.type = FD_TYPES__UNIXSK,
|
||||||
.open = open_unix_sk,
|
.open = open_unix_sk,
|
||||||
.want_transport = unixsk_should_open_transport,
|
.want_transport = unixsk_should_open_transport,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user