]> git.sur5r.net Git - bacula/bacula/commitdiff
Unify the reserve_device() for a single device into one subroutine.
authorKern Sibbald <kern@sibbald.com>
Fri, 20 May 2005 09:00:10 +0000 (09:00 +0000)
committerKern Sibbald <kern@sibbald.com>
Fri, 20 May 2005 09:00:10 +0000 (09:00 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2072 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kes-1.37
bacula/src/host.h.in
bacula/src/jcr.h
bacula/src/stored/job.c
bacula/src/version.h

index 3a1d8f7887581a3467535a8352d1692e173f1942..252f4c7cffee22ce4627ceeb27c9ec7e6ae37dfc 100644 (file)
@@ -4,6 +4,8 @@
 General:
 
 Changes to 1.37.19:
+20May05
+- Unify the reserve_device() for a single device into one subroutine.
 18May05
 - Modify wait during use_device to happen only after all devices
   have been examined rather than in the reserve_device code.  
index dfe93bf042a29350ed4b348a10ca292357f66c21..fc4fa56541e3cd8d57e87c35b44df4e80f9d9a7b 100644 (file)
@@ -5,22 +5,17 @@
  *
  */
 /*
-   Copyright (C) 2000-2004 Kern Sibbald and John Walker
+   Copyright (C) 2000-2005 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as ammended with additional clauses defined in the
+   file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
index 8fdc424ff2a5afed705e1c49ae9e3a979e1f48ef..0ef096e29bbf027043023cb94ee8e4f6ab74ab69 100644 (file)
@@ -239,7 +239,6 @@ struct JCR {
    int type;
    DCR *dcr;                          /* device context record */
    alist *dcrs;                       /* list of dcrs open */
-// DEVRES *device;                    /* device resource to use */
    POOLMEM *job_name;                 /* base Job name (not unique) */
    POOLMEM *fileset_name;             /* FileSet */
    POOLMEM *fileset_md5;              /* MD5 for FileSet */
index 1b01cdc0f524af74aeaea0622c8ee80866d49762..f2ac8022b9698c96aca42d549a7e6544753dbc38 100644 (file)
@@ -267,6 +267,7 @@ public:
 };
 
 static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, int append);
+static int reserve_device(JCR *jcr, DIRSTORE *store, DEVRES *device, char *device_name, int append);
 
 static bool use_storage_cmd(JCR *jcr)
 {
@@ -402,18 +403,13 @@ done:
    return ok;
 }
 
-/*
- *  Returns: 1 -- OK, have DCR
- *           0 -- must wait
- *          -1 -- fatal error
- */
 static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, int append)
 {
    DEVRES *device;
    AUTOCHANGER *changer;
    BSOCK *dir = jcr->dir_bsock;
    bool ok;
-   DCR *dcr;
+   int stat;
 
    Dmsg1(100, "Search res for %s\n", device_name);
    foreach_res(device, R_DEVICE) {
@@ -421,36 +417,9 @@ static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, i
       /* Find resource, and make sure we were able to open it */
       if (fnmatch(device_name, device->hdr.name, 0) == 0 &&
           strcmp(device->media_type, store->media_type) == 0) {
-         const int name_len = MAX_NAME_LENGTH;
-         if (!device->dev) {
-            device->dev = init_dev(jcr, NULL, device);
-         }
-         if (!device->dev) {
-            Jmsg(jcr, M_WARNING, 0, _("\n"
-               "     Device \"%s\" requested by DIR could not be opened or does not exist.\n"),
-                 device_name);
-            return 0;
-         }  
-         Dmsg1(100, "Found device %s\n", device->hdr.name);
-         dcr = new_dcr(jcr, device->dev);
-         if (!dcr) {
-            bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), device_name);
-            Dmsg1(100, ">dird: %s\n", dir->msg);
-            return -1;
-         }
-         jcr->dcr = dcr;
-         bstrncpy(dcr->pool_name, store->pool_name, name_len);
-         bstrncpy(dcr->pool_type, store->pool_type, name_len);
-         bstrncpy(dcr->media_type, store->media_type, name_len);
-         bstrncpy(dcr->dev_name, device_name, name_len);
-         if (append == SD_APPEND) {
-            ok = reserve_device_for_append(dcr);
-         } else {
-            ok = reserve_device_for_read(dcr);
-         }
-         if (!ok) {
-            free_dcr(jcr->dcr);
-            return 0;
+         stat = reserve_device(jcr, store, device, device_name, append);
+         if (stat != 1) {
+            return stat;
          }
          Dmsg1(220, "Got: %s", dir->msg);
          bash_spaces(device_name);
@@ -463,43 +432,14 @@ static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, i
       Dmsg1(100, "Try changer res=%s\n", changer->hdr.name);
       /* Find resource, and make sure we were able to open it */
       if (fnmatch(device_name, changer->hdr.name, 0) == 0) {
-         const int name_len = MAX_NAME_LENGTH;
          /* Try each device in this AutoChanger */
          foreach_alist(device, changer->device) {
             Dmsg1(100, "Try changer device %s\n", device->hdr.name);
-            if (!device->dev) {
-               device->dev = init_dev(jcr, NULL, device);
-            }
-            if (!device->dev) {
-               Dmsg1(100, "Device %s could not be opened. Skipped\n", device_name);
-               Jmsg(jcr, M_WARNING, 0, _("\n"
-                  "     Device \"%s\" in changer \"%s\" requested by DIR could not be opened or does not exist.\n"),
-                    device->hdr.name, device_name);
-               continue;
-            }
-            if (!device->dev->autoselect) {
-               continue;           /* device is not available */
-            }
-            dcr = new_dcr(jcr, device->dev);
-            if (!dcr) {
-               bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), device_name);
-               Dmsg1(100, ">dird: %s\n", dir->msg);
+            stat = reserve_device(jcr, store, device, device_name, append);
+            if (stat == -1) {            /* hard error */
                return -1;
             }
-            Dmsg1(100, "Found changer device %s\n", device->hdr.name);
-            bstrncpy(dcr->pool_name, store->pool_name, name_len);
-            bstrncpy(dcr->pool_type, store->pool_type, name_len);
-            bstrncpy(dcr->media_type, store->media_type, name_len);
-            bstrncpy(dcr->dev_name, device_name, name_len);
-            jcr->dcr = dcr;
-            if (append == SD_APPEND) {
-               ok = reserve_device_for_append(dcr);
-            } else {
-               ok = reserve_device_for_read(dcr);
-            }
-            if (!ok) {
-               Jmsg(jcr, M_WARNING, 0, _("Could not reserve device: %s\n"), device_name);
-               free_dcr(jcr->dcr);
+            if (stat == 0) {             /* must wait, try next one */
                continue;
             }
             POOL_MEM dev_name;
@@ -515,6 +455,56 @@ static int search_res_for_device(JCR *jcr, DIRSTORE *store, char *device_name, i
    return 0;                    /* nothing found */
 }
 
+/*
+ *  Returns: 1 -- OK, have DCR
+ *           0 -- must wait
+ *          -1 -- fatal error
+ */
+static int reserve_device(JCR *jcr, DIRSTORE *store, DEVRES *device, char *device_name, int append)
+{
+   bool ok;
+   DCR *dcr;
+   const int name_len = MAX_NAME_LENGTH;
+   if (!device->dev) {
+      device->dev = init_dev(jcr, NULL, device);
+   }
+   if (!device->dev) {
+      if (dev_cap(device->dev, CAP_AUTOCHANGER)) {
+        Jmsg(jcr, M_WARNING, 0, _("\n"
+           "     Device \"%s\" in changer \"%s\" requested by DIR could not be opened or does not exist.\n"),
+             device->hdr.name, device_name);
+      } else {
+         Jmsg(jcr, M_WARNING, 0, _("\n"
+            "     Device \"%s\" requested by DIR could not be opened or does not exist.\n"),
+              device_name);
+      }
+      return 0;
+   }  
+   Dmsg1(100, "Found device %s\n", device->hdr.name);
+   dcr = new_dcr(jcr, device->dev);
+   if (!dcr) {
+      BSOCK *dir = jcr->dir_bsock;
+      bnet_fsend(dir, _("3926 Could not get dcr for device: %s\n"), device_name);
+      Dmsg1(100, ">dird: %s\n", dir->msg);
+      return -1;
+   }
+   jcr->dcr = dcr;
+   bstrncpy(dcr->pool_name, store->pool_name, name_len);
+   bstrncpy(dcr->pool_type, store->pool_type, name_len);
+   bstrncpy(dcr->media_type, store->media_type, name_len);
+   bstrncpy(dcr->dev_name, device_name, name_len);
+   if (append == SD_APPEND) {
+      ok = reserve_device_for_append(dcr);
+   } else {
+      ok = reserve_device_for_read(dcr);
+   }
+   if (!ok) {
+      free_dcr(jcr->dcr);
+      return 0;
+   }
+   return 1;
+}
+
 
 #ifdef needed
 /*
index 8bf04ac47c3d2d0b34c11e80d971dd6bcddd43ee..a3d4614df55a213f9cdeb6b562bde9cdc71e6137 100644 (file)
@@ -1,8 +1,8 @@
 /* */
 #undef  VERSION
 #define VERSION "1.37.19"
-#define BDATE   "18 May 2005"
-#define LSMDATE "18May05"
+#define BDATE   "20 May 2005"
+#define LSMDATE "20May05"
 
 /* Debug flags */
 #undef  DEBUG