master - lvmlockd: fix check for no running lock manager
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=09c792c20667aa8d7fb...
Commit: 09c792c20667aa8d7fb2799e484d913a5eb8a147
Parent: f847fcd31a41f61dd81b30ac91f3e2720088b8f2
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Aug 29 15:18:12 2017 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Aug 29 15:18:12 2017 -0500
lvmlockd: fix check for no running lock manager
In some cases it was reporting there was no running
lock manager when there is.
---
daemons/lvmlockd/lvmlockd-core.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index f9d07c1..a921140 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -3676,7 +3676,17 @@ static int client_send_result(struct client *cl, struct action *act)
if (!gl_lsname_dlm[0])
strcat(result_flags, "NO_GL_LS,");
} else {
- strcat(result_flags, "NO_GL_LS,NO_LM");
+ int found_lm = 0;
+
+ if (lm_support_dlm() && lm_is_running_dlm())
+ found_lm++;
+ if (lm_support_sanlock() && lm_is_running_sanlock())
+ found_lm++;
+
+ if (!found_lm)
+ strcat(result_flags, "NO_GL_LS,NO_LM");
+ else
+ strcat(result_flags, "NO_GL_LS");
}
}
6 years, 3 months
master - lvmlockd: print error about starting lock manager
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f847fcd31a41f61dd81...
Commit: f847fcd31a41f61dd81b30ac91f3e2720088b8f2
Parent: c8fdc5c0877b137ed3ca1f217d8ef0fa89299a9a
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Aug 28 16:24:00 2017 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Aug 28 16:24:00 2017 -0500
lvmlockd: print error about starting lock manager
In the case where lvmlockd is running, but no lock manager
is running, we should print a specific error message about
that situation.
---
daemons/lvmlockd/lvmlockd-core.c | 2 +-
lib/locking/lvmlockd.c | 10 ++++++++++
lib/locking/lvmlockd.h | 1 +
3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index 903da7c..f9d07c1 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -3676,7 +3676,7 @@ static int client_send_result(struct client *cl, struct action *act)
if (!gl_lsname_dlm[0])
strcat(result_flags, "NO_GL_LS,");
} else {
- strcat(result_flags, "NO_GL_LS,");
+ strcat(result_flags, "NO_GL_LS,NO_LM");
}
}
diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c
index d85021c..a0e3f03 100644
--- a/lib/locking/lvmlockd.c
+++ b/lib/locking/lvmlockd.c
@@ -115,6 +115,9 @@ static void _flags_str_to_lockd_flags(const char *flags_str, uint32_t *lockd_fla
if (strstr(flags_str, "NO_GL_LS"))
*lockd_flags |= LD_RF_NO_GL_LS;
+ if (strstr(flags_str, "NO_LM"))
+ *lockd_flags |= LD_RF_NO_LM;
+
if (strstr(flags_str, "DUP_GL_LS"))
*lockd_flags |= LD_RF_DUP_GL_LS;
@@ -1362,6 +1365,9 @@ int lockd_gl_create(struct cmd_context *cmd, const char *def_mode, const char *v
log_error("Global lock failed: check that VG holding global lock exists and is started.");
else
log_error("Global lock failed: check that global lockspace is started.");
+
+ if (lockd_flags & LD_RF_NO_LM)
+ log_error("Start a lock manager, lvmlockd did not find one running.");
return 0;
}
@@ -1565,6 +1571,9 @@ int lockd_gl(struct cmd_context *cmd, const char *def_mode, uint32_t flags)
* access to lease storage.
*/
+ if (result == -ENOLS && (lockd_flags & LD_RF_NO_LM))
+ log_error("Start a lock manager, lvmlockd did not find one running.");
+
if (result == -ENOLS ||
result == -ESTARTING ||
result == -EVGKILLED ||
@@ -1583,6 +1592,7 @@ int lockd_gl(struct cmd_context *cmd, const char *def_mode, uint32_t flags)
log_error("Global lock failed: storage failed for sanlock leases");
else
log_error("Global lock failed: error %d", result);
+
return 0;
}
diff --git a/lib/locking/lvmlockd.h b/lib/locking/lvmlockd.h
index 8b282d8..cf23e9b 100644
--- a/lib/locking/lvmlockd.h
+++ b/lib/locking/lvmlockd.h
@@ -28,6 +28,7 @@
#define LD_RF_NO_GL_LS 0x00000002
#define LD_RF_WARN_GL_REMOVED 0x00000004
#define LD_RF_DUP_GL_LS 0x00000008
+#define LD_RF_NO_LM 0x00000010
/* lockd_state flags */
#define LDST_EX 0x00000001
6 years, 3 months
master - cleanup: easier to read code
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c8fdc5c0877b137ed3c...
Commit: c8fdc5c0877b137ed3ca1f217d8ef0fa89299a9a
Parent: 962874bfe2a3c3511e42fe29f0f013c780f65e63
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 11:53:26 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200
cleanup: easier to read code
Split into lines for better reading.
---
daemons/clvmd/clvmd-command.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/daemons/clvmd/clvmd-command.c b/daemons/clvmd/clvmd-command.c
index cf19dc2..2971ecb 100644
--- a/daemons/clvmd/clvmd-command.c
+++ b/daemons/clvmd/clvmd-command.c
@@ -171,8 +171,10 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
/* Check the status of the command and return the error text */
if (status) {
- *retlen = 1 + ((*buf) ? dm_snprintf(*buf, buflen, "%s",
- strerror(status)) : -1);
+ if (*buf)
+ *retlen = dm_snprintf(*buf, buflen, "%s", strerror(status)) + 1;
+ else
+ *retlen = 0;
}
return status;
6 years, 3 months
master - dmsetup: validate strtol reading
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=962874bfe2a3c3511e4...
Commit: 962874bfe2a3c3511e42fe29f0f013c780f65e63
Parent: 47b7d4a7336fa60eb25ad15b2fc3fcb5b96ce1c2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 11:48:17 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200
dmsetup: validate strtol reading
Better validation for --mode option.
---
tools/dmsetup.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 341522c..d9532fb 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -7054,7 +7054,13 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
if (c == 'M' || ind == MODE_ARG) {
_switches[MODE_ARG]++;
/* FIXME Accept modes as per chmod */
- _int_args[MODE_ARG] = (int) strtol(optarg, NULL, 8);
+ errno = 0;
+ _int_args[MODE_ARG] = (int) strtol(optarg, &s, 8);
+ if (errno || !s || *s || !_int_args[MODE_ARG]) {
+ log_error("Invalid argument for --mode: %s. %s",
+ optarg, errno ? strerror(errno) : "");
+ return 0;
+ }
}
if (ind == DEFERRED_ARG)
_switches[DEFERRED_ARG]++;
6 years, 3 months
master - dmsetup: add missing -- for option
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=47b7d4a7336fa60eb25...
Commit: 47b7d4a7336fa60eb25ad15b2fc3fcb5b96ce1c2
Parent: 26d97f179fabe0669dc10e7e16398803c323ca93
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 11:47:36 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200
dmsetup: add missing -- for option
---
tools/dmsetup.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 0fd2f2c..341522c 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -6157,7 +6157,7 @@ static struct command _dmsetup_commands[] = {
{"create", "<dev_name>\n"
"\t [-j|--major <major> -m|--minor <minor>]\n"
"\t [-U|--uid <uid>] [-G|--gid <gid>] [-M|--mode <octal_mode>]\n"
- "\t [-u|uuid <uuid>] [--addnodeonresume|--addnodeoncreate]\n"
+ "\t [-u|--uuid <uuid>] [--addnodeonresume|--addnodeoncreate]\n"
"\t [--readahead {[+]<sectors>|auto|none}]\n"
"\t [-n|--notable|--table {<table>|<table_file>}]\n"
"\tcreate --concise [<concise_device_spec_list>]", 0, 2, 0, 0, _create},
6 years, 3 months
master - reporting: validate time parsing with strtol
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=26d97f179fabe0669dc...
Commit: 26d97f179fabe0669dc10e7e16398803c323ca93
Parent: d79d9193298b04246c18dcacd8b372518eb10ffc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 11:58:33 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200
reporting: validate time parsing with strtol
Check for out-of-range numbers being result of strtol parsing.
---
lib/report/report.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 89110f0..c32df71 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -898,7 +898,12 @@ static int _translate_time_items(struct dm_report *rh, struct time_info *info,
id = ti->prop->id;
if (_is_time_num(id)) {
+ errno = 0;
num = strtol(ti->s, &end, 10);
+ if (errno) {
+ log_error("_translate_time_items: invalid time.");
+ return 0;
+ }
switch (id) {
case TIME_NUM_MULTIPLIER_NEGATIVE:
multiplier = -num;
6 years, 3 months
master - lvmlockd: log pthread_join errno code
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d79d9193298b04246c1...
Commit: d79d9193298b04246c18dcacd8b372518eb10ffc
Parent: da9a8fdedc25645706ae198bad098f366351db58
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 11:52:09 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200
lvmlockd: log pthread_join errno code
Log possible errno with pthread_join (and one close() instance).
---
daemons/lvmlockd/lvmlockd-core.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index 253d86b..903da7c 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -3539,11 +3539,15 @@ static int setup_worker_thread(void)
static void close_worker_thread(void)
{
+ int perrno;
+
pthread_mutex_lock(&worker_mutex);
worker_stop = 1;
pthread_cond_signal(&worker_cond);
pthread_mutex_unlock(&worker_mutex);
- pthread_join(worker_thread, NULL);
+
+ if ((perrno = pthread_join(worker_thread, NULL)))
+ log_error("pthread_join worker_thread error %d", perrno);
}
/* client_mutex is locked */
@@ -3769,7 +3773,8 @@ static int client_send_result(struct client *cl, struct action *act)
if (dump_fd >= 0) {
/* To avoid deadlock, send data here after the reply. */
send_dump_buf(dump_fd, dump_len);
- close(dump_fd);
+ if (close(dump_fd))
+ log_error("failed to close dump socket %d", dump_fd);
}
return rv;
@@ -4786,11 +4791,15 @@ static int setup_client_thread(void)
static void close_client_thread(void)
{
+ int perrno;
+
pthread_mutex_lock(&client_mutex);
client_stop = 1;
pthread_cond_signal(&client_cond);
pthread_mutex_unlock(&client_mutex);
- pthread_join(client_thread, NULL);
+
+ if ((perrno = pthread_join(client_thread, NULL)))
+ log_error("pthread_join client_thread error %d", perrno);
}
/*
6 years, 3 months
master - lvmlockctl: fix check for failing close
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=da9a8fdedc25645706a...
Commit: da9a8fdedc25645706ae198bad098f366351db58
Parent: 288e10cf8b990cd740fba409d6f20525209f4f43
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 11:57:49 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200
lvmlockctl: fix check for failing close
On close() failure it's -1.
---
daemons/lvmlockd/lvmlockctl.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockctl.c b/daemons/lvmlockd/lvmlockctl.c
index 7d4e072..436221d 100644
--- a/daemons/lvmlockd/lvmlockctl.c
+++ b/daemons/lvmlockd/lvmlockctl.c
@@ -379,7 +379,7 @@ static int setup_dump_socket(void)
rv = bind(s, (struct sockaddr *) &dump_addr, dump_addrlen);
if (rv < 0) {
rv = -errno;
- if (!close(s))
+ if (close(s))
log_error("failed to close dump socket");
return rv;
}
6 years, 3 months
master - lvmlockd: avoid double unlock of client_mutex
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=288e10cf8b990cd740f...
Commit: 288e10cf8b990cd740fba409d6f20525209f4f43
Parent: b3b1e788e16c77f6784f30b8e984f68792f8fa1a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 14:07:45 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:59 2017 +0200
lvmlockd: avoid double unlock of client_mutex
Avoid double unlocking of client_mutex and
and unlock client_mutex in 'else' branch
since it's already unlocked in 'if (cl->dead)' branch.
---
WHATS_NEW | 1 +
daemons/lvmlockd/lvmlockd-core.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index ac69c16..32bbc41 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.174 -
=================================
+ Avoid double unlocking of client & lockspace mutexes in lvmlockd.
Fix leaking of file descriptor for non-blocking filebased locking.
Fix check for 2nd mda at end of disk fits if using pvcreate --restorefile.
Use maximum metadataarea size that fits with pvcreate --restorefile.
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index 36d84e2..253d86b 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -4761,8 +4761,8 @@ static void *client_thread_main(void *arg_in)
} else {
pthread_mutex_unlock(&cl->mutex);
}
- }
- pthread_mutex_unlock(&client_mutex);
+ } else
+ pthread_mutex_unlock(&client_mutex);
}
out:
return NULL;
6 years, 3 months
master - daemonize: more unified code
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b3b1e788e16c77f6784...
Commit: b3b1e788e16c77f6784f30b8e984f68792f8fa1a
Parent: 5de944420224f3b629e843f9c190132ed9ff3dca
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Aug 25 11:55:38 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Aug 25 14:20:57 2017 +0200
daemonize: more unified code
ATM we have several instances of daemonizing code.
Each has its 'special' logic so not completely easy
to unify them all into a single routine.
Start to unify them and use one strategy for rediricting
all input/outpus to /dev/null - use 'dup2' function for this
and open /dev/null before fork to make sure it's available.
---
daemons/clvmd/clvmd.c | 26 ++++++++++----------------
libdaemon/server/daemon-server.c | 21 +++++++++++++++------
2 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 79aa939..46f5f44 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -1105,31 +1105,25 @@ static void be_daemon(int timeout)
break;
default: /* Parent */
+ (void) close(devnull);
(void) close(child_pipe[1]);
- wait_for_child(child_pipe[0], timeout);
+ wait_for_child(child_pipe[0], timeout); /* noreturn */
}
/* Detach ourself from the calling environment */
- if (close(0) || close(1) || close(2)) {
- perror("Error closing terminal FDs");
- exit(4);
- }
- setsid();
+ (void) dup2(devnull, STDIN_FILENO);
+ (void) dup2(devnull, STDOUT_FILENO);
+ (void) dup2(devnull, STDERR_FILENO);
+
+ if (devnull > STDERR_FILENO)
+ (void) close(devnull);
- if (dup2(devnull, 0) < 0 || dup2(devnull, 1) < 0
- || dup2(devnull, 2) < 0) {
- perror("Error setting terminal FDs to /dev/null");
- log_error("Error setting terminal FDs to /dev/null: %m");
- exit(5);
- }
- if ((devnull > STDERR_FILENO) && close(devnull)) {
- log_sys_error("close", "/dev/null");
- exit(7);
- }
if (chdir("/")) {
log_error("Error setting current directory to /: %m");
exit(6);
}
+
+ setsid();
}
static int verify_message(char *buf, int len)
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index 6fdf195..0950c2e 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -334,6 +334,11 @@ static void _daemonise(daemon_state s)
struct timeval tval;
sigset_t my_sigset;
+ if ((fd = open("/dev/null", O_RDWR)) == -1) {
+ fprintf(stderr, "Unable to open /dev/null.\n");
+ exit(EXIT_FAILURE);
+ }
+
sigemptyset(&my_sigset);
if (sigprocmask(SIG_SETMASK, &my_sigset, NULL) < 0) {
fprintf(stderr, "Unable to restore signals.\n");
@@ -350,6 +355,7 @@ static void _daemonise(daemon_state s)
break;
default:
+ (void) close(fd);
/* Wait for response from child */
while (!waitpid(pid, &child_status, WNOHANG) && !_shutdown_requested) {
tval.tv_sec = 0;
@@ -374,12 +380,20 @@ static void _daemonise(daemon_state s)
if (chdir("/"))
exit(1);
+ (void) dup2(fd, STDIN_FILENO);
+ (void) dup2(fd, STDOUT_FILENO);
+ (void) dup2(fd, STDERR_FILENO);
+
+ if (fd > STDERR_FILENO)
+ (void) close(fd);
+
+ /* Switch to sysconf(_SC_OPEN_MAX) ?? */
if (getrlimit(RLIMIT_NOFILE, &rlim) < 0)
fd = 256; /* just have to guess */
else
fd = rlim.rlim_cur;
- for (--fd; fd >= 0; fd--) {
+ for (--fd; fd > STDERR_FILENO; fd--) {
#ifdef __linux__
/* Do not close fds preloaded by systemd! */
if (_systemd_activation && fd == SD_FD_SOCKET_SERVER)
@@ -388,11 +402,6 @@ static void _daemonise(daemon_state s)
(void) close(fd);
}
- if ((open("/dev/null", O_RDONLY) < 0) ||
- (open("/dev/null", O_WRONLY) < 0) ||
- (open("/dev/null", O_WRONLY) < 0))
- exit(1);
-
setsid();
}
6 years, 3 months