X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Flabel.c;h=e7fb9ee89f2b1cf90e90988728dcd3d9b14d067b;hb=37190d54ceff7f2b45a58a1c6241688cc5cba1c2;hp=26db7b941dd01ddb17b19e695a21beafe9dc2ffb;hpb=ef440f6ff950294887e1e61e8304aba12de37996;p=bacula%2Fbacula diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 26db7b941d..e7fb9ee89f 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -1,16 +1,7 @@ -/* - * - * label.c Bacula routines to handle labels - * - * Kern Sibbald, MM - * - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2006 Free Software Foundation Europe e.V. + Copyright (C) 2000-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -34,6 +25,15 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * label.c Bacula routines to handle labels + * + * Kern Sibbald, MM + * + * + * Version $Id$ + */ #include "bacula.h" /* pull in global headers */ #include "stored.h" /* pull in Storage Deamon headers */ @@ -122,7 +122,7 @@ int read_dev_volume_label(DCR *dcr) want_ansi_label = dcr->VolCatInfo.LabelType != B_BACULA_LABEL || dcr->device->label_type != B_BACULA_LABEL; - if (want_ansi_label || dev_cap(dev, CAP_CHECKLABELS)) { + if (want_ansi_label || dev->has_cap(CAP_CHECKLABELS)) { stat = read_ansi_ibm_label(dcr); /* If we want a label and didn't find it, return error */ if (want_ansi_label && stat != VOL_OK) { @@ -213,7 +213,12 @@ int read_dev_volume_label(DCR *dcr) } dev->set_labeled(); /* set has Bacula label */ - new_volume(dcr, dev->VolHdr.VolumeName); + if (reserve_volume(dcr, dev->VolHdr.VolumeName) == NULL) { + Mmsg2(jcr->errmsg, _("Could not reserve volume %s on %s\n"), + dev->VolHdr.VolumeName, dev->print_name()); + stat = VOL_NAME_ERROR; + goto bail_out; + } /* Compare Volume Names */ Dmsg2(30, "Compare Vol names: VolName=%s hdr=%s\n", VolName?VolName:"*", dev->VolHdr.VolumeName); @@ -239,7 +244,7 @@ int read_dev_volume_label(DCR *dcr) } Dmsg0(30, "Leave read_volume_label() VOL_OK\n"); /* If we are a streaming device, we only get one chance to read */ - if (!dev_cap(dev, CAP_STREAM)) { + if (!dev->has_cap(CAP_STREAM)) { dev->rewind(dcr); if (have_ansi_label) { stat = read_ansi_ibm_label(dcr); @@ -316,8 +321,8 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, goto bail_out; } - if (relabel) { - dev->close_part(dcr); /* make sure closed for rename */ + if (relabel && !dev->is_tape()) { + dev->close_part(dcr); /* make sure DVD/file closed for rename */ } /* Set the new filename for open, ... */ @@ -332,8 +337,7 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, } Dmsg1(150, "Label type=%d\n", dev->label_type); if (!dev->rewind(dcr)) { - free_volume(dev); - memset(&dev->VolHdr, 0, sizeof(dev->VolHdr)); + dev->clear_volhdr(); Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->print_errmsg()); if (!forge_on) { goto bail_out; @@ -394,13 +398,17 @@ bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, if (debug_level >= 20) { dump_volume_label(dev); } - new_volume(dcr, VolName); + if (reserve_volume(dcr, VolName) == NULL) { + Mmsg2(dcr->jcr->errmsg, _("Could not reserve volume %s on %s\n"), + dev->VolHdr.VolumeName, dev->print_name()); + goto bail_out; + } + dev->clear_append(); /* remove append since this is PRE_LABEL */ return true; bail_out: - free_volume(dev); - memset(&dev->VolHdr, 0, sizeof(dev->VolHdr)); + dev->clear_volhdr(); dev->clear_append(); /* remove append since this is PRE_LABEL */ return false; } @@ -419,7 +427,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) if (dev->open(dcr, OPEN_READ_WRITE) < 0) { return false; } - Dmsg2(190, "set append found freshly labeled volume. fd=%d dev=%x\n", dev->fd, dev); + 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 (!write_volume_label_to_block(dcr)) { @@ -436,7 +444,7 @@ 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 (!dev_cap(dev, CAP_STREAM)) { + if (!dev->has_cap(CAP_STREAM)) { if (!dev->rewind(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Rewind error on device %s: ERR=%s\n"), dev->print_name(), dev->print_errmsg()); @@ -471,7 +479,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) } /* Attempt write to check write permission */ - Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd); + Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd()); if (!write_block_to_dev(dcr)) { Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s: ERR=%s\n"), dev->print_name(), dev->print_errmsg()); @@ -571,7 +579,7 @@ static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec) rec->FileIndex = dev->VolHdr.LabelType; rec->VolSessionId = jcr->VolSessionId; rec->VolSessionTime = jcr->VolSessionTime; - rec->Stream = jcr->NumVolumes; + rec->Stream = jcr->NumWriteVolumes; Dmsg2(150, "Created Vol label rec: FI=%s len=%d\n", FI_to_ascii(buf, rec->FileIndex), rec->data_len); } @@ -589,8 +597,7 @@ void create_volume_label(DEVICE *dev, const char *VolName, ASSERT(dev != NULL); - free_volume(dev); /* release any old volume */ - memset(&dev->VolHdr, 0, sizeof(dev->VolHdr)); + dev->clear_volhdr(); /* release any old volume */ bstrncpy(dev->VolHdr.Id, BaculaId, sizeof(dev->VolHdr.Id)); dev->VolHdr.VerNum = BaculaTapeVersion;