python/sanlock.c
by David Teigland
python/sanlock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit 7c9a67b725a7a6525a6a653a816239d3c49f90bd
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Nov 30 12:22:00 2012 -0500
python: fix typo for the offset parameter
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index e32fab3..c57909a 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -183,7 +183,7 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
const char *lockspace, *path;
struct sanlk_lockspace ls;
- static char *kwlist[] = {"lockspace", "path", "offest",
+ static char *kwlist[] = {"lockspace", "path", "offset",
"max_hosts", "num_hosts", "use_aio", NULL};
/* initialize lockspace structure */
10 years, 6 months
[PATCH 1/3] python: fix typo for the offset parameter
by Federico Simoncelli
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
python/sanlock.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index e32fab3..c57909a 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -183,7 +183,7 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
const char *lockspace, *path;
struct sanlk_lockspace ls;
- static char *kwlist[] = {"lockspace", "path", "offest",
+ static char *kwlist[] = {"lockspace", "path", "offset",
"max_hosts", "num_hosts", "use_aio", NULL};
/* initialize lockspace structure */
--
1.7.1
10 years, 6 months
src/client.c src/cmd.c src/delta_lease.c src/delta_lease.h src/direct.c src/direct.h src/direct_lib.c src/lockspace.c src/main.c src/paxos_lease.c src/paxos_lease.h src/sanlock.8 src/sanlock_admin.h src/sanlock_direct.h src/sanlock_internal.h src/sanlock_sock.h
by David Teigland
src/client.c | 216 ++++++++++++++++++++++++++++++++++++++++++-------
src/cmd.c | 192 ++++++++++++++++++++++++++++++++++++++++---
src/delta_lease.c | 59 ++++++++++++-
src/delta_lease.h | 7 +
src/direct.c | 49 +++++------
src/direct.h | 11 +-
src/direct_lib.c | 36 +++++++-
src/lockspace.c | 2
src/main.c | 60 +++++++++++--
src/paxos_lease.c | 32 +++++++
src/paxos_lease.h | 4
src/sanlock.8 | 41 ++++++---
src/sanlock_admin.h | 77 +++++++++++++++++
src/sanlock_direct.h | 18 ++++
src/sanlock_internal.h | 1
src/sanlock_sock.h | 40 ++++-----
16 files changed, 729 insertions(+), 116 deletions(-)
New commits:
commit 185bc1f850ead0092d20d6dacc647a40ebdd1205
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Nov 21 09:14:18 2012 -0600
sanlock: read and write apis for lockspace and resource
- write_lockspace includes an arg to specify the io timeout
written in the disk record.
- read_lockspace provides the io timeout from the disk record.
- read_lockspace/resource only require path and offset input.
If host_id is zero or unspecified, host_id 1 is used.
If other parameters are specified, they are used and verified.
# sanlock client init -s s1:0:/dev/vg/leases:0
# sanlock client init -r s1:r1:/dev/vg/leases:1048576
# sanlock client read -s ::/dev/vg/leases:0
s s1:1:/dev/vg/leases:0
io_timeout 10
# sanlock client read -r ::/dev/vg/leases:1048576
r s1:r1:/dev/vg/leases:1048576:0
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/client.c b/src/client.c
index 48e1505..ae73226 100644
--- a/src/client.c
+++ b/src/client.c
@@ -187,50 +187,157 @@ int sanlock_align(struct sanlk_disk *disk)
return rv;
}
-int sanlock_init(struct sanlk_lockspace *ls,
- struct sanlk_resource *res,
- int max_hosts, int num_hosts)
+int sanlock_read_lockspace(struct sanlk_lockspace *ls, uint32_t flags, uint32_t *io_timeout)
{
- int rv, fd, cmd, datalen;
+ struct sm_header h;
+ int rv, fd;
- if (!ls && !res)
+ if (!ls || !ls->host_id_disk.path[0])
return -EINVAL;
rv = connect_socket(&fd);
if (rv < 0)
return rv;
- if (ls && ls->host_id_disk.path[0]) {
- cmd = SM_CMD_INIT_LOCKSPACE;
- datalen = sizeof(struct sanlk_lockspace);
- } else {
- cmd = SM_CMD_INIT_RESOURCE;
- datalen = sizeof(struct sanlk_resource) +
- sizeof(struct sanlk_disk) * res->num_disks;
+ rv = send_header(fd, SM_CMD_READ_LOCKSPACE, flags,
+ sizeof(struct sanlk_lockspace),
+ 0, 0);
+ if (rv < 0)
+ goto out;
+
+ rv = send(fd, ls, sizeof(struct sanlk_lockspace), 0);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ /* receive result, io_timeout and ls struct */
+
+ memset(&h, 0, sizeof(struct sm_header));
+
+ rv = recv(fd, &h, sizeof(h), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
}
- rv = send_header(fd, cmd, 0, datalen, max_hosts, num_hosts);
+ if (rv != sizeof(h)) {
+ rv = -1;
+ goto out;
+ }
+
+ rv = (int)h.data;
if (rv < 0)
goto out;
- if (ls) {
- rv = send(fd, ls, sizeof(struct sanlk_lockspace), 0);
- if (rv < 0) {
- rv = -errno;
- goto out;
- }
- } else {
- rv = send(fd, res, sizeof(struct sanlk_resource), 0);
- if (rv < 0) {
- rv = -errno;
- goto out;
- }
+ rv = recv(fd, ls, sizeof(struct sanlk_lockspace), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
- rv = send(fd, res->disks, sizeof(struct sanlk_disk) * res->num_disks, 0);
- if (rv < 0) {
- rv = -errno;
- goto out;
- }
+ if (rv != sizeof(struct sanlk_lockspace)) {
+ rv = -1;
+ goto out;
+ }
+
+ *io_timeout = h.data2;
+ rv = (int)h.data;
+ out:
+ close(fd);
+ return rv;
+}
+
+int sanlock_read_resource(struct sanlk_resource *res, uint32_t flags)
+{
+ struct sm_header h;
+ int rv, fd;
+
+ if (!res || !res->num_disks || res->num_disks > SANLK_MAX_DISKS ||
+ !res->disks[0].path[0])
+ return -EINVAL;
+
+ rv = connect_socket(&fd);
+ if (rv < 0)
+ return rv;
+
+ rv = send_header(fd, SM_CMD_READ_RESOURCE, flags,
+ sizeof(struct sanlk_resource) +
+ sizeof(struct sanlk_disk) * res->num_disks,
+ 0, 0);
+ if (rv < 0)
+ goto out;
+
+ rv = send(fd, res, sizeof(struct sanlk_resource), 0);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ rv = send(fd, res->disks, sizeof(struct sanlk_disk) * res->num_disks, 0);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ /* receive result and res struct */
+
+ memset(&h, 0, sizeof(struct sm_header));
+
+ rv = recv(fd, &h, sizeof(h), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ if (rv != sizeof(h)) {
+ rv = -1;
+ goto out;
+ }
+
+ rv = (int)h.data;
+ if (rv < 0)
+ goto out;
+
+ rv = recv(fd, res, sizeof(struct sanlk_resource), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ if (rv != sizeof(struct sanlk_resource)) {
+ rv = -1;
+ goto out;
+ }
+
+ rv = (int)h.data;
+ out:
+ close(fd);
+ return rv;
+}
+
+int sanlock_write_lockspace(struct sanlk_lockspace *ls, int max_hosts,
+ uint32_t flags, uint32_t io_timeout)
+{
+ int rv, fd;
+
+ if (!ls || !ls->host_id_disk.path[0])
+ return -EINVAL;
+
+ rv = connect_socket(&fd);
+ if (rv < 0)
+ return rv;
+
+ rv = send_header(fd, SM_CMD_WRITE_LOCKSPACE, flags,
+ sizeof(struct sanlk_lockspace),
+ max_hosts, io_timeout);
+ if (rv < 0)
+ goto out;
+
+ rv = send(fd, ls, sizeof(struct sanlk_lockspace), 0);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
}
rv = recv_result(fd);
@@ -239,6 +346,55 @@ int sanlock_init(struct sanlk_lockspace *ls,
return rv;
}
+int sanlock_write_resource(struct sanlk_resource *res,
+ int max_hosts, int num_hosts, uint32_t flags)
+{
+ int rv, fd;
+
+ if (!res || !res->num_disks || res->num_disks > SANLK_MAX_DISKS ||
+ !res->disks[0].path[0])
+ return -EINVAL;
+
+ rv = connect_socket(&fd);
+ if (rv < 0)
+ return rv;
+
+ rv = send_header(fd, SM_CMD_WRITE_RESOURCE, flags,
+ sizeof(struct sanlk_resource) +
+ sizeof(struct sanlk_disk) * res->num_disks,
+ max_hosts, num_hosts);
+ if (rv < 0)
+ goto out;
+
+ rv = send(fd, res, sizeof(struct sanlk_resource), 0);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ rv = send(fd, res->disks, sizeof(struct sanlk_disk) * res->num_disks, 0);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ rv = recv_result(fd);
+ out:
+ close(fd);
+ return rv;
+}
+
+/* old api */
+int sanlock_init(struct sanlk_lockspace *ls,
+ struct sanlk_resource *res,
+ int max_hosts, int num_hosts)
+{
+ if (ls)
+ return sanlock_write_lockspace(ls, max_hosts, 0, 0);
+ else
+ return sanlock_write_resource(res, max_hosts, num_hosts, 0);
+}
+
/* src has colons unescaped, dst should have them escaped with backslash */
size_t sanlock_path_export(char *dst, const char *src, size_t dstlen)
diff --git a/src/cmd.c b/src/cmd.c
index d443e92..18b9db0 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1106,23 +1106,180 @@ static void cmd_align(struct task *task GNUC_UNUSED, struct cmd_args *ca)
client_resume(ca->ci_in);
}
-static void cmd_init_lockspace(struct task *task, struct cmd_args *ca)
+static void cmd_read_lockspace(struct task *task, struct cmd_args *ca)
+{
+ struct sm_header h;
+ struct sanlk_lockspace lockspace;
+ struct sync_disk sd;
+ uint64_t host_id;
+ int io_timeout = 0;
+ int fd, rv, result;
+
+ fd = client[ca->ci_in].fd;
+
+ rv = recv(fd, &lockspace, sizeof(struct sanlk_lockspace), MSG_WAITALL);
+ if (rv != sizeof(struct sanlk_lockspace)) {
+ log_error("cmd_read_lockspace %d,%d recv %d %d",
+ ca->ci_in, fd, rv, errno);
+ result = -ENOTCONN;
+ goto reply;
+ }
+
+ if (!lockspace.host_id)
+ host_id = 1;
+ else
+ host_id = lockspace.host_id;
+
+ log_debug("cmd_read_lockspace %d,%d %llu %s:%llu",
+ ca->ci_in, fd,
+ (unsigned long long)host_id,
+ lockspace.host_id_disk.path,
+ (unsigned long long)lockspace.host_id_disk.offset);
+
+ if (!lockspace.host_id_disk.path[0]) {
+ result = -ENODEV;
+ goto reply;
+ }
+
+ memset(&sd, 0, sizeof(struct sync_disk));
+ memcpy(&sd, &lockspace.host_id_disk, sizeof(struct sanlk_disk));
+ sd.fd = -1;
+
+ rv = open_disk(&sd);
+ if (rv < 0) {
+ result = -ENODEV;
+ goto reply;
+ }
+
+ /* sets ls->name and io_timeout */
+ result = delta_read_lockspace(task, &sd, host_id, &lockspace,
+ DEFAULT_IO_TIMEOUT, &io_timeout);
+ if (result == SANLK_OK)
+ result = 0;
+
+ close_disks(&sd, 1);
+ reply:
+ log_debug("cmd_read_lockspace %d,%d done %d", ca->ci_in, fd, result);
+
+ memcpy(&h, &ca->header, sizeof(struct sm_header));
+ h.data = result;
+ h.data2 = io_timeout;
+ h.length = sizeof(h) + sizeof(lockspace);
+ send(fd, &h, sizeof(h), MSG_NOSIGNAL);
+ send(fd, &lockspace, sizeof(lockspace), MSG_NOSIGNAL);
+ client_resume(ca->ci_in);
+}
+
+static void cmd_read_resource(struct task *task, struct cmd_args *ca)
+{
+ struct sm_header h;
+ struct sanlk_resource res;
+ struct token *token = NULL;
+ int token_len, disks_len;
+ int j, fd, rv, result;
+
+ fd = client[ca->ci_in].fd;
+
+ /* receiving and setting up token copied from cmd_acquire */
+
+ rv = recv(fd, &res, sizeof(struct sanlk_resource), MSG_WAITALL);
+ if (rv != sizeof(struct sanlk_resource)) {
+ log_error("cmd_read_resource %d,%d recv %d %d",
+ ca->ci_in, fd, rv, errno);
+ result = -ENOTCONN;
+ goto reply;
+ }
+
+ if (!res.num_disks || res.num_disks > SANLK_MAX_DISKS) {
+ result = -ERANGE;
+ goto reply;
+ }
+
+ disks_len = res.num_disks * sizeof(struct sync_disk);
+ token_len = sizeof(struct token) + disks_len;
+
+ token = malloc(token_len);
+ if (!token) {
+ result = -ENOMEM;
+ goto reply;
+ }
+ memset(token, 0, token_len);
+ token->disks = (struct sync_disk *)&token->r.disks[0]; /* shorthand */
+ token->r.num_disks = res.num_disks;
+ memcpy(token->r.lockspace_name, res.lockspace_name, SANLK_NAME_LEN);
+ memcpy(token->r.name, res.name, SANLK_NAME_LEN);
+
+ /*
+ * receive sanlk_disk's / sync_disk's
+ *
+ * WARNING: as a shortcut, this requires that sync_disk and
+ * sanlk_disk match; this is the reason for the pad fields
+ * in sanlk_disk (TODO: let these differ?)
+ */
+
+ rv = recv(fd, token->disks, disks_len, MSG_WAITALL);
+ if (rv != disks_len) {
+ result = -ENOTCONN;
+ goto reply;
+ }
+
+ /* zero out pad1 and pad2, see WARNING above */
+ for (j = 0; j < token->r.num_disks; j++) {
+ token->disks[j].sector_size = 0;
+ token->disks[j].fd = -1;
+ }
+
+ log_debug("cmd_read_resource %d,%d %.256s:%llu",
+ ca->ci_in, fd,
+ token->disks[0].path,
+ (unsigned long long)token->r.disks[0].offset);
+
+ rv = open_disks(token->disks, token->r.num_disks);
+ if (rv < 0) {
+ result = rv;
+ goto reply;
+ }
+
+ token->io_timeout = DEFAULT_IO_TIMEOUT;
+
+ /* sets res.lockspace_name, res.name, res.lver */
+ result = paxos_read_resource(task, token, &res);
+ if (result == SANLK_OK)
+ result = 0;
+
+ close_disks(token->disks, token->r.num_disks);
+ reply:
+ if (token)
+ free(token);
+ log_debug("cmd_read_resource %d,%d done %d", ca->ci_in, fd, result);
+
+ memcpy(&h, &ca->header, sizeof(struct sm_header));
+ h.data = result;
+ h.data2 = 0;
+ h.length = sizeof(h) + sizeof(res);
+ send(fd, &h, sizeof(h), MSG_NOSIGNAL);
+ send(fd, &res, sizeof(res), MSG_NOSIGNAL);
+ client_resume(ca->ci_in);
+}
+
+static void cmd_write_lockspace(struct task *task, struct cmd_args *ca)
{
struct sanlk_lockspace lockspace;
struct sync_disk sd;
int fd, rv, result;
+ int io_timeout = DEFAULT_IO_TIMEOUT;
fd = client[ca->ci_in].fd;
rv = recv(fd, &lockspace, sizeof(struct sanlk_lockspace), MSG_WAITALL);
if (rv != sizeof(struct sanlk_lockspace)) {
- log_error("cmd_init_lockspace %d,%d recv %d %d",
+ log_error("cmd_write_lockspace %d,%d recv %d %d",
ca->ci_in, fd, rv, errno);
result = -ENOTCONN;
goto reply;
}
- log_debug("cmd_init_lockspace %d,%d %.48s:%llu:%s:%llu",
+ log_debug("cmd_write_lockspace %d,%d %.48s:%llu:%s:%llu",
ca->ci_in, fd, lockspace.name,
(unsigned long long)lockspace.host_id,
lockspace.host_id_disk.path,
@@ -1143,17 +1300,20 @@ static void cmd_init_lockspace(struct task *task, struct cmd_args *ca)
goto reply;
}
- result = delta_lease_init(task, DEFAULT_IO_TIMEOUT, &sd, lockspace.name, ca->header.data);
+ if (ca->header.data2)
+ io_timeout = ca->header.data2;
+
+ result = delta_lease_init(task, io_timeout, &sd, lockspace.name, ca->header.data);
close_disks(&sd, 1);
reply:
- log_debug("cmd_init_lockspace %d,%d done %d", ca->ci_in, fd, result);
+ log_debug("cmd_write_lockspace %d,%d done %d", ca->ci_in, fd, result);
send_result(fd, &ca->header, result);
client_resume(ca->ci_in);
}
-static void cmd_init_resource(struct task *task, struct cmd_args *ca)
+static void cmd_write_resource(struct task *task, struct cmd_args *ca)
{
struct token *token = NULL;
struct sanlk_resource res;
@@ -1166,7 +1326,7 @@ static void cmd_init_resource(struct task *task, struct cmd_args *ca)
rv = recv(fd, &res, sizeof(struct sanlk_resource), MSG_WAITALL);
if (rv != sizeof(struct sanlk_resource)) {
- log_error("cmd_init_resource %d,%d recv %d %d",
+ log_error("cmd_write_resource %d,%d recv %d %d",
ca->ci_in, fd, rv, errno);
result = -ENOTCONN;
goto reply;
@@ -1211,7 +1371,7 @@ static void cmd_init_resource(struct task *task, struct cmd_args *ca)
token->disks[j].fd = -1;
}
- log_debug("cmd_init_resource %d,%d %.48s:%.48s:%.256s:%llu",
+ log_debug("cmd_write_resource %d,%d %.48s:%.48s:%.256s:%llu",
ca->ci_in, fd,
token->r.lockspace_name,
token->r.name,
@@ -1232,7 +1392,7 @@ static void cmd_init_resource(struct task *task, struct cmd_args *ca)
reply:
if (token)
free(token);
- log_debug("cmd_init_resource %d,%d done %d", ca->ci_in, fd, result);
+ log_debug("cmd_write_resource %d,%d done %d", ca->ci_in, fd, result);
send_result(fd, &ca->header, result);
client_resume(ca->ci_in);
@@ -1329,11 +1489,17 @@ void call_cmd_thread(struct task *task, struct cmd_args *ca)
case SM_CMD_ALIGN:
cmd_align(task, ca);
break;
- case SM_CMD_INIT_LOCKSPACE:
- cmd_init_lockspace(task, ca);
+ case SM_CMD_WRITE_LOCKSPACE:
+ cmd_write_lockspace(task, ca);
+ break;
+ case SM_CMD_WRITE_RESOURCE:
+ cmd_write_resource(task, ca);
+ break;
+ case SM_CMD_READ_LOCKSPACE:
+ cmd_read_lockspace(task, ca);
break;
- case SM_CMD_INIT_RESOURCE:
- cmd_init_resource(task, ca);
+ case SM_CMD_READ_RESOURCE:
+ cmd_read_resource(task, ca);
break;
case SM_CMD_EXAMINE_LOCKSPACE:
case SM_CMD_EXAMINE_RESOURCE:
diff --git a/src/delta_lease.c b/src/delta_lease.c
index bad5e63..e0fe372 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -148,6 +148,43 @@ static int verify_leader(struct sync_disk *disk,
return result;
}
+
+/* read the lockspace name and io_timeout given the disk location */
+
+int delta_read_lockspace(struct task *task,
+ struct sync_disk *disk,
+ uint64_t host_id,
+ struct sanlk_lockspace *ls,
+ int io_timeout,
+ int *io_timeout_ret)
+{
+ struct leader_record leader;
+ char *space_name;
+ int rv, error;
+
+ /* host_id N is block offset N-1 */
+
+ memset(&leader, 0, sizeof(struct leader_record));
+
+ rv = read_sectors(disk, host_id - 1, 1, (char *)&leader, sizeof(struct leader_record),
+ task, io_timeout, "read_lockspace");
+ if (rv < 0)
+ return rv;
+
+ if (!ls->name[0])
+ space_name = leader.space_name;
+
+ error = verify_leader(disk, space_name, host_id, &leader, "read_lockspace");
+
+ if (error == SANLK_OK) {
+ memcpy(ls->name, leader.space_name, SANLK_NAME_LEN);
+ ls->host_id = host_id;
+ *io_timeout_ret = leader.io_timeout;
+ }
+
+ return error;
+}
+
int delta_lease_leader_read(struct task *task, int io_timeout,
struct sync_disk *disk,
char *space_name,
@@ -618,6 +655,9 @@ int delta_lease_init(struct task *task,
if (!max_hosts)
max_hosts = DEFAULT_MAX_HOSTS;
+ if (!io_timeout)
+ io_timeout = DEFAULT_IO_TIMEOUT;
+
align_size = direct_align(disk);
if (align_size < 0)
return align_size;
@@ -647,16 +687,27 @@ int delta_lease_init(struct task *task,
leader->io_timeout = io_timeout;
strncpy(leader->space_name, space_name, NAME_ID_SIZE);
leader->checksum = leader_checksum(leader);
+
+ /* make the first record invalid so we can do a single atomic
+ write below to commit the whole thing */
+ if (!i)
+ leader->magic = 0;
}
rv = write_iobuf(disk->fd, disk->offset, iobuf, iobuf_len, task, io_timeout);
+ if (rv < 0)
+ goto out;
+
+ /* commit the whole lockspace by making the first record valid */
+
+ leader = (struct leader_record *)iobuf;
+ leader->magic = DELTA_DISK_MAGIC;
+ rv = write_iobuf(disk->fd, disk->offset, iobuf, disk->sector_size, task, io_timeout);
+ out:
if (rv != SANLK_AIO_TIMEOUT)
free(iobuf);
- if (rv < 0)
- return rv;
-
- return 0;
+ return rv;
}
diff --git a/src/delta_lease.h b/src/delta_lease.h
index 4c21267..f015d1e 100644
--- a/src/delta_lease.h
+++ b/src/delta_lease.h
@@ -48,4 +48,11 @@ int delta_lease_init(struct task *task,
char *space_name,
int max_hosts);
+int delta_read_lockspace(struct task *task,
+ struct sync_disk *disk,
+ uint64_t host_id,
+ struct sanlk_lockspace *ls,
+ int io_timeout,
+ int *io_timeout_ret);
+
#endif
diff --git a/src/direct.c b/src/direct.c
index ab39569..7308c82 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -91,6 +91,9 @@ static int do_paxos_action(int action, struct task *task, int io_timeout,
int disks_len, token_len;
int j, rv = 0;
+ if (!io_timeout)
+ io_timeout = DEFAULT_IO_TIMEOUT;
+
disks_len = res->num_disks * sizeof(struct sync_disk);
token_len = sizeof(struct token) + disks_len;
@@ -199,6 +202,9 @@ static int do_delta_action(int action,
memset(bitmap, 0, sizeof(bitmap));
+ if (!io_timeout)
+ io_timeout = DEFAULT_IO_TIMEOUT;
+
/* for log_space in delta functions */
memset(&space, 0, sizeof(space));
space.io_timeout = io_timeout;
@@ -392,36 +398,31 @@ int direct_align(struct sync_disk *disk)
return -EINVAL;
}
-/*
- * sanlock direct init [-s LOCKSPACE] [-r RESOURCE]
- *
- * Note: host_id not used for init, whatever is given in LOCKSPACE
- * is ignored
- */
-
-int direct_init(struct task *task,
- int io_timeout,
- struct sanlk_lockspace *ls,
- struct sanlk_resource *res,
- int max_hosts, int num_hosts)
+/* io_timeout is written to leader record and used for the write call itself */
+int direct_write_lockspace(struct task *task, struct sanlk_lockspace *ls,
+ int max_hosts, uint32_t io_timeout)
{
- int rv = -1;
+ if (!ls)
+ return -1;
- if (ls && ls->host_id_disk.path[0]) {
- rv = do_delta_action(ACT_DIRECT_INIT, task, io_timeout, ls, max_hosts, NULL, NULL);
+ return do_delta_action(ACT_DIRECT_INIT, task, io_timeout, ls,
+ max_hosts, NULL, NULL);
+}
- } else if (res) {
- if (!res->num_disks)
- return -ENODEV;
+int direct_write_resource(struct task *task, struct sanlk_resource *res,
+ int max_hosts, int num_hosts)
+{
+ if (!res)
+ return -1;
- if (!res->disks[0].path[0])
- return -ENODEV;
+ if (!res->num_disks)
+ return -ENODEV;
- rv = do_paxos_action(ACT_DIRECT_INIT, task, io_timeout, res,
- max_hosts, num_hosts, 0, 0, NULL);
- }
+ if (!res->disks[0].path[0])
+ return -ENODEV;
- return rv;
+ return do_paxos_action(ACT_DIRECT_INIT, task, 0, res,
+ max_hosts, num_hosts, 0, 0, NULL);
}
int direct_read_leader(struct task *task,
diff --git a/src/direct.h b/src/direct.h
index bd71096..f6371ed 100644
--- a/src/direct.h
+++ b/src/direct.h
@@ -45,10 +45,13 @@ int direct_live_id(struct task *task, int io_timeout,
int direct_align(struct sync_disk *disk);
-int direct_init(struct task *task, int io_timeout,
- struct sanlk_lockspace *ls,
- struct sanlk_resource *res,
- int max_hosts, int num_hosts);
+/* io_timeout is written in the leader record and used for the
+ write call itself */
+int direct_write_lockspace(struct task *task, struct sanlk_lockspace *ls,
+ int max_hosts, uint32_t io_timeout);
+
+int direct_write_resource(struct task *task, struct sanlk_resource *res,
+ int max_hosts, int num_hosts);
int direct_read_leader(struct task *task, int io_timeout,
struct sanlk_lockspace *ls,
diff --git a/src/direct_lib.c b/src/direct_lib.c
index 750ae71..c5b6dc0 100644
--- a/src/direct_lib.c
+++ b/src/direct_lib.c
@@ -123,6 +123,37 @@ int sanlock_direct_live_id(struct sanlk_lockspace *ls,
return rv;
}
+int sanlock_direct_write_lockspace(struct sanlk_lockspace *ls, int max_hosts,
+ uint32_t flags GNUC_UNUSED, uint32_t io_timeout)
+{
+ struct task task;
+ int rv;
+
+ setup_task_lib(&task, 1);
+
+ rv = direct_write_lockspace(&task, ls, max_hosts, io_timeout);
+
+ close_task_aio(&task);
+
+ return rv;
+}
+
+int sanlock_direct_write_resource(struct sanlk_resource *res,
+ int max_hosts, int num_hosts,
+ uint32_t flags GNUC_UNUSED)
+{
+ struct task task;
+ int rv;
+
+ setup_task_lib(&task, 1);
+
+ rv = direct_write_resource(&task, res, max_hosts, num_hosts);
+
+ close_task_aio(&task);
+
+ return rv;
+}
+
int sanlock_direct_init(struct sanlk_lockspace *ls,
struct sanlk_resource *res,
int max_hosts, int num_hosts, int use_aio)
@@ -132,7 +163,10 @@ int sanlock_direct_init(struct sanlk_lockspace *ls,
setup_task_lib(&task, use_aio);
- rv = direct_init(&task, DEFAULT_IO_TIMEOUT, ls, res, max_hosts, num_hosts);
+ if (ls)
+ rv = direct_write_lockspace(&task, ls, max_hosts, 0);
+ else
+ rv = direct_write_resource(&task, res, max_hosts, num_hosts);
close_task_aio(&task);
diff --git a/src/lockspace.c b/src/lockspace.c
index 469b66f..8e05fa5 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -384,7 +384,7 @@ static void *lockspace_thread(void *arg_in)
struct space *sp;
struct leader_record leader;
uint64_t delta_begin, last_success = 0;
- int rv, delta_length, renewal_interval;
+ int rv, delta_length, renewal_interval = 0;
int id_renewal_seconds, id_renewal_fail_seconds;
int acquire_result, delta_result, read_result;
int opened = 0;
diff --git a/src/main.c b/src/main.c
index 2ce26a3..37b20db 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1157,8 +1157,10 @@ static void process_connection(int ci)
case SM_CMD_EXAMINE_RESOURCE:
case SM_CMD_EXAMINE_LOCKSPACE:
case SM_CMD_ALIGN:
- case SM_CMD_INIT_LOCKSPACE:
- case SM_CMD_INIT_RESOURCE:
+ case SM_CMD_WRITE_LOCKSPACE:
+ case SM_CMD_WRITE_RESOURCE:
+ case SM_CMD_READ_LOCKSPACE:
+ case SM_CMD_READ_RESOURCE:
rv = client_suspend(ci);
if (rv < 0)
return;
@@ -1779,6 +1781,7 @@ static void print_usage(void)
printf("sanlock client log_dump\n");
printf("sanlock client shutdown [-f 0|1]\n");
printf("sanlock client init -s LOCKSPACE | -r RESOURCE\n");
+ printf("sanlock client read -s LOCKSPACE | -r RESOURCE\n");
printf("sanlock client align -s LOCKSPACE\n");
printf("sanlock client add_lockspace -s LOCKSPACE\n");
printf("sanlock client inq_lockspace -s LOCKSPACE\n");
@@ -1902,6 +1905,10 @@ static int read_command_line(int argc, char *argv[])
com.action = ACT_CLIENT_ALIGN;
else if (!strcmp(act, "init"))
com.action = ACT_CLIENT_INIT;
+ else if (!strcmp(act, "write"))
+ com.action = ACT_CLIENT_INIT;
+ else if (!strcmp(act, "read"))
+ com.action = ACT_CLIENT_READ;
else {
log_tool("client action \"%s\" is unknown", act);
exit(EXIT_FAILURE);
@@ -2117,6 +2124,8 @@ static int do_client(void)
struct sanlk_resource **res_args = NULL;
struct sanlk_resource *res;
char *res_state = NULL;
+ char *res_str = NULL;
+ uint32_t io_timeout = 0;
int i, fd, rv = 0;
if (com.action == ACT_COMMAND || com.action == ACT_ACQUIRE) {
@@ -2271,14 +2280,45 @@ static int do_client(void)
case ACT_CLIENT_INIT:
log_tool("init");
if (com.lockspace.host_id_disk.path[0])
- rv = sanlock_init(&com.lockspace, NULL,
- com.max_hosts, com.num_hosts);
+ rv = sanlock_write_lockspace(&com.lockspace,
+ com.max_hosts, 0,
+ com.io_timeout_arg);
else
- rv = sanlock_init(NULL, com.res_args[0],
- com.max_hosts, com.num_hosts);
+ rv = sanlock_write_resource(com.res_args[0],
+ com.max_hosts,
+ com.num_hosts, 0);
log_tool("init done %d", rv);
break;
+ case ACT_CLIENT_READ:
+ if (com.lockspace.host_id_disk.path[0])
+ rv = sanlock_read_lockspace(&com.lockspace, 0, &io_timeout);
+ else
+ rv = sanlock_read_resource(com.res_args[0], 0);
+
+ if (rv < 0) {
+ log_tool("read error %d", rv);
+ break;
+ }
+
+ if (com.lockspace.host_id_disk.path[0]) {
+ log_tool("s %.48s:%llu:%s:%llu",
+ com.lockspace.name,
+ (unsigned long long)com.lockspace.host_id,
+ com.lockspace.host_id_disk.path,
+ (unsigned long long)com.lockspace.host_id_disk.offset);
+ log_tool("io_timeout %u", io_timeout);
+ } else {
+ rv = sanlock_res_to_str(com.res_args[0], &res_str);
+ if (rv < 0) {
+ log_tool("res_to_str error %d", rv);
+ break;
+ }
+ log_tool("r %s", res_str);
+ free(res_str);
+ }
+ break;
+
default:
log_tool("action not implemented");
rv = -1;
@@ -2299,8 +2339,12 @@ static int do_direct(void)
switch (com.action) {
case ACT_DIRECT_INIT:
- rv = direct_init(&main_task, com.io_timeout_arg, &com.lockspace,
- com.res_args[0], com.max_hosts, com.num_hosts);
+ if (com.lockspace.host_id_disk.path[0])
+ rv = direct_write_lockspace(&main_task, &com.lockspace,
+ com.max_hosts, com.io_timeout_arg);
+ else
+ rv = direct_write_resource(&main_task, com.res_args[0],
+ com.max_hosts, com.num_hosts);
log_tool("init done %d", rv);
break;
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 0561730..577ed0b 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -692,6 +692,38 @@ static int leaders_match(struct leader_record *a, struct leader_record *b)
return 0;
}
+/* read the lockspace name and resource name given the disk location */
+
+int paxos_read_resource(struct task *task,
+ struct token *token,
+ struct sanlk_resource *res)
+{
+ struct leader_record leader;
+ int rv;
+
+ memset(&leader, 0, sizeof(struct leader_record));
+
+ rv = read_leader(task, token, &token->disks[0], &leader);
+ if (rv < 0)
+ return rv;
+
+ if (!res->lockspace_name[0])
+ memcpy(token->r.lockspace_name, leader.space_name, NAME_ID_SIZE);
+
+ if (!res->name[0])
+ memcpy(token->r.name, leader.resource_name, NAME_ID_SIZE);
+
+ rv = verify_leader(token, &token->disks[0], &leader, "read_resource");
+
+ if (rv == SANLK_OK) {
+ memcpy(res->lockspace_name, leader.space_name, NAME_ID_SIZE);
+ memcpy(res->name, leader.resource_name, NAME_ID_SIZE);
+ res->lver = leader.lver;
+ }
+
+ return rv;
+}
+
static int _leader_read_one(struct task *task,
struct token *token,
struct leader_record *leader_ret,
diff --git a/src/paxos_lease.h b/src/paxos_lease.h
index 6e7e833..99df087 100644
--- a/src/paxos_lease.h
+++ b/src/paxos_lease.h
@@ -42,4 +42,8 @@ int paxos_lease_request_read(struct task *task, struct token *token,
int paxos_lease_request_write(struct task *task, struct token *token,
struct request_record *rr);
+int paxos_read_resource(struct task *task,
+ struct token *token,
+ struct sanlk_resource *res);
+
#endif
diff --git a/src/sanlock.8 b/src/sanlock.8
index a6bf6c4..59ef392 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -242,9 +242,6 @@ use mlockall (0 none, 1 current, 2 current and future)
.BR \-a " 0|1"
use async i/o
-.BI -o " sec"
-io timeout in seconds
-
.B "sanlock client"
.I action
[options]
@@ -273,11 +270,28 @@ command will be ignored if any lockspaces exist. With the force option
released, and lockspaces removed.
.BR "sanlock client init -s" " LOCKSPACE"
-.br
+
+Tell the sanlock daemon to initialize a lockspace on disk. The -o option
+can be used to specify the io timeout to be written in the host_id leases.
+(Also see sanlock direct init.)
+
.BR "sanlock client init -r" " RESOURCE"
-Tell the sanlock daemon to initialize storage for lease areas.
-(See sanlock direct init.)
+Tell the sanlock daemon to initialize a resource lease on disk.
+(Also see sanlock direct init.)
+
+.BR "sanlock client read -s" " LOCKSPACE"
+
+Tell the sanlock daemon to read a lockspace from disk. Only the
+LOCKSPACE path and offset are required. If host_id is zero, the first
+record at offset (host_id 1) is used. The complete LOCKSPACE and io
+timeout are printed. (Also see sanlock direct read_leader and read_id.)
+
+.BR "sanlock client read -r" " RESOURCE"
+
+Tell the sanlock daemon to read a resource lease from disk. Only the
+RESOURCE path and offset are required. The complete RESOURCE is printed.
+(Also see sanlock direct read_leader.)
.BR "sanlock client align -s" " LOCKSPACE"
@@ -287,11 +301,14 @@ path. Only path is used from the LOCKSPACE argument.
.BR "sanlock client add_lockspace -s" " LOCKSPACE"
Tell the sanlock daemon to acquire the specified host_id in the lockspace.
-This will allow resources to be acquired in the lockspace.
+This will allow resources to be acquired in the lockspace. The -o option
+can be used to specify the io timeout of the acquiring host, and will be
+written in the host_id lease.
.BR "sanlock client inq_lockspace -s" " LOCKSPACE"
-Ask to the sanlock daemon weather the lockspace is acquired or not.
+Inquire about the state of the lockspace in the sanlock daemon, whether
+it is being added or removed, or is joined.
.BR "sanlock client rem_lockspace -s" " LOCKSPACE"
@@ -359,7 +376,8 @@ lockspace, or initialize storage for one resource (paxos) lease. Both
options require 1MB of space. The host_id in the LOCKSPACE string is not
relevant to initialization, so the value is ignored. (The default of 2000
host_ids can be changed for special cases using the -n num_hosts and -m
-max_hosts options.)
+max_hosts options.) With -s, the -o option specifies the io timeout to be
+written in the host_id leases.
.BR "sanlock direct read_leader -s" " LOCKSPACE"
.br
@@ -374,9 +392,8 @@ the single sector of a delta lease, or the first sector of a paxos lease.
read_id reads a host_id and prints the owner. live_id reads a host_id
once a second until it the timestamp or owner change (prints live 1), or
-until host_dead_seconds (prints live 0). (host_dead_seconds is derived
-from the io_timeout option. The live 0|1 conclusion will not match the
-sanlock daemon's conclusion unless the configured timeouts match.)
+until host_dead_seconds (prints live 0). (host_dead_seconds is based on
+the owner's io timeout.)
./" .P
./" .BR "sanlock direct acquire_id -s" " LOCKSPACE"
./" .br
diff --git a/src/sanlock_admin.h b/src/sanlock_admin.h
index 4544c21..14b1e7a 100644
--- a/src/sanlock_admin.h
+++ b/src/sanlock_admin.h
@@ -70,10 +70,87 @@ int sanlock_align(struct sanlk_disk *disk);
* Use max_hosts = 0 for default value.
* Use num_hosts = 0 for default value.
* Provide either lockspace or resource, not both
+ *
+ * (Old api, see write_lockspace/resource)
*/
int sanlock_init(struct sanlk_lockspace *ls,
struct sanlk_resource *res,
int max_hosts, int num_hosts);
+/*
+ * write a lockspace to disk
+ *
+ * the sanlock daemon writes max_hosts lockspace leader records to disk
+ *
+ * the lockspace will support up to max_hosts using the lockspace at once
+ *
+ * use max_hosts = 0 for default value
+ *
+ * the first host_id (1) (the first record at offset) is the last
+ * leader record written, so read_lockspace of host_id 1 will fail
+ * until the entire write_lockspace is complete.
+ */
+
+int sanlock_write_lockspace(struct sanlk_lockspace *ls, int max_hosts,
+ uint32_t flags, uint32_t io_timeout);
+
+/*
+ * read one host's lockspace record from disk
+ *
+ * the sanlock daemon reads one lockspace leader record from disk
+ *
+ * the minimum input is path and offset
+ *
+ * if name is specified and does not match the leader record name,
+ * SANLK_LEADER_LOCKSPACE is returned
+ *
+ * if name is not specified, it is filled it with the value from disk
+ *
+ * if host_id is zero, host_id 1 is used (the first record at offset)
+ *
+ * if there is no delta lease magic number found at the host_id location,
+ * SANLK_LEADER_MAGIC is returned
+ *
+ * on success, zero is returned and
+ * io_timeout and the entire sanlk_lockspace struct are written to
+ */
+
+int sanlock_read_lockspace(struct sanlk_lockspace *ls,
+ uint32_t flags, uint32_t *io_timeout);
+
+/*
+ * format a resource lease area on disk
+ *
+ * the sanlock daemon writes a resource lease area to disk
+ *
+ * use max_hosts = 0 for default value
+ * use num_hosts = 0 for default value
+ */
+
+int sanlock_write_resource(struct sanlk_resource *res,
+ int max_hosts, int num_hosts, uint32_t flags);
+
+/*
+ * read a resource lease from disk
+ *
+ * the sanlock daemon reads the lease's leader record from disk
+ *
+ * the minimum input is one disk with path and offset
+ *
+ * if lockspace name is specified and does not match the leader record
+ * lockspace name, SANLK_LEADER_LOCKSPACE is returned
+ *
+ * if resource name is specified and does not match the leader record
+ * resource name, SANLK_LEADER_RESOURCE is returned
+ *
+ * if there is no paxos lease magic number found in the leader record,
+ * SANLK_LEADER_MAGIC is returned
+ *
+ * on success, zero is returned and
+ * the entire sanlk_resource struct is written to (res->disks is not changed)
+ */
+
+int sanlock_read_resource(struct sanlk_resource *res, uint32_t flags);
+
#endif
diff --git a/src/sanlock_direct.h b/src/sanlock_direct.h
index 0f0cf18..cbdec46 100644
--- a/src/sanlock_direct.h
+++ b/src/sanlock_direct.h
@@ -32,6 +32,8 @@ int sanlock_direct_live_id(struct sanlk_lockspace *ls,
* Use max_hosts = 0 for default value.
* Use num_hosts = 0 for default value.
* Provide either lockspace or resource, not both
+ *
+ * (Old api, see write_lockspace/resource)
*/
int sanlock_direct_init(struct sanlk_lockspace *ls,
@@ -39,6 +41,22 @@ int sanlock_direct_init(struct sanlk_lockspace *ls,
int max_hosts, int num_hosts, int use_aio);
/*
+ * write a lockspace to disk
+ * (also see sanlock_write_lockspace)
+ */
+
+int sanlock_direct_write_lockspace(struct sanlk_lockspace *ls, int max_hosts,
+ uint32_t flags, uint32_t io_timeout);
+
+/*
+ * format a resource lease area on disk
+ * (also see sanlock_write_resource)
+ */
+
+int sanlock_direct_write_resource(struct sanlk_resource *res,
+ int max_hosts, int num_hosts, uint32_t flags);
+
+/*
* Returns the alignment in bytes required by sanlock_direct_init()
* (1MB for disks with 512 sectors, 8MB for disks with 4096 sectors)
*/
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 65496ff..414ceb8 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -309,6 +309,7 @@ enum {
ACT_NEXT_FREE,
ACT_READ_LEADER,
ACT_CLIENT_INIT,
+ ACT_CLIENT_READ,
ACT_CLIENT_ALIGN,
ACT_EXAMINE,
};
diff --git a/src/sanlock_sock.h b/src/sanlock_sock.h
index 5f8fcf0..fbabbb2 100644
--- a/src/sanlock_sock.h
+++ b/src/sanlock_sock.h
@@ -18,25 +18,27 @@
#define MAX_CLIENT_MSG (1024 * 1024) /* TODO: this is random */
enum {
- SM_CMD_REGISTER = 1,
- SM_CMD_ADD_LOCKSPACE = 2,
- SM_CMD_REM_LOCKSPACE = 3,
- SM_CMD_SHUTDOWN = 4,
- SM_CMD_STATUS = 5,
- SM_CMD_LOG_DUMP = 6,
- SM_CMD_ACQUIRE = 7,
- SM_CMD_RELEASE = 8,
- SM_CMD_INQUIRE = 9,
- SM_CMD_RESTRICT = 10,
- SM_CMD_REQUEST = 11,
- SM_CMD_ALIGN = 12,
- SM_CMD_INIT_LOCKSPACE = 13,
- SM_CMD_INIT_RESOURCE = 14,
- SM_CMD_EXAMINE_LOCKSPACE = 15,
- SM_CMD_EXAMINE_RESOURCE = 16,
- SM_CMD_HOST_STATUS = 17,
- SM_CMD_INQ_LOCKSPACE = 18,
- SM_CMD_KILLPATH = 19,
+ SM_CMD_REGISTER = 1,
+ SM_CMD_ADD_LOCKSPACE = 2,
+ SM_CMD_REM_LOCKSPACE = 3,
+ SM_CMD_SHUTDOWN = 4,
+ SM_CMD_STATUS = 5,
+ SM_CMD_LOG_DUMP = 6,
+ SM_CMD_ACQUIRE = 7,
+ SM_CMD_RELEASE = 8,
+ SM_CMD_INQUIRE = 9,
+ SM_CMD_RESTRICT = 10,
+ SM_CMD_REQUEST = 11,
+ SM_CMD_ALIGN = 12,
+ SM_CMD_EXAMINE_LOCKSPACE = 13,
+ SM_CMD_EXAMINE_RESOURCE = 14,
+ SM_CMD_HOST_STATUS = 15,
+ SM_CMD_INQ_LOCKSPACE = 16,
+ SM_CMD_KILLPATH = 17,
+ SM_CMD_WRITE_LOCKSPACE = 18,
+ SM_CMD_WRITE_RESOURCE = 19,
+ SM_CMD_READ_LOCKSPACE = 20,
+ SM_CMD_READ_RESOURCE = 21,
};
struct sm_header {
10 years, 6 months
Re: check_our_lease corrupt
by sysadmin@albasoft.com
On 11/21/2012 05:22 PM, David Teigland wrote:
> On Wed, Nov 21, 2012 at 05:15:55PM +0100, sysadmin(a)albasoft.com wrote:
>
>> On this specific host it was running directly on ext4. I'll change
>> it to nfs and report.
>>
> Aren't you using multiple hosts to run shared vm images?
> If not, then using sanlock is pointless.
>
Yes, I am using multiple hosts and sharings vm.
But this was the nfs server host, so I thought there was no point in nfs
mounting a local path.
>
>> That path is on ext4 filesystem on top of LVM2 logical volume on top
>> of a md raid1 device. Does that say something to you?
>>
> ext4 or md are probably the cause of the problems; sanlock will not
> work properly with either.
>
>
I'm running another set of 3 hosts with exactly the same arrangement
(ext4, lvm, md raid) for months, and I get no error.
The only log from sanlock I get is
Nov 17 18:01:50 storage02 kernel: EXT4-fs (dm-1): Unaligned AIO/DIO on
inode 1569995 by sanlock; performance will be poor.
but no "check_our_lease corrupt"
10 years, 6 months
check_our_lease corrupt
by sysadmin@albasoft.com
Hi,
My host is logging these errors about once a week, which lead to guest
(qemu KVM on libvirt) been killed. Host CPU is at all times very low.
Something related to ext4 and "performance will be poor"?
Thanks
kernel-2.6.32-279.11.1.el6.x86_64
libvirt-0.9.10-21.el6_3.5.x86_64
sanlock-2.3-1.el6.x86_64
Nov 18 20:42:51 appserver01 kernel: EXT4-fs (dm-0): Unaligned AIO/DIO on
inode 48 by sanlock; performance will be poor.
Nov 19 20:42:53 appserver01 kernel: EXT4-fs (dm-0): Unaligned AIO/DIO on
inode 48 by sanlock; performance will be poor.
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: s1 delta_renew reread mismatch
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader1 delta_renew_last error 0 lockspace
__LIBVIRT__DISKS__ host_id 1
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader2 path
/var/lib/libvirt/sanlock/__LIBVIRT__DISKS__ offset 0
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader3 m 12212010 v 30002 ss 512 nh 0 mh 1 oi 1 og 14 lv 0
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader4 sn __LIBVIRT__DISKS__ rn
18fefd6b-45fe-4d2b-8774-7c890826d722.appserver0 ts 1040519 cs b1df2fa4
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader1 delta_renew_read error 0 lockspace
__LIBVIRT__DISKS__ host_id 1
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader2 path
/var/lib/libvirt/sanlock/__LIBVIRT__DISKS__ offset 0
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader3 m 12212010 v 30002 ss 512 nh 0 mh 1 oi 1 og 14 lv 0
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: leader4 sn __LIBVIRT__DISKS__ rn
18fefd6b-45fe-4d2b-8774-7c890826d722.appserver0 ts 1040499 cs a4181d8a
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [18880]: s1 renewal error -261 delta_length 0 last_success 1040519
Nov 19 21:38:19 appserver01 sanlock[17941]: 2012-11-19 21:38:19+0100
1040540 [17941]: s1 check_our_lease corrupt -261
10 years, 6 months
5 commits - .gitignore src/Makefile src/client.c src/client_cmd.c src/helper.c src/lockspace.c src/lockspace.h src/main.c src/paxos_lease.c tests/Makefile tests/sanlk_path.c
by David Teigland
.gitignore | 14 ++++++++++++++
src/Makefile | 15 ++++++++++++---
src/client.c | 7 +++++--
src/client_cmd.c | 12 ++++++------
src/helper.c | 2 +-
src/lockspace.c | 46 +++++++++++++---------------------------------
src/lockspace.h | 6 +++---
src/main.c | 24 ++++++++++++------------
src/paxos_lease.c | 4 ++--
tests/Makefile | 1 +
tests/sanlk_path.c | 3 ++-
11 files changed, 71 insertions(+), 63 deletions(-)
New commits:
commit 3d15c31a76e2bc8928fd425179de694621446992
Author: Saggi Mizrahi <smizrahi(a)redhat.com>
Date: Fri Nov 16 23:49:43 2012 -0500
Add a gitignore file
Signed-off-by: Saggi Mizrahi <smizrahi(a)redhat.com>
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..74a57d8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,14 @@
+*.swp
+*.co
+.vimdir
+cscope.*
+src/libsanlock.so*
+src/libsanlock_client.so*
+src/sanlock
+python/build/
+python/usr/
+tests/devcount
+tests/killpath
+tests/sanlk_client
+tests/sanlk_load
+tests/sanlk_path
commit 00157c44ebce2d7423632819b2ffe3e31940aa16
Author: Saggi Mizrahi <smizrahi(a)redhat.com>
Date: Fri Nov 16 23:49:42 2012 -0500
Set constness in some places
This is far from fixing all the areas where const is missing but I was
already there
Signed-off-by: Saggi Mizrahi <smizrahi(a)redhat.com>
diff --git a/src/lockspace.c b/src/lockspace.c
index 88da3f1..469b66f 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -37,7 +37,7 @@
static uint32_t space_id_counter = 1;
-static struct space *_search_space(char *name,
+static struct space *_search_space(const char *name,
struct sync_disk *disk,
uint64_t host_id,
struct list_head *head1,
@@ -68,12 +68,12 @@ static struct space *_search_space(char *name,
return NULL;
}
-struct space *find_lockspace(char *name)
+struct space *find_lockspace(const char *name)
{
return _search_space(name, NULL, 0, &spaces, &spaces_rem, &spaces_add);
}
-int _lockspace_info(char *space_name, struct space_info *spi)
+int _lockspace_info(const char *space_name, struct space_info *spi)
{
struct space *sp;
@@ -95,7 +95,7 @@ int _lockspace_info(char *space_name, struct space_info *spi)
return -1;
}
-int lockspace_info(char *space_name, struct space_info *spi)
+int lockspace_info(const char *space_name, struct space_info *spi)
{
int rv;
diff --git a/src/lockspace.h b/src/lockspace.h
index 5096154..dc1099d 100644
--- a/src/lockspace.h
+++ b/src/lockspace.h
@@ -9,9 +9,9 @@
#ifndef __HOST_ID_H__
#define __HOST_ID__H__
-struct space *find_lockspace(char *name);
-int _lockspace_info(char *space_name, struct space_info *spi);
-int lockspace_info(char *space_name, struct space_info *spi);
+struct space *find_lockspace(const char *name);
+int _lockspace_info(const char *space_name, struct space_info *spi);
+int lockspace_info(const char *space_name, struct space_info *spi);
int lockspace_disk(char *space_name, struct sync_disk *disk);
int host_info(char *space_name, uint64_t host_id, struct host_status *hs_out);
int host_status_set_bit(char *space_name, uint64_t host_id);
commit 4fb7e60aa95832be14aa8f0b2514a8213257cb63
Author: Saggi Mizrahi <smizrahi(a)redhat.com>
Date: Fri Nov 16 23:49:41 2012 -0500
Tidy up some copy pasted code
Signed-off-by: Saggi Mizrahi <smizrahi(a)redhat.com>
diff --git a/src/lockspace.c b/src/lockspace.c
index 72e32ec..88da3f1 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -44,36 +44,16 @@ static struct space *_search_space(char *name,
struct list_head *head2,
struct list_head *head3)
{
+ int i;
struct space *sp;
+ struct list_head *heads[] = {head1, head2, head3};
- if (head1) {
- list_for_each_entry(sp, head1, list) {
- if (name && strncmp(sp->space_name, name, NAME_ID_SIZE))
- continue;
- if (disk && strncmp(sp->host_id_disk.path, disk->path, SANLK_PATH_LEN))
- continue;
- if (disk && sp->host_id_disk.offset != disk->offset)
- continue;
- if (host_id && sp->host_id != host_id)
- continue;
- return sp;
- }
- }
- if (head2) {
- list_for_each_entry(sp, head2, list) {
- if (name && strncmp(sp->space_name, name, NAME_ID_SIZE))
- continue;
- if (disk && strncmp(sp->host_id_disk.path, disk->path, SANLK_PATH_LEN))
- continue;
- if (disk && sp->host_id_disk.offset != disk->offset)
- continue;
- if (host_id && sp->host_id != host_id)
- continue;
- return sp;
+ for (i = 0; i < 3; i++) {
+ if (!heads[i]) {
+ continue;
}
- }
- if (head3) {
- list_for_each_entry(sp, head3, list) {
+
+ list_for_each_entry(sp, heads[i], list) {
if (name && strncmp(sp->space_name, name, NAME_ID_SIZE))
continue;
if (disk && strncmp(sp->host_id_disk.path, disk->path, SANLK_PATH_LEN))
commit c4bad660e881082ea4c8f1b4efb61ebefab23dbc
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Nov 20 13:21:44 2012 -0600
sanlock: clean up daemon exit error path
we want lockfile removal to be the last thing done
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index a97ef06..2ce26a3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1617,15 +1617,17 @@ static int do_daemon(void)
helper_ci = client_add(helper_status_fd, process_helper, helper_dead);
if (helper_ci < 0)
- goto out_logging;
+ return rv;
strcpy(client[helper_ci].owner_name, "helper");
setup_signals();
setup_logging();
fd = lockfile(SANLK_RUN_DIR, SANLK_LOCKFILE_NAME, com.uid, com.gid);
- if (fd < 0)
+ if (fd < 0) {
+ close_logging();
return fd;
+ }
setup_host_name();
@@ -1638,7 +1640,7 @@ static int do_daemon(void)
rv = thread_pool_create(DEFAULT_MIN_WORKER_THREADS, com.max_worker_threads);
if (rv < 0)
- goto out_lockfile;
+ goto out;
rv = setup_listener();
if (rv < 0)
@@ -1654,10 +1656,10 @@ static int do_daemon(void)
out_threads:
thread_pool_free();
- out_lockfile:
- unlink_lockfile(fd, SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
- out_logging:
+ out:
+ /* order reversed from setup so lockfile is last */
close_logging();
+ unlink_lockfile(fd, SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
return rv;
}
commit d53d9eba30e0a1091be31dae58219f1b1adbbaa9
Author: Saggi Mizrahi <smizrahi(a)redhat.com>
Date: Fri Nov 16 23:49:40 2012 -0500
Fix various build warnings
Signed-off-by: Saggi Mizrahi <smizrahi(a)redhat.com>
diff --git a/src/Makefile b/src/Makefile
index 2fb2dee..dc5668a 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -53,7 +53,15 @@ LIB_CLIENT_SOURCE = \
client.c \
sanlock_sock.c
-CFLAGS += -D_GNU_SOURCE -g \
+OPTIMIZE_FLAG = -O2 -Wp,-D_FORTIFY_SOURCE=2
+ifeq ($(DEBUG), 1)
+ OPTIMIZE_FLAG = -O0
+ CFLAGS += -g
+endif
+
+
+
+CFLAGS += -D_GNU_SOURCE \
-Wall \
-Wformat \
-Wformat-security \
@@ -68,10 +76,11 @@ CFLAGS += -D_GNU_SOURCE -g \
-Winline \
-Wredundant-decls \
-Wno-sign-compare \
- -Wp,-D_FORTIFY_SOURCE=2 \
-fexceptions \
-fasynchronous-unwind-tables \
- -fdiagnostics-show-option
+ -fdiagnostics-show-option \
+ $(OPTIMIZE_FLAG) \
+ $(NULL)
VER=$(shell cat ../VERSION)
CFLAGS += -DVERSION=\"$(VER)\"
diff --git a/src/client.c b/src/client.c
index 3c7287e..48e1505 100644
--- a/src/client.c
+++ b/src/client.c
@@ -42,13 +42,16 @@ static int connect_socket(int *sock_fd)
int rv, s;
struct sockaddr_un addr;
+ *sock_fd = -1;
s = socket(AF_LOCAL, SOCK_STREAM, 0);
if (s < 0)
return -errno;
rv = sanlock_socket_address(&addr);
- if (rv < 0)
+ if (rv < 0) {
+ close(s);
return rv;
+ }
rv = connect(s, (struct sockaddr *) &addr, sizeof(struct sockaddr_un));
if (rv < 0) {
@@ -265,7 +268,7 @@ size_t sanlock_path_export(char *dst, const char *src, size_t dstlen)
return 0;
}
-/* src has colons escaped with backslash, dst should have backslash removed */
+/* src has colons escaped with backslash, dst should have backslash removed */
size_t sanlock_path_import(char *dst, const char *src, size_t dstlen)
{
diff --git a/src/client_cmd.c b/src/client_cmd.c
index 069f75f..6551aae 100644
--- a/src/client_cmd.c
+++ b/src/client_cmd.c
@@ -330,7 +330,7 @@ int sanlock_status(int debug, char sort_arg)
char maxstr[SANLK_STATE_MAXSTR];
char maxbin[SANLK_STATE_MAXSTR];
struct sanlk_state *st;
- char *buf, *str, *bin;
+ char *buf = NULL, *str, *bin;
int fd, rv, len;
int sort_p = 0, sort_s = 0;
@@ -358,12 +358,12 @@ int sanlock_status(int debug, char sort_arg)
bin = maxbin;
while (1) {
- if (sort_p || sort_s) {
+ if (sort_s || sort_p) {
len = sizeof(struct sanlk_state) + SANLK_STATE_MAXSTR*4;
- buf = malloc(len);
+ buf = calloc(len, sizeof(char));
if (!buf)
return -ENOMEM;
- memset(buf, 0, len);
+
st = (struct sanlk_state *)buf;
str = buf + sizeof(struct sanlk_state);
bin = buf + sizeof(struct sanlk_state) + SANLK_STATE_MAXSTR;
@@ -387,8 +387,8 @@ int sanlock_status(int debug, char sort_arg)
recv_bin(fd, st, bin);
- if (sort_p || sort_s) {
- if (sort_count == MAX_SORT_ENTRIES) {
+ if (sort_s || sort_p) {
+ if ((sort_count == MAX_SORT_ENTRIES) || (!buf)) {
printf("cannot sort over %d\n", MAX_SORT_ENTRIES);
goto out;
}
diff --git a/src/helper.c b/src/helper.c
index 222f567..2fce221 100644
--- a/src/helper.c
+++ b/src/helper.c
@@ -151,7 +151,7 @@ int run_helper(int in_fd, int out_fd, int log_stderr)
struct helper_msg hm;
unsigned int fork_count = 0;
unsigned int wait_count = 0;
- time_t now, last_send, last_good;
+ time_t now, last_send, last_good = 0;
int timeout = STANDARD_TIMEOUT_MS;
int rv, pid, status;
diff --git a/src/lockspace.c b/src/lockspace.c
index 8fa9211..72e32ec 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -403,7 +403,7 @@ static void *lockspace_thread(void *arg_in)
struct task task;
struct space *sp;
struct leader_record leader;
- uint64_t delta_begin, last_success;
+ uint64_t delta_begin, last_success = 0;
int rv, delta_length, renewal_interval;
int id_renewal_seconds, id_renewal_fail_seconds;
int acquire_result, delta_result, read_result;
@@ -879,7 +879,7 @@ int rem_lockspace_wait(struct sanlk_lockspace *ls, unsigned int space_id)
return 0;
}
-/*
+/*
* we call stop_host_id() when all pids are gone and we're in a safe state, so
* it's safe to unlink the watchdog right away here. We want to sp the unlink
* as soon as it's safe, so we can reduce the chance we get killed by the
diff --git a/src/main.c b/src/main.c
index 17c37a4..a97ef06 100644
--- a/src/main.c
+++ b/src/main.c
@@ -520,7 +520,7 @@ void client_pid_dead(int ci)
lock both spaces_mutex and cl->mutex when adding new tokens to the client.
(It needs to check that the lockspace for the new tokens hasn't failed
while the tokens were being acquired.)
-
+
In kill_pids and all_pids_dead could we check cl->pid <= 0 without
taking cl->mutex, since client_pid_dead in the main thread is the
only place that changes that? */
@@ -551,7 +551,7 @@ static void kill_pids(struct space *sp)
struct client *cl;
uint64_t now, last_success;
int id_renewal_fail_seconds;
- int ci, fd, pid, sig;
+ int ci, sig;
int do_kill, in_grace;
/*
@@ -603,9 +603,6 @@ static void kill_pids(struct space *sp)
cl->kill_last = now;
cl->kill_count++;
- fd = cl->fd;
- pid = cl->pid;
-
/*
* the transition from using killpath/sigterm to sigkill
* is when now >=
@@ -1613,7 +1610,7 @@ static int do_daemon(void)
sprintf(main_task.name, "%s", "main");
setup_task_aio(&main_task, com.aio_arg, 0);
-
+
rv = client_alloc();
if (rv < 0)
return rv;
@@ -1641,7 +1638,7 @@ static int do_daemon(void)
rv = thread_pool_create(DEFAULT_MIN_WORKER_THREADS, com.max_worker_threads);
if (rv < 0)
- goto out_logging;
+ goto out_lockfile;
rv = setup_listener();
if (rv < 0)
@@ -1657,9 +1654,10 @@ static int do_daemon(void)
out_threads:
thread_pool_free();
+ out_lockfile:
+ unlink_lockfile(fd, SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
out_logging:
close_logging();
- unlink_lockfile(fd, SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
return rv;
}
@@ -1733,7 +1731,7 @@ static int parse_arg_resource(char *arg)
return 0;
}
-/*
+/*
* daemon: acquires leases for the local host_id, associates them with a local
* pid, and releases them when the associated pid exits.
*
@@ -2433,7 +2431,7 @@ int main(int argc, char *argv[])
helper_pid = -1;
helper_kill_fd = -1;
helper_status_fd = -1;
-
+
pthread_mutex_init(&spaces_mutex, NULL);
INIT_LIST_HEAD(&spaces);
INIT_LIST_HEAD(&spaces_rem);
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 30451d4..0561730 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -269,7 +269,7 @@ static int run_ballot(struct task *task, struct token *token, int num_hosts,
int sector_size = token->disks[0].sector_size;
int sector_count;
int iobuf_len;
- int d, q, rv;
+ int d, q, rv = 0;
int q_max = -1;
int error;
@@ -917,7 +917,7 @@ static int _lease_read_num(struct task *task,
int *leader_reps;
int num_disks = token->r.num_disks;
int leaders_len, leader_reps_len;
- int i, d, rv, found, num_reads, q_one, tmp_q = -1;
+ int i, d, rv = 0, found, num_reads, q_one, tmp_q = -1;
leaders_len = num_disks * sizeof(struct leader_record);
leader_reps_len = num_disks * sizeof(int);
diff --git a/tests/Makefile b/tests/Makefile
index 28f5d21..53fefea 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -25,6 +25,7 @@ CFLAGS += -D_GNU_SOURCE -g \
-Wredundant-decls \
-Wno-sign-compare \
-Wp,-D_FORTIFY_SOURCE=2 \
+ -O2 \
-fexceptions \
-fasynchronous-unwind-tables \
-fdiagnostics-show-option
diff --git a/tests/sanlk_path.c b/tests/sanlk_path.c
index f9d8f6f..6befa68 100644
--- a/tests/sanlk_path.c
+++ b/tests/sanlk_path.c
@@ -121,7 +121,8 @@ void test_sanlock_path_import(void)
"sanlock_path_import destination is different");
}
-int main(int argc, char *argv[])
+int main(int argc __attribute__ ((unused)),
+ char *argv[] __attribute__ ((unused)))
{
test_sanlock_path_export();
test_sanlock_path_import();
10 years, 6 months
2 commits - init.d/sanlock.sysconfig init.d/wdmd.sysconfig src/sysconfig.sanlock wdmd/main.c wdmd/sysconfig.wdmd
by David Teigland
init.d/sanlock.sysconfig | 12 ++++++++++++
init.d/wdmd.sysconfig | 11 +++++++++++
src/sysconfig.sanlock | 12 ------------
wdmd/main.c | 33 ++++++++++++++++++++-------------
wdmd/sysconfig.wdmd | 8 --------
5 files changed, 43 insertions(+), 33 deletions(-)
New commits:
commit d8a502cf22cd87aa546c5fcc79c1ce05593af280
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Tue Nov 20 11:52:22 2012 -0500
wdmd: make the watchdog device configurable
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/init.d/sanlock.sysconfig b/init.d/sanlock.sysconfig
new file mode 100644
index 0000000..89b6fa3
--- /dev/null
+++ b/init.d/sanlock.sysconfig
@@ -0,0 +1,12 @@
+# SANLOCKOPTS -- set the command line options for the sanlock daemon
+# See sanlock man page for full list of command line options.
+#
+# Include "-U sanlock -G sanlock" in the option string unless
+# also changing the SANLOCKUSER above.
+#
+# To disable use of watchdog via wdmd
+#SANLOCKOPTS="-U sanlock -G sanlock -w 0"
+#
+# To disable use of watchdog via wdmd and disable high priority features
+#SANLOCKOPTS="-U sanlock -G sanlock -w 0 -h 0"
+
diff --git a/init.d/wdmd.sysconfig b/init.d/wdmd.sysconfig
new file mode 100644
index 0000000..1ef8564
--- /dev/null
+++ b/init.d/wdmd.sysconfig
@@ -0,0 +1,11 @@
+# WDMDOPTS -- set the command line options for the wdmd daemon
+# See wdmd man page for full list of command line options.
+#
+# Include "-G sanlock" in the option string.
+#
+# To enable use of test scripts
+#WDMDOPTS="-G sanlock -S 1"
+#
+# To select a specific watchdog device
+#WDMDOPTS="-G sanlock -w /dev/watchdog1"
+
diff --git a/src/sysconfig.sanlock b/src/sysconfig.sanlock
deleted file mode 100644
index 89b6fa3..0000000
--- a/src/sysconfig.sanlock
+++ /dev/null
@@ -1,12 +0,0 @@
-# SANLOCKOPTS -- set the command line options for the sanlock daemon
-# See sanlock man page for full list of command line options.
-#
-# Include "-U sanlock -G sanlock" in the option string unless
-# also changing the SANLOCKUSER above.
-#
-# To disable use of watchdog via wdmd
-#SANLOCKOPTS="-U sanlock -G sanlock -w 0"
-#
-# To disable use of watchdog via wdmd and disable high priority features
-#SANLOCKOPTS="-U sanlock -G sanlock -w 0 -h 0"
-
diff --git a/wdmd/main.c b/wdmd/main.c
index 08f2c94..d1666b9 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -64,6 +64,7 @@ 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";
struct script_status {
uint64_t start;
@@ -921,13 +922,13 @@ static int open_dev(void)
int fd;
if (dev_fd != -1) {
- log_error("/dev/watchdog already open fd %d", dev_fd);
+ log_error("watchdog already open fd %d", dev_fd);
return -1;
}
- fd = open("/dev/watchdog", O_WRONLY | O_CLOEXEC);
+ fd = open(watchdog_path, O_WRONLY | O_CLOEXEC);
if (fd < 0) {
- log_error("no /dev/watchdog, load a watchdog driver");
+ log_error("no %s, load a watchdog driver", watchdog_path);
return fd;
}
@@ -942,7 +943,7 @@ static void close_watchdog_unclean(void)
return;
}
- log_error("/dev/watchdog closed unclean");
+ log_error("%s closed unclean", watchdog_path);
close(dev_fd);
dev_fd = -1;
@@ -960,9 +961,9 @@ static void close_watchdog(void)
rv = write(dev_fd, "V", 1);
if (rv < 0)
- log_error("/dev/watchdog disarm write error %d", errno);
+ log_error("%s disarm write error %d", watchdog_path, errno);
else
- log_error("/dev/watchdog disarmed");
+ log_error("%s disarmed", watchdog_path);
close(dev_fd);
dev_fd = -1;
@@ -980,7 +981,7 @@ static int setup_watchdog(void)
rv = ioctl(dev_fd, WDIOC_GETTIMEOUT, &timeout);
if (rv < 0) {
- log_error("/dev/watchdog failed to report timeout");
+ log_error("%s failed to report timeout", watchdog_path);
close_watchdog();
return -1;
}
@@ -992,18 +993,18 @@ static int setup_watchdog(void)
rv = ioctl(dev_fd, WDIOC_SETTIMEOUT, &timeout);
if (rv < 0) {
- log_error("/dev/watchdog failed to set timeout");
+ log_error("%s failed to set timeout", watchdog_path);
close_watchdog();
return -1;
}
if (timeout != fire_timeout) {
- log_error("/dev/watchdog failed to set new timeout");
+ log_error("%s failed to set new timeout", watchdog_path);
close_watchdog();
return -1;
}
out:
- log_error("/dev/watchdog armed with fire_timeout %d", fire_timeout);
+ log_error("%s armed with fire_timeout %d", watchdog_path, fire_timeout);
return 0;
}
@@ -1152,7 +1153,7 @@ static int test_loop(void)
if (dev_fd == -1) {
open_dev();
pet_watchdog();
- log_error("/dev/watchdog reopen");
+ log_error("%s reopen", watchdog_path);
} else {
pet_watchdog();
}
@@ -1328,6 +1329,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);
exit(status);
}
@@ -1360,7 +1362,7 @@ int main(int argc, char *argv[])
{0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hdVDH:G:S:s:k:",
+ c = getopt_long(argc, argv, "hdVDH:G:S:s:k:w:",
long_options, &option_index);
if (c == -1)
break;
@@ -1393,6 +1395,9 @@ int main(int argc, char *argv[])
case 'k':
kill_script_sec = atoi(optarg);
break;
+ case 'w':
+ watchdog_path = strdup(optarg);
+ break;
}
}
diff --git a/wdmd/sysconfig.wdmd b/wdmd/sysconfig.wdmd
deleted file mode 100644
index 06a13db..0000000
--- a/wdmd/sysconfig.wdmd
+++ /dev/null
@@ -1,8 +0,0 @@
-# WDMDOPTS -- set the command line options for the wdmd daemon
-# See wdmd man page for full list of command line options.
-#
-# Include "-G sanlock" in the option string.
-#
-# To enable use of test scripts
-#WDMDOPTS="-G sanlock -S 1"
-
commit 4b5733fdf52390cb78361a46a53c3b74a5e7b8c7
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Tue Nov 20 11:36:49 2012 -0500
wdmd: trap also SIGINT for a clean exit
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/wdmd/main.c b/wdmd/main.c
index 646a0ac..08f2c94 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -1029,7 +1029,8 @@ static void process_signals(int ci)
return;
}
- if (fdsi.ssi_signo == SIGTERM) {
+ if ((fdsi.ssi_signo == SIGTERM) ||
+ (fdsi.ssi_signo == SIGINT)) {
if (!active_clients())
daemon_quit = 1;
}
@@ -1046,6 +1047,7 @@ static int setup_signals(void)
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
+ sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGHUP);
rv = sigprocmask(SIG_BLOCK, &mask, NULL);
10 years, 6 months
[PATCHv2] wdmd: make the watchdog device configurable
by Federico Simoncelli
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
src/sysconfig.sanlock => init.d/sanlock.sysconfig | 0
wdmd/sysconfig.wdmd => init.d/wdmd.sysconfig | 3 ++
wdmd/main.c | 29 ++++++++++++--------
3 files changed, 20 insertions(+), 12 deletions(-)
rename src/sysconfig.sanlock => init.d/sanlock.sysconfig (100%)
rename wdmd/sysconfig.wdmd => init.d/wdmd.sysconfig (73%)
diff --git a/src/sysconfig.sanlock b/init.d/sanlock.sysconfig
similarity index 100%
rename from src/sysconfig.sanlock
rename to init.d/sanlock.sysconfig
diff --git a/wdmd/sysconfig.wdmd b/init.d/wdmd.sysconfig
similarity index 73%
rename from wdmd/sysconfig.wdmd
rename to init.d/wdmd.sysconfig
index 06a13db..1ef8564 100644
--- a/wdmd/sysconfig.wdmd
+++ b/init.d/wdmd.sysconfig
@@ -5,4 +5,7 @@
#
# To enable use of test scripts
#WDMDOPTS="-G sanlock -S 1"
+#
+# To select a specific watchdog device
+#WDMDOPTS="-G sanlock -w /dev/watchdog1"
diff --git a/wdmd/main.c b/wdmd/main.c
index 1f1395a..9ea0018 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -65,6 +65,7 @@ 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";
struct script_status {
uint64_t start;
@@ -922,13 +923,13 @@ static int open_dev(void)
int fd;
if (dev_fd != -1) {
- log_error("/dev/watchdog already open fd %d", dev_fd);
+ log_error("watchdog already open fd %d", dev_fd);
return -1;
}
- fd = open("/dev/watchdog", O_WRONLY | O_CLOEXEC);
+ fd = open(watchdog_path, O_WRONLY | O_CLOEXEC);
if (fd < 0) {
- log_error("no /dev/watchdog, load a watchdog driver");
+ log_error("no %s, load a watchdog driver", watchdog_path);
return fd;
}
@@ -943,7 +944,7 @@ static void close_watchdog_unclean(void)
return;
}
- log_error("/dev/watchdog closed unclean");
+ log_error("%s closed unclean", watchdog_path);
close(dev_fd);
dev_fd = -1;
@@ -961,9 +962,9 @@ static void close_watchdog(void)
rv = write(dev_fd, "V", 1);
if (rv < 0)
- log_error("/dev/watchdog disarm write error %d", errno);
+ log_error("%s disarm write error %d", watchdog_path, errno);
else
- log_error("/dev/watchdog disarmed");
+ log_error("%s disarmed", watchdog_path);
close(dev_fd);
dev_fd = -1;
@@ -981,7 +982,7 @@ static int setup_watchdog(void)
rv = ioctl(dev_fd, WDIOC_GETTIMEOUT, &timeout);
if (rv < 0) {
- log_error("/dev/watchdog failed to report timeout");
+ log_error("%s failed to report timeout", watchdog_path);
close_watchdog();
return -1;
}
@@ -993,18 +994,18 @@ static int setup_watchdog(void)
rv = ioctl(dev_fd, WDIOC_SETTIMEOUT, &timeout);
if (rv < 0) {
- log_error("/dev/watchdog failed to set timeout");
+ log_error("%s failed to set timeout", watchdog_path);
close_watchdog();
return -1;
}
if (timeout != fire_timeout) {
- log_error("/dev/watchdog failed to set new timeout");
+ log_error("%s failed to set new timeout", watchdog_path);
close_watchdog();
return -1;
}
out:
- log_error("/dev/watchdog armed with fire_timeout %d", fire_timeout);
+ log_error("%s armed with fire_timeout %d", watchdog_path, fire_timeout);
return 0;
}
@@ -1153,7 +1154,7 @@ static int test_loop(void)
if (dev_fd == -1) {
open_dev();
pet_watchdog();
- log_error("/dev/watchdog reopen");
+ log_error("%s reopen", watchdog_path);
} else {
pet_watchdog();
}
@@ -1330,6 +1331,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);
exit(status);
}
@@ -1362,7 +1364,7 @@ int main(int argc, char *argv[])
{0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hdVDFH:G:S:s:k:",
+ c = getopt_long(argc, argv, "hdVDFH:G:S:s:k:w:",
long_options, &option_index);
if (c == -1)
break;
@@ -1398,6 +1400,9 @@ int main(int argc, char *argv[])
case 'k':
kill_script_sec = atoi(optarg);
break;
+ case 'w':
+ watchdog_path = strdup(optarg);
+ break;
}
}
--
1.7.1
10 years, 6 months
[PATCH 1/2] wdmd: trap also SIGINT for a clean exit
by Federico Simoncelli
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
wdmd/main.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/wdmd/main.c b/wdmd/main.c
index 28fa042..1f1395a 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -1030,7 +1030,8 @@ static void process_signals(int ci)
return;
}
- if (fdsi.ssi_signo == SIGTERM) {
+ if ((fdsi.ssi_signo == SIGTERM) ||
+ (fdsi.ssi_signo == SIGINT)) {
if (!active_clients())
daemon_quit = 1;
}
@@ -1047,6 +1048,7 @@ static int setup_signals(void)
sigemptyset(&mask);
sigaddset(&mask, SIGTERM);
+ sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGHUP);
rv = sigprocmask(SIG_BLOCK, &mask, NULL);
--
1.7.1
10 years, 6 months
init.d/sanlock.service
by David Teigland
init.d/sanlock.service | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
New commits:
commit 917c64327acb0ae53ce605dc6b47a4a0f4983827
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Tue Nov 13 10:59:09 2012 -0600
systemd: add wdmd dependency for sanlock
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/init.d/sanlock.service b/init.d/sanlock.service
index f026fe0..64d9ced 100644
--- a/init.d/sanlock.service
+++ b/init.d/sanlock.service
@@ -1,6 +1,7 @@
[Unit]
Description=Shared Storage Lease Manager
-After=syslog.target wdmd.service
+After=syslog.target
+Wants=wdmd.service
[Service]
Type=forking
10 years, 7 months