src/client_msg.h | 18 +++++++++---------
src/delta_lease.c | 40 +++++++++++++++++++++++++---------------
src/main.c | 6 +++---
tests/devcount.c | 8 ++++----
4 files changed, 41 insertions(+), 31 deletions(-)
New commits:
commit 9d304e986d50f0c4163d7557f2e37114b8f71f10
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Apr 15 17:12:19 2011 -0500
sanlock: misc changes and fix
fix goto fail/out was wrong
other minor changes
diff --git a/src/client_msg.h b/src/client_msg.h
index 2f8ffca..12b206a 100644
--- a/src/client_msg.h
+++ b/src/client_msg.h
@@ -12,15 +12,15 @@
#define MAX_CLIENT_MSG (1024 * 1024) /* TODO: this is random */
enum {
- SM_CMD_REGISTER = 1,
- SM_CMD_ADD_LOCKSPACE,
- SM_CMD_REM_LOCKSPACE,
- SM_CMD_SHUTDOWN,
- SM_CMD_STATUS,
- SM_CMD_LOG_DUMP,
- SM_CMD_ACQUIRE,
- SM_CMD_RELEASE,
- SM_CMD_INQUIRE,
+ 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,
};
#define SANLK_STATE_MAXSTR 4096
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 34d651e..56d8283 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -36,37 +36,47 @@
static int verify_leader(struct sync_disk *disk,
char *space_name,
- char *resource_name,
+ uint64_t host_id,
struct leader_record *lr)
{
+ char resource_name[NAME_ID_SIZE];
uint32_t sum;
if (lr->magic != DELTA_DISK_MAGIC) {
- log_error("verify_leader wrong magic %x %s",
+ log_error("verify_leader %llu wrong magic %x %s",
+ (unsigned long long)host_id,
lr->magic, disk->path);
return SANLK_BAD_MAGIC;
}
if ((lr->version & 0xFFFF0000) != DELTA_DISK_VERSION_MAJOR) {
- log_error("verify_leader wrong version %x %s",
+ log_error("verify_leader %llu wrong version %x %s",
+ (unsigned long long)host_id,
lr->version, disk->path);
return SANLK_BAD_VERSION;
}
if (lr->sector_size != disk->sector_size) {
- log_error("verify_leader wrong sector size %d %d %s",
+ log_error("verify_leader %llu wrong sector size %d %d %s",
+ (unsigned long long)host_id,
lr->sector_size, disk->sector_size, disk->path);
return SANLK_BAD_SECTORSIZE;
}
if (strncmp(lr->space_name, space_name, NAME_ID_SIZE)) {
- log_error("verify_leader wrong space name %.48s %.48s %s",
+ log_error("verify_leader %llu wrong space name %.48s %.48s %s",
+ (unsigned long long)host_id,
lr->space_name, space_name, disk->path);
return SANLK_BAD_LOCKSPACE;
}
+ memset(resource_name, 0, NAME_ID_SIZE);
+ snprintf(resource_name, NAME_ID_SIZE, "host_id_%llu",
+ (unsigned long long)host_id);
+
if (strncmp(lr->resource_name, resource_name, NAME_ID_SIZE)) {
- log_error("verify_leader wrong resource name %.48s %.48s %s",
+ log_error("verify_leader %llu wrong resource name %.48s %.48s %s",
+ (unsigned long long)host_id,
lr->resource_name, resource_name, disk->path);
return SANLK_BAD_RESOURCEID;
}
@@ -74,7 +84,8 @@ static int verify_leader(struct sync_disk *disk,
sum = leader_checksum(lr);
if (lr->checksum != sum) {
- log_error("verify_leader wrong checksum %x %x %s",
+ log_error("verify_leader %llu wrong checksum %x %x %s",
+ (unsigned long long)host_id,
lr->checksum, sum, disk->path);
return SANLK_BAD_CHECKSUM;
}
@@ -88,24 +99,23 @@ int delta_lease_leader_read(struct timeout *ti,
uint64_t host_id,
struct leader_record *leader_ret)
{
- char resource_name[NAME_ID_SIZE];
+ struct leader_record leader;
int rv, error;
/* host_id N is block offset N-1 */
- rv = read_sectors(disk, host_id - 1, 1, (char *)leader_ret,
+ rv = read_sectors(disk, host_id - 1, 1, (char *)&leader,
sizeof(struct leader_record),
ti->io_timeout_seconds, ti->use_aio, "delta_leader");
if (rv < 0)
return SANLK_READ_LEADERS;
- memset(resource_name, 0, NAME_ID_SIZE);
- snprintf(resource_name, NAME_ID_SIZE, "host_id_%llu",
- (unsigned long long)host_id);
-
- error = verify_leader(disk, space_name, resource_name, leader_ret);
+ error = verify_leader(disk, space_name, host_id, &leader);
+ if (error < 0)
+ return error;
- return error;
+ memcpy(leader_ret, &leader, sizeof(struct leader_record));
+ return SANLK_OK;
}
int delta_lease_acquire(struct timeout *ti,
diff --git a/src/main.c b/src/main.c
index 1e2731a..14c2a66 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1680,8 +1680,8 @@ static void process_cmd_thread_resource(int ci_in, struct sm_header
*h_recv)
/* lease for another registered client with pid specified by data2 */
ci_target = find_client_pid(h_recv->data2);
if (ci_target < 0) {
- result = -ENOENT;
- goto out;
+ result = -ESRCH;
+ goto fail;
}
} else {
/* lease for this registered client */
@@ -1691,7 +1691,7 @@ static void process_cmd_thread_resource(int ci_in, struct sm_header
*h_recv)
ca = malloc(sizeof(struct cmd_args));
if (!ca) {
result = -ENOMEM;
- goto out;
+ goto fail;
}
cl = &client[ci_target];
diff --git a/tests/devcount.c b/tests/devcount.c
index ab03003..074b495 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -469,7 +469,7 @@ static int do_relock(int argc, char *argv[])
rv = sanlock_inquire(-1, pid, 0, &res_count, &state);
if (rv < 0) {
/* pid may have exited */
- printf("sanlock_inquire error %d\n", rv);
+ printf("%d sanlock_inquire error %d\n", parent_pid, rv);
goto run_more;
}
rv = sanlock_str_to_res(state, &res_inq);
@@ -490,7 +490,7 @@ static int do_relock(int argc, char *argv[])
rv = sanlock_release(-1, pid, SANLK_REL_ALL, 0, NULL);
if (rv < 0) {
/* pid may have exited */
- printf("sanlock_release error %d\n", rv);
+ printf("%d sanlock_release error %d\n", parent_pid, rv);
goto run_more;
}
@@ -965,7 +965,7 @@ static int do_migrate(int argc, char *argv[])
rv = sanlock_inquire(-1, pid, 0, &res_count, &state);
if (rv < 0) {
- printf("sanlock_inquire error %d\n", rv);
+ printf("%d sanlock_inquire error %d\n", parent_pid, rv);
goto fail;
}
printf("%d sanlock_inquire done\n", parent_pid);
@@ -974,7 +974,7 @@ static int do_migrate(int argc, char *argv[])
rv = sanlock_release(-1, pid, SANLK_REL_ALL, 0, NULL);
if (rv < 0) {
- printf("sanlock_release error %d\n", rv);
+ printf("%d sanlock_release error %d\n", parent_pid, rv);
goto fail;
}
printf("%d sanlock_release done\n", parent_pid);