2007-06-04 13:53:19 +04:00
/*
ctdb tunables code
Copyright ( C ) Andrew Tridgell 2007
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 09:29:31 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-06-04 13:53:19 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 09:29:31 +04:00
along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2007-06-04 13:53:19 +04:00
*/
2015-10-26 08:50:46 +03:00
# include "replace.h"
# include "system/network.h"
# include <talloc.h>
# include <tdb.h>
# include "lib/util/debug.h"
# include "ctdb_private.h"
2007-06-04 13:53:19 +04:00
2015-10-23 06:17:34 +03:00
# include "common/common.h"
2015-11-11 07:41:10 +03:00
# include "common/logging.h"
2016-07-07 10:04:32 +03:00
# include "common/tunable.h"
2007-06-04 13:53:19 +04:00
2007-06-04 14:22:44 +04:00
/*
set all tunables to defaults
*/
void ctdb_tunables_set_defaults ( struct ctdb_context * ctdb )
{
2016-07-07 10:04:32 +03:00
ctdb_tunable_set_defaults ( & ctdb - > tunable ) ;
2007-06-04 14:22:44 +04:00
}
2007-06-04 13:53:19 +04:00
/*
get a tunable
*/
2016-07-07 10:04:32 +03:00
int32_t ctdb_control_get_tunable ( struct ctdb_context * ctdb , TDB_DATA indata ,
2007-06-04 13:53:19 +04:00
TDB_DATA * outdata )
{
2016-07-07 10:04:32 +03:00
struct ctdb_control_get_tunable * t =
2007-06-04 13:53:19 +04:00
( struct ctdb_control_get_tunable * ) indata . dptr ;
char * name ;
uint32_t val ;
2016-07-07 10:04:32 +03:00
bool ret ;
2007-06-04 13:53:19 +04:00
if ( indata . dsize < sizeof ( * t ) | |
t - > length > indata . dsize - offsetof ( struct ctdb_control_get_tunable , name ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Bad indata in ctdb_control_get_tunable \n " ) ) ;
2007-06-04 13:53:19 +04:00
return - 1 ;
}
name = talloc_strndup ( ctdb , ( char * ) t - > name , t - > length ) ;
CTDB_NO_MEMORY ( ctdb , name ) ;
2016-07-07 10:04:32 +03:00
ret = ctdb_tunable_get_value ( & ctdb - > tunable , name , & val ) ;
2007-06-04 13:53:19 +04:00
talloc_free ( name ) ;
2016-07-07 10:04:32 +03:00
if ( ! ret ) {
2013-05-21 09:41:56 +04:00
return - EINVAL ;
2007-06-04 13:53:19 +04:00
}
outdata - > dptr = ( uint8_t * ) talloc ( outdata , uint32_t ) ;
CTDB_NO_MEMORY ( ctdb , outdata - > dptr ) ;
* ( uint32_t * ) outdata - > dptr = val ;
outdata - > dsize = sizeof ( uint32_t ) ;
return 0 ;
}
/*
set a tunable
*/
int32_t ctdb_control_set_tunable ( struct ctdb_context * ctdb , TDB_DATA indata )
{
2015-10-28 11:18:02 +03:00
struct ctdb_tunable_old * t =
( struct ctdb_tunable_old * ) indata . dptr ;
2007-06-04 13:53:19 +04:00
char * name ;
2016-07-07 10:04:32 +03:00
int ret ;
bool obsolete ;
2007-06-04 13:53:19 +04:00
if ( indata . dsize < sizeof ( * t ) | |
2015-10-28 11:18:02 +03:00
t - > length > indata . dsize - offsetof ( struct ctdb_tunable_old , name ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Bad indata in ctdb_control_set_tunable \n " ) ) ;
2007-06-04 13:53:19 +04:00
return - 1 ;
}
name = talloc_strndup ( ctdb , ( char * ) t - > name , t - > length ) ;
CTDB_NO_MEMORY ( ctdb , name ) ;
2016-07-07 10:04:32 +03:00
ret = ctdb_tunable_set_value ( & ctdb - > tunable , name , t - > value ,
& obsolete ) ;
if ( ! ret ) {
talloc_free ( name ) ;
2007-06-04 13:53:19 +04:00
return - 1 ;
}
2009-06-25 08:45:17 +04:00
2016-07-07 10:04:32 +03:00
if ( obsolete ) {
2014-12-09 05:49:06 +03:00
DEBUG ( DEBUG_WARNING ,
2016-07-07 10:04:32 +03:00
( " Setting obsolete tunable \" %s \" \n " , name ) ) ;
talloc_free ( name ) ;
2015-02-09 02:32:47 +03:00
return 1 ;
2014-12-09 05:49:06 +03:00
}
2016-07-07 10:04:32 +03:00
talloc_free ( name ) ;
2007-06-04 13:53:19 +04:00
return 0 ;
}
/*
list tunables
*/
int32_t ctdb_control_list_tunables ( struct ctdb_context * ctdb , TDB_DATA * outdata )
{
char * list = NULL ;
struct ctdb_control_list_tunable * t ;
2016-07-07 10:04:32 +03:00
list = ctdb_tunable_names_to_string ( outdata ) ;
2016-03-15 22:55:37 +03:00
CTDB_NO_MEMORY ( ctdb , list ) ;
2016-03-08 07:12:42 +03:00
outdata - > dsize = offsetof ( struct ctdb_control_list_tunable , data ) +
2007-06-04 13:53:19 +04:00
strlen ( list ) + 1 ;
outdata - > dptr = talloc_size ( outdata , outdata - > dsize ) ;
CTDB_NO_MEMORY ( ctdb , outdata - > dptr ) ;
t = ( struct ctdb_control_list_tunable * ) outdata - > dptr ;
t - > length = strlen ( list ) + 1 ;
memcpy ( t - > data , list , t - > length ) ;
talloc_free ( list ) ;
2016-03-08 07:12:42 +03:00
return 0 ;
2007-06-04 13:53:19 +04:00
}