[sheepdog] [PATCH v3] try to set RLIMIT_NOFILE to recommended value
Vasiliy Tolstov
v.tolstov at selfip.ru
Tue Mar 17 15:25:07 CET 2015
Signed-off-by: Vasiliy Tolstov <v.tolstov at selfip.ru>
---
sheep/sheep.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/sheep/sheep.c b/sheep/sheep.c
index fc53ec9..45d364f 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -522,21 +522,27 @@ static int create_work_queues(void)
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);
+ struct rlimit r;
+ int ret;
+
+ ret = getrlimit(RLIMIT_NOFILE, &r);
+ if (ret < 0) {
+ sd_err("failed to getrlimit");
+ } else {
+ if (r.rlim_cur < SD_RLIM_NOFILE) {
+ sd_warn("Allowed open files %lu, suggested %u",
+ r.rlim_cur, SD_RLIM_NOFILE);
+ r.rlim_cur = SD_RLIM_NOFILE;
+ r.rlim_max = SD_RLIM_NOFILE;
+ if (setrlimit(RLIMIT_NOFILE, &r) != 0) {
+ sd_warn("Failed to set open files limit to suggested %lu",
+ r.rlim_cur);
+ } 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");
--
2.2.2
More information about the sheepdog
mailing list