|
|
5c2e41 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
5c2e41 |
From: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
5c2e41 |
Date: Mon, 8 Oct 2018 11:41:03 -0500
|
|
|
5c2e41 |
Subject: [PATCH] libmultipath: remove max_fds code duplication
|
|
|
5c2e41 |
|
|
|
5c2e41 |
Instead of multipath, multipathd, and mpathpersist all having code to
|
|
|
5c2e41 |
set the max number of open file descriptors, just use a util function to
|
|
|
5c2e41 |
do it.
|
|
|
5c2e41 |
|
|
|
5c2e41 |
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
|
|
|
5c2e41 |
---
|
|
|
5c2e41 |
libmpathpersist/mpath_persist.c | 11 +----------
|
|
|
5c2e41 |
libmultipath/util.c | 31 +++++++++++++++++++++++++++++++
|
|
|
5c2e41 |
libmultipath/util.h | 1 +
|
|
|
5c2e41 |
multipath/main.c | 12 +-----------
|
|
|
5c2e41 |
multipathd/main.c | 31 +++----------------------------
|
|
|
5c2e41 |
5 files changed, 37 insertions(+), 49 deletions(-)
|
|
|
5c2e41 |
|
|
|
5c2e41 |
diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c
|
|
|
5c2e41 |
index 4229a94..29e7fb4 100644
|
|
|
5c2e41 |
--- a/libmpathpersist/mpath_persist.c
|
|
|
5c2e41 |
+++ b/libmpathpersist/mpath_persist.c
|
|
|
5c2e41 |
@@ -31,7 +31,6 @@
|
|
|
5c2e41 |
#include <stdlib.h>
|
|
|
5c2e41 |
#include <string.h>
|
|
|
5c2e41 |
#include <errno.h>
|
|
|
5c2e41 |
-#include <sys/resource.h>
|
|
|
5c2e41 |
|
|
|
5c2e41 |
#define __STDC_FORMAT_MACROS 1
|
|
|
5c2e41 |
|
|
|
5c2e41 |
@@ -48,15 +47,7 @@ mpath_lib_init (void)
|
|
|
5c2e41 |
return NULL;
|
|
|
5c2e41 |
}
|
|
|
5c2e41 |
|
|
|
5c2e41 |
- if (conf->max_fds) {
|
|
|
5c2e41 |
- struct rlimit fd_limit;
|
|
|
5c2e41 |
-
|
|
|
5c2e41 |
- fd_limit.rlim_cur = conf->max_fds;
|
|
|
5c2e41 |
- fd_limit.rlim_max = conf->max_fds;
|
|
|
5c2e41 |
- if (setrlimit(RLIMIT_NOFILE, &fd_limit) < 0)
|
|
|
5c2e41 |
- condlog(0, "can't set open fds limit to %d : %s",
|
|
|
5c2e41 |
- conf->max_fds, strerror(errno));
|
|
|
5c2e41 |
- }
|
|
|
5c2e41 |
+ set_max_fds(conf->max_fds);
|
|
|
5c2e41 |
|
|
|
5c2e41 |
return conf;
|
|
|
5c2e41 |
}
|
|
|
5c2e41 |
diff --git a/libmultipath/util.c b/libmultipath/util.c
|
|
|
5c2e41 |
index 347af5b..d08112d 100644
|
|
|
5c2e41 |
--- a/libmultipath/util.c
|
|
|
5c2e41 |
+++ b/libmultipath/util.c
|
|
|
5c2e41 |
@@ -7,6 +7,8 @@
|
|
|
5c2e41 |
#include <sys/sysmacros.h>
|
|
|
5c2e41 |
#include <sys/types.h>
|
|
|
5c2e41 |
#include <sys/utsname.h>
|
|
|
5c2e41 |
+#include <sys/time.h>
|
|
|
5c2e41 |
+#include <sys/resource.h>
|
|
|
5c2e41 |
#include <dirent.h>
|
|
|
5c2e41 |
#include <unistd.h>
|
|
|
5c2e41 |
#include <errno.h>
|
|
|
5c2e41 |
@@ -465,3 +467,32 @@ int safe_write(int fd, const void *buf, size_t count)
|
|
|
5c2e41 |
}
|
|
|
5c2e41 |
return 0;
|
|
|
5c2e41 |
}
|
|
|
5c2e41 |
+
|
|
|
5c2e41 |
+void set_max_fds(int max_fds)
|
|
|
5c2e41 |
+{
|
|
|
5c2e41 |
+ struct rlimit fd_limit;
|
|
|
5c2e41 |
+
|
|
|
5c2e41 |
+ if (!max_fds)
|
|
|
5c2e41 |
+ return;
|
|
|
5c2e41 |
+
|
|
|
5c2e41 |
+ if (getrlimit(RLIMIT_NOFILE, &fd_limit) < 0) {
|
|
|
5c2e41 |
+ condlog(0, "can't get open fds limit: %s",
|
|
|
5c2e41 |
+ strerror(errno));
|
|
|
5c2e41 |
+ fd_limit.rlim_cur = 0;
|
|
|
5c2e41 |
+ fd_limit.rlim_max = 0;
|
|
|
5c2e41 |
+ }
|
|
|
5c2e41 |
+ if (fd_limit.rlim_cur < max_fds) {
|
|
|
5c2e41 |
+ fd_limit.rlim_cur = max_fds;
|
|
|
5c2e41 |
+ if (fd_limit.rlim_max < max_fds)
|
|
|
5c2e41 |
+ fd_limit.rlim_max = max_fds;
|
|
|
5c2e41 |
+ if (setrlimit(RLIMIT_NOFILE, &fd_limit) < 0) {
|
|
|
5c2e41 |
+ condlog(0, "can't set open fds limit to "
|
|
|
5c2e41 |
+ "%lu/%lu : %s",
|
|
|
5c2e41 |
+ fd_limit.rlim_cur, fd_limit.rlim_max,
|
|
|
5c2e41 |
+ strerror(errno));
|
|
|
5c2e41 |
+ } else {
|
|
|
5c2e41 |
+ condlog(3, "set open fds limit to %lu/%lu",
|
|
|
5c2e41 |
+ fd_limit.rlim_cur, fd_limit.rlim_max);
|
|
|
5c2e41 |
+ }
|
|
|
5c2e41 |
+ }
|
|
|
5c2e41 |
+}
|
|
|
5c2e41 |
diff --git a/libmultipath/util.h b/libmultipath/util.h
|
|
|
5c2e41 |
index 56cec76..c246295 100644
|
|
|
5c2e41 |
--- a/libmultipath/util.h
|
|
|
5c2e41 |
+++ b/libmultipath/util.h
|
|
|
5c2e41 |
@@ -21,6 +21,7 @@ int get_linux_version_code(void);
|
|
|
5c2e41 |
int parse_prkey(char *ptr, uint64_t *prkey);
|
|
|
5c2e41 |
int parse_prkey_flags(char *ptr, uint64_t *prkey, uint8_t *flags);
|
|
|
5c2e41 |
int safe_write(int fd, const void *buf, size_t count);
|
|
|
5c2e41 |
+void set_max_fds(int max_fds);
|
|
|
5c2e41 |
|
|
|
5c2e41 |
#define KERNEL_VERSION(maj, min, ptc) ((((maj) * 256) + (min)) * 256 + (ptc))
|
|
|
5c2e41 |
|
|
|
5c2e41 |
diff --git a/multipath/main.c b/multipath/main.c
|
|
|
5c2e41 |
index d5aad95..05b7bf0 100644
|
|
|
5c2e41 |
--- a/multipath/main.c
|
|
|
5c2e41 |
+++ b/multipath/main.c
|
|
|
5c2e41 |
@@ -56,8 +56,6 @@
|
|
|
5c2e41 |
#include "pgpolicies.h"
|
|
|
5c2e41 |
#include "version.h"
|
|
|
5c2e41 |
#include <errno.h>
|
|
|
5c2e41 |
-#include <sys/time.h>
|
|
|
5c2e41 |
-#include <sys/resource.h>
|
|
|
5c2e41 |
#include "wwids.h"
|
|
|
5c2e41 |
#include "uxsock.h"
|
|
|
5c2e41 |
#include "mpath_cmd.h"
|
|
|
5c2e41 |
@@ -1002,15 +1000,7 @@ main (int argc, char *argv[])
|
|
|
5c2e41 |
logsink = 1;
|
|
|
5c2e41 |
}
|
|
|
5c2e41 |
|
|
|
5c2e41 |
- if (conf->max_fds) {
|
|
|
5c2e41 |
- struct rlimit fd_limit;
|
|
|
5c2e41 |
-
|
|
|
5c2e41 |
- fd_limit.rlim_cur = conf->max_fds;
|
|
|
5c2e41 |
- fd_limit.rlim_max = conf->max_fds;
|
|
|
5c2e41 |
- if (setrlimit(RLIMIT_NOFILE, &fd_limit) < 0)
|
|
|
5c2e41 |
- condlog(0, "can't set open fds limit to %d : %s",
|
|
|
5c2e41 |
- conf->max_fds, strerror(errno));
|
|
|
5c2e41 |
- }
|
|
|
5c2e41 |
+ set_max_fds(conf->max_fds);
|
|
|
5c2e41 |
|
|
|
5c2e41 |
libmp_udev_set_sync_support(1);
|
|
|
5c2e41 |
|
|
|
5c2e41 |
diff --git a/multipathd/main.c b/multipathd/main.c
|
|
|
5c2e41 |
index 5f0193b..d3f7719 100644
|
|
|
5c2e41 |
--- a/multipathd/main.c
|
|
|
5c2e41 |
+++ b/multipathd/main.c
|
|
|
5c2e41 |
@@ -12,8 +12,6 @@
|
|
|
5c2e41 |
#include <sys/types.h>
|
|
|
5c2e41 |
#include <fcntl.h>
|
|
|
5c2e41 |
#include <errno.h>
|
|
|
5c2e41 |
-#include <sys/time.h>
|
|
|
5c2e41 |
-#include <sys/resource.h>
|
|
|
5c2e41 |
#include <limits.h>
|
|
|
5c2e41 |
#include <linux/oom.h>
|
|
|
5c2e41 |
#include <libudev.h>
|
|
|
5c2e41 |
@@ -2663,33 +2661,10 @@ child (void * param)
|
|
|
5c2e41 |
|
|
|
5c2e41 |
envp = getenv("LimitNOFILE");
|
|
|
5c2e41 |
|
|
|
5c2e41 |
- if (envp) {
|
|
|
5c2e41 |
+ if (envp)
|
|
|
5c2e41 |
condlog(2,"Using systemd provided open fds limit of %s", envp);
|
|
|
5c2e41 |
- } else if (conf->max_fds) {
|
|
|
5c2e41 |
- struct rlimit fd_limit;
|
|
|
5c2e41 |
-
|
|
|
5c2e41 |
- if (getrlimit(RLIMIT_NOFILE, &fd_limit) < 0) {
|
|
|
5c2e41 |
- condlog(0, "can't get open fds limit: %s",
|
|
|
5c2e41 |
- strerror(errno));
|
|
|
5c2e41 |
- fd_limit.rlim_cur = 0;
|
|
|
5c2e41 |
- fd_limit.rlim_max = 0;
|
|
|
5c2e41 |
- }
|
|
|
5c2e41 |
- if (fd_limit.rlim_cur < conf->max_fds) {
|
|
|
5c2e41 |
- fd_limit.rlim_cur = conf->max_fds;
|
|
|
5c2e41 |
- if (fd_limit.rlim_max < conf->max_fds)
|
|
|
5c2e41 |
- fd_limit.rlim_max = conf->max_fds;
|
|
|
5c2e41 |
- if (setrlimit(RLIMIT_NOFILE, &fd_limit) < 0) {
|
|
|
5c2e41 |
- condlog(0, "can't set open fds limit to "
|
|
|
5c2e41 |
- "%lu/%lu : %s",
|
|
|
5c2e41 |
- fd_limit.rlim_cur, fd_limit.rlim_max,
|
|
|
5c2e41 |
- strerror(errno));
|
|
|
5c2e41 |
- } else {
|
|
|
5c2e41 |
- condlog(3, "set open fds limit to %lu/%lu",
|
|
|
5c2e41 |
- fd_limit.rlim_cur, fd_limit.rlim_max);
|
|
|
5c2e41 |
- }
|
|
|
5c2e41 |
- }
|
|
|
5c2e41 |
-
|
|
|
5c2e41 |
- }
|
|
|
5c2e41 |
+ else
|
|
|
5c2e41 |
+ set_max_fds(conf->max_fds);
|
|
|
5c2e41 |
|
|
|
5c2e41 |
vecs = gvecs = init_vecs();
|
|
|
5c2e41 |
if (!vecs)
|
|
|
5c2e41 |
--
|
|
|
5c2e41 |
2.7.4
|
|
|
5c2e41 |
|