Re: Crash-utility Digest, Vol 86, Issue 13

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello, Dave,

To begin with, I am sincerely grateful for your detailed suggestions.
I have read the suggetions you gave and finished modifying the relative
parts. The following will demonstrate the modifications.

The first is when it comes to older kernels that do not have cgroups, it
now offers justification of whether the kernel have cgroups and output information when the kernel do not contain cgroup.

Secondly, you mentioned the cgroups "unabled" in the previous mail, considerring those inactive cgroups whose root(cgroupfs_root) is not linked by the active root list, I prefer to display something when there are no active cgroups other than output the inactive cgroups. If the inactive cgroups' information is needy, I need to rethink and find another way to get target data structure.

Thirdly, the unnecessary -h option was deleted and help information was
corrected according to your suggestions.

Lastly, the changed "lscgroup" command add the address of cgroup when displaying cgroups. For the reason that address length is fixed on a certain system, the first column of output is used to display the address.

You can check the modifications in the attachment by the same operation
as said in last mail.

Lots of thanks.
Yongming Yu


crash-utility-request@xxxxxxxxxx 写道:
Send Crash-utility mailing list submissions to
	crash-utility@xxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
	https://www.redhat.com/mailman/listinfo/crash-utility
or, via email, send a message with subject or body 'help' to
	crash-utility-request@xxxxxxxxxx

You can reach the person managing the list at
	crash-utility-owner@xxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Crash-utility digest..."


Today's Topics:

   1. Re: [Crash]  [PATCH] add a new command: lscgroup (Dave Anderson)


----------------------------------------------------------------------

Message: 1
Date: Fri, 9 Nov 2012 14:52:51 -0500 (EST)
From: Dave Anderson <anderson@xxxxxxxxxx>
To: "Discussion list for crash utility usage,	maintenance and
	development" <crash-utility@xxxxxxxxxx>
Subject: Re:  [Crash]  [PATCH] add a new command:
	lscgroup
Message-ID:
	<1824583457.29845585.1352490771952.JavaMail.root@xxxxxxxxxx>
Content-Type: text/plain; charset=utf-8



----- Original Message -----
Hello Dave,

I have been working on a new command named lscgroup to
list cgroups' information and finished it recently.

This command displays all the cgroups' information or the
appointed cgroups' information relatively according to user's
input. The following shows the two types of output.

1.Display all the cgroups' information of the system.
crash> lscgroup
blkio:/
blkio:/libvirt
blkio:/libvirt/lxc
blkio:/libvirt/qemu
net_cls:/
...
...
cpuset:/
cpuset:/libvirt
cpuset:/libvirt/lxc
cpuset:/libvirt/qemu


2.Display the appointed cgroups' information.
crash> lscgroup  memory:/   cpuset:/libvirt
memory:/
memory:/libvirt
memory:/libvirt/lxc
memory:/libvirt/qemu
cpuset:/libvirt
cpuset:/libvirt/lxc
cpuset:/libvirt/qemu

To see more details, please refer to the help information and the patch.

To build the module from the top-level crash-<version> directory,
enter:
   $ cp <path-to>/lscgroup.c extensions
   $ make extensions

Thanks for diving into this kernel subsystem.  Given the emergence
of cgroups, this command could ultimately be considered as a new built-in command.
However, that being said, it does need some additional work.

First, for older kernels that don't have cgroups, there should be a
protection mechanism to prevent this from happening:

 crash> sys | grep RELEASE
      RELEASE: 2.6.18-146.el5
 crash> lscgroup

 lscgroup: invalid structure member offset: cgroupfs_root_root_list
           FILE: lscgroup.c  LINE: 503  FUNCTION: cgroup_list_cgroups()

 [/usr/bin/crash] error trace: 4611e1 => 7f3b8f3a19d7 => 7f3b8f3a14e6 => 50b701

   50b701: OFFSET_verify+161
   4611e1: exec_command+801

 lscgroup: invalid structure member offset: cgroupfs_root_root_list
           FILE: lscgroup.c  LINE: 503  FUNCTION: cgroup_list_cgroups()

crash>
You should check for the existence of a kernel variable or structure definition,
and if they don't exist, call command_not_supported().

Secondly, if I am not mistaken, your command only shows "enabled" cgroups?
So for example, on this RHEL6 system, the command quietly does nothing:

 crash> sys | grep RELEASE
      RELEASE: 2.6.32-15.el6.x86_64
 crash> lscgroup
crash> Is that the case? I wonder if you should also show cgroups that are not enabled, i.e., like /proc/cgroups does? Or at a minimum, it should
show display something like "(no cgroups enabled)" instead of just
showing nothing at all.

Thirdly, your help page shows a "-h" option, which is unnecessary:

 crash> help lscgroup

 NAME
   lscgroup - list all cgroups

 SYNOPSIS
   lscgroup lscgroup [<controllers>:<path>] [...][-h]

  ...

because it doesn't do anything other than show the SYNOPSIS line
from the "help lscgroup" output:

 crash> lscgroup -h
 Usage:
   lscgroup lscgroup [<controllers>:<path>] [...][-h]
 Enter "help lscgroup" for details.
crash>
And you should change the third line in help_lscgroup[] from:

  char *help_lscgroup[] = {
  "lscgroup",
  "list all cgroups",
  "lscgroup [<controllers>:<path>] [...][-h]",

to:

  "[<controllers>:<path>] [...][-h]",

so that "lscgroup" is not printed twice in the "help lscgroup" and
the "Usage:" output.


And lastly, and most importantly, is what the command does *not* show.

Consider that most crash commands that delve into kernel
subsystems typically show information intermingled with
key data structure addresses.  So if there is a bug associated
with a kernel subsystem, the data structure addresses displayed
by a crash command can be used as a starting point for debugging
purposes.
So for example, if there was a bug associated with cgroups, your
command's output only shows the name strings, but there's nothing
else to "work with" for debugging.  Wouldn't it be more helpful to
at least display the cgroup and/or the cgroupfs_root addresses? Then there would be useful data structure addresses to start with.

Thanks,
  Dave












------------------------------

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

End of Crash-utility Digest, Vol 86, Issue 13
*********************************************



--
--------------------------------------------------
Yu Yongming
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.
(FNST)No. 6 Wenzhu Road, Nanjing, 210012, China
EMail:yuym.fnst@xxxxxxxxxxxxxx

Regards__
--------------------------------------------------


/* lscgroup.c - list cgroups
 *
 * Copyright (C) 2012 FUJITSU LIMITED
 * Author: Yu Yongming <yuym.fnst@xxxxxxxxxxxxxx>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 */

#include "defs.h"

#define PATHNAME_MAX      200
#define ROOT_MAX          64
#define CG_CONTROLLER_MAX 20
#define CG_HIER_MAX       20
#define FL_LIST           0x1

#define CGROUP_MEMBER_OFFSET_INIT(X,Y,Z) (cgroup_offset_table.X=MEMBER_OFFSET(Y,Z))
#define CGROUP_OFFSET(X) (OFFSET_verify(cgroup_offset_table.X, (char *)__FUNCTION__, __FILE__, __LINE__, #X))

/*
 *struct declaration
 */
struct cgroup_offset_table {
	long cgroupfs_root_root_list;
	long cgroupfs_root_top_cgroup;
	long cgroupfs_root_subsys_list;
	long cgroupfs_root_actual_subsys_bits;
	long cgroupfs_root_name;
	long cgroup_sibling;
	long cgroup_children;
	long cgroup_dentry;
	long cgroup_subsys_name;
	long cgroup_subsys_sibling;
};

struct cgroup_group_spec {
	char path[PATHNAME_MAX];
	char *controllers[CG_CONTROLLER_MAX];
};

/*
 *function declaration
 */
int _init(void);
int _fini(void);

void cmd_lscgroup(void);
char *help_lscgroup[];

static void cgroup_init(void);
static void get_controller_name(ulong);
static void get_cgroup_name(ulong, char *);
static void parse_top_cgroup(ulong, char *);
static void print_all_cgroups(void);
static int in_cgroupfs_root(char *, struct cgroup_group_spec *);
static ulong locate_top_cgroup(struct cgroup_group_spec *);
static void parse_path(char *, char **);
static ulong locate_cgroup(ulong, ulong, char *);
static void standarlize_path(char *);
static void cgroup_elem_cgroup(struct cgroup_group_spec *);
static void cgroup_list_cgroups(char *, struct cgroup_group_spec **, int);
static int parse_cgroup_spec(struct cgroup_group_spec **, char *);
static void cgroup_free_group_spec(struct cgroup_group_spec *);

/*
 * global data
 */

static char controller_name[PATHNAME_MAX];

static struct command_table_entry command_table[] = {
	{"lscgroup", cmd_lscgroup, help_lscgroup, 0},
	{NULL},
};

static struct cgroup_offset_table cgroup_offset_table = { 0 };

char *help_lscgroup[] = {
"lscgroup",
"list all cgroups",
"[<controllers>:<path>] [...]",
"  The command list all/chosen cgroups.",
"  <controllers>:<path> defines control groups which subgroups will be shown.",
"  If this parameter is not used then the command list all cgroups which are",
"  present.",
"\nEXAMPLE",
"  display chosen cgroups:\n",
"    %s>lscgroup cpuset:/libvirt",
"    cpuset:/libvirt",
"    cpuset:/libvirt/lxc",
"    cpuset:/libvirt/qemu",
"	",
"  display all cgroups:\n",
"    %s>lscgroup",
"    blkio:/", 
"    blkio:/libvirt", 
"    blkio:/libvirt/lxc", 
"    blkio:/libvirt/qemu", 
"    net_cls:/", 
"    freezer:/", 
"    freezer:/libvirt", 
"    freezer:/libvirt/lxc", 
"    freezer:/libvirt/qemu", 
"    devices:/",
"    devices:/libvirt", 
"    devices:/libvirt/lxc", 
"    devices:/libvirt/qemu", 
"    memory:/", 
"    memory:/libvirt", 
"    memory:/libvirt/lxc",
"    memory:/libvirt/qemu",
"    cpuacct:/ ",
"    cpuacct:/libvirt",
"    cpuacct:/libvirt/lxc",
"    cpuacct:/libvirt/qemu",
"    cpu:/",
"    cpu:/libvirt",
"    cpu:/libvirt/lxc",
"    cpu:/libvirt/qemu",
"    cpuset:/",
"    cpuset:/libvirt",
"    cpuset:/libvirt/lxc",
"    cpuset:/libvirt/qemu",
NULL
};

int 
_init(void)
{
	register_extension(command_table);
	return 1;
}

int 
_fini(void)
{
	return 1;
}

static void 
cgroup_init(void)
{
	CGROUP_MEMBER_OFFSET_INIT(cgroupfs_root_root_list, "cgroupfs_root",
		"root_list");
	CGROUP_MEMBER_OFFSET_INIT(cgroupfs_root_top_cgroup, "cgroupfs_root",
		"top_cgroup");
	CGROUP_MEMBER_OFFSET_INIT(cgroupfs_root_subsys_list, "cgroupfs_root",
		"subsys_list");
	CGROUP_MEMBER_OFFSET_INIT(cgroupfs_root_actual_subsys_bits,
		"cgroupfs_root", "actual_subsys_bits");
	CGROUP_MEMBER_OFFSET_INIT(cgroupfs_root_name, "cgroupfs_root",
		"name");
	CGROUP_MEMBER_OFFSET_INIT(cgroup_sibling, "cgroup", "sibling");
	CGROUP_MEMBER_OFFSET_INIT(cgroup_children, "cgroup", "children");
	CGROUP_MEMBER_OFFSET_INIT(cgroup_dentry, "cgroup", "dentry");
	CGROUP_MEMBER_OFFSET_INIT(cgroup_subsys_name, "cgroup_subsys", "name");
	CGROUP_MEMBER_OFFSET_INIT(cgroup_subsys_sibling, "cgroup_subsys", 
		"sibling");
}

static void 
get_controller_name(ulong cgroupfs_root)
{
	char name[PATHNAME_MAX];
	ulong subsys, next, subsys_list, name_buf, name_addr;
	int len;
	
	BZERO(name, PATHNAME_MAX);
	BZERO(controller_name, PATHNAME_MAX);

	readmem(cgroupfs_root + CGROUP_OFFSET(cgroupfs_root_actual_subsys_bits),
		KVADDR, &subsys, sizeof(ulong), "cgroupfs_root_actual_subsys",
		FAULT_ON_ERROR);
	if(subsys == 0) {
		readmem(cgroupfs_root + CGROUP_OFFSET(cgroupfs_root_name), 
			KVADDR, &name, ROOT_MAX, "cgroupfs_root_name",
			FAULT_ON_ERROR);
		strcat(controller_name, name);
		return ;
	}
	subsys_list = cgroupfs_root + CGROUP_OFFSET(cgroupfs_root_subsys_list);
	readmem(subsys_list, KVADDR, &next, sizeof(ulong),
		"cgroupfs_root_subsys_list", FAULT_ON_ERROR);
	
	do {
		name_buf = next - CGROUP_OFFSET(cgroup_subsys_sibling)
                	+ CGROUP_OFFSET(cgroup_subsys_name);
		readmem(name_buf, KVADDR, &name_addr, sizeof(ulong),
			"cgroup_subsys_name", FAULT_ON_ERROR);
                readmem(name_addr, KVADDR, name, sizeof(name), 
			"char* name", FAULT_ON_ERROR);
			
		strcat(controller_name, name);
		strcat(controller_name, ",");

		readmem(next, KVADDR, &next, sizeof(ulong),
                "list_head", FAULT_ON_ERROR);
	} while(next != subsys_list);
	
	len = strlen(controller_name);	
	controller_name[len-1] = '\0';
}

static void
get_cgroup_name(ulong cgroup, char *name)
{
	ulong dentry, name_addr;
	char *dentry_buf;
	int len;

	readmem(cgroup + CGROUP_OFFSET(cgroup_dentry), KVADDR,
		&dentry, sizeof(ulong), "cgroup dentry",
		FAULT_ON_ERROR);

	dentry_buf = GETBUF(SIZE(dentry));
	readmem(dentry, KVADDR, dentry_buf, SIZE(dentry),
		"dentry", FAULT_ON_ERROR);
	len = UINT(dentry_buf + OFFSET(dentry_d_name) + OFFSET(qstr_len));
	name_addr = ULONG(dentry_buf + OFFSET(dentry_d_name) + OFFSET(qstr_name));
	readmem(name_addr, KVADDR, name, len, "qstr name", FAULT_ON_ERROR);
	FREEBUF(dentry_buf);
}

static void 
parse_top_cgroup(ulong top_cgroup, char *path)
{
	int len;
	char tmp_buf[PATHNAME_MAX];
	ulong list_head[2], next, child;

	BZERO(tmp_buf, PATHNAME_MAX);
	get_cgroup_name(top_cgroup, tmp_buf);
	if (strlen(path) > 1) 
		strncat(path, "/", 1);
	strncat(path, tmp_buf, strlen(tmp_buf));

	fprintf(fp, "%lx\t%s:%s\n", top_cgroup, controller_name, path);

	child = top_cgroup + CGROUP_OFFSET(cgroup_children);
	readmem(child, KVADDR, list_head, sizeof(ulong) * 2,
		"cgroup children", FAULT_ON_ERROR);

	if ((list_head[0] == child) && (list_head[1] == child))
		return;

	next = list_head[0];
	while (next != child) {
		top_cgroup = next - CGROUP_OFFSET(cgroup_sibling);
		readmem(top_cgroup + CGROUP_OFFSET(cgroup_sibling) +
			OFFSET(list_head_next), KVADDR, &next, sizeof(ulong),
			"cgroup siblings", FAULT_ON_ERROR);
		len = strlen(path);
		parse_top_cgroup(top_cgroup, path);
		path[len] = '\0';
	}
}

static void 
print_all_cgroups(void)
{
	struct syment *roots;
        ulong top_cgroup;
        ulong list_head[2], next, cgroupfs_root;;
        char path_name[PATHNAME_MAX];
	char buf1[BUFSIZE];

        BZERO(path_name, PATHNAME_MAX);

        if (!(roots = symbol_search("roots")))
                error(FATAL, "roots symbol does not exist?\n");

        readmem(roots->value, KVADDR, list_head, sizeof(ulong) * 2,
                "list_head", FAULT_ON_ERROR);

        if ((list_head[0] == roots->value) && (list_head[1] == roots->value)) {
        	fprintf(fp, "no active cgroup hierarchy in the kernel.");
	        return;
	}

	//fprintf(fp, " CGROUP_ADDR\t\t <CONTROLLER>:<PATH>\n");
	fprintf(fp, "%s\t <CONTROLLER>:<PATH>\n",
		mkstring(buf1, VADDR_PRLEN, CENTER, "CGROUP_ADDR"));
        next = list_head[0];
        while (next != roots->value) {
                cgroupfs_root = next - CGROUP_OFFSET(cgroupfs_root_root_list);
		get_controller_name(cgroupfs_root);

                top_cgroup = cgroupfs_root +
                        CGROUP_OFFSET(cgroupfs_root_top_cgroup);
                /* print infomation of cgroup and subcgroup */
                parse_top_cgroup(top_cgroup, path_name);

                readmem(next + OFFSET(list_head_next), KVADDR, &next,
                        sizeof(ulong), "list_head next", FAULT_ON_ERROR);
                BZERO(path_name, PATHNAME_MAX);
		BZERO(controller_name, PATHNAME_MAX);
        }
}

static int
in_cgroupfs_root(char *tmp_name, struct cgroup_group_spec *elem)
{
	char *name;
	int i = 0;
	name = strtok(tmp_name, ",");
	while(name != NULL) {	
		while(elem->controllers[i] != NULL && i < CG_CONTROLLER_MAX) {
			if(STREQ(name, elem->controllers[i]))
				return 1;
			i++;
		}
		name = strtok(NULL, ",");
		i = 0;
	}	
	
	return 0;
}

static ulong 
locate_top_cgroup(struct cgroup_group_spec *elem)
{
	struct syment *roots;
	ulong top_cgroup;
	ulong list_head[2], next, cgroupfs_root;
	char tmp_name[PATHNAME_MAX];

	if (!(roots = symbol_search("roots")))
		error(FATAL, "roots symbol does not exist?");

	readmem(roots->value, KVADDR, list_head, sizeof(ulong)*2,
		"list_head", FAULT_ON_ERROR);

	if ((list_head[0] == roots->value) && (list_head[1] == roots->value))
		return 0;
	
	next = list_head[0];
	while (next != roots->value) {
		/* begin from first root */
		cgroupfs_root = next - CGROUP_OFFSET(cgroupfs_root_root_list);
		get_controller_name(cgroupfs_root);
		strcpy(tmp_name, controller_name);

		if (in_cgroupfs_root(tmp_name, elem)) {
   			top_cgroup = cgroupfs_root +
   				CGROUP_OFFSET(cgroupfs_root_top_cgroup);
  			return top_cgroup;
		}
		readmem(next + OFFSET(list_head_next), KVADDR, &next,
   			sizeof(ulong), "list_head", FAULT_ON_ERROR);
		BZERO(controller_name, PATHNAME_MAX);
	}
	return 0;
}

/*
 * function parse_path and extracts the input path before the first '/' as
 * relatively path which will be used to compare with path name of cgroup.
 * In addition, it ignores the unnecessary '/' in the path
 */
static void 
parse_path(char *path, char **elem_path)
{ 
 	char *token;

	token = *elem_path;
	if (token[0] == '/') {
		*path++ = *token++;
	} else {
		while (*token) {
			if (*token == '/' && *(token + 1) == '/') {
				token++;
			} else if (*token == '/' && *(token + 1) != '/') {
				token++; 
				break;
			} else {
				*path++ = *token++;	
			}
		}	
	}
	*elem_path = token;
	*path = '\0';
}

static ulong 
locate_cgroup(ulong current, ulong prev_addr, char *elem_path)
{
        char tmp_buf[PATHNAME_MAX];
	char path[PATHNAME_MAX];
	char *tmp_path = elem_path;
	ulong child, sibling, child_offset, sibling_offset;

	if (*elem_path == '\0')
		return prev_addr;

        BZERO(tmp_buf, PATHNAME_MAX);
	get_cgroup_name(current, tmp_buf);

	parse_path(path, &elem_path);

	readmem(current + CGROUP_OFFSET(cgroup_children), KVADDR, &child,
                sizeof(ulong), "cgroup children", FAULT_ON_ERROR);
        readmem(current + CGROUP_OFFSET(cgroup_sibling), KVADDR, &sibling,
                sizeof(ulong), "cgroup sibling", FAULT_ON_ERROR);	

	child_offset = CGROUP_OFFSET(cgroup_children);
	sibling_offset = CGROUP_OFFSET(cgroup_sibling);
	/* parse the children if temp=path_name, do change elem_path */
	if (STREQ(tmp_buf, path)) {
		if ((child - child_offset != current))
			return locate_cgroup(child - sibling_offset,
					current, elem_path);
		else if (*elem_path == '\0')
			return current;
	} else { 
	/* parse the sibling if temp !=path_name, do not chage elem_path */
		if (((sibling - child_offset) != prev_addr) &&
		    ((sibling - sibling_offset) != current)) {
			elem_path = tmp_path;
			return locate_cgroup(sibling - sibling_offset,
					prev_addr, elem_path);
		}
	}
	return 0;
}

/*
 * make the input path begin with character '/' and end without character '/'
 * to cope with the situation that the input path may be like "/xxxxx",
 * "xxxxx", "xxxxx/", or "/xxxxx/"
 */
static void 
standarlize_path(char *path)
{
	int len;

	len = strlen(path) - 1;
	if (path[len] == '/')
		path[len] = '\0';

	if (path[0] != '/') {
		len = strlen(path);
		path[len + 1] = '\0';
		while (len) {
			path[len] = path[len - 1];
			len--;
		}
		path[0] = '/';
	}
}

static void 
mani_path(char *path)
{	
	int len;

	standarlize_path(path);
 	
	if (STREQ(path, "/")) {
		*path = '\0';
                return ;
	}
	len = strlen(path);
	while (path[len] != '/') {
		path[len] = '\0';
		len--;
	}
	path[len] = '\0';
	path[0] = '/';
}

static void 
cgroup_elem_cgroup(struct cgroup_group_spec *list_elem)
{
	ulong top_cgroup;
	ulong cgroup;
	char path_name[PATHNAME_MAX];
	char buf1[BUFSIZE];

	top_cgroup = locate_top_cgroup(list_elem);
	if (top_cgroup == 0) {
		fprintf(fp, "cannot find top cgroup, check the input.\n");
		return ;
	}
        
	strcpy(path_name, list_elem->path);
	standarlize_path(path_name);
	cgroup = locate_cgroup(top_cgroup, top_cgroup, path_name);
	if (cgroup == 0) {
		fprintf(fp, "can not find cgroup %s, check the input.\n", 
			list_elem->path);
		return ;
	}
 
	mani_path(list_elem->path);
	fprintf(fp, "%s\t <CONTROLLER>:<PATH>\n",
                mkstring(buf1, VADDR_PRLEN, CENTER, "CGROUP_ADDR"));
	parse_top_cgroup(cgroup, list_elem->path);
}

static void 
cgroup_list_cgroups(char *tname, struct cgroup_group_spec *cgroup_list[],
	int flags)
{
	int i;

	i = 0;	
	cgroup_init();
	if(cgroup_offset_table.cgroupfs_root_root_list == -1) {
		fprintf(fp, "cgroup does not exist, check kernel version.");
		return ;
	}
	if ((flags & FL_LIST) == 0) {
		/* list all the cgroups */
		print_all_cgroups();
	} else {
		/* list the specified cgroups */
		while ((cgroup_list[i]->path != NULL)) {
			cgroup_elem_cgroup(cgroup_list[i]);
			i++;
		}
	}
}

static int 
parse_cgroup_spec(struct cgroup_group_spec **list, char *optarg)
{
	struct cgroup_group_spec *ptr;
	int i, j;
	char *controller, *path, *temp;

	ptr = *list;

	for (i = 0; i < CG_HIER_MAX; i++, ptr++) {
		if (!list[i])
			break;
	}

	if (i == CG_HIER_MAX) {
		fprintf(fp, "Max allowed hierarchies %d reached\n",
			CG_HIER_MAX);
		return -1;
	}

	controller = strtok(optarg, ":");
	if (!controller)
		return -1;

	path = strtok(NULL, ":");
	if (!path)
		return -1;

	list[i] = (struct cgroup_group_spec *)GETBUF(sizeof(**list));
	j = 0;
	do {
		if (j == 0)
			temp = strtok(controller, ",");
		else
			temp = strtok(NULL, ",");

		if (temp) {
			list[i]->controllers[j] = strdup(temp);
			if (!list[i]->controllers[j]) {
				FREEBUF(list[i]);
				fprintf(fp, "%s\n", strerror(errno));
				return -1;
			}
		}
		j++;
	} while (temp && (j < (CG_CONTROLLER_MAX - 1)));

	strncpy(list[i]->path, path, strlen(path));

	return 0;
}

static void 
cgroup_free_group_spec(struct cgroup_group_spec *elem)
{
	int i;

	if (!elem)
		return;

	for (i = 0; i < CG_CONTROLLER_MAX; i++) {
		if (elem->controllers[i])
			free(elem->controllers[i]);
	}
	FREEBUF(elem);
}

void 
cmd_lscgroup(void)
{
	int c, i, ret, flags;
	struct cgroup_group_spec *cgroup_list[CG_HIER_MAX];

	ret = flags = 0;
	while ((c = getopt(argcnt, args, "")) != EOF) {
		switch(c) {
		default:
			cmd_usage(pc->curcmd, SYNOPSIS);
			return ;
		}
	}
	if (argerrs)
		cmd_usage(pc->curcmd, SYNOPSIS);

	BZERO(cgroup_list, sizeof(cgroup_list));
	
	if (optind < argcnt)
		flags |= FL_LIST;

	while (args[optind]) {
		ret = parse_cgroup_spec(cgroup_list, args[optind]);
		if (ret) {
			fprintf(fp, "%s: cgroup controller"
				" and path parsing failed(%s)\n",
				args[0], args[optind]);
		}
		optind++;
	}
	cgroup_list_cgroups(args[0], cgroup_list, flags);

	if (!cgroup_list[0])
		return;
	
	for (i = 0; i < CG_HIER_MAX; i++)
		cgroup_free_group_spec(cgroup_list[i]);
}

--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux