]> git.sur5r.net Git - bacula/bacula/commitdiff
SD crash fixes, get restore report values correct
authorKern Sibbald <kern@sibbald.com>
Sun, 1 Jun 2003 15:29:19 +0000 (15:29 +0000)
committerKern Sibbald <kern@sibbald.com>
Sun, 1 Jun 2003 15:29:19 +0000 (15:29 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@558 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/backup.c
bacula/src/stored/acquire.c
bacula/src/stored/dev.c
bacula/src/stored/device.c
bacula/src/stored/dircmd.c
bacula/src/version.h

index 6afcd799507746939900af984f08582a5a139f73..976f7151dceb58dbb0a9fd71d9cbd471528f9004 100644 (file)
@@ -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;
 }
 
index cbcc30d14442ae5a5f63ac501fe660bf3709080b..98ac1eac9fc518d83971253ed62f5c9d23479042 100644 (file)
@@ -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");
index 6080f2671c2d4baee32e5152367251b293b5b4b1..a613f62bfece81bb706a98c78b0726c17ddc60d9 100644 (file)
@@ -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)
index b98d0091c923eee01535099d8cf3b6c7d3e79774..f5e7be218b2f93f5b35107fce8d26ac572c47b85 100644 (file)
@@ -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
-}
index 26c8664f60129a4ecf574a954e0e831240cbb3cc..69aaa299bb3ea78d8b0825ac2d2ee105e78f19dc 100644 (file)
@@ -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));
index 8dfa9bb2824a7a154ab412da4a55256d2c8ff740..d0a233c6131375c46cc9327f84f07648c74ffee8 100644 (file)
@@ -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