From: Kern Sibbald Date: Fri, 22 Feb 2008 15:03:16 +0000 (+0000) Subject: kes Add patch from Martin Schmid scm@apsag.com that checks to see if X-Git-Tag: Release-3.0.0~1826 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b28ebbc1e857fbb395b3fb5c6837e4ec24a937a9;p=bacula%2Fbacula kes Add patch from Martin Schmid scm@apsag.com that checks to see if ftruncate() actually works. In the case of some (cheap) NAS devices, it does not, and so recycling NAS Volumes does not work. The code simply unlink()s the file, then recreates it. This fixes bug #1011. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6463 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/AUTHORS b/bacula/AUTHORS index 20218a0852..17bd5e0474 100644 --- a/bacula/AUTHORS +++ b/bacula/AUTHORS @@ -61,6 +61,7 @@ Lucas Di Pentima Ludovic Strappazon Marc Cousin Marc Schiffbauer +Martin Schmid Martin Simmons Meno Abels Michael Renner diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index b8ef18713d..030bb3adff 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -1917,6 +1917,8 @@ boffset_t DEVICE::lseek(DCR *dcr, boffset_t offset, int whence) bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */ { + struct stat st; + Dmsg1(100, "truncate %s\n", print_name()); switch (dev_type) { case B_TAPE_DEV: @@ -1925,15 +1927,62 @@ bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */ case B_DVD_DEV: return truncate_dvd(dcr); case B_FILE_DEV: - /* ***FIXME*** we really need to unlink() the file so that - * its name can be changed for a relabel. - */ if (ftruncate(m_fd, 0) != 0) { berrno be; Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"), print_name(), be.bstrerror()); return false; } + + /* + * Check for a successful ftruncate() and issue a work-around for devices + * (mostly cheap NAS) that don't support truncation. + * Workaround supplied by Martin Schmid as a solution to bug #1011. + * 1. close file + * 2. delete file + * 3. open new file with same mode + * 4. change ownership to original + */ + + if (fstat(m_fd, &st) != 0) { + berrno be; + Mmsg2(errmsg, _("Unable to stat device %s. ERR=%s\n"), + print_name(), be.bstrerror()); + return false; + } + + if (st.st_size != 0) { /* ftruncate() didn't work */ + POOL_MEM archive_name(PM_FNAME); + + pm_strcpy(archive_name, dev_name); + if (!IsPathSeparator(archive_name.c_str()[strlen(archive_name.c_str())-1])) { + pm_strcat(archive_name, "/"); + } + pm_strcat(archive_name, dcr->VolumeName); + + Mmsg2(errmsg, _("Device %s doesn't support ftruncate(). Recreating file %s.\n"), + print_name(), archive_name.c_str()); + + /* Close file and blow it away */ + ::close(m_fd); + ::unlink(archive_name.c_str()); + + /* Recreate the file -- of course, empty */ + set_mode(CREATE_READ_WRITE); + if ((m_fd = ::open(archive_name.c_str(), mode, st.st_mode)) < 0) { + berrno be; + dev_errno = errno; + Mmsg2(errmsg, _("Could not reopen: %s, ERR=%s\n"), archive_name.c_str(), + be.bstrerror()); + Dmsg1(100, "reopen failed: %s", errmsg); + Emsg0(M_FATAL, 0, errmsg); + return false; + } + + /* Reset proper owner */ + chown(archive_name.c_str(), st.st_uid, st.st_gid); + } + return true; } return false; diff --git a/bacula/src/version.h b/bacula/src/version.h index b905abc810..8aa124b187 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.3.10" -#define BDATE "16 February 2008" -#define LSMDATE "16Feb08" +#define BDATE "22 February 2008" +#define LSMDATE "22Feb08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 2a344b954b..14712f0550 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -1,6 +1,11 @@ Technical notes on version 2.3 General: +22Feb08 +kes Add patch from Martin Schmid scm@apsag.com that checks to see if + ftruncate() actually works. In the case of some (cheap) NAS devices, + it does not, and so recycling NAS Volumes does not work. The code + simply unlink()s the file, then recreates it. This fixes bug #1011. 21Feb08 kes First incomplete cut of big malloc blocks for htable. kes Tweak plugin code.