From: Kern Sibbald Date: Fri, 29 Jan 2010 13:09:37 +0000 (+0100) Subject: Remove old bdb files + change DQUEUE to use dlist X-Git-Tag: Release-7.0.0~2292 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=feb31533be92e3b7ec3fe13d648a005a81702926;p=bacula%2Fbacula Remove old bdb files + change DQUEUE to use dlist --- diff --git a/bacula/src/cats/Makefile.in b/bacula/src/cats/Makefile.in index 1c8bd52787..26fa9645be 100644 --- a/bacula/src/cats/Makefile.in +++ b/bacula/src/cats/Makefile.in @@ -24,9 +24,9 @@ dummy: # # include files installed when using libtool # -INCLUDE_FILES = bdb.h cats.h protos.h sql_cmds.h +INCLUDE_FILES = cats.h protos.h sql_cmds.h -LIBBACSQL_SRCS = mysql.c bdb.c dbi.c \ +LIBBACSQL_SRCS = mysql.c dbi.c \ sql.c sql_cmds.c sql_create.c sql_delete.c sql_find.c \ sql_get.c sql_list.c sql_update.c sqlite.c \ postgresql.c ingres.c myingres.c \ diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 2272401c41..7712c5c622 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -116,7 +116,7 @@ typedef struct s_sql_field { * S Q L I T E */ struct B_DB { - BQUEUE bq; /* queue control */ + dlink link; /* queue control */ brwlock_t lock; /* transaction lock */ struct sqlite *db; char **result; @@ -238,7 +238,7 @@ typedef struct s_sql_field { * S Q L I T E */ struct B_DB { - BQUEUE bq; /* queue control */ + dlink link; /* queue control */ brwlock_t lock; /* transaction lock */ struct sqlite3 *db; char **result; @@ -350,7 +350,7 @@ extern const char* my_sqlite_batch_fill_path_query; * M Y S Q L */ struct B_DB { - BQUEUE bq; /* queue control */ + dlink link; /* queue control */ brwlock_t lock; /* transaction lock */ MYSQL mysql; MYSQL *db; @@ -447,7 +447,7 @@ typedef struct pg_field { * P O S T G R E S Q L */ struct B_DB { - BQUEUE bq; /* queue control */ + dlink link; /* queue control */ brwlock_t lock; /* transaction lock */ PGconn *db; PGresult *result; @@ -555,7 +555,7 @@ typedef char **INGRES_ROW; * I N G R E S */ struct B_DB { - BQUEUE bq; /* queue control */ + dlink link; /* queue control */ brwlock_t lock; /* transaction lock */ INGconn *db; INGresult *result; @@ -665,7 +665,7 @@ typedef struct dbi_field { } DBI_FIELD; typedef struct dbi_field_get { - BQUEUE bq; + dlink link; char *value; } DBI_FIELD_GET; @@ -677,7 +677,7 @@ typedef struct dbi_field_get { * D B I */ struct B_DB { - BQUEUE bq; /* queue control */ + dlink link; /* queue control */ brwlock_t lock; /* transaction lock */ dbi_conn *db; dbi_result *result; @@ -777,52 +777,6 @@ extern const char* my_dbi_match[4]; #define SQL_ROW DBI_ROW #define SQL_FIELD DBI_FIELD - -#else /* USE BACULA DB routines */ - -#define HAVE_BACULA_DB 1 - -/* Change this each time there is some incompatible - * file format change!!!! - */ -#define BDB_VERSION 13 /* file version number */ - -struct s_control { - int bdb_version; /* Version number */ - uint32_t JobId; /* next Job Id */ - uint32_t PoolId; /* next Pool Id */ - uint32_t MediaId; /* next Media Id */ - uint32_t JobMediaId; /* next JobMedia Id */ - uint32_t ClientId; /* next Client Id */ - uint32_t FileSetId; /* nest FileSet Id */ - time_t time; /* time file written */ -}; - - -/* This is the REAL definition for using the - * Bacula internal DB - */ -struct B_DB { - BQUEUE bq; /* queue control */ -/* pthread_mutex_t mutex; */ /* single thread lock */ - brwlock_t lock; /* transaction lock */ - int ref_count; /* number of times opened */ - struct s_control control; /* control file structure */ - int cfd; /* control file device */ - FILE *jobfd; /* Jobs records file descriptor */ - FILE *poolfd; /* Pool records fd */ - FILE *mediafd; /* Media records fd */ - FILE *jobmediafd; /* JobMedia records fd */ - FILE *clientfd; /* Client records fd */ - FILE *filesetfd; /* FileSet records fd */ - char *db_name; /* name of database */ - POOLMEM *errmsg; /* nicely edited error message */ - POOLMEM *cmd; /* Command string */ - POOLMEM *cached_path; - int cached_path_len; /* length of cached path */ - uint32_t cached_path_id; -}; - #endif /* HAVE_SQLITE3 */ #endif /* HAVE_MYSQL */ #endif /* HAVE_SQLITE */ diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index 16e7546bd4..e532f4a5c4 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2003-2008 Free Software Foundation Europe e.V. + Copyright (C) 2003-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -33,7 +33,6 @@ * based upon work done by Dan Langille, December 2003 and * by Kern Sibbald, March 2000 * - * Version $Id$ */ @@ -55,10 +54,10 @@ */ /* List of open databases */ -static BQUEUE db_list = {&db_list, &db_list}; +static dlist *db_list = NULL; /* Control allocated fields by my_dbi_getvalue */ -static BQUEUE dbi_getvalue_list = {&dbi_getvalue_list, &dbi_getvalue_list}; +static dlist *dbi_getvalue_list = NULL; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -80,7 +79,8 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char const char *db_address, int db_port, const char *db_socket, int mult_db_connections) { - B_DB *mdb; + B_DB *mdb = NULL; + DBI_FIELD_GET *field; char db_driver[10]; char db_driverdir[256]; @@ -116,9 +116,13 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char return NULL; } P(mutex); /* lock DB queue */ + if (db_list == NULL) { + db_list = New(dlist(mdb, &mdb->link)); + db_getvalue_list = New(dlist(field, field->link)); + } if (!mult_db_connections) { /* Look to see if DB already open */ - for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) { + foreach_dlist(mdb, db_list) { if (bstrcmp(mdb->db_name, db_name) && bstrcmp(mdb->db_address, db_address) && bstrcmp(mdb->db_driver, db_driver) && @@ -165,7 +169,7 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char mdb->esc_name = get_pool_memory(PM_FNAME); mdb->esc_path = get_pool_memory(PM_FNAME); mdb->allow_transactions = mult_db_connections; - qinsert(&db_list, &mdb->bq); /* put db in list */ + db_list->append(mdb); /* put db in list */ V(mutex); return mdb; } @@ -335,7 +339,7 @@ db_close_database(JCR *jcr, B_DB *mdb) sql_free_result(mdb); mdb->ref_count--; if (mdb->ref_count == 0) { - qdchain(&mdb->bq); + db_list->remove(mdb); if (mdb->connected && mdb->db) { //sql_close(mdb); dbi_shutdown_r(mdb->instance); @@ -515,7 +519,7 @@ DBI_ROW my_dbi_fetch_row(B_DB *mdb) Dmsg4(500, "my_dbi_fetch_row row[%d] field: '%p' in queue: '%p' has value: '%s'\n", j, mdb->row[j], mdb->field_get->value, mdb->row[j]); // insert in queue to future free - qinsert(&dbi_getvalue_list, &mdb->field_get->bq); + dbi_getvalue_list->append(mdb->field_get); } // increment the row number for the next call mdb->row_number++; @@ -691,7 +695,7 @@ void my_dbi_free_result(B_DB *mdb) * Using a queue to store all pointer allocate is a good way to free all things * when necessary */ - while((f=(DBI_FIELD_GET *)qremove(&dbi_getvalue_list))) { + foreach_dlist(f, dbi_getvalue_list) { Dmsg2(500, "my_dbi_free_result field value: '%p' in queue: '%p'\n", f->value, f); free(f->value); free(f); diff --git a/bacula/src/cats/mysql.c b/bacula/src/cats/mysql.c index 994e0e5485..c71418e449 100644 --- a/bacula/src/cats/mysql.c +++ b/bacula/src/cats/mysql.c @@ -54,7 +54,7 @@ */ /* List of open databases */ -static BQUEUE db_list = {&db_list, &db_list}; +static dlist *db_list = NULL; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -76,16 +76,19 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char const char *db_address, int db_port, const char *db_socket, int mult_db_connections) { - B_DB *mdb; + B_DB *mdb = NULL; if (!db_user) { Jmsg(jcr, M_FATAL, 0, _("A user name for MySQL must be supplied.\n")); return NULL; } P(mutex); /* lock DB queue */ + if (db_list == NULL) { + db_list = New(dlist(mdb, &mdb->link)); + } /* Look to see if DB already open */ if (!mult_db_connections) { - for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) { + foreach_dlist(mdb, db_list) { if (bstrcmp(mdb->db_name, db_name) && bstrcmp(mdb->db_address, db_address) && mdb->db_port == db_port) { @@ -126,7 +129,7 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char mdb->esc_name = get_pool_memory(PM_FNAME); mdb->esc_path = get_pool_memory(PM_FNAME); mdb->allow_transactions = mult_db_connections; - qinsert(&db_list, &mdb->bq); /* put db in list */ + db_list->append(mdb); /* put db in list */ Dmsg3(100, "initdb ref=%d connected=%d db=%p\n", mdb->ref_count, mdb->connected, mdb->db); V(mutex); @@ -236,7 +239,7 @@ db_close_database(JCR *jcr, B_DB *mdb) Dmsg3(100, "closedb ref=%d connected=%d db=%p\n", mdb->ref_count, mdb->connected, mdb->db); if (mdb->ref_count == 0) { - qdchain(&mdb->bq); + db_list->remove(mdb); if (mdb->connected) { Dmsg1(100, "close db=%p\n", mdb->db); mysql_close(&mdb->mysql); diff --git a/bacula/src/cats/postgresql.c b/bacula/src/cats/postgresql.c index c5757efced..82c9b2377b 100644 --- a/bacula/src/cats/postgresql.c +++ b/bacula/src/cats/postgresql.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2003-2007 Free Software Foundation Europe e.V. + Copyright (C) 2003-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -32,7 +32,6 @@ * Dan Langille, December 2003 * based upon work done by Kern Sibbald, March 2000 * - * Version $Id$ */ @@ -57,7 +56,7 @@ */ /* List of open databases */ -static BQUEUE db_list = {&db_list, &db_list}; +static dlist *db_list = NULL; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -80,16 +79,19 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char const char *db_address, int db_port, const char *db_socket, int mult_db_connections) { - B_DB *mdb; + B_DB *mdb = NULL; if (!db_user) { Jmsg(jcr, M_FATAL, 0, _("A user name for PostgreSQL must be supplied.\n")); return NULL; } P(mutex); /* lock DB queue */ + if (db_list == NULL) { + db_list = New(dlist(mdb, &mdb->link)); + } if (!mult_db_connections) { /* Look to see if DB already open */ - for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) { + foreach_dlist(mdb, db_list) { if (bstrcmp(mdb->db_name, db_name) && bstrcmp(mdb->db_address, db_address) && mdb->db_port == db_port) { @@ -127,7 +129,7 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char mdb->esc_name = get_pool_memory(PM_FNAME); mdb->esc_path = get_pool_memory(PM_FNAME); mdb->allow_transactions = mult_db_connections; - qinsert(&db_list, &mdb->bq); /* put db in list */ + db_list->append(mdb); /* put db in list */ V(mutex); return mdb; } @@ -262,7 +264,7 @@ db_close_database(JCR *jcr, B_DB *mdb) sql_free_result(mdb); mdb->ref_count--; if (mdb->ref_count == 0) { - qdchain(&mdb->bq); + db_list->remove(mdb); if (mdb->connected && mdb->db) { sql_close(mdb); } diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index f98539ed38..1672f07502 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -30,7 +30,6 @@ * * Kern Sibbald, January 2002 * - * Version $Id$ */ @@ -53,7 +52,7 @@ */ /* List of open databases */ -static BQUEUE db_list = {&db_list, &db_list}; +static dlist *db_list = NULL; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -99,12 +98,15 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char const char *db_address, int db_port, const char *db_socket, int mult_db_connections) { - B_DB *mdb; + B_DB *mdb = NULL; P(mutex); /* lock DB queue */ + if (db_list == NULL) { + db_list = New(dlist(mdb, &mdb->link)); + } /* Look to see if DB already open */ if (!mult_db_connections) { - for (mdb=NULL; (mdb=(B_DB *)qnext(&db_list, &mdb->bq)); ) { + foreach_dlist(mdb, db_list) { if (bstrcmp(mdb->db_name, db_name) && bstrcmp(mdb->db_address, db_address) && mdb->db_port == db_port) { @@ -116,7 +118,7 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char } } Dmsg0(300, "db_open first time\n"); - mdb = (B_DB *) malloc(sizeof(B_DB)); + mdb = (B_DB *)malloc(sizeof(B_DB)); memset(mdb, 0, sizeof(B_DB)); mdb->db_name = bstrdup(db_name); mdb->have_insert_id = true; @@ -131,7 +133,7 @@ db_init_database(JCR *jcr, const char *db_name, const char *db_user, const char mdb->esc_name = get_pool_memory(PM_FNAME); mdb->esc_path = get_pool_memory(PM_FNAME); mdb->allow_transactions = mult_db_connections; - qinsert(&db_list, &mdb->bq); /* put db in list */ + db_list->append(mdb); V(mutex); return mdb; } @@ -245,7 +247,7 @@ db_close_database(JCR *jcr, B_DB *mdb) sql_free_result(mdb); mdb->ref_count--; if (mdb->ref_count == 0) { - qdchain(&mdb->bq); + db_list->remove(mdb); if (mdb->connected && mdb->db) { sqlite_close(mdb->db); }