Skip to content
Permalink
Browse files

dird: defined slot_status_t and slot_type_t as enum class

- reduce confusion between slot type and status
- corrected a switch condition on a false struct variable
  (has to be vol_list_t::slot_type, not vol_list_t::slot_status)
  in file dird/sd_cmds.cc:473
- the names of the enum classes should be adapted to our
  coding style guide upon next refactoring and are left
  to the old style to enable easier comparison with old code
  • Loading branch information...
franku committed May 24, 2019
1 parent 725eb98 commit 6dce7398d2ed41b96fb12f512e20cc3dfe35f14a
@@ -115,21 +115,21 @@ typedef enum
VOL_LIST_PARTIAL
} vol_list_type;

typedef enum
enum class slot_type_t
{
kSlotTypeUnknown, /**< Unknown slot type */
kSlotTypeDrive, /**< Drive slot */
kSlotTypeStorage, /**< Storage slot */
kSlotTypeImport, /**< Import/export slot */
kSlotTypePicker /**< Robotics */
} slot_type_t;
kSlotTypeUnknown,
kSlotTypeDrive,
kSlotTypeStorage,
kSlotTypeImport, /**< Import/export slot */
kSlotTypePicker /**< Robotics */
};

typedef enum
enum class slot_status_t
{
slot_status_unknown, /**< Slot content is unknown */
slot_status_empty, /**< Slot is empty */
slot_status_full /**< Slot is full */
} slot_status_t;
kSlotStatusUnknown,
kSlotStatusEmpty,
kSlotStatusFull
};

enum s_mapping_type
{
@@ -145,8 +145,8 @@ struct vol_list_t {
dlink link; /**< Link for list */
slot_number_t element_address = kInvalidSlotNumber; /**< scsi element address */
slot_flags_t flags = 0; /**< Slot specific flags see e_slot_flag enum */
slot_type_t slot_type = kSlotTypeUnknown; /**< See slot_type_* */
slot_status_t slot_status = slot_status_unknown; /**< See slot_status_* */
slot_type_t slot_type = slot_type_t::kSlotTypeUnknown;
slot_status_t slot_status = slot_status_t::kSlotStatusUnknown;
slot_number_t bareos_slot_number = kInvalidSlotNumber; /**< Drive number when
kSlotTypeDrive or actual slot number */
slot_number_t currently_loaded_slot_number = kInvalidSlotNumber; /**< Volume loaded in drive when
@@ -142,8 +142,8 @@ int NdmpLoadNext(struct ndm_session* sess)
}

slot_number_t slotnumber = GetElementAddressByBareosSlotNumber(
&store->runtime_storage_status->storage_mapping, kSlotTypeStorage,
mr.Slot);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeStorage, mr.Slot);
/* check for success */
if (!IsSlotNumberValid(slotnumber)) {
Jmsg(jcr, M_FATAL, 0, _("GetElementAddressByBareosSlotNumber failed\n"));
@@ -534,7 +534,7 @@ static inline bool extract_post_backup_stats_ndmp_native(

media->slot_addr = GetBareosSlotNumberByElementAddress(
&jcr->res.write_storage->runtime_storage_status->storage_mapping,
kSlotTypeStorage, media->slot_addr);
slot_type_t::kSlotTypeStorage, media->slot_addr);
#if 0
Jmsg(jcr, M_INFO, 0, _("Physical Slot is %d\n"), media->slot_addr);
Jmsg(jcr, M_INFO, 0, _("Logical slot is : %d\n"), media->slot_addr);
@@ -292,8 +292,8 @@ static bool DoNdmpNativeRestore(JobControlRecord* jcr)
Jmsg(jcr, M_INFO, 0, _("Logical slot for volume %s is %d\n"), media->label,
media->slot_addr);
ndmp_slot = GetElementAddressByBareosSlotNumber(
&store->runtime_storage_status->storage_mapping, kSlotTypeStorage,
media->slot_addr);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeStorage, media->slot_addr);
media->slot_addr = ndmp_slot;
Jmsg(jcr, M_INFO, 0, _("Physical(NDMP) slot for volume %s is %d\n"),
media->label, media->slot_addr);
@@ -471,12 +471,12 @@ dlist* ndmp_get_vol_list(UaContext* ua,
/*
* Normal slot
*/
vl->slot_type = kSlotTypeStorage;
vl->slot_type = slot_type_t::kSlotTypeStorage;
if (edp->Full) {
vl->slot_status = slot_status_full;
vl->slot_status = slot_status_t::kSlotStatusFull;
FillVolumeName(vl, edp);
} else {
vl->slot_status = slot_status_empty;
vl->slot_status = slot_status_t::kSlotStatusEmpty;
}
vl->element_address = edp->element_address;
break;
@@ -493,13 +493,13 @@ dlist* ndmp_get_vol_list(UaContext* ua,
/*
* Normal slot
*/
vl->slot_type = kSlotTypeStorage;
vl->slot_type = slot_type_t::kSlotTypeStorage;
vl->element_address = edp->element_address;
if (!edp->Full) {
free(vl);
continue;
} else {
vl->slot_status = slot_status_full;
vl->slot_status = slot_status_t::kSlotStatusFull;
FillVolumeName(vl, edp);
}
break;
@@ -522,26 +522,26 @@ dlist* ndmp_get_vol_list(UaContext* ua,
/*
* Normal slot
*/
vl->slot_type = kSlotTypeStorage;
vl->slot_type = slot_type_t::kSlotTypeStorage;
vl->element_address = edp->element_address;
if (edp->Full) {
vl->slot_status = slot_status_full;
vl->slot_status = slot_status_t::kSlotStatusFull;
FillVolumeName(vl, edp);
} else {
vl->slot_status = slot_status_empty;
vl->slot_status = slot_status_t::kSlotStatusEmpty;
}
break;
case SMC_ELEM_TYPE_IEE:
/*
* Import/Export bareos_slot_number
*/
vl->slot_type = kSlotTypeImport;
vl->slot_type = slot_type_t::kSlotTypeImport;
vl->element_address = edp->element_address;
if (edp->Full) {
vl->slot_status = slot_status_full;
vl->slot_status = slot_status_t::kSlotStatusFull;
FillVolumeName(vl, edp);
} else {
vl->slot_status = slot_status_empty;
vl->slot_status = slot_status_t::kSlotStatusEmpty;
}
if (edp->InEnab) { vl->flags |= can_import; }
if (edp->ExEnab) { vl->flags |= can_export; }
@@ -555,22 +555,22 @@ dlist* ndmp_get_vol_list(UaContext* ua,
/*
* Drive
*/
vl->slot_type = kSlotTypeDrive;
vl->slot_type = slot_type_t::kSlotTypeDrive;
vl->element_address = edp->element_address;
if (edp->Full) {
slot_number_t slot_mapping;
vl->slot_status = slot_status_full;
vl->slot_status = slot_status_t::kSlotStatusFull;
slot_mapping = GetBareosSlotNumberByElementAddress(
&store->runtime_storage_status->storage_mapping,
kSlotTypeStorage, edp->src_se_addr);
slot_type_t::kSlotTypeStorage, edp->src_se_addr);
vl->currently_loaded_slot_number = slot_mapping;
FillVolumeName(vl, edp);
} else {
vl->slot_status = slot_status_empty;
vl->slot_status = slot_status_t::kSlotStatusEmpty;
}
break;
default:
vl->slot_type = kSlotTypeUnknown;
vl->slot_type = slot_type_t::kSlotTypeUnknown;
vl->element_address = edp->element_address;
break;
}
@@ -706,8 +706,8 @@ bool NdmpTransferVolume(UaContext* ua,
* to physical slot numbers for the actual NDMP operation.
*/
from_addr = GetBareosSlotNumberByElementAddress(
&store->runtime_storage_status->storage_mapping, kSlotTypeStorage,
src_slot);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeStorage, src_slot);
if (from_addr == kInvalidSlotNumber) {
ua->ErrorMsg("No slot mapping for slot %hd\n", src_slot);
return retval;
@@ -716,8 +716,8 @@ bool NdmpTransferVolume(UaContext* ua,
ndmp_job.from_addr_given = 1;

to_addr = GetElementAddressByBareosSlotNumber(
&store->runtime_storage_status->storage_mapping, kSlotTypeStorage,
dst_slot);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeStorage, dst_slot);
if (to_addr == kInvalidSlotNumber) {
ua->ErrorMsg("No slot mapping for slot %hd\n", dst_slot);
return retval;
@@ -921,8 +921,8 @@ bool NdmpAutochangerVolumeOperation(UaContext* ua,
* Map the logical address to a physical one.
*/
slot_mapping = GetElementAddressByBareosSlotNumber(
&store->runtime_storage_status->storage_mapping, kSlotTypeStorage,
slot);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeStorage, slot);
if (slot_mapping == kInvalidSlotNumber) {
ua->ErrorMsg("No slot mapping for slot %hd\n", slot);
return retval;
@@ -935,7 +935,8 @@ bool NdmpAutochangerVolumeOperation(UaContext* ua,
* Map the logical address to a physical one.
*/
drive_mapping = GetElementAddressByBareosSlotNumber(
&store->runtime_storage_status->storage_mapping, kSlotTypeDrive, slot);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeDrive, slot);
if (drive_mapping == kInvalidSlotNumber) {
ua->ErrorMsg("No slot mapping for drive %hd\n", drive);
return retval;
@@ -1039,8 +1040,8 @@ bool NdmpSendLabelRequest(UaContext* ua,
slot_number_t slot_mapping;

slot_mapping = GetElementAddressByBareosSlotNumber(
&store->runtime_storage_status->storage_mapping, kSlotTypeStorage,
slot);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeStorage, slot);
if (slot_mapping == kInvalidSlotNumber) {
ua->ErrorMsg("No slot mapping for slot %hd\n", slot);
return retval;
@@ -1125,8 +1126,8 @@ bool ndmp_native_setup_robot_and_tape_for_native_backup_job(
}

driveaddress = GetElementAddressByBareosSlotNumber(
&store->runtime_storage_status->storage_mapping, kSlotTypeDrive,
driveindex);
&store->runtime_storage_status->storage_mapping,
slot_type_t::kSlotTypeDrive, driveindex);
if (driveaddress == kInvalidSlotNumber) {
Jmsg(jcr, M_ERROR, 0,
_("Could not lookup driveaddress for driveindex %d\n"), driveaddress);
@@ -35,7 +35,7 @@ slot_number_t GetElementAddressByBareosSlotNumber(
slot_number_t calculated_slot;

switch (slot_type) {
case kSlotTypeStorage:
case slot_type_t::kSlotTypeStorage:
if ((slotnumber > smc_elem_aa->se_count) ||
!IsSlotNumberValid(slotnumber)) {
calculated_slot = kInvalidSlotNumber;
@@ -45,7 +45,7 @@ slot_number_t GetElementAddressByBareosSlotNumber(
- 1; // normal slots count start from 1
}
break;
case kSlotTypeImport:
case slot_type_t::kSlotTypeImport:
if ((slotnumber < (smc_elem_aa->se_count + 1)) ||
(slotnumber > (smc_elem_aa->se_count + smc_elem_aa->iee_count + 1))) {
calculated_slot = kInvalidSlotNumber;
@@ -56,7 +56,7 @@ slot_number_t GetElementAddressByBareosSlotNumber(
- 1; // normal slots count start from 1
}
break;
case kSlotTypePicker:
case slot_type_t::kSlotTypePicker:
if ((slotnumber == kInvalidSlotNumber) ||
slotnumber > (smc_elem_aa->mte_count - 1)) {
calculated_slot = kInvalidSlotNumber;
@@ -65,7 +65,7 @@ slot_number_t GetElementAddressByBareosSlotNumber(
+ smc_elem_aa->mte_addr;
}
break;
case kSlotTypeDrive:
case slot_type_t::kSlotTypeDrive:
if ((slotnumber > (smc_elem_aa->dte_count) - 1) ||
(slotnumber == kInvalidSlotNumber)) {
calculated_slot = kInvalidSlotNumber;
@@ -75,7 +75,7 @@ slot_number_t GetElementAddressByBareosSlotNumber(
}
break;
default:
case kSlotTypeUnknown:
case slot_type_t::kSlotTypeUnknown:
calculated_slot = kInvalidSlotNumber;
break;
}
@@ -93,7 +93,7 @@ slot_number_t GetBareosSlotNumberByElementAddress(
slot_number_t calculated_slot;

switch (slot_type) {
case kSlotTypeStorage:
case slot_type_t::kSlotTypeStorage:
if (element_addr < smc_elem_aa->se_addr ||
(element_addr > smc_elem_aa->se_addr + smc_elem_aa->se_count - 1)) {
calculated_slot = kInvalidSlotNumber;
@@ -103,7 +103,7 @@ slot_number_t GetBareosSlotNumberByElementAddress(
+ 1; // slots count start from 1
}
break;
case kSlotTypeImport:
case slot_type_t::kSlotTypeImport:
if ((element_addr < smc_elem_aa->iee_addr) ||
(element_addr > smc_elem_aa->iee_addr + smc_elem_aa->iee_count - 1)) {
calculated_slot = kInvalidSlotNumber;
@@ -114,7 +114,7 @@ slot_number_t GetBareosSlotNumberByElementAddress(
+ 1; // slots count start from 1
}
break;
case kSlotTypeDrive:
case slot_type_t::kSlotTypeDrive:
if ((element_addr < smc_elem_aa->dte_addr) ||
(element_addr > smc_elem_aa->dte_addr + smc_elem_aa->dte_count - 1)) {
calculated_slot = kInvalidSlotNumber;
@@ -123,12 +123,12 @@ slot_number_t GetBareosSlotNumberByElementAddress(
- smc_elem_aa->dte_addr;
}
break;
case kSlotTypePicker:
case slot_type_t::kSlotTypePicker:
calculated_slot = element_addr
- smc_elem_aa->mte_addr;
break;
default:
case kSlotTypeUnknown:
case slot_type_t::kSlotTypeUnknown:
calculated_slot = kInvalidSlotNumber;
break;
}

0 comments on commit 6dce739

Please sign in to comment.
You can’t perform that action at this time.