]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/reserve.c
Make cd accept wildcards
[bacula/bacula] / bacula / src / stored / reserve.c
index 3223d884fc055533805d4240a5f638c4862909d4..a40be1607ad68ec6498246f86bcab48726946de9 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2009 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -32,8 +32,6 @@
  *
  *   Split from job.c and acquire.c June 2005
  *
- *   Version $Id$
- *
  */
 
 #include "bacula.h"
@@ -48,7 +46,7 @@ static int can_reserve_drive(DCR *dcr, RCTX &rctx);
 static int reserve_device(RCTX &rctx);
 static bool reserve_device_for_read(DCR *dcr);
 static bool reserve_device_for_append(DCR *dcr, RCTX &rctx);
-static bool use_storage_cmd(JCR *jcr);
+static bool use_device_cmd(JCR *jcr);
 static void queue_reserve_message(JCR *jcr);
 static void pop_reserve_messages(JCR *jcr);
 //void switch_device(DCR *dcr, DEVICE *dev);
@@ -68,8 +66,8 @@ bool use_cmd(JCR *jcr)
    /*
     * Get the device, media, and pool information
     */
-   if (!use_storage_cmd(jcr)) {
-      set_jcr_job_status(jcr, JS_ErrorTerminated);
+   if (!use_device_cmd(jcr)) {
+      jcr->setJobStatus(JS_ErrorTerminated);
       memset(jcr->sd_auth_key, 0, strlen(jcr->sd_auth_key));
       return false;
    }
@@ -163,6 +161,7 @@ void DCR::unreserve_device()
       }
    }
    unlock_volumes();
+   generate_plugin_event(jcr, bsdEventDeviceClose, this);
    dev->dunlock();
 }
 
@@ -177,13 +176,13 @@ void DCR::unreserve_device()
  *  use device=bbb
  *
  */
-static bool use_storage_cmd(JCR *jcr)
+static bool use_device_cmd(JCR *jcr)
 {
    POOL_MEM store_name, dev_name, media_type, pool_name, pool_type;
    BSOCK *dir = jcr->dir_bsock;
-   int append;
+   int32_t append;
    bool ok;       
-   int Copy, Stripe;
+   int32_t Copy, Stripe;
    DIRSTORE *store;
    RCTX rctx;
    alist *dirstore;
@@ -236,6 +235,7 @@ static bool use_storage_cmd(JCR *jcr)
       }
    }  while (ok && dir->recv() >= 0);
 
+#ifdef xxxx
    /* Developer debug code */
    char *device_name;
    if (debug_level >= dbglvl) {
@@ -248,6 +248,7 @@ static bool use_storage_cmd(JCR *jcr)
          }
       }
    }
+#endif
 
    init_jcr_device_wait_timers(jcr);
    jcr->dcr = new_dcr(jcr, NULL, NULL);         /* get a dcr */
@@ -272,6 +273,12 @@ static bool use_storage_cmd(JCR *jcr)
       bool fail = false;
       rctx.notify_dir = true;
 
+      /* Put new dcr in proper location */
+      if (rctx.append) {
+         rctx.jcr->dcr = jcr->dcr;
+      } else {
+         rctx.jcr->read_dcr = jcr->dcr;
+      }
       lock_reservations();
       for ( ; !fail && !job_canceled(jcr); ) {
          pop_reserve_messages(jcr);
@@ -453,7 +460,7 @@ bool find_suitable_device_for_job(JCR *jcr, RCTX &rctx)
 
                if (vol->dev->is_autochanger()) {
                   Dmsg1(dbglvl, "vol=%s is in changer\n", vol->vol_name);
-                  if (!is_vol_in_autochanger(rctx, vol)) {
+                  if (!is_vol_in_autochanger(rctx, vol) || !vol->dev->autoselect) {
                      continue;
                   }
                } else if (strcmp(device_name, vol->dev->device->hdr.name) != 0) {
@@ -785,10 +792,15 @@ static bool reserve_device_for_read(DCR *dcr)
       goto bail_out;
    }
 
+   /* Note: on failure this returns jcr->errmsg properly edited */
+   if (generate_plugin_event(jcr, bsdEventDeviceTryOpen, dcr) != bRC_OK) {
+      queue_reserve_message(jcr);
+      goto bail_out;
+   }
    dev->clear_append();
    dev->set_read();
-   ok = true;
    dcr->set_reserved();
+   ok = true;
 
 bail_out:
    dev->dunlock();
@@ -850,6 +862,11 @@ static bool reserve_device_for_append(DCR *dcr, RCTX &rctx)
       goto bail_out;
    }
 
+   /* Note: on failure this returns jcr->errmsg properly edited */
+   if (generate_plugin_event(jcr, bsdEventDeviceTryOpen, dcr) != bRC_OK) {
+      queue_reserve_message(jcr);
+      goto bail_out;
+   }
    dcr->set_reserved();
    ok = true;