From: Kern Sibbald Date: Mon, 23 Apr 2007 16:31:14 +0000 (+0000) Subject: kes Implement posix_fadvise in FD, and for reading spool files in SD. X-Git-Tag: Release-7.0.0~6520 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f6adfc7d37008f32973642840bdcdee3405e13e8;p=bacula%2Fbacula kes Implement posix_fadvise in FD, and for reading spool files in SD. kes Add thread timer to bnet_connect() to break from OS if wait time expires. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@4608 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/autoconf/config.h.in b/bacula/autoconf/config.h.in index e8cbef04e7..9ca7d391dd 100644 --- a/bacula/autoconf/config.h.in +++ b/bacula/autoconf/config.h.in @@ -500,6 +500,9 @@ /* Define if OpenSSL library is available */ #undef HAVE_OPENSSL +/* Define to 1 if you have the `posix_fadvise' function. */ +#undef HAVE_POSIX_FADVISE + /* Define if your printf() function supports format strings with positions. */ #undef HAVE_POSIX_PRINTF @@ -814,9 +817,9 @@ /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be automatically deduced at runtime. - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ #undef STACK_DIRECTION /* Define to 1 if the `S_IS*' macros in do not work properly. */ diff --git a/bacula/autoconf/configure.in b/bacula/autoconf/configure.in index 9c68e8b77d..e1f6607585 100644 --- a/bacula/autoconf/configure.in +++ b/bacula/autoconf/configure.in @@ -1618,6 +1618,7 @@ AC_CHECK_FUNCS( \ AC_CHECK_FUNCS(fchdir, [AC_DEFINE(HAVE_FCHDIR)]) AC_CHECK_FUNCS(strtoll, [AC_DEFINE(HAVE_STRTOLL)]) +AC_CHECK_FUNCS(posix_fadvise) AC_CHECK_FUNCS(chflags) diff --git a/bacula/configure b/bacula/configure index 2f05d3fdfe..2f29990584 100755 --- a/bacula/configure +++ b/bacula/configure @@ -30118,6 +30118,116 @@ fi done +for ac_func in posix_fadvise +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; } +if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$ac_func || defined __stub___$ac_func +choke me +#endif + +int +main () +{ +return $ac_func (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_var=no" +fi + +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_var'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + for ac_func in chflags do diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index 58cf3848b5..4fd1e59fb3 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -658,12 +658,17 @@ BSOCK *bnet_connect(JCR * jcr, int retry_interval, utime_t max_retry_time, int fatal = 0; time_t begin_time = time(NULL); time_t now; + btimer_t *tid = NULL; + /* Try to trap out of OS call when time expires */ + tid = start_thread_timer(pthread_self(), (uint32_t)max_retry_time); + for (i = 0; (bsock = bnet_open(jcr, name, host, service, port, heart_beat, &fatal)) == NULL; i -= retry_interval) { berrno be; if (fatal || (jcr && job_canceled(jcr))) { - return NULL; + bsock = NULL; + goto bail_out; } Dmsg4(100, "Unable to connect to %s on %s:%d. ERR=%s\n", name, host, port, be.strerror()); @@ -679,9 +684,15 @@ BSOCK *bnet_connect(JCR * jcr, int retry_interval, utime_t max_retry_time, if (begin_time + max_retry_time <= now) { Qmsg4(jcr, M_FATAL, 0, _("Unable to connect to %s on %s:%d. ERR=%s\n"), name, host, port, be.strerror()); - return NULL; + bsock = NULL; + goto bail_out; } } + +bail_out; + if (tid) { + stop_thread_timer(tid); + } return bsock; } @@ -729,10 +740,10 @@ bool bnet_fsend(BSOCK * bs, const char *fmt, ...) bs->msg = realloc_pool_memory(bs->msg, maxlen + maxlen / 2); } return bs->send(); -// return bnet_send(bs); } -int bnet_get_peer(BSOCK *bs, char *buf, socklen_t buflen) { +int bnet_get_peer(BSOCK *bs, char *buf, socklen_t buflen) +{ #if !defined(HAVE_WIN32) if (bs->peer_addr.sin_family == 0) { socklen_t salen = sizeof(bs->peer_addr); diff --git a/bacula/src/lib/bsock.c b/bacula/src/lib/bsock.c index 25e00a042e..4677cea2ec 100644 --- a/bacula/src/lib/bsock.c +++ b/bacula/src/lib/bsock.c @@ -286,6 +286,11 @@ bool BSOCK::despool(void update_attr_spool_size(ssize_t size), ssize_t tsize) int count = 0; rewind(spool_fd); + +#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED) + posix_fadvise(fileno(spool_fd), 0, 0, POSIX_FADV_WILLNEED); +#endif + while (fread((char *)&pktsiz, 1, sizeof(int32_t), spool_fd) == sizeof(int32_t)) { size += sizeof(int32_t); diff --git a/bacula/src/qt-console/restore/restore.cpp b/bacula/src/qt-console/restore/restore.cpp index 039db0c768..7fcf4d089b 100644 --- a/bacula/src/qt-console/restore/restore.cpp +++ b/bacula/src/qt-console/restore/restore.cpp @@ -130,6 +130,9 @@ void restoreDialog::fillDirectory() } fileWidget->clear(); fileWidget->insertTopLevelItems(0, items); + for (int i=0; i<7; i++) { + fileWidget->resizeColumnToContents(i); + } free_pool_memory(file); free_pool_memory(path); diff --git a/bacula/src/stored/bacula-sd.conf.in b/bacula/src/stored/bacula-sd.conf.in index 3ca34340be..247eb01e41 100644 --- a/bacula/src/stored/bacula-sd.conf.in +++ b/bacula/src/stored/bacula-sd.conf.in @@ -74,7 +74,13 @@ Device { # RemovableMedia = yes; # RandomAccess = no; # AutoChanger = yes +# # # # Enable the Alert command only if you have the mtx package loaded +# # Note, apparently on some systems, tapeinfo resets the SCSI controller +# # thus if you turn this on, make sure it does not reset your SCSI +# # controller. I have never had any problems, and smartctl does +# # not seem to cause such problems. +# # # Alert Command = "sh -c 'tapeinfo -f %c |grep TapeAlert|cat'" # If you have smartctl, enable this, it has more info than tapeinfo # Alert Command = "sh -c 'smartctl -H -l error %c'" diff --git a/bacula/src/stored/spool.c b/bacula/src/stored/spool.c index bf57c08ad6..9aa5a66ad4 100644 --- a/bacula/src/stored/spool.c +++ b/bacula/src/stored/spool.c @@ -262,6 +262,10 @@ static bool despool_data(DCR *dcr, bool commit) Dmsg1(800, "read/write block size = %d\n", block->buf_len); lseek(rdcr->spool_fd, 0, SEEK_SET); /* rewind */ +#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED) + posix_fadvise(rdcr->spool_fd, 0, 0, POSIX_FADV_WILLNEED); +#endif + /* Add run time, to get current wait time */ time_t despool_start = time(NULL) - jcr->run_time; diff --git a/bacula/technotes-2.1 b/bacula/technotes-2.1 index f4555944f9..3bf0d0539c 100644 --- a/bacula/technotes-2.1 +++ b/bacula/technotes-2.1 @@ -1,6 +1,10 @@ Technical notes on version 2.1 General: +23Apr07 +kes Implement posix_fadvise in FD, and for reading spool files in SD. +kes Add thread timer to bnet_connect() to break from OS if wait time + expires. 22Apr07 kes Update Win32 build to include new files, new symbols, and renamed files.