From d4cdfcb0408560b741a6574e594962f65344e2e7 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 24 Sep 2005 13:11:31 +0000 Subject: [PATCH] - Fix mode change open in btape.c - Use nonblocking opens on Linux only. - Move set_blocking code for tapes into method to simplify main line code. - Cleanup the code for ensuring we advance tape on fsf. This should fix IBM problems -- patch from Adam Thorton was very helpful. - Remove test for BMT_EOD in fixup_device... this eliminates need for status_dev() routine. - Before doing label ensure device is in read-write mode. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2400 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 2 ++ bacula/kes-1.37 | 13 +++++++ bacula/src/findlib/attribs.c | 17 ++++----- bacula/src/lib/base64.c | 68 ++++++++++++++++-------------------- bacula/src/stored/btape.c | 14 ++++---- bacula/src/stored/butil.c | 3 ++ bacula/src/stored/dev.c | 61 +++++++++++++++++--------------- bacula/src/stored/dev.h | 1 + bacula/src/stored/device.c | 7 +--- bacula/src/stored/label.c | 6 ++++ bacula/src/version.h | 6 ++-- 11 files changed, 105 insertions(+), 93 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 63aeb67e3e..a88f2a6c68 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -52,6 +52,7 @@ Final items for 1.37 before release: Document: +- Does ClientRunAfterJob fail the job on a bad return code? - datadir for po files. - AM_GNU_GETTEXT finds the library if you specify --with-libintl-prefix @@ -64,6 +65,7 @@ Document: - Does WildFile match against full name? Doc. For 1.39: +- Add a recursive mark command (rmark) to restore. - "Minimum Job Interval = nnn" sets minimum interval between Jobs of the same level and does not permit multiple simultaneous running of that Job (i.e. lets any previous invocation finish diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index f38aaae9f4..854a4e65c1 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -3,6 +3,19 @@ General: +Changes to 1.37.40: +24Sep05 +- Fix mode change open in btape.c +- Use nonblocking opens on Linux only. +- Move set_blocking code for tapes into method to + simplify main line code. +- Cleanup the code for ensuring we advance tape on fsf. + This should fix IBM problems -- patch from Adam Thorton + was very helpful. +- Remove test for BMT_EOD in fixup_device... this eliminates + need for status_dev() routine. +- Before doing label ensure device is in read-write mode. + Changes to 1.37.39: 20Sep05 - Tweak daemon.c berrno, copyright. diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index 512a45220f..678aa9c71a 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -9,22 +9,17 @@ * */ /* - Copyright (C) 2002-2005 Kern Sibbald + Copyright (C) 2000-2005 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. */ diff --git a/bacula/src/lib/base64.c b/bacula/src/lib/base64.c index 5d4ed4ddbf..dbfcbd60bf 100644 --- a/bacula/src/lib/base64.c +++ b/bacula/src/lib/base64.c @@ -5,24 +5,18 @@ * * Version $Id$ */ - /* - Copyright (C) 2000-2004 Kern Sibbald and John Walker + Copyright (C) 2000-2005 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. */ @@ -133,7 +127,7 @@ from_base64(intmax_t *value, char *where) * buf as base64 characters. * * Returns: the number of characters stored not - * including the EOS + * including the EOS */ int bin_to_base64(char *buf, char *bin, int len) @@ -146,9 +140,9 @@ bin_to_base64(char *buf, char *bin, int len) rem = 0; for (i=0; i>= (rem - 6); @@ -159,7 +153,7 @@ bin_to_base64(char *buf, char *bin, int len) if (rem) { mask = 1; for (i=1; iis_open()) { - Dmsg1(200, "Opening device %s\n", dcr->VolumeName); - if (dev->open(dcr, OPEN_READ_WRITE) < 0) { - Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg); - unlock_device(dev); - free_block(block); - return false; - } + Dmsg1(200, "Opening device %s\n", dcr->VolumeName); + if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg); + unlock_device(dev); + free_block(block); + return false; } Pmsg1(000, _("open device %s: OK\n"), dev->print_name()); dev->set_append(); /* put volume in append mode */ diff --git a/bacula/src/stored/butil.c b/bacula/src/stored/butil.c index b7fcb2a5f8..37de885283 100644 --- a/bacula/src/stored/butil.c +++ b/bacula/src/stored/butil.c @@ -224,8 +224,10 @@ static DEVRES *find_device_res(char *device_name, int read_access) bool found = false; DEVRES *device; + Dmsg0(900, "Enter find_device_res\n"); LockRes(); foreach_res(device, R_DEVICE) { + Dmsg2(900, "Compare %s and %s\n", device->device_name, device_name); if (strcmp(device->device_name, device_name) == 0) { found = true; break; @@ -242,6 +244,7 @@ static DEVRES *find_device_res(char *device_name, int read_access) } } foreach_res(device, R_DEVICE) { + Dmsg2(900, "Compare %s and %s\n", device->hdr.name, device_name); if (strcmp(device->hdr.name, device_name) == 0) { found = true; break; diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 43b6456aa5..0cd3fcfa06 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -265,11 +265,13 @@ DEVICE::open(DCR *dcr, int omode) return fd; } else { ::close(fd); /* use system close so correct mode will be used on open */ + fd = -1; + Dmsg0(100, "Close fd for mode change.\n"); } } - if (dcr) { - bstrncpy(VolCatInfo.VolCatName, dcr->VolumeName, sizeof(VolCatInfo.VolCatName)); - } + if (dcr) { + bstrncpy(VolCatInfo.VolCatName, dcr->VolumeName, sizeof(VolCatInfo.VolCatName)); + } Dmsg4(29, "open dev: tape=%d dev_name=%s vol=%s mode=%s\n", is_tape(), print_name(), VolCatInfo.VolCatName, mode_to_str(omode)); @@ -326,7 +328,7 @@ void DEVICE::set_mode(int new_mode) */ void DEVICE::open_tape_device(DCR *dcr, int omode) { - int nonblocking = 0;; + int nonblocking = 0; file_size = 0; int timeout; int ioerrcnt = 10; @@ -339,12 +341,14 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) set_mode(omode); timeout = max_open_wait; errno = 0; +#ifdef HAVE_LINUX_OS if (open_nowait) { /* Set wait counters to zero for no wait */ timeout = ioerrcnt = 0; /* Open drive in non-block mode */ nonblocking = O_NONBLOCK; } +#endif if (is_fifo() && timeout) { /* Set open timer */ tid = start_thread_timer(pthread_self(), timeout); @@ -380,25 +384,15 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) stop_thread_timer(tid); tid = 0; } - Emsg0(M_FATAL, 0, errmsg); + Jmsg0(dcr->jcr, M_FATAL, 0, errmsg); break; } - /* Really an if, but we use a break for an error exit */ - while (fd >= 0) { - /* If opened in non-block mode, make it block now */ - if (nonblocking) { - int oflags; - nonblocking = 0; - /* Try to reset blocking */ - if ((oflags = fcntl(fd, F_GETFL, 0)) < 0 || - fcntl(fd, F_SETFL, oflags & ~O_NONBLOCK) < 0) { - berrno be; - Jmsg1(dcr->jcr, M_ERROR, 0, _("fcntl error. ERR=%s\n"), be.strerror()); - ::close(fd); /* use system close() */ - fd = -1; - break; - } - } + + if (nonblocking) { + set_blocking(); + } + + if (fd >= 0) { openmode = omode; /* save open mode */ Dmsg2(100, "openmode=%d %s\n", openmode, mode_to_str(openmode)); dev_errno = 0; @@ -406,9 +400,8 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) use_count = 1; update_pos_dev(this); /* update position */ set_os_device_parameters(this); /* do system dependent stuff */ - Dmsg0(500, "Open OK\n"); - break; } + /* Stop any open() timer we started */ if (tid) { stop_thread_timer(tid); @@ -417,6 +410,19 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) Dmsg1(29, "open dev: tape %d opened\n", fd); } +void DEVICE::set_blocking() +{ + int oflags; + /* Try to reset blocking */ + if ((oflags = fcntl(fd, F_GETFL, 0)) < 0 || + fcntl(fd, F_SETFL, oflags & ~O_NONBLOCK) < 0) { + berrno be; + ::close(fd); /* use system close() */ + fd = ::open(dev_name, mode, MODE_RW); + Dmsg2(100, "fcntl error. ERR=%s. Close-reopen fd=%d\n", be.strerror(), fd); + } +} + /* * Open a file device */ @@ -873,18 +879,17 @@ eod_dev(DEVICE *dev) return false; } /* - * Avoid infinite loop. ***FIXME*** possibly add code - * to set EOD or to turn off CAP_FASTFSF if on. + * Avoid infinite loop by ensuring we advance. */ if (file_num == (int)dev->file) { struct mtget mt_stat; Dmsg1(100, "fsf did not advance from file %d\n", file_num); + dev->set_ateof(); if (dev_get_os_pos(dev, &mt_stat)) { Dmsg2(100, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno); - dev->set_ateof(); dev->file = mt_stat.mt_fileno; - } - return false; + } + break; } } } diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index baa5e49e20..6b35033861 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -338,6 +338,7 @@ private: void open_tape_device(DCR *dcr, int omode); /* in dev.c */ void open_file_device(int omode); /* in dev.c */ void open_dvd_device(DCR *dcr, int omode); /* in dev.c */ + void set_blocking(); /* in dev.c */ }; diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 0a3c945604..17d1803c1d 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -73,7 +73,6 @@ extern int debug_level; */ bool fixup_device_block_write_error(DCR *dcr) { - uint32_t stat; char PrevVolName[MAX_NAME_LENGTH]; DEV_BLOCK *label_blk; DEV_BLOCK *block = dcr->block; @@ -84,12 +83,8 @@ bool fixup_device_block_write_error(DCR *dcr) DEVICE *dev = dcr->dev; wait_time = time(NULL); - stat = status_dev(dev); - if (!(stat & BMT_EOD)) { - return false; /* this really shouldn't happen */ - } - Dmsg0(100, "======= Got EOD ========\n"); + Dmsg0(100, "Enter fixup_device_block_write_error\n"); block_device(dev, BST_DOING_ACQUIRE); /* Unlock, but leave BLOCKED */ diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 993a8c53d6..167a810179 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -299,6 +299,9 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *Po Dmsg0(99, "write_volume_label()\n"); empty_block(dcr->block); + if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + goto bail_out; + } Dmsg1(100, "Label type=%d\n", dev->label_type); if (!rewind_dev(dev)) { free_volume(dev); @@ -375,6 +378,9 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; + if (dev->open(dcr, OPEN_READ_WRITE) < 0) { + return false; + } Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, dev); dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */ dev->set_append(); diff --git a/bacula/src/version.h b/bacula/src/version.h index 5d8d3a1a93..f9bf722e7b 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -3,9 +3,9 @@ */ #undef VERSION -#define VERSION "1.37.39" -#define BDATE "20 September 2005" -#define LSMDATE "20Sep05" +#define VERSION "1.37.40" +#define BDATE "24 September 2005" +#define LSMDATE "24Sep05" /* Debug flags */ #undef DEBUG -- 2.39.2