From f179f842de746a221b16c4f7466468365847c94c Mon Sep 17 00:00:00 2001 From: David Teigland Date: Jun 18 2012 22:02:16 +0000 Subject: daemon: don't put struct space on stack struct space has become very large, and it was still kept on the stack unnecessarily in a few places. Use a new space_info struct and copy the necessary fields. Signed-off-by: David Teigland --- diff --git a/src/cmd.c b/src/cmd.c index 6417df0..514a13d 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -88,7 +88,7 @@ static int check_new_tokens_space(struct client *cl, struct token *new_tokens[], int new_tokens_count) { - struct space space; + struct space_info spi; struct token *token; int i, rv, empty_slots = 0; @@ -107,9 +107,9 @@ static int check_new_tokens_space(struct client *cl, for (i = 0; i < new_tokens_count; i++) { token = new_tokens[i]; - rv = _lockspace_info(token->r.lockspace_name, &space); + rv = _lockspace_info(token->r.lockspace_name, &spi); - if (!rv && !space.killing_pids && space.host_id == token->host_id) + if (!rv && !spi.killing_pids && spi.host_id == token->host_id) continue; return -ENOSPC; @@ -125,7 +125,7 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca) struct token *new_tokens[SANLK_MAX_RESOURCES]; struct sanlk_resource res; struct sanlk_options opt; - struct space space; + struct space_info spi; char *opt_str; int token_len, disks_len; int fd, rv, i, j, empty_slots, lvl; @@ -290,23 +290,23 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca) for (i = 0; i < new_tokens_count; i++) { token = new_tokens[i]; - rv = lockspace_info(token->r.lockspace_name, &space); - if (rv < 0 || space.killing_pids) { + rv = lockspace_info(token->r.lockspace_name, &spi); + if (rv < 0 || spi.killing_pids) { log_errot(token, "cmd_acquire %d,%d,%d invalid lockspace " "found %d failed %d name %.48s", - cl_ci, cl_fd, cl_pid, rv, space.killing_pids, + cl_ci, cl_fd, cl_pid, rv, spi.killing_pids, token->r.lockspace_name); result = -ENOSPC; goto done; } - token->host_id = space.host_id; - token->host_generation = space.host_generation; + token->host_id = spi.host_id; + token->host_generation = spi.host_generation; token->pid = cl_pid; if (cl->restrict & SANLK_RESTRICT_SIGKILL) token->flags |= T_RESTRICT_SIGKILL; /* save a record of what this token_id is for later debugging */ - log_level(space.space_id, token->token_id, NULL, LOG_WARNING, + log_level(spi.space_id, token->token_id, NULL, LOG_WARNING, "resource %.48s:%.48s:%.256s:%llu%s for %d,%d,%d", token->r.lockspace_name, token->r.name, diff --git a/src/lockspace.c b/src/lockspace.c index 0e9ad87..c39a036 100644 --- a/src/lockspace.c +++ b/src/lockspace.c @@ -92,25 +92,33 @@ struct space *find_lockspace(char *name) return _search_space(name, NULL, 0, &spaces, &spaces_rem, &spaces_add); } -int _lockspace_info(char *space_name, struct space *sp_out) +int _lockspace_info(char *space_name, struct space_info *spi) { struct space *sp; list_for_each_entry(sp, &spaces, list) { if (strncmp(sp->space_name, space_name, NAME_ID_SIZE)) continue; - memcpy(sp_out, sp, sizeof(struct space)); + + /* keep this in sync with any new fields added to + struct space_info */ + + spi->space_id = sp->space_id; + spi->host_id = sp->host_id; + spi->host_generation = sp->host_generation; + spi->killing_pids = sp->killing_pids; + return 0; } return -1; } -int lockspace_info(char *space_name, struct space *sp_out) +int lockspace_info(char *space_name, struct space_info *spi) { int rv; pthread_mutex_lock(&spaces_mutex); - rv = _lockspace_info(space_name, sp_out); + rv = _lockspace_info(space_name, spi); pthread_mutex_unlock(&spaces_mutex); return rv; @@ -118,14 +126,17 @@ int lockspace_info(char *space_name, struct space *sp_out) int lockspace_disk(char *space_name, struct sync_disk *disk) { - struct space space; - int rv; + struct space *sp; + int rv = -1; pthread_mutex_lock(&spaces_mutex); - rv = _lockspace_info(space_name, &space); - if (!rv) { - memcpy(disk, &space.host_id_disk, sizeof(struct sync_disk)); + list_for_each_entry(sp, &spaces, list) { + if (strncmp(sp->space_name, space_name, NAME_ID_SIZE)) + continue; + + memcpy(disk, &sp->host_id_disk, sizeof(struct sync_disk)); disk->fd = -1; + rv = 0; } pthread_mutex_unlock(&spaces_mutex); diff --git a/src/lockspace.h b/src/lockspace.h index cf456ed..80055d6 100644 --- a/src/lockspace.h +++ b/src/lockspace.h @@ -10,8 +10,8 @@ #define __HOST_ID__H__ struct space *find_lockspace(char *name); -int _lockspace_info(char *space_name, struct space *sp_out); -int lockspace_info(char *space_name, struct space *sp_out); +int _lockspace_info(char *space_name, struct space_info *spi); +int lockspace_info(char *space_name, struct space_info *spi); int lockspace_disk(char *space_name, struct sync_disk *disk); int host_info(char *space_name, uint64_t host_id, struct host_status *hs_out); int host_status_set_bit(char *space_name, uint64_t host_id); diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h index d3ab366..2188a95 100644 --- a/src/sanlock_internal.h +++ b/src/sanlock_internal.h @@ -155,6 +155,16 @@ struct space { struct host_status host_status[DEFAULT_MAX_HOSTS]; }; +/* Update lockspace_info() to copy any fields from struct space + to space_info */ + +struct space_info { + uint32_t space_id; + uint64_t host_id; + uint64_t host_generation; + int killing_pids; +}; + /* * Example of watchdog behavior when host_id renewals fail, assuming * that sanlock cannot successfully kill the pids it is supervising that