From a3ef526736159b093aa39fb52145f54dbbbd98fe Mon Sep 17 00:00:00 2001 From: Michal Rakowski Date: Fri, 17 Dec 2021 17:24:06 +0100 Subject: [PATCH] Introduce 'SetVolumeAppendOnly' and 'SetVolumeImmutable' SD directives Those two are instead of previously existing ProtectVolumes. --- bacula/src/stored/block_util.c | 2 +- bacula/src/stored/file_dev.c | 12 +++++++----- bacula/src/stored/mount.c | 10 ++++++---- bacula/src/stored/stored_conf.c | 3 ++- bacula/src/stored/stored_conf.h | 3 ++- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/bacula/src/stored/block_util.c b/bacula/src/stored/block_util.c index b770b193d..508b38e5f 100644 --- a/bacula/src/stored/block_util.c +++ b/bacula/src/stored/block_util.c @@ -620,7 +620,7 @@ bool is_user_volume_size_reached(DCR *dcr, bool quiet) dev->getVolCatName()); } - if (dev->device->protect_vols) { + if (dev->device->set_vol_immutable) { /* Set volume as immutable */ if (!dev->set_immutable(dev->getVolCatName())) { /* We may proceed with that but warn the user */ diff --git a/bacula/src/stored/file_dev.c b/bacula/src/stored/file_dev.c index c003a3360..c4b7314ec 100644 --- a/bacula/src/stored/file_dev.c +++ b/bacula/src/stored/file_dev.c @@ -246,10 +246,12 @@ bool DEVICE::truncate(DCR *dcr) Dmsg2(100, "Truncate adata=%d fd=%d\n", dev->adata, dev->m_fd); /* Need to clear the APPEND flag before truncating */ - if (!clear_append_only(dcr->VolumeName)) { - Mmsg2(errmsg, _("Unable to clear append_only flag for volume %s on device %s.\n"), - dcr->VolumeName, print_name()); - return false; + if (dev->device->set_vol_append_only) { + if (!clear_append_only(dcr->VolumeName)) { + Mmsg2(errmsg, _("Unable to clear append_only flag for volume %s on device %s.\n"), + dcr->VolumeName, print_name()); + return false; + } } if (ftruncate(dev->m_fd, 0) != 0) { @@ -556,7 +558,7 @@ void file_dev::get_volume_fpath(const char *vol_name, POOLMEM **fname) */ bool file_dev::check_volume_protection_time(const char *vol_name) { - if (!device->protect_vols) { + if (!device->set_vol_immutable) { Dmsg1(DT_VOLUME|50, "ProtectVolumes turned off for volume: %s\n", vol_name); return true; } diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 479f1eff5..9e0bc62a3 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -296,10 +296,12 @@ read_volume: } /* Set the append flag on the volume */ - if (!dev->set_append_only(getVolCatName())) { - Jmsg(jcr, M_WARNING, 0, _("Unable to set the APPEND flag on the volume: %s, err: %s\n"), - getVolCatName(), dev->bstrerror()); - goto mount_next_vol; + if (dev->device->set_vol_append_only) { + if (!dev->set_append_only(getVolCatName())) { + Jmsg(jcr, M_WARNING, 0, _("Unable to set the APPEND flag on the volume: %s, err: %s\n"), + getVolCatName(), dev->bstrerror()); + goto mount_next_vol; + } } } else { /* diff --git a/bacula/src/stored/stored_conf.c b/bacula/src/stored/stored_conf.c index 82ea02d90..011218d0e 100644 --- a/bacula/src/stored/stored_conf.c +++ b/bacula/src/stored/stored_conf.c @@ -159,7 +159,8 @@ static RES_ITEM dev_items[] = { {"Enabled", store_bool, ITEM(res_dev.enabled), 0, ITEM_DEFAULT, 1}, {"AutoSelect", store_bool, ITEM(res_dev.autoselect), 0, ITEM_DEFAULT, 1}, {"ReadOnly", store_bool, ITEM(res_dev.read_only), 0, ITEM_DEFAULT, 0}, - {"ProtectVolumes", store_bool, ITEM(res_dev.protect_vols), 0, ITEM_DEFAULT, 0}, + {"SetVolumeAppendOnly", store_bool, ITEM(res_dev.set_vol_append_only), 0, ITEM_DEFAULT, 0}, + {"SetVolumeImmutable", store_bool, ITEM(res_dev.set_vol_immutable), 0, ITEM_DEFAULT, 0}, {"MinimumVolumeProtectionTime", store_time, ITEM(res_dev.min_volume_protection_time), 0, ITEM_DEFAULT, 30*24*60*60}, {"ChangerDevice", store_strname,ITEM(res_dev.changer_name), 0, 0, 0}, {"ControlDevice", store_strname,ITEM(res_dev.control_name), 0, 0, 0}, diff --git a/bacula/src/stored/stored_conf.h b/bacula/src/stored/stored_conf.h index fff1e285a..c8ce15b1d 100644 --- a/bacula/src/stored/stored_conf.h +++ b/bacula/src/stored/stored_conf.h @@ -223,7 +223,8 @@ public: bool enabled; /* Set when enabled (default) */ bool autoselect; /* Automatically select from AutoChanger */ bool read_only; /* Drive is read only */ - bool protect_vols; /* Protect Volumes */ + bool set_vol_append_only; /* Set 'Append Only' filesystem flag for volumes */ + bool set_vol_immutable; /* Set 'Immutable' filesystem flag for volumes */ utime_t min_volume_protection_time; /* Minimum Volume Protection Time */ uint32_t drive_index; /* Autochanger drive index */ uint32_t cap_bits; /* Capabilities of this device */ -- 2.47.3