This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
- version 2 as ammended with additional clauses defined in the
+ version 2 as amended with additional clauses defined in the
file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
*/
DCR *new_dcr(JCR *jcr, DEVICE *dev)
{
- if (jcr && jcr->dcr) {
- return jcr->dcr;
- }
DCR *dcr = (DCR *)malloc(sizeof(DCR));
memset(dcr, 0, sizeof(DCR));
- if (jcr) {
- jcr->dcr = dcr;
- }
dcr->jcr = jcr;
- dcr->dev = dev;
if (dev) {
+ dcr->dev = dev;
dcr->device = dev->device;
+ dcr->block = new_block(dev);
+ dcr->rec = new_record();
+ dcr->max_job_spool_size = dev->device->max_job_spool_size;
+ /* Attach this dcr only if dev is initialized */
+ if (dev->fd != 0 && jcr && jcr->JobType != JT_SYSTEM) {
+ dev->attached_dcrs->append(dcr); /* attach dcr to device */
+// jcr->dcrs->append(dcr); /* put dcr in list for Job */
+ }
}
- dcr->block = new_block(dev);
- dcr->rec = new_record();
dcr->spool_fd = -1;
- dcr->max_job_spool_size = dev->device->max_job_spool_size;
- /* Attach this dcr only if dev is initialized */
- if (dev->fd != 0 && jcr && jcr->JobType != JT_SYSTEM) {
- dev->attached_dcrs->append(dcr); /* attach dcr to device */
-// jcr->dcrs->append(dcr); /* put dcr in list for Job */
- }
return dcr;
}
if (dcr->reserved_device) {
lock_device(dev);
dev->reserved_device--;
- Dmsg1(200, "=========== Dec reserve=%d\n", dev->reserved_device);
+ Dmsg1(200, "Dec reserve=%d\n", dev->reserved_device);
dcr->reserved_device = false;
if (dev->num_writers < 0) {
Jmsg1(dcr->jcr, M_ERROR, 0, _("Hey! num_writers=%d!!!!\n"), dev->num_writers);
if (dcr->jcr) {
dcr->jcr->dcr = NULL;
}
+ free_unused_volume(dcr); /* free unused vols attached to this dcr */
free(dcr);
}
* reading. If it is a file, it opens it.
* If it is a tape, it checks the volume name
*/
- for ( ; !dev->is_open(); ) {
- Dmsg1(120, "bstored: open vol=%s\n", dcr->VolumeName);
- if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
- if (dev->dev_errno == EIO) { /* no tape loaded */
- Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
- dev->print_name(), dcr->VolumeName, strerror_dev(dev));
- goto default_path;
- }
-
- /* If we have a dvd that requires mount,
- * we need to try to open the label, so the info can be reported
- * if a wrong volume has been mounted. */
- if (dev->is_dvd() && (dcr->VolCatInfo.VolCatParts > 0)) {
- break;
- }
-
- Jmsg3(jcr, M_FATAL, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
- dev->print_name(), dcr->VolumeName, strerror_dev(dev));
- goto get_out;
+ Dmsg1(100, "bstored: open vol=%s\n", dcr->VolumeName);
+ if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
+ if (dev->dev_errno == EIO) { /* no tape loaded */
+ Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed (EIO): ERR=%s\n"),
+ dev->print_name(), dcr->VolumeName, strerror_dev(dev));
+ goto default_path;
}
- Dmsg1(129, "opened dev %s OK\n", dev->print_name());
+
+ Jmsg3(jcr, M_FATAL, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
+ dev->print_name(), dcr->VolumeName, strerror_dev(dev));
+ goto get_out;
}
+ Dmsg1(100, "opened dev %s OK\n", dev->print_name());
- vol_label_status = read_dev_volume_label(dcr);
+ /* Read Volume Label */
Dmsg0(200, "calling read-vol-label\n");
+ vol_label_status = read_dev_volume_label(dcr);
switch (vol_label_status) {
case VOL_OK:
vol_ok = true;
get_out:
dev->unblock();
if (!vol_ok) {
- free_dcr(dcr);
dcr = NULL;
}
return dcr;
if (dcr->reserved_device) {
dev->reserved_device--;
- Dmsg1(200, "============ Dec reserve=%d\n", dev->reserved_device);
+ Dmsg1(200, "Dec reserve=%d\n", dev->reserved_device);
dcr->reserved_device = false;
}
*/
if (dev->can_read()) {
Jmsg1(jcr, M_FATAL, 0, _("Device %s is busy reading.\n"), dev->print_name());
+ Dmsg1(200, "Device %s is busy reading.\n", dev->print_name());
goto get_out;
}
* OK if next volume matches current volume
* otherwise mount desired volume obtained from
* dir_find_next_appendable_volume
+ * dev->VolHdr.VolumeName is what is in the drive
+ * dcr->VolumeName is what we pass into the routines, or
+ * get back from the subroutines.
*/
bstrncpy(dcr->VolumeName, dev->VolHdr.VolumeName, sizeof(dcr->VolumeName));
if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE) &&
!(dir_find_next_appendable_volume(dcr) &&
strcmp(dev->VolHdr.VolumeName, dcr->VolumeName) == 0)) { /* wrong tape mounted */
- Dmsg0(190, "Wrong tape mounted.\n");
- if (dev->num_writers != 0 || dev->reserved_device) {
- Jmsg(jcr, M_FATAL, 0, _("Device %s is busy writing on another Volume.\n"), dev->print_name());
+ Dmsg2(190, "Wrong tape mounted: %s. wants:%s\n", dev->VolHdr.VolumeName,
+ dcr->VolumeName);
+ /* Release volume reserved by dir_find_next_appendable_volume() */
+ if (dcr->VolumeName[0]) {
+ free_unused_volume(dcr);
+ }
+ if (dev->num_writers != 0) {
+ Jmsg3(jcr, M_FATAL, 0, _("Wanted Volume \"%s\", but device %s is busy writing on \"%s\" .\n"),
+ dcr->VolumeName, dev->print_name(), dev->VolHdr.VolumeName);
+ Dmsg3(200, "Wanted Volume \"%s\", but device %s is busy writing on \"%s\" .\n",
+ dcr->VolumeName, dev->print_name(), dev->VolHdr.VolumeName);
goto get_out;
}
/* Wrong tape mounted, release it, then fall through to get correct one */
if (dev->num_writers == 0) {
memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
}
- }
+ }
} else {
/* Not already in append mode, so mount the device */
Dmsg0(190, "Not in append mode, try mount.\n");
/* Reduce "noise" -- don't print if job canceled */
Jmsg(jcr, M_FATAL, 0, _("Could not ready device %s for append.\n"),
dev->print_name());
+ Dmsg1(200, "Could not ready device %s for append.\n",
+ dev->print_name());
}
goto get_out;
}
JCR *jcr = dcr->jcr;
DEVICE *dev = dcr->dev;
bool ok = true;
+ bool was_reading = false;
lock_device(dev);
Dmsg1(100, "release_device device is %s\n", dev->is_tape()?"tape":"disk");
/* if device is reserved, job never started, so release the reserve here */
if (dcr->reserved_device) {
dev->reserved_device--;
- Dmsg1(200, "========= Dec reserve=%d\n", dev->reserved_device);
+ Dmsg1(200, "Dec reserve=%d\n", dev->reserved_device);
dcr->reserved_device = false;
}
if (dev->can_read()) {
dev->clear_read(); /* clear read bit */
+ was_reading = true;
/******FIXME**** send read volume usage statistics to director */
}
unlock_device(dev);
free_dcr(dcr);
- jcr->dcr = NULL;
+ if (was_reading) {
+ jcr->read_dcr = NULL;
+ } else {
+ jcr->dcr = NULL;
+ }
pthread_cond_broadcast(&wait_device_release);
return ok;
}