From 7f7447d979d17abff0019fe878cb3794b2600126 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Thu, 26 Oct 2017 07:51:42 +0200 Subject: [PATCH] Backport Enterprise code --- bacula/src/dird/dird.c | 11 ++--------- bacula/src/filed/filed.c | 12 ++---------- bacula/src/lib/message.c | 14 ++++++++++++++ bacula/src/lib/protos.h | 2 ++ bacula/src/stored/aligned_dev.h | 2 -- bacula/src/stored/append.c | 2 +- bacula/src/stored/block_util.c | 2 +- bacula/src/stored/btape.c | 2 +- bacula/src/stored/dev.h | 2 -- bacula/src/stored/device.c | 4 ++++ bacula/src/stored/file_dev.c | 3 +-- bacula/src/stored/label.c | 34 +++++++++++++++++---------------- bacula/src/stored/stored.c | 13 ++----------- regress/scripts/functions.pm | 5 ++++- 14 files changed, 52 insertions(+), 56 deletions(-) diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 9bde2ebb84..c950080d59 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -82,8 +82,6 @@ extern dlist client_globals; extern dlist store_globals; extern dlist job_globals; extern dlist sched_globals; -extern dlist *daemon_msg_queue; -extern pthread_mutex_t daemon_msg_queue_mutex; extern RES_ITEM job_items[]; #if defined(_MSC_VER) extern "C" { // work around visual compiler mangling variables @@ -175,7 +173,6 @@ int main (int argc, char *argv[]) bool no_signals = false; char *uid = NULL; char *gid = NULL; - MQUEUE_ITEM *item = NULL; /* DELETE ME when bugs in MA1512, MA1632 MA1639 are fixed */ MA1512_reload_job_end_cb = reload_job_end_cb; @@ -190,8 +187,7 @@ int main (int argc, char *argv[]) init_msg(NULL, NULL); /* initialize message handler */ init_reload(); daemon_start_time = time(NULL); - /* Setup daemon message queue */ - daemon_msg_queue = New(dlist(item, &item->link)); + setup_daemon_message_queue(); console_command = run_console_command; while ((ch = getopt(argc, argv, "c:d:fg:mr:stu:v?T")) != -1) { @@ -698,10 +694,7 @@ void terminate_dird(int sig) term_msg(); /* terminate message handler */ cleanup_crypto(); - P(daemon_msg_queue_mutex); - daemon_msg_queue->destroy(); - free(daemon_msg_queue); - V(daemon_msg_queue_mutex); + free_daemon_message_queue(); if (reload_table) { free(reload_table); diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 28b2baffd2..b9a7d74108 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -37,9 +37,6 @@ CLIENT *me; /* my resource */ bool no_signals = false; void *start_heap; extern struct s_cmds cmds[]; -extern dlist *daemon_msg_queue; -extern pthread_mutex_t daemon_msg_queue_mutex; - #ifndef CONFIG_FILE /* Might be overwritten */ #define CONFIG_FILE "bacula-fd.conf" /* default config file */ @@ -90,7 +87,6 @@ int main (int argc, char *argv[]) bool keep_readall_caps = false; char *uid = NULL; char *gid = NULL; - MQUEUE_ITEM *item = NULL; start_heap = sbrk(0); setlocale(LC_ALL, ""); @@ -101,8 +97,7 @@ int main (int argc, char *argv[]) my_name_is(argc, argv, PROG_NAME); init_msg(NULL, NULL); daemon_start_time = time(NULL); - /* Setup daemon message queue */ - daemon_msg_queue = New(dlist(item, &item->link)); + setup_daemon_message_queue(); while ((ch = getopt(argc, argv, "c:d:fg:kmstTu:v?D:")) != -1) { switch (ch) { @@ -285,10 +280,7 @@ void terminate_filed(int sig) generate_daemon_event(NULL, "Exit"); unload_plugins(); - P(daemon_msg_queue_mutex); - daemon_msg_queue->destroy(); - free(daemon_msg_queue); - V(daemon_msg_queue_mutex); + free_daemon_message_queue(); if (!test_config) { write_state_file(me->working_directory, diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 5aa6fdd8fe..5e90f0fefa 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -1905,3 +1905,17 @@ bool debug_parse_tags(const char *options, int64_t *current_level) } int generate_daemon_event(JCR *jcr, const char *event) { return 0; } + +void setup_daemon_message_queue() +{ + static MQUEUE_ITEM *item = NULL; + daemon_msg_queue = New(dlist(item, &item->link)); +} + +void free_daemon_message_queue() +{ + P(daemon_msg_queue_mutex); + daemon_msg_queue->destroy(); + free(daemon_msg_queue); + V(daemon_msg_queue_mutex); +} diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index f76d790f45..de4d5d6aa2 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -274,6 +274,8 @@ int get_blowup (void); bool handle_hangup_blowup (JCR *jcr, uint32_t file_count, uint64_t byte_count); void set_assert_msg (const char *file, int line, const char *msg); void register_message_callback(void msg_callback(int type, char *msg)); +void setup_daemon_message_queue(); +void free_daemon_message_queue(); /* bnet_server.c */ void bnet_thread_server(dlist *addr_list, int max_clients, diff --git a/bacula/src/stored/aligned_dev.h b/bacula/src/stored/aligned_dev.h index 612b55b5d1..4e5a993dad 100644 --- a/bacula/src/stored/aligned_dev.h +++ b/bacula/src/stored/aligned_dev.h @@ -23,8 +23,6 @@ #ifndef _ALIGNED_DEV_H_ #define _ALIGNED_DEV_H_ -inline const char *DEVICE::aligned_name() const { return adev_name; } - class aligned_dev : public file_dev { public: diff --git a/bacula/src/stored/append.c b/bacula/src/stored/append.c index aed73b3cbf..9d137e2028 100644 --- a/bacula/src/stored/append.c +++ b/bacula/src/stored/append.c @@ -304,7 +304,7 @@ fi_checked: if (ok || dev->can_write()) { if (!dev->flush_before_eos(dcr)) { /* Print only if ok and not cancelled to avoid spurious messages */ - if (!jcr->is_job_canceled()) { + if (ok && !jcr->is_job_canceled()) { Jmsg2(jcr, M_FATAL, 0, _("Fatal append error on device %s: ERR=%s\n"), dev->print_name(), dev->bstrerror()); Dmsg0(100, _("Set ok=FALSE after write_block_to_device.\n")); diff --git a/bacula/src/stored/block_util.c b/bacula/src/stored/block_util.c index ed18bd8573..bf0a8c3872 100644 --- a/bacula/src/stored/block_util.c +++ b/bacula/src/stored/block_util.c @@ -251,7 +251,7 @@ void DEVICE::free_dcr_blocks(DCR *dcr) void free_block(DEV_BLOCK *block) { if (block) { - Dmsg1(999, "free_block block=%p\n", block); + Dmsg1(999, "free_block buffer=%p\n", block->buf); if (block->buf) { free_memory(block->buf); } diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index e88a9b7934..959bf0c60b 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -773,7 +773,7 @@ static void rectestcmd() } free_record(rec); Dmsg0(900, "=== free_blocks\n"); - dcr->dev->free_dcr_blocks(dcr); + free_block(dcr->block); dcr->block = save_block; /* restore block to dcr */ Dsm_check(200); } diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 924fa67994..412205b1d6 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -402,7 +402,6 @@ public: bool must_load() const { return m_load; }; const char *strerror() const; const char *archive_name() const; - const char *aligned_name() const; const char *name() const; const char *print_name() const; /* Name for display purposes */ void set_ateot(); /* in dev.c */ @@ -795,7 +794,6 @@ public: int try_autolabel(bool opened); bool find_a_volume(); bool is_suitable_volume_mounted(); - bool is_eod_valid(); int check_volume_label(bool &ask, bool &autochanger); void release_volume(); void do_swapping(bool is_writing); diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 27be8c1950..a748455f9f 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -110,6 +110,10 @@ bool fixup_device_block_write_error(DCR *dcr, int retries) bstrncpy(PrevVolName, dev->getVolCatName(), sizeof(PrevVolName)); bstrncpy(dev->VolHdr.PrevVolumeName, PrevVolName, sizeof(dev->VolHdr.PrevVolumeName)); + /* create temporary block, that will be released at the end, current blocks + * have been saved in local DEV_BLOCK above and will be restored before to + * leave the function + */ dev->new_dcr_blocks(dcr); /* Inform User about end of medium */ diff --git a/bacula/src/stored/file_dev.c b/bacula/src/stored/file_dev.c index 516274ef23..365e148f80 100644 --- a/bacula/src/stored/file_dev.c +++ b/bacula/src/stored/file_dev.c @@ -208,7 +208,7 @@ bool file_dev::open_device(DCR *dcr, int omode) pm_strcpy(dcr->jcr->errmsg, errmsg); } } - Dmsg1(100, "open dev: disk fd=%d opened, aligned=%d\n", m_fd); + Dmsg1(100, "open dev: disk fd=%d opened\n", m_fd); state |= preserve; /* reset any important state info */ Leave(dbglvl); @@ -235,7 +235,6 @@ bool DEVICE::truncate(DCR *dcr) break; } - /* Do truncate for 1 or 2 devices */ Dmsg2(100, "Truncate adata=%d fd=%d\n", dev->adata, dev->m_fd); if (ftruncate(dev->m_fd, 0) != 0) { berrno be; diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index f205dcd3cb..6f41b7bb0f 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -400,25 +400,27 @@ bool DEVICE::write_volume_label(DCR *dcr, const char *VolName, goto bail_out; } - /* Not aligned data */ - if (dev->weof(dcr, 1)) { - dev->set_labeled(); - } + if (!dev->is_aligned()) { + /* Not aligned data */ + if (dev->weof(dcr, 1)) { + dev->set_labeled(); + } - if (chk_dbglvl(100)) { - dev->dump_volume_label(); - } - Dmsg0(50, "Call reserve_volume\n"); - /**** ***FIXME*** if dev changes, dcr must be updated */ - if (reserve_volume(dcr, VolName) == NULL) { - if (!dcr->jcr->errmsg[0]) { - Mmsg3(dcr->jcr->errmsg, _("Could not reserve volume %s on %s device %s\n"), - dev->VolHdr.VolumeName, dev->print_type(), dev->print_name()); + if (chk_dbglvl(100)) { + dev->dump_volume_label(); } - Dmsg1(50, "%s", dcr->jcr->errmsg); - goto bail_out; + Dmsg0(50, "Call reserve_volume\n"); + /**** ***FIXME*** if dev changes, dcr must be updated */ + if (reserve_volume(dcr, VolName) == NULL) { + if (!dcr->jcr->errmsg[0]) { + Mmsg3(dcr->jcr->errmsg, _("Could not reserve volume %s on %s device %s\n"), + dev->VolHdr.VolumeName, dev->print_type(), dev->print_name()); + } + Dmsg1(50, "%s", dcr->jcr->errmsg); + goto bail_out; + } + dev = dcr->dev; /* may have changed in reserve_volume */ } - dev = dcr->dev; /* may have changed in reserve_volume */ dev->clear_append(); /* remove append since this is PRE_LABEL */ Leave(100); return true; diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 5886433d9a..9ca4c56024 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -40,10 +40,6 @@ /* Imported functions and variables */ extern bool parse_sd_config(CONFIG *config, const char *configfile, int exit_code); -extern dlist *daemon_msg_queue; -extern pthread_mutex_t daemon_msg_queue_mutex; - - /* Forward referenced functions */ void terminate_stored(int sig); static int check_resources(); @@ -131,7 +127,6 @@ int main (int argc, char *argv[]) pthread_t thid; char *uid = NULL; char *gid = NULL; - MQUEUE_ITEM *item = NULL; start_heap = sbrk(0); setlocale(LC_ALL, ""); @@ -142,8 +137,7 @@ int main (int argc, char *argv[]) my_name_is(argc, argv, "bacula-sd"); init_msg(NULL, NULL); daemon_start_time = time(NULL); - /* Setup daemon message queue */ - daemon_msg_queue = New(dlist(item, &item->link)); + setup_daemon_message_queue(); /* Sanity checks */ if (TAPE_BSIZE % B_DEV_BSIZE != 0 || TAPE_BSIZE / B_DEV_BSIZE == 0) { @@ -756,10 +750,7 @@ void terminate_stored(int sig) unload_plugins(); free_volume_lists(); - P(daemon_msg_queue_mutex); - daemon_msg_queue->destroy(); - free(daemon_msg_queue); - V(daemon_msg_queue_mutex); + free_daemon_message_queue(); foreach_res(device, R_DEVICE) { Dmsg2(10, "Term device %s %s\n", device->hdr.name, device->device_name); diff --git a/regress/scripts/functions.pm b/regress/scripts/functions.pm index 4e1ed546da..32ed40159e 100644 --- a/regress/scripts/functions.pm +++ b/regress/scripts/functions.pm @@ -219,7 +219,8 @@ sub start_bacula 'truncate client_group_member;', 'update Media set LocationId=0;', 'truncate location;', - ''); + '', + 'quit'); run_bconsole(); return $ret; } @@ -400,6 +401,7 @@ sub check_parts print FP "\@echo File generated by scripts::function::check_part()\n"; print FP "sql\n"; print FP "SELECT 'Name', VolumeName, Storage.Name FROM Media JOIN Storage USING (StorageId) WHERE VolType = 14;\n"; + print FP "\nquit\n"; close(FP); unlink("$tmp/check_parts.out"); @@ -444,6 +446,7 @@ sub check_jobmedia print FP "SELECT 'Index', JobId, FirstIndex, LastIndex, JobMediaId FROM JobMedia ORDER BY JobId, JobMediaId;\n"; print FP "SELECT 'Block', JobId, MediaId, StartFile, EndFile, StartBlock, EndBlock, JobMediaId FROM JobMedia ORDER BY JobId, JobMediaId;\n"; print FP "SELECT 'ERROR StartAddress > EndAddress (JobMediaId)', JobMediaId from JobMedia where ((CAST(StartFile AS bigint)<<32) + StartBlock) > ((CAST (EndFile AS bigint) <<32) + EndBlock);\n"; + print FP "\nquit\n"; close(FP); my $tempfile = "$tmp/check_jobmedia.$$"; -- 2.39.5