* Version $Id$
*/
/*
- Copyright (C) 2003-2005 Kern Sibbald
+ Copyright (C) 2003-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
/*
* Update Slots corresponding to Volumes in autochanger
*/
-int update_slots(UAContext *ua)
+void update_slots(UAContext *ua)
{
STORE *store;
vol_list_t *vl, *vol_list = NULL;
if (!open_db(ua)) {
- return 1;
+ return;
}
store = get_storage_resource(ua, true/*arg is storage*/);
if (!store) {
- return 1;
+ return;
}
- drive = get_storage_drive(ua, store);
set_storage(ua->jcr, store);
+ drive = get_storage_drive(ua, store);
scan = find_arg(ua, N_("scan")) >= 0;
max_slots = get_num_slots_from_SD(ua);
+ Dmsg1(100, "max_slots=%d\n", max_slots);
if (max_slots <= 0) {
bsendmsg(ua, _("No slots in changer to scan.\n"));
- return 1;
+ return;
}
slot_list = (char *)malloc(max_slots+1);
if (!get_user_slot_list(ua, slot_list, max_slots)) {
free(slot_list);
- return 1;
+ return;
}
vol_list = get_vol_list_from_SD(ua, scan);
goto bail_out;
}
+ /* First zap out any InChanger with StorageId=0 */
+ db_sql_query(ua->db, "UPDATE Media SET InChanger=0 WHERE StorageId=0", NULL, NULL);
+
/* Walk through the list updating the media records */
for (vl=vol_list; vl; vl=vl->next) {
if (vl->Slot > max_slots) {
db_unlock(ua->db);
if (!vl->VolName) {
Dmsg1(000, "No VolName for Slot=%d setting InChanger to zero.\n", vl->Slot);
- bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), vl->Slot);
+ bsendmsg(ua, _("No VolName for Slot=%d InChanger set to zero.\n"), vl->Slot);
continue;
}
memset(&mr, 0, sizeof(mr));
db_unlock(ua->db);
continue;
} else {
- bsendmsg(ua, _("Volume \"%s\" not found in catalog. Slot=%d set InChanger to zero.\n"),
+ bsendmsg(ua, _("Volume \"%s\" not found in catalog. Slot=%d InChanger set to zero.\n"),
mr.VolumeName, vl->Slot);
}
db_unlock(ua->db);
free(slot_list);
close_sd_bsock(ua);
- return 1;
+ return;
}
if (!store) {
return 1;
}
- drive = get_storage_drive(ua, store);
set_storage(ua->jcr, store);
+ drive = get_storage_drive(ua, store);
if (label_barcodes) {
label_from_barcodes(ua, drive);
mr.VolBytes = 1;
bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
mr.MediaType[0] = 0;
+ mr.StorageId = store->StorageId;
if (!db_update_media_record(ua->jcr, ua->db, &mr)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
}
} else { /* create the media record */
+ if (pr.MaxVols > 0 && pr.NumVols >= pr.MaxVols) {
+ bsendmsg(ua, _("Maximum pool Volumes=%d reached.\n"), pr.MaxVols);
+ goto bail_out;
+ }
set_pool_dbr_defaults_in_media_dbr(&mr, &pr);
bstrncpy(mr.VolStatus, "Cleaning", sizeof(mr.VolStatus));
mr.MediaType[0] = 0;
if (media_record_exists) { /* we update it */
mr->VolBytes = 1;
mr->InChanger = 1;
+ mr->StorageId = ua->jcr->store->StorageId;
if (!db_update_media_record(ua->jcr, ua->db, mr)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
ok = false;
set_pool_dbr_defaults_in_media_dbr(mr, pr);
mr->VolBytes = 1; /* flag indicating Volume labeled */
mr->InChanger = 1;
+ mr->StorageId = ua->jcr->store->StorageId;
if (db_create_media_record(ua->jcr, ua->db, mr)) {
bsendmsg(ua, _("Catalog record for Volume \"%s\", Slot %d successfully created.\n"),
mr->VolumeName, mr->Slot);