#include "bacula.h" /* pull in global headers */
#include "stored.h" /* pull in Storage Deamon headers */
-/* Forward referenced functions */
+/* Forward referenced routines */
+static void mark_volume_in_error(JCR *jcr, DEVICE *dev);
/*
*/
int mount_next_write_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, int release)
{
- int retry = 0, autochanger;
- bool ask, recycle;
+ int retry = 0;
+ bool ask = false, recycle, autochanger;
+ int vol_label_status;
Dmsg0(100, "Enter mount_next_volume()\n");
+ /*
+ * Attempt to mount the next volume. If something non-fatal goes
+ * wrong, we come back here to re-try (new op messages, re-read
+ * Volume, ...)
+ */
mount_next_vol:
if (retry++ > 5) {
Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount device %s.\n"),
Jmsg(jcr, M_FATAL, 0, _("Job %d canceled.\n"), jcr->JobId);
return 0;
}
- autochanger = 0;
- recycle = ask = false;
+ autochanger = false; /* Assume no autochanger */
+ recycle = false;
if (release) {
Dmsg0(100, "mount_next_volume release=1\n");
release_volume(jcr, dev);
* It assumes that the device is not already in use!
*
*/
-
-
dev->state &= ~(ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF);
- for ( ;; ) {
- int vol_label_status;
- autochanger = autoload_device(jcr, dev, 1, NULL);
- Dmsg1(100, "autoload_dev returns %d\n", autochanger);
-
- /*
- * If we autochanged to correct Volume or (we have not just
- * released the Volume AND we can automount) we go ahead
- * and read the label. If there is no tape in the drive,
- * we will err, recurse and ask the operator the next time.
- */
- if (autochanger || (!release && dev_is_tape(dev) && dev_cap(dev, CAP_AUTOMOUNT))) {
- ask = false; /* don't ask SYSOP this time */
- }
- Dmsg2(100, "Ask=%d autochanger=%d\n", ask, autochanger);
- release = 1; /* release next time if we "recurse" */
+ autochanger = autoload_device(jcr, dev, 1, NULL);
+ Dmsg1(100, "autoload_dev returns %d\n", autochanger);
+ /*
+ * If we autochanged to correct Volume or (we have not just
+ * released the Volume AND we can automount) we go ahead
+ * and read the label. If there is no tape in the drive,
+ * we will err, recurse and ask the operator the next time.
+ */
+ if (autochanger || (!release && dev_is_tape(dev) && dev_cap(dev, CAP_AUTOMOUNT))) {
+ ask = false; /* don't ask SYSOP this time */
+ }
+ Dmsg2(100, "Ask=%d autochanger=%d\n", ask, autochanger);
+ release = true; /* release next time if we "recurse" */
- if (ask && !dir_ask_sysop_to_mount_next_volume(jcr, dev)) {
- Dmsg0(100, "Error return ask_sysop ...\n");
- return 0; /* error return */
- }
- Dmsg1(100, "want vol=%s\n", jcr->VolumeName);
+ if (ask && !dir_ask_sysop_to_mount_next_volume(jcr, dev)) {
+ Dmsg0(100, "Error return ask_sysop ...\n");
+ return 0; /* error return */
+ }
+ Dmsg1(100, "want vol=%s\n", jcr->VolumeName);
- /* Open device */
- if (!(dev_state(dev, ST_OPENED))) {
- int mode;
- if (dev_cap(dev, CAP_STREAM)) {
- mode = OPEN_WRITE_ONLY;
- } else {
- mode = OPEN_READ_WRITE;
- }
- if (open_dev(dev, jcr->VolCatInfo.VolCatName, mode) < 0) {
- Jmsg2(jcr, M_FATAL, 0, _("Unable to open device %s. ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- return 0;
- }
- }
+ /* Open device */
+ if (!(dev_state(dev, ST_OPENED))) {
+ int mode;
+ if (dev_cap(dev, CAP_STREAM)) {
+ mode = OPEN_WRITE_ONLY;
+ } else {
+ mode = OPEN_READ_WRITE;
+ }
+ if (open_dev(dev, jcr->VolCatInfo.VolCatName, mode) < 0) {
+ Jmsg2(jcr, M_FATAL, 0, _("Unable to open device %s. ERR=%s\n"),
+ dev_name(dev), strerror_dev(dev));
+ return 0;
+ }
+ }
- /*
- * Now make sure we have the right tape mounted
- */
+ /*
+ * Now make sure we have the right tape mounted
+ */
read_volume:
- /*
- * If we are writing to a stream device, ASSUME the volume label
- * is correct.
- */
- if (dev_cap(dev, CAP_STREAM)) {
- vol_label_status = VOL_OK;
- create_volume_label(dev, jcr->VolumeName, "Default");
- dev->VolHdr.LabelType = PRE_LABEL;
- } else {
- vol_label_status = read_dev_volume_label(jcr, dev, block);
- }
+ /*
+ * If we are writing to a stream device, ASSUME the volume label
+ * is correct.
+ */
+ if (dev_cap(dev, CAP_STREAM)) {
+ vol_label_status = VOL_OK;
+ create_volume_label(dev, jcr->VolumeName, "Default");
+ dev->VolHdr.LabelType = PRE_LABEL;
+ } else {
+ vol_label_status = read_dev_volume_label(jcr, dev, block);
+ }
- Dmsg2(100, "dirVol=%s dirStat=%s\n", jcr->VolumeName,
- jcr->VolCatInfo.VolCatStatus);
- /*
- * At this point, dev->VolCatInfo has what is in the drive, if anything,
- * and jcr->VolCatInfo has what the Director wants.
- */
- switch (vol_label_status) {
- case VOL_OK:
- Dmsg1(100, "Vol OK name=%s\n", jcr->VolumeName);
- memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(jcr->VolCatInfo));
- recycle = strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0;
- break; /* got a Volume */
- case VOL_NAME_ERROR:
- VOLUME_CAT_INFO VolCatInfo;
+ Dmsg2(100, "dirVol=%s dirStat=%s\n", jcr->VolumeName,
+ jcr->VolCatInfo.VolCatStatus);
+ /*
+ * At this point, dev->VolCatInfo has what is in the drive, if anything,
+ * and jcr->VolCatInfo has what the Director wants.
+ */
+ switch (vol_label_status) {
+ case VOL_OK:
+ Dmsg1(100, "Vol OK name=%s\n", jcr->VolumeName);
+ memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(jcr->VolCatInfo));
+ recycle = strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0;
+ break; /* got a Volume */
+ case VOL_NAME_ERROR:
+ VOLUME_CAT_INFO VolCatInfo;
- Dmsg1(100, "Vol NAME Error Name=%s\n", jcr->VolumeName);
- /*
- * OK, we got a different volume mounted. First save the
- * requested Volume info (jcr) structure, then query if
- * this volume is really OK. If not, put back the desired
- * volume name and continue.
- */
- memcpy(&VolCatInfo, &jcr->VolCatInfo, sizeof(VolCatInfo));
- /* Check if this is a valid Volume in the pool */
- pm_strcpy(&jcr->VolumeName, dev->VolHdr.VolName);
- if (!dir_get_volume_info(jcr, GET_VOL_INFO_FOR_WRITE)) {
- Mmsg(&jcr->errmsg, _("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(&jcr->VolCatInfo, &VolCatInfo, sizeof(jcr->VolCatInfo));
- goto mount_error;
- }
- Dmsg1(100, "want new name=%s\n", jcr->VolumeName);
- memcpy(&dev->VolCatInfo, &jcr->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.
+ Dmsg1(100, "Vol NAME Error Name=%s\n", jcr->VolumeName);
+ /*
+ * OK, we got a different volume mounted. First save the
+ * requested Volume info (jcr) structure, then query if
+ * this volume is really OK. If not, put back the desired
+ * volume name and continue.
*/
- 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 jcr->VolCatInfo has what
- * the Director wants and dev->VolCatInfo has info on the
- * previous tape (or nothing).
- */
- if (dev_cap(dev, CAP_LABEL) && (jcr->VolCatInfo.VolCatBytes == 0 ||
- (!dev_is_tape(dev) && strcmp(jcr->VolCatInfo.VolCatStatus,
- "Recycle") == 0))) {
- Dmsg0(100, "Create volume label\n");
- if (!write_volume_label_to_dev(jcr, (DEVRES *)dev->device, jcr->VolumeName,
- jcr->pool_name)) {
- Dmsg0(100, "!write_vol_label\n");
- goto mount_next_vol;
- }
- Dmsg0(100, "dir_update_vol_info. Set Append\n");
- /* Copy Director's info into the device info */
- memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(dev->VolCatInfo));
- dir_update_volume_info(jcr, dev, 1); /* indicate tape labeled */
- Jmsg(jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"),
- jcr->VolumeName, dev_name(dev));
- goto read_volume; /* read label we just wrote */
- }
- /* NOTE! Fall-through wanted. */
- case VOL_NO_MEDIA:
- default:
-mount_error:
- /* Send error message */
- Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+ memcpy(&VolCatInfo, &jcr->VolCatInfo, sizeof(VolCatInfo));
+ /* Check if this is a valid Volume in the pool */
+ pm_strcpy(&jcr->VolumeName, dev->VolHdr.VolName);
+ if (!dir_get_volume_info(jcr, GET_VOL_INFO_FOR_WRITE)) {
+ 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(&jcr->VolCatInfo, &VolCatInfo, sizeof(jcr->VolCatInfo));
ask = true;
- /* was - goto ask_again; */
goto mount_next_vol;
}
- break;
+ Dmsg1(100, "want new name=%s\n", jcr->VolumeName);
+ memcpy(&dev->VolCatInfo, &jcr->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 jcr->VolCatInfo has what
+ * the Director wants and dev->VolCatInfo has info on the
+ * previous tape (or nothing).
+ */
+ if (dev_cap(dev, CAP_LABEL) && (jcr->VolCatInfo.VolCatBytes == 0 ||
+ (!dev_is_tape(dev) && strcmp(jcr->VolCatInfo.VolCatStatus,
+ "Recycle") == 0))) {
+ Dmsg0(100, "Create volume label\n");
+ if (!write_volume_label_to_dev(jcr, (DEVRES *)dev->device, jcr->VolumeName,
+ jcr->pool_name)) {
+ Dmsg0(100, "!write_vol_label\n");
+ goto mount_next_vol;
+ }
+ Dmsg0(100, "dir_update_vol_info. Set Append\n");
+ /* Copy Director's info into the device info */
+ memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(dev->VolCatInfo));
+ dir_update_volume_info(jcr, dev, 1); /* indicate tape labeled */
+ Jmsg(jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"),
+ jcr->VolumeName, dev_name(dev));
+ goto read_volume; /* read label we just wrote */
+ }
+ /* NOTE! Fall-through wanted. */
+ case VOL_NO_MEDIA:
+ default:
+ /* Send error message */
+ Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+ ask = true;
+ goto mount_next_vol;
}
/*
Jmsg(jcr, M_INFO, 0, _("Wrote label to prelabeled Volume \"%s\" on device %s\n"),
jcr->VolumeName, dev_name(dev));
}
+ /*
+ * End writing real Volume label (from pre-labeled tape), or recycling
+ * the volume.
+ */
} else {
/*
if (!eod_dev(dev)) {
Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data %s. ERR=%s\n"),
dev_name(dev), strerror_dev(dev));
- Jmsg(jcr, M_INFO, 0, _("Marking Volume \"%s\" in Error in Catalog.\n"),
- jcr->VolumeName);
- bstrncpy(dev->VolCatInfo.VolCatStatus, "Error", sizeof(dev->VolCatInfo.VolCatStatus));
- Dmsg0(100, "dir_update_vol_info. Set Error.\n");
- dir_update_volume_info(jcr, dev, 0);
+ mark_volume_in_error(jcr, dev);
goto mount_next_vol;
}
/* *****FIXME**** we should do some checking for files too */
Jmsg(jcr, M_ERROR, 0, _("I canot write on this volume because:\n\
The number of files mismatch! Volume=%u Catalog=%u\n"),
dev_file(dev), dev->VolCatInfo.VolCatFiles);
- bstrncpy(dev->VolCatInfo.VolCatStatus, "Error", sizeof(dev->VolCatInfo.VolCatStatus));
- Dmsg0(100, "dir_update_vol_info. Set Error.\n");
- dir_update_volume_info(jcr, dev, 0);
+ mark_volume_in_error(jcr, dev);
goto mount_next_vol;
}
}
return 1;
}
+static void mark_volume_in_error(JCR *jcr, DEVICE *dev)
+{
+ Jmsg(jcr, M_INFO, 0, _("Marking Volume \"%s\" in Error in Catalog.\n"),
+ jcr->VolumeName);
+ bstrncpy(dev->VolCatInfo.VolCatStatus, "Error", sizeof(dev->VolCatInfo.VolCatStatus));
+ Dmsg0(100, "dir_update_vol_info. Set Error.\n");
+ dir_update_volume_info(jcr, dev, 0);
+}
+/*
+ * If we are reading, we come here at the end of the tape
+ * and see if there are more volumes to be mounted.
+ */
int mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
{
Dmsg2(90, "NumVolumes=%d CurVolume=%d\n", jcr->NumVolumes, jcr->CurVolume);
*/
void release_volume(JCR *jcr, DEVICE *dev)
{
-
if (jcr->WroteVol) {
Jmsg0(jcr, M_ERROR, 0, "Hey!!!!! WroteVol non-zero !!!!!\n");
}
memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo));
memset(&jcr->VolCatInfo, 0, sizeof(jcr->VolCatInfo));
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
- dev->state &= ~ST_LABEL; /* label not yet read */
+ /* Force re-read of label */
+ dev->state &= ~(ST_LABEL|ST_READ|ST_APPEND);
jcr->VolumeName[0] = 0;
if ((dev->state & ST_OPENED) &&