From: Kern Sibbald Date: Thu, 13 Aug 2009 17:21:45 +0000 (+0200) Subject: Make SD lock tracing work again. Has not worked for some time. X-Git-Tag: Release-5.0.0~333^2~4 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=befa6e13a2e22e9c93b7bb313f6f3b65b0ebf95b;p=bacula%2Fbacula Make SD lock tracing work again. Has not worked for some time. --- diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index a7763a725e..477fde6161 100644 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -641,6 +641,30 @@ JCR *get_jcr_by_id(uint32_t JobId) return jcr; } +/* + * Given a thread id, find the JobId + * Returns: JobId on success + * 0 on failure + */ +uint32_t get_jobid_from_tid(pthread_t tid) +{ + JCR *jcr = NULL; + bool found = false; + + foreach_jcr(jcr) { + if (pthread_equal(jcr->my_thread_id, tid)) { + found = true; + break; + } + } + endeach_jcr(jcr); + if (found) { + return jcr->JobId; + } + return 0; +} + + /* * Given a SessionId and SessionTime, find the JCR * Returns: jcr on success diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index d2efd2c9fa..5379ec5e05 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -191,23 +191,24 @@ bool is_an_integer (const char *n); bool is_name_valid (char *name, POOLMEM **msg); /* jcr.c (most definitions are in src/jcr.h) */ -void init_last_jobs_list(); -void term_last_jobs_list(); -void lock_last_jobs_list(); -void unlock_last_jobs_list(); -bool read_last_jobs_list(int fd, uint64_t addr); +void init_last_jobs_list(); +void term_last_jobs_list(); +void lock_last_jobs_list(); +void unlock_last_jobs_list(); +bool read_last_jobs_list(int fd, uint64_t addr); uint64_t write_last_jobs_list(int fd, uint64_t addr); -void write_state_file(char *dir, const char *progname, int port); -void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx); -void lock_jobs(); -void unlock_jobs(); -JCR *jcr_walk_start(); -JCR *jcr_walk_next(JCR *prev_jcr); -void jcr_walk_end(JCR *jcr); +void write_state_file(char *dir, const char *progname, int port); +void job_end_push(JCR *jcr, void job_end_cb(JCR *jcr,void *), void *ctx); +void lock_jobs(); +void unlock_jobs(); +JCR *jcr_walk_start(); +JCR *jcr_walk_next(JCR *prev_jcr); +void jcr_walk_end(JCR *jcr); +JCR *get_jcr_from_tsd(); +void set_jcr_in_tsd(JCR *jcr); +void remove_jcr_from_tsd(JCR *jcr); uint32_t get_jobid_from_tsd(); -JCR *get_jcr_from_tsd(); -void set_jcr_in_tsd(JCR *jcr); -void remove_jcr_from_tsd(JCR *jcr); +uint32_t get_jobid_from_tid(pthread_t tid); /* lex.c */ diff --git a/bacula/src/lib/signal.c b/bacula/src/lib/signal.c index a8b39936ed..0e5acea298 100644 --- a/bacula/src/lib/signal.c +++ b/bacula/src/lib/signal.c @@ -101,10 +101,9 @@ static void dbg_print_bacula() /* Print also B_DB and RWLOCK structure * Can add more info about JCR with dbg_jcr_add_hook() */ + dbg_print_lock(fp); _dbg_print_jcr(fp); - _dbg_print_plugin(fp); - dbg_print_lock(fp); if (fp != stderr) { fclose(fp); diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 117122919f..abb53c25c3 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2001-2008 Free Software Foundation Europe e.V. + Copyright (C) 2001-2009 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. diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index b0424b4306..052015e23f 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -455,6 +455,7 @@ public: #endif void dblock(int why); /* in lock.c */ void dunblock(bool locked=false); /* in lock.c */ + bool is_device_unmounted(); /* in lock.c */ void set_blocked(int block) { m_blocked = block; }; int blocked() const { return m_blocked; }; bool is_blocked() const { return m_blocked != BST_NOT_BLOCKED; }; @@ -530,8 +531,13 @@ public: void clear_found_in_use() { m_found_in_use = false; }; bool is_reserved() const { return m_reserved; }; bool is_dev_locked() { return m_dev_locked; } +#ifdef SD_DEBUG_LOCK + void _dlock(const char *, int); /* in lock.c */ + void _dunlock(const char *, int); /* in lock.c */ +#else void dlock() { dev->dlock(); m_dev_locked = true; } void dunlock() { m_dev_locked = false; dev->dunlock(); } +#endif void dblock(int why) { dev->dblock(why); } diff --git a/bacula/src/stored/lock.c b/bacula/src/stored/lock.c index aea4b6a203..40a134b0dc 100644 --- a/bacula/src/stored/lock.c +++ b/bacula/src/stored/lock.c @@ -155,17 +155,28 @@ void DEVICE::dunblock(bool locked) #ifdef SD_DEBUG_LOCK +void DCR::_dlock(const char *file, int line) +{ + dev->_dlock(file, line); + m_dev_locked = true; +} +void DCR::_dunlock(const char *file, int line) +{ + m_dev_locked = false; + dev->_dunlock(file, line); + +} + void DEVICE::_dlock(const char *file, int line) { - Dmsg4(sd_dbglvl, "dlock from %s:%d precnt=%d JobId=%u\n", file, line, - m_count, get_jobid_from_tid()); + Dmsg3(sd_dbglvl, "dlock from %s:%d precnt=%d\n", file, line, m_count); /* Note, this *really* should be protected by a mutex, but * since it is only debug code we don't worry too much. */ if (m_count > 0 && pthread_equal(m_pid, pthread_self())) { - Dmsg5(sd_dbglvl, "Possible DEADLOCK!! lock held by JobId=%u from %s:%d m_count=%d JobId=%u\n", + Dmsg4(sd_dbglvl, "Possible DEADLOCK!! lock held by JobId=%u from %s:%d m_count=%d\n", get_jobid_from_tid(m_pid), - file, line, m_count, get_jobid_from_tid()); + file, line, m_count); } P(m_mutex); m_pid = pthread_self(); @@ -175,8 +186,7 @@ void DEVICE::_dlock(const char *file, int line) void DEVICE::_dunlock(const char *file, int line) { m_count--; - Dmsg4(sd_dbglvl+1, "dunlock from %s:%d postcnt=%d JobId=%u\n", file, line, - m_count, get_jobid_from_tid()); + Dmsg3(sd_dbglvl+1, "dunlock from %s:%d postcnt=%d\n", file, line, m_count); V(m_mutex); } @@ -198,14 +208,15 @@ void DEVICE::_r_dunlock(const char *file, int line) #ifdef SD_DEBUG_LOCK void DEVICE::_r_dlock(const char *file, int line) { - Dmsg4(sd_dbglvl+1, "r_dlock blked=%s from %s:%d JobId=%u\n", this->print_blocked(), - file, line, get_jobid_from_tid()); + Dmsg3(sd_dbglvl+1, "r_dlock blked=%s from %s:%d\n", this->print_blocked(), + file, line); #else void DEVICE::r_dlock() { #endif int stat; - this->dlock(); + P(m_mutex); /* this->dlock(); */ + m_count++; /* this->dlock() */ if (this->blocked() && !pthread_equal(this->no_wait_id, pthread_self())) { this->num_waiting++; /* indicate that I am waiting */ while (this->blocked()) { diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index db34f428e0..e18ca3aa32 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -131,7 +131,6 @@ bool fixup_device_block_write_error(DCR *dcr); void set_start_vol_position(DCR *dcr); void set_new_volume_parameters(DCR *dcr); void set_new_file_parameters(DCR *dcr); -bool is_device_unmounted(DEVICE *dev); /* From dircmd.c */ void *handle_connection_request(void *arg); @@ -231,32 +230,30 @@ extern int reservations_lock_count; #ifdef SD_DEBUG_LOCK #define lock_reservations() \ - do { Dmsg4(sd_dbglvl, "lock_reservations at %s:%d precnt=%d JobId=%u\n", \ + do { Dmsg3(sd_dbglvl, "lock_reservations at %s:%d precnt=%d\n", \ __FILE__, __LINE__, \ - reservations_lock_count, get_jobid_from_tid(pthread_self())); \ + reservations_lock_count); \ _lock_reservations(); \ - Dmsg1(sd_dbglvl, "lock_reservations: got lock JobId=%u\n", \ - get_jobid_from_tid(pthread_self())); \ + Dmsg0(sd_dbglvl, "lock_reservations: got lock\n"); \ } while (0) #define unlock_reservations() \ - do { Dmsg4(sd_dbglvl, "unlock_reservations at %s:%d precnt=%d JobId=%u\n", \ + do { Dmsg3(sd_dbglvl, "unlock_reservations at %s:%d precnt=%d\n", \ __FILE__, __LINE__, \ - reservations_lock_count, get_jobid_from_tid(pthread_self())); \ + reservations_lock_count); \ _unlock_reservations(); } while (0) #define lock_volumes() \ - do { Dmsg4(sd_dbglvl, "lock_volumes at %s:%d precnt=%d JobId=%u\n", \ + do { Dmsg3(sd_dbglvl, "lock_volumes at %s:%d precnt=%d\n", \ __FILE__, __LINE__, \ - vol_list_lock_count, get_jobid_from_tid(pthread_self())); \ + vol_list_lock_count); \ _lock_volumes(); \ - Dmsg1(sd_dbglvl, "lock_volumes: got lock JobId=%u\n", \ - get_jobid_from_tid(pthread_self())); \ + Dmsg0(sd_dbglvl, "lock_volumes: got lock\n"); \ } while (0) #define unlock_volumes() \ - do { Dmsg4(sd_dbglvl, "unlock_volumes at %s:%d precnt=%d JobId=%u\n", \ + do { Dmsg3(sd_dbglvl, "unlock_volumes at %s:%d precnt=%d\n", \ __FILE__, __LINE__, \ - vol_list_lock_count, get_jobid_from_tid(pthread_self())); \ + vol_list_lock_count); \ _unlock_volumes(); } while (0) #else diff --git a/bacula/src/stored/stored.h b/bacula/src/stored/stored.h index eadd47b9b7..1229ad54d9 100644 --- a/bacula/src/stored/stored.h +++ b/bacula/src/stored/stored.h @@ -1,7 +1,7 @@ /* Bacula® - The Network Backup Solution - Copyright (C) 2000-2008 Free Software Foundation Europe e.V. + Copyright (C) 2000-2009 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. @@ -38,7 +38,11 @@ /* Set to debug mutexes */ //#define SD_DEBUG_LOCK +#ifdef SD_DEBUG_LOCK +const int sd_dbglvl = 3; +#else const int sd_dbglvl = 300; +#endif #ifdef HAVE_MTIO_H #include diff --git a/bacula/technotes b/bacula/technotes index e797bf8efc..d41b2cebaf 100644 --- a/bacula/technotes +++ b/bacula/technotes @@ -2,6 +2,8 @@ General: +13Aug09 +kes Make SD lock tracing work again. Has not worked for some time. 12Aug09 kes Make new big-virtual-changer test. Test concurrency. ebl Add .lsfiles, .lsdirs, .update command to interface user with bvfs object diff --git a/regress/tests/big-virtual-changer-test b/regress/tests/big-virtual-changer-test index 81dfba2929..d38847daa3 100755 --- a/regress/tests/big-virtual-changer-test +++ b/regress/tests/big-virtual-changer-test @@ -42,7 +42,7 @@ cat <${cwd}/tmp/bconcmds @output /dev/null messages @$out ${cwd}/tmp/log1.out -setdebug level=100 storage=Virtual +setdebug level=10 storage=Virtual @#setdebug level=200 client=$CLIENT label storage=Virtual volume=TestVolume001 slot=1 Pool=Default drive=0 label storage=Virtual volume=TestVolume002 slot=2 Pool=Full drive=0