static int status_cmd(JCR *sjcr);
static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *vname, char *poolname,
int Slot);
+static void send_blocked_status(JCR *jcr, DEVICE *dev);
struct s_cmds {
char *cmd;
strcpy(jcr->VolumeName, vname);
jcr->VolCatInfo.Slot = slot;
- autoload_device(jcr, dev, 0); /* autoload if possible */
+ autoload_device(jcr, dev, 0, dir); /* autoload if possible */
block = new_block(dev);
+ /* Ensure that the device is open -- not autoload_device() closes it */
+ for ( ; !(dev->state & ST_OPENED); ) {
+ if (open_dev(dev, jcr->VolumeName, READ_WRITE) < 0) {
+ if (dev->dev_errno == EAGAIN || dev->dev_errno == EBUSY) {
+ sleep(30);
+ }
+ bnet_fsend(dir, _("3903 Unable to open device %s. ERR=%s\n"),
+ dev_name(dev), strerror_dev(dev));
+ goto bail_out;
+ }
+ }
+
/* See what we have for a Volume */
switch (read_dev_volume_label(jcr, dev, block)) {
case VOL_NAME_ERROR:
break;
case VOL_IO_ERROR:
case VOL_NO_LABEL:
- write_volume_label_to_dev(jcr, jcr->device, vname, poolname);
+ if (!write_volume_label_to_dev(jcr, jcr->device, vname, poolname)) {
+ bnet_fsend(dir, _("3903 Failed to label Volume: ERR=%s\n"), strerror_dev(dev));
+ break;
+ }
strcpy(jcr->VolumeName, vname);
bnet_fsend(dir, _("3000 OK label. Volume=%s Device=%s\n"),
vname, dev->dev_name);
Unknown status %d from read_volume_label()\n"), jcr->label_status);
break;
}
+bail_out:
free_block(block);
return_device_lock(dev, &hold);
}
} else {
bnet_fsend(user, _("Device %s open but no Bacula volume is mounted.\n"), dev_name(dev));
}
- switch (dev->dev_blocked) {
- case BST_UNMOUNTED:
- bnet_fsend(user, _(" Deviced is blocked. User unmounted.\n"));
- break;
- case BST_UNMOUNTED_WAITING_FOR_SYSOP:
- bnet_fsend(user, _(" Deviced is blocked. User unmounted during wait for media/mount.\n"));
- break;
- case BST_WAITING_FOR_SYSOP:
- if (jcr->JobStatus == JS_WaitMount) {
- bnet_fsend(user, _(" Device is blocked waiting for mount.\n"));
- } else {
- bnet_fsend(user, _(" Device is blocked waiting for appendable media.\n"));
- }
- break;
- case BST_DOING_ACQUIRE:
- bnet_fsend(user, _(" Device is being initialized.\n"));
- break;
- case BST_WRITING_LABEL:
- bnet_fsend(user, _(" Device is blocked labeling a Volume.\n"));
- break;
- default:
- break;
- }
+ send_blocked_status(jcr, dev);
bpb = dev->VolCatInfo.VolCatBlocks;
if (bpb <= 0) {
bpb = 1;
} else {
bnet_fsend(user, _("Device %s is not open.\n"), dev_name(dev));
+ send_blocked_status(jcr, dev);
}
}
}
bnet_sig(user, BNET_EOD);
return 1;
}
+
+static void send_blocked_status(JCR *jcr, DEVICE *dev)
+{
+ BSOCK *user = jcr->dir_bsock;
+
+ switch (dev->dev_blocked) {
+ case BST_UNMOUNTED:
+ bnet_fsend(user, _(" Device is BLOCKED. User unmounted.\n"));
+ break;
+ case BST_UNMOUNTED_WAITING_FOR_SYSOP:
+ bnet_fsend(user, _(" Device is BLOCKED. User unmounted during wait for media/mount.\n"));
+ break;
+ case BST_WAITING_FOR_SYSOP:
+ if (jcr->JobStatus == JS_WaitMount) {
+ bnet_fsend(user, _(" Device is BLOCKED waiting for mount.\n"));
+ } else {
+ bnet_fsend(user, _(" Device is BLOCKED waiting for appendable media.\n"));
+ }
+ break;
+ case BST_DOING_ACQUIRE:
+ bnet_fsend(user, _(" Device is being initialized.\n"));
+ break;
+ case BST_WRITING_LABEL:
+ bnet_fsend(user, _(" Device is blocked labeling a Volume.\n"));
+ break;
+ default:
+ break;
+ }
+}