]> git.sur5r.net Git - bacula/bacula/commitdiff
- Fix mode change open in btape.c
authorKern Sibbald <kern@sibbald.com>
Sat, 24 Sep 2005 13:11:31 +0000 (13:11 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 24 Sep 2005 13:11:31 +0000 (13:11 +0000)
- 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
bacula/kes-1.37
bacula/src/findlib/attribs.c
bacula/src/lib/base64.c
bacula/src/stored/btape.c
bacula/src/stored/butil.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/device.c
bacula/src/stored/label.c
bacula/src/version.h

index 63aeb67e3e70df358bde91214e0dcc2083ff27ba..a88f2a6c68aabd51284cae17dd188212e13b6871 100644 (file)
@@ -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
index f38aaae9f4a2f982769689efa459ed1117bc2d43..854a4e65c132ca17f32bdf55c87dd044decf150d 100644 (file)
@@ -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.
index 512a45220fa022fbb95e806ea8dbadf0b646e179..678aa9c71a7b506fbeee90430f273c2d10b64584 100755 (executable)
@@ -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.
 
  */
 
index 5d4ed4ddbf88401741b228d2729aff426ffb2e22..dbfcbd60bf46ed99e0ce3e669881a0b89dd809ae 100644 (file)
@@ -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<len; ) {
       if (rem < 6) {
-        reg <<= 8;
-        reg |= (int8_t)bin[i++];
-        rem += 8;
+         reg <<= 8;
+         reg |= (int8_t)bin[i++];
+         rem += 8;
       }
       save = reg;
       reg >>= (rem - 6);
@@ -159,7 +153,7 @@ bin_to_base64(char *buf, char *bin, int len)
    if (rem) {
       mask = 1;
       for (i=1; i<rem; i++) {
-        mask = (mask << 1) | 1;
+         mask = (mask << 1) | 1;
       }
       buf[j++] = base64_digits[reg & mask];
    }
@@ -228,8 +222,8 @@ int main(int argc, char *argv[])
    for (i=0; my_glob.gl_pathv[i]; i++) {
       fname = my_glob.gl_pathv[i];
       if (lstat(fname, &statp) < 0) {
-        printf("Cannot stat %s: %s\n", fname, strerror(errno));
-        continue;
+         printf("Cannot stat %s: %s\n", fname, strerror(errno));
+         continue;
       }
       encode_stat(where, &statp);
 
@@ -258,28 +252,28 @@ int main(int argc, char *argv[])
 #endif
 
       if (debug_level)
-        printf("%s: len=%d val=%s\n", fname, strlen(where), where);
+         printf("%s: len=%d val=%s\n", fname, strlen(where), where);
 
       decode_stat(where, &statn);
 
       if (statp.st_dev != statn.st_dev ||
-         statp.st_ino != statn.st_ino ||
-         statp.st_mode != statn.st_mode ||
-         statp.st_nlink != statn.st_nlink ||
-         statp.st_uid != statn.st_uid ||
-         statp.st_gid != statn.st_gid ||
-         statp.st_rdev != statn.st_rdev ||
-         statp.st_size != statn.st_size ||
-         statp.st_blksize != statn.st_blksize ||
-         statp.st_blocks != statn.st_blocks ||
-         statp.st_atime != statn.st_atime ||
-         statp.st_mtime != statn.st_mtime ||
-         statp.st_ctime != statn.st_ctime) {
-
-        printf("%s: %s\n", fname, where);
-        encode_stat(where, &statn);
-        printf("%s: %s\n", fname, where);
-        printf("NOT EQAL\n");
+          statp.st_ino != statn.st_ino ||
+          statp.st_mode != statn.st_mode ||
+          statp.st_nlink != statn.st_nlink ||
+          statp.st_uid != statn.st_uid ||
+          statp.st_gid != statn.st_gid ||
+          statp.st_rdev != statn.st_rdev ||
+          statp.st_size != statn.st_size ||
+          statp.st_blksize != statn.st_blksize ||
+          statp.st_blocks != statn.st_blocks ||
+          statp.st_atime != statn.st_atime ||
+          statp.st_mtime != statn.st_mtime ||
+          statp.st_ctime != statn.st_ctime) {
+
+         printf("%s: %s\n", fname, where);
+         encode_stat(where, &statn);
+         printf("%s: %s\n", fname, where);
+         printf("NOT EQAL\n");
       }
 
    }
index dd73797be5533115b5e70d0f8ada746e0d9dfbe0..c957de79a4acd2c1fc00acfea96d699e9e11d791 100644 (file)
@@ -328,14 +328,12 @@ static bool open_the_device()
 
    block = new_block(dev);
    lock_device(dev);
-   if (!dev->is_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 */
index b7fcb2a5f8d56762aa6491f103a8f9849ecea48c..37de8852839e6b85a60946c0ffbd48b2b1ff5874 100644 (file)
@@ -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;
index 43b6456aa51175dc20714a4529ececf7c0e25e3d..0cd3fcfa06fd86dfc9c4bc95e7a4b281ecd11076 100644 (file)
@@ -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;
          }
       }
    }
index baa5e49e2063c518f9d0cc235027402412a25b8d..6b350338616c74f9aebd8a37972f7e9c8b4de1c8 100644 (file)
@@ -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 */
 
 };
 
index 0a3c945604060b8b2bf05acda9be95d74ca4a5e9..17d1803c1d872ed1497b2daee63054c3c53cdb21 100644 (file)
@@ -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 */
index 993a8c53d6f514761161a4c5ed5a9af57cf50a2a..167a810179083f1891b046a326b2197cc55a447b 100644 (file)
@@ -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();
index 5d8d3a1a93a600fa0f18c4761351444778bc0435..f9bf722e7b6bc4b8947eca9262296293657c39d5 100644 (file)
@@ -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