[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sanlock-devel
Subject:    2 commits - sanlock.spec src/delta_lease.c src/direct.c src/host_id.c src/leader.h src/Makefile src/
From:       teigland () fedoraproject ! org (David Teigland)
Date:       2011-04-15 20:34:41
Message-ID: 20110415203441.B93291201DB () lists ! fedorahosted ! org
[Download RAW message or body]

 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 at 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 at 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;
 }



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic