src/client_resource.c | 2
src/direct.c | 48 +++++-----
src/main.c | 216 +++++++++++++++++++++++--------------------------
src/paxos_lease.c | 28 +++---
src/sanlock_internal.h | 13 +-
src/token_manager.c | 43 +--------
src/token_manager.h | 2
7 files changed, 157 insertions(+), 195 deletions(-)
New commits:
commit dabfd65b1da818a68d5a4e9610cfb2d4863a7ab4
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Mar 30 16:09:16 2011 -0500
sanlock: rework internal structs
Use a sanlk_resource struct in the token instead of duplicating
the fields. This allows the use of the recent res_to_str function,
and we can remove the second parallel implementation.
diff --git a/src/client_resource.c b/src/client_resource.c
index 8bab02b..46eceae 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -465,7 +465,7 @@ int sanlock_args_to_state(int res_count,
return rv;
}
- if (strlen(str) > SANLK_MAX_RES_STR) {
+ if (strlen(str) > SANLK_MAX_RES_STR - 1) {
free(str);
free(state);
return -EINVAL;
diff --git a/src/direct.c b/src/direct.c
index a4f70b0..2bce141 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -35,15 +35,33 @@ static int do_paxos_action(void)
struct sanlk_resource *res;
struct token *token;
struct leader_record leader_read, leader_ret;
+ int disks_len, token_len;
int num_opened;
int i, j, rv = 0;
for (i = 0; i < com.res_count; i++) {
res = com.res_args[i];
- rv = create_token(res->num_disks, &token);
- if (rv < 0)
- return rv;
+ disks_len = res->num_disks * sizeof(struct sync_disk);
+ token_len = sizeof(struct token) + disks_len;
+
+ token = malloc(token_len);
+ if (!token)
+ return -ENOMEM;
+ memset(token, 0, token_len);
+ token->disks = (struct sync_disk *)&token->r.disks[0];
+ token->r.num_disks = res->num_disks;
+ memcpy(token->r.lockspace_name, res->lockspace_name, SANLK_NAME_LEN);
+ memcpy(token->r.name, res->name, SANLK_NAME_LEN);
+
+ /* WARNING sync_disk == sanlk_disk */
+
+ memcpy(token->disks, &res->disks, disks_len);
+
+ for (j = 0; j < token->r.num_disks; j++) {
+ token->disks[j].sector_size = 0;
+ token->disks[j].fd = 0;
+ }
/*
* TODO: verify all resources are in the same lockspace?
@@ -54,21 +72,7 @@ static int do_paxos_action(void)
token->host_id = com.local_host_id;
token->host_generation = com.local_host_generation;
- strncpy(token->space_name, res->lockspace_name, NAME_ID_SIZE);
- strncpy(token->resource_name, res->name, NAME_ID_SIZE);
-
- /* see WARNING above about sync_disk == sanlk_disk */
-
- memcpy(token->disks, &res->disks,
- token->num_disks * sizeof(struct sync_disk));
-
- /* zero out pad1 and pad2, see WARNING above */
- for (j = 0; j < token->num_disks; j++) {
- token->disks[j].sector_size = 0;
- token->disks[j].fd = 0;
- }
-
- num_opened = open_disks(token->disks, token->num_disks);
+ num_opened = open_disks(token->disks, token->r.num_disks);
if (!majority_disks(token, num_opened)) {
log_tool("cannot open majority of disks");
return -1;
@@ -87,7 +91,7 @@ static int do_paxos_action(void)
rv = paxos_lease_acquire(token, 0, &leader_ret, 0, com.num_hosts);
if (rv < 0) {
log_tool("cannot acquire lease on %s",
- token->resource_name);
+ token->r.name);
return -1;
}
break;
@@ -96,20 +100,20 @@ static int do_paxos_action(void)
rv = paxos_lease_leader_read(token, &leader_read);
if (rv < 0) {
log_tool("cannot read lease on %s",
- token->resource_name);
+ token->r.name);
return -1;
}
rv = paxos_lease_release(token, &leader_read, &leader_ret);
if (rv < 0) {
log_tool("cannot release lease on %s",
- token->resource_name);
+ token->r.name);
return -1;
}
break;
}
- free_token(token);
+ free(token);
}
return 0;
diff --git a/src/main.c b/src/main.c
index 9d38fc1..4ab96ed 100644
--- a/src/main.c
+++ b/src/main.c
@@ -237,7 +237,7 @@ static int client_using_space(struct client *cl, struct space *sp)
token = cl->tokens[i];
if (!token)
continue;
- if (strncmp(token->space_name, sp->space_name, NAME_ID_SIZE))
+ if (strncmp(token->r.lockspace_name, sp->space_name, NAME_ID_SIZE))
continue;
rv = 1;
log_spoke(sp, token, "client_using_space pid %d", cl->pid);
@@ -482,7 +482,6 @@ static void *cmd_acquire_thread(void *args_in)
struct cmd_args *ca = args_in;
struct sm_header h;
struct client *cl;
- struct sync_disk *disks = NULL;
struct token *token = NULL;
struct token *new_tokens[SANLK_MAX_RESOURCES];
struct sanlk_resource res;
@@ -491,7 +490,8 @@ static void *cmd_acquire_thread(void *args_in)
char *opt_str;
uint64_t acquire_lver = 0;
uint32_t new_num_hosts = 0;
- int fd, rv, i, j, disks_len, num_disks, empty_slots, opened;
+ int token_len, disks_len;
+ int fd, rv, i, j, empty_slots, opened;
int alloc_count = 0, add_count = 0, open_count = 0, acquire_count = 0;
int pos = 0, pid_dead = 0;
int new_tokens_count;
@@ -534,80 +534,69 @@ static void *cmd_acquire_thread(void *args_in)
*/
for (i = 0; i < new_tokens_count; i++) {
- token = malloc(sizeof(struct token));
- if (!token) {
- rv = -ENOMEM;
- goto fail_free;
- }
- memset(token, 0, sizeof(struct token));
-
/*
- * receive sanlk_resource, copy into token
+ * receive sanlk_resource, create token for it
*/
rv = recv(fd, &res, sizeof(struct sanlk_resource), MSG_WAITALL);
if (rv > 0)
pos += rv;
if (rv != sizeof(struct sanlk_resource)) {
- log_error("cmd_acquire recv %d %d", rv, errno);
- free(token);
+ log_error("cmd_acquire recv res %d %d", rv, errno);
rv = -EIO;
goto fail_free;
}
- strncpy(token->space_name, res.lockspace_name, SANLK_NAME_LEN);
- strncpy(token->resource_name, res.name, SANLK_NAME_LEN);
+ if (res.num_disks > MAX_DISKS) {
+ rv = -ERANGE;
+ goto fail_free;
+ }
+
+ disks_len = res.num_disks * sizeof(struct sync_disk);
+ token_len = sizeof(struct token) + disks_len;
+
+ token = malloc(token_len);
+ if (!token) {
+ rv = -ENOMEM;
+ goto fail_free;
+ }
+ memset(token, 0, token_len);
+ token->disks = (struct sync_disk *)&token->r.disks[0]; /* shorthand */
+ token->r.num_disks = res.num_disks;
+ memcpy(token->r.lockspace_name, res.lockspace_name, SANLK_NAME_LEN);
+ memcpy(token->r.name, res.name, SANLK_NAME_LEN);
+
token->acquire_lver = res.lver;
token->acquire_data64 = res.data64;
token->acquire_data32 = res.data32;
token->acquire_flags = res.flags;
- token->num_disks = res.num_disks;
/*
* receive sanlk_disk's / sync_disk's
*
* WARNING: as a shortcut, this requires that sync_disk and
* sanlk_disk match; this is the reason for the pad fields
- * in sanlk_disk (TODO: let these differ)
+ * in sanlk_disk (TODO: let these differ?)
*/
- num_disks = token->num_disks;
- if (num_disks > MAX_DISKS) {
- free(token);
- rv = -ERANGE;
- goto fail_free;
- }
-
- disks = malloc(num_disks * sizeof(struct sync_disk));
- if (!disks) {
- free(token);
- rv = -ENOMEM;
- goto fail_free;
- }
-
- disks_len = num_disks * sizeof(struct sync_disk);
- memset(disks, 0, disks_len);
-
- rv = recv(fd, disks, disks_len, MSG_WAITALL);
+ rv = recv(fd, token->disks, disks_len, MSG_WAITALL);
if (rv > 0)
pos += rv;
if (rv != disks_len) {
- log_error("cmd_acquire recv %d %d", rv, errno);
- free(disks);
+ log_error("cmd_acquire recv disks %d %d", rv, errno);
free(token);
rv = -EIO;
goto fail_free;
}
/* zero out pad1 and pad2, see WARNING above */
- for (j = 0; j < num_disks; j++) {
- disks[j].sector_size = 0;
- disks[j].fd = 0;
+ for (j = 0; j < token->r.num_disks; j++) {
+ token->disks[j].sector_size = 0;
+ token->disks[j].fd = 0;
}
token->token_id = token_id_counter++;
- token->disks = disks;
new_tokens[i] = token;
alloc_count++;
@@ -618,7 +607,7 @@ static void *cmd_acquire_thread(void *args_in)
* represents for reference from later log messages. */
log_errot(token, "lockspace %.48s resource %.48s has token_id %u for pid
%u",
- token->space_name, token->resource_name, token->token_id, cl->pid);
+ token->r.lockspace_name, token->r.name, token->token_id, cl->pid);
}
/*
@@ -629,7 +618,7 @@ static void *cmd_acquire_thread(void *args_in)
if (rv > 0)
pos += rv;
if (rv != sizeof(struct sanlk_options)) {
- log_error("cmd_acquire recv %d %d", rv, errno);
+ log_error("cmd_acquire recv opt %d %d", rv, errno);
rv = -EIO;
goto fail_free;
}
@@ -651,7 +640,7 @@ static void *cmd_acquire_thread(void *args_in)
if (rv > 0)
pos += rv;
if (rv != opt.len) {
- log_error("cmd_acquire recv %d %d", rv, errno);
+ log_error("cmd_acquire recv opt_str %d %d", rv, errno);
free(opt_str);
rv = -EIO;
goto fail_free;
@@ -669,10 +658,10 @@ static void *cmd_acquire_thread(void *args_in)
for (i = 0; i < new_tokens_count; i++) {
token = new_tokens[i];
- rv = get_space_info(token->space_name, &space);
+ rv = get_space_info(token->r.lockspace_name, &space);
if (rv < 0 || space.killing_pids) {
log_errot(token, "cmd_acquire bad space %.48s",
- token->space_name);
+ token->r.lockspace_name);
goto fail_free;
}
token->host_id = space.host_id;
@@ -691,7 +680,7 @@ static void *cmd_acquire_thread(void *args_in)
for (i = 0; i < new_tokens_count; i++) {
token = new_tokens[i];
- opened = open_disks(token->disks, token->num_disks);
+ opened = open_disks(token->disks, token->r.num_disks);
if (!majority_disks(token, opened)) {
log_errot(token, "cmd_acquire open_disks %d", opened);
rv = -ENODEV;
@@ -751,11 +740,12 @@ static void *cmd_acquire_thread(void *args_in)
/* space may have failed while new tokens were being acquired */
for (i = 0; i < new_tokens_count; i++) {
token = new_tokens[i];
- rv = get_space_info(token->space_name, &space);
+ rv = get_space_info(token->r.lockspace_name, &space);
if (!rv && !space.killing_pids && space.host_id == token->host_id)
continue;
pthread_mutex_unlock(&cl->mutex);
- log_errot(token, "cmd_acquire bad space %.48s", token->space_name);
+ log_errot(token, "cmd_acquire bad space %.48s",
+ token->r.lockspace_name);
rv = -EINVAL;
goto fail_release;
}
@@ -792,9 +782,9 @@ static void *cmd_acquire_thread(void *args_in)
if (!token)
continue;
release_token(token);
- close_disks(token->disks, token->num_disks);
+ close_disks(token->disks, token->r.num_disks);
del_resource(token);
- free_token(token);
+ free(token);
}
fail_release:
@@ -803,7 +793,7 @@ static void *cmd_acquire_thread(void *args_in)
fail_close:
for (i = 0; i < open_count; i++)
- close_disks(new_tokens[i]->disks, new_tokens[i]->num_disks);
+ close_disks(new_tokens[i]->disks, new_tokens[i]->r.num_disks);
fail_del:
for (i = 0; i < add_count; i++)
@@ -811,7 +801,7 @@ static void *cmd_acquire_thread(void *args_in)
fail_free:
for (i = 0; i < alloc_count; i++)
- free_token(new_tokens[i]);
+ free(new_tokens[i]);
fail_reply:
set_cmd_active(ca->ci_target, 0);
@@ -858,7 +848,7 @@ static void *cmd_release_thread(void *args_in)
rv = release_token(token);
if (rv < 0)
result = -1;
- free_token(token);
+ free(token);
cl->tokens[j] = NULL;
}
goto reply;
@@ -881,15 +871,15 @@ static void *cmd_release_thread(void *args_in)
if (!token)
continue;
- if (memcmp(token->space_name, res.lockspace_name, NAME_ID_SIZE))
+ if (memcmp(token->r.lockspace_name, res.lockspace_name, NAME_ID_SIZE))
continue;
- if (memcmp(token->resource_name, res.name, NAME_ID_SIZE))
+ if (memcmp(token->r.name, res.name, NAME_ID_SIZE))
continue;
rv = release_token(token);
if (rv < 0)
result = -1;
- free_token(token);
+ free(token);
cl->tokens[j] = NULL;
found = 1;
break;
@@ -923,10 +913,12 @@ static void *cmd_inquire_thread(void *args_in)
struct cmd_args *ca = args_in;
struct sm_header h;
struct token *token;
- struct sanlk_resource *res;
- char *reply_str;
struct client *cl;
- int fd, i, d, reply_len, result = 0, total = 0, ret, pos, reply_str_len = 0;
+ char *state, *str;
+ int state_maxlen = 0, state_strlen = 0;
+ int res_count = 0, cat_count = 0;
+ int result = 0;
+ int fd, i, rv;
cl = &client[ca->ci_target];
fd = client[ca->ci_in].fd;
@@ -936,77 +928,85 @@ static void *cmd_inquire_thread(void *args_in)
for (i = 0; i < SANLK_MAX_RESOURCES; i++) {
if (cl->tokens[i])
- total++;
+ res_count++;
}
- /* TODO: use sanlock_res_to_str() */
+ state_maxlen = res_count * (SANLK_MAX_RES_STR + 1);
- reply_len = total * SANLK_MAX_RES_STR;
- reply_str = malloc(reply_len);
- if (!reply_str) {
+ state = malloc(state_maxlen);
+ if (!state) {
result = -ENOMEM;
goto reply;
}
- memset(reply_str, 0, reply_len);
- res = (struct sanlk_resource *)reply_str;
- pos = 0;
- ret = 0;
+ memset(state, 0, state_maxlen);
+
+ /* should match sanlock_args_to_state() */
for (i = 0; i < SANLK_MAX_RESOURCES; i++) {
token = cl->tokens[i];
if (!token)
continue;
- ret = snprintf(reply_str + pos, reply_len - pos, "%s:%s",
- token->space_name, token->resource_name);
+ /* check number of tokens hasn't changed since first count */
- if (ret >= reply_len - pos)
- goto out;
- pos += ret;
+ if (cat_count >= res_count) {
+ log_error("cmd_inquire count changed %d %d",
+ res_count, cat_count);
+ result = -1;
+ goto reply;
+ }
- for (d = 0; d < token->num_disks; d++) {
- ret = snprintf(reply_str + pos, reply_len - pos, ":%s:%llu",
- token->disks[d].path,
- (unsigned long long)token->disks[d].offset);
+ str = NULL;
- if (ret >= reply_len - pos)
- goto out;
- pos += ret;
+ rv = sanlock_res_to_str(&token->r, &str);
+ if (rv < 0 || !str) {
+ log_errot(token, "cmd_inquire res_to_str error %d", rv);
+ result = -2;
+ goto reply;
}
- ret = snprintf(reply_str + pos, reply_len - pos, ":%llu ",
- (unsigned long long)token->leader.lver);
+ if (strlen(str) > SANLK_MAX_RES_STR - 1) {
+ log_errot(token, "cmd_inquire str too long %zu", strlen(str));
+ free(str);
+ result = -3;
+ goto reply;
+ }
- if (ret >= reply_len - pos)
- goto out;
- pos += ret;
- }
+ /* space is str separator, so it's invalid within each str */
- /* remove trailing space */
- pos--;
- reply_str[pos++] = '\0';
- reply_str_len = strlen(reply_str);
+ if (strstr(str, " ")) {
+ log_errot(token, "cmd_inquire str has space");
+ free(str);
+ result = -4;
+ goto reply;
+ }
- ret = 0;
- out:
- if (ret)
- result = -ENOSPC;
+ if (i)
+ strcat(state, " ");
+ strcat(state, str);
+ cat_count++;
+ free(str);
+ }
+
+ state[state_maxlen - 1] = '\0';
+ state_strlen = strlen(state);
+ result = 0;
reply:
set_cmd_active(ca->ci_target, 0);
- log_debug("cmd_inquire done result %d total %d pos %d reply_str_len %d",
- result, total, pos, reply_str_len);
+ log_debug("cmd_inquire done result %d res_count %d strlen %d",
+ result, res_count, state_strlen);
memcpy(&h, &ca->header, sizeof(struct sm_header));
h.data = result;
- h.data2 = total;
+ h.data2 = res_count;
- if (reply_str) {
- h.length = sizeof(h) + pos;
+ if (state) {
+ h.length = sizeof(h) + state_strlen + 1;
send(fd, &h, sizeof(h), MSG_NOSIGNAL);
- send(fd, reply_str, pos, MSG_NOSIGNAL);
- free(reply_str);
+ send(fd, state, state_strlen + 1, MSG_NOSIGNAL);
+ free(state);
} else {
h.length = sizeof(h);
send(fd, &h, sizeof(h), MSG_NOSIGNAL);
@@ -1208,7 +1208,6 @@ static void cmd_status(int fd, struct sm_header *h_recv)
struct sanlk_state cst;
struct sanlk_state rst;
struct sanlk_lockspace lockspace;
- struct sanlk_resource resource;
char str[SANLK_STATE_MAXSTR];
struct token *token;
struct space *sp;
@@ -1301,21 +1300,16 @@ static void cmd_status(int fd, struct sm_header *h_recv)
str_len = print_token_state(token, str);
memset(&rst, 0, sizeof(rst));
rst.type = SANLK_STATE_RESOURCE;
- strncpy(rst.name, token->resource_name, NAME_ID_SIZE);
+ strncpy(rst.name, token->r.name, NAME_ID_SIZE);
rst.str_len = str_len;
send(fd, &rst, sizeof(rst), MSG_NOSIGNAL);
if (str_len)
send(fd, str, str_len, MSG_NOSIGNAL);
- memset(&resource, 0, sizeof(resource));
- strncpy(resource.lockspace_name, token->space_name, NAME_ID_SIZE);
- strncpy(resource.name, token->resource_name, NAME_ID_SIZE);
- resource.num_disks = token->num_disks;
-
- send(fd, &resource, sizeof(resource), MSG_NOSIGNAL);
+ send(fd, &token->r, sizeof(struct sanlk_resource), MSG_NOSIGNAL);
- for (j = 0; j < token->num_disks; j++) {
+ for (j = 0; j < token->r.num_disks; j++) {
send(fd, &token->disks[j], sizeof(struct sanlk_disk), MSG_NOSIGNAL);
}
}
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index ad54920..c9c07cd 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -49,7 +49,7 @@ struct paxos_dblock {
int majority_disks(struct token *token, int num)
{
- int num_disks = token->num_disks;
+ int num_disks = token->r.num_disks;
/* odd number of disks */
@@ -187,7 +187,7 @@ static int run_disk_paxos(struct token *token, uint64_t host_id,
uint64_t inp,
struct paxos_dblock bk[num_hosts];
struct paxos_dblock bk_max;
struct paxos_dblock dblock;
- int num_disks = token->num_disks;
+ int num_disks = token->r.num_disks;
int num_writes, num_reads;
int d, q, rv;
@@ -427,15 +427,15 @@ static int verify_leader(struct token *token, struct sync_disk
*disk,
return DP_BAD_SECTORSIZE;
}
- if (strncmp(lr->space_name, token->space_name, NAME_ID_SIZE)) {
+ 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->space_name, disk->path);
+ lr->space_name, token->r.lockspace_name, disk->path);
return DP_BAD_LOCKSPACE;
}
- if (strncmp(lr->resource_name, token->resource_name, NAME_ID_SIZE)) {
+ 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->resource_name, disk->path);
+ lr->resource_name, token->r.name, disk->path);
return DP_BAD_RESOURCEID;
}
@@ -471,7 +471,7 @@ int paxos_lease_leader_read(struct token *token, struct leader_record
*leader_re
int *leader_reps;
int leaders_len, leader_reps_len;
int num_reads;
- int num_disks = token->num_disks;
+ int num_disks = token->r.num_disks;
int rv, d, i, found;
int error;
@@ -570,7 +570,7 @@ int paxos_lease_leader_read(struct token *token, struct leader_record
*leader_re
static int write_new_leader(struct token *token, struct leader_record *nl)
{
- int num_disks = token->num_disks;
+ int num_disks = token->r.num_disks;
int num_writes = 0;
int error = DP_OK;
int rv, d;
@@ -824,7 +824,7 @@ int paxos_lease_renew(struct token *token,
int rv, d;
int error;
- for (d = 0; d < token->num_disks; d++) {
+ for (d = 0; d < token->r.num_disks; d++) {
memset(&new_leader, 0, sizeof(struct leader_record));
rv = read_leader(&token->disks[d], &new_leader);
@@ -896,8 +896,8 @@ int paxos_lease_init(struct token *token, int num_hosts, int
max_hosts)
uint32_t offset, ss;
uint64_t bb, be, sb, se;
- printf("initialize lease for resource %.48s\n", token->resource_name);
- for (d = 0; d < token->num_disks; d++) {
+ printf("initialize lease for resource %.48s\n", token->r.name);
+ for (d = 0; d < token->r.num_disks; d++) {
printf("disk %s offset %llu/%llu sector_size %d\n",
token->disks[d].path,
(unsigned long long)token->disks[d].offset,
@@ -931,11 +931,11 @@ int paxos_lease_init(struct token *token, int num_hosts, int
max_hosts)
leader.num_hosts = num_hosts;
leader.max_hosts = max_hosts;
leader.timestamp = LEASE_FREE;
- strncpy(leader.space_name, token->space_name, NAME_ID_SIZE);
- strncpy(leader.resource_name, token->resource_name, NAME_ID_SIZE);
+ strncpy(leader.space_name, token->r.lockspace_name, NAME_ID_SIZE);
+ strncpy(leader.resource_name, token->r.name, NAME_ID_SIZE);
leader.checksum = leader_checksum(&leader);
- for (d = 0; d < token->num_disks; d++) {
+ for (d = 0; d < token->r.num_disks; d++) {
write_leader(&token->disks[d], &leader);
write_request(&token->disks[d], &req);
for (q = 0; q < max_hosts; q++)
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 4a1a2f4..0fa14e5 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -67,27 +67,24 @@ struct sync_disk {
threads. */
struct token {
- /* mirror external sanlk_resource from acquire */
- char space_name[NAME_ID_SIZE];
- char resource_name[NAME_ID_SIZE];
+ /* values copied from acquire res arg */
uint64_t acquire_lver;
uint64_t acquire_data64;
uint32_t acquire_data32;
uint32_t acquire_flags;
- int num_disks;
- /* copied from the sp with space_name */
+ /* copied from the sp with r.lockspace_name */
uint64_t host_id;
uint64_t host_generation;
- /* disks from acquire */
- struct sync_disk *disks;
-
/* internal */
int token_id; /* used to refer to this token instance in log messages */
int acquire_result;
int release_result;
struct leader_record leader; /* copy of last leader_record we wrote */
+
+ struct sync_disk *disks; /* shorthand, points to r.disks[0] */
+ struct sanlk_resource r;
};
struct lease_status {
diff --git a/src/token_manager.c b/src/token_manager.c
index 2cdc1fd..2c88560 100644
--- a/src/token_manager.c
+++ b/src/token_manager.c
@@ -49,9 +49,9 @@ static struct resource *find_resource(struct token *token,
struct resource *r;
list_for_each_entry(r, head, list) {
- if (strncmp(r->space_name, token->space_name, NAME_ID_SIZE))
+ if (strncmp(r->space_name, token->r.lockspace_name, NAME_ID_SIZE))
continue;
- if (strncmp(r->resource_name, token->resource_name, NAME_ID_SIZE))
+ if (strncmp(r->resource_name, token->r.name, NAME_ID_SIZE))
continue;
return r;
}
@@ -86,8 +86,8 @@ int add_resource(struct token *token, int pid)
}
memset(r, 0, sizeof(struct resource));
- strncpy(r->space_name, token->space_name, NAME_ID_SIZE);
- strncpy(r->resource_name, token->resource_name, NAME_ID_SIZE);
+ strncpy(r->space_name, token->r.lockspace_name, NAME_ID_SIZE);
+ strncpy(r->resource_name, token->r.name, NAME_ID_SIZE);
r->token = token;
r->pid = pid;
list_add_tail(&r->list, &resources);
@@ -160,37 +160,6 @@ int release_token(struct token *token)
return rv; /* DP_OK */
}
-/* return < 0 on error, 1 on success */
-
-int create_token(int num_disks, struct token **token_out)
-{
- struct token *token;
- struct sync_disk *disks;
-
- token = malloc(sizeof(struct token));
- if (!token)
- return -ENOMEM;
- memset(token, 0, sizeof(struct token));
-
- disks = malloc(num_disks * sizeof(struct sync_disk));
- if (!disks) {
- free(token);
- return -ENOMEM;
- }
-
- token->disks = disks;
- token->num_disks = num_disks;
- *token_out = token;
- return 0;
-}
-
-void free_token(struct token *token)
-{
- if (token->disks)
- free(token->disks);
- free(token);
-}
-
/* thread that releases tokens of pid's that die */
static void *async_release_thread(void *arg GNUC_UNUSED)
@@ -216,7 +185,7 @@ static void *async_release_thread(void *arg GNUC_UNUSED)
if (token->acquire_result == 1)
release_token(token);
- close_disks(token->disks, token->num_disks);
+ close_disks(token->disks, token->r.num_disks);
/* we don't want to remove r from dispose_list until after the
lease is released because we don't want a new token for
@@ -226,7 +195,7 @@ static void *async_release_thread(void *arg GNUC_UNUSED)
pthread_mutex_lock(&resource_mutex);
_del_resource(r);
pthread_mutex_unlock(&resource_mutex);
- free_token(token);
+ free(token);
}
out:
return NULL;
diff --git a/src/token_manager.h b/src/token_manager.h
index 64f95b9..3fddfe1 100644
--- a/src/token_manager.h
+++ b/src/token_manager.h
@@ -12,8 +12,6 @@
int acquire_token(struct token *token, uint64_t acquire_lver, int new_num_hosts);
int release_token(struct token *token);
-int create_token(int num_disks, struct token **token_out);
-void free_token(struct token *token);
void release_token_async(struct token *token);
int add_resource(struct token *token, int pid);