2 This patch corrects a problem of manual mounting of volumes,
3 where Bacula will accept an incorrect volume for restore.
4 Apply it to version 2.4.1 with:
7 patch -p0 <2.4.1-wrong-volume.patch
8 ./configure <your-options>
15 Index: src/stored/mount.c
16 ===================================================================
17 --- src/stored/mount.c (revision 7422)
18 +++ src/stored/mount.c (working copy)
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 - Bacula® is a registered trademark of John Walker.
24 + Bacula® is a registered trademark of Kern Sibbald.
25 The licensor of Bacula is the Free Software Foundation Europe
26 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
27 Switzerland, email:ftf@fsfeurope.org.
29 ask = true; /* ask operator to mount tape */
30 do_find = true; /* re-find a volume after unload */
32 - do_swapping(true /*writing*/);
34 + do_swapping(true /*is_writing*/);
35 + do_load(true /*is_writing*/);
37 if (do_find && !find_a_volume()) {
38 goto no_lock_bail_out;
40 return dir_get_volume_info(this, GET_VOL_INFO_FOR_WRITE);
43 -void DCR::do_swapping(bool is_writing)
44 +bool DCR::do_unload()
46 if (dev->must_unload()) {
47 Dmsg1(100, "must_unload release %s\n", dev->print_name());
53 +bool DCR::do_load(bool is_writing)
55 + if (dev->must_load()) {
56 + Dmsg1(100, "Must load %s\n", dev->print_name());
57 + if (autoload_device(this, is_writing, NULL) > 0) {
66 +void DCR::do_swapping(bool is_writing)
69 * See if we are asked to swap the Volume from another device
70 * if so, unload the other device here, and attach the
74 dev->vol->clear_swapping();
75 + Dmsg1(100, "=== set in_use vol=%s\n", dev->vol->vol_name);
76 dev->vol->set_in_use();
77 dev->VolHdr.VolumeName[0] = 0; /* don't yet have right Volume */
81 - if (dev->must_load()) {
82 - Dmsg1(100, "Must load %s\n", dev->print_name());
83 - if (autoload_device(this, is_writing, NULL) > 0) {
90 Index: src/stored/dev.h
91 ===================================================================
92 --- src/stored/dev.h (revision 7422)
93 +++ src/stored/dev.h (working copy)
95 int check_volume_label(bool &ask, bool &autochanger);
96 void release_volume();
97 void do_swapping(bool is_writing);
99 + bool do_load(bool is_writing);
100 bool is_tape_position_ok();
103 Index: src/stored/acquire.c
104 ===================================================================
105 --- src/stored/acquire.c (revision 7422)
106 +++ src/stored/acquire.c (working copy)
108 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
111 - Bacula® is a registered trademark of John Walker.
112 + Bacula® is a registered trademark of Kern Sibbald.
113 The licensor of Bacula is the Free Software Foundation Europe
114 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
115 Switzerland, email:ftf@fsfeurope.org.
118 /* Forward referenced functions */
119 static void attach_dcr_to_dev(DCR *dcr);
120 +static void set_dcr_from_vol(DCR *dcr, VOL_LIST *vol);
123 /*********************************************************************
125 jcr->NumReadVolumes, jcr->CurReadVolume);
126 goto get_out; /* should not happen */
129 - * Note, if we want to be able to work from a .bsr file only
130 - * for disaster recovery, we must "simulate" reading the catalog
132 - bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
133 - bstrncpy(dcr->VolCatInfo.VolCatName, vol->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
134 - bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type));
135 - dcr->VolCatInfo.Slot = vol->Slot;
136 - dcr->VolCatInfo.InChanger = vol->Slot > 0;
137 + set_dcr_from_vol(dcr, vol);
139 + Dmsg2(100, "Want Vol=%s Slot=%d\n", vol->VolumeName, vol->Slot);
142 * If the MediaType requested for this volume is not the
143 @@ -174,20 +169,12 @@
147 - if (reserve_volume(dcr, dcr->VolumeName) == NULL) {
148 - Dmsg2(100, "Could not reserve volume %s on %s\n", dcr->VolumeName,
149 - dcr->dev->print_name());
150 - Jmsg2(jcr, M_FATAL, 0, _("Could not reserve volume %s on %s\n"), dcr->VolumeName,
151 - dcr->dev->print_name());
154 if (dev->vol && dev->vol->is_swapping()) {
155 dev->vol->set_slot(vol->Slot);
156 Dmsg3(100, "swapping: slot=%d Vol=%s dev=%s\n", dev->vol->get_slot(),
157 dev->vol->vol_name, dev->print_name());
161 init_device_wait_timers(dcr);
163 tape_previously_mounted = dev->can_read() || dev->can_append() ||
165 goto get_out; /* error return */
168 - dcr->do_swapping(false/*is_writing*/);
170 + dcr->do_swapping(false/*!is_writing*/);
171 + dcr->do_load(false /*!is_writing*/);
172 + set_dcr_from_vol(dcr, vol); /* refresh dcr with desired volume info */
175 * This code ensures that the device is ready for
176 @@ -239,10 +229,12 @@
177 vol_label_status = read_dev_volume_label(dcr);
178 switch (vol_label_status) {
180 + Dmsg0(50, "Got correct volume.\n");
182 dev->VolCatInfo = dcr->VolCatInfo; /* structure assignment */
185 + Dmsg0(50, "IO Error\n");
187 * Send error message generated by read_dev_volume_label()
188 * only we really had a tape mounted. This supresses superfluous
189 @@ -253,13 +245,10 @@
193 + Dmsg0(50, "Vol name error.\n");
194 if (dev->is_volume_to_unload()) {
197 -// if (tape_initially_mounted) {
198 - tape_initially_mounted = false;
199 -// goto default_path;
201 dev->set_unload(); /* force unload of unwanted tape */
202 if (!unload_autochanger(dcr, -1)) {
203 /* at least free the device so we can re-open with correct volume */
206 Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
208 + Dmsg0(50, "default path\n");
209 tape_previously_mounted = true;
213 try_autochanger = false;
214 continue; /* try reading volume mounted */
216 - /* Try closing and re-opening */
218 - if (dev->open(dcr, OPEN_READ_ONLY) >= 0) {
222 - Jmsg3(jcr, M_WARNING, 0, _("Read open device %s Volume \"%s\" failed: ERR=%s\n"),
223 - dev->print_name(), dcr->VolumeName, dev->bstrerror());
227 /* Mount a specific volume and no other */
229 if (!dir_ask_sysop_to_mount_volume(dcr, ST_READ)) {
230 goto get_out; /* error return */
232 - try_autochanger = true; /* permit using autochanger again */
233 + try_autochanger = true; /* permit trying the autochanger again */
234 continue; /* try reading again */
242 +static void set_dcr_from_vol(DCR *dcr, VOL_LIST *vol)
245 + * Note, if we want to be able to work from a .bsr file only
246 + * for disaster recovery, we must "simulate" reading the catalog
248 + bstrncpy(dcr->VolumeName, vol->VolumeName, sizeof(dcr->VolumeName));
249 + bstrncpy(dcr->VolCatInfo.VolCatName, vol->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
250 + bstrncpy(dcr->media_type, vol->MediaType, sizeof(dcr->media_type));
251 + dcr->VolCatInfo.Slot = vol->Slot;
252 + dcr->VolCatInfo.InChanger = vol->Slot > 0;