-read_volume:
- switch (read_dev_volume_label(jcr, dev, block)) {
- case VOL_OK:
- Dmsg1(500, "Vol OK name=%s\n", jcr->VolumeName);
- memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(jcr->VolCatInfo));
- if (strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0) {
- recycle = 1;
- }
- break; /* got it */
- case VOL_NAME_ERROR:
- Dmsg1(500, "Vol NAME Error Name=%s\n", jcr->VolumeName);
- /* Check if we can accept this as an anonymous volume */
- strcpy(jcr->VolumeName, dev->VolHdr.VolName);
- if (!dev->capabilities & CAP_ANONVOLS || !dir_get_volume_info(jcr)) {
- goto mount_next_vol;
- }
- Dmsg1(200, "want new name=%s\n", jcr->VolumeName);
- memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(jcr->VolCatInfo));
- break;
-
- case VOL_NO_LABEL:
- case VOL_IO_ERROR:
- Dmsg1(500, "Vol NO_LABEL or IO_ERROR name=%s\n", jcr->VolumeName);
- /* If permitted, create a label */
- if (dev->capabilities & CAP_LABEL) {
- Dmsg0(190, "Create volume label\n");
- if (!write_volume_label_to_dev(jcr, (DEVRES *)dev->device, jcr->VolumeName,
- jcr->pool_name)) {
- goto mount_next_vol;
- }
- Jmsg(jcr, M_INFO, 0, _("Created Volume label %s on device %s.\n"),
- jcr->VolumeName, dev_name(dev));
- goto read_volume; /* read label we just wrote */
- }
- /* NOTE! Fall-through wanted. */
- default:
- /* Send error message */
- Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
- if (autochanger) {
- Jmsg(jcr, M_ERROR, 0, _("Autochanger Volume %s not found in slot %d.\n\
- Setting slot to zero in catalog.\n"),
- jcr->VolumeName, jcr->VolCatInfo.Slot);
- jcr->VolCatInfo.Slot = 0; /* invalidate slot */
- dir_update_volume_info(jcr, &jcr->VolCatInfo, 1); /* set slot */
- }
+ memcpy(&VolCatInfo, &dcr->VolCatInfo, sizeof(VolCatInfo));
+ /* Check if this is a valid Volume in the pool */
+ bstrncpy(dcr->VolumeName, dev->VolHdr.VolName, sizeof(dcr->VolumeName));
+ if (!dir_get_volume_info(dcr, GET_VOL_INFO_FOR_WRITE)) {
+ bstrncpy(dev->BadVolName, dev->VolHdr.VolName, sizeof(dev->BadVolName));
+ Jmsg(jcr, M_WARNING, 0, _("Director wanted Volume \"%s\".\n"
+ " Current Volume \"%s\" not acceptable because:\n"
+ " %s"),
+ VolCatInfo.VolCatName, dev->VolHdr.VolName,
+ jcr->dir_bsock->msg);
+ /* Restore desired volume name, note device info out of sync */
+ memcpy(&dcr->VolCatInfo, &VolCatInfo, sizeof(dcr->VolCatInfo));
+ ask = true;
+ goto mount_next_vol;
+ }
+ Dmsg1(100, "want new name=%s\n", dcr->VolumeName);
+ memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
+ recycle = strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0;
+ break; /* got a Volume */
+ /*
+ * At this point, we assume we have a blank tape mounted.
+ */
+ case VOL_NO_LABEL:
+ case VOL_IO_ERROR:
+ /*
+ * If permitted, we label the device, make sure we can do
+ * it by checking that the VolCatBytes is zero => not labeled,
+ * once the Volume is labeled we don't want to label another
+ * blank tape with the same name. For disk, we go ahead and
+ * label it anyway, because the OS insures that there is only
+ * one Volume with that name.
+ * As noted above, at this point dcr->VolCatInfo has what
+ * the Director wants and dev->VolCatInfo has info on the
+ * previous tape (or nothing).
+ */
+ if (dev_cap(dev, CAP_LABEL) && (dcr->VolCatInfo.VolCatBytes == 0 ||
+ (!dev->is_tape() && strcmp(dcr->VolCatInfo.VolCatStatus,
+ "Recycle") == 0))) {
+ Dmsg0(100, "Create volume label\n");
+ /* Create a new Volume label and write it to the device */
+ if (!write_new_volume_label_to_dev(dcr, dcr->VolumeName,
+ dcr->pool_name)) {
+ Dmsg0(100, "!write_vol_label\n");