[CRIU] [PATCH] dump: Rework dump_one_fd types assignment
Cyrill Gorcunov
gorcunov at openvz.org
Tue Apr 10 10:20:16 EDT 2012
This should open a way for more easier extension
of dumping files.
In particular one could add new type to enum fd_types
and handle it there depending on type assigned.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
cr-dump.c | 43 +++++++++++++++++++++----------------------
include/image.h | 3 +++
2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index 1e73109..4428bbb 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -331,18 +331,6 @@ err:
return ret;
}
-static int dump_one_fdinfo(struct fd_parms *p, int lfd,
- const struct cr_fdset *cr_fdset)
-{
- p->id = MAKE_FD_GENID(p->stat.st_dev, p->stat.st_ino, p->pos);
- if (S_ISFIFO(p->stat.st_mode))
- p->type = FDINFO_PIPE;
- else
- p->type = FDINFO_REG;
-
- return do_dump_one_fdinfo(p, lfd, cr_fdset);
-}
-
static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
{
struct fd_parms params;
@@ -375,6 +363,7 @@ static int fill_fd_params(pid_t pid, int fd, int lfd, struct fd_parms *p)
return -1;
}
+ p->type = FDINFO_UND;
p->fd_name = fd;
p->pos = lseek(lfd, 0, SEEK_CUR);
p->flags = fcntl(lfd, F_GETFL);
@@ -394,13 +383,13 @@ static int dump_unsupp_fd(const struct fd_parms *p)
return -1;
}
-static int dump_one_chrdev(struct fd_parms *p, int lfd, const struct cr_fdset *set)
+static int dumpable_chrdev(struct fd_parms *p, int lfd, const struct cr_fdset *set)
{
int maj;
maj = major(p->stat.st_rdev);
if (maj == MEM_MAJOR)
- return dump_one_fdinfo(p, lfd, set);
+ return 1;
if (p->fd_name < 3 && (maj == TTY_MAJOR ||
maj == UNIX98_PTY_SLAVE_MAJOR)) {
@@ -408,7 +397,7 @@ static int dump_one_chrdev(struct fd_parms *p, int lfd, const struct cr_fdset *s
return 0;
}
- return dump_unsupp_fd(p);
+ return -1;
}
static int dump_one_fd(pid_t pid, int fd, int lfd,
@@ -424,15 +413,25 @@ static int dump_one_fd(pid_t pid, int fd, int lfd,
if (S_ISSOCK(p.stat.st_mode))
return dump_socket(&p, lfd, cr_fdset);
- if (S_ISCHR(p.stat.st_mode))
- return dump_one_chrdev(&p, lfd, cr_fdset);
+ if (S_ISFIFO(p.stat.st_mode))
+ p.type = FDINFO_PIPE;
+ else if (S_ISREG(p.stat.st_mode) || S_ISDIR(p.stat.st_mode))
+ p.type = FDINFO_REG;
+ else if (S_ISCHR(p.stat.st_mode)) {
+ switch (dumpable_chrdev(&p, lfd, cr_fdset)) {
+ case 0: /* Skip it */
+ return 0;
+ case 1:
+ p.type = FDINFO_REG;
+ }
+ }
+
+ if (FDINFO_IS_UNKNOWN(p.type))
+ return dump_unsupp_fd(&p);
- if (S_ISREG(p.stat.st_mode) ||
- S_ISDIR(p.stat.st_mode) ||
- S_ISFIFO(p.stat.st_mode))
- return dump_one_fdinfo(&p, lfd, cr_fdset);
+ p.id = MAKE_FD_GENID(p.stat.st_dev, p.stat.st_ino, p.pos);
- return dump_unsupp_fd(&p);
+ return do_dump_one_fdinfo(&p, lfd, cr_fdset);
}
static int dump_task_files_seized(struct parasite_ctl *ctl, const struct cr_fdset *cr_fdset,
diff --git a/include/image.h b/include/image.h
index a992062..2ad2ab2 100644
--- a/include/image.h
+++ b/include/image.h
@@ -33,6 +33,9 @@
#define PIPEFS_MAGIC 0x50495045
+#define FDINFO_IS_UNKNOWN(type) \
+ ((type) == FDINFO_UND || (type) >= FD_INFO_MAX)
+
enum fd_types {
FDINFO_UND,
FDINFO_REG,
--
1.7.7.6
More information about the CRIU
mailing list