]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/askdir.c
- Add copyright to title page of manual so it is clear.
[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\n";
43 static char FileAttributes[] = "UpdCat Job=%s FileAttributes ";
44 static char Job_status[]     = "Status Job=%s JobStatus=%d\n";
45 static char Device_update[] = "DevUpd Job=%s device=%s "
46    "append=%d read=%d num_writers=%d "
47    "open=%d labeled=%d offline=%d "
48    "reserved=%d max_writers=%d "
49    "autoselect=%d autochanger=%d "
50    "poolid=%s "
51    "changer_name=%s media_type=%s volume_name=%s\n";
52
53
54
55 /* Responses received from the Director */
56 static char OK_media[] = "1000 OK VolName=%127s VolJobs=%u VolFiles=%u"
57    " VolBlocks=%u VolBytes=%" lld " VolMounts=%u VolErrors=%u VolWrites=%u"
58    " MaxVolBytes=%" lld " VolCapacityBytes=%" lld " VolStatus=%20s"
59    " Slot=%d MaxVolJobs=%u MaxVolFiles=%u InChanger=%d"
60    " VolReadTime=%" lld " VolWriteTime=%" lld " EndFile=%u EndBlock=%u"
61    " VolParts=%u LabelType=%d";
62
63
64 static char OK_create[] = "1000 OK CreateJobMedia\n";
65
66 /* Send update information about a device to Director */
67 bool dir_update_device(JCR *jcr, DEVICE *dev)
68 {
69    BSOCK *dir = jcr->dir_bsock;
70    POOL_MEM dev_name, VolumeName, MediaType, ChangerName;
71    DEVRES *device = dev->device;
72    bool ok;
73    char ed1[50];
74    
75    pm_strcpy(dev_name, device->hdr.name);
76    bash_spaces(dev_name);
77    if (dev->is_labeled()) {
78       pm_strcpy(VolumeName, dev->VolHdr.VolName);
79    } else {
80       pm_strcpy(VolumeName, "*");
81    }
82    bash_spaces(VolumeName);
83    pm_strcpy(MediaType, device->media_type);
84    bash_spaces(MediaType);
85    if (device->changer_res) {
86       pm_strcpy(ChangerName, device->changer_res->hdr.name);
87       bash_spaces(ChangerName);
88    } else {
89       pm_strcpy(ChangerName, "*");
90    }
91    ok =bnet_fsend(dir, Device_update, 
92       jcr->Job,
93       dev_name.c_str(),
94       dev->can_append()!=0,
95       dev->can_read()!=0, dev->num_writers, 
96       dev->is_open()!=0, dev->is_labeled()!=0,
97       dev->is_offline()!=0, dev->reserved_device, 
98       dev->is_tape()?100000:1,
99       dev->autoselect, 0, 
100       edit_uint64(dev->PoolId, ed1),
101       ChangerName.c_str(), MediaType.c_str(), VolumeName.c_str());
102    Dmsg1(100, ">dird: %s\n", dir->msg);
103    return ok;
104 }
105
106 bool dir_update_changer(JCR *jcr, AUTOCHANGER *changer)
107 {
108    BSOCK *dir = jcr->dir_bsock;
109    POOL_MEM dev_name, MediaType;
110    DEVRES *device;
111    bool ok;
112
113    pm_strcpy(dev_name, changer->hdr.name);
114    bash_spaces(dev_name);
115    device = (DEVRES *)changer->device->first();
116    pm_strcpy(MediaType, device->media_type);
117    bash_spaces(MediaType);
118    /* This is mostly to indicate that we are here */
119    ok = bnet_fsend(dir, Device_update,
120       jcr->Job,
121       dev_name.c_str(),         /* Changer name */
122       0, 0, 0,                  /* append, read, num_writers */
123       0, 0, 0,                  /* is_open, is_labeled, offline */
124       0, 0,                     /* reserved, max_writers */
125       0,                        /* Autoselect */
126       changer->device->size(),  /* Number of devices */
127       "0",                      /* PoolId */
128       "*",                      /* ChangerName */
129       MediaType.c_str(),        /* MediaType */
130       "*");                     /* VolName */
131    Dmsg1(100, ">dird: %s\n", dir->msg);
132    return ok;
133 }
134
135
136 /*
137  * Send current JobStatus to Director
138  */
139 bool dir_send_job_status(JCR *jcr)
140 {
141    return bnet_fsend(jcr->dir_bsock, Job_status, jcr->Job, jcr->JobStatus);
142 }
143
144 /*
145  * Common routine for:
146  *   dir_get_volume_info()
147  * and
148  *   dir_find_next_appendable_volume()
149  *
150  *  Returns: true  on success and vol info in dcr->VolCatInfo
151  *           false on failure
152  */
153 static bool do_get_volume_info(DCR *dcr)
154 {
155     JCR *jcr = dcr->jcr;
156     BSOCK *dir = jcr->dir_bsock;
157     VOLUME_CAT_INFO vol;
158     int n;
159     int InChanger;
160
161     dcr->VolumeName[0] = 0;           /* No volume */
162     if (bnet_recv(dir) <= 0) {
163        Dmsg0(200, "getvolname error bnet_recv\n");
164        Mmsg(jcr->errmsg, _("Network error on bnet_recv in req_vol_info.\n"));
165        return false;
166     }
167     memset(&vol, 0, sizeof(vol));
168     Dmsg1(100, "<dird %s", dir->msg);
169     n = sscanf(dir->msg, OK_media, vol.VolCatName,
170                &vol.VolCatJobs, &vol.VolCatFiles,
171                &vol.VolCatBlocks, &vol.VolCatBytes,
172                &vol.VolCatMounts, &vol.VolCatErrors,
173                &vol.VolCatWrites, &vol.VolCatMaxBytes,
174                &vol.VolCatCapacityBytes, vol.VolCatStatus,
175                &vol.Slot, &vol.VolCatMaxJobs, &vol.VolCatMaxFiles,
176                &InChanger, &vol.VolReadTime, &vol.VolWriteTime,
177                &vol.EndFile, &vol.EndBlock, &vol.VolCatParts,
178                &vol.LabelType);
179     if (n != 21) {
180        Dmsg2(100, "Bad response from Dir fields=%d: %s\n", n, dir->msg);
181        Mmsg(jcr->errmsg, _("Error getting Volume info: %s\n"), dir->msg);
182        return false;
183     }
184     vol.InChanger = InChanger;        /* bool in structure */
185     unbash_spaces(vol.VolCatName);
186     bstrncpy(dcr->VolumeName, vol.VolCatName, sizeof(dcr->VolumeName));
187     memcpy(&dcr->VolCatInfo, &vol, sizeof(dcr->VolCatInfo));
188
189     Dmsg2(300, "do_reqest_vol_info got slot=%d Volume=%s\n",
190           vol.Slot, vol.VolCatName);
191     return true;
192 }
193
194
195 /*
196  * Get Volume info for a specific volume from the Director's Database
197  *
198  * Returns: true  on success   (not Director guarantees that Pool and MediaType
199  *                             are correct and VolStatus==Append or
200  *                             VolStatus==Recycle)
201  *          false on failure
202  *
203  *          Volume information returned in jcr
204  */
205 bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing)
206 {
207     JCR *jcr = dcr->jcr;
208     BSOCK *dir = jcr->dir_bsock;
209
210     bstrncpy(dcr->VolCatInfo.VolCatName, dcr->VolumeName, sizeof(dcr->VolCatInfo.VolCatName));
211     bash_spaces(dcr->VolCatInfo.VolCatName);
212     bnet_fsend(dir, Get_Vol_Info, jcr->Job, dcr->VolCatInfo.VolCatName,
213        writing==GET_VOL_INFO_FOR_WRITE?1:0);
214     Dmsg1(100, ">dird: %s", dir->msg);
215     return do_get_volume_info(dcr);
216 }
217
218
219
220 /*
221  * Get info on the next appendable volume in the Director's database
222  * Returns: true  on success
223  *          false on failure
224  *
225  *          Volume information returned in dcr
226  *
227  */
228 bool dir_find_next_appendable_volume(DCR *dcr)
229 {
230     JCR *jcr = dcr->jcr;
231     BSOCK *dir = jcr->dir_bsock;
232     JCR *njcr;
233
234     Dmsg0(200, "dir_find_next_appendable_volume\n");
235     /*
236      * Try the three oldest or most available volumes.  Note,
237      *   the most available could already be mounted on another
238      *   drive, so we continue looking for a not in use Volume.
239      */
240     for (int vol_index=1;  vol_index < 3; vol_index++) {
241        bash_spaces(dcr->media_type);
242        bash_spaces(dcr->pool_name);
243        bnet_fsend(dir, Find_media, jcr->Job, vol_index, dcr->pool_name, dcr->media_type);
244        unbash_spaces(dcr->media_type);
245        unbash_spaces(dcr->pool_name);
246        Dmsg1(100, ">dird: %s", dir->msg);
247        if (do_get_volume_info(dcr)) {
248           Dmsg2(300, "JobId=%d got possible Vol=%s\n", jcr->JobId, dcr->VolumeName);
249           bool found = false;
250           /*
251            * Walk through all jobs and see if the volume is
252            *  already mounted. If so, try a different one.
253            * This would be better done by walking through
254            *  all the devices.
255            */
256           lock_jcr_chain();
257           foreach_jcr(njcr) {
258              if (jcr == njcr) {
259                 free_locked_jcr(njcr);
260                 continue;             /* us */
261              }
262              Dmsg2(300, "Compare to JobId=%d using Vol=%s\n", njcr->JobId, njcr->dcr->VolumeName);
263              if (njcr->dcr && strcmp(dcr->VolumeName, njcr->dcr->VolumeName) == 0) {
264                 found = true;
265                 Dmsg1(400, "Vol in use by JobId=%u\n", njcr->JobId);
266                 free_locked_jcr(njcr);
267                 break;
268              }
269              free_locked_jcr(njcr);
270           }
271           unlock_jcr_chain();
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     Dmsg1(100, ">dird: %s", dir->msg);
364    if (bnet_recv(dir) <= 0) {
365       Dmsg0(190, "create_jobmedia error bnet_recv\n");
366       Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: ERR=%s\n"),
367            bnet_strerror(dir));
368       return false;
369    }
370    Dmsg1(100, "<dir: %s", dir->msg);
371    if (strcmp(dir->msg, OK_create) != 0) {
372       Dmsg1(130, "Bad response from Dir: %s\n", dir->msg);
373       Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: %s\n"), dir->msg);
374       return false;
375    }
376    return true;
377 }
378
379
380 /*
381  * Update File Attribute data
382  */
383 bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec)
384 {
385    JCR *jcr = dcr->jcr;
386    BSOCK *dir = jcr->dir_bsock;
387    ser_declare;
388
389 #ifdef NO_ATTRIBUTES_TEST
390    return true;
391 #endif
392
393    dir->msglen = sprintf(dir->msg, FileAttributes, jcr->Job);
394    dir->msg = check_pool_memory_size(dir->msg, dir->msglen +
395                 sizeof(DEV_RECORD) + rec->data_len);
396    ser_begin(dir->msg + dir->msglen, 0);
397    ser_uint32(rec->VolSessionId);
398    ser_uint32(rec->VolSessionTime);
399    ser_int32(rec->FileIndex);
400    ser_int32(rec->Stream);
401    ser_uint32(rec->data_len);
402    ser_bytes(rec->data, rec->data_len);
403    dir->msglen = ser_length(dir->msg);
404    Dmsg1(1800, ">dird: %s\n", dir->msg);    /* Attributes */
405    return bnet_send(dir);
406 }
407
408
409 /*
410  *   Request the sysop to create an appendable volume
411  *
412  *   Entered with device blocked.
413  *   Leaves with device blocked.
414  *
415  *   Returns: true  on success (operator issues a mount command)
416  *            false on failure
417  *              Note, must create dev->errmsg on error return.
418  *
419  *    On success, dcr->VolumeName and dcr->VolCatInfo contain
420  *      information on suggested volume, but this may not be the
421  *      same as what is actually mounted.
422  *
423  *    When we return with success, the correct tape may or may not
424  *      actually be mounted. The calling routine must read it and
425  *      verify the label.
426  */
427 bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr)
428 {
429    int stat = 0, jstat;
430    bool unmounted;
431    bool first = true;
432    DEVICE *dev = dcr->dev;
433    JCR *jcr = dcr->jcr;
434
435    Dmsg0(400, "enter dir_ask_sysop_to_create_appendable_volume\n");
436    ASSERT(dev->dev_blocked);
437    for ( ;; ) {
438       if (job_canceled(jcr)) {
439          Mmsg(dev->errmsg,
440               _("Job %s canceled while waiting for mount on Storage Device \"%s\".\n"),
441               jcr->Job, dev->print_name());
442          Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
443          return false;
444       }
445       /* First pass, we *know* there are no appendable volumes, so no need to call */
446       if (!first && dir_find_next_appendable_volume(dcr)) { /* get suggested volume */
447          unmounted = (dev->dev_blocked == BST_UNMOUNTED) ||
448                      (dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP);
449          /*
450           * If we have a valid volume name and we are not
451           *   removable media, return now, or if we have a
452           *   Slot for an autochanger, otherwise wait
453           *   for the operator to mount the media.
454           */
455          if (!unmounted && ((dcr->VolumeName[0] && !dev_cap(dev, CAP_REM) &&
456                 dev_cap(dev, CAP_LABEL)) ||
457                  (dcr->VolumeName[0] && dcr->VolCatInfo.Slot))) {
458             Dmsg0(400, "Return 1 from mount without wait.\n");
459             return true;
460          }
461          jstat = JS_WaitMount;
462          if (!dev->poll) {
463             Jmsg(jcr, M_MOUNT, 0, _(
464 "Please mount Volume \"%s\" on Storage Device %s for Job %s\n"
465 "Use \"mount\" command to release Job.\n"),
466               dcr->VolumeName, dev->print_name(), jcr->Job);
467             Dmsg3(400, "Mount %s on %s for Job %s\n",
468                   dcr->VolumeName, dcr->dev_name, jcr->Job);
469          }
470       } else {
471          jstat = JS_WaitMedia;
472          if (!dev->poll) {
473             Jmsg(jcr, M_MOUNT, 0, _(
474 "Job %s waiting. Cannot find any appendable volumes.\n"
475 "Please use the \"label\"  command to create a new Volume for:\n"
476 "    Storage:      %s\n"
477 "    Media type:   %s\n"
478 "    Pool:         %s\n"),
479                jcr->Job,
480                dev->print_name(),
481                dcr->media_type,
482                dcr->pool_name);
483          }
484       }
485       first = false;
486
487       jcr->JobStatus = jstat;
488       dir_send_job_status(jcr);
489
490       stat = wait_for_sysop(dcr);
491       if (dev->poll) {
492          Dmsg1(400, "Poll timeout in create append vol on device %s\n", dev->print_name());
493          continue;
494       }
495
496       if (stat == ETIMEDOUT) {
497          if (!double_dev_wait_time(dev)) {
498             Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device %s for Job %s\n"),
499                dev->print_name(), jcr->Job);
500             Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
501             Dmsg1(400, "Gave up waiting on device %s\n", dev->print_name());
502             return false;             /* exceeded maximum waits */
503          }
504          continue;
505       }
506       if (stat == EINVAL) {
507          berrno be;
508          Mmsg2(dev->errmsg, _("pthread error in mount_next_volume stat=%d ERR=%s\n"),
509                stat, be.strerror(stat));
510          Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
511          return false;
512       }
513       if (stat != 0) {
514          berrno be;
515          Jmsg(jcr, M_WARNING, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat,
516             be.strerror(stat));
517       }
518       Dmsg1(400, "Someone woke me for device %s\n", dev->print_name());
519
520       /* If no VolumeName, and cannot get one, try again */
521       if (dcr->VolumeName[0] == 0 && !job_canceled(jcr) &&
522           !dir_find_next_appendable_volume(dcr)) {
523          Jmsg(jcr, M_MOUNT, 0, _(
524 "Someone woke me up, but I cannot find any appendable\n"
525 "volumes for Job=%s.\n"), jcr->Job);
526          /* Restart wait counters after user interaction */
527          init_dev_wait_timers(dev);
528          continue;
529       }
530       unmounted = (dev->dev_blocked == BST_UNMOUNTED) ||
531                   (dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP);
532       if (unmounted) {
533          continue;                    /* continue to wait */
534       }
535
536       /*
537        * Device mounted, we have a volume, break and return
538        */
539       break;
540    }
541    set_jcr_job_status(jcr, JS_Running);
542    dir_send_job_status(jcr);
543    Dmsg0(400, "leave dir_ask_sysop_to_mount_create_appendable_volume\n");
544    return true;
545 }
546
547 /*
548  *   Request to mount specific Volume
549  *
550  *   Entered with device blocked and dcr->VolumeName is desired
551  *      volume.
552  *   Leaves with device blocked.
553  *
554  *   Returns: true  on success (operator issues a mount command)
555  *            false on failure
556  *                  Note, must create dev->errmsg on error return.
557  *
558  */
559 bool dir_ask_sysop_to_mount_volume(DCR *dcr)
560 {
561    int stat = 0;
562    const char *msg;
563    DEVICE *dev = dcr->dev;
564    JCR *jcr = dcr->jcr;
565
566    Dmsg0(400, "enter dir_ask_sysop_to_mount_volume\n");
567    if (!dcr->VolumeName[0]) {
568       Mmsg0(dev->errmsg, _("Cannot request another volume: no volume name given.\n"));
569       return false;
570    }
571    ASSERT(dev->dev_blocked);
572    for ( ;; ) {
573       if (job_canceled(jcr)) {
574          Mmsg(dev->errmsg, _("Job %s canceled while waiting for mount on Storage Device %s.\n"),
575               jcr->Job, dev->print_name());
576          return false;
577       }
578
579       if (!dev->poll) {
580          msg = _("Please mount");
581          Jmsg(jcr, M_MOUNT, 0, _("%s Volume \"%s\" on Storage Device %s for Job %s\n"),
582               msg, dcr->VolumeName, dev->print_name(), jcr->Job);
583          Dmsg3(400, "Mount \"%s\" on device \"%s\" for Job %s\n",
584                dcr->VolumeName, dcr->dev_name, jcr->Job);
585       }
586
587       jcr->JobStatus = JS_WaitMount;
588       dir_send_job_status(jcr);
589
590       stat = wait_for_sysop(dcr);    ;     /* wait on device */
591       if (dev->poll) {
592          Dmsg1(400, "Poll timeout in mount vol on device %s\n", dev->print_name());
593          Dmsg1(400, "Blocked=%s\n", edit_blocked_reason(dev));
594          return true;
595       }
596
597       if (stat == ETIMEDOUT) {
598          if (!double_dev_wait_time(dev)) {
599             Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device %s for Job %s\n"),
600                dev->print_name(), jcr->Job);
601             Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
602             Dmsg1(400, "Gave up waiting on device %s\n", dev->print_name());
603             return false;             /* exceeded maximum waits */
604          }
605          continue;
606       }
607       if (stat == EINVAL) {
608          berrno be;
609          Mmsg2(dev->errmsg, _("pthread error in mount_volume stat=%d ERR=%s\n"),
610                stat, be.strerror(stat));
611          Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg);
612          return false;
613       }
614       if (stat != 0) {
615          berrno be;
616          Jmsg(jcr, M_FATAL, 0, _("pthread error in mount_next_volume stat=%d: ERR=%s\n"), stat,
617             be.strerror(stat));
618       }
619       Dmsg1(400, "Someone woke me for device %s\n", dev->print_name());
620       break;
621    }
622    set_jcr_job_status(jcr, JS_Running);
623    dir_send_job_status(jcr);
624    Dmsg0(400, "leave dir_ask_sysop_to_mount_volume\n");
625    return true;
626 }