From 22a5d43f2bf48e4d5c056dc17bd7cff90d84290e Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 25 Sep 2006 07:37:18 +0000 Subject: [PATCH] kes Apply the recycle patch from Richard Mortimer. kes Convert a few if statements in dev.c to switch statements. kes Start using print_errmsg instead of bstrerror(). kes Print a job message in SD when a job is marked to be canceled. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3500 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/bpipe.h | 22 +++++++++------------ bacula/src/stored/append.c | 2 -- bacula/src/stored/dev.c | 40 +++++++++++++++++++------------------- bacula/src/stored/dircmd.c | 1 + bacula/src/stored/label.c | 27 +++++++++++++++---------- bacula/src/version.h | 4 ++-- bacula/technotes-1.39 | 5 +++++ 7 files changed, 54 insertions(+), 47 deletions(-) diff --git a/bacula/src/lib/bpipe.h b/bacula/src/lib/bpipe.h index 353dd553f0..38c2c21f10 100644 --- a/bacula/src/lib/bpipe.h +++ b/bacula/src/lib/bpipe.h @@ -5,30 +5,26 @@ */ /* - Copyright (C) 2002-2004 Kern Sibbald and John Walker + Copyright (C) 2002-2006 Kern Sibbald This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of - the License, or (at your option) any later version. + modify it under the terms of the GNU General Public License + version 2 as amended with additional clauses defined in the + file LICENSE in the main source directory. 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 General Public - License along with this program; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + the file LICENSE for additional details. */ -typedef struct s_bpipe { +class BPIPE { +public: pid_t worker_pid; time_t worker_stime; int wait; btimer_t *timer_id; FILE *rfd; FILE *wfd; -} BPIPE; +}; diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index 9910ce1c0e..bbecc716e5 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -205,8 +205,6 @@ bool do_append_data(JCR *jcr) if (!write_block_to_device(dcr)) { Dmsg2(90, "Got write_block_to_dev error on device %s. %s\n", dev->print_name(), dev->bstrerror()); - Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"), - dev->print_name(), dev->bstrerror()); ok = false; break; } diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 80160e630d..0d0110510d 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1811,12 +1811,12 @@ void DEVICE::close_part(DCR *dcr) off_t DEVICE::lseek(DCR *dcr, off_t offset, int whence) { - if (is_dvd()) { + switch (dev_type) { + case B_DVD_DEV: return lseek_dvd(dcr, offset, whence); - } - if (is_file()) { + case B_FILE_DEV: return ::lseek(fd, offset, whence); - } + } return -1; } @@ -1824,25 +1824,25 @@ off_t DEVICE::lseek(DCR *dcr, off_t offset, int whence) bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */ { Dmsg1(100, "truncate %s\n", print_name()); - if (is_tape()) { - return true; /* we don't really truncate tapes */ + switch (dev_type) { + case B_TAPE_DEV: /* maybe we should rewind and write and eof ???? */ - } - - if (is_dvd()) { + return true; /* we don't really truncate tapes */ + case B_DVD_DEV: return truncate_dvd(dcr); + case B_FILE_DEV: + /* ***FIXME*** we really need to unlink() the file so that + * its name can be changed for a relabel. + */ + if (ftruncate(fd, 0) != 0) { + berrno be; + Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"), + print_name(), be.strerror()); + return false; + } + return true; } - - /* ***FIXME*** we really need to unlink() the file so that - * its name can be changed for a relabel. - */ - if (ftruncate(fd, 0) != 0) { - berrno be; - Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"), - print_name(), be.strerror()); - return false; - } - return true; + return false; } /* Mount the device. diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index f3ce023113..f83263105b 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -279,6 +279,7 @@ static bool cancel_cmd(JCR *cjcr) pthread_cond_broadcast(&jcr->read_dcr->dev->wait_next_vol); pthread_cond_broadcast(&wait_device_release); } + Jmsg(jcr, M_INFO, 0, _("Job marked to be canceled.\n")); bnet_fsend(dir, _("3000 Job %s marked to be canceled.\n"), jcr->Job); free_jcr(jcr); } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 12b25388d5..b000455723 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -99,7 +99,7 @@ int read_dev_volume_label(DCR *dcr) if (!dev->rewind(dcr)) { Mmsg(jcr->errmsg, _("Couldn't rewind device %s: ERR=%s\n"), - dev->print_name(), dev->bstrerror()); + dev->print_name(), dev->print_errmsg()); Dmsg1(30, "return VOL_NO_MEDIA: %s", jcr->errmsg); return VOL_NO_MEDIA; } @@ -138,14 +138,14 @@ int read_dev_volume_label(DCR *dcr) if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) { Mmsg(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula " "labeled Volume, because: ERR=%s"), NPRT(VolName), - dev->print_name(), dev->bstrerror()); + dev->print_name(), dev->print_errmsg()); Dmsg1(30, "%s", jcr->errmsg); } else if (!read_record_from_block(block, record)) { Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n")); Dmsg1(30, "%s", jcr->errmsg); } else if (!unser_volume_label(dev, record)) { Mmsg(jcr->errmsg, _("Could not unserialize Volume label: ERR=%s\n"), - dev->bstrerror()); + dev->print_errmsg()); Dmsg1(30, "%s", jcr->errmsg); } else if (strcmp(dev->VolHdr.Id, BaculaId) != 0 && strcmp(dev->VolHdr.Id, OldBaculaId) != 0) { @@ -321,7 +321,7 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, if (!dev->rewind(dcr)) { free_volume(dev); memset(&dev->VolHdr, 0, sizeof(dev->VolHdr)); - Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->bstrerror()); + Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->print_errmsg()); if (!forge_on) { goto bail_out; } @@ -350,7 +350,7 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, /* Temporarily mark in append state to enable writing */ dev->set_append(); if (!write_record_to_block(dcr->block, dcr->rec)) { - Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror()); + Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg()); goto bail_out; } else { Dmsg2(30, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev->print_name()); @@ -358,7 +358,7 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, Dmsg0(99, "Call write_block_to_dev()\n"); if (!write_block_to_dev(dcr)) { - Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror()); + Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg()); goto bail_out; } @@ -366,7 +366,7 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, 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()); + Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg()); goto bail_out; } } @@ -426,13 +426,19 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) if (!dev_cap(dev, CAP_STREAM)) { if (!dev->rewind(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Rewind error on device %s: ERR=%s\n"), - dev->print_name(), dev->bstrerror()); + dev->print_name(), dev->print_errmsg()); return false; } if (recycle) { if (!dev->truncate(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Truncate error on device %s: ERR=%s\n"), - dev->print_name(), dev->bstrerror()); + dev->print_name(), dev->print_errmsg()); + return false; + } + if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + Jmsg2(jcr, M_FATAL, 0, + _("Failed to re-open DVD after truncate on device %s: ERR=%s\n"), + dev->print_name(), dev->print_errmsg()); return false; } } @@ -455,11 +461,12 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd); if (!write_block_to_dev(dcr)) { Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s: ERR=%s\n"), - dev->print_name(), dev->bstrerror()); + dev->print_name(), dev->print_errmsg()); Dmsg0(200, "===ERROR write block to dev\n"); return false; } } + dev->set_labeled(); /* Set or reset Volume statistics */ dev->VolCatInfo.VolCatJobs = 0; dev->VolCatInfo.VolCatFiles = 0; diff --git a/bacula/src/version.h b/bacula/src/version.h index a5393b4bbe..530bbd840c 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "1.39.23" -#define BDATE "23 September 2006" -#define LSMDATE "23Sep06" +#define BDATE "24 September 2006" +#define LSMDATE "24Sep06" #define BYEAR "2006" /* year for copyright messages in progs */ /* Debug flags */ diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index 5592d3775f..59440762b2 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -1,6 +1,11 @@ Technical notes on version 1.39 General: +24Sep06 +kes Apply the recycle patch from Richard Mortimer. +kes Convert a few if statements in dev.c to switch statements. +kes Start using print_errmsg instead of bstrerror(). +kes Print a job message in SD when a job is marked to be canceled. 23Sep06 kes All code added back. Fixed block.c read/write to loop only 3 times. This apparently keeps the OS from crashing (at least -- 2.39.5