From: Eric Bollengier Date: Thu, 6 Aug 2009 14:07:39 +0000 (+0200) Subject: Add the rest of files for new Bvfs X-Git-Tag: Release-5.0.0~336^2~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6bfbda510749a4cdf68010a61871679a9217f8b8;p=bacula%2Fbacula Add the rest of files for new Bvfs --- diff --git a/bacula/src/cats/Makefile.in b/bacula/src/cats/Makefile.in index 221648698e..501c713474 100644 --- a/bacula/src/cats/Makefile.in +++ b/bacula/src/cats/Makefile.in @@ -29,7 +29,7 @@ INCLUDE_FILES = bdb.h cats.h protos.h sql_cmds.h LIBSRCS = mysql.c bdb.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 + postgresql.c bvfs.c LIBOBJS = $(LIBSRCS:.c=$(DEFAULT_OBJECT_TYPE)) LIBBACSQL_LT_CURRENT = 1 diff --git a/bacula/src/cats/cats.h b/bacula/src/cats/cats.h index 0d6d0d5b8c..8c18ce7f89 100644 --- a/bacula/src/cats/cats.h +++ b/bacula/src/cats/cats.h @@ -179,6 +179,7 @@ struct B_DB { #define sql_fetch_field(x) my_sqlite_fetch_field(x) #define sql_num_fields(x) ((x)->ncolumn) #define SQL_ROW char** +#define SQL_MATCH "MATCH" #define sql_batch_start(x,y) my_batch_start(x,y) #define sql_batch_end(x,y,z) my_batch_end(x,y,z) @@ -313,6 +314,7 @@ struct B_DB { #define sql_batch_end(x,y,z) my_batch_end(x,y,z) #define sql_batch_insert(x,y,z) my_batch_insert(x,y,z) #define SQL_ROW char** +#define SQL_MATCH "MATCH" #define sql_batch_lock_path_query my_sqlite_batch_lock_query #define sql_batch_lock_filename_query my_sqlite_batch_lock_query #define sql_batch_unlock_tables_query my_sqlite_batch_unlock_query @@ -396,6 +398,7 @@ struct B_DB { #define sql_num_fields(x) (int)mysql_num_fields((x)->result) #define SQL_ROW MYSQL_ROW #define SQL_FIELD MYSQL_FIELD +#define SQL_MATCH "MATCH" #define sql_batch_start(x,y) my_batch_start(x,y) #define sql_batch_end(x,y,z) my_batch_end(x,y,z) @@ -527,6 +530,7 @@ extern const char* my_pg_batch_fill_path_query; #define SQL_ROW POSTGRESQL_ROW #define SQL_FIELD POSTGRESQL_FIELD +#define SQL_MATCH "~" #else @@ -634,6 +638,7 @@ extern const char* my_dbi_batch_lock_filename_query[4]; extern const char* my_dbi_batch_unlock_tables_query[4]; extern const char* my_dbi_batch_fill_filename_query[4]; extern const char* my_dbi_batch_fill_path_query[4]; +extern const char* my_dbi_match[4]; /* "Generic" names for easier conversion */ #define sql_store_result(x) (x)->result @@ -644,6 +649,7 @@ extern const char* my_dbi_batch_fill_path_query[4]; #define sql_strerror(x) my_dbi_strerror(x) #define sql_num_rows(x) dbi_result_get_numrows((x)->result) #define sql_data_seek(x, i) my_dbi_data_seek((x), (i)) +#define SQL_MATCH my_dbi_match[db_type] /* #define sql_affected_rows(x) dbi_result_get_numrows_affected((x)->result) */ #define sql_affected_rows(x) 1 #define sql_insert_id(x,y) my_dbi_sql_insert_id((x), (y)) diff --git a/bacula/src/cats/dbi.c b/bacula/src/cats/dbi.c index ea089a1955..7cbfc1868f 100644 --- a/bacula/src/cats/dbi.c +++ b/bacula/src/cats/dbi.c @@ -1282,6 +1282,17 @@ const char *my_dbi_batch_unlock_tables_query[4] = { /* SQLite3 */ "COMMIT"}; +const char *my_dbi_match[4] = { + /* Mysql */ + "MATCH", + /* Postgresql */ + "~", + /* SQLite */ + "MATCH", + /* SQLite3 */ + "MATCH" +}; + const char *my_dbi_batch_fill_path_query[4] = { /* Mysql */ "INSERT INTO Path (Path) " diff --git a/bacula/src/cats/protos.h b/bacula/src/cats/protos.h index ea03a3cc54..5214c8a05e 100644 --- a/bacula/src/cats/protos.h +++ b/bacula/src/cats/protos.h @@ -59,8 +59,10 @@ void db_end_transaction(JCR *jcr, B_DB *mdb); int db_int64_handler(void *ctx, int num_fields, char **row); void db_thread_cleanup(); void _dbg_print_db(JCR *jcr, FILE *fp); +int db_int_handler(void *ctx, int num_fields, char **row); /* sql_create.c */ +int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); bool db_create_file_attributes_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); bool db_create_job_record(JCR *jcr, B_DB *db, JOB_DBR *jr); int db_create_media_record(JCR *jcr, B_DB *db, MEDIA_DBR *media_dbr); @@ -89,6 +91,7 @@ int db_find_next_volume(JCR *jcr, B_DB *mdb, int index, bool InChanger, MEDIA_DB bool db_find_failed_job_since(JCR *jcr, B_DB *mdb, JOB_DBR *jr, POOLMEM *stime, int &JobLevel); /* sql_get.c */ +int db_get_path_record(JCR *jcr, B_DB *mdb); bool db_get_pool_record(JCR *jcr, B_DB *db, POOL_DBR *pdbr); int db_get_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr); bool db_get_job_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr); diff --git a/bacula/src/cats/sql.c b/bacula/src/cats/sql.c index 00a0a9d43d..22eff8ef79 100644 --- a/bacula/src/cats/sql.c +++ b/bacula/src/cats/sql.c @@ -112,7 +112,7 @@ dbid_list::~dbid_list() /* * Called here to retrieve an integer from the database */ -static int int_handler(void *ctx, int num_fields, char **row) +int db_int_handler(void *ctx, int num_fields, char **row) { uint32_t *val = (uint32_t *)ctx; @@ -156,7 +156,7 @@ bool check_tables_version(JCR *jcr, B_DB *mdb) const char *query = "SELECT VersionId FROM Version"; bacula_db_version = 0; - if (!db_sql_query(mdb, query, int_handler, (void *)&bacula_db_version)) { + if (!db_sql_query(mdb, query, db_int_handler, (void *)&bacula_db_version)) { Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); return false; } diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 422a0a6b42..ee93e94250 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -56,7 +56,6 @@ static const int dbglevel = 500; #ifndef HAVE_BATCH_FILE_INSERT static int db_create_file_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); -static int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar); #endif /* HAVE_BATCH_FILE_INSERT */ @@ -535,8 +534,76 @@ int db_create_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr) } +/* Create a Unique record for the Path -- no duplicates */ +int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) +{ + SQL_ROW row; + int stat; + mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*mdb->pnl+2); + db_escape_string(jcr, mdb, mdb->esc_name, mdb->path, mdb->pnl); + + if (mdb->cached_path_id != 0 && mdb->cached_path_len == mdb->pnl && + strcmp(mdb->cached_path, mdb->path) == 0) { + ar->PathId = mdb->cached_path_id; + return 1; + } + Mmsg(mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->esc_name); + + if (QUERY_DB(jcr, mdb, mdb->cmd)) { + mdb->num_rows = sql_num_rows(mdb); + if (mdb->num_rows > 1) { + char ed1[30]; + Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"), + edit_uint64(mdb->num_rows, ed1), mdb->path); + Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg); + } + /* Even if there are multiple paths, take the first one */ + if (mdb->num_rows >= 1) { + if ((row = sql_fetch_row(mdb)) == NULL) { + Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb)); + Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg); + sql_free_result(mdb); + ar->PathId = 0; + ASSERT(ar->PathId); + return 0; + } + ar->PathId = str_to_int64(row[0]); + sql_free_result(mdb); + /* Cache path */ + if (ar->PathId != mdb->cached_path_id) { + mdb->cached_path_id = ar->PathId; + mdb->cached_path_len = mdb->pnl; + pm_strcpy(mdb->cached_path, mdb->path); + } + ASSERT(ar->PathId); + return 1; + } + sql_free_result(mdb); + } + + Mmsg(mdb->cmd, "INSERT INTO Path (Path) VALUES ('%s')", mdb->esc_name); + + if (!INSERT_DB(jcr, mdb, mdb->cmd)) { + Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"), + mdb->cmd, sql_strerror(mdb)); + Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); + ar->PathId = 0; + stat = 0; + } else { + ar->PathId = sql_insert_id(mdb, NT_("Path")); + stat = 1; + } + + /* Cache path */ + if (stat && ar->PathId != mdb->cached_path_id) { + mdb->cached_path_id = ar->PathId; + mdb->cached_path_len = mdb->pnl; + pm_strcpy(mdb->cached_path, mdb->path); + } + return stat; +} /* * Create a Unique record for the counter -- no duplicates @@ -984,77 +1051,6 @@ static int db_create_file_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) return stat; } -/* Create a Unique record for the Path -- no duplicates */ -static int db_create_path_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) -{ - SQL_ROW row; - int stat; - - mdb->esc_name = check_pool_memory_size(mdb->esc_name, 2*mdb->pnl+2); - db_escape_string(jcr, mdb, mdb->esc_name, mdb->path, mdb->pnl); - - if (mdb->cached_path_id != 0 && mdb->cached_path_len == mdb->pnl && - strcmp(mdb->cached_path, mdb->path) == 0) { - ar->PathId = mdb->cached_path_id; - return 1; - } - - Mmsg(mdb->cmd, "SELECT PathId FROM Path WHERE Path='%s'", mdb->esc_name); - - if (QUERY_DB(jcr, mdb, mdb->cmd)) { - mdb->num_rows = sql_num_rows(mdb); - if (mdb->num_rows > 1) { - char ed1[30]; - Mmsg2(&mdb->errmsg, _("More than one Path!: %s for path: %s\n"), - edit_uint64(mdb->num_rows, ed1), mdb->path); - Jmsg(jcr, M_WARNING, 0, "%s", mdb->errmsg); - } - /* Even if there are multiple paths, take the first one */ - if (mdb->num_rows >= 1) { - if ((row = sql_fetch_row(mdb)) == NULL) { - Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb)); - Jmsg(jcr, M_ERROR, 0, "%s", mdb->errmsg); - sql_free_result(mdb); - ar->PathId = 0; - ASSERT(ar->PathId); - return 0; - } - ar->PathId = str_to_int64(row[0]); - sql_free_result(mdb); - /* Cache path */ - if (ar->PathId != mdb->cached_path_id) { - mdb->cached_path_id = ar->PathId; - mdb->cached_path_len = mdb->pnl; - pm_strcpy(mdb->cached_path, mdb->path); - } - ASSERT(ar->PathId); - return 1; - } - sql_free_result(mdb); - } - - Mmsg(mdb->cmd, "INSERT INTO Path (Path) VALUES ('%s')", mdb->esc_name); - - if (!INSERT_DB(jcr, mdb, mdb->cmd)) { - Mmsg2(&mdb->errmsg, _("Create db Path record %s failed. ERR=%s\n"), - mdb->cmd, sql_strerror(mdb)); - Jmsg(jcr, M_FATAL, 0, "%s", mdb->errmsg); - ar->PathId = 0; - stat = 0; - } else { - ar->PathId = sql_insert_id(mdb, NT_("Path")); - stat = 1; - } - - /* Cache path */ - if (stat && ar->PathId != mdb->cached_path_id) { - mdb->cached_path_id = ar->PathId; - mdb->cached_path_len = mdb->pnl; - pm_strcpy(mdb->cached_path, mdb->path); - } - return stat; -} - /* Create a Unique record for the filename -- no duplicates */ static int db_create_filename_record(JCR *jcr, B_DB *mdb, ATTR_DBR *ar) { diff --git a/bacula/src/cats/sql_get.c b/bacula/src/cats/sql_get.c index d0a885cb44..ba675ea67e 100644 --- a/bacula/src/cats/sql_get.c +++ b/bacula/src/cats/sql_get.c @@ -57,7 +57,6 @@ /* Forward referenced functions */ static int db_get_file_record(JCR *jcr, B_DB *mdb, JOB_DBR *jr, FILE_DBR *fdbr); static int db_get_filename_record(JCR *jcr, B_DB *mdb); -static int db_get_path_record(JCR *jcr, B_DB *mdb); /* @@ -229,7 +228,7 @@ static int db_get_filename_record(JCR *jcr, B_DB *mdb) * * DO NOT use Jmsg in this routine (see notes for get_file_record) */ -static int db_get_path_record(JCR *jcr, B_DB *mdb) +int db_get_path_record(JCR *jcr, B_DB *mdb) { SQL_ROW row; uint32_t PathId = 0; diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index f3114d625f..402c965ac1 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -226,7 +226,6 @@ bool complete_jcr_for_job(JCR *jcr, JOB *job, POOL *pool); RUN *find_next_run(RUN *run, JOB *job, utime_t &runtime, int ndays); /* ua_restore.c */ -int get_next_jobid_from_list(char **p, JobId_t *JobId); void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *MediaType); /* ua_server.c */ diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index 366d9ed370..5eae29b5c0 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -1329,42 +1329,6 @@ bail_out: return ok; } - -/* - * Return next JobId from comma separated list - * - * Returns: - * 1 if next JobId returned - * 0 if no more JobIds are in list - * -1 there is an error - */ -int get_next_jobid_from_list(char **p, JobId_t *JobId) -{ - const int maxlen = 30; - char jobid[maxlen+1]; - char *q = *p; - - jobid[0] = 0; - for (int i=0; i