From ce03ce1beb289542dd6ea45c4750357ba0b07e96 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Wed, 25 Jun 2008 21:13:06 +0000 Subject: [PATCH] kes Add debug code and refactor subroutine in stored/mount.c kes Fix format problem in bscan output reported in bug #1105. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7231 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/bscan.c | 4 +- bacula/src/stored/dev.h | 3 +- bacula/src/stored/device.c | 2 + bacula/src/stored/mount.c | 95 ++++++++++++++++++++----------------- bacula/src/stored/reserve.c | 2 + bacula/technotes-2.5 | 3 ++ 6 files changed, 63 insertions(+), 46 deletions(-) diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index c55c0a0359..265a6201d5 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -293,7 +293,7 @@ int main (int argc, char *argv[]) struct stat sb; fstat(dev->fd(), &sb); currentVolumeSize = sb.st_size; - Pmsg1(000, _("First Volume Size = %sn"), + Pmsg1(000, _("First Volume Size = %s\n"), edit_uint64(currentVolumeSize, ed1)); } @@ -367,7 +367,7 @@ static bool bscan_mount_next_read_volume(DCR *dcr) struct stat sb; fstat(dev->fd(), &sb); currentVolumeSize = sb.st_size; - Pmsg1(000, _("First Volume Size = %sn"), + Pmsg1(000, _("First Volume Size = %s\n"), edit_uint64(currentVolumeSize, ed1)); } return stat; diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 9ef62f0d74..4abc2d7faf 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -95,7 +95,7 @@ enum { B_TAPE_DEV, B_DVD_DEV, B_FIFO_DEV, - B_VTAPE_DEV, /* change to B_TAPE_DEV after init */ + B_VTAPE_DEV, /* change to B_TAPE_DEV after init */ B_VTL_DEV }; @@ -545,6 +545,7 @@ public: void mark_volume_in_error(); void mark_volume_not_inchanger(); int try_autolabel(bool opened); + bool find_a_volume(); bool is_suitable_volume_mounted(); bool is_eod_valid(); int check_volume_label(bool &ask, bool &autochanger); diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index b3c4c91fc4..1675cbf831 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -122,6 +122,7 @@ bool fixup_device_block_write_error(DCR *dcr) edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2), bstrftime(dt, sizeof(dt), time(NULL))); + Dmsg0(050, "set_unload\n"); dev->set_unload(); if (!dcr->mount_next_write_volume()) { free_block(label_blk); @@ -129,6 +130,7 @@ bool fixup_device_block_write_error(DCR *dcr) dev->dlock(); goto bail_out; } + Dmsg1(050, "must_unload=%d\n", dev->must_unload()); dev->dlock(); /* lock again */ dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */ diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 26d0cb224f..8ae5a0ee3b 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -96,6 +96,7 @@ mount_next_vol: goto no_lock_bail_out; } lock_volumes(); + Dmsg1(150, "Continue after dir_ask_sysop_to_mount. must_load=%d\n", dev->must_load()); } if (job_canceled(jcr)) { Jmsg(jcr, M_FATAL, 0, _("Job %d canceled.\n"), jcr->JobId); @@ -108,34 +109,10 @@ mount_next_vol: } do_swapping(true /*writing*/); - if (!is_suitable_volume_mounted()) { - bool have_vol = false; - /* Do we have a candidate volume? */ - if (dev->vol) { - bstrncpy(VolumeName, dev->vol->vol_name, sizeof(VolumeName)); - have_vol = dir_get_volume_info(this, GET_VOL_INFO_FOR_WRITE); - } - /* - * Get Director's idea of what tape we should have mounted. - * in dcr->VolCatInfo - */ - if (!have_vol) { - Dmsg0(200, "Before dir_find_next_appendable_volume.\n"); - while (!dir_find_next_appendable_volume(dcr)) { - Dmsg0(200, "not dir_find_next\n"); - if (job_canceled(jcr)) { - goto bail_out; - } - unlock_volumes(); - if (!dir_ask_sysop_to_create_appendable_volume(dcr)) { - goto no_lock_bail_out; - } - lock_volumes(); - Dmsg0(200, "Again dir_find_next_append...\n"); - } - goto mount_next_vol; - } + if (!find_a_volume()) { + goto no_lock_bail_out; } + if (job_canceled(jcr)) { goto bail_out; } @@ -179,9 +156,13 @@ mount_next_vol: } Dmsg2(150, "Ask=%d autochanger=%d\n", ask, autochanger); - if (ask && !dir_ask_sysop_to_mount_volume(dcr, ST_APPEND)) { - Dmsg0(150, "Error return ask_sysop ...\n"); - goto bail_out; /* error return */ + if (ask) { + unlock_volumes(); + if (!dir_ask_sysop_to_mount_volume(dcr, ST_APPEND)) { + Dmsg0(150, "Error return ask_sysop ...\n"); + goto no_lock_bail_out; + } + lock_volumes(); } if (job_canceled(jcr)) { goto bail_out; @@ -225,30 +206,22 @@ mount_next_vol: if (try_autolabel(false) == try_read_vol) { break; /* created a new volume label */ } + Dmsg0(50, "set_unload\n"); dev->set_unload(); /* force ask sysop */ ask = true; + Dmsg0(150, "goto mount_next_vol\n"); goto mount_next_vol; -#ifdef xxx - /* If DVD, ignore the error, very often you cannot open the device - * (when there is no DVD, or when the one inserted is a wrong one) */ - if (dev->poll || dev->is_dvd()) { - goto mount_next_vol; - } else { - Jmsg2(jcr, M_ERROR, 0, _("Could not open device %s: ERR=%s\n"), - dev->print_name(), dev->print_errmsg()); - goto bail_out; - } -#endif } /* * Now check the volume label to make sure we have the right tape mounted */ read_volume: - switch (check_volume_label(ask, autochanger)) { case check_next_vol: + Dmsg0(50, "set_unload\n"); dev->set_unload(); /* want a different Volume */ + Dmsg0(150, "goto mount_next_vol\n"); goto mount_next_vol; case check_read_vol: goto read_volume; @@ -294,6 +267,7 @@ read_volume: goto mount_next_vol; } if (!is_eod_valid()) { + Dmsg0(150, "goto mount_next_vol\n"); goto mount_next_vol; } @@ -320,6 +294,40 @@ no_lock_bail_out: return false; } +bool DCR::find_a_volume() +{ + DCR *dcr = this; + if (!is_suitable_volume_mounted()) { + bool have_vol = false; + /* Do we have a candidate volume? */ + if (dev->vol) { + bstrncpy(VolumeName, dev->vol->vol_name, sizeof(VolumeName)); + have_vol = dir_get_volume_info(this, GET_VOL_INFO_FOR_WRITE); + } + /* + * Get Director's idea of what tape we should have mounted. + * in dcr->VolCatInfo + */ + if (!have_vol) { + Dmsg0(200, "Before dir_find_next_appendable_volume.\n"); + while (!dir_find_next_appendable_volume(dcr)) { + Dmsg0(200, "not dir_find_next\n"); + if (job_canceled(jcr)) { + unlock_volumes(); + return false; + } + unlock_volumes(); + if (!dir_ask_sysop_to_create_appendable_volume(dcr)) { + return false; + } + lock_volumes(); + Dmsg0(150, "Again dir_find_next_append...\n"); + } + } + } + return true; +} + int DCR::check_volume_label(bool &ask, bool &autochanger) { int vol_label_status; @@ -649,6 +657,7 @@ void DCR::mark_volume_in_error() Dmsg0(150, "dir_update_vol_info. Set Error.\n"); dir_update_volume_info(this, false, false); volume_unused(this); + Dmsg0(50, "set_unload\n"); dev->set_unload(); /* must get a new volume */ } @@ -687,7 +696,6 @@ void DCR::release_volume() dev->block_num = dev->file = 0; dev->EndBlock = dev->EndFile = 0; memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo)); -// memset(&VolCatInfo, 0, sizeof(VolCatInfo)); dev->clear_volhdr(); /* Force re-read of label */ dev->clear_labeled(); @@ -704,6 +712,7 @@ void DCR::release_volume() if (dev->is_open()) { dev->offline_or_rewind(); } + Dmsg0(50, "set_unload\n"); dev->set_unload(); Dmsg0(190, "release_volume\n"); } diff --git a/bacula/src/stored/reserve.c b/bacula/src/stored/reserve.c index 47a6759dfa..d161f0820f 100644 --- a/bacula/src/stored/reserve.c +++ b/bacula/src/stored/reserve.c @@ -348,6 +348,7 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) Dmsg2(dbglvl, "reserve_vol free vol=%s at %p\n", vol->vol_name, vol->vol_name); free_volume(dev); // volume_unused(dcr); + Dmsg0(50, "set_unload\n"); dev->set_unload(); /* have to unload current volume */ debug_list_volumes("reserve_vol free"); } @@ -389,6 +390,7 @@ VOLRES *reserve_volume(DCR *dcr, const char *VolumeName) VolumeName, vol->dev->print_name(), dev->print_name()); free_volume(dev); /* free any volume attached to our drive */ // volume_unused(dcr); + Dmsg0(50, "set_unload\n"); dev->set_unload(); /* Unload any volume that is on our drive */ dcr->dev = vol->dev; /* temp point to other dev */ slot = get_autochanger_loaded_slot(dcr); /* get slot on other drive */ diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index d43ff97c86..6706193dda 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -31,6 +31,8 @@ vtape driver General: 25Jun08 +kes Add debug code and refactor subroutine in stored/mount.c +kes Fix format problem in bscan output reported in bug #1105. ebl Fix get_next_volume_for_append logic with autochanger - use pruned volumes if found - don't reset the inchanger flag after getting a recycled volume @@ -38,6 +40,7 @@ ebl Fix get_next_volume_for_append logic with autochanger Fix recycle_oldest_purged_volume to take InChanger flag in account 23Jun08 ebl Add mmap/unmmap implementation for tokyodbm under win32 +22Jun08 kes Make first step toward eliminating globals from config scanning. Also should be a workaround for FORTIFY_SOURCE GNU C bug -- fixes bug #1042. -- 2.39.5