]> git.sur5r.net Git - bacula/bacula/commitdiff
kes Put removing zero sized spool part file in subroutine and
authorKern Sibbald <kern@sibbald.com>
Thu, 14 Sep 2006 21:11:10 +0000 (21:11 +0000)
committerKern Sibbald <kern@sibbald.com>
Thu, 14 Sep 2006 21:11:10 +0000 (21:11 +0000)
     call from release_device().
kes  Add Richard's patch for relabel to dircmd.c, but save and restore
     dev Volume name.

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

bacula/src/stored/acquire.c
bacula/src/stored/dev.c
bacula/src/stored/dircmd.c
bacula/src/stored/dvd.c
bacula/src/stored/protos.h
bacula/technotes-1.39

index 50c79ebca28558738d4c1fb14975f32b4b602e3a..7b2be84304a3b63b5bc5908ff8a78c4efd375a45 100644 (file)
@@ -483,6 +483,7 @@ bool release_device(DCR *dcr)
 
    /* If no writers, close if file or !CAP_ALWAYS_OPEN */
    if (dev->num_writers == 0 && (!dev->is_tape() || !dev_cap(dev, CAP_ALWAYSOPEN))) {
+      dvd_remove_empty_part(dcr);        /* get rid of any empty spool part */
       dev->close();
    }
 
index 184f1dbbfc9b73103d08b2f2af503a42c1a150aa..cc599b5657aabf08f38db54fffe51d3800fb3187 100644 (file)
@@ -1776,37 +1776,6 @@ void DEVICE::close()
       return;                         /* already closed */
    }
 
-   if (is_dvd() && !unmount_dvd(this, 1)) {
-      Dmsg1(0, "Cannot unmount device %s.\n", print_name());
-   }
-   
-   /* Remove the last part file if it is empty */
-   if (is_dvd() && num_dvd_parts > 0) {
-      struct stat statp;
-      uint32_t part_save = part;
-      POOL_MEM archive_name(PM_FNAME);
-      int status;
-
-      part = num_dvd_parts;
-      make_spooled_dvd_filename(this, archive_name);
-      /* Check that the part file is empty */
-      status = stat(archive_name.c_str(), &statp);
-      if (status == 0 && statp.st_size == 0) {
-         Dmsg3(100, "Unlink empty part in close call make_dvd_filename. part=%d num=%d vol=%s\n", 
-                part, num_dvd_parts, VolCatInfo.VolCatName);
-         Dmsg1(100, "unlink(%s)\n", archive_name.c_str());
-         unlink(archive_name.c_str());
-         if (part_save == part) {
-           set_part_spooled(false);        /* no spooled part left */
-         }
-      } else if (status < 0) {                         
-         if (part_save == part) {
-           set_part_spooled(false);        /* spool doesn't exit */
-         }
-      }       
-      part = part_save;               /* restore part number */
-   }
-   
    /* Clean up device packet so it can be reused */
    clear_opened();
    state &= ~(ST_LABEL|ST_READ|ST_APPEND|ST_EOT|ST_WEOT|ST_EOF);
index d2d871958ebadaa36b591240dcfb648446b5f923..8889efaa811777800bd5718c052cbb8e089589dd 100644 (file)
@@ -447,12 +447,18 @@ static void label_volume_if_ok(DCR *dcr, char *oldname,
          break;
       }
       if (relabel && dev->is_dvd()) {
-         /* Change the partition file name */
-         bstrncpy(dcr->VolumeName, newname, sizeof(dcr->VolumeName));
+         /* Save dev VolumeName */
+         bstrncpy(dcr->VolumeName, dev->VolCatInfo.VolCatName, sizeof(dcr->VolumeName));
+         /* Use new name for DVD truncation */
+         bstrncpy(dev->VolCatInfo.VolCatName, newname, sizeof(dev->VolCatInfo.VolCatName));
          if (!dev->truncate(dcr)) {
             bnet_fsend(dir, _("3912 Failed to truncate previous DVD volume.\n"));
+            /* Restore device VolName */
+            bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName));
             break;
          }
+         /* Restore device VolName */
+         bstrncpy(dev->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dev->VolCatInfo.VolCatName));
       }
       free_volume(dev);               /* release old volume name */
       /* Fall through wanted! */
index d4ef800fc9633e6b2b715171ab0f511d530cb46f..5ee722c81eb256b90f3fd6976f0e297b4aa281dc 100644 (file)
@@ -52,6 +52,7 @@ void make_spooled_dvd_filename(DEVICE *dev, POOL_MEM &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, "/");
    }
@@ -756,6 +757,38 @@ bool dvd_close_job(DCR *dcr)
    return ok;
 }
 
+void dvd_remove_empty_part(DCR *dcr) 
+{
+   DEVICE *dev = dcr->dev;
+
+   /* Remove the last part file if it is empty */
+   if (dev->is_dvd() && dev->num_dvd_parts > 0) {
+      struct stat statp;
+      uint32_t part_save = dev->part;
+      POOL_MEM archive_name(PM_FNAME);
+      int status;
+
+      dev->part = dev->num_dvd_parts;
+      make_spooled_dvd_filename(dev, archive_name);
+      /* Check that the part file is empty */
+      status = stat(archive_name.c_str(), &statp);
+      if (status == 0 && statp.st_size == 0) {
+         Dmsg3(100, "Unlink empty part in close call make_dvd_filename. part=%d num=%d vol=%s\n", 
+                part_save, dev->num_dvd_parts, dev->VolCatInfo.VolCatName);
+         Dmsg1(100, "unlink(%s)\n", archive_name.c_str());
+         unlink(archive_name.c_str());
+         if (part_save == dev->part) {
+            dev->set_part_spooled(false);  /* no spooled part left */
+         }
+      } else if (status < 0) {                         
+         if (part_save == dev->part) {
+            dev->set_part_spooled(false);  /* spool doesn't exit */
+         }
+      }       
+      dev->part = part_save;               /* restore part number */
+   }
+}
+
 bool truncate_dvd(DCR *dcr) 
 {
    DEVICE* dev = dcr->dev;
index b988bf011532116276ea08a37d03208b4117ff5e..bf31bc8125f8d9ea17d8e4e8f66d29c41fa4297b 100644 (file)
@@ -109,6 +109,7 @@ bool    truncate_dvd(DCR *dcr);
 bool    check_can_write_on_non_blank_dvd(DCR *dcr);
 int     find_num_dvd_parts(DCR *dcr);
 off_t   lseek_dvd(DCR *dcr, off_t offset, int whence);
+void    dvd_remove_empty_part(DCR *dcr);
 
 /* From device.c */
 bool     open_device(DCR *dcr);
index a950550eb63977e8751a03cb9b8e9d92c47dc8a4..4e52178829fec67c024328f991d7eac498969dc0 100644 (file)
@@ -2,6 +2,10 @@
 
 General:
 14Sep06
+kes  Put removing zero sized spool part file in subroutine and
+     call from release_device().
+kes  Add Richard's patch for relabel to dircmd.c, but save and restore
+     dev Volume name.
 kes  Rework a lot of subroutines in dev.c to take dcr as an
      argument. This is done to eliminate the usage of attached_dcrs
      in lseek().