X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fdird%2Fnext_vol.c;fp=bacula%2Fsrc%2Fdird%2Fnext_vol.c;h=74238fc026e6238318bd4c6402a47918ec6ccab8;hb=b6a1f7208143a51f07573fe986fcea297f90944b;hp=ebae0779e9353d702977147b046d5c11a68d6fad;hpb=78717f3f0a57f3174a176ac9319a1b2eb485e9c3;p=bacula%2Fbacula diff --git a/bacula/src/dird/next_vol.c b/bacula/src/dird/next_vol.c index ebae0779e9..74238fc026 100644 --- a/bacula/src/dird/next_vol.c +++ b/bacula/src/dird/next_vol.c @@ -1,29 +1,17 @@ /* 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. */ /* * @@ -31,7 +19,7 @@ * 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 * */ @@ -40,12 +28,19 @@ 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; } /* @@ -58,7 +53,7 @@ void set_storageid_in_mr(STORE *store, MEDIA_DBR *mr) * 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; @@ -67,13 +62,15 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index, 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 */ @@ -119,7 +116,7 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index, 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", @@ -127,7 +124,7 @@ int find_next_volume_for_append(JCR *jcr, MEDIA_DBR *mr, int index, } /* * 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; @@ -216,7 +213,7 @@ bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr) /* 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; @@ -231,7 +228,7 @@ bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr) /* 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); @@ -241,7 +238,7 @@ bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr) /* 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; @@ -252,7 +249,7 @@ bool has_volume_expired(JCR *jcr, MEDIA_DBR *mr) /* 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; @@ -374,10 +371,10 @@ bool get_scratch_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr, /* 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)); @@ -385,9 +382,6 @@ bool get_scratch_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr, 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)); @@ -410,19 +404,19 @@ bool get_scratch_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr, 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"), @@ -450,9 +444,9 @@ bool get_scratch_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr, 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; } }