From: Tatuya JINMEI 神明達哉 Date: Wed, 20 Aug 2008 23:57:59 +0000 (+0000) Subject: 2420. [func] Add new command line option '-S' for named to specify X-Git-Tag: v9.3.6b1~36^2~20 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=13d9b8ce94aee267761cd297a583e280df262d60;p=thirdparty%2Fbind9.git 2420. [func] Add new command line option '-S' for named to specify the max number of sockets. [RT #18493] Use caution: this option may not work for some operating systems without rebuilding named. --- diff --git a/CHANGES b/CHANGES index d7691a70c7c..d40ee3c206d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +2420. [func] Add new command line option '-S' for named to specify + the max number of sockets. [RT #18493] + Use caution: this option may not work for some + operating systems without rebuilding named. + 2419. [cleanup] Document that isc_socket_create() and isc_socket_open() should not be used for isc_sockettype_fdwatch sockets. [RT #18521] @@ -41,10 +46,6 @@ 2406. [bug] Sockets could be closed too early, leading to inconsistent states in the socket module. [RT #18298] -xxxx. [bug] Connecting UDP sockets for outgoing queries could - unexpectedly fail with an 'address already in use' - error. - 2405. [cleanup] The default value for dnssec-validation was changed to "yes" in 9.5.0-P1 and all subsequent releases; this was inadvertently omitted from CHANGES at the time. diff --git a/bin/named/main.c b/bin/named/main.c index 50a44343e77..005485f6190 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: main.c,v 1.162 2008/04/03 23:14:52 jinmei Exp $ */ +/* $Id: main.c,v 1.163 2008/08/20 23:57:59 jinmei Exp $ */ /*! \file */ @@ -85,6 +85,7 @@ static char program_name[ISC_DIR_NAMEMAX] = "named"; static char absolute_conffile[ISC_DIR_PATHMAX]; static char saved_command_line[512]; static char version[512]; +static unsigned int maxsocks = 0; void ns_main_earlywarning(const char *format, ...) { @@ -356,7 +357,8 @@ parse_command_line(int argc, char *argv[]) { isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, - "46c:C:d:fgi:lm:n:N:p:P:st:T:u:vx:")) != -1) { + "46c:C:d:fgi:lm:n:N:p:P:" + "sS:t:T:u:vx:")) != -1) { switch (ch) { case '4': if (disable4) @@ -435,6 +437,10 @@ parse_command_line(int argc, char *argv[]) { /* XXXRTH temporary syntax */ want_stats = ISC_TRUE; break; + case 'S': + maxsocks = parse_int(isc_commandline_argument, + "max number of sockets"); + break; case 't': /* XXXJAB should we make a copy? */ ns_g_chrootdir = isc_commandline_argument; @@ -479,6 +485,7 @@ parse_command_line(int argc, char *argv[]) { static isc_result_t create_managers(void) { isc_result_t result; + unsigned int socks; #ifdef ISC_PLATFORM_USETHREADS unsigned int cpus_detected; #endif @@ -510,13 +517,19 @@ create_managers(void) { return (ISC_R_UNEXPECTED); } - result = isc_socketmgr_create(ns_g_mctx, &ns_g_socketmgr); + result = isc_socketmgr_create2(ns_g_mctx, &ns_g_socketmgr, maxsocks); if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_socketmgr_create() failed: %s", isc_result_totext(result)); return (ISC_R_UNEXPECTED); } + result = isc_socketmgr_getmaxsockets(ns_g_socketmgr, &socks); + if (result == ISC_R_SUCCESS) { + isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, + NS_LOGMODULE_SERVER, + ISC_LOG_INFO, "using up to %u sockets", socks); + } result = isc_entropy_create(ns_g_mctx, &ns_g_entropy); if (result != ISC_R_SUCCESS) { diff --git a/bin/named/named.docbook b/bin/named/named.docbook index a60d1496681..92737046019 100644 --- a/bin/named/named.docbook +++ b/bin/named/named.docbook @@ -18,7 +18,7 @@ - PERFORMANCE OF THIS SOFTWARE. --> - + June 30, 2000 @@ -64,6 +64,7 @@ + @@ -214,6 +215,33 @@ + + -S #max-socks + + + Allow named to use up to + #max-socks sockets. + + + + This option should be unnecessary for the vast majority + of users. + The use of this option could even be harmful because the + specified value may exceed the limitation of the + underlying system API. + It is therefore set only when the default configuration + causes exhaustion of file descriptors and the + operational environment is known to support the + specified number of sockets. + Note also that the actual maximum number is normally a little + fewer than the specified value because + named reserves some file descriptors + for its internal use. + + + + + -t directory diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 94155f2651c..8c2271ebfc2 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.h,v 1.82 2008/08/20 06:16:05 marka Exp $ */ +/* $Id: socket.h,v 1.83 2008/08/20 23:57:59 jinmei Exp $ */ #ifndef ISC_SOCKET_H #define ISC_SOCKET_H 1 @@ -753,8 +753,15 @@ isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region, isc_result_t isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp); + +isc_result_t +isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, + unsigned int maxsocks); /*%< - * Create a socket manager. + * Create a socket manager. If "maxsocks" is non-zero, it specifies the + * maximum number of sockets that the created manager should handle. + * isc_socketmgr_create() is equivalent of isc_socketmgr_create2() with + * "maxsocks" being zero. * * Notes: * @@ -775,6 +782,7 @@ isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp); *\li #ISC_R_SUCCESS *\li #ISC_R_NOMEMORY *\li #ISC_R_UNEXPECTED + *\li #ISC_R_NOTIMPLEMENTED */ isc_result_t diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 4c4f59edd37..c90503671b4 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.300 2008/08/20 06:16:05 marka Exp $ */ +/* $Id: socket.c,v 1.301 2008/08/20 23:57:59 jinmei Exp $ */ /*! \file */ @@ -140,16 +140,14 @@ struct isc_socketwait { #ifdef USE_SELECT /*% - * Mac OS X needs a special definition to support larger values in select() + * Mac OS X needs a special definition to support larger values in select(). + * We always define this because a larger value can be specified run-time. */ -#if ISC_SOCKET_MAXSOCKETS > FD_SETSIZE #ifdef __APPLE__ #define _DARWIN_UNLIMITED_SELECT #endif /* __APPLE__ */ -#endif /* ISC_SOCKET_MAXSOCKETS > FD_SETSIZE */ #endif /* USE_SELECT */ - /*% * Size of per-FD lock buckets. */ @@ -3475,6 +3473,13 @@ cleanup_watcher(isc_mem_t *mctx, isc_socketmgr_t *manager) { isc_result_t isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) { + return (isc_socketmgr_create2(mctx, managerp, 0)); +} + +isc_result_t +isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, + unsigned int maxsocks) +{ int i; isc_socketmgr_t *manager; #ifdef ISC_PLATFORM_USETHREADS @@ -3486,19 +3491,26 @@ isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) { #ifndef ISC_PLATFORM_USETHREADS if (socketmgr != NULL) { + /* Don't allow maxsocks to be updated */ + if (maxsocks > 0 && socketmgr->maxsocks != maxsocks) + return (ISC_R_EXISTS); + socketmgr->refs++; *managerp = socketmgr; return (ISC_R_SUCCESS); } #endif /* ISC_PLATFORM_USETHREADS */ + if (maxsocks == 0) + maxsocks = ISC_SOCKET_MAXSOCKETS; + manager = isc_mem_get(mctx, sizeof(*manager)); if (manager == NULL) return (ISC_R_NOMEMORY); /* zero-clear so that necessary cleanup on failure will be easy */ memset(manager, 0, sizeof(*manager)); - manager->maxsocks = ISC_SOCKET_MAXSOCKETS; + manager->maxsocks = maxsocks; manager->fds = isc_mem_get(mctx, manager->maxsocks * sizeof(isc_socket_t *)); if (manager->fds == NULL) { diff --git a/lib/isc/win32/libisc.def b/lib/isc/win32/libisc.def index 94f1f2f336f..2c46a1ae72a 100644 --- a/lib/isc/win32/libisc.def +++ b/lib/isc/win32/libisc.def @@ -420,6 +420,7 @@ isc_socket_sendtov isc_socket_sendv isc_socket_setname isc_socketmgr_create +isc_socketmgr_create2 isc_socketmgr_destroy isc_socketmgr_getmaxsockets isc_stdio_close diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 17c901f957e..d623cec9066 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: socket.c,v 1.65 2008/08/20 06:16:05 marka Exp $ */ +/* $Id: socket.c,v 1.66 2008/08/20 23:57:59 jinmei Exp $ */ /* This code has been rewritten to take advantage of Windows Sockets * I/O Completion Ports and Events. I/O Completion Ports is ONLY @@ -2906,12 +2906,22 @@ event_wait(void *uap) { */ isc_result_t isc_socketmgr_create(isc_mem_t *mctx, isc_socketmgr_t **managerp) { + return (isc_socketmgr_create2(mctx, managerp, maxsocks)); +} + +isc_result_t +isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, + unsigned int maxsocks) +{ isc_socketmgr_t *manager; events_thread_t *evthread = NULL; isc_result_t result; REQUIRE(managerp != NULL && *managerp == NULL); + if (maxsocks != 0) + return (ISC_R_NOTIMPLEMENTED); + manager = isc_mem_get(mctx, sizeof(*manager)); if (manager == NULL) return (ISC_R_NOMEMORY);