From b0a107eb39d1855393cb3ac8381f80b2c7cf6804 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Mon, 26 May 2003 15:40:52 +0000 Subject: [PATCH] Cleanup a few minor restore bugs git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@548 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/sql_cmds.c | 2 +- bacula/src/dird/ua_restore.c | 4 +- bacula/src/filed/job.c | 2 +- bacula/src/stored/bls.c | 6 +- bacula/src/stored/butil.c | 16 ++-- bacula/src/stored/protos.h | 160 ++++++++++++++++---------------- bacula/src/stored/read.c | 5 +- bacula/src/stored/read_record.c | 9 +- 8 files changed, 105 insertions(+), 99 deletions(-) diff --git a/bacula/src/dird/sql_cmds.c b/bacula/src/dird/sql_cmds.c index e1aa5674a4..e77ad04978 100644 --- a/bacula/src/dird/sql_cmds.c +++ b/bacula/src/dird/sql_cmds.c @@ -230,7 +230,7 @@ char *uar_sel_fileset = "SELECT FileSet.FileSetId,FileSet.FileSet,FileSet.MD5 FROM Job," "Client,FileSet WHERE Job.FileSetId=FileSet.FileSetId " "AND Job.ClientId=%u AND Client.ClientId=%u " - "GROUP BY FileSet.FileSetId"; + "GROUP BY FileSet.FileSetId ORDER BY FileSet.FileSetId"; /* Find MediaType used by this Job */ char *uar_mediatype = diff --git a/bacula/src/dird/ua_restore.c b/bacula/src/dird/ua_restore.c index b523b83270..61c2556d7c 100644 --- a/bacula/src/dird/ua_restore.c +++ b/bacula/src/dird/ua_restore.c @@ -195,6 +195,7 @@ int restorecmd(UAContext *ua, char *cmd) * For display purposes, the same JobId, with different volumes may * appear more than once, however, we only insert it once. */ + int items = 0; for (p=ji.JobIds; next_jobid_from_list(&p, &JobId) > 0; ) { if (JobId == last_JobId) { @@ -202,6 +203,7 @@ int restorecmd(UAContext *ua, char *cmd) } last_JobId = JobId; bsendmsg(ua, _("Building directory tree for JobId %u ...\n"), JobId); + items++; /* * Find files for this JobId and insert them in the tree */ @@ -218,7 +220,7 @@ int restorecmd(UAContext *ua, char *cmd) } } - bsendmsg(ua, "%d items inserted into the tree and marked for extraction.\n"); + bsendmsg(ua, "%d items inserted into the tree and marked for extraction.\n", items); free_pool_memory(query); /* Check MediaType and select storage that corresponds */ diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 2b9a8a85d9..155dc19ad6 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -185,7 +185,7 @@ void *handle_client_request(void *dirp) found = TRUE; /* indicate command found */ if (!cmds[i].func(jcr)) { /* do command */ quit = TRUE; /* error or fully terminated, get out */ - Pmsg0(20, "Command error or Job done.\n"); + Dmsg0(20, "Command error or Job done.\n"); } break; } diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index a38a25feb3..7a33c3b1f7 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -252,15 +252,15 @@ static void do_blocks(char *infname) continue; } if (dev->state & ST_EOF) { - Emsg1(M_INFO, 0, "Got EOF on device %s\n", dev_name(dev)); + Jmsg(jcr, M_INFO, 0, "Got EOF on device %s\n", dev_name(dev)); Dmsg0(20, "read_record got eof. try again\n"); continue; } if (dev->state & ST_SHORT) { - Emsg0(M_INFO, 0, dev->errmsg); + Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg); continue; } - display_error_status(dev); + display_tape_error_status(jcr, dev); break; } Dmsg5(100, "Blk=%u blen=%u bVer=%d SessId=%u SessTim=%u\n", diff --git a/bacula/src/stored/butil.c b/bacula/src/stored/butil.c index 8c1b9996af..a9cad0198e 100644 --- a/bacula/src/stored/butil.c +++ b/bacula/src/stored/butil.c @@ -233,25 +233,25 @@ JCR *setup_jcr(char *name, char *device, BSR *bsr, char *VolumeName) /* * Device got an error, attempt to analyse it */ -void display_error_status(DEVICE *dev) +void display_tape_error_status(JCR *jcr, DEVICE *dev) { uint32_t status; - Emsg0(M_ERROR, 0, dev->errmsg); + Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); status_dev(dev, &status); Dmsg1(20, "Device status: %x\n", status); if (status & BMT_EOD) - Emsg0(M_ERROR_TERM, 0, _("Unexpected End of Data\n")); + Jmsg(jcr, M_ERROR, 0, _("Unexpected End of Data\n")); else if (status & BMT_EOT) - Emsg0(M_ERROR_TERM, 0, _("Unexpected End of Tape\n")); + Jmsg(jcr, M_ERROR, 0, _("Unexpected End of Tape\n")); else if (status & BMT_EOF) - Emsg0(M_ERROR_TERM, 0, _("Unexpected End of File\n")); + Jmsg(jcr, M_ERROR, 0, _("Unexpected End of File\n")); else if (status & BMT_DR_OPEN) - Emsg0(M_ERROR_TERM, 0, _("Tape Door is Open\n")); + Jmsg(jcr, M_ERROR, 0, _("Tape Door is Open\n")); else if (!(status & BMT_ONLINE)) - Emsg0(M_ERROR_TERM, 0, _("Unexpected Tape is Off-line\n")); + Jmsg(jcr, M_ERROR, 0, _("Unexpected Tape is Off-line\n")); else - Emsg2(M_ERROR_TERM, 0, _("Read error on Record Header %s: %s\n"), dev_name(dev), strerror(errno)); + Jmsg(jcr, M_ERROR, 0, _("Read error on Record Header %s: %s\n"), dev_name(dev), strerror(errno)); } diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 6a95c82c9e..1b0adc6c3f 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -28,86 +28,86 @@ uint32_t new_VolSessionId(); /* From acquire.c */ -DEVICE *acquire_device_for_append(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); -int acquire_device_for_read(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); -int release_device(JCR *jcr, DEVICE *dev); +DEVICE *acquire_device_for_append(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +int acquire_device_for_read(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +int release_device(JCR *jcr, DEVICE *dev); /* From askdir.c */ -int dir_get_volume_info(JCR *jcr, int writing); -int dir_find_next_appendable_volume(JCR *jcr); -int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel); -int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev); -int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev); -int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec); -int dir_send_job_status(JCR *jcr); -int dir_create_jobmedia_record(JCR *jcr); +int dir_get_volume_info(JCR *jcr, int writing); +int dir_find_next_appendable_volume(JCR *jcr); +int dir_update_volume_info(JCR *jcr, VOLUME_CAT_INFO *vol, int relabel); +int dir_ask_sysop_to_mount_next_volume(JCR *jcr, DEVICE *dev); +int dir_ask_sysop_to_mount_volume(JCR *jcr, DEVICE *dev); +int dir_update_file_attributes(JCR *jcr, DEV_RECORD *rec); +int dir_send_job_status(JCR *jcr); +int dir_create_jobmedia_record(JCR *jcr); /* authenticate.c */ -int authenticate_director(JCR *jcr); -int authenticate_filed(JCR *jcr); +int authenticate_director(JCR *jcr); +int authenticate_filed(JCR *jcr); /* From block.c */ -void dump_block(DEV_BLOCK *b, char *msg); +void dump_block(DEV_BLOCK *b, char *msg); DEV_BLOCK *new_block(DEVICE *dev); -void init_block_write(DEV_BLOCK *block); -void empty_block(DEV_BLOCK *block); -void free_block(DEV_BLOCK *block); -int write_block_to_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); -int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +void init_block_write(DEV_BLOCK *block); +void empty_block(DEV_BLOCK *block); +void free_block(DEV_BLOCK *block); +int write_block_to_device(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +int write_block_to_dev(JCR *jcr, DEVICE *dev, 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); +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); /* From butil.c -- utilities for SD tool programs */ -void print_ls_output(char *fname, char *link, int type, struct stat *statp); +void print_ls_output(char *fname, char *link, int type, struct stat *statp); JCR *setup_jcr(char *name, char *device, BSR *bsr, char *VolumeName); DEVICE *setup_to_access_device(JCR *jcr, int read_access); -void display_error_status(DEVICE *dev); +void display_tape_error_status(JCR *jcr, DEVICE *dev); DEVRES *find_device_res(char *device_name, int read_access); /* From dev.c */ -DEVICE *init_dev(DEVICE *dev, DEVRES *device); -int open_dev(DEVICE *dev, char *VolName, int mode); -void close_dev(DEVICE *dev); -void force_close_dev(DEVICE *dev); -int truncate_dev(DEVICE *dev); -void term_dev(DEVICE *dev); -char * strerror_dev(DEVICE *dev); -void clrerror_dev(DEVICE *dev, int func); -int update_pos_dev(DEVICE *dev); -int rewind_dev(DEVICE *dev); -int load_dev(DEVICE *dev); -int offline_dev(DEVICE *dev); -int flush_dev(DEVICE *dev); -int weof_dev(DEVICE *dev, int num); -int write_block(DEVICE *dev); -int write_dev(DEVICE *dev, char *buf, size_t len); -int read_dev(DEVICE *dev, char *buf, size_t len); -int status_dev(DEVICE *dev, uint32_t *status); -int eod_dev(DEVICE *dev); -int fsf_dev(DEVICE *dev, int num); -int fsr_dev(DEVICE *dev, int num); -int bsf_dev(DEVICE *dev, int num); -int bsr_dev(DEVICE *dev, int num); -void attach_jcr_to_device(DEVICE *dev, JCR *jcr); -void detach_jcr_from_device(DEVICE *dev, JCR *jcr); -JCR *next_attached_jcr(DEVICE *dev, JCR *jcr); -int dev_can_write(DEVICE *dev); +DEVICE *init_dev(DEVICE *dev, DEVRES *device); +int open_dev(DEVICE *dev, char *VolName, int mode); +void close_dev(DEVICE *dev); +void force_close_dev(DEVICE *dev); +int truncate_dev(DEVICE *dev); +void term_dev(DEVICE *dev); +char * strerror_dev(DEVICE *dev); +void clrerror_dev(DEVICE *dev, int func); +int update_pos_dev(DEVICE *dev); +int rewind_dev(DEVICE *dev); +int load_dev(DEVICE *dev); +int offline_dev(DEVICE *dev); +int flush_dev(DEVICE *dev); +int weof_dev(DEVICE *dev, int num); +int write_block(DEVICE *dev); +int write_dev(DEVICE *dev, char *buf, size_t len); +int read_dev(DEVICE *dev, char *buf, size_t len); +int status_dev(DEVICE *dev, uint32_t *status); +int eod_dev(DEVICE *dev); +int fsf_dev(DEVICE *dev, int num); +int fsr_dev(DEVICE *dev, int num); +int bsf_dev(DEVICE *dev, int num); +int bsr_dev(DEVICE *dev, int num); +void attach_jcr_to_device(DEVICE *dev, JCR *jcr); +void detach_jcr_from_device(DEVICE *dev, JCR *jcr); +JCR *next_attached_jcr(DEVICE *dev, JCR *jcr); +int dev_can_write(DEVICE *dev); /* Get info about device */ -char * dev_name(DEVICE *dev); -char * dev_vol_name(DEVICE *dev); +char * dev_name(DEVICE *dev); +char * dev_vol_name(DEVICE *dev); uint32_t dev_block(DEVICE *dev); uint32_t dev_file(DEVICE *dev); -int dev_is_tape(DEVICE *dev); +int dev_is_tape(DEVICE *dev); /* From device.c */ -int open_device(DEVICE *dev); -int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +int open_device(DEVICE *dev); +int fixup_device_block_write_error(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); void _lock_device(char *file, int line, DEVICE *dev); void _unlock_device(char *file, int line, DEVICE *dev); void _block_device(char *file, int line, DEVICE *dev, int state); @@ -123,41 +123,41 @@ void new_steal_device_lock(DEVICE *dev, brwsteal_t *hold, int state); void new_return_device_lock(DEVICE *dev, brwsteal_t *hold); /* From dircmd.c */ -void *connection_request(void *arg); +void *connection_request(void *arg); /* From fd_cmds.c */ -void run_job(JCR *jcr); +void run_job(JCR *jcr); /* From job.c */ -void stored_free_jcr(JCR *jcr); -void connection_from_filed(void *arg); -void handle_filed_connection(BSOCK *fd, char *job_name); +void stored_free_jcr(JCR *jcr); +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); -void create_session_label(JCR *jcr, DEV_RECORD *rec, int label); -void create_volume_label(DEVICE *dev, char *VolName); -int write_volume_label_to_dev(JCR *jcr, DEVRES *device, char *VolName, char *PoolName); -int write_session_label(JCR *jcr, DEV_BLOCK *block, int label); -int write_volume_label_to_block(JCR *jcr, DEVICE *dev, 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); +int read_dev_volume_label(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +void create_session_label(JCR *jcr, DEV_RECORD *rec, int label); +void create_volume_label(DEVICE *dev, char *VolName); +int write_volume_label_to_dev(JCR *jcr, DEVRES *device, char *VolName, char *PoolName); +int write_session_label(JCR *jcr, DEV_BLOCK *block, int label); +int write_volume_label_to_block(JCR *jcr, DEVICE *dev, 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); /* From match_bsr.c */ int match_bsr(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, - SESSION_LABEL *sesrec); + SESSION_LABEL *sesrec); /* From mount.c */ -int mount_next_write_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, int release); -int mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); +int mount_next_write_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, int release); +int mount_next_read_volume(JCR *jcr, DEVICE *dev, DEV_BLOCK *block); /* From autochanger.c */ -int autoload_device(JCR *jcr, DEVICE *dev, int writing, BSOCK *dir); -int autochanger_list(JCR *jcr, DEVICE *dev, BSOCK *dir); -void invalidate_slot_in_catalog(JCR *jcr); +int autoload_device(JCR *jcr, DEVICE *dev, int writing, BSOCK *dir); +int autochanger_list(JCR *jcr, DEVICE *dev, BSOCK *dir); +void invalidate_slot_in_catalog(JCR *jcr); /* From parse_bsr.c */ @@ -172,11 +172,11 @@ extern void create_vol_list(JCR *jcr); /* From record.c */ char *FI_to_ascii(int fi); char *stream_to_ascii(int stream, int fi); -int write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec); -int can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec); -int read_record_from_block(DEV_BLOCK *block, DEV_RECORD *rec); +int write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec); +int can_write_record_to_block(DEV_BLOCK *block, DEV_RECORD *rec); +int read_record_from_block(DEV_BLOCK *block, DEV_RECORD *rec); DEV_RECORD *new_record(); -void free_record(DEV_RECORD *rec); +void free_record(DEV_RECORD *rec); /* From read_record.c */ int read_records(JCR *jcr, DEVICE *dev, diff --git a/bacula/src/stored/read.c b/bacula/src/stored/read.c index d3a17145c8..b26cf7d00a 100644 --- a/bacula/src/stored/read.c +++ b/bacula/src/stored/read.c @@ -113,7 +113,7 @@ int do_read_data(JCR *jcr) * Read records, apply BSR filtering, and return any that are * matched. */ - for ( ;ok && !done; ) { + for ( ; ok && !done; ) { if (job_canceled(jcr)) { ok = FALSE; break; @@ -142,6 +142,9 @@ int do_read_data(JCR *jcr) if (dev->state & ST_SHORT) { continue; } + /* I/O error -- or non-standard end of tape */ + ok = FALSE; + break; } for (rec->state=0; !is_block_empty(rec); ) { diff --git a/bacula/src/stored/read_record.c b/bacula/src/stored/read_record.c index c376f84fd4..ed1ed3f5f5 100644 --- a/bacula/src/stored/read_record.c +++ b/bacula/src/stored/read_record.c @@ -51,7 +51,7 @@ int read_records(JCR *jcr, DEVICE *dev, block = new_block(dev); rec = new_record(); - for ( ;ok && !done; ) { + for ( ; ok && !done; ) { if (job_canceled(jcr)) { ok = FALSE; break; @@ -94,16 +94,17 @@ int read_records(JCR *jcr, DEVICE *dev, goto next_record; } if (dev->state & ST_EOF) { - Emsg2(M_INFO, 0, "Got EOF on device %s, Volume \"%s\"\n", + Jmsg(jcr, M_INFO, 0, "Got EOF on device %s, Volume \"%s\"\n", dev_name(dev), jcr->VolumeName); Dmsg0(20, "read_record got eof. try again\n"); continue; } if (dev->state & ST_SHORT) { - Emsg0(M_INFO, 0, dev->errmsg); + Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg); continue; } - display_error_status(dev); + /* I/O error or strange end of tape */ + display_tape_error_status(jcr, dev); ok = FALSE; break; } -- 2.39.5