]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/acquire.c
Simplify two messages in acquire.c
[bacula/bacula] / bacula / src / stored / acquire.c
index a2971c17b38f72fc17a18873d554a82580967bac..8599e0b35921ac22793fe1aa7eaf96291e3c9e3c 100644 (file)
@@ -43,6 +43,7 @@ int acquire_device_for_read(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    int stat = 0;
    int tape_previously_mounted;
    VOL_LIST *vol;
+   int autochanger = 0;
 
    lock_device(dev);
    block_device(dev, BST_DOING_ACQUIRE);
@@ -51,14 +52,14 @@ int acquire_device_for_read(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    tape_previously_mounted = (dev->state & ST_READ) || (dev->state & ST_APPEND);
 
    if (dev->state & ST_READ || dev->num_writers > 0) {
-      Jmsg1(jcr, M_FATAL, 0, _("Device %s is busy. Job cancelled.\n"), dev_name(dev));
+      Jmsg1(jcr, M_FATAL, 0, _("Device %s is busy. Job canceled.\n"), dev_name(dev));
       goto get_out;
    }
 
    /* Find next Volume, if any */
    vol = jcr->VolList;
    if (!vol) {
-      Jmsg(jcr, M_FATAL, 0, _("No volumes specified. Job cancelled.\n"));
+      Jmsg(jcr, M_FATAL, 0, _("No volumes specified. Job canceled.\n"));
       goto get_out;
    }
    jcr->CurVolume++;
@@ -68,8 +69,8 @@ int acquire_device_for_read(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    pm_strcpy(&jcr->VolumeName, vol->VolumeName);
 
    for (int i=0; i<5; i++) {
-      if (job_cancelled(jcr)) {
-         Mmsg0(&dev->errmsg, _("Job cancelled.\n"));
+      if (job_canceled(jcr)) {
+         Mmsg0(&dev->errmsg, _("Job canceled.\n"));
         goto get_out;                /* error return */
       }
       /*
@@ -89,41 +90,48 @@ int acquire_device_for_read(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
       dev->state &= ~ST_LABEL;          /* force reread of label */
       Dmsg0(200, "calling read-vol-label\n");
       switch (read_dev_volume_label(jcr, dev, block)) {
-        case VOL_OK:
-           stat = 1;
-           break;                    /* got it */
-        case VOL_IO_ERROR:
-           /*
-            * Send error message generated by read_dev_volume_label()
-            *  only we really had a tape mounted. This supresses superfluous
-            *  error messages when nothing is mounted.
-            */
-           if (tape_previously_mounted) {
-               Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);                         
-           }
-           goto default_path;
-        default:
-            Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+      case VOL_OK:
+        stat = 1;
+        break;                    /* got it */
+      case VOL_IO_ERROR:
+        /*
+         * Send error message generated by read_dev_volume_label()
+         *  only we really had a tape mounted. This supresses superfluous
+         *  error messages when nothing is mounted.
+         */
+        if (tape_previously_mounted) {
+            Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);                         
+        }
+        goto default_path;
+      default:
+         Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
 default_path:
-           tape_previously_mounted = 0;
-            Dmsg0(200, "dir_get_volume_info\n");
-           if (!dir_get_volume_info(jcr, 0)) { 
-               Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
-           }
+        tape_previously_mounted = 1;
+        if (autochanger) {
+           invalidate_slot_in_catalog(jcr);
+        }
+         Dmsg0(200, "dir_get_volume_info\n");
+        if (!dir_get_volume_info(jcr, 0)) { 
+            Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+        }
+        /* Call autochanger only once unless ask_sysop called */
+        if (!autochanger) {
             Dmsg2(200, "calling autoload Vol=%s Slot=%d\n",
               jcr->VolumeName, jcr->VolCatInfo.Slot);                         
-           if (autoload_device(jcr, dev, 0, NULL)) {
+           if ((autochanger=autoload_device(jcr, dev, 0, NULL))) {
               continue;
            }
-           /* Mount a specific volume and no other */
-            Dmsg0(200, "calling dir_ask_sysop\n");
-           if (!dir_ask_sysop_to_mount_volume(jcr, dev)) {
-              goto get_out;          /* error return */
-           }
-           continue;                 /* try reading again */
-      }
+        }
+        /* Mount a specific volume and no other */
+         Dmsg0(200, "calling dir_ask_sysop\n");
+        if (!dir_ask_sysop_to_mount_volume(jcr, dev)) {
+           goto get_out;             /* error return */
+        }
+        autochanger = 0;             /* permit using autochanger again */
+        continue;                    /* try reading again */
+      } /* end switch */
       break;
-   }
+   } /* end for loop */
    if (stat == 0) {
       Jmsg1(jcr, M_FATAL, 0, _("Too many errors trying to mount device \"%s\".\n"),
            dev_name(dev));