Skip to content

Commit

Permalink
refactor: rename AutoXflateMode
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBoerlin authored and BareosBot committed Aug 10, 2023
1 parent cceb42d commit e73db91
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 64 deletions.
32 changes: 16 additions & 16 deletions core/src/plugins/stored/autoxflate/autoxflate-sd.cc
Expand Up @@ -113,17 +113,17 @@ static int const debuglevel = 200;


// Does the mode contain OUT
static bool AutoxflateModeContainsOut(AutoXflateMode mode)
static bool AutoxflateModeContainsOut(IODirection mode)
{
return (mode == AutoXflateMode::IO_DIRECTION_OUT
|| mode == AutoXflateMode::IO_DIRECTION_INOUT);
return (mode == IODirection::WRITE
|| mode == IODirection::READ_WRITE);
}

// Does the mode contain IN
static bool AutoxflateModeContainsIn(AutoXflateMode mode)
static bool AutoxflateModeContainsIn(IODirection mode)
{
return (mode == AutoXflateMode::IO_DIRECTION_IN
|| mode == AutoXflateMode::IO_DIRECTION_INOUT);
return (mode == IODirection::READ
|| mode == IODirection::READ_WRITE);
}

// what streams can be decompressed by the plugin
Expand Down Expand Up @@ -312,28 +312,28 @@ static bRC setup_record_translation(PluginContext* ctx, void* value)
&& dcr->jcr->is_JobType(JT_RESTORE)
&& (AutoxflateModeContainsIn(dcr->autodeflate)
|| !AutoxflateModeContainsIn(dcr->autoinflate))) {
dcr->autoinflate = AutoXflateMode::IO_DIRECTION_IN;
dcr->autodeflate = AutoXflateMode::IO_DIRECTION_NONE;
dcr->autoinflate = IODirection::READ;
dcr->autodeflate = IODirection::NONE;
Jmsg(ctx, M_INFO,
_("autoxflate-sd: overriding settings on %s for NDMP restore\n"),
dcr->dev_name);
}

// Give jobmessage info what is configured
switch (dcr->autodeflate) {
case AutoXflateMode::IO_DIRECTION_NONE:
case IODirection::NONE:
deflate_in = SETTING_NO;
deflate_out = SETTING_NO;
break;
case AutoXflateMode::IO_DIRECTION_IN:
case IODirection::READ:
deflate_in = SETTING_YES;
deflate_out = SETTING_NO;
break;
case AutoXflateMode::IO_DIRECTION_OUT:
case IODirection::WRITE:
deflate_in = SETTING_NO;
deflate_out = SETTING_YES;
break;
case AutoXflateMode::IO_DIRECTION_INOUT:
case IODirection::READ_WRITE:
deflate_in = SETTING_YES;
deflate_out = SETTING_YES;
break;
Expand All @@ -345,19 +345,19 @@ static bRC setup_record_translation(PluginContext* ctx, void* value)
}

switch (dcr->autoinflate) {
case AutoXflateMode::IO_DIRECTION_NONE:
case IODirection::NONE:
inflate_in = SETTING_NO;
inflate_out = SETTING_NO;
break;
case AutoXflateMode::IO_DIRECTION_IN:
case IODirection::READ:
inflate_in = SETTING_YES;
inflate_out = SETTING_NO;
break;
case AutoXflateMode::IO_DIRECTION_OUT:
case IODirection::WRITE:
inflate_in = SETTING_NO;
inflate_out = SETTING_YES;
break;
case AutoXflateMode::IO_DIRECTION_INOUT:
case IODirection::READ_WRITE:
inflate_in = SETTING_YES;
inflate_out = SETTING_YES;
break;
Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/dev.h
Expand Up @@ -63,7 +63,7 @@
#include "include/bareos.h"
#include "stored/record.h"
#include "stored/volume_catalog_info.h"
#include "stored/autoxflate.h"
#include "stored/io_direction.h"
#include "lib/btimers.h"

#include <vector>
Expand Down Expand Up @@ -232,7 +232,7 @@ class Device {
int oflags{}; /**< Read/write flags */
DeviceMode open_mode{DeviceMode::kUndefined};
std::string device_type{};
AutoXflateMode access_mode{}; /**< Allowed access mode(s) for reservation */
IODirection access_mode{}; /**< Allowed access mode(s) for reservation */
bool autoselect{}; /**< Autoselect in autochanger */
bool norewindonclose{}; /**< Don't rewind tape drive on close */
bool initiated{}; /**< Set when FactoryCreateDevice() called */
Expand Down
6 changes: 3 additions & 3 deletions core/src/stored/device_control_record.h
Expand Up @@ -39,7 +39,7 @@
#ifndef BAREOS_STORED_DEVICE_CONTROL_RECORD_H_
#define BAREOS_STORED_DEVICE_CONTROL_RECORD_H_

#include "stored/autoxflate.h"
#include "stored/io_direction.h"
#include "stored/volume_catalog_info.h"

namespace storagedaemon {
Expand Down Expand Up @@ -97,8 +97,8 @@ class DeviceControlRecord {
bool any_volume{}; /**< Any OK for dir_find_next... */
bool attached_to_dev{}; /**< Set when attached to dev */
bool keep_dcr{}; /**< Do not free dcr in release_dcr */
AutoXflateMode autodeflate{AutoXflateMode::IO_DIRECTION_NONE};
AutoXflateMode autoinflate{AutoXflateMode::IO_DIRECTION_NONE};
IODirection autodeflate{IODirection::NONE};
IODirection autoinflate{IODirection::NONE};
uint32_t VolFirstIndex{}; /**< First file index this Volume */
uint32_t VolLastIndex{}; /**< Last file index this Volume */
uint32_t FileIndex{}; /**< Current File Index */
Expand Down
1 change: 0 additions & 1 deletion core/src/stored/device_resource.cc
Expand Up @@ -22,7 +22,6 @@
*/

#include "lib/parse_conf.h"
#include "stored/autoxflate.h"
#include "stored/device_resource.h"
#include "stored/stored_globals.h"
#include <fmt/format.h>
Expand Down
12 changes: 6 additions & 6 deletions core/src/stored/device_resource.h
Expand Up @@ -25,7 +25,7 @@
#define BAREOS_STORED_DEVICE_RESOURCE_H_

#include "stored/dev.h"
#include "stored/autoxflate.h"
#include "stored/io_direction.h"
#include "lib/bareos_resource.h"

namespace storagedaemon {
Expand All @@ -45,7 +45,7 @@ class DeviceResource : public BareosResource {
char* spool_directory; /**< Spool file directory */
std::string device_type{DeviceType::B_UNKNOWN_DEV};
uint32_t label_type{B_BAREOS_LABEL};
AutoXflateMode access_mode{AutoXflateMode::IO_DIRECTION_INOUT}; /**< Allowed access mode(s) for reservation */
IODirection access_mode{IODirection::READ_WRITE}; /**< Allowed access mode(s) for reservation */
bool autoselect{true}; /**< Automatically select from AutoChanger */
bool norewindonclose{true}; /**< Don't rewind tape drive on close */
bool drive_tapealert_enabled{false}; /**< Enable Tape Alert monitoring */
Expand All @@ -70,11 +70,11 @@ class DeviceResource : public BareosResource {
compression */
uint16_t autodeflate_level{6}; /**< Compression level to use for compression
algorithm which uses levels */
AutoXflateMode autodeflate{
AutoXflateMode::IO_DIRECTION_NONE}; /**< auto deflation in this IO
IODirection autodeflate{
IODirection::NONE}; /**< auto deflation in this IO
direction */
AutoXflateMode autoinflate{
AutoXflateMode::IO_DIRECTION_NONE}; /**< auto inflation in this IO
IODirection autoinflate{
IODirection::NONE}; /**< auto inflation in this IO
direction */
utime_t vol_poll_interval{
300}; /**< Interval between polling volume during mount */
Expand Down
16 changes: 8 additions & 8 deletions core/src/stored/autoxflate.h → core/src/stored/io_direction.h
Expand Up @@ -21,21 +21,21 @@
02110-1301, USA.
*/

#ifndef BAREOS_STORED_AUTOXFLATE_H_
#define BAREOS_STORED_AUTOXFLATE_H_
#ifndef BAREOS_STORED_IO_DIRECTION_H_
#define BAREOS_STORED_IO_DIRECTION_H_

#include "include/bareos.h"

namespace storagedaemon {

enum class AutoXflateMode : uint16_t
enum class IODirection : uint16_t
{
IO_DIRECTION_NONE = 0,
IO_DIRECTION_IN,
IO_DIRECTION_OUT,
IO_DIRECTION_INOUT
NONE = 0,
READ,
WRITE,
READ_WRITE
};

} // namespace storagedaemon

#endif // BAREOS_STORED_AUTOXFLATE_H_
#endif // BAREOS_STORED_IO_DIRECTION_H_
24 changes: 12 additions & 12 deletions core/src/stored/mac.cc
Expand Up @@ -381,21 +381,21 @@ static inline void CheckAutoXflation(JobControlRecord* jcr)

// Check autodeflation.
switch (jcr->sd_impl->read_dcr->autodeflate) {
case AutoXflateMode::IO_DIRECTION_IN:
case AutoXflateMode::IO_DIRECTION_INOUT:
case IODirection::READ:
case IODirection::READ_WRITE:
Dmsg0(200, "Clearing autodeflate on read_dcr\n");
jcr->sd_impl->read_dcr->autodeflate = AutoXflateMode::IO_DIRECTION_NONE;
jcr->sd_impl->read_dcr->autodeflate = IODirection::NONE;
break;
default:
break;
}

if (jcr->sd_impl->dcr) {
switch (jcr->sd_impl->dcr->autodeflate) {
case AutoXflateMode::IO_DIRECTION_OUT:
case AutoXflateMode::IO_DIRECTION_INOUT:
case IODirection::WRITE:
case IODirection::READ_WRITE:
Dmsg0(200, "Clearing autodeflate on write dcr\n");
jcr->sd_impl->dcr->autodeflate = AutoXflateMode::IO_DIRECTION_NONE;
jcr->sd_impl->dcr->autodeflate = IODirection::NONE;
break;
default:
break;
Expand All @@ -404,21 +404,21 @@ static inline void CheckAutoXflation(JobControlRecord* jcr)

// Check autoinflation.
switch (jcr->sd_impl->read_dcr->autoinflate) {
case AutoXflateMode::IO_DIRECTION_IN:
case AutoXflateMode::IO_DIRECTION_INOUT:
case IODirection::READ:
case IODirection::READ_WRITE:
Dmsg0(200, "Clearing autoinflate on read_dcr\n");
jcr->sd_impl->read_dcr->autoinflate = AutoXflateMode::IO_DIRECTION_NONE;
jcr->sd_impl->read_dcr->autoinflate = IODirection::NONE;
break;
default:
break;
}

if (jcr->sd_impl->dcr) {
switch (jcr->sd_impl->dcr->autoinflate) {
case AutoXflateMode::IO_DIRECTION_OUT:
case AutoXflateMode::IO_DIRECTION_INOUT:
case IODirection::WRITE:
case IODirection::READ_WRITE:
Dmsg0(200, "Clearing autoinflate on write dcr\n");
jcr->sd_impl->dcr->autoinflate = AutoXflateMode::IO_DIRECTION_NONE;
jcr->sd_impl->dcr->autoinflate = IODirection::NONE;
break;
default:
break;
Expand Down
10 changes: 5 additions & 5 deletions core/src/stored/reserve.cc
Expand Up @@ -438,7 +438,7 @@ bool FindSuitableDeviceForJob(JobControlRecord* jcr, ReserveContext& rctx)
rctx.device_name = device_name;
rctx.device_resource = vol->dev->device_resource;

if (rctx.device_resource->access_mode == AutoXflateMode::IO_DIRECTION_IN) {
if (rctx.device_resource->access_mode == IODirection::READ) {
Dmsg1(debuglevel,
"device=%s not suitable because it is read only\n",
vol->dev->device_resource->resource_name_);
Expand Down Expand Up @@ -547,11 +547,11 @@ int SearchResForDevice(ReserveContext& rctx)
Dmsg1(100, "Device %s not autoselect skipped.\n",
rctx.device_resource->resource_name_);
continue; /* Device is not available */
} else if (rctx.append && rctx.device_resource->access_mode == AutoXflateMode::IO_DIRECTION_IN) {
} else if (rctx.append && rctx.device_resource->access_mode == IODirection::READ) {
Dmsg1(debuglevel, "Device %s is read only.\n",
rctx.device_resource->resource_name_);
continue; /* Device is not available */
} else if (!rctx.append && rctx.device_resource->access_mode == AutoXflateMode::IO_DIRECTION_OUT) {
} else if (!rctx.append && rctx.device_resource->access_mode == IODirection::WRITE) {
Dmsg1(debuglevel, "Device %s is write only.\n",
rctx.device_resource->resource_name_);
continue; /* Device is not available */
Expand Down Expand Up @@ -661,9 +661,9 @@ static int ReserveDevice(ReserveContext& rctx)
Dmsg3(debuglevel,
"chk AccessMode append=%d access_mode=%d\n",
rctx.append, rctx.device_resource->access_mode);
if (rctx.append && rctx.device_resource->access_mode == AutoXflateMode::IO_DIRECTION_IN) {
if (rctx.append && rctx.device_resource->access_mode == IODirection::READ) {
return -1;
} else if (!rctx.append && rctx.device_resource->access_mode == AutoXflateMode::IO_DIRECTION_OUT) {
} else if (!rctx.append && rctx.device_resource->access_mode == IODirection::WRITE) {
return -1;
}

Expand Down
22 changes: 11 additions & 11 deletions core/src/stored/stored_conf.cc
Expand Up @@ -250,18 +250,18 @@ static struct s_kw authentication_methods[]

struct s_io_kw {
const char* name;
AutoXflateMode token;
IODirection token;
};

static s_io_kw io_directions[] = {{"in", AutoXflateMode::IO_DIRECTION_IN},
{"read", AutoXflateMode::IO_DIRECTION_IN},
{"readonly", AutoXflateMode::IO_DIRECTION_IN},
{"out", AutoXflateMode::IO_DIRECTION_OUT},
{"write", AutoXflateMode::IO_DIRECTION_OUT},
{"writeonly", AutoXflateMode::IO_DIRECTION_OUT},
{"both", AutoXflateMode::IO_DIRECTION_INOUT},
{"readwrite", AutoXflateMode::IO_DIRECTION_INOUT},
{nullptr, AutoXflateMode::IO_DIRECTION_NONE}};
static s_io_kw io_directions[] = {{"in", IODirection::READ},
{"read", IODirection::READ},
{"readonly", IODirection::READ},
{"out", IODirection::WRITE},
{"write", IODirection::WRITE},
{"writeonly", IODirection::WRITE},
{"both", IODirection::READ_WRITE},
{"readwrite", IODirection::READ_WRITE},
{nullptr, IODirection::READ_WRITE}};

static s_kw compression_algorithms[]
= {{"gzip", COMPRESS_GZIP}, {"lzo", COMPRESS_LZO1X},
Expand Down Expand Up @@ -337,7 +337,7 @@ static void StoreIoDirection(LEX* lc, ResourceItem* item, int index, int)
LexGetToken(lc, BCT_NAME);
for (i = 0; io_directions[i].name; i++) {
if (Bstrcasecmp(lc->str, io_directions[i].name)) {
SetItemVariable<AutoXflateMode>(*item, io_directions[i].token);
SetItemVariable<IODirection>(*item, io_directions[i].token);
i = 0;
break;
}
Expand Down

0 comments on commit e73db91

Please sign in to comment.