recycle = ask = autochanger = 0;
if (release) {
Dmsg0(100, "mount_next_volume release=1\n");
- /*
- * First erase all memory of the current volume
- */
- dev->block_num = dev->file = 0;
- dev->EndBlock = dev->EndFile = 0;
- 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 */
- jcr->VolumeName[0] = 0;
-
- if (!dev_is_tape(dev) || !dev_cap(dev, CAP_ALWAYSOPEN)) {
- if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
- offline_dev(dev);
- }
- close_dev(dev);
- }
-
- /* If we have not closed the device, then at least rewind the tape */
- if (dev->state & ST_OPENED) {
- if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
- offline_dev(dev);
- }
- if (!rewind_dev(dev)) {
- Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device %s. ERR=%s\n"),
- dev_name(dev), strerror_dev(dev));
- }
- }
+ release_volume(jcr, dev);
ask = 1; /* ask operator to mount tape */
}
/*
* Get Director's idea of what tape we should have mounted.
*/
- if (!dir_find_next_appendable_volume(jcr)) {
- ask = 1; /* we must ask */
- Dmsg0(100, "did not find next volume. Must ask.\n");
+ if (!dir_find_next_appendable_volume(jcr) &&
+ !dir_ask_sysop_to_mount_next_volume(jcr, dev)) {
+ return 0;
}
Dmsg2(100, "After find_next_append. Vol=%s Slot=%d\n",
jcr->VolCatInfo.VolCatName, jcr->VolCatInfo.Slot);
- release = 1; /* release if we "recurse" */
/*
* Get next volume and ready it for append
dev->state &= ~(ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF);
- jcr->VolFirstFile = jcr->JobFiles; /* first update of Vol FileIndex */
for ( ;; ) {
int vol_label_status;
autochanger = autoload_device(jcr, dev, 1, NULL);
- if (autochanger) {
- ask = 0; /* if autochange no need to ask sysop */
+
+ /*
+ * 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 = 0; /* don't ask SYSOP this time */
}
+ release = 1; /* release next time if we "recurse" */
+
+ask_again:
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 */
- for ( ; !(dev->state & ST_OPENED); ) {
+ if (!(dev->state & ST_OPENED)) {
int mode;
if (dev_cap(dev, CAP_STREAM)) {
mode = OPEN_WRITE_ONLY;
} else {
vol_label_status = read_dev_volume_label(jcr, dev, block);
}
+ /*
+ * 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));
- if (strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0) {
- recycle = 1;
- }
- break; /* got it */
- case VOL_NAME_ERROR:
- Dmsg1(100, "Vol NAME Error Name=%s\n", jcr->VolumeName);
- /*
- * OK, we got a different volume mounted. First save the
- * requested Volume info in the dev structure, then query if
- * this volume is really OK. If not, put back the desired
- * volume name and continue.
- */
- memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(jcr->VolCatInfo));
- /* Check if this is a valid Volume in the pool */
- bstrncpy(jcr->VolumeName, dev->VolHdr.VolName, sizeof(jcr->VolumeName));
- if (!dir_get_volume_info(jcr, 1)) {
- Mmsg(&jcr->errmsg, _("Wanted Volume \"%s\".\n"
- " Current Volume \"%s\" not acceptable because:\n"
- " %s"),
- dev->VolCatInfo.VolCatName, dev->VolHdr.VolName,
- jcr->dir_bsock->msg);
- /* Restore desired volume name, note device info out of sync */
- memcpy(&jcr->VolCatInfo, &dev->VolCatInfo, sizeof(jcr->VolCatInfo));
- goto mount_error;
- }
- Dmsg1(100, "want new name=%s\n", jcr->VolumeName);
- memcpy(&dev->VolCatInfo, &jcr->VolCatInfo, sizeof(jcr->VolCatInfo));
- break;
+ case VOL_OK:
+ Dmsg1(100, "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 a Volume */
+ case VOL_NAME_ERROR:
+ VOLUME_CAT_INFO VolCatInfo;
- 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_cap(dev, CAP_LABEL)) {
- 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;
- }
- 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. */
- default:
-mount_error:
- /* Send error message */
- Jmsg1(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->VolCatInfo.VolCatName, jcr->VolCatInfo.Slot);
- jcr->VolCatInfo.Slot = 0; /* invalidate slot */
- Dmsg0(200, "update vol info in mount\n");
- dir_update_volume_info(jcr, &jcr->VolCatInfo, 1); /* set slot */
+ 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(jcr->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(jcr->VolCatInfo));
+ break; /* got a Volume */
+
+ 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_cap(dev, CAP_LABEL)) {
+ 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, "Default\n");
- goto mount_next_vol;
+ 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. */
+ default:
+mount_error:
+ /* Send error message */
+ Jmsg1(jcr, M_WARNING, 0, "%s", jcr->errmsg);
+ Dmsg0(100, "Default\n");
+ ask = 1;
+ goto ask_again;
}
break;
}
dev->VolCatInfo.VolCatFiles = 0;
dev->VolCatInfo.VolCatErrors = 0;
dev->VolCatInfo.VolCatBlocks = 0;
+ dev->VolCatInfo.VolCatRBytes = 0;
if (recycle) {
dev->VolCatInfo.VolCatMounts++;
dev->VolCatInfo.VolCatRecycles++;
dev_file(dev));
} else {
Jmsg(jcr, M_ERROR, 0, _("I canot write on this volume because:\n\
-The number of files mismatch! Volume=%d Catalog=%d\n"),
+The number of files mismatch! Volume=%u Catalog=%u\n"),
dev_file(dev), dev->VolCatInfo.VolCatFiles);
strcpy(dev->VolCatInfo.VolCatStatus, "Error");
Dmsg0(200, "dir_update_vol_info. Set Error.\n");
close_dev(dev);
dev->state &= ~ST_READ;
if (!acquire_device_for_read(jcr, dev, block)) {
- Emsg2(M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev),
+ Jmsg2(jcr, M_FATAL, 0, "Cannot open Dev=%s, Vol=%s\n", dev_name(dev),
jcr->VolumeName);
return 0;
}
Dmsg0(90, "End of Device reached.\n");
return 0;
}
+
+/*
+ * Either because we are going to hang a new volume, or because
+ * of explicit user request, we release the current volume.
+ */
+void release_volume(JCR *jcr, DEVICE *dev)
+{
+
+ if (jcr->WroteVol) {
+ Jmsg0(jcr, M_ERROR, 0, "Hey!!!!! WroteVol non-zero !!!!!\n");
+ }
+ /*
+ * First erase all memory of the current volume
+ */
+ dev->block_num = dev->file = 0;
+ dev->EndBlock = dev->EndFile = 0;
+ 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 */
+ jcr->VolumeName[0] = 0;
+
+ if (!dev_is_tape(dev) || !dev_cap(dev, CAP_ALWAYSOPEN)) {
+ offline_or_rewind_dev(dev);
+ close_dev(dev);
+ }
+
+ /* If we have not closed the device, then at least rewind the tape */
+ if (dev->state & ST_OPENED) {
+ offline_or_rewind_dev(dev);
+ }
+}