]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dvd.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / stored / dvd.c
index a6f79af56400962752dec64ee143c269d4ffd2f0..417cf5fcec0fad34143699161341700c004b17d1 100644 (file)
@@ -209,7 +209,7 @@ get_out:
    
    dev->set_mounted(mount);              /* set/clear mounted flag */
    free_pool_memory(results);
-   /* Do not check free space when unmounting (otherwise it will mount it again) */
+   /* Do not check free space when unmounting */
    if (mount) {
       update_free_space_dev(dev);
    }
@@ -317,9 +317,12 @@ bool dvd_write_part(DCR *dcr)
     *     been crossed
     *   - Bacula thinks he must finish to write to the device, so it
     *     tries to write the last part (0-byte), but dvd-writepart fails...
+    *
+    * There is one exception: when recycling a volume, we write a blank part
+    * file, so, then, we need to accept to write it.
     */
-   if (dev->part_size == 0) {
-      Dmsg3(29, "dvd_write_part: device is %s, won't write blank part %d\n", dev->print_name(), dev->part);
+   if ((dev->part_size == 0) && (dev->part > 0)) {
+      Dmsg2(29, "dvd_write_part: device is %s, won't write blank part %d\n", dev->print_name(), dev->part);
       /* Delete spool file */
       make_spooled_dvd_filename(dev, archive_name);
       unlink(archive_name.c_str());
@@ -346,10 +349,23 @@ bool dvd_write_part(DCR *dcr)
     * timeout = dev->max_open_wait + (dev->max_part_size/(1350*1024/2));
     * I modified this for a longer timeout; pre-formatting, blanking and
     * writing can take quite a while
-    *
-    * NB: Use part_size and not max_part_size, needed when you don't set max part size (so it defaults to 0)
     */
-   timeout = dev->max_open_wait + (dev->part_size/(1350*1024)*8);
+
+   /* Explanation of the timeout value, when writing the first part,
+    *  by Arno Lehmann :
+    * 9 GB, write speed 1x: 6990 seconds (almost 2 hours...)
+    * Overhead: 900 seconds (starting, initializing, finalizing,probably 
+    *   reloading 15 minutes)
+    * Sum: 15780.
+    * A reasonable last-exit timeout would be 16000 seconds. Quite long - 
+    * almost 4.5 hours, but hopefully, that timeout will only ever be needed 
+    * in case of a serious emergency.
+    */
+
+   if (dev->part == 0)
+      timeout = 16000;
+   else
+      timeout = dev->max_open_wait + (dev->part_size/(1350*1024/4));
 
    Dmsg2(29, "dvd_write_part: cmd=%s timeout=%d\n", ocmd.c_str(), timeout);
       
@@ -472,6 +488,8 @@ int dvd_open_next_part(DCR *dcr)
     *  needed. If num_parts represents what is on the DVD
     *  we should only need to change it when writing a part
     *  to the DVD.
+    * NB. As dvd_write_part increments dev->num_parts, I also
+    *  think it is not needed.
     */
    if (dev->num_parts < dev->part) {
       Dmsg2(100, "Set npart=%d to part=%d\n", dev->num_parts, dev->part);
@@ -502,8 +520,8 @@ int dvd_open_first_part(DCR *dcr, int mode)
 {
    DEVICE *dev = dcr->dev;
 
-   Dmsg4(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_parts=%d\n", dev->print_name(), 
-         dev->VolCatInfo.VolCatName, dev->openmode, dev->num_parts);
+   Dmsg5(29, "Enter: ==== open_first_part dev=%s Vol=%s mode=%d num_parts=%d append=%d\n", dev->print_name(), 
+         dev->VolCatInfo.VolCatName, dev->openmode, dev->num_parts, dev->can_append());
 
    if (dev->fd >= 0) {
       close(dev->fd);
@@ -516,11 +534,16 @@ int dvd_open_first_part(DCR *dcr, int mode)
    
    Dmsg2(50, "Call dev->open(vol=%s, mode=%d)\n", dcr->VolCatInfo.VolCatName, 
          mode);
+   int append = dev->can_append();
    if (dev->open(dcr, mode) < 0) {
       Dmsg0(50, "open dev() failed\n");
       return -1;
    }
-   Dmsg1(50, "Leave open_first_part state=%s\n", dev->is_open()?"open":"not open");
+   if (append && (dev->part == dev->num_parts)) { /* If needed, set the append flag back */
+      dev->set_append();
+   }
+   Dmsg2(50, "Leave open_first_part state=%s append=%d\n", dev->is_open()?"open":"not open", dev->can_append());
+   
    return dev->fd;
 }
 
@@ -724,6 +747,11 @@ bool truncate_dvd_dev(DCR *dcr) {
       return false;
    }
    
+   /* Set num_parts to zero (on disk) */
+   dev->num_parts = 0;
+   dcr->VolCatInfo.VolCatParts = 0;
+   dev->VolCatInfo.VolCatParts = 0;
+   
    if (dvd_open_first_part(dcr, OPEN_READ_WRITE) < 0) {
       Dmsg0(100, "truncate_dvd_dev: Error while opening first part (2).\n");
       return false;
@@ -748,7 +776,7 @@ bool check_can_write_on_non_blank_dvd(DCR *dcr) {
    if (name_max < 1024) {
       name_max = 1024;
    }
-         
+   
    if (!(dp = opendir(dev->device->mount_point))) {
       berrno be;
       dev->dev_errno = errno;