src/main.c
by David Teigland
src/main.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
New commits:
commit a4d42ec6cd865f1cad1122b6ea67906de8e2a8cb
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 19 11:47:39 2011 -0500
sanlock: interval between renewal checks
A lot of client activity would create a lot of repeated
lockspace checks back to back. Enforce the desired intervals
between the checks.
diff --git a/src/main.c b/src/main.c
index 14c2a66..a5d251b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -516,16 +516,30 @@ static int all_pids_dead(struct space *sp)
return 1;
}
-#define MAIN_POLL_MS 2000
+static unsigned int time_diff(struct timeval *begin, struct timeval *end)
+{
+ struct timeval result;
+ timersub(end, begin, &result);
+ return (result.tv_sec * 1000) + (result.tv_usec / 1000);
+}
+
+#define STANDARD_CHECK_INTERVAL 1000 /* milliseconds */
+#define RECOVERY_CHECK_INTERVAL 200 /* milliseconds */
static int main_loop(void)
{
void (*workfn) (int ci);
void (*deadfn) (int ci);
struct space *sp, *safe;
- int poll_timeout = MAIN_POLL_MS;
+ struct timeval now, last_check;
+ int poll_timeout, check_interval;
+ unsigned int ms;
int i, rv, empty;
+ gettimeofday(&last_check, NULL);
+ poll_timeout = STANDARD_CHECK_INTERVAL;
+ check_interval = STANDARD_CHECK_INTERVAL;
+
while (1) {
rv = poll(pollfd, client_maxi + 1, poll_timeout);
if (rv == -1 && errno == EINTR)
@@ -548,6 +562,15 @@ static int main_loop(void)
}
}
+
+ gettimeofday(&now, NULL);
+ ms = time_diff(&last_check, &now);
+ if (ms < check_interval) {
+ poll_timeout = check_interval - ms;
+ continue;
+ }
+ last_check = now;
+
pthread_mutex_lock(&spaces_mutex);
list_for_each_entry_safe(sp, safe, &spaces, list) {
if (sp->killing_pids) {
@@ -562,12 +585,16 @@ static int main_loop(void)
} else {
kill_pids(sp);
}
+ check_interval = RECOVERY_CHECK_INTERVAL;
} else {
if (external_shutdown || sp->external_remove ||
!host_id_renewed(sp)) {
log_space(sp, "set killing_pids");
sp->killing_pids = 1;
kill_pids(sp);
+ check_interval = RECOVERY_CHECK_INTERVAL;
+ } else {
+ check_interval = STANDARD_CHECK_INTERVAL;
}
}
}
@@ -578,6 +605,13 @@ static int main_loop(void)
break;
clear_spaces(0);
+
+ gettimeofday(&now, NULL);
+ ms = time_diff(&last_check, &now);
+ if (ms < check_interval)
+ poll_timeout = check_interval - ms;
+ else
+ poll_timeout = 1;
}
clear_spaces(1);
13 years
python/sanlockmod.c
by David Teigland
python/sanlockmod.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
New commits:
commit 70e18d301a967b996ed1882b49a3bf91d2fb175e
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Mon Apr 18 16:26:45 2011 +0100
python: register process only once
diff --git a/python/sanlockmod.c b/python/sanlockmod.c
index 789246a..9d214f5 100644
--- a/python/sanlockmod.c
+++ b/python/sanlockmod.c
@@ -60,9 +60,9 @@ __parse_resource(char *resource, struct sanlk_resource **ret_res)
static PyObject *
py_register(PyObject *self, PyObject *args)
{
- Py_BEGIN_ALLOW_THREADS
- __sanlockmod_fd = sanlock_register();
- Py_END_ALLOW_THREADS
+ if (__sanlockmod_fd < 0) {
+ __sanlockmod_fd = sanlock_register();
+ }
if (__sanlockmod_fd < 0) {
PyErr_SetString(sanlockmod_exception, "SANLock registration failed");
13 years
src/delta_lease.c src/delta_lease.h src/direct.c src/host_id.c src/paxos_lease.c
by David Teigland
src/delta_lease.c | 93 +++++++++++++++++++++++++++++++++++++++++++++---------
src/delta_lease.h | 3 +
src/direct.c | 6 ++-
src/host_id.c | 2 -
src/paxos_lease.c | 74 +++++++++++++++++++++++++++++++++++++-----
5 files changed, 151 insertions(+), 27 deletions(-)
New commits:
commit bf4c25094f57ef31166ef59e71d5b19236d5719c
Author: David Teigland <teigland(a)redhat.com>
Date: Mon Apr 18 15:41:21 2011 -0500
sanlock: log error of full bad block
when verify_leader finds a bad block, put all the
data in the error message, and then re-read the block
and log those values also.
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 56d8283..19a8b61 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -34,40 +34,81 @@
/* delta_leases are a series max_hosts leader_records, one leader per sector,
host N's delta_lease is the leader_record in sectors N-1 */
+static void log_leader_error(int result,
+ char *space_name,
+ uint64_t host_id,
+ struct sync_disk *disk,
+ struct leader_record *lr,
+ const char *caller)
+{
+ log_error("leader1 %s error %d lockspace %.48s host_id %llu",
+ caller ? caller : "unknown",
+ result,
+ space_name,
+ (unsigned long long)host_id);
+
+ log_error("leader2 path %s offset %llu",
+ disk->path,
+ (unsigned long long)disk->offset);
+
+ log_error("leader3 m %u v %u ss %u nh %llu mh %llu oi %llu og %llu lv %llu",
+ lr->magic,
+ lr->version,
+ lr->sector_size,
+ (unsigned long long)lr->num_hosts,
+ (unsigned long long)lr->max_hosts,
+ (unsigned long long)lr->owner_id,
+ (unsigned long long)lr->owner_generation,
+ (unsigned long long)lr->lver);
+
+ log_error("leader4 sn %.48s rn %.48s ts %llu cs %x",
+ lr->space_name,
+ lr->resource_name,
+ (unsigned long long)lr->timestamp,
+ lr->checksum);
+}
+
static int verify_leader(struct sync_disk *disk,
char *space_name,
uint64_t host_id,
- struct leader_record *lr)
+ struct leader_record *lr,
+ const char *caller)
{
+ struct leader_record leader_rr;
char resource_name[NAME_ID_SIZE];
uint32_t sum;
+ int result, rv;
if (lr->magic != DELTA_DISK_MAGIC) {
log_error("verify_leader %llu wrong magic %x %s",
(unsigned long long)host_id,
lr->magic, disk->path);
- return SANLK_BAD_MAGIC;
+ result = SANLK_BAD_MAGIC;
+ goto fail;
}
if ((lr->version & 0xFFFF0000) != DELTA_DISK_VERSION_MAJOR) {
log_error("verify_leader %llu wrong version %x %s",
(unsigned long long)host_id,
lr->version, disk->path);
- return SANLK_BAD_VERSION;
+ result = SANLK_BAD_VERSION;
+ goto fail;
}
if (lr->sector_size != disk->sector_size) {
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;
+ result = SANLK_BAD_SECTORSIZE;
+ goto fail;
}
if (strncmp(lr->space_name, space_name, NAME_ID_SIZE)) {
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;
+ result = SANLK_BAD_LOCKSPACE;
+ goto fail;
}
memset(resource_name, 0, NAME_ID_SIZE);
@@ -78,7 +119,8 @@ static int verify_leader(struct sync_disk *disk,
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;
+ result = SANLK_BAD_RESOURCEID;
+ goto fail;
}
sum = leader_checksum(lr);
@@ -87,30 +129,48 @@ static int verify_leader(struct sync_disk *disk,
log_error("verify_leader %llu wrong checksum %x %x %s",
(unsigned long long)host_id,
lr->checksum, sum, disk->path);
- return SANLK_BAD_CHECKSUM;
+ result = SANLK_BAD_CHECKSUM;
+ goto fail;
}
return SANLK_OK;
+
+ fail:
+ log_leader_error(result, space_name, host_id, disk, lr, caller);
+
+ memset(&leader_rr, 0, sizeof(leader_rr));
+
+ rv = read_sectors(disk, host_id - 1, 1, (char *)&leader_rr,
+ sizeof(struct leader_record),
+ 0, 0, "delta_verify");
+
+ log_leader_error(rv, space_name, host_id, disk, &leader_rr, "delta_verify");
+
+ return result;
}
int delta_lease_leader_read(struct timeout *ti,
struct sync_disk *disk,
char *space_name,
uint64_t host_id,
- struct leader_record *leader_ret)
+ struct leader_record *leader_ret,
+ const char *caller)
{
struct leader_record leader;
int rv, error;
/* host_id N is block offset N-1 */
+ memset(&leader, 0, sizeof(struct leader_record));
+ memset(leader_ret, 0, sizeof(struct leader_record));
+
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;
- error = verify_leader(disk, space_name, host_id, &leader);
+ error = verify_leader(disk, space_name, host_id, &leader, caller);
if (error < 0)
return error;
@@ -131,7 +191,8 @@ int delta_lease_acquire(struct timeout *ti,
log_space(sp, "delta_acquire %llu begin", (unsigned long long)host_id);
- error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader);
+ error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader,
+ "delta_acquire_begin");
if (error < 0)
return error;
@@ -169,7 +230,8 @@ int delta_lease_acquire(struct timeout *ti,
log_space(sp, "delta_acquire long sleep %d", delay);
sleep(delay);
- error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader);
+ error = delta_lease_leader_read(ti, disk, space_name, host_id,
+ &leader, "delta_acquire_wait");
if (error < 0)
return error;
@@ -199,7 +261,8 @@ int delta_lease_acquire(struct timeout *ti,
log_space(sp, "delta_acquire sleep 2d %d", delay);
sleep(delay);
- error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader);
+ error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader,
+ "delta_acquire_check");
if (error < 0)
return error;
@@ -224,7 +287,8 @@ int delta_lease_renew(struct timeout *ti,
/* log_space(sp, "delta_renew %llu begin", (unsigned long long)host_id); */
- error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader);
+ error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader,
+ "delta_renew_begin");
if (error < 0)
return error;
@@ -252,7 +316,8 @@ int delta_lease_renew(struct timeout *ti,
/* log_space(sp, "delta_renew sleep 2d %d", delay); */
sleep(delay);
- error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader);
+ error = delta_lease_leader_read(ti, disk, space_name, host_id, &leader,
+ "delta_renew_check");
if (error < 0)
return error;
diff --git a/src/delta_lease.h b/src/delta_lease.h
index 95d0661..cadfa3f 100644
--- a/src/delta_lease.h
+++ b/src/delta_lease.h
@@ -13,7 +13,8 @@ int delta_lease_leader_read(struct timeout *ti,
struct sync_disk *disk,
char *space_name,
uint64_t host_id,
- struct leader_record *leader_ret);
+ struct leader_record *leader_ret,
+ const char *caller);
int delta_lease_acquire(struct timeout *ti,
struct space *sp,
diff --git a/src/direct.c b/src/direct.c
index fb85f53..1a8312b 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -197,7 +197,8 @@ static int do_delta_action(int action,
rv = delta_lease_leader_read(ti, &sd,
ls->name,
ls->host_id,
- &leader);
+ &leader,
+ "direct_release");
if (rv < 0)
return rv;
rv = delta_lease_release(ti, &space, &sd,
@@ -209,7 +210,8 @@ static int do_delta_action(int action,
rv = delta_lease_leader_read(ti, &sd,
ls->name,
ls->host_id,
- &leader);
+ &leader,
+ "direct_read");
break;
}
diff --git a/src/host_id.c b/src/host_id.c
index 2f7f14f..928d57b 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -124,7 +124,7 @@ int host_id_leader_read(struct timeout *ti,
return rv;
rv = delta_lease_leader_read(ti, &space.host_id_disk, space_name,
- host_id, leader_ret);
+ host_id, leader_ret, "host_id");
if (rv < 0)
return rv;
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 39d0c6c..a11e020 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -406,46 +406,88 @@ uint32_t leader_checksum(struct leader_record *lr)
return crc32c((uint32_t)~1, (char *)lr, LEADER_CHECKSUM_LEN);
}
+static void log_leader_error(int result,
+ struct token *token,
+ struct sync_disk *disk,
+ struct leader_record *lr,
+ const char *caller)
+{
+ log_errot(token, "leader1 %s error %d sn %.48s rn %.48s",
+ caller ? caller : "unknown",
+ result,
+ token->r.lockspace_name,
+ token->r.name);
+
+ log_errot(token, "leader2 path %s offset %llu",
+ disk->path,
+ (unsigned long long)disk->offset);
+
+ log_errot(token, "leader3 m %u v %u ss %u nh %llu mh %llu oi %llu og %llu lv %llu",
+ lr->magic,
+ lr->version,
+ lr->sector_size,
+ (unsigned long long)lr->num_hosts,
+ (unsigned long long)lr->max_hosts,
+ (unsigned long long)lr->owner_id,
+ (unsigned long long)lr->owner_generation,
+ (unsigned long long)lr->lver);
+
+ log_errot(token, "leader4 sn %.48s rn %.48s ts %llu cs %x",
+ lr->space_name,
+ lr->resource_name,
+ (unsigned long long)lr->timestamp,
+ lr->checksum);
+}
+
static int verify_leader(struct token *token, struct sync_disk *disk,
- struct leader_record *lr)
+ struct leader_record *lr,
+ const char *caller)
{
+ struct leader_record leader_rr;
uint32_t sum;
+ int result, rv;
if (lr->magic != PAXOS_DISK_MAGIC) {
log_errot(token, "verify_leader wrong magic %x %s",
lr->magic, disk->path);
- return SANLK_BAD_MAGIC;
+ result = SANLK_BAD_MAGIC;
+ goto fail;
}
if ((lr->version & 0xFFFF0000) != PAXOS_DISK_VERSION_MAJOR) {
log_errot(token, "verify_leader wrong version %x %s",
lr->version, disk->path);
- return SANLK_BAD_VERSION;
+ result = SANLK_BAD_VERSION;
+ goto fail;
}
if (lr->sector_size != disk->sector_size) {
log_errot(token, "verify_leader wrong sector size %d %d %s",
lr->sector_size, disk->sector_size, disk->path);
- return SANLK_BAD_SECTORSIZE;
+ result = SANLK_BAD_SECTORSIZE;
+ goto fail;
}
if (strncmp(lr->space_name, token->r.lockspace_name, NAME_ID_SIZE)) {
log_errot(token, "verify_leader wrong space name %.48s %.48s %s",
lr->space_name, token->r.lockspace_name, disk->path);
- return SANLK_BAD_LOCKSPACE;
+ result = SANLK_BAD_LOCKSPACE;
+ goto fail;
}
if (strncmp(lr->resource_name, token->r.name, NAME_ID_SIZE)) {
log_errot(token, "verify_leader wrong resource name %.48s %.48s %s",
lr->resource_name, token->r.name, disk->path);
- return SANLK_BAD_RESOURCEID;
+ result = SANLK_BAD_RESOURCEID;
+ goto fail;
}
if (lr->num_hosts < token->host_id) {
log_errot(token, "verify_leader num_hosts too small %llu %llu %s",
(unsigned long long)lr->num_hosts,
(unsigned long long)token->host_id, disk->path);
- return SANLK_BAD_NUMHOSTS;
+ result = SANLK_BAD_NUMHOSTS;
+ goto fail;
}
sum = leader_checksum(lr);
@@ -453,10 +495,24 @@ static int verify_leader(struct token *token, struct sync_disk *disk,
if (lr->checksum != sum) {
log_errot(token, "verify_leader wrong checksum %x %x %s",
lr->checksum, sum, disk->path);
- return SANLK_BAD_CHECKSUM;
+ result = SANLK_BAD_CHECKSUM;
+ goto fail;
}
return SANLK_OK;
+
+ fail:
+ log_leader_error(result, token, disk, lr, caller);
+
+ memset(&leader_rr, 0, sizeof(leader_rr));
+
+ rv = read_sectors(disk, 0, 1, (char *)&leader_rr,
+ sizeof(struct leader_record),
+ 0, 0, "paxos_verify");
+
+ log_leader_error(rv, token, disk, &leader_rr, "paxos_verify");
+
+ return result;
}
static int leaders_match(struct leader_record *a, struct leader_record *b)
@@ -509,7 +565,7 @@ int paxos_lease_leader_read(struct timeout *ti,
if (rv < 0)
continue;
- rv = verify_leader(token, &token->disks[d], &leaders[d]);
+ rv = verify_leader(token, &token->disks[d], &leaders[d], caller);
if (rv < 0)
continue;
13 years
src/direct.c
by David Teigland
src/direct.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
New commits:
commit 3bc89aa936c38e488c967b19503068db369a8d00
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Mon Apr 18 14:44:51 2011 +0100
direct: close disks after initialization
diff --git a/src/direct.c b/src/direct.c
index 42dc15c..fb85f53 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -86,7 +86,7 @@ static int do_paxos_action(int action,
rv = paxos_lease_init(ti, token, num_hosts, max_hosts);
if (rv < 0) {
log_tool("cannot initialize disks");
- return -1;
+ goto exit_fail;
}
break;
@@ -97,7 +97,7 @@ static int do_paxos_action(int action,
rv = paxos_lease_acquire(ti, token, 0, &leader_ret, 0, num_hosts);
if (rv < 0) {
log_tool("cannot acquire lease on %s", token->r.name);
- return -1;
+ goto exit_fail;
}
break;
@@ -105,19 +105,21 @@ static int do_paxos_action(int action,
rv = paxos_lease_leader_read(ti, token, &leader_read, "direct_release");
if (rv < 0) {
log_tool("cannot read lease on %s", token->r.name);
- return -1;
+ goto exit_fail;
}
rv = paxos_lease_release(ti, token, &leader_read, &leader_ret);
if (rv < 0) {
log_tool("cannot release lease on %s", token->r.name);
- return -1;
+ goto exit_fail;
}
break;
}
+exit_fail:
+ close_disks(token->disks, token->r.num_disks);
free(token);
- return 0;
+ return rv;
}
/*
@@ -366,6 +368,8 @@ int direct_init(struct timeout *ti,
}
rv = delta_lease_init(ti, &sd, ls->name, max_hosts);
+ close_disks(&sd, 1);
+
if (rv < 0) {
log_tool("lockspace init failed %d", rv);
return -1;
13 years
src/client_msg.h src/delta_lease.c src/main.c tests/devcount.c
by David Teigland
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);
13 years
2 commits - sanlock.spec src/delta_lease.c src/direct.c src/host_id.c src/leader.h src/Makefile src/paxos_lease.c src/sanlock_internal.h src/sanlock_rv.h src/token_manager.c tests/devcount.c
by David Teigland
sanlock.spec | 1
src/Makefile | 2 -
src/delta_lease.c | 26 +++++++-------
src/direct.c | 2 -
src/host_id.c | 14 +++----
src/leader.h | 34 ------------------
src/paxos_lease.c | 66 ++++++++++++++++++------------------
src/sanlock_internal.h | 1
src/sanlock_rv.h | 44 ++++++++++++++++++++++++
src/token_manager.c | 4 +-
tests/devcount.c | 88 ++++++++++++++++++++-----------------------------
11 files changed, 140 insertions(+), 142 deletions(-)
New commits:
commit c28359fe83ae0f9ce51bb6582d08a6d2bff91179
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Apr 15 15:31:53 2011 -0500
sanlock: new return values
new sanlock_rv.h includes sanlock-specific return values
from -200 and less. sanlock also already returns errno.h
values, which overlapped the previous DP_ values.
diff --git a/sanlock.spec b/sanlock.spec
index d502b2f..5b5fdee 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -125,6 +125,7 @@ developing applications that use %{name}.
%{_libdir}/libsanlock.so
%{_libdir}/libsanlock_direct.so
%{_includedir}/sanlock.h
+%{_includedir}/sanlock_rv.h
%{_includedir}/sanlock_admin.h
%{_includedir}/sanlock_resource.h
%{_includedir}/sanlock_direct.h
diff --git a/src/Makefile b/src/Makefile
index 41c11a3..b3c3ade 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -10,7 +10,7 @@ LIB_TARGET = libsanlock
LIB2_TARGET = libsanlock_direct
-HEADER_TARGET = sanlock.h sanlock_resource.h sanlock_admin.h sanlock_direct.h
+HEADER_TARGET = sanlock.h sanlock_rv.h sanlock_resource.h sanlock_admin.h sanlock_direct.h
SOMAJOR=1
SOMINOR=0
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 4561324..34d651e 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -44,31 +44,31 @@ static int verify_leader(struct sync_disk *disk,
if (lr->magic != DELTA_DISK_MAGIC) {
log_error("verify_leader wrong magic %x %s",
lr->magic, disk->path);
- return DP_BAD_MAGIC;
+ return SANLK_BAD_MAGIC;
}
if ((lr->version & 0xFFFF0000) != DELTA_DISK_VERSION_MAJOR) {
log_error("verify_leader wrong version %x %s",
lr->version, disk->path);
- return DP_BAD_VERSION;
+ return SANLK_BAD_VERSION;
}
if (lr->sector_size != disk->sector_size) {
log_error("verify_leader wrong sector size %d %d %s",
lr->sector_size, disk->sector_size, disk->path);
- return DP_BAD_SECTORSIZE;
+ return SANLK_BAD_SECTORSIZE;
}
if (strncmp(lr->space_name, space_name, NAME_ID_SIZE)) {
log_error("verify_leader wrong space name %.48s %.48s %s",
lr->space_name, space_name, disk->path);
- return DP_BAD_LOCKSPACE;
+ return SANLK_BAD_LOCKSPACE;
}
if (strncmp(lr->resource_name, resource_name, NAME_ID_SIZE)) {
log_error("verify_leader wrong resource name %.48s %.48s %s",
lr->resource_name, resource_name, disk->path);
- return DP_BAD_RESOURCEID;
+ return SANLK_BAD_RESOURCEID;
}
sum = leader_checksum(lr);
@@ -76,10 +76,10 @@ static int verify_leader(struct sync_disk *disk,
if (lr->checksum != sum) {
log_error("verify_leader wrong checksum %x %x %s",
lr->checksum, sum, disk->path);
- return DP_BAD_CHECKSUM;
+ return SANLK_BAD_CHECKSUM;
}
- return DP_OK;
+ return SANLK_OK;
}
int delta_lease_leader_read(struct timeout *ti,
@@ -97,7 +97,7 @@ int delta_lease_leader_read(struct timeout *ti,
sizeof(struct leader_record),
ti->io_timeout_seconds, ti->use_aio, "delta_leader");
if (rv < 0)
- return DP_READ_LEADERS;
+ return SANLK_READ_LEADERS;
memset(resource_name, 0, NAME_ID_SIZE);
snprintf(resource_name, NAME_ID_SIZE, "host_id_%llu",
@@ -197,7 +197,7 @@ int delta_lease_acquire(struct timeout *ti,
goto retry;
memcpy(leader_ret, &leader, sizeof(struct leader_record));
- return DP_OK;
+ return SANLK_OK;
}
int delta_lease_renew(struct timeout *ti,
@@ -219,7 +219,7 @@ int delta_lease_renew(struct timeout *ti,
return error;
if (leader.owner_id != our_host_id)
- return DP_BAD_LEADER;
+ return SANLK_BAD_LEADER;
new_ts = time(NULL);
@@ -247,10 +247,10 @@ int delta_lease_renew(struct timeout *ti,
return error;
if ((leader.timestamp != new_ts) || (leader.owner_id != our_host_id))
- return DP_BAD_LEADER;
+ return SANLK_BAD_LEADER;
memcpy(leader_ret, &leader, sizeof(struct leader_record));
- return DP_OK;
+ return SANLK_OK;
}
int delta_lease_release(struct timeout *ti,
@@ -277,7 +277,7 @@ int delta_lease_release(struct timeout *ti,
return error;
memcpy(leader_ret, &leader, sizeof(struct leader_record));
- return DP_OK;
+ return SANLK_OK;
}
/* the host_id lease area begins disk->offset bytes from the start of
diff --git a/src/direct.c b/src/direct.c
index a5ad320..42dc15c 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -211,7 +211,7 @@ static int do_delta_action(int action,
break;
}
- if (rv == DP_OK)
+ if (rv == SANLK_OK)
rv = 0;
if (leader_ret)
diff --git a/src/host_id.c b/src/host_id.c
index f4127c3..2f7f14f 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -181,22 +181,22 @@ static void *host_id_thread(void *arg_in)
/* we need to start the watchdog after we acquire the host_id but
before we allow any pid's to begin running */
- if (result == DP_OK) {
+ if (result == SANLK_OK) {
rv = create_watchdog_file(sp, t);
if (rv < 0) {
log_erros(sp, "create_watchdog failed %d", rv);
- result = DP_ERROR;
+ result = SANLK_ERROR;
}
}
pthread_mutex_lock(&sp->mutex);
sp->lease_status.acquire_last_result = result;
sp->lease_status.acquire_last_time = t;
- if (result == DP_OK)
+ if (result == SANLK_OK)
sp->lease_status.acquire_good_time = t;
sp->lease_status.renewal_last_result = result;
sp->lease_status.renewal_last_time = t;
- if (result == DP_OK)
+ if (result == SANLK_OK)
sp->lease_status.renewal_good_time = t;
pthread_cond_broadcast(&sp->cond);
pthread_mutex_unlock(&sp->mutex);
@@ -244,7 +244,7 @@ static void *host_id_thread(void *arg_in)
sp->lease_status.renewal_last_result = result;
sp->lease_status.renewal_last_time = t;
- if (result == DP_OK) {
+ if (result == SANLK_OK) {
sp->lease_status.renewal_good_time = t;
good_diff = t - good_time;
@@ -274,7 +274,7 @@ static void *host_id_thread(void *arg_in)
/* unlink called below to get it done ASAP */
close_watchdog_file(sp);
out:
- if (dl_result == DP_OK)
+ if (dl_result == SANLK_OK)
delta_lease_release(&to, sp, &sp->host_id_disk, sp->space_name,
sp->host_id, &leader, &leader);
@@ -341,7 +341,7 @@ int add_space(struct space *sp)
result = sp->lease_status.acquire_last_result;
pthread_mutex_unlock(&sp->mutex);
- if (result != DP_OK) {
+ if (result != SANLK_OK) {
/* the thread exits right away if acquire fails */
pthread_join(sp->thread, NULL);
rv = result;
diff --git a/src/leader.h b/src/leader.h
index c3e25b4..87b3d31 100644
--- a/src/leader.h
+++ b/src/leader.h
@@ -9,40 +9,6 @@
#ifndef __LEADER_H__
#define __LEADER_H__
-enum {
- DP_OK = 1,
- DP_NONE = 0, /* unused */
- DP_ERROR = -1,
- DP_INVAL = -2,
- DP_NOMEM = -3,
- DP_LIVE_LEADER = -4,
- DP_DIFF_LEADERS = -5,
- DP_READ_LEADERS = -6,
- DP_OWN_DBLOCK = -7,
- DP_WRITE1_DBLOCKS = -8,
- DP_WRITE2_DBLOCKS = -9,
- DP_WRITE_REQUESTS = -10,
- DP_WRITE_LEADERS = -11,
- DP_READ1_MBAL = -12,
- DP_READ1_LVER = -13,
- DP_READ2_MBAL = -14,
- DP_READ2_LVER = -15,
- DP_READ1_DBLOCKS = -16,
- DP_READ2_DBLOCKS = -17,
- DP_BAD_MAGIC = -18,
- DP_BAD_VERSION = -19,
- DP_BAD_CLUSTERMODE = -20,
- DP_BAD_RESOURCEID = -21,
- DP_BAD_NUMHOSTS = -22,
- DP_BAD_CHECKSUM = -23,
- DP_BAD_LEADER = -24,
- DP_OTHER_INP = -25,
- DP_BAD_SECTORSIZE = -26,
- DP_REACQUIRE_LVER = -27,
- DP_BAD_LOCKSPACE = -28,
- DP_OTHER_OWNER = -29,
-};
-
/* does not include terminating null byte */
/* NB NAME_ID_SIZE must match SANLK_NAME_LEN */
/* NB NAME_ID_SIZE is part of ondisk format */
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 4d85a97..39d0c6c 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -201,12 +201,12 @@ static int run_disk_paxos(struct timeout *ti,
if (!host_id) {
log_errot(token, "invalid host_id");
- return DP_INVAL;
+ return SANLK_INVAL;
}
if (!inp) {
log_errot(token, "invalid inp");
- return DP_INVAL;
+ return SANLK_INVAL;
}
/* read one of our own dblock's to get initial dblock values */
@@ -223,7 +223,7 @@ static int run_disk_paxos(struct timeout *ti,
if (rv < 0) {
log_errot(token, "no initial dblock found");
- return DP_OWN_DBLOCK;
+ return SANLK_OWN_DBLOCK;
}
log_token(token, "initial dblock %u mbal %llu bal %llu inp %llu lver %llu", d,
@@ -267,7 +267,7 @@ static int run_disk_paxos(struct timeout *ti,
if (!majority_disks(token, num_writes)) {
log_errot(token, "cannot write dblock to majority of disks");
- return DP_WRITE1_DBLOCKS;
+ return SANLK_WRITE1_DBLOCKS;
}
num_reads = 0;
@@ -287,7 +287,7 @@ static int run_disk_paxos(struct timeout *ti,
d, q,
(unsigned long long)bk[q].lver,
(unsigned long long)dblock.lver);
- return DP_READ1_LVER;
+ return SANLK_READ1_LVER;
}
/* see "It aborts the ballot" in comment above */
@@ -297,7 +297,7 @@ static int run_disk_paxos(struct timeout *ti,
d, q,
(unsigned long long)bk[q].mbal,
(unsigned long long)dblock.mbal);
- return DP_READ1_MBAL;
+ return SANLK_READ1_MBAL;
}
/* see choosing inp for phase 2 in comment below */
@@ -312,7 +312,7 @@ static int run_disk_paxos(struct timeout *ti,
if (!majority_disks(token, num_reads)) {
log_errot(token, "cannot read dblocks on majority of disks");
- return DP_READ1_DBLOCKS;
+ return SANLK_READ1_DBLOCKS;
}
/*
@@ -354,7 +354,7 @@ static int run_disk_paxos(struct timeout *ti,
if (!majority_disks(token, num_writes)) {
log_errot(token, "cannot write dblock to majority of disks 2");
- return DP_WRITE2_DBLOCKS;
+ return SANLK_WRITE2_DBLOCKS;
}
num_reads = 0;
@@ -374,7 +374,7 @@ static int run_disk_paxos(struct timeout *ti,
d, q,
(unsigned long long)bk[q].lver,
(unsigned long long)dblock.lver);
- return DP_READ2_LVER;
+ return SANLK_READ2_LVER;
}
/* see "It aborts the ballot" in comment above */
@@ -384,21 +384,21 @@ static int run_disk_paxos(struct timeout *ti,
d, q,
(unsigned long long)bk[q].mbal,
(unsigned long long)dblock.mbal);
- return DP_READ2_MBAL;
+ return SANLK_READ2_MBAL;
}
}
}
if (!majority_disks(token, num_reads)) {
log_errot(token, "cannot read dblocks from majority of disks 2");
- return DP_READ2_DBLOCKS;
+ return SANLK_READ2_DBLOCKS;
}
/* "When it completes phase 2, p has committed dblock[p].inp." */
memcpy(dblock_out, &dblock, sizeof(struct paxos_dblock));
- return DP_OK;
+ return SANLK_OK;
}
uint32_t leader_checksum(struct leader_record *lr)
@@ -414,38 +414,38 @@ static int verify_leader(struct token *token, struct sync_disk *disk,
if (lr->magic != PAXOS_DISK_MAGIC) {
log_errot(token, "verify_leader wrong magic %x %s",
lr->magic, disk->path);
- return DP_BAD_MAGIC;
+ return SANLK_BAD_MAGIC;
}
if ((lr->version & 0xFFFF0000) != PAXOS_DISK_VERSION_MAJOR) {
log_errot(token, "verify_leader wrong version %x %s",
lr->version, disk->path);
- return DP_BAD_VERSION;
+ return SANLK_BAD_VERSION;
}
if (lr->sector_size != disk->sector_size) {
log_errot(token, "verify_leader wrong sector size %d %d %s",
lr->sector_size, disk->sector_size, disk->path);
- return DP_BAD_SECTORSIZE;
+ return SANLK_BAD_SECTORSIZE;
}
if (strncmp(lr->space_name, token->r.lockspace_name, NAME_ID_SIZE)) {
log_errot(token, "verify_leader wrong space name %.48s %.48s %s",
lr->space_name, token->r.lockspace_name, disk->path);
- return DP_BAD_LOCKSPACE;
+ return SANLK_BAD_LOCKSPACE;
}
if (strncmp(lr->resource_name, token->r.name, NAME_ID_SIZE)) {
log_errot(token, "verify_leader wrong resource name %.48s %.48s %s",
lr->resource_name, token->r.name, disk->path);
- return DP_BAD_RESOURCEID;
+ return SANLK_BAD_RESOURCEID;
}
if (lr->num_hosts < token->host_id) {
log_errot(token, "verify_leader num_hosts too small %llu %llu %s",
(unsigned long long)lr->num_hosts,
(unsigned long long)token->host_id, disk->path);
- return DP_BAD_NUMHOSTS;
+ return SANLK_BAD_NUMHOSTS;
}
sum = leader_checksum(lr);
@@ -453,10 +453,10 @@ static int verify_leader(struct token *token, struct sync_disk *disk,
if (lr->checksum != sum) {
log_errot(token, "verify_leader wrong checksum %x %x %s",
lr->checksum, sum, disk->path);
- return DP_BAD_CHECKSUM;
+ return SANLK_BAD_CHECKSUM;
}
- return DP_OK;
+ return SANLK_OK;
}
static int leaders_match(struct leader_record *a, struct leader_record *b)
@@ -484,12 +484,12 @@ int paxos_lease_leader_read(struct timeout *ti,
leaders = malloc(leaders_len);
if (!leaders)
- return DP_NOMEM;
+ return SANLK_NOMEM;
leader_reps = malloc(leader_reps_len);
if (!leader_reps) {
free(leaders);
- return DP_NOMEM;
+ return SANLK_NOMEM;
}
/*
@@ -529,7 +529,7 @@ int paxos_lease_leader_read(struct timeout *ti,
if (!majority_disks(token, num_reads)) {
log_errot(token, "paxos_leader_read no majority reads");
- error = DP_READ_LEADERS;
+ error = SANLK_READ_LEADERS;
goto fail;
}
@@ -551,7 +551,7 @@ int paxos_lease_leader_read(struct timeout *ti,
if (!found) {
log_errot(token, "paxos_leader_read no majority reps");
- error = DP_DIFF_LEADERS;
+ error = SANLK_DIFF_LEADERS;
goto fail;
}
@@ -565,7 +565,7 @@ int paxos_lease_leader_read(struct timeout *ti,
prev_leader.resource_name);
memcpy(leader_ret, &prev_leader, sizeof(struct leader_record));
- return DP_OK;
+ return SANLK_OK;
fail:
free(leaders);
@@ -578,7 +578,7 @@ static int write_new_leader(struct timeout *ti,
{
int num_disks = token->r.num_disks;
int num_writes = 0;
- int error = DP_OK;
+ int error = SANLK_OK;
int rv, d;
for (d = 0; d < num_disks; d++) {
@@ -590,7 +590,7 @@ static int write_new_leader(struct timeout *ti,
if (!majority_disks(token, num_writes)) {
log_errot(token, "write_new_leader no majority writes");
- error = DP_WRITE_LEADERS;
+ error = SANLK_WRITE_LEADERS;
}
return error;
@@ -728,7 +728,7 @@ int paxos_lease_acquire(struct timeout *ti,
if (last_timestamp && (host_id_leader.timestamp != last_timestamp)) {
log_errot(token, "paxos_acquire host_id %llu alive",
(unsigned long long)prev_leader.owner_id);
- error = DP_LIVE_LEADER;
+ error = SANLK_LIVE_LEADER;
goto out;
}
@@ -741,7 +741,7 @@ int paxos_lease_acquire(struct timeout *ti,
log_errot(token, "paxos_acquire acquire_lver %llu prev_leader %llu",
(unsigned long long)acquire_lver,
(unsigned long long)prev_leader.lver);
- error = DP_REACQUIRE_LVER;
+ error = SANLK_REACQUIRE_LVER;
goto out;
}
@@ -782,7 +782,7 @@ int paxos_lease_acquire(struct timeout *ti,
(unsigned long long)dblock.bal,
(unsigned long long)dblock.inp,
(unsigned long long)dblock.lver);
- error = DP_OTHER_INP;
+ error = SANLK_OTHER_INP;
goto out;
}
@@ -844,7 +844,7 @@ int paxos_lease_renew(struct timeout *ti,
if (memcmp(&new_leader, leader_last,
sizeof(struct leader_record))) {
log_errot(token, "leader changed between renewals");
- return DP_BAD_LEADER;
+ return SANLK_BAD_LEADER;
}
}
@@ -877,13 +877,13 @@ int paxos_lease_release(struct timeout *ti,
if (memcmp(&leader, leader_last, sizeof(struct leader_record))) {
log_errot(token, "release error leader changed");
- return DP_BAD_LEADER;
+ return SANLK_BAD_LEADER;
}
if (leader.owner_id != token->host_id) {
log_errot(token, "release error other owner_id %llu",
(unsigned long long)leader.owner_id);
- return DP_OTHER_OWNER;
+ return SANLK_OTHER_OWNER;
}
leader.timestamp = LEASE_FREE;
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index eadbdc5..60ffb2d 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -21,6 +21,7 @@
#endif
#include "sanlock.h"
+#include "sanlock_rv.h"
#include "leader.h"
#include "list.h"
diff --git a/src/sanlock_rv.h b/src/sanlock_rv.h
new file mode 100644
index 0000000..53c6c4f
--- /dev/null
+++ b/src/sanlock_rv.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ */
+
+#ifndef __SANLOCK_RV_H__
+#define __SANLOCK_RV_H__
+
+#define SANLK_OK 1
+#define SANLK_NONE 0 /* unused */
+#define SANLK_ERROR -201
+#define SANLK_INVAL -202
+#define SANLK_NOMEM -203
+#define SANLK_LIVE_LEADER -204
+#define SANLK_DIFF_LEADERS -205
+#define SANLK_READ_LEADERS -206
+#define SANLK_OWN_DBLOCK -207
+#define SANLK_WRITE1_DBLOCKS -208
+#define SANLK_WRITE2_DBLOCKS -209
+#define SANLK_WRITE_REQUESTS -210
+#define SANLK_WRITE_LEADERS -211
+#define SANLK_READ1_MBAL -212
+#define SANLK_READ1_LVER -213
+#define SANLK_READ2_MBAL -214
+#define SANLK_READ2_LVER -215
+#define SANLK_READ1_DBLOCKS -216
+#define SANLK_READ2_DBLOCKS -217
+#define SANLK_BAD_MAGIC -218
+#define SANLK_BAD_VERSION -219
+#define SANLK_BAD_CLUSTERMODE -220
+#define SANLK_BAD_RESOURCEID -221
+#define SANLK_BAD_NUMHOSTS -222
+#define SANLK_BAD_CHECKSUM -223
+#define SANLK_BAD_LEADER -224
+#define SANLK_OTHER_INP -225
+#define SANLK_BAD_SECTORSIZE -226
+#define SANLK_REACQUIRE_LVER -227
+#define SANLK_BAD_LOCKSPACE -228
+#define SANLK_OTHER_OWNER -229
+
+#endif
diff --git a/src/token_manager.c b/src/token_manager.c
index f57a91b..3b19a5d 100644
--- a/src/token_manager.c
+++ b/src/token_manager.c
@@ -138,7 +138,7 @@ int acquire_token(struct token *token, uint64_t acquire_lver,
memcpy(&token->leader, &leader_ret, sizeof(struct leader_record));
token->r.lver = token->leader.lver;
- return rv; /* DP_OK */
+ return rv; /* SANLK_OK */
}
/* return < 0 on error, 1 on success */
@@ -158,7 +158,7 @@ int release_token(struct token *token)
return rv;
memcpy(&token->leader, &leader_ret, sizeof(struct leader_record));
- return rv; /* DP_OK */
+ return rv; /* SANLK_OK */
}
/* thread that releases tokens of pid's that die */
commit 48d9992dde1ffaf0e67ebd418b0f9037910e8baf
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Apr 15 14:34:44 2011 -0500
devcount: small changes
diff --git a/tests/devcount.c b/tests/devcount.c
index e372645..ab03003 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -26,9 +26,9 @@ char count_path[PATH_MAX];
char lock_path[PATH_MAX];
int count_offset;
int lock_offset;
-
int our_hostid;
int max_hostid;
+struct sanlk_lockspace lockspace;
struct entry {
uint32_t turn;
@@ -329,6 +329,19 @@ static int do_count(int argc, char *argv[])
return -1;
}
+static void add_lockspace(void)
+{
+ int rv;
+
+ strcpy(lockspace.name, "devcount");
+ strcpy(lockspace.host_id_disk.path, lock_path);
+ lockspace.host_id_disk.offset = lock_offset;
+ lockspace.host_id = our_hostid;
+
+ rv = sanlock_add_lockspace(&lockspace, 0);
+ printf("%d sanlock_add_lockspace %d\n", getpid(), rv);
+}
+
/*
* Test inquire and acquire with version
*
@@ -361,7 +374,6 @@ static int do_count(int argc, char *argv[])
static int do_relock(int argc, char *argv[])
{
char *av[COUNT_ARGS+1];
- struct sanlk_lockspace lockspace;
struct sanlk_resource *res, *res_inq;
int i, j, pid, rv, sock, len, status;
int res_count;
@@ -378,10 +390,12 @@ static int do_relock(int argc, char *argv[])
strcpy(count_path, argv[4]);
our_hostid = atoi(argv[7]);
+ add_lockspace();
+
len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
res = malloc(len);
memset(res, 0, len);
- strcpy(res->lockspace_name, "devcount");
+ strcpy(res->lockspace_name, lockspace.name);
snprintf(res->name, SANLK_NAME_LEN, "resource%s", count_path);
res->name[SANLK_NAME_LEN-1] = '\0';
res->num_disks = 1;
@@ -389,15 +403,6 @@ static int do_relock(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- memset(&lockspace, 0, sizeof(lockspace));
- strcpy(lockspace.name, "devcount");
- strcpy(lockspace.host_id_disk.path, lock_path);
- lockspace.host_id_disk.offset = lock_offset;
- lockspace.host_id = our_hostid;
-
- rv = sanlock_add_lockspace(&lockspace, 0);
- printf("%d sanlock_add_lockspace %d\n", parent_pid, rv);
-
/*
* argv[0] = devcount
* argv[1] = relock
@@ -417,8 +422,6 @@ static int do_relock(int argc, char *argv[])
if (!pid) {
int child_pid = getpid();
- printf("\n");
-
sock = sanlock_register();
if (sock < 0) {
printf("%d sanlock_register error %d\n",
@@ -465,9 +468,9 @@ static int do_relock(int argc, char *argv[])
rv = sanlock_inquire(-1, pid, 0, &res_count, &state);
if (rv < 0) {
- /* FIXME: if child exited this should just continue */
+ /* pid may have exited */
printf("sanlock_inquire error %d\n", rv);
- goto fail;
+ goto run_more;
}
rv = sanlock_str_to_res(state, &res_inq);
if (rv < 0) {
@@ -486,8 +489,9 @@ 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);
- goto fail;
+ goto run_more;
}
printf("%d sanlock_release done\n", parent_pid);
@@ -533,10 +537,8 @@ static int do_relock(int argc, char *argv[])
static int do_lock(int argc, char *argv[])
{
char *av[COUNT_ARGS+1];
- struct sanlk_lockspace lockspace;
struct sanlk_resource *res;
int i, j, pid, rv, sock, len, status;
- uint32_t parent_pid = getpid();
if (argc < LOCK_ARGS)
return -1;
@@ -547,10 +549,12 @@ static int do_lock(int argc, char *argv[])
strcpy(count_path, argv[4]);
our_hostid = atoi(argv[7]);
+ add_lockspace();
+
len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
res = malloc(len);
memset(res, 0, len);
- strcpy(res->lockspace_name, "devcount");
+ strcpy(res->lockspace_name, lockspace.name);
snprintf(res->name, SANLK_NAME_LEN, "resource%s", count_path);
res->name[SANLK_NAME_LEN-1] = '\0';
res->num_disks = 1;
@@ -558,15 +562,6 @@ static int do_lock(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- memset(&lockspace, 0, sizeof(lockspace));
- strcpy(lockspace.name, "devcount");
- strcpy(lockspace.host_id_disk.path, lock_path);
- lockspace.host_id_disk.offset = lock_offset;
- lockspace.host_id = our_hostid;
-
- rv = sanlock_add_lockspace(&lockspace, 0);
- printf("%d sanlock_add_lockspace %d\n", parent_pid, rv);
-
/*
* argv[0] = devcount
* argv[1] = lock
@@ -586,8 +581,6 @@ static int do_lock(int argc, char *argv[])
if (!pid) {
int child_pid = getpid();
- printf("\n");
-
sock = sanlock_register();
if (sock < 0) {
printf("%d sanlock_register error %d\n",
@@ -639,10 +632,12 @@ static int do_wrap(int argc, char *argv[])
strcpy(count_path, argv[4]);
our_hostid = atoi(argv[7]);
+ add_lockspace();
+
len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
res = malloc(len);
memset(res, 0, len);
- strcpy(res->lockspace_name, "devcount");
+ strcpy(res->lockspace_name, lockspace.name);
snprintf(res->name, SANLK_NAME_LEN, "resource%s", count_path);
res->name[SANLK_NAME_LEN-1] = '\0';
res->num_disks = 1;
@@ -867,7 +862,6 @@ static int wait_migrate_incoming(uint64_t *lver)
static int do_migrate(int argc, char *argv[])
{
char *av[MIGRATE_ARGS+1];
- struct sanlk_lockspace lockspace;
struct sanlk_resource *res;
int i, j, pid, rv, sock, len, status, init;
int pfd[2];
@@ -886,10 +880,12 @@ static int do_migrate(int argc, char *argv[])
our_hostid = atoi(argv[7]);
max_hostid = atoi(argv[8]);
+ add_lockspace();
+
len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
res = malloc(len);
memset(res, 0, len);
- strcpy(res->lockspace_name, "devcount");
+ strcpy(res->lockspace_name, lockspace.name);
snprintf(res->name, SANLK_NAME_LEN, "resource%s", count_path);
res->name[SANLK_NAME_LEN-1] = '\0';
res->num_disks = 1;
@@ -897,15 +893,6 @@ static int do_migrate(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- memset(&lockspace, 0, sizeof(lockspace));
- strcpy(lockspace.name, "devcount");
- strcpy(lockspace.host_id_disk.path, lock_path);
- lockspace.host_id_disk.offset = lock_offset;
- lockspace.host_id = our_hostid;
-
- rv = sanlock_add_lockspace(&lockspace, 0);
- printf("%d sanlock_add_lockspace %d\n", parent_pid, rv);
-
/*
* argv[0] = devcount
* argv[1] = migrate
@@ -927,8 +914,6 @@ static int do_migrate(int argc, char *argv[])
int child_pid = getpid();
char junk;
- printf("\n");
-
sock = sanlock_register();
if (sock < 0) {
printf("%d sanlock_register error %d\n",
@@ -1134,9 +1119,9 @@ int main(int argc, char *argv[])
printf(" sanlock direct init -n 8 -r devcount:resource<count_disk>:<lock_disk>:1024000\n");
printf(" dd if=/dev/zero of=<count_disk> bs=512 count=24\n");
printf("\n");
- printf("devcount migrate <lock_disk> rw <count_disk> <sec1> <sec2> <hostid> <max_hostid>\n");
- printf(" sanlock add_lockspace -s devcount:<hostid>:<lock_disk>:0\n");
- printf(" loop around fork, sanlock_acquire, exec devcount rw\n");
+ printf("devcount rw <count_disk> <sec1> <sec2> <hostid>\n");
+ printf(" rw: read count for sec1, looking for writes, then write for sec2\n");
+ printf(" wr: write count for sec1, then read for sec2, looking for writes\n");
printf("\n");
printf("devcount lock <lock_disk> rw <count_disk> <sec1> <sec2> <hostid>\n");
printf(" sanlock add_lockspace -s devcount:<hostid>:<lock_disk>:0\n");
@@ -1148,11 +1133,12 @@ int main(int argc, char *argv[])
printf(" sigstop child, inquire, release, re-acquire, sigcont|sigkill\n");
printf("\n");
printf("devcount wrap <lock_disk> rw <count_disk> <sec1> <sec2> <hostid>\n");
+ printf(" sanlock add_lockspace -s devcount:<hostid>:<lock_disk>:0\n");
printf(" sanlock_acquire, exec devcount rw\n");
+ printf("devcount migrate <lock_disk> rw <count_disk> <sec1> <sec2> <hostid> <max_hostid>\n");
+ printf(" sanlock add_lockspace -s devcount:<hostid>:<lock_disk>:0\n");
+ printf(" loop around fork, sanlock_acquire, exec devcount rw\n");
printf("\n");
- printf("devcount rw <count_disk> <sec1> <sec2> <hostid>\n");
- printf(" rw: read count for sec1, looking for writes, then write for sec2\n");
- printf(" wr: write count for sec1, then read for sec2, looking for writes\n");
printf("\n");
return -1;
}
13 years
3 commits - python/sanlockmod.c python/sanlock.py python/setup.py sanlock.spec src/Makefile
by David Teigland
python/sanlock.py | 12 +++
python/sanlockmod.c | 171 ++++++++++++++++++++++++++++++++++++++--------------
python/setup.py | 3
sanlock.spec | 1
src/Makefile | 2
5 files changed, 140 insertions(+), 49 deletions(-)
New commits:
commit 5b8a39c88fda035fb0d2c7d90884d85498b9dd7f
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Apr 15 16:18:24 2011 +0100
python: add sanlock init functions and exception
diff --git a/python/sanlock.py b/python/sanlock.py
index 35ccb3b..87e33b3 100644
--- a/python/sanlock.py
+++ b/python/sanlock.py
@@ -7,10 +7,18 @@
import sys
import sanlockmod
-SANLOCK_FUNCTIONS = ('register', 'add_lockspace',
- 'rem_lockspace', 'acquire', 'release')
+SANLOCK_FUNCTIONS = (
+ 'register', 'add_lockspace', 'rem_lockspace', 'acquire', 'release'
+)
+
+SanlockException = sanlockmod.exception
for skfun in SANLOCK_FUNCTIONS:
setattr(sys.modules[__name__], skfun, getattr(sanlockmod, skfun))
del skfun
+def init_lockspace(lockspace, max_hosts=2000, use_aio=True):
+ sanlockmod.init_lockspace(lockspace, max_hosts, 0, use_aio)
+
+def init_resource(resource, num_hosts, max_hosts=2000, use_aio=True):
+ sanlockmod.init_resource(resource, max_hosts, num_hosts, use_aio)
diff --git a/python/sanlockmod.c b/python/sanlockmod.c
index 65ead2a..789246a 100644
--- a/python/sanlockmod.c
+++ b/python/sanlockmod.c
@@ -10,6 +10,7 @@
#include <sanlock.h>
#include <sanlock_resource.h>
#include <sanlock_admin.h>
+#include <sanlock_direct.h>
int __sanlockmod_fd = -1;
PyObject *py_module;
@@ -17,6 +18,45 @@ PyObject *py_module;
/* SANLock exception */
static PyObject *sanlockmod_exception;
+static int
+__parse_lockspace(char *lockspace, struct sanlk_lockspace *ret_ls)
+{
+ char *lockspace_arg;
+
+ /* sanlock_str_to_lockspace is destructive */
+ lockspace_arg = strdup(lockspace);
+
+ if (lockspace_arg == NULL) {
+ PyErr_SetString(sanlockmod_exception, "SANLock extension memory error");
+ return -1;
+ }
+
+ /* convert lockspace string to structure */
+ if (sanlock_str_to_lockspace(lockspace_arg, ret_ls) != 0) {
+ PyErr_SetString(sanlockmod_exception, "Invalid SANLock lockspace");
+ goto exit_fail;
+ }
+
+ free(lockspace_arg);
+ return 0;
+
+exit_fail:
+ free(lockspace_arg);
+ return -1;
+}
+
+static int
+__parse_resource(char *resource, struct sanlk_resource **ret_res)
+{
+ /* convert resource string to structure */
+ if (sanlock_str_to_res(resource, ret_res) != 0) {
+ PyErr_SetString(sanlockmod_exception, "Invalid SANLock resource");
+ return -1;
+ }
+
+ return 0;
+}
+
static PyObject *
py_register(PyObject *self, PyObject *args)
{
@@ -32,45 +72,80 @@ py_register(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static int
-__parse_lockspace(PyObject *args, struct sanlk_lockspace *ret_ls)
+static PyObject *py_init_lockspace(PyObject *self, PyObject *args)
{
- char *lockspace, *lockspace_arg;
+ int rv, max_hosts, num_hosts, use_aio;
+ char *lockspace;
+ struct sanlk_lockspace ls;
/* parse python tuple */
- if (!PyArg_ParseTuple(args, "s", &lockspace)) {
- return -1;
+ if (!PyArg_ParseTuple(args, "siii", &lockspace,
+ &max_hosts, &num_hosts, &use_aio)) {
+ return NULL;
}
- /* sanlock_str_to_lockspace is destructive */
- lockspace_arg = strdup(lockspace);
+ /* parse and check sanlock lockspace */
+ if (__parse_lockspace(lockspace, &ls) != 0) {
+ return NULL;
+ }
- if (lockspace_arg == NULL) {
- PyErr_SetString(sanlockmod_exception, "SANLock extension memory error");
- return -1;
+ /* init sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_direct_init(&ls, NULL, max_hosts, num_hosts, use_aio);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ PyErr_SetString(sanlockmod_exception, "SANLock lockspace init failure");
+ return NULL;
}
- /* convert lockspace string to structure */
- if (sanlock_str_to_lockspace(lockspace_arg, ret_ls) != 0) {
- PyErr_SetString(sanlockmod_exception, "Invalid SANLock lockspace");
- goto exit_fail;
+ Py_RETURN_NONE;
+}
+
+static PyObject *py_init_resource(PyObject *self, PyObject *args)
+{
+ int rv, max_hosts, num_hosts, use_aio;
+ char *resource;
+ struct sanlk_resource *res;
+
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "siii", &resource,
+ &max_hosts, &num_hosts, &use_aio)) {
+ return NULL;
}
- free(lockspace_arg);
- return 0;
+ /* parse and check sanlock resource */
+ if (__parse_resource(resource, &res) != 0) {
+ return NULL;
+ }
-exit_fail:
- free(lockspace_arg);
- return -1;
+ /* init sanlock resource (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_direct_init(NULL, res, max_hosts, num_hosts, use_aio);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ PyErr_SetString(sanlockmod_exception, "SANLock resource init failure");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
}
static PyObject *
py_add_lockspace(PyObject *self, PyObject *args)
{
int rv;
+ char *lockspace;
struct sanlk_lockspace ls;
- if (__parse_lockspace(args, &ls) != 0) {
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &lockspace)) {
+ return NULL;
+ }
+
+ /* parse and check sanlock lockspace */
+ if (__parse_lockspace(lockspace, &ls) != 0) {
return NULL;
}
@@ -91,9 +166,16 @@ static PyObject *
py_rem_lockspace(PyObject *self, PyObject *args)
{
int rv;
+ char *lockspace;
struct sanlk_lockspace ls;
- if (__parse_lockspace(args, &ls) != 0) {
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &lockspace)) {
+ return NULL;
+ }
+
+ /* parse and check sanlock lockspace */
+ if (__parse_lockspace(lockspace, &ls) != 0) {
return NULL;
}
@@ -110,36 +192,24 @@ py_rem_lockspace(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}
-static int
-__parse_resource(PyObject *args, struct sanlk_resource **ret_res)
+static PyObject *
+py_acquire(PyObject *self, PyObject *args)
{
+ int rv;
char *resource;
+ struct sanlk_resource *res;
/* parse python tuple */
if (!PyArg_ParseTuple(args, "s", &resource)) {
- return -1;
- }
-
- /* convert resource string to structure */
- if (sanlock_str_to_res(resource, ret_res) != 0) {
- PyErr_SetString(sanlockmod_exception, "Invalid SANLock resource");
- return -1;
+ return NULL;
}
- return 0;
-}
-
-static PyObject *
-py_acquire(PyObject *self, PyObject *args)
-{
- int rv;
- struct sanlk_resource *res;
-
- if (__parse_resource(args, &res) != 0) {
+ /* parse and check sanlock resource */
+ if (__parse_resource(resource, &res) != 0) {
return NULL;
}
- /* acquire resource (gil disabled) */
+ /* acquire sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_acquire(__sanlockmod_fd, -1, 0, 1, &res, 0);
Py_END_ALLOW_THREADS
@@ -161,13 +231,20 @@ static PyObject *
py_release(PyObject *self, PyObject *args)
{
int rv;
+ char *resource;
struct sanlk_resource *res;
- if (__parse_resource(args, &res) != 0) {
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &resource)) {
+ return NULL;
+ }
+
+ /* parse and check sanlock resource */
+ if (__parse_resource(resource, &res) != 0) {
return NULL;
}
- /* release resource (gil disabled)*/
+ /* release sanlock resource (gil disabled)*/
Py_BEGIN_ALLOW_THREADS
rv = sanlock_release(__sanlockmod_fd, -1, 0, 1, &res);
Py_END_ALLOW_THREADS
@@ -188,14 +265,18 @@ exit_fail:
static PyMethodDef
sanlockmod_methods[] = {
{"register", py_register, METH_NOARGS, "Register to SANLock daemon."},
+ {"init_lockspace", py_init_lockspace, METH_VARARGS,
+ "Initialize a device to be used as SANLock lockspace."},
+ {"init_resource", py_init_resource, METH_VARARGS,
+ "Initialize a device to be used as SANLock resource."},
{"add_lockspace", py_add_lockspace, METH_VARARGS,
"Add a lockspace, acquiring a host_id in it."},
{"rem_lockspace", py_rem_lockspace, METH_VARARGS,
"Remove a lockspace, releasing our host_id in it."},
{"acquire", py_acquire, METH_VARARGS,
- "Acquire leases for the current process."},
+ "Acquire a resource lease for the current process."},
{"release", py_release, METH_VARARGS,
- "Release leases for the current process."},
+ "Release a resource lease for the current process."},
{NULL, NULL, 0, NULL}
};
diff --git a/python/setup.py b/python/setup.py
index 843216c..f74076f 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -6,11 +6,12 @@
from distutils.core import setup, Extension
+sanlocklib = ['sanlock', 'sanlock_direct', 'blkid', 'rt']
sanlockmod = Extension(name = 'sanlockmod',
sources = ['sanlockmod.c'],
include_dirs = ['../src'],
library_dirs = ['../src'],
- libraries = ['sanlock'])
+ libraries = sanlocklib)
setup(name = 'SANLock',
version = '1.0',
commit df08cf012ae4f13559acbd8fb5cf55da84ed1183
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Apr 15 16:18:23 2011 +0100
rpm: add sanlock_direct header
diff --git a/sanlock.spec b/sanlock.spec
index a1ec029..d502b2f 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -127,6 +127,7 @@ developing applications that use %{name}.
%{_includedir}/sanlock.h
%{_includedir}/sanlock_admin.h
%{_includedir}/sanlock_resource.h
+%{_includedir}/sanlock_direct.h
%changelog
* Mon Apr 4 2011 Federico Simoncelli <fsimonce(a)redhat.com> - 1.1.0-3
commit c3b8de0091700911b1857759bb19694f19fe377e
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Apr 15 16:18:22 2011 +0100
makefile: fix install typo
diff --git a/src/Makefile b/src/Makefile
index a7ce394..41c11a3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -102,5 +102,5 @@ install: all
$(INSTALL) -c -m 755 $(SHLIB_TARGET) $(DESTDIR)/$(LIB_LIBDIR)
$(INSTALL) -c -m 755 $(SHLIB2_TARGET) $(DESTDIR)/$(LIB_LIBDIR)
cp -a $(LIB_TARGET).so $(DESTDIR)/$(LIB_LIBDIR)
- cp -a $(LIB2_TARGET).so.$(SOMAJOR) $(DESTDIR)/$(LIB_LIBDIR)
+ cp -a $(LIB2_TARGET).so $(DESTDIR)/$(LIB_LIBDIR)
$(INSTALL) -c -m 644 $(HEADER_TARGET) $(DESTDIR)/$(HEADER_DIR)
13 years
tests/devcount.c tests/devcountn
by David Teigland
tests/devcount.c | 58 +++++++++----------------------------------
tests/devcountn | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+), 45 deletions(-)
New commits:
commit a7b2b21047deddf7e7d310cf7b41a4ad11df173e
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Apr 15 12:43:24 2011 -0500
devcountn: start multiple devcount tests
diff --git a/tests/devcount.c b/tests/devcount.c
index fbb0723..e372645 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -75,11 +75,12 @@ void print_entries(int pid, char *buf)
}
}
-void print_our_we(int pid, struct entry *our_we)
+void print_our_we(int pid, int writes, struct entry *our_we)
{
- printf("%d w index %d turn %u time %llu %u:%llu:%llu "
+ printf("%d w %d index %d turn %u time %llu %u:%llu:%llu "
"last %u %llu %u:%llu:%llu\n",
pid,
+ writes,
our_hostid - 1,
our_we->turn,
(unsigned long long)our_we->time,
@@ -111,6 +112,7 @@ static int do_count(int argc, char *argv[])
uint32_t max_turn;
int sec1, sec2;
int read_seconds, write_seconds;
+ uint32_t writes = 0;
if (argc < COUNT_ARGS)
return -1;
@@ -128,8 +130,10 @@ static int do_count(int argc, char *argv[])
read_seconds = sec2;
}
+ /*
printf("%d %s count_disk %s sec1 %d sec2 %d our_hostid %d\n",
our_pid, argv[1], count_path, sec1, sec2, our_hostid);
+ */
fd = open(count_path, O_RDWR | O_DIRECT | O_SYNC, 0);
if (fd < 0) {
@@ -255,9 +259,9 @@ static int do_count(int argc, char *argv[])
perror("write failed");
goto fail;
}
+ writes = 1;
- printf("%d first write\n", our_pid);
- print_our_we(our_pid, our_we);
+ print_our_we(our_pid, writes, our_we);
start = time(NULL);
@@ -272,13 +276,13 @@ static int do_count(int argc, char *argv[])
perror("write failed");
goto fail;
}
+ writes++;
if (write_seconds && (our_we->time - start >= write_seconds))
break;
}
- printf("%d last write\n", our_pid);
- print_our_we(our_pid, our_we);
+ print_our_we(our_pid, writes, our_we);
if (turn_file) {
fprintf(turn_file, "turn %03u start %llu end %llu host %u pid %u\n",
@@ -385,9 +389,6 @@ static int do_relock(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- printf("%d lock_disk %s count_disk %s our_hostid %d\n",
- parent_pid, lock_path, count_path, our_hostid);
-
memset(&lockspace, 0, sizeof(lockspace));
strcpy(lockspace.name, "devcount");
strcpy(lockspace.host_id_disk.path, lock_path);
@@ -395,15 +396,7 @@ static int do_relock(int argc, char *argv[])
lockspace.host_id = our_hostid;
rv = sanlock_add_lockspace(&lockspace, 0);
- if (rv == -EEXIST) {
- printf("%d sanlock_add_lockspace exists\n", parent_pid);
- rv = 0;
- }
- if (rv < 0) {
- printf("%d sanlock_add_lockspace error %d\n", parent_pid, rv);
- exit(EXIT_FAILURE);
- }
- printf("%d sanlock_add_lockspace done\n", parent_pid);
+ printf("%d sanlock_add_lockspace %d\n", parent_pid, rv);
/*
* argv[0] = devcount
@@ -565,9 +558,6 @@ static int do_lock(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- printf("%d lock_disk %s count_disk %s our_hostid %d\n",
- parent_pid, lock_path, count_path, our_hostid);
-
memset(&lockspace, 0, sizeof(lockspace));
strcpy(lockspace.name, "devcount");
strcpy(lockspace.host_id_disk.path, lock_path);
@@ -575,15 +565,7 @@ static int do_lock(int argc, char *argv[])
lockspace.host_id = our_hostid;
rv = sanlock_add_lockspace(&lockspace, 0);
- if (rv == -EEXIST) {
- printf("%d sanlock_add_lockspace exists\n", parent_pid);
- rv = 0;
- }
- if (rv < 0) {
- printf("%d sanlock_add_lockspace error %d\n", parent_pid, rv);
- exit(EXIT_FAILURE);
- }
- printf("%d sanlock_add_lockspace done\n", parent_pid);
+ printf("%d sanlock_add_lockspace %d\n", parent_pid, rv);
/*
* argv[0] = devcount
@@ -668,9 +650,6 @@ static int do_wrap(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- printf("%d lock_disk %s count_disk %s our_hostid %d\n",
- pid, lock_path, count_path, our_hostid);
-
/*
* argv[0] = devcount
* argv[1] = wrap
@@ -918,9 +897,6 @@ static int do_migrate(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- printf("%d lock_disk %s count_disk %s our_hostid %d max_hostid %d\n",
- parent_pid, lock_path, count_path, our_hostid, max_hostid);
-
memset(&lockspace, 0, sizeof(lockspace));
strcpy(lockspace.name, "devcount");
strcpy(lockspace.host_id_disk.path, lock_path);
@@ -928,15 +904,7 @@ static int do_migrate(int argc, char *argv[])
lockspace.host_id = our_hostid;
rv = sanlock_add_lockspace(&lockspace, 0);
- if (rv == -EEXIST) {
- printf("%d sanlock_add_lockspace exists\n", parent_pid);
- rv = 0;
- }
- if (rv < 0) {
- printf("%d sanlock_add_lockspace error %d\n", parent_pid, rv);
- exit(EXIT_FAILURE);
- }
- printf("%d sanlock_add_lockspace done\n", parent_pid);
+ printf("%d sanlock_add_lockspace %d\n", parent_pid, rv);
/*
* argv[0] = devcount
diff --git a/tests/devcountn b/tests/devcountn
new file mode 100755
index 0000000..625eb33
--- /dev/null
+++ b/tests/devcountn
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+if [ $# -le 3 ]; then
+ echo ""
+ echo "Start N devcount commands"
+ echo ""
+ echo "devcountn N init LOCKDEV_BASE COUNTDEV_BASE"
+ echo "devcountn N rw COUNTDEV_BASE SEC1 SEC2 HOSTID"
+ echo "devcountn N lock LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID"
+ echo "devcountn N relock LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID"
+ echo "devcountn N wrap LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID"
+ echo "devcountn N migrate LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID MAXID"
+ echo ""
+ echo "devcount <cmd> LOCKDEV1 rw COUNTDEV1 ..."
+ echo "devcount <cmd> LOCKDEV2 rw COUNTDEV2 ..."
+ echo "devcount <cmd> LOCKDEV3 rw COUNTDEV3 ..."
+ echo ...
+ echo "devcount <cmd> LOCKDEVN rw COUNTDEVN ..."
+ echo ""
+ echo "Examples"
+ echo ""
+ echo "devcountn 3 init /dev/lock /dev/count"
+ echo " devcount init /dev/lock1 /dev/count1"
+ echo " devcount init /dev/lock2 /dev/count2"
+ echo " devcount init /dev/lock3 /dev/count3"
+ echo ""
+ echo "devcountn 3 rw /dev/count 5 5 1"
+ echo " devcount rw /dev/count1 5 5 1"
+ echo " devcount rw /dev/count2 5 5 1"
+ echo " devcount rw /dev/count3 5 5 1"
+ echo ""
+ echo "devcountn 3 lock /dev/lock rw /dev/count 5 5 1"
+ echo " sanlock add_lockspace -s devcount:1:/dev/lock1:0"
+ echo " (the add_lockspace command from each subsequent devcount will fail)"
+ echo " devcount lock /dev/lock1 rw /dev/count1 5 5 1"
+ echo " devcount lock /dev/lock2 rw /dev/count2 5 5 1"
+ echo " devcount lock /dev/lock3 rw /dev/count3 5 5 1"
+ echo ""
+ exit 0
+fi
+
+num=$1
+cmd1=$2
+
+if [ "$cmd1" != "init" ]; then
+ deva=$3
+ cmd2=$4
+ devb=$5
+ sec1=$6
+ sec2=$7
+ hostid=$8
+ maxid=$9
+
+ i=1
+ echo sanlock add_lockspace -s devcount:$hostid:$deva$i:0
+ sanlock add_lockspace -s devcount:$hostid:$deva$i:0
+fi
+
+for i in `seq 1 $num`; do
+ if [ "$cmd1" == "init" ]; then
+ deva=$3
+ devb=$4
+ echo ./devcount init $deva$i $devb$i
+ ./devcount init $deva$i $devb$i
+ elif [ "$cmd1" == "rw" ] || [ "$cmd1" == "wr" ]; then
+ echo ./devcount $cmd1 $deva$i $sec1 $sec2 $hostid
+ ./devcount $cmd1 $deva$i $sec1 $sec2 $hostid &
+ else
+ echo ./devcount $cmd1 $deva$i $cmd2 $devb$i $sec1 $sec2 $hostid $maxid
+ ./devcount $cmd1 $deva$i $cmd2 $devb$i $sec1 $sec2 $hostid $maxid &
+ fi
+done
+
13 years
src/delta_lease.c src/host_id.c src/leader.h src/paxos_lease.c src/sanlock_internal.h
by David Teigland
src/delta_lease.c | 7 -------
src/host_id.c | 2 +-
src/leader.h | 2 +-
src/paxos_lease.c | 7 -------
src/sanlock_internal.h | 1 -
5 files changed, 2 insertions(+), 17 deletions(-)
New commits:
commit 23fc027e8bc1eece21f0fe8f7b3b5e4af9c7de3c
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Apr 13 13:56:24 2011 -0500
sanlock: remove remaining cluster_mode
Remove last traces of this (unused).
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 6804e78..b2e9dda 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -53,12 +53,6 @@ static int verify_leader(struct sync_disk *disk,
return DP_BAD_VERSION;
}
- if (lr->cluster_mode != options.cluster_mode) {
- log_error("verify_leader wrong cluster mode %d %d %s",
- lr->cluster_mode, options.cluster_mode, disk->path);
- return DP_BAD_CLUSTERMODE;
- }
-
if (lr->sector_size != disk->sector_size) {
log_error("verify_leader wrong sector size %d %d %s",
lr->sector_size, disk->sector_size, disk->path);
@@ -312,7 +306,6 @@ int delta_lease_init(struct sync_disk *disk, char *space_name, int max_hosts)
leader.magic = DELTA_DISK_MAGIC;
leader.version = DELTA_DISK_VERSION_MAJOR | DELTA_DISK_VERSION_MINOR;
- leader.cluster_mode = options.cluster_mode;
leader.sector_size = disk->sector_size;
leader.max_hosts = 1;
leader.timestamp = LEASE_FREE;
diff --git a/src/host_id.c b/src/host_id.c
index 8c8056a..7d2836a 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -289,7 +289,7 @@ int add_space(struct space *sp)
{
int rv, result;
- if (!sp->name[0]) {
+ if (!sp->space_name[0]) {
log_erros(sp, "add_space no name");
rv = -EINVAL;
goto fail;
diff --git a/src/leader.h b/src/leader.h
index 735a6d1..c3e25b4 100644
--- a/src/leader.h
+++ b/src/leader.h
@@ -79,7 +79,7 @@ enum {
struct leader_record {
uint32_t magic;
uint32_t version;
- uint32_t cluster_mode;
+ uint32_t unused0;
uint32_t sector_size;
uint64_t num_hosts;
uint64_t max_hosts;
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index b4797b2..2934b6b 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -415,12 +415,6 @@ static int verify_leader(struct token *token, struct sync_disk *disk,
return DP_BAD_VERSION;
}
- if (lr->cluster_mode != options.cluster_mode) {
- log_errot(token, "verify_leader wrong cluster mode %d %d %s",
- lr->cluster_mode, options.cluster_mode, disk->path);
- return DP_BAD_CLUSTERMODE;
- }
-
if (lr->sector_size != disk->sector_size) {
log_errot(token, "verify_leader wrong sector size %d %d %s",
lr->sector_size, disk->sector_size, disk->path);
@@ -929,7 +923,6 @@ int paxos_lease_init(struct token *token, int num_hosts, int max_hosts)
leader.magic = PAXOS_DISK_MAGIC;
leader.version = PAXOS_DISK_VERSION_MAJOR | PAXOS_DISK_VERSION_MINOR;
- leader.cluster_mode = options.cluster_mode;
leader.sector_size = token->disks[0].sector_size;
leader.num_hosts = num_hosts;
leader.max_hosts = max_hosts;
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 88cabe1..7e305af 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -270,7 +270,6 @@ struct options {
int use_aio;
int use_watchdog;
int high_priority;
- uint32_t cluster_mode;
};
/* values used while processing command, not afterward */
13 years
src/host_id.c
by David Teigland
src/host_id.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
New commits:
commit f6e5d72a37c52fb29ee57e50fb011fa66ccd4d79
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Apr 13 13:15:23 2011 -0500
sanlock: check lockspace name and host_id
diff --git a/src/host_id.c b/src/host_id.c
index 535307e..8c8056a 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -289,6 +289,18 @@ int add_space(struct space *sp)
{
int rv, result;
+ if (!sp->name[0]) {
+ log_erros(sp, "add_space no name");
+ rv = -EINVAL;
+ goto fail;
+ }
+
+ if (!sp->host_id) {
+ log_erros(sp, "add_space zero host_id");
+ rv = -EINVAL;
+ goto fail;
+ }
+
if (space_exists(sp->space_name, &sp->host_id_disk, sp->host_id)) {
log_erros(sp, "add_space exists");
rv = -EEXIST;
@@ -305,7 +317,7 @@ int add_space(struct space *sp)
if (rv != 1) {
log_erros(sp, "add_space open_disk failed %d %s",
rv, sp->host_id_disk.path);
- rv = -1;
+ rv = -ENODEV;
goto fail;
}
13 years