]> git.sur5r.net Git - bacula/bacula/commitdiff
- Detect device mounted for DVD and suppress be sure to
authorKern Sibbald <kern@sibbald.com>
Wed, 29 Jun 2005 20:52:24 +0000 (20:52 +0000)
committerKern Sibbald <kern@sibbald.com>
Wed, 29 Jun 2005 20:52:24 +0000 (20:52 +0000)
  mount message after label.
- Set Cleaning tape status to "Cleaning" and force no
  MediaType.
- Get DVD writing working with new standard Bacula open()
  code.
- Rename get_filename() to make more sense.
- Detect "is already mounted on" on mount command so to avoid
  error if device is already mounted.
- Eliminated guess_name() code. It may be necessary to
  add it back later.
- Eliminate seg fault from printing invalid results.
- Make dvd_write_part() bool.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2169 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kes-1.37
bacula/src/dird/ua_label.c
bacula/src/stored/acquire.c
bacula/src/stored/block.c
bacula/src/stored/dev.c
bacula/src/stored/dvd.c
bacula/src/stored/mount.c
bacula/src/stored/protos.h
bacula/src/stored/read.c
bacula/src/stored/reserve.c
bacula/src/version.h

index 5afe0f8e154967ffa16b11eb71c4c0d826279da1..9bdca223935353fff8923a6455aa34fc9688ceb6 100644 (file)
@@ -4,6 +4,21 @@
 General:
 
 Changes to 1.37.28:
+30Jun05
+- Detect device mounted for DVD and suppress be sure to 
+  mount message after label.
+- Set Cleaning tape status to "Cleaning" and force no
+  MediaType.
+- Get DVD writing working with new standard Bacula open()
+  code.
+- Rename get_filename() to make more sense.
+- Detect "is already mounted on" on mount command so to avoid
+  error if device is already mounted.
+- Eliminated guess_name() code. It may be necessary to
+  add it back later.
+- Eliminate seg fault from printing invalid results.
+- Make dvd_write_part() bool.
+
 29Jun05
 - Attempt to fix DVD writing by eliminating a number of the 
   DVD subroutines to simplify.
index e710da0c7ca42b3a02bf83a0fe3ae5afede76b1e..da0054a92147a9f02a3299b85b7c02b50ca9c162 100644 (file)
@@ -419,10 +419,12 @@ checkName:
             /* Here we can get
              *  3001 OK mount. Device=xxx      or
              *  3001 Mounted Volume vvvv
+             *  3002 Device "DVD-Writer" (/dev/hdc) is mounted.
              *  3906 is cannot mount non-tape
              * So for those, no need to print a reminder
              */
             if (strncmp(sd->msg, "3001 ", 5) == 0 ||
+                strncmp(sd->msg, "3002 ", 5) == 0 ||
                 strncmp(sd->msg, "3906 ", 5) == 0) {
                print_reminder = false;
             }
@@ -521,11 +523,15 @@ static void label_from_barcodes(UAContext *ua)
       if (is_cleaning_tape(ua, &mr, &pr)) {
          if (media_record_exists) {      /* we update it */
             mr.VolBytes = 1;
+            bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
+            mr.MediaType[0] = 0;
             if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
                 bsendmsg(ua, "%s", db_strerror(ua->db));
             }
          } else {                        /* create the media record */
             set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
+            bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
+            mr.MediaType[0] = 0;
             if (db_create_media_record(ua->jcr, ua->db, &mr)) {
                bsendmsg(ua, _("Catalog record for cleaning tape \"%s\" successfully created.\n"),
                   mr.VolumeName);
index 7268ab7aaf944c78d74090dd19d684a5645b8845..d5d753debd8fa5e8c86391b5683ccf8fb18bedc8 100644 (file)
@@ -92,7 +92,7 @@ void free_dcr(DCR *dcr)
    if (dcr->reserved_device) {
       lock_device(dev);
       dev->reserved_device--;
-      Dmsg1(200, "=========== Dec reserve=%d\n", dev->reserved_device);
+      Dmsg1(200, "Dec reserve=%d\n", dev->reserved_device);
       dcr->reserved_device = false;
       if (dev->num_writers < 0) {
          Jmsg1(dcr->jcr, M_ERROR, 0, _("Hey! num_writers=%d!!!!\n"), dev->num_writers);
@@ -314,7 +314,7 @@ DCR *acquire_device_for_append(DCR *dcr)
 
    if (dcr->reserved_device) {
       dev->reserved_device--;
-      Dmsg1(200, "============ Dec reserve=%d\n", dev->reserved_device);
+      Dmsg1(200, "Dec reserve=%d\n", dev->reserved_device);
       dcr->reserved_device = false;
    }
 
@@ -423,7 +423,7 @@ bool release_device(DCR *dcr)
    /* if device is reserved, job never started, so release the reserve here */
    if (dcr->reserved_device) {
       dev->reserved_device--;
-      Dmsg1(200, "========= Dec reserve=%d\n", dev->reserved_device);
+      Dmsg1(200, "Dec reserve=%d\n", dev->reserved_device);
       dcr->reserved_device = false;
    }
 
index 3e97f73c7d8c405589310c70a941d663a43f38d9..56b7bd54f64a423a61e5f3caa71c7b4e1ca8a220 100644 (file)
@@ -182,7 +182,7 @@ void ser_block_header(DEV_BLOCK *block)
    uint32_t CheckSum = 0;
    uint32_t block_len = block->binbuf;
 
-   Dmsg1(390, "ser_block_header: block_len=%d\n", block_len);
+   Dmsg1(1390, "ser_block_header: block_len=%d\n", block_len);
    ser_begin(block->buf, BLKHDR2_LENGTH);
    ser_uint32(CheckSum);
    ser_uint32(block_len);
@@ -196,7 +196,7 @@ void ser_block_header(DEV_BLOCK *block)
    /* Checksum whole block except for the checksum */
    CheckSum = bcrc32((uint8_t *)block->buf+BLKHDR_CS_LENGTH,
                  block_len-BLKHDR_CS_LENGTH);
-   Dmsg1(390, "ser_bloc_header: checksum=%x\n", CheckSum);
+   Dmsg1(1390, "ser_bloc_header: checksum=%x\n", CheckSum);
    ser_begin(block->buf, BLKHDR2_LENGTH);
    ser_uint32(CheckSum);              /* now add checksum to block header */
 }
@@ -500,7 +500,7 @@ bool write_block_to_dev(DCR *dcr)
    }
 
    dev->VolCatInfo.VolCatWrites++;
-   Dmsg1(300, "Write block of %u bytes\n", wlen);
+   Dmsg1(1300, "Write block of %u bytes\n", wlen);
 #ifdef DEBUG_BLOCK_ZEROING
    uint32_t *bp = (uint32_t *)block->buf;
    if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) {
@@ -586,7 +586,7 @@ bool write_block_to_dev(DCR *dcr)
    dev->file_size += wlen;
    dev->part_size += wlen;
 
-   Dmsg2(300, "write_block: wrote block %d bytes=%d\n", dev->block_num, wlen);
+   Dmsg2(1300, "write_block: wrote block %d bytes=%d\n", dev->block_num, wlen);
    empty_block(block);
    return true;
 }
index b084a94541dadc9699bc480907f11bd0e35e49ce..195857477091129e07016edd89f182b95be930d4 100644 (file)
@@ -446,7 +446,7 @@ static void open_file_device(DCR *dcr, int mode)
 }
 
 /*
- * Open a DVD device. N.B. at this point, dev->VolCatInfo.VolCatName
+ * Open a DVD device. N.B. at this point, dcr->VolCatInfo.VolCatName
  *  has the desired Volume name, but there is NO assurance that
  *  any other field of VolCatInfo is correct.
  */
@@ -457,7 +457,7 @@ static void open_dvd_device(DCR *dcr, int mode)
    struct stat filestat;
 
    /*
-    * Handle opening of File Archive (not a tape)
+    * Handle opening of DVD Volume
     */     
    Dmsg3(29, "Enter: open_file_dev: %s dev=%s mode=%d\n", dev->is_dvd()?"DVD":"disk",
          archive_name.c_str(), mode);
@@ -474,8 +474,6 @@ static void open_dvd_device(DCR *dcr, int mode)
    }
    dev->part_size = 0;
    
-   Dmsg1(100, "Call make_dvd_filename. Vol=%s\n", dev->VolCatInfo.VolCatName);
-   make_dvd_filename(dev, archive_name);
 
    if (mount_dev(dev, 1) < 0) {
       Mmsg(dev->errmsg, _("Could not mount device %s.\n"),
@@ -496,8 +494,19 @@ static void open_dvd_device(DCR *dcr, int mode)
    if (dev->part < dev->num_parts) {
       mode = OPEN_READ_ONLY;
    }
-   
    dev->set_mode(mode);
+
+   Dmsg1(100, "Call make_dvd_filename. Vol=%s\n", dev->VolCatInfo.VolCatName);
+   /* 
+    * If we are opening it read-only, it is *probably* on the
+    *   DVD, so try the DVD first, otherwise look in the spool dir.
+    */
+   if (mode == OPEN_READ_ONLY) {
+      make_mounted_dvd_filename(dev, archive_name);
+   } else {
+      make_spooled_dvd_filename(dev, archive_name);
+   }
+
    /* If creating file, give 0640 permissions */
    Dmsg3(29, "mode=%d open(%s, 0x%x, 0640)\n", mode, archive_name.c_str(), dev->mode);
    if ((dev->fd = open(archive_name.c_str(), dev->mode, 0640)) < 0) {
@@ -506,7 +515,12 @@ static void open_dvd_device(DCR *dcr, int mode)
       Mmsg2(dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(), 
             be.strerror());
       Dmsg1(29, "open failed: %s", dev->errmsg);
-   } else {
+      if (mode == OPEN_READ_ONLY) {
+         make_spooled_dvd_filename(dev, archive_name);
+         dev->fd = open(archive_name.c_str(), dev->mode, 0640);  /* try on spool */
+      }
+   }
+   if (dev->fd >= 0) {
       /* Get size of file */
       if (fstat(dev->fd, &filestat) < 0) {
          berrno be;
@@ -1589,7 +1603,7 @@ static void do_close(DEVICE *dev)
       POOL_MEM archive_name(PM_FNAME);
       dev->part = dev->num_parts;
       Dmsg1(100, "Call make_dvd_filename. Vol=%s\n", dev->VolCatInfo.VolCatName);
-      make_dvd_filename(dev, archive_name);
+      make_spooled_dvd_filename(dev, archive_name);
       /* Check that the part file is empty */
       if ((stat(archive_name.c_str(), &statp) == 0) && (statp.st_size == 0)) {
          Dmsg1(100, "unlink(%s)\n", archive_name.c_str());
index c5ee187d9b3032f5305c154611be3906e83c011e..c60cb5f87818654836227d562f5bad36525118f1 100644 (file)
 /* Forward referenced functions */
 static char *edit_device_codes_dev(DEVICE *dev, char *omsg, const char *imsg);
 static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout);
-static int dvd_write_part(DEVICE *dev);
+static bool dvd_write_part(DEVICE *dev);
+static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name);
 
 /* 
  * Write the current volume/part filename to archive_name.
  */
-void make_dvd_filename(DEVICE *dev, POOL_MEM &archive_name) 
+void make_mounted_dvd_filename(DEVICE *dev, POOL_MEM &archive_name) 
 {
-   char partnumber[20];
-   
-   /*
-    * If we try to open the last part, just open it from disk, 
-    * otherwise, open it from the spooling directory.
-    */
-   Dmsg2(100, "DVD part=%d num_parts=%d\n", dev->part, dev->num_parts);
-   if (dev->part < dev->num_parts) {
-      Dmsg1(100, "Arch = mount point: %s\n", dev->device->mount_point);
-      pm_strcpy(archive_name, dev->device->mount_point);
+   pm_strcpy(archive_name, dev->device->mount_point);
+   add_file_and_part_name(dev, archive_name);
+}
+
+void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name)
+{
+   /* Use the working directory if spool directory is not defined */
+   if (dev->device->spool_directory) {
+      pm_strcpy(archive_name, dev->device->spool_directory);
    } else {
-      /* Use the working directory if spool directory is not defined */
-      if (dev->device->spool_directory) {
-         pm_strcpy(archive_name, dev->device->spool_directory);
-      } else {
-         pm_strcpy(archive_name, working_directory);
-      }
+      pm_strcpy(archive_name, working_directory);
    }
-      
+   add_file_and_part_name(dev, archive_name);
+}      
+
+static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name)
+{
+   char partnumber[20];
    if (archive_name.c_str()[strlen(archive_name.c_str())-1] != '/') {
       pm_strcat(archive_name, "/");
    }
@@ -100,18 +100,18 @@ bool unmount_dev(DEVICE *dev, int timeout)
 static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout) 
 {
    POOL_MEM ocmd(PM_FNAME);
-   POOLMEMresults;
-   charicmd;
+   POOLMEM *results;
+   char *icmd;
    int status, timeout;
    
    if (mount) {
       if (dev->is_mounted()) {
-         goto get_out;
+         return true;
       }
       icmd = dev->device->mount_command;
    } else {
       if (!dev->is_mounted()) {
-         goto get_out;
+         return true;
       }
       icmd = dev->device->unmount_command;
    }
@@ -127,15 +127,18 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout)
       timeout = 0;
    }
    results = get_pool_memory(PM_MESSAGE);
+   results[0] = 0;
    /* If busy retry each second */
    while ((status = run_program_full_output(ocmd.c_str(), 
                        dev->max_open_wait/2, results)) != 0) {
+      if (fnmatch("*is already mounted on", results, 0) == 0) {
+         break;
+      }
       if (timeout-- > 0) {
-         Dmsg2(400, "Device %s cannot be (un)mounted. Retrying... ERR=%s\n", dev->dev_name, results);
          /* Sometimes the device cannot be mounted because it is already mounted.
           * Try to unmount it, then remount it */
          if (mount) {
-            Dmsg1(400, "Trying to unmount the device %s...\n", dev->dev_name);
+            Dmsg1(400, "Trying to unmount the device %s...\n", dev->print_name());
             do_mount_dev(dev, 0, 0);
          }
          bmicrosleep(1, 0);
@@ -150,187 +153,8 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout)
    
    dev->set_mounted(mount);              /* set/clear mounted flag */
    free_pool_memory(results);
-
-get_out:
-   Dmsg1(29, "Exit do_mount_dev: mounted=%d\n", !!dev->is_mounted());
-   return true;
-}
-
-/* Only for devices that require a mount -- currently DVDs only
- *
- * Try to find the Volume name of the loaded device.
- *
- * Returns true  if read_dev_volume_label can now read the label,
- *               NOTE!!! at this point the device may not be
- *               opened.
- *               Maybe it should open the first part.  ***FIXME***
- *
- *         false if an error occured, and read_dev_volume_label
- *               must abort with an IO_ERROR.
- *
- * To find the Volume name, it lists all the files on the DVD,
- * and searches for a file which has a minimum size (500 bytes).
- * If this file has a numeric extension, like part files, try to
- * open the file which has no extension (e.g.  the first part
- * file).
- *
- * So, if the DVD does not contains a Bacula volume, a random file is opened,
- * and no valid label could be read from this file.
- *
- * It is useful, so the operator can be told that a wrong volume is mounted, with
- * the label name of the current volume. We can also check that the currently
- * mounted disk is writable. (See also read_dev_volume_label_guess in label.c).
-
-   If we are writing, then there is no need to guess. We should just
-   check that the Volume does not already exist.
-
-   If we are reading, I don't see the reason to guess since we
-   know what Volume we want. The file either exists or does not
-   exist.
-
- *
- */
-#ifdef xxx
-bool can_open_mounted_dev(DEVICE *dev) 
-{
-   Dmsg1(29, "Enter: dev=%s\n", dev->dev_name);
-   POOL_MEM guessedname(PM_FNAME);
-   DIR* dp;
-   struct dirent *entry, *result;
-   struct stat statp;
-   int index;
-   int name_max;
-   
-   if (!dev->is_dvd()) {
-      Dmsg1(100, "device does not require mount, returning 0. dev=%s\n", dev->dev_name);
-      return true;
-   }
-
-#ifndef HAVE_DIRENT_H
-   Dmsg0(29, "readdir not available, cannot guess volume name\n");
-   return true; 
-#endif
-   
-   update_free_space_dev(dev);
-
-   if (mount_dev(dev, 1) < 0) {
-      /* If the device cannot be mounted, check if it is writable */
-      if (dev->have_media()) {
-         Dmsg1(100, "device cannot be mounted, but it seems to be writable, returning 0. dev=%s\n", dev->dev_name);
-         return true;
-      } else {
-         Dmsg1(100, "device cannot be mounted, and is not writable, returning -1. dev=%s\n", dev->dev_name);
-         return false;
-      }
-   }
-      
-   name_max = pathconf(".", _PC_NAME_MAX);
-   if (name_max < 1024) {
-      name_max = 1024;
-   }
-      
-   if (!(dp = opendir(dev->device->mount_point))) {
-      berrno be;
-      dev->dev_errno = errno;
-      Dmsg3(29, "failed to open dir %s (dev=%s), ERR=%s\n", dev->device->mount_point, dev->dev_name, be.strerror());
-      return false;
-   }
-   
-   entry = (struct dirent *)malloc(sizeof(struct dirent) + name_max + 100);
-   while (1) {
-      if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) {
-         dev->dev_errno = ENOENT;
-         Dmsg2(29, "failed to find suitable file in dir %s (dev=%s)\n", dev->device->mount_point, dev->dev_name);
-         closedir(dp);
-         free(entry);
-         return false;
-      }
-      
-      ASSERT(name_max+1 > (int)sizeof(struct dirent) + (int)NAMELEN(entry));
-      
-      if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
-         continue;
-      }
-      
-      pm_strcpy(guessedname, dev->device->mount_point);
-      if (guessedname.c_str()[strlen(guessedname.c_str())-1] != '/') {
-         pm_strcat(guessedname, "/");
-      }
-      pm_strcat(guessedname, entry->d_name);
-      
-      if (stat(guessedname.c_str(), &statp) < 0) {
-         berrno be;
-         Dmsg3(29, "failed to stat %s (dev=%s), ERR=%s\n",
-               guessedname.c_str(), dev->dev_name, be.strerror());
-         continue;
-      }
-      
-      if (!S_ISREG(statp.st_mode) || (statp.st_size < 500)) {
-         Dmsg2(100, "%s is not a regular file, or less than 500 bytes (dev=%s)\n", 
-               guessedname.c_str(), dev->dev_name);
-         continue;
-      }
-      
-      /* Ok, we found a good file, remove the part extension if possible. */
-      for (index = strlen(guessedname.c_str())-1; index >= 0; index--) {
-         if ((guessedname.c_str()[index] == '/') || 
-             (guessedname.c_str()[index] < '0') || 
-             (guessedname.c_str()[index] > '9')) {
-            break;
-         }
-         if (guessedname.c_str()[index] == '.') {
-            guessedname.c_str()[index] = '\0';
-            break;
-         }
-      }
-      
-      if ((stat(guessedname.c_str(), &statp) < 0) || (statp.st_size < 500)) {
-         /* The file with extension truncated does not exists or is too small, so use it with its extension. */
-         berrno be;
-         Dmsg3(100, "failed to stat %s (dev=%s), using the file with its extension, ERR=%s\n", 
-               guessedname.c_str(), dev->dev_name, be.strerror());
-         pm_strcpy(guessedname, dev->device->mount_point);
-         if (guessedname.c_str()[strlen(guessedname.c_str())-1] != '/') {
-            pm_strcat(guessedname, "/");
-         }
-         pm_strcat(guessedname, entry->d_name);
-         continue;
-      }
-      break;
-   }
-   closedir(dp);
-   free(entry);
-   
-   if (dev->fd >= 0) {
-      close(dev->fd);
-   }
-     
-   Dmsg1(100, "open(%s) read-only\n", guessedname.c_str());
-   if ((dev->fd = open(guessedname.c_str(), O_RDONLY | O_BINARY)) < 0) {
-      berrno be;
-      dev->dev_errno = errno;
-      Dmsg3(29, "failed to open %s (dev=%s), ERR=%s\n", 
-            guessedname.c_str(), dev->dev_name, be.strerror());
-      Dmsg0(100, "Call open_first_part\n");
-      if (open_first_part(dev, OPEN_READ_ONLY) < 0) {
-         berrno be;
-         dev->dev_errno = errno;
-         Mmsg1(&dev->errmsg, _("Could not open_first_part, ERR=%s\n"), be.strerror());
-         Emsg0(M_FATAL, 0, dev->errmsg);         
-      }
-      return false;
-   }
-   dev->part_start = 0;
-   dev->part_size = statp.st_size;
-   dev->part = 0;
-   dev->set_opened();
-   dev->use_count = 1;
-   Dmsg2(29, "Exit: %s opened (dev=%s)\n", guessedname.c_str(), dev->dev_name);
-   
    return true;
 }
-#endif
-
 
 /* Update the free space on the device */
 void update_free_space_dev(DEVICE* dev) 
@@ -357,6 +181,7 @@ void update_free_space_dev(DEVICE* dev)
    Dmsg1(29, "update_free_space_dev: cmd=%s\n", ocmd.c_str());
 
    results = get_pool_memory(PM_MESSAGE);
+   results[0] = 0;
    
    /* Try at most 3 times to get the free space on the device. This should perhaps be configurable. */
    timeout = 3;
@@ -400,7 +225,7 @@ void update_free_space_dev(DEVICE* dev)
    return;
 }
 
-static int dvd_write_part(DEVICE *dev) 
+static bool dvd_write_part(DEVICE *dev) 
 {
    Dmsg1(29, "dvd_write_part: device is %s\n", dev->dev_name);
    
@@ -410,11 +235,12 @@ static int dvd_write_part(DEVICE *dev)
    
    POOL_MEM ocmd(PM_FNAME);
    POOLMEM *results;
-   results = get_pool_memory(PM_MESSAGE);
    char* icmd;
    int status;
    int timeout;
    
+   results = get_pool_memory(PM_MESSAGE);
+   results[0] = 0;
    icmd = dev->device->write_part_command;
    
    edit_device_codes_dev(dev, ocmd.c_str(), icmd);
@@ -433,16 +259,15 @@ static int dvd_write_part(DEVICE *dev)
       Dmsg1(000, "%s", dev->errmsg);
       dev->dev_errno = EIO;
       free_pool_memory(results);
-      return -1;
-   } else {
-      Dmsg1(10, "dvd_write_part: command output=%s\n", results);
-      POOL_MEM archive_name(PM_FNAME);
-      Dmsg1(100, "Call get_filename. Vol=%s\n", dev->VolCatInfo.VolCatName);
-      make_dvd_filename(dev, archive_name);
-      unlink(archive_name.c_str());
-      free_pool_memory(results);
-      return 0;
+      return false;
    }
+
+   POOL_MEM archive_name(PM_FNAME);
+   /* Delete spool file */
+   make_spooled_dvd_filename(dev, archive_name);
+   unlink(archive_name.c_str());
+   free_pool_memory(results);
+   return true;
 }
 
 /* Open the next part file.
@@ -454,7 +279,8 @@ int open_next_part(DCR *dcr)
 {
    DEVICE *dev = dcr->dev;
       
-   Dmsg3(29, "Enter: open_next_part %s %s %d\n", dev->dev_name, 
+   Dmsg5(29, "Enter: open_next_part part=%d npart=%d dev=%s vol=%s mode=%d\n", 
+      dev->part, dev->num_parts, dev->print_name(),
          dev->VolCatInfo.VolCatName, dev->openmode);
    /* When appending, do not open a new part if the current is empty */
    if (dev->can_append() && (dev->part == dev->num_parts) && 
@@ -475,7 +301,7 @@ int open_next_part(DCR *dcr)
     *  DVD before opening the next part.
     */
    if (dev->is_dvd() && (dev->part == dev->num_parts) && dev->can_append()) {
-      if (dvd_write_part(dev) < 0) {
+      if (!dvd_write_part(dev)) {
          return -1;
       }
    }
@@ -483,6 +309,7 @@ int open_next_part(DCR *dcr)
    dev->part_start += dev->part_size;
    dev->part++;
    
+   Dmsg2(29, "part=%d num_parts=%d\n", dev->part, dev->num_parts);
    if ((dev->num_parts < dev->part) && dev->can_append()) {
       POOL_MEM archive_name(PM_FNAME);
       struct stat buf;
@@ -491,16 +318,16 @@ int open_next_part(DCR *dcr)
        * First check what is on DVD.  If out part is there, we
        *   are in trouble, so bail out.
        */
-      make_dvd_filename(dev, archive_name);   /* makes dvd name */
+      make_mounted_dvd_filename(dev, archive_name);   /* makes dvd name */
       if (stat(archive_name.c_str(), &buf) == 0) {
-         /* bad new bail out */
+         /* bad news bail out */
          Mmsg1(&dev->errmsg, _("Next Volume part already exists on DVD. Cannot continue: %s\n"),
             archive_name.c_str());
          return -1;
       }
 
       dev->num_parts = dev->part;
-      make_dvd_filename(dev, archive_name);   /* makes spool name */
+      make_spooled_dvd_filename(dev, archive_name);   /* makes spool name */
       
       /* Check if the next part exists in spool directory . */
       if ((stat(archive_name.c_str(), &buf) == 0) || (errno != ENOENT)) {
@@ -568,7 +395,7 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence)
    dcr = (DCR *)dev->attached_dcrs->first();  /* any dcr will do */
    switch(whence) {
    case SEEK_SET:
-      Dmsg1(100, "lseek_dev SEEK_SET called %d\n", offset);
+      Dmsg1(100, "lseek_dev SEEK_SET to %d\n", (int)offset);
       if ((uint64_t)offset >= dev->part_start) {
          if ((uint64_t)(offset - dev->part_start) < dev->part_size) {
             /* We are staying in the current part, just seek */
@@ -598,22 +425,21 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence)
       }
       break;
    case SEEK_CUR:
-      Dmsg1(100, "lseek_dev SEEK_CUR called %d\n", offset);
+      Dmsg1(100, "lseek_dev SEEK_CUR to %d\n", (int)offset);
       if ((pos = lseek(dev->fd, (off_t)0, SEEK_CUR)) < 0) {
          return pos;   
       }
       pos += dev->part_start;
       if (offset == 0) {
          return pos;
-      }
-      else { /* Not used in Bacula, but should work */
+      } else { /* Not used in Bacula, but should work */
          return lseek_dev(dev, pos, SEEK_SET);
       }
       break;
    case SEEK_END:
-      Dmsg1(100, "lseek_dev SEEK_END called %d\n", offset);
+      Dmsg1(100, "lseek_dev SEEK_END to %d\n", (int)offset);
       if (offset > 0) { /* Not used by bacula */
-         Dmsg1(100, "lseek_dev SEEK_END called with an invalid offset %d\n", offset);
+         Dmsg1(100, "lseek_dev SEEK_END called with an invalid offset %d\n", (int)offset);
          errno = EINVAL;
          return -1;
       }
@@ -680,7 +506,6 @@ bool dvd_close_job(DCR *dcr)
          dev->dev_errno = EIO;
          ok = false;
       }
-      
       dev->VolCatInfo.VolCatParts = dev->num_parts;
    }
    return ok;
@@ -725,7 +550,7 @@ static char *edit_device_codes_dev(DEVICE* dev, char *omsg, const char *imsg)
             str = dev->device->mount_point;
             break;
          case 'v':
-            make_dvd_filename(dev, archive_name);
+            make_spooled_dvd_filename(dev, archive_name);
             str = archive_name.c_str();
             break;
          default:
@@ -740,9 +565,9 @@ static char *edit_device_codes_dev(DEVICE* dev, char *omsg, const char *imsg)
          add[1] = 0;
          str = add;
       }
-      Dmsg1(900, "add_str %s\n", str);
+      Dmsg1(1900, "add_str %s\n", str);
       pm_strcat(&omsg, (char *)str);
-      Dmsg1(800, "omsg=%s\n", omsg);
+      Dmsg1(1800, "omsg=%s\n", omsg);
    }
    return omsg;
 }
index 67b748f498d385ac324197d4b393342c7cc9b59b..b7a101b3ecd90c9b1fd1a66dde94e6adc0c8d461 100644 (file)
@@ -146,25 +146,12 @@ mount_next_vol:
    }
 
    /* Ensure the device is open */
-   /* If we have a dvd that requires mount, we first want to guess
-    * which Volume is loaded, so we continue (if the wrong device is
-    * loaded, open_device just below would fail. 
-    */
-   if (!dev->is_dvd()) {
-      if (!open_device(dcr)) {
-         if (dev->poll) {
-            goto mount_next_vol;
-         } else {
-            return false;
-         }
+   if (!open_device(dcr)) {
+      if (dev->poll) {
+         goto mount_next_vol;
+      } else {
+         return false;
       }
-   } else {
-      /*
-       * Just copy the VolCatName in the device resource 
-       *   (usually done by open_dev).
-       * It is necessary so we can open the real files later.   
-       */
-      bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolCatInfo.VolCatName, sizeof(dev->VolCatInfo.VolCatName));
    }
 
    /*
index 618ae64cb7f1fe0e4c253341577d3f257222e085..e08d3833ddaed036e442df9661fa520a0f622979 100644 (file)
@@ -118,7 +118,8 @@ bool dvd_close_job(DCR *dcr);
 bool mount_dev(DEVICE* dev, int timeout);
 bool unmount_dev(DEVICE* dev, int timeout);
 void update_free_space_dev(DEVICE *dev);
-void make_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
+void make_mounted_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
+void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name);
 
 /* From device.c */
 bool     open_device(DCR *dcr);
index a02c70d757eedba8693dd3782ad9fd9cb3eed6ec..724e560831276eb826a5e16760ff6d2a8506861e 100644 (file)
@@ -99,19 +99,19 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
    if (rec->FileIndex < 0) {
       return true;
    }
-   Dmsg5(100, "Send to FD: SessId=%u SessTim=%u FI=%d Strm=%d, len=%d\n",
+   Dmsg5(400, "Send to FD: SessId=%u SessTim=%u FI=%d Strm=%d, len=%d\n",
       rec->VolSessionId, rec->VolSessionTime, rec->FileIndex, rec->Stream,
       rec->data_len);
 
    /* Send record header to File daemon */
    if (!bnet_fsend(fd, rec_header, rec->VolSessionId, rec->VolSessionTime,
           rec->FileIndex, rec->Stream, rec->data_len)) {
-      Dmsg1(30, ">filed: Error Hdr=%s\n", fd->msg);
+      Pmsg1(000, ">filed: Error Hdr=%s\n", fd->msg);
       Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
          bnet_strerror(fd));
       return false;
    } else {
-      Dmsg1(31, ">filed: Hdr=%s\n", fd->msg);
+      Dmsg1(400, ">filed: Hdr=%s\n", fd->msg);
    }
 
 
@@ -119,7 +119,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec)
    save_msg = fd->msg;          /* save fd message pointer */
    fd->msg = rec->data;         /* pass data directly to bnet_send */
    fd->msglen = rec->data_len;
-   Dmsg1(31, ">filed: send %d bytes data.\n", fd->msglen);
+   Dmsg1(400, ">filed: send %d bytes data.\n", fd->msglen);
    if (!bnet_send(fd)) {
       Pmsg1(000, "Error sending to FD. ERR=%s\n", bnet_strerror(fd));
       Jmsg1(jcr, M_FATAL, 0, _("Error sending to File daemon. ERR=%s\n"),
index e48b9817f3f1aa85540d3ba0a0af4bb2168f2ccb..f6b17003d90c5ca4ae63241f2a041803a7e4f982 100644 (file)
@@ -604,7 +604,7 @@ static bool reserve_device_for_append(DCR *dcr, bool PreferMountedVols)
    }
 
    dev->reserved_device++;
-   Dmsg1(200, "============= Inc reserve=%d\n", dev->reserved_device);
+   Dmsg1(200, "Inc reserve=%d\n", dev->reserved_device);
    dcr->reserved_device = true;
    ok = true;
 
index 0ca77f7e05d0eacb980a227aa8fce3f17738f621..c1659c10843925dbfe2c7b85b93aa5656f86fa0c 100644 (file)
@@ -1,8 +1,8 @@
 /* */
 #undef  VERSION
 #define VERSION "1.37.28"
-#define BDATE   "29 June 2005"
-#define LSMDATE "29Jun05"
+#define BDATE   "30 June 2005"
+#define LSMDATE "30Jun05"
 
 /* Debug flags */
 #undef  DEBUG