]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Rework SD acquire for read to handle autochanger Volume
authorKern Sibbald <kern@sibbald.com>
Sat, 3 May 2008 14:51:43 +0000 (14:51 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 3 May 2008 14:51:43 +0000 (14:51 +0000)
     swapping.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/branches/Branch-2.2@6887 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/stored/acquire.c
bacula/src/stored/askdir.c
bacula/src/stored/autochanger.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/dircmd.c
bacula/src/stored/mount.c
bacula/src/stored/reserve.c
bacula/technotes-2.1

index 207e3415dc54e68cc8abebb05068156d4ae648a9..1d0d8a4ed347da0c4ec0e4e1d78ad445d580bbb1 100644 (file)
@@ -89,9 +89,27 @@ bool acquire_device_for_read(DCR *dcr)
          jcr->NumReadVolumes, jcr->CurReadVolume);
       goto get_out;                   /* should not happen */   
    }
+   /*    
+    * Note, if we want to be able to work from a .bsr file only          
+    *  for disaster recovery, we must "simulate" reading the catalog
+    */
    bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
+   bstrncpy(dcr->VolCatInfo.VolCatName, vol->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
    bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type));
    dcr->VolCatInfo.Slot = vol->Slot;
+   dcr->VolCatInfo.InChanger = vol->Slot > 0; 
+   if (reserve_volume(dcr, dcr->VolumeName) == NULL) {
+      Dmsg2(100, "Could not reserve volume %s on %s\n", dcr->VolumeName,
+            dcr->dev->print_name());
+      Jmsg2(jcr, M_FATAL, 0, _("Could not reserve volume %s on %s\n"), dcr->VolumeName,
+            dcr->dev->print_name());
+      goto get_out;
+   }
+   if (dev->vol && dev->vol->is_swapping()) {
+      dev->vol->set_slot(vol->Slot);
+      Dmsg3(100, "swapping: slot=%d Vol=%s dev=%s\n", dev->vol->get_slot(),
+         dev->vol->vol_name, dev->print_name());
+   }
     
    /*
     * If the MediaType requested for this volume is not the
@@ -192,9 +210,7 @@ bool acquire_device_for_read(DCR *dcr)
          goto get_out;                /* error return */
       }
 
-      dcr->do_swapping();
-
-      autoload_device(dcr, 0, NULL);
+      dcr->do_swapping(false/*is_writing*/);
 
       /*
        * This code ensures that the device is ready for
index a5ad1a6976ae86b5f848e58720aef21d8b2a914e..cf23a4fd9aba34457c877312ee945256444e972d 100644 (file)
@@ -283,7 +283,7 @@ bool dir_find_next_appendable_volume(DCR *dcr)
           bstrncpy(lastVolume, dcr->VolumeName, sizeof(lastVolume));
           if (dcr->can_i_use_volume()) {
              Dmsg1(100, "Call reserve_volume. Vol=%s\n", dcr->VolumeName);
-             if (reserve_volume(dcr, dcr->VolumeName) == 0) {
+             if (reserve_volume(dcr, dcr->VolumeName) == NULL) {
                 Dmsg2(100, "Could not reserve volume %s on %s\n", dcr->VolumeName,
                     dcr->dev->print_name());
                 continue;
index d11928de8c335ca2cb427af8fb9cd680fab7af8a..94e0134ed27490d333f5e12c98220b762b482e72 100644 (file)
@@ -118,7 +118,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
    POOLMEM *changer;
 
    if (!dev->is_autochanger()) {
-      Dmsg1(200, "Device %s is not an autochanger\n", dev->print_name());
+      Dmsg1(Dmsg0(100, "ChangerCommand=0, virtual disk changer\n");
       return 0;
    }
 
@@ -128,6 +128,8 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir)
    }
 
    slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
+   Dmsg3(100, "autoload: slot=%d InChgr=%d Vol=%s\n", dcr->VolCatInfo.Slot,
+         dcr->VolCatInfo.InChanger, dcr->VolCatInfo.VolCatName);
    /*
     * Handle autoloaders here.  If we cannot autoload it, we
     *  will return 0 so that the sysop will be asked to load it.
@@ -249,7 +251,7 @@ int get_autochanger_loaded_slot(DCR *dcr)
       return -1;
    }
    if (!dcr->device->changer_command) {
-      Jmsg(jcr, M_FATAL, 0, _("3992 Missing Changer command.\n"));
+//    Jmsg(jcr, M_FATAL, 0, _("3992 Missing Changer command.\n"));
       return -1;
    }
    if (dev->Slot > 0) {
index 079f4eac00690010bee4b9ec2fc121f9aeff0124..63797951265a3cab9184428fed137fc1e3075425 100644 (file)
@@ -1885,7 +1885,7 @@ void DEVICE::close()
  *  the Volume parts multiple times without losing track of what the    
  *  main Volume parameters are.
  */
-void DEVICE::close_part(DCR *dcr)
+void DEVICE::close_part(DCR * /*dcr*/)
 {
    VOLUME_LABEL saveVolHdr;
    VOLUME_CAT_INFO saveVolCatInfo;     /* Volume Catalog Information */
@@ -1896,7 +1896,6 @@ void DEVICE::close_part(DCR *dcr)
    close();                           /* close current part */
    VolHdr = saveVolHdr;               /* structure assignment */
    VolCatInfo = saveVolCatInfo;       /* structure assignment */
-   dcr->VolCatInfo = saveVolCatInfo;  /* structure assignment */
 }
 
 boffset_t DEVICE::lseek(DCR *dcr, boffset_t offset, int whence)
index 7a3f07665b31f90385bdf0a4c57bf299d28aaf86..76f9bb34d8cbc301f1a21fa208c2156bfc17ced1 100644 (file)
@@ -533,7 +533,7 @@ public:
    bool is_eod_valid();
    int check_volume_label(bool &ask, bool &autochanger);
    void release_volume();
-   void do_swapping();
+   void do_swapping(bool is_writing);
 };
 
 /*
index 411d6687a369d7fd622b79417c907cf177bfe490..ceac150446910fb5813f187b1c2dd4440f6e46d4 100644 (file)
@@ -913,7 +913,7 @@ static bool release_cmd(JCR *jcr)
          } else if (dev->is_busy()) {
             send_dir_busy_message(dir, dev);
          } else {                     /* device not being used */
-            Dmsg0(90, "Device not in use, releaseing\n");
+            Dmsg0(90, "Device not in use, releasing\n");
             unload_autochanger(dcr, -1);
             dcr->release_volume();
             dir->fsend(_("3022 Device %s released.\n"), 
index b38f17979678a3dcce5035603a60051c091478f5..0a9634de2c493077e489888ac0ea0d019a6f69f1 100644 (file)
@@ -106,7 +106,7 @@ mount_next_vol:
    if (dev->must_unload()) {
       ask = true;                     /* ask operator to mount tape */
    }
-   do_swapping();
+   do_swapping(true /*writing*/);
 
    if (!is_suitable_volume_mounted()) {
       bool have_vol = false;
@@ -153,7 +153,7 @@ mount_next_vol:
     * and move the tape to the end of data.
     *
     */
-   if (autoload_device(dcr, 1, NULL) > 0) {
+   if (autoload_device(dcr, true/*writing*/, NULL) > 0) {
       autochanger = true;
       ask = false;
    } else {
@@ -470,7 +470,7 @@ bool DCR::is_suitable_volume_mounted()
    return dir_get_volume_info(this, GET_VOL_INFO_FOR_WRITE);
 }
 
-void DCR::do_swapping()
+void DCR::do_swapping(bool is_writing)
 {
    if (dev->must_unload()) {
       Dmsg1(100, "swapping: unloading %s\n", dev->print_name());
@@ -502,8 +502,9 @@ void DCR::do_swapping()
    }
    if (dev->must_load()) {
       Dmsg1(100, "swapping: must load %s\n", dev->print_name());
-      dev->clear_load();
-      dev->clear_volhdr();               /* force "load" */
+      if (autoload_device(this, is_writing, NULL) > 0) {
+         dev->clear_load();
+      }
    }
 }
 
@@ -680,7 +681,7 @@ void DCR::release_volume()
    dev->block_num = dev->file = 0;
    dev->EndBlock = dev->EndFile = 0;
    memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo));
-   memset(&VolCatInfo, 0, sizeof(VolCatInfo));
+// memset(&VolCatInfo, 0, sizeof(VolCatInfo));
    dev->clear_volhdr();
    /* Force re-read of label */
    dev->clear_labeled();
index 714b24d2d4a6441769c6039dc8d2211f796f9ca7..ba918274b2dc227f6291c07c611a12ce361b8427 100644 (file)
@@ -1574,7 +1574,7 @@ static int can_reserve_drive(DCR *dcr, RCTX &rctx)
             /* Changing pool, unload old tape if any in drive */
             Dmsg1(dbglvl, "jid=%u OK dev: num_writers=0, not reserved, pool change, unload changer\n", (int)jcr->JobId);
             /* ***FIXME*** use set_unload() */
-            unload_autochanger(dcr, 0);
+            unload_autochanger(dcr, -1);
          }
       }
       /* Device is available but not yet reserved, reserve it for us */
index d255a2787a652f3c737fca3791b652f26608f307..72c48e9a16a53a39bd4cc0d8db806cd5d74bd6d2 100644 (file)
@@ -2,6 +2,8 @@
 
 General:
 03May08
+kes  Rework SD acquire for read to handle autochanger Volume
+     swapping.
 kes  Implement regression that explicitly tests swapping a Volume
      from one drive to another.
 kes  Enhance disk-changer to detect most error conditions.