- pm_strcpy(&jcr->VolumeName, dev->VolHdr.VolName);
- bstrncpy(dcr->VolumeName, dev->VolHdr.VolName, sizeof(dcr->VolumeName));
- if (!dir_get_volume_info(jcr, GET_VOL_INFO_FOR_WRITE) &&
- !(dir_find_next_appendable_volume(jcr) &&
- strcmp(dev->VolHdr.VolName, jcr->VolumeName) == 0)) { /* wrong tape mounted */
- if (dev->num_writers != 0) {
- DEVICE *d = ((DEVRES *)dev->device)->dev;
- uint32_t open_vols = 0;
- for ( ; d; d=d->next) {
- open_vols++;
- }
- if (dev_state(dev, ST_FILE) && dev->max_open_vols > open_vols) {
- d = init_dev(NULL, (DEVRES *)dev->device); /* init new device */
- d->prev = dev; /* chain in new device */
- d->next = dev->next;
- dev->next = d;
- /* Release old device */
- P(dev->mutex);
- unblock_device(dev);
- V(dev->mutex);
- /* Make new device current device and lock it */
- dev = d;
- lock_device(dev);
- block_device(dev, BST_DOING_ACQUIRE);
- unlock_device(dev);
- } else {
- Jmsg(jcr, M_FATAL, 0, _("Device %s is busy writing on another Volume.\n"), dev_name(dev));
- goto get_out;
- }
- }
- /* Wrong tape mounted, release it, then fall through to get correct one */
- release = 1;
- do_mount = true;
+ 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 */
+ 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 */
+ Dmsg0(190, "Wrong tape mounted, release and try mount.\n");
+ release = true;
+ do_mount = true;