/* Forward referenced functions */
-static int do_label(UAContext *ua, char *cmd, int relabel);
+static int do_label(UAContext *ua, const char *cmd, int relabel);
static void label_from_barcodes(UAContext *ua);
static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, int relabel, bool media_record_exits);
static vol_list_t *get_vol_list_from_SD(UAContext *ua, bool scan);
static void free_vol_list(vol_list_t *vol_list);
-static int is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr);
+static bool is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr);
static BSOCK *open_sd_bsock(UAContext *ua);
static void close_sd_bsock(UAContext *ua);
static char *get_volume_name_from_SD(UAContext *ua, int Slot);
*
* label storage=xxx volume=vvv
*/
-int label_cmd(UAContext *ua, char *cmd)
+int label_cmd(UAContext *ua, const char *cmd)
{
return do_label(ua, cmd, 0); /* standard label */
}
-int relabel_cmd(UAContext *ua, char *cmd)
+int relabel_cmd(UAContext *ua, const char *cmd)
{
return do_label(ua, cmd, 1); /* relabel tape */
}
-#define MAX_SLOTS 5000
+static int const max_slots = 5000;
static bool get_user_slot_list(UAContext *ua, char *slot_list, int num_slots)
{
int i;
- char *msg;
+ const char *msg;
for (int i=0; i<num_slots; i++) {
slot_list[i] = 0;
scan = find_arg(ua, _("scan")) >= 0;
- slot_list = (char *)malloc(MAX_SLOTS);
- if (!get_user_slot_list(ua, slot_list, MAX_SLOTS)) {
+ slot_list = (char *)malloc(max_slots);
+ if (!get_user_slot_list(ua, slot_list, max_slots)) {
free(slot_list);
return 1;
}
/* Walk through the list updating the media records */
for (vl=vol_list; vl; vl=vl->next) {
+ if (vl->Slot >= max_slots) {
+ bsendmsg(ua, _("Slot %d larger than max %d ignored.\n"));
+ continue;
+ }
/* Check if user wants us to look at this slot */
if (!slot_list[vl->Slot]) {
+ Dmsg1(100, "Skipping slot=%d\n", vl->Slot);
continue;
}
/* If scanning, we read the label rather than the barcode */
vl->VolName = NULL;
}
vl->VolName = get_volume_name_from_SD(ua, vl->Slot);
+ Dmsg2(100, "Got Vol=%s from SD for Slot=%d\n", vl->VolName, vl->Slot);
}
+ slot_list[vl->Slot] = 0; /* clear Slot */
if (!vl->VolName) {
+ Dmsg1(100, "No VolName for Slot=%d setting InChanger to zero.\n", vl->Slot);
+ memset(&mr, 0, sizeof(mr));
+ mr.Slot = vl->Slot;
+ mr.InChanger = 1;
+ /* Set InChanger to zero for this Slot */
+ db_lock(ua->db);
+ db_make_inchanger_unique(ua->jcr, ua->db, &mr);
+ db_unlock(ua->db);
+ bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), vl->Slot);
continue;
}
memset(&mr, 0, sizeof(mr));
}
db_unlock(ua->db);
}
-
-
+ memset(&mr, 0, sizeof(mr));
+ mr.InChanger = 1;
+ for (int i=1; i<max_slots; i++) {
+ if (slot_list[i]) {
+ mr.Slot = i;
+ /* Set InChanger to zero for this Slot */
+ db_lock(ua->db);
+ db_make_inchanger_unique(ua->jcr, ua->db, &mr);
+ db_unlock(ua->db);
+ bsendmsg(ua, _("No VolName for Slot=%d set InChanger to zero.\n"), i);
+ }
+ }
+
bail_out:
free_vol_list(vol_list);
/*
* Common routine for both label and relabel
*/
-static int do_label(UAContext *ua, char *cmd, int relabel)
+static int do_label(UAContext *ua, const char *cmd, int relabel)
{
STORE *store;
BSOCK *sd;
int ok = FALSE;
int i;
bool media_record_exists = false;
- static char *barcode_keyword[] = {
+ static const char *barcode_keyword[] = {
"barcode",
"barcodes",
NULL};
bool media_record_exists;
char *slot_list;
- slot_list = (char *)malloc(MAX_SLOTS);
- if (!get_user_slot_list(ua, slot_list, MAX_SLOTS)) {
- free(slot_list);
- return;
+ slot_list = (char *)malloc(max_slots);
+ if (!get_user_slot_list(ua, slot_list, max_slots)) {
+ goto bail_out;
}
vol_list = get_vol_list_from_SD(ua, false /*no scan*/);
bstrncpy(mr.MediaType, store->media_type, sizeof(mr.MediaType));
mr.Slot = vl->Slot;
- if (!send_label_request(ua, &mr, &omr, &pr, 0, media_record_exists)) {
- goto bail_out;
- }
+ send_label_request(ua, &mr, &omr, &pr, 0, media_record_exists);
}
bail_out:
+ free(slot_list);
free_vol_list(vol_list);
close_sd_bsock(ua);
* Check if the Volume name has legal characters
* If ua is non-NULL send the message
*/
-int is_volume_name_legal(UAContext *ua, char *name)
+bool is_volume_name_legal(UAContext *ua, const char *name)
{
int len;
- char *p;
- char *accept = ":.-_";
+ const char *p;
+ const char *accept = ":.-_";
/* Restrict the characters permitted in the Volume name */
for (p=name; *p; p++) {
return 1;
}
+/*
+ * NOTE! This routine opens the SD socket but leaves it open
+ */
static int send_label_request(UAContext *ua, MEDIA_DBR *mr, MEDIA_DBR *omr,
POOL_DBR *pr, int relabel, bool media_record_exists)
{
}
}
} else {
- bsendmsg(ua, _("Label command failed.\n"));
+ bsendmsg(ua, _("Label command failed for Volume %s.\n"), mr->VolumeName);
}
return ok;
}
int rtn_slot;
if (!(sd=open_sd_bsock(ua))) {
+ bsendmsg(ua, _("Could not open SD socket.\n"));
return NULL;
}
bstrncpy(dev_name, store->dev_name, sizeof(dev_name));
/* Get Volume name in this Slot */
while (bnet_recv(sd) >= 0) {
bsendmsg(ua, "%s", sd->msg);
+ Dmsg1(100, "Got: %s", sd->msg);
if (strncmp(sd->msg, "3001 Volume=", 12) == 0) {
VolName = (char *)malloc(sd->msglen);
if (sscanf(sd->msg, "3001 Volume=%s Slot=%d", VolName, &rtn_slot) == 2) {
VolName = NULL;
}
}
+ close_sd_bsock(ua);
Dmsg1(200, "get_vol_name=%s\n", NPRT(VolName));
return VolName;
}
vl = (vol_list_t *)malloc(sizeof(vol_list_t));
vl->Slot = Slot;
if (p) {
+ if (*p == ':') {
+ p++; /* skip separator */
+ }
vl->VolName = bstrdup(p);
} else {
vl->VolName = NULL;
}
+ Dmsg2(100, "Add slot=%d Vol=%s to SD list.\n", vl->Slot, NPRT(vl->VolName));
if (!vol_list) {
vl->next = vol_list;
vol_list = vl;
static void free_vol_list(vol_list_t *vol_list)
{
vol_list_t *vl;
+
/* Free list */
for (vl=vol_list; vl; ) {
vol_list_t *ovl;
* with the Cleaning Prefix. If they match, this is a cleaning
* tape.
*/
-static int is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr)
+static bool is_cleaning_tape(UAContext *ua, MEDIA_DBR *mr, POOL_DBR *pr)
{
+ /* Find Pool resource */
+ ua->jcr->pool = (POOL *)GetResWithName(R_POOL, pr->Name);
if (!ua->jcr->pool) {
- /* Find Pool resource */
- ua->jcr->pool = (POOL *)GetResWithName(R_POOL, pr->Name);
- if (!ua->jcr->pool) {
- bsendmsg(ua, _("Pool %s resource not found!\n"), pr->Name);
- return 1;
- }
+ bsendmsg(ua, _("Pool \"%s\" resource not found!\n"), pr->Name);
+ return true;
}
if (ua->jcr->pool->cleaning_prefix == NULL) {
- return 0;
+ return false;
}
- Dmsg4(200, "CLNprefix=%s: Vol=%s: len=%d strncmp=%d\n",
+ Dmsg4(100, "CLNprefix=%s: Vol=%s: len=%d strncmp=%d\n",
ua->jcr->pool->cleaning_prefix, mr->VolumeName,
strlen(ua->jcr->pool->cleaning_prefix),
strncmp(mr->VolumeName, ua->jcr->pool->cleaning_prefix,