From 9e81f599d76c37988d2692db51fb128aa5749c13 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 25 May 2002 15:29:37 +0000 Subject: [PATCH] Make Recycle work -- kes25May02 git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@29 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/baconfig.h | 6 +- bacula/src/cats/sql_create.c | 11 +- bacula/src/console.glade | 315 +++++++++++++++++------------- bacula/src/console/console_conf.c | 1 + bacula/src/dird/autoprune.c | 4 +- bacula/src/dird/catreq.c | 34 ++-- bacula/src/dird/dird.c | 2 +- bacula/src/dird/dird_conf.c | 101 ++++++++-- bacula/src/dird/job.c | 4 +- bacula/src/dird/newvol.c | 21 +- bacula/src/dird/protos.h | 2 +- bacula/src/dird/run_conf.c | 23 ++- bacula/src/dird/ua_cmds.c | 10 +- bacula/src/dird/ua_output.c | 20 +- bacula/src/dird/ua_prune.c | 6 +- bacula/src/dird/ua_select.c | 6 + bacula/src/filed/filed_conf.c | 1 + bacula/src/jcr.h | 1 + bacula/src/lib/message.c | 13 +- bacula/src/lib/parse_conf.c | 12 +- bacula/src/lib/protos.h | 170 ++++++++-------- bacula/src/stored/askdir.c | 44 ++--- bacula/src/stored/bextract.c | 20 +- bacula/src/stored/block.c | 4 +- bacula/src/stored/block.h | 30 +-- bacula/src/stored/dev.c | 86 ++++---- bacula/src/stored/device.c | 18 +- bacula/src/stored/dircmd.c | 2 +- bacula/src/stored/label.c | 19 +- bacula/src/stored/protos.h | 3 +- bacula/src/stored/record.c | 4 +- bacula/src/stored/record.h | 82 ++++---- bacula/src/stored/stored_conf.c | 1 + bacula/src/version.h | 4 +- 34 files changed, 634 insertions(+), 446 deletions(-) diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index d7393b19a4..5472c7f651 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -42,7 +42,11 @@ #endif /* #define ASSERT(x) if (!(x)) Emsg1(M_ABORT, 0, "Failed ASSERT: %s\n", __STRING(x)) */ -#define ASSERT(x) if (!(x)) Emsg1(M_ABORT, 0, "Failed ASSERT: %s\n", #x) +#define ASSERT(x) if (!(x)) { \ + char *jcr = NULL; \ + Emsg1(M_ERROR, 0, "Failed ASSERT: %s\n", #x); \ + jcr[0] = 0; } + #ifdef ENABLE_NLS diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index 6b08a73898..e889fee83f 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -293,8 +293,8 @@ int db_create_client_record(B_DB *mdb, CLIENT_DBR *cr) db_unlock(mdb); return 0; } - sql_free_result(mdb); cr->ClientId = atoi(row[0]); + sql_free_result(mdb); db_unlock(mdb); return 1; } @@ -353,8 +353,8 @@ FileSet=\"%s\" and MD5=\"%s\"", fsr->FileSet, fsr->MD5); db_unlock(mdb); return 0; } - sql_free_result(mdb); fsr->FileSetId = atoi(row[0]); + sql_free_result(mdb); db_unlock(mdb); return 1; } @@ -544,6 +544,7 @@ static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar, char *path) if (*path == 0) { Mmsg0(&mdb->errmsg, _("Null path given to db_create_path_record\n")); ar->PathId = 0; + ASSERT(ar->PathId); return 0; } @@ -551,6 +552,7 @@ static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar, char *path) if (mdb->cached_path_id != 0 && strcmp(mdb->cached_path, path) == 0) { ar->PathId = mdb->cached_path_id; + ASSERT(ar->PathId); db_unlock(mdb); return 1; } @@ -574,10 +576,11 @@ static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar, char *path) Mmsg1(&mdb->errmsg, _("error fetching row: %s\n"), sql_strerror(mdb)); sql_free_result(mdb); ar->PathId = 0; + ASSERT(ar->PathId); return 0; } - sql_free_result(mdb); ar->PathId = atoi(row[0]); + sql_free_result(mdb); /* Cache path */ if (ar->PathId != mdb->cached_path_id) { mdb->cached_path_id = ar->PathId; @@ -585,6 +588,7 @@ static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar, char *path) strlen(path)+1); strcpy(mdb->cached_path, path); } + ASSERT(ar->PathId); db_unlock(mdb); return 1; } @@ -611,6 +615,7 @@ static int db_create_path_record(B_DB *mdb, ATTR_DBR *ar, char *path) strlen(path)+1); strcpy(mdb->cached_path, path); } + ASSERT(ar->PathId); db_unlock(mdb); return stat; } diff --git a/bacula/src/console.glade b/bacula/src/console.glade index cf1622a783..2df7b3bfe7 100644 --- a/bacula/src/console.glade +++ b/bacula/src/console.glade @@ -69,140 +69,6 @@ - - GnomeDialog - SelectDirectorDialog - Select Director - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - True - False - True - False - False - False - - - GtkVBox - GnomeDialog:vbox - dialog-vbox2 - False - 1 - - 0 - True - True - - - - GtkHButtonBox - GnomeDialog:action_area - dialog-action_area2 - GTK_BUTTONBOX_END - 8 - 85 - 27 - 7 - 0 - - 0 - False - True - GTK_PACK_END - - - - GtkButton - button11 - True - True - - clicked - on_select_director_clicked - Sun, 17 Mar 2002 21:07:26 GMT - - GNOME_STOCK_BUTTON_OK - - - - GtkButton - button13 - True - True - GNOME_STOCK_BUTTON_CANCEL - - - - - GtkVBox - vbox4 - False - 0 - - 0 - True - True - - - - GtkLabel - label20 - - GTK_JUSTIFY_CENTER - False - 0.5 - 0.5 - 0 - 0 - - 3 - False - False - - - - - GtkHBox - hbox10 - False - 0 - - 0 - True - True - - - - GtkCombo - combo1 - False - True - False - True - False - - - 0 - True - True - - - - GtkEntry - GtkCombo:entry - combo-entry9 - True - True - True - 0 - - - - - - - - GnomeDialog RunDialog @@ -818,11 +684,6 @@ on_app1_delete_event Mon, 01 Apr 2002 07:29:22 GMT - - show - on_app1_show - Mon, 01 Apr 2002 07:29:16 GMT - Bacula Console GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE @@ -1449,4 +1310,180 @@ + + GtkDialog + SelectDirectorDialog + Select Director + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + True + False + False + False + + + GtkVBox + Dialog:vbox + dialog-vbox6 + False + 0 + + + GtkHBox + Dialog:action_area + dialog-action_area2 + 10 + True + 5 + + 0 + False + True + GTK_PACK_END + + + + GtkHBox + hbox21 + False + 0 + + 0 + True + True + + + + GtkButton + button11 + 85 + True + + clicked + on_select_director_OK_clicked + Wed, 22 May 2002 19:42:41 GMT + + GNOME_STOCK_BUTTON_OK + GTK_RELIEF_NORMAL + + 0 + False + False + + + + + GtkLabel + label46 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 2 + 0 + + 0 + False + False + + + + + GtkButton + button13 + True + + clicked + on_select_director_cancel_clicked + Wed, 22 May 2002 19:43:08 GMT + + GNOME_STOCK_BUTTON_CANCEL + GTK_RELIEF_NORMAL + + 0 + False + False + + + + + + + GtkVBox + vbox10 + False + 0 + + 0 + True + True + + + + GtkLabel + label48 + 12 + + GTK_JUSTIFY_CENTER + False + 0.48 + 0.46 + 0 + 0 + + 0 + False + False + + + + + GtkLabel + label47 + + GTK_JUSTIFY_CENTER + False + 0.5 + 0.5 + 0 + 0 + + 0 + False + False + + + + + GtkCombo + combo1 + 6 + False + True + False + True + False + + + 0 + False + False + + + + GtkEntry + GtkCombo:entry + dirselect + True + True + True + 0 + + + + + + + diff --git a/bacula/src/console/console_conf.c b/bacula/src/console/console_conf.c index 555a08bfbb..202d750ae3 100644 --- a/bacula/src/console/console_conf.c +++ b/bacula/src/console/console_conf.c @@ -228,6 +228,7 @@ void save_resource(int type, struct res_items *items, int pass) return; } + /* The following code is only executed during pass 1 */ switch (type) { case R_CONSOLE: size = sizeof(CONSRES); diff --git a/bacula/src/dird/autoprune.c b/bacula/src/dird/autoprune.c index 4422e9fa85..64f38888e4 100644 --- a/bacula/src/dird/autoprune.c +++ b/bacula/src/dird/autoprune.c @@ -110,8 +110,8 @@ int prune_volumes(JCR *jcr) UAContext ua; if (!jcr->job->PruneVolumes && !jcr->pool->AutoPrune) { - Dmsg0(200, "AutoPrune not set in Pool.\n"); - return stat; + Dmsg0(100, "AutoPrune not set in Pool.\n"); + return 0; } memset(&mr, 0, sizeof(mr)); memset(&pr, 0, sizeof(pr)); diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index 58bef7f4db..f8f9965f65 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -48,7 +48,7 @@ static char Update_media[] = "CatReq Job=%127s UpdateMedia VolName=%s\ VolJobs=%d VolFiles=%d VolBlocks=%d VolBytes=%" lld " VolMounts=%d\ VolErrors=%d VolWrites=%d VolMaxBytes=%" lld " EndTime=%d VolStatus=%10s\ FirstIndex=%d LastIndex=%d StartFile=%d EndFile=%d \ - StartBlock=%d EndBlock=%d\n"; + StartBlock=%d EndBlock=%d relabel=%d\n"; /* Responses sent to Storage daemon */ static char OK_media[] = "1000 OK VolName=%s VolJobs=%d VolFiles=%d\ @@ -65,7 +65,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg) MEDIA_DBR mr; JOBMEDIA_DBR jm; char Job[MAX_NAME_LENGTH]; - int index, ok; + int index, ok, relabel; char *omsg; memset(&mr, 0, sizeof(mr)); @@ -84,22 +84,18 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg) /* * Find the Volume */ - ok = FALSE; - if (db_find_next_volume(jcr->db, index, &mr)) { - jcr->MediaId = mr.MediaId; - Dmsg1(20, "Find_next_vol MediaId=%d\n", jcr->MediaId); - strcpy(jcr->VolumeName, mr.VolumeName); - ok = TRUE; - } else { + ok = db_find_next_volume(jcr->db, index, &mr); + if (!ok) { /* Well, try finding recycled tapes */ ok = find_recycled_volume(jcr, &mr); + Dmsg1(100, "find_recycled_volume1 %d\n", ok); if (!ok) { - if (prune_volumes(jcr)) { - ok = recycle_a_volume(jcr, &mr); - } + prune_volumes(jcr); + ok = recycle_a_volume(jcr, &mr); + Dmsg1(100, "find_recycled_volume2 %d\n", ok); if (!ok) { /* See if we can create a new Volume */ - ok = newVolume(jcr); + ok = newVolume(jcr, &mr); } } } @@ -107,6 +103,8 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg) * Send Find Media response to Storage daemon */ if (ok) { + jcr->MediaId = mr.MediaId; + strcpy(jcr->VolumeName, mr.VolumeName); bash_spaces(mr.VolumeName); bnet_fsend(bs, OK_media, mr.VolumeName, mr.VolJobs, mr.VolFiles, mr.VolBlocks, mr.VolBytes, mr.VolMounts, mr.VolErrors, @@ -146,7 +144,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg) mr.VolWrites, mr.VolMaxBytes, mr.VolCapacityBytes, mr.VolStatus); } else { - Dmsg4(000, "get_media_record PoolId=%d wanted %d, Status=%s, \ + Dmsg4(100, "get_media_record PoolId=%d wanted %d, Status=%s, \ MediaType=%s\n", mr.PoolId, jcr->PoolId, mr.VolStatus, mr.MediaType); /* Not suitable volume */ bnet_fsend(bs, "1998 Volume not appropriate.\n"); @@ -165,7 +163,7 @@ MediaType=%s\n", mr.PoolId, jcr->PoolId, mr.VolStatus, mr.MediaType); &mr.VolFiles, &mr.VolBlocks, &mr.VolBytes, &mr.VolMounts, &mr.VolErrors, &mr.VolWrites, &mr.VolMaxBytes, &mr.LastWritten, &mr.VolStatus, &jm.FirstIndex, &jm.LastIndex, &jm.StartFile, &jm.EndFile, - &jm.StartBlock, &jm.EndBlock) == 18) { + &jm.StartBlock, &jm.EndBlock, &relabel) == 19) { /* * Update Media Record */ @@ -177,12 +175,12 @@ MediaType=%s\n", mr.PoolId, jcr->PoolId, mr.VolStatus, mr.MediaType); jm.JobId = jcr->JobId; jm.MediaId = jcr->MediaId; /* - * A single write means we just labeled the tape, + * If relabel is set, it means we just labeled the tape, * so no need to create a jobmedia record. * Otherwise, record the fact that this job used this Volume */ - if (mr.VolWrites > 1) { - Dmsg4(20, "create_jobmedia JobId=%d MediaId=%d FI=%d LI=%d\n", + if (!relabel) { + Dmsg4(100, "create_jobmedia JobId=%d MediaId=%d FI=%d LI=%d\n", jm.JobId, jm.MediaId, jm.FirstIndex, jm.LastIndex); if(!db_create_jobmedia_record(jcr->db, &jm)) { Jmsg(jcr, M_ERROR, 0, _("Catalog error creating JobMedia record. %s"), diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index e96b49a923..0313d1bb4f 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -186,7 +186,7 @@ int main (int argc, char *argv[]) /* Create pid must come after we are a daemon -- so we have our final pid */ create_pid_file(director->pid_directory, "bacula-dir", director->DIRport); - signal(SIGHUP, reload_config); +/* signal(SIGHUP, reload_config); */ init_console_msg(working_directory); diff --git a/bacula/src/dird/dird_conf.c b/bacula/src/dird/dird_conf.c index a0bc675d0a..b1145ce37e 100644 --- a/bacula/src/dird/dird_conf.c +++ b/bacula/src/dird/dird_conf.c @@ -460,11 +460,73 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ... sendit(sock, " Exc: %s\n", res->res_fs.exclude_array[i]); break; case R_SCHEDULE: - if (res->res_sch.run) - sendit(sock, "Schedule: name=%s Level=%s\n", res->res_sch.hdr.name, - level_to_str(res->res_sch.run->level)); - else + if (res->res_sch.run) { + int i; + RUN *run = res->res_sch.run; + char buf[1000], num[10]; sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name); + if (!run) { + break; + } +next_run: + sendit(sock, " --> Run Level=%s\n", level_to_str(run->level)); + strcpy(buf, " hour="); + for (i=0; i<24; i++) { + if (bit_is_set(i, run->hour)) { + sprintf(num, "%d ", i+1); + strcat(buf, num); + } + } + strcat(buf, "\n"); + sendit(sock, buf); + strcpy(buf, " mday="); + for (i=0; i<31; i++) { + if (bit_is_set(i, run->mday)) { + sprintf(num, "%d ", i+1); + strcat(buf, num); + } + } + strcat(buf, "\n"); + sendit(sock, buf); + strcpy(buf, " month="); + for (i=0; i<12; i++) { + if (bit_is_set(i, run->month)) { + sprintf(num, "%d ", i+1); + strcat(buf, num); + } + } + strcat(buf, "\n"); + sendit(sock, buf); + strcpy(buf, " wday="); + for (i=0; i<7; i++) { + if (bit_is_set(i, run->wday)) { + sprintf(num, "%d ", i+1); + strcat(buf, num); + } + } + strcat(buf, "\n"); + sendit(sock, buf); + sendit(sock, " mins=%d\n", run->minute); + if (run->pool) { + sendit(sock, " --> "); + dump_resource(-R_POOL, (RES *)run->pool, sendit, sock); + } + if (run->storage) { + sendit(sock, " --> "); + dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock); + } + if (run->msgs) { + sendit(sock, " --> "); + dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock); + } + /* If another Run record is chained in, go print it */ + if (run->next) { + run = run->next; + goto next_run; + } + } else { + sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name); + } break; case R_GROUP: sendit(sock, "Group: name=%s\n", res->res_group.hdr.name); @@ -478,11 +540,8 @@ void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ... sendit(sock, " max_vols=%d auto_prune=%d VolRetention=%" lld "\n", res->res_pool.max_volumes, res->res_pool.AutoPrune, res->res_pool.VolRetention); - sendit(sock, " recycle=%d\n", res->res_pool.Recycle); - - - sendit(sock, " LabelFormat=%s\n", res->res_pool.label_format? - res->res_pool.label_format:"NONE"); + sendit(sock, " recycle=%d LabelFormat=%s\n", res->res_pool.Recycle, + res->res_pool.label_format?res->res_pool.label_format:"*None*"); break; case R_MSGS: sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name); @@ -629,7 +688,8 @@ void free_resource(int type) /* * Save the new resource by chaining it into the head list for * the resource. If this is pass 2, we update any resource - * pointers (currently only in the Job resource). + * pointers because they may not have been defined until + * later in pass 1. */ void save_resource(int type, struct res_items *items, int pass) { @@ -654,9 +714,9 @@ void save_resource(int type, struct res_items *items, int pass) } } - /* During pass 2, we looked up pointers to all the resources - * referrenced in the current resource, , now we - * must copy their address from the static record to the allocated + /* During pass 2 in each "store" routine, we looked up pointers + * to all the resources referrenced in the current resource, now we + * must copy their addresses from the static record to the allocated * record. */ if (pass == 2) { @@ -665,7 +725,6 @@ void save_resource(int type, struct res_items *items, int pass) case R_CATALOG: case R_STORAGE: case R_FILESET: - case R_SCHEDULE: case R_GROUP: case R_POOL: case R_MSGS: @@ -712,6 +771,17 @@ void save_resource(int type, struct res_items *items, int pass) } res->res_client.catalog = res_all.res_client.catalog; break; + case R_SCHEDULE: + /* Schedule is a bit different in that it contains a RUN record + * chain which isn't a "named" resource. This chain was linked + * in by run_conf.c during pass 2, so here we jam the pointer + * into the Schedule resource. + */ + if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) { + Emsg1(M_ABORT, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name); + } + res->res_sch.run = res_all.res_sch.run; + break; default: Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type); error = 1; @@ -731,6 +801,7 @@ void save_resource(int type, struct res_items *items, int pass) return; } + /* The following code is only executed for pass 1 */ switch (type) { case R_DIRECTOR: size = sizeof(DIRRES); @@ -769,7 +840,7 @@ void save_resource(int type, struct res_items *items, int pass) } /* Common */ if (!error) { - res = (URES *) malloc(size); + res = (URES *)malloc(size); memcpy(res, &res_all, size); res->res_dir.hdr.next = resources[rindex].res_head; resources[rindex].res_head = (RES *)res; diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index c6c55e0dc2..28d1a1fb58 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -154,7 +154,9 @@ static void job_thread(void *arg) switch (jcr->JobType) { case JT_BACKUP: do_backup(jcr); - do_autoprune(jcr); + if (jcr->JobStatus == JS_Terminated) { + do_autoprune(jcr); + } break; case JT_VERIFY: do_verify(jcr); diff --git a/bacula/src/dird/newvol.c b/bacula/src/dird/newvol.c index 92c2b1f691..6b3cec4216 100644 --- a/bacula/src/dird/newvol.c +++ b/bacula/src/dird/newvol.c @@ -39,13 +39,11 @@ * Really crude automatic Volume name creation using * LabelFormat */ -int newVolume(JCR *jcr) +int newVolume(JCR *jcr, MEDIA_DBR *mr) { - MEDIA_DBR mr; POOL_DBR pr; char name[MAXSTRING]; - memset(&mr, 0, sizeof(mr)); memset(&pr, 0, sizeof(pr)); /* See if we can create a new Volume */ @@ -53,18 +51,17 @@ int newVolume(JCR *jcr) if (db_get_pool_record(jcr->db, &pr) && pr.LabelFormat[0] && pr.LabelFormat[0] != '*') { if (pr.MaxVols == 0 || pr.NumVols < pr.MaxVols) { - memset(&mr, 0, sizeof(mr)); - mr.PoolId = jcr->PoolId; - strcpy(mr.MediaType, jcr->store->media_type); + mr->PoolId = jcr->PoolId; + strcpy(mr->MediaType, jcr->store->media_type); strcpy(name, pr.LabelFormat); strcat(name, "%04d"); - sprintf(mr.VolumeName, name, ++pr.NumVols); - strcpy(mr.VolStatus, "Append"); - mr.Recycle = pr.Recycle; - mr.VolRetention = pr.VolRetention; - if (db_create_media_record(jcr->db, &mr) && + sprintf(mr->VolumeName, name, ++pr.NumVols); + strcpy(mr->VolStatus, "Append"); + mr->Recycle = pr.Recycle; + mr->VolRetention = pr.VolRetention; + if (db_create_media_record(jcr->db, mr) && db_update_pool_record(jcr->db, &pr) == 1) { - Dmsg1(90, "Created new Volume=%s\n", mr.VolumeName); + Dmsg1(90, "Created new Volume=%s\n", mr->VolumeName); return 1; } else { Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db)); diff --git a/bacula/src/dird/protos.h b/bacula/src/dird/protos.h index 9f612b24e8..10788274a4 100644 --- a/bacula/src/dird/protos.h +++ b/bacula/src/dird/protos.h @@ -73,7 +73,7 @@ extern int32_t bget_msg(BSOCK *bs, int type); extern int response(BSOCK *fd, char *resp, char *cmd); /* newvol.c */ -extern int newVolume(JCR *jcr); +extern int newVolume(JCR *jcr, MEDIA_DBR *mr); /* ua_cmd.c */ extern int create_pool(B_DB *db, POOL *pool); diff --git a/bacula/src/dird/run_conf.c b/bacula/src/dird/run_conf.c index e173356a54..1ff22e5ebe 100644 --- a/bacula/src/dird/run_conf.c +++ b/bacula/src/dird/run_conf.c @@ -157,7 +157,7 @@ static struct s_kw RunFields[] = { * * Parse Run statement: * - * Run [on] 2 january at 23:45 + * Run [on] 2 january at 23:45 * * Default Run time is daily at 0:0 * @@ -248,6 +248,18 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) } /* end switch */ } /* end if strcasecmp */ } /* end for RunFields */ + + /* At this point, it is not a keyword. Check for old syle + * Job Levels without keyword. This form is depreciated!!! + */ + for (j=0; joblevels[j].level_name; j++) { + if (strcasecmp(lc->str, joblevels[j].level_name) == 0) { + lrun.level = joblevels[j].level; + lrun.job_type = joblevels[j].job_type; + found = TRUE; + break; + } + } } /* end for found */ @@ -258,7 +270,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) state = s_none; set_defaults(); - while ((token = lex_get_token(lc)) != T_EOL) { + for ( ; token != T_EOL; (token = lex_get_token(lc))) { int len, pm; switch (token) { case T_NUMBER: @@ -328,7 +340,6 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) } if (!have_hour) { clear_bit(0, lrun.hour); - have_hour = TRUE; } p = strchr(lc->str, ':'); if (!p) { @@ -357,6 +368,7 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) } set_bit(code, lrun.hour); lrun.minute = code2; + have_hour = TRUE; break; case s_at: have_at = TRUE; @@ -462,7 +474,6 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) break; case s_monthly: clear_defaults(); - set_bit(0, lrun.mday); set_bits(0, 11, lrun.month); break; default: @@ -475,8 +486,8 @@ void store_run(LEX *lc, struct res_items *item, int index, int pass) * and link it into the list of run records * in the schedule resource. */ - if (pass == 1) { - trun = (RUN *) malloc(sizeof(RUN)); + if (pass == 2) { + trun = (RUN *)malloc(sizeof(RUN)); memcpy(trun, &lrun, sizeof(RUN)); if (*run) { trun->next = *run; diff --git a/bacula/src/dird/ua_cmds.c b/bacula/src/dird/ua_cmds.c index 3f1ee1c59f..6f4b7f09d5 100644 --- a/bacula/src/dird/ua_cmds.c +++ b/bacula/src/dird/ua_cmds.c @@ -660,11 +660,17 @@ static int update_pool(UAContext *ua) int id; POOL *pool; + + pool = get_pool_resource(ua); + if (!pool) { + return 0; + } + memset(&pr, 0, sizeof(pr)); + strcpy(pr.Name, pool->hdr.name); if (!get_pool_dbr(ua, &pr)) { - return 1; + return 0; } - strcpy(pr.PoolType, pool->pool_type); if (pr.MaxVols != (uint32_t) (pool->max_volumes)) { pr.MaxVols = pool->max_volumes; diff --git a/bacula/src/dird/ua_output.c b/bacula/src/dird/ua_output.c index 2df7c9d702..cfeadeca1c 100644 --- a/bacula/src/dird/ua_output.c +++ b/bacula/src/dird/ua_output.c @@ -189,7 +189,7 @@ int showcmd(UAContext *ua, char *cmd) */ int listcmd(UAContext *ua, char *cmd) { - char *VolumeName; + POOLMEM *VolumeName; int jobid, n; int i, j; JOB_DBR jr; @@ -283,8 +283,9 @@ int listcmd(UAContext *ua, char *cmd) } else if (strcasecmp(ua->argk[i], _("pools")) == 0) { db_list_pool_records(ua->db, prtit, ua); - /* List MEDIA */ - } else if (strcasecmp(ua->argk[i], _("media")) == 0) { + /* List MEDIA or VOLUMES */ + } else if (strcasecmp(ua->argk[i], _("media")) == 0 || + strcasecmp(ua->argk[i], _("volumes")) == 0) { int done = FALSE; for (j=i+1; jargc; j++) { if (strcasecmp(ua->argk[j], _("job")) == 0 && ua->argv[j]) { @@ -298,7 +299,7 @@ int listcmd(UAContext *ua, char *cmd) } else { continue; } - VolumeName = (char *) get_pool_memory(PM_FNAME); + VolumeName = get_pool_memory(PM_FNAME); n = db_get_job_volume_names(ua->db, jobid, VolumeName); bsendmsg(ua, _("Jobid %d used %d Volume(s): %s\n"), jobid, n, VolumeName); free_memory(VolumeName); @@ -328,8 +329,7 @@ void do_messages(UAContext *ua, char *cmd) rewind(con_fd); while (fgets(msg, sizeof(msg), con_fd)) { mlen = strlen(msg); - ua->UA_sock->msg = (char *) check_pool_memory_size( - ua->UA_sock->msg, mlen+1); + ua->UA_sock->msg = check_pool_memory_size(ua->UA_sock->msg, mlen+1); strcpy(ua->UA_sock->msg, msg); ua->UA_sock->msglen = mlen; bnet_send(ua->UA_sock); @@ -382,12 +382,12 @@ void bsendmsg(void *ctx, char *fmt, ...) UAContext *ua = (UAContext *)ctx; BSOCK *bs = ua->UA_sock; int maxlen, len; - char *msg; + POOLMEM *msg; if (bs) { msg = bs->msg; } else { - msg = (char *)get_pool_memory(PM_EMSG); + msg = get_pool_memory(PM_EMSG); } again: @@ -396,7 +396,7 @@ again: len = bvsnprintf(msg, maxlen, fmt, arg_ptr); va_end(arg_ptr); if (len < 0 || len >= maxlen) { - msg = (char *) realloc_pool_memory(msg, maxlen + 200); + msg = realloc_pool_memory(msg, maxlen + 200); goto again; } @@ -405,7 +405,7 @@ again: bnet_send(bs); } else { /* No UA, send to Job */ Jmsg(ua->jcr, M_INFO, 0, msg); - free_memory(msg); + free_pool_memory(msg); } } diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index 13c4bf5abf..8f78f0ebda 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -487,8 +487,8 @@ int prune_jobs(UAContext *ua, CLIENT *client) db_sql_query(ua->db, query, NULL, (void *)NULL); Dmsg1(050, "Del sql=%s\n", query); } - bsendmsg(ua, _("Pruned %d Jobs for client %s from %s catalog.\n"), del.num_ids, - client->hdr.name, client->catalog->hdr.name); + bsendmsg(ua, _("Pruned %d %s for client %s from %s catalog.\n"), del.num_ids, + del.num_ids==1?_("Job"):_("Jobs"), client->hdr.name, client->catalog->hdr.name); bail_out: drop_temp_tables(ua); @@ -581,7 +581,7 @@ int prune_volume(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr) if (del.JobId) { free(del.JobId); } - if (ua->verbose) { + if (ua->verbose && del.num_del != 0) { bsendmsg(ua, _("Pruned %d Jobs on Volume %s from catalog.\n"), del.num_del, mr->VolumeName); } diff --git a/bacula/src/dird/ua_select.c b/bacula/src/dird/ua_select.c index 0a2fddddca..91f7f84962 100644 --- a/bacula/src/dird/ua_select.c +++ b/bacula/src/dird/ua_select.c @@ -254,6 +254,12 @@ int get_pool_dbr(UAContext *ua, POOL_DBR *pr) { int i; + if (pr->Name[0]) { /* If name already supplied */ + if (db_get_pool_record(ua->db, pr)) { + return pr->PoolId; + } + bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), pr->Name, db_strerror(ua->db)); + } for (i=1; iargc; i++) { if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i]) { strcpy(pr->Name, ua->argv[i]); diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index c2ef765ef6..315163e706 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -266,6 +266,7 @@ void save_resource(int type, struct res_items *items, int pass) return; } + /* The following code is only executed on pass 1 */ switch (type) { case R_DIRECTOR: size = sizeof(DIRRES); diff --git a/bacula/src/jcr.h b/bacula/src/jcr.h index a0792bf3c2..dc94829887 100644 --- a/bacula/src/jcr.h +++ b/bacula/src/jcr.h @@ -175,6 +175,7 @@ struct s_jcr { long CurVolume; /* current volume number */ int mode; /* manual/auto run */ int label_status; /* device volume label status */ + int label_errors; /* count of label errors */ int session_opened; DEV_RECORD rec; /* Read/Write record */ long Ticket; /* ticket for this job */ diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index d2d434d54e..e36b55d487 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -157,7 +157,7 @@ init_msg(void *vjcr, MSGS *msg) * for the current Job. */ for (d=msg->dest_chain; d; d=d->next) { - dnew = (DEST *) malloc(sizeof(DEST)); + dnew = (DEST *)malloc(sizeof(DEST)); memcpy(dnew, d, sizeof(DEST)); dnew->next = temp_chain; dnew->fd = NULL; @@ -890,12 +890,15 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...) Dmsg1(200, "Enter Jmsg type=%d\n", type); msgs = NULL; + job = NULL; if (jcr) { msgs = jcr->msgs; job = jcr->Job; } - if (msgs == NULL) { + if (!msgs) { msgs = daemon_msgs; + } + if (!job) { job = "*None*"; } @@ -949,7 +952,7 @@ Jmsg(void *vjcr, int type, int level, char *fmt,...) /* * Edit a message into a Pool memory buffer, with file:lineno */ -int m_msg(char *file, int line, char **pool_buf, char *fmt, ...) +int m_msg(char *file, int line, POOLMEM **pool_buf, char *fmt, ...) { va_list arg_ptr; int i, len, maxlen; @@ -963,7 +966,7 @@ again: len = bvsnprintf(*pool_buf+i, maxlen, fmt, arg_ptr); va_end(arg_ptr); if (len < 0 || len >= maxlen) { - *pool_buf = (char *) realloc_pool_memory(*pool_buf, maxlen + i + 200); + *pool_buf = realloc_pool_memory(*pool_buf, maxlen + i + 200); goto again; } return len; @@ -973,7 +976,7 @@ again: * Edit a message into a Pool Memory buffer NO file:lineno * Returns: string length of what was edited. */ -int Mmsg(char **pool_buf, char *fmt, ...) +int Mmsg(POOLMEM **pool_buf, char *fmt, ...) { va_list arg_ptr; int len, maxlen; diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index aabfa3328c..77590b139b 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -18,6 +18,16 @@ * definitions as well as any specific store routines * for the resource records. * + * N.B. This is a two pass parser, so if you malloc() a string + * in a "store" routine, you must ensure to do it during + * only one of the two passes, or to free it between. + * Also, note that the resource record is malloced and + * saved in save_resource() during pass 1. Anything that + * you want saved after pass two (e.g. resource pointers) + * must explicitly be done in save_resource. Take a look + * at the Job resource in src/dird/dird_conf.c to see how + * it is done. + * * Kern Sibbald, January MM * * Version $Id$ @@ -752,7 +762,7 @@ parse_config(char *cf) * and the second picks up the items. */ Dmsg0(200, "Enter parse_config()\n"); - for (pass=1; pass<= 2; pass++) { + for (pass=1; pass <= 2; pass++) { Dmsg1(200, "parse_config pass %d\n", pass); lc = lex_open_file(lc, cf); while ((token=lex_get_token(lc)) != T_EOF) { diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index 7fc99d14bf..5d2b3426d7 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -24,131 +24,131 @@ */ /* base64.c */ -void base64_init __PROTO((void)); -int to_base64 __PROTO((intmax_t value, char *where)); -int from_base64 __PROTO((intmax_t *value, char *where)); -void encode_stat __PROTO((char *buf, struct stat *statp)); -void decode_stat __PROTO((char *buf, struct stat *statp)); -int bin_to_base64 __PROTO((char *buf, char *bin, int len)); +void base64_init (void); +int to_base64 (intmax_t value, char *where); +int from_base64 (intmax_t *value, char *where); +void encode_stat (char *buf, struct stat *statp); +void decode_stat (char *buf, struct stat *statp); +int bin_to_base64 (char *buf, char *bin, int len); /* bmisc.c */ -void *b_malloc (char *file, int line, size_t size); +void *b_malloc (char *file, int line, size_t size); #ifndef DEBUG -void *bmalloc (size_t size); +void *bmalloc (size_t size); #endif -void *brealloc (void *buf, size_t size); -void *bcalloc (size_t size1, size_t size2); -int bsnprintf (char *str, size_t size, const char *format, ...); -int bvsnprintf (char *str, size_t size, const char *format, va_list ap); -int pool_sprintf (char *pool_buf, char *fmt, ...); -void create_pid_file (char *dir, char *progname, int port); -int delete_pid_file (char *dir, char *progname, int port); +void *brealloc (void *buf, size_t size); +void *bcalloc (size_t size1, size_t size2); +int bsnprintf (char *str, size_t size, const char *format, ...); +int bvsnprintf (char *str, size_t size, const char *format, va_list ap); +int pool_sprintf (char *pool_buf, char *fmt, ...); +void create_pid_file (char *dir, char *progname, int port); +int delete_pid_file (char *dir, char *progname, int port); /* bnet.c */ -int32_t bnet_recv __PROTO((BSOCK *bsock)); -int bnet_send __PROTO((BSOCK *bsock)); -int bnet_fsend (BSOCK *bs, char *fmt, ...); -int bnet_set_buffer_size (BSOCK *bs, uint32_t size, int rw); -int bnet_sig (BSOCK *bs, int sig); -BSOCK * bnet_connect (void *jcr, int retry_interval, - int max_retry_time, char *name, char *host, char *service, - int port, int verbose); -int bnet_wait_data (BSOCK *bsock, int sec); -void bnet_close __PROTO((BSOCK *bsock)); -BSOCK * init_bsock __PROTO((int sockfd, char *who, char *ip, int port)); -BSOCK * dup_bsock __PROTO((BSOCK *bsock)); -void term_bsock __PROTO((BSOCK *bsock)); -char * bnet_strerror __PROTO((BSOCK *bsock)); -char * bnet_sig_to_ascii __PROTO((BSOCK *bsock)); -int bnet_wait_data __PROTO((BSOCK *bsock, int sec)); +int32_t bnet_recv (BSOCK *bsock); +int bnet_send (BSOCK *bsock); +int bnet_fsend (BSOCK *bs, char *fmt, ...); +int bnet_set_buffer_size (BSOCK *bs, uint32_t size, int rw); +int bnet_sig (BSOCK *bs, int sig); +BSOCK * bnet_connect (void *jcr, int retry_interval, + int max_retry_time, char *name, char *host, char *service, + int port, int verbose); +int bnet_wait_data (BSOCK *bsock, int sec); +void bnet_close (BSOCK *bsock); +BSOCK * init_bsock (int sockfd, char *who, char *ip, int port); +BSOCK * dup_bsock (BSOCK *bsock); +void term_bsock (BSOCK *bsock); +char * bnet_strerror (BSOCK *bsock); +char * bnet_sig_to_ascii (BSOCK *bsock); +int bnet_wait_data (BSOCK *bsock, int sec); /* cram-md5.c */ int cram_md5_get_auth(BSOCK *bs, char *password); int cram_md5_auth(BSOCK *bs, char *password); void hmac_md5(uint8_t* text, int text_len, uint8_t* key, - int key_len, uint8_t *hmac); + int key_len, uint8_t *hmac); /* create_file.c */ int create_file(void *jcr, char *fname, char *ofile, char *lname, - int type, struct stat *statp, int *ofd); + int type, struct stat *statp, int *ofd); int set_statp(void *jcr, char *fname, char *ofile, char *lname, int type, - struct stat *statp); + struct stat *statp); /* crc32.c */ uint32_t bcrc32(uint8_t *buf, int len); /* daemon.c */ -void daemon_start __PROTO(()); +void daemon_start (); /* lex.c */ -LEX * lex_close_file __PROTO((LEX *lf)); -LEX * lex_open_file __PROTO((LEX *lf, char *fname)); -int lex_get_char __PROTO((LEX *lf)); -void lex_unget_char __PROTO((LEX *lf)); -char * lex_tok_to_str __PROTO((int token)); -int lex_get_token __PROTO((LEX *lf)); +LEX * lex_close_file (LEX *lf); +LEX * lex_open_file (LEX *lf, char *fname); +int lex_get_char (LEX *lf); +void lex_unget_char (LEX *lf); +char * lex_tok_to_str (int token); +int lex_get_token (LEX *lf); /* makepath.c */ int make_path( - void *jcr, - const char *argpath, - int mode, - int parent_mode, - uid_t owner, - gid_t group, - int preserve_existing, - char *verbose_fmt_string); + void *jcr, + const char *argpath, + int mode, + int parent_mode, + uid_t owner, + gid_t group, + int preserve_existing, + char *verbose_fmt_string); /* message.c */ -void my_name_is __PROTO((int argc, char *argv[], char *name)); -void init_msg __PROTO((void *jcr, MSGS *msg)); -void term_msg __PROTO((void)); -void close_msg __PROTO((void *jcr)); -void add_msg_dest __PROTO((MSGS *msg, int dest, int type, char *where, char *dest_code)); -void rem_msg_dest __PROTO((MSGS *msg, int dest, int type, char *where)); -void Jmsg (void *jcr, int type, int level, char *fmt, ...); -void dispatch_message __PROTO((void *jcr, int type, int level, char *buf)); -void init_console_msg __PROTO((char *wd)); -void free_msgs_res(MSGS *msgs); +void my_name_is (int argc, char *argv[], char *name); +void init_msg (void *jcr, MSGS *msg); +void term_msg (void); +void close_msg (void *jcr); +void add_msg_dest (MSGS *msg, int dest, int type, char *where, char *dest_code); +void rem_msg_dest (MSGS *msg, int dest, int type, char *where); +void Jmsg (void *jcr, int type, int level, char *fmt, ...); +void dispatch_message (void *jcr, int type, int level, char *buf); +void init_console_msg (char *wd); +void free_msgs_res (MSGS *msgs); /* bnet_server.c */ -void bnet_thread_server(int port, int max_clients, workq_t *client_wq, - void handle_client_request(void *bsock)); -void bnet_server __PROTO((int port, void handle_client_request(BSOCK *bsock))); -int net_connect __PROTO((int port)); -BSOCK * bnet_bind __PROTO((int port)); -BSOCK * bnet_accept __PROTO((BSOCK *bsock, char *who)); +void bnet_thread_server(int port, int max_clients, workq_t *client_wq, + void handle_client_request(void *bsock)); +void bnet_server (int port, void handle_client_request(BSOCK *bsock)); +int net_connect (int port); +BSOCK * bnet_bind (int port); +BSOCK * bnet_accept (BSOCK *bsock, char *who); /* signal.c */ -void init_signals __PROTO((void terminate(int sig))); -void init_stack_dump (void); +void init_signals (void terminate(int sig)); +void init_stack_dump (void); /* util.c */ -void lcase __PROTO((char *str)); -void bash_spaces __PROTO((char *str)); -void unbash_spaces __PROTO((char *str)); -void strip_trailing_junk __PROTO((char *str)); -void strip_trailing_slashes __PROTO((char *dir)); -int skip_spaces __PROTO((char **msg)); -int skip_nonspaces __PROTO((char **msg)); -int fstrsch __PROTO((char *a, char *b)); -char * encode_time __PROTO((time_t time, char *buf)); -char * encode_mode __PROTO((mode_t mode, char *buf)); -char * edit_uint64_with_commas __PROTO((uint64_t val, char *buf)); -char * add_commas __PROTO((char *val, char *buf)); -char * edit_uint64 (uint64_t val, char *buf); -int do_shell_expansion (char *name); -int is_a_number (const char *num); -int string_to_btime(char *str, btime_t *value); -char *edit_btime(btime_t val, char *buf); +void lcase (char *str); +void bash_spaces (char *str); +void unbash_spaces (char *str); +void strip_trailing_junk (char *str); +void strip_trailing_slashes (char *dir); +int skip_spaces (char **msg); +int skip_nonspaces (char **msg); +int fstrsch (char *a, char *b); +char * encode_time (time_t time, char *buf); +char * encode_mode (mode_t mode, char *buf); +char * edit_uint64_with_commas (uint64_t val, char *buf); +char * add_commas (char *val, char *buf); +char * edit_uint64 (uint64_t val, char *buf); +int do_shell_expansion (char *name); +int is_a_number (const char *num); +int string_to_btime (char *str, btime_t *value); +char *edit_btime (btime_t val, char *buf); /* - *void print_ls_output __PROTO((char *fname, char *lname, int type, struct stat *statp)); + *void print_ls_output (char *fname, char *lname, int type, struct stat *statp); */ /* watchdog.c */ diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index d0f13a4b7a..698c9e18aa 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -37,7 +37,7 @@ static char Update_media[] = "CatReq Job=%s UpdateMedia VolName=%s\ VolJobs=%d VolFiles=%d VolBlocks=%d VolBytes=%" lld " VolMounts=%d\ VolErrors=%d VolWrites=%d VolMaxBytes=%" lld " EndTime=%d VolStatus=%s\ FirstIndex=%d LastIndex=%d StartFile=%d EndFile=%d \ - StartBlock=%d EndBlock=%d\n"; + StartBlock=%d EndBlock=%d relabel=%d\n"; static char FileAttributes[] = "UpdCat Job=%s FileAttributes "; @@ -138,13 +138,13 @@ int dir_find_next_appendable_volume(JCR *jcr) * After writing a Volume, send the updated statistics * back to the director. */ -int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol) +int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel) { BSOCK *dir = jcr->dir_bsock; time_t EndTime = time(NULL); if (vol->VolCatName[0] == 0) { - Emsg0(M_ERROR, 0, "NULL Volume name. This shouldn't happen!!!\n"); + Jmsg0(jcr, M_ERROR, 0, _("NULL Volume name. This shouldn't happen!!!\n")); } bnet_fsend(dir, Update_media, jcr->Job, vol->VolCatName, vol->VolCatJobs, vol->VolCatFiles, @@ -154,7 +154,8 @@ int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol) vol->VolCatStatus, jcr->VolFirstFile, jcr->JobFiles, jcr->start_file, jcr->end_file, - jcr->start_block, jcr->end_block); + jcr->start_block, jcr->end_block, + relabel); Dmsg1(20, "update_volume_data(): %s", dir->msg); if (bnet_recv(dir) <= 0) { Dmsg0(90, "updateVolCatInfo error bnet_recv\n"); @@ -163,8 +164,7 @@ int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol) Dmsg1(20, "Updatevol: %s", dir->msg); if (strcmp(dir->msg, OK_update) != 0) { Dmsg1(30, "Bad response from Dir: %s\n", dir->msg); - Jmsg(jcr, M_ERROR, 0, "Error updating Volume Info: %s\n", - dir->msg); + Jmsg(jcr, M_ERROR, 0, _("Error updating Volume Info: %s\n"), dir->msg); return 0; } return 1; @@ -227,7 +227,7 @@ int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev) wait_sec = min_wait; for ( ;; ) { if (job_cancelled(jcr)) { - Mmsg(&dev->errmsg, "Job %s cancelled while waiting for mount on Storage Device \"%s\".\n", + Mmsg(&dev->errmsg, _("Job %s cancelled while waiting for mount on Storage Device \"%s\".\n"), jcr->Job, jcr->dev_name); return 0; } @@ -248,16 +248,16 @@ int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev) } else { msg = "Please mount"; } - Jmsg(jcr, M_MOUNT, 0, "%s Volume \"%s\" on Storage Device \"%s\" for Job %s\n", + Jmsg(jcr, M_MOUNT, 0, _("%s Volume \"%s\" on Storage Device \"%s\" for Job %s\n"), msg, jcr->VolumeName, jcr->dev_name, jcr->Job); Dmsg3(90, "Mount %s on %s for Job %s\n", jcr->VolumeName, jcr->dev_name, jcr->Job); } else { jstat = JS_WaitMedia; - Jmsg(jcr, M_MOUNT, 0, "Job %s waiting. Cannot find any appendable volumes.\n\ + Jmsg(jcr, M_MOUNT, 0, _("Job %s waiting. Cannot find any appendable volumes.\n\ Please use the \"unmount\" and \"label\" commands to create new Volumes for:\n\ Storage Device \"%s\" with Pool \"%s\" and Media type \"%s\".\n\ -Use \"mount\" to resume the job.\n", +Use \"mount\" to resume the job.\n"), jcr->Job, jcr->dev_name, jcr->pool_name, jcr->media_type); } /* @@ -298,7 +298,7 @@ Use \"mount\" to resume the job.\n", } num_wait++; if (num_wait >= max_num_wait) { - Mmsg(&dev->errmsg, "Gave up waiting to mount Storage Device \"%s\" for Job %s\n", + Mmsg(&dev->errmsg, _("Gave up waiting to mount Storage Device \"%s\" for Job %s\n"), jcr->dev_name, jcr->Job); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); Dmsg1(90, "Gave up waiting on device %s\n", dev->dev_name); @@ -307,13 +307,13 @@ Use \"mount\" to resume the job.\n", continue; } if (stat == EINVAL) { - Mmsg2(&dev->errmsg, "pthread error in mount_next_volume stat=%d ERR=%s\n", + Mmsg2(&dev->errmsg, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat, strerror(stat)); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); return 0; } if (stat != 0) { - Jmsg(jcr, M_ERROR, 0, "pthread error in mount_next_volume stat=%d ERR=%s\n", stat, + Jmsg(jcr, M_ERROR, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat, strerror(stat)); } Dmsg1(90, "Someone woke me for device %s\n", dev->dev_name); @@ -324,9 +324,9 @@ Use \"mount\" to resume the job.\n", /* If no VolumeName, and cannot get one, try again */ if (jcr->VolumeName[0] == 0 && !dir_find_next_appendable_volume(jcr)) { - Jmsg(jcr, M_MOUNT, 0, + Jmsg(jcr, M_MOUNT, 0, _( "You woke me up, but I cannot find any appendable\n\ -volumes for Job=%s.\n", jcr->Job); +volumes for Job=%s.\n"), jcr->Job); continue; } break; @@ -365,19 +365,19 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) Dmsg0(30, "enter dir_ask_sysop_to_mount_next_volume\n"); if (!jcr->VolumeName[0]) { - Mmsg0(&dev->errmsg, "Cannot request another volume: no volume name given.\n"); + Mmsg0(&dev->errmsg, _("Cannot request another volume: no volume name given.\n")); return 0; } ASSERT(dev->dev_blocked); wait_sec = min_wait; for ( ;; ) { if (job_cancelled(jcr)) { - Mmsg(&dev->errmsg, "Job %s cancelled while waiting for mount on Storage Device \"%s\".\n", + Mmsg(&dev->errmsg, _("Job %s cancelled while waiting for mount on Storage Device \"%s\".\n"), jcr->Job, jcr->dev_name); return 0; } - msg = "Please mount"; - Jmsg(jcr, M_MOUNT, 0, "%s Volume \"%s\" on Storage Device \"%s\" for Job %s\n", + msg = _("Please mount"); + Jmsg(jcr, M_MOUNT, 0, _("%s Volume \"%s\" on Storage Device \"%s\" for Job %s\n"), msg, jcr->VolumeName, jcr->dev_name, jcr->Job); Dmsg3(90, "Mount %s on %s for Job %s\n", jcr->VolumeName, jcr->dev_name, jcr->Job); @@ -420,7 +420,7 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) } num_wait++; if (num_wait >= max_num_wait) { - Mmsg(&dev->errmsg, "Gave up waiting to mount Storage Device \"%s\" for Job %s\n", + Mmsg(&dev->errmsg, _("Gave up waiting to mount Storage Device \"%s\" for Job %s\n"), jcr->dev_name, jcr->Job); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); Dmsg1(90, "Gave up waiting on device %s\n", dev->dev_name); @@ -429,13 +429,13 @@ int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev) continue; } if (stat == EINVAL) { - Mmsg2(&dev->errmsg, "pthread error in mount_volume stat=%d ERR=%s\n", + Mmsg2(&dev->errmsg, _("pthread error in mount_volume stat=%d ERR=%s\n"), stat, strerror(stat)); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); return 0; } if (stat != 0) { - Jmsg(jcr, M_ERROR, 0, "pthread error in mount_next_volume stat=%d ERR=%s\n", stat, + Jmsg(jcr, M_ERROR, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat, strerror(stat)); } Dmsg1(90, "Someone woke me for device %s\n", dev->dev_name); diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 40da3c4006..963fdd95aa 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -144,9 +144,9 @@ static void do_extract(char *devname, char *where) long total = 0; DEV_RECORD rec; DEV_BLOCK *block; - char *fname; /* original file name */ - char *ofile; /* output name with prefix */ - char *lname; /* link name */ + POOLMEM *fname; /* original file name */ + POOLMEM *ofile; /* output name with prefix */ + POOLMEM *lname; /* link name */ int wherelen; /* prefix length */ if (strncmp(devname, "/dev/", 5) != 0) { @@ -176,9 +176,9 @@ static void do_extract(char *devname, char *where) } wherelen = strlen(where); - fname = (char *)get_pool_memory(PM_FNAME); - ofile = (char *)get_pool_memory(PM_FNAME); - lname = (char *)get_pool_memory(PM_FNAME); + fname = get_pool_memory(PM_FNAME); + ofile = get_pool_memory(PM_FNAME); + lname = get_pool_memory(PM_FNAME); block = new_block(dev); @@ -189,7 +189,7 @@ static void do_extract(char *devname, char *where) } memset(&rec, 0, sizeof(rec)); - rec.data = (char *) get_memory(70000); + rec.data = get_memory(70000); for ( ;; ) { @@ -276,13 +276,13 @@ static void do_extract(char *devname, char *where) } if (sizeof_pool_memory(fname) < rec.data_len) { - fname = (char *) realloc_pool_memory(fname, rec.data_len + 1); + fname = realloc_pool_memory(fname, rec.data_len + 1); } if (sizeof_pool_memory(ofile) < sizeof_pool_memory(fname) + wherelen + 1) { - ofile = (char *)realloc_pool_memory(ofile, sizeof_pool_memory(fname) + wherelen + 1); + ofile = realloc_pool_memory(ofile, sizeof_pool_memory(fname) + wherelen + 1); } if (sizeof_pool_memory(lname) < rec.data_len) { - ofile = (char *)realloc_pool_memory(ofile, rec.data_len + 1); + ofile = realloc_pool_memory(ofile, rec.data_len + 1); } *fname = 0; *lname = 0; diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index f36d742159..c0a218a244 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -90,7 +90,7 @@ void dump_block(DEV_BLOCK *b, char *msg) */ DEV_BLOCK *new_block(DEVICE *dev) { - DEV_BLOCK *block = (DEV_BLOCK *) get_memory(sizeof(DEV_BLOCK)); + DEV_BLOCK *block = (DEV_BLOCK *)get_memory(sizeof(DEV_BLOCK)); memset(block, 0, sizeof(DEV_BLOCK)); @@ -106,7 +106,7 @@ DEV_BLOCK *new_block(DEVICE *dev) block->buf_len = ((block->buf_len + TAPE_BSIZE - 1) / TAPE_BSIZE) * TAPE_BSIZE; } block->block_len = block->buf_len; /* default block size */ - block->buf = (char *) get_memory(block->buf_len); + block->buf = get_memory(block->buf_len); if (block->buf == NULL) { Mmsg0(&dev->errmsg, _("Unable to malloc block buffer.\n")); Emsg0(M_FATAL, 0, dev->errmsg); diff --git a/bacula/src/stored/block.h b/bacula/src/stored/block.h index b1b51e77a6..b6b620689f 100644 --- a/bacula/src/stored/block.h +++ b/bacula/src/stored/block.h @@ -30,14 +30,14 @@ #ifndef __BLOCK_H #define __BLOCK_H 1 -#define MAX_BLOCK_LENGTH 500001 /* this is a sort of sanity check */ -#define DEFAULT_BLOCK_SIZE (512 * 126) /* 64,512 N.B. do not use 65,636 here */ +#define MAX_BLOCK_LENGTH 500001 /* this is a sort of sanity check */ +#define DEFAULT_BLOCK_SIZE (512 * 126) /* 64,512 N.B. do not use 65,636 here */ /* Block Header definitions. */ #define BLKHDR_ID "BB01" #define BLKHDR_ID_LENGTH 4 -#define BLKHDR_CS_LENGTH 4 /* checksum length */ -#define BLKHDR_LENGTH 16 /* Total length */ +#define BLKHDR_CS_LENGTH 4 /* checksum length */ +#define BLKHDR_LENGTH 16 /* Total length */ /* * This is the Media structure for a block header @@ -60,21 +60,21 @@ typedef struct s_block_hdr { * This is the memory structure for a device block. */ typedef struct s_dev_block { - struct s_dev_block *next; /* pointer to next one */ + struct s_dev_block *next; /* pointer to next one */ /* binbuf is the number of bytes remaining * in the buffer. For writes, it is bytes not yet written. * For reads, it is remaining bytes not yet read. */ - uint32_t binbuf; /* bytes in buffer */ - uint32_t block_len; /* length of current block read */ - uint32_t buf_len; /* max/default block length */ - uint32_t BlockNumber; /* sequential block number */ - uint32_t read_len; /* bytes read into buffer */ - int failed_write; /* set if write failed */ - char *bufp; /* pointer into buffer */ - char *buf; /* actual data buffer. This is a - * Pool buffer! - */ + uint32_t binbuf; /* bytes in buffer */ + uint32_t block_len; /* length of current block read */ + uint32_t buf_len; /* max/default block length */ + uint32_t BlockNumber; /* sequential block number */ + uint32_t read_len; /* bytes read into buffer */ + int failed_write; /* set if write failed */ + char *bufp; /* pointer into buffer */ + POOLMEM *buf; /* actual data buffer. This is a + * Pool buffer! + */ } DEV_BLOCK; #endif diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 32cd48dec7..d4e4380ad7 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -146,17 +146,17 @@ init_dev(DEVICE *dev, char *dev_name) if ((errstat = pthread_mutex_init(&dev->mutex, NULL)) != 0) { dev->dev_errno = errstat; - Mmsg1(&dev->errmsg, "Unable to init mutex: ERR=%s\n", strerror(errstat)); + Mmsg1(&dev->errmsg, _("Unable to init mutex: ERR=%s\n"), strerror(errstat)); Emsg0(M_FATAL, 0, dev->errmsg); } if ((errstat = pthread_cond_init(&dev->wait, NULL)) != 0) { dev->dev_errno = errstat; - Mmsg1(&dev->errmsg, "Unable to init cond variable: ERR=%s\n", strerror(errstat)); + Mmsg1(&dev->errmsg, _("Unable to init cond variable: ERR=%s\n"), strerror(errstat)); Emsg0(M_FATAL, 0, dev->errmsg); } if ((errstat = pthread_cond_init(&dev->wait_next_vol, NULL)) != 0) { dev->dev_errno = errstat; - Mmsg1(&dev->errmsg, "Unable to init cond variable: ERR=%s\n", strerror(errstat)); + Mmsg1(&dev->errmsg, _("Unable to init cond variable: ERR=%s\n"), strerror(errstat)); Emsg0(M_FATAL, 0, dev->errmsg); } dev->fd = -1; @@ -189,7 +189,7 @@ open_dev(DEVICE *dev, char *VolName, int mode) return -1; } dev->use_count++; - Mmsg2(&dev->errmsg, "WARNING!!!! device %s opened %d times!!!\n", + Mmsg2(&dev->errmsg, _("WARNING!!!! device %s opened %d times!!!\n"), dev->dev_name, dev->use_count); Emsg0(M_WARNING, 0, dev->errmsg); return dev->fd; @@ -210,7 +210,7 @@ open_dev(DEVICE *dev, char *VolName, int mode) } if ((dev->fd = open(dev->dev_name, dev->mode, MODE_RW)) < 0) { dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "stored: unable to open device %s: ERR=%s\n", + Mmsg2(&dev->errmsg, _("stored: unable to open device %s: ERR=%s\n"), dev->dev_name, strerror(dev->dev_errno)); Emsg0(M_FATAL, 0, dev->errmsg); } else { @@ -235,7 +235,7 @@ open_dev(DEVICE *dev, char *VolName, int mode) } if ((dev->fd = open(archive_name, dev->mode, MODE_RW)) < 0) { dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "Could not open: %s, ERR=%s\n", archive_name, strerror(dev->dev_errno)); + Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name, strerror(dev->dev_errno)); Emsg0(M_FATAL, 0, dev->errmsg); } else { dev->dev_errno = 0; @@ -262,7 +262,7 @@ int rewind_dev(DEVICE *dev) Dmsg0(29, "rewind_dev\n"); if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg1(&dev->errmsg, "Bad call to rewind_dev. Device %s not open\n", + Mmsg1(&dev->errmsg, _("Bad call to rewind_dev. Device %s not open\n"), dev->dev_name); Emsg0(M_ABORT, 0, dev->errmsg); return 0; @@ -287,7 +287,7 @@ int rewind_dev(DEVICE *dev) sleep(5); continue; } - Mmsg2(&dev->errmsg, "Rewind error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("Rewind error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; } @@ -296,7 +296,7 @@ int rewind_dev(DEVICE *dev) } else { if (lseek(dev->fd, 0, SEEK_SET) < 0) { dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "lseek error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; } @@ -339,13 +339,13 @@ eod_dev(DEVICE *dev) Dmsg1(50, "ioctl error: %s\n", strerror(dev->dev_errno)); clrerror_dev(dev, mt_com.mt_op); update_pos_dev(dev); - Mmsg2(&dev->errmsg, "ioctl MTEOM error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTEOM error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; } if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) { dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "ioctl MTIOCGET error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; } @@ -387,7 +387,7 @@ int update_pos_dev(DEVICE *dev) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad device call. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad device call. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return 0; } @@ -400,7 +400,7 @@ int update_pos_dev(DEVICE *dev) Dmsg1(200, "Seek error: ERR=%s\n", strerror(dev->dev_errno)); pos = 0; dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "lseek error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); } else { stat = 1; @@ -412,7 +412,7 @@ int update_pos_dev(DEVICE *dev) if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) { Dmsg1(50, "MTIOCGET error: %s\n", strerror(dev->dev_errno)); dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "ioctl MTIOCGET error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); } else { stat = 1; @@ -453,7 +453,7 @@ status_dev(DEVICE *dev, uint32_t *status) Dmsg2(-20," file=%d block=%d\n", dev->file, dev->block_num); if (ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) < 0) { dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "ioctl MTIOCGET error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; } @@ -519,7 +519,7 @@ int load_dev(DEVICE *dev) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to load_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to load_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return 0; } @@ -529,7 +529,7 @@ int load_dev(DEVICE *dev) #ifndef MTLOAD Dmsg0(200, "stored: MTLOAD command not available\n"); dev->dev_errno = ENOTTY; /* function not available */ - Mmsg2(&dev->errmsg, "ioctl MTLOAD error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; return 0; #else @@ -539,7 +539,7 @@ int load_dev(DEVICE *dev) mt_com.mt_count = 1; if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "ioctl MTLOAD error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; } return 1; @@ -557,7 +557,7 @@ int offline_dev(DEVICE *dev) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to load_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to load_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return 0; } @@ -570,7 +570,7 @@ int offline_dev(DEVICE *dev) mt_com.mt_count = 1; if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { dev->dev_errno = errno; - Mmsg2(&dev->errmsg, "ioctl MTOFFL error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); return 0; } @@ -590,7 +590,7 @@ fsf_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return -1; } @@ -600,7 +600,7 @@ fsf_dev(DEVICE *dev, int num) } if (dev->state & ST_EOT) { dev->dev_errno = 0; - Mmsg1(&dev->errmsg, "Device %s at End of Tape.\n", dev->dev_name); + Mmsg1(&dev->errmsg, _("Device %s at End of Tape.\n"), dev->dev_name); return -1; } if (dev->state & ST_EOF) @@ -623,7 +623,7 @@ fsf_dev(DEVICE *dev, int num) dev->state |= ST_EOT; clrerror_dev(dev, -1); Dmsg1(200, "Set ST_EOT read error %d\n", dev->dev_errno); - Mmsg2(&dev->errmsg, "read error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("read error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); Dmsg1(200, "%s", dev->errmsg); break; @@ -652,7 +652,7 @@ fsf_dev(DEVICE *dev, int num) dev->state |= ST_EOT; Dmsg0(200, "Set ST_EOT\n"); clrerror_dev(dev, MTFSF); - Mmsg2(&dev->errmsg, "ioctl MTFSF error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); Dmsg0(200, "Got < 0 for MT_FSF\n"); Dmsg1(200, "%s", dev->errmsg); @@ -672,7 +672,7 @@ fsf_dev(DEVICE *dev, int num) } if (dev->state & ST_EOT) { dev->dev_errno = 0; - Mmsg1(&dev->errmsg, "Device %s at End of Tape.\n", dev->dev_name); + Mmsg1(&dev->errmsg, _("Device %s at End of Tape.\n"), dev->dev_name); stat = -1; } else { stat = 0; @@ -699,7 +699,7 @@ bsf_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return -1; } @@ -715,7 +715,7 @@ bsf_dev(DEVICE *dev, int num) stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { clrerror_dev(dev, MTBSF); - Mmsg2(&dev->errmsg, "ioctl MTBSF error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTBSF error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); } update_pos_dev(dev); @@ -734,7 +734,7 @@ fsr_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return -1; } @@ -757,7 +757,7 @@ fsr_dev(DEVICE *dev, int num) dev->file++; } clrerror_dev(dev, MTFSR); - Mmsg2(&dev->errmsg, "ioctl MTFSR error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTFSR error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); } update_pos_dev(dev); @@ -775,7 +775,7 @@ bsr_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return -1; } @@ -791,7 +791,7 @@ bsr_dev(DEVICE *dev, int num) stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com); if (stat < 0) { clrerror_dev(dev, MTBSR); - Mmsg2(&dev->errmsg, "ioctl MTBSR error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTBSR error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); } update_pos_dev(dev); @@ -811,7 +811,7 @@ weof_dev(DEVICE *dev, int num) if (dev->fd < 0) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return -1; } @@ -829,7 +829,7 @@ weof_dev(DEVICE *dev, int num) dev->file++; } else { clrerror_dev(dev, MTWEOF); - Mmsg2(&dev->errmsg, "ioctl MTWEOF error on %s. ERR=%s.\n", + Mmsg2(&dev->errmsg, _("ioctl MTWEOF error on %s. ERR=%s.\n"), dev->dev_name, strerror(dev->dev_errno)); } return stat; @@ -900,7 +900,7 @@ clrerror_dev(DEVICE *dev, int func) } if (msg != NULL) { dev->dev_errno = ENOSYS; - Mmsg1(&dev->errmsg, "This device does not support %s.\n", msg); + Mmsg1(&dev->errmsg, _("This device does not support %s.\n"), msg); Emsg0(M_ERROR, 0, dev->errmsg); } } @@ -946,7 +946,7 @@ void close_dev(DEVICE *dev) { if (!dev) { - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return; } @@ -961,7 +961,7 @@ close_dev(DEVICE *dev) void force_close_dev(DEVICE *dev) { if (!dev) { - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return; } @@ -970,6 +970,18 @@ void force_close_dev(DEVICE *dev) dev->use_count--; } +int truncate_dev(DEVICE *dev) +{ + if (dev->state & ST_TAPE) { + return 1; + } + if (ftruncate(dev->fd, 0) != 0) { + Mmsg1(&dev->errmsg, _("Unable to truncate device. ERR=%s\n"), strerror(errno)); + return 0; + } + return 1; +} + int dev_is_tape(DEVICE *dev) { @@ -1008,7 +1020,7 @@ term_dev(DEVICE *dev) { if (!dev) { dev->dev_errno = EBADF; - Mmsg0(&dev->errmsg, "Bad call to fsf_dev. Archive not open\n"); + Mmsg0(&dev->errmsg, _("Bad call to fsf_dev. Archive not open\n")); Emsg0(M_FATAL, 0, dev->errmsg); return; } diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index f463c7a678..90f0979534 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -195,17 +195,17 @@ int release_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) weof_dev(dev, 1); dev->VolCatInfo.VolCatFiles++; /* increment number of files */ /* Note! do volume update before close, which zaps VolCatInfo */ - dir_update_volume_info(jcr, &dev->VolCatInfo); /* send Volume info to Director */ + dir_update_volume_info(jcr, &dev->VolCatInfo, 0); /* send Volume info to Director */ if (!dev_is_tape(dev)) { close_dev(dev); } else { Dmsg0(90, "Device is tape leave open in release_device\n"); } } else { - dir_update_volume_info(jcr, &dev->VolCatInfo); /* send Volume info to Director */ + dir_update_volume_info(jcr, &dev->VolCatInfo, 0); /* send Volume info to Director */ } } else { - Emsg1(M_ERROR, 0, _("BAD ERROR: release_device %s not in use.\n"), dev_name(dev)); + Jmsg1(jcr, M_ERROR, 0, _("BAD ERROR: release_device %s not in use.\n"), dev_name(dev)); } V(dev->mutex); return 1; @@ -408,6 +408,12 @@ mount_next_vol: Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device %s. ERR=%s\n"), dev_name(dev), strerror_dev(dev)); } + if (recycle) { + if (!truncate_dev(dev)) { + Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device %s. ERR=%s\n"), + dev_name(dev), strerror_dev(dev)); + } + } if (!write_block_to_dev(dev, block)) { Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s. ERR=%s\n"), dev_name(dev), strerror_dev(dev)); @@ -434,7 +440,7 @@ mount_next_vol: dev->VolCatInfo.VolCatReads = 1; } strcpy(dev->VolCatInfo.VolCatStatus, "Append"); - dir_update_volume_info(jcr, &dev->VolCatInfo); + dir_update_volume_info(jcr, &dev->VolCatInfo, 1); /* indicate doing relabel */ if (recycle) { Jmsg(jcr, M_INFO, 0, _("Recycled volume %s on device %s, all previous data lost.\n"), jcr->VolumeName, dev_name(dev)); @@ -456,7 +462,7 @@ mount_next_vol: Jmsg(jcr, M_INFO, 0, _("Marking Volume %s in Error in Catalog.\n"), jcr->VolumeName); strcpy(dev->VolCatInfo.VolCatStatus, "Error"); - dir_update_volume_info(jcr, &dev->VolCatInfo); + dir_update_volume_info(jcr, &dev->VolCatInfo, 0); return 0; } /* *****FIXME**** we might do some checking for files too */ @@ -556,7 +562,7 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) strcpy(dev->VolCatInfo.VolCatStatus, "Full"); Dmsg0(90, "Call update_vol_info\n"); - if (!dir_update_volume_info(jcr, &dev->VolCatInfo)) { /* send Volume info to Director */ + if (!dir_update_volume_info(jcr, &dev->VolCatInfo, 0)) { /* send Volume info to Director */ Jmsg(jcr, M_ERROR, 0, _("Could not update Volume info Volume=%s Job=%s\n"), dev->VolCatInfo.VolCatName, jcr->Job); return 0; /* device locked */ diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 97b66a0c52..1d9a962772 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -129,7 +129,7 @@ void connection_request(void *arg) * Authenticate the Director */ if (!authenticate_director(jcr)) { - Emsg0(M_FATAL, 0, _("Unable to authenticate Director\n")); + Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate Director\n")); free_jcr(jcr); return; } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index f1d85154d5..8be64279fd 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -73,7 +73,14 @@ int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) if (VolName && *VolName && strcmp(dev->VolHdr.VolName, VolName) != 0) { Mmsg(&jcr->errmsg, _("Volume name mismatch on device %s: Wanted %s got %s\n"), dev_name(dev), VolName, dev->VolHdr.VolName); - + /* + * Cancel Job if too many label errors + * => we are in a loop + */ + if (jcr->label_errors > 100) { + jcr->JobStatus = JS_Cancelled; + Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg); + } return jcr->label_status = VOL_NAME_ERROR; } Dmsg0(30, "Leave read_volume_label() VOL_OK\n"); @@ -120,6 +127,14 @@ because:\n %s"), dev_name(dev), strerror_dev(dev)); if (VolName && *VolName && strcmp(dev->VolHdr.VolName, VolName) != 0) { Mmsg(&jcr->errmsg, _("Volume name mismatch. Wanted %s got %s\n"), VolName, dev->VolHdr.VolName); + /* + * Cancel Job if too many label errors + * => we are in a loop + */ + if (jcr->label_errors > 100) { + jcr->JobStatus = JS_Cancelled; + Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg); + } return jcr->label_status = VOL_NAME_ERROR; } Dmsg1(30, "Copy vol_name=%s\n", dev->VolHdr.VolName); @@ -211,7 +226,7 @@ int write_volume_label_to_block(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) Dmsg0(20, "write Label in write_volume_label_to_block()\n"); memset(&rec, 0, sizeof(rec)); - rec.data = (char *) get_memory(SER_LENGTH_Volume_Label); + rec.data = get_memory(SER_LENGTH_Volume_Label); create_volume_label_record(jcr, dev, &rec); diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index e83494a21e..7fffbc952c 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -30,7 +30,7 @@ uint32_t new_VolSessionId(); /* From askdir.c */ int dir_get_volume_info(JCR *jcr); int dir_find_next_appendable_volume(JCR *jcr); -int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol); +int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel); int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev); int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev); int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec); @@ -57,6 +57,7 @@ DEVICE *init_dev(DEVICE *dev, char *device); int open_dev(DEVICE *dev, char *VolName, int mode); void close_dev(DEVICE *dev); void force_close_dev(DEVICE *dev); +int truncate_dev(DEVICE *dev); void term_dev(DEVICE *dev); char * strerror_dev(DEVICE *dev); void clrerror_dev(DEVICE *dev, int func); diff --git a/bacula/src/stored/record.c b/bacula/src/stored/record.c index 382cb54792..3e4dedb2f3 100644 --- a/bacula/src/stored/record.c +++ b/bacula/src/stored/record.c @@ -93,7 +93,7 @@ DEV_RECORD *new_record(void) rec = (DEV_RECORD *) get_memory(sizeof(DEV_RECORD)); memset(rec, 0, sizeof(DEV_RECORD)); - rec->data = (char *) get_pool_memory(PM_MESSAGE); + rec->data = get_pool_memory(PM_MESSAGE); return rec; } @@ -360,7 +360,7 @@ remlen=%d data_len=%d\n", ASSERT(data_bytes < MAX_BLOCK_LENGTH); /* temp sanity check */ - rec->data = (char *) check_pool_memory_size(rec->data, rec->data_len+data_bytes); + rec->data = check_pool_memory_size(rec->data, rec->data_len+data_bytes); /* * At this point, we have read the header, now we diff --git a/bacula/src/stored/record.h b/bacula/src/stored/record.h index 19a195807f..7d070fd3d1 100644 --- a/bacula/src/stored/record.h +++ b/bacula/src/stored/record.h @@ -30,14 +30,14 @@ #define __RECORD_H 1 /* Return codes from read_device_volume_label() */ -#define VOL_NOT_READ 0 /* Volume label not read */ -#define VOL_OK 1 /* volume name OK */ -#define VOL_NO_LABEL 2 /* volume not labeled */ -#define VOL_IO_ERROR 3 /* volume I/O error */ -#define VOL_NAME_ERROR 4 /* Volume name mismatch */ -#define VOL_CREATE_ERROR 5 /* Error creating label */ -#define VOL_VERSION_ERROR 6 /* Bacula version error */ -#define VOL_LABEL_ERROR 7 /* Bad label type */ +#define VOL_NOT_READ 0 /* Volume label not read */ +#define VOL_OK 1 /* volume name OK */ +#define VOL_NO_LABEL 2 /* volume not labeled */ +#define VOL_IO_ERROR 3 /* volume I/O error */ +#define VOL_NAME_ERROR 4 /* Volume name mismatch */ +#define VOL_CREATE_ERROR 5 /* Error creating label */ +#define VOL_VERSION_ERROR 6 /* Bacula version error */ +#define VOL_LABEL_ERROR 7 /* Bad label type */ /* Length of Record Header (5 * 4 bytes) */ @@ -62,17 +62,17 @@ typedef struct s_record_hdr { * This is the memory structure for the record header. */ typedef struct s_dev_rec { - int sync; /* synchronous */ - uint32_t File; /* File number, returned if sync set */ - uint32_t Block; /* Block number, returned if sync set */ - uint32_t VolSessionId; /* sequential id within this session */ - uint32_t VolSessionTime; /* session start time */ - int32_t FileIndex; /* sequential file number */ - int32_t Stream; /* stream number */ - uint32_t data_len; /* current record length */ - uint32_t remainder; /* remaining bytes to read/write */ + int sync; /* synchronous */ + uint32_t File; /* File number, returned if sync set */ + uint32_t Block; /* Block number, returned if sync set */ + uint32_t VolSessionId; /* sequential id within this session */ + uint32_t VolSessionTime; /* session start time */ + int32_t FileIndex; /* sequential file number */ + int32_t Stream; /* stream number */ + uint32_t data_len; /* current record length */ + uint32_t remainder; /* remaining bytes to read/write */ uint8_t ser_buf[RECHDR_LENGTH]; /* serialized record header goes here */ - char *data; /* Record data. This MUST be a memory pool item */ + POOLMEM *data; /* Record data. This MUST be a memory pool item */ } DEV_RECORD; @@ -81,11 +81,11 @@ typedef struct s_dev_rec { * Note, these values are negative to distinguish them * from user records where the FileIndex is forced positive. */ -#define PRE_LABEL -1 /* Vol label on unwritten tape */ -#define VOL_LABEL -2 /* Volume label first file */ -#define EOM_LABEL -3 /* Writen at end of tape */ -#define SOS_LABEL -4 /* Start of Session */ -#define EOS_LABEL -5 /* End of Session */ +#define PRE_LABEL -1 /* Vol label on unwritten tape */ +#define VOL_LABEL -2 /* Volume label first file */ +#define EOM_LABEL -3 /* Writen at end of tape */ +#define SOS_LABEL -4 /* Start of Session */ +#define EOS_LABEL -5 /* End of Session */ /* @@ -97,20 +97,20 @@ struct Volume_Label { * in the DEVICE buffer, but are not actually written * to the tape. */ - int32_t LabelType; /* This is written in header only */ - uint32_t LabelSize; /* length of serialized label */ + int32_t LabelType; /* This is written in header only */ + uint32_t LabelSize; /* length of serialized label */ /* * The items below this line are stored on * the tape */ - char Id[32]; /* Bacula Immortal ... */ + char Id[32]; /* Bacula Immortal ... */ - uint32_t VerNum; /* Label version number */ + uint32_t VerNum; /* Label version number */ - float64_t label_date; /* Date tape labeled */ - float64_t label_time; /* Time tape labeled */ - float64_t write_date; /* Date this label written */ - float64_t write_time; /* Time this label written */ + float64_t label_date; /* Date tape labeled */ + float64_t label_time; /* Time tape labeled */ + float64_t write_date; /* Date this label written */ + float64_t write_time; /* Time this label written */ char VolName[MAX_NAME_LENGTH]; /* Volume name */ char PrevVolName[MAX_NAME_LENGTH]; /* Previous Volume Name */ @@ -119,9 +119,9 @@ struct Volume_Label { char MediaType[MAX_NAME_LENGTH]; /* Type of this media */ char HostName[MAX_NAME_LENGTH]; /* Host name of writing computer */ - char LabelProg[32]; /* Label program name */ - char ProgVersion[32]; /* Program version */ - char ProgDate[32]; /* Program build date/time */ + char LabelProg[32]; /* Label program name */ + char ProgVersion[32]; /* Program version */ + char ProgDate[32]; /* Program build date/time */ }; #define SER_LENGTH_Volume_Label 1024 /* max serialised length of volume label */ @@ -134,15 +134,15 @@ typedef struct Volume_Label VOLUME_LABEL; * This record is at the beginning and end of each session */ struct Session_Label { - char Id[32]; /* Bacula Immortal ... */ + char Id[32]; /* Bacula Immortal ... */ - uint32_t VerNum; /* Label version number */ + uint32_t VerNum; /* Label version number */ - uint32_t JobId; /* Job id */ - uint32_t VolumeIndex; /* Sequence no of volume for this job */ + uint32_t JobId; /* Job id */ + uint32_t VolumeIndex; /* Sequence no of volume for this job */ - float64_t write_date; /* Date this label written */ - float64_t write_time; /* Time this label written */ + float64_t write_date; /* Date this label written */ + float64_t write_time; /* Time this label written */ char PoolName[MAX_NAME_LENGTH]; /* Pool name */ char PoolType[MAX_NAME_LENGTH]; /* Pool type */ @@ -159,6 +159,6 @@ struct Session_Label { }; typedef struct Session_Label SESSION_LABEL; -#define SERIAL_BUFSIZE 1024 /* volume serialisation buffer size */ +#define SERIAL_BUFSIZE 1024 /* volume serialisation buffer size */ #endif diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 43e86213b7..1220202d55 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -342,6 +342,7 @@ void save_resource(int type, struct res_items *items, int pass) return; } + /* The following code is only executed on pass 1 */ switch (type) { case R_DIRECTOR: size = sizeof(DIRRES); diff --git a/bacula/src/version.h b/bacula/src/version.h index 2295a84b89..4ad45a44c0 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.20" #define VSTRING "1" -#define DATE "22 May 2002" -#define LSMDATE "22May02" +#define DATE "25 May 2002" +#define LSMDATE "25May02" /* Debug flags */ #define DEBUG 1 -- 2.39.5