]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dircmd.c
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / stored / dircmd.c
index 1a2e933e7a837a231f954c95e6992fe995e8b770..c7b03140846ef64d724411c77013014d4160e563 100644 (file)
@@ -1,8 +1,7 @@
 /*
    Bacula(R) - The Network Backup Solution
 
-   Copyright (C) 2000-2015 Kern Sibbald
-   Copyright (C) 2001-2014 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2016 Kern Sibbald
 
    The original author of Bacula is Kern Sibbald, with contributions
    from many others, a complete list can be found in the file AUTHORS.
@@ -541,7 +540,7 @@ static bool do_label(JCR *jcr, int relabel)
    POOLMEM *newname, *oldname, *poolname, *mtype;
    POOL_MEM dev_name;
    BSOCK *dir = jcr->dir_bsock;
-   DCR *dcr;
+   DCR *dcr = NULL;;
    DEVICE *dev;
    bool ok = false;
    int32_t slot, drive;
@@ -572,8 +571,28 @@ static bool do_label(JCR *jcr, int relabel)
       unbash_spaces(mtype);
       dcr = find_device(jcr, dev_name, mtype, drive);
       if (dcr) {
+         uint32_t max_jobs;
          dev = dcr->dev;
+         ok = true;
          dev->Lock();                 /* Use P to avoid indefinite block */
+         max_jobs = dev->max_concurrent_jobs;
+         dev->max_concurrent_jobs = 1;
+         bstrncpy(dcr->VolumeName, newname, sizeof(dcr->VolumeName));
+         if (dcr->can_i_write_volume()) {
+            if (reserve_volume(dcr, newname) == NULL) {
+               ok = false;
+            }
+            Dmsg1(000, "Reserved volume \"%s\"\n", newname);
+         } else {
+            ok = false;
+         }
+         if (!ok) {
+            Dmsg2(000, "Reserve error on volume \"%s\": ERR=%s\n", newname, jcr->errmsg);
+            dir->fsend(_("3908 Error reserving volume: %s\n"), jcr->errmsg);
+            dev->max_concurrent_jobs = max_jobs;
+            dev->Unlock();
+            goto bail_out;
+         }
          if (!dev->is_open() && !dev->is_busy()) {
             Dmsg1(400, "Can %slabel. Device is not open\n", relabel?"re":"");
             label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel);
@@ -588,8 +607,9 @@ static bool do_label(JCR *jcr, int relabel)
             Dmsg0(400, "Can relabel. device not used\n");
             label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel);
          }
+         dev->max_concurrent_jobs = max_jobs;
+         volume_unused(dcr);
          dev->Unlock();
-         free_dcr(dcr);
       } else {
          dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), dev_name.c_str());
       }
@@ -598,6 +618,10 @@ static bool do_label(JCR *jcr, int relabel)
       pm_strcpy(jcr->errmsg, dir->msg);
       dir->fsend(_("3903 Error scanning label command: %s\n"), jcr->errmsg);
    }
+bail_out:
+   if (dcr) {
+      free_dcr(dcr);
+   }
    free_memory(oldname);
    free_memory(newname);
    free_memory(poolname);