From: Kern Sibbald Date: Thu, 14 Sep 2006 21:11:10 +0000 (+0000) Subject: kes Put removing zero sized spool part file in subroutine and X-Git-Tag: Release-2.0.0~448 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2ae3dee9e59e1e6cb16a14632bd6c7e83baf34c7;p=bacula%2Fbacula 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. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3469 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 50c79ebca2..7b2be84304 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -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(); } diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 184f1dbbfc..cc599b5657 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -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); diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index d2d871958e..8889efaa81 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -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! */ diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index d4ef800fc9..5ee722c81e 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -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; diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index b988bf0115..bf31bc8125 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -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); diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index a950550eb6..4e52178829 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -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().