* Version $Id$
*/
/*
- Copyright (C) 2002-2005 Kern Sibbald
+ Copyright (C) 2002-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
/* Ensure that the media_type for each device is the same */
foreach_res(changer, R_AUTOCHANGER) {
DEVRES *device;
- char *media_type = NULL;
foreach_alist(device, changer->device) {
/*
* If the device does not have a changer name or changer command
OK = false;
}
+#ifdef xxx_needed
if (media_type == NULL) {
media_type = device->media_type; /* get Media Type of first device */
continue;
OK = false;
continue;
}
+#endif
}
}
return OK;
int rtn_stat = -1; /* error status */
POOLMEM *changer;
+ if (!dev->is_autochanger()) {
+ return 0;
+ }
slot = dcr->VolCatInfo.InChanger ? dcr->VolCatInfo.Slot : 0;
/*
* Handle autoloaders here. If we cannot autoload it, we
* will return 0 so that the sysop will be asked to load it.
*/
- if (writing && dev->is_autochanger() && slot <= 0) {
+ if (writing && slot <= 0) {
if (dir) {
return 0; /* For user, bail out right now */
}
dcr->VolCatInfo.Slot = slot; /* slot to be loaded */
changer = edit_device_codes(dcr, changer,
dcr->device->changer_command, "load");
+ offline_or_rewind_dev(dev);
+ force_close_device(dev);
status = run_program(changer, timeout, NULL);
if (status == 0) {
Jmsg(jcr, M_INFO, 0, _("3305 Autochanger \"load slot %d, drive %d\", status is OK.\n"),
rtn_stat = -1; /* hard error */
}
Dmsg2(400, "load slot %d status=%d\n", slot, status);
+ unlock_changer(dcr);
} else {
status = 0; /* we got what we want */
dev->Slot = slot; /* set currently loaded slot */
} else {
rtn_stat = 0; /* no changer found */
}
- unlock_changer(dcr);
free_pool_memory(changer);
return rtn_stat;
status = run_program(changer, timeout, results);
Dmsg3(50, "run_prog: %s stat=%d result=%s\n", changer, status, results);
if (status == 0) {
- loaded = atoi(results);
+ loaded = str_to_int32(results);
if (loaded > 0) {
Jmsg(jcr, M_INFO, 0, _("3302 Autochanger \"loaded drive %d\", result is Slot %d.\n"),
drive, loaded);
loaded = get_autochanger_loaded_slot(dcr);
}
- /* We are going to load a new tape, so close the device */
- offline_or_rewind_dev(dev);
- force_close_device(dev);
-
if (loaded > 0) {
POOLMEM *changer = get_pool_memory(PM_FNAME);
lock_changer(dcr);
dcr->VolCatInfo.Slot = loaded;
changer = edit_device_codes(dcr, changer,
dcr->device->changer_command, "unload");
+ offline_or_rewind_dev(dev);
+ force_close_device(dev);
int stat = run_program(changer, timeout, NULL);
dcr->VolCatInfo.Slot = slot;
if (stat != 0) {
AUTOCHANGER *changer = dcr->dev->device->changer_res;
DEVRES *device;
bool found = false;
+ bool first = true;
+
if (!changer) {
return false;
if (!found) {
return true;
}
+
+ /* The Volume we want is on another device. */
+
+ for (int i=0; i < 3; i++) {
+ if (dev->is_busy()) {
+ wait_for_device(dcr->jcr, first);
+ first = false;
+ continue;
+ }
+ break;
+ }
+ P(dev->mutex);
if (dev->is_busy()) {
Jmsg(jcr, M_WARNING, 0, _("Volume %s is in use by device %s\n"),
dcr->VolumeName, dev->print_name());
Dmsg2(200, "Volume %s is in use by device %s\n",
dcr->VolumeName, dev->print_name());
-
+ V(dev->mutex);
return false;
}
- /* We are going to unload a tape, so close the device */
- offline_or_rewind_dev(dev);
- force_close_device(dev);
-
POOLMEM *changer_cmd = get_pool_memory(PM_FNAME);
lock_changer(dcr);
Jmsg(jcr, M_INFO, 0,
changer_cmd = edit_device_codes(dcr, changer_cmd,
dcr->device->changer_command, "unload");
Dmsg1(200, "Run program=%s\n", changer_cmd);
+ offline_or_rewind_dev(dev);
+ force_close_device(dev);
int stat = run_program(changer_cmd, timeout, NULL);
dcr->VolCatInfo.Slot = save_slot;
dcr->dev = save_dev;
Dmsg0(200, "Slot unloaded\n");
}
unlock_changer(dcr);
+ V(dev->mutex);
free_pool_memory(changer_cmd);
return ok;
}
if (!dev->is_autochanger() || !dcr->device->changer_name ||
!dcr->device->changer_command) {
+ if (strcmp(cmd, "drives") == 0) {
+ bnet_fsend(dir, "drives=1\n");
+ }
bnet_fsend(dir, _("3993 Device %s not an autochanger device.\n"),
dev->print_name());
return false;
}
- changer = get_pool_memory(PM_FNAME);
/* List command? */
if (strcmp(cmd, "list") == 0) {
unload_autochanger(dcr, -1);
}
+ if (strcmp(cmd, "drives") == 0) {
+ AUTOCHANGER *changer_res = dcr->device->changer_res;
+ int drives = 1;
+ if (changer_res) {
+ drives = changer_res->device->size();
+ }
+ bnet_fsend(dir, "drives=%d\n", drives);
+ Dmsg1(100, "drives=%d\n", drives);
+ return true;
+ }
+ changer = get_pool_memory(PM_FNAME);
lock_changer(dcr);
/* Now issue the command */
changer = edit_device_codes(dcr, changer,
Dmsg1(100, "<stored: %s\n", dir->msg);
bnet_send(dir);
}
- } else {
+ } else if (strcmp(cmd, "slots") == 0 ) {
+ char buf[100], *p;
/* For slots command, read a single line */
- bstrncpy(dir->msg, "slots=", len);
- fgets(dir->msg+6, len-6, bpipe->rfd);
- dir->msglen = strlen(dir->msg);
+ buf[0] = 0;
+ fgets(buf, sizeof(buf)-1, bpipe->rfd);
+ buf[sizeof(buf)-1] = 0;
+ /* Strip any leading space in front of # of slots */
+ for (p=buf; B_ISSPACE(*p); p++)
+ { }
+ bnet_fsend(dir, "slots=%s", p);
Dmsg1(100, "<stored: %s", dir->msg);
- bnet_send(dir);
- }
+ }
stat = close_bpipe(bpipe);
if (stat != 0) {