Commit 35e560de authored by Pavel Emelyanov's avatar Pavel Emelyanov

timers: Reshuffle new and legacy restoration code

Make explicit checks and helpers for legacy images.
This should facilitate its removal some day in the
future.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 87da9b83
...@@ -1733,21 +1733,15 @@ static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val) ...@@ -1733,21 +1733,15 @@ static inline int decode_itimer(char *n, ItimerEntry *ie, struct itimerval *val)
return 0; return 0;
} }
static int prepare_itimers(int pid, CoreEntry *core, struct task_restore_args *args) /*
* Legacy itimers restore from CR_FD_ITIMERS
*/
static int prepare_itimers_from_fd(int pid, struct task_restore_args *args)
{ {
int fd, ret = -1; int fd, ret = -1;
ItimerEntry *ie; ItimerEntry *ie;
if (core->tc->timers) {
TaskTimersEntry *tte = core->tc->timers;
ret = decode_itimer("real", tte->real, &args->itimers[0]);
ret |= decode_itimer("virt", tte->virt, &args->itimers[1]);
ret |= decode_itimer("prof", tte->prof, &args->itimers[2]);
return ret;
}
fd = open_image(CR_FD_ITIMERS, O_RSTR, pid); fd = open_image(CR_FD_ITIMERS, O_RSTR, pid);
if (fd < 0) if (fd < 0)
return fd; return fd;
...@@ -1780,6 +1774,21 @@ out: ...@@ -1780,6 +1774,21 @@ out:
return ret; return ret;
} }
static int prepare_itimers(int pid, CoreEntry *core, struct task_restore_args *args)
{
int ret = 0;
TaskTimersEntry *tte = core->tc->timers;
if (!tte)
return prepare_itimers_from_fd(pid, args);
ret |= decode_itimer("real", tte->real, &args->itimers[0]);
ret |= decode_itimer("virt", tte->virt, &args->itimers[1]);
ret |= decode_itimer("prof", tte->prof, &args->itimers[2]);
return ret;
}
static inline int timespec_valid(struct timespec *ts) static inline int timespec_valid(struct timespec *ts)
{ {
return (ts->tv_sec >= 0) && ((unsigned long)ts->tv_nsec < NSEC_PER_SEC); return (ts->tv_sec >= 0) && ((unsigned long)ts->tv_nsec < NSEC_PER_SEC);
...@@ -1829,31 +1838,31 @@ static int cmp_posix_timer_proc_id(const void *p1, const void *p2) ...@@ -1829,31 +1838,31 @@ static int cmp_posix_timer_proc_id(const void *p1, const void *p2)
static unsigned long posix_timers_cpos; static unsigned long posix_timers_cpos;
static unsigned int posix_timers_nr; static unsigned int posix_timers_nr;
static int prepare_posix_timers(int pid, CoreEntry *core) static void sort_posix_timers(void)
{ {
int fd = -1; /*
int ret = -1; * This is required for restorer's create_posix_timers(),
struct restore_posix_timer *t; * it will probe them one-by-one for the desired ID, since
* kernel doesn't provide another API for timer creation
posix_timers_cpos = rst_mem_cpos(RM_PRIVATE); * with given ID.
*/
if (core->tc->timers) {
int i;
TaskTimersEntry *tte = core->tc->timers;
posix_timers_nr = tte->n_posix; if (posix_timers_nr > 0)
for (i = 0; i < posix_timers_nr; i++) { qsort(rst_mem_remap_ptr(posix_timers_cpos, RM_PRIVATE),
t = rst_mem_alloc(sizeof(struct restore_posix_timer), RM_PRIVATE); posix_timers_nr,
if (!t) sizeof(struct restore_posix_timer),
goto out; cmp_posix_timer_proc_id);
}
if (decode_posix_timer(tte->posix[i], t)) /*
goto out; * Legacy posix timers restoration from CR_FD_POSIX_TIMERS
} */
ret = 0; static int prepare_posix_timers_from_fd(int pid)
goto out; {
} int fd = -1;
int ret = -1;
struct restore_posix_timer *t;
fd = open_image(CR_FD_POSIX_TIMERS, O_RSTR, pid); fd = open_image(CR_FD_POSIX_TIMERS, O_RSTR, pid);
if (fd < 0) { if (fd < 0) {
...@@ -1883,13 +1892,36 @@ static int prepare_posix_timers(int pid, CoreEntry *core) ...@@ -1883,13 +1892,36 @@ static int prepare_posix_timers(int pid, CoreEntry *core)
} }
close_safe(&fd); close_safe(&fd);
out: if (!ret)
if (posix_timers_nr > 0) sort_posix_timers();
qsort(rst_mem_remap_ptr(posix_timers_cpos, RM_PRIVATE),
posix_timers_nr, return ret;
sizeof(struct restore_posix_timer), }
cmp_posix_timer_proc_id);
static int prepare_posix_timers(int pid, CoreEntry *core)
{
int i, ret = -1;
TaskTimersEntry *tte = core->tc->timers;
struct restore_posix_timer *t;
posix_timers_cpos = rst_mem_cpos(RM_PRIVATE);
if (!tte)
return prepare_posix_timers_from_fd(pid);
posix_timers_nr = tte->n_posix;
for (i = 0; i < posix_timers_nr; i++) {
t = rst_mem_alloc(sizeof(struct restore_posix_timer), RM_PRIVATE);
if (!t)
goto out;
if (decode_posix_timer(tte->posix[i], t))
goto out;
}
ret = 0;
sort_posix_timers();
out:
return ret; return ret;
} }
......
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