2 * This file handles accepting Director Commands
4 * Most Director commands are handled here, with the
5 * exception of the Job command command and subsequent
6 * subcommands that are handled
9 * N.B. in this file, in general we must use P(dev->mutex) rather
10 * than lock_device(dev) so that we can examine the blocked
11 * state rather than blocking ourselves. In some "safe" cases,
12 * we can do things to a blocked device. CAREFUL!!!!
14 * File daemon commands are handled in fdcmd.c
16 * Kern Sibbald, May MMI
22 Copyright (C) 2000-2003 Kern Sibbald and John Walker
24 This program is free software; you can redistribute it and/or
25 modify it under the terms of the GNU General Public License as
26 published by the Free Software Foundation; either version 2 of
27 the License, or (at your option) any later version.
29 This program is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 General Public License for more details.
34 You should have received a copy of the GNU General Public
35 License along with this program; if not, write to the Free
36 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
44 /* Exported variables */
46 /* Imported variables */
47 extern BSOCK *filed_chan;
48 extern int r_first, r_last;
49 extern struct s_res resources[];
50 extern char my_name[];
51 extern time_t daemon_start_time;
52 extern struct s_last_job last_job;
54 /* Static variables */
55 static char derrmsg[] = "3900 Invalid command\n";
56 static char OKsetdebug[] = "3000 OK setdebug=%d\n";
59 /* Imported functions */
60 extern void terminate_child();
61 extern int job_cmd(JCR *jcr);
62 extern int status_cmd(JCR *sjcr);
64 /* Forward referenced functions */
65 static int label_cmd(JCR *jcr);
66 static int relabel_cmd(JCR *jcr);
67 static int release_cmd(JCR *jcr);
68 static int setdebug_cmd(JCR *jcr);
69 static int cancel_cmd(JCR *cjcr);
70 static int mount_cmd(JCR *jcr);
71 static int unmount_cmd(JCR *jcr);
72 static int autochanger_cmd(JCR *sjcr);
73 static int do_label(JCR *jcr, int relabel);
74 static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
75 char *newname, char *poolname,
76 int Slot, int relabel);
80 int (*func)(JCR *jcr);
84 * The following are the recognized commands from the Director.
86 static struct s_cmds cmds[] = {
87 {"JobId=", job_cmd}, /* start Job */
88 {"setdebug=", setdebug_cmd}, /* set debug level */
89 {"cancel", cancel_cmd},
90 {"label", label_cmd}, /* label a tape */
91 {"relabel", relabel_cmd}, /* relabel a tape */
93 {"unmount", unmount_cmd},
94 {"status", status_cmd},
95 {"autochanger", autochanger_cmd},
96 {"release", release_cmd},
97 {NULL, NULL} /* list terminator */
102 * Connection request. We accept connections either from the
103 * Director or a Client.
105 * Note, we are running as a seperate thread of the Storage daemon.
106 * and it is because a Director has made a connection with
107 * us on the "Message" channel.
109 * Basic tasks done here:
110 * - Create a JCR record
111 * - Authenticate the Director
112 * - We wait for a command
113 * - We execute the command
114 * - We continue or exit depending on the return status
116 void *connection_request(void *arg)
118 BSOCK *bs = (BSOCK *)arg;
122 char name[MAX_NAME_LENGTH];
124 if (bnet_recv(bs) <= 0) {
125 Emsg0(M_ERROR, 0, _("Connection request failed.\n"));
130 * See if this is a File daemon connection
132 if (bs->msglen < 25 || bs->msglen > (int)sizeof(name)+25) {
133 Emsg1(M_ERROR, 0, _("Invalid Dir connection. Len=%d\n"), bs->msglen);
135 if (sscanf(bs->msg, "Hello Start Job %127s calling\n", name) == 1) {
136 handle_filed_connection(bs, name);
140 jcr = new_jcr(sizeof(JCR), stored_free_jcr); /* create Job Control Record */
141 jcr->dir_bsock = bs; /* save Director bsock */
143 Dmsg0(1000, "stored in start_job\n");
146 * Authenticate the Director
148 if (!authenticate_director(jcr)) {
149 Jmsg(jcr, M_FATAL, 0, _("Unable to authenticate Director\n"));
153 Dmsg0(90, "Message channel init completed.\n");
155 for (quit=0; !quit;) {
157 if ((bnet_stat = bnet_recv(bs)) <= 0) {
158 break; /* connection terminated */
160 Dmsg1(9, "<dird: %s\n", bs->msg);
162 for (i=0; cmds[i].cmd; i++) {
163 if (strncmp(cmds[i].cmd, bs->msg, strlen(cmds[i].cmd)) == 0) {
164 if (!cmds[i].func(jcr)) { /* do command */
165 quit = TRUE; /* error, get out */
166 Dmsg1(90, "Command %s requsts quit\n", cmds[i].cmd);
168 found = TRUE; /* indicate command found */
172 if (!found) { /* command not found */
173 bnet_fsend(bs, derrmsg);
178 if (bnet_stat != BNET_TERMINATE) {
179 bnet_sig(bs, BNET_TERMINATE);
186 * Set debug level as requested by the Director
189 static int setdebug_cmd(JCR *jcr)
191 BSOCK *dir = jcr->dir_bsock;
194 Dmsg1(10, "setdebug_cmd: %s", dir->msg);
195 if (sscanf(dir->msg, "setdebug=%d", &level) != 1 || level < 0) {
196 bnet_fsend(dir, "3991 Bad setdebug command: %s\n", dir->msg);
200 return bnet_fsend(dir, OKsetdebug, level);
207 static int cancel_cmd(JCR *cjcr)
209 BSOCK *dir = cjcr->dir_bsock;
211 char Job[MAX_NAME_LENGTH];
214 if (sscanf(dir->msg, "cancel Job=%127s", Job) == 1) {
215 if (!(jcr=get_jcr_by_full_name(Job))) {
216 bnet_fsend(dir, _("3992 Job %s not found.\n"), Job);
219 oldStatus = jcr->JobStatus;
220 set_jcr_job_status(jcr, JS_Canceled);
221 if (!jcr->authenticated && oldStatus == JS_WaitFD) {
222 pthread_cond_signal(&jcr->job_start_wait); /* wake waiting thread */
225 if (jcr->file_bsock) {
226 bnet_sig(jcr->file_bsock, BNET_TERMINATE);
228 /* If thread waiting on mount, wake him */
229 if (jcr->device && jcr->device->dev &&
230 (jcr->device->dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
231 jcr->device->dev->dev_blocked == BST_UNMOUNTED ||
232 jcr->device->dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
233 pthread_cond_signal(&jcr->device->dev->wait_next_vol);
235 bnet_fsend(dir, _("3000 Job %s marked to be canceled.\n"), jcr->Job);
239 bnet_fsend(dir, _("3993 Error scanning cancel command.\n"));
241 bnet_sig(dir, BNET_EOD);
249 static int label_cmd(JCR *jcr)
251 return do_label(jcr, 0);
254 static int relabel_cmd(JCR *jcr)
256 return do_label(jcr, 1);
259 static int do_label(JCR *jcr, int relabel)
261 POOLMEM *dname, *newname, *oldname, *poolname, *mtype;
262 BSOCK *dir = jcr->dir_bsock;
265 int found = 0, ok = 0;
268 dname = get_memory(dir->msglen+1);
269 newname = get_memory(dir->msglen+1);
270 oldname = get_memory(dir->msglen+1);
271 poolname = get_memory(dir->msglen+1);
272 mtype = get_memory(dir->msglen+1);
274 if (sscanf(dir->msg, "relabel %s OldName=%s NewName=%s PoolName=%s MediaType=%s Slot=%d",
275 dname, oldname, newname, poolname, mtype, &slot) == 6) {
280 if (sscanf(dir->msg, "label %s VolumeName=%s PoolName=%s MediaType=%s Slot=%d",
281 dname, newname, poolname, mtype, &slot) == 5) {
286 unbash_spaces(dname);
287 unbash_spaces(newname);
288 unbash_spaces(oldname);
289 unbash_spaces(poolname);
290 unbash_spaces(mtype);
293 while ((device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device))) {
294 /* Find resource, and make sure we were able to open it */
295 if (strcmp(device->hdr.name, dname) == 0 && device->dev) {
296 Dmsg1(20, "Found device %s\n", device->hdr.name);
303 /******FIXME**** compare MediaTypes */
304 jcr->device = device;
307 P(dev->mutex); /* Use P to avoid indefinite block */
308 if (!(dev->state & ST_OPENED)) {
309 if (open_dev(dev, newname, READ_WRITE) < 0) {
310 bnet_fsend(dir, _("3994 Connot open device: %s\n"), strerror_dev(dev));
312 label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
313 force_close_dev(dev);
315 /* Under certain "safe" conditions, we can steal the lock */
316 } else if (dev->dev_blocked &&
317 (dev->dev_blocked == BST_UNMOUNTED ||
318 dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
319 dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
320 label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
321 } else if (dev->state & ST_READ || dev->num_writers) {
322 if (dev->state & ST_READ) {
323 bnet_fsend(dir, _("3901 Device %s is busy with 1 reader.\n"),
326 bnet_fsend(dir, _("3902 Device %s is busy with %d writer(s).\n"),
327 dev_name(dev), dev->num_writers);
329 } else { /* device not being used */
330 label_volume_if_ok(jcr, dev, oldname, newname, poolname, slot, relabel);
334 bnet_fsend(dir, _("3999 Device %s not found\n"), dname);
337 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
338 pm_strcpy(&jcr->errmsg, dir->msg);
339 bnet_fsend(dir, _("3903 Error scanning label command: %s\n"), jcr->errmsg);
342 free_memory(oldname);
343 free_memory(newname);
344 free_memory(poolname);
346 bnet_sig(dir, BNET_EOD);
351 * Read the tape label and determine if we can safely
352 * label the tape (not a Bacula volume), then label it.
354 * Enter with the mutex set
356 static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname,
357 char *newname, char *poolname,
358 int slot, int relabel)
360 BSOCK *dir = jcr->dir_bsock;
364 steal_device_lock(dev, &hold, BST_WRITING_LABEL);
366 pm_strcpy(&jcr->VolumeName, newname);
367 jcr->VolCatInfo.Slot = slot;
368 autoload_device(jcr, dev, 0, dir); /* autoload if possible */
369 block = new_block(dev);
371 /* Ensure that the device is open -- autoload_device() closes it */
372 for ( ; !(dev->state & ST_OPENED); ) {
373 if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
374 if (dev->dev_errno == EAGAIN || dev->dev_errno == EBUSY) {
377 bnet_fsend(dir, _("3910 Unable to open device %s. ERR=%s\n"),
378 dev_name(dev), strerror_dev(dev));
383 /* See what we have for a Volume */
384 switch (read_dev_volume_label(jcr, dev, block)) {
386 case VOL_VERSION_ERROR:
387 case VOL_LABEL_ERROR:
391 "3911 Cannot label Volume because it is already labeled: %s\n"),
392 dev->VolHdr.VolName);
395 /* Relabel request. If oldname matches, continue */
396 if (strcmp(oldname, dev->VolHdr.VolName) != 0) {
397 bnet_fsend(dir, _("Wrong volume mounted.\n"));
400 /* Fall through wanted! */
403 if (!write_volume_label_to_dev(jcr, jcr->device, newname, poolname)) {
404 bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
407 strcpy(jcr->VolumeName, newname);
408 bnet_fsend(dir, _("3000 OK label. Volume=%s Device=%s\n"),
409 newname, dev->dev_name);
412 bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
415 bnet_fsend(dir, _("3913 Cannot label Volume. \
416 Unknown status %d from read_volume_label()\n"), jcr->label_status);
421 give_back_device_lock(dev, &hold);
428 * Read the tape label
430 * Enter with the mutex set
432 static int read_label(JCR *jcr, DEVICE *dev)
435 BSOCK *dir = jcr->dir_bsock;
439 steal_device_lock(dev, &hold, BST_DOING_ACQUIRE);
441 jcr->VolumeName[0] = 0;
442 block = new_block(dev);
443 dev->state &= ~ST_LABEL; /* force read of label */
444 switch (read_dev_volume_label(jcr, dev, block)) {
446 bnet_fsend(dir, _("3001 Mounted Volume: %s\n"), dev->VolHdr.VolName);
450 bnet_fsend(dir, _("3902 Cannot mount Volume on Storage Device \"%s\" because:\n%s\n"),
451 dev->dev_name, jcr->errmsg);
456 give_back_device_lock(dev, &hold);
461 * Mount command from Director
463 static int mount_cmd(JCR *jcr)
466 BSOCK *dir = jcr->dir_bsock;
471 dev_name = get_memory(dir->msglen+1);
472 if (sscanf(dir->msg, "mount %s", dev_name) == 1) {
473 unbash_spaces(dev_name);
476 while ((device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device))) {
477 /* Find resource, and make sure we were able to open it */
478 if (strcmp(device->hdr.name, dev_name) == 0 && device->dev) {
479 Dmsg1(20, "Found device %s\n", device->hdr.name);
486 jcr->device = device;
488 P(dev->mutex); /* Use P to avoid indefinite block */
489 switch (dev->dev_blocked) { /* device blocked? */
491 case BST_WAITING_FOR_SYSOP:
492 /* Someone is waiting, wake him */
493 Dmsg0(100, "Waiting for mount. Attempting to wake thread\n");
494 dev->dev_blocked = BST_MOUNT;
495 pthread_cond_signal(&dev->wait_next_vol);
496 bnet_fsend(dir, "3001 OK mount. Device=%s\n", dev->dev_name);
499 case BST_UNMOUNTED_WAITING_FOR_SYSOP:
501 /* We freed the device, so reopen it and wake any waiting threads */
502 if (open_dev(dev, NULL, READ_WRITE) < 0) {
503 bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"),
507 block = new_block(dev);
508 read_dev_volume_label(jcr, dev, block);
510 if (dev->dev_blocked == BST_UNMOUNTED) {
511 Dmsg0(100, "Unmounted. Unblocking device\n");
512 read_label(jcr, dev);
515 Dmsg0(100, "Unmounted waiting for mount. Attempting to wake thread\n");
516 dev->dev_blocked = BST_MOUNT;
517 pthread_cond_signal(&dev->wait_next_vol);
519 if (dev->state & ST_LABEL) {
520 bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
521 dev->dev_name, dev->VolHdr.VolName);
523 bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
524 "Try unmounting and remounting the Volume.\n"),
529 case BST_DOING_ACQUIRE:
530 bnet_fsend(dir, _("3001 Device %s is mounted; doing acquire.\n"),
534 case BST_WRITING_LABEL:
535 bnet_fsend(dir, _("3903 Device %s is being labeled.\n"), dev->dev_name);
538 case BST_NOT_BLOCKED:
539 if (dev->state & ST_OPENED) {
540 if (dev->state & ST_LABEL) {
541 bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
542 dev->dev_name, dev->VolHdr.VolName);
544 bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
545 "Try unmounting and remounting the Volume.\n"),
549 if (!dev_is_tape(dev)) {
550 bnet_fsend(dir, _("3906 cannot mount non-tape.\n"));
553 if (open_dev(dev, NULL, READ_WRITE) < 0) {
554 bnet_fsend(dir, _("3901 open device failed: ERR=%s\n"),
558 read_label(jcr, dev);
559 if (dev->state & ST_LABEL) {
560 bnet_fsend(dir, _("3001 Device %s is mounted with Volume \"%s\"\n"),
561 dev->dev_name, dev->VolHdr.VolName);
563 bnet_fsend(dir, _("3905 Device %s open but no Bacula volume is mounted.\n"
564 "Try unmounting and remounting the Volume.\n"),
571 bnet_fsend(dir, _("3905 Bizarre wait state %d\n"), dev->dev_blocked);
576 bnet_fsend(dir, _("3999 Device %s not found\n"), dev_name);
579 pm_strcpy(&jcr->errmsg, dir->msg);
580 bnet_fsend(dir, _("3906 Error scanning mount command: %s\n"), jcr->errmsg);
582 free_memory(dev_name);
583 bnet_sig(dir, BNET_EOD);
588 * unmount command from Director
590 static int unmount_cmd(JCR *jcr)
593 BSOCK *dir = jcr->dir_bsock;
598 dname = get_memory(dir->msglen+1);
599 if (sscanf(dir->msg, "unmount %s", dname) == 1) {
600 unbash_spaces(dname);
603 while ((device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device))) {
604 /* Find resource, and make sure we were able to open it */
605 if (strcmp(device->hdr.name, dname) == 0 && device->dev) {
606 Dmsg1(20, "Found device %s\n", device->hdr.name);
613 jcr->device = device;
615 P(dev->mutex); /* Use P to avoid indefinite block */
616 if (!(dev->state & ST_OPENED)) {
617 Dmsg0(90, "Device already unmounted\n");
618 bnet_fsend(dir, _("3901 Device %s is already unmounted.\n"), dev_name(dev));
620 } else if (dev->dev_blocked == BST_WAITING_FOR_SYSOP) {
621 Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
623 open_dev(dev, NULL, 0); /* fake open for close */
624 offline_or_rewind_dev(dev);
625 force_close_dev(dev);
626 dev->dev_blocked = BST_UNMOUNTED_WAITING_FOR_SYSOP;
627 bnet_fsend(dir, _("3001 Device %s unmounted.\n"), dev_name(dev));
629 } else if (dev->dev_blocked == BST_DOING_ACQUIRE) {
630 bnet_fsend(dir, _("3902 Device %s is busy in acquire.\n"),
633 } else if (dev->dev_blocked == BST_WRITING_LABEL) {
634 bnet_fsend(dir, _("3903 Device %s is being labeled.\n"),
637 } else if (dev->state & ST_READ || dev->num_writers) {
638 if (dev->state & ST_READ) {
639 Dmsg0(90, "Device in read mode\n");
640 bnet_fsend(dir, _("3904 Device %s is busy with 1 reader.\n"),
643 Dmsg1(90, "Device busy with %d writers\n", dev->num_writers);
644 bnet_fsend(dir, _("3905 Device %s is busy with %d writer(s).\n"),
645 dev_name(dev), dev->num_writers);
648 } else { /* device not being used */
649 Dmsg0(90, "Device not in use, unmounting\n");
650 /* On FreeBSD, I am having ASSERT() failures in block_device()
651 * and I can only imagine that the thread id that we are
652 * leaving in no_wait_id is being re-used. So here,
653 * we simply do it by hand. Gross, but maybe a solutions
655 /* block_device(dev, BST_UNMOUNTED); replace with 2 lines below */
656 dev->dev_blocked = BST_UNMOUNTED;
658 open_dev(dev, NULL, 0); /* fake open for close */
659 offline_or_rewind_dev(dev);
660 force_close_dev(dev);
661 bnet_fsend(dir, _("3002 Device %s unmounted.\n"), dev_name(dev));
665 bnet_fsend(dir, _("3999 Device %s not found\n"), dname);
668 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
669 pm_strcpy(&jcr->errmsg, dir->msg);
670 bnet_fsend(dir, _("3907 Error scanning unmount command: %s\n"), jcr->errmsg);
673 bnet_sig(dir, BNET_EOD);
678 * Release command from Director. This rewinds the device and if
679 * configured does a offline and ensures that Bacula will
680 * re-read the label of the tape before continuing. This gives
681 * the operator the chance to change the tape anytime before the
684 static int release_cmd(JCR *jcr)
687 BSOCK *dir = jcr->dir_bsock;
692 dname = get_memory(dir->msglen+1);
693 if (sscanf(dir->msg, "release %s", dname) == 1) {
694 unbash_spaces(dname);
697 while ((device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device))) {
698 /* Find resource, and make sure we were able to open it */
699 if (strcmp(device->hdr.name, dname) == 0 && device->dev) {
700 Dmsg1(20, "Found device %s\n", device->hdr.name);
707 jcr->device = device;
709 P(dev->mutex); /* Use P to avoid indefinite block */
710 if (!(dev->state & ST_OPENED)) {
711 Dmsg0(90, "Device already released\n");
712 bnet_fsend(dir, _("3911 Device %s already released.\n"), dev_name(dev));
714 } else if (dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
715 dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP) {
716 Dmsg2(90, "%d waiter dev_block=%d. doing unmount\n", dev->num_waiting,
718 bnet_fsend(dir, _("3912 Device %s waiting for mount.\n"), dev_name(dev));
720 } else if (dev->dev_blocked == BST_DOING_ACQUIRE) {
721 bnet_fsend(dir, _("3913 Device %s is busy in acquire.\n"),
724 } else if (dev->dev_blocked == BST_WRITING_LABEL) {
725 bnet_fsend(dir, _("3914 Device %s is being labeled.\n"),
728 } else if (dev->state & ST_READ || dev->num_writers) {
729 if (dev->state & ST_READ) {
730 Dmsg0(90, "Device in read mode\n");
731 bnet_fsend(dir, _("3915 Device %s is busy with 1 reader.\n"),
734 Dmsg1(90, "Device busy with %d writers\n", dev->num_writers);
735 bnet_fsend(dir, _("3916 Device %s is busy with %d writer(s).\n"),
736 dev_name(dev), dev->num_writers);
739 } else { /* device not being used */
740 Dmsg0(90, "Device not in use, unmounting\n");
741 release_volume(jcr, dev);
742 bnet_fsend(dir, _("3012 Device %s released.\n"), dev_name(dev));
746 bnet_fsend(dir, _("3999 Device %s not found\n"), dname);
749 /* NB dir->msg gets clobbered in bnet_fsend, so save command */
750 pm_strcpy(&jcr->errmsg, dir->msg);
751 bnet_fsend(dir, _("3917 Error scanning release command: %s\n"), jcr->errmsg);
754 bnet_sig(dir, BNET_EOD);
761 * Autochanger command from Director
763 static int autochanger_cmd(JCR *jcr)
766 BSOCK *dir = jcr->dir_bsock;
771 devname = get_memory(dir->msglen+1);
772 if (sscanf(dir->msg, "autochanger list %s ", devname) == 1) {
773 unbash_spaces(devname);
776 while ((device=(DEVRES *)GetNextRes(R_DEVICE, (RES *)device))) {
777 /* Find resource, and make sure we were able to open it */
778 if (strcmp(device->hdr.name, devname) == 0 && device->dev) {
779 Dmsg1(20, "Found device %s\n", device->hdr.name);
786 jcr->device = device;
788 P(dev->mutex); /* Use P to avoid indefinite block */
789 if (!dev_is_tape(dev)) {
790 bnet_fsend(dir, _("3995 Device %s is not an autochanger.\n"),
792 } else if (!(dev->state & ST_OPENED)) {
793 if (open_dev(dev, NULL, READ_WRITE) < 0) {
794 bnet_fsend(dir, _("3994 Connot open device: %s\n"), strerror_dev(dev));
796 autochanger_list(jcr, dev, dir);
797 force_close_dev(dev);
799 /* Under certain "safe" conditions, we can steal the lock */
800 } else if (dev->dev_blocked &&
801 (dev->dev_blocked == BST_UNMOUNTED ||
802 dev->dev_blocked == BST_WAITING_FOR_SYSOP ||
803 dev->dev_blocked == BST_UNMOUNTED_WAITING_FOR_SYSOP)) {
804 autochanger_list(jcr, dev, dir);
805 } else if (dev->state & ST_READ || dev->num_writers) {
806 if (dev->state & ST_READ) {
807 bnet_fsend(dir, _("3901 Device %s is busy with 1 reader.\n"),
810 bnet_fsend(dir, _("3902 Device %s is busy with %d writer(s).\n"),
811 dev_name(dev), dev->num_writers);
813 } else { /* device not being used */
814 autochanger_list(jcr, dev, dir);
818 bnet_fsend(dir, _("3999 Device %s not found\n"), devname);
820 } else { /* error on scanf */
821 pm_strcpy(&jcr->errmsg, dir->msg);
822 bnet_fsend(dir, _("3907 Error scanning autocharger list command: %s\n"),
825 free_memory(devname);
826 bnet_sig(dir, BNET_EOD);