*mdb->errmsg = 0;
mdb->cmd = get_pool_memory(PM_EMSG); /* command buffer */
mdb->ref_count = 1;
+ mdb->cached_path = get_pool_memory(PM_FNAME);
+ mdb->cached_path_id = 0;
qinsert(&db_list, &mdb->bq); /* put db in list */
Dmsg0(200, "Done db_open_database()\n");
mdb->cfd = -1;
rwl_destroy(&mdb->lock);
free_pool_memory(mdb->errmsg);
free_pool_memory(mdb->cmd);
+ free_pool_memory(mdb->cached_path);
free(mdb);
}
V(mutex);
char *sqlite_errmsg; /* error message returned by sqlite */
POOLMEM *errmsg; /* nicely edited error message */
POOLMEM *cmd; /* SQL command string */
+ POOLMEM *cached_path;
+ uint32_t cached_path_id;
} B_DB;
int connected;
POOLMEM *errmsg; /* nicely edited error message */
POOLMEM *cmd; /* SQL command string */
+ POOLMEM *cached_path;
+ uint32_t cached_path_id;
} B_DB;
char *db_name; /* name of database */
POOLMEM *errmsg; /* nicely edited error message */
POOLMEM *cmd; /* Command string */
+ POOLMEM *cached_path;
+ uint32_t cached_path_id;
} B_DB;
#endif /* HAVE_MYSQL */
mdb->errmsg = get_pool_memory(PM_EMSG); /* get error message buffer */
*mdb->errmsg = 0;
mdb->cmd = get_pool_memory(PM_EMSG); /* get command buffer */
+ mdb->cached_path = get_pool_memory(PM_FNAME);
+ mdb->cached_path_id = 0;
mdb->ref_count = 1;
qinsert(&db_list, &mdb->bq); /* put db in list */
V(mutex);
rwl_destroy(&mdb->lock);
free_pool_memory(mdb->errmsg);
free_pool_memory(mdb->cmd);
+ free_pool_memory(mdb->cached_path);
if (mdb->db_name) {
free(mdb->db_name);
}
{
int stat;
+ ASSERT(ar->JobId);
+ ASSERT(ar->PathId);
+ ASSERT(ar->FilenameId);
+
db_lock(mdb);
/* Must create it */
Mmsg(&mdb->cmd,
static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar, char *path)
{
SQL_ROW row;
- static uint32_t cached_id = 0;
- static char cached_path[MAXSTRING];
int stat;
if (*path == 0) {
db_lock(mdb);
- if (cached_id != 0 && strcmp(cached_path, path) == 0) {
- ar->PathId = cached_id;
+ if (mdb->cached_path_id != 0 && strcmp(mdb->cached_path, path) == 0) {
+ ar->PathId = mdb->cached_path_id;
db_unlock(mdb);
return 1;
- }
+ }
Mmsg(&mdb->cmd, "SELECT PathId FROM Path WHERE Path=\"%s\"", path);
}
sql_free_result(mdb);
ar->PathId = atoi(row[0]);
- if (ar->PathId != cached_id) {
- cached_id = ar->PathId;
- strncpy(cached_path, path, sizeof(cached_path));
- cached_path[sizeof(cached_path)-1] = 0;
+ /* Cache path */
+ if (ar->PathId != mdb->cached_path_id) {
+ mdb->cached_path_id = ar->PathId;
+ mdb->cached_path = check_pool_memory_size(mdb->cached_path,
+ strlen(path)+1);
+ strcpy(mdb->cached_path, path);
}
db_unlock(mdb);
return 1;
stat = 1;
}
- if (ar->PathId != cached_id) {
- cached_id = ar->PathId;
- strncpy(cached_path, path, sizeof(cached_path));
- cached_path[sizeof(cached_path)-1] = 0;
+ /* Cache path */
+ if (ar->PathId != mdb->cached_path_id) {
+ mdb->cached_path_id = ar->PathId;
+ mdb->cached_path = check_pool_memory_size(mdb->cached_path,
+ strlen(path)+1);
+ strcpy(mdb->cached_path, path);
}
db_unlock(mdb);
return stat;
static int db_create_filename_record(B_DB *mdb, ATTR_DBR *ar, char *fname)
{
SQL_ROW row;
- int stat;
db_lock(mdb);
Mmsg(&mdb->cmd, "SELECT FilenameId FROM Filename WHERE Name=\"%s\"", fname);
if ((row = sql_fetch_row(mdb)) == NULL) {
Mmsg2(&mdb->errmsg, _("error fetching row for file=%s: ERR=%s\n"),
fname, sql_strerror(mdb));
- sql_free_result(mdb);
- db_unlock(mdb);
ar->FilenameId = 0;
- return 0;
+ } else {
+ ar->FilenameId = atoi(row[0]);
}
sql_free_result(mdb);
- ar->FilenameId = atoi(row[0]);
db_unlock(mdb);
- return 1;
+ return ar->FilenameId > 0;
}
sql_free_result(mdb);
}
Mmsg2(&mdb->errmsg, _("Create db Filename record %s failed. ERR=%s\n"),
mdb->cmd, sql_strerror(mdb));
ar->FilenameId = 0;
- stat = 0;
} else {
ar->FilenameId = sql_insert_id(mdb);
- stat = 1;
}
db_unlock(mdb);
- return stat;
+ return ar->FilenameId > 0;
}
#endif /* HAVE_MYSQL || HAVE_SQLITE */
char file[MAXSTRING];
char spath[MAXSTRING];
char buf[MAXSTRING];
- Dmsg0(20, "get_file_from_catalog\n");
+ Dmsg1(20, "Enter get_file_from_catalog fname=%s \n", fname);
/* Find path without the filename */
for (p=l=fname; *p; p++) {
db_escape_string(buf, spath, pnl);
fdbr->PathId = db_get_path_record(mdb, buf);
- Dmsg1(50, "db_get_path_record PathId=%d\n", fdbr->PathId);
+ Dmsg2(50, "db_get_path_record PathId=%d path=%s\n", fdbr->PathId, buf);
id = db_get_file_record(mdb, fdbr);
"SELECT FileId, LStat, MD5 from File where File.JobId=%d and File.PathId=%d and \
File.FilenameId=%d", fdbr->JobId, fdbr->PathId, fdbr->FilenameId);
+ Dmsg3(050, "Get_file_record JobId=%d FilenameId=%d PathId=%d\n",
+ fdbr->JobId, fdbr->FilenameId, fdbr->PathId);
+
+ Dmsg1(100, "Query=%s\n", mdb->cmd);
+
if (QUERY_DB(mdb, mdb->cmd)) {
mdb->num_rows = sql_num_rows(mdb);
+ Dmsg1(050, "get_file_record num_rows=%d\n", (int)mdb->num_rows);
/*
* Note, we can find more than one File record with the same
*/
if (mdb->num_rows > 1) {
Emsg1(M_WARNING, 0, _("get_file_record want 1 got rows=%d\n"), mdb->num_rows);
- Emsg1(M_ERROR, 0, "%s\n", mdb->cmd);
+ Emsg1(M_ERROR, 0, "%s", mdb->cmd);
}
if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
static int db_get_filename_record(B_DB *mdb, char *fname)
{
SQL_ROW row;
- int FilenameId;
+ int FilenameId = 0;
if (*fname == 0) {
Mmsg0(&mdb->errmsg, _("Null name given to db_get_filename_record\n"));
if (mdb->num_rows > 1) {
Mmsg1(&mdb->errmsg, _("More than one Filename!: %d\n"), (int)(mdb->num_rows));
- } else if (mdb->num_rows == 1) {
+ Emsg1(M_WARNING, 0, _("get_filename_record want 1 got rows=%d\n"), mdb->num_rows);
+ Emsg1(M_ERROR, 0, "%s", mdb->errmsg);
+ }
+ if (mdb->num_rows >= 1) {
if ((row = sql_fetch_row(mdb)) == NULL) {
Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
- FilenameId = 0;
+ Emsg1(M_ERROR, 0, "%s", mdb->errmsg);
} else {
FilenameId = atoi(row[0]);
if (FilenameId <= 0) {
- Mmsg2(&mdb->errmsg, _("Create db Filename record %s found bad record: %d\n"),
+ Mmsg2(&mdb->errmsg, _("Get DB Filename record %s found bad record: %d\n"),
mdb->cmd, FilenameId);
+ Emsg1(M_ERROR, 0, "%s", mdb->errmsg);
+ FilenameId = 0;
}
}
- sql_free_result(mdb);
- db_unlock(mdb);
- return FilenameId;
}
sql_free_result(mdb);
}
db_unlock(mdb);
- return 0; /* failed */
+ return FilenameId;
}
/* Get path record
{
SQL_ROW row;
uint32_t PathId = 0;
- /*******FIXME***** move into mdb record and allocate */
- static uint32_t cached_id = 0;
- static char cached_path[MAXSTRING];
if (*path == 0) {
Emsg0(M_ABORT, 0, _("Null path given to db_get_path_record\n"));
}
- if (cached_id != 0 && strcmp(cached_path, path) == 0) {
- return cached_id;
- }
db_lock(mdb);
+
+ if (mdb->cached_path_id != 0 && strcmp(mdb->cached_path, path) == 0) {
+ db_unlock(mdb);
+ return mdb->cached_path_id;
+ }
+
Mmsg(&mdb->cmd, "SELECT PathId FROM Path WHERE Path=\"%s\"", path);
if (QUERY_DB(mdb, mdb->cmd)) {
Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb));
} else {
PathId = atoi(row[0]);
- /* Cache path if it will fit in our static buffer */
- if (PathId != cached_id && strlen(path) < sizeof(cached_path)+2) {
- cached_id = PathId;
- strcpy(cached_path, path);
+ if (PathId <= 0) {
+ Mmsg2(&mdb->errmsg, _("Get DB path record %s found bad record: %d\n"),
+ mdb->cmd, PathId);
+ PathId = 0;
+ } else {
+ /* Cache path */
+ if (PathId != mdb->cached_path_id) {
+ mdb->cached_path_id = PathId;
+ mdb->cached_path = check_pool_memory_size(mdb->cached_path,
+ strlen(path)+1);
+ strcpy(mdb->cached_path, path);
+ }
}
}
}
sql_free_result(mdb);
}
db_unlock(mdb);
- return 0; /* failed */
+ return PathId;
}
mdb->errmsg = get_pool_memory(PM_EMSG); /* get error message buffer */
*mdb->errmsg = 0;
mdb->cmd = get_pool_memory(PM_EMSG); /* get command buffer */
+ mdb->cached_path = get_pool_memory(PM_FNAME);
+ mdb->cached_path_id = 0;
mdb->ref_count = 1;
qinsert(&db_list, &mdb->bq); /* put db in list */
V(mutex);
rwl_destroy(&mdb->lock);
free_pool_memory(mdb->errmsg);
free_pool_memory(mdb->cmd);
+ free_pool_memory(mdb->cached_path);
if (mdb->db_name) {
free(mdb->db_name);
}
pr.PoolId = jcr->PoolId;
if (!db_get_pool_record(jcr->db, &pr) || !db_get_media_ids(jcr->db, &num_ids, &ids)) {
Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
- goto rtn;
+ goto bail_out;
}
stat += prune_volume(&ua, &pr, &mr);
Dmsg1(200, "Num pruned = %d\n", stat);
}
-rtn:
+
+bail_out:
db_unlock(jcr->db);
free_ua_context(&ua);
if (ids) {
}
if (stream == STREAM_UNIX_ATTRIBUTES) {
+ jcr->jr.JobFiles++;
len = strlen(fd->msg); /* length before attributes */
ar.attr = &fd->msg[len+1];
ar.fname = jcr->fname;
break;
case JT_VERIFY:
do_verify(jcr);
- do_autoprune(jcr);
+// do_autoprune(jcr);
break;
case JT_RESTORE:
do_restore(jcr);
- do_autoprune(jcr);
+// do_autoprune(jcr);
break;
case JT_ADMIN:
/* No actual job */
if (!db_sql_query(ua->db, query, count_handler, (void *)&cnt)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
Dmsg0(050, "Count failed\n");
- goto rtn;
+ goto bail_out;
}
if (cnt.count == 0) {
mr->VolumeName);
}
stat = mark_media_purged(ua, mr);
- goto rtn;
+ goto bail_out;
}
if (cnt.count < MAX_DEL_LIST_LEN) {
bsendmsg(ua, "%s", db_strerror(ua->db));
}
Dmsg0(050, "Count failed\n");
- goto rtn;
+ goto bail_out;
}
/* Use Volume Retention to prune Jobs and Files */
stat = mark_media_purged(ua, mr);
}
-rtn:
+bail_out:
db_unlock(ua->db);
free_pool_memory(query);
return stat;
int last_full_id;
if (!get_or_create_client_record(jcr)) {
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
Dmsg1(9, "bdird: created client %s record\n", jcr->client->hdr.name);
if (!db_find_last_full_verify(jcr->db, &jr)) {
Jmsg(jcr, M_FATAL, 0, _("Unable to find last full verify. %s"),
db_strerror(jcr->db));
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
last_full_id = jr.JobId;
Dmsg1(20, "Last full id=%d\n", last_full_id);
jcr->jr.Level = jcr->level;
if (!db_update_job_start_record(jcr->db, &jcr->jr)) {
Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
if (!jcr->fname) {
jr.JobId = last_full_id;
if (!db_get_job_record(jcr->db, &jr)) {
Jmsg(jcr, M_ERROR, 0, _("Could not get job record. %s"), db_strerror(jcr->db));
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
Jmsg(jcr, M_INFO, 0, _("Verifying against Init JobId %d run %s\n"),
last_full_id, jr.cStartTime);
*/
jcr->sd_auth_key = bstrdup("dummy"); /* dummy Storage daemon key */
if (!connect_to_file_daemon(jcr, 10, FDConnectTimeout, 1)) {
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
fd = jcr->file_bsock;
Dmsg0(30, ">filed: Send include list\n");
if (!send_include_list(jcr)) {
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
Dmsg0(30, ">filed: Send exclude list\n");
if (!send_exclude_list(jcr)) {
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
/*
break;
default:
Jmsg1(jcr, M_FATAL, 0, _("Unimplemented save level %d\n"), jcr->level);
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
Dmsg1(20, ">filed: %s", fd->msg);
bnet_fsend(fd, levelcmd, level, " ");
if (!response(fd, OKlevel, "Level")) {
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
/*
*/
bnet_fsend(fd, verifycmd);
if (!response(fd, OKverify, "Verify")) {
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
/*
* catalog depending on the run type.
*/
/* Compare to catalog */
- if (jcr->level == L_VERIFY_CATALOG) {
+ switch (jcr->level) {
+ case L_VERIFY_CATALOG:
Dmsg0(10, "Verify level=catalog\n");
get_attributes_and_compare_to_catalog(jcr, last_full_id);
+ break;
- /* Build catalog */
- } else if (jcr->level == L_VERIFY_INIT) {
+ case L_VERIFY_INIT:
+ /* Build catalog */
Dmsg0(10, "Verify level=init\n");
get_attributes_and_put_in_catalog(jcr);
+ break;
- } else {
+ default:
Jmsg1(jcr, M_FATAL, 0, _("Unimplemented save level %d\n"), jcr->level);
- verify_cleanup(jcr, JS_ErrorTerminated);
- return 0;
+ goto bail_out;
}
verify_cleanup(jcr, JS_Terminated);
return 1;
+
+bail_out:
+ verify_cleanup(jcr, JS_Terminated);
+ return 0;
}
/*
struct stat statc; /* catalog stat */
int stat = JS_Terminated;
char buf[MAXSTRING];
- char *fname = (char *)get_pool_memory(PM_MESSAGE);
+ POOLMEM *fname = get_pool_memory(PM_MESSAGE);
int do_MD5 = FALSE;
memset(&fdbr, 0, sizeof(FILE_DBR));
char *attr, *p;
char Opts_MD5[MAXSTRING]; /* Verify Opts or MD5 signature */
- fname = (char *)check_pool_memory_size(fname, fd->msglen);
- jcr->fname = (char *)check_pool_memory_size(jcr->fname, fd->msglen);
+ fname = check_pool_memory_size(fname, fd->msglen);
+ jcr->fname = check_pool_memory_size(jcr->fname, fd->msglen);
Dmsg1(50, "Atts+MD5=%s\n", fd->msg);
if ((len = sscanf(fd->msg, "%ld %d %100s %s", &file_index, &stream,
Opts_MD5, fname)) != 4) {
Jmsg3(jcr, M_FATAL, 0, _("bird<filed: bad attributes, expected 4 fields got %d\n\
mslen=%d msg=%s\n"), len, fd->msglen, fd->msg);
- jcr->JobStatus = JS_ErrorTerminated;
- return 0;
+ goto bail_out;
}
/*
* Got attributes stream, decode it
*/
if (stream == STREAM_UNIX_ATTRIBUTES) {
+ jcr->jr.JobFiles++;
attr_file_index = file_index; /* remember attribute file_index */
len = strlen(fd->msg);
attr = &fd->msg[len+1];
if (attr_file_index != file_index) {
Jmsg2(jcr, M_FATAL, 0, _("MD5 index %d not same as attributes %d\n"),
file_index, attr_file_index);
- jcr->JobStatus = JS_ErrorTerminated;
- return 0;
+ goto bail_out;
}
if (do_MD5) {
db_escape_string(buf, Opts_MD5, strlen(Opts_MD5));
if (n < 0) {
Jmsg2(jcr, M_FATAL, 0, _("bdird<filed: bad attributes from filed n=%d : %s\n"),
n, strerror(errno));
- jcr->JobStatus = JS_ErrorTerminated;
- return 0;
+ goto bail_out;
}
/* Now find all the files that are missing -- i.e. all files in
if (jcr->fn_printed) {
stat = JS_Differences;
}
+ free_pool_memory(fname);
jcr->JobStatus = stat;
return 1;
+
+bail_out:
+ free_pool_memory(fname);
+ jcr->JobStatus = JS_ErrorTerminated;
+ return 0;
}
/*
uint32_t PoolId; /* Pool record id */
FileId_t FileId; /* Last file id inserted */
uint32_t FileIndex; /* Last FileIndex processed */
- char *fname; /* name to put into catalog */
+ POOLMEM *fname; /* name to put into catalog */
int fn_printed; /* printed filename */
char *stime; /* start time for incremental/differential */
JOB_DBR jr; /* Job record in Database */
/* */
#define VERSION "1.20"
#define VSTRING "1"
-#define DATE "21 May 2002"
-#define LSMDATE "21May02"
+#define DATE "22 May 2002"
+#define LSMDATE "22May02"
/* Debug flags */
#define DEBUG 1