2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2002-2012 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version three of the GNU Affero General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Affero General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula(R) is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Routines to acquire and release a device for read/write
31 * Kern Sibbald, August MMII
35 #include "bacula.h" /* pull in global headers */
36 #include "stored.h" /* pull in Storage Deamon headers */
38 /* Forward referenced functions */
39 static void attach_dcr_to_dev(DCR *dcr);
40 static void detach_dcr_from_dev(DCR *dcr);
41 static void set_dcr_from_vol(DCR *dcr, VOL_LIST *vol);
43 /*********************************************************************
44 * Acquire device for reading.
45 * The drive should have previously been reserved by calling
46 * reserve_device_for_read(). We read the Volume label from the block and
47 * leave the block pointers just after the label.
49 * Returns: NULL if failed for any reason
52 bool acquire_device_for_read(DCR *dcr)
54 DEVICE *dev = dcr->dev;
57 bool tape_previously_mounted;
59 bool try_autochanger = true;
64 P(dev->read_acquire_mutex);
65 Dmsg2(950, "dcr=%p dev=%p\n", dcr, dcr->dev);
66 Dmsg2(950, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
67 dev->dblock(BST_DOING_ACQUIRE);
69 if (dev->num_writers > 0) {
70 Jmsg2(jcr, M_FATAL, 0, _("Acquire read: num_writers=%d not zero. Job %d canceled.\n"),
71 dev->num_writers, jcr->JobId);
75 /* Find next Volume, if any */
79 Jmsg(jcr, M_FATAL, 0, _("No volumes specified for reading. Job %s canceled.\n"),
80 edit_int64(jcr->JobId, ed1));
84 for (i=1; i<jcr->CurReadVolume; i++) {
88 Jmsg(jcr, M_FATAL, 0, _("Logic error: no next volume to read. Numvol=%d Curvol=%d\n"),
89 jcr->NumReadVolumes, jcr->CurReadVolume);
90 goto get_out; /* should not happen */
92 set_dcr_from_vol(dcr, vol);
94 if (generate_plugin_event(jcr, bsdEventDeviceOpen, dcr) != bRC_OK) {
95 Jmsg(jcr, M_FATAL, 0, _("generate_plugin_event(bsdEventDeviceOpen) Failed\n"));
99 Dmsg2(100, "Want Vol=%s Slot=%d\n", vol->VolumeName, vol->Slot);
102 * If the MediaType requested for this volume is not the
103 * same as the current drive, we attempt to find the same
104 * device that was used to write the orginal volume. If
105 * found, we switch to using that device.
107 * N.B. A lot of routines rely on the dcr pointer not changing
108 * read_records.c even has multiple dcrs cached, so we take care
109 * here to release all important parts of the dcr and re-acquire
110 * them such as the block pointer (size may change), but we do
111 * not release the dcr.
113 Dmsg2(50, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
114 if (dcr->media_type[0] && strcmp(dcr->media_type, dev->device->media_type) != 0) {
119 Jmsg3(jcr, M_INFO, 0, _("Changing read device. Want Media Type=\"%s\" have=\"%s\"\n"
121 dcr->media_type, dev->device->media_type, dev->print_name());
122 Dmsg3(50, "Changing read device. Want Media Type=\"%s\" have=\"%s\"\n"
124 dcr->media_type, dev->device->media_type, dev->print_name());
126 generate_plugin_event(jcr, bsdEventDeviceClose, dcr);
128 dev->dunblock(DEV_UNLOCKED);
131 memset(&rctx, 0, sizeof(RCTX));
134 jcr->reserve_msgs = New(alist(10, not_owned_by_alist));
135 rctx.any_drive = true;
136 rctx.device_name = vol->device;
137 store = new DIRSTORE;
138 memset(store, 0, sizeof(DIRSTORE));
139 store->name[0] = 0; /* No dir name */
140 bstrncpy(store->media_type, vol->MediaType, sizeof(store->media_type));
141 bstrncpy(store->pool_name, dcr->pool_name, sizeof(store->pool_name));
142 bstrncpy(store->pool_type, dcr->pool_type, sizeof(store->pool_type));
143 store->append = false;
145 clean_device(dcr); /* clean up the dcr */
148 * Search for a new device
150 stat = search_res_for_device(rctx);
151 release_reserve_messages(jcr); /* release queued messages */
152 unlock_reservations();
154 if (stat == 1) { /* found new device to use */
156 * Switching devices, so acquire lock on new device,
157 * then release the old one.
159 P(dcr->dev->read_acquire_mutex);
160 V(dev->read_acquire_mutex);
161 dev = dcr->dev; /* get new device pointer */
162 dev->dblock(BST_DOING_ACQUIRE);
164 dcr->VolumeName[0] = 0;
165 Jmsg(jcr, M_INFO, 0, _("Media Type change. New read device %s chosen.\n"),
167 Dmsg1(50, "Media Type change. New read device %s chosen.\n", dev->print_name());
168 if (generate_plugin_event(jcr, bsdEventDeviceOpen, dcr) != bRC_OK) {
169 Jmsg(jcr, M_FATAL, 0, _("generate_plugin_event(bsdEventDeviceOpen) Failed\n"));
172 bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
173 dcr->setVolCatName(vol->VolumeName);
174 bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type));
175 dcr->VolCatInfo.Slot = vol->Slot;
176 dcr->VolCatInfo.InChanger = vol->Slot > 0;
177 bstrncpy(dcr->pool_name, store->pool_name, sizeof(dcr->pool_name));
178 bstrncpy(dcr->pool_type, store->pool_type, sizeof(dcr->pool_type));
181 Jmsg1(jcr, M_FATAL, 0, _("No suitable device found to read Volume \"%s\"\n"),
183 Dmsg1(50, "No suitable device found to read Volume \"%s\"\n", vol->VolumeName);
187 Dmsg2(400, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
191 if (dev->vol && dev->vol->is_swapping()) {
192 dev->vol->set_slot(vol->Slot);
193 Dmsg3(100, "swapping: slot=%d Vol=%s dev=%s\n", dev->vol->get_slot(),
194 dev->vol->vol_name, dev->print_name());
197 init_device_wait_timers(dcr);
199 tape_previously_mounted = dev->can_read() || dev->can_append() ||
201 // tape_initially_mounted = tape_previously_mounted;
203 /* Volume info is always needed because of VolParts */
204 Dmsg1(150, "dir_get_volume_info vol=%s\n", dcr->VolumeName);
205 if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_READ)) {
206 Dmsg2(150, "dir_get_vol_info failed for vol=%s: %s\n",
207 dcr->VolumeName, jcr->errmsg);
208 Jmsg1(jcr, M_WARNING, 0, "Read acquire: %s", jcr->errmsg);
210 dev->set_load(); /* set to load volume */
213 /* If not polling limit retries */
214 if (!dev->poll && retry++ > 10) {
217 dev->clear_labeled(); /* force reread of label */
218 if (job_canceled(jcr)) {
220 Mmsg1(dev->errmsg, _("Job %s canceled.\n"), edit_int64(jcr->JobId, ed1));
221 Jmsg(jcr, M_INFO, 0, dev->errmsg);
222 goto get_out; /* error return */
226 dcr->do_swapping(false/*!is_writing*/);
227 dcr->do_load(false /*!is_writing*/);
228 set_dcr_from_vol(dcr, vol); /* refresh dcr with desired volume info */
231 * This code ensures that the device is ready for
232 * reading. If it is a file, it opens it.
233 * If it is a tape, it checks the volume name
235 Dmsg1(100, "bstored: open vol=%s\n", dcr->VolumeName);
236 if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
238 Jmsg3(jcr, M_WARNING, 0, _("Read open device %s Volume \"%s\" failed: ERR=%s\n"),
239 dev->print_name(), dcr->VolumeName, dev->bstrerror());
243 Dmsg1(50, "opened dev %s OK\n", dev->print_name());
245 /* Read Volume Label */
246 Dmsg0(50, "calling read-vol-label\n");
247 vol_label_status = read_dev_volume_label(dcr);
248 switch (vol_label_status) {
250 Dmsg0(50, "Got correct volume.\n");
252 dev->VolCatInfo = dcr->VolCatInfo; /* structure assignment */
255 Dmsg0(50, "IO Error\n");
257 * Send error message generated by read_dev_volume_label()
258 * only we really had a tape mounted. This supresses superfluous
259 * error messages when nothing is mounted.
261 if (tape_previously_mounted) {
262 Jmsg(jcr, M_WARNING, 0, "Read acquire: %s", jcr->errmsg);
266 Dmsg3(50, "Vol name=%s want=%s drv=%s.\n", dev->VolHdr.VolumeName,
267 dcr->VolumeName, dev->print_name());
268 if (dev->is_volume_to_unload()) {
271 dev->set_unload(); /* force unload of unwanted tape */
272 if (!unload_autochanger(dcr, -1)) {
273 /* at least free the device so we can re-open with correct volume */
280 Jmsg1(jcr, M_WARNING, 0, "Read acquire: %s", jcr->errmsg);
282 Dmsg0(50, "default path\n");
283 tape_previously_mounted = true;
286 * If the device requires mount, close it, so the device can be ejected.
288 if (dev->requires_mount()) {
293 /* Call autochanger only once unless ask_sysop called */
294 if (try_autochanger) {
296 Dmsg2(200, "calling autoload Vol=%s Slot=%d\n",
297 dcr->VolumeName, dcr->VolCatInfo.Slot);
298 stat = autoload_device(dcr, 0, NULL);
300 try_autochanger = false;
301 continue; /* try reading volume mounted */
305 /* Mount a specific volume and no other */
306 Dmsg0(200, "calling dir_ask_sysop\n");
307 if (!dir_ask_sysop_to_mount_volume(dcr, ST_READ)) {
308 goto get_out; /* error return */
311 /* Volume info is always needed because of VolParts */
312 Dmsg1(150, "dir_get_volume_info vol=%s\n", dcr->VolumeName);
313 if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_READ)) {
314 Dmsg2(150, "dir_get_vol_info failed for vol=%s: %s\n",
315 dcr->VolumeName, jcr->errmsg);
316 Jmsg1(jcr, M_WARNING, 0, "Read acquire: %s", jcr->errmsg);
318 dev->set_load(); /* set to load volume */
320 try_autochanger = true; /* permit trying the autochanger again */
322 continue; /* try reading again */
328 Jmsg1(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s for reading.\n"),
335 jcr->sendJobStatus(JS_Running);
336 Jmsg(jcr, M_INFO, 0, _("Ready to read from volume \"%s\" on device %s.\n"),
337 dcr->VolumeName, dev->print_name());
341 /* If failed and not writing plugin close device */
342 if (!ok && dev->num_writers == 0) {
343 generate_plugin_event(jcr, bsdEventDeviceClose, dcr);
345 dcr->clear_reserved();
347 * Normally we are blocked, but in at least one error case above
348 * we are not blocked because we unsuccessfully tried changing
351 if (dev->is_blocked()) {
352 dev->dunblock(DEV_LOCKED);
354 dev->dunlock(); /* dunblock() unlock the device too */
356 Dmsg2(950, "dcr=%p dev=%p\n", dcr, dcr->dev);
357 Dmsg2(950, "MediaType dcr=%s dev=%s\n", dcr->media_type, dev->device->media_type);
358 V(dev->read_acquire_mutex);
363 * Acquire device for writing. We permit multiple writers.
364 * If this is the first one, we read the label.
366 * Returns: NULL if failed for any reason
368 * Note, normally reserve_device_for_append() is called
369 * before this routine.
371 DCR *acquire_device_for_append(DCR *dcr)
373 DEVICE *dev = dcr->dev;
376 bool have_vol = false;
378 init_device_wait_timers(dcr);
380 P(dev->acquire_mutex); /* only one job at a time */
382 Dmsg1(100, "acquire_append device is %s\n", dev->is_tape()?"tape":
383 (dev->is_dvd()?"DVD":"disk"));
387 * With the reservation system, this should not happen
389 if (dev->can_read()) {
390 Jmsg1(jcr, M_FATAL, 0, _("Want to append, but device %s is busy reading.\n"), dev->print_name());
391 Dmsg1(200, "Want to append but device %s is busy reading.\n", dev->print_name());
398 * have_vol defines whether or not mount_next_write_volume should
399 * ask the Director again about what Volume to use.
401 if (dev->can_append() && dcr->is_suitable_volume_mounted() &&
402 strcmp(dcr->VolCatInfo.VolCatStatus, "Recycle") != 0) {
403 Dmsg0(190, "device already in append.\n");
405 * At this point, the correct tape is already mounted, so
406 * we do not need to do mount_next_write_volume(), unless
407 * we need to recycle the tape.
409 if (dev->num_writers == 0) {
410 dev->VolCatInfo = dcr->VolCatInfo; /* structure assignment */
412 have_vol = dcr->is_tape_position_ok();
417 block_device(dev, BST_DOING_ACQUIRE);
419 Dmsg1(190, "jid=%u Do mount_next_write_vol\n", (uint32_t)jcr->JobId);
420 if (!dcr->mount_next_write_volume()) {
421 if (!job_canceled(jcr)) {
422 /* Reduce "noise" -- don't print if job canceled */
423 Jmsg(jcr, M_FATAL, 0, _("Could not ready device %s for append.\n"),
425 Dmsg1(200, "Could not ready device %s for append.\n",
432 Dmsg2(190, "Output pos=%u:%u\n", dcr->dev->file, dcr->dev->block_num);
437 if (generate_plugin_event(jcr, bsdEventDeviceOpen, dcr) != bRC_OK) {
438 Jmsg(jcr, M_FATAL, 0, _("generate_plugin_event(bsdEventDeviceOpen) Failed\n"));
442 dev->num_writers++; /* we are now a writer */
443 if (jcr->NumWriteVolumes == 0) {
444 jcr->NumWriteVolumes = 1;
446 dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */
447 Dmsg4(100, "=== nwriters=%d nres=%d vcatjob=%d dev=%s\n",
448 dev->num_writers, dev->num_reserved(), dev->VolCatInfo.VolCatJobs,
450 dir_update_volume_info(dcr, false, false); /* send Volume info to Director */
454 /* Don't plugin close here, we might have multiple writers */
455 dcr->clear_reserved();
457 V(dev->acquire_mutex);
458 return ok ? dcr : NULL;
462 * This job is done, so release the device. From a Unix standpoint,
463 * the device remains open.
465 * Note, if we were spooling, we may enter with the device blocked.
466 * We unblock at the end, only if it was us who blocked the
470 bool release_device(DCR *dcr)
473 DEVICE *dev = dcr->dev;
476 int was_blocked = BST_NOT_BLOCKED;
479 if (!dev->is_blocked()) {
480 block_device(dev, BST_RELEASING);
482 was_blocked = dev->blocked();
483 dev->set_blocked(BST_RELEASING);
486 Dmsg2(100, "release_device device %s is %s\n", dev->print_name(), dev->is_tape()?"tape":"disk");
488 /* if device is reserved, job never started, so release the reserve here */
489 dcr->clear_reserved();
491 if (dev->can_read()) {
492 VOLUME_CAT_INFO *vol = &dev->VolCatInfo;
493 generate_plugin_event(jcr, bsdEventDeviceClose, dcr);
494 dev->clear_read(); /* clear read bit */
495 Dmsg2(150, "dir_update_vol_info. label=%d Vol=%s\n",
496 dev->is_labeled(), vol->VolCatName);
497 if (dev->is_labeled() && vol->VolCatName[0] != 0) {
498 dir_update_volume_info(dcr, false, false); /* send Volume info to Director */
499 remove_read_volume(jcr, dcr->VolumeName);
502 } else if (dev->num_writers > 0) {
504 * Note if WEOT is set, we are at the end of the tape
505 * and may not be positioned correctly, so the
506 * job_media_record and update_vol_info have already been
507 * done, which means we skip them here.
510 Dmsg1(100, "There are %d writers in release_device\n", dev->num_writers);
511 if (dev->is_labeled()) {
512 Dmsg2(200, "dir_create_jobmedia. Release vol=%s dev=%s\n",
513 dev->getVolCatName(), dev->print_name());
514 if (!dev->at_weot() && !dir_create_jobmedia_record(dcr)) {
515 Jmsg2(jcr, M_FATAL, 0, _("Could not create JobMedia record for Volume=\"%s\" Job=%s\n"),
516 dcr->getVolCatName(), jcr->Job);
518 /* If no more writers, and no errors, and wrote something, write an EOF */
519 if (!dev->num_writers && dev->can_write() && dev->block_num > 0) {
521 write_ansi_ibm_labels(dcr, ANSI_EOF_LABEL, dev->VolHdr.VolumeName);
523 if (!dev->at_weot()) {
524 dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */
525 /* Note! do volume update before close, which zaps VolCatInfo */
526 dir_update_volume_info(dcr, false, false); /* send Volume info to Director */
527 Dmsg2(200, "dir_update_vol_info. Release vol=%s dev=%s\n",
528 dev->getVolCatName(), dev->print_name());
530 if (dev->num_writers == 0) { /* if not being used */
531 volume_unused(dcr); /* we obviously are not using the volume */
537 * If we reach here, it is most likely because the job
538 * has failed, since the device is not in read mode and
539 * there are no writers. It was probably reserved.
543 Dmsg3(100, "%d writers, %d reserve, dev=%s\n", dev->num_writers, dev->num_reserved(),
546 /* If no writers, close if file or !CAP_ALWAYS_OPEN */
547 if (dev->num_writers == 0 && (!dev->is_tape() || !dev->has_cap(CAP_ALWAYSOPEN))) {
548 generate_plugin_event(jcr, bsdEventDeviceClose, dcr);
549 dvd_remove_empty_part(dcr); /* get rid of any empty spool part */
554 /* Fire off Alert command and include any output */
555 if (!job_canceled(jcr) && dcr->device->alert_command) {
559 char line[MAXSTRING];
560 alert = get_pool_memory(PM_FNAME);
561 alert = edit_device_codes(dcr, alert, dcr->device->alert_command, "");
562 /* Wait maximum 5 minutes */
563 bpipe = open_bpipe(alert, 60 * 5, "r");
565 while (fgets(line, sizeof(line), bpipe->rfd)) {
566 Jmsg(jcr, M_ALERT, 0, _("Alert: %s"), line);
568 status = close_bpipe(bpipe);
574 Jmsg(jcr, M_ALERT, 0, _("3997 Bad alert command: %s: ERR=%s.\n"),
575 alert, be.bstrerror(status));
578 Dmsg1(400, "alert status=%d\n", status);
579 free_pool_memory(alert);
581 pthread_cond_broadcast(&dev->wait_next_vol);
582 Dmsg2(100, "JobId=%u broadcast wait_device_release at %s\n",
583 (uint32_t)jcr->JobId, bstrftimes(tbuf, sizeof(tbuf), (utime_t)time(NULL)));
584 pthread_cond_broadcast(&wait_device_release);
588 * If we are the thread that blocked the device, then unblock it
590 if (pthread_equal(dev->no_wait_id, pthread_self())) {
593 /* Otherwise, reset the prior block status and unlock */
594 dev->set_blocked(was_blocked);
599 detach_dcr_from_dev(dcr);
603 Dmsg2(100, "===== Device %s released by JobId=%u\n", dev->print_name(),
604 (uint32_t)jcr->JobId);
609 * Clean up the device for reuse without freeing the memory
611 bool clean_device(DCR *dcr)
614 dcr->keep_dcr = true; /* do not free the dcr */
615 ok = release_device(dcr);
616 dcr->keep_dcr = false;
621 * Create a new Device Control Record and attach
622 * it to the device (if this is a real job).
623 * Note, this has been updated so that it can be called first
624 * without a DEVICE, then a second or third time with a DEVICE,
625 * and each time, it should cleanup and point to the new device.
626 * This should facilitate switching devices.
627 * Note, each dcr must point to the controlling job (jcr). However,
628 * a job can have multiple dcrs, so we must not store in the jcr's
629 * structure as previously. The higher level routine must store
630 * this dcr in the right place
633 DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev)
637 dcr = (DCR *)malloc(sizeof(DCR));
638 memset(dcr, 0, sizeof(DCR));
639 dcr->tid = pthread_self();
641 if ((errstat = pthread_mutex_init(&dcr->m_mutex, NULL)) != 0) {
643 dev->dev_errno = errstat;
644 Mmsg1(dev->errmsg, _("Unable to init mutex: ERR=%s\n"), be.bstrerror(errstat));
645 Jmsg0(jcr, M_ERROR_TERM, 0, dev->errmsg);
648 dcr->jcr = jcr; /* point back to jcr */
649 /* Set device information, possibly change device */
652 free_block(dcr->block);
654 dcr->block = new_block(dev);
656 free_record(dcr->rec);
658 dcr->rec = new_record();
659 if (dcr->attached_to_dev) {
660 detach_dcr_from_dev(dcr);
662 /* Use job spoolsize prior to device spoolsize */
663 if (jcr->spool_size) {
664 dcr->max_job_spool_size = jcr->spool_size;
666 dcr->max_job_spool_size = dev->device->max_job_spool_size;
668 dcr->device = dev->device;
670 attach_dcr_to_dev(dcr);
676 * Search the dcrs list for the given dcr. If it is found,
677 * as it should be, then remove it. Also zap the jcr pointer
678 * to the dcr if it is the same one.
680 * Note, this code will be turned on when we can write to multiple
681 * dcrs at the same time.
684 static void remove_dcr_from_dcrs(DCR *dcr)
690 int num = jcr->dcrs->size();
691 for (i=0; i < num; i++) {
692 ldcr = (DCR *)jcr->dcrs->get(i);
694 jcr->dcrs->remove(i);
695 if (jcr->dcr == dcr) {
704 static void attach_dcr_to_dev(DCR *dcr)
712 if (jcr) Dmsg1(500, "JobId=%u enter attach_dcr_to_dev\n", (uint32_t)jcr->JobId);
713 /* ***FIXME*** return error if dev not initiated */
714 if (!dcr->attached_to_dev && dev->initiated && jcr && jcr->getJobType() != JT_SYSTEM) {
716 dev->attached_dcrs->append(dcr); /* attach dcr to device */
718 dcr->attached_to_dev = true;
719 Dmsg1(500, "JobId=%u attach_dcr_to_dev\n", (uint32_t)jcr->JobId);
725 * DCR is locked before calling this routine
727 static void locked_detach_dcr_from_dev(DCR *dcr)
729 DEVICE *dev = dcr->dev;
730 Dmsg0(500, "Enter detach_dcr_from_dev\n"); /* jcr is NULL in some cases */
732 /* Detach this dcr only if attached */
733 if (dcr->attached_to_dev && dev) {
734 dcr->unreserve_device();
736 dcr->dev->attached_dcrs->remove(dcr); /* detach dcr from device */
737 // remove_dcr_from_dcrs(dcr); /* remove dcr from jcr list */
740 dcr->attached_to_dev = false;
744 static void detach_dcr_from_dev(DCR *dcr)
747 locked_detach_dcr_from_dev(dcr);
752 * Free up all aspects of the given dcr -- i.e. dechain it,
753 * release allocated memory, zap pointers, ...
755 void free_dcr(DCR *dcr)
762 locked_detach_dcr_from_dev(dcr);
765 free_block(dcr->block);
768 free_record(dcr->rec);
770 if (jcr && jcr->dcr == dcr) {
773 if (jcr && jcr->read_dcr == dcr) {
774 jcr->read_dcr = NULL;
777 pthread_mutex_destroy(&dcr->m_mutex);
781 static void set_dcr_from_vol(DCR *dcr, VOL_LIST *vol)
784 * Note, if we want to be able to work from a .bsr file only
785 * for disaster recovery, we must "simulate" reading the catalog
787 bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
788 dcr->setVolCatName(vol->VolumeName);
789 bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type));
790 dcr->VolCatInfo.Slot = vol->Slot;
791 dcr->VolCatInfo.InChanger = vol->Slot > 0;