All of lore.kernel.org
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: Alexey Kodanev <alexey.kodanev@oracle.com>
Cc: vasily.isaenko@oracle.com, ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH] New core test of cgroups and extended attributes
Date: Tue, 28 May 2013 16:37:08 +0200	[thread overview]
Message-ID: <20130528143707.GA4229@rei> (raw)
In-Reply-To: <1369398051-2772-1-git-send-email-alexey.kodanev@oracle.com>

Hi!
> +void setup(int argc, char *argv[])
> +{
> +	char *msg;
> +	msg = parse_opts(argc, argv, options, help);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +	tst_require_root(NULL);
> +
> +	if (access("/proc/cgroups", F_OK) == -1)
> +		tst_brkm(TCONF, NULL, "Kernel doesn't support for cgroups");
                                                     ^         ^
				               Either add have here or
					       remove the for

> +	/* initialize test value */
> +	val.size = value_size;
> +	val.buf = SAFE_MALLOC(NULL, value_size);
> +
> +	tst_sig(FORK, DEF_HANDLER, cleanup);
> +
> +	tst_tmpdir();
> +
> +	make_cgroup_options();
> +
> +	int any_mounted = 0;
> +	int i;
> +	for (i = 0; i < cgrp_opt_num; ++i) {
> +		char dir[MAX_DIR_NAME];
> +		snprintf(cgrp_opt[i].dir, MAX_DIR_NAME, "cgx_%d",
> +			cgrp_opt[i].hier);
> +		SAFE_MKDIR(cleanup, cgrp_opt[i].dir, 0755);
> +		if (mount(cgrp_opt[i].dir, cgrp_opt[i].dir, "cgroup", 0,
> +			cgrp_opt[i].opt) == -1) {
> +			tst_resm(TINFO, "Can't mount: %s", dir);
> +			continue;
> +		}
> +
> +		any_mounted = 1;
> +		cgrp_opt[i].mounted = 1;
> +
> +		/* create new hierarchy */
> +		SAFE_CHDIR(cleanup, cgrp_opt[i].dir);
> +		SAFE_MKDIR(cleanup, subdir_name, 0755);
> +		cgrp_opt[i].subdir = 1;
> +		SAFE_CHDIR(cleanup, "..");
> +	}

I would keep the mounting code in the function that parses the cgroups
proc file, that way we can have simple:

	if (!mount_cgroups())
		tst_brkm(TBROK, cleanup, "Nothing mounted");

in the setup and keep all the details in the function.

> +	if (!any_mounted)
> +		tst_brkm(TBROK, cleanup, "Mounted nothing");

This should be TCONF.

> +}
> +
> +void make_cgroup_options(void)
> +{
> +	/* detect subsystems */
> +	FILE *fd = fopen("/proc/cgroups", "r");
> +	if (fd == NULL)
> +		tst_brkm(TBROK, cleanup, "Failed to read /proc/cgroups");
> +
> +	char str[MAX_DIR_NAME];
> +	char name[MAX_DIR_NAME];
> +	int	hier	= 0,
> +		num	= 0,
> +		enabled	= 0,
> +		first	= 1;

I would keep these at one line, which would save vertical space, but
that is purely cosmetic change.

> +	while ((fgets(str, MAX_DIR_NAME, fd)) != NULL) {
> +		/* skip first line */
> +		if (first) {
> +			first = 0;
> +			continue;
> +		}
> +		if (sscanf(str, "%s\t%d\t%d\t%d",
> +			name, &hier, &num, &enabled) != 4)
> +			tst_brkm(TBROK, cleanup, "Can't parse /proc/cgroups");
> +
> +		if (!enabled)
> +			continue;
> +
> +		/* BUG WORKAROUND
> +		 * Only mount those subsystems, which are not mounted yet.
> +		 * It's a workaround to a bug when mount doesn't
> +		 * return any err code while mounting already mounted
> +		 * subsystems, but with additional "xattr" option.
> +		 * In that case, mount will succeed, but xattr won't be
> +		 * supported in the new mount anyway.
> +		 * Should be removed as soon as a fix committed to upstream.
> +		 */
> +		if (hier != 0)
> +			continue;
> +		/* end of workaround */

Remove the /* end of workaround */ please.

> +		int found = 0;
> +		int i;
> +		for (i = 0; i < cgrp_opt_num; ++i) {
> +			if (cgrp_opt[i].hier == hier) {
> +				found = 1;
> +				break;
> +			}
> +		}
> +
> +		if (!found) {
> +			i = cgrp_opt_num++;
> +			cgrp_opt[i].hier = hier;
> +		}
> +
> +		int len = strlen(cgrp_opt[i].opt);
> +		if (len == 0) {

                Could also be if (cgrp_opt[i].opt[0] == '\0') {
		(or something similar)

> +			strcpy(cgrp_opt[i].opt, "xattr");
> +			len = strlen(cgrp_opt[i].opt);

                        len == 5 in this case ;)

> +		}
> +
> +		sprintf(cgrp_opt[i].opt + len, ",%s", name);

So we create a list of subsystem by hierarchy here, and try to mount
them with xattr later?

Ah but due to bug in kernel (hier == 0 when we got to this part) we end
up only with these that are not mounted at the moment, right?

That looks OK. Hopefully the kernel gets fixed. Will the kernel support
mouting the subsystems with additional xattr flags or will the mount
return an error (on my machine all mounted subsystems are mounted
without xattr)?

> +	}
> +	fclose(fd);
> +
> +	int i;
> +	for (i = 0; i < cgrp_opt_num; ++i) {
> +		tst_resm(TINFO, "mount options %d: %s (hier = %d)",
> +			i, cgrp_opt[i].opt, cgrp_opt[i].hier);
> +	}
> +}
> +


-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_may
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2013-05-28 14:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-24 12:20 [LTP] [PATCH] New core test of cgroups and extended attributes Alexey Kodanev
2013-05-28 14:37 ` chrubis [this message]
     [not found]   ` <51A4C663.7010506@oracle.com>
2013-05-28 15:43     ` chrubis
     [not found]       ` <51A5E74C.5000002@oracle.com>
2013-05-30 11:07         ` [LTP] Device firmware loading test chrubis
     [not found]           ` <51A747E8.7070105@oracle.com>
2013-05-30 13:13             ` chrubis
  -- strict thread matches above, loose matches on Subject: below --
2013-05-29 10:28 [LTP] [PATCH] New core test of cgroups and extended attributes Alexey Kodanev
2013-05-30 18:55 ` chrubis
2013-05-23 16:28 Alexey Kodanev
2013-05-23  7:09 Alexey Kodanev
2013-05-23 13:31 ` chrubis
2013-05-22 10:24 Alexey Kodanev
2013-05-22 14:26 ` chrubis
2013-05-15  9:40 Alexey Kodanev
2013-05-15 12:38 ` chrubis
     [not found]   ` <51939CB6.3020808@oracle.com>
2013-05-15 14:56     ` chrubis
     [not found]       ` <5194838B.2060104@oracle.com>
2013-05-16  8:39         ` chrubis
     [not found]           ` <5194A887.3010204@oracle.com>
2013-05-16 10:06             ` chrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130528143707.GA4229@rei \
    --to=chrubis@suse.cz \
    --cc=alexey.kodanev@oracle.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=vasily.isaenko@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.