python/sanlock.c | 2
src/cmd.c | 8 +-
src/diskio.c | 18 +++---
src/log.h | 18 +++++-
src/main.c | 139 ++++++++++++++++++++++++++++++++++---------------
src/sanlock.8 | 14 +++-
src/sanlock_internal.h | 6 +-
7 files changed, 144 insertions(+), 61 deletions(-)
New commits:
commit acfa6febfd0eec904fd379a1bc4bbcaa6f0d3176
Author: David Weber <wb(a)munzinger.de>
Date: Mon Oct 8 10:25:16 2012 -0500
Replace restrict field name with restricted
"restrict" is a keyword in C99 so it mustn't be used.
diff --git a/src/cmd.c b/src/cmd.c
index 1f60e04..d443e92 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -303,7 +303,7 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca)
token->host_generation = spi.host_generation;
token->pid = cl_pid;
token->io_timeout = spi.io_timeout;
- if (cl->restrict & SANLK_RESTRICT_SIGKILL)
+ if (cl->restricted & SANLK_RESTRICT_SIGKILL)
token->flags |= T_RESTRICT_SIGKILL;
/* save a record of what this token_id is for later debugging */
@@ -1399,7 +1399,7 @@ static int print_state_client(struct client *cl, int ci, char *str)
"fd=%d "
"pid=%d "
"flags=%x "
- "restrict=%x "
+ "restricted=%x "
"cmd_active=%d "
"cmd_last=%d "
"pid_dead=%d "
@@ -1411,7 +1411,7 @@ static int print_state_client(struct client *cl, int ci, char *str)
cl->fd,
cl->pid,
cl->flags,
- cl->restrict,
+ cl->restricted,
cl->cmd_active,
cl->cmd_last,
cl->pid_dead,
@@ -1749,7 +1749,7 @@ static void cmd_restrict(int ci, int fd, struct sm_header *h_recv)
log_debug("cmd_restrict ci %d fd %d pid %d flags %x",
ci, fd, client[ci].pid, h_recv->cmd_flags);
- client[ci].restrict = h_recv->cmd_flags;
+ client[ci].restricted = h_recv->cmd_flags;
send_result(fd, h_recv, 0);
}
diff --git a/src/main.c b/src/main.c
index 33f90a7..87c784d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -253,7 +253,7 @@ static void _client_free(int ci)
cl->need_free = 0;
cl->kill_count = 0;
cl->kill_last = 0;
- cl->restrict = 0;
+ cl->restricted = 0;
cl->flags = 0;
memset(cl->owner_name, 0, sizeof(cl->owner_name));
memset(cl->killpath, 0, SANLK_HELPER_PATH_LEN);
@@ -631,10 +631,10 @@ static void kill_pids(struct space *sp)
* sigkill will be used in place of sigterm if restricted
*/
- if ((sig == SIGKILL) && (cl->restrict & SANLK_RESTRICT_SIGKILL))
+ if ((sig == SIGKILL) && (cl->restricted & SANLK_RESTRICT_SIGKILL))
sig = SIGTERM;
- if ((sig == SIGTERM) && (cl->restrict & SANLK_RESTRICT_SIGTERM))
+ if ((sig == SIGTERM) && (cl->restricted & SANLK_RESTRICT_SIGTERM))
sig = SIGKILL;
do_kill = 1;
@@ -1138,7 +1138,7 @@ static void process_connection(int ci)
ci, rv, h.magic, SM_MAGIC);
goto dead;
}
- if (client[ci].restrict & SANLK_RESTRICT_ALL) {
+ if (client[ci].restricted & SANLK_RESTRICT_ALL) {
log_error("ci %d fd %d pid %d cmd %d restrict all",
ci, client[ci].fd, client[ci].pid, h.cmd);
goto dead;
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 53e5866..65496ff 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -67,7 +67,7 @@ struct sync_disk {
* 'struct resource' keeps track of resources globally, resources list
*/
-#define T_RESTRICT_SIGKILL 0x00000001 /* inherited from client->restrict */
+#define T_RESTRICT_SIGKILL 0x00000001 /* inherited from client->restricted */
#define T_LS_DEAD 0x00000002 /* don't bother trying to release if ls is dead */
struct token {
@@ -215,7 +215,7 @@ struct client {
int need_free;
int kill_count;
uint32_t flags;
- uint32_t restrict;
+ uint32_t restricted;
uint64_t kill_last;
char owner_name[SANLK_NAME_LEN+1];
char killpath[SANLK_HELPER_PATH_LEN];
commit 5e76f09f9bcecbc9349dc3ee7faf43bcc7c1376c
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Oct 5 10:13:52 2012 -0500
sanlock: print command output to stdout
instead of stderr
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/log.h b/src/log.h
index db6d275..10b8c36 100644
--- a/src/log.h
+++ b/src/log.h
@@ -50,7 +50,7 @@ void copy_log_dump(char *buf, int *len);
#define log_tool(fmt, args...) \
do { \
- fprintf(stderr, fmt "\n", ##args); \
+ printf(fmt "\n", ##args); \
} while (0)
#endif
commit d05aac412b50baee23d2a0847e1676040d2efbff
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Oct 4 16:47:58 2012 -0500
sanlock: client add_lockspace with timeout
When a -o io timeout value not equal to the
default (10) is used, the command will use
the add_lockspace_timeout api.
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index a0b5145..33f90a7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2177,9 +2177,16 @@ static int do_client(void)
break;
case ACT_ADD_LOCKSPACE:
- log_tool("add_lockspace");
- rv = sanlock_add_lockspace(&com.lockspace, 0);
- log_tool("add_lockspace done %d", rv);
+ if (com.io_timeout_arg != DEFAULT_IO_TIMEOUT) {
+ log_tool("add_lockspace_timeout %d", com.io_timeout_arg);
+ rv = sanlock_add_lockspace_timeout(&com.lockspace, 0,
+ com.io_timeout_arg);
+ log_tool("add_lockspace_timeout done %d", rv);
+ } else {
+ log_tool("add_lockspace");
+ rv = sanlock_add_lockspace(&com.lockspace, 0);
+ log_tool("add_lockspace done %d", rv);
+ }
break;
case ACT_INQ_LOCKSPACE:
commit da94fe800c843b467f926420ccbe9961e8289f46
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Oct 4 16:26:54 2012 -0500
sanlock: fix aborted command clearing
When clearing the remainder of an aborted
command, non-blocking recv is used to avoid
blocking the main thread, but this means it
needs to do a minimal amount of retrying when
EAGAIN is returned. It wasn't retrying at all,
so the remainder of the message was handled as
a new command, which caused errors when the
fragment was found to have a bad magic number.
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index 522ae6a..a0b5145 100644
--- a/src/main.c
+++ b/src/main.c
@@ -396,13 +396,22 @@ void client_recv_all(int ci, struct sm_header *h_recv, int pos)
{
char trash[64];
int rem = h_recv->length - sizeof(struct sm_header) - pos;
- int rv, error = 0, total = 0;
+ int rv, error = 0, total = 0, retries = 0;
if (!rem)
return;
while (1) {
rv = recv(client[ci].fd, trash, sizeof(trash), MSG_DONTWAIT);
+
+ if (rv == -1 && errno == EAGAIN) {
+ usleep(1000);
+ if (retries < 20) {
+ retries++;
+ continue;
+ }
+ }
+
if (rv == -1)
error = errno;
if (rv <= 0)
@@ -413,8 +422,8 @@ void client_recv_all(int ci, struct sm_header *h_recv, int pos)
break;
}
- log_debug("recv_all %d,%d,%d pos %d rv %d error %d rem %d total %d",
- ci, client[ci].fd, client[ci].pid, pos, rv, error, rem, total);
+ log_debug("recv_all %d,%d,%d pos %d rv %d error %d retries %d rem %d total
%d",
+ ci, client[ci].fd, client[ci].pid, pos, rv, error, retries, rem, total);
}
void send_result(int fd, struct sm_header *h_recv, int result);
@@ -998,6 +1007,8 @@ static void process_cmd_thread_registered(int ci_in, struct sm_header
*h_recv)
break;
}
if (ci_target < 0) {
+ log_error("cmd %d target pid %d not found",
+ h_recv->cmd, h_recv->data2);
result = -ESRCH;
goto fail;
}
commit 85887f4d8e22fbf57e9012ec6dccd2d17a2ff21a
Author: David Teigland <teigland(a)redhat.com>
Date: Mon Oct 1 11:47:46 2012 -0500
sanlock: update man page
to reflect recent changes
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index 46aa5ef..522ae6a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1759,8 +1759,8 @@ static void print_usage(void)
printf(" -t <num> max worker threads (%d)\n",
DEFAULT_MAX_WORKER_THREADS);
printf(" -g <sec> seconds for graceful recovery (%d)\n",
DEFAULT_GRACE_SEC);
printf(" -w 0|1 use watchdog through wdmd (%d)\n",
DEFAULT_USE_WATCHDOG);
- printf(" -h 0|1 use high priority features (%d)\n",
DEFAULT_HIGH_PRIORITY);
- printf(" (realtime scheduling, mlockall)\n");
+ printf(" -h 0|1 use high priority (RR) scheduling (%d)\n",
DEFAULT_HIGH_PRIORITY);
+ printf(" -l <num> use mlockall (0 none, 1 current, 2 current and
future) (2)\n");
printf(" -a 0|1 use async io (%d)\n", DEFAULT_USE_AIO);
printf(" -o 0|1 io timeout in seconds (%d)\n", DEFAULT_IO_TIMEOUT);
printf("\n");
diff --git a/src/sanlock.8 b/src/sanlock.8
index e716264..a6bf6c4 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -234,7 +234,10 @@ seconds for graceful recovery
use watchdog through wdmd
.BR -h " 0|1"
-use high priority features (realtime scheduling, mlockall)
+use high priority (RR) scheduling
+
+.BR -l " num"
+use mlockall (0 none, 1 current, 2 current and future)
.BR \-a " 0|1"
use async i/o
@@ -252,10 +255,10 @@ Print processes, lockspaces, and resources being manged by the
sanlock
daemon. Add -D to show extra internal daemon status for debugging.
Add -o p to show resources by pid, or -o s to show resources by lockspace.
-.BR "sanlock client host_status -s" " LOCKSPACE"
+.B sanlock client host_status
Print state of host_id delta leases read during the last renewal.
-Only lockspace_name is used from the LOCKSPACE argument.
+State of all lockspaces is shown (use -s to select one).
Add -D to show extra internal daemon status for debugging.
.B sanlock client log_dump
@@ -491,7 +494,10 @@ take:
\fB1\fP (KILL_PID): kill the process holding the resource lease. When the
process has exited, the resource lease will be released, and can then be
-acquired by anyone.
+acquired by anyone. The kill signal is SIGKILL (or SIGTERM if SIGKILL
+is restricted.)
+
+\fB2\fP (SIGUSR1): send SIGUSR1 to the process holding the resource lease.
.SS Graceful recovery
commit cc2fd83accfd6c9389dd8adc53ec58ab5b083f82
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Sep 28 14:30:27 2012 -0500
sanlock: change log level for startup and io timeouts
make daemon startup and io timeout messages a warning instead
of an error, so they are written to sanlock.log,
not /var/log/messages (which should be for real errors).
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/diskio.c b/src/diskio.c
index f187ea4..7647094 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -348,7 +348,7 @@ static struct aicb *find_callback_slot(struct task *task, int ioto)
struct aicb *ev_aicb = container_of(ev_iocb, struct aicb, iocb);
int op = ev_iocb ? ev_iocb->aio_lio_opcode : -1;
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld old free",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld old free",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2);
ev_aicb->used = 0;
free(ev_aicb->buf);
@@ -429,20 +429,20 @@ static int do_linux_aio(int fd, uint64_t offset, char *buf, int
len,
ev_aicb->used = 0;
if (ev_iocb != iocb) {
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld other free",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld other free",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2);
free(ev_aicb->buf);
ev_aicb->buf = NULL;
goto retry;
}
if ((int)event.res < 0) {
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld match res",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld match res",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2);
rv = event.res;
goto out;
}
if (event.res != len) {
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld match len %d",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld match len %d",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2, len);
rv = -EMSGSIZE;
goto out;
@@ -466,7 +466,7 @@ static int do_linux_aio(int fd, uint64_t offset, char *buf, int len,
task->to_count++;
- log_taske(task, "aio timeout %d %p:%p:%p ioto %d to_count %d",
+ log_taskw(task, "aio timeout %d %p:%p:%p ioto %d to_count %d",
cmd, aicb, iocb, buf, ioto, task->to_count);
rv = io_cancel(task->aio_ctx, iocb, &event);
@@ -802,26 +802,26 @@ int read_iobuf_reap(int fd, uint64_t offset, char *iobuf, int
iobuf_len,
ev_aicb->used = 0;
if (ev_iocb != iocb) {
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld other free r",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld other free r",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2);
free(ev_aicb->buf);
ev_aicb->buf = NULL;
goto retry;
}
if ((int)event.res < 0) {
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld match res r",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld match res r",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2);
rv = event.res;
goto out;
}
if (event.res != iobuf_len) {
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld match len %d r",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld match len %d r",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2, iobuf_len);
rv = -EMSGSIZE;
goto out;
}
- log_taske(task, "aio collect %d %p:%p:%p result %ld:%ld match reap",
+ log_taskw(task, "aio collect %d %p:%p:%p result %ld:%ld match reap",
op, ev_aicb, ev_iocb, ev_aicb->buf, event.res, event.res2);
rv = 0;
diff --git a/src/log.h b/src/log.h
index 2421597..db6d275 100644
--- a/src/log.h
+++ b/src/log.h
@@ -9,6 +9,21 @@
#ifndef __LOG_H__
#define __LOG_H__
+/*
+ * Log levels are used mainly to indicate where the message
+ * should be recorded:
+ *
+ * log_error() write to /var/log/messages and /var/log/sanlock.log
+ * log_level(WARNING) write to /var/log/sanlock.log
+ * log_debug() write to incore buffer, not to file
+ *
+ * Anything in /var/log/messages should not happen and should be reported.
+ * So anything we want to visible and reported should be LOG_ERR.
+ *
+ * If we want to log something to assist in debugging, but not be reported,
+ * it should be LOG_WARNING (goes only to sanlock.log)
+ */
+
void log_level(uint32_t space_id, uint32_t token_id, char *name_in, int level, const char
*fmt, ...)
__attribute__((format(printf, 5, 6)));
@@ -27,6 +42,7 @@ void copy_log_dump(char *buf, int *len);
#define log_errst(space, token, fmt, args...) log_level(space->space_id,
token->token_id, NULL, LOG_ERR, fmt, ##args)
#define log_taske(task, fmt, args...) log_level(0, 0, task->name, LOG_ERR,
fmt, ##args)
+#define log_taskw(task, fmt, args...) log_level(0, 0, task->name, LOG_WARNING,
fmt, ##args)
#define log_taskd(task, fmt, args...) log_level(0, 0, task->name, LOG_DEBUG,
fmt, ##args)
/* use log_tool for tool actions (non-daemon), and for daemon until
diff --git a/src/main.c b/src/main.c
index eea6bb3..46aa5ef 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1625,9 +1625,8 @@ static int do_daemon(void)
setup_groups();
- log_error("sanlock daemon started %s host %s time %llu",
- RELEASE_VERSION, our_host_name_global,
- (unsigned long long)time(NULL));
+ log_level(0, 0, NULL, LOG_WARNING, "sanlock daemon started %s host %s",
+ RELEASE_VERSION, our_host_name_global);
setup_priority();
commit 3cc457d215713035cf9aa2024841184913c350d7
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Thu Sep 27 12:06:03 2012 -0400
sanlock: use signal handler for all terminating signals
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index b85eca6..eea6bb3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1242,7 +1242,9 @@ static int setup_listener(void)
return -1;
}
-static void sigterm_handler(int sig GNUC_UNUSED)
+static void sigterm_handler(int sig GNUC_UNUSED,
+ siginfo_t *info GNUC_UNUSED,
+ void *ctx GNUC_UNUSED)
{
external_shutdown = 1;
}
@@ -1438,6 +1440,25 @@ static void setup_groups(void)
free(pgroup);
}
+static void setup_signals(void)
+{
+ struct sigaction act;
+ int rv, i, sig_list[] = { SIGHUP, SIGINT, SIGTERM, 0 };
+
+ memset(&act, 0, sizeof(act));
+
+ act.sa_flags = SA_SIGINFO;
+ act.sa_sigaction = sigterm_handler;
+
+ for (i = 0; sig_list[i] != 0; i++) {
+ rv = sigaction(sig_list[i], &act, NULL);
+ if (rv < 0) {
+ log_error("cannot set the signal handler for: %i", sig_list[i]);
+ exit(EXIT_FAILURE);
+ }
+ }
+}
+
/*
* first pipe for daemon to send requests to helper; they are not acknowledged
* and the daemon does not get any result back for the requests.
@@ -1563,7 +1584,6 @@ static void helper_dead(int ci GNUC_UNUSED)
static int do_daemon(void)
{
- struct sigaction act;
int fd, rv;
/* TODO: copy comprehensive daemonization method from libvirtd */
@@ -1594,12 +1614,7 @@ static int do_daemon(void)
goto out_logging;
strcpy(client[helper_ci].owner_name, "helper");
- memset(&act, 0, sizeof(act));
- act.sa_handler = sigterm_handler;
- rv = sigaction(SIGTERM, &act, NULL);
- if (rv < 0)
- return rv;
-
+ setup_signals();
setup_logging();
fd = lockfile(SANLK_RUN_DIR, SANLK_LOCKFILE_NAME, com.uid, com.gid);
commit b08e8726c7e854921ec6d8d590c77d4e4d18c4b0
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Thu Sep 27 12:06:02 2012 -0400
python: fix the tuple parsing for py_add_lockspace
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index cefe3d4..e32fab3 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -288,7 +288,7 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|ki", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|kIi", kwlist,
&lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
&iotimeout,
&async)) {
return NULL;
commit abaf80bbf21b9c771684def60f73f3f1a287bc20
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Thu Sep 27 15:46:59 2012 -0400
sanlock: configuring the core dump output
All the setrlimit calls have been moved to a new setup_limits function
that is called regardless the presence of the -U and -G options.
The new RLIMIT_CORE limit is set to allow the core dump to be written
in case of a crash (for more details: man core).
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index 9645e3e..b85eca6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@
#include <pwd.h>
#include <grp.h>
#include <sys/types.h>
+#include <sys/prctl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/socket.h>
@@ -1328,19 +1329,10 @@ static void setup_host_name(void)
uuid, name.nodename);
}
-static void setup_groups(void)
+static void setup_limits(void)
{
- int rv, i, j, h;
- int pngroups, sngroups, ngroups_max;
- gid_t *pgroup, *sgroup;
- struct rlimit rlim;
-
- if (!com.uname || !com.gname)
- return;
-
- /* before switching to a different user/group we must configure
- the limits for memlock and rtprio */
- rlim.rlim_cur = rlim.rlim_max= -1;
+ int rv;
+ struct rlimit rlim = { .rlim_cur = -1, .rlim_max= -1 };
rv = setrlimit(RLIMIT_MEMLOCK, &rlim);
if (rv < 0) {
@@ -1354,6 +1346,22 @@ static void setup_groups(void)
exit(EXIT_FAILURE);
}
+ rv = setrlimit(RLIMIT_CORE, &rlim);
+ if (rv < 0) {
+ log_error("cannot set the limits for core dumps %i", errno);
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void setup_groups(void)
+{
+ int rv, i, j, h;
+ int pngroups, sngroups, ngroups_max;
+ gid_t *pgroup, *sgroup;
+
+ if (!com.uname || !com.gname)
+ return;
+
ngroups_max = sysconf(_SC_NGROUPS_MAX);
if (ngroups_max < 0) {
log_error("cannot get the max number of groups %i", errno);
@@ -1417,6 +1425,15 @@ static void setup_groups(void)
log_error("cannot set user id to %i errno %i", com.uid, errno);
}
+ /* When a program is owned by a user (group) other than the real user
+ * (group) ID of the process, the PR_SET_DUMPABLE option gets cleared.
+ * See RLIMIT_CORE in setup_limits and man 5 core.
+ */
+ rv = prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
+ if (rv < 0) {
+ log_error("cannot set dumpable process errno %i", errno);
+ }
+
out:
free(pgroup);
}
@@ -1558,6 +1575,7 @@ static int do_daemon(void)
}
}
+ setup_limits();
setup_helper();
/* main task never does disk io, so we don't really need to set
commit aff1f7713ca8f3836e1b76611b3222628f9c2b84
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Sep 26 14:02:00 2012 -0500
sanlock: configurable mlockall level
-l 0 -> no mlockall
-l 1 -> mlockall(CURRENT)
-l 2 -> mlockall(CURRENT|FUTURE)
The default is now set to 1 (was 2).
CURRENT|FUTURE results in each pthread_create using
8MB of RSS for the thread stack. CURRENT alone does
not.
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index dea78f7..9645e3e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1249,16 +1249,21 @@ static void sigterm_handler(int sig GNUC_UNUSED)
static void setup_priority(void)
{
struct sched_param sched_param;
- int rv;
+ int rv = 0;
- if (!com.high_priority)
- return;
+ if (com.mlock_level == 1)
+ rv = mlockall(MCL_CURRENT);
+ else if (com.mlock_level == 2)
+ rv = mlockall(MCL_CURRENT | MCL_FUTURE);
- rv = mlockall(MCL_CURRENT | MCL_FUTURE);
if (rv < 0) {
- log_error("mlockall failed: %s", strerror(errno));
+ log_error("mlockall %d failed: %s",
+ com.mlock_level, strerror(errno));
}
+ if (!com.high_priority)
+ return;
+
rv = sched_get_priority_max(SCHED_RR);
if (rv < 0) {
log_error("could not get max scheduler priority err %d", errno);
@@ -1956,6 +1961,9 @@ static int read_command_line(int argc, char *argv[])
case 'h':
com.high_priority = atoi(optionarg);
break;
+ case 'l':
+ com.mlock_level = atoi(optionarg);
+ break;
case 'o':
if (com.action == ACT_STATUS) {
com.sort_arg = *optionarg;
@@ -2386,6 +2394,7 @@ int main(int argc, char *argv[])
memset(&com, 0, sizeof(com));
com.use_watchdog = DEFAULT_USE_WATCHDOG;
com.high_priority = DEFAULT_HIGH_PRIORITY;
+ com.mlock_level = DEFAULT_MLOCK_LEVEL;
com.max_worker_threads = DEFAULT_MAX_WORKER_THREADS;
com.io_timeout_arg = DEFAULT_IO_TIMEOUT;
com.aio_arg = DEFAULT_USE_AIO;
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 2c67fc8..53e5866 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -239,6 +239,7 @@ EXTERN struct client *client;
#define DEFAULT_GRACE_SEC 40
#define DEFAULT_USE_WATCHDOG 1
#define DEFAULT_HIGH_PRIORITY 1
+#define DEFAULT_MLOCK_LEVEL 1 /* 1=CURRENT, 2=CURRENT|FUTURE */
#define DEFAULT_SOCKET_UID 0
#define DEFAULT_SOCKET_GID 0
#define DEFAULT_SOCKET_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
@@ -254,6 +255,7 @@ struct command_line {
int quiet_fail;
int use_watchdog;
int high_priority;
+ int mlock_level;
int max_worker_threads;
int aio_arg;
int io_timeout_arg;