[CRIU] [PATCH 07/12] posix-timer: Add dump functionality

Pavel Tikhomirov snorcht at gmail.com
Wed May 29 19:36:16 EDT 2013


Signed-off-by: Pavel Tikhomirov <snorcht at gmail.com>
---
 cr-dump.c                  |   13 ++++++++++
 include/parasite-syscall.h |    3 +++
 parasite-syscall.c         |   62 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)

diff --git a/cr-dump.c b/cr-dump.c
index 6ea17a7..4b3f2da 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1488,6 +1488,19 @@ static int dump_one_task(struct pstree_item *item)
 		goto err_cure;
 	}
 
+	struct proc_posix_timers_stat proc_args;
+	ret = parse_posix_timers(pid, &proc_args);
+	if (ret < 0){
+		pr_err("Can't read posix timers file (pid: %d)\n", pid);
+		goto err_cure;
+	}
+
+	ret = parasite_dump_posix_timers_seized(&proc_args, parasite_ctl, cr_fdset);
+	if (ret) {
+		pr_err("Can't dump posix timers (pid: %d)\n", pid);
+		goto err_cure;
+	}
+
 	ret = dump_task_core_all(parasite_ctl, item->core[0], &pps_buf, &misc, &vmas, cr_fdset);
 	if (ret) {
 		pr_err("Dump core (pid: %d) failed with %d\n", pid, ret);
diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index 4a41228..38bdb31 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -44,6 +44,9 @@ struct list_head;
 extern int parasite_dump_sigacts_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_fdset);
 extern int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_fdset);
 
+struct proc_posix_timers_stat;
+extern int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args, struct parasite_ctl *ctl, struct cr_fdset *cr_fdset);
+
 void *parasite_args_s(struct parasite_ctl *ctl, int args_size);
 int parasite_execute_daemon(unsigned int cmd, struct parasite_ctl *ctl);
 int parasite_send_fd(struct parasite_ctl *ctl, int fd);
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 258be82..ec2cc97 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -8,6 +8,7 @@
 #include "protobuf.h"
 #include "protobuf/sa.pb-c.h"
 #include "protobuf/itimer.pb-c.h"
+#include "protobuf/posix-timer.pb-c.h"
 #include "protobuf/creds.pb-c.h"
 #include "protobuf/core.pb-c.h"
 #include "protobuf/pagemap.pb-c.h"
@@ -27,6 +28,8 @@
 #include "vdso.h"
 #include "restorer.h"
 
+#include "proc_parse.h"
+
 #include <string.h>
 #include <stdlib.h>
 
@@ -604,6 +607,65 @@ int parasite_dump_itimers_seized(struct parasite_ctl *ctl, struct cr_fdset *cr_f
 	return ret;
 }
 
+static int dump_one_posix_timer(struct posix_timer *v, struct proc_posix_timer *vp, int fd)
+{
+	PosixTimerEntry pte = POSIX_TIMER_ENTRY__INIT;
+
+	pte.it_id = vp->it_id;
+	pte.clock_id = vp->clock_id;
+	pte.si_signo = vp->si_signo;
+	pte.it_sigev_notify = vp->it_sigev_notify;
+	pte.sival_ptr = vp->sival_ptr.i; //pointer to int through union
+
+	pte.overrun = v->overrun;
+
+	pte.isec = v->val.it_interval.tv_sec;
+	pte.insec = v->val.it_interval.tv_nsec;
+	pte.vsec = v->val.it_value.tv_sec;
+	pte.vnsec = v->val.it_value.tv_nsec;
+
+	return pb_write_one(fd, &pte, PB_POSIX_TIMERS);
+}
+
+int parasite_dump_posix_timers_seized(struct proc_posix_timers_stat *proc_args, struct parasite_ctl *ctl, struct cr_fdset *cr_fdset)
+{
+	struct parasite_dump_posix_timers_args * args;
+	struct proc_posix_timer *temp;
+	int i, fd;
+	int ret = 0;
+
+	args = parasite_args_s(ctl, sizeof(int) + sizeof(struct posix_timer) * proc_args->timer_n);
+	args->timer_n = proc_args->timer_n;
+
+	i = 0;
+	list_for_each_entry(temp, &proc_args->timers, list) {
+		args->timer[i].it_id = temp->it_id;
+		i++;
+	}
+
+	ret = parasite_execute_daemon(PARASITE_CMD_DUMP_POSIX_TIMERS, ctl);
+	if (ret < 0)
+		goto end_posix;
+
+	fd = fdset_fd(cr_fdset, CR_FD_POSIX_TIMERS);
+
+	i = 0;
+	list_for_each_entry(temp, &proc_args->timers, list) {
+		ret = dump_one_posix_timer(&args->timer[i], temp, fd);
+		i++;
+		if (ret)
+			goto end_posix;
+	}
+
+end_posix:
+	while (!list_empty(&proc_args->timers)) {
+		temp = list_first_entry(&proc_args->timers, struct proc_posix_timer, list);
+		list_del(&temp->list);
+		xfree(temp);
+	}
+	return ret;
+}
+
 int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_misc *misc)
 {
 	struct parasite_dump_misc *ma;
-- 
1.7.9.5



More information about the CRIU mailing list