Commit 28638b61 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

protobuf: Convert inotify data to protobuf engine

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent fa923ee1
......@@ -75,22 +75,6 @@ typedef struct {
*/
#define REMAP_GHOST (1 << 31)
struct inotify_wd_entry {
u32 id;
u64 i_ino;
u32 mask;
u32 ignored_mask;
u32 s_dev;
u32 wd;
fh_t f_handle;
} __packed;
struct inotify_file_entry {
u32 id;
u16 flags;
fown_t fown;
} __packed;
struct fs_entry {
u32 cwd_id;
u32 root_id;
......
......@@ -8,6 +8,7 @@
#include "../protobuf/eventfd.pb-c.h"
#include "../protobuf/eventpoll.pb-c.h"
#include "../protobuf/inotify.pb-c.h"
#define PROC_TASK_COMM_LEN 32
#define PROC_TASK_COMM_LEN_FMT "(%31s"
......@@ -123,7 +124,7 @@ extern int parse_pid_status(pid_t pid, struct proc_status_creds *);
union fdinfo_entries {
EventfdFileEntry efd;
EventpollTfdEntry epl;
struct inotify_wd_entry ify;
InotifyWdEntry ify;
};
extern int parse_fdinfo(int fd, int type,
......
......@@ -34,14 +34,17 @@
#include "list.h"
#include "lock.h"
#include "protobuf.h"
#include "protobuf/inotify.pb-c.h"
struct inotify_wd_info {
struct list_head list;
struct inotify_wd_entry *iwe;
InotifyWdEntry *iwe;
};
struct inotify_file_info {
struct list_head list;
struct inotify_file_entry *ife;
InotifyFileEntry *ife;
struct list_head marks;
struct file_desc d;
};
......@@ -56,23 +59,31 @@ int is_inotify_link(int lfd)
void show_inotify_wd(int fd_inotify_wd, struct cr_options *o)
{
struct inotify_wd_entry e;
InotifyWdEntry *e;
pr_img_head(CR_FD_INOTIFY_WD);
while (1) {
int ret;
ret = read_img_eof(fd_inotify_wd, &e);
ret = pb_read_eof(fd_inotify_wd, &e, inotify_wd_entry);
if (ret <= 0)
goto out;
if (e->f_handle->n_handle < 2) {
pr_err("Corrupted image n_handle = %d while %d expected\n",
(int)e->f_handle->n_handle, FH_ENTRY_SIZES__min_entries);
goto out;
}
pr_msg("inotify-wd: id 0x%08x 0x%08x s_dev 0x%08x i_ino 0x%016lx "
" mask 0x%08x ignored_mask 0x%08x "
"[fhandle] 0x%08x 0x%08x 0x%016lx:0x%016lx ...\n",
e.id, e.wd, e.s_dev, e.i_ino, e.mask, e.ignored_mask,
e.f_handle.bytes, e.f_handle.type,
e.f_handle.__handle[0],
e.f_handle.__handle[1]);
"[fhandle] bytes 0x%08x type 0x%08x "
"handle 0x%016lx:0x%016lx\n",
e->id, e->wd, e->s_dev, e->i_ino, e->mask, e->ignored_mask,
e->f_handle->bytes, e->f_handle->type,
e->f_handle->handle[0], e->f_handle->handle[1]);
inotify_wd_entry__free_unpacked(e, NULL);
}
out:
pr_img_tail(CR_FD_INOTIFY_WD);
......@@ -80,19 +91,21 @@ out:
void show_inotify(int fd_inotify, struct cr_options *o)
{
struct inotify_file_entry e;
InotifyFileEntry *e;
pr_img_head(CR_FD_INOTIFY);
while (1) {
int ret;
ret = read_img_eof(fd_inotify, &e);
ret = pb_read_eof(fd_inotify, &e, inotify_file_entry);
if (ret <= 0)
goto out;
pr_msg("inotify: id 0x%08x flags 0x%08x\n\t", e.id, e.flags);
show_fown_cont(&e.fown);
pr_msg("inotify: id 0x%08x flags 0x%08x\n\t", e->id, e->flags);
pb_show_fown_cont(e->fown);
pr_msg("\n");
inotify_file_entry__free_unpacked(e, NULL);
}
out:
pr_img_tail(CR_FD_INOTIFY);
......@@ -100,27 +113,30 @@ out:
static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
{
struct inotify_wd_entry *we = &e->ify;
InotifyWdEntry *we = &e->ify;
we->id = *(u32 *)arg;
pr_info("inotify wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16lx mask 0x%08x\n",
we->wd, we->s_dev, we->i_ino, we->mask);
pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016lx:0x%016lx\n",
we->f_handle.bytes, we->f_handle.type,
we->f_handle.__handle[0], we->f_handle.__handle[1]);
return write_img(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we);
we->f_handle->bytes, we->f_handle->type,
we->f_handle->handle[0], we->f_handle->handle[1]);
return pb_write(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we, inotify_wd_entry);
}
static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
{
struct inotify_file_entry ie;
InotifyFileEntry ie = INOTIFY_FILE_ENTRY__INIT;
FownEntry fown;
pb_prep_fown(&fown, &p->fown);
ie.id = id;
ie.flags = p->flags;
ie.fown = p->fown;
ie.fown = &fown;
pr_info("inotify: id 0x%08x flags 0x%08x\n", ie.id, ie.flags);
if (write_img(fdset_fd(glob_fdset, CR_FD_INOTIFY), &ie))
if (pb_write(fdset_fd(glob_fdset, CR_FD_INOTIFY), &ie, inotify_file_entry))
return -1;
return parse_fdinfo(lfd, FDINFO_INOTIFY, dump_inotify_entry, &id);
......@@ -137,11 +153,20 @@ int dump_inotify(struct fd_parms *p, int lfd, const struct cr_fdset *set)
return do_dump_gen_file(p, lfd, &inotify_ops, set);
}
static int restore_one_inotify(int inotify_fd, struct inotify_wd_entry *iwe)
static int restore_one_inotify(int inotify_fd, InotifyWdEntry *iwe)
{
char path[32];
int mntfd, ret = -1;
int wd, target;
fh_t handle = { };
/* syscall waits for strict structure here */
handle.type = iwe->f_handle->type;
handle.bytes = iwe->f_handle->bytes;
memcpy(handle.__handle, iwe->f_handle->handle,
min(pb_repeated_size(iwe->f_handle, handle),
sizeof(handle.__handle)));
mntfd = open_mount(iwe->s_dev);
if (mntfd < 0) {
......@@ -149,7 +174,7 @@ static int restore_one_inotify(int inotify_fd, struct inotify_wd_entry *iwe)
return -1;
}
target = sys_open_by_handle_at(mntfd, (void *)&iwe->f_handle, 0);
target = sys_open_by_handle_at(mntfd, (void *)&handle, 0);
if (target < 0) {
pr_perror("Can't open file handle for 0x%08x:0x%016lx",
iwe->s_dev, iwe->i_ino);
......@@ -210,7 +235,7 @@ static int open_inotify_fd(struct file_desc *d)
}
}
if (restore_fown(tmp, &info->ife->fown))
if (pb_restore_fown(tmp, info->ife->fown))
close_safe(&tmp);
return tmp;
......@@ -250,11 +275,7 @@ int collect_inotify(void)
if (!info)
return -1;
info->ife = xmalloc(sizeof(*info->ife));
if (!info->ife)
return -1;
ret = read_img_eof(image_fd, info->ife);
ret = pb_read_eof(image_fd, &info->ife, inotify_file_entry);
if (ret < 0)
goto err;
else if (!ret)
......@@ -273,14 +294,12 @@ int collect_inotify(void)
goto err;
while (1) {
ret = -1;
mark = xmalloc(sizeof(*mark));
if (!mark)
goto err;
mark->iwe = xmalloc(sizeof(*mark->iwe));
if (!mark->iwe)
goto err;
ret = read_img_eof(image_wd, mark->iwe);
ret = pb_read_eof(image_wd, &mark->iwe, inotify_wd_entry);
if (ret < 0)
goto err;
else if (!ret)
......
......@@ -15,6 +15,7 @@
#include "crtools.h"
#include "proc_parse.h"
#include "protobuf.h"
#include <stdlib.h>
......@@ -684,18 +685,18 @@ static char nybble(const char n)
return 0;
}
static void parse_fhandle_encoded(char *tok, fh_t *f)
static void parse_fhandle_encoded(char *tok, FhEntry *fh)
{
char *d = (char *)f->__handle;
char *d = (char *)fh->handle;
int i = 0;
memzero(d, sizeof(f->__handle));
memzero(d, pb_repeated_size(fh, handle));
while (*tok == ' ')
tok++;
while (*tok) {
if (i >= sizeof(f->__handle))
if (i >= pb_repeated_size(fh, handle))
break;
d[i++] = (nybble(tok[0]) << 4) | nybble(tok[1]);
if (tok[1])
......@@ -756,8 +757,12 @@ int parse_fdinfo(int fd, int type,
continue;
}
if (fdinfo_field(str, "inotify wd")) {
FhEntry f_handle = FH_ENTRY__INIT;
int hoff;
inotify_wd_entry__init(&entry.ify);
entry.ify.f_handle = &f_handle;
if (type != FDINFO_INOTIFY)
goto parse_err;
ret = sscanf(str,
......@@ -767,13 +772,22 @@ int parse_fdinfo(int fd, int type,
"f_handle: %n",
&entry.ify.wd, &entry.ify.i_ino, &entry.ify.s_dev,
&entry.ify.mask, &entry.ify.ignored_mask,
&entry.ify.f_handle.bytes, &entry.ify.f_handle.type,
&entry.ify.f_handle->bytes, &entry.ify.f_handle->type,
&hoff);
if (ret != 7)
goto parse_err;
parse_fhandle_encoded(str + hoff, &entry.ify.f_handle);
f_handle.n_handle = FH_ENTRY_SIZES__min_entries;
f_handle.handle = xmalloc(pb_repeated_size(&f_handle, handle));
if (!f_handle.handle)
return -1;
parse_fhandle_encoded(str + hoff, entry.ify.f_handle);
ret = cb(&entry, arg);
xfree(f_handle.handle);
if (ret)
return ret;
continue;
......
......@@ -27,6 +27,8 @@ PROTO_FILES += fifo.proto
PROTO_FILES += remap-file-path.proto
PROTO_FILES += eventfd.proto
PROTO_FILES += eventpoll.proto
PROTO_FILES += fh.proto
PROTO_FILES += inotify.proto
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
......
enum fh_entry_sizes {
min_entries = 16;
}
message fh_entry {
required uint32 bytes = 1;
required uint32 type = 2;
/* The minimum is fh_n_handle repetitions */
repeated uint64 handle = 3;
}
import "fh.proto";
import "fown.proto";
message inotify_wd_entry {
required uint32 id = 1;
required uint64 i_ino = 2;
required uint32 mask = 3;
required uint32 ignored_mask = 4;
required uint32 s_dev = 5;
required uint32 wd = 6;
required fh_entry f_handle = 7;
}
message inotify_file_entry {
required uint32 id = 1;
required uint32 flags = 2;
required fown_entry fown = 4;
}
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