Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
2dba8f17
Commit
2dba8f17
authored
Aug 03, 2017
by
Michał Stachowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for hugetlbfs in empty dir volume plugin
parent
38d5dee6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
12 deletions
+61
-12
types.go
pkg/api/types.go
+3
-2
empty_dir.go
pkg/volume/empty_dir/empty_dir.go
+39
-6
empty_dir_linux.go
pkg/volume/empty_dir/empty_dir_linux.go
+6
-1
empty_dir_test.go
pkg/volume/empty_dir/empty_dir_test.go
+10
-1
types.go
staging/src/k8s.io/api/core/v1/types.go
+3
-2
No files found.
pkg/api/types.go
View file @
2dba8f17
...
@@ -681,8 +681,9 @@ type EmptyDirVolumeSource struct {
...
@@ -681,8 +681,9 @@ type EmptyDirVolumeSource struct {
type
StorageMedium
string
type
StorageMedium
string
const
(
const
(
StorageMediumDefault
StorageMedium
=
""
// use whatever the default is for the node
StorageMediumDefault
StorageMedium
=
""
// use whatever the default is for the node
StorageMediumMemory
StorageMedium
=
"Memory"
// use memory (tmpfs)
StorageMediumMemory
StorageMedium
=
"Memory"
// use memory (tmpfs)
StorageMediumHugepages
StorageMedium
=
"Hugepages"
// use hugepages
)
)
// Protocol defines network protocols supported for things like container ports.
// Protocol defines network protocols supported for things like container ports.
...
...
pkg/volume/empty_dir/empty_dir.go
View file @
2dba8f17
...
@@ -104,9 +104,11 @@ func (plugin *emptyDirPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts vo
...
@@ -104,9 +104,11 @@ func (plugin *emptyDirPlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, opts vo
func
(
plugin
*
emptyDirPlugin
)
newMounterInternal
(
spec
*
volume
.
Spec
,
pod
*
v1
.
Pod
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
func
(
plugin
*
emptyDirPlugin
)
newMounterInternal
(
spec
*
volume
.
Spec
,
pod
*
v1
.
Pod
,
mounter
mount
.
Interface
,
mountDetector
mountDetector
,
opts
volume
.
VolumeOptions
)
(
volume
.
Mounter
,
error
)
{
medium
:=
v1
.
StorageMediumDefault
medium
:=
v1
.
StorageMediumDefault
if
spec
.
Volume
.
EmptyDir
!=
nil
{
// Support a non-specified source as EmptyDir.
if
spec
.
Volume
.
EmptyDir
!=
nil
{
// Support a non-specified source as EmptyDir.
medium
=
spec
.
Volume
.
EmptyDir
.
Medium
medium
=
spec
.
Volume
.
EmptyDir
.
Medium
}
}
return
&
emptyDir
{
return
&
emptyDir
{
pod
:
pod
,
pod
:
pod
,
volName
:
spec
.
Name
(),
volName
:
spec
.
Name
(),
...
@@ -159,8 +161,9 @@ type mountDetector interface {
...
@@ -159,8 +161,9 @@ type mountDetector interface {
type
storageMedium
int
type
storageMedium
int
const
(
const
(
mediumUnknown
storageMedium
=
0
// assume anything we don't explicitly handle is this
mediumUnknown
storageMedium
=
0
// assume anything we don't explicitly handle is this
mediumMemory
storageMedium
=
1
// memory (e.g. tmpfs on linux)
mediumMemory
storageMedium
=
1
// memory (e.g. tmpfs on linux)
mediumHugepages
storageMedium
=
2
// hugepages
)
)
// EmptyDir volumes are temporary directories exposed to the pod.
// EmptyDir volumes are temporary directories exposed to the pod.
...
@@ -221,6 +224,8 @@ func (ed *emptyDir) SetUpAt(dir string, fsGroup *int64) error {
...
@@ -221,6 +224,8 @@ func (ed *emptyDir) SetUpAt(dir string, fsGroup *int64) error {
err
=
ed
.
setupDir
(
dir
)
err
=
ed
.
setupDir
(
dir
)
case
v1
.
StorageMediumMemory
:
case
v1
.
StorageMediumMemory
:
err
=
ed
.
setupTmpfs
(
dir
)
err
=
ed
.
setupTmpfs
(
dir
)
case
v1
.
StorageMediumHugepages
:
err
=
ed
.
setupHugepages
(
dir
)
default
:
default
:
err
=
fmt
.
Errorf
(
"unknown storage medium %q"
,
ed
.
medium
)
err
=
fmt
.
Errorf
(
"unknown storage medium %q"
,
ed
.
medium
)
}
}
...
@@ -257,6 +262,29 @@ func (ed *emptyDir) setupTmpfs(dir string) error {
...
@@ -257,6 +262,29 @@ func (ed *emptyDir) setupTmpfs(dir string) error {
return
ed
.
mounter
.
Mount
(
"tmpfs"
,
dir
,
"tmpfs"
,
nil
/* options */
)
return
ed
.
mounter
.
Mount
(
"tmpfs"
,
dir
,
"tmpfs"
,
nil
/* options */
)
}
}
// setupHugepages creates a hugepage mount at the specified directory.
func
(
ed
*
emptyDir
)
setupHugepages
(
dir
string
)
error
{
if
ed
.
mounter
==
nil
{
return
fmt
.
Errorf
(
"memory storage requested, but mounter is nil"
)
}
if
err
:=
ed
.
setupDir
(
dir
);
err
!=
nil
{
return
err
}
// Make SetUp idempotent.
medium
,
isMnt
,
err
:=
ed
.
mountDetector
.
GetMountMedium
(
dir
)
if
err
!=
nil
{
return
err
}
// If the directory is a mountpoint with medium memory, there is no
// work to do since we are already in the desired state.
if
isMnt
&&
medium
==
mediumHugepages
{
return
nil
}
glog
.
V
(
3
)
.
Infof
(
"pod %v: mounting hugepages for volume %v"
,
ed
.
pod
.
UID
,
ed
.
volName
)
return
ed
.
mounter
.
Mount
(
"nodev"
,
dir
,
"hugetlbfs"
,
[]
string
{})
}
// setupDir creates the directory with the default permissions specified by the perm constant.
// setupDir creates the directory with the default permissions specified by the perm constant.
func
(
ed
*
emptyDir
)
setupDir
(
dir
string
)
error
{
func
(
ed
*
emptyDir
)
setupDir
(
dir
string
)
error
{
// Create the directory if it doesn't already exist.
// Create the directory if it doesn't already exist.
...
@@ -318,9 +346,14 @@ func (ed *emptyDir) TearDownAt(dir string) error {
...
@@ -318,9 +346,14 @@ func (ed *emptyDir) TearDownAt(dir string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
isMnt
&&
medium
==
mediumMemory
{
if
isMnt
{
ed
.
medium
=
v1
.
StorageMediumMemory
if
medium
==
mediumMemory
{
return
ed
.
teardownTmpfs
(
dir
)
ed
.
medium
=
v1
.
StorageMediumMemory
return
ed
.
teardownTmpfsOrHugetlbfs
(
dir
)
}
else
if
medium
==
mediumHugepages
{
ed
.
medium
=
v1
.
StorageMediumHugepages
return
ed
.
teardownTmpfsOrHugetlbfs
(
dir
)
}
}
}
// assume StorageMediumDefault
// assume StorageMediumDefault
return
ed
.
teardownDefault
(
dir
)
return
ed
.
teardownDefault
(
dir
)
...
@@ -336,7 +369,7 @@ func (ed *emptyDir) teardownDefault(dir string) error {
...
@@ -336,7 +369,7 @@ func (ed *emptyDir) teardownDefault(dir string) error {
return
nil
return
nil
}
}
func
(
ed
*
emptyDir
)
teardownTmpfs
(
dir
string
)
error
{
func
(
ed
*
emptyDir
)
teardownTmpfs
OrHugetlbfs
(
dir
string
)
error
{
if
ed
.
mounter
==
nil
{
if
ed
.
mounter
==
nil
{
return
fmt
.
Errorf
(
"memory storage requested, but mounter is nil"
)
return
fmt
.
Errorf
(
"memory storage requested, but mounter is nil"
)
}
}
...
...
pkg/volume/empty_dir/empty_dir_linux.go
View file @
2dba8f17
...
@@ -27,7 +27,10 @@ import (
...
@@ -27,7 +27,10 @@ import (
)
)
// Defined by Linux - the type number for tmpfs mounts.
// Defined by Linux - the type number for tmpfs mounts.
const
linuxTmpfsMagic
=
0x01021994
const
(
linuxTmpfsMagic
=
0x01021994
linuxHugetlbfsMagic
=
0x958458f6
)
// realMountDetector implements mountDetector in terms of syscalls.
// realMountDetector implements mountDetector in terms of syscalls.
type
realMountDetector
struct
{
type
realMountDetector
struct
{
...
@@ -48,6 +51,8 @@ func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, er
...
@@ -48,6 +51,8 @@ func (m *realMountDetector) GetMountMedium(path string) (storageMedium, bool, er
glog
.
V
(
5
)
.
Infof
(
"Statfs_t of %v: %+v"
,
path
,
buf
)
glog
.
V
(
5
)
.
Infof
(
"Statfs_t of %v: %+v"
,
path
,
buf
)
if
buf
.
Type
==
linuxTmpfsMagic
{
if
buf
.
Type
==
linuxTmpfsMagic
{
return
mediumMemory
,
!
notMnt
,
nil
return
mediumMemory
,
!
notMnt
,
nil
}
else
if
buf
.
Type
==
linuxHugetlbfsMagic
{
return
mediumHugepages
,
!
notMnt
,
nil
}
}
return
mediumUnknown
,
!
notMnt
,
nil
return
mediumUnknown
,
!
notMnt
,
nil
}
}
pkg/volume/empty_dir/empty_dir_test.go
View file @
2dba8f17
...
@@ -80,6 +80,15 @@ func TestPluginEmptyRootContext(t *testing.T) {
...
@@ -80,6 +80,15 @@ func TestPluginEmptyRootContext(t *testing.T) {
expectedTeardownMounts
:
0
})
expectedTeardownMounts
:
0
})
}
}
func
TestPluginHugetlbfs
(
t
*
testing
.
T
)
{
doTestPlugin
(
t
,
pluginTestConfig
{
medium
:
v1
.
StorageMediumHugepages
,
expectedSetupMounts
:
1
,
expectedTeardownMounts
:
0
,
shouldBeMountedBeforeTeardown
:
true
,
})
}
type
pluginTestConfig
struct
{
type
pluginTestConfig
struct
{
medium
v1
.
StorageMedium
medium
v1
.
StorageMedium
idempotent
bool
idempotent
bool
...
@@ -165,7 +174,7 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
...
@@ -165,7 +174,7 @@ func doTestPlugin(t *testing.T, config pluginTestConfig) {
if
e
,
a
:=
config
.
expectedSetupMounts
,
len
(
physicalMounter
.
Log
);
e
!=
a
{
if
e
,
a
:=
config
.
expectedSetupMounts
,
len
(
physicalMounter
.
Log
);
e
!=
a
{
t
.
Errorf
(
"Expected %v physicalMounter calls during setup, got %v"
,
e
,
a
)
t
.
Errorf
(
"Expected %v physicalMounter calls during setup, got %v"
,
e
,
a
)
}
else
if
config
.
expectedSetupMounts
==
1
&&
}
else
if
config
.
expectedSetupMounts
==
1
&&
(
physicalMounter
.
Log
[
0
]
.
Action
!=
mount
.
FakeActionMount
||
physicalMounter
.
Log
[
0
]
.
FSType
!=
"tmpfs"
)
{
(
physicalMounter
.
Log
[
0
]
.
Action
!=
mount
.
FakeActionMount
||
(
physicalMounter
.
Log
[
0
]
.
FSType
!=
"tmpfs"
&&
physicalMounter
.
Log
[
0
]
.
FSType
!=
"hugetlbfs"
)
)
{
t
.
Errorf
(
"Unexpected physicalMounter action during setup: %#v"
,
physicalMounter
.
Log
[
0
])
t
.
Errorf
(
"Unexpected physicalMounter action during setup: %#v"
,
physicalMounter
.
Log
[
0
])
}
}
physicalMounter
.
ResetLog
()
physicalMounter
.
ResetLog
()
...
...
staging/src/k8s.io/api/core/v1/types.go
View file @
2dba8f17
...
@@ -943,8 +943,9 @@ type FlockerVolumeSource struct {
...
@@ -943,8 +943,9 @@ type FlockerVolumeSource struct {
type
StorageMedium
string
type
StorageMedium
string
const
(
const
(
StorageMediumDefault
StorageMedium
=
""
// use whatever the default is for the node
StorageMediumDefault
StorageMedium
=
""
// use whatever the default is for the node
StorageMediumMemory
StorageMedium
=
"Memory"
// use memory (tmpfs)
StorageMediumMemory
StorageMedium
=
"Memory"
// use memory (tmpfs)
StorageMediumHugepages
StorageMedium
=
"HugePages"
// use hugepages
)
)
// Protocol defines network protocols supported for things like container ports.
// Protocol defines network protocols supported for things like container ports.
...
...
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