File: api0cfg.c

package info (click to toggle)
libinnodb 1.0.6.6750-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 8,072 kB
  • ctags: 7,325
  • sloc: ansic: 107,290; sh: 9,930; lex: 664; yacc: 530; makefile: 335; perl: 46
file content (1350 lines) | stat: -rw-r--r-- 39,199 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
/***********************************************************************
Copyright (c) 2008 Innobase Oy. All rights reserved.
Copyright (c) 2008 Oracle. All rights reserved.

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
the Free Software Foundation; version 2 of the License.

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
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

************************************************************************/
#include <stdarg.h>

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

#include "univ.i"
#include "api0api.h"
#include "btr0sea.h"
#include "buf0buf.h" /* for buf_pool */
#include "buf0lru.h" /* for buf_LRU_* */
#include "db0err.h"
#include "log0recv.h"
#include "srv0srv.h"
#include "srv0start.h"
#include "trx0sys.h"	/* for trx_sys_file_format_name_to_id() */
#include "os0sync.h"

UNIV_STATIC	char*	srv_file_flush_method_str = NULL;

/* If set then we rollback the transaction on DB_LOCK_WAIT_TIMEOUT error. */
extern ibool	ses_rollback_on_timeout;

/* A point in the LRU list (expressed as a percent), all blocks from this
point onwards (inclusive) are considered "old" blocks. */
UNIV_STATIC ulint	lru_old_blocks_pct;

/** We copy the argument passed to ib_cfg_set_text("data_file_path")
because srv_parse_data_file_paths_and_sizes() parses it's input argument
destructively. The copy is done using ut_malloc(). */
UNIV_STATIC	char*	srv_data_file_paths_and_sizes = NULL;

/* enum ib_cfg_flag_t @{ */
typedef enum ib_cfg_flag {
	IB_CFG_FLAG_NONE = 0x1,
	IB_CFG_FLAG_READONLY_AFTER_STARTUP = 0x2,/* can be modified only
						 before innodb is started */
	IB_CFG_FLAG_READONLY = 0x4		/* cannot be modified */
} ib_cfg_flag_t;
/* @} */

/* struct ib_cfg_var_t @{ */
typedef struct ib_cfg_var {
	const char*	name;	/* config var name */
	ib_cfg_type_t	type;	/* config var type */
	ib_cfg_flag_t	flag;	/* config var flag */
	ib_uint64_t	min_val;/* minimum allowed value for numeric types,
				ignored for other types */
	ib_uint64_t	max_val;/* maximum allowed value for numeric types,
				ignored for other types */
	ib_err_t	(*validate)(const struct ib_cfg_var*, const void*); /*
				function used to validate a new variable's
				value when setting it */
	ib_err_t	(*set)(struct ib_cfg_var*, const void*); /* function
				used to set the variable's value */
	ib_err_t	(*get)(const struct ib_cfg_var*, void*); /* function
				used to get the variable's value */
	void*		tank;	/* opaque storage that may be used by the
				set() and get() functions */
} ib_cfg_var_t;
/* @} */

/*******************************************************************//**
@file api/api0cfg.c
Assign src to dst according to type. If this is a string variable (char*)
the string itself is not copied.
ib_cfg_assign() @{
@return	DB_SUCCESS if assigned (type is known) */
UNIV_STATIC
ib_err_t
ib_cfg_assign(
/*==========*/
	ib_cfg_type_t	type,	/*!< in: type of src and dst */
	void*		dst,	/*!< out: destination */
	const void*	src)	/*!< in: source */
{
	switch (type) {
	case IB_CFG_IBOOL: {

		*(ib_bool_t*) dst = *(const ib_bool_t*) src;
		return(DB_SUCCESS);
	}

	case IB_CFG_ULINT: {

		*(ulint*) dst = *(const ulint*) src;
		return(DB_SUCCESS);
	}

	case IB_CFG_ULONG: {

		*(ulong*) dst = *(const ulong*) src;
		return(DB_SUCCESS);
	}

	case IB_CFG_TEXT: {

		*(char**) dst = *(char**) src;
		return(DB_SUCCESS);
	}

	case IB_CFG_CB: {

		*(ib_cb_t*) dst = *(ib_cb_t*) src;
		return(DB_SUCCESS);
	}
	/* do not add default: in order to produce a compilation
	warning if new type is added which is not handled here */
	}

	/* NOT REACHED */
	return(DB_ERROR);
}
/* @} */

/*******************************************************************//**
A generic function used for ib_cfg_var_t::validate() to check a numeric
type for min/max allowed value overflow.
ib_cfg_var_validate_numeric() @{
@return	DB_SUCCESS if value is in range */
UNIV_STATIC
ib_err_t
ib_cfg_var_validate_numeric(
/*========================*/
	const struct ib_cfg_var* cfg_var,/*!< in/out: configuration variable to
					check */
	const void*		value)	/*!< in: value to check */
{
	switch (cfg_var->type) {

	case IB_CFG_ULINT: {
		ulint	v;

		v = *(ulint*) value;

		if ((ulint) cfg_var->min_val <= v
		    && v <= (ulint) cfg_var->max_val) {

			return(DB_SUCCESS);
		} else {

			return(DB_INVALID_INPUT);
		}
	}

	case IB_CFG_ULONG: {
		ulong	v;

		v = *(ulong*) value;

		if ((ulong) cfg_var->min_val <= v
		    && v <= (ulong) cfg_var->max_val) {

			return(DB_SUCCESS);
		} else {

			return(DB_INVALID_INPUT);
		}
	}

	default:
		ut_error;
	}

	/* NOT REACHED */
	return(DB_ERROR);
}
/* @} */

/* generic and specific ib_cfg_var_(set|get)_* functions @{ */

/*******************************************************************//**
A generic function used for ib_cfg_var_t::set() that stores the value
of the configuration parameter in the location pointed by
ib_cfg_var_t::tank. If this is a string variable (char*) then the string
is not copied and a reference to "value" is made. It should not be freed
or modified until InnoDB is running or a new value is set.
ib_cfg_var_set_generic() @{
@return	DB_SUCCESS if set successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_set_generic(
/*===================*/
	struct ib_cfg_var*	cfg_var,/*!< in/out: configuration variable to
					manipulate */
	const void*		value)	/*!< in: value to set */
{
	ib_err_t	ret;

	if (cfg_var->validate != NULL) {
		ret = cfg_var->validate(cfg_var, value);
		if (ret != DB_SUCCESS) {
			return(ret);
		}
	}

	ret = ib_cfg_assign(cfg_var->type, cfg_var->tank, value);

	return(ret);
}
/* @} */

/*******************************************************************//**
A generic function used for ib_cfg_var_t::get() that retrieves the value
of the configuration parameter from the location pointed by
ib_cfg_var_t::tank and stores it in "value". The variable is not copied
to "value" even if it is a string variable (char*). Only a pointer to the
storage is written in "value". It should not be freed unless it was
allocated by the user and set with ib_cfg_set().
ib_cfg_var_get_generic() @{
@return	DB_SUCCESS if retrieved successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_get_generic(
/*===================*/
	const struct ib_cfg_var*	cfg_var,/*!< in: configuration
						variable whose value to
						retrieve */
	void*				value)	/*!< out: place to store
						the retrieved value */
{
	return(ib_cfg_assign(cfg_var->type, value, cfg_var->tank));
}
/* @} */

/*******************************************************************//**
Set the value of the config variable "adaptive_hash_index".
ib_cfg_var_set_adaptive_hash_index() @{
@return	DB_SUCCESS if set successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_set_adaptive_hash_index(
/*===============================*/
	struct ib_cfg_var*	cfg_var,/*!< in/out: configuration variable to
					manipulate, must be
					"adaptive_hash_index" */
	const void*		value)	/*!< in: value to set, must point to
					ib_bool_t variable */
{
	ut_a(strcasecmp(cfg_var->name, "adaptive_hash_index") == 0);
	ut_a(cfg_var->type == IB_CFG_IBOOL);

	btr_search_enabled = !(*(const ib_bool_t*) value);

	return(DB_SUCCESS);
}
/* @} */

/*******************************************************************//**
Retrieve the value of the config variable "adaptive_hash_index".
ib_cfg_var_get_adaptive_hash_index() @{
@return	DB_SUCCESS if retrieved successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_get_adaptive_hash_index(
/*===============================*/
	const struct ib_cfg_var*	cfg_var,/*!< in: configuration
						variable whose value to
						retrieve, must be
						"adaptive_hash_index" */
	void*				value)	/*!< out: place to store
						the retrieved value, must
						point to ib_bool_t variable */
{
	ut_a(strcasecmp(cfg_var->name, "adaptive_hash_index") == 0);
	ut_a(cfg_var->type == IB_CFG_IBOOL);

	*(ib_bool_t*) value = !btr_search_enabled;

	return(DB_SUCCESS);
}
/* @} */

/*******************************************************************//**
Set the value of the config variable "data_file_path".
ib_cfg_var_set_data_file_path() @{
@return	DB_SUCCESS if set successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_set_data_file_path(
/*==========================*/
	struct ib_cfg_var*	cfg_var,/*!< in/out: configuration variable to
					manipulate, must be
					"data_file_path" */
	const void*		value)	/*!< in: value to set, must point to
					char* variable */
{
	const char*	value_str;

	ut_a(strcasecmp(cfg_var->name, "data_file_path") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	value_str = *(char**) value;

	if (srv_parse_data_file_paths_and_sizes(value_str)) {
		return(DB_SUCCESS);
	} else {
		return(DB_INVALID_INPUT);
	}
}
/* @} */

/*******************************************************************//**
Retrieve the value of the config variable "data_file_path".
ib_cfg_var_get_data_file_path() @{
@return	DB_SUCCESS if retrieved successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_get_data_file_path(
/*==========================*/
	const struct ib_cfg_var*	cfg_var,/*!< in: configuration
						variable whose value to
						retrieve, must be
						"data_file_path" */
	void*				value)	/*!< out: place to store
						the retrieved value, must
						point to char* variable */
{
	ut_a(strcasecmp(cfg_var->name, "data_file_path") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	*(char**) value = srv_data_file_paths_and_sizes;

	return(DB_SUCCESS);
}
/* @} */

/*******************************************************************//**
Set the value of the config variable "file_format".
ib_cfg_var_set_file_format() @{
@return	DB_SUCCESS if set successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_set_file_format(
/*=======================*/
	struct ib_cfg_var*	cfg_var,/*!< in/out: configuration variable to
					manipulate, must be "file_format" */
	const void*		value)	/*!< in: value to set, must point to
					char* variable */
{
	ulint		format_id;

	ut_a(strcasecmp(cfg_var->name, "file_format") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	format_id = trx_sys_file_format_name_to_id(*(char**) value);

	if (format_id > DICT_TF_FORMAT_MAX) {
		return(DB_INVALID_INPUT);
	}

	srv_file_format = format_id;

	return(DB_SUCCESS);
}
/* @} */

/*******************************************************************//**
Retrieve the value of the config variable "file_format".
ib_cfg_var_get_file_format @{
@return	DB_SUCCESS if retrieved successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_get_file_format(
/*=======================*/
	const struct ib_cfg_var*	cfg_var,/*!< in: configuration
						variable whose value to
						retrieve, must be
						"file_format" */
	void*				value)	/*!< out: place to store
						the retrieved value, must
						point to char* variable */
{
	ut_a(strcasecmp(cfg_var->name, "file_format") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	*(const char**) value = trx_sys_file_format_id_to_name(
		srv_file_format);

	return(DB_SUCCESS);
}
/* @} */

/*******************************************************************//**
Check the value of the config variable "data_home_dir". We need to ensure
that the value ends with a path separator.
ib_cfg_var_validate_data_home_dir() @{
@return	DB_SUCCESS if value is valid */
UNIV_STATIC
ib_err_t
ib_cfg_var_validate_data_home_dir(
/*==============================*/
	const struct ib_cfg_var*cfg_var,/*!< in/out: configuration variable to
					check, must be "data_home_dir" */
	const void*		value)	/*!< in: value to check, must point to
					char* variable */
{
	ulint		len;
	char*		value_str;

	ut_a(strcasecmp(cfg_var->name, "data_home_dir") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	value_str = *(char**) value;

	len = ut_strlen(value_str);

	/* We simply require that this variable end in a path separator.
	We will normalize it before use internally. */
	if (len == 0
	    || (value_str[len - 1] != '/' && value_str[len - 1] != '\\')) {

		return(DB_INVALID_INPUT);
	}

	return(DB_SUCCESS);
}
/* @} */

/*******************************************************************//**
Set the value of the config variable "log_group_home_dir".
ib_cfg_var_set_log_group_home_dir @{
@return	DB_SUCCESS if set successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_set_log_group_home_dir(
/*==============================*/
	struct ib_cfg_var*	cfg_var,/*!< in/out: configuration variable to
					manipulate, must be
					"log_group_home_dir" */
	const void*		value)	/*!< in: value to set, must point to
					char* variable */
{
	const char*	value_str;

	ut_a(strcasecmp(cfg_var->name, "log_group_home_dir") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	ut_a(srv_log_group_home_dir == NULL);

	value_str = *(char**) value;

	if (srv_parse_log_group_home_dirs(value_str)) {
		return(DB_SUCCESS);
	} else {
		return(DB_INVALID_INPUT);
	}
}
/* @} */

/*******************************************************************//**
Set the value of the config variable "flush_method".
ib_cfg_var_set_flush_method@{
@return	DB_SUCCESS if set successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_set_flush_method(
/*========================*/
	struct ib_cfg_var*	cfg_var,/*!< in/out: configuration variable to
					manipulate, must be
					"log_group_home_dir" */
	const void*		value)	/*!< in: value to set, must point to
					char* variable */
{
	const char*	value_str;
	ib_err_t	err = DB_SUCCESS;

	ut_a(strcasecmp(cfg_var->name, "flush_method") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	value_str = *(const char**) value;

	os_aio_use_native_aio = FALSE;

#ifndef __WIN__
	if (0 == ut_strcmp(value_str, "fsync")) {
		srv_unix_file_flush_method = SRV_UNIX_FSYNC;
	} else if (0 == ut_strcmp(value_str, "O_DSYNC")) {
		srv_unix_file_flush_method = SRV_UNIX_O_DSYNC;
	} else if (0 == ut_strcmp(value_str, "O_DIRECT")) {
		srv_unix_file_flush_method = SRV_UNIX_O_DIRECT;
	} else if (0 == ut_strcmp(value_str, "littlesync")) {
		srv_unix_file_flush_method = SRV_UNIX_LITTLESYNC;
	} else if (0 == ut_strcmp(value_str, "nosync")) {
		srv_unix_file_flush_method = SRV_UNIX_NOSYNC;
	} else {
		err = DB_INVALID_INPUT;
	}
#else
	if (0 == ut_strcmp(value_str, "normal")) {
		srv_win_file_flush_method = SRV_WIN_IO_NORMAL;
	} else if (0 == ut_strcmp(value_str, "unbuffered")) {
		srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
	} else if (0 == ut_strcmp(value_str, "async_unbuffered")) {
		srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;
	} else {
		err = DB_INVALID_INPUT;
	}

	if (err == DB_SUCCESS) {
		switch (os_get_os_version()) {
		case OS_WIN95:
		case OS_WIN31:
		case OS_WINNT:
			/* On Win 95, 98, ME, Win32 subsystem for Windows
			3.1, and NT use simulated aio. In NT Windows provides
		       	async i/o, but when run in conjunction with InnoDB
		       	Hot Backup, it seemed to corrupt the data files. */
	
			os_aio_use_native_aio = FALSE;
			break;
		default:
			/* On Win 2000 and XP use async i/o */
			os_aio_use_native_aio = TRUE;
			break;
		}
	}
#endif

	if (err == DB_SUCCESS) {
		*(const char**) cfg_var->tank = value_str;
	} else {
		*(const char**) cfg_var->tank = NULL;
	}

	return(err);
}
/* @} */
/*******************************************************************//**
Retrieve the value of the config variable "log_group_home_dir".
ib_cfg_var_get_log_group_home_dir() @{
@return	DB_SUCCESS if retrieved successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_get_log_group_home_dir(
/*==============================*/
	const struct ib_cfg_var*	cfg_var,/*!< in: configuration
						variable whose value to
						retrieve, must be
						"log_group_home_dir" */
	void*				value)	/*!< out: place to store
						the retrieved value, must
						point to char* variable */
{
	ut_a(strcasecmp(cfg_var->name, "log_group_home_dir") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	*(const char**) value = NULL;

	return(DB_SUCCESS);
}
/* @} */

/*******************************************************************//**
Set the value of the config variable "lru_old_blocks_pct".
ib_cfg_var_set_lru_old_blocks_pct() @{
@return	DB_SUCCESS if set successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_set_lru_old_blocks_pct(
/*==============================*/
	struct ib_cfg_var*	cfg_var,/*!< in/out: configuration variable to
					manipulate, must be
					"lru_old_blocks_pct" */
	const void*		value)	/*!< in: value to set, must point to
					ulint variable */
{
	ibool	adjust_buf_pool;

	ut_a(strcasecmp(cfg_var->name, "lru_old_blocks_pct") == 0);
	ut_a(cfg_var->type == IB_CFG_ULINT);

	if (cfg_var->validate != NULL) {
		ib_err_t	ret;

		ret = cfg_var->validate(cfg_var, value);

		if (ret != DB_SUCCESS) {
			return(ret);
		}
	}

	if (buf_pool != NULL) {
		/* buffer pool has been created */
		adjust_buf_pool = TRUE;
	} else {
		/* buffer pool not yet created, do not attempt to modify it */
		adjust_buf_pool = FALSE;
	}

	lru_old_blocks_pct = buf_LRU_old_ratio_update(
		*(ulint*) value, adjust_buf_pool);

	return(DB_SUCCESS);
}
/* @} */

/* ib_cfg_var_get_generic() is used to get the value of lru_old_blocks_pct */

/* There is no ib_cfg_var_set_version() */

/*******************************************************************//**
Retrieve the value of the config variable "version".
ib_cfg_var_get_version() @{
@return	DB_SUCCESS if retrieved successfully */
UNIV_STATIC
ib_err_t
ib_cfg_var_get_version(
/*===================*/
	const struct ib_cfg_var*	cfg_var,/*!< in: configuration
						variable whose value to
						retrieve, must be
						"version" */
	void*				value)	/*!< out: place to store
						the retrieved value, must
						point to char* variable */
{
	ut_a(strcasecmp(cfg_var->name, "version") == 0);
	ut_a(cfg_var->type == IB_CFG_TEXT);

	*(const char**) value = INNODB_VERSION_STR;

	return(DB_SUCCESS);
}
/* @} */

/* @} */

/* cfg_vars_defaults[] @{ */
UNIV_STATIC const ib_cfg_var_t cfg_vars_defaults[] = {
	{STRUCT_FLD(name,	"adaptive_hash_index"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_adaptive_hash_index),
	 STRUCT_FLD(get,	ib_cfg_var_get_adaptive_hash_index),
	 STRUCT_FLD(tank,	NULL)},

	{STRUCT_FLD(name,	"adaptive_flushing"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_adaptive_flushing)},

	{STRUCT_FLD(name,	"additional_mem_pool_size"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	512 * 1024),
	 STRUCT_FLD(max_val,	IB_UINT64_T_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_mem_pool_size)},

	{STRUCT_FLD(name,	"autoextend_increment"),
	 STRUCT_FLD(type,	IB_CFG_ULONG),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	1),
	 STRUCT_FLD(max_val,	1000),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_auto_extend_increment)},

	{STRUCT_FLD(name,	"buffer_pool_size"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	5 * 1024 * 1024),
	 STRUCT_FLD(max_val,	ULINT_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_buf_pool_size)},

	{STRUCT_FLD(name,	"checksums"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_use_checksums)},

	{STRUCT_FLD(name,	"data_file_path"),
	 STRUCT_FLD(type,	IB_CFG_TEXT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_data_file_path),
	 STRUCT_FLD(get,	ib_cfg_var_get_data_file_path),
	 STRUCT_FLD(tank,	NULL)},

	{STRUCT_FLD(name,	"data_home_dir"),
	 STRUCT_FLD(type,	IB_CFG_TEXT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_data_home_dir),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_data_home)},

	{STRUCT_FLD(name,	"doublewrite"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_use_doublewrite_buf)},

	{STRUCT_FLD(name,	"file_format"),
	 STRUCT_FLD(type,	IB_CFG_TEXT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL /* validation is done inside
				     ib_cfg_var_set_file_format */),
	 STRUCT_FLD(set,	ib_cfg_var_set_file_format),
	 STRUCT_FLD(get,	ib_cfg_var_get_file_format),
	 STRUCT_FLD(tank,	NULL)},

	{STRUCT_FLD(name,	"file_io_threads"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	4),
	 STRUCT_FLD(max_val,	64),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_n_file_io_threads)},

	{STRUCT_FLD(name,	"file_per_table"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_file_per_table)},

	{STRUCT_FLD(name,	"flush_log_at_trx_commit"),
	 STRUCT_FLD(type,	IB_CFG_ULONG),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	2),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_flush_log_at_trx_commit)},

	{STRUCT_FLD(name,	"flush_method"),
	 STRUCT_FLD(type,	IB_CFG_TEXT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_flush_method),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_file_flush_method_str)},

	{STRUCT_FLD(name,	"force_recovery"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	IB_RECOVERY_DEFAULT),
	 STRUCT_FLD(max_val,	IB_RECOVERY_NO_LOG_REDO),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_force_recovery)},

	{STRUCT_FLD(name,	"io_capacity"),
	 STRUCT_FLD(type,	IB_CFG_ULONG),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	100),
	 STRUCT_FLD(max_val,	1000000),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_io_capacity)},

	{STRUCT_FLD(name,	"lock_wait_timeout"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	1),
	 STRUCT_FLD(max_val,	1024 * 1024 * 1024),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&ses_lock_wait_timeout)},

	{STRUCT_FLD(name,	"log_buffer_size"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	256 * 1024),
	 STRUCT_FLD(max_val,	IB_UINT64_T_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_log_buffer_size)},

	{STRUCT_FLD(name,	"log_file_size"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	1024 * 1024),
	 STRUCT_FLD(max_val,	ULINT_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_log_file_size)},

	{STRUCT_FLD(name,	"log_files_in_group"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	2),
	 STRUCT_FLD(max_val,	100),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_n_log_files)},

	{STRUCT_FLD(name,	"log_group_home_dir"),
	 STRUCT_FLD(type,	IB_CFG_TEXT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_log_group_home_dir),
	 STRUCT_FLD(get,	ib_cfg_var_get_log_group_home_dir),
	 STRUCT_FLD(tank,	NULL)},

	{STRUCT_FLD(name,	"max_dirty_pages_pct"),
	 STRUCT_FLD(type,	IB_CFG_ULONG),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	100),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_max_buf_pool_modified_pct)},

	{STRUCT_FLD(name,	"max_purge_lag"),
	 STRUCT_FLD(type,	IB_CFG_ULONG),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	IB_UINT64_T_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_max_purge_lag)},

	{STRUCT_FLD(name,	"lru_old_blocks_pct"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	5),
	 STRUCT_FLD(max_val,	95),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_lru_old_blocks_pct),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&lru_old_blocks_pct)},

	{STRUCT_FLD(name,	"lru_block_access_recency"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0xFFFFFFFFUL),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&buf_LRU_old_threshold_ms)},

	{STRUCT_FLD(name,	"open_files"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	10),
	 STRUCT_FLD(max_val,	IB_UINT64_T_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_max_n_open_files)},

	{STRUCT_FLD(name,	"read_io_threads"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	1),
	 STRUCT_FLD(max_val,	64),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_n_read_io_threads)},

	{STRUCT_FLD(name,	"write_io_threads"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY_AFTER_STARTUP),
	 STRUCT_FLD(min_val,	1),
	 STRUCT_FLD(max_val,	64),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_n_write_io_threads)},

	/* New, not present in InnoDB/MySQL */
	{STRUCT_FLD(name,	"pre_rollback_hook"),
	 STRUCT_FLD(type,	IB_CFG_CB),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&recv_pre_rollback_hook)},

	/* New, not present in InnoDB/MySQL */
	{STRUCT_FLD(name,	"print_verbose_log"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_print_verbose_log)},

	/* New, not present in InnoDB/MySQL */
	{STRUCT_FLD(name,	"rollback_on_timeout"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&ses_rollback_on_timeout)},

	{STRUCT_FLD(name,	"stats_sample_pages"),
	 STRUCT_FLD(type,	IB_CFG_ULINT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	1),
	 STRUCT_FLD(max_val,	ULINT_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_stats_sample_pages)},

	{STRUCT_FLD(name,	"status_file"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_innodb_status)},

	{STRUCT_FLD(name,	"sync_spin_loops"),
	 STRUCT_FLD(type,	IB_CFG_ULONG),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	IB_UINT64_T_MAX),
	 STRUCT_FLD(validate,	ib_cfg_var_validate_numeric),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_n_spin_wait_rounds)},

	{STRUCT_FLD(name,	"use_sys_malloc"),
	 STRUCT_FLD(type,	IB_CFG_IBOOL),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_NONE),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	ib_cfg_var_set_generic),
	 STRUCT_FLD(get,	ib_cfg_var_get_generic),
	 STRUCT_FLD(tank,	&srv_use_sys_malloc)},

	{STRUCT_FLD(name,	"version"),
	 STRUCT_FLD(type,	IB_CFG_TEXT),
	 STRUCT_FLD(flag,	IB_CFG_FLAG_READONLY),
	 STRUCT_FLD(min_val,	0),
	 STRUCT_FLD(max_val,	0),
	 STRUCT_FLD(validate,	NULL),
	 STRUCT_FLD(set,	NULL /* The ::set() function should never
				     be called because this variable is
				     flagged as IB_CFG_FLAG_READONLY */),
	 STRUCT_FLD(get,	ib_cfg_var_get_version),
	 STRUCT_FLD(tank,	NULL)},
};
/* @} */

/** This mutex has to work even if the InnoDB latching infrastructure
hasn't been initialized. */
UNIV_STATIC os_fast_mutex_t	cfg_vars_mutex;
UNIV_STATIC ib_cfg_var_t	cfg_vars[UT_ARR_SIZE(cfg_vars_defaults)];

/* public API functions and some auxiliary ones @{ */

/*********************************************************************//**
Lookup a variable name.
ib_cfg_lookup_var() @{
@return	config variable instance if found else NULL */
UNIV_STATIC
ib_cfg_var_t*
ib_cfg_lookup_var(
/*==============*/
	const char*	var)		/*!< in: variable name */
{
	ulint		i;

	for (i = 0; i < UT_ARR_SIZE(cfg_vars); ++i) {
		ib_cfg_var_t*	cfg_var;

		cfg_var = &cfg_vars[i];

		if (strcasecmp(var, cfg_var->name) == 0) {
			return(cfg_var);
		}
	}

	return(NULL);
}
/* @} */

/*********************************************************************//**
Get the type of a configuration variable. Returns DB_SUCCESS if the
variable with name "name" was found and "type" was set.
ib_cfg_var_get_type() @{
@return	DB_SUCCESS if successful */

ib_err_t
ib_cfg_var_get_type(
/*================*/
	const char*	name,		/*!< in: variable name */
	ib_cfg_type_t*	type)		/*!< out: variable type */
{
	ib_cfg_var_t*	cfg_var;
	ib_err_t	ret;

	os_fast_mutex_lock(&cfg_vars_mutex);

	cfg_var = ib_cfg_lookup_var(name);

	if (cfg_var != NULL) {
		*type = cfg_var->type;
		ret = DB_SUCCESS;
	} else {
		ret = DB_NOT_FOUND;
	}

	os_fast_mutex_unlock(&cfg_vars_mutex);

	return(ret);
}
/* @} */

/*********************************************************************//**
Set a configuration variable. "ap" must contain one argument whose type
depends on the type of the variable with the given "name". Returns
DB_SUCCESS if the variable with name "name" was found and if its value
was set.
ib_cfg_set_ap() @{
@return	DB_SUCCESS if set */
UNIV_STATIC
ib_err_t
ib_cfg_set_ap(
/*==========*/
	const char*	name,		/*!< in: variable name */
	va_list		ap)		/*!< in: variable value */
{
	ib_cfg_var_t*	cfg_var;
	ib_err_t	ret = DB_NOT_FOUND;

	os_fast_mutex_lock(&cfg_vars_mutex);

	cfg_var = ib_cfg_lookup_var(name);

	if (cfg_var != NULL) {

		/* check whether setting the variable is appropriate,
		according to its flag */
		if (cfg_var->flag & IB_CFG_FLAG_READONLY
		    || (cfg_var->flag & IB_CFG_FLAG_READONLY_AFTER_STARTUP
			&& srv_was_started)) {

			ret = DB_READONLY;
		} else {

			/* Get the parameter according to its type and
			call ::set() */
			switch (cfg_var->type) {
			case IB_CFG_IBOOL: {
				ib_bool_t	value;

				value = va_arg(ap, ib_bool_t);

				ret = cfg_var->set(cfg_var, &value);

				break;
			}

			case IB_CFG_ULINT: {
				ulint	value;

				value = va_arg(ap, ulint);

				ret = cfg_var->set(cfg_var, &value);

				break;
			}

			case IB_CFG_ULONG: {
				ulong	value;

				value = va_arg(ap, ulong);

				ret = cfg_var->set(cfg_var, &value);

				break;
			}

			case IB_CFG_TEXT: {
				const char*	value;

				value = va_arg(ap, const char*);

				ret = cfg_var->set(cfg_var, &value);

				break;
			}

			case IB_CFG_CB: {
				ib_cb_t	value;

				value = va_arg(ap, ib_cb_t);

				ret = cfg_var->set(cfg_var, &value);

				break;
			}
			/* do not add default: in order to produce a
			compilation warning if new type is added which is
			not handled here */
			}
		}
	}
	
	os_fast_mutex_unlock(&cfg_vars_mutex);

	return(ret);
}
/* @} */

/*********************************************************************//**
Set a configuration variable. The second argument's type depends on the
type of the variable with the given "name". Returns DB_SUCCESS if the
variable with name "name" was found and if its value was set. Strings
are not copied, be sure not to destroy or modify your string after it
has been given to this function. Memory management is left to the caller.
E.g. if you malloc() a string and give it to this function and then
malloc() another string and give it again to this function for the same
config variable, then you are responsible to free the first string.
ib_cfg_set() @{
@return	DB_SUCCESS if set */

ib_err_t
ib_cfg_set(
/*=======*/
	const char*	name,		/*!< in: variable name */
	...)				/*!< in: variable value */
{
	va_list		ap;
	ib_bool_t	ret;

	va_start(ap, name);

	ret = ib_cfg_set_ap(name, ap);

	va_end(ap);

	return(ret);
}
/* @} */

/*********************************************************************//**
Get the value of a configuration variable. The type of the returned value
depends on the type of the configuration variable. DB_SUCCESS is returned
if the variable with name "name" was found and "value" was set. Strings
are not copied and a reference to the internal storage is returned. Be
sure not to modify the returned value or you may confuse InnoDB or cause
a crash.
ib_cfg_get() @{
@return	DB_SUCCESS if retrieved successfully */

ib_err_t
ib_cfg_get(
/*=======*/
	const char*	name,		/*!< in: variable name */
	void*		value)		/*!< out: pointer to the place to
					store the retrieved value */
{
	ib_cfg_var_t*	cfg_var;
	ib_err_t	ret;

	os_fast_mutex_lock(&cfg_vars_mutex);

	cfg_var = ib_cfg_lookup_var(name);

	if (cfg_var != NULL) {
		ret = cfg_var->get(cfg_var, value);
	} else {
		ret = DB_NOT_FOUND;
	}

	os_fast_mutex_unlock(&cfg_vars_mutex);

	return(ret);
}
/* @} */

/*********************************************************************//**
Get a list of the names of all configuration variables.
The caller is responsible for free(3)ing the returned array of strings
when it is not needed anymore and for not modifying the individual strings.
ib_cfg_get_all() @{
@return	DB_SUCCESS or error code */

ib_err_t
ib_cfg_get_all(
/*===========*/
	const char***	names,		/*!< out: pointer to array of strings */
	ib_u32_t*	names_num)	/*!< out: number of strings returned */
{
	ib_u32_t	i;

	*names_num = UT_ARR_SIZE(cfg_vars_defaults);

	*names = (const char**) malloc(*names_num * sizeof(const char*));
	if (*names == NULL) {
		return(DB_OUT_OF_MEMORY);
	}

	for (i = 0; i < *names_num; i++) {
		(*names)[i] = cfg_vars_defaults[i].name;
	}

	return(DB_SUCCESS);
}
/* @} */

/*********************************************************************//**
Initialize the config system.
ib_cfg_init() @{
@return	DB_SUCCESS or error code */

ib_err_t
ib_cfg_init(void)
/*=============*/
{
	/* Initialize the mutex that protects cfg_vars[]. */
	os_fast_mutex_init(&cfg_vars_mutex);

	ut_memcpy(cfg_vars, cfg_vars_defaults, sizeof(cfg_vars));

	/* Set the default options. */
	srv_file_flush_method_str = NULL;
	srv_unix_file_flush_method = SRV_UNIX_FSYNC;
	srv_win_file_flush_method = SRV_WIN_IO_UNBUFFERED;

	os_aio_print_debug = FALSE;
	os_aio_use_native_aio = FALSE;

#define IB_CFG_SET(name, var)	\
	if (ib_cfg_set(name, var) != DB_SUCCESS) ut_error

	IB_CFG_SET("additional_mem_pool_size", 4 * 1024 * 1024);
	IB_CFG_SET("buffer_pool_size", 8 * 1024 * 1024);
	IB_CFG_SET("data_file_path", "ibdata1:32M:autoextend");
	IB_CFG_SET("data_home_dir", "./");
	IB_CFG_SET("file_io_threads", 4);
	IB_CFG_SET("file_per_table", IB_TRUE);
#ifndef __WIN__
	IB_CFG_SET("flush_method", "fsync");
#endif
	IB_CFG_SET("lock_wait_timeout", 60);
	IB_CFG_SET("log_buffer_size", 384 * 1024);
	IB_CFG_SET("log_file_size", 16 * 1024 * 1024);
	IB_CFG_SET("log_files_in_group", 2);
	IB_CFG_SET("log_group_home_dir", ".");
	IB_CFG_SET("lru_old_blocks_pct", 3 * 100 / 8);
	IB_CFG_SET("lru_block_access_recency", 0);
	IB_CFG_SET("rollback_on_timeout", IB_TRUE);
	IB_CFG_SET("read_io_threads", 4);
	IB_CFG_SET("write_io_threads", 4);
#undef IB_CFG_SET

	return(DB_SUCCESS);
}
/* @} */

/*********************************************************************//**
Shutdown the config system.
ib_cfg_shutdown() @{
@return	DB_SUCCESS or error code */

ib_err_t
ib_cfg_shutdown(void)
/*=================*/
{
	os_fast_mutex_lock(&cfg_vars_mutex);

	/* TODO: Check for NULL values of allocated config variables. */
	memset(cfg_vars, 0x0, sizeof(cfg_vars));

	os_fast_mutex_unlock(&cfg_vars_mutex);

	os_fast_mutex_free(&cfg_vars_mutex);

	return(DB_SUCCESS);
}
/* @} */

/* @} */

/* vim: set foldmethod=marker foldmarker=@{,@}: */