From 035b15e3707bb295142830a27ac36f6997cb3861 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 11 Jan 2010 07:27:09 +0200 Subject: [PATCH] , --- Makefile | 2 +- include/bouncer.h | 37 ++++--- include/list.h | 277 ---------------------------------------------- include/objects.h | 10 +- include/stats.h | 4 +- src/admin.c | 34 +++--- src/janitor.c | 50 ++++----- src/loader.c | 2 +- src/main.c | 4 +- src/objects.c | 77 ++++++------- src/server.c | 2 +- src/slab.c | 28 ++--- src/stats.c | 10 +- src/takeover.c | 8 +- 14 files changed, 135 insertions(+), 410 deletions(-) delete mode 100644 include/list.h diff --git a/Makefile b/Makefile index da55a74..2ff514a 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SRCS = client.c loader.c objects.c pooler.c proto.c sbuf.c server.c util.c \ varcache.c aatree.c hash.c slab.c HDRS = client.h loader.h objects.h pooler.h proto.h sbuf.h server.h util.h \ admin.h stats.h takeover.h md5.h janitor.h pktbuf.h system.h bouncer.h \ - list.h mbuf.h varcache.h aatree.h hash.h slab.h iobuf.h + mbuf.h varcache.h aatree.h hash.h slab.h iobuf.h # data & dirs to include in tgz DOCS = doc/overview.txt doc/usage.txt doc/config.txt doc/todo.txt diff --git a/include/bouncer.h b/include/bouncer.h index 93911f0..76d2437 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -23,6 +23,8 @@ #include "system.h" #include +#include +#include #include @@ -73,7 +75,6 @@ extern int cf_sbuf_len; #include "aatree.h" #include "hash.h" #include "util.h" -#include "list.h" #include "mbuf.h" #include "iobuf.h" #include "sbuf.h" @@ -154,21 +155,21 @@ struct PgStats { * ->newer_stats = ->stats */ struct PgPool { - List head; /* entry in global pool_list */ - List map_head; /* entry in user->pool_list */ + struct List head; /* entry in global pool_list */ + struct List map_head; /* entry in user->pool_list */ PgDatabase *db; /* corresponging database */ PgUser *user; /* user logged in as */ - StatList active_client_list; /* waiting events logged in clients */ - StatList waiting_client_list; /* client waits for a server to be available */ - StatList cancel_req_list; /* closed client connections with server key */ + struct StatList active_client_list; /* waiting events logged in clients */ + struct StatList waiting_client_list; /* client waits for a server to be available */ + struct StatList cancel_req_list; /* closed client connections with server key */ - StatList active_server_list; /* servers linked with clients */ - StatList idle_server_list; /* servers ready to be linked with clients */ - StatList used_server_list; /* server just unlinked from clients */ - StatList tested_server_list; /* server in testing process */ - StatList new_server_list; /* servers in login phase */ + struct StatList active_server_list; /* servers linked with clients */ + struct StatList idle_server_list; /* servers ready to be linked with clients */ + struct StatList used_server_list; /* server just unlinked from clients */ + struct StatList tested_server_list; /* server in testing process */ + struct StatList new_server_list; /* servers in login phase */ PgStats stats; PgStats newer_stats; @@ -212,8 +213,8 @@ struct PgPool { * whis user has logged in. */ struct PgUser { - List head; /* used to attach user to list */ - List pool_list; /* list of pools where pool->user == this user */ + struct List head; /* used to attach user to list */ + struct List pool_list; /* list of pools where pool->user == this user */ Node tree_node; /* used to attach user to tree */ char name[MAX_USERNAME]; char passwd[MAX_PASSWORD]; @@ -223,7 +224,7 @@ struct PgUser { * A database entry from config. */ struct PgDatabase { - List head; + struct List head; char name[MAX_DBNAME]; /* db name for clients */ bool db_paused; /* PAUSE ; was issued */ @@ -257,7 +258,7 @@ struct PgDatabase { * ->state corresponds to various lists the struct can be at. */ struct PgSocket { - List head; /* list header */ + struct List head; /* list header */ PgSocket *link; /* the dest of packets */ PgPool *pool; /* parent pool, if NULL not yet assigned */ @@ -373,16 +374,16 @@ extern ConfElem bouncer_params[]; extern usec_t g_suspend_start; static inline PgSocket * _MUSTCHECK -pop_socket(StatList *slist) +pop_socket(struct StatList *slist) { - List *item = statlist_pop(slist); + struct List *item = statlist_pop(slist); if (item == NULL) return NULL; return container_of(item, PgSocket, head); } static inline PgSocket * -first_socket(StatList *slist) +first_socket(struct StatList *slist) { if (statlist_empty(slist)) return NULL; diff --git a/include/list.h b/include/list.h deleted file mode 100644 index 32e70d5..0000000 --- a/include/list.h +++ /dev/null @@ -1,277 +0,0 @@ -/* - * PgBouncer - Lightweight connection pooler for PostgreSQL. - * - * Copyright (c) 2007-2009 Marko Kreen, Skype Technologies OÜ - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Circular doubly linked list implementation. - * - * Basic idea from . - * - * seemed usable, but overcomplicated. - */ - -#ifndef __LIST_H_ -#define __LIST_H_ - -/* turn on slow checking */ -/* #define LIST_DEBUG */ - -/* give offset of a field inside struct */ -#ifndef offsetof -#define offsetof(type, field) ((unsigned long)&(((type *)0)->field)) -#endif - -/* given pointer to field inside struct, return pointer to struct */ -#ifndef container_of -#define container_of(ptr, type, field) ((type *)((char *)(ptr) - offsetof(type, field))) -#endif - -/* list type */ -typedef struct List List; -struct List { - List *next; - List *prev; -}; - -#define LIST(var) List var = { &var, &var } - -/* initialize struct */ -static inline void list_init(List *list) -{ - list->next = list->prev = list; -} - -/* is list empty? */ -static inline bool list_empty(const List *list) -{ - return list->next == list; -} - -/* add item to the start of the list */ -static inline List *list_prepend(List *item, List *list) -{ - Assert(list_empty(item)); - - item->next = list->next; - item->prev = list; - list->next->prev = item; - list->next = item; - return item; -} - -/* add item to the end of the list */ -static inline List *list_append(List *item, List *list) -{ - Assert(list_empty(item)); - - item->next = list; - item->prev = list->prev; - list->prev->next = item; - list->prev = item; - return item; -} - -/* remove item from list */ -static inline List *list_del(List *item) -{ - item->prev->next = item->next; - item->next->prev = item->prev; - item->next = item->prev = item; - return item; -} - -/* remove first from list and return */ -static inline List *list_pop(List *list) -{ - if (list_empty(list)) - return NULL; - return list_del(list->next); -} - -/* remove first from list and return */ -static inline List *list_first(const List *list) -{ - if (list_empty(list)) - return NULL; - return list->next; -} - -/* put all elems in one list in the start of another list */ -static inline void list_prepend_list(List *src, List *dst) -{ - if (list_empty(src)) - return; - src->next->prev = dst; - src->prev->next = dst->next; - dst->next->prev = src->prev; - dst->next = src->next; - - src->next = src->prev = src; -} - -/* put all elems in one list in the end of another list */ -static inline void list_append_list(List *src, List *dst) -{ - if (list_empty(src)) - return; - src->next->prev = dst->prev; - src->prev->next = dst; - dst->prev->next = src->next; - dst->prev = src->prev; - - src->next = src->prev = src; -} - -/* remove first elem from list and return with casting */ -#define list_pop_type(list, typ, field) \ - (list_empty(list) ? NULL \ - : container_of(list_del((list)->next), typ, field)) - -/* loop over list */ -#define list_for_each(item, list) \ - for ((item) = (list)->next; \ - (item) != (list); \ - (item) = (item)->next) - -/* loop over list and allow removing item */ -#define list_for_each_safe(item, list, tmp) \ - for ((item) = (list)->next, (tmp) = (list)->next->next; \ - (item) != (list); \ - (item) = (tmp), (tmp) = (tmp)->next) - -static inline bool item_in_list(const List *item, const List *list) -{ - List *tmp; - list_for_each(tmp, list) - if (tmp == item) - return 1; - return 0; -} - - -/* - * wrapper for List that keeps track of number of items - */ - -typedef struct StatList StatList; -struct StatList { - List head; - int cur_count; -#ifdef LIST_DEBUG - const char *name; -#endif -}; - -#ifdef LIST_DEBUG -#define STATLIST(var) StatList var = { {&var.head, &var.head}, 0, #var } -#else -#define STATLIST(var) StatList var = { {&var.head, &var.head}, 0 } -#endif - -static inline void statlist_inc_count(StatList *list, int val) -{ - list->cur_count += val; -} - -static inline void statlist_prepend(List *item, StatList *list) -{ - list_prepend(item, &list->head); - statlist_inc_count(list, 1); -} - -static inline void statlist_append(List *item, StatList *list) -{ - list_append(item, &list->head); - statlist_inc_count(list, 1); -} - -static inline void statlist_put_before(List *item, StatList *list, List *pos) -{ - list_append(item, pos); - statlist_inc_count(list, 1); -} - -static inline void statlist_remove(List *item, StatList *list) -{ -#ifdef LIST_DEBUG - /* sanity check */ - if (!item_in_list(item, &list->head)) - fatal("item in wrong list, expected: %s", list->name); -#endif - - list_del(item); - list->cur_count--; - - Assert(list->cur_count >= 0); -} - -static inline void statlist_init(StatList *list, const char *name) -{ - list_init(&list->head); - list->cur_count = 0; -#ifdef LIST_DEBUG - list->name = name; -#endif -} - -static inline int statlist_count(const StatList *list) -{ - Assert(list->cur_count > 0 || list_empty(&list->head)); - return list->cur_count; -} - -static inline List *statlist_pop(StatList *list) -{ - List *item = list_pop(&list->head); - - if (item) - list->cur_count--; - - Assert(list->cur_count >= 0); - - return item; -} - -static inline void statlist_prepend_list(StatList *src, StatList *dst) -{ - list_prepend_list(&src->head, &dst->head); - statlist_inc_count(dst, src->cur_count); - src->cur_count = 0; -} - -static inline void statlist_append_list(StatList *src, StatList *dst) -{ - list_append_list(&src->head, &dst->head); - statlist_inc_count(dst, src->cur_count); - src->cur_count = 0; -} - -static inline List *statlist_first(const StatList *list) -{ - return list_first(&list->head); -} - -static inline bool statlist_empty(const StatList *list) -{ - return list_empty(&list->head); -} - -#define statlist_for_each(item, list) list_for_each(item, &((list)->head)) -#define statlist_for_each_safe(item, list, tmp) list_for_each_safe(item, &((list)->head), tmp) - -#endif /* __LIST_H_ */ - diff --git a/include/objects.h b/include/objects.h index 3e2e6e9..e9d98a8 100644 --- a/include/objects.h +++ b/include/objects.h @@ -16,12 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -extern StatList user_list; +extern struct StatList user_list; extern Tree user_tree; -extern StatList pool_list; -extern StatList database_list; -extern StatList autodatabase_idle_list; -extern StatList login_client_list; +extern struct StatList pool_list; +extern struct StatList database_list; +extern struct StatList autodatabase_idle_list; +extern struct StatList login_client_list; extern ObjectCache *client_cache; extern ObjectCache *server_cache; extern ObjectCache *db_cache; diff --git a/include/stats.h b/include/stats.h index 2200948..cd7c802 100644 --- a/include/stats.h +++ b/include/stats.h @@ -18,6 +18,6 @@ void stats_setup(void); -bool admin_database_stats(PgSocket *client, StatList *pool_list) _MUSTCHECK; -bool show_stat_totals(PgSocket *client, StatList *pool_list) _MUSTCHECK; +bool admin_database_stats(PgSocket *client, struct StatList *pool_list) _MUSTCHECK; +bool show_stat_totals(PgSocket *client, struct StatList *pool_list) _MUSTCHECK; diff --git a/src/admin.c b/src/admin.c index 409963f..545d118 100644 --- a/src/admin.c +++ b/src/admin.c @@ -92,7 +92,7 @@ bool admin_error(PgSocket *admin, const char *fmt, ...) static int count_paused_databases(void) { - List *item; + struct List *item; PgDatabase *db; int cnt = 0; @@ -105,7 +105,7 @@ static int count_paused_databases(void) static int count_db_active(PgDatabase *db) { - List *item; + struct List *item; PgPool *pool; int cnt = 0; @@ -321,9 +321,9 @@ static bool show_pooler_fds(PgSocket *admin) return res; } -static bool show_fds_from_list(PgSocket *admin, StatList *list) +static bool show_fds_from_list(PgSocket *admin, struct StatList *list) { - List *item; + struct List *item; PgSocket *sk; bool res = true; @@ -343,7 +343,7 @@ static bool show_fds_from_list(PgSocket *admin, StatList *list) */ static bool admin_show_fds(PgSocket *admin, const char *arg) { - List *item; + struct List *item; PgPool *pool; bool res; @@ -404,7 +404,7 @@ static bool admin_show_fds(PgSocket *admin, const char *arg) static bool admin_show_databases(PgSocket *admin, const char *arg) { PgDatabase *db; - List *item; + struct List *item; char *host; const char *f_user; PktBuf *buf; @@ -464,7 +464,7 @@ static bool admin_show_lists(PgSocket *admin, const char *arg) static bool admin_show_users(PgSocket *admin, const char *arg) { PgUser *user; - List *item; + struct List *item; PktBuf *buf = pktbuf_dynamic(256); if (!buf) { admin_error(admin, "no mem"); @@ -543,9 +543,9 @@ static void socket_row(PktBuf *buf, PgSocket *sk, const char *state, bool debug) } /* Helper for SHOW CLIENTS */ -static void show_socket_list(PktBuf *buf, StatList *list, const char *state, bool debug) +static void show_socket_list(PktBuf *buf, struct StatList *list, const char *state, bool debug) { - List *item; + struct List *item; PgSocket *sk; statlist_for_each(item, list) { @@ -557,7 +557,7 @@ static void show_socket_list(PktBuf *buf, StatList *list, const char *state, boo /* Command: SHOW CLIENTS */ static bool admin_show_clients(PgSocket *admin, const char *arg) { - List *item; + struct List *item; PgPool *pool; PktBuf *buf = pktbuf_dynamic(256); @@ -581,7 +581,7 @@ static bool admin_show_clients(PgSocket *admin, const char *arg) /* Command: SHOW SERVERS */ static bool admin_show_servers(PgSocket *admin, const char *arg) { - List *item; + struct List *item; PgPool *pool; PktBuf *buf; @@ -607,7 +607,7 @@ static bool admin_show_servers(PgSocket *admin, const char *arg) /* Command: SHOW SOCKETS */ static bool admin_show_sockets(PgSocket *admin, const char *arg) { - List *item; + struct List *item; PgPool *pool; PktBuf *buf; @@ -634,9 +634,9 @@ static bool admin_show_sockets(PgSocket *admin, const char *arg) return true; } -static void show_active_socket_list(PktBuf *buf, StatList *list, const char *state) +static void show_active_socket_list(PktBuf *buf, struct StatList *list, const char *state) { - List *item; + struct List *item; statlist_for_each(item, list) { PgSocket *sk = container_of(item, PgSocket, head); if (!sbuf_is_empty(&sk->sbuf)) @@ -647,7 +647,7 @@ static void show_active_socket_list(PktBuf *buf, StatList *list, const char *sta /* Command: SHOW ACTIVE_SOCKETS */ static bool admin_show_active_sockets(PgSocket *admin, const char *arg) { - List *item; + struct List *item; PgPool *pool; PktBuf *buf; @@ -677,7 +677,7 @@ static bool admin_show_active_sockets(PgSocket *admin, const char *arg) /* Command: SHOW POOLS */ static bool admin_show_pools(PgSocket *admin, const char *arg) { - List *item; + struct List *item; PgPool *pool; PktBuf *buf; PgSocket *waiter; @@ -1193,7 +1193,7 @@ void admin_setup(void) void admin_pause_done(void) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *admin; bool res; diff --git a/src/janitor.c b/src/janitor.c index 85321f7..5131db8 100644 --- a/src/janitor.c +++ b/src/janitor.c @@ -27,9 +27,9 @@ static struct timeval full_maint_period = {0, USEC / 3}; static struct event full_maint_ev; /* close all sockets in server list */ -static void close_server_list(StatList *sk_list, const char *reason) +static void close_server_list(struct StatList *sk_list, const char *reason) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *server; statlist_for_each_safe(item, sk_list, tmp) { @@ -38,9 +38,9 @@ static void close_server_list(StatList *sk_list, const char *reason) } } -static void close_client_list(StatList *sk_list, const char *reason) +static void close_client_list(struct StatList *sk_list, const char *reason) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *client; statlist_for_each_safe(item, sk_list, tmp) { @@ -70,9 +70,9 @@ bool suspend_socket(PgSocket *sk, bool force_suspend) } /* suspend all sockets in socket list */ -static int suspend_socket_list(StatList *list, bool force_suspend) +static int suspend_socket_list(struct StatList *list, bool force_suspend) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *sk; int active = 0; @@ -85,9 +85,9 @@ static int suspend_socket_list(StatList *list, bool force_suspend) } /* resume all suspended sockets in socket list */ -static void resume_socket_list(StatList *list) +static void resume_socket_list(struct StatList *list) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *sk; statlist_for_each_safe(item, list, tmp) { @@ -102,7 +102,7 @@ static void resume_socket_list(StatList *list) /* resume all suspended sockets in all pools */ static void resume_sockets(void) { - List *item; + struct List *item; PgPool *pool; statlist_for_each(item, &pool_list) { @@ -169,7 +169,7 @@ static void launch_recheck(PgPool *pool) */ static void per_loop_activate(PgPool *pool) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *client; /* see if any server have been freed */ @@ -254,7 +254,7 @@ static int per_loop_suspend(PgPool *pool, bool force_suspend) */ void per_loop_maint(void) { - List *item; + struct List *item; PgPool *pool; int active = 0; int partial_pause = 0; @@ -307,7 +307,7 @@ void per_loop_maint(void) /* maintaining clients in pool */ static void pool_client_maint(PgPool *pool) { - List *item, *tmp; + struct List *item, *tmp; usec_t now = get_cached_time(); PgSocket *client; usec_t age; @@ -353,10 +353,10 @@ static void pool_client_maint(PgPool *pool) } } -static void check_unused_servers(PgPool *pool, StatList *slist, bool idle_test) +static void check_unused_servers(PgPool *pool, struct StatList *slist, bool idle_test) { usec_t now = get_cached_time(); - List *item, *tmp; + struct List *item, *tmp; usec_t idle, age; PgSocket *server; usec_t lifetime_kill_gap = 0; @@ -434,7 +434,7 @@ static void check_pool_size(PgPool *pool) /* maintain servers in a pool */ static void pool_server_maint(PgPool *pool) { - List *item, *tmp; + struct List *item, *tmp; usec_t age, now = get_cached_time(); PgSocket *server; @@ -473,7 +473,7 @@ static void pool_server_maint(PgPool *pool) static void cleanup_client_logins(void) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *client; usec_t age; usec_t now = get_cached_time(); @@ -492,7 +492,7 @@ static void cleanup_client_logins(void) static void kill_database(PgDatabase *db); static void cleanup_inactive_autodatabases(void) { - List *item, *tmp; + struct List *item, *tmp; PgDatabase *db; usec_t age; usec_t now = get_cached_time(); @@ -513,7 +513,7 @@ static void cleanup_inactive_autodatabases(void) /* full-scale maintenance, done only occasionally */ static void do_full_maint(int sock, short flags, void *arg) { - List *item, *tmp; + struct List *item, *tmp; PgPool *pool; /* @@ -531,8 +531,8 @@ static void do_full_maint(int sock, short flags, void *arg) if (pool->db->db_auto && pool->db->inactive_time == 0 && pool_client_count(pool) == 0 && pool_server_count(pool) == 0 ) { pool->db->inactive_time = get_cached_time(); - statlist_remove(&pool->db->head, &database_list); - statlist_append(&pool->db->head, &autodatabase_idle_list); + statlist_remove(&database_list, &pool->db->head); + statlist_append(&autodatabase_idle_list, &pool->db->head); } } @@ -577,14 +577,14 @@ static void kill_pool(PgPool *pool) close_server_list(&pool->new_server_list, reason); list_del(&pool->map_head); - statlist_remove(&pool->head, &pool_list); + statlist_remove(&pool_list, &pool->head); obj_free(pool_cache, pool); } static void kill_database(PgDatabase *db) { PgPool *pool; - List *item, *tmp; + struct List *item, *tmp; log_warning("dropping database '%s' as it does not exist anymore or inactive auto-database", db->name); @@ -598,9 +598,9 @@ static void kill_database(PgDatabase *db) if (db->connect_query) free((void *)db->connect_query); if (db->inactive_time) - statlist_remove(&db->head, &autodatabase_idle_list); + statlist_remove(&autodatabase_idle_list, &db->head); else - statlist_remove(&db->head, &database_list); + statlist_remove(&database_list, &db->head); obj_free(db_cache, db); } @@ -608,7 +608,7 @@ static void kill_database(PgDatabase *db) there's need for review */ void config_postprocess(void) { - List *item, *tmp; + struct List *item, *tmp; PgDatabase *db; statlist_for_each_safe(item, &database_list, tmp) { diff --git a/src/loader.c b/src/loader.c index b0e2d68..ebabb00 100644 --- a/src/loader.c +++ b/src/loader.c @@ -447,7 +447,7 @@ bool loader_users_check(void) static void disable_users(void) { PgUser *user; - List *item; + struct List *item; statlist_for_each(item, &user_list) { user = container_of(item, PgUser, head); diff --git a/src/main.c b/src/main.c index 3d4db18..4cf7bc9 100644 --- a/src/main.c +++ b/src/main.c @@ -275,7 +275,7 @@ static bool set_defer_accept(ConfElem *elem, const char *val, PgSocket *console) static void set_dbs_dead(bool flag) { - List *item; + struct List *item; PgDatabase *db; statlist_for_each(item, &database_list) { @@ -559,7 +559,7 @@ static void check_limits(void) int total_users = statlist_count(&user_list); int fd_count; int err; - List *item; + struct List *item; PgDatabase *db; log_noise("event: %d, SBuf: %d, PgSocket: %d, IOBuf: %d", diff --git a/src/objects.c b/src/objects.c index 07ad1cb..41930ff 100644 --- a/src/objects.c +++ b/src/objects.c @@ -130,19 +130,19 @@ void change_client_state(PgSocket *client, SocketState newstate) case CL_FREE: break; case CL_JUSTFREE: - statlist_remove(&client->head, &justfree_client_list); + statlist_remove(&justfree_client_list, &client->head); break; case CL_LOGIN: - statlist_remove(&client->head, &login_client_list); + statlist_remove(&login_client_list, &client->head); break; case CL_WAITING: - statlist_remove(&client->head, &pool->waiting_client_list); + statlist_remove(&pool->waiting_client_list, &client->head); break; case CL_ACTIVE: - statlist_remove(&client->head, &pool->active_client_list); + statlist_remove(&pool->active_client_list, &client->head); break; case CL_CANCEL: - statlist_remove(&client->head, &pool->cancel_req_list); + statlist_remove(&pool->cancel_req_list, &client->head); break; default: fatal("bad cur client state: %d", client->state); @@ -156,19 +156,19 @@ void change_client_state(PgSocket *client, SocketState newstate) obj_free(client_cache, client); break; case CL_JUSTFREE: - statlist_append(&client->head, &justfree_client_list); + statlist_append(&justfree_client_list, &client->head); break; case CL_LOGIN: - statlist_append(&client->head, &login_client_list); + statlist_append(&login_client_list, &client->head); break; case CL_WAITING: - statlist_append(&client->head, &pool->waiting_client_list); + statlist_append(&pool->waiting_client_list, &client->head); break; case CL_ACTIVE: - statlist_append(&client->head, &pool->active_client_list); + statlist_append(&pool->active_client_list, &client->head); break; case CL_CANCEL: - statlist_append(&client->head, &pool->cancel_req_list); + statlist_append(&pool->cancel_req_list, &client->head); break; default: fatal("bad new client state: %d", client->state); @@ -185,22 +185,22 @@ void change_server_state(PgSocket *server, SocketState newstate) case SV_FREE: break; case SV_JUSTFREE: - statlist_remove(&server->head, &justfree_server_list); + statlist_remove(&justfree_server_list, &server->head); break; case SV_LOGIN: - statlist_remove(&server->head, &pool->new_server_list); + statlist_remove(&pool->new_server_list, &server->head); break; case SV_USED: - statlist_remove(&server->head, &pool->used_server_list); + statlist_remove(&pool->used_server_list, &server->head); break; case SV_TESTED: - statlist_remove(&server->head, &pool->tested_server_list); + statlist_remove(&pool->tested_server_list, &server->head); break; case SV_IDLE: - statlist_remove(&server->head, &pool->idle_server_list); + statlist_remove(&pool->idle_server_list, &server->head); break; case SV_ACTIVE: - statlist_remove(&server->head, &pool->active_server_list); + statlist_remove(&pool->active_server_list, &server->head); break; default: fatal("change_server_state: bad old server state: %d", server->state); @@ -214,28 +214,28 @@ void change_server_state(PgSocket *server, SocketState newstate) obj_free(server_cache, server); break; case SV_JUSTFREE: - statlist_append(&server->head, &justfree_server_list); + statlist_append(&justfree_server_list, &server->head); break; case SV_LOGIN: - statlist_append(&server->head, &pool->new_server_list); + statlist_append(&pool->new_server_list, &server->head); break; case SV_USED: /* use LIFO */ - statlist_prepend(&server->head, &pool->used_server_list); + statlist_prepend(&pool->used_server_list, &server->head); break; case SV_TESTED: - statlist_append(&server->head, &pool->tested_server_list); + statlist_append(&pool->tested_server_list, &server->head); break; case SV_IDLE: if (server->close_needed || cf_server_round_robin) /* try to avoid immediate usage then */ - statlist_append(&server->head, &pool->idle_server_list); + statlist_append(&pool->idle_server_list, &server->head); else /* otherwise use LIFO */ - statlist_prepend(&server->head, &pool->idle_server_list); + statlist_prepend(&pool->idle_server_list, &server->head); break; case SV_ACTIVE: - statlist_append(&server->head, &pool->active_server_list); + statlist_append(&pool->active_server_list, &server->head); break; default: fatal("bad server state"); @@ -243,7 +243,7 @@ void change_server_state(PgSocket *server, SocketState newstate) } /* compare pool names, for use with put_in_order */ -static int cmp_pool(List *i1, List *i2) +static int cmp_pool(struct List *i1, struct List *i2) { PgPool *p1 = container_of(i1, PgPool, head); PgPool *p2 = container_of(i2, PgPool, head); @@ -255,7 +255,7 @@ static int cmp_pool(List *i1, List *i2) } /* compare user names, for use with put_in_order */ -static int cmp_user(List *i1, List *i2) +static int cmp_user(struct List *i1, struct List *i2) { PgUser *u1 = container_of(i1, PgUser, head); PgUser *u2 = container_of(i2, PgUser, head); @@ -263,7 +263,7 @@ static int cmp_user(List *i1, List *i2) } /* compare db names, for use with put_in_order */ -static int cmp_database(List *i1, List *i2) +static int cmp_database(struct List *i1, struct List *i2) { PgDatabase *db1 = container_of(i1, PgDatabase, head); PgDatabase *db2 = container_of(i2, PgDatabase, head); @@ -271,21 +271,22 @@ static int cmp_database(List *i1, List *i2) } /* put elem into list in correct pos */ -static void put_in_order(List *newitem, StatList *list, int (*cmpfn)(List *, List *)) +static void put_in_order(struct List *newitem, struct StatList *list, + int (*cmpfn)(struct List *, struct List *)) { int res; - List *item; + struct List *item; statlist_for_each(item, list) { res = cmpfn(item, newitem); if (res == 0) fatal("put_in_order: found existing elem"); else if (res > 0) { - statlist_put_before(newitem, list, item); + statlist_put_before(list, newitem, item); return; } } - statlist_append(newitem, list); + statlist_append(list, newitem); } /* create new object if new, then return it */ @@ -379,7 +380,7 @@ PgUser *force_user(PgDatabase *db, const char *name, const char *passwd) /* find an existing database */ PgDatabase *find_database(const char *name) { - List *item, *tmp; + struct List *item, *tmp; PgDatabase *db; statlist_for_each(item, &database_list) { db = container_of(item, PgDatabase, head); @@ -391,7 +392,7 @@ PgDatabase *find_database(const char *name) db = container_of(item, PgDatabase, head); if (strcmp(db->name, name) == 0) { db->inactive_time = 0; - statlist_remove(&db->head, &autodatabase_idle_list); + statlist_remove(&autodatabase_idle_list, &db->head); put_in_order(&db->head, &database_list, cmp_database); return db; } @@ -434,7 +435,7 @@ static PgPool *new_pool(PgDatabase *db, PgUser *user) statlist_init(&pool->new_server_list, "new_server_list"); statlist_init(&pool->cancel_req_list, "cancel_req_list"); - list_append(&pool->map_head, &user->pool_list); + list_append(&user->pool_list, &pool->map_head); /* keep pools in db/user order to make stats faster */ put_in_order(&pool->head, &pool_list, cmp_pool); @@ -445,7 +446,7 @@ static PgPool *new_pool(PgDatabase *db, PgUser *user) /* find pool object, create if needed */ PgPool *get_pool(PgDatabase *db, PgUser *user) { - List *item; + struct List *item; PgPool *pool; if (!db || !user) @@ -926,7 +927,7 @@ bool finish_client_login(PgSocket *client) /* client->cancel_key has requested client key */ void accept_cancel_request(PgSocket *req) { - List *pitem, *citem; + struct List *pitem, *citem; PgPool *pool; PgSocket *server = NULL, *client, *main_client = NULL; @@ -1107,7 +1108,7 @@ bool use_server_socket(int fd, PgAddr *addr, void for_each_server(PgPool *pool, void (*func)(PgSocket *sk)) { - List *item; + struct List *item; statlist_for_each(item, &pool->idle_server_list) func(container_of(item, PgSocket, head)); @@ -1132,7 +1133,7 @@ static void tag_dirty(PgSocket *sk) void tag_database_dirty(PgDatabase *db) { - List *item; + struct List *item; PgPool *pool; statlist_for_each(item, &pool_list) { @@ -1145,7 +1146,7 @@ void tag_database_dirty(PgDatabase *db) /* move objects from justfree_* to free_* lists */ void reuse_just_freed_objects(void) { - List *tmp, *item; + struct List *tmp, *item; PgSocket *sk; bool close_works = true; diff --git a/src/server.c b/src/server.c index 5088f53..ed18b76 100644 --- a/src/server.c +++ b/src/server.c @@ -58,7 +58,7 @@ static bool load_parameter(PgSocket *server, PktHdr *pkt, bool startup) /* we cannot log in at all, notify clients */ static void kill_pool_logins(PgPool *pool, PktHdr *errpkt) { - List *item, *tmp; + struct List *item, *tmp; PgSocket *client; const char *level, *msg; diff --git a/src/slab.c b/src/slab.c index d0ab965..23484c6 100644 --- a/src/slab.c +++ b/src/slab.c @@ -31,9 +31,9 @@ * Store for pre-initialized objects of one type. */ struct ObjectCache { - List head; - StatList freelist; - StatList slablist; + struct List head; + struct StatList freelist; + struct StatList slablist; char name[32]; unsigned final_size; unsigned total_count; @@ -44,7 +44,7 @@ struct ObjectCache { * Header for each slab. */ struct Slab { - List head; + struct List head; }; /* keep track of all caches */ @@ -66,7 +66,7 @@ static void init_objcache(ObjectCache *cache, safe_strcpy(cache->name, name, sizeof(cache->name)); cache->total_count = 0; cache->init_func = init_func; - statlist_append(&cache->head, &objcache_list); + statlist_append(&objcache_list, &cache->head); if (align == 0) cache->final_size = ALIGN(obj_size); @@ -103,14 +103,14 @@ ObjectCache * objcache_create(const char *name, /* free all storage associated by cache */ void objcache_destroy(ObjectCache *cache) { - List *item, *tmp; + struct List *item, *tmp; struct Slab *slab; statlist_for_each_safe(item, &cache->slablist, tmp) { slab = container_of(item, struct Slab, head); free(slab); } - statlist_remove(&cache->head, &objcache_list); + statlist_remove(&objcache_list, &cache->head); memset(cache, 0, sizeof(*cache)); obj_free(objcache_cache, cache); } @@ -141,20 +141,20 @@ static void grow(ObjectCache *cache) /* init objects */ for (i = 0; i < count; i++) { void *obj = area + i * cache->final_size; - List *head = (List *)obj; + struct List *head = (struct List *)obj; list_init(head); - statlist_append(head, &cache->freelist); + statlist_append(&cache->freelist, head); } /* register to cache */ cache->total_count += count; - statlist_append(&slab->head, &cache->slablist); + statlist_append(&cache->slablist, &slab->head); } /* get free object from cache */ void *obj_alloc(ObjectCache *cache) { - List *item = statlist_pop(&cache->freelist); + struct List *item = statlist_pop(&cache->freelist); if (!item) { grow(cache); item = statlist_pop(&cache->freelist); @@ -171,9 +171,9 @@ void *obj_alloc(ObjectCache *cache) /* put object back to cache */ void obj_free(ObjectCache *cache, void *obj) { - List *item = obj; + struct List *item = obj; list_init(item); - statlist_prepend(item, &cache->freelist); + statlist_prepend(&cache->freelist, item); } /* total number of objects allocated from cache */ @@ -203,7 +203,7 @@ static void run_slab_stats(ObjectCache *cache, slab_stat_fn fn, void *arg) void objcache_stats(slab_stat_fn fn, void *arg) { ObjectCache *cache; - List *item; + struct List *item; statlist_for_each(item, &objcache_list) { cache = container_of(item, ObjectCache, head); diff --git a/src/stats.c b/src/stats.c index 35382c1..4318aaa 100644 --- a/src/stats.c +++ b/src/stats.c @@ -66,10 +66,10 @@ static void write_stats(PktBuf *buf, PgStats *stat, PgStats *old, char *dbname) avg.server_bytes, avg.query_time); } -bool admin_database_stats(PgSocket *client, StatList *pool_list) +bool admin_database_stats(PgSocket *client, struct StatList *pool_list) { PgPool *pool; - List *item; + struct List *item; PgDatabase *cur_db = NULL; PgStats st_total, st_db, old_db, old_total; int rows = 0; @@ -122,10 +122,10 @@ bool admin_database_stats(PgSocket *client, StatList *pool_list) return true; } -bool show_stat_totals(PgSocket *client, StatList *pool_list) +bool show_stat_totals(PgSocket *client, struct StatList *pool_list) { PgPool *pool; - List *item; + struct List *item; PgStats st_total, old_total, avg; PktBuf *buf; @@ -167,7 +167,7 @@ bool show_stat_totals(PgSocket *client, StatList *pool_list) static void refresh_stats(int s, short flags, void *arg) { - List *item; + struct List *item; PgPool *pool; struct timeval period = { cf_stats_period, 0 }; PgStats old_total, cur_total, avg; diff --git a/src/takeover.c b/src/takeover.c index ef18f6c..743de93 100644 --- a/src/takeover.c +++ b/src/takeover.c @@ -137,7 +137,7 @@ static void takeover_load_fd(MBuf *pkt, const struct cmsghdr *cmsg) static void takeover_create_link(PgPool *pool, PgSocket *client) { - List *item; + struct List *item; PgSocket *server; statlist_for_each(item, &pool->active_server_list) { @@ -152,9 +152,9 @@ static void takeover_create_link(PgPool *pool, PgSocket *client) } /* clean the inappropriate places the old fds got stored in */ -static void takeover_clean_socket_list(StatList *list) +static void takeover_clean_socket_list(struct StatList *list) { - List *item; + struct List *item; PgSocket *sk; statlist_for_each(item, list) { sk = container_of(item, PgSocket, head); @@ -168,7 +168,7 @@ static void takeover_clean_socket_list(StatList *list) /* all fds loaded, create links */ static void takeover_postprocess_fds(void) { - List *item, *item2; + struct List *item, *item2; PgSocket *client; PgPool *pool; -- 2.40.0