Commit 8041eac0 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

protobuf: Use RegFileEntry instead of reg_file_entry structure v3

This patch switches reg_file_entry structure with RegFileEntry
protobuf entry. Note that there a few nits remains

 - old fown_t structure doesn't scale well with FownEntry from
   RegFileEntry, so to not mess with rest of crtools code
   I've added a couple of opencoded copy operands, will clean
   this aspect up once rest of code is converted

 - the "show" procedure doesn't print fown for same reason

v2:
 - rename fown_t to fown_entry in .proto
v3:
 - don't print nil symbol on show
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a1fe3caf
......@@ -26,6 +26,7 @@
#include "protobuf.h"
#include "protobuf/fdinfo.pb-c.h"
#include "protobuf/regfile.pb-c.h"
#define DEF_PAGES_PER_LINE 6
......@@ -104,34 +105,24 @@ void show_fown_cont(fown_t *fown)
void show_reg_files(int fd_reg_files, struct cr_options *o)
{
struct reg_file_entry rfe;
local_buf[0] = 0;
pr_img_head(CR_FD_REG_FILES);
while (1) {
RegFileEntry *rfe;
int ret;
ret = read_img_eof(fd_reg_files, &rfe);
ret = pb_read_eof(fd_reg_files, &rfe, reg_file_entry);
if (ret <= 0)
goto out;
pr_msg("id: 0x%8x flags: 0x%4x pos: 0x%lx ", rfe.id, rfe.flags, rfe.pos);
show_fown_cont(&rfe.fown);
if (rfe.len) {
int ret = read(fd_reg_files, local_buf, rfe.len);
if (ret != rfe.len) {
pr_perror("Can't read %d bytes", rfe.len);
goto out;
}
local_buf[rfe.len] = 0;
pr_msg(" --> %s", local_buf);
}
break;
pr_msg("id: 0x%8x flags: 0x%4x pos: 0x%lx",
rfe->id, rfe->flags, rfe->pos);
if (rfe->name)
pr_msg(" --> %s", rfe->name);
pr_msg("\n");
reg_file_entry__free_unpacked(rfe, NULL);
}
out:
pr_img_tail(CR_FD_REG_FILES);
}
......
......@@ -12,6 +12,8 @@
#include "fifo.h"
#include "protobuf/regfile.pb-c.h"
/*
* FIFO checkpoint and restore is done in a bit unusual manner.
* We use files-reg.c engine to save fifo path and flags,
......@@ -89,7 +91,7 @@ static int do_open_fifo(struct reg_file_info *rfi, void *arg)
return -1;
}
new_fifo = open(rfi->path, rfi->rfe.flags);
new_fifo = open(rfi->path, rfi->rfe->flags);
if (new_fifo < 0) {
pr_perror("Can't open fifo %#x [%s]", info->fe->id, rfi->path);
goto out;
......
......@@ -12,6 +12,9 @@
#include "list.h"
#include "util.h"
#include "protobuf.h"
#include "protobuf/regfile.pb-c.h"
#include "files-reg.h"
/*
......@@ -162,7 +165,7 @@ static int collect_remaps(void)
rfe.remap_id &= ~REMAP_GHOST;
rfi = container_of(fdesc, struct reg_file_info, d);
pr_info("Configuring remap %#x -> %#x\n", rfi->rfe.id, rfe.remap_id);
pr_info("Configuring remap %#x -> %#x\n", rfi->rfe->id, rfe.remap_id);
ret = open_remap_ghost(rfi, &rfe);
if (ret < 0)
break;
......@@ -291,13 +294,14 @@ static int check_path_remap(char *path, const struct stat *ost, int lfd, u32 id)
return 0;
}
int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
{
char fd_str[128];
char path[PATH_MAX];
int len, rfd;
struct reg_file_entry rfe;
RegFileEntry rfe = REG_FILE_ENTRY__INIT;
FownEntry fown = FOWN_ENTRY__INIT;
snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", lfd);
len = readlink(fd_str, path, sizeof(path) - 1);
......@@ -313,20 +317,21 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
if (check_path_remap(path, &p->stat, lfd, id))
return -1;
rfe.len = len;
rfe.flags = p->flags;
rfe.pos = p->pos;
rfe.id = id;
rfe.fown = p->fown;
fown.uid = p->fown.uid;
fown.euid = p->fown.euid;
fown.signum = p->fown.signum;
fown.pid_type = p->fown.pid_type;
fown.pid = p->fown.pid;
rfd = fdset_fd(glob_fdset, CR_FD_REG_FILES);
rfe.id = id;
rfe.flags = p->flags;
rfe.pos = p->pos;
rfe.fown = &fown;
rfe.name = path;
if (write_img(rfd, &rfe))
return -1;
if (write_img_buf(rfd, path, len))
return -1;
rfd = fdset_fd(glob_fdset, CR_FD_REG_FILES);
return 0;
return pb_write(rfd, &rfe, reg_file_entry);
}
static const struct fdtype_ops regfile_ops = {
......@@ -345,6 +350,7 @@ static int open_path(struct file_desc *d,
int(*open_cb)(struct reg_file_info *, void *), void *arg)
{
struct reg_file_info *rfi;
fown_t fown;
int tmp;
rfi = container_of(d, struct reg_file_info, d);
......@@ -365,7 +371,13 @@ static int open_path(struct file_desc *d,
if (rfi->remap_path)
unlink(rfi->path);
if (restore_fown(tmp, &rfi->rfe.fown))
fown.uid = rfi->rfe->fown->uid;
fown.euid = rfi->rfe->fown->uid;
fown.signum = rfi->rfe->fown->signum;
fown.pid_type = rfi->rfe->fown->pid_type;
fown.pid = rfi->rfe->fown->pid;
if (restore_fown(tmp, &fown))
return -1;
return tmp;
......@@ -388,13 +400,13 @@ static int do_open_reg(struct reg_file_info *rfi, void *arg)
{
int fd;
fd = open(rfi->path, rfi->rfe.flags);
fd = open(rfi->path, rfi->rfe->flags);
if (fd < 0) {
pr_perror("Can't open file on restore");
return fd;
}
if (lseek(fd, rfi->rfe.pos, SEEK_SET) < 0) {
if (lseek(fd, rfi->rfe->pos, SEEK_SET) < 0) {
pr_perror("Can't restore file pos");
return -1;
}
......@@ -427,24 +439,26 @@ int collect_reg_files(void)
return -1;
while (1) {
RegFileEntry *rfe;
rfi = xmalloc(sizeof(*rfi));
ret = -1;
if (rfi == NULL)
break;
rfi->path = NULL;
ret = read_img_eof(fd, &rfi->rfe);
ret = pb_read_eof(fd, &rfe, reg_file_entry);
if (ret <= 0)
break;
ret = read_img_str(fd, &rfi->path, rfi->rfe.len);
if (ret < 0)
break;
rfi->rfe = rfe;
rfi->path = rfe->name;
rfi->remap_path = NULL;
pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe.id);
file_desc_add(&rfi->d, rfi->rfe.id, &reg_desc_ops);
pr_info("Collected [%s] ID %#x\n", rfi->path, rfi->rfe->id);
file_desc_add(&rfi->d, rfi->rfe->id, &reg_desc_ops);
}
if (rfi) {
......
......@@ -5,14 +5,14 @@
#include "files.h"
#include "image.h"
#include "../protobuf/regfile.pb-c.h"
struct cr_fdset;
struct fd_parms;
struct reg_file_info {
struct file_desc d;
struct reg_file_entry rfe;
RegFileEntry *rfe;
char *remap_path;
char *path;
};
......
......@@ -69,15 +69,6 @@ typedef struct {
u32 pid;
} __packed fown_t;
struct reg_file_entry {
u32 id;
u16 flags;
u16 len;
u64 pos;
fown_t fown;
u8 name[0];
} __packed;
struct remap_file_path_entry {
u32 orig_id;
u32 remap_id;
......
......@@ -20,6 +20,8 @@ CFLAGS += $(WARNINGS) $(DEFINES)
LIBRARY := protobuf-lib.o
PROTO_FILES += fdinfo.proto
PROTO_FILES += fown.proto
PROTO_FILES += regfile.proto
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
......
message fown_entry {
required uint32 uid = 1;
required uint32 euid = 2;
required uint32 signum = 3;
required uint32 pid_type = 4;
required uint32 pid = 5;
}
import "fown.proto";
message reg_file_entry {
required uint32 id = 1;
required uint32 flags = 2;
required uint64 pos = 3;
required fown_entry fown = 5;
required string name = 6;
}
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