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
1880c4ee
Commit
1880c4ee
authored
Nov 06, 2015
by
Sami Wagiaalla
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move formatAndMount and diskLooksUnformatted to mount_linux
parent
3a5768a0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
50 deletions
+56
-50
mount.go
pkg/util/mount/mount.go
+0
-50
mount_linux.go
pkg/util/mount/mount_linux.go
+48
-0
mount_unsupported.go
pkg/util/mount/mount_unsupported.go
+8
-0
No files found.
pkg/util/mount/mount.go
View file @
1880c4ee
...
@@ -19,8 +19,6 @@ limitations under the License.
...
@@ -19,8 +19,6 @@ limitations under the License.
package
mount
package
mount
import
(
import
(
"strings"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/exec"
)
)
...
@@ -68,54 +66,6 @@ func (mounter *SafeFormatAndMount) Mount(source string, target string, fstype st
...
@@ -68,54 +66,6 @@ func (mounter *SafeFormatAndMount) Mount(source string, target string, fstype st
return
mounter
.
formatAndMount
(
source
,
target
,
fstype
,
options
)
return
mounter
.
formatAndMount
(
source
,
target
,
fstype
,
options
)
}
}
// formatAndMount uses unix utils to format and mount the given disk
func
(
mounter
*
SafeFormatAndMount
)
formatAndMount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
options
=
append
(
options
,
"defaults"
)
// Try to mount the disk
err
:=
mounter
.
Interface
.
Mount
(
source
,
target
,
fstype
,
options
)
if
err
!=
nil
{
// It is possible that this disk is not formatted. Double check using diskLooksUnformatted
notFormatted
,
err
:=
mounter
.
diskLooksUnformatted
(
source
)
if
err
==
nil
&&
notFormatted
{
args
:=
[]
string
{
source
}
// Disk is unformatted so format it.
// Use 'ext4' as the default
if
len
(
fstype
)
==
0
{
fstype
=
"ext4"
}
if
fstype
==
"ext4"
||
fstype
==
"ext3"
{
args
=
[]
string
{
"-E"
,
"lazy_itable_init=0,lazy_journal_init=0"
,
"-F"
,
source
}
}
cmd
:=
mounter
.
Runner
.
Command
(
"mkfs."
+
fstype
,
args
...
)
_
,
err
:=
cmd
.
CombinedOutput
()
if
err
==
nil
{
// the disk has been formatted sucessfully try to mount it again.
return
mounter
.
Interface
.
Mount
(
source
,
target
,
fstype
,
options
)
}
return
err
}
}
return
err
}
// diskLooksUnformatted uses 'lsblk' to see if the given disk is unformated
func
(
mounter
*
SafeFormatAndMount
)
diskLooksUnformatted
(
disk
string
)
(
bool
,
error
)
{
args
:=
[]
string
{
"-nd"
,
"-o"
,
"FSTYPE"
,
disk
}
cmd
:=
mounter
.
Runner
.
Command
(
"lsblk"
,
args
...
)
dataOut
,
err
:=
cmd
.
CombinedOutput
()
output
:=
strings
.
TrimSpace
(
string
(
dataOut
))
// TODO (#13212): check if this disk has partitions and return false, and
// an error if so.
if
err
!=
nil
{
return
false
,
err
}
return
output
==
""
,
nil
}
// New returns a mount.Interface for the current system.
// New returns a mount.Interface for the current system.
func
New
()
Interface
{
func
New
()
Interface
{
return
&
Mounter
{}
return
&
Mounter
{}
...
...
pkg/util/mount/mount_linux.go
View file @
1880c4ee
...
@@ -235,3 +235,51 @@ func readProcMountsFrom(file io.Reader, out *[]MountPoint) (uint32, error) {
...
@@ -235,3 +235,51 @@ func readProcMountsFrom(file io.Reader, out *[]MountPoint) (uint32, error) {
}
}
return
hash
.
Sum32
(),
nil
return
hash
.
Sum32
(),
nil
}
}
// formatAndMount uses unix utils to format and mount the given disk
func
(
mounter
*
SafeFormatAndMount
)
formatAndMount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
options
=
append
(
options
,
"defaults"
)
// Try to mount the disk
err
:=
mounter
.
Interface
.
Mount
(
source
,
target
,
fstype
,
options
)
if
err
!=
nil
{
// It is possible that this disk is not formatted. Double check using diskLooksUnformatted
notFormatted
,
err
:=
mounter
.
diskLooksUnformatted
(
source
)
if
err
==
nil
&&
notFormatted
{
args
:=
[]
string
{
source
}
// Disk is unformatted so format it.
// Use 'ext4' as the default
if
len
(
fstype
)
==
0
{
fstype
=
"ext4"
}
if
fstype
==
"ext4"
||
fstype
==
"ext3"
{
args
=
[]
string
{
"-E"
,
"lazy_itable_init=0,lazy_journal_init=0"
,
"-F"
,
source
}
}
cmd
:=
mounter
.
Runner
.
Command
(
"mkfs."
+
fstype
,
args
...
)
_
,
err
:=
cmd
.
CombinedOutput
()
if
err
==
nil
{
// the disk has been formatted sucessfully try to mount it again.
return
mounter
.
Interface
.
Mount
(
source
,
target
,
fstype
,
options
)
}
return
err
}
}
return
err
}
// diskLooksUnformatted uses 'lsblk' to see if the given disk is unformated
func
(
mounter
*
SafeFormatAndMount
)
diskLooksUnformatted
(
disk
string
)
(
bool
,
error
)
{
args
:=
[]
string
{
"-nd"
,
"-o"
,
"FSTYPE"
,
disk
}
cmd
:=
mounter
.
Runner
.
Command
(
"lsblk"
,
args
...
)
dataOut
,
err
:=
cmd
.
CombinedOutput
()
output
:=
strings
.
TrimSpace
(
string
(
dataOut
))
// TODO (#13212): check if this disk has partitions and return false, and
// an error if so.
if
err
!=
nil
{
return
false
,
err
}
return
output
==
""
,
nil
}
pkg/util/mount/mount_unsupported.go
View file @
1880c4ee
...
@@ -35,3 +35,11 @@ func (mounter *Mounter) List() ([]MountPoint, error) {
...
@@ -35,3 +35,11 @@ func (mounter *Mounter) List() ([]MountPoint, error) {
func
(
mounter
*
Mounter
)
IsLikelyNotMountPoint
(
file
string
)
(
bool
,
error
)
{
func
(
mounter
*
Mounter
)
IsLikelyNotMountPoint
(
file
string
)
(
bool
,
error
)
{
return
true
,
nil
return
true
,
nil
}
}
func
(
mounter
*
SafeFormatAndMount
)
formatAndMount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
return
nil
}
func
(
mounter
*
SafeFormatAndMount
)
diskLooksUnformatted
(
disk
string
)
(
bool
,
error
)
{
return
true
,
nil
}
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