[CRIU] [PATCH 4/4] protobuf: Use FdinfoEntry instead of struct
fdinfo_entry
Cyrill Gorcunov
gorcunov at openvz.org
Fri Jul 6 08:10:48 EDT 2012
This patch get rid of fdinfo_entry and start using protobuf
facility for real.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
cr-dump.c | 20 ++++++++++----------
cr-show.c | 16 ++++++++--------
file-ids.c | 2 +-
files.c | 20 ++++++++++++--------
include/file-ids.h | 5 +++--
include/files.h | 6 ++++--
include/image.h | 7 -------
include/sockets.h | 1 -
pipes.c | 2 +-
sk-unix.c | 2 +-
10 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/cr-dump.c b/cr-dump.c
index 9ee3463..6052114 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -45,6 +45,9 @@
#include "inotify.h"
#include "pstree.h"
+#include "protobuf.h"
+#include "protobuf/fdinfo.pb-c.h"
+
#ifndef CONFIG_X86_64
# error No x86-32 support yet
#endif
@@ -130,30 +133,27 @@ u32 make_gen_id(const struct fd_parms *p)
int do_dump_gen_file(struct fd_parms *p, int lfd,
const struct fdtype_ops *ops, const struct cr_fdset *cr_fdset)
{
- struct fdinfo_entry e;
+ FdinfoEntry e = FDINFO_ENTRY__INIT;
int ret = -1;
- e.type = ops->type;
e.id = ops->make_gen_id(p);
e.fd = p->fd;
- e.flags = p->fd_flags;
+ e.type = ops->type;
+ e.flags = p->fd_flags;
ret = fd_id_generate(p->pid, &e);
if (ret == 1) /* new ID generated */
ret = ops->dump(lfd, e.id, p);
if (ret < 0)
- goto err;
+ return -1;
pr_info("fdinfo: type: 0x%2x flags: 0x%4x pos: 0x%8lx fd: %d\n",
ops->type, p->flags, p->pos, p->fd);
- if (write_img(fdset_fd(cr_fdset, CR_FD_FDINFO), &e))
- goto err;
-
- ret = 0;
-err:
- return ret;
+ return pb_write(fdset_fd(cr_fdset, CR_FD_FDINFO), &e,
+ fdinfo_entry__get_packed_size,
+ fdinfo_entry__pack);
}
static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
diff --git a/cr-show.c b/cr-show.c
index 97c8037..dd17b09 100644
--- a/cr-show.c
+++ b/cr-show.c
@@ -24,6 +24,9 @@
#include "ipc_ns.h"
#include "pstree.h"
+#include "protobuf.h"
+#include "protobuf/fdinfo.pb-c.h"
+
#define DEF_PAGES_PER_LINE 6
#ifndef CONFIG_X86_64
@@ -77,21 +80,18 @@ static char *fdtype2s(u8 type)
void show_files(int fd_files, struct cr_options *o)
{
- struct fdinfo_entry e;
pr_img_head(CR_FD_FDINFO);
while (1) {
- int ret;
+ FdinfoEntry *e;
+ int ret = pb_read_eof(fd_files, &e, fdinfo_entry__unpack);
- ret = read_img_eof(fd_files, &e);
if (ret <= 0)
goto out;
-
- pr_msg("type: %-5s fd: %-5d id: %#x flags %#x",
- fdtype2s(e.type), e.fd, e.id, e.flags);
-
- pr_msg("\n");
+ pr_msg("type: %-5s fd: %-5d id: %#x flags %#x\n",
+ fdtype2s(e->type), e->fd, e->id, e->flags);
+ fdinfo_entry__free_unpacked(e, NULL);
}
out:
diff --git a/file-ids.c b/file-ids.c
index 31cd215..690713e 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -30,7 +30,7 @@ u32 fd_id_generate_special(void)
return fd_tree.subid++;
}
-int fd_id_generate(pid_t pid, struct fdinfo_entry *fe)
+int fd_id_generate(pid_t pid, FdinfoEntry *fe)
{
u32 id;
struct kid_elem e;
diff --git a/files.c b/files.c
index 38f1ea3..0b2f6d8 100644
--- a/files.c
+++ b/files.c
@@ -24,6 +24,8 @@
#include "sockets.h"
#include "pstree.h"
+#include "protobuf.h"
+
static struct fdinfo_list_entry *fdinfo_list;
static int nr_fdinfo_list;
@@ -71,7 +73,7 @@ struct file_desc *find_file_desc_raw(int type, u32 id)
return NULL;
}
-static inline struct file_desc *find_file_desc(struct fdinfo_entry *fe)
+static inline struct file_desc *find_file_desc(FdinfoEntry *fe)
{
return find_file_desc_raw(fe->type, fe->id);
}
@@ -152,7 +154,7 @@ int rst_file_params(int fd, fown_t *fown, int flags)
return 0;
}
-static int collect_fd(int pid, struct fdinfo_entry *e, struct rst_info *rst_info)
+static int collect_fd(int pid, FdinfoEntry *e, struct rst_info *rst_info)
{
struct fdinfo_list_entry *l, *le = &fdinfo_list[nr_fdinfo_list];
struct file_desc *fdesc;
@@ -206,13 +208,15 @@ int prepare_fd_pid(int pid, struct rst_info *rst_info)
}
while (1) {
- struct fdinfo_entry e;
+ FdinfoEntry *e;
- ret = read_img_eof(fdinfo_fd, &e);
+ ret = pb_read_eof(fdinfo_fd, &e, fdinfo_entry__unpack);
if (ret <= 0)
break;
- ret = collect_fd(pid, &e, rst_info);
+ ret = collect_fd(pid, e, rst_info);
+ fdinfo_entry__free_unpacked(e, NULL);
+
if (ret < 0)
break;
}
@@ -251,7 +255,7 @@ static void transport_name_gen(struct sockaddr_un *addr, int *len,
*addr->sun_path = '\0';
}
-static int should_open_transport(struct fdinfo_entry *fe, struct file_desc *fd)
+static int should_open_transport(FdinfoEntry *fe, struct file_desc *fd)
{
if (fd->ops->want_transport)
return fd->ops->want_transport(fe, fd);
@@ -322,7 +326,7 @@ int send_fd_to_peer(int fd, struct fdinfo_list_entry *fle, int tsk)
return send_fd(tsk, &saddr, len, fd);
}
-static int open_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
+static int open_fd(int pid, FdinfoEntry *fe, struct file_desc *d)
{
int tmp;
int sock;
@@ -379,7 +383,7 @@ static int open_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
return 0;
}
-static int receive_fd(int pid, struct fdinfo_entry *fe, struct file_desc *d)
+static int receive_fd(int pid, FdinfoEntry *fe, struct file_desc *d)
{
int tmp;
struct fdinfo_list_entry *fle;
diff --git a/include/file-ids.h b/include/file-ids.h
index d71f553..4cb052e 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -5,14 +5,15 @@
#include "types.h"
#include "rbtree.h"
+#include "../protobuf/fdinfo.pb-c.h"
+
#define FD_PID_INVALID (-2U)
#define FD_DESC_INVALID (-3U)
#define MAKE_FD_GENID(dev, ino, pos) \
(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
-struct fdinfo_entry;
-extern int fd_id_generate(pid_t pid, struct fdinfo_entry *fe);
+extern int fd_id_generate(pid_t pid, FdinfoEntry *fe);
extern u32 fd_id_generate_special(void);
extern void fd_id_show_tree(void);
diff --git a/include/files.h b/include/files.h
index b69bb0a..3ffa75d 100644
--- a/include/files.h
+++ b/include/files.h
@@ -7,6 +7,8 @@
#include "list.h"
#include "image.h"
+#include "../protobuf/fdinfo.pb-c.h"
+
struct pstree_item;
struct file_desc;
struct cr_fdset;
@@ -38,13 +40,13 @@ struct fdinfo_list_entry {
struct list_head ps_list;
int pid;
futex_t real_pid;
- struct fdinfo_entry fe;
+ FdinfoEntry fe;
};
struct file_desc_ops {
unsigned int type;
int (*open)(struct file_desc *d);
- int (*want_transport)(struct fdinfo_entry *fe, struct file_desc *d);
+ int (*want_transport)(FdinfoEntry *fe, struct file_desc *d);
};
struct file_desc {
diff --git a/include/image.h b/include/image.h
index e528b3e..c522e25 100644
--- a/include/image.h
+++ b/include/image.h
@@ -131,13 +131,6 @@ struct inotify_file_entry {
fown_t fown;
} __packed;
-struct fdinfo_entry {
- u32 fd;
- u8 type;
- u8 flags;
- u32 id;
-} __packed;
-
struct fs_entry {
u32 cwd_id;
u32 root_id;
diff --git a/include/sockets.h b/include/sockets.h
index 267e7e2..9979a76 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -9,7 +9,6 @@
struct fdinfo_list_entry;
struct sk_opts_entry;
-struct fdinfo_entry;
struct cr_options;
struct file_desc;
struct fd_parms;
diff --git a/pipes.c b/pipes.c
index 73fab79..b30ee25 100644
--- a/pipes.c
+++ b/pipes.c
@@ -241,7 +241,7 @@ static int open_pipe(struct file_desc *d)
return tmp;
}
-static int want_transport(struct fdinfo_entry *fe, struct file_desc *d)
+static int want_transport(FdinfoEntry *fe, struct file_desc *d)
{
struct pipe_info *pi;
diff --git a/sk-unix.c b/sk-unix.c
index 749300c..d788518 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -573,7 +573,7 @@ done:
return 0;
}
-static int unixsk_should_open_transport(struct fdinfo_entry *fe,
+static int unixsk_should_open_transport(FdinfoEntry *fe,
struct file_desc *d)
{
struct unix_sk_info *ui;
--
1.7.7.6
More information about the CRIU
mailing list