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

protobuf: Convert struct fs_entry to PB engine

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 28638b61
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/fdinfo.pb-c.h" #include "protobuf/fdinfo.pb-c.h"
#include "protobuf/fs.pb-c.h"
#ifndef CONFIG_X86_64 #ifndef CONFIG_X86_64
# error No x86-32 support yet # error No x86-32 support yet
...@@ -344,7 +345,7 @@ err: ...@@ -344,7 +345,7 @@ err:
static int dump_task_fs(pid_t pid, struct cr_fdset *fdset) static int dump_task_fs(pid_t pid, struct cr_fdset *fdset)
{ {
struct fd_parms p = { .fd = FD_DESC_INVALID, }; struct fd_parms p = { .fd = FD_DESC_INVALID, };
struct fs_entry fe; FsEntry fe = FS_ENTRY__INIT;
int fd, ret; int fd, ret;
fd = open_proc(pid, "cwd"); fd = open_proc(pid, "cwd");
...@@ -384,7 +385,7 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset) ...@@ -384,7 +385,7 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset)
pr_info("Dumping task cwd id %#x root id %#x\n", pr_info("Dumping task cwd id %#x root id %#x\n",
fe.cwd_id, fe.root_id); fe.cwd_id, fe.root_id);
return write_img(fdset_fd(fdset, CR_FD_FS), &fe); return pb_write(fdset_fd(fdset, CR_FD_FS), &fe, fs_entry);
} }
static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd, static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "protobuf/fifo.pb-c.h" #include "protobuf/fifo.pb-c.h"
#include "protobuf/remap-file-path.pb-c.h" #include "protobuf/remap-file-path.pb-c.h"
#include "protobuf/fown.pb-c.h" #include "protobuf/fown.pb-c.h"
#include "protobuf/fs.pb-c.h"
#define DEF_PAGES_PER_LINE 6 #define DEF_PAGES_PER_LINE 6
...@@ -243,13 +244,14 @@ void show_fifo(int fd, struct cr_options *o) ...@@ -243,13 +244,14 @@ void show_fifo(int fd, struct cr_options *o)
void show_fs(int fd_fs, struct cr_options *o) void show_fs(int fd_fs, struct cr_options *o)
{ {
struct fs_entry fe; FsEntry *fe;
pr_img_head(CR_FD_FS); pr_img_head(CR_FD_FS);
if (read_img(fd_fs, &fe) > 0) { if (pb_read_eof(fd_fs, &fe, fs_entry) > 0) {
pr_msg("CWD : %#x\n", fe.cwd_id); pr_msg("CWD : %#x\n", fe->cwd_id);
pr_msg("ROOT: %#x\n", fe.root_id); pr_msg("ROOT: %#x\n", fe->root_id);
fs_entry__free_unpacked(fe, NULL);
} }
pr_img_tail(CR_FD_FS); pr_img_tail(CR_FD_FS);
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "pstree.h" #include "pstree.h"
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/fs.pb-c.h"
static struct fdinfo_list_entry *fdinfo_list; static struct fdinfo_list_entry *fdinfo_list;
static int nr_fdinfo_list; static int nr_fdinfo_list;
...@@ -560,23 +561,23 @@ done: ...@@ -560,23 +561,23 @@ done:
int prepare_fs(int pid) int prepare_fs(int pid)
{ {
int ifd, cwd; int ifd, cwd, ret = -1;
struct fs_entry fe; FsEntry *fe;
ifd = open_image_ro(CR_FD_FS, pid); ifd = open_image_ro(CR_FD_FS, pid);
if (ifd < 0) if (ifd < 0)
return -1; return -1;
if (read_img(ifd, &fe) < 0) if (pb_read(ifd, &fe, fs_entry) < 0)
return -1; return -1;
cwd = open_reg_by_id(fe.cwd_id); cwd = open_reg_by_id(fe->cwd_id);
if (cwd < 0) if (cwd < 0)
return -1; goto err;
if (fchdir(cwd) < 0) { if (fchdir(cwd) < 0) {
pr_perror("Can't change root"); pr_perror("Can't change root");
return -1; goto err;
} }
close(cwd); close(cwd);
...@@ -591,7 +592,10 @@ int prepare_fs(int pid) ...@@ -591,7 +592,10 @@ int prepare_fs(int pid)
* by path thus exposing this (yet unclean) logic here. * by path thus exposing this (yet unclean) logic here.
*/ */
return 0; ret = 0;
err:
fs_entry__free_unpacked(fe, NULL);
return ret;
} }
int get_filemap_fd(int pid, struct vma_entry *vma_entry) int get_filemap_fd(int pid, struct vma_entry *vma_entry)
......
...@@ -75,11 +75,6 @@ typedef struct { ...@@ -75,11 +75,6 @@ typedef struct {
*/ */
#define REMAP_GHOST (1 << 31) #define REMAP_GHOST (1 << 31)
struct fs_entry {
u32 cwd_id;
u32 root_id;
} __packed;
struct pstree_entry { struct pstree_entry {
u32 pid; u32 pid;
u32 ppid; u32 ppid;
......
...@@ -29,6 +29,7 @@ PROTO_FILES += eventfd.proto ...@@ -29,6 +29,7 @@ PROTO_FILES += eventfd.proto
PROTO_FILES += eventpoll.proto PROTO_FILES += eventpoll.proto
PROTO_FILES += fh.proto PROTO_FILES += fh.proto
PROTO_FILES += inotify.proto PROTO_FILES += inotify.proto
PROTO_FILES += fs.proto
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES)) HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES)) SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
......
message fs_entry {
required uint32 cwd_id = 1;
required uint32 root_id = 2;
}
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