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

protobuf: Convert itimer_entry to PB format

Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 6b9d3aff
......@@ -51,6 +51,7 @@
#include "protobuf.h"
#include "protobuf/sa.pb-c.h"
#include "protobuf/itimer.pb-c.h"
static struct pstree_item *me;
......@@ -937,7 +938,7 @@ static inline int timeval_valid(struct timeval *tv)
return (tv->tv_sec >= 0) && ((unsigned long)tv->tv_usec < USEC_PER_SEC);
}
static inline int itimer_restore_and_fix(char *n, struct itimer_entry *ie,
static inline int itimer_restore_and_fix(char *n, ItimerEntry *ie,
struct itimerval *val)
{
if (ie->isec == 0 && ie->iusec == 0) {
......@@ -980,23 +981,36 @@ static inline int itimer_restore_and_fix(char *n, struct itimer_entry *ie,
static int prepare_itimers(int pid, struct task_restore_core_args *args)
{
int fd, ret = -1;
struct itimer_entry ie[3];
ItimerEntry *ie;
fd = open_image_ro(CR_FD_ITIMERS, pid);
if (fd < 0)
return fd;
if (read_img_buf(fd, ie, sizeof(ie)) > 0) {
ret = itimer_restore_and_fix("real",
&ie[0], &args->itimers[0]);
if (!ret)
ret = itimer_restore_and_fix("virt",
&ie[1], &args->itimers[1]);
if (!ret)
ret = itimer_restore_and_fix("prof",
&ie[2], &args->itimers[2]);
}
ret = pb_read(fd, &ie, itimer_entry);
if (ret < 0)
goto out;
ret = itimer_restore_and_fix("real", ie, &args->itimers[0]);
itimer_entry__free_unpacked(ie, NULL);
if (ret < 0)
goto out;
ret = pb_read(fd, &ie, itimer_entry);
if (ret < 0)
goto out;
ret = itimer_restore_and_fix("virt", ie, &args->itimers[1]);
itimer_entry__free_unpacked(ie, NULL);
if (ret < 0)
goto out;
ret = pb_read(fd, &ie, itimer_entry);
if (ret < 0)
goto out;
ret = itimer_restore_and_fix("prof", ie, &args->itimers[2]);
itimer_entry__free_unpacked(ie, NULL);
if (ret < 0)
goto out;
out:
close_safe(&fd);
return ret;
}
......
......@@ -36,6 +36,7 @@
#include "protobuf/pipe.pb-c.h"
#include "protobuf/pipe-data.pb-c.h"
#include "protobuf/sa.pb-c.h"
#include "protobuf/itimer.pb-c.h"
#define DEF_PAGES_PER_LINE 6
......@@ -383,7 +384,7 @@ out:
pr_img_tail(CR_FD_SIGACT);
}
static void show_itimer(char *n, struct itimer_entry *ie)
static void show_itimer(char *n, ItimerEntry *ie)
{
pr_msg("%s: int %lu.%lu val %lu.%lu\n", n,
(unsigned long)ie->isec, (unsigned long)ie->iusec,
......@@ -392,15 +393,28 @@ static void show_itimer(char *n, struct itimer_entry *ie)
void show_itimers(int fd, struct cr_options *o)
{
struct itimer_entry ie[3];
ItimerEntry *ie;
int ret;
pr_img_head(CR_FD_ITIMERS);
if (read_img_buf(fd, ie, sizeof(ie)) < 0)
ret = pb_read(fd, &ie, itimer_entry);
if (ret < 0)
goto out;
show_itimer("real", ie);
itimer_entry__free_unpacked(ie, NULL);
show_itimer("real", &ie[0]);
show_itimer("virt", &ie[1]);
show_itimer("prof", &ie[2]);
ret = pb_read(fd, &ie, itimer_entry);
if (ret < 0)
goto out;
show_itimer("virt", ie);
itimer_entry__free_unpacked(ie, NULL);
ret = pb_read(fd, &ie, itimer_entry);
if (ret < 0)
goto out;
show_itimer("prof", ie);
itimer_entry__free_unpacked(ie, NULL);
out:
pr_img_tail(CR_FD_ITIMERS);
}
......
......@@ -201,13 +201,6 @@ struct page_entry {
u8 data[PAGE_IMAGE_SIZE];
} __packed;
struct itimer_entry {
u64 isec;
u64 iusec;
u64 vsec;
u64 vusec;
} __packed;
#define CR_CAP_SIZE 2
struct creds_entry {
......
......@@ -14,6 +14,7 @@
#include "protobuf.h"
#include "protobuf/sa.pb-c.h"
#include "protobuf/itimer.pb-c.h"
#include <string.h>
#include <stdlib.h>
......@@ -460,14 +461,14 @@ int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_f
static int dump_one_timer(struct itimerval *v, int fd)
{
struct itimer_entry ie;
ItimerEntry ie = ITIMER_ENTRY__INIT;
ie.isec = v->it_interval.tv_sec;
ie.iusec = v->it_interval.tv_usec;
ie.vsec = v->it_value.tv_sec;
ie.vusec = v->it_value.tv_sec;
return write_img(fd, &ie);
return pb_write(fd, &ie, itimer_entry);
}
int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_fdset)
......
......@@ -37,6 +37,7 @@ PROTO_FILES += sk-packet.proto
PROTO_FILES += mnt.proto
PROTO_FILES += pipe-data.proto
PROTO_FILES += sa.proto
PROTO_FILES += itimer.proto
HDRS := $(patsubst %.proto,%.pb-c.h,$(PROTO_FILES))
SRCS := $(patsubst %.proto,%.pb-c.c,$(PROTO_FILES))
......
message itimer_entry {
required uint64 isec = 1;
required uint64 iusec = 2;
required uint64 vsec = 3;
required uint64 vusec = 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