[CRIU] [PATCH v4 1/5] criu: dump loginuid & oom_score_adj values

Dmitry Safonov dsafonov at odin.com
Mon Dec 14 01:19:14 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 |  4 ++++
 proc_parse.c         | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 protobuf/core.proto  |  4 ++++
 4 files changed, 90 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..7b37659 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -111,9 +111,13 @@ struct fstype {
 
 struct vm_area_list;
 
+#define INVALID_UID ((uid_t)-1)
+
 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 b007c56..2eef21a 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -724,6 +724,56 @@ 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);
+	close(fd);
+	if (num < 0) {
+		pr_perror("Unable to read /proc/%d/loginuid", pid);
+		goto out;
+	}
+	buf[num] = '\0';
+
+	return strtol(buf, NULL, 10);
+
+out:
+	*err = -1;
+	return INVALID_UID; /* 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);
+	close(fd);
+	if (num < 0) {
+		pr_perror("Unable to read /proc/%d/oom_score_adj", pid);
+		goto out;
+	}
+	buf[num] = '\0';
+
+	return strtol(buf, NULL, 10);
+
+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..189acf4 100644
--- a/protobuf/core.proto
+++ b/protobuf/core.proto
@@ -38,6 +38,10 @@ message task_core_entry {
 
 	optional seccomp_mode		seccomp_mode	= 11;
 	optional uint32			seccomp_filter	= 12;
+
+	optional uint32			loginuid	= 13;
+
+	optional int32			oom_score_adj	= 14;
 }
 
 message task_kobj_ids_entry {
-- 
2.6.3



More information about the CRIU mailing list