]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/reserve.c
ebl Fix a bug in read_close_session which return random status
[bacula/bacula] / bacula / src / stored / reserve.c
index 1485111ca8325ec263701786c64d8e1d32681c97..349aa29592073efa3bdb95628292ea98a362008f 100644 (file)
@@ -54,6 +54,7 @@ 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 void queue_reserve_message(JCR *jcr);
+static void pop_reserve_messages(JCR *jcr);
 
 /* Requests from the Director daemon */
 static char use_storage[]  = "use storage=%127s media_type=%127s "
@@ -415,7 +416,6 @@ VOLRES *find_volume(DCR *dcr)
 void unreserve_device(DCR *dcr)
 {
    DEVICE *dev = dcr->dev;
-   dev->dlock();
    if (dcr->reserved_device) {
       dcr->reserved_device = false;
       dev->reserved_device--;
@@ -432,7 +432,6 @@ void unreserve_device(DCR *dcr)
    }
 
    volume_unused(dcr);
-   dev->dunlock();
 }
 
 /*  
@@ -573,8 +572,6 @@ static bool use_storage_cmd(JCR *jcr)
    int Copy, Stripe;
    DIRSTORE *store;
    RCTX rctx;
-   char *msg;
-   alist *msgs;
    alist *dirstore;
 
    memset(&rctx, 0, sizeof(RCTX));
@@ -584,7 +581,7 @@ static bool use_storage_cmd(JCR *jcr)
     *   use_device for each device that it wants to use.
     */
    dirstore = New(alist(10, not_owned_by_alist));
-   msgs = jcr->reserve_msgs = New(alist(10, not_owned_by_alist));  
+   jcr->reserve_msgs = New(alist(10, not_owned_by_alist));  
    do {
       Dmsg2(dbglvl, "jid=%u <dird: %s", jid(), dir->msg);
       ok = sscanf(dir->msg, use_storage, store_name.c_str(), 
@@ -664,9 +661,7 @@ static bool use_storage_cmd(JCR *jcr)
 
       lock_reservations();
       for ( ; !fail && !job_canceled(jcr); ) {
-         while ((msg = (char *)msgs->pop())) {
-            free(msg);
-         }
+         pop_reserve_messages(jcr);
          rctx.suitable_device = false;
          rctx.have_volume = false;
          rctx.VolumeName[0] = 0;
@@ -784,7 +779,7 @@ static bool use_storage_cmd(JCR *jcr)
       Dmsg2(dbglvl, "jid=%u >dird: %s", jid(), dir->msg);
    }
 
-   release_msgs(jcr);
+   release_reserve_messages(jcr);
    return ok;
 }
 
@@ -801,7 +796,7 @@ static bool is_vol_in_autochanger(RCTX &rctx, VOLRES *vol)
    AUTOCHANGER *changer = vol->dev->device->changer_res;
 
    /* Find resource, and make sure we were able to open it */
-   if (fnmatch(rctx.device_name, changer->hdr.name, 0) == 0) {
+   if (strcmp(rctx.device_name, changer->hdr.name) == 0) {
       Dmsg2(dbglvl, "jid=%u Found changer device %s\n",
                      (int)rctx.jcr->JobId, vol->dev->device->hdr.name);
       return true;
@@ -993,7 +988,7 @@ int search_res_for_device(RCTX &rctx)
    foreach_res(changer, R_AUTOCHANGER) {
       Dmsg2(dbglvl, "jid=%u Try match changer res=%s\n", (int)rctx.jcr->JobId, changer->hdr.name);
       /* Find resource, and make sure we were able to open it */
-      if (fnmatch(rctx.device_name, changer->hdr.name, 0) == 0) {
+      if (strcmp(rctx.device_name, changer->hdr.name) == 0) {
          /* Try each device in this AutoChanger */
          foreach_alist(rctx.device, changer->device) {
             Dmsg2(dbglvl, "jid=%u Try changer device %s\n", (int)rctx.jcr->JobId, 
@@ -1022,7 +1017,7 @@ int search_res_for_device(RCTX &rctx)
       foreach_res(rctx.device, R_DEVICE) {
          Dmsg2(dbglvl, "jid=%u Try match res=%s\n", (int)rctx.jcr->JobId, rctx.device->hdr.name);
          /* Find resource, and make sure we were able to open it */
-         if (fnmatch(rctx.device_name, rctx.device->hdr.name, 0) == 0) {
+         if (strcmp(rctx.device_name, rctx.device->hdr.name) == 0) {
             stat = reserve_device(rctx);
             if (stat != 1) {             /* try another device */
                continue;
@@ -1522,7 +1517,10 @@ bail_out:
    jcr->unlock();
 }
 
-void release_msgs(JCR *jcr)
+/*
+ * Pop and release any reservations messages
+ */
+static void pop_reserve_messages(JCR *jcr)
 {
    alist *msgs;
    char *msg;
@@ -1535,7 +1533,21 @@ void release_msgs(JCR *jcr)
    while ((msg = (char *)msgs->pop())) {
       free(msg);
    }
-   delete msgs;
+bail_out:
+   jcr->unlock();
+}
+
+/*
+ * Also called from acquire.c 
+ */
+void release_reserve_messages(JCR *jcr)
+{
+   pop_reserve_messages(jcr);
+   jcr->lock();
+   if (!jcr->reserve_msgs) {
+      goto bail_out;
+   }
+   delete jcr->reserve_msgs;
    jcr->reserve_msgs = NULL;
 
 bail_out: