2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2001-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * This file handles accepting Director Commands
23 * Most Director commands are handled here, with the
24 * exception of the Job command command and subsequent
25 * subcommands that are handled
28 * N.B. in this file, in general we must use P(dev->mutex) rather
29 * than dev->rLock() so that we can examine the blocked
30 * state rather than blocking ourselves because a Job
31 * thread has the device blocked. In some "safe" cases,
32 * we can do things to a blocked device. CAREFUL!!!!
34 * File daemon commands are handled in fdcmd.c
36 * Written by Kern Sibbald, May MMI
43 /* Exported variables */
45 /* Imported variables */
46 extern BSOCK *filed_chan;
47 extern struct s_last_job last_job;
48 extern bool init_done;
50 /* Static variables */
51 static char derrmsg[] = "3900 Invalid command:";
52 static char OKsetdebug[] = "3000 OK setdebug=%ld trace=%ld options=%s tags=%s\n";
53 static char invalid_cmd[] = "3997 Invalid command for a Director with Monitor directive enabled.\n";
54 static char OK_bootstrap[] = "3000 OK bootstrap\n";
55 static char ERROR_bootstrap[] = "3904 Error bootstrap\n";
56 static char OKclient[] = "3000 OK client command\n";
58 /* Imported functions */
59 extern void terminate_child();
60 extern bool job_cmd(JCR *jcr);
61 extern bool use_cmd(JCR *jcr);
62 extern bool run_cmd(JCR *jcr);
63 extern bool status_cmd(JCR *sjcr);
64 extern bool qstatus_cmd(JCR *jcr);
65 //extern bool query_cmd(JCR *jcr);
67 /* Forward referenced functions */
68 static bool client_cmd(JCR *jcr);
69 static bool storage_cmd(JCR *jcr);
70 static bool label_cmd(JCR *jcr);
71 static bool die_cmd(JCR *jcr);
72 static bool relabel_cmd(JCR *jcr);
73 static bool readlabel_cmd(JCR *jcr);
74 static bool release_cmd(JCR *jcr);
75 static bool setdebug_cmd(JCR *jcr);
76 static bool cancel_cmd(JCR *cjcr);
77 static bool mount_cmd(JCR *jcr);
78 static bool unmount_cmd(JCR *jcr);
79 static bool enable_cmd(JCR *jcr);
80 static bool disable_cmd(JCR *jcr);
81 //static bool action_on_purge_cmd(JCR *jcr);
82 static bool bootstrap_cmd(JCR *jcr);
83 static bool changer_cmd(JCR *sjcr);
84 static bool do_label(JCR *jcr, int relabel);
85 static DCR *find_device(JCR *jcr, POOL_MEM &dev_name,
86 POOLMEM *media_type, int drive);
87 static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, int Slot);
88 static void label_volume_if_ok(DCR *dcr, char *oldname,
89 char *newname, char *poolname,
90 int Slot, int relabel);
91 static bool try_autoload_device(JCR *jcr, DCR *dcr, int slot, const char *VolName);
92 static void send_dir_busy_message(BSOCK *dir, DEVICE *dev);
94 /* Responses send to Director for storage command */
95 static char BADcmd[] = "2902 Bad %s\n";
96 static char OKstore[] = "2000 OK storage\n";
98 /* Commands received from director that need scanning */
99 static char storaddr[] = "storage address=%s port=%d ssl=%d Job=%127s Authentication=%127s";
103 bool (*func)(JCR *jcr);
104 bool monitoraccess; /* set if monitors can access this cmd */
108 * The following are the recognized commands from the Director.
110 static struct s_cmds cmds[] = {
111 {"JobId=", job_cmd, 0}, /* start Job */
112 {"autochanger", changer_cmd, 0},
113 {"bootstrap", bootstrap_cmd, 0},
114 {"cancel", cancel_cmd, 0},
115 {"client", client_cmd, 0}, /* client address */
116 {".die", die_cmd, 0},
117 {"label", label_cmd, 0}, /* label a tape */
118 {"mount", mount_cmd, 0},
119 {"enable", enable_cmd, 0},
120 {"disable", disable_cmd, 0},
121 {"readlabel", readlabel_cmd, 0},
122 {"release", release_cmd, 0},
123 {"relabel", relabel_cmd, 0}, /* relabel a tape */
124 {"setdebug=", setdebug_cmd, 0}, /* set debug level */
125 {"status", status_cmd, 1},
126 {".status", qstatus_cmd, 1},
127 {"stop", cancel_cmd, 0},
128 {"storage", storage_cmd, 0}, /* get SD addr from Dir */
129 {"unmount", unmount_cmd, 0},
130 {"use storage=", use_cmd, 0},
132 // {"query", query_cmd, 0},
133 {NULL, NULL} /* list terminator */
138 * Connection request. We accept connections either from the
139 * Director or a Client (File daemon).
141 * Note, we are running as a separate thread of the Storage daemon.
142 * and it is because a Director has made a connection with
143 * us on the "Message" channel.
145 * Basic tasks done here:
146 * - Create a JCR record
147 * - If it was from the FD, call handle_filed_connection()
148 * - Authenticate the Director
149 * - We wait for a command
150 * - We execute the command
151 * - We continue or exit depending on the return status
153 void *handle_connection_request(void *arg)
155 BSOCK *bs = (BSOCK *)arg;
162 if (bs->recv() <= 0) {
163 Jmsg1(NULL, M_ERROR, 0, _("Connection request from %s failed.\n"), bs->who());
164 bmicrosleep(5, 0); /* make user wait 5 seconds */
169 /* Check for client connection */
170 if (is_client_connection(bs)) {
171 handle_client_connection(bs);
176 * This is a connection from the Director, so setup a JCR
178 Dmsg1(050, "Got a DIR connection at %s\n", bstrftimes(tbuf, sizeof(tbuf),
179 (utime_t)time(NULL)));
180 jcr = new_jcr(sizeof(JCR), stored_free_jcr); /* create Job Control Record */
181 jcr->dir_bsock = bs; /* save Director bsock */
182 jcr->dir_bsock->set_jcr(jcr);
183 jcr->dcrs = New(alist(10, not_owned_by_alist));
184 create_jobmedia_queue(jcr);
185 /* Initialize FD start condition variable */
186 int errstat = pthread_cond_init(&jcr->job_start_wait, NULL);
189 Jmsg1(jcr, M_FATAL, 0, _("Unable to init job cond variable: ERR=%s\n"), be.bstrerror(errstat));
193 Dmsg0(1000, "stored in start_job\n");
196 * Validate then authenticate the Director
198 if (!validate_dir_hello(jcr)) {
201 if (!authenticate_director(jcr)) {
202 Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate Director\n"));
205 Dmsg0(90, "Message channel init completed.\n");
207 for (quit=false; !quit;) {
209 if ((bnet_stat = bs->recv()) <= 0) {
210 break; /* connection terminated */
212 Dmsg1(199, "<dird: %s\n", bs->msg);
213 /* Ensure that device initialization is complete */
218 for (i=0; cmds[i].cmd; i++) {
219 if (strncmp(cmds[i].cmd, bs->msg, strlen(cmds[i].cmd)) == 0) {
220 if ((!cmds[i].monitoraccess) && (jcr->director->monitor)) {
221 Dmsg1(100, "Command \"%s\" is invalid.\n", cmds[i].cmd);
222 bs->fsend(invalid_cmd);
223 bs->signal(BNET_EOD);
226 Dmsg1(200, "Do command: %s\n", cmds[i].cmd);
227 if (!cmds[i].func(jcr)) { /* do command */
228 quit = true; /* error, get out */
229 Dmsg1(190, "Command %s requests quit\n", cmds[i].cmd);
231 found = true; /* indicate command found */
235 if (!found) { /* command not found */
237 Mmsg(err_msg, "%s %s\n", derrmsg, bs->msg);
238 bs->fsend(err_msg.c_str());
243 generate_daemon_event(jcr, "JobEnd");
244 generate_plugin_event(jcr, bsdEventJobEnd);
245 flush_jobmedia_queue(jcr);
246 dequeue_messages(jcr); /* send any queued messages */
247 bs->signal(BNET_TERMINATE);
248 free_plugins(jcr); /* release instantiated plugins */
255 * Force SD to die, and hopefully dump itself. Turned on only
256 * in development version.
258 static bool die_cmd(JCR *jcr)
263 BSOCK *dir = jcr->dir_bsock;
264 pthread_mutex_t m=PTHREAD_MUTEX_INITIALIZER;
266 if (strstr(dir->msg, "deadlock")) {
267 Pmsg0(000, "I have been requested to deadlock ...\n");
272 Pmsg1(000, "I have been requested to die ... (%s)\n", dir->msg);
273 a = djcr->JobId; /* ref NULL pointer */
280 * Get address of client from Director
281 * This initiates SD Calls Client.
282 * We attempt to connect to the client (an FD or SD) and
285 static bool client_cmd(JCR *jcr)
287 int client_port; /* client port */
288 int enable_ssl; /* enable ssl */
289 BSOCK *dir = jcr->dir_bsock;
290 BSOCK *cl = new_bsock(); /* client bsock */
292 Dmsg1(100, "ClientCmd: %s", dir->msg);
293 jcr->sd_calls_client = true;
294 if (sscanf(dir->msg, "client address=%s port=%d ssl=%d", &jcr->client_addr, &client_port,
296 pm_strcpy(jcr->errmsg, dir->msg);
297 Jmsg(jcr, M_FATAL, 0, _("Bad client command: %s"), jcr->errmsg);
298 Dmsg1(050, "Bad client command: %s", jcr->errmsg);
302 Dmsg3(110, "Connect to client: %s:%d ssl=%d\n", jcr->client_addr, client_port,
304 /* Open command communications with Client */
305 /* Try to connect for 1 hour at 10 second intervals */
306 if (!cl->connect(jcr, 10, (int)me->ClientConnectTimeout, me->heartbeat_interval,
307 _("Client daemon"), jcr->client_addr, NULL, client_port, 1)) {
308 /* destroy() OK because cl is local */
310 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Client daemon: %s:%d\n"),
311 jcr->client_addr, client_port);
312 Dmsg2(100, "Failed to connect to Client daemon: %s:%d\n",
313 jcr->client_addr, client_port);
316 Dmsg0(110, "SD connection OK to Client.\n");
318 jcr->file_bsock = cl;
319 jcr->file_bsock->set_jcr(jcr);
320 if (!send_hello_client(jcr, jcr->Job)) {
324 /* Send OK to Director */
325 return dir->fsend(OKclient);
328 jcr->setJobStatus(JS_ErrorTerminated);
329 dir->fsend("3902 Bad %s cmd\n", "client");
334 * Get address of storage daemon from Director
336 static bool storage_cmd(JCR *jcr)
338 int stored_port; /* storage daemon port */
339 int enable_ssl; /* enable ssl to sd */
340 char sd_auth_key[200];
341 BSOCK *dir = jcr->dir_bsock;
342 BSOCK *sd = new_bsock(); /* storage daemon bsock */
343 char Job[MAX_NAME_LENGTH];
345 Dmsg1(050, "StorageCmd: %s", dir->msg);
346 if (sscanf(dir->msg, storaddr, &jcr->stored_addr, &stored_port,
347 &enable_ssl, Job, sd_auth_key) != 5) {
348 pm_strcpy(jcr->errmsg, dir->msg);
349 Jmsg(jcr, M_FATAL, 0, _("Bad storage command: %s"), jcr->errmsg);
350 Pmsg1(010, "Bad storage command: %s", jcr->errmsg);
355 if (jcr->sd_auth_key) {
356 bfree_and_null(jcr->sd_auth_key);
357 jcr->sd_auth_key = bstrdup(sd_auth_key);
359 if (stored_port != 0) {
360 Dmsg2(050, "sd_calls=%d sd_client=%d\n", jcr->sd_calls_client,
362 jcr->sd_calls_client = false; /* We are doing the connecting */
363 Dmsg3(050, "Connect to storage and wait: %s:%d ssl=%d\n", jcr->stored_addr, stored_port,
365 /* Open command communications with Storage daemon */
366 /* Try to connect for 1 hour at 10 second intervals */
367 if (!sd->connect(jcr, 10, (int)me->ClientConnectTimeout, me->heartbeat_interval,
368 _("Storage daemon"), jcr->stored_addr, NULL, stored_port, 1)) {
369 /* destroy() OK because sd is local */
371 Jmsg(jcr, M_FATAL, 0, _("Failed to connect to Storage daemon: %s:%d\n"),
372 jcr->stored_addr, stored_port);
373 Dmsg2(010, "Failed to connect to Storage daemon: %s:%d\n",
374 jcr->stored_addr, stored_port);
378 Dmsg0(050, "Connection OK to SD.\n");
380 jcr->store_bsock = sd;
381 } else { /* The storage daemon called us */
382 jcr->sd_calls_client = true;
383 /* We should already have a storage connection! */
384 if (jcr->file_bsock && jcr->store_bsock == NULL) {
385 jcr->store_bsock = jcr->file_bsock;
387 if (jcr->store_bsock == NULL) {
388 Jmsg0(jcr, M_FATAL, 0, _("In storage_cmd port==0, no prior Storage connection.\n"));
389 Pmsg0(010, "In storage_cmd port==0, no prior Storage connection.\n");
394 if (!send_hello_sd(jcr, Job)) {
398 if (!authenticate_storagedaemon(jcr)) {
402 * We are a client so we read from the socket we just
403 * opened as if we were a FD, so set file_bsock and
404 * clear the store_bsock.
406 jcr->file_bsock = jcr->store_bsock;
407 jcr->store_bsock = NULL;
408 jcr->authenticated = true; /* Dir authentication is sufficient */
409 Dmsg1(050, "=== Storage_cmd authenticated Job=%s with SD.\n", Job);
411 /* Send OK to Director */
412 return dir->fsend(OKstore);
415 Dmsg0(100, "Send storage command failed.\n");
416 dir->fsend(BADcmd, "storage");
422 * Set debug level as requested by the Director
425 static bool setdebug_cmd(JCR *jcr)
427 BSOCK *dir = jcr->dir_bsock;
428 int32_t trace_flag, lvl, hangup, blowup;
429 int64_t level, level_tags = 0;
432 *tags = *options = 0;
434 Dmsg1(10, "setdebug_cmd: %s", dir->msg);
436 if (sscanf(dir->msg, "setdebug=%ld trace=%ld hangup=%ld blowup=%ld options=%55s tags=%511s",
437 &lvl, &trace_flag, &hangup, &blowup, options, tags) != 6)
439 if (sscanf(dir->msg, "setdebug=%ld trace=%ld", &lvl, &trace_flag) != 2 || lvl < 0) {
440 dir->fsend(_("3991 Bad setdebug command: %s\n"), dir->msg);
445 set_trace(trace_flag);
448 set_debug_flags(options);
449 if (!debug_parse_tags(tags, &level_tags)) {
455 debug_level_tags = level_tags;
457 return dir->fsend(OKsetdebug, lvl, trace_flag, options, tags);
463 * Be careful, we switch to using the job's JCR! So, using
464 * BSOCKs on that jcr can have two threads in the same code.
466 static bool cancel_cmd(JCR *cjcr)
468 BSOCK *dir = cjcr->dir_bsock;
470 char Job[MAX_NAME_LENGTH];
475 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
476 status = JS_Canceled;
478 } else if (sscanf(dir->msg, "stop Job=%127s", Job) == 1) {
479 status = JS_Incomplete;
482 dir->fsend(_("3903 Error scanning cancel command.\n"));
485 if (!(jcr=get_jcr_by_full_name(Job))) {
486 dir->fsend(_("3904 Job %s not found.\n"), Job);
488 oldStatus = jcr->JobStatus;
489 jcr->setJobStatus(status);
490 Dmsg2(800, "Cancel JobId=%d %p\n", jcr->JobId, jcr);
491 if (!jcr->authenticated && oldStatus == JS_WaitFD) {
492 pthread_cond_signal(&jcr->job_start_wait); /* wake waiting thread */
494 if (jcr->file_bsock) {
495 jcr->file_bsock->set_terminated();
496 jcr->file_bsock->set_timed_out();
497 Dmsg2(800, "Term bsock jid=%d %p\n", jcr->JobId, jcr);
499 /* Still waiting for FD to connect, release it */
500 pthread_cond_signal(&jcr->job_start_wait); /* wake waiting job */
501 Dmsg2(800, "Signal FD connect jid=%d %p\n", jcr->JobId, jcr);
503 /* If thread waiting on mount, wake him */
504 if (jcr->dcr && jcr->dcr->dev && jcr->dcr->dev->waiting_for_mount()) {
505 pthread_cond_broadcast(&jcr->dcr->dev->wait_next_vol);
506 Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId);
507 pthread_cond_broadcast(&wait_device_release);
509 if (jcr->read_dcr && jcr->read_dcr->dev && jcr->read_dcr->dev->waiting_for_mount()) {
510 pthread_cond_broadcast(&jcr->read_dcr->dev->wait_next_vol);
511 Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)jcr->JobId);
512 pthread_cond_broadcast(&wait_device_release);
514 jcr->my_thread_send_signal(TIMEOUT_SIGNAL);
515 dir->fsend(_("3000 JobId=%ld Job=\"%s\" marked to be %s.\n"),
516 jcr->JobId, jcr->Job, reason);
521 dir->signal(BNET_EOD);
529 static bool label_cmd(JCR *jcr)
531 return do_label(jcr, 0);
534 static bool relabel_cmd(JCR *jcr)
536 return do_label(jcr, 1);
539 static bool do_label(JCR *jcr, int relabel)
541 POOLMEM *newname, *oldname, *poolname, *mtype;
543 BSOCK *dir = jcr->dir_bsock;
549 newname = get_memory(dir->msglen+1);
550 oldname = get_memory(dir->msglen+1);
551 poolname = get_memory(dir->msglen+1);
552 mtype = get_memory(dir->msglen+1);
554 if (sscanf(dir->msg, "relabel %127s OldName=%127s NewName=%127s PoolName=%127s "
555 "MediaType=%127s Slot=%d drive=%d",
556 dev_name.c_str(), oldname, newname, poolname, mtype,
557 &slot, &drive) == 7) {
562 if (sscanf(dir->msg, "label %127s VolumeName=%127s PoolName=%127s "
563 "MediaType=%127s Slot=%d drive=%d",
564 dev_name.c_str(), newname, poolname, mtype, &slot, &drive) == 6) {
569 unbash_spaces(newname);
570 unbash_spaces(oldname);
571 unbash_spaces(poolname);
572 unbash_spaces(mtype);
573 dcr = find_device(jcr, dev_name, mtype, drive);
578 dev->Lock(); /* Use P to avoid indefinite block */
580 if (chk_dbglvl(DT_VOLUME)) {
581 Dmsg0(0, "Waiting few seconds to force a bug...\n");
585 max_jobs = dev->max_concurrent_jobs;
586 dev->max_concurrent_jobs = 1;
587 bstrncpy(dcr->VolumeName, newname, sizeof(dcr->VolumeName));
588 if (dcr->can_i_write_volume()) {
589 if (reserve_volume(dcr, newname) == NULL) {
592 Dmsg1(000, "Reserved volume \"%s\"\n", newname);
597 Dmsg2(000, "Reserve error on volume \"%s\": ERR=%s\n", newname, jcr->errmsg);
598 dir->fsend(_("3908 Error reserving volume: %s\n"), jcr->errmsg);
599 dev->max_concurrent_jobs = max_jobs;
603 if (!dev->is_open() && !dev->is_busy()) {
604 Dmsg1(400, "Can %slabel. Device is not open\n", relabel?"re":"");
605 label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel);
607 /* Under certain "safe" conditions, we can steal the lock */
608 } else if (dev->can_steal_lock()) {
609 Dmsg0(400, "Can relabel. can_steal_lock\n");
610 label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel);
611 } else if (dev->is_busy() || dev->is_blocked()) {
612 send_dir_busy_message(dir, dev);
613 } else { /* device not being used */
614 Dmsg0(400, "Can relabel. device not used\n");
615 label_volume_if_ok(dcr, oldname, newname, poolname, slot, relabel);
617 dev->max_concurrent_jobs = max_jobs;
619 free_volume(dcr->dev);
621 dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), dev_name.c_str());
624 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
625 pm_strcpy(jcr->errmsg, dir->msg);
626 dir->fsend(_("3903 Error scanning label command: %s\n"), jcr->errmsg);
632 free_memory(oldname);
633 free_memory(newname);
634 free_memory(poolname);
636 dir->signal(BNET_EOD);
641 * Read the tape label and determine if we can safely
642 * label the tape (not a Bacula volume), then label it.
644 * Enter with the mutex set
646 static void label_volume_if_ok(DCR *dcr, char *oldname,
647 char *newname, char *poolname,
648 int slot, int relabel)
650 BSOCK *dir = dcr->jcr->dir_bsock;
652 DEVICE *dev = dcr->dev;
655 const char *volname = (relabel == 1) ? oldname : newname;
657 steal_device_lock(dev, &hold, BST_WRITING_LABEL);
658 Dmsg1(100, "Stole device %s lock, writing label.\n", dev->print_name());
660 Dmsg0(90, "try_autoload_device - looking for volume_info\n");
661 if (!try_autoload_device(dcr->jcr, dcr, slot, volname)) {
662 goto bail_out; /* error */
665 /* Ensure that the device is open -- autoload_device() closes it */
666 if (dev->is_tape()) {
667 mode = OPEN_READ_WRITE;
669 mode = CREATE_READ_WRITE;
673 dev->truncating = true; /* let open() know we will truncate it */
675 /* Set old volume name for open if relabeling */
676 dcr->setVolCatName(volname);
677 if (!dev->open(dcr, mode)) {
678 dir->fsend(_("3910 Unable to open device \"%s\": ERR=%s\n"),
679 dev->print_name(), dev->bstrerror());
683 /* See what we have for a Volume */
684 label_status = read_dev_volume_label(dcr);
686 /* Set new volume name */
687 dcr->setVolCatName(newname);
688 switch(label_status) {
690 case VOL_VERSION_ERROR:
691 case VOL_LABEL_ERROR:
695 "3920 Cannot label Volume because it is already labeled: \"%s\"\n"),
696 dev->VolHdr.VolumeName);
700 /* Relabel request. If oldname matches, continue */
701 if (strcmp(oldname, dev->VolHdr.VolumeName) != 0) {
702 dir->fsend(_("3921 Wrong volume mounted.\n"));
705 if (dev->label_type != B_BACULA_LABEL) {
706 dir->fsend(_("3922 Cannot relabel an ANSI/IBM labeled Volume.\n"));
709 /* Fall through wanted! */
712 if (!write_new_volume_label_to_dev(dcr, newname, poolname,
713 relabel, true /* write dvd now */)) {
714 dir->fsend(_("3912 Failed to label Volume: ERR=%s\n"), dcr->jcr->errmsg);
717 bstrncpy(dcr->VolumeName, newname, sizeof(dcr->VolumeName));
718 /* The following 3000 OK label. string is scanned in ua_label.c */
720 if (dev->dev_type == B_FILE_DEV) {
721 type = dev->dev_type;
725 dir->fsend("3000 OK label. VolBytes=%lld VolABytes=%lld VolType=%d Volume=\"%s\" Device=%s\n",
726 dev->VolCatInfo.VolCatBytes, dev->VolCatInfo.VolCatAdataBytes,
727 type, newname, dev->print_name());
730 dir->fsend(_("3912 Failed to label Volume: ERR=%s\n"), dcr->jcr->errmsg);
733 dir->fsend(_("3914 Failed to label Volume (no media): ERR=%s\n"), dcr->jcr->errmsg);
736 dir->fsend(_("3913 Cannot label Volume. "
737 "Unknown status %d from read_volume_label()\n"), label_status);
742 if (dev->is_open() && !dev->has_cap(CAP_ALWAYSOPEN)) {
745 if (!dev->is_open()) {
748 volume_unused(dcr); /* no longer using volume */
749 give_back_device_lock(dev, &hold);
755 * Read the tape label
757 * Enter with the mutex set
759 static bool read_label(DCR *dcr)
763 BSOCK *dir = jcr->dir_bsock;
765 DEVICE *dev = dcr->dev;
767 steal_device_lock(dev, &hold, BST_DOING_ACQUIRE);
769 dcr->VolumeName[0] = 0;
770 dev->clear_labeled(); /* force read of label */
771 switch (read_dev_volume_label(dcr)) {
773 dir->fsend(_("3001 Mounted Volume: %s\n"), dev->VolHdr.VolumeName);
777 dir->fsend(_("3902 Cannot mount Volume on Storage Device \"%s\" because:\n%s"),
778 dev->print_name(), jcr->errmsg);
783 give_back_device_lock(dev, &hold);
788 * Searches for device by name, and if found, creates a dcr and
791 static DCR *find_device(JCR *jcr, POOL_MEM &devname,
792 POOLMEM *media_type, int drive)
795 AUTOCHANGER *changer;
799 unbash_spaces(devname);
800 foreach_res(device, R_DEVICE) {
801 /* Find resource, and make sure we were able to open it */
802 if (strcmp(device->hdr.name, devname.c_str()) == 0 &&
803 (!media_type || strcmp(device->media_type, media_type) ==0)) {
805 device->dev = init_dev(jcr, device);
808 Jmsg(jcr, M_WARNING, 0, _("\n"
809 " Device \"%s\" requested by DIR could not be opened or does not exist.\n"),
813 Dmsg1(20, "Found device %s\n", device->hdr.name);
819 foreach_res(changer, R_AUTOCHANGER) {
820 /* Find resource, and make sure we were able to open it */
821 if (strcmp(devname.c_str(), changer->hdr.name) == 0) {
822 /* Try each device in this AutoChanger */
823 foreach_alist(device, changer->device) {
824 Dmsg1(100, "Try changer device %s\n", device->hdr.name);
826 device->dev = init_dev(jcr, device);
829 Dmsg1(100, "Device %s could not be opened. Skipped\n", devname.c_str());
830 Jmsg(jcr, M_WARNING, 0, _("\n"
831 " Device \"%s\" in changer \"%s\" requested by DIR could not be opened or does not exist.\n"),
832 device->hdr.name, devname.c_str());
835 if (!device->dev->autoselect) {
836 Dmsg1(100, "Device %s not autoselect skipped.\n", devname.c_str());
837 continue; /* device is not available */
838 } else if (!device->dev->enabled) {
839 Dmsg1(100, "Device %s disabled skipped.\n", devname.c_str());
840 continue; /* device disabled */
842 if ((drive < 0 || drive == (int)device->dev->drive_index) &&
843 (!media_type || strcmp(device->media_type, media_type) ==0)) {
844 Dmsg1(20, "Found changer device %s\n", device->hdr.name);
848 Dmsg3(100, "Device %s drive wrong: want=%d got=%d skipping\n",
849 devname.c_str(), drive, (int)device->dev->drive_index);
851 break; /* we found it but could not open a device */
857 Dmsg1(100, "Found device %s\n", device->hdr.name);
858 dcr = new_dcr(jcr, NULL, device->dev);
859 dcr->device = device;
865 * Mount command from Director
867 static bool mount_cmd(JCR *jcr)
870 BSOCK *dir = jcr->dir_bsock;
873 int32_t drive; /* device index */
877 Dmsg1(100, "%s\n", dir->msg);
878 ok = sscanf(dir->msg, "mount %127s drive=%d slot=%d", devname.c_str(),
882 ok = sscanf(dir->msg, "mount %127s drive=%d", devname.c_str(), &drive) == 2;
884 Dmsg3(100, "ok=%d device_index=%d slot=%d\n", ok, drive, slot);
886 dcr = find_device(jcr, devname, NULL, drive);
889 dev->Lock(); /* Use P to avoid indefinite block */
890 Dmsg2(100, "mount cmd blocked=%d must_unload=%d\n", dev->blocked(),
892 switch (dev->blocked()) { /* device blocked? */
893 case BST_WAITING_FOR_SYSOP:
894 /* Someone is waiting, wake him */
895 Dmsg0(100, "Waiting for mount. Attempting to wake thread\n");
896 dev->set_blocked(BST_MOUNT);
897 dir->fsend("3001 OK mount requested. %sDevice=%s\n",
898 slot>0?_("Specified slot ignored. "):"",
900 Dmsg1(100, "JobId=%u broadcast wait_next_vol\n", (uint32_t)dcr->jcr->JobId);
901 pthread_cond_broadcast(&dev->wait_next_vol);
902 Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)dcr->jcr->JobId);
903 pthread_cond_broadcast(&wait_device_release);
906 /* In both of these two cases, we (the user) unmounted the Volume */
907 case BST_UNMOUNTED_WAITING_FOR_SYSOP:
909 Dmsg2(100, "Unmounted changer=%d slot=%d\n", dev->is_autochanger(), slot);
910 if (dev->is_autochanger() && slot > 0) {
911 try_autoload_device(jcr, dcr, slot, "");
913 /* We freed the device, so reopen it and wake any waiting threads */
914 if (!dev->open(dcr, OPEN_READ_ONLY)) {
915 dir->fsend(_("3901 Unable to open device \"%s\": ERR=%s\n"),
916 dev->print_name(), dev->bstrerror());
917 if (dev->blocked() == BST_UNMOUNTED) {
918 /* We blocked the device, so unblock it */
919 Dmsg0(100, "Unmounted. Unblocking device\n");
924 read_dev_volume_label(dcr);
925 if (dev->blocked() == BST_UNMOUNTED) {
926 /* We blocked the device, so unblock it */
927 Dmsg0(100, "Unmounted. Unblocking device\n");
928 read_label(dcr); /* this should not be necessary */
931 Dmsg0(100, "Unmounted waiting for mount. Attempting to wake thread\n");
932 dev->set_blocked(BST_MOUNT);
934 if (dev->is_labeled()) {
935 dir->fsend(_("3001 Device \"%s\" is mounted with Volume \"%s\"\n"),
936 dev->print_name(), dev->VolHdr.VolumeName);
938 dir->fsend(_("3905 Device \"%s\" open but no Bacula volume is mounted.\n"
939 "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
942 pthread_cond_broadcast(&dev->wait_next_vol);
943 Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)dcr->jcr->JobId);
944 pthread_cond_broadcast(&wait_device_release);
947 case BST_DOING_ACQUIRE:
948 dir->fsend(_("3001 Device \"%s\" is doing acquire.\n"),
952 case BST_WRITING_LABEL:
953 dir->fsend(_("3903 Device \"%s\" is being labeled.\n"),
957 case BST_NOT_BLOCKED:
958 Dmsg2(100, "Not blocked changer=%d slot=%d\n", dev->is_autochanger(), slot);
959 if (dev->is_autochanger() && slot > 0) {
960 try_autoload_device(jcr, dcr, slot, "");
962 if (dev->is_open()) {
963 if (dev->is_labeled()) {
964 dir->fsend(_("3001 Device \"%s\" is mounted with Volume \"%s\"\n"),
965 dev->print_name(), dev->VolHdr.VolumeName);
967 dir->fsend(_("3905 Device \"%s\" open but no Bacula volume is mounted.\n"
968 "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
971 } else if (dev->is_tape()) {
972 if (!dev->open(dcr, OPEN_READ_ONLY)) {
973 dir->fsend(_("3901 Unable to open device \"%s\": ERR=%s\n"),
974 dev->print_name(), dev->bstrerror());
978 if (dev->is_labeled()) {
979 dir->fsend(_("3001 Device \"%s\" is already mounted with Volume \"%s\"\n"),
980 dev->print_name(), dev->VolHdr.VolumeName);
982 dir->fsend(_("3905 Device \"%s\" open but no Bacula volume is mounted.\n"
983 "If this is not a blank tape, try unmounting and remounting the Volume.\n"),
986 if (dev->is_open() && !dev->has_cap(CAP_ALWAYSOPEN)) {
989 } else if (dev->is_unmountable()) {
991 dir->fsend(_("3002 Device \"%s\" is mounted.\n"), dev->print_name());
993 dir->fsend(_("3907 %s"), dev->bstrerror());
995 } else { /* must be file */
996 dir->fsend(_("3906 File device \"%s\" is always mounted.\n"),
998 pthread_cond_broadcast(&dev->wait_next_vol);
999 Dmsg1(100, "JobId=%u broadcast wait_device_release\n", (uint32_t)dcr->jcr->JobId);
1000 pthread_cond_broadcast(&wait_device_release);
1005 dir->fsend(_("3930 Device \"%s\" is being released.\n"), dev->print_name());
1009 dir->fsend(_("3905 Unknown wait state %d\n"), dev->blocked());
1015 dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
1018 pm_strcpy(jcr->errmsg, dir->msg);
1019 dir->fsend(_("3909 Error scanning mount command: %s\n"), jcr->errmsg);
1021 dir->signal(BNET_EOD);
1025 /* enable command from Director */
1026 static bool enable_cmd(JCR *jcr)
1029 BSOCK *dir = jcr->dir_bsock;
1035 ok = sscanf(dir->msg, "enable %127s drive=%d", devname.c_str(),
1037 Dmsg3(100, "ok=%d device=%s device_index=%d\n", ok, devname.c_str(), drive);
1039 dcr = find_device(jcr, devname, NULL, drive);
1042 dev->Lock(); /* Use P to avoid indefinite block */
1043 dev->enabled = true;
1044 dir->fsend(_("3002 Device \"%s\" enabled.\n"), dev->print_name());
1049 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
1050 pm_strcpy(jcr->errmsg, dir->msg);
1051 dir->fsend(_("3907 Error scanning \"enable\" command: %s\n"), jcr->errmsg);
1053 dir->signal(BNET_EOD);
1057 /* enable command from Director */
1058 static bool disable_cmd(JCR *jcr)
1061 BSOCK *dir = jcr->dir_bsock;
1067 ok = sscanf(dir->msg, "disable %127s drive=%d", devname.c_str(),
1069 Dmsg3(100, "ok=%d device=%s device_index=%d\n", ok, devname.c_str(), drive);
1071 dcr = find_device(jcr, devname, NULL, drive);
1075 dev->enabled = false;
1076 dir->fsend(_("3002 Device \"%s\" disabled.\n"), dev->print_name());
1081 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
1082 pm_strcpy(jcr->errmsg, dir->msg);
1083 dir->fsend(_("3907 Error scanning \"disable\" command: %s\n"), jcr->errmsg);
1085 dir->signal(BNET_EOD);
1091 * unmount command from Director
1093 static bool unmount_cmd(JCR *jcr)
1096 BSOCK *dir = jcr->dir_bsock;
1101 if (sscanf(dir->msg, "unmount %127s drive=%d", devname.c_str(), &drive) == 2) {
1102 dcr = find_device(jcr, devname, NULL, drive);
1105 dev->Lock(); /* Use P to avoid indefinite block */
1106 if (!dev->is_open()) {
1107 if (!dev->is_busy()) {
1108 unload_autochanger(dcr, -1);
1110 if (dev->is_unmountable()) {
1111 if (dev->unmount(0)) {
1112 dir->fsend(_("3002 Device \"%s\" unmounted.\n"),
1115 dir->fsend(_("3907 %s"), dev->bstrerror());
1118 Dmsg0(90, "Device already unmounted\n");
1119 dir->fsend(_("3901 Device \"%s\" is already unmounted.\n"),
1122 } else if (dev->blocked() == BST_WAITING_FOR_SYSOP) {
1123 Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
1125 if (!unload_autochanger(dcr, -1)) {
1127 * ***FIXME**** what is this ???? -- probably we had
1128 * the wrong volume so we must free it and try again. KES
1133 if (dev->is_unmountable() && !dev->unmount(0)) {
1134 dir->fsend(_("3907 %s"), dev->bstrerror());
1136 dev->set_blocked(BST_UNMOUNTED_WAITING_FOR_SYSOP);
1137 dir->fsend(_("3001 Device \"%s\" unmounted.\n"),
1141 } else if (dev->blocked() == BST_DOING_ACQUIRE) {
1142 dir->fsend(_("3902 Device \"%s\" is busy in acquire.\n"),
1145 } else if (dev->blocked() == BST_WRITING_LABEL) {
1146 dir->fsend(_("3903 Device \"%s\" is being labeled.\n"),
1149 } else if (dev->is_busy()) {
1150 send_dir_busy_message(dir, dev);
1151 } else { /* device not being used */
1152 Dmsg0(90, "Device not in use, unmounting\n");
1153 /* On FreeBSD, I am having ASSERT() failures in block_device()
1154 * and I can only imagine that the thread id that we are
1155 * leaving in no_wait_id is being re-used. So here,
1156 * we simply do it by hand. Gross, but a solution.
1158 /* block_device(dev, BST_UNMOUNTED); replace with 2 lines below */
1159 dev->set_blocked(BST_UNMOUNTED);
1160 clear_thread_id(dev->no_wait_id);
1161 if (!unload_autochanger(dcr, -1)) {
1165 if (dev->is_unmountable() && !dev->unmount(0)) {
1166 dir->fsend(_("3907 %s"), dev->bstrerror());
1168 dir->fsend(_("3002 Device \"%s\" unmounted.\n"),
1175 dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
1178 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
1179 pm_strcpy(jcr->errmsg, dir->msg);
1180 dir->fsend(_("3907 Error scanning unmount command: %s\n"), jcr->errmsg);
1182 dir->signal(BNET_EOD);
1188 * The truncate command will recycle a volume. The director can call this
1189 * after purging a volume so that disk space will not be wasted. Only useful
1190 * for File Storage, of course.
1193 * It is currently disabled
1195 static bool action_on_purge_cmd(JCR *jcr)
1197 BSOCK *dir = jcr->dir_bsock;
1199 char devname[MAX_NAME_LENGTH];
1200 char volumename[MAX_NAME_LENGTH];
1203 /* TODO: Need to find a free device and ask for slot to the director */
1204 if (sscanf(dir->msg,
1205 "action_on_purge %127s vol=%127s action=%d",
1206 devname, volumename, &action)!= 5)
1208 dir->fsend(_("3916 Error scanning action_on_purge command\n"));
1211 unbash_spaces(volumename);
1212 unbash_spaces(devname);
1214 /* Check if action is correct */
1215 if (action & AOP_TRUNCTATE) {
1221 dir->signal(BNET_EOD);
1227 * Release command from Director. This rewinds the device and if
1228 * configured does a offline and ensures that Bacula will
1229 * re-read the label of the tape before continuing. This gives
1230 * the operator the chance to change the tape anytime before the
1233 static bool release_cmd(JCR *jcr)
1236 BSOCK *dir = jcr->dir_bsock;
1241 if (sscanf(dir->msg, "release %127s drive=%d", devname.c_str(), &drive) == 2) {
1242 dcr = find_device(jcr, devname, NULL, drive);
1245 dev->Lock(); /* Use P to avoid indefinite block */
1246 if (!dev->is_open()) {
1247 if (!dev->is_busy()) {
1248 unload_autochanger(dcr, -1);
1250 Dmsg0(90, "Device already released\n");
1251 dir->fsend(_("3921 Device \"%s\" already released.\n"),
1254 } else if (dev->blocked() == BST_WAITING_FOR_SYSOP) {
1255 Dmsg2(90, "%d waiter dev_block=%d.\n", dev->num_waiting,
1257 unload_autochanger(dcr, -1);
1258 dir->fsend(_("3922 Device \"%s\" waiting for sysop.\n"),
1261 } else if (dev->blocked() == BST_UNMOUNTED_WAITING_FOR_SYSOP) {
1262 Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
1264 dir->fsend(_("3922 Device \"%s\" waiting for mount.\n"),
1267 } else if (dev->blocked() == BST_DOING_ACQUIRE) {
1268 dir->fsend(_("3923 Device \"%s\" is busy in acquire.\n"),
1271 } else if (dev->blocked() == BST_WRITING_LABEL) {
1272 dir->fsend(_("3914 Device \"%s\" is being labeled.\n"),
1275 } else if (dev->is_busy()) {
1276 send_dir_busy_message(dir, dev);
1277 } else { /* device not being used */
1278 Dmsg0(90, "Device not in use, releasing\n");
1279 dcr->release_volume();
1280 dir->fsend(_("3022 Device \"%s\" released.\n"),
1286 dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
1289 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
1290 pm_strcpy(jcr->errmsg, dir->msg);
1291 dir->fsend(_("3927 Error scanning release command: %s\n"), jcr->errmsg);
1293 dir->signal(BNET_EOD);
1297 static pthread_mutex_t bsr_mutex = PTHREAD_MUTEX_INITIALIZER;
1298 static uint32_t bsr_uniq = 0;
1300 static bool get_bootstrap_file(JCR *jcr, BSOCK *sock)
1302 POOLMEM *fname = get_pool_memory(PM_FNAME);
1306 if (jcr->RestoreBootstrap) {
1307 unlink(jcr->RestoreBootstrap);
1308 free_pool_memory(jcr->RestoreBootstrap);
1312 Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name,
1313 jcr->Job, bsr_uniq);
1315 Dmsg1(400, "bootstrap=%s\n", fname);
1316 jcr->RestoreBootstrap = fname;
1317 bs = fopen(fname, "a+b"); /* create file */
1320 Jmsg(jcr, M_FATAL, 0, _("Could not create bootstrap file %s: ERR=%s\n"),
1321 jcr->RestoreBootstrap, be.bstrerror());
1324 Dmsg0(150, "=== Bootstrap file ===\n");
1325 while (sock->recv() >= 0) {
1326 Dmsg1(150, "%s", sock->msg);
1327 fputs(sock->msg, bs);
1330 Dmsg0(150, "=== end bootstrap file ===\n");
1331 jcr->bsr = parse_bsr(jcr, jcr->RestoreBootstrap);
1333 Jmsg(jcr, M_FATAL, 0, _("Error parsing bootstrap file.\n"));
1336 if (chk_dbglvl(150)) {
1337 dump_bsr(jcr->bsr, true);
1339 /* If we got a bootstrap, we are reading, so create read volume list */
1340 create_restore_volume_list(jcr);
1344 unlink(jcr->RestoreBootstrap);
1345 free_pool_memory(jcr->RestoreBootstrap);
1346 jcr->RestoreBootstrap = NULL;
1348 sock->fsend(ERROR_bootstrap);
1351 return sock->fsend(OK_bootstrap);
1354 static bool bootstrap_cmd(JCR *jcr)
1356 return get_bootstrap_file(jcr, jcr->dir_bsock);
1360 * Autochanger command from Director
1362 static bool changer_cmd(JCR *jcr)
1365 BSOCK *dir = jcr->dir_bsock;
1368 const char *cmd = NULL;
1371 * A safe_cmd may call autochanger script but does not load/unload
1372 * slots so it can be done at the same time that the drive is open.
1374 bool safe_cmd = false;
1376 if (sscanf(dir->msg, "autochanger listall %127s", devname.c_str()) == 1) {
1378 safe_cmd = ok = true;
1379 } else if (sscanf(dir->msg, "autochanger list %127s", devname.c_str()) == 1) {
1381 safe_cmd = ok = true;
1382 } else if (sscanf(dir->msg, "autochanger slots %127s", devname.c_str()) == 1) {
1384 safe_cmd = ok = true;
1385 } else if (sscanf(dir->msg, "autochanger drives %127s", devname.c_str()) == 1) {
1387 safe_cmd = ok = true;
1390 dcr = find_device(jcr, devname, NULL, -1);
1393 dev->Lock(); /* Use P to avoid indefinite block */
1394 if (!dev->device->changer_res) {
1395 dir->fsend(_("3998 Device \"%s\" is not an autochanger.\n"),
1397 /* Under certain "safe" conditions, we can steal the lock */
1398 } else if (safe_cmd || !dev->is_open() || dev->can_steal_lock()) {
1399 autochanger_cmd(dcr, dir, cmd);
1400 } else if (dev->is_busy() || dev->is_blocked()) {
1401 send_dir_busy_message(dir, dev);
1402 } else { /* device not being used */
1403 autochanger_cmd(dcr, dir, cmd);
1408 dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
1410 } else { /* error on scanf */
1411 pm_strcpy(jcr->errmsg, dir->msg);
1412 dir->fsend(_("3909 Error scanning autochanger drives/list/slots command: %s\n"),
1415 dir->signal(BNET_EOD);
1420 * Read and return the Volume label
1422 static bool readlabel_cmd(JCR *jcr)
1425 BSOCK *dir = jcr->dir_bsock;
1428 int32_t Slot, drive;
1430 if (sscanf(dir->msg, "readlabel %127s Slot=%d drive=%d", devname.c_str(),
1431 &Slot, &drive) == 3) {
1432 dcr = find_device(jcr, devname, NULL, drive);
1435 dev->Lock(); /* Use P to avoid indefinite block */
1436 if (!dev->is_open()) {
1437 read_volume_label(jcr, dcr, dev, Slot);
1439 /* Under certain "safe" conditions, we can steal the lock */
1440 } else if (dev->can_steal_lock()) {
1441 read_volume_label(jcr, dcr, dev, Slot);
1442 } else if (dev->is_busy() || dev->is_blocked()) {
1443 send_dir_busy_message(dir, dev);
1444 } else { /* device not being used */
1445 read_volume_label(jcr, dcr, dev, Slot);
1450 dir->fsend(_("3999 Device \"%s\" not found or could not be opened.\n"), devname.c_str());
1453 pm_strcpy(jcr->errmsg, dir->msg);
1454 dir->fsend(_("3909 Error scanning readlabel command: %s\n"), jcr->errmsg);
1456 dir->signal(BNET_EOD);
1462 * Read the tape label
1464 * Enter with the mutex set
1466 static void read_volume_label(JCR *jcr, DCR *dcr, DEVICE *dev, int Slot)
1468 BSOCK *dir = jcr->dir_bsock;
1472 steal_device_lock(dev, &hold, BST_WRITING_LABEL);
1474 if (!try_autoload_device(jcr, dcr, Slot, "")) {
1475 goto bail_out; /* error */
1478 dev->clear_labeled(); /* force read of label */
1479 switch (read_dev_volume_label(dcr)) {
1481 /* DO NOT add quotes around the Volume name. It is scanned in the DIR */
1482 dir->fsend(_("3001 Volume=%s Slot=%d\n"), dev->VolHdr.VolumeName, Slot);
1483 Dmsg1(100, "Volume: %s\n", dev->VolHdr.VolumeName);
1486 dir->fsend(_("3902 Cannot mount Volume on Storage Device \"%s\" because:\n%s"),
1487 dev->print_name(), jcr->errmsg);
1492 give_back_device_lock(dev, &hold);
1496 static bool try_autoload_device(JCR *jcr, DCR *dcr, int slot, const char *VolName)
1498 BSOCK *dir = jcr->dir_bsock;
1500 bstrncpy(dcr->VolumeName, VolName, sizeof(dcr->VolumeName));
1501 dcr->VolCatInfo.Slot = slot;
1502 dcr->VolCatInfo.InChanger = slot > 0;
1503 if (autoload_device(dcr, 0, dir) < 0) { /* autoload if possible */
1509 static void send_dir_busy_message(BSOCK *dir, DEVICE *dev)
1511 if (dev->is_blocked()) {
1512 switch (dev->blocked()) {
1514 dir->fsend(_("3931 Device \"%s\" is BLOCKED. user unmounted.\n"),
1517 case BST_UNMOUNTED_WAITING_FOR_SYSOP:
1518 dir->fsend(_("3932 Device \"%s\" is BLOCKED. user unmounted during wait for media/mount.\n"),
1521 case BST_WAITING_FOR_SYSOP:
1522 dir->fsend(_("3933 Device \"%s\" is BLOCKED waiting for media.\n"),
1525 case BST_DOING_ACQUIRE:
1526 dir->fsend(_("3934 Device \"%s\" is being initialized.\n"),
1529 case BST_WRITING_LABEL:
1530 dir->fsend(_("3935 Device \"%s\" is blocked labeling a Volume.\n"),
1534 dir->fsend(_("3935 Device \"%s\" is blocked for unknown reason.\n"),
1538 } else if (dev->can_read()) {
1539 dir->fsend(_("3936 Device \"%s\" is busy reading.\n"),
1540 dev->print_name());;
1542 dir->fsend(_("3937 Device \"%s\" is busy with writers=%d reserved=%d.\n"),
1543 dev->print_name(), dev->num_writers, dev->num_reserved());