* 0 on failure (no changer available)
* -1 on error on autochanger
*/
-int autoload_device(JCR *jcr, DEVICE *dev, int writing, BSOCK *dir)
+int autoload_device(DCR *dcr, int writing, BSOCK *dir)
{
+ JCR *jcr = dcr->jcr;
+ DEVICE *dev = dcr->dev;
int slot = jcr->VolCatInfo.Slot;
int drive = jcr->device->drive_index;
int rtn_stat = -1; /* error status */
if (dir) {
return 0; /* For user, bail out right now */
}
- if (dir_find_next_appendable_volume(jcr)) {
+ if (dir_find_next_appendable_volume(dcr)) {
slot = jcr->VolCatInfo.Slot;
} else {
slot = 0;
changer = edit_device_codes(jcr, changer,
jcr->device->changer_command, "unload");
status = run_program(changer, timeout, NULL);
+ if (status != 0) {
+ berrno be;
+ be.set_errno(status);
+ Jmsg(jcr, M_INFO, 0, _("3992 Bad autochanger \"unload slot %d, drive %d\": ERR=%s.\n"),
+ slot, drive, be.strerror());
+ }
+
Dmsg1(400, "unload status=%d\n", status);
}
/*
Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"),
slot, drive);
} else {
- Jmsg(jcr, M_INFO, 0, _("3992 Bad autochanger \"load slot %d, drive %d\", status=%d.\n"),
- slot, drive, status);
+ berrno be;
+ be.set_errno(status);
+ Jmsg(jcr, M_INFO, 0, _("3992 Bad autochanger \"load slot %d, drive %d\": ERR=%s.\n"),
+ slot, drive, be.strerror());
}
Dmsg2(400, "load slot %d status=%d\n", slot, status);
} else {
drive);
}
} else {
- Jmsg(jcr, M_INFO, 0, _("3991 Bad autochanger \"loaded drive %d\" command, status=%d.\n"),
- drive, status);
+ berrno be;
+ be.set_errno(status);
+ Jmsg(jcr, M_INFO, 0, _("3991 Bad autochanger \"loaded drive %d\" command: ERR=%s.\n"),
+ drive, be.strerror());
loaded = -1; /* force unload */
}
free_pool_memory(changer);
* The Volume is not in the correct slot, so mark this
* Volume as not being in the Changer.
*/
-void invalid_slot_in_catalog(JCR *jcr, DEVICE *dev)
+void invalid_slot_in_catalog(DCR *dcr)
{
+ JCR *jcr = dcr->jcr;
+ DEVICE *dev = dcr->dev;
Jmsg(jcr, M_ERROR, 0, _("Autochanger Volume \"%s\" not found in slot %d.\n"
" Setting slot to zero in catalog.\n"),
jcr->VolCatInfo.VolCatName, jcr->VolCatInfo.Slot);
jcr->VolCatInfo.InChanger = false;
dev->VolCatInfo.InChanger = false;
Dmsg0(100, "update vol info in mount\n");
- dir_update_volume_info(jcr, true); /* set new status */
+ dir_update_volume_info(dcr, true); /* set new status */
}
/*
* with their barcodes.
* We assume that it is always the Console that is calling us.
*/
-int autochanger_list(JCR *jcr, DEVICE *dev, BSOCK *dir)
+bool autochanger_list(DCR *dcr, BSOCK *dir)
{
+ DEVICE *dev = dcr->dev;
+ JCR *jcr = dcr->jcr;
uint32_t timeout = jcr->device->max_changer_wait;
POOLMEM *changer;
BPIPE *bpipe;
if (!dev_cap(dev, CAP_AUTOCHANGER) || !jcr->device->changer_name ||
!jcr->device->changer_command) {
bnet_fsend(dir, _("3993 Not a autochanger device.\n"));
- return 0;
+ return false;
}
changer = get_pool_memory(PM_FNAME);
slot = jcr->VolCatInfo.Slot;
jcr->VolCatInfo.Slot = loaded;
changer = edit_device_codes(jcr, changer, jcr->device->changer_command, "unload");
- run_program(changer, timeout, NULL);
+ int stat = run_program(changer, timeout, NULL);
+ if (stat != 0) {
+ berrno be;
+ be.set_errno(stat);
+ Jmsg(jcr, M_INFO, 0, _("3995 Bad autochanger \"unload slot %d\" command: ERR=%s.\n"),
+ loaded, be.strerror());
+ }
jcr->VolCatInfo.Slot = slot;
}
bpipe = open_bpipe(changer, timeout, "r");
if (!bpipe) {
bnet_fsend(dir, _("3993 Open bpipe failed.\n"));
- goto bail_out;
+ free_pool_memory(changer);
+ return false;
}
/* Get output from changer */
while (fgets(dir->msg, len, bpipe->rfd)) {
dir->msglen = strlen(dir->msg);
bnet_send(dir);
}
+ int stat = close_bpipe(bpipe);
+ if (stat != 0) {
+ berrno be;
+ be.set_errno(stat);
+ bnet_fsend(dir, "Autochanger error: ERR=%s\n", be.strerror());
+ }
bnet_sig(dir, BNET_EOD);
- close_bpipe(bpipe);
-bail_out:
free_pool_memory(changer);
- return 1;
+ return true;
}
-
/*
* Edit codes into ChangerCommand
* %% = %