/*
Bacula® - The Network Backup Solution
- Copyright (C) 2001-2012 Free Software Foundation Europe e.V.
+ Copyright (C) 2001-2014 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.
+ 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 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.
+ 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.
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.
*/
/*
*
* volume for append. Split out of catreq.c August MMIII
* catalog request from the Storage daemon.
- * Kern Sibbald, March MMI
+ * Written by Kern Sibbald, March MMI
*
*/
static int const dbglvl = 50; /* debug level */
-/* Set storage id if possible */
+/*
+ * We setup the StorageId 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) {
- mr->StorageId = store->StorageId;
+ if (!store) {
+ return;
}
+ /* At this point we know store != NULL */
+ mr->StorageId = store->StorageId;
}
/*
* 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;
+
/*
* 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;
/* 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;
/* 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"),
+ Jmsg(jcr, M_INFO, 0, _("Using Volume \"%s\" from 'Scratch' pool.\n"),
mr->VolumeName);
-
+
ok = true;
}
}