]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/askdir.c
- Add more documentation to mtx-changer.in
[bacula/bacula] / bacula / src / stored / askdir.c
1 /*
2  *  Subroutines to handle Catalog reqests sent to the Director
3  *   Reqests/commands from the Director are handled in dircmd.c
4  *
5  *   Kern Sibbald, December 2000
6  *
7  *   Version $Id$
8  */
9 /*
10    Copyright (C) 2000-2005 Kern Sibbald
11
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License as
14    published by the Free Software Foundation; either version 2 of
15    the License, or (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20    General Public License for more details.
21
22    You should have received a copy of the GNU General Public
23    License along with this program; if not, write to the Free
24    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25    MA 02111-1307, USA.
26
27  */
28
29 #include "bacula.h"                   /* pull in global headers */
30 #include "stored.h"                   /* pull in Storage Deamon headers */
31
32 /* Requests sent to the Director */
33 static char Find_media[]   = "CatReq Job=%s FindMedia=%d pool_name=%s media_type=%s\n";
34 static char Get_Vol_Info[] = "CatReq Job=%s GetVolInfo VolName=%s write=%d\n";
35 static char Update_media[] = "CatReq Job=%s UpdateMedia VolName=%s"
36    " VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%s VolMounts=%u"
37    " VolErrors=%u VolWrites=%u MaxVolBytes=%s EndTime=%d VolStatus=%s"
38    " Slot=%d relabel=%d InChanger=%d VolReadTime=%s VolWriteTime=%s"
39    " VolParts=%u\n";
40 static char Create_job_media[] = "CatReq Job=%s CreateJobMedia"
41    " FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u"
42    " StartBlock=%u EndBlock=%u Copy=%d Strip=%d\n";
43 static char FileAttributes[] = "UpdCat Job=%s FileAttributes ";
44 static char Job_status[]     = "Status Job=%s JobStatus=%d\n";
45
46
47
48 /* Responses received from the Director */
49 static char OK_media[] = "1000 OK VolName=%127s VolJobs=%u VolFiles=%u"
50    " VolBlocks=%u VolBytes=%" lld " VolMounts=%u VolErrors=%u VolWrites=%u"
51    " MaxVolBytes=%" lld " VolCapacityBytes=%" lld " VolStatus=%20s"
52    " Slot=%d MaxVolJobs=%u MaxVolFiles=%u InChanger=%d"
53    " VolReadTime=%" lld " VolWriteTime=%" lld " EndFile=%u EndBlock=%u"
54    " VolParts=%u LabelType=%d";
55
56
57 static char OK_create[] = "1000 OK CreateJobMedia\n";
58
59 #ifdef needed
60
61 static char Device_update[] = "DevUpd Job=%s device=%s "
62    "append=%d read=%d num_writers=%d "
63    "open=%d labeled=%d offline=%d "
64    "reserved=%d max_writers=%d "
65    "autoselect=%d autochanger=%d "
66    "changer_name=%s media_type=%s volume_name=%s\n";
67
68
69 /* Send update information about a device to Director */
70 bool dir_update_device(JCR *jcr, DEVICE *dev)
71 {
72    BSOCK *dir = jcr->dir_bsock;
73    POOL_MEM dev_name, VolumeName, MediaType, ChangerName;
74    DEVRES *device = dev->device;
75    bool ok;
76    
77    pm_strcpy(dev_name, device->hdr.name);
78    bash_spaces(dev_name);
79    if (dev->is_labeled()) {
80       pm_strcpy(VolumeName, dev->VolHdr.VolName);
81    } else {
82       pm_strcpy(VolumeName, "*");
83    }
84    bash_spaces(VolumeName);
85    pm_strcpy(MediaType, device->media_type);
86    bash_spaces(MediaType);
87    if (device->changer_res) {
88       pm_strcpy(ChangerName, device->changer_res->hdr.name);
89       bash_spaces(ChangerName);
90    } else {
91       pm_strcpy(ChangerName, "*");
92    }
93    ok =bnet_fsend(dir, Device_update, 
94       jcr->Job,
95       dev_name.c_str(),
96       dev->can_append()!=0,
97       dev->can_read()!=0, dev->num_writers, 
98       dev->is_open()!=0, dev->is_labeled()!=0,
99       dev->is_offline()!=0, dev->reserved_device, 
100       dev->is_tape()?100000:1,
101       dev->autoselect, 0, 
102       ChangerName.c_str(), MediaType.c_str(), VolumeName.c_str());
103    Dmsg1(100, ">dird: %s\n", dir->msg);
104    return ok;
105 }
106
107 bool dir_update_changer(JCR *jcr, AUTOCHANGER *changer)
108 {
109    BSOCK *dir = jcr->dir_bsock;
110    POOL_MEM dev_name, MediaType;
111    DEVRES *device;
112    bool ok;
113
114    pm_strcpy(dev_name, changer->hdr.name);
115    bash_spaces(dev_name);
116    device = (DEVRES *)changer->device->first();
117    pm_strcpy(MediaType, device->media_type);
118    bash_spaces(MediaType);
119    /* This is mostly to indicate that we are here */
120    ok = bnet_fsend(dir, Device_update,
121       jcr->Job,
122       dev_name.c_str(),         /* Changer name */
123       0, 0, 0,                  /* append, read, num_writers */
124       0, 0, 0,                  /* is_open, is_labeled, offline */
125       0, 0,                     /* reserved, max_writers */
126       0,                        /* Autoselect */
127       changer->device->size(),  /* Number of devices */
128       "0",                      /* PoolId */
129       "*",                      /* ChangerName */
130       MediaType.c_str(),        /* MediaType */
131       "*");                     /* VolName */
132    Dmsg1(100, ">dird: %s\n", dir->msg);
133    return ok;
134 }
135 #endif
136
137
138 /*
139  * Send current JobStatus to Director
140  */
141 bool dir_send_job_status(JCR *jcr)
142 {
143    return bnet_fsend(jcr->dir_bsock, Job_status, jcr->Job, jcr->JobStatus);
144 }
145
146 /*
147  * Common routine for:
148  *   dir_get_volume_info()
149  * and
150  *   dir_find_next_appendable_volume()
151  *
152  *  Returns: true  on success and vol info in dcr->VolCatInfo
153  *           false on failure
154  */
155 static bool do_get_volume_info(DCR *dcr)
156 {
157     JCR *jcr = dcr->jcr;
158     BSOCK *dir = jcr->dir_bsock;
159     VOLUME_CAT_INFO vol;
160     int n;
161     int InChanger;
162
163     dcr->VolumeName[0] = 0;           /* No volume */
164     if (bnet_recv(dir) <= 0) {
165        Dmsg0(200, "getvolname error bnet_recv\n");
166        Mmsg(jcr->errmsg, _("Network error on bnet_recv in req_vol_info.\n"));
167        return false;
168     }
169     memset(&vol, 0, sizeof(vol));
170     Dmsg1(100, "<dird %s", dir->msg);
171     n = sscanf(dir->msg, OK_media, vol.VolCatName,
172                &vol.VolCatJobs, &vol.VolCatFiles,
173                &vol.VolCatBlocks, &vol.VolCatBytes,
174                &vol.VolCatMounts, &vol.VolCatErrors,
175                &vol.VolCatWrites, &vol.VolCatMaxBytes,
176                &vol.VolCatCapacityBytes, vol.VolCatStatus,
177                &vol.Slot, &vol.VolCatMaxJobs, &vol.VolCatMaxFiles,
178                &InChanger, &vol.VolReadTime, &vol.VolWriteTime,
179                &vol.EndFile, &vol.EndBlock, &vol.VolCatParts,
180                &vol.LabelType);
181     if (n != 21) {
182        Dmsg2(100, "Bad response from Dir fields=%d: %s\n", n, dir->msg);
183        Mmsg(jcr->errmsg, _("Error getting Volume info: %s\n"), dir->msg);
184        return false;
185     }
186     vol.InChanger = InChanger;        /* bool in structure */
187     unbash_spaces(vol.VolCatName);
188     bstrncpy(dcr->VolumeName, vol.VolCatName, sizeof(dcr->VolumeName));
189     memcpy(&dcr->VolCatInfo, &vol, sizeof(dcr->VolCatInfo));
190
191     Dmsg2(300, "do_reqest_vol_info got slot=%d Volume=%s\n",
192           vol.Slot, vol.VolCatName);
193     return true;
194 }
195
196
197 /*
198  * Get Volume info for a specific volume from the Director's Database
199  *
200  * Returns: true  on success   (not Director guarantees that Pool and MediaType
201  *                             are correct and VolStatus==Append or
202  *                             VolStatus==Recycle)
203  *          false on failure
204  *
205  *          Volume information returned in dcr->VolCatInfo
206  */
207 bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing)
208 {
209     JCR *jcr = dcr->jcr;
210     BSOCK *dir = jcr->dir_bsock;
211
212     bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
213     bash_spaces(dcr->VolCatInfo.VolCatName);
214     bnet_fsend(dir, Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName,
215        writing==GET_VOL_INFO_FOR_WRITE?1:0);
216     Dmsg1(100, ">dird: %s", dir->msg);
217     return do_get_volume_info(dcr);
218 }
219
220
221
222 /*
223  * Get info on the next appendable volume in the Director's database
224  * Returns: true  on success
225  *          false on failure
226  *
227  *          Volume information returned in dcr
228  *
229  */
230 bool dir_find_next_appendable_volume(DCR *dcr)
231 {
232     JCR *jcr = dcr->jcr;
233     BSOCK *dir = jcr->dir_bsock;
234     JCR *njcr;
235
236     Dmsg0(200, "dir_find_next_appendable_volume\n");
237     /*
238      * Try the three oldest or most available volumes.  Note,
239      *   the most available could already be mounted on another
240      *   drive, so we continue looking for a not in use Volume.
241      */
242     for (int vol_index=1;  vol_index < 3; vol_index++) {
243        bash_spaces(dcr->media_type);
244        bash_spaces(dcr->pool_name);
245        bnet_fsend(dir, Find_media, jcr->Job, vol_index, dcr->pool_name, dcr->media_type);
246        unbash_spaces(dcr->media_type);
247        unbash_spaces(dcr->pool_name);
248        Dmsg1(100, ">dird: %s", dir->msg);
249        if (do_get_volume_info(dcr)) {
250           Dmsg2(300, "JobId=%d got possible Vol=%s\n", jcr->JobId, dcr->VolumeName);
251           bool found = false;
252           /*
253            * Walk through all jobs and see if the volume is
254            *  already mounted. If so, try a different one.
255            * This would be better done by walking through
256            *  all the devices.
257            */
258           foreach_jcr(njcr) {
259              if (jcr == njcr) {
260                 free_jcr(njcr);
261                 continue;             /* us */
262              }
263              Dmsg2(300, "Compare to JobId=%d using Vol=%s\n", njcr->JobId, njcr->dcr->VolumeName);
264              if (njcr->dcr && strcmp(dcr->VolumeName, njcr->dcr->VolumeName) == 0) {
265                 found = true;
266                 Dmsg1(400, "Vol in use by JobId=%u\n", njcr->JobId);
267                 free_jcr(njcr);
268                 break;
269              }
270              free_jcr(njcr);
271           }
272           if (!found) {
273              Dmsg0(400, "dir_find_next_appendable_volume return true\n");
274              return true;             /* Got good Volume */
275           }
276        } else {
277           Dmsg0(200, "No volume info, return false\n");
278           return false;
279        }
280     }
281     Dmsg0(400, "dir_find_next_appendable_volume return true\n");
282     return true;
283 }
284
285
286 /*
287  * After writing a Volume, send the updated statistics
288  * back to the director. The information comes from the
289  * dev record.
290  */
291 bool dir_update_volume_info(DCR *dcr, bool label)
292 {
293    JCR *jcr = dcr->jcr;
294    BSOCK *dir = jcr->dir_bsock;
295    DEVICE *dev = dcr->dev;
296    time_t LastWritten = time(NULL);
297    char ed1[50], ed2[50], ed3[50], ed4[50];
298    VOLUME_CAT_INFO *vol = &dev->VolCatInfo;
299    int InChanger;
300    POOL_MEM VolumeName;
301
302    if (vol->VolCatName[0] == 0) {
303       Jmsg0(jcr, M_FATAL, 0, _("NULL Volume name. This shouldn't happen!!!\n"));
304       Pmsg0(000, "NULL Volume name. This shouldn't happen!!!\n");
305       return false;
306    }
307    if (dev->can_read()) {
308       Jmsg0(jcr, M_FATAL, 0, _("Attempt to update_volume_info in read mode!!!\n"));
309       Pmsg0(000, "Attempt to update_volume_info in read mode!!!\n");
310       return false;
311    }
312
313    Dmsg1(300, "Update cat VolFiles=%d\n", dev->file);
314    /* Just labeled or relabeled the tape */
315    if (label) {
316       bstrncpy(vol->VolCatStatus, "Append", sizeof(vol->VolCatStatus));
317       vol->VolCatBytes = 1;           /* indicates tape labeled */
318    }
319    pm_strcpy(VolumeName, vol->VolCatName);
320    bash_spaces(VolumeName);
321    InChanger = vol->InChanger;
322    bnet_fsend(dir, Update_media, jcr->Job,
323       VolumeName.c_str(), vol->VolCatJobs, vol->VolCatFiles,
324       vol->VolCatBlocks, edit_uint64(vol->VolCatBytes, ed1),
325       vol->VolCatMounts, vol->VolCatErrors,
326       vol->VolCatWrites, edit_uint64(vol->VolCatMaxBytes, ed2),
327       LastWritten, vol->VolCatStatus, vol->Slot, label,
328       InChanger,                      /* bool in structure */
329       edit_uint64(vol->VolReadTime, ed3),
330       edit_uint64(vol->VolWriteTime, ed4),
331       vol->VolCatParts);
332     Dmsg1(100, ">dird: %s", dir->msg);
333
334    if (!do_get_volume_info(dcr)) {
335       Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg);
336       Pmsg2(000, "Didn't get vol info vol=%s: ERR=%s", 
337          vol->VolCatName, jcr->errmsg);
338       return false;
339    }
340    Dmsg1(420, "get_volume_info(): %s", dir->msg);
341    /* Update dev Volume info in case something changed (e.g. expired) */
342    memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
343    return true;
344 }
345
346 /*
347  * After writing a Volume, create the JobMedia record.
348  */
349 bool dir_create_jobmedia_record(DCR *dcr)
350 {
351    JCR *jcr = dcr->jcr;
352    BSOCK *dir = jcr->dir_bsock;
353
354    if (!dcr->WroteVol) {
355       return true;                    /* nothing written to tape */
356    }
357
358    dcr->WroteVol = false;
359    bnet_fsend(dir, Create_job_media, jcr->Job,
360       dcr->VolFirstIndex, dcr->VolLastIndex,
361       dcr->StartFile, dcr->EndFile,
362       dcr->StartBlock, dcr->EndBlock, 
363       dcr->Copy, dcr->Stripe);
364     Dmsg1(100, ">dird: %s", dir->msg);
365    if (bnet_recv(dir) <= 0) {
366       Dmsg0(190, "create_jobmedia error bnet_recv\n");
367       Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: ERR=%s\n"),
368            bnet_strerror(dir));
369       return false;
370    }
371    Dmsg1(100, "<dir: %s", dir->msg);
372    if (strcmp(dir->msg, OK_create) != 0) {
373       Dmsg1(130, "Bad response from Dir: %s\n", dir->msg);
374       Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: %s\n"), dir->msg);
375       return false;
376    }
377    return true;
378 }
379
380
381 /*
382  * Update File Attribute data
383  */
384 bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec)
385 {
386    JCR *jcr = dcr->jcr;
387    BSOCK *dir = jcr->dir_bsock;
388    ser_declare;
389
390 #ifdef NO_ATTRIBUTES_TEST
391    return true;
392 #endif
393
394    dir->msglen = sprintf(dir->msg, FileAttributes, jcr->Job);
395    dir->msg = check_pool_memory_size(dir->msg, dir->msglen +
396                 sizeof(DEV_RECORD) + rec->data_len);
397    ser_begin(dir->msg + dir->msglen, 0);
398    ser_uint32(rec->VolSessionId);
399    ser_uint32(rec->VolSessionTime);
400    ser_int32(rec->FileIndex);
401    ser_int32(rec->Stream);
402    ser_uint32(rec->data_len);
403    ser_bytes(rec->data, rec->data_len);
404    dir->msglen = ser_length(dir->msg);
405    Dmsg1(1800, ">dird: %s\n", dir->msg);    /* Attributes */
406    return bnet_send(dir);
407 }
408
409
410 /*
411  *   Request the sysop to create an appendable volume
412  *
413  *   Entered with device blocked.
414  *   Leaves with device blocked.
415  *
416  *   Returns: true  on success (operator issues a mount command)
417  *            false on failure
418  *              Note, must create dev->errmsg on error return.
419  *
420  *    On success, dcr->VolumeName and dcr->VolCatInfo contain
421  *      information on suggested volume, but this may not be the
422  *      same as what is actually mounted.
423  *
424  *    When we return with success, the correct tape may or may not
425  *      actually be mounted. The calling routine must read it and
426  *      verify the label.
427  */
428 bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr)
429 {
430    int stat = 0, jstat;
431    bool unmounted;
432    bool first = true;
433    DEVICE *dev = dcr->dev;
434    JCR *jcr = dcr->jcr;
435
436    Dmsg0(400, "enter dir_ask_sysop_to_create_appendable_volume\n");
437    ASSERT(dev->dev_blocked);
438    for ( ;; ) {
439       if (job_canceled(jcr)) {
440          Mmsg(dev->errmsg,
441               _("Job %s canceled while waiting for mount on Storage Device \"%s\".\n"),
442               jcr->Job, dev->print_name());
443          Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
444          return false;
445       }
446       /* First pass, we *know* there are no appendable volumes, so no need to call */
447       if (!first && dir_find_next_appendable_volume(dcr)) { /* get suggested volume */
448          unmounted = (dev->dev_blocked == BST_UNMOUNTED) ||
449                      (dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP);
450          /*
451           * If we have a valid volume name and we are not
452           *   removable media, return now, or if we have a
453           *   Slot for an autochanger, otherwise wait
454           *   for the operator to mount the media.
455           */
456          if (!unmounted && ((dcr->VolumeName[0] && !dev_cap(dev, CAP_REM) &&
457                 dev_cap(dev, CAP_LABEL)) ||
458                  (dcr->VolumeName[0] && dcr->VolCatInfo.Slot))) {
459             Dmsg0(400, "Return 1 from mount without wait.\n");
460             return true;
461          }
462          jstat = JS_WaitMount;
463          if (!dev->poll) {
464             Jmsg(jcr, M_MOUNT, 0, _(
465 "Please mount Volume \"%s\" on Storage Device %s for Job %s\n"
466 "Use \"mount\" command to release Job.\n"),
467               dcr->VolumeName, dev->print_name(), jcr->Job);
468             Dmsg3(400, "Mount %s on %s for Job %s\n",
469                   dcr->VolumeName, dcr->dev_name, jcr->Job);
470          }
471       } else {
472          jstat = JS_WaitMedia;
473          if (!dev->poll) {
474             Jmsg(jcr, M_MOUNT, 0, _(
475 "Job %s waiting. Cannot find any appendable volumes.\n"
476 "Please use the \"label\"  command to create a new Volume for:\n"
477 "    Storage:      %s\n"
478 "    Media type:   %s\n"
479 "    Pool:         %s\n"),
480                jcr->Job,
481                dev->print_name(),
482                dcr->media_type,
483                dcr->pool_name);
484          }
485       }
486       first = false;
487
488       jcr->JobStatus = jstat;
489       dir_send_job_status(jcr);
490
491       stat = wait_for_sysop(dcr);
492       if (dev->poll) {
493          Dmsg1(400, "Poll timeout in create append vol on device %s\n", dev->print_name());
494          continue;
495       }
496
497       if (stat == ETIMEDOUT) {
498          if (!double_dev_wait_time(dev)) {
499             Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device %s for Job %s\n"),
500                dev->print_name(), jcr->Job);
501             Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
502             Dmsg1(400, "Gave up waiting on device %s\n", dev->print_name());
503             return false;             /* exceeded maximum waits */
504          }
505          continue;
506       }
507       if (stat == EINVAL) {
508          berrno be;
509          Mmsg2(dev->errmsg, _("pthread error in mount_next_volume stat=%d ERR=%s\n"),
510                stat, be.strerror(stat));
511          Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
512          return false;
513       }
514       if (stat != 0) {
515          berrno be;
516          Jmsg(jcr, M_WARNING, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat,
517             be.strerror(stat));
518       }
519       Dmsg1(400, "Someone woke me for device %s\n", dev->print_name());
520
521       /* If no VolumeName, and cannot get one, try again */
522       if (dcr->VolumeName[0] == 0 && !job_canceled(jcr) &&
523           !dir_find_next_appendable_volume(dcr)) {
524          Jmsg(jcr, M_MOUNT, 0, _(
525 "Someone woke me up, but I cannot find any appendable\n"
526 "volumes for Job=%s.\n"), jcr->Job);
527          /* Restart wait counters after user interaction */
528          init_device_wait_timers(dcr);
529          continue;
530       }
531       unmounted = (dev->dev_blocked == BST_UNMOUNTED) ||
532                   (dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP);
533       if (unmounted) {
534          continue;                    /* continue to wait */
535       }
536
537       /*
538        * Device mounted, we have a volume, break and return
539        */
540       break;
541    }
542    set_jcr_job_status(jcr, JS_Running);
543    dir_send_job_status(jcr);
544    Dmsg0(400, "leave dir_ask_sysop_to_mount_create_appendable_volume\n");
545    return true;
546 }
547
548 /*
549  *   Request to mount specific Volume
550  *
551  *   Entered with device blocked and dcr->VolumeName is desired
552  *      volume.
553  *   Leaves with device blocked.
554  *
555  *   Returns: true  on success (operator issues a mount command)
556  *            false on failure
557  *                  Note, must create dev->errmsg on error return.
558  *
559  */
560 bool dir_ask_sysop_to_mount_volume(DCR *dcr)
561 {
562    int stat = 0;
563    const char *msg;
564    DEVICE *dev = dcr->dev;
565    JCR *jcr = dcr->jcr;
566
567    Dmsg0(400, "enter dir_ask_sysop_to_mount_volume\n");
568    if (!dcr->VolumeName[0]) {
569       Mmsg0(dev->errmsg, _("Cannot request another volume: no volume name given.\n"));
570       return false;
571    }
572    ASSERT(dev->dev_blocked);
573    for ( ;; ) {
574       if (job_canceled(jcr)) {
575          Mmsg(dev->errmsg, _("Job %s canceled while waiting for mount on Storage Device %s.\n"),
576               jcr->Job, dev->print_name());
577          return false;
578       }
579
580       if (!dev->poll) {
581          msg = _("Please mount");
582          Jmsg(jcr, M_MOUNT, 0, _("%s Volume \"%s\" on Storage Device %s for Job %s\n"),
583               msg, dcr->VolumeName, dev->print_name(), jcr->Job);
584          Dmsg3(400, "Mount \"%s\" on device \"%s\" for Job %s\n",
585                dcr->VolumeName, dcr->dev_name, jcr->Job);
586       }
587
588       jcr->JobStatus = JS_WaitMount;
589       dir_send_job_status(jcr);
590
591       stat = wait_for_sysop(dcr);    ;     /* wait on device */
592       if (dev->poll) {
593          Dmsg1(400, "Poll timeout in mount vol on device %s\n", dev->print_name());
594          Dmsg1(400, "Blocked=%s\n", edit_blocked_reason(dev));
595          return true;
596       }
597
598       if (stat == ETIMEDOUT) {
599          if (!double_dev_wait_time(dev)) {
600             Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device %s for Job %s\n"),
601                dev->print_name(), jcr->Job);
602             Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
603             Dmsg1(400, "Gave up waiting on device %s\n", dev->print_name());
604             return false;             /* exceeded maximum waits */
605          }
606          continue;
607       }
608       if (stat == EINVAL) {
609          berrno be;
610          Mmsg2(dev->errmsg, _("pthread error in mount_volume stat=%d ERR=%s\n"),
611                stat, be.strerror(stat));
612          Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
613          return false;
614       }
615       if (stat != 0) {
616          berrno be;
617          Jmsg(jcr, M_FATAL, 0, _("pthread error in mount_next_volume stat=%d: ERR=%s\n"), stat,
618             be.strerror(stat));
619       }
620       Dmsg1(400, "Someone woke me for device %s\n", dev->print_name());
621       break;
622    }
623    set_jcr_job_status(jcr, JS_Running);
624    dir_send_job_status(jcr);
625    Dmsg0(400, "leave dir_ask_sysop_to_mount_volume\n");
626    return true;
627 }