]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Report immutable/readonly error messages to the job log
authorEric Bollengier <eric@baculasystems.com>
Thu, 15 Feb 2024 09:49:12 +0000 (10:49 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 21 Mar 2024 16:11:51 +0000 (17:11 +0100)
bacula/src/stored/aligned_dev.h
bacula/src/stored/block_util.c
bacula/src/stored/dev.h
bacula/src/stored/dircmd.c
bacula/src/stored/file_dev.c
bacula/src/stored/file_dev.h

index eb09cd9e399e81aabb48a6aee63e417aa304b038..d4a63fae0359636fd47e6a11149aea623f76d96c 100644 (file)
@@ -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
index 1f50854a622cfc1792fd4453e67bd275e677c9e0..85e3710fe9137971b9a72a94e9baaf1d0cb34841 100644 (file)
@@ -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"),
index 2224ed367d099102f02cd3a7f4037ede37983229..c6c09d311b407ae3696d772094ba79fcfdbc0659 100644 (file)
@@ -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 */
index ebbcec0cbe7a0cb69edfaa56097038bb726605ab..3e396d970517340362bdd9dea2646a6ac5f8356d 100644 (file)
@@ -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);
index 892de4f9a0412d67e9fe15cccc87b577a4653f88..e129260d72961257ec442b6bff64e3a07b03dca1 100644 (file)
@@ -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;
       }
    }
index 892fa75214f1ab4858acfe3465ed979b9d9d40b5..468bb9861cfcdf0be643dc7b40e4884786e97c8f 100644 (file)
@@ -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();
 };