From de4aa5b8c831347ece0472d9077210ffb885e5f8 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 6 Jan 2008 09:29:19 +0000 Subject: [PATCH] More calls to volume_unused() git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6243 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/acquire.c | 3 ++- bacula/src/stored/block.c | 3 ++- bacula/src/stored/btape.c | 3 ++- bacula/src/stored/dircmd.c | 2 ++ bacula/src/stored/label.c | 18 +++++++++++------- bacula/src/stored/read_record.c | 3 ++- bacula/src/stored/reserve.c | 12 ++++++++---- bacula/technotes-2.3 | 5 +++++ 8 files changed, 34 insertions(+), 15 deletions(-) diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index cbd7616f30..198bb858cd 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2007 Free Software Foundation Europe e.V. + Copyright (C) 2002-2008 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. @@ -80,6 +80,7 @@ bool acquire_device_for_read(DCR *dcr) edit_int64(jcr->JobId, ed1)); goto get_out; } + volume_unused(dcr); /* release any current volume */ jcr->CurReadVolume++; for (i=1; iCurReadVolume; i++) { vol = vol->next; diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index d257f05b63..fc530139a2 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2007 Free Software Foundation Europe e.V. + Copyright (C) 2001-2008 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. @@ -772,6 +772,7 @@ static bool terminate_writing_volume(DCR *dcr) } bail_out: + volume_unused(dcr); /* mark volume unused */ dev->set_ateot(); /* no more writing this tape */ Dmsg1(50, "*** Leave terminate_writing_volume -- %s\n", ok?"OK":"ERROR"); return ok; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 81237ece1b..3cd7be3095 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2007 Free Software Foundation Europe e.V. + Copyright (C) 2000-2008 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. @@ -2732,6 +2732,7 @@ static bool my_mount_next_read_volume(DCR *dcr) Pmsg2(000, _("End of Volume \"%s\" %d records.\n"), dcr->VolumeName, quickie_count); + volume_unused(dcr); /* mark volume no longer needed */ if (LastBlock != block->BlockNumber) { VolBytes += block->block_len; } diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 95a05e075a..57e960f94c 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -512,6 +512,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, } bail_out: + volume_unused(dcr); /* no longer using */ if (!dev->is_open()) { dev->clear_volhdr(); } @@ -548,6 +549,7 @@ static bool read_label(DCR *dcr) ok = false; break; } + volume_unused(dcr); give_back_device_lock(dev, &hold); return ok; } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 5e6c75bfca..68fe6f1b52 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -257,6 +257,7 @@ int read_dev_volume_label(DCR *dcr) return VOL_OK; bail_out: + volume_unused(dcr); /* mark volume "released" */ empty_block(block); dev->rewind(dcr); Dmsg1(150, "return %d\n", stat); @@ -315,13 +316,15 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, Dmsg0(150, "write_volume_label()\n"); empty_block(dcr->block); - /* If relabeling, truncate the device */ - if (relabel && !dev->truncate(dcr)) { - goto bail_out; - } - - if (relabel && !dev->is_tape()) { - dev->close_part(dcr); /* make sure DVD/file closed for rename */ + if (relabel) { + volume_unused(dcr); /* mark current volume unused */ + /* Truncate device */ + if (!dev->truncate(dcr)) { + goto bail_out; + } + if (!dev->is_tape()) { + dev->close_part(dcr); /* make sure DVD/file closed for rename */ + } } /* Set the new filename for open, ... */ @@ -451,6 +454,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) return false; } if (recycle) { + volume_unused(dcr); /* mark volume unused */ if (!dev->truncate(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Truncate error on device %s: ERR=%s\n"), dev->print_name(), dev->print_errmsg()); diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index 69707e247d..4190d11848 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2007 Free Software Foundation Europe e.V. + Copyright (C) 2002-2008 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. @@ -82,6 +82,7 @@ bool read_records(DCR *dcr, DEV_RECORD *trec = new_record(); Jmsg(jcr, M_INFO, 0, _("End of Volume at file %u on device %s, Volume \"%s\"\n"), dev->file, dev->print_name(), dcr->VolumeName); + volume_unused(dcr); /* mark volume unused */ if (!mount_cb(dcr)) { Jmsg(jcr, M_INFO, 0, _("End of all volumes.\n")); ok = false; /* Stop everything */ diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 0c15236e13..e65c6bb984 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -330,19 +330,20 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) vol = dev->vol; /* * Make sure we don't remove the current volume we are inserting - * because it was probably inserted by another job. + * because it was probably inserted by another job, or it + * is not being used and is marked as released. */ if (strcmp(vol->vol_name, VolumeName) == 0) { Dmsg1(dbglvl, "OK, vol=%s on device.\n", VolumeName); + vol->released = false; /* retake vol if released previously */ goto get_out; /* Volume already on this device */ } else { /* Don't release a volume if it is in use */ -#ifdef xxx if (!vol->released) { + Dmsg1(dbglvl, "Cannot free vol=%s. It is not released.\n", vol->vol_name); vol = NULL; /* vol in use */ goto get_out; } -#endif Dmsg2(dbglvl, "reserve_vol free vol=%s at %p\n", vol->vol_name, vol->vol_name); unload_autochanger(dcr, -1); /* unload the volume */ free_volume(dev); @@ -475,7 +476,6 @@ void unreserve_device(DCR *dcr) dev->num_writers = 0; } } - volume_unused(dcr); } @@ -515,6 +515,10 @@ bool volume_unused(DCR *dcr) if (dev->is_tape() || dev->is_autochanger()) { return true; } else { + /* + * Note, this frees the volume reservation entry, but the + * file descriptor remains open with the OS. + */ return free_volume(dev); } } diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 1d35512bfb..6b112fa4af 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,11 @@ Technical notes on version 2.3 General: +06Jan08 +kes A few more tweaks to new reservation code. Make sure to clear + vol released flag when retaking volume. When reading label and + label is bad mark volume unused. When recycling, mark volume + unused so it can be renamed. 05Jan08 kes Fix reserve_volume() so it doesn't release a volume in use (i.e. a volume entry not marked released). This should be -- 2.39.5