]> git.sur5r.net Git - bacula/bacula/commitdiff
- Make all files in working directory have .xxx at end.
authorKern Sibbald <kern@sibbald.com>
Mon, 18 Jul 2005 19:25:16 +0000 (19:25 +0000)
committerKern Sibbald <kern@sibbald.com>
Mon, 18 Jul 2005 19:25:16 +0000 (19:25 +0000)
- Work on DVD writing.

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

bacula/kernstodo
bacula/src/lib/message.c
bacula/src/stored/block.c
bacula/src/stored/dev.c
bacula/src/stored/dev.h
bacula/src/stored/dvd.c
bacula/src/stored/label.c
bacula/src/stored/spool.c

index bb92b379996bdefab9f3cf22864bdc69aa9e3ba6..600115e41572ca61626bf9b30ac2748b6bb8b23f 100644 (file)
@@ -47,7 +47,7 @@ Document:
 - On Win32 working directory must have drive letter ????
 - On Win32 working directory must be writable by SYSTEM to
   do restores.
-
+- Clean up working extensions: db, pid, state, bsr, mail, conmsg, spool
 
 
 For 1.39:
index c608fecee1963d15832cbbb3361960dfc1e13719..c641983ae0a7c3c9a22e258309b7820c541e906b 100755 (executable)
@@ -344,10 +344,10 @@ void rem_msg_dest(MSGS *msg, int dest_code, int msg_type, char *where)
 static void make_unique_mail_filename(JCR *jcr, POOLMEM *&name, DEST *d)
 {
    if (jcr) {
-      Mmsg(name, "%s/%s.mail.%s.%d", working_directory, my_name,
+      Mmsg(name, "%s/%s.%s.%d.mail", working_directory, my_name,
                  jcr->Job, (int)(long)d);
    } else {
-      Mmsg(name, "%s/%s.mail.%s.%d", working_directory, my_name,
+      Mmsg(name, "%s/%s.%s.%d.mail", working_directory, my_name,
                  my_name, (int)(long)d);
    }
    Dmsg1(850, "mailname=%s\n", name);
index ca6cbc8def565d1547f2a5613de3ccb4ce376ece..4b65c0d975eb60bb0063c1db677e78824be07398 100644 (file)
@@ -544,8 +544,9 @@ bool write_block_to_dev(DCR *dcr)
             dev->VolCatInfo.VolCatName,
             dev->file, dev->block_num, dev->print_name(), wlen, stat);
       }
-      Dmsg6(100, "=== Write error. size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n",
-         wlen, stat, dev->block_num, block->BlockNumber, dev->dev_errno, strerror(dev->dev_errno));
+      Dmsg7(100, "=== Write error. fd=%d size=%u rtn=%d dev_blk=%d blk_blk=%d errno=%d: ERR=%s\n",
+         dev->fd, wlen, stat, dev->block_num, block->BlockNumber, 
+         dev->dev_errno, strerror(dev->dev_errno));
 
       ok = terminate_writing_volume(dcr);
       if (!ok && !forge_on) {
index d75b03a3b1fd5389dea50bcc8b359d3e40a981f9..b34e814b4d778f3e0d2741dc4ab1d3fcffe638d2 100644 (file)
@@ -338,7 +338,7 @@ void DEVICE::open_tape_device(int omode)
    }
    /* If busy retry each second for max_open_wait seconds */
 open_again:
-   Dmsg1(500, "Try open %s\n", dev_name);
+   Dmsg1(500, "Try open %s\n", print_name());
    /* Use system open() */
    while ((fd = ::open(dev_name, mode, MODE_RW+nonblocking)) < 0) {
       berrno be;
@@ -377,7 +377,8 @@ open_again:
          ::close(fd);                /* use system close() */
          goto open_again;
       }
-      openmode = mode;               /* save open mode */
+      openmode = omode;              /* save open mode */
+      Dmsg2(100, "openmode=%d %s\n", openmode, mode_to_str(openmode));
       dev_errno = 0;
       set_opened();
       use_count = 1;
@@ -422,6 +423,7 @@ void DEVICE::open_file_device(int omode)
    Dmsg3(29, "open dev: %s dev=%s mode=%s\n", is_dvd()?"DVD":"disk",
          archive_name.c_str(), mode_to_str(omode));
    openmode = omode;
+   Dmsg2(100, "openmode=%d %s\n", openmode, mode_to_str(openmode));
    
    set_mode(omode);
    /* If creating file, give 0640 permissions */
@@ -486,6 +488,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode)
       is_dvd()?"DVD":"disk", archive_name.c_str(), mode_to_str(omode),
       part, num_parts);
    openmode = omode;
+   Dmsg2(100, "openmode=%d %s\n", openmode, mode_to_str(openmode));
    
    /*
     * If we are not trying to access the last part, set mode to 
@@ -522,6 +525,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode)
          fd = ::open(archive_name.c_str(), mode, 0640);  /* try on spool */
       }
    }
+   Dmsg1(100, "after open fd=%d\n", fd);
    if (fd >= 0) {
       /* Get size of file */
       if (fstat(fd, &filestat) < 0) {
@@ -539,17 +543,21 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode)
          set_opened();
          use_count = 1;
          update_pos_dev(this);                /* update position */
-         /* Just created Volume */
-         if (omode == OPEN_READ_WRITE && part_size == 0) {
+         /* Check if just created Volume  part */
+         if (omode == OPEN_READ_WRITE && (part == 0 || part_size == 0)) {
             part++;
-            num_parts++;
+            num_parts = part;
             VolCatInfo.VolCatParts = num_parts;
+         } else {
+            if (part == 0) {             /* we must have opened the first part */
+               part++;
+            }
          }
       }
    }
    Dmsg4(29, "open dev: DVD fd=%d opened, part=%d nump=%d, part_size=%u\n", 
       fd, part, num_parts, part_size);
-   if (is_open() && is_dvd() && (omode != OPEN_READ_ONLY) && 
+   if (is_open() && (omode != OPEN_READ_ONLY) && 
        (free_space_errno == 0 || num_parts == part)) {
       update_free_space_dev(this);
    }
@@ -560,7 +568,7 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode)
 #undef rewind_dev
 bool _rewind_dev(char *file, int line, DEVICE *dev)
 {
-   Dmsg2(100, "rewind_dev called from %s:%d\n", file, line);
+   Dmsg3(100, "rewind_dev fd=%d called from %s:%d\n", dev->fd, file, line);
    return rewind_dev(dev);
 }
 #endif
@@ -575,7 +583,7 @@ bool rewind_dev(DEVICE *dev)
    struct mtop mt_com;
    unsigned int i;
 
-   Dmsg1(29, "rewind_dev %s\n", dev->print_name());
+   Dmsg2(29, "rewind_dev fd=%d %s\n", dev->fd, dev->print_name());
    if (dev->fd < 0) {
       dev->dev_errno = EBADF;
       Mmsg1(dev->errmsg, _("Bad call to rewind_dev. Device %s not open\n"),
@@ -1656,6 +1664,7 @@ static void do_close(DEVICE *dev)
    dev->file_size = 0;
    dev->file_addr = 0;
    dev->part = 0;
+   dev->num_parts = 0;
    dev->part_size = 0;
    dev->part_start = 0;
    dev->EndFile = dev->EndBlock = 0;
index 726ec18939300c0d259ad8e1d5efb9ba67471f42..5e9d5c2a16b42154ac0b31b1a089ff8aa3173922 100644 (file)
@@ -112,6 +112,7 @@ enum {
 #define ST_MOUNTED         (1<<15)    /* the device is mounted to the mount point */
 #define ST_MEDIA           (1<<16)    /* Media found in mounted device */
 #define ST_OFFLINE         (1<<17)    /* set offline by operator */
+#define ST_PART_SPOOLED    (1<<18)    /* spooling part */
 
 /* dev_blocked states (mutually exclusive) */
 enum {
@@ -260,6 +261,7 @@ public:
    int is_offline() const { return state & ST_OFFLINE; }
    int is_labeled() const { return state & ST_LABEL; }
    int is_mounted() const { return state & ST_MOUNTED; }
+   int is_part_spooled() const { return state & ST_PART_SPOOLED; }
    int have_media() const { return state & ST_MEDIA; }
    int is_short_block() const { return state & ST_SHORT; }
    int is_busy() const { return (state & ST_READ) || num_writers || reserved_device; }
@@ -303,6 +305,8 @@ public:
    void set_mounted() { state |= ST_MOUNTED; };
    void set_media() { state |= ST_MEDIA; };
    void set_short_block() { state |= ST_SHORT; };
+   void set_part_spooled(int val) { if (val) state |= ST_PART_SPOOLED; \
+          else state &= ~ST_PART_SPOOLED; };
    void set_mounted(int val) { if (val) state |= ST_MOUNTED; \
           else state &= ~ST_MOUNTED; };
    void clear_append() { state &= ~ST_APPEND; };
index e13357a684f6c09142a70fef1f164e6490720516..8425f2c913f322f48fe885f61448e874d983225c 100644 (file)
@@ -37,6 +37,7 @@ void make_mounted_dvd_filename(DEVICE *dev, POOL_MEM &archive_name)
 {
    pm_strcpy(archive_name, dev->device->mount_point);
    add_file_and_part_name(dev, archive_name);
+   dev->set_part_spooled(false);
 }
 
 void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name)
@@ -48,6 +49,7 @@ void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &archive_name)
       pm_strcpy(archive_name, working_directory);
    }
    add_file_and_part_name(dev, archive_name);
+   dev->set_part_spooled(true);
 }      
 
 static void add_file_and_part_name(DEVICE *dev, POOL_MEM &archive_name)
@@ -125,12 +127,11 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout)
    } else {
       timeout = 0;
    }
-   results = get_pool_memory(PM_MESSAGE);
+   results = get_memory(2000);
    results[0] = 0;
    /* If busy retry each second */
    while ((status = run_program_full_output(ocmd.c_str(), 
                        dev->max_open_wait/2, results)) != 0) {
-      Dmsg1(100, "results len=%d\n", strlen(results));
       if (fnmatch("*is already mounted on", results, 0) == 0) {
          break;
       }
@@ -147,7 +148,6 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout)
       Dmsg2(40, "Device %s cannot be mounted. ERR=%s\n", dev->print_name(), results);
       Mmsg(dev->errmsg, "Device %s cannot be mounted. ERR=%s\n", 
            dev->print_name(), results);
-#ifdef xxx
       /*
        * Now, just to be sure it is not mounted, try to read the
        *  filesystem.
@@ -185,7 +185,6 @@ static bool do_mount_dev(DEVICE* dev, int mount, int dotimeout)
          break;                          /*   there must be something mounted */
       }
 get_out:
-#endif
       free_pool_memory(results);
       return false;
    }
@@ -227,7 +226,6 @@ void update_free_space_dev(DEVICE* dev)
    
    while (1) {
       if (run_program_full_output(ocmd.c_str(), dev->max_open_wait/2, results) == 0) {
-         Dmsg1(100, "results len=%d\n", strlen(results));
          Dmsg1(100, "Free space program run : %s\n", results);
          free = str_to_int64(results);
          if (free >= 0) {
@@ -310,7 +308,6 @@ static bool dvd_write_part(DCR *dcr)
    Dmsg2(29, "dvd_write_part: cmd=%s timeout=%d\n", ocmd.c_str(), timeout);
       
    status = run_program_full_output(ocmd.c_str(), timeout, results.c_str());
-   Dmsg1(100, "results len=%d\n", strlen(results.c_str()));
    if (status != 0) {
       Mmsg1(dev->errmsg, "Error while writing current part to the DVD: %s", 
             results.c_str());
@@ -327,7 +324,6 @@ static bool dvd_write_part(DCR *dcr)
    update_free_space_dev(dev);
    Jmsg(dcr->jcr, M_INFO, 0, _("Remaining free space %s on %s\n"), 
       edit_uint64_with_commas(dev->free_space, ed1), dev->print_name());
-   Dmsg1(100, "results=%s\n", results.c_str());
    return true;
 }
 
@@ -417,7 +413,7 @@ int open_next_part(DCR *dcr)
       dev->num_parts = dev->part;
       dev->VolCatInfo.VolCatParts = dev->part;
    }
-   Dmsg2(50, "Call dev->open(vol=%s, mode=%d", dev->VolCatInfo.VolCatName, 
+   Dmsg2(50, "Call dev->open(vol=%s, mode=%d\n", dev->VolCatInfo.VolCatName, 
          dev->openmode);
    /* Open next part */
    if (dev->open(dcr, dev->openmode) < 0) {
@@ -464,12 +460,13 @@ int open_first_part(DCR *dcr, int mode)
 /* Protected version of lseek, which opens the right part if necessary */
 off_t lseek_dev(DEVICE *dev, off_t offset, int whence)
 {
-   int openmode;
    DCR *dcr;
    off_t pos;
    
-   Dmsg0(100, "Enter lseek_dev\n");
-   if (!dev->is_dvd() || dev->num_parts <= 1) { /* If there is only one part, simply call lseek. */
+   Dmsg3(100, "Enter lseek_dev fd=%d part=%d nparts=%d\n", dev->fd,
+      dev->part, dev->num_parts);
+   if (!dev->is_dvd()) { 
+      Dmsg0(100, "Using sys lseek\n");
       return lseek(dev->fd, offset, whence);
    }
       
@@ -478,9 +475,9 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence)
    case SEEK_SET:
       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) {
+         offset -= dev->part_start; /* adjust for start of this part */
+         if (offset == 0 || (uint64_t)offset < dev->part_size) {
             /* We are staying in the current part, just seek */
-            offset -= dev->part_start; /* adjust for start of this part */
             if ((pos = lseek(dev->fd, offset, SEEK_SET)) < 0) {
                return pos;   
             } else {
@@ -522,24 +519,36 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence)
       break;
    case SEEK_END:
       Dmsg1(100, "lseek_dev SEEK_END to %d\n", (int)offset);
+      /*
+       * Bacula does not use offsets for SEEK_END
+       *  Also, Bacula uses seek_end only when it wants to
+       *  append to the volume, so for a dvd that means
+       *  that the volume must be spooled since the DVD
+       *  itself is read-only (as currently implemented).
+       */
       if (offset > 0) { /* Not used by bacula */
          Dmsg1(100, "lseek_dev SEEK_END called with an invalid offset %d\n", (int)offset);
          errno = EINVAL;
          return -1;
       }
-      
-      if (dev->part == dev->num_parts) { /* The right part is already loaded */
+      /* If we are already on a spooled part and have the
+       *  right part number, simply seek
+       */
+      if (dev->is_part_spooled() && dev->part == dev->num_parts) {
          if ((pos = lseek(dev->fd, (off_t)0, SEEK_END)) < 0) {
             return pos;   
          } else {
             return pos + dev->part_start;
          }
       } else {
-         /* Load the first part, then load the next until we reach the last one.
-          * This is the only way to be sure we compute the right file address. */
-         /* Save previous openmode, and open all but last part read-only (useful for DVDs) */
-         openmode = dev->openmode;
-         
+         /*
+          * Load the first part, then load the next until we reach the last one.
+          * This is the only way to be sure we compute the right file address.
+          *
+          * Save previous openmode, and open all but last part read-only 
+          * (useful for DVDs) 
+          */
+         int modesave = dev->openmode;
          /* Works because num_parts > 0. */
          if (open_first_part(dcr, OPEN_READ_ONLY) < 0) {
             Dmsg0(100, "lseek_dev failed while trying to open the first part\n");
@@ -551,7 +560,7 @@ off_t lseek_dev(DEVICE *dev, off_t offset, int whence)
                return -1;
             }
          }
-         dev->openmode = openmode;
+         dev->openmode = modesave;
          if (open_next_part(dcr) < 0) {
             Dmsg0(100, "lseek_dev failed while trying to open the next part\n");
             return -1;
index 26c88b6170ef62d983d69756cea11d432ead5508..50357885a27714d0f818cd6a3b612a7ba33f7ea8 100644 (file)
@@ -357,7 +357,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle)
    DEVICE *dev = dcr->dev;
    JCR *jcr = dcr->jcr;
 
-   Dmsg1(190, "set append found freshly labeled volume. dev=%x\n", dev);
+   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();
    if (!write_volume_label_to_block(dcr)) {
@@ -398,7 +398,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle)
       }
 
       /* Attempt write to check write permission */
-      Dmsg0(200, "Attempt to write to device.\n");
+      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(), strerror_dev(dev));
index 474ea44199d965c65791ade25c97ba43482a7d59..bf6925b2f82ce383f38efc9563f41faf80912344 100644 (file)
@@ -131,7 +131,7 @@ static void make_unique_data_spool_filename(DCR *dcr, POOLMEM **name)
    } else {
       dir = working_directory;
    }
-   Mmsg(name, "%s/%s.data.spool.%s.%s", dir, my_name, dcr->jcr->Job, 
+   Mmsg(name, "%s/%s.data.%s.%s.spool", dir, my_name, dcr->jcr->Job, 
         dcr->device->hdr.name);
 }
 
@@ -563,7 +563,7 @@ bail_out:
 
 static void make_unique_spool_filename(JCR *jcr, POOLMEM **name, int fd)
 {
-   Mmsg(name, "%s/%s.attr.spool.%s.%d", working_directory, my_name,
+   Mmsg(name, "%s/%s.attr.%s.%d.spool", working_directory, my_name,
       jcr->Job, fd);
 }