From: Kern Sibbald Date: Sun, 21 Feb 2010 18:22:11 +0000 (+0100) Subject: Fix three-pool regress bug X-Git-Tag: Release-5.2.1~1693 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8bf85e1528db0f4906b9a7b0cc00e1cdb0af4651;p=bacula%2Fbacula Fix three-pool regress bug --- diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 4c9f627a1f..3ab87943e6 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-2009 Free Software Foundation Europe e.V. + Copyright (C) 2002-2010 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. @@ -154,7 +154,7 @@ bool acquire_device_for_read(DCR *dcr) Dmsg1(50, "Media Type change. New read device %s chosen.\n", dev->print_name()); bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName)); - bstrncpy(dcr->VolCatInfo.VolCatName, vol->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(vol->VolumeName); bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type)); dcr->VolCatInfo.Slot = vol->Slot; dcr->VolCatInfo.InChanger = vol->Slot > 0; @@ -387,7 +387,7 @@ DCR *acquire_device_for_append(DCR *dcr) * we need to recycle the tape. */ if (dev->num_writers == 0) { - memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo)); + dev->VolCatInfo = dcr->VolCatInfo; /* structure assignment */ } have_vol = dcr->is_tape_position_ok(); } @@ -480,10 +480,10 @@ bool release_device(DCR *dcr) Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers); if (dev->is_labeled()) { Dmsg2(200, "dir_create_jobmedia. Release vol=%s dev=%s\n", - dev->VolCatInfo.VolCatName, dev->print_name()); + dev->getVolCatName(), dev->print_name()); if (!dev->at_weot() && !dir_create_jobmedia_record(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"), - dcr->VolCatInfo.VolCatName, jcr->Job); + dcr->getVolCatName(), jcr->Job); } /* If no more writers, and no errors, and wrote something, write an EOF */ if (!dev->num_writers && dev->can_write() && dev->block_num > 0) { @@ -495,7 +495,7 @@ bool release_device(DCR *dcr) /* Note! do volume update before close, which zaps VolCatInfo */ dir_update_volume_info(dcr, false, false); /* send Volume info to Director */ Dmsg2(200, "dir_update_vol_info. Release vol=%s dev=%s\n", - dev->VolCatInfo.VolCatName, dev->print_name()); + dev->getVolCatName(), dev->print_name()); } if (dev->num_writers == 0) { /* if not being used */ volume_unused(dcr); /* we obviously are not using the volume */ @@ -738,7 +738,7 @@ static void set_dcr_from_vol(DCR *dcr, VOL_LIST *vol) * for disaster recovery, we must "simulate" reading the catalog */ bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName)); - bstrncpy(dcr->VolCatInfo.VolCatName, vol->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(vol->VolumeName); bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type)); dcr->VolCatInfo.Slot = vol->Slot; dcr->VolCatInfo.InChanger = vol->Slot > 0; diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 38605b0a20..6e13beaa8f 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 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. @@ -31,7 +31,6 @@ * * Kern Sibbald, December 2000 * - * Version $Id$ */ #include "bacula.h" /* pull in global headers */ @@ -173,6 +172,7 @@ static bool do_get_volume_info(DCR *dcr) int n; int32_t InChanger; + dcr->setVolCatInfo(false); if (dir->recv() <= 0) { Dmsg0(200, "getvolname error bnet_recv\n"); Mmsg(jcr->errmsg, _("Network error on bnet_recv in req_vol_info.\n")); @@ -197,6 +197,7 @@ static bool do_get_volume_info(DCR *dcr) return false; } vol.InChanger = InChanger; /* bool in structure */ + vol.is_valid = true; unbash_spaces(vol.VolCatName); bstrncpy(dcr->VolumeName, vol.VolCatName, sizeof(dcr->VolumeName)); dcr->VolCatInfo = vol; /* structure assignment */ @@ -223,12 +224,12 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) BSOCK *dir = jcr->dir_bsock; P(vol_info_mutex); - bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); - bash_spaces(dcr->VolCatInfo.VolCatName); - dir->fsend(Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName, + dcr->setVolCatName(dcr->VolumeName); + bash_spaces(dcr->getVolCatName()); + dir->fsend(Get_Vol_Info, jcr->Job, dcr->getVolCatName(), writing==GET_VOL_INFO_FOR_WRITE?1:0); Dmsg1(100, ">dird %s", dir->msg); - unbash_spaces(dcr->VolCatInfo.VolCatName); + unbash_spaces(dcr->getVolCatName()); bool ok = do_get_volume_info(dcr); V(vol_info_mutex); return ok; diff --git a/bacula/src/stored/autochanger.c b/bacula/src/stored/autochanger.c index 792dfe3bcb..a0d7e99fc7 100644 --- a/bacula/src/stored/autochanger.c +++ b/bacula/src/stored/autochanger.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2008 Free Software Foundation Europe e.V. + Copyright (C) 2002-2010 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. @@ -31,7 +31,6 @@ * * Kern Sibbald, August MMII * - * Version $Id$ */ #include "bacula.h" /* pull in global headers */ @@ -130,7 +129,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir) slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0; Dmsg3(100, "autoload: slot=%d InChgr=%d Vol=%s\n", dcr->VolCatInfo.Slot, - dcr->VolCatInfo.InChanger, dcr->VolCatInfo.VolCatName); + dcr->VolCatInfo.InChanger, dcr->getVolCatName()); /* * Handle autoloaders here. If we cannot autoload it, we * will return 0 so that the sysop will be asked to load it. @@ -151,7 +150,7 @@ int autoload_device(DCR *dcr, int writing, BSOCK *dir) changer = get_pool_memory(PM_FNAME); if (slot <= 0) { Jmsg(jcr, M_INFO, 0, _("Invalid slot=%d defined in catalog for Volume \"%s\" " - "on %s. Manual load may be required.\n"), slot, dcr->VolCatInfo.VolCatName, + "on %s. Manual load may be required.\n"), slot, dcr->getVolCatName(), dev->print_name()); rtn_stat = 0; } else if (!dcr->device->changer_name) { diff --git a/bacula/src/stored/bcopy.c b/bacula/src/stored/bcopy.c index 5467397f79..7328d58d5e 100644 --- a/bacula/src/stored/bcopy.c +++ b/bacula/src/stored/bcopy.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2002-2008 Free Software Foundation Europe e.V. + Copyright (C) 2002-2010 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. @@ -382,8 +382,8 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr, int /*mode*/) bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { Dmsg0(100, "Fake dir_get_volume_info\n"); - bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(dcr->VolumeName); dcr->VolCatInfo.VolCatParts = find_num_dvd_parts(dcr); - Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); + Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->getVolCatName(), dcr->VolCatInfo.VolCatParts); return 1; } diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index d0bdc05685..f4aa3dbaa6 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 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. @@ -31,8 +31,6 @@ * * Kern E. Sibbald, MM * - * Version $Id$ - * */ #include "bacula.h" @@ -522,8 +520,8 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr, int /*mode*/) bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { Dmsg0(100, "Fake dir_get_volume_info\n"); - bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(dcr->VolumeName); dcr->VolCatInfo.VolCatParts = find_num_dvd_parts(dcr); - Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); + Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->getVolCatName(), dcr->VolCatInfo.VolCatParts); return 1; } diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index a36edfeef5..e4a12fe934 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-2009 Free Software Foundation Europe e.V. + Copyright (C) 2001-2010 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. @@ -32,8 +32,6 @@ * Kern Sibbald, March MMI * added BB02 format October MMII * - * Version $Id$ - * */ @@ -368,7 +366,7 @@ bool write_block_to_device(DCR *dcr) if (!dir_create_jobmedia_record(dcr)) { dev->dev_errno = EIO; Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"), - dcr->VolCatInfo.VolCatName, jcr->Job); + dcr->getVolCatName(), jcr->Job); set_new_volume_parameters(dcr); stat = false; goto bail_out; @@ -577,7 +575,7 @@ bool write_block_to_dev(DCR *dcr) } if (dev->dev_errno == ENOSPC) { Jmsg(jcr, M_INFO, 0, _("End of Volume \"%s\" at %u:%u on device %s. Write of %u bytes got %d.\n"), - dev->VolCatInfo.VolCatName, + dev->getVolCatName(), dev->file, dev->block_num, dev->print_name(), wlen, stat); } if (debug_level >= 100) { @@ -732,7 +730,7 @@ static bool terminate_writing_volume(DCR *dcr) Dmsg0(190, "Error from create JobMedia\n"); dev->dev_errno = EIO; Jmsg2(dcr->jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"), - dcr->VolCatInfo.VolCatName, dcr->jcr->Job); + dcr->getVolCatName(), dcr->jcr->Job); ok = false; } dcr->block->write_failed = true; @@ -806,7 +804,7 @@ static bool do_new_file_bookkeeping(DCR *dcr) Dmsg0(190, "Error from create_job_media.\n"); dev->dev_errno = EIO; Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"), - dcr->VolCatInfo.VolCatName, jcr->Job); + dcr->getVolCatName(), jcr->Job); terminate_writing_volume(dcr); dev->dev_errno = EIO; return false; @@ -884,7 +882,7 @@ static bool do_dvd_size_checks(DCR *dcr) Dmsg1(100, "Cannot get free space on the device ERR=%s.\n", dev->errmsg); Jmsg(jcr, M_FATAL, 0, _("End of Volume \"%s\" at %u:%u on device %s " "(part_size=%s, free_space=%s, free_space_errno=%d, errmsg=%s).\n"), - dev->VolCatInfo.VolCatName, + dev->getVolCatName(), dev->file, dev->block_num, dev->print_name(), edit_uint64_with_commas(dev->part_size, ed1), edit_uint64_with_commas(dev->free_space, ed2), dev->free_space_errno, dev->errmsg); @@ -897,7 +895,7 @@ static bool do_dvd_size_checks(DCR *dcr) Dmsg0(100, "==== Just enough free space on the device to write the current part...\n"); Jmsg(jcr, M_INFO, 0, _("End of Volume \"%s\" at %u:%u on device %s " "(part_size=%s, free_space=%s, free_space_errno=%d).\n"), - dev->VolCatInfo.VolCatName, + dev->getVolCatName(), dev->file, dev->block_num, dev->print_name(), edit_uint64_with_commas(dev->part_size, ed1), edit_uint64_with_commas(dev->free_space, ed2), dev->free_space_errno); diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index cb270d955d..4a53a64b57 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -484,8 +484,8 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr, int /*mode*/) bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { Dmsg0(100, "Fake dir_get_volume_info\n"); - bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(dcr->VolumeName); dcr->VolCatInfo.VolCatParts = find_num_dvd_parts(dcr); - Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); + Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->getVolCatName(), dcr->VolCatInfo.VolCatParts); return 1; } diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 854f70dffa..3c09d96bf1 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -33,8 +33,6 @@ * * Kern E. Sibbald, December 2001 * - * - * Version $Id$ */ #include "bacula.h" @@ -333,7 +331,7 @@ static bool bscan_mount_next_read_volume(DCR *dcr) { DEVICE *dev = dcr->dev; DCR *mdcr; - Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->VolCatInfo.VolCatName); + Dmsg1(100, "Walk attached jcrs. Volume=%s\n", dev->getVolCatName()); foreach_dlist(mdcr, dev->attached_dcrs) { JCR *mjcr = mdcr->jcr; Dmsg1(000, "========== JobId=%u ========\n", mjcr->JobId); @@ -351,7 +349,7 @@ static bool bscan_mount_next_read_volume(DCR *dcr) mjcr->read_dcr->VolLastIndex = dcr->VolLastIndex; if (!create_jobmedia_record(db, mjcr)) { Pmsg2(000, _("Could not create JobMedia record for Volume=%s Job=%s\n"), - dev->VolCatInfo.VolCatName, mjcr->Job); + dev->getVolCatName(), mjcr->Job); } } @@ -1336,8 +1334,8 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr, int /*mode*/) bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { Dmsg0(100, "Fake dir_get_volume_info\n"); - bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(dcr->VolumeName); dcr->VolCatInfo.VolCatParts = find_num_dvd_parts(dcr); - Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatParts); + Dmsg2(500, "Vol=%s num_parts=%d\n", dcr->getVolCatName(), dcr->VolCatInfo.VolCatParts); return 1; } diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index d8cbc56bde..38a8236707 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-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 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. @@ -3005,7 +3005,7 @@ bool dir_update_volume_info(DCR *dcr, bool relabel, bool update_LastWritten) bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { Dmsg0(20, "Enter dir_get_volume_info\n"); - bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(dcr->VolumeName); return 1; } @@ -3117,8 +3117,8 @@ static void set_volume_name(const char *VolName, int volnum) DCR *dcr = jcr->dcr; VolumeName = VolName; vol_num = volnum; - bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName)); - bstrncpy(dcr->VolCatInfo.VolCatName, VolName, sizeof(dcr->VolCatInfo.VolCatName)); + dev->setVolCatName(VolName); + dcr->setVolCatName(VolName); bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName)); dcr->VolCatInfo.Slot = volnum; dcr->VolCatInfo.InChanger = true; diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 3673caa22c..aa0425f6aa 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 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. @@ -47,7 +47,6 @@ * daemon. More complicated coding (double buffering, writer * thread, ...) is left for a later version. * - * Version $Id$ */ /* @@ -354,11 +353,11 @@ DEVICE::open(DCR *dcr, int omode) } } if (dcr) { - bstrncpy(VolCatInfo.VolCatName, dcr->VolumeName, sizeof(VolCatInfo.VolCatName)); + VolCatInfo = dcr->VolCatInfo; /* structure assign */ } Dmsg4(100, "open dev: type=%d dev_name=%s vol=%s mode=%s\n", dev_type, - print_name(), VolCatInfo.VolCatName, mode_to_str(omode)); + print_name(), getVolCatName(), mode_to_str(omode)); state &= ~(ST_LABEL|ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF); label_type = B_BACULA_LABEL; if (is_tape() || is_fifo()) { @@ -531,7 +530,7 @@ void DEVICE::open_file_device(DCR *dcr, int omode) if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) { pm_strcat(archive_name, "/"); } - pm_strcat(archive_name, VolCatInfo.VolCatName); + pm_strcat(archive_name, getVolCatName()); } mount(1); /* do mount if required */ @@ -559,8 +558,8 @@ void DEVICE::open_file_device(DCR *dcr, int omode) } /* - * Open a DVD device. N.B. at this point, dcr->VolCatInfo.VolCatName - * (NB:??? I think it's VolCatInfo.VolCatName that is right) + * Open a DVD device. N.B. at this point, dcr->getVolCatName() + * (NB:??? I think it's getVolCatName() that is right) * has the desired Volume name, but there is NO assurance that * any other field of VolCatInfo is correct. */ @@ -584,7 +583,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode) * copy here, when opening. */ VolCatInfo = dcr->VolCatInfo; /* structure assignment */ - Dmsg1(100, "Volume=%s\n", VolCatInfo.VolCatName); + Dmsg1(100, "Volume=%s\n", getVolCatName()); if (VolCatInfo.VolCatName[0] == 0) { Dmsg1(10, "Could not open DVD device %s. No Volume name given.\n", @@ -1913,6 +1912,7 @@ void DEVICE::clear_volhdr() { Dmsg1(100, "Clear volhdr vol=%s\n", VolHdr.VolumeName); memset(&VolHdr, 0, sizeof(VolHdr)); + setVolCatInfo(false); } @@ -2475,7 +2475,7 @@ int32_t DEVICE::get_os_tape_file() char * dev_vol_name(DEVICE *dev) { - return dev->VolCatInfo.VolCatName; + return dev->getVolCatName(); } diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 93baea05f7..bd7344e8b9 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 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. @@ -31,8 +31,6 @@ * * Kern Sibbald, MM * - * Version $Id$ - * */ /* @@ -193,6 +191,7 @@ struct VOLUME_CAT_INFO { utime_t VolFirstWritten; /* Time of first write */ utime_t VolLastWritten; /* Time of last write */ bool InChanger; /* Set if vol in current magazine */ + bool is_valid; /* set if this data is valid */ char VolCatStatus[20]; /* Volume status */ char VolCatName[MAX_NAME_LENGTH]; /* Desired volume to mount */ }; @@ -394,6 +393,13 @@ public: char *bstrerror(void) { return errmsg; }; char *print_errmsg() { return errmsg; }; int32_t get_slot() const { return m_slot; }; + void setVolCatInfo(bool valid) { VolCatInfo.is_valid = valid; }; + bool haveVolCatInfo() const { return VolCatInfo.is_valid; }; + void setVolCatName(const char *name) { + bstrncpy(VolCatInfo.VolCatName, name, sizeof(VolCatInfo.VolCatName)); + setVolCatInfo(false); + }; + char *getVolCatName() { return VolCatInfo.VolCatName; }; void set_unload(); /* in dev.c */ void clear_volhdr(); /* in dev.c */ @@ -549,6 +555,13 @@ public: void dunlock() { m_dev_locked = false; dev->dunlock(); } #endif void dblock(int why) { dev->dblock(why); } + void setVolCatInfo(bool valid) { VolCatInfo.is_valid = valid; }; + bool haveVolCatInfo() const { return VolCatInfo.is_valid; }; + void setVolCatName(const char *name) { + bstrncpy(VolCatInfo.VolCatName, name, sizeof(VolCatInfo.VolCatName)); + setVolCatInfo(false); + }; + char *getVolCatName() { return VolCatInfo.VolCatName; }; /* Methods in reserve.c */ diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index a3eb0c5d98..6fb4082bde 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2009 Free Software Foundation Europe e.V. + Copyright (C) 2000-2010 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. @@ -110,7 +110,7 @@ bool fixup_device_block_write_error(DCR *dcr, int retries) /* Continue unlocked, but leave BLOCKED */ dev->dunlock(); - bstrncpy(PrevVolName, dev->VolCatInfo.VolCatName, sizeof(PrevVolName)); + bstrncpy(PrevVolName, dev->getVolCatName(), sizeof(PrevVolName)); bstrncpy(dev->VolHdr.PrevVolumeName, PrevVolName, sizeof(dev->VolHdr.PrevVolumeName)); label_blk = new_block(dev); @@ -160,7 +160,7 @@ bool fixup_device_block_write_error(DCR *dcr, int retries) /* * Walk through all attached jcrs indicating the volume has changed */ - Dmsg1(100, "Notify vol change. Volume=%s\n", dev->VolCatInfo.VolCatName); + Dmsg1(100, "Notify vol change. Volume=%s\n", dev->getVolCatName()); DCR *mdcr; foreach_dlist(mdcr, dev->attached_dcrs) { JCR *mjcr = mdcr->jcr; diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 5ee4d6756f..05cfdf4319 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -475,7 +475,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, dev->truncating = true; /* let open() know we will truncate it */ } /* Set old volume name for open if relabeling */ - bstrncpy(dcr->VolCatInfo.VolCatName, volname, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(volname); if (dev->open(dcr, mode) < 0) { dir->fsend(_("3910 Unable to open device %s: ERR=%s\n"), dev->print_name(), dev->bstrerror()); @@ -486,7 +486,7 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, label_status = read_dev_volume_label(dcr); /* Set new volume name */ - bstrncpy(dcr->VolCatInfo.VolCatName, newname, sizeof(dcr->VolCatInfo.VolCatName)); + dcr->setVolCatName(newname); switch(label_status) { case VOL_NAME_ERROR: case VOL_VERSION_ERROR: diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index 0496359b4a..8dd3147206 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2005-2008 Free Software Foundation Europe e.V. + Copyright (C) 2005-2010 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. @@ -32,7 +32,6 @@ * * Nicolas Boichat, MMV * - * Version $Id$ */ #include "bacula.h" @@ -69,7 +68,7 @@ static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name) pm_strcat(archive_name, "/"); } - pm_strcat(archive_name, dev->VolCatInfo.VolCatName); + pm_strcat(archive_name, dev->getVolCatName()); /* if part > 1, append .# to the filename (where # is the part number) */ if (dev->part > 1) { pm_strcat(archive_name, "."); @@ -308,7 +307,7 @@ int dvd_open_next_part(DCR *dcr) Dmsg6(29, "Enter: == open_next_part part=%d npart=%d dev=%s vol=%s mode=%d file_addr=%d\n", dev->part, dev->num_dvd_parts, dev->print_name(), - dev->VolCatInfo.VolCatName, dev->openmode, dev->file_addr); + dev->getVolCatName(), dev->openmode, dev->file_addr); if (!dev->is_dvd()) { Dmsg1(100, "Device %s is not dvd!!!!\n", dev->print_name()); return -1; @@ -383,7 +382,7 @@ int dvd_open_next_part(DCR *dcr) #endif } - Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName, + Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName(), dev->openmode); /* Open next part. Note, this sets part_size for part opened. */ @@ -405,12 +404,12 @@ static bool dvd_open_first_part(DCR *dcr, int mode) DEVICE *dev = dcr->dev; Dmsg5(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_dvd_parts=%d append=%d\n", dev->print_name(), - dev->VolCatInfo.VolCatName, dev->openmode, dev->num_dvd_parts, dev->can_append()); + dev->getVolCatName(), dev->openmode, dev->num_dvd_parts, dev->can_append()); dev->close_part(dcr); - Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName, + Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName(), mode); Dmsg0(100, "Set part=1\n"); dev->part = 1; @@ -609,7 +608,7 @@ void dvd_remove_empty_part(DCR *dcr) status = stat(archive_name.c_str(), &statp); if (status == 0 && statp.st_size == 0) { Dmsg3(100, "Unlink empty part in close call make_dvd_filename. part=%d num=%d vol=%s\n", - part_save, dev->num_dvd_parts, dev->VolCatInfo.VolCatName); + part_save, dev->num_dvd_parts, dev->getVolCatName()); Dmsg1(100, "unlink(%s)\n", archive_name.c_str()); unlink(archive_name.c_str()); if (part_save == dev->part) { @@ -733,7 +732,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr) break; } else { Dmsg2(99, "check_can_write_on_non_blank_dvd: found %s (versus %s)\n", - result->d_name, dev->VolCatInfo.VolCatName); + result->d_name, dev->getVolCatName()); if (strcmp(result->d_name, ".") && strcmp(result->d_name, "..") && strcmp(result->d_name, ".keep")) { /* Found a file, checking it is empty */ @@ -784,7 +783,7 @@ int find_num_dvd_parts(DCR *dcr) DIR* dp; struct dirent *entry, *result; int name_max; - int len = strlen(dcr->VolCatInfo.VolCatName); + int len = strlen(dcr->getVolCatName()); /* Now count the number of parts */ name_max = pathconf(".", _PC_NAME_MAX); @@ -802,7 +801,7 @@ int find_num_dvd_parts(DCR *dcr) entry = (struct dirent *)malloc(sizeof(struct dirent) + name_max + 1000); - Dmsg1(100, "Looking for Vol=%s\n", dcr->VolCatInfo.VolCatName); + Dmsg1(100, "Looking for Vol=%s\n", dcr->getVolCatName()); for ( ;; ) { int flen; bool ignore; @@ -816,7 +815,7 @@ int find_num_dvd_parts(DCR *dcr) ignore = true; if (flen >= len) { result->d_name[len] = 0; - if (strcmp(dcr->VolCatInfo.VolCatName, result->d_name) == 0) { + if (strcmp(dcr->getVolCatName(), result->d_name) == 0) { num_parts++; Dmsg1(100, "find_num_dvd_parts: found part: %s\n", result->d_name); ignore = false; diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 99f285b550..e2b5a94d61 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -321,8 +321,8 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, } /* Set the new filename for open, ... */ - bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName)); - bstrncpy(dcr->VolCatInfo.VolCatName, VolName, sizeof(dcr->VolCatInfo.VolCatName)); + dev->setVolCatName(VolName); + dcr->setVolCatName(VolName); Dmsg1(150, "New VolName=%s\n", VolName); if (dev->open(dcr, OPEN_READ_WRITE) < 0) { /* If device is not tape, attempt to create it */ @@ -440,6 +440,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) } Dmsg1(150, "wrote vol label to block. Vol=%s\n", dcr->VolumeName); + dev->setVolCatInfo(false); dev->VolCatInfo.VolCatBytes = 0; /* reset byte count */ /* @@ -513,7 +514,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) } Dmsg1(150, "dir_update_vol_info. Set Append vol=%s\n", dcr->VolumeName); bstrncpy(dev->VolCatInfo.VolCatStatus, "Append", sizeof(dev->VolCatInfo.VolCatStatus)); - bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName)); + dev->setVolCatName(dcr->VolumeName); if (!dir_update_volume_info(dcr, true, true)) { /* indicate doing relabel */ return false; } diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index da54fb3a5d..6e8fabaab4 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -123,7 +123,7 @@ mount_next_vol: goto bail_out; } Dmsg3(150, "After find_next_append. Vol=%s Slot=%d Parts=%d\n", - VolCatInfo.VolCatName, VolCatInfo.Slot, VolCatInfo.VolCatParts); + getVolCatName(), VolCatInfo.Slot, VolCatInfo.VolCatParts); /* * Get next volume and ready it for append @@ -137,6 +137,7 @@ mount_next_vol: * */ unlock_volumes(); + dcr->setVolCatInfo(false); /* out of date when Vols unlocked */ if (autoload_device(dcr, true/*writing*/, NULL) > 0) { autochanger = true; ask = false; @@ -166,6 +167,7 @@ mount_next_vol: if (ask) { unlock_volumes(); + dcr->setVolCatInfo(false); /* out of date when Vols unlocked */ if (!dir_ask_sysop_to_mount_volume(dcr, ST_APPEND)) { Dmsg0(150, "Error return ask_sysop ...\n"); goto no_lock_bail_out; @@ -241,6 +243,16 @@ read_volume: case check_ok: break; } + /* + * Check that volcatinfo is good + */ + if (!dev->haveVolCatInfo()) { + Dmsg0(000, "Do not have volcatinfo\n"); + if (!find_a_volume()) { + goto mount_next_vol; + } + dev->VolCatInfo = VolCatInfo; /* structure assignment */ + } /* * See if we have a fresh tape or a tape with data. @@ -347,7 +359,10 @@ bool DCR::find_a_volume() } } } - return true; + if (dcr->haveVolCatInfo()) { + return true; + } + return dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE); } int DCR::check_volume_label(bool &ask, bool &autochanger) @@ -370,6 +385,7 @@ int DCR::check_volume_label(bool &ask, bool &autochanger) Dmsg2(150, "Want dirVol=%s dirStat=%s\n", VolumeName, VolCatInfo.VolCatStatus); + /* * At this point, dev->VolCatInfo has what is in the drive, if anything, * and dcr->VolCatInfo has what the Director wants. @@ -446,6 +462,8 @@ int DCR::check_volume_label(bool &ask, bool &autochanger) Jmsg2(jcr, M_WARNING, 0, _("Could not reserve volume %s on %s\n"), dev->VolHdr.VolumeName, dev->print_name()); ask = true; + dev->setVolCatInfo(false); + setVolCatInfo(false); goto check_next_volume; } break; /* got a Volume */ @@ -490,6 +508,8 @@ int DCR::check_volume_label(bool &ask, bool &autochanger) return check_ok; check_next_volume: + dev->setVolCatInfo(false); + setVolCatInfo(false); return check_next_vol; check_bail_out: @@ -717,7 +737,7 @@ void DCR::mark_volume_not_inchanger() { Jmsg(jcr, M_ERROR, 0, _("Autochanger Volume \"%s\" not found in slot %d.\n" " Setting InChanger to zero in catalog.\n"), - VolCatInfo.VolCatName, VolCatInfo.Slot); + getVolCatName(), VolCatInfo.Slot); dev->VolCatInfo = VolCatInfo; /* structure assignment */ VolCatInfo.InChanger = false; dev->VolCatInfo.InChanger = false; diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index f2dde69b16..bd8639dd7d 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2009 Free Software Foundation Europe e.V. + Copyright (C) 2004-2010 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. @@ -30,7 +30,6 @@ * * Kern Sibbald, March 2004 * - * Version $Id$ */ #include "bacula.h" @@ -308,7 +307,7 @@ static bool despool_data(DCR *dcr, bool commit) if (!dir_create_jobmedia_record(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"), - dcr->VolCatInfo.VolCatName, jcr->Job); + dcr->getVolCatName(), jcr->Job); } /* Set new file/block parameters for current dcr */ set_new_file_parameters(dcr);