From: Kern Sibbald Date: Sun, 1 Apr 2007 13:19:03 +0000 (+0000) Subject: Move bnet_despool() into class in bsock.c X-Git-Tag: Release-7.0.0~6637 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=16f9788651d8139c31d8bda6010fd428fe0d14f8;p=bacula%2Fbacula Move bnet_despool() into class in bsock.c git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4489 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/dird/scheduler.c b/bacula/src/dird/scheduler.c index 35c4178766..97a60dbe09 100644 --- a/bacula/src/dird/scheduler.c +++ b/bacula/src/dird/scheduler.c @@ -175,11 +175,11 @@ again: } /* Recheck at least once per minute */ bmicrosleep((next_check_secs < twait)?next_check_secs:twait, 0); - /* Attempt to handle clock shift from/to daylight savings time + /* Attempt to handle clock shift (but not daylight savings time changes) * we allow a skew of 10 seconds before invalidating everything. */ now = time(NULL); - if (now < prev+10 || now > (prev+next_check_secs+10)) { + if (now < prev-10 || now > (prev+next_check_secs+10)) { schedules_invalidated = true; } } @@ -284,6 +284,9 @@ static void find_runs() wom = mday / 7; woy = tm_woy(now); /* get week of year */ + Dmsg7(dbglvl, "now = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n", + now, hour, month, mday, wday, wom, woy); + /* * Compute values for next hour from now. * We do this to be sure we don't miss a job while @@ -299,6 +302,9 @@ static void find_runs() nh_wom = nh_mday / 7; nh_woy = tm_woy(now); /* get week of year */ + Dmsg7(dbglvl, "nh = %x: h=%d m=%d md=%d wd=%d wom=%d woy=%d\n", + next_hour, nh_hour, nh_month, nh_mday, nh_wday, nh_wom, nh_woy); + /* Loop through all jobs */ LockRes(); foreach_res(job, R_JOB) { @@ -351,24 +357,20 @@ static void find_runs() Dmsg3(dbglvl, "run@%p: run_now=%d run_nh=%d\n", run, run_now, run_nh); - /* find time (time_t) job is to be run */ - (void)localtime_r(&now, &tm); /* reset tm structure */ - tm.tm_min = run->minute; /* set run minute */ - tm.tm_sec = 0; /* zero secs */ - if (run_now) { - runtime = mktime(&tm); - add_job(job, run, now, runtime); - } - /* If job is to be run in the next hour schedule it */ - if (run_nh) { - /* Set correct values */ - tm.tm_hour = nh_hour; - tm.tm_mday = nh_mday + 1; /* fixup because we biased for tests above */ - tm.tm_mon = nh_month; - tm.tm_year = nh_year; - runtime = mktime(&tm); - add_job(job, run, now, runtime); - } + if (run_now || run_nh) { + /* find time (time_t) job is to be run */ + (void)localtime_r(&now, &tm); /* reset tm structure */ + tm.tm_min = run->minute; /* set run minute */ + tm.tm_sec = 0; /* zero secs */ + runtime = mktime(&tm); + if (run_now) { + add_job(job, run, now, runtime); + } + /* If job is to be run in the next hour schedule it */ + if (run_nh) { + add_job(job, run, now, runtime + 3600); + } + } } } UnlockRes(); diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index c63a4e9f0e..c92bdc7ab4 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -215,55 +215,6 @@ void bnet_suppress_error_messages(BSOCK * bsock, bool flag) bsock->suppress_error_msgs = flag; } - -/* - * Transmit spooled data now to a BSOCK - */ -int bnet_despool_to_bsock(BSOCK * bsock, void update_attr_spool_size(ssize_t size), - ssize_t tsize) -{ - int32_t pktsiz; - size_t nbytes; - ssize_t last = 0, size = 0; - int count = 0; - - rewind(bsock->spool_fd); - while (fread((char *)&pktsiz, 1, sizeof(int32_t), bsock->spool_fd) == - sizeof(int32_t)) { - size += sizeof(int32_t); - bsock->msglen = ntohl(pktsiz); - if (bsock->msglen > 0) { - if (bsock->msglen > (int32_t) sizeof_pool_memory(bsock->msg)) { - bsock->msg = realloc_pool_memory(bsock->msg, bsock->msglen + 1); - } - nbytes = fread(bsock->msg, 1, bsock->msglen, bsock->spool_fd); - if (nbytes != (size_t) bsock->msglen) { - berrno be; - Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, bsock->msglen); - Qmsg1(bsock->jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), - be.strerror()); - update_attr_spool_size(tsize - last); - return 0; - } - size += nbytes; - if ((++count & 0x3F) == 0) { - update_attr_spool_size(size - last); - last = size; - } - } - bnet_send(bsock); - } - update_attr_spool_size(tsize - last); - if (ferror(bsock->spool_fd)) { - berrno be; - Qmsg1(bsock->jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), - be.strerror()); - return 0; - } - return 1; -} - - /* * Send a message over the network. The send consists of * two network packets. The first is sends a 32 bit integer containing @@ -277,82 +228,6 @@ bool bnet_send(BSOCK *bsock) return bsock->send(); } -#ifdef xxx -bool bnet_send(BSOCK * bsock) -{ - int32_t rc; - int32_t pktsiz; - - if (bsock->errors || bsock->terminated || bsock->msglen > 1000000) { - return false; - } - pktsiz = htonl((int32_t)bsock->msglen); - /* send int32_t containing size of data packet */ - bsock->timer_start = watchdog_time; /* start timer */ - bsock->timed_out = 0; - rc = write_nbytes(bsock, (char *)&pktsiz, sizeof(int32_t)); - bsock->timer_start = 0; /* clear timer */ - if (rc != sizeof(int32_t)) { - if (bsock->msglen == BNET_TERMINATE) { /* if we were terminating */ - bsock->terminated = 1; - return false; /* ignore any errors */ - } - bsock->errors++; - if (errno == 0) { - bsock->b_errno = EIO; - } else { - bsock->b_errno = errno; - } - if (rc < 0) { - if (!bsock->suppress_error_msgs && !bsock->timed_out) { - Qmsg4(bsock->jcr(), M_ERROR, 0, - _("Write error sending len to %s:%s:%d: ERR=%s\n"), bsock->who, - bsock->host(), bsock->port(), bnet_strerror(bsock)); - } - } else { - Qmsg5(bsock->jcr(), M_ERROR, 0, - _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), - sizeof(int32_t), bsock->who(), - bsock->host(), bsock->port(), rc); - } - return false; - } - - bsock->out_msg_no++; /* increment message number */ - if (bsock->msglen <= 0) { /* length only? */ - return true; /* yes, no data */ - } - - /* send data packet */ - bsock->timer_start = watchdog_time; /* start timer */ - bsock->timed_out = 0; - rc = write_nbytes(bsock, bsock->msg, bsock->msglen); - bsock->timer_start = 0; /* clear timer */ - if (rc != bsock->msglen) { - bsock->errors++; - if (errno == 0) { - bsock->b_errno = EIO; - } else { - bsock->b_errno = errno; - } - if (rc < 0) { - if (!bsock->suppress_error_msgs) { - Qmsg5(bsock->jcr(), M_ERROR, 0, - _("Write error sending %d bytes to %s:%s:%d: ERR=%s\n"), - bsock->msglen, bsock->who(), - bsock->host(), bsock->port(), bnet_strerror(bsock)); - } - } else { - Qmsg5(bsock->jcr(), M_ERROR, 0, - _("Wrote %d bytes to %s:%s:%d, but only %d accepted.\n"), - bsock->msglen, bsock->who(), bsock->host(), - bsock->port(), rc); - } - return false; - } - return true; -} -#endif /* * Establish a TLS connection -- server side diff --git a/bacula/src/lib/bsock.c b/bacula/src/lib/bsock.c index 30a7eed18e..25e00a042e 100644 --- a/bacula/src/lib/bsock.c +++ b/bacula/src/lib/bsock.c @@ -275,6 +275,53 @@ bool BSOCK::signal(int signal) return send(); } +/* + * Despool spooled attributes + */ +bool BSOCK::despool(void update_attr_spool_size(ssize_t size), ssize_t tsize) +{ + int32_t pktsiz; + size_t nbytes; + ssize_t last = 0, size = 0; + int count = 0; + + rewind(spool_fd); + while (fread((char *)&pktsiz, 1, sizeof(int32_t), spool_fd) == + sizeof(int32_t)) { + size += sizeof(int32_t); + msglen = ntohl(pktsiz); + if (msglen > 0) { + if (msglen > (int32_t) sizeof_pool_memory(msg)) { + msg = realloc_pool_memory(msg, msglen + 1); + } + nbytes = fread(msg, 1, msglen, spool_fd); + if (nbytes != (size_t) msglen) { + berrno be; + Dmsg2(400, "nbytes=%d msglen=%d\n", nbytes, msglen); + Qmsg1(jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), + be.strerror()); + update_attr_spool_size(tsize - last); + return false; + } + size += nbytes; + if ((++count & 0x3F) == 0) { + update_attr_spool_size(size - last); + last = size; + } + } + send(); + } + update_attr_spool_size(tsize - last); + if (ferror(spool_fd)) { + berrno be; + Qmsg1(jcr(), M_FATAL, 0, _("fread attr spool error. ERR=%s\n"), + be.strerror()); + return false; + } + return true; +} + + void BSOCK::close() { BSOCK *bsock = this; diff --git a/bacula/src/lib/bsock.h b/bacula/src/lib/bsock.h index addace2b72..1bd1b73013 100644 --- a/bacula/src/lib/bsock.h +++ b/bacula/src/lib/bsock.h @@ -87,6 +87,7 @@ public: char *host() { return m_host; }; int port() { return m_port; }; JCR *jcr() { return m_jcr; }; + bool despool(void update_attr_spool_size(ssize_t size), ssize_t tsize); }; /* diff --git a/bacula/src/lib/protos.h b/bacula/src/lib/protos.h index a358209943..4c3dd934ca 100644 --- a/bacula/src/lib/protos.h +++ b/bacula/src/lib/protos.h @@ -105,7 +105,6 @@ const char *bnet_strerror (BSOCK *bsock); const char *bnet_sig_to_ascii (BSOCK *bsock); int bnet_wait_data (BSOCK *bsock, int sec); int bnet_wait_data_intr (BSOCK *bsock, int sec); -int bnet_despool_to_bsock (BSOCK *bsock, void update(ssize_t size), ssize_t size); bool is_bnet_stop (BSOCK *bsock); int is_bnet_error (BSOCK *bsock); void bnet_suppress_error_messages(BSOCK *bsock, bool flag); diff --git a/bacula/src/lib/watchdog.c b/bacula/src/lib/watchdog.c index 9420782eb0..e28be1161c 100644 --- a/bacula/src/lib/watchdog.c +++ b/bacula/src/lib/watchdog.c @@ -84,11 +84,11 @@ int start_watchdog(void) } wd_queue = New(dlist(dummy, &dummy->link)); wd_inactive = New(dlist(dummy, &dummy->link)); + wd_is_init = true; if ((stat = pthread_create(&wd_tid, NULL, watchdog_thread, NULL)) != 0) { return stat; } - wd_is_init = true; return 0; } diff --git a/bacula/src/stored/mac.c b/bacula/src/stored/mac.c index 900701eba4..27f3543872 100644 --- a/bacula/src/stored/mac.c +++ b/bacula/src/stored/mac.c @@ -164,7 +164,7 @@ ok_out: edit_uint64(jcr->JobBytes, ec1)); Dmsg4(200, Job_end, jcr->Job, jcr->JobStatus, jcr->JobFiles, ec1); - bnet_sig(dir, BNET_EOD); /* send EOD to Director daemon */ + dir->signal(BNET_EOD); /* send EOD to Director daemon */ return ok; } diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index 4cc076e312..abcdb0a7b9 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -1,14 +1,7 @@ -/* - * Spooling code - * - * Kern Sibbald, March 2004 - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2004-2006 Free Software Foundation Europe e.V. + Copyright (C) 2004-2007 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. @@ -32,6 +25,13 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * Spooling code + * + * Kern Sibbald, March 2004 + * + * Version $Id$ + */ #include "bacula.h" #include "stored.h" @@ -77,18 +77,17 @@ enum { void list_spool_stats(void sendit(const char *msg, int len, void *sarg), void *arg) { - char *msg, ed1[30], ed2[30]; + char ed1[30], ed2[30]; + POOL_MEM msg(PM_MESSAGE); int len; - msg = (char *)get_pool_memory(PM_MESSAGE); - if (spool_stats.data_jobs || spool_stats.max_data_size) { len = Mmsg(msg, _("Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n"), spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1), spool_stats.total_data_jobs, edit_uint64_with_commas(spool_stats.max_data_size, ed2)); - sendit(msg, len, arg); + sendit(msg.c_str(), len, arg); } if (spool_stats.attr_jobs || spool_stats.max_attr_size) { len = Mmsg(msg, _("Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n"), @@ -96,10 +95,8 @@ void list_spool_stats(void sendit(const char *msg, int len, void *sarg), void *a spool_stats.total_attr_jobs, edit_uint64_with_commas(spool_stats.max_attr_size, ed2)); - sendit(msg, len, arg); + sendit(msg.c_str(), len, arg); } - - free_pool_memory(msg); } bool begin_data_spool(DCR *dcr) @@ -615,7 +612,7 @@ bool commit_attribute_spool(JCR *jcr) V(mutex); Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"), edit_uint64_with_commas(size, ec1)); - bnet_despool_to_bsock(jcr->dir_bsock, update_attr_spool_size, size); + jcr->dir_bsock->despool(update_attr_spool_size, size); return close_attr_spool_file(jcr, jcr->dir_bsock); } return true; diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index 2689c81484..309b1b05ed 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -2,6 +2,7 @@ General: 01Apr07 +kes Move bnet_despool() into class in bsock.c kes Modify job report to include director name and Build OS. kes Move drop and check_catalog() before fork. kes Add update database scripts (version 9 to 10) to updatedb directory.