update to sanlock-2.6-6

- wdmd: fix miscellaneous build warnings
- wdmd: dynamically select working watchdog device
This commit is contained in:
Federico Simoncelli 2013-01-13 12:00:41 +01:00
parent 17309f21cd
commit 771637f425
3 changed files with 231 additions and 1 deletions

View File

@ -0,0 +1,59 @@
From e076556572ae9129807a0ae00bb63b7ff0a54807 Mon Sep 17 00:00:00 2001
From: Federico Simoncelli <fsimonce@redhat.com>
Date: Mon, 10 Dec 2012 17:33:58 +0100
Subject: [PATCH 5/6] wdmd: fix miscellaneous build warnings
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fixed warnings:
* wdmd: _FORTIFY_SOURCE requires compiling with optimization (-O)
* wdmd: initialization discards const qualifier from pointer target type
* ignoring return value of write
Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
---
wdmd/Makefile | 2 +-
wdmd/main.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/wdmd/Makefile b/wdmd/Makefile
index de6b035..bf871c5 100644
--- a/wdmd/Makefile
+++ b/wdmd/Makefile
@@ -21,7 +21,7 @@ LIB_SOURCE = client.c wdmd_sock.c
TEST_SOURCE = wdmd_client.c
-CFLAGS += -D_GNU_SOURCE -g \
+CFLAGS += -D_GNU_SOURCE -g -O2 \
-Wall \
-Wformat \
-Wformat-security \
diff --git a/wdmd/main.c b/wdmd/main.c
index ff2d57c..8a97f04 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -63,8 +63,8 @@ static int shm_fd;
static int allow_scripts;
static int kill_script_sec;
-static char *scripts_dir = (char *)"/etc/wdmd.d";
-static char *watchdog_path = "/dev/watchdog";
+static const char *scripts_dir = "/etc/wdmd.d";
+static const char *watchdog_path = "/dev/watchdog";
struct script_status {
uint64_t start;
@@ -1307,7 +1307,7 @@ static void print_debug_and_exit(void)
if (rv < 0)
exit(1);
- write(STDOUT_FILENO, debug_buf, strlen(debug_buf));
+ rv = write(STDOUT_FILENO, debug_buf, strlen(debug_buf));
exit(0);
}
--
1.7.11.7

View File

@ -0,0 +1,164 @@
From b154ab95212f2a882f9893000a184199baa8fb68 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 8 Jan 2013 14:23:14 -0600
Subject: [PATCH 6/6] wdmd: dynamically select working watchdog device
Some watchdog drivers enable both /dev/watchdog0 and
/dev/watchdog1. Sometimes, only one of them works,
and the working one is not consistent. So, we need
to test which works before deciding which to use.
Signed-off-by: David Teigland <teigland@redhat.com>
---
wdmd/main.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 82 insertions(+), 5 deletions(-)
diff --git a/wdmd/main.c b/wdmd/main.c
index 8a97f04..827d1bb 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -49,6 +49,8 @@
#define DEFAULT_SOCKET_GID 0
#define DEFAULT_SOCKET_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP)
+#define WDPATH_SIZE 64
+
static int test_interval = DEFAULT_TEST_INTERVAL;
static int fire_timeout = DEFAULT_FIRE_TIMEOUT;
static int high_priority = DEFAULT_HIGH_PRIORITY;
@@ -64,7 +66,9 @@ static int shm_fd;
static int allow_scripts;
static int kill_script_sec;
static const char *scripts_dir = "/etc/wdmd.d";
-static const char *watchdog_path = "/dev/watchdog";
+static char watchdog_path[WDPATH_SIZE];
+static char option_path[WDPATH_SIZE];
+static char saved_path[WDPATH_SIZE];
struct script_status {
uint64_t start;
@@ -928,7 +932,7 @@ static int open_dev(void)
fd = open(watchdog_path, O_WRONLY | O_CLOEXEC);
if (fd < 0) {
- log_error("no %s, load a watchdog driver", watchdog_path);
+ log_error("open %s error %d", watchdog_path, errno);
return fd;
}
@@ -969,10 +973,18 @@ static void close_watchdog(void)
dev_fd = -1;
}
-static int setup_watchdog(void)
+static int _setup_watchdog(char *path)
{
+ struct stat buf;
int rv, timeout;
+ strncpy(watchdog_path, path, WDPATH_SIZE);
+ watchdog_path[WDPATH_SIZE - 1] = '\0';
+
+ rv = stat(watchdog_path, &buf);
+ if (rv < 0)
+ return -1;
+
rv = open_dev();
if (rv < 0)
return -1;
@@ -1006,9 +1018,73 @@ static int setup_watchdog(void)
out:
log_error("%s armed with fire_timeout %d", watchdog_path, fire_timeout);
+ /* TODO: save watchdog_path in /var/run/wdmd/saved_path,
+ * and in startup read that file, copying it to saved_path */
+
return 0;
}
+/*
+ * Order of preference:
+ * . saved path (path used before daemon restart)
+ * . command line option (-w)
+ * . /dev/watchdog0
+ * . /dev/watchdog1
+ * . /dev/watchdog
+ */
+
+static int setup_watchdog(void)
+{
+ int rv;
+
+ if (!saved_path[0])
+ goto opt;
+
+ rv = _setup_watchdog(saved_path);
+ if (!rv)
+ return 0;
+
+ opt:
+ if (!option_path[0] || !strcmp(saved_path, option_path))
+ goto zero;
+
+ rv = _setup_watchdog(option_path);
+ if (!rv)
+ return 0;
+
+ zero:
+ if (!strcmp(saved_path, "/dev/watchdog0") ||
+ !strcmp(option_path, "/dev/watchdog0"))
+ goto one;
+
+ rv = _setup_watchdog((char *)"/dev/watchdog0");
+ if (!rv)
+ return 0;
+
+ one:
+ if (!strcmp(saved_path, "/dev/watchdog1") ||
+ !strcmp(option_path, "/dev/watchdog1"))
+ goto old;
+
+ rv = _setup_watchdog((char *)"/dev/watchdog1");
+ if (!rv)
+ return 0;
+
+ old:
+ if (!strcmp(saved_path, "/dev/watchdog") ||
+ !strcmp(option_path, "/dev/watchdog"))
+ goto out;
+
+ rv = _setup_watchdog((char *)"/dev/watchdog");
+ if (!rv)
+ return 0;
+
+ out:
+ log_error("no watchdog device, load a watchdog driver");
+ return -1;
+
+}
+
static void pet_watchdog(void)
{
int rv, unused;
@@ -1327,7 +1403,7 @@ static void print_usage_and_exit(int status)
printf("-s <path> path to scripts dir (default %s)\n", scripts_dir);
printf("-k <num> kill unfinished scripts after num seconds (default %d)\n",
kill_script_sec);
- printf("-w /dev/watchdog path to the watchdog device (default %s)\n", watchdog_path);
+ printf("-w /dev/watchdog path to the watchdog device to try first\n");
exit(status);
}
@@ -1394,7 +1470,8 @@ int main(int argc, char *argv[])
kill_script_sec = atoi(optarg);
break;
case 'w':
- watchdog_path = strdup(optarg);
+ snprintf(option_path, WDPATH_SIZE, "%s", optarg);
+ option_path[WDPATH_SIZE - 1] = '\0';
break;
}
}
--
1.7.11.7

View File

@ -1,6 +1,6 @@
Name: sanlock
Version: 2.6
Release: 5%{?dist}
Release: 6%{?dist}
Summary: A shared disk lock manager
Group: System Environment/Base
@ -23,6 +23,9 @@ Patch0: 0001-fix-systemd-service-files.patch
Patch1: 0002-wdmd-use-mode-775-for-run-dir.patch
Patch2: 0003-systemd-add-wdmd-dependency-for-sanlock.patch
Patch3: 0004-wdmd-make-the-watchdog-device-configurable.patch
Patch4: 0005-wdmd-fix-miscellaneous-build-warnings.patch
Patch5: 0006-wdmd-dynamically-select-working-watchdog-device.patch
%description
sanlock uses disk paxos to manage leases on shared storage.
@ -263,6 +266,10 @@ if [ $1 -ge 1 ] ; then
fi
%changelog
* Sun Jan 13 2013 Federico Simoncelli <fsimonce@redhat.com> 2.6-6
- wdmd: fix miscellaneous build warnings
- wdmd: dynamically select working watchdog device
* Wed Jan 2 2013 Federico Simoncelli <fsimonce@redhat.com> 2.6-5
- wdmd: make the watchdog device configurable