src/client_resource.c | 9 +++++++--
src/delta_lease.c | 2 ++
src/diskio.c | 5 +++++
src/host_id.c | 5 +++++
src/paxos_lease.c | 12 ++++++------
5 files changed, 25 insertions(+), 8 deletions(-)
New commits:
commit 39b47eeee5edb2d69088d83e23fc83fc1c62c046
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Aug 23 11:57:39 2011 -0500
sanlock: minor fixes and cleanups
handle null str arg in str_to_lockspace
handle error from direct_align
free mem from leaders_read_multiple (not using this function)
diff --git a/src/client_resource.c b/src/client_resource.c
index eeffae4..18f185f 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -536,6 +536,7 @@ int sanlock_args_to_state(int res_count,
free(str);
}
+ /* caller to free state */
*res_state = state;
return 0;
}
@@ -592,6 +593,7 @@ int sanlock_state_to_args(char *res_state,
memset(str, 0, sizeof(str));
}
+ /* caller to free res_count res and args */
*res_count = arg_count;
*res_args = args;
return 0;
@@ -617,6 +619,9 @@ int sanlock_str_to_lockspace(char *str, struct sanlk_lockspace *ls)
char *offset = NULL;
int i;
+ if (!str)
+ return -EINVAL;
+
for (i = 0; i < strlen(str); i++) {
if (str[i] == '\\') {
i++;
@@ -646,8 +651,8 @@ int sanlock_str_to_lockspace(char *str, struct sanlk_lockspace *ls)
offset++;
}
- if (str)
- strncpy(ls->name, str, NAME_ID_SIZE);
+ strncpy(ls->name, str, NAME_ID_SIZE);
+
if (host_id)
ls->host_id = atoll(host_id);
if (path)
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 12386ce..f8dc729 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -538,6 +538,8 @@ int delta_lease_init(struct task *task,
max_hosts = DEFAULT_MAX_HOSTS;
align_size = direct_align(disk);
+ if (align_size < 0)
+ return align_size;
if (disk->sector_size * max_hosts > align_size)
return -E2BIG;
diff --git a/src/diskio.c b/src/diskio.c
index c336b3b..bd8f72e 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -153,6 +153,11 @@ int open_disk(struct sync_disk *disk)
}
align_size = direct_align(disk);
+ if (align_size < 0) {
+ rv = align_size;
+ close(fd);
+ goto fail;
+ }
if (disk->offset % align_size) {
rv = -EBADSLT;
diff --git a/src/host_id.c b/src/host_id.c
index a16194e..b7faef2 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -356,6 +356,11 @@ static void *lockspace_thread(void *arg_in)
opened = 1;
sp->align_size = direct_align(&sp->host_id_disk);
+ if (sp->align_size < 0) {
+ log_erros(sp, "direct_align error");
+ acquire_result = sp->align_size;
+ goto set_status;
+ }
sp->lease_status.renewal_read_buf = malloc(sp->align_size);
if (!sp->lease_status.renewal_read_buf) {
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 0816a64..2a65c60 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -779,7 +779,7 @@ static int _leader_read_multiple(struct task *task,
if (!majority_disks(token, num_reads)) {
log_errot(token, "%s leader read error %d", caller, rv);
error = SANLK_LEADER_READ;
- goto fail;
+ goto out;
}
/* check that a majority of disks have the same leader */
@@ -801,13 +801,11 @@ static int _leader_read_multiple(struct task *task,
if (!found) {
log_errot(token, "%s leader inconsistent", caller);
error = SANLK_LEADER_DIFF;
- goto fail;
+ goto out;
}
- memcpy(leader_ret, &leader, sizeof(struct leader_record));
- return SANLK_OK;
-
- fail:
+ error = SANLK_OK;
+ out:
memcpy(leader_ret, &leader, sizeof(struct leader_record));
free(leaders);
free(leader_reps);
@@ -1481,6 +1479,8 @@ int paxos_lease_init(struct task *task,
max_hosts = DEFAULT_MAX_HOSTS;
align_size = direct_align(&token->disks[0]);
+ if (align_size < 0)
+ return align_size;
if (token->disks[0].sector_size * (2 + max_hosts) > align_size)
return -E2BIG;