/*
- Bacula® - The Network Backup Solution
-
- Copyright (C) 2001-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.
- This program is Free Software; you can redistribute it and/or
- modify it under the terms of version three of the GNU Affero General Public
- License as published by the Free Software Foundation and included
- in the file LICENSE.
-
- 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 Affero General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Bacula® is a registered trademark of Kern Sibbald.
- The licensor of Bacula is the Free Software Foundation Europe
- (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
- Switzerland, email:ftf@fsfeurope.org.
+ Bacula(R) - The Network Backup Solution
+
+ Copyright (C) 2000-2017 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.
+
+ You may use this file and others of this release according to the
+ license defined in the LICENSE file, which includes the Affero General
+ Public License, v3.0 ("AGPLv3") and some additional permissions and
+ terms pursuant to its AGPLv3 Section 7.
+
+ This notice must be preserved when any source code is
+ conveyed and/or propagated.
+
+ Bacula(R) is a registered trademark of Kern Sibbald.
*/
/*
- *
* Bacula Director -- next_vol -- handles finding the next
* volume for append. Split out of catreq.c August MMIII
* catalog request from the Storage daemon.
-
- * Kern Sibbald, March MMI
*
+ * Kern Sibbald, March MMI
*/
#include "bacula.h"
static int const dbglvl = 50; /* debug level */
-/* Set storage id if possible */
+/*
+ * We setup the StorageId or StorageId group if it is
+ * an autochanger from the Storage and put it in
+ * the media record.
+ * store == NULL => use existing StorageId
+ */
void set_storageid_in_mr(STORE *store, MEDIA_DBR *mr)
{
- if (store != NULL) {
+ if (store == NULL) {
+ /* Just use the plain (single) StorageId */
+ mr->sid_group = edit_int64(mr->StorageId, mr->sid);
+ return;
+ }
+
+ /* At this point we know store != NULL */
+ mr->StorageId = store->StorageId;
+ /* Get to the parent of the autochanger (if any) */
+ if (store->changer) {
+ store = store->changer;
mr->StorageId = store->StorageId;
}
+ /* Go to the master shared storage head (if any) */
+ if (store->shared_storage && store->shared_storage->ac_group) {
+ store = store->shared_storage;
+ }
+ /* If it is an autochanger we should have an ac_group */
+ if (store->autochanger && store->ac_group) {
+ /* Note we keep the StorageId of the local autochanger */
+ mr->sid_group = store->ac_group;
+ } else {
+ /* Otherwise, we just use the plain (single) StorageId */
+ mr->sid_group = edit_int64(mr->StorageId, mr->sid);
+ }
+}
+
+static void add_volume_to_exclude_list(JCR *jcr, int index, MEDIA_DBR *mr)
+{
+ char ed1[50];
+ if (index == 1) {
+ *jcr->next_vol_list = 0;
+
+ } else if (*jcr->next_vol_list) {
+ pm_strcat(jcr->next_vol_list, ",");
+ }
+ pm_strcat(jcr->next_vol_list, edit_int64(mr->MediaId, ed1));
+
+ /* The list is valid only in find_next_volume_for_append() */
+ mr->exclude_list = NULL;
+}
+
+static void set_volume_to_exclude_list(JCR *jcr, int index, MEDIA_DBR *mr)
+{
+ if (index == 1) {
+ *jcr->next_vol_list = 0;
+ }
+ mr->exclude_list = jcr->next_vol_list;
}
/*
* MEDIA_DBR mr with PoolId set
* create -- whether or not to create a new volume
*/
-int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index,
+int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index,
bool create, bool prune)
{
int retry = 0;
STORE *store = jcr->wstore;
bstrncpy(mr->MediaType, store->media_type, sizeof(mr->MediaType));
- Dmsg3(dbglvl, "find_next_vol_for_append: JobId=%u PoolId=%d, MediaType=%s\n",
- (uint32_t)jcr->JobId, (int)mr->PoolId, mr->MediaType);
+ Dmsg6(dbglvl, "find_next_vol_for_append: JobId=%u PoolId=%d, MediaType=%s index=%d create=%d prune=%d\n",
+ (uint32_t)jcr->JobId, (int)mr->PoolId, mr->MediaType, index,
+ create, prune);
/*
* If we are using an Autochanger, restrict Volume
* search to the Autochanger on the first pass
*/
- InChanger = store->autochanger;
+ InChanger = (store->autochanger)? true : false;
+
+ /* Make sure we don't send two times the same volume in the same session */
+ set_volume_to_exclude_list(jcr, index, mr);
+
/*
* Find the Next Volume for Append
*/
ok, index, InChanger, mr->VolStatus);
/*
* 5. Try pulling a volume from the Scratch pool
- */
+ */
ok = get_scratch_volume(jcr, InChanger, mr, store);
set_storageid_in_mr(store, mr); /* put StorageId in new record */
Dmsg4(dbglvl, "after get scratch volume ok=%d index=%d InChanger=%d Vstat=%s\n",
}
/*
* If we are using an Autochanger and have not found
- * a volume, retry looking for any volume.
+ * a volume, retry looking for any volume.
*/
if (!ok && InChanger) {
InChanger = false;
} /* end for loop */
db_unlock(jcr->db);
Dmsg1(dbglvl, "return ok=%d find_next_vol\n", ok);
+
+ /* We keep the record of all previous volumes requested */
+ if (ok) {
+ add_volume_to_exclude_list(jcr, index, mr);;
+ }
return ok;
}
/* First handle Max Volume Bytes */
if ((mr->MaxVolBytes > 0 && mr->VolBytes >= mr->MaxVolBytes)) {
Jmsg(jcr, M_INFO, 0, _("Max Volume bytes=%s exceeded. "
- "Marking Volume \"%s\" as Full.\n"),
+ "Marking Volume \"%s\" as Full.\n"),
edit_uint64_with_commas(mr->MaxVolBytes, ed1), mr->VolumeName);
bstrncpy(mr->VolStatus, "Full", sizeof(mr->VolStatus));
expired = true;
/* Now see if Max Jobs written to volume */
} else if (mr->MaxVolJobs > 0 && mr->MaxVolJobs <= mr->VolJobs) {
Jmsg(jcr, M_INFO, 0, _("Max Volume jobs=%s exceeded. "
- "Marking Volume \"%s\" as Used.\n"),
+ "Marking Volume \"%s\" as Used.\n"),
edit_uint64_with_commas(mr->MaxVolJobs, ed1), mr->VolumeName);
Dmsg3(dbglvl, "MaxVolJobs=%d JobId=%d Vol=%s\n", mr->MaxVolJobs,
(uint32_t)jcr->JobId, mr->VolumeName);
/* Now see if Max Files written to volume */
} else if (mr->MaxVolFiles > 0 && mr->MaxVolFiles <= mr->VolFiles) {
Jmsg(jcr, M_INFO, 0, _("Max Volume files=%s exceeded. "
- "Marking Volume \"%s\" as Used.\n"),
+ "Marking Volume \"%s\" as Used.\n"),
edit_uint64_with_commas(mr->MaxVolFiles, ed1), mr->VolumeName);
bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
expired = true;
/* See if Vol Use has expired */
if (mr->VolUseDuration <= (now - mr->FirstWritten)) {
Jmsg(jcr, M_INFO, 0, _("Max configured use duration=%s sec. exceeded. "
- "Marking Volume \"%s\" as Used.\n"),
+ "Marking Volume \"%s\" as Used.\n"),
edit_uint64_with_commas(mr->VolUseDuration, ed1), mr->VolumeName);
bstrncpy(mr->VolStatus, "Used", sizeof(mr->VolStatus));
expired = true;
/* Check if a duration or limit has expired */
if (has_volume_expired(jcr, mr)) {
*reason = _("volume has expired");
+ if (!mr->Recycle) { /* cannot recycle */
+ return;
+ }
/* Keep going because we may be able to recycle volume */
}
/* Only one thread at a time can pull from the scratch pool */
P(mutex);
- /*
+ /*
* Get Pool record for Scratch Pool
* choose between ScratchPoolId and Scratch
- * db_get_pool_record will first try ScratchPoolId,
+ * db_get_pool_numvols will first try ScratchPoolId,
* and then try the pool named Scratch
*/
memset(&spr, 0, sizeof(spr));
spr.PoolId = mr->ScratchPoolId;
if (db_get_pool_record(jcr, jcr->db, &spr)) {
smr.PoolId = spr.PoolId;
- if (InChanger) {
- smr.StorageId = mr->StorageId; /* want only Scratch Volumes in changer */
- }
bstrncpy(smr.VolStatus, "Append", sizeof(smr.VolStatus)); /* want only appendable volumes */
bstrncpy(smr.MediaType, mr->MediaType, sizeof(smr.MediaType));
if (found) {
POOL_MEM query(PM_MESSAGE);
- /*
+ /*
* Get pool record where the Scratch Volume will go to ensure
* that we can add a Volume.
*/
memset(&pr, 0, sizeof(pr));
bstrncpy(pr.Name, jcr->pool->name(), sizeof(pr.Name));
- if (!db_get_pool_record(jcr, jcr->db, &pr)) {
- Jmsg(jcr, M_WARNING, 0, _("Unable to get Pool record: ERR=%s"),
+ if (!db_get_pool_numvols(jcr, jcr->db, &pr)) {
+ Jmsg(jcr, M_WARNING, 0, _("Unable to get Pool record: ERR=%s"),
db_strerror(jcr->db));
goto bail_out;
}
-
+
/* Make sure there is room for another volume */
if (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
Jmsg(jcr, M_WARNING, 0, _("Unable add Scratch Volume, Pool \"%s\" full MaxVols=%d\n"),
goto bail_out;
}
- Jmsg(jcr, M_INFO, 0, _("Using Volume \"%s\" from 'Scratch' pool.\n"),
- mr->VolumeName);
-
+ Jmsg(jcr, M_INFO, 0, _("Using Volume \"%s\" from '%s' %spool.\n"),
+ mr->VolumeName, spr.Name,
+ ((strcmp(spr.Name, "Scratch") == 0) ? "" : "Scratch "));
+
ok = true;
}
}