[sheepdog] [PATCH v5] try to set RLIMIT_NOFILE to recommended value

Hitoshi Mitake mitake.hitoshi at gmail.com
Tue Apr 7 18:02:25 CEST 2015


At Thu, 26 Mar 2015 09:59:38 +0300,
Vasiliy Tolstov wrote:
> 
> Signed-off-by: Vasiliy Tolstov <v.tolstov at selfip.ru>
> ---
>  sheep/sheep.c | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/sheep/sheep.c b/sheep/sheep.c
> index fc53ec9..3280580 100644
> --- a/sheep/sheep.c
> +++ b/sheep/sheep.c
> @@ -524,23 +524,26 @@ static void check_host_env(void)
>  {
>  	struct rlimit r;
>  
> -	if (getrlimit(RLIMIT_NOFILE, &r) < 0)
> -		sd_err("failed to get nofile %m");
> -	/*
> -	 * 1024 is default for NOFILE on most distributions, which is very
> -	 * dangerous to run Sheepdog cluster.
> -	 */
> -	else if (r.rlim_cur == 1024)
> -		sd_warn("Allowed open files 1024 too small, suggested %u",
> -			SD_RLIM_NOFILE);
> -	else if (r.rlim_cur < SD_RLIM_NOFILE)
> -		sd_info("Allowed open files %lu, suggested %u", r.rlim_cur,
> -			SD_RLIM_NOFILE);
> +	if (getrlimit(RLIMIT_NOFILE, &r) < 0) {
> +		sd_err("failed to getrlimit");
> +        }

You need to remove above curly braces, and
> +
> +        if (r.rlim_cur < SD_RLIM_NOFILE) {

this check should be skipped if the above getrlimit() fails.

Thanks,
Hitoshi

> +                r.rlim_cur = SD_RLIM_NOFILE;
> +                r.rlim_max = SD_RLIM_NOFILE;
> +                if (setrlimit(RLIMIT_NOFILE, &r) != 0) {
> +                        sd_warn("failed to set nofile to suggested %lu",
> +                                r.rlim_cur);
> +                        sd_warn("increase nofile via sysctl fs.nr_open");
> +                }
> +        } else {
> +                sd_info("allowed open files set to suggested %lu", r.rlim_cur);
> +        }
>  
>  	if (getrlimit(RLIMIT_CORE, &r) < 0)
>  		sd_debug("failed to get core %m");
>  	else if (r.rlim_cur < RLIM_INFINITY)
> -		sd_debug("Allowed core file size %lu, suggested unlimited",
> +		sd_debug("allowed core file size %lu, suggested unlimited",
>  			 r.rlim_cur);
>  
>  	/*
> -- 
> 2.3.3
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> https://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list