Skip to content

Commit

Permalink
Merge pull request #744 from bareos/dev/pstorz/use-archive_device-var…
Browse files Browse the repository at this point in the history
…iable

stored: use "archive_device_string" variable for archive device
  • Loading branch information
pstorz committed Mar 12, 2021
2 parents 5a39e5d + e1bccb5 commit fb76608
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 108 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -34,6 +34,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- Change Copy Job behaviour regarding Archive Jobs [PR #717]
- py2lug-fd-ovirt systemtest: use ovirt-plugin.ini config file [PR #729]
- Ctest now runs in scripted mode. [PR #742]
- storage daemon: class Device: rename dev_name to archive_device_string (as the value stored here is the value of the "Archive Device" directive) [PR #744]

### Deprecated

Expand Down
21 changes: 11 additions & 10 deletions core/src/plugins/stored/scsicrypto/scsicrypto-sd.cc
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2012 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -340,7 +340,7 @@ static bRC do_set_scsi_encryption_key(void* value)
* Check if encryption key is needed for reading this volume.
*/
P(crypto_operation_mutex);
if (!NeedScsiCryptoKey(dev->fd(), dev->dev_name, true)) {
if (!NeedScsiCryptoKey(dev->fd(), dev->archive_device_string, true)) {
V(crypto_operation_mutex);
Dmsg0(debuglevel, "scsicrypto-sd: No encryption key needed!\n");
return bRC_OK;
Expand Down Expand Up @@ -396,7 +396,7 @@ static bRC do_set_scsi_encryption_key(void* value)
Dmsg1(debuglevel, "scsicrypto-sd: Loading new crypto key %s\n", VolEncrKey);

P(crypto_operation_mutex);
if (SetScsiEncryptionKey(dev->fd(), dev->dev_name, VolEncrKey)) {
if (SetScsiEncryptionKey(dev->fd(), dev->archive_device_string, VolEncrKey)) {
dev->SetCryptoEnabled();
V(crypto_operation_mutex);
return bRC_OK;
Expand Down Expand Up @@ -443,13 +443,14 @@ static bRC do_clear_scsi_encryption_key(void* value)
* the stored.
*/
if (device_resource->query_crypto_status) {
need_to_clear = IsScsiEncryptionEnabled(dev->fd(), dev->dev_name);
need_to_clear
= IsScsiEncryptionEnabled(dev->fd(), dev->archive_device_string);
} else {
need_to_clear = dev->IsCryptoEnabled();
}
if (need_to_clear) {
Dmsg0(debuglevel, "scsicrypto-sd: Clearing crypto key\n");
if (ClearScsiEncryptionKey(dev->fd(), dev->dev_name)) {
if (ClearScsiEncryptionKey(dev->fd(), dev->archive_device_string)) {
dev->ClearCryptoEnabled();
V(crypto_operation_mutex);
return bRC_OK;
Expand Down Expand Up @@ -502,7 +503,7 @@ static bRC handle_read_error(void* value)
*/
if (device_resource->query_crypto_status) {
P(crypto_operation_mutex);
if (NeedScsiCryptoKey(dev->fd(), dev->dev_name, false)) {
if (NeedScsiCryptoKey(dev->fd(), dev->archive_device_string, false)) {
decryption_needed = true;
} else {
decryption_needed = false;
Expand Down Expand Up @@ -551,8 +552,8 @@ static bRC send_device_encryption_status(void* value)
if (dst->device_resource->drive_crypto_enabled) {
P(crypto_operation_mutex);
dst->status_length = GetScsiDriveEncryptionStatus(
dst->device_resource->dev->fd(), dst->device_resource->dev->dev_name,
dst->status, 4);
dst->device_resource->dev->fd(),
dst->device_resource->dev->archive_device_string, dst->status, 4);
V(crypto_operation_mutex);
}
return bRC_OK;
Expand All @@ -574,8 +575,8 @@ static bRC send_volume_encryption_status(void* value)
if (dst->device_resource->drive_crypto_enabled) {
P(crypto_operation_mutex);
dst->status_length = GetScsiVolumeEncryptionStatus(
dst->device_resource->dev->fd(), dst->device_resource->dev->dev_name,
dst->status, 4);
dst->device_resource->dev->fd(),
dst->device_resource->dev->archive_device_string, dst->status, 4);
V(crypto_operation_mutex);
}
return bRC_OK;
Expand Down
12 changes: 6 additions & 6 deletions core/src/plugins/stored/scsitapealert/scsitapealert-sd.cc
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2013-2013 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -213,26 +213,26 @@ static bRC handle_tapealert_readout(void* value)
if (!device_resource->drive_tapealert_enabled) {
Dmsg1(debuglevel,
"scsitapealert-sd: tapealert is not enabled on device %s\n",
dev->dev_name);
dev->archive_device_string);
return bRC_OK;
}

Dmsg1(debuglevel, "scsitapealert-sd: checking for tapealerts on device %s\n",
dev->dev_name);
dev->archive_device_string);
P(tapealert_operation_mutex);
GetTapealertFlags(dev->fd(), dev->dev_name, &flags);
GetTapealertFlags(dev->fd(), dev->archive_device_string, &flags);
V(tapealert_operation_mutex);

Dmsg1(debuglevel,
"scsitapealert-sd: checking for tapealerts on device %s DONE\n",
dev->dev_name);
dev->archive_device_string);
Dmsg1(debuglevel, "scsitapealert-sd: flags: %ld \n", flags);

if (flags) {
Dmsg1(
debuglevel,
"scsitapealert-sd: tapealerts on device %s, calling UpdateTapeAlerts\n",
dev->dev_name);
dev->archive_device_string);
bareos_core_functions->UpdateTapeAlert(dcr, flags);
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/ansi_label.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2005-2009 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -88,7 +88,7 @@ int ReadAnsiIbmLabel(DeviceControlRecord* dcr)
dev->clrerror(-1);
Dmsg1(100, "Read device got: ERR=%s\n", be.bstrerror());
Mmsg2(jcr->errmsg, _("Read error on device %s in ANSI label. ERR=%s\n"),
dev->dev_name, be.bstrerror());
dev->archive_device_string, be.bstrerror());
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
dev->VolCatInfo.VolCatErrors++;
return VOL_IO_ERROR;
Expand Down
8 changes: 4 additions & 4 deletions core/src/stored/backends/droplet_device.cc
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2014-2017 Planets Communications B.V.
Copyright (C) 2014-2020 Bareos GmbH & Co. KG
Copyright (C) 2014-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -888,7 +888,7 @@ bool droplet_device::initialize()
sysmd_.location_constraint = dpl_location_constraint(temp.c_str());
if (sysmd_.location_constraint == -1) {
Mmsg2(errmsg, _("Illegal location argument %s for device %s%s\n"),
temp.c_str(), dev_name);
temp.c_str(), archive_device_string);
goto bail_out;
}
}
Expand All @@ -899,7 +899,7 @@ bool droplet_device::initialize()
sysmd_.canned_acl = dpl_canned_acl(temp.c_str());
if (sysmd_.canned_acl == -1) {
Mmsg2(errmsg, _("Illegal canned_acl argument %s for device %s%s\n"),
temp.c_str(), dev_name);
temp.c_str(), archive_device_string);
goto bail_out;
}
}
Expand All @@ -910,7 +910,7 @@ bool droplet_device::initialize()
sysmd_.storage_class = dpl_storage_class(temp.c_str());
if (sysmd_.storage_class == -1) {
Mmsg2(errmsg, _("Illegal storage_class argument %s for device %s%s\n"),
temp.c_str(), dev_name);
temp.c_str(), archive_device_string);
goto bail_out;
}
}
Expand Down
12 changes: 7 additions & 5 deletions core/src/stored/backends/generic_tape_device.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2014-2014 Planets Communications B.V.
Copyright (C) 2014-2020 Bareos GmbH & Co. KG
Copyright (C) 2014-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -69,7 +69,9 @@ void generic_tape_device::OpenDevice(DeviceControlRecord* dcr, DeviceMode omode)
/*
* Windows Code
*/
if ((fd_ = d_open(dev_name, oflags, 0)) < 0) { dev_errno = errno; }
if ((fd_ = d_open(archive_device_string, oflags, 0)) < 0) {
dev_errno = errno;
}
#else
/*
* UNIX Code
Expand All @@ -80,7 +82,7 @@ void generic_tape_device::OpenDevice(DeviceControlRecord* dcr, DeviceMode omode)
/*
* Try non-blocking open
*/
fd_ = d_open(dev_name, oflags | O_NONBLOCK, 0);
fd_ = d_open(archive_device_string, oflags | O_NONBLOCK, 0);
if (fd_ < 0) {
BErrNo be;
dev_errno = errno;
Expand Down Expand Up @@ -113,7 +115,7 @@ void generic_tape_device::OpenDevice(DeviceControlRecord* dcr, DeviceMode omode)
* Got fd and rewind worked, so we must have medium in drive
*/
d_close(fd_);
fd_ = d_open(dev_name, oflags, 0); /* open normally */
fd_ = d_open(archive_device_string, oflags, 0); /* open normally */
if (fd_ < 0) {
BErrNo be;
dev_errno = errno;
Expand Down Expand Up @@ -987,7 +989,7 @@ void generic_tape_device::SetOsDeviceParameters(DeviceControlRecord* dcr)
{
Device* dev = dcr->dev;

if (bstrcmp(dev->dev_name, "/dev/null")) {
if (bstrcmp(dev->archive_device_string, "/dev/null")) {
return; /* no use trying to set /dev/null */
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/stored/backends/unix_fifo_device.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2013-2013 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -78,15 +78,15 @@ void unix_fifo_device::OpenDevice(DeviceControlRecord* dcr, DeviceMode omode)
/*
* Try non-blocking open
*/
fd_ = d_open(dev_name, oflags | O_NONBLOCK, 0);
fd_ = d_open(archive_device_string, oflags | O_NONBLOCK, 0);
if (fd_ < 0) {
BErrNo be;
dev_errno = errno;
Dmsg5(100, "Open error on %s omode=%d oflags=%x errno=%d: ERR=%s\n",
prt_name, omode, oflags, errno, be.bstrerror());
} else {
d_close(fd_);
fd_ = d_open(dev_name, oflags, 0); /* open normally */
fd_ = d_open(archive_device_string, oflags, 0); /* open normally */
if (fd_ < 0) {
BErrNo be;
dev_errno = errno;
Expand Down
4 changes: 2 additions & 2 deletions core/src/stored/backends/unix_file_device.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2013-2013 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -288,7 +288,7 @@ bool unix_file_device::d_truncate(DeviceControlRecord* dcr)
* 3. open new file with same mode
* 4. change ownership to original
*/
PmStrcpy(archive_name, dev_name);
PmStrcpy(archive_name, archive_device_string);
if (!IsPathSeparator(
archive_name.c_str()[strlen(archive_name.c_str()) - 1])) {
PmStrcat(archive_name, "/");
Expand Down
8 changes: 4 additions & 4 deletions core/src/stored/btape.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -696,7 +696,7 @@ static void capcmd()
printf("\n");

printf(_("Device parameters:\n"));
printf("Device name: %s\n", dev->dev_name);
printf("Device name: %s\n", dev->archive_device_string);
printf("File=%u block=%u\n", dev->file, dev->block_num);
printf("Min block=%u Max block=%u\n", dev->min_block_size,
dev->max_block_size);
Expand Down Expand Up @@ -1899,8 +1899,8 @@ static void scancmd()
if ((status = read(dev->fd(), buf, sizeof(buf))) < 0) {
BErrNo be;
dev->clrerror(-1);
Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"), dev->dev_name,
be.bstrerror());
Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"),
dev->archive_device_string, be.bstrerror());
Pmsg2(0, _("Bad status from read %d. ERR=%s\n"), status,
dev->bstrerror());
if (blocks > 0) {
Expand Down
36 changes: 20 additions & 16 deletions core/src/stored/butil.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -54,7 +54,8 @@ static bool setup_to_access_device(DeviceControlRecord* dcr,
char* dev_name,
const char* VolumeName,
bool readonly);
static DeviceResource* find_device_res(char* device_name, bool readonly);
static DeviceResource* find_device_res(char* archive_device_string,
bool readonly);
static void MyFreeJcr(JobControlRecord* jcr);

/**
Expand Down Expand Up @@ -175,7 +176,8 @@ static bool setup_to_access_device(DeviceControlRecord* dcr,
if (VolName[0]) {
bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName));
}
bstrncpy(dcr->dev_name, device_resource->device_name, sizeof(dcr->dev_name));
bstrncpy(dcr->dev_name, device_resource->archive_device_string,
sizeof(dcr->dev_name));

CreateRestoreVolumeList(jcr);

Expand Down Expand Up @@ -246,34 +248,36 @@ static void MyFreeJcr(JobControlRecord* jcr)
* Returns: NULL on failure
* Device resource pointer on success
*/
static DeviceResource* find_device_res(char* device_name, bool readonly)
static DeviceResource* find_device_res(char* archive_device_string,
bool readonly)
{
bool found = false;
DeviceResource* device_resource;

Dmsg0(900, "Enter find_device_res\n");
LockRes(my_config);
foreach_res (device_resource, R_DEVICE) {
Dmsg2(900, "Compare %s and %s\n", device_resource->device_name,
device_name);
if (bstrcmp(device_resource->device_name, device_name)) {
Dmsg2(900, "Compare %s and %s\n", device_resource->archive_device_string,
archive_device_string);
if (bstrcmp(device_resource->archive_device_string,
archive_device_string)) {
found = true;
break;
}
}

if (!found) {
/* Search for name of Device resource rather than archive name */
if (device_name[0] == '"') {
int len = strlen(device_name);
bstrncpy(device_name, device_name + 1, len + 1);
if (archive_device_string[0] == '"') {
int len = strlen(archive_device_string);
bstrncpy(archive_device_string, archive_device_string + 1, len + 1);
len--;
if (len > 0) { device_name[len - 1] = 0; /* zap trailing " */ }
if (len > 0) { archive_device_string[len - 1] = 0; /* zap trailing " */ }
}
foreach_res (device_resource, R_DEVICE) {
Dmsg2(900, "Compare %s and %s\n", device_resource->resource_name_,
device_name);
if (bstrcmp(device_resource->resource_name_, device_name)) {
archive_device_string);
if (bstrcmp(device_resource->resource_name_, archive_device_string)) {
found = true;
break;
}
Expand All @@ -283,14 +287,14 @@ static DeviceResource* find_device_res(char* device_name, bool readonly)

if (!found) {
Pmsg2(0, _("Could not find device \"%s\" in config file %s.\n"),
device_name, configfile);
archive_device_string, configfile);
return NULL;
}

if (readonly) {
Pmsg1(0, _("Using device: \"%s\" for reading.\n"), device_name);
Pmsg1(0, _("Using device: \"%s\" for reading.\n"), archive_device_string);
} else {
Pmsg1(0, _("Using device: \"%s\" for writing.\n"), device_name);
Pmsg1(0, _("Using device: \"%s\" for writing.\n"), archive_device_string);
}

return device_resource;
Expand Down

0 comments on commit fb76608

Please sign in to comment.