.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();