Skip to content

Commit

Permalink
added test and functinos
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz committed Dec 20, 2018
1 parent f3e9084 commit 7357106
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 45 deletions.
2 changes: 1 addition & 1 deletion core/src/dird/dird.h
Expand Up @@ -109,7 +109,7 @@ typedef enum {
typedef enum {
slot_type_unknown, /**< Unknown slot type */
slot_type_drive, /**< Drive slot */
slot_type_normal, /**< Normal slot */
slot_type_storage, /**< Normal slot */
slot_type_import, /**< Import/export slot */
slot_type_picker /**< Robotics */
} slot_type;
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/ndmp_dma_backup_NDMP_NATIVE.cc
Expand Up @@ -130,7 +130,7 @@ int NdmpLoadNext(struct ndm_session *sess) {
goto bail_out;
}

slot_number_t slotnumber = LookupStorageMapping(store, slot_type_normal, LOGICAL_TO_PHYSICAL, mr.Slot);
slot_number_t slotnumber = LookupStorageMapping(store, slot_type_storage, LOGICAL_TO_PHYSICAL, mr.Slot);
/*
* check if LookupStorageMapping was successful
*/
Expand Down Expand Up @@ -573,7 +573,7 @@ static inline bool extract_post_backup_stats_ndmp_native(JobControlRecord *jcr,
* translate Physical to Logical Slot before storing into database
*/

media->slot_addr = LookupStorageMapping(jcr->res.wstore, slot_type_normal,
media->slot_addr = LookupStorageMapping(jcr->res.wstore, slot_type_storage,
PHYSICAL_TO_LOGICAL, media->slot_addr);
#if 0
Jmsg(jcr, M_INFO, 0, _("Physical Slot is %d\n"), media->slot_addr);
Expand Down
2 changes: 1 addition & 1 deletion core/src/dird/ndmp_dma_restore_NDMP_NATIVE.cc
Expand Up @@ -350,7 +350,7 @@ 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 = LookupStorageMapping(jcr->res.rstore, slot_type_normal, LOGICAL_TO_PHYSICAL, media->slot_addr);
ndmp_slot = LookupStorageMapping(jcr->res.rstore, slot_type_storage, LOGICAL_TO_PHYSICAL, 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);
Expand Down
22 changes: 11 additions & 11 deletions core/src/dird/ndmp_dma_storage.cc
Expand Up @@ -276,7 +276,7 @@ static void NdmpFillStorageMappings(StorageResource *store, struct ndm_session *
mapping->Type = slot_type_picker;
break;
case SMC_ELEM_TYPE_SE:
mapping->Type = slot_type_normal;
mapping->Type = slot_type_storage;
break;
case SMC_ELEM_TYPE_IEE:
mapping->Type = slot_type_import;
Expand Down Expand Up @@ -315,7 +315,7 @@ static void NdmpFillStorageMappings(StorageResource *store, struct ndm_session *
case slot_type_drive:
mapping->Slot = drive++;
break;
case slot_type_normal:
case slot_type_storage:
case slot_type_import:
mapping->Slot = slot++;
break;
Expand Down Expand Up @@ -371,7 +371,7 @@ dlist *ndmp_get_vol_list(UaContext *ua, StorageResource *store, bool listall, bo
/*
* Normal slot
*/
vl->Type = slot_type_normal;
vl->Type = slot_type_storage;
if (edp->Full) {
vl->Content = slot_content_full;
FillVolumeName(vl, edp);
Expand All @@ -393,7 +393,7 @@ dlist *ndmp_get_vol_list(UaContext *ua, StorageResource *store, bool listall, bo
/*
* Normal slot
*/
vl->Type = slot_type_normal;
vl->Type = slot_type_storage;
vl->Index = edp->element_address;
if (!edp->Full) {
free(vl);
Expand Down Expand Up @@ -422,7 +422,7 @@ dlist *ndmp_get_vol_list(UaContext *ua, StorageResource *store, bool listall, bo
/*
* Normal slot
*/
vl->Type = slot_type_normal;
vl->Type = slot_type_storage;
vl->Index = edp->element_address;
if (edp->Full) {
vl->Content = slot_content_full;
Expand Down Expand Up @@ -465,7 +465,7 @@ dlist *ndmp_get_vol_list(UaContext *ua, StorageResource *store, bool listall, bo
slot_number_t slot_mapping;

vl->Content = slot_content_full;
slot_mapping = LookupStorageMapping(store, slot_type_normal, PHYSICAL_TO_LOGICAL, edp->src_se_addr);
slot_mapping = LookupStorageMapping(store, slot_type_storage, PHYSICAL_TO_LOGICAL, edp->src_se_addr);
vl->Loaded = slot_mapping;
FillVolumeName(vl, edp);
} else {
Expand Down Expand Up @@ -564,7 +564,7 @@ slot_number_t NdmpGetNumSlots(UaContext *ua, StorageResource *store)
*/
foreach_dlist(mapping, store->rss->storage_mappings) {
switch (mapping->Type) {
case slot_type_normal:
case slot_type_storage:
case slot_type_import:
slots++;
break;
Expand Down Expand Up @@ -642,15 +642,15 @@ bool NdmpTransferVolume(UaContext *ua, StorageResource *store,
* As the upper level functions work with logical slot numbers convert them
* to physical slot numbers for the actual NDMP operation.
*/
slot_mapping = LookupStorageMapping(store, slot_type_normal, LOGICAL_TO_PHYSICAL, src_slot);
slot_mapping = LookupStorageMapping(store, slot_type_storage, LOGICAL_TO_PHYSICAL, src_slot);
if (slot_mapping == -1) {
ua->ErrorMsg("No slot mapping for slot %hd\n", src_slot);
return retval;
}
ndmp_job.from_addr = slot_mapping;
ndmp_job.from_addr_given = 1;

slot_mapping = LookupStorageMapping(store, slot_type_normal, LOGICAL_TO_PHYSICAL, dst_slot);
slot_mapping = LookupStorageMapping(store, slot_type_storage, LOGICAL_TO_PHYSICAL, dst_slot);
if (slot_mapping == -1) {
ua->ErrorMsg("No slot mapping for slot %hd\n", dst_slot);
return retval;
Expand Down Expand Up @@ -767,7 +767,7 @@ bool NdmpAutochangerVolumeOperation(UaContext *ua, StorageResource *store, const
/*
* Map the logical address to a physical one.
*/
slot_mapping = LookupStorageMapping(store, slot_type_normal, LOGICAL_TO_PHYSICAL, slot);
slot_mapping = LookupStorageMapping(store, slot_type_storage, LOGICAL_TO_PHYSICAL, slot);
if (slot_mapping == -1) {
ua->ErrorMsg("No slot mapping for slot %hd\n", slot);
return retval;
Expand Down Expand Up @@ -877,7 +877,7 @@ bool NdmpSendLabelRequest(UaContext *ua, StorageResource *store, MediaDbRecord *
if (slot > 0) {
slot_number_t slot_mapping;

slot_mapping = LookupStorageMapping(store, slot_type_normal, LOGICAL_TO_PHYSICAL, slot);
slot_mapping = LookupStorageMapping(store, slot_type_storage, LOGICAL_TO_PHYSICAL, slot);
if (slot_mapping == -1) {
ua->ErrorMsg("No slot mapping for slot %hd\n", slot);
return retval;
Expand Down
8 changes: 4 additions & 4 deletions core/src/dird/sd_cmds.cc
Expand Up @@ -390,7 +390,7 @@ dlist *native_get_vol_list(UaContext *ua, StorageResource *store, bool listall,
continue;
}

vl->Type = slot_type_normal;
vl->Type = slot_type_storage;
if (strlen(field2) > 0) {
vl->Content = slot_content_full;
vl->VolName = bstrdup(field2);
Expand Down Expand Up @@ -419,7 +419,7 @@ dlist *native_get_vol_list(UaContext *ua, StorageResource *store, bool listall,
continue;
}

vl->Type = slot_type_normal;
vl->Type = slot_type_storage;
vl->Content = slot_content_full;
vl->VolName = bstrdup(field2);
vl->Index = INDEX_SLOT_OFFSET + vl->Slot;
Expand All @@ -436,7 +436,7 @@ dlist *native_get_vol_list(UaContext *ua, StorageResource *store, bool listall,
vl->Type = slot_type_drive;
break;
case 'S':
vl->Type = slot_type_normal;
vl->Type = slot_type_storage;
break;
case 'I':
vl->Type = slot_type_import;
Expand Down Expand Up @@ -483,7 +483,7 @@ dlist *native_get_vol_list(UaContext *ua, StorageResource *store, bool listall,
case 'F':
vl->Content = slot_content_full;
switch (vl->Type) {
case slot_type_normal:
case slot_type_storage:
case slot_type_import:
if (field4) {
vl->VolName = bstrdup(field4);
Expand Down
95 changes: 95 additions & 0 deletions core/src/dird/storage.cc
Expand Up @@ -930,4 +930,99 @@ slot_number_t LookupStorageMapping(StorageResource *store, slot_type slot_type,

return retval;
}



struct SmcElementAddressAssignment {

/* media transport element */
unsigned picker_base_address;
unsigned picker_count;

/* storage element */
unsigned storage_base_address;
unsigned storage_count;

/* import/export element */
unsigned import_export_base_address;
unsigned import_export_count;

/* data transfer element */
unsigned drive_base_address;
unsigned drive_count;

};


/**
* calculate the element address for given slotnumber and slot_type
*/
slot_number_t GetElementAddressByBareosSlotNumber(SmcElementAddressAssignment *smc_elem_aa , slot_type slot_type, slot_number_t slotnumber)
{

if (slot_type == slot_type_storage) {
return (slotnumber
+ smc_elem_aa->storage_base_address
- 1); // normal slots count start from 1

} else if(slot_type == slot_type_import) {
return (slotnumber
+ smc_elem_aa->import_export_base_address
- smc_elem_aa->storage_count // i/e slots follow after normal slots
- 1); // normal slots count start from 1

} else if (slot_type == slot_type_picker) {
return (slotnumber
+ smc_elem_aa->picker_base_address
);

} else if (slot_type == slot_type_drive) {
return (slotnumber
+ smc_elem_aa->drive_base_address
);

} else if (slot_type == slot_type_unknown){
return -1;
} else {
return -1;
}
}

/**
* calculate the slotnumber for element address and slot_type
*/
slot_number_t GetBareosSlotNumberByElementAddress(SmcElementAddressAssignment *smc_elem_aa, slot_type slot_type, slot_number_t element_addr)
{
if (slot_type == slot_type_storage) {
return (element_addr
- smc_elem_aa->storage_base_address
+ 1); // slots count start from 1


} else if(slot_type == slot_type_import) {
return (element_addr
- smc_elem_aa->import_export_count
+ smc_elem_aa->storage_count // i/e slots follow after normal slots
+ 1); // slots count start from 1

} else if (slot_type == slot_type_drive) {
return (element_addr
- smc_elem_aa->drive_base_address
);

} else if (slot_type == slot_type_picker) {
return (element_addr
- smc_elem_aa->picker_base_address
);

} else if (slot_type == slot_type_unknown){
return -1;

} else {
return -1;
}

}


} /* namespace directordaemon */
24 changes: 12 additions & 12 deletions core/src/dird/ua_impexp.cc
Expand Up @@ -101,7 +101,7 @@ static inline void validate_slot_list(UaContext *ua,
*/
foreach_dlist(vl, vol_list->contents) {
switch (vl->Type) {
case slot_type_normal:
case slot_type_storage:
case slot_type_import:
if (BitIsSet(vl->Slot - 1, slot_list)) {
switch (content) {
Expand All @@ -119,7 +119,7 @@ static inline void validate_slot_list(UaContext *ua,
* that it has content. We just unload the drive
* on the export move operation.
*/
if (vl->Type == slot_type_normal &&
if (vl->Type == slot_type_storage &&
vl->Content == slot_content_empty &&
vol_is_loaded_in_drive(store, vol_list, vl->Slot) != NULL) {
continue;
Expand All @@ -140,7 +140,7 @@ static inline void validate_slot_list(UaContext *ua,
* make sure its not loaded in a drive because
* then the slot is not really empty.
*/
if (vl->Type == slot_type_normal &&
if (vl->Type == slot_type_storage &&
vl->Content == slot_content_empty &&
vol_is_loaded_in_drive(store, vol_list, vl->Slot) == NULL) {
continue;
Expand Down Expand Up @@ -282,7 +282,7 @@ static inline changer_vol_list_t *scan_slots_for_volnames(UaContext *ua,
* See if the slot is empty because the volume is
* loaded in a drive.
*/
if (vl1->Type == slot_type_normal &&
if (vl1->Type == slot_type_storage &&
(vl2 = vol_is_loaded_in_drive(store, vol_list, vl1->Slot)) != NULL) {
if (vl2->VolName) {
free(vl2->VolName);
Expand Down Expand Up @@ -366,7 +366,7 @@ static inline changer_vol_list_t *scan_slots_for_volnames(UaContext *ua,
continue;
}
break;
case slot_type_normal:
case slot_type_storage:
case slot_type_import:
/*
* See if a slot list selection was done and
Expand Down Expand Up @@ -446,7 +446,7 @@ static inline bool get_slot_list_using_volname(UaContext *ua,
* We only select normal and import/export slots.
*/
switch (vl1->Type) {
case slot_type_normal:
case slot_type_storage:
case slot_type_import:
/*
* When the source slot list is limited we check to
Expand Down Expand Up @@ -613,7 +613,7 @@ static inline slot_number_t auto_fill_slot_selection(StorageResource *store,
* make sure its not loaded in a drive because
* then the slot is not really empty.
*/
if (type == slot_type_normal &&
if (type == slot_type_storage &&
content == slot_content_empty &&
vol_is_loaded_in_drive(store, vol_list, vl->Slot) != NULL) {
Dmsg3(100, "Skipping slot %hd, Type %hd, Content %hd is empty but loaded in drive\n",
Expand Down Expand Up @@ -655,7 +655,7 @@ static inline bool verify_slot_list(StorageResource *store,
* don't consider any other slot type.
*/
switch (vl->Type) {
case slot_type_normal:
case slot_type_storage:
case slot_type_import:
if (BitIsSet(vl->Slot - 1, slot_list)) {
/*
Expand All @@ -675,7 +675,7 @@ static inline bool verify_slot_list(StorageResource *store,
* we can just release the drive so that its put back into
* the slot and then moved.
*/
if (vl->Type == slot_type_normal) {
if (vl->Type == slot_type_storage) {
switch (content) {
case slot_content_empty:
if (vol_is_loaded_in_drive(store, vol_list, vl->Slot) != NULL) {
Expand Down Expand Up @@ -1223,7 +1223,7 @@ static bool PerformMoveOperation(UaContext *ua, enum e_move_op operation)
nr_enabled_dst_slots = auto_fill_slot_selection(store.store,
vol_list,
dst_slot_list,
slot_type_normal,
slot_type_storage,
slot_content_empty);
if (nr_enabled_src_slots > nr_enabled_dst_slots) {
ua->WarningMsg(_("Not enough free slots available to import %hd volumes\n"),
Expand All @@ -1234,7 +1234,7 @@ static bool PerformMoveOperation(UaContext *ua, enum e_move_op operation)
/*
* All slots in the destination selection need to be normal slots and empty.
*/
if (!verify_slot_list(store.store, vol_list, dst_slot_list, slot_type_normal, slot_content_empty)) {
if (!verify_slot_list(store.store, vol_list, dst_slot_list, slot_type_storage, slot_content_empty)) {
ua->WarningMsg(_("Not all slots in destination selection are normal slots and empty.\n"));
goto bail_out;
}
Expand All @@ -1246,7 +1246,7 @@ static bool PerformMoveOperation(UaContext *ua, enum e_move_op operation)
/*
* All slots in the source selection need to be normal slots.
*/
if (!verify_slot_list(store.store, vol_list, src_slot_list, slot_type_normal, slot_content_full)) {
if (!verify_slot_list(store.store, vol_list, src_slot_list, slot_type_storage, slot_content_full)) {
ua->WarningMsg(_("Not all slots in source selection are normal slots and filled.\n"));
goto bail_out;
}
Expand Down

0 comments on commit 7357106

Please sign in to comment.