From: Eric Bollengier Date: Thu, 15 Feb 2024 09:49:12 +0000 (+0100) Subject: Report immutable/readonly error messages to the job log X-Git-Tag: Release-15.0.2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3813d631f253617841769ff2b46a024a56a83215;p=thirdparty%2Fbacula.git Report immutable/readonly error messages to the job log --- diff --git a/bacula/src/stored/aligned_dev.h b/bacula/src/stored/aligned_dev.h index eb09cd9e3..d4a63fae0 100644 --- a/bacula/src/stored/aligned_dev.h +++ b/bacula/src/stored/aligned_dev.h @@ -111,9 +111,9 @@ public: bool is_fs_nearly_full(uint64_t threshold); int rehydrate_record(DCR *dcr, DEV_RECORD *rec); - int set_writable(int fd, const char *vol_name); - int set_readonly(int fd, const char *vol_name); - int set_atime(int fd, const char *vol_name, btime_t val); + int set_writable(int fd, const char *vol_name, POOLMEM **error); + int set_readonly(int fd, const char *vol_name, POOLMEM **error); + int set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error); /* * Locking and blocking calls diff --git a/bacula/src/stored/block_util.c b/bacula/src/stored/block_util.c index 1f50854a6..85e3710fe 100644 --- a/bacula/src/stored/block_util.c +++ b/bacula/src/stored/block_util.c @@ -843,8 +843,8 @@ bool terminate_writing_volume(DCR *dcr) if (dev->device->set_vol_immutable || dev->device->set_vol_read_only) { uint32_t when = MAX(dev->device->min_volume_protection_time, dev->VolCatInfo.VolRetention); btime_t now = time(NULL); - if (dev->set_atime(-1, dev->getVolCatName(), now + when) < 0) { - Jmsg(dcr->jcr, M_WARNING, 0, _(" Failed to set the volume %s on device %s in atime retention, ERR=%s.\n"), + if (dev->set_atime(-1, dev->getVolCatName(), now + when, &dev->errmsg) < 0) { + Jmsg(dcr->jcr, M_WARNING, 0, _(" Failed to set the atime retention on volume %s on device %s. %s.\n"), dev->getVolCatName(), dev->print_name(), dev->errmsg); } bstrftime(buf2, sizeof(buf2), now+when); @@ -854,11 +854,10 @@ bool terminate_writing_volume(DCR *dcr) if (dev->device->set_vol_read_only) { /* Set volume as immutable/read only */ - if (dev->set_readonly(dev->m_fd, dev->getVolCatName()) < 0) { - berrno be; + if (dev->set_readonly(dev->m_fd, dev->getVolCatName(), &dev->errmsg) < 0) { /* We may proceed with that but warn the user */ - Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s in read-only, ERR=%s.\n"), - dev->getVolCatName(), dev->print_name(), be.bstrerror()); + Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s in read-only. %s.\n"), + dev->getVolCatName(), dev->print_name(), dev->errmsg); } else { Jmsg(dcr->jcr, M_INFO, 0, _("Marking Volume \"%s\" as read-only. Retention set to %s (%s).\n"), dev->getVolCatName(), buf2, buf); @@ -873,7 +872,7 @@ bool terminate_writing_volume(DCR *dcr) /* Set volume as immutable */ if (!dev->set_immutable(dev->getVolCatName(), &dev->errmsg)) { /* We may proceed with that but warn the user */ - Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s as immutable, ERR=%s.\n"), + Jmsg(dcr->jcr, M_WARNING, 0, _("Failed to set the volume %s on device %s as immutable, %s.\n"), dev->getVolCatName(), dev->print_name(), dev->errmsg); } else { Jmsg(dcr->jcr, M_INFO, 0, _("Marking Volume \"%s\" as immutable. Retention set to %s (%s).\n"), diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 2224ed367..c6c09d311 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -618,9 +618,9 @@ public: virtual bool check_volume_protection_time(const char *vol_name) { return true; }; virtual bool check_for_immutable(const char *vol_name) { return false; }; virtual bool check_for_read_only(int fd, const char *vol_name) { return false; }; - virtual int set_writable(int fd, const char *vol_name) { errno=ENOSYS; return -1;}; - virtual int set_readonly(int fd, const char *vol_name) { errno=ENOSYS; return -1;}; - virtual int set_atime(int fd, const char *vol_name, btime_t val) { errno=ENOSYS; return -1;}; + virtual int set_writable(int fd, const char *vol_name, POOLMEM **error) { pm_strcpy(error, "Not implemented"); errno=ENOSYS; return -1;}; + virtual int set_readonly(int fd, const char *vol_name, POOLMEM **error) { pm_strcpy(error, "Not implemented"); errno=ENOSYS; return -1;}; + virtual int set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error) { pm_strcpy(error, "Not implemented"); errno=ENOSYS; return -1;}; virtual int use_protect() { return 0; }; virtual int use_volume_encryption(); virtual const char *print_type() = 0; /* in dev.c */ diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index ebbcec0cb..3e396d970 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -1339,7 +1339,7 @@ static bool volumeprotect_cmd(JCR *jcr) BSOCK *dir = jcr->dir_bsock; char mediatype[MAX_NAME_LENGTH]; char volume[MAX_NAME_LENGTH]; - POOL_MEM device, tmp; + POOL_MEM device, tmp, error; uint32_t retention; int32_t drive; bool ok; @@ -1364,10 +1364,10 @@ static bool volumeprotect_cmd(JCR *jcr) if (dev->device->set_vol_immutable || dev->device->set_vol_read_only) { uint32_t when = MAX(dev->device->min_volume_protection_time, retention); btime_t now = time(NULL); - if (dev->set_atime(-1, volume, now + when) < 0) { - berrno be; - Mmsg(tmp, _(" Failed to set the volume %s on device %s in atime retention, ERR=%s.\n"), - volume, dev->print_name(), be.bstrerror()); + if (dev->set_atime(-1, volume, now + when, error.handle()) < 0) { + MmsgD3(DT_VOLUME|50, tmp, + _(" Failed to set the volume %s on device %s in atime retention, ERR=%s.\n"), + volume, dev->print_name(), error.c_str()); } pm_strcpy(tmp, ""); bstrftime(buf2, sizeof(buf2), now+when); @@ -1375,9 +1375,9 @@ static bool volumeprotect_cmd(JCR *jcr) } if (dev->device->set_vol_immutable) { /* Set volume as immutable */ - if (!dev->set_immutable(volume, tmp.handle())) { + if (!dev->set_immutable(volume, error.handle())) { /* We may proceed with that but warn the user */ - dir->fsend(_("3900 Unable to set immutable flag %s\n"), tmp.c_str()); + dir->fsend(_("3900 Unable to set immutable flag %s\n"), error.c_str()); } else { dir->fsend(_("3000 Mark volume \"%s\" as immutable. Retention set to %s (%s).\n"), volume, buf2, buf); @@ -1387,11 +1387,10 @@ static bool volumeprotect_cmd(JCR *jcr) } else if (dev->device->set_vol_read_only) { /* Set volume as immutable/read only */ - if (dev->set_readonly(-1, volume) < 0) { - berrno be; + if (dev->set_readonly(-1, volume, error.handle()) < 0) { /* We may proceed with that but warn the user */ dir->fsend(_("3900 Failed to set the volume %s on device %s in read-only, ERR=%s.%s\n"), - volume, dev->print_name(), be.bstrerror(), tmp.c_str()); + volume, dev->print_name(), error.c_str(), tmp.c_str()); } else { dir->fsend(_("3000 Marking volume \"%s\" as read-only. Retention set to %s (%s).\n"), volume,buf2, buf); diff --git a/bacula/src/stored/file_dev.c b/bacula/src/stored/file_dev.c index 892de4f9a..e129260d7 100644 --- a/bacula/src/stored/file_dev.c +++ b/bacula/src/stored/file_dev.c @@ -219,7 +219,7 @@ bool file_dev::open_device(DCR *dcr, int omode) if (immutable && clear_immutable(getVolCatName(), &errmsg)) { tryopen = true; } - if (readonly && set_writable(-1, getVolCatName()) == 0) { + if (readonly && set_writable(-1, getVolCatName(), &errmsg) == 0) { tryopen = true; } if (tryopen) { /* It should be now possible to open the device with desired mode */ @@ -275,7 +275,7 @@ bool file_dev::open_device(DCR *dcr, int omode) return m_fd >= 0; } -int file_dev::set_writable(int fd, const char *vol_name) +int file_dev::set_writable(int fd, const char *vol_name, POOLMEM **error) { POOL_MEM fname; get_volume_fpath(vol_name, fname.handle()); @@ -286,12 +286,12 @@ int file_dev::set_writable(int fd, const char *vol_name) int ret = bchmod(fd, fname.c_str(), 0600); if (ret < 0) { berrno be; - Dmsg1(DT_VOLUME|50, _("Unable to change permission to 0600. ERR=%s\n"), be.bstrerror()); + MmsgD1(DT_VOLUME|50, error, _("Unable to change permission to 0600. ERR=%s\n"), be.bstrerror()); } return ret; } -int file_dev::set_readonly(int fd, const char *vol_name) +int file_dev::set_readonly(int fd, const char *vol_name, POOLMEM **error) { POOL_MEM fname; get_volume_fpath(vol_name, fname.handle()); @@ -299,12 +299,12 @@ int file_dev::set_readonly(int fd, const char *vol_name) int ret = bchmod(fd, fname.c_str(), 0400); if (ret < 0) { berrno be; - Dmsg1(DT_VOLUME|50, _("Unable to change permission to 0400. ERR=%s\n"), be.bstrerror()); + MmsgD1(DT_VOLUME|50, error, _("Unable to change permission to 0400. ERR=%s\n"), be.bstrerror()); } return ret; } -int file_dev::set_atime(int fd, const char *vol_name, btime_t val) +int file_dev::set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error) { struct stat sp; int ret; @@ -312,13 +312,13 @@ int file_dev::set_atime(int fd, const char *vol_name, btime_t val) get_volume_fpath(vol_name, fname.handle()); if (bstat(fd, fname.c_str(), &sp) < 0) { berrno be; - Dmsg2(DT_VOLUME|50, _("Unable to stat %s. ERR=%s\n"), fname.c_str(), be.bstrerror()); + MmsgD2(DT_VOLUME|50, error, _("Unable to stat %s. ERR=%s\n"), fname.c_str(), be.bstrerror()); return -1; } ret = set_own_time(fd, fname.c_str(), val, sp.st_mtime); if (ret < 0) { berrno be; - Dmsg2(DT_VOLUME|50, _("Unable to set atime/mtime to %s. ERR=%s\n"), fname.c_str(), be.bstrerror()); + MmsgD2(DT_VOLUME|50, error, _("Unable to set atime/mtime to %s. ERR=%s\n"), fname.c_str(), be.bstrerror()); } return ret; } @@ -355,10 +355,9 @@ bool DEVICE::truncate(DCR *dcr) } if (dev->device->set_vol_read_only) { - if (set_writable(dev->m_fd, dcr->VolumeName) < 0) { - berrno be; + if (set_writable(dev->m_fd, dcr->VolumeName, &errmsg) < 0) { Mmsg3(errmsg, _("Unable to set write permission for volume %s on device %s. %s\n"), - dcr->VolumeName, print_name(), be.bstrerror()); + dcr->VolumeName, print_name(), errmsg); return false; } } diff --git a/bacula/src/stored/file_dev.h b/bacula/src/stored/file_dev.h index 892fa7521..468bb9861 100644 --- a/bacula/src/stored/file_dev.h +++ b/bacula/src/stored/file_dev.h @@ -53,9 +53,9 @@ public: bool check_for_read_only(int fd, const char *vol_name); bool get_os_device_freespace(); bool is_fs_nearly_full(uint64_t threshold); - int set_writable(int fd, const char *vol_name); - int set_readonly(int fd, const char *vol_name); - int set_atime(int fd, const char *vol_name, btime_t val); + int set_writable(int fd, const char *vol_name, POOLMEM **error); + int set_readonly(int fd, const char *vol_name, POOLMEM **error); + int set_atime(int fd, const char *vol_name, btime_t val, POOLMEM **error); int use_protect(); };