From bf625de424e5a6c9af6b2ac2a2355448b6d34154 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 8 Jul 2004 09:25:36 +0000 Subject: [PATCH] More DCR implementation + debug code for zeroed block headers git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1459 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/ReleaseNotes | 43 ++++++++++++- bacula/src/baconfig.h | 5 ++ bacula/src/lib/bsys.c | 13 ++++ bacula/src/stored/acquire.c | 2 +- bacula/src/stored/bcopy.c | 2 +- bacula/src/stored/bextract.c | 4 +- bacula/src/stored/block.c | 104 ++++++++++++++++++-------------- bacula/src/stored/bls.c | 13 ++-- bacula/src/stored/bscan.c | 2 +- bacula/src/stored/btape.c | 68 +++++++++++---------- bacula/src/stored/dircmd.c | 8 +-- bacula/src/stored/label.c | 10 +-- bacula/src/stored/mount.c | 2 +- bacula/src/stored/protos.h | 8 +-- bacula/src/stored/read.c | 9 +-- bacula/src/stored/read_record.c | 8 ++- bacula/src/stored/stored.c | 2 +- bacula/src/version.h | 13 ++-- 18 files changed, 201 insertions(+), 115 deletions(-) diff --git a/bacula/ReleaseNotes b/bacula/ReleaseNotes index 3e897d0679..c5a9b9990b 100644 --- a/bacula/ReleaseNotes +++ b/bacula/ReleaseNotes @@ -1,8 +1,49 @@ - Release Notes for Bacula 1.34.4 + Release Notes for Bacula 1.34.5 Bacula code: Total files = 364 Total lines = 103,481 (*.h *.c *.in) +Changes for 1.34.5: +Major Changes: +- Correct socket close on Win32 in bnet.c (in addition to compat.cpp). + Caused fd leak in Win32 for each connection. +- Fix a number of places in query.sql where multiple JobIds are + printed (due to JobMedia records). +- Abort configure if Internal is selected as the database. +- Close socket in SD when connection rejected. Caused fd leaks. + +Items to note!!!! +- If you are upgrading from 1.32, please be sure to see the database + upgrade procedure under the 1.34.0 notes. + +Other Items: +- Fixed Gnome crash on up/down arrow with no history. +- Fixed btape "fill" crash with multiple tape option. +- Add new query: List jobs on Volume given Volume name. +- Remove vol labeled test in askdir update_volume_info so that non-labeled + Volume in catalog can be marked in error. +- Initialize job_start_wait cond variable after every new_jcr() otherwise + NetBSD gets error in library when trying to delete it without being inited. +- Fix typo (9 instead of 0) return status in write_new_volume_label. +- Fix mount.c to call routine that correctly marks a volume in error. +- Eliminate printing INFO message in UpdateDB (cats) -- it generates + "false" error messages. +- Eliminate some GTK error messages when running the Gnome2 console. +- Apply Peter Eriksson's lib file order changes in linking for IRIX. +- Add testimonials to the Web page +- Add the bugs list to the Web page "lists". +- Clarify the English in SuSE and Slackware when SD not running. +- Applied the patches sent by Andreas Jellinghaus: build Gnome and + wx-console in client-only build if configured; add ./configure option + to permit setting of sbin modes -- default is 0745 as before; remove + cats library from Gnome console build; remove old version from Gnome + About box. Thanks Andreas. +- Correct a typo in the FreeBSD SD autostart install. +- New bacula.spec.in from Scott. +- Use /usr/lib/sendmail instead of mail if no mail program is configured. + Submitted by Peter Eriksson. This *should* be more portable. + + Changes for 1.34.4: Major Changes/Features: - Implement | and < in FD for new FileSet files. diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index 35f857de32..31441a8576 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -273,6 +273,11 @@ extern void _v(char *file, int line, pthread_mutex_t *m); #define LockRes() b_LockRes(__FILE__, __LINE__) #define UnlockRes() b_UnlockRes(__FILE__, __LINE__) +#ifdef DEBUG_MEMSET +#define memset(a, v, n) b_memset(__FILE__, __LINE__, a, v, n) +void b_memset(const char *file, int line, void *mem, int val, size_t num); +#endif + /* * The digit following Dmsg and Emsg indicates the number of substitutions in diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index 4d0e28a0b4..ff4cdd543a 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -283,6 +283,19 @@ void _v(char *file, int line, pthread_mutex_t *m) } #endif /* DEBUG_MUTEX */ +#ifdef DEBUG_MEMSET +/* These routines are not normally turned on */ +#undef memset +void b_memset(const char *file, int line, void *mem, int val, size_t num) +{ + /* Testing for 2000 byte zero at beginning of Volume block */ + if (num > 1900 && num < 3000) { + Pmsg3(000, "Memset for %d bytes at %s:%d\n", (int)num, file, line); + } + memset(mem, val, num); +} +#endif + #if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) static int del_pid_file_ok = FALSE; #endif diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 09d2d6a166..727c23ef66 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -146,7 +146,7 @@ DCR *acquire_device_for_read(JCR *jcr) */ dcr->dev->state &= ~ST_LABEL; /* force reread of label */ Dmsg0(200, "calling read-vol-label\n"); - switch (read_dev_volume_label(jcr, dev, dcr->block)) { + switch (read_dev_volume_label(dcr, dcr->block)) { case VOL_OK: vol_ok = true; break; /* got it */ diff --git a/bacula/src/stored/bcopy.c b/bacula/src/stored/bcopy.c index 01bc5db056..ead6fa2e29 100644 --- a/bacula/src/stored/bcopy.c +++ b/bacula/src/stored/bcopy.c @@ -168,7 +168,7 @@ int main (int argc, char *argv[]) } out_block = out_jcr->dcr->block; - read_records(in_jcr, in_dev, record_cb, mount_next_read_volume); + read_records(in_jcr->dcr, record_cb, mount_next_read_volume); if (!write_block_to_device(out_jcr->dcr, out_block)) { Pmsg0(000, _("Write of last block failed.\n")); } diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 14252447f8..ce8898bc71 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -41,6 +41,7 @@ static void do_extract(char *fname); static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec); static DEVICE *dev = NULL; +static DCR *dcr; static BFILE bfd; static JCR *jcr; static FF_PKT my_ff; @@ -204,6 +205,7 @@ static void do_extract(char *devname) if (!dev) { exit(1); } + dcr = jcr->dcr; /* Make sure where directory exists and that it is a directory */ if (stat(where, &statp) < 0) { @@ -220,7 +222,7 @@ static void do_extract(char *devname) compress_buf = get_memory(compress_buf_size); - read_records(jcr, dev, record_cb, mount_next_read_volume); + read_records(dcr, record_cb, mount_next_read_volume); /* If output file is still open, it was the last one in the * archive since we just hit an end of file, so close the file. */ diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 2c4512423d..7174a89e96 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -233,15 +233,13 @@ static bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) block->bufp = block->buf + bhl; if (strncmp(Id, BLKHDR1_ID, BLKHDR_ID_LENGTH) != 0) { dev->dev_errno = EIO; - Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: %s, got %s. Buffer discarded.\n"), + Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"), dev->file, dev->block_num, BLKHDR1_ID, Id); if (block->read_errors == 0 || verbose >= 2) { Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); } block->read_errors++; - if (!forge_on) { - return false; - } + return false; } } else if (Id[3] == '2') { unser_uint32(block->VolSessionId); @@ -251,32 +249,25 @@ static bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) block->bufp = block->buf + bhl; if (strncmp(Id, BLKHDR2_ID, BLKHDR_ID_LENGTH) != 0) { dev->dev_errno = EIO; - Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: %s, got %s. Buffer discarded.\n"), + Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"), dev->file, dev->block_num, BLKHDR2_ID, Id); if (block->read_errors == 0 || verbose >= 2) { Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); } block->read_errors++; - if (!forge_on) { - return false; - } + return false; } } else { dev->dev_errno = EIO; - Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: %s, got %s. Buffer discarded.\n"), + Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Wanted ID: \"%s\", got \"%s\". Buffer discarded.\n"), dev->file, dev->block_num, BLKHDR2_ID, Id); if (block->read_errors == 0 || verbose >= 2) { Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); } block->read_errors++; - if (!forge_on) { - return false; - } unser_uint32(block->VolSessionId); unser_uint32(block->VolSessionTime); - bhl = BLKHDR2_LENGTH; - block->BlockVer = 2; - block->bufp = block->buf + bhl; + return false; } /* Sanity check */ @@ -288,9 +279,7 @@ static bool unser_block_header(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); } block->read_errors++; - if (!forge_on) { - return false; - } + return false; } Dmsg1(190, "unser_block_header block_len=%d\n", block_len); @@ -525,7 +514,21 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block) dev->VolCatInfo.VolCatWrites++; Dmsg1(200, "Write block of %u bytes\n", wlen); +#ifdef DEBUG_BLOCK_ZEROING + uint32_t *bp = (uint32_t *)block->buf; + if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) { + Jmsg0(jcr, M_ABORT, 0, "Write block header zeroed.\n"); + } +#endif + stat = write(dev->fd, block->buf, (size_t)wlen); + +#ifdef DEBUG_BLOCK_ZEROING + if (bp[0] == 0 && bp[1] == 0 && bp[2] == 0 && block->buf[12] == 0) { + Jmsg0(jcr, M_ABORT, 0, "Write block header zeroed.\n"); + } +#endif + if (stat != (ssize_t)wlen) { /* We should check for errno == ENOSPC, BUT many * devices simply report EIO when the volume is full. @@ -581,7 +584,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block) * then re-read it and verify that the block number is * correct. */ - if (dev->state & ST_TAPE && dev_cap(dev, CAP_BSR)) { + if ((dev->state & ST_TAPE) && dev_cap(dev, CAP_BSR)) { /* Now back up over what we wrote and read the last block */ if (!bsf_dev(dev, 1)) { @@ -609,7 +612,7 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block) if (ok) { DEV_BLOCK *lblock = new_block(dev); /* Note, this can destroy dev->errmsg */ - if (!read_block_from_dev(jcr, dev, lblock, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_dev(dcr, lblock, NO_BLOCK_NUMBER_CHECK)) { Jmsg(jcr, M_ERROR, 0, _("Re-read last block at EOT failed. ERR=%s"), dev->errmsg); } else { if (lblock->BlockNumber+1 == block->BlockNumber) { @@ -665,12 +668,13 @@ bool write_block_to_dev(DCR *dcr, DEV_BLOCK *block) * Read block with locking * */ -int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers) +bool read_block_from_device(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers) { - int stat; + bool stat; + DEVICE *dev = dcr->dev; Dmsg0(90, "Enter read_block_from_device\n"); lock_device(dev); - stat = read_block_from_dev(jcr, dev, block, check_block_numbers); + stat = read_block_from_dev(dcr, block, check_block_numbers); unlock_device(dev); Dmsg0(90, "Leave read_block_from_device\n"); return stat; @@ -681,19 +685,17 @@ int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_b * the block header. For a file, the block may be partially * or completely in the current buffer. */ -int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers) +bool read_block_from_dev(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers) { ssize_t stat; int looping; uint32_t BlockNumber; int retry; - DCR *dcr = jcr->dcr; + JCR *jcr = dcr->jcr; + DEVICE *dev = dcr->dev; - if (!dcr) { - Jmsg0(jcr, M_ABORT, 0, _("DCR is NULL!\n")); - } if (dev_state(dev, ST_EOT)) { - return 0; + return false; } looping = 0; Dmsg1(100, "Full read() in read_block_from_device() len=%d\n", @@ -705,32 +707,39 @@ reread: dev->dev_name); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); block->read_len = 0; - return 0; + return false; } retry = 0; do { +// uint32_t *bp = (uint32_t *)block->buf; +// Dmsg3(000, "Read %p %u at %llu\n", block->buf, block->buf_len, lseek(dev->fd, 0, SEEK_CUR)); + stat = read(dev->fd, block->buf, (size_t)block->buf_len); + +// Dmsg8(000, "stat=%d Csum=%u blen=%u bnum=%u %c%c%c%c\n",stat, bp[0],bp[1],bp[2], +// block->buf[12],block->buf[13],block->buf[14],block->buf[15]); + if (retry == 1) { dev->VolCatInfo.VolCatErrors++; } } while (stat == -1 && (errno == EINTR || errno == EIO) && retry++ < 11); -// Dmsg1(100, "read stat = %d\n", stat); if (stat < 0) { Dmsg1(90, "Read device got: ERR=%s\n", strerror(errno)); clrerror_dev(dev, -1); block->read_len = 0; - Mmsg4(&dev->errmsg, _("Read error at file:block %d:%d on device %s. ERR=%s.\n"), + Mmsg4(&dev->errmsg, _("Read error at file:blk %u:%u on device %s. ERR=%s.\n"), dev->file, dev->block_num, dev->dev_name, strerror(dev->dev_errno)); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); if (dev->state & ST_EOF) { /* EOF just seen? */ dev->state |= ST_EOT; /* yes, error => EOT */ } - return 0; + return false; } Dmsg1(90, "Read device got %d bytes\n", stat); if (stat == 0) { /* Got EOF ! */ dev->block_num = block->read_len = 0; - Mmsg1(&dev->errmsg, _("Read zero bytes on device %s.\n"), dev->dev_name); + Mmsg3(&dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"), + dev->file, dev->block_num, dev->dev_name); if (dev->state & ST_EOF) { /* EOF already read? */ dev->state |= ST_EOT; /* yes, 2 EOFs => EOT */ block->read_len = 0; @@ -739,24 +748,28 @@ reread: dev->file++; /* increment file */ dev->state |= ST_EOF; /* set EOF read */ block->read_len = 0; - return 0; /* return eof */ + return false; /* return eof */ } /* Continue here for successful read */ block->read_len = stat; /* save length read */ if (block->read_len < BLKHDR2_LENGTH) { dev->dev_errno = EIO; - Mmsg2(&dev->errmsg, _("Volume data error! Very short block of %d bytes on device %s discarded.\n"), - block->read_len, dev->dev_name); + Mmsg4(&dev->errmsg, _("Volume data error at %u:%u! Very short block of %d bytes on device %s discarded.\n"), + dev->file, dev->block_num, block->read_len, dev->dev_name); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); dev->state |= ST_SHORT; /* set short block */ block->read_len = block->binbuf = 0; - return 0; /* return error */ + return false; /* return error */ } BlockNumber = block->BlockNumber + 1; if (!unser_block_header(jcr, dev, block)) { - block->read_len = 0; - return 0; + if (forge_on) { + dev->file_addr += block->read_len; + dev->file_size += block->read_len; + goto reread; + } + return false; } /* @@ -776,10 +789,10 @@ reread: if (!bsr_dev(dev, 1)) { Jmsg(jcr, M_ERROR, 0, "%s", strerror_dev(dev)); block->read_len = 0; - return 0; + return false; } } else { - Dmsg0(100, "Seek to beginning of block for reread.\n"); + Dmsg0(200, "Seek to beginning of block for reread.\n"); off_t pos = lseek(dev->fd, (off_t)0, SEEK_CUR); /* get curr pos */ pos -= block->read_len; lseek(dev->fd, pos, SEEK_SET); @@ -805,7 +818,7 @@ reread: Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); dev->state |= ST_SHORT; /* set short block */ block->read_len = block->binbuf = 0; - return 0; /* return error */ + return false; /* return error */ } dev->state &= ~(ST_EOF|ST_SHORT); /* clear EOF and short block */ @@ -849,12 +862,13 @@ reread: off_t pos = lseek(dev->fd, (off_t)0, SEEK_CUR); /* get curr pos */ pos -= (block->read_len - block->block_len); lseek(dev->fd, pos, SEEK_SET); - Dmsg2(100, "Did lseek blk_size=%d rdlen=%d\n", block->block_len, + Dmsg2(200, "Did lseek blk_size=%d rdlen=%d\n", block->block_len, block->read_len); dev->file_addr = pos; + dev->file_size = pos; } Dmsg2(200, "Exit read_block read_len=%d block_len=%d\n", block->read_len, block->block_len); block->block_read = true; - return 1; + return true; } diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 09c4cfaaa7..5259008864 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -42,6 +42,7 @@ static void get_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sess static bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec); static DEVICE *dev; +static DCR *dcr; static bool dump_label = false; static bool list_blocks = false; static bool list_jobs = false; @@ -205,6 +206,7 @@ int main (int argc, char *argv[]) if (!dev) { exit(1); } + dcr = jcr->dcr; rec = new_record(); block = new_block(dev); attr = new_attr(); @@ -253,7 +255,7 @@ static void do_blocks(char *infname) rec = new_record(); } for ( ;; ) { - if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_device(dcr, block, NO_BLOCK_NUMBER_CHECK)) { Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev)); if (dev->state & ST_EOT) { if (!mount_next_read_volume(jcr, dev, block)) { @@ -264,7 +266,7 @@ static void do_blocks(char *infname) /* Read and discard Volume label */ DEV_RECORD *record; record = new_record(); - read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK); + read_block_from_device(dcr, block, NO_BLOCK_NUMBER_CHECK); read_record_from_block(block, record); get_session_record(dev, record, &sessrec); free_record(record); @@ -295,7 +297,8 @@ static void do_blocks(char *infname) block->VolSessionId, block->VolSessionTime); if (verbose == 1) { read_record_from_block(block, rec); - Pmsg7(-1, "Block: %u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n", + Pmsg9(-1, "File:blk=%u:%u blk_num=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n", + dev->file, dev->block_num, block->BlockNumber, block->block_len, FI_to_ascii(rec->FileIndex), rec->VolSessionId, rec->VolSessionTime, stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len); @@ -325,7 +328,7 @@ static bool jobs_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec) /* Do list job records */ static void do_jobs(char *infname) { - read_records(jcr, dev, jobs_cb, mount_next_read_volume); + read_records(dcr, jobs_cb, mount_next_read_volume); } /* Do an ls type listing of an archive */ @@ -335,7 +338,7 @@ static void do_ls(char *infname) dump_volume_label(dev); return; } - read_records(jcr, dev, record_cb, mount_next_read_volume); + read_records(dcr, record_cb, mount_next_read_volume); printf("%u files found.\n", num_files); } diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 817b0842f9..b972422587 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -318,7 +318,7 @@ static void do_scan() /* Detach bscan's jcr as we are not a real Job on the tape */ detach_jcr_from_device(dev, bjcr); - read_records(bjcr, dev, record_cb, bscan_mount_next_read_volume); + read_records(bjcr->dcr, record_cb, bscan_mount_next_read_volume); release_device(bjcr); free_attr(attr); diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index 04b2f66066..e875ebe1e8 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -55,6 +55,7 @@ bool forge_on = false; static uint32_t btape_state_level = 2; DEVICE *dev = NULL; +DCR *dcr; DEVRES *device = NULL; @@ -235,6 +236,7 @@ int main(int margc, char *margv[]) if (!dev) { exit(1); } + dcr = jcr->dcr; if (!open_the_device()) { goto terminate; } @@ -349,32 +351,32 @@ static void readlabelcmd() DEV_BLOCK *block; block = new_block(dev); - stat = read_dev_volume_label(jcr, dev, block); + stat = read_dev_volume_label(dcr, block); switch (stat) { - case VOL_NO_LABEL: - Pmsg0(0, "Volume has no label.\n"); - break; - case VOL_OK: - Pmsg0(0, "Volume label read correctly.\n"); - break; - case VOL_IO_ERROR: - Pmsg1(0, "I/O error on device: ERR=%s", strerror_dev(dev)); - break; - case VOL_NAME_ERROR: - Pmsg0(0, "Volume name error\n"); - break; - case VOL_CREATE_ERROR: - Pmsg1(0, "Error creating label. ERR=%s", strerror_dev(dev)); - break; - case VOL_VERSION_ERROR: - Pmsg0(0, "Volume version error.\n"); - break; - case VOL_LABEL_ERROR: - Pmsg0(0, "Bad Volume label type.\n"); - break; - default: - Pmsg0(0, "Unknown error.\n"); - break; + case VOL_NO_LABEL: + Pmsg0(0, "Volume has no label.\n"); + break; + case VOL_OK: + Pmsg0(0, "Volume label read correctly.\n"); + break; + case VOL_IO_ERROR: + Pmsg1(0, "I/O error on device: ERR=%s", strerror_dev(dev)); + break; + case VOL_NAME_ERROR: + Pmsg0(0, "Volume name error\n"); + break; + case VOL_CREATE_ERROR: + Pmsg1(0, "Error creating label. ERR=%s", strerror_dev(dev)); + break; + case VOL_VERSION_ERROR: + Pmsg0(0, "Volume version error.\n"); + break; + case VOL_LABEL_ERROR: + Pmsg0(0, "Bad Volume label type.\n"); + break; + default: + Pmsg0(0, "Unknown error.\n"); + break; } debug_level = 20; @@ -679,7 +681,7 @@ static int re_read_block_test() goto bail_out; } Pmsg0(0, "Backspace record OK.\n"); - if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_dev(dcr, block, NO_BLOCK_NUMBER_CHECK)) { Pmsg1(0, _("Read block failed! ERR=%s\n"), strerror(dev->dev_errno)); goto bail_out; } @@ -784,7 +786,7 @@ static int write_read_test() } for (i=1; i<=2000; i++) { read_again: - if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_dev(dcr, block, NO_BLOCK_NUMBER_CHECK)) { if (dev_state(dev, ST_EOF)) { Pmsg0(-1, _("Got EOF on tape.\n")); goto read_again; @@ -934,7 +936,7 @@ static int position_test() goto bail_out; } read_again: - if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_dev(dcr, block, NO_BLOCK_NUMBER_CHECK)) { if (dev_state(dev, ST_EOF)) { Pmsg0(-1, _("Got EOF on tape.\n")); goto read_again; @@ -1578,7 +1580,7 @@ static void scan_blocks() update_pos_dev(dev); tot_files = dev->file; for (;;) { - if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_device(dcr, block, NO_BLOCK_NUMBER_CHECK)) { Dmsg1(100, "!read_block(): ERR=%s\n", strerror_dev(dev)); if (dev->state & ST_EOT) { if (blocks > 0) { @@ -2000,14 +2002,14 @@ static void do_unfill() rewind_dev(dev); /* get to a known place on tape */ /* Read the first 1000 records */ Pmsg0(-1, _("Reading the first 1000 records.\n")); - read_records(jcr, dev, quickie_cb, my_mount_next_read_volume); + read_records(dcr, quickie_cb, my_mount_next_read_volume); Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num, last_file, last_block_num); if (!reposition_dev(dev, last_file, last_block_num)) { Pmsg1(-1, "Reposition error. ERR=%s\n", strerror_dev(dev)); } Pmsg1(-1, _("Reading block %u.\n"), last_block_num); - if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_device(dcr, block, NO_BLOCK_NUMBER_CHECK)) { Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev)); goto bail_out; } @@ -2058,7 +2060,7 @@ static void do_unfill() goto bail_out; } Pmsg1(-1, _("Reading block %d.\n"), dev->block_num); - if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_device(dcr, block, NO_BLOCK_NUMBER_CHECK)) { Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev)); goto bail_out; } @@ -2074,7 +2076,7 @@ static void do_unfill() goto bail_out; } Pmsg1(-1, _("Reading block %d.\n"), dev->block_num); - if (!read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_device(dcr, block, NO_BLOCK_NUMBER_CHECK)) { Pmsg1(-1, _("Error reading block: ERR=%s\n"), strerror_dev(dev)); goto bail_out; } diff --git a/bacula/src/stored/dircmd.c b/bacula/src/stored/dircmd.c index 82ec5bc78d..13a7f933a6 100644 --- a/bacula/src/stored/dircmd.c +++ b/bacula/src/stored/dircmd.c @@ -383,7 +383,7 @@ static void label_volume_if_ok(JCR *jcr, DEVICE *dev, char *oldname, } /* See what we have for a Volume */ - switch (read_dev_volume_label(jcr, dev, block)) { + switch (read_dev_volume_label(jcr->dcr, block)) { case VOL_NAME_ERROR: case VOL_VERSION_ERROR: case VOL_LABEL_ERROR: @@ -443,7 +443,7 @@ static int read_label(JCR *jcr, DEVICE *dev) jcr->VolumeName[0] = 0; block = new_block(dev); dev->state &= ~ST_LABEL; /* force read of label */ - switch (read_dev_volume_label(jcr, dev, block)) { + switch (read_dev_volume_label(jcr->dcr, block)) { case VOL_OK: bnet_fsend(dir, _("3001 Mounted Volume: %s\n"), dev->VolHdr.VolName); stat = 1; @@ -523,7 +523,7 @@ static int mount_cmd(JCR *jcr) break; } block = new_block(dev); - read_dev_volume_label(jcr, dev, block); + read_dev_volume_label(jcr->dcr, block); free_block(block); if (dev->dev_blocked == BST_UNMOUNTED) { /* We blocked the device, so unblock it */ @@ -866,7 +866,7 @@ static void read_volume_label(JCR *jcr, DEVICE *dev, int Slot) } dev->state &= ~ST_LABEL; /* force read of label */ - switch (read_dev_volume_label(jcr, dev, block)) { + switch (read_dev_volume_label(jcr->dcr, block)) { case VOL_OK: /* DO NOT add quotes around the Volume name. It is scanned in the DIR */ bnet_fsend(dir, _("3001 Volume=%s Slot=%d\n"), dev->VolHdr.VolName, Slot); diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 354fb6fa52..a4ce64e641 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -56,11 +56,13 @@ extern int debug_level; * VOL_LABEL_ERROR * VOL_NO_MEDIA */ -int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) +int read_dev_volume_label(DCR *dcr, DEV_BLOCK *block) { + JCR *jcr = dcr->jcr; + DEVICE *dev = dcr->dev; char *VolName = jcr->VolumeName; DEV_RECORD *record; - int ok = 0; + bool ok = false; Dmsg3(100, "Enter read_volume_label device=%s vol=%s dev_Vol=%s\n", dev_name(dev), VolName, dev->VolHdr.VolName); @@ -95,7 +97,7 @@ int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) /* Read the Volume label block */ record = new_record(); Dmsg0(90, "Big if statement in read_volume_label\n"); - if (!read_block_from_dev(jcr, dev, block, NO_BLOCK_NUMBER_CHECK)) { + if (!read_block_from_dev(dcr, block, NO_BLOCK_NUMBER_CHECK)) { Mmsg(&jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula " "labeled Volume, because: ERR=%s"), NPRT(VolName), dev_name(dev), strerror_dev(dev)); @@ -108,7 +110,7 @@ int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block) strcmp(dev->VolHdr.Id, OldBaculaId) != 0) { Mmsg(&jcr->errmsg, _("Volume Header Id bad: %s\n"), dev->VolHdr.Id); } else { - ok = 1; + ok = true; } if (!ok) { free_record(record); diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index a8aaad7dee..3dea7c4a95 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -170,7 +170,7 @@ read_volume: create_volume_label(dev, jcr->VolumeName, "Default"); dev->VolHdr.LabelType = PRE_LABEL; } else { - vol_label_status = read_dev_volume_label(jcr, dev, block); + vol_label_status = read_dev_volume_label(jcr->dcr, block); } Dmsg2(100, "dirVol=%s dirStat=%s\n", jcr->VolumeName, diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index fbd933f6de..759b910aa4 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -66,8 +66,8 @@ void ser_block_header(DEV_BLOCK *block); #define CHECK_BLOCK_NUMBERS true #define NO_BLOCK_NUMBER_CHECK false -int read_block_from_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers); -int read_block_from_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, bool check_block_numbers); +bool read_block_from_device(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers); +bool read_block_from_dev(DCR *dcr, DEV_BLOCK *block, bool check_block_numbers); /* From butil.c -- utilities for SD tool programs */ void print_ls_output(const char *fname, const char *link, int type, struct stat *statp); @@ -145,7 +145,7 @@ void connection_from_filed(void *arg); void handle_filed_connection(BSOCK *fd, char *job_name); /* From label.c */ -int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +int read_dev_volume_label(DCR *dcr, DEV_BLOCK *block); void create_session_label(JCR *jcr, 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); @@ -195,7 +195,7 @@ DEV_RECORD *new_record(); void free_record(DEV_RECORD *rec); /* From read_record.c */ -bool read_records(JCR *jcr, DEVICE *dev, +bool read_records(DCR *dcr, bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec), bool mount_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)); diff --git a/bacula/src/stored/read.c b/bacula/src/stored/read.c index a7335e60c7..bdf870052c 100644 --- a/bacula/src/stored/read.c +++ b/bacula/src/stored/read.c @@ -46,7 +46,7 @@ bool do_read_data(JCR *jcr) { BSOCK *fd = jcr->file_bsock; bool ok = true; - DEVICE *dev; + DCR *dcr; Dmsg0(20, "Start read data.\n"); @@ -71,17 +71,14 @@ bool do_read_data(JCR *jcr) /* * Ready device for reading, and read records */ - if (!acquire_device_for_read(jcr)) { + if (!(dcr=acquire_device_for_read(jcr))) { free_vol_list(jcr); return false; } - dev = jcr->dcr->dev; - Dmsg1(20, "Begin read device=%s\n", dev_name(dev)); - /* Tell File daemon we will send data */ bnet_fsend(fd, OK_data); - ok = read_records(jcr, dev, record_cb, mount_next_read_volume); + ok = read_records(dcr, record_cb, mount_next_read_volume); /* Send end of data to FD */ bnet_sig(fd, BNET_EOD); diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index 430d57428d..ef8bc32ad3 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -41,10 +41,12 @@ static int try_repositioning(JCR *jcr, DEV_RECORD *rec, DEVICE *dev); static char *rec_state_to_str(DEV_RECORD *rec); #endif -bool read_records(JCR *jcr, DEVICE *dev, +bool read_records(DCR *dcr, bool record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec), bool mount_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)) { + JCR *jcr = dcr->jcr; + DEVICE *dev = dcr->dev; DEV_BLOCK *block; DEV_RECORD *rec = NULL; uint32_t record; @@ -62,7 +64,7 @@ bool read_records(JCR *jcr, DEVICE *dev, ok = false; break; } - if (!read_block_from_device(jcr, dev, block, CHECK_BLOCK_NUMBERS)) { + if (!read_block_from_device(dcr, block, CHECK_BLOCK_NUMBERS)) { if (dev_state(dev, ST_EOT)) { DEV_RECORD *trec = new_record(); @@ -87,7 +89,7 @@ bool read_records(JCR *jcr, DEVICE *dev, * and pass it off to the callback routine, then continue * most likely reading the previous record. */ - read_block_from_device(jcr, dev, block, NO_BLOCK_NUMBER_CHECK); + read_block_from_device(dcr, block, NO_BLOCK_NUMBER_CHECK); read_record_from_block(block, trec); handle_session_record(dev, trec, &sessrec); ok = record_cb(jcr, dev, block, trec); diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 7646be3221..957738336f 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -332,7 +332,7 @@ void *device_allocation(void *arg) } jcr->device = device; dcr = new_dcr(jcr, device->dev); - switch (read_dev_volume_label(jcr, device->dev, dcr->block)) { + switch (read_dev_volume_label(dcr, dcr->block)) { case VOL_OK: break; default: diff --git a/bacula/src/version.h b/bacula/src/version.h index 15cb014b0f..aeddec6808 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -2,8 +2,8 @@ #undef VERSION #define VERSION "1.35.0" #define VSTRING "1" -#define BDATE "07 July 2004" -#define LSMDATE "07Jul04" +#define BDATE "08 July 2004" +#define LSMDATE "08Jul04" /* Debug flags */ #undef DEBUG @@ -12,8 +12,13 @@ #define SMCHECK #define TRACE_FILE 1 -// #define TRACE_JCR_CHAIN 1 -// #define TRACE_RES 1 + +/* Debug flags not normally turned on */ + +/* #define TRACE_JCR_CHAIN 1 */ +/* #define TRACE_RES 1 */ +/* #define DEBUG_MEMSET 1 */ +#define DEBUG_BLOCK_ZEROING 1 /* #define FULL_DEBUG 1 */ /* normally on for testing only */ -- 2.39.5