Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
1e0d53fe
Unverified
Commit
1e0d53fe
authored
Sep 25, 2018
by
Steven Allen
Committed by
GitHub
Sep 25, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5496 from rob-deutsch/fix/5495
fixed tests of raised fd limits
parents
30414a4c
aada0cc1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
43 additions
and
32 deletions
+43
-32
cmd/ipfs/daemon.go
cmd/ipfs/daemon.go
+5
-1
cmd/ipfs/util/ulimit.go
cmd/ipfs/util/ulimit.go
+14
-18
cmd/ipfs/util/ulimit_freebsd.go
cmd/ipfs/util/ulimit_freebsd.go
+14
-5
cmd/ipfs/util/ulimit_test.go
cmd/ipfs/util/ulimit_test.go
+3
-3
cmd/ipfs/util/ulimit_unix.go
cmd/ipfs/util/ulimit_unix.go
+5
-5
mk/util.mk
mk/util.mk
+2
-0
No files found.
cmd/ipfs/daemon.go
View file @
1e0d53fe
...
...
@@ -201,8 +201,12 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
managefd
,
_
:=
req
.
Options
[
adjustFDLimitKwd
]
.
(
bool
)
if
managefd
{
if
err
:=
utilmain
.
ManageFdLimit
();
err
!=
nil
{
if
changedFds
,
newFdsLimit
,
err
:=
utilmain
.
ManageFdLimit
();
err
!=
nil
{
log
.
Errorf
(
"setting file descriptor limit: %s"
,
err
)
}
else
{
if
changedFds
{
fmt
.
Printf
(
"Successfully raised file descriptor limit to %d.
\n
"
,
newFdsLimit
)
}
}
}
...
...
cmd/ipfs/util/ulimit.go
View file @
1e0d53fe
...
...
@@ -16,9 +16,9 @@ var (
supportsFDManagement
=
false
// getlimit returns the soft and hard limits of file descriptors counts
getLimit
func
()
(
int64
,
int64
,
error
)
getLimit
func
()
(
u
int64
,
u
int64
,
error
)
// set limit sets the soft and hard limits of file descriptors counts
setLimit
func
(
int64
,
int64
)
error
setLimit
func
(
u
int64
,
u
int64
)
error
)
// maxFds is the maximum number of file descriptors that go-ipfs
...
...
@@ -45,21 +45,19 @@ func setMaxFds() {
// ManageFdLimit raise the current max file descriptor count
// of the process based on the IPFS_FD_MAX value
func
ManageFdLimit
()
error
{
func
ManageFdLimit
()
(
changed
bool
,
newLimit
uint64
,
err
error
)
{
if
!
supportsFDManagement
{
return
nil
return
false
,
0
,
nil
}
setMaxFds
()
soft
,
hard
,
err
:=
getLimit
()
if
err
!=
nil
{
return
err
return
false
,
0
,
err
}
max
:=
int64
(
maxFds
)
if
max
<=
soft
{
return
nil
if
maxFds
<=
soft
{
return
false
,
0
,
nil
}
// the soft limit is the value that the kernel enforces for the
...
...
@@ -67,25 +65,23 @@ func ManageFdLimit() error {
// the hard limit acts as a ceiling for the soft limit
// an unprivileged process may only set it's soft limit to a
// alue in the range from 0 up to the hard limit
if
err
=
setLimit
(
max
,
max
);
err
!=
nil
{
if
err
=
setLimit
(
max
Fds
,
max
Fds
);
err
!=
nil
{
if
err
!=
syscall
.
EPERM
{
return
fmt
.
Errorf
(
"error setting: ulimit: %s"
,
err
)
return
false
,
0
,
fmt
.
Errorf
(
"error setting: ulimit: %s"
,
err
)
}
// the process does not have permission so we should only
// set the soft value
if
max
>
hard
{
return
errors
.
New
(
if
max
Fds
>
hard
{
return
false
,
0
,
errors
.
New
(
"cannot set rlimit, IPFS_FD_MAX is larger than the hard limit"
,
)
}
if
err
=
setLimit
(
max
,
hard
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error setting ulimit wihout hard limit: %s"
,
err
)
if
err
=
setLimit
(
max
Fds
,
hard
);
err
!=
nil
{
return
false
,
0
,
fmt
.
Errorf
(
"error setting ulimit wihout hard limit: %s"
,
err
)
}
}
fmt
.
Printf
(
"Successfully raised file descriptor limit to %d.
\n
"
,
max
)
return
nil
return
true
,
maxFds
,
nil
}
cmd/ipfs/util/ulimit_freebsd.go
View file @
1e0d53fe
...
...
@@ -3,6 +3,9 @@
package
util
import
(
"errors"
"math"
unix
"gx/ipfs/QmVGjyM9i2msKvLXwh9VosCTgP4mL91kC7hDmqnwTTx6Hu/sys/unix"
)
...
...
@@ -12,16 +15,22 @@ func init() {
setLimit
=
freebsdSetLimit
}
func
freebsdGetLimit
()
(
int64
,
int64
,
error
)
{
func
freebsdGetLimit
()
(
u
int64
,
u
int64
,
error
)
{
rlimit
:=
unix
.
Rlimit
{}
err
:=
unix
.
Getrlimit
(
unix
.
RLIMIT_NOFILE
,
&
rlimit
)
return
rlimit
.
Cur
,
rlimit
.
Max
,
err
if
(
rlimit
.
Cur
<
0
)
||
(
rlimit
.
Max
<
0
)
{
return
0
,
0
,
errors
.
New
(
"invalid rlimits"
)
}
return
uint64
(
rlimit
.
Cur
),
uint64
(
rlimit
.
Max
),
err
}
func
freebsdSetLimit
(
soft
int64
,
max
int64
)
error
{
func
freebsdSetLimit
(
soft
uint64
,
max
uint64
)
error
{
if
(
soft
>
math
.
MaxInt64
)
||
(
max
>
math
.
MaxInt64
)
{
return
errors
.
New
(
"invalid rlimits"
)
}
rlimit
:=
unix
.
Rlimit
{
Cur
:
soft
,
Max
:
max
,
Cur
:
int64
(
soft
)
,
Max
:
int64
(
max
)
,
}
return
unix
.
Setrlimit
(
unix
.
RLIMIT_NOFILE
,
&
rlimit
)
}
cmd/ipfs/util/ulimit_test.go
View file @
1e0d53fe
...
...
@@ -12,7 +12,7 @@ import (
func
TestManageFdLimit
(
t
*
testing
.
T
)
{
t
.
Log
(
"Testing file descriptor count"
)
if
err
:=
ManageFdLimit
();
err
!=
nil
{
if
_
,
_
,
err
:=
ManageFdLimit
();
err
!=
nil
{
t
.
Errorf
(
"Cannot manage file descriptors"
)
}
...
...
@@ -41,7 +41,7 @@ func TestManageInvalidNFds(t *testing.T) {
// call to check and set the maximum file descriptor from the env
setMaxFds
()
if
err
=
ManageFdLimit
();
err
==
nil
{
if
_
,
_
,
err
:
=
ManageFdLimit
();
err
==
nil
{
t
.
Errorf
(
"ManageFdLimit should return an error"
)
}
else
if
err
!=
nil
{
flag
:=
strings
.
Contains
(
err
.
Error
(),
...
...
@@ -79,7 +79,7 @@ func TestManageFdLimitWithEnvSet(t *testing.T) {
t
.
Errorf
(
"The maxfds is not set from IPFS_FD_MAX"
)
}
if
err
=
ManageFdLimit
();
err
!=
nil
{
if
_
,
_
,
err
=
ManageFdLimit
();
err
!=
nil
{
t
.
Errorf
(
"Cannot manage file descriptor count"
)
}
...
...
cmd/ipfs/util/ulimit_unix.go
View file @
1e0d53fe
...
...
@@ -12,16 +12,16 @@ func init() {
setLimit
=
unixSetLimit
}
func
unixGetLimit
()
(
int64
,
int64
,
error
)
{
func
unixGetLimit
()
(
u
int64
,
u
int64
,
error
)
{
rlimit
:=
unix
.
Rlimit
{}
err
:=
unix
.
Getrlimit
(
unix
.
RLIMIT_NOFILE
,
&
rlimit
)
return
int64
(
rlimit
.
Cur
)
,
int64
(
rlimit
.
Max
)
,
err
return
rlimit
.
Cur
,
rlimit
.
Max
,
err
}
func
unixSetLimit
(
soft
int64
,
max
int64
)
error
{
func
unixSetLimit
(
soft
u
int64
,
max
u
int64
)
error
{
rlimit
:=
unix
.
Rlimit
{
Cur
:
uint64
(
soft
)
,
Max
:
uint64
(
max
)
,
Cur
:
soft
,
Max
:
max
,
}
return
unix
.
Setrlimit
(
unix
.
RLIMIT_NOFILE
,
&
rlimit
)
}
mk/util.mk
View file @
1e0d53fe
...
...
@@ -20,6 +20,8 @@ SUPPORTED_PLATFORMS += linux-amd64
SUPPORTED_PLATFORMS
+=
darwin-386
SUPPORTED_PLATFORMS
+=
darwin-amd64
SUPPORTED_PLATFORMS
+=
freebsd-amd64
space
:=
space
+=
comma
:=
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment