All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1 1/2] lib: Add .ulimit
Date: Mon, 23 Oct 2023 14:29:16 +0200	[thread overview]
Message-ID: <ZTZnHLi1tSN_WGPc@yuki> (raw)
In-Reply-To: <20231021122958.13458-2-wegao@suse.com>

Hi!
> +	/*
> +	 * {NULL, NULL} terminated array of (ulimit resource type and value)
              ^
	      That's technically {0, NULL} or maybe we can just start
	      using the newer syntax with just {}
> +	 */
> +	const struct tst_ulimit_val *ulimit;
> +
>  	/*
>  	 * NULL terminated array of kernel config options required for the
>  	 * test.
> diff --git a/include/tst_ulimit.h b/include/tst_ulimit.h
> new file mode 100644
> index 000000000..b4f97670a
> --- /dev/null
> +++ b/include/tst_ulimit.h
> @@ -0,0 +1,18 @@
> +/* SPDX-License-Identifier: GPL-2.0-only
> + *
> + * Copyright (c) 2023 Wei Gao <wegao@suse.com>
> + */
> +
> +#ifndef TST_ULIMIT_H__
> +#define TST_ULIMIT_H__
> +
> +#include <sys/resource.h>
> +
> +struct tst_ulimit_val {
> +	int resource;
> +	struct rlimit rlim;
> +};
> +
> +void tst_ulimit_conf(const struct tst_ulimit_val *conf);

Maybe tst_ulimit_set()?

> +#endif
> diff --git a/lib/tst_test.c b/lib/tst_test.c
> index 2e58cad33..a8c7c7ba6 100644
> --- a/lib/tst_test.c
> +++ b/lib/tst_test.c
> @@ -1227,6 +1227,15 @@ static void do_setup(int argc, char *argv[])
>  		}
>  	}
>  
> +	if (tst_test->ulimit) {
> +		const struct tst_ulimit_val *pvl = tst_test->ulimit;
> +
> +		while (pvl->resource) {
> +			tst_ulimit_conf(pvl);
> +			pvl++;
> +		}
> +	}
> +
>  	if (tst_test->mntpoint)
>  		SAFE_MKDIR(tst_test->mntpoint, 0777);
>  
> diff --git a/lib/tst_ulimit.c b/lib/tst_ulimit.c
> new file mode 100644
> index 000000000..1249d65d8
> --- /dev/null
> +++ b/lib/tst_ulimit.c
> @@ -0,0 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2023 Wei Gao <wegao@suse.com>
> + */
> +
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +#include "tst_ulimit.h"
> +
> +struct tst_ulimit_conf {
> +	int resource;
> +	struct rlimit rlim;
> +};

This structure is defined in header already.

> +void tst_ulimit_conf(const struct tst_ulimit_val *conf)
> +{
> +	struct rlimit rlim;
> +
> +	rlim.rlim_cur = conf->rlim.rlim_cur;
> +	rlim.rlim_max = conf->rlim.rlim_max;

I wonder if we should adjust the max only if it's smallre than the
requested value.

> +	tst_res(TINFO, "Set ulimit resource:%d rlim_cur:%ld rlim_max:%ld", conf->resource, rlim.rlim_cur, rlim.rlim_max);
> +	SAFE_SETRLIMIT(conf->resource, &rlim);
> +}
> -- 
> 2.35.3
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2023-10-23 12:29 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-21 12:29 [LTP] [PATCH v1 0/2] Lib add .ulimit setting Wei Gao via ltp
2023-10-21 12:29 ` [LTP] [PATCH v1 1/2] lib: Add .ulimit Wei Gao via ltp
2023-10-23 11:03   ` Petr Vorel
2023-10-23 12:29   ` Cyril Hrubis [this message]
2023-10-23 12:32     ` Cyril Hrubis
2023-10-21 12:29 ` [LTP] [PATCH v1 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2023-10-23 11:26   ` Petr Vorel
2023-10-25  8:37 ` [LTP] [PATCH v2 0/2] Lib add .ulimit setting Wei Gao via ltp
2023-10-25  8:37   ` [LTP] [PATCH v2 1/2] lib: Add .ulimit Wei Gao via ltp
2024-01-08 11:47     ` Petr Vorel
2023-10-25  8:37   ` [LTP] [PATCH v2 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2024-01-08 10:17     ` Petr Vorel
2024-01-09  6:59   ` [LTP] [PATCH v3 0/2] Lib add .ulimit setting Wei Gao via ltp
2024-01-09  6:59     ` [LTP] [PATCH v3 1/2] lib: Add .ulimit Wei Gao via ltp
2024-01-19 16:08       ` Cyril Hrubis
2024-01-23  7:57         ` Petr Vorel
2024-01-09  6:59     ` [LTP] [PATCH v3 2/2] execl01.c: set stack to unlimited Wei Gao via ltp
2024-01-19 16:09       ` Cyril Hrubis
2024-01-23  2:19     ` [LTP] [PATCH v4 0/2] Lib add .ulimit setting Wei Gao via ltp
2024-01-23  2:19       ` [LTP] [PATCH v4 1/2] lib: Add .ulimit Wei Gao via ltp
2024-01-23  8:36         ` Petr Vorel
2024-01-30 11:55           ` Petr Vorel
2024-01-23  2:19       ` [LTP] [PATCH v4 2/2] execl01.c: set stack to unlimited Wei Gao via ltp

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=ZTZnHLi1tSN_WGPc@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.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.