From 7e9687dbe5989935551969a9a863bc4cd4e71a17 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 29 Dec 2003 11:57:37 +0000 Subject: [PATCH] Fix watchdog crash in btape+detect more Device config problems in btape test + fix infinite loops in fsf due to bad config + correct for system dependences in backspace at EOM git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@964 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/sql_cmds.c | 4 ++-- bacula/src/lib/watchdog.c | 6 +++--- bacula/src/stored/btape.c | 15 ++++++++++++++- bacula/src/stored/dev.c | 15 +++++++++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/bacula/src/dird/sql_cmds.c b/bacula/src/dird/sql_cmds.c index d02a0b44dd..c915801488 100644 --- a/bacula/src/dird/sql_cmds.c +++ b/bacula/src/dird/sql_cmds.c @@ -254,8 +254,8 @@ char *uar_inc_dec = "AND JobMedia.MediaId=Media.MediaId " "AND Job.Level IN ('I', 'D') AND JobStatus='T' " "AND Job.FileSetId=FileSet.FileSetId " - "%s" - "AND FileSet.FileSet='%s' "; + "AND FileSet.FileSet='%s' " + "%s"; char *uar_list_temp = "SELECT JobId,Level,JobFiles,StartTime,VolumeName,StartFile," diff --git a/bacula/src/lib/watchdog.c b/bacula/src/lib/watchdog.c index 9ee2de331c..bcba37e565 100755 --- a/bacula/src/lib/watchdog.c +++ b/bacula/src/lib/watchdog.c @@ -45,7 +45,7 @@ static void *watchdog_thread(void *arg); /* Static globals */ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t timer = PTHREAD_COND_INITIALIZER; -static int quit; +static bool quit; static bool wd_is_init = false; /* Forward referenced callback functions */ @@ -69,7 +69,7 @@ int start_watchdog(void) Dmsg0(200, "Initialising NicB-hacked watchdog thread\n"); watchdog_time = time(NULL); - quit = FALSE; + quit = false; if ((stat = pthread_create(&wd_tid, NULL, watchdog_thread, NULL)) != 0) { return stat; } @@ -89,7 +89,7 @@ int stop_watchdog(void) watchdog_t *p, *n; if (!wd_is_init) { - Emsg0(M_ABORT, 0, "BUG! stop_watchdog called before start_watchdog\n"); + return 0; } Dmsg0(200, "Sending stop signal to NicB-hacked watchdog thread\n"); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index e7d1426e6b..aca13e57e9 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -953,6 +953,19 @@ test_again: " Fast Forward Space File = no\n\n" "to your Device resource for this drive.\n"); } + + Pmsg0(-1, "\n"); + Pmsg0(0, _("Now forward spacing 4 more files.\n")); + if (!fsf_dev(dev, 4)) { + Pmsg1(0, "Bad status from fsr. ERR=%s\n", strerror_dev(dev)); + goto bail_out; + } + Pmsg2(-1, _("We should be in file 5. I am at file %d. This is %s\n"), + dev->file, dev->file == 5 ? "correct!" : "NOT correct!!!!"); + if (dev->file != 5) { + goto bail_out; + } + return 1; bail_out: @@ -985,7 +998,7 @@ static void testcmd() goto all_done; } if (stat == -1) { /* first test failed */ - if (dev_cap(dev, CAP_EOM)) { + if (dev_cap(dev, CAP_EOM) || dev_cap(dev, CAP_FASTFSF)) { Pmsg0(-1, "\nAppend test failed. Attempting again.\n" "Setting \"Hardware End of Medium = no\n" " and \"Fast Forward Space File = no\n" diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index b55b007780..23ae650208 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -458,7 +458,7 @@ eod_dev(DEVICE *dev) * Move file by file to the end of the tape */ int file_num; - for (file_num=0; !(dev->state & ST_EOT); ) { + for (file_num=dev->file; !(dev->state & ST_EOT); file_num++) { Dmsg0(200, "eod_dev: doing fsf 1\n"); if (!fsf_dev(dev, 1)) { Dmsg0(200, "fsf_dev error.\n"); @@ -468,7 +468,8 @@ eod_dev(DEVICE *dev) * Avoid infinite loop. ***FIXME*** possibly add code * to set EOD or to turn off CAP_FASTFSF if on. */ - if (file_num++ != (int)dev->file) { + if (file_num == (int)dev->file) { + Dmsg1(000, "fsf_dev did not advance from file %d\n", file_num); return 0; /* we are not progressing, bail out */ } } @@ -479,8 +480,14 @@ eod_dev(DEVICE *dev) * the second EOF. */ if (dev_cap(dev, CAP_BSFATEOM)) { - stat = bsf_dev(dev, 1); - dev->file++; /* keep same file */ + struct mtget mt_stat; + /* Backup over EOF */ + stat = bsf_dev(dev, 1); + /* If BSF worked and fileno is known (not -1), set file */ + if (stat == 0 && ioctl(dev->fd, MTIOCGET, (char *)&mt_stat) == 0 && + mt_stat.mt_fileno >= 0) { + dev->file = mt_stat.mt_fileno; + } } else { update_pos_dev(dev); /* update position */ stat = 1; -- 2.39.5