+ set_dcr_from_vol(dcr, vol);
+
+ Dmsg2(100, "Want Vol=%s Slot=%d\n", vol->VolumeName, vol->Slot);
+
+ /*
+ * If the MediaType requested for this volume is not the
+ * same as the current drive, we attempt to find the same
+ * device that was used to write the orginal volume. If
+ * found, we switch to using that device.
+ *
+ * N.B. A lot of routines rely on the dcr pointer not changing
+ * read_records.c even has multiple dcrs cached, so we take care
+ * here to release all important parts of the dcr and re-acquire
+ * them such as the block pointer (size may change), but we do
+ * not release the dcr.
+ */
+ Dmsg2(50, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
+ if (dcr->media_type[0] && strcmp(dcr->media_type, dev->device->media_type) != 0) {
+ RCTX rctx;
+ DIRSTORE *store;
+ int stat;
+
+ Jmsg3(jcr, M_INFO, 0, _("Changing device. Want Media Type=\"%s\" have=\"%s\"\n"
+ " device=%s\n"),
+ dcr->media_type, dev->device->media_type, dev->print_name());
+ Dmsg3(50, "Changing device. Want Media Type=\"%s\" have=\"%s\"\n"
+ " device=%s\n",
+ dcr->media_type, dev->device->media_type, dev->print_name());
+
+ dev->dunblock(DEV_UNLOCKED);
+
+ lock_reservations();
+ memset(&rctx, 0, sizeof(RCTX));
+ rctx.jcr = jcr;
+ jcr->reserve_msgs = New(alist(10, not_owned_by_alist));
+ rctx.any_drive = true;
+ rctx.device_name = vol->device;
+ store = new DIRSTORE;
+ memset(store, 0, sizeof(DIRSTORE));
+ store->name[0] = 0; /* No dir name */
+ bstrncpy(store->media_type, vol->MediaType, sizeof(store->media_type));
+ bstrncpy(store->pool_name, dcr->pool_name, sizeof(store->pool_name));
+ bstrncpy(store->pool_type, dcr->pool_type, sizeof(store->pool_type));
+ store->append = false;
+ rctx.store = store;
+ clean_device(dcr); /* clean up the dcr */
+
+ /*
+ * Search for a new device
+ */
+ stat = search_res_for_device(rctx);
+ release_reserve_messages(jcr); /* release queued messages */
+ unlock_reservations();
+
+ if (stat == 1) {
+ dev = dcr->dev; /* get new device pointer */
+ dev->dblock(BST_DOING_ACQUIRE);
+ dcr->VolumeName[0] = 0;
+ Jmsg(jcr, M_INFO, 0, _("Media Type change. New device %s chosen.\n"),
+ dev->print_name());
+ Dmsg1(50, "Media Type change. New device %s chosen.\n", dev->print_name());
+
+ bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
+ bstrncpy(dcr->VolCatInfo.VolCatName, vol->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
+ bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type));
+ dcr->VolCatInfo.Slot = vol->Slot;
+ dcr->VolCatInfo.InChanger = vol->Slot > 0;
+ bstrncpy(dcr->pool_name, store->pool_name, sizeof(dcr->pool_name));
+ bstrncpy(dcr->pool_type, store->pool_type, sizeof(dcr->pool_type));
+ } else {
+ /* error */
+ Jmsg1(jcr, M_FATAL, 0, _("No suitable device found to read Volume \"%s\"\n"),
+ vol->VolumeName);
+ Dmsg1(50, "No suitable device found to read Volume \"%s\"\n", vol->VolumeName);
+ goto get_out;
+ }
+ }