[CRIU] [PATCH v3 1/3] criu: dump loginuid & oom_score_adj values
Dmitry Safonov
dsafonov at odin.com
Tue Dec 8 07:11:55 PST 2015
https://jira.sw.ru/browse/PSBM-41993
Signed-off-by: Dmitry Safonov <dsafonov at odin.com>
---
cr-dump.c | 32 ++++++++++++++++++++++++++++++++
include/proc_parse.h | 2 ++
proc_parse.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
protobuf/core.proto | 5 +++++
4 files changed, 91 insertions(+)
diff --git a/cr-dump.c b/cr-dump.c
index 5cc375d..e76071c 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -323,6 +323,34 @@ static int dump_task_rlimits(int pid, TaskRlimitsEntry *rls)
return 0;
}
+static int dump_pid_misc(pid_t pid, TaskCoreEntry *tc)
+{
+ int ret;
+
+ pr_info("dumping /proc/%d/{oom_score_adj,loginuid}\n", pid);
+
+ tc->has_loginuid = true;
+ tc->loginuid = parse_pid_loginuid(pid, &ret);
+ /*
+ * loginuid dumping is critical, as if not correctly
+ * restored, you may loss ability to login via SSH to CT
+ */
+ if (ret < 0)
+ return ret;
+
+ tc->oom_score_adj = parse_pid_oom_score_adj(pid, &ret);
+ /*
+ * oom_score_adj dumping is not very critical, as it will affect
+ * on victim in OOM situation and one will find dumping error in log
+ */
+ if (ret < 0)
+ tc->has_oom_score_adj = false;
+ else
+ tc->has_oom_score_adj = true;
+
+ return 0;
+}
+
static int dump_filemap(pid_t pid, struct vma_area *vma_area,
const struct cr_imgset *imgset)
{
@@ -702,6 +730,10 @@ static int dump_task_core_all(struct pstree_item *item,
if (ret)
goto err;
+ ret = dump_pid_misc(pid, core->tc);
+ if (ret)
+ goto err;
+
ret = dump_task_rlimits(pid, core->tc->rlimits);
if (ret)
goto err;
diff --git a/include/proc_parse.h b/include/proc_parse.h
index e45d93f..85e7e99 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -114,6 +114,8 @@ struct vm_area_list;
extern bool add_skip_mount(const char *mountpoint);
extern struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump);
extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
+extern unsigned int parse_pid_loginuid(pid_t pid, int *err);
+extern int parse_pid_oom_score_adj(pid_t pid, int *err);
extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list);
extern int parse_self_maps_lite(struct vm_area_list *vms);
extern int parse_pid_status(pid_t pid, struct proc_status_creds *);
diff --git a/proc_parse.c b/proc_parse.c
index c479b0f..15b0195 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -724,6 +724,58 @@ err:
return -1;
}
+unsigned int parse_pid_loginuid(pid_t pid, int *err)
+{
+ int fd;
+ ssize_t num;
+
+ *err = 0;
+ fd = open_proc(pid, "loginuid");
+ if (fd < 0)
+ goto out;
+
+ num = read(fd, buf, 10);
+ if (num < 0) {
+ pr_perror("Unable to read /proc/%d/loginuid", pid);
+ goto close_out;
+ }
+ buf[num] = '\0';
+
+ return strtol(buf, NULL, 10);
+
+close_out:
+ close(fd);
+out:
+ *err = -1;
+ return 4294967295; /* unset value */
+}
+
+int parse_pid_oom_score_adj(pid_t pid, int *err)
+{
+ int fd;
+ ssize_t num;
+
+ *err = 0;
+ fd = open_proc(pid, "oom_score_adj");
+ if (fd < 0)
+ goto out;
+
+ num = read(fd, buf, 10);
+ if (num < 0) {
+ pr_perror("Unable to read /proc/%d/oom_score_adj", pid);
+ goto close_out;
+ }
+ buf[num] = '\0';
+
+ return strtol(buf, NULL, 10);
+
+close_out:
+ close(fd);
+out:
+ *err = -1;
+ return 0;
+}
+
static int ids_parse(char *str, unsigned int *arr)
{
char *end;
diff --git a/protobuf/core.proto b/protobuf/core.proto
index 94322c0..4fe604e 100644
--- a/protobuf/core.proto
+++ b/protobuf/core.proto
@@ -38,6 +38,11 @@ message task_core_entry {
optional seccomp_mode seccomp_mode = 11;
optional uint32 seccomp_filter = 12;
+
+ optional uint32 loginuid = 13
+ [default = 4294967295]; /* not set */
+
+ optional int32 oom_score_adj = 14;
}
message task_kobj_ids_entry {
--
2.6.3
More information about the CRIU
mailing list