]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/2.4.x/2.4.1-wrong-volume.patch
Rework patches
[bacula/bacula] / bacula / patches / 2.4.x / 2.4.1-wrong-volume.patch
1
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:
5
6  cd <bacula-source>
7  patch -p0 <2.4.1-wrong-volume.patch
8  ./configure <your-options>
9  make
10  ...
11  make install
12
13   
14  
15 Index: src/stored/mount.c
16 ===================================================================
17 --- src/stored/mount.c  (revision 7422)
18 +++ src/stored/mount.c  (working copy)
19 @@ -20,7 +20,7 @@
20     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21     02110-1301, USA.
22  
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.
28 @@ -113,7 +113,9 @@
29        ask = true;                     /* ask operator to mount tape */
30        do_find = true;                 /* re-find a volume after unload */
31     }
32 -   do_swapping(true /*writing*/);
33 +   do_unload();
34 +   do_swapping(true /*is_writing*/);
35 +   do_load(true /*is_writing*/);
36  
37     if (do_find && !find_a_volume()) {
38        goto no_lock_bail_out;
39 @@ -500,12 +502,30 @@
40     return dir_get_volume_info(this, GET_VOL_INFO_FOR_WRITE);
41  }
42  
43 -void DCR::do_swapping(bool is_writing)
44 +bool DCR::do_unload()
45  {
46     if (dev->must_unload()) {
47        Dmsg1(100, "must_unload release %s\n", dev->print_name());
48        release_volume();
49     }
50 +   return false;
51 +}
52 +
53 +bool DCR::do_load(bool is_writing)
54 +{
55 +   if (dev->must_load()) {
56 +      Dmsg1(100, "Must load %s\n", dev->print_name());
57 +      if (autoload_device(this, is_writing, NULL) > 0) {
58 +         dev->clear_load();
59 +         return true;
60 +      }
61 +      return false;
62 +   }
63 +   return true;
64 +}
65 +
66 +void DCR::do_swapping(bool is_writing)
67 +{
68     /*
69      * See if we are asked to swap the Volume from another device
70      *  if so, unload the other device here, and attach the
71 @@ -522,17 +542,12 @@
72        }
73        if (dev->vol) {
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 */
78        }
79        dev->swap_dev = NULL;
80     }
81 -   if (dev->must_load()) {
82 -      Dmsg1(100, "Must load %s\n", dev->print_name());
83 -      if (autoload_device(this, is_writing, NULL) > 0) {
84 -         dev->clear_load();
85 -      }
86 -   }
87  }
88  
89  
90 Index: src/stored/dev.h
91 ===================================================================
92 --- src/stored/dev.h    (revision 7422)
93 +++ src/stored/dev.h    (working copy)
94 @@ -542,6 +542,8 @@
95     int check_volume_label(bool &ask, bool &autochanger);
96     void release_volume();
97     void do_swapping(bool is_writing);
98 +   bool do_unload();
99 +   bool do_load(bool is_writing);
100     bool is_tape_position_ok();
101  };
102  
103 Index: src/stored/acquire.c
104 ===================================================================
105 --- src/stored/acquire.c        (revision 7422)
106 +++ src/stored/acquire.c        (working copy)
107 @@ -20,7 +20,7 @@
108     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
109     02110-1301, USA.
110  
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.
116 @@ -38,6 +38,7 @@
117  
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);
121  
122  
123  /*********************************************************************
124 @@ -88,15 +89,9 @@
125           jcr->NumReadVolumes, jcr->CurReadVolume);
126        goto get_out;                   /* should not happen */   
127     }
128 -   /*    
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
131 -    */
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);
138 +
139 +   Dmsg2(100, "Want Vol=%s Slot=%d\n", vol->VolumeName, vol->Slot);
140      
141     /*
142      * If the MediaType requested for this volume is not the
143 @@ -174,20 +169,12 @@
144  
145     dev->clear_unload();
146  
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());
152 -      goto get_out;
153 -   }
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());
158     }
159  
160 -
161     init_device_wait_timers(dcr);
162  
163     tape_previously_mounted = dev->can_read() || dev->can_append() ||
164 @@ -217,7 +204,10 @@
165           goto get_out;                /* error return */
166        }
167  
168 -      dcr->do_swapping(false/*is_writing*/);
169 +      dcr->do_unload();
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 */
173  
174        /*
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) {
179        case VOL_OK:
180 +         Dmsg0(50, "Got correct volume.\n");
181           ok = true;
182           dev->VolCatInfo = dcr->VolCatInfo;     /* structure assignment */
183           break;                    /* got it */
184        case VOL_IO_ERROR:
185 +         Dmsg0(50, "IO Error\n");
186           /*
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 @@
190           }
191           goto default_path;
192        case VOL_NAME_ERROR:
193 +         Dmsg0(50, "Vol name error.\n");
194           if (dev->is_volume_to_unload()) {
195              goto default_path;
196           }
197 -//       if (tape_initially_mounted) {
198 -            tape_initially_mounted = false;
199 -//          goto default_path;
200 -//       }
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 */
204 @@ -270,6 +259,7 @@
205        default:
206           Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
207  default_path:
208 +         Dmsg0(50, "default path\n");
209           tape_previously_mounted = true;
210           
211           /*
212 @@ -289,15 +279,6 @@
213                 try_autochanger = false;
214                 continue;              /* try reading volume mounted */
215              }
216 -            /* Try closing and re-opening */
217 -            dev->close();
218 -            if (dev->open(dcr, OPEN_READ_ONLY) >= 0) {
219 -               continue;
220 -            }
221 -            if (!dev->poll) {
222 -               Jmsg3(jcr, M_WARNING, 0, _("Read open device %s Volume \"%s\" failed: ERR=%s\n"),
223 -                     dev->print_name(), dcr->VolumeName, dev->bstrerror());
224 -            }
225           }
226           
227           /* Mount a specific volume and no other */
228 @@ -305,7 +286,7 @@
229           if (!dir_ask_sysop_to_mount_volume(dcr, ST_READ)) {
230              goto get_out;             /* error return */
231           }
232 -         try_autochanger = true;      /* permit using autochanger again */
233 +         try_autochanger = true;      /* permit trying the autochanger again */
234           continue;                    /* try reading again */
235        } /* end switch */
236        break;
237 @@ -693,3 +674,16 @@
238     }
239     free(dcr);
240  }
241 +
242 +static void set_dcr_from_vol(DCR *dcr, VOL_LIST *vol)
243 +{
244 +   /*    
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
247 +    */
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; 
253 +}