X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Flabel.c;h=32a65297bfd00756a23effb430fa252c59cec531;hb=b22b260eaa7fb9f122523fff0e324dca5904b97f;hp=43afb8933abaac0f89bef5d68371351f5cbd843b;hpb=a18896757d81b61a990755940b0f4ce600911192;p=bacula%2Fbacula diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 43afb8933a..32a65297bf 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -28,9 +28,6 @@ /* Forward referenced functions */ static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec); -extern char my_name[]; -extern int debug_level; - /* * Read the volume label * @@ -166,6 +163,7 @@ int read_dev_volume_label(DCR *dcr) empty_block(block); return VOL_OK; } + Dmsg0(100, "No volume label - bailing out\n"); stat = VOL_NO_LABEL; goto bail_out; } @@ -291,7 +289,8 @@ bool write_volume_label_to_block(DCR *dcr) * * This routine should be used only when labeling a blank tape. */ -bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName) +bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, + const char *PoolName, bool dvdnow) { DEVICE *dev = dcr->dev; @@ -315,8 +314,8 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *Po } } - /* Create PRE_LABEL */ - create_volume_label(dev, VolName, PoolName); + /* Create PRE_LABEL or VOL_LABEL if DVD */ + create_volume_label(dev, VolName, PoolName, dvdnow); /* * If we have already detected an ANSI label, re-read it @@ -349,6 +348,15 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *Po Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror()); goto bail_out; } + + /* Now commit block to DVD if we should write now */ + if (dev->is_dvd() && dvdnow) { + if (!dvd_write_part(dcr)) { + Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror()); + goto bail_out; + } + } + Dmsg0(99, " Wrote block to device\n"); if (dev->weof(1)) { @@ -380,27 +388,20 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) { DEVICE *dev = dcr->dev; JCR *jcr = dcr->jcr; - bool can_write = true; if (dev->open(dcr, OPEN_READ_WRITE) < 0) { - /* If device is DVD, attempt to create it */ - if (!dev->is_dvd()) { - return false; - } - if (dev->open(dcr, CREATE_READ_WRITE) < 0) { - /* We forge on for a DVD but don't do any writing */ - can_write = false; - } + return false; } Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, dev); dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */ dev->set_append(); - if (can_write) { - if (!write_volume_label_to_block(dcr)) { - Dmsg0(200, "Error from write volume label.\n"); - return false; - } + if (!write_volume_label_to_block(dcr)) { + Dmsg0(200, "Error from write volume label.\n"); + return false; } + + dev->VolCatInfo.VolCatBytes = 0; /* reset byte count */ + /* * If we are not dealing with a streaming device, * write the block now to ensure we have write permission. @@ -408,15 +409,17 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) * We do not write the block now if this is an ANSI label. This * avoids re-writing the ANSI label, which we do not want to do. */ - if (can_write && !dev_cap(dev, CAP_STREAM)) { + if (!dev_cap(dev, CAP_STREAM)) { if (!dev->rewind(dcr)) { - Jmsg2(jcr, M_WARNING, 0, _("Rewind error on device %s: ERR=%s\n"), + Jmsg2(jcr, M_FATAL, 0, _("Rewind error on device %s: ERR=%s\n"), dev->print_name(), dev->bstrerror()); + return false; } if (recycle) { if (!dev->truncate(dcr)) { - Jmsg2(jcr, M_WARNING, 0, _("Truncate error on device %s: ERR=%s\n"), + Jmsg2(jcr, M_FATAL, 0, _("Truncate error on device %s: ERR=%s\n"), dev->print_name(), dev->bstrerror()); + return false; } } @@ -446,7 +449,6 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) /* Set or reset Volume statistics */ dev->VolCatInfo.VolCatJobs = 0; dev->VolCatInfo.VolCatFiles = 0; - dev->VolCatInfo.VolCatBytes = 1; dev->VolCatInfo.VolCatErrors = 0; dev->VolCatInfo.VolCatBlocks = 0; dev->VolCatInfo.VolCatRBytes = 0; @@ -475,7 +477,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) * End writing real Volume label (from pre-labeled tape), or recycling * the volume. */ - Dmsg0(200, "OK from rewite vol label.\n"); + Dmsg0(200, "OK from rewrite vol label.\n"); return true; } @@ -544,7 +546,8 @@ static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec) /* * Create a volume label in memory */ -void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName) +void create_volume_label(DEVICE *dev, const char *VolName, + const char *PoolName, bool dvdnow) { DEVRES *device = (DEVRES *)dev->device; @@ -557,7 +560,12 @@ void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName) bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id)); dev->VolHdr.VerNum = BaculaTapeVersion; - dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */ + if (dev->is_dvd() && dvdnow) { + /* We do not want to re-label a DVD so write VOL_LABEL now */ + dev->VolHdr.LabelType = VOL_LABEL; + } else { + dev->VolHdr.LabelType = PRE_LABEL; /* Mark tape as unused */ + } bstrncpy(dev->VolHdr.VolumeName, VolName, sizeof(dev->VolHdr.VolumeName)); bstrncpy(dev->VolHdr.PoolName, PoolName, sizeof(dev->VolHdr.PoolName)); bstrncpy(dev->VolHdr.MediaType, device->media_type, sizeof(dev->VolHdr.MediaType)); @@ -698,15 +706,15 @@ bool write_session_label(DCR *dcr, int label) return false; } - Dmsg6(20, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d " + Dmsg6(50, "Write sesson_label record JobId=%d FI=%s SessId=%d Strm=%s len=%d " "remainder=%d\n", jcr->JobId, FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId, stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len, rec->remainder); free_record(rec); - Dmsg2(20, "Leave write_session_label Block=%d File=%d\n", - dev->block_num, dev->file); + Dmsg2(50, "Leave write_session_label Block=%ud File=%ud\n", + dev->get_block(), dev->get_file()); return true; }