1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
994.2.4
by Monty Taylor
Blast. Fixed some make distcheck issues. |
16 |
#include "mysys/mysys_priv.h" |
1
by brian
clean slate |
17 |
#include "my_static.h" |
212.5.18
by Monty Taylor
Moved m_ctype, m_string and my_bitmap. Removed t_ctype. |
18 |
#include <mystrings/m_string.h> |
629.1.1
by Monty Taylor
More solaris fixes. |
19 |
#include <stdlib.h> |
20 |
#include <string.h> |
|
1
by brian
clean slate |
21 |
|
22 |
/*
|
|
23 |
set how many open files we want to be able to handle
|
|
24 |
||
25 |
SYNOPSIS
|
|
26 |
set_maximum_open_files()
|
|
27 |
max_file_limit Files to open
|
|
28 |
||
29 |
NOTES
|
|
30 |
The request may not fulfilled becasue of system limitations
|
|
31 |
||
32 |
RETURN
|
|
33 |
Files available to open.
|
|
34 |
May be more or less than max_file_limit!
|
|
35 |
*/
|
|
36 |
||
37 |
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
|
|
38 |
||
39 |
#ifndef RLIM_INFINITY
|
|
971.4.1
by Monty Taylor
GCC on Solaris build fixes. |
40 |
#define RLIM_INFINITY ((rlim_t) 0xffffffff)
|
1
by brian
clean slate |
41 |
#endif
|
42 |
||
779.3.23
by Monty Taylor
More fixy-fixes. |
43 |
static uint64_t set_max_open_files(uint64_t max_file_limit) |
1
by brian
clean slate |
44 |
{
|
971.4.1
by Monty Taylor
GCC on Solaris build fixes. |
45 |
struct rlimit rlim; |
632.1.11
by Monty Taylor
Fixed Sun Studio warnings in mysys. |
46 |
rlim_t old_cur; |
1
by brian
clean slate |
47 |
|
971.4.1
by Monty Taylor
GCC on Solaris build fixes. |
48 |
if (!getrlimit(RLIMIT_NOFILE,&rlim)) |
1
by brian
clean slate |
49 |
{
|
971.4.1
by Monty Taylor
GCC on Solaris build fixes. |
50 |
old_cur= rlim.rlim_cur; |
51 |
if (rlim.rlim_cur == (rlim_t)RLIM_INFINITY) |
|
52 |
rlim.rlim_cur = max_file_limit; |
|
53 |
if (rlim.rlim_cur >= max_file_limit) |
|
637
by Brian Aker
Merge from Monty |
54 |
{
|
971.4.1
by Monty Taylor
GCC on Solaris build fixes. |
55 |
return rlim.rlim_cur; |
637
by Brian Aker
Merge from Monty |
56 |
}
|
971.4.1
by Monty Taylor
GCC on Solaris build fixes. |
57 |
rlim.rlim_cur= rlim.rlim_max= max_file_limit; |
58 |
if (setrlimit(RLIMIT_NOFILE, &rlim)) |
|
632.1.11
by Monty Taylor
Fixed Sun Studio warnings in mysys. |
59 |
max_file_limit= (old_cur < UINT32_MAX) ? (uint32_t)old_cur : UINT32_MAX; |
1
by brian
clean slate |
60 |
else
|
61 |
{
|
|
971.4.1
by Monty Taylor
GCC on Solaris build fixes. |
62 |
rlim.rlim_cur= 0; /* Safety if next call fails */ |
63 |
(void) getrlimit(RLIMIT_NOFILE,&rlim); |
|
64 |
if (rlim.rlim_cur) /* If call didn't fail */ |
|
65 |
max_file_limit= (uint32_t) rlim.rlim_cur; |
|
1
by brian
clean slate |
66 |
}
|
67 |
}
|
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
68 |
return(max_file_limit); |
1
by brian
clean slate |
69 |
}
|
70 |
||
71 |
#else
|
|
779.3.23
by Monty Taylor
More fixy-fixes. |
72 |
static int set_max_open_files(uint64_t max_file_limit) |
1
by brian
clean slate |
73 |
{
|
74 |
/* We don't know the limit. Return best guess */
|
|
398.1.4
by Monty Taylor
Renamed max/min. |
75 |
return cmin(max_file_limit, OS_FILE_LIMIT); |
1
by brian
clean slate |
76 |
}
|
77 |
#endif
|
|
78 |
||
79 |
||
80 |
/*
|
|
81 |
Change number of open files
|
|
82 |
||
83 |
SYNOPSIS:
|
|
84 |
my_set_max_open_files()
|
|
85 |
files Number of requested files
|
|
86 |
||
87 |
RETURN
|
|
88 |
number of files available for open
|
|
89 |
*/
|
|
90 |
||
779.3.23
by Monty Taylor
More fixy-fixes. |
91 |
uint64_t my_set_max_open_files(uint64_t files) |
1
by brian
clean slate |
92 |
{
|
93 |
struct st_my_file_info *tmp; |
|
94 |
||
398.1.4
by Monty Taylor
Renamed max/min. |
95 |
files= set_max_open_files(cmin(files, OS_FILE_LIMIT)); |
1
by brian
clean slate |
96 |
if (files <= MY_NFILE) |
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
97 |
return(files); |
1
by brian
clean slate |
98 |
|
779.3.23
by Monty Taylor
More fixy-fixes. |
99 |
if (!(tmp= (st_my_file_info*) malloc((size_t)cmax(sizeof(st_my_file_info) * files,SIZE_MAX)))) |
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
100 |
return(MY_NFILE); |
1
by brian
clean slate |
101 |
|
102 |
/* Copy any initialized files */
|
|
779.3.23
by Monty Taylor
More fixy-fixes. |
103 |
memcpy(tmp, my_file_info, |
104 |
sizeof(*tmp) * |
|
105 |
(size_t)cmin(my_file_limit, |
|
779.3.24
by Monty Taylor
Fixed solaris fixes on linux again. |
106 |
cmax(files,UINT32_MAX))); |
212.6.14
by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove(). |
107 |
/*
|
108 |
The int cast is necessary since 'my_file_limits' might be greater
|
|
109 |
than 'files'.
|
|
110 |
*/
|
|
111 |
memset(tmp + my_file_limit, 0, |
|
398.1.4
by Monty Taylor
Renamed max/min. |
112 |
cmax((int) (files - my_file_limit), 0)*sizeof(*tmp)); |
1
by brian
clean slate |
113 |
my_free_open_file_info(); /* Free if already allocated */ |
114 |
my_file_info= tmp; |
|
779.3.24
by Monty Taylor
Fixed solaris fixes on linux again. |
115 |
my_file_limit= (size_t)cmax(UINT32_MAX,files); |
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
116 |
return(files); |
1
by brian
clean slate |
117 |
}
|
118 |
||
119 |
||
120 |
void my_free_open_file_info() |
|
121 |
{
|
|
122 |
if (my_file_info != my_file_info_default) |
|
123 |
{
|
|
124 |
/* Copy data back for my_print_open_files */
|
|
212.6.14
by Mats Kindahl
Removing redundant use of casts in mysys for memcmp(), memcpy(), memset(), and memmove(). |
125 |
memcpy(my_file_info_default, my_file_info, |
1
by brian
clean slate |
126 |
sizeof(*my_file_info_default)* MY_NFILE); |
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
127 |
free((char*) my_file_info); |
1
by brian
clean slate |
128 |
my_file_info= my_file_info_default; |
129 |
my_file_limit= MY_NFILE; |
|
130 |
}
|
|
51.3.19
by Jay Pipes
Phase 6 - Remove DBUG from mysys |
131 |
return; |
1
by brian
clean slate |
132 |
}
|