]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Implement algorithm to handle only one appendable volume with
authorKern Sibbald <kern@sibbald.com>
Fri, 1 Jun 2007 21:10:38 +0000 (21:10 +0000)
committerKern Sibbald <kern@sibbald.com>
Fri, 1 Jun 2007 21:10:38 +0000 (21:10 +0000)
     Prefer Mounted Volumes = no.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4965 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/ChangeLog
bacula/src/stored/askdir.c
bacula/src/stored/dev.h
bacula/src/stored/reserve.c
bacula/technotes-2.1

index ad5c7d5ebdcffd6fec3eee81cae4893584e2acd1..2ac35c23357b2fa80d2c63d730e7922ae8734c95 100644 (file)
@@ -2,6 +2,8 @@
 
 General:
 01Jun07
+kes  Implement algorithm to handle only one appendable volume with
+     Prefer Mounted Volumes = no.
 kes  Fix a Bacula PostgreSQL bug dereferencing a NULL pointer      
      returned from a query.
 kes  Make volume lock recursive.
index b93b9337164041fc28821326c26cfb124a9c7151..68ea835c8ae5c41a33546256bd102fa7d149e540 100644 (file)
@@ -173,7 +173,7 @@ static bool do_get_volume_info(DCR *dcr)
     int n;
     int32_t InChanger;
 
-    if (bnet_recv(dir) <= 0) {
+    if (dir->recv() <= 0) {
        Dmsg0(200, "getvolname error bnet_recv\n");
        Mmsg(jcr->errmsg, _("Network error on bnet_recv in req_vol_info.\n"));
        return false;
@@ -224,7 +224,7 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing)
     P(vol_info_mutex);
     bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
     bash_spaces(dcr->VolCatInfo.VolCatName);
-    bnet_fsend(dir, Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName,
+    dir->fsend(Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName,
        writing==GET_VOL_INFO_FOR_WRITE?1:0);
     Dmsg1(100, ">dird: %s", dir->msg);
     unbash_spaces(dcr->VolCatInfo.VolCatName);
@@ -241,6 +241,8 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing)
  * Returns: true  on success dcr->VolumeName is volume
  *                reserve_volume() called on Volume name
  *          false on failure dcr->VolumeName[0] == 0
+ *                also sets dcr->volume_in_use if at least one 
+ *                in use volume was found.
  *
  *          Volume information returned in dcr
  *
@@ -259,10 +261,11 @@ bool dir_find_next_appendable_volume(DCR *dcr)
      */
     lock_reservations();
     P(vol_info_mutex);
+    dcr->volume_in_use = false;
     for (int vol_index=1;  vol_index < 20; vol_index++) {
        bash_spaces(dcr->media_type);
        bash_spaces(dcr->pool_name);
-       bnet_fsend(dir, Find_media, jcr->Job, vol_index, dcr->pool_name, dcr->media_type);
+       dir->fsend(Find_media, jcr->Job, vol_index, dcr->pool_name, dcr->media_type);
        unbash_spaces(dcr->media_type);
        unbash_spaces(dcr->pool_name);
        Dmsg1(100, ">dird: %s", dir->msg);
@@ -273,6 +276,7 @@ bool dir_find_next_appendable_volume(DCR *dcr)
              break;
           } else {
              Dmsg1(100, "Volume %s is in use.\n", dcr->VolumeName);
+             dcr->volume_in_use = true;
              continue;
           }
        } else {
index 108389760d69b636f6ca45b64e357eac8b44f83c..57169d113c55cc620430c99fe81c601acf768950 100644 (file)
@@ -472,6 +472,7 @@ public:
    bool reserved_device;              /* set if reserve done */
    bool any_volume;                   /* Any OK for dir_find_next... */
    bool attached_to_dev;              /* set when attached to dev */
+   bool volume_in_use;                /* set in dir_find_next_appendable_volume() */
    uint32_t VolFirstIndex;            /* First file index this Volume */
    uint32_t VolLastIndex;             /* Last file index this Volume */
    uint32_t FileIndex;                /* Current File Index */
index 9000f9906eb8b42a96ba1c2cb150a0b71ee6b154..3fb60b4340e81299579d7ebd4470078d0af20ef6 100644 (file)
@@ -441,13 +441,13 @@ bool volume_unused(DCR *dcr)
 
    if (dev->vol == NULL) {
       Dmsg2(dbglvl, "JobId=%u vol_unused: no vol on %s\n", (int)dcr->jcr->JobId, dev->print_name());
-      debug_list_volumes("null return unreserve_volume");
+      debug_list_volumes("null vol cannot unreserve_volume");
       return false;
    }
 
    if (dev->is_busy()) {
       Dmsg2(dbglvl, "JobId=%u vol_unused: no vol on %s\n", (int)dcr->jcr->JobId, dev->print_name());
-      debug_list_volumes("dev busy return unreserve_volume");
+      debug_list_volumes("dev busy cannot unreserve_volume");
       return false;
    }
 
@@ -881,7 +881,7 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx)
          rctx.device_name = device_name;
          stat = search_res_for_device(rctx); 
          if (stat == 1) {             /* found available device */
-            Dmsg2(dbglvl, "JobId=%u Suitable device found=%s\n", (int)rctx.jcr->JobId, 
+            Dmsg2(dbglvl, "JobId=%u available device found=%s\n", (int)rctx.jcr->JobId, 
                   device_name);
             ok = true;
             break;
@@ -1029,7 +1029,18 @@ static int reserve_device(RCTX &rctx)
             Dmsg1(dbglvl, "JobId=%u No next volume found\n", (int)rctx.jcr->JobId);
             rctx.have_volume = false;
             rctx.VolumeName[0] = 0;
-        }
+            /*
+             * If there is at least one volume that is valid and in use,
+             *   but we get here, check if we are running with prefers
+             *   non-mounted drives.  In that case, we have selected a
+             *   non-used drive and our one and only volume is mounted
+             *   elsewhere, so we bail out and retry using that drive.
+             */
+            if (dcr->volume_in_use && !rctx.PreferMountedVols) {
+               rctx.PreferMountedVols = true;
+               goto bail_out;
+            }
+         }
       }
       ok = reserve_device_for_append(dcr, rctx);
       if (ok) {
@@ -1050,13 +1061,10 @@ static int reserve_device(RCTX &rctx)
       }
    }
    if (!ok) {
-      rctx.have_volume = false;
-      free_dcr(dcr);
-      Dmsg1(dbglvl, "JobId=%u Not OK.\n", (int)rctx.jcr->JobId);
-      return 0;
+      goto bail_out;
    }
-   POOL_MEM dev_name;
    if (rctx.notify_dir) {
+      POOL_MEM dev_name;
       BSOCK *dir = rctx.jcr->dir_bsock;
       pm_strcpy(dev_name, rctx.device->hdr.name);
       bash_spaces(dev_name);
@@ -1066,6 +1074,12 @@ static int reserve_device(RCTX &rctx)
       ok = true;
    }
    return ok ? 1 : -1;
+
+bail_out:
+   rctx.have_volume = false;
+   free_dcr(dcr);
+   Dmsg1(dbglvl, "JobId=%u Not OK.\n", (int)rctx.jcr->JobId);
+   return 0;
 }
 
 /*
index c44788b6888e5629b7e0def60309c35cceb3e355..6006afbbfa006348d563737fcd638b23f36f91f2 100644 (file)
@@ -2,6 +2,8 @@
 
 General:
 01Jun07
+kes  Implement algorithm to handle only one appendable volume with
+     Prefer Mounted Volumes = no.
 kes  Fix a Bacula PostgreSQL bug dereferencing a NULL pointer      
      returned from a query.
 kes  Make volume lock recursive.