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

Dmitry Safonov dsafonov at odin.com
Tue Dec 8 04:22:00 PST 2015


On 12/08/2015 03:10 PM, Andrew Vagin wrote:
> On Mon, Dec 07, 2015 at 05:17:08PM +0300, Dmitry Safonov wrote:
>> https://jira.sw.ru/browse/PSBM-41993
>>
>> Signed-off-by: Dmitry Safonov <dsafonov at odin.com>
>> ---
>>   cr-dump.c            | 11 +++++++++++
>>   include/proc_parse.h |  2 ++
>>   proc_parse.c         | 38 ++++++++++++++++++++++++++++++++++++++
>>   protobuf/core.proto  |  5 +++++
>>   4 files changed, 56 insertions(+)
>>
>> diff --git a/cr-dump.c b/cr-dump.c
>> index 5cc375d..06cf428 100644
>> --- a/cr-dump.c
>> +++ b/cr-dump.c
>> @@ -323,6 +323,15 @@ static int dump_task_rlimits(int pid, TaskRlimitsEntry *rls)
>>   	return 0;
>>   }
>>   
>> +static void dump_pid_misc(pid_t pid, TaskCoreEntry *tc)
>> +{
>> +	pr_info("dumping /proc/%d/{oom_score_adj,loginuid}\n", pid);
>> +	tc->loginuid = parse_pid_loginuid(pid);
> parse_pid_loginuid can return an error. Do we have to handle it?
It's usefull if handle dump_pid_misc ret code, below

>
>> +	tc->has_loginuid = true;
>> +	tc->oom_score_adj = parse_pid_oom_score_adj(pid);
>> +	tc->has_oom_score_adj = true;
>> +}
>> +
>>   static int dump_filemap(pid_t pid, struct vma_area *vma_area,
>>   		const struct cr_imgset *imgset)
>>   {
>> @@ -702,6 +711,8 @@ static int dump_task_core_all(struct pstree_item *item,
>>   	if (ret)
>>   		goto err;
>>   
>> +	dump_pid_misc(pid, core->tc);
> Why do we not hanle errors of dump_pid_misc()?
I suggest that it's not critical to stop dumping core. Is it?

>
>> +
>>   	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..3cc821b 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);
>> +extern int parse_pid_oom_score_adj(pid_t pid);
>>   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..c40a1b1 100644
>> --- a/proc_parse.c
>> +++ b/proc_parse.c
>> @@ -724,6 +724,44 @@ err:
>>   	return -1;
>>   }
>>   
>> +unsigned int parse_pid_loginuid(pid_t pid)
>> +{
>> +	unsigned int ret = 4294967295; /* unset value */
>> +	int fd;
>> +
>> +	fd = open_proc(pid, "loginuid");
>> +	if (fd < 0)
>> +		goto out;
>> +
>> +	if (read(fd, buf, BUF_SIZE) < 0)
> 		pr_perror("Unable to read loginuid")
Yeah, sure with path

>
>> +		goto close_out;
>> +	ret = strtol(buf, NULL, 10);
>> +
>> +close_out:
>> +	close(fd);
>> +out:
>> +	return ret;
>> +}
>> +
>> +int parse_pid_oom_score_adj(pid_t pid)
>> +{
>> +	int ret = 0;
>> +	int fd;
>> +
>> +	fd = open_proc(pid, "oom_score_adj");
>> +	if (fd < 0)
>> +		goto out;
>> +
>> +	if (read(fd, buf, BUF_SIZE) < 0)
> 		pr_perror
Sure too

>> +		goto close_out;
>> +	ret = strtol(buf, NULL, 10);
>> +
>> +close_out:
>> +	close(fd);
>> +out:
>> +	return ret;
>> +}
>> +
>>   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
>>
>> _______________________________________________
>> CRIU mailing list
>> CRIU at openvz.org
>> https://lists.openvz.org/mailman/listinfo/criu


-- 
Regards,
Dmitry Safonov



More information about the CRIU mailing list