From aa87a4d524a58a8fdabba022535ab87411e3e161 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 19 Sep 2006 19:00:46 +0000 Subject: [PATCH] Back out more code git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3485 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/block.c | 3 +++ bacula/src/stored/btape.c | 2 +- bacula/src/stored/dircmd.c | 36 +++++++++++++++++++++++++----------- bacula/src/stored/label.c | 16 +--------------- bacula/src/stored/mount.c | 2 +- bacula/src/stored/protos.h | 3 +-- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 737ab5c4fe..fb36d5a888 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -401,6 +401,7 @@ bool write_block_to_dev(DCR *dcr) return true; #endif ASSERT(block->binbuf == ((uint32_t) (block->bufp - block->buf))); + ASSERT(dev->is_open()); /* dump_block(block, "before write"); */ if (dev->at_weot()) { @@ -909,6 +910,8 @@ bool read_block_from_dev(DCR *dcr, bool check_block_numbers) JCR *jcr = dcr->jcr; DEVICE *dev = dcr->dev; DEV_BLOCK *block = dcr->block; + + ASSERT(dev->is_open()); if (dev->at_eot()) { return false; diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 8184f53204..fb561309c8 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -384,7 +384,7 @@ static void labelcmd() } } dev->rewind(dcr); - write_new_volume_label_to_dev(dcr, cmd, "Default", false,/*no relabel*/ true /* label dvd now */); + write_new_volume_label_to_dev(dcr, cmd, "Default", true /* label dvd now */); Pmsg1(-1, _("Wrote Volume label for volume \"%s\".\n"), cmd); } diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index f3ce023113..8889efaa81 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -390,14 +390,18 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, DEVICE *dev = dcr->dev; int label_status; int mode; - const char *volname = (relabel == 1) ? oldname : newname; + const char *volname = (relabel == 0) ? newname : oldname; char ed1[50]; steal_device_lock(dev, &hold, BST_WRITING_LABEL); Dmsg1(100, "Stole device %s lock, writing label.\n", dev->print_name()); - Dmsg0(90, "try_autoload_device - looking for volume_info\n"); + if (relabel && dev->is_dvd()) { + /* Fake at least one partition to ensure that we look for the old volume */ + dcr->VolCatInfo.VolCatParts = 1; + } + if (!try_autoload_device(dcr->jcr, slot, volname)) { goto bail_out; /* error */ } @@ -408,12 +412,10 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, } else { mode = CREATE_READ_WRITE; } - - if (relabel) { - dev->truncating = true; /* let open() know we will truncate it */ + if (dev->is_dvd()) { + bstrncpy(dcr->VolCatInfo.VolCatName, volname, sizeof(dcr->VolCatInfo.VolCatName)); } - /* Set old volume name for open if relabeling */ - bstrncpy(dcr->VolCatInfo.VolCatName, volname, sizeof(dcr->VolCatInfo.VolCatName)); + if (dev->open(dcr, mode) < 0) { bnet_fsend(dir, _("3910 Unable to open device %s: ERR=%s\n"), dev->print_name(), dev->strerror()); @@ -423,8 +425,6 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, /* See what we have for a Volume */ label_status = read_dev_volume_label(dcr); - /* Set new volume name */ - bstrncpy(dcr->VolCatInfo.VolCatName, newname, sizeof(dcr->VolCatInfo.VolCatName)); switch(label_status) { case VOL_NAME_ERROR: case VOL_VERSION_ERROR: @@ -446,11 +446,25 @@ static void label_volume_if_ok(DCR *dcr, char *oldname, bnet_fsend(dir, _("3922 Cannot relabel an ANSI/IBM labeled Volume.\n")); break; } + if (relabel && dev->is_dvd()) { + /* Save dev VolumeName */ + bstrncpy(dcr->VolumeName, dev->VolCatInfo.VolCatName, sizeof(dcr->VolumeName)); + /* Use new name for DVD truncation */ + bstrncpy(dev->VolCatInfo.VolCatName, newname, sizeof(dev->VolCatInfo.VolCatName)); + if (!dev->truncate(dcr)) { + bnet_fsend(dir, _("3912 Failed to truncate previous DVD volume.\n")); + /* Restore device VolName */ + bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName)); + break; + } + /* Restore device VolName */ + bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName)); + } + free_volume(dev); /* release old volume name */ /* Fall through wanted! */ case VOL_IO_ERROR: case VOL_NO_LABEL: - if (!write_new_volume_label_to_dev(dcr, newname, poolname, - relabel, true /* write dvd now */)) { + if (!write_new_volume_label_to_dev(dcr, newname, poolname, true /* write dvd now */)) { bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), dev->bstrerror()); break; } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 12b25388d5..32a65297bf 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -290,7 +290,7 @@ bool write_volume_label_to_block(DCR *dcr) * This routine should be used only when labeling a blank tape. */ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, - const char *PoolName, bool relabel, bool dvdnow) + const char *PoolName, bool dvdnow) { DEVICE *dev = dcr->dev; @@ -298,19 +298,6 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, Dmsg0(99, "write_volume_label()\n"); empty_block(dcr->block); - /* If relabeling, truncate the device */ - if (relabel && !dev->truncate(dcr)) { - goto bail_out; - } - - if (relabel) { - dev->close_part(dcr); /* make sure closed for rename */ - } - - /* Set the new filename for open, ... */ - bstrncpy(dev->VolCatInfo.VolCatName, VolName, sizeof(dev->VolCatInfo.VolCatName)); - bstrncpy(dcr->VolCatInfo.VolCatName, VolName, sizeof(dcr->VolCatInfo.VolCatName)); - Dmsg1(150, "New VolName=%s\n", VolName); if (dev->open(dcr, OPEN_READ_WRITE) < 0) { /* If device is not tape, attempt to create it */ if (dev->is_tape() || dev->open(dcr, CREATE_READ_WRITE) < 0) { @@ -364,7 +351,6 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, /* Now commit block to DVD if we should write now */ if (dev->is_dvd() && dvdnow) { - Dmsg1(150, "New VolName=%s\n", dev->VolCatInfo.VolCatName); if (!dvd_write_part(dcr)) { Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror()); goto bail_out; diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index ddc2b5d58f..4ca03652d3 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -445,7 +445,7 @@ static int try_autolabel(DCR *dcr) Dmsg0(150, "Create volume label\n"); /* Create a new Volume label and write it to the device */ if (!write_new_volume_label_to_dev(dcr, dcr->VolumeName, - dcr->pool_name, false, /* no relabel */ false /* defer DVD label */)) { + dcr->pool_name, false /* defer DVD label */)) { Dmsg0(150, "!write_vol_label\n"); mark_volume_in_error(dcr); return try_next_vol; diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index e9c8b1cca9..84ef598d07 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -146,8 +146,7 @@ int read_dev_volume_label(DCR *dcr); int read_dvd_volume_label(DCR *dcr, bool write); void create_session_label(DCR *dcr, DEV_RECORD *rec, int label); void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName, bool dvdnow); -bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, - const char *PoolName, bool relabel, bool dvdnow); +bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName, bool dvdnow); #define ANSI_VOL_LABEL 0 #define ANSI_EOF_LABEL 1 #define ANSI_EOV_LABEL 2 -- 2.39.2