From aa876a774416ae524ac956204d1a9cef82cf5a0d Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 2 Apr 2004 09:26:14 +0000 Subject: [PATCH] Fix btape autochanger handling git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1173 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/ReleaseNotes | 7 ++++-- bacula/kernstodo | 7 +++--- bacula/scripts/mtx-changer.in | 1 + bacula/src/filed/status.c | 3 +-- bacula/src/lib/bpipe.c | 18 ++++++++++++--- bacula/src/lib/signal.c | 2 +- bacula/src/stored/autochanger.c | 4 ++-- bacula/src/stored/btape.c | 40 +++++++++++++++++++++++---------- bacula/src/version.h | 4 ++-- 9 files changed, 59 insertions(+), 27 deletions(-) diff --git a/bacula/ReleaseNotes b/bacula/ReleaseNotes index a644726239..8ee823ec5c 100644 --- a/bacula/ReleaseNotes +++ b/bacula/ReleaseNotes @@ -33,12 +33,16 @@ Items to note: !!!!! at the end of the tape. For most tape drives, this is totally transparent and nothing needs to be done. For FreeBSD see below. - FreeBSD users NOTE!!!!! - You MUST add the following two records to your SD Device resource for + You may need the following two records to your SD Device resource for tape drives. TWOEOF = yes Fast Forward Space File = no + The "Fast Forward Space File" is surely needed, and the TWOEOF + is needed on some systems and not others. Running the btape + "test" command will tell you. + - The daemon protocol has changed, you must update everything at once. - The database level has been updated. You must either re-initialize your databases with: @@ -176,4 +180,3 @@ Additional changes: - Fixed thread race problem in multiple simultaneous jobs to a single Volume where the volume lable is not in the first tape block, so the tape is not recognized. - diff --git a/bacula/kernstodo b/bacula/kernstodo index f9ea23b2a6..4e0a39c934 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -83,6 +83,7 @@ From Chris Hull: For version 1.35: +- Add code to check for tape alerts -- tapeinfo. - Make sure list of Volumes needed is in correct order for restore. See havana. - Remove paths (and files that reference them) that have no trailing slash @@ -114,8 +115,9 @@ For version 1.35: name last backed up, the completefile is dumped.On Windows systems, with creation date of files, we can be evensmarter about this and not count entirely upon the length.On a restore, the full and all incrementals - since it will beapplied in sequence to restore the file. - Add a - regression test for dbcheck. - Add disk seeking on restore. - Allow + since it will beapplied in sequence to restore the file. +- Add a regression test for dbcheck. +- Add disk seeking on restore. - Allow for optional cancelling of SD and FD in case DIR gets a fatal error. Requested by Jesse Guardiani - Bizarre message: Error: Could not open WriteBootstrap file: @@ -140,7 +142,6 @@ For version 1.35: The dates you will find in your restore log seem to be the original creation dates - Volume "add"ed to Pool gets recycled in first use. VolBytes=0 -- Get rid of 0 dates in LastWritten, ... - If a tape is recycled while it is mounted, Stanislav Tvrudy must do an additional mount to deblock the job. - From Johan Decock: diff --git a/bacula/scripts/mtx-changer.in b/bacula/scripts/mtx-changer.in index eaa0eefd6f..c5d202cc34 100644 --- a/bacula/scripts/mtx-changer.in +++ b/bacula/scripts/mtx-changer.in @@ -10,6 +10,7 @@ # you will have the following input to this script: # # mtx-changer "changer-device" "command" "slot" "archive-device" "drive-index" +# $1 $2 $3 $4 $5 # # for example: # diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 5565deeebc..b3077d05c2 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -222,7 +222,7 @@ static void list_terminated_jobs(void sendit(const char *msg, int len, void *sa dt, JobName); sendit(buf, strlen(buf), arg); } - sendit("\n", 1, arg); + sendit("====\n", 1, arg); unlock_last_jobs_list(); } @@ -249,7 +249,6 @@ int status_cmd(JCR *jcr) bnet_fsend(user, "\n"); do_status(bsock_sendit, (void *)user); - bnet_fsend(user, "====\n"); bnet_sig(user, BNET_EOD); return 1; diff --git a/bacula/src/lib/bpipe.c b/bacula/src/lib/bpipe.c index cc176f031c..50d81e596e 100644 --- a/bacula/src/lib/bpipe.c +++ b/bacula/src/lib/bpipe.c @@ -191,7 +191,7 @@ int close_bpipe(BPIPE *bpipe) if (stat != 0) { stat = ECHILD; } - Dmsg1(200, "status =%d\n", stat); + Dmsg1(200, "child status=%d\n", stat); } else if (WIFSIGNALED(chldstatus)) { /* process died */ stat = ECHILD; Dmsg0(200, "Signaled\n"); @@ -229,12 +229,24 @@ int run_program(char *prog, int wait, POOLMEM *results) } if (results) { mp_chr(results)[0] = 0; - stat1 = fgets(mp_chr(results), sizeof_pool_memory(results), bpipe->rfd) == NULL; + fgets(mp_chr(results), sizeof_pool_memory(results), bpipe->rfd); + if (feof(bpipe->rfd)) { + stat1 = 0; + } else { + stat1 = ferror(bpipe->rfd); + } + if (stat1 < 0) { + Dmsg2(100, "Run program fgets stat=%d ERR=%s\n", stat1, strerror(errno)); + } else if (stat1 != 0) { + Dmsg1(100, "Run program fgets stat=%d\n", stat1); + } } else { stat1 = 0; } stat2 = close_bpipe(bpipe); - return stat2 != 0 ? stat2 : stat1; + stat1 = stat2 != 0 ? stat2 : stat1; + Dmsg1(100, "Run program returning %d\n", stat1); + return stat1; } diff --git a/bacula/src/lib/signal.c b/bacula/src/lib/signal.c index 82027beca4..48e65c8d47 100644 --- a/bacula/src/lib/signal.c +++ b/bacula/src/lib/signal.c @@ -70,7 +70,7 @@ static void signal_handler(int sig) if (already_dead) { exit(1); } - Dmsg1(200, "sig=%d\n", sig); + Dmsg2(200, "sig=%d %s\n", sig, sig_names[sig]); /* Ignore certain signals */ if (sig == SIGCHLD || sig == SIGUSR2) { return; diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 72237ad63a..5eb229500e 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -30,7 +30,7 @@ #include "stored.h" /* pull in Storage Deamon headers */ /* Forward referenced functions */ -static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd); +char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd); static int get_autochanger_loaded_slot(JCR *jcr); @@ -258,7 +258,7 @@ bail_out: * cmd = command string (load, unload, ...) * */ -static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd) +char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd) { char *p; const char *str; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 8c815cc8e5..dd6546324a 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -39,6 +39,7 @@ /* External subroutines */ extern void free_config_resources(); +extern char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd); /* Exported variables */ int quit = 0; @@ -82,7 +83,6 @@ static void set_volume_name(char *VolName, int volnum); static void rawfill_cmd(); static void bfill_cmd(); static bool open_the_device(); -static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd); static void autochangercmd(); static void do_unfill(); @@ -1037,9 +1037,10 @@ static int autochanger_test() { POOLMEM *results, *changer; int slot, status, loaded; - int timeout = 120; + int timeout = jcr->device->max_changer_wait; int sleep_time = 0; + Dmsg1(100, "Max changer wait = %d sec\n", timeout); if (!dev_cap(dev, CAP_AUTOCHANGER)) { return 1; } @@ -1075,38 +1076,51 @@ try_again: if (status == 0) { loaded = atoi(results); } else { - Pmsg1(-1, _("3991 Bad autochanger \"load slot\" status=%d.\n"), status); - loaded = -1; /* force unload */ + Pmsg1(-1, _("3991 Bad autochanger command: %s\n"), changer); + Pmsg2(-1, _("3991 status=%d result=%s\n"), status, results); goto bail_out; } if (loaded) { Pmsg1(-1, "Slot %d loaded. I am going to unload it.\n", loaded); } else { - Pmsg0(-1, "Nothing loaded into the drive. OK.\n"); + Pmsg0(-1, "Nothing loaded in the drive. OK.\n"); } Dmsg1(100, "Results from loaded query=%s\n", results); if (loaded) { + jcr->VolCatInfo.Slot = loaded; offline_or_rewind_dev(dev); /* We are going to load a new tape, so close the device */ force_close_dev(dev); - Pmsg0(-1, _("3302 Issuing autochanger \"unload\" command.\n")); + Pmsg2(-1, _("3302 Issuing autochanger \"unload %d %d\" command.\n"), + loaded, dev->drive_index); changer = edit_device_codes(jcr, changer, jcr->device->changer_command, "unload"); - status = run_program(changer, timeout, NULL); + status = run_program(changer, timeout, results); Pmsg2(-1, "unload status=%s %d\n", status==0?"OK":"Bad", status); + if (status != 0) { + Pmsg1(-1, _("3992 Bad autochanger command: %s\n"), changer); + Pmsg2(-1, _("3992 status=%d result=%s\n"), status, results); + } } /* * Load the Slot 1 */ - Pmsg1(-1, _("3303 Issuing autochanger \"load slot %d\" command.\n"), slot); + + slot = 1; + jcr->VolCatInfo.Slot = slot; + Pmsg2(-1, _("3303 Issuing autochanger \"load slot %d %d\" command.\n"), + slot, dev->drive_index); changer = edit_device_codes(jcr, changer, jcr->device->changer_command, "load"); - Dmsg1(200, "Changer=%s\n", changer); - status = run_program(changer, timeout, NULL); + Dmsg1(100, "Changer=%s\n", changer); + force_close_dev(dev); + status = run_program(changer, timeout, results); if (status == 0) { - Pmsg1(-1, _("3304 Autochanger \"load slot %d\" status is OK.\n"), slot); + Pmsg2(-1, _("3303 Autochanger \"load slot %d %d\" status is OK.\n"), + slot, dev->drive_index); } else { - Pmsg1(-1, _("3992 Bad autochanger \"load slot\" status=%d.\n"), status); + Pmsg1(-1, _("3993 Bad autochanger command: %s\n"), changer); + Pmsg2(-1, _("3993 status=%d result=%s\n"), status, results); goto bail_out; } @@ -2624,6 +2638,7 @@ static void set_volume_name(char *VolName, int volnum) dcr->VolCatInfo.Slot = volnum; } +#ifdef xxx /* * Edit codes into ChangerCommand * %% = % @@ -2701,6 +2716,7 @@ static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd) } return omsg; } +#endif #ifdef xxxx_needed /* diff --git a/bacula/src/version.h b/bacula/src/version.h index cbf2da5184..604d5452d0 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.33.6" #define VSTRING "1" -#define BDATE "01 Apr 2004" -#define LSMDATE "01Apr04" +#define BDATE "02 Apr 2004" +#define LSMDATE "02Apr04" /* Debug flags */ #undef DEBUG -- 2.39.5