From: Kern Sibbald Date: Fri, 16 Jul 2004 16:34:56 +0000 (+0000) Subject: More dcr updates X-Git-Tag: Release-1.35.1~64 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1ebe4fb0e7f3e3f6873b9cb573cc858a780cb908;p=bacula%2Fbacula More dcr updates git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1470 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 727c23ef66..026fccc29f 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -319,7 +319,7 @@ DCR *acquire_device_for_append(JCR *jcr) } if (do_mount || recycle) { - if (!mount_next_write_volume(jcr, dev, dcr->block, release)) { + if (!mount_next_write_volume(dcr, dcr->block, release)) { if (!job_canceled(jcr)) { /* Reduce "noise" -- don't print if job canceled */ Jmsg(jcr, M_FATAL, 0, _("Could not ready device \"%s\" for append.\n"), diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index f311dd9765..cbe87c3be0 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -82,7 +82,7 @@ int do_append_data(JCR *jcr) /* * Write Begin Session Record */ - if (!write_session_label(jcr, block, SOS_LABEL)) { + if (!write_session_label(dcr, block, SOS_LABEL)) { Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"), strerror_dev(dev)); set_jcr_job_status(jcr, JS_ErrorTerminated); @@ -238,7 +238,7 @@ int do_append_data(JCR *jcr) * if we are at the end of the tape or we got a fatal I/O error. */ if (ok || dev_can_write(dev)) { - if (!write_session_label(jcr, block, EOS_LABEL)) { + if (!write_session_label(dcr, block, EOS_LABEL)) { Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev)); set_jcr_job_status(jcr, JS_ErrorTerminated); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index e875ebe1e8..ea2e4ea356 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -337,7 +337,7 @@ static void labelcmd() } } rewind_dev(dev); - write_new_volume_label_to_dev(jcr, jcr->device->dev, cmd, "Default"); + write_new_volume_label_to_dev(dcr, cmd, "Default"); Pmsg1(-1, "Wrote Volume label for volume \"%s\".\n", cmd); } @@ -633,7 +633,7 @@ static int re_read_block_test() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } else { @@ -644,7 +644,7 @@ static int re_read_block_test() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } else { @@ -655,7 +655,7 @@ static int re_read_block_test() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } else { @@ -752,7 +752,7 @@ static int write_read_test() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } @@ -768,7 +768,7 @@ static int write_read_test() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } @@ -860,7 +860,7 @@ static int position_test() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } @@ -876,7 +876,7 @@ static int position_test() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } @@ -1444,7 +1444,7 @@ static void wrcmd() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } else { @@ -1732,7 +1732,7 @@ This may take a long time -- hours! ...\n\n"); /* * Write Begin Session Record */ - if (!write_session_label(jcr, block, SOS_LABEL)) { + if (!write_session_label(dcr, block, SOS_LABEL)) { set_jcr_job_status(jcr, JS_ErrorTerminated); Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"), strerror_dev(dev)); @@ -1849,12 +1849,12 @@ This may take a long time -- hours! ...\n\n"); } else if (!ok) { set_jcr_job_status(jcr, JS_ErrorTerminated); } - if (!write_session_label(jcr, block, EOS_LABEL)) { + if (!write_session_label(dcr, block, EOS_LABEL)) { Pmsg1(000, _("Error writting end session label. ERR=%s\n"), strerror_dev(dev)); ok = false; } /* Write out final block of this session */ - if (!write_block_to_device(jcr->dcr, block)) { + if (!write_block_to_device(dcr, block)) { Pmsg0(-1, _("Set ok=false after write_block_to_device.\n")); ok = false; } @@ -2158,7 +2158,7 @@ static int flush_block(DEV_BLOCK *block, int dump) /* Copy block */ this_file = dev->file; this_block_num = dev->block_num; - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg3(000, "Last block at: %u:%u this_dev_block_num=%d\n", last_file, last_block_num, this_block_num); if (vol_num == 1) { @@ -2269,7 +2269,7 @@ static void qfillcmd() Pmsg0(0, _("Error writing record to block.\n")); goto bail_out; } - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Pmsg0(0, _("Error writing block to device.\n")); goto bail_out; } @@ -2372,7 +2372,7 @@ static void bfill_cmd() *p = block_num; block->binbuf = block->buf_len; block->bufp = block->buf + block->binbuf; - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { break; } if ((block_num++ % 100) == 0) { diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 555118c89f..8596c055af 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -131,7 +131,7 @@ bool fixup_device_block_write_error(DCR *dcr, DEV_BLOCK *block) edit_uint64_with_commas(dev->VolCatInfo.VolCatBlocks, b2), bstrftime(dt, sizeof(dt), time(NULL))); - if (!mount_next_write_volume(jcr, dev, label_blk, 1)) { + if (!mount_next_write_volume(dcr, label_blk, 1)) { free_block(label_blk); P(dev->mutex); unblock_device(dev); diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 4d340ceb3d..4695f731f0 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -402,7 +402,7 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname, /* Fall through wanted! */ case VOL_IO_ERROR: case VOL_NO_LABEL: - if (!write_new_volume_label_to_dev(jcr, dev, newname, poolname)) { + if (!write_new_volume_label_to_dev(jcr->dcr, newname, poolname)) { bnet_fsend(dir, _("3912 Failed to label Volume: ERR=%s\n"), strerror_dev(dev)); break; } diff --git a/bacula/src/stored/job.c b/bacula/src/stored/job.c index 5f87dbd429..7eea25673b 100644 --- a/bacula/src/stored/job.c +++ b/bacula/src/stored/job.c @@ -355,7 +355,7 @@ void stored_free_jcr(JCR *jcr) free_pool_memory(jcr->RestoreBootstrap); jcr->RestoreBootstrap = NULL; } - if (jcr->next_dev && jcr->prev_dev) { + if (jcr->next_dev || jcr->prev_dev) { Emsg0(M_FATAL, 0, _("In free_jcr(), but still attached to device!!!!\n")); } pthread_cond_destroy(&jcr->job_start_wait); diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 38388ab12c..fc816bee1c 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -31,7 +31,7 @@ #include "stored.h" /* pull in Storage Deamon headers */ /* Forward referenced functions */ -static void create_volume_label_record(JCR *jcr, DEVICE *dev, DEV_RECORD *rec); +static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec); extern char my_name[]; extern int debug_level; @@ -180,11 +180,11 @@ int read_dev_volume_label(DCR *dcr, DEV_BLOCK *block) * * Assumes that the record is already read. * - * Returns: 0 on error - * 1 on success + * Returns: false on error + * true on success */ -int unser_volume_label(DEVICE *dev, DEV_RECORD *rec) +bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec) { ser_declare; @@ -194,7 +194,7 @@ int unser_volume_label(DEVICE *dev, DEV_RECORD *rec) stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len); if (!forge_on) { - return 0; + return false; } } @@ -234,7 +234,7 @@ int unser_volume_label(DEVICE *dev, DEV_RECORD *rec) if (debug_level >= 90) { dump_volume_label(dev); } - return 1; + return true; } /* @@ -243,15 +243,17 @@ int unser_volume_label(DEVICE *dev, DEV_RECORD *rec) * Returns: false on failure * true on success */ -bool write_volume_label_to_block(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) +bool write_volume_label_to_block(DCR *dcr, DEV_BLOCK *block) { DEV_RECORD rec; + DEVICE *dev = dcr->dev; + JCR *jcr = dcr->jcr; Dmsg0(20, "write Label in write_volume_label_to_block()\n"); memset(&rec, 0, sizeof(rec)); rec.data = get_memory(SER_LENGTH_Volume_Label); - create_volume_label_record(jcr, dev, &rec); + create_volume_label_record(dcr, &rec); empty_block(block); /* Volume label always at beginning */ block->BlockNumber = 0; @@ -273,10 +275,12 @@ bool write_volume_label_to_block(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) * Assumes that the dev->VolHdr structure is properly * initialized. */ -static void create_volume_label_record(JCR *jcr, DEVICE *dev, DEV_RECORD *rec) +static void create_volume_label_record(DCR *dcr, DEV_RECORD *rec) { ser_declare; struct date_time dt; + DEVICE *dev = dcr->dev; + JCR *jcr = dcr->jcr; /* Serialize the label into the device record. */ @@ -327,8 +331,6 @@ static void create_volume_label_record(JCR *jcr, DEVICE *dev, DEV_RECORD *rec) /* * Create a volume label in memory - * Returns: 0 on error - * 1 on success */ void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName) { @@ -376,11 +378,12 @@ void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName) * * This routine should be used only when labeling a blank tape. */ -bool write_new_volume_label_to_dev(JCR *jcr, DEVICE *dev, const char *VolName, const char *PoolName) +bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName) { DEV_RECORD rec; DEV_BLOCK *block; bool ok = false; + DEVICE *dev = dcr->dev; Dmsg0(99, "write_volume_label()\n"); @@ -397,7 +400,7 @@ bool write_new_volume_label_to_dev(JCR *jcr, DEVICE *dev, const char *VolName, c block = new_block(dev); memset(&rec, 0, sizeof(rec)); rec.data = get_memory(SER_LENGTH_Volume_Label); - create_volume_label_record(jcr, dev, &rec); + create_volume_label_record(dcr, &rec); rec.Stream = 0; if (!write_record_to_block(block, &rec)) { @@ -409,7 +412,7 @@ bool write_new_volume_label_to_dev(JCR *jcr, DEVICE *dev, const char *VolName, c } Dmsg0(99, "Call write_block_to_dev()\n"); - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { memset(&dev->VolHdr, 0, sizeof(dev->VolHdr)); Dmsg2(30, "Bad Label write on %s. ERR=%s\n", dev_name(dev), strerror_dev(dev)); goto bail_out; @@ -435,9 +438,9 @@ bail_out: * Create session label * The pool memory must be released by the calling program */ -void create_session_label(JCR *jcr, DEV_RECORD *rec, int label) +void create_session_label(DCR *dcr, DEV_RECORD *rec, int label) { - DCR *dcr = jcr->dcr; + JCR *jcr = dcr->jcr; ser_declare; rec->VolSessionId = jcr->VolSessionId; @@ -488,9 +491,9 @@ void create_session_label(JCR *jcr, DEV_RECORD *rec, int label) * Returns: false on failure * true on success */ -bool write_session_label(JCR *jcr, DEV_BLOCK *block, int label) +bool write_session_label(DCR *dcr, DEV_BLOCK *block, int label) { - DCR *dcr = jcr->dcr; + JCR *jcr = dcr->jcr; DEVICE *dev = dcr->dev; DEV_RECORD *rec; @@ -519,7 +522,7 @@ bool write_session_label(JCR *jcr, DEV_BLOCK *block, int label) Jmsg1(jcr, M_ABORT, 0, _("Bad session label = %d\n"), label); break; } - create_session_label(jcr, rec, label); + create_session_label(dcr, rec, label); rec->FileIndex = label; /* @@ -630,7 +633,7 @@ bail_out: debug_level = dbl; } -int unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec) +bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec) { ser_declare; @@ -674,7 +677,7 @@ int unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec) label->JobStatus = JS_Terminated; /* kludge */ } } - return 1; + return true; } diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 3dea7c4a95..1e55ca8e74 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -30,7 +30,7 @@ #include "bacula.h" /* pull in global headers */ #include "stored.h" /* pull in Storage Deamon headers */ -static bool rewrite_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *bloc, bool recycle); +static bool rewrite_volume_label(DCR *dcr, DEV_BLOCK *block, bool recycle); /* @@ -45,11 +45,13 @@ static bool rewrite_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *bloc, bool re * impossible to get the requested Volume. * */ -bool mount_next_write_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool release) +bool mount_next_write_volume(DCR *dcr, DEV_BLOCK *block, bool release) { int retry = 0; bool ask = false, recycle, autochanger; int vol_label_status; + DEVICE *dev = dcr->dev; + JCR *jcr = dcr->jcr; Dmsg0(100, "Enter mount_next_volume()\n"); @@ -250,7 +252,7 @@ read_volume: "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(jcr, dev, jcr->VolumeName, + if (!write_new_volume_label_to_dev(jcr->dcr, jcr->VolumeName, jcr->pool_name)) { Dmsg0(100, "!write_vol_label\n"); goto mount_next_vol; @@ -297,7 +299,7 @@ read_volume: * If the tape is marked as Recycle, we rewrite the label. */ if (dev->VolHdr.LabelType == PRE_LABEL || recycle) { - if (!rewrite_volume_label(jcr, dev, block, recycle)) { + if (!rewrite_volume_label(jcr->dcr, block, recycle)) { goto mount_next_vol; } } else { @@ -348,11 +350,14 @@ The number of files mismatch! Volume=%u Catalog=%u\n"), * Returns: true if OK * false if unable to write it */ -static bool rewrite_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool recycle) +static bool rewrite_volume_label(DCR *dcr, DEV_BLOCK *block, bool recycle) { + DEVICE *dev = dcr->dev; + JCR *jcr = dcr->jcr; + Dmsg1(190, "ready_for_append found freshly labeled volume. dev=%x\n", dev); dev->VolHdr.LabelType = VOL_LABEL; /* set Volume label */ - if (!write_volume_label_to_block(jcr, dev, block)) { + if (!write_volume_label_to_block(dcr, block)) { return false; } /* @@ -372,7 +377,7 @@ static bool rewrite_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool r } } /* Attempt write to check write permission */ - if (!write_block_to_dev(jcr->dcr, block)) { + if (!write_block_to_dev(dcr, block)) { Jmsg2(jcr, M_ERROR, 0, _("Unable to write device \"%s\". ERR=%s\n"), dev_name(dev), strerror_dev(dev)); return false; diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 759b910aa4..fa45a7354f 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -146,15 +146,15 @@ void handle_filed_connection(BSOCK *fd, char *job_name); /* From label.c */ int read_dev_volume_label(DCR *dcr, DEV_BLOCK *block); -void create_session_label(JCR *jcr, DEV_RECORD *rec, int label); +void create_session_label(DCR *dcr, DEV_RECORD *rec, int label); void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName); -bool write_new_volume_label_to_dev(JCR *jcr, DEVICE *dev, const char *VolName, const char *PoolName); -bool write_session_label(JCR *jcr, DEV_BLOCK *block, int label); -bool write_volume_label_to_block(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName); +bool write_session_label(DCR *dcr, DEV_BLOCK *block, int label); +bool write_volume_label_to_block(DCR *dcr, DEV_BLOCK *block); void dump_volume_label(DEVICE *dev); void dump_label_record(DEVICE *dev, DEV_RECORD *rec, int verbose); -int unser_volume_label(DEVICE *dev, DEV_RECORD *rec); -int unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec); +bool unser_volume_label(DEVICE *dev, DEV_RECORD *rec); +bool unser_session_label(SESSION_LABEL *label, DEV_RECORD *rec); /* From match_bsr.c */ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, @@ -165,7 +165,7 @@ BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev); bool match_set_eof(BSR *bsr, DEV_RECORD *rec); /* From mount.c */ -bool mount_next_write_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool release); +bool mount_next_write_volume(DCR *dcr, DEV_BLOCK *block, bool release); bool mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); void release_volume(JCR *jcr, DEVICE *dev); void mark_volume_in_error(JCR *jcr, DEVICE *dev);