From: Kern Sibbald Date: Sun, 1 Jun 2003 15:29:19 +0000 (+0000) Subject: SD crash fixes, get restore report values correct X-Git-Tag: Release-1.31~98 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ceb09df0e699c6ded348c7bf19c63291dd0609fd;p=bacula%2Fbacula SD crash fixes, get restore report values correct git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@558 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/backup.c b/bacula/src/dird/backup.c index 6afcd79950..976f7151dc 100644 --- a/bacula/src/dird/backup.c +++ b/bacula/src/dird/backup.c @@ -278,12 +278,14 @@ int wait_for_job_termination(JCR *jcr) int32_t n = 0; BSOCK *fd = jcr->file_bsock; int fd_ok = FALSE; + uint32_t JobFiles, Errors; + uint64_t ReadBytes, JobBytes; set_jcr_job_status(jcr, JS_Running); /* Wait for Client to terminate */ while ((n = bget_dirmsg(fd)) >= 0) { - if (sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &jcr->JobFiles, - &jcr->ReadBytes, &jcr->JobBytes, &jcr->Errors) == 5) { + if (!fd_ok && sscanf(fd->msg, EndJob, &jcr->FDJobStatus, &JobFiles, + &ReadBytes, &JobBytes, &Errors) == 5) { fd_ok = TRUE; set_jcr_job_status(jcr, jcr->FDJobStatus); Dmsg1(100, "FDStatus=%c\n", (char)jcr->JobStatus); @@ -301,6 +303,7 @@ int wait_for_job_termination(JCR *jcr) } bnet_sig(fd, BNET_TERMINATE); /* tell Client we are terminating */ + /* Note, the SD stores in jcr->JobFiles/ReadBytes/JobBytes/Errors */ wait_for_storage_daemon_termination(jcr); /* Return the first error status we find FD or SD */ @@ -310,6 +313,11 @@ int wait_for_job_termination(JCR *jcr) if (!fd_ok || is_bnet_error(fd)) { return JS_ErrorTerminated; } + /* Return values from FD */ + jcr->JobFiles = JobFiles; + jcr->Errors = Errors; + jcr->ReadBytes = ReadBytes; + jcr->JobBytes = JobBytes; return jcr->SDJobStatus; } diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index cbcc30d144..98ac1eac9f 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -79,13 +79,13 @@ int acquire_device_for_read(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) * If it is a tape, it checks the volume name */ for ( ; !(dev->state & ST_OPENED); ) { - Dmsg1(120, "bstored: open vol=%s\n", jcr->VolumeName); - if (open_dev(dev, jcr->VolumeName, READ_ONLY) < 0) { - Jmsg(jcr, M_FATAL, 0, _("Open device %s volume %s failed, ERR=%s\n"), - dev_name(dev), jcr->VolumeName, strerror_dev(dev)); - goto get_out; - } - Dmsg1(129, "open_dev %s OK\n", dev_name(dev)); + Dmsg1(120, "bstored: open vol=%s\n", jcr->VolumeName); + if (open_dev(dev, jcr->VolumeName, READ_ONLY) < 0) { + Jmsg(jcr, M_FATAL, 0, _("Open device %s volume %s failed, ERR=%s\n"), + dev_name(dev), jcr->VolumeName, strerror_dev(dev)); + goto get_out; + } + Dmsg1(129, "open_dev %s OK\n", dev_name(dev)); } dev->state &= ~ST_LABEL; /* force reread of label */ Dmsg0(200, "calling read-vol-label\n"); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 6080f2671c..a613f62bfe 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1089,7 +1089,6 @@ static void do_close(DEVICE *dev) dev->EndFile = dev->EndBlock = 0; memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo)); memset(&dev->VolHdr, 0, sizeof(dev->VolHdr)); - dev->use_count--; if (dev->tid) { stop_thread_timer(dev->tid); dev->tid = 0; @@ -1109,10 +1108,8 @@ close_dev(DEVICE *dev) } if (dev->fd >= 0 && dev->use_count == 1) { do_close(dev); - } else { - Dmsg0(29, "close_dev but in use so leave open.\n"); - dev->use_count--; } + dev->use_count--; } /* @@ -1127,6 +1124,7 @@ void force_close_dev(DEVICE *dev) } Dmsg0(29, "really close_dev\n"); do_close(dev); + dev->use_count--; } int truncate_dev(DEVICE *dev) diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index b98d0091c9..f5e7be218b 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -293,11 +293,16 @@ void _unblock_device(char *file, int line, DEVICE *dev) Dmsg3(100, "unblock %d from %s:%d\n", dev->dev_blocked, file, line); ASSERT(dev->dev_blocked); dev->dev_blocked = BST_NOT_BLOCKED; + dev->no_wait_id = 0; if (dev->num_waiting > 0) { pthread_cond_broadcast(&dev->wait); /* wake them up */ } } +/* + * Enter with device locked and blocked + * Exit with device unlocked and blocked by us. + */ void _steal_device_lock(char *file, int line, DEVICE *dev, bsteal_lock_t *hold, int state) { Dmsg4(100, "steal lock. old=%d new=%d from %s:%d\n", dev->dev_blocked, state, @@ -309,6 +314,10 @@ void _steal_device_lock(char *file, int line, DEVICE *dev, bsteal_lock_t *hold, V(dev->mutex); } +/* + * Enter with device blocked by us but not locked + * Exit with device locked, and blocked by previous owner + */ void _return_device_lock(char *file, int line, DEVICE *dev, bsteal_lock_t *hold) { Dmsg4(100, "return lock. old=%d new=%d from %s:%d\n", @@ -318,69 +327,3 @@ void _return_device_lock(char *file, int line, DEVICE *dev, bsteal_lock_t *hold) dev->no_wait_id = hold->no_wait_id; } - - -/* ================================================================== - * New device locking code. It is not currently used. - * ================================================================== - */ - -/* - * New device locking scheme - */ -void _new_lock_device(char *file, int line, DEVICE *dev) -{ -#ifdef NEW_LOCK - int errstat; - if ((errstat=rwl_writelock(&dev->lock)) != 0) { - e_msg(file, line, M_ABORT, 0, "rwl_writelock failure. ERR=%s\n", - strerror(errstat)); - } -#endif -} - -void _new_lock_device(char *file, int line, DEVICE *dev, int state) -{ -#ifdef NEW_LOCK - int errstat; - if ((errstat=rwl_writelock(&dev->lock)) != 0) { - e_msg(file, line, M_ABORT, 0, "rwl_writelock failure. ERR=%s\n", - strerror(errstat)); - } - dev->dev_blocked = state; -#endif -} - -void _new_unlock_device(char *file, int line, DEVICE *dev) -{ -#ifdef NEW_LOCK - int errstat; - if (dev->lock.w_active == 1) { - dev->dev_blocked = BST_NOT_BLOCKED; - } - if ((errstat=rwl_writeunlock(&dev->lock)) != 0) { - e_msg(file, line, M_ABORT, 0, "rwl_writeunlock failure. ERR=%s\n", - strerror(errstat)); - } -#endif -} - -void new_steal_device_lock(DEVICE *dev, brwsteal_t *hold, int state) -{ -#ifdef NEW_LOCK - hold->state = dev->dev_blocked; - hold->writer_id = dev->lock.writer_id; - dev->dev_blocked = state; - dev->lock.writer_id = pthread_self(); - V(dev->lock.mutex); -#endif -} - -void new_return_device_lock(DEVICE *dev, brwsteal_t *hold) -{ -#ifdef NEW_LOCK - P(dev->lock.mutex); - dev->dev_blocked = hold->state; - dev->lock.writer_id = hold->writer_id; -#endif -} diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 26c8664f60..69aaa299bb 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -366,16 +366,16 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname, autoload_device(jcr, dev, 0, dir); /* autoload if possible */ block = new_block(dev); - /* Ensure that the device is open -- not autoload_device() closes it */ + /* Ensure that the device is open -- autoload_device() closes it */ for ( ; !(dev->state & ST_OPENED); ) { - if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) { - if (dev->dev_errno == EAGAIN || dev->dev_errno == EBUSY) { - bmicrosleep(30, 0); - } - bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"), - dev_name(dev), strerror_dev(dev)); - goto bail_out; - } + if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) { + if (dev->dev_errno == EAGAIN || dev->dev_errno == EBUSY) { + bmicrosleep(30, 0); + } + bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"), + dev_name(dev), strerror_dev(dev)); + goto bail_out; + } } /* See what we have for a Volume */ @@ -616,6 +616,7 @@ static int unmount_cmd(JCR *jcr) } else if (dev->dev_blocked == BST_WAITING_FOR_SYSOP) { Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting, dev->dev_blocked); + open_dev(dev, NULL, 0); /* fake open for close */ offline_or_rewind_dev(dev); force_close_dev(dev); dev->dev_blocked = BST_UNMOUNTED_WAITING_FOR_SYSOP; @@ -643,6 +644,7 @@ static int unmount_cmd(JCR *jcr) } else { /* device not being used */ Dmsg0(90, "Device not in use, unmounting\n"); block_device(dev, BST_UNMOUNTED); + open_dev(dev, NULL, 0); /* fake open for close */ offline_or_rewind_dev(dev); force_close_dev(dev); bnet_fsend(dir, _("3002 Device %s unmounted.\n"), dev_name(dev)); diff --git a/bacula/src/version.h b/bacula/src/version.h index 8dfa9bb282..d0a233c613 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -1,8 +1,8 @@ /* */ #define VERSION "1.31" #define VSTRING "1" -#define BDATE "30 May 2003" -#define LSMDATE "30May03" +#define BDATE "01 Jun 2003" +#define LSMDATE "01Jun03" /* Debug flags */ #define DEBUG 1