]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/device.c
First cut of restore
[bacula/bacula] / bacula / src / stored / device.c
index cf21a50594b94b5d6869c128402590a485b9382d..9ff3b759f44187cec20dd1db4c969877ef67f000 100644 (file)
@@ -176,7 +176,10 @@ int release_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
    Dmsg1(90, "release_device device is %s\n", dev_is_tape(dev)?"tape":"disk");
    if (dev->state & ST_READ) {
       dev->state &= ~ST_READ;        /* clear read bit */
-      if (!dev_is_tape(dev)) {
+      if (!dev_is_tape(dev) || !(dev->capabilities & CAP_ALWAYSOPEN)) {
+        if (dev->capabilities & CAP_OFFLINEUNMOUNT) {
+           offline_dev(dev);
+        }
         close_dev(dev);
       }
       /******FIXME**** send read volume usage statistics to director */
@@ -190,10 +193,12 @@ int release_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
         dev->VolCatInfo.VolCatFiles++;             /* increment number of files */
         /* Note! do volume update before close, which zaps VolCatInfo */
         dir_update_volume_info(jcr, &dev->VolCatInfo, 0); /* send Volume info to Director */
-        if (!dev_is_tape(dev)) {
+
+        if (!dev_is_tape(dev) || !(dev->capabilities & CAP_ALWAYSOPEN)) {
+           if (dev->capabilities & CAP_OFFLINEUNMOUNT) {
+              offline_dev(dev);
+           }
            close_dev(dev);
-        } else {
-            Dmsg0(90, "Device is tape leave open in release_device\n");
         }
       } else {
         dir_create_job_media_record(jcr);
@@ -247,8 +252,18 @@ mount_next_vol:
       memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
       dev->state &= ~ST_LABEL;       /* label not yet read */
 
-      /* Rewind device */                                   
+      if (!dev_is_tape(dev) || !(dev->capabilities & CAP_ALWAYSOPEN)) {
+        if (dev->capabilities & CAP_OFFLINEUNMOUNT) {
+           offline_dev(dev);
+        }
+        close_dev(dev);
+      }
+
+      /* If we have not closed the device, then at least rewind the tape */
       if (dev->state & ST_OPENED) {
+        if (dev->capabilities & CAP_OFFLINEUNMOUNT) {
+           offline_dev(dev);
+        }
         if (!rewind_dev(dev)) {
             Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device %s. ERR=%s\n"), 
                  dev_name(dev), strerror_dev(dev));
@@ -299,7 +314,7 @@ mount_next_vol:
       Dmsg1(100, "Want changer slot=%d\n", slot);
 
       if (slot > 0 && jcr->device->changer_name && jcr->device->changer_command) {
-        uint32_t timeout = jcr->device->changer_timeout;
+        uint32_t timeout = jcr->device->max_changer_wait;
         POOLMEM *changer, *results;
         int status, loaded;
 
@@ -635,10 +650,6 @@ int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
           PrevVolName, edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, b1),
           edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2));
 
-      if (!dev_is_tape(dev)) {          /* If file, */
-        close_dev(dev);                 /* yes, close it */
-      }
-
       /* Unlock, but leave BLOCKED */
       unlock_device(dev);
       if (!mount_next_volume(jcr, dev, label_blk, 1)) {
@@ -822,7 +833,7 @@ static char *edit_device_codes(JCR *jcr, char *omsg, char *imsg, char *cmd)
    const char *str;
    char add[20];
 
-   Dmsg1(200, "edit_job_codes: %s\n", imsg);
+   Dmsg1(200, "edit_device_codes: %s\n", imsg);
    add[2] = 0;
    o = omsg;
    for (p=imsg; *p; p++) {