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

protobuf: Use GhostFileEntry instead of struct ghost_file_entry

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 8041eac0
......@@ -27,6 +27,7 @@
#include "protobuf.h"
#include "protobuf/fdinfo.pb-c.h"
#include "protobuf/regfile.pb-c.h"
#include "protobuf/ghost-file.pb-c.h"
#define DEF_PAGES_PER_LINE 6
......@@ -157,11 +158,13 @@ void show_remap_files(int fd, struct cr_options *o)
void show_ghost_file(int fd, struct cr_options *o)
{
struct ghost_file_entry gfe;
GhostFileEntry *gfe;
pr_img_head(CR_FD_GHOST_FILE);
if (read_img(fd, &gfe) > 0)
pr_msg("uid %u god %u mode %#x\n", gfe.uid, gfe.gid, gfe.mode);
if (pb_read_eof(fd, &gfe, ghost_file_entry) > 0) {
pr_msg("uid %u god %u mode %#x\n", gfe->uid, gfe->gid, gfe->mode);
ghost_file_entry__free_unpacked(gfe, NULL);
}
pr_img_tail(CR_FD_GHOST_FILE);
}
......
......@@ -60,7 +60,7 @@ static int open_remap_ghost(struct reg_file_info *rfi,
struct remap_file_path_entry *rfe)
{
struct ghost_file *gf;
struct ghost_file_entry gfe;
GhostFileEntry *gfe = NULL;
int gfd, ifd, ghost_flags;
list_for_each_entry(gf, &ghost_files, list)
......@@ -86,13 +86,13 @@ static int open_remap_ghost(struct reg_file_info *rfi,
if (ifd < 0)
goto err;
if (read_img(ifd, &gfe) < 0)
if (pb_read(ifd, &gfe, ghost_file_entry) < 0)
goto err;
snprintf(gf->path, PATH_MAX, "%s.cr.%x.ghost", rfi->path, rfe->remap_id);
if (S_ISFIFO(gfe.mode)) {
if (mknod(gf->path, gfe.mode, 0)) {
if (S_ISFIFO(gfe->mode)) {
if (mknod(gf->path, gfe->mode, 0)) {
pr_perror("Can't create node for ghost file\n");
goto err;
}
......@@ -100,22 +100,23 @@ static int open_remap_ghost(struct reg_file_info *rfi,
} else
ghost_flags = O_WRONLY | O_CREAT | O_EXCL;
gfd = open(gf->path, ghost_flags, gfe.mode);
gfd = open(gf->path, ghost_flags, gfe->mode);
if (gfd < 0) {
pr_perror("Can't open ghost file");
goto err;
}
if (fchown(gfd, gfe.uid, gfe.gid) < 0) {
if (fchown(gfd, gfe->uid, gfe->gid) < 0) {
pr_perror("Can't reset user/group on ghost %#x\n", rfe->remap_id);
goto err;
}
if (S_ISREG(gfe.mode)) {
if (S_ISREG(gfe->mode)) {
if (copy_file(ifd, gfd, 0) < 0)
goto err;
}
ghost_file_entry__free_unpacked(gfe, NULL);
close(ifd);
close(gfd);
......@@ -126,6 +127,8 @@ gf_found:
return 0;
err:
if (gfe)
ghost_file_entry__free_unpacked(gfe, NULL);
xfree(gf->path);
xfree(gf);
return -1;
......@@ -178,7 +181,7 @@ static int collect_remaps(void)
static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
{
int img, fd;
struct ghost_file_entry gfe;
GhostFileEntry gfe = GHOST_FILE_ENTRY__INIT;
char lpath[32];
pr_info("Dumping ghost file contents (id %#x)\n", id);
......@@ -191,7 +194,7 @@ static int dump_ghost_file(int _fd, u32 id, const struct stat *st)
gfe.gid = st->st_gid;
gfe.mode = st->st_mode;
if (write_img(img, &gfe))
if (pb_write(img, &gfe, ghost_file_entry))
return -1;
if (S_ISREG(st->st_mode)) {
......
......@@ -6,6 +6,7 @@
#include "image.h"
#include "../protobuf/regfile.pb-c.h"
#include "../protobuf/ghost-file.pb-c.h"
struct cr_fdset;
struct fd_parms;
......
......@@ -80,12 +80,6 @@ struct remap_file_path_entry {
*/
#define REMAP_GHOST (1 << 31)
struct ghost_file_entry {
u32 uid;
u32 gid;
u32 mode;
} __packed;
struct eventfd_file_entry {
u32 id;
u16 flags;
......
......@@ -22,6 +22,7 @@ LIBRARY := protobuf-lib.o
PROTO_FILES += fdinfo.proto
PROTO_FILES += fown.proto
PROTO_FILES += regfile.proto
PROTO_FILES += ghost-file.proto
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
......
message ghost_file_entry {
required uint32 uid = 1;
required uint32 gid = 2;
required uint32 mode = 3;
}
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