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
2f46df35
Commit
2f46df35
authored
Jan 26, 2018
by
mlmhl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return a more human readable error message if mount an unformatted volume as readonly
parent
84bfc7ad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
22 deletions
+32
-22
mount.go
pkg/util/mount/mount.go
+0
-6
mount_linux.go
pkg/util/mount/mount_linux.go
+32
-16
No files found.
pkg/util/mount/mount.go
View file @
2f46df35
...
...
@@ -125,12 +125,6 @@ type SafeFormatAndMount struct {
// disk is already formatted or it is being mounted as read-only, it
// will be mounted without formatting.
func
(
mounter
*
SafeFormatAndMount
)
FormatAndMount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
// Don't attempt to format if mounting as readonly. Go straight to mounting.
for
_
,
option
:=
range
options
{
if
option
==
"ro"
{
return
mounter
.
Interface
.
Mount
(
source
,
target
,
fstype
,
options
)
}
}
return
mounter
.
formatAndMount
(
source
,
target
,
fstype
,
options
)
}
...
...
pkg/util/mount/mount_linux.go
View file @
2f46df35
...
...
@@ -19,6 +19,7 @@ limitations under the License.
package
mount
import
(
"errors"
"fmt"
"os"
"os/exec"
...
...
@@ -472,23 +473,33 @@ func (mounter *Mounter) ExistsPath(pathname string) bool {
// formatAndMount uses unix utils to format and mount the given disk
func
(
mounter
*
SafeFormatAndMount
)
formatAndMount
(
source
string
,
target
string
,
fstype
string
,
options
[]
string
)
error
{
readOnly
:=
false
for
_
,
option
:=
range
options
{
if
option
==
"ro"
{
readOnly
=
true
break
}
}
options
=
append
(
options
,
"defaults"
)
// Run fsck on the disk to fix repairable issues
glog
.
V
(
4
)
.
Infof
(
"Checking for issues with fsck on disk: %s"
,
source
)
args
:=
[]
string
{
"-a"
,
source
}
out
,
err
:=
mounter
.
Exec
.
Run
(
"fsck"
,
args
...
)
if
err
!=
nil
{
ee
,
isExitError
:=
err
.
(
utilexec
.
ExitError
)
switch
{
case
err
==
utilexec
.
ErrExecutableNotFound
:
glog
.
Warningf
(
"'fsck' not found on system; continuing mount without running 'fsck'."
)
case
isExitError
&&
ee
.
ExitStatus
()
==
fsckErrorsCorrected
:
glog
.
Infof
(
"Device %s has errors which were corrected by fsck."
,
source
)
case
isExitError
&&
ee
.
ExitStatus
()
==
fsckErrorsUncorrected
:
return
fmt
.
Errorf
(
"'fsck' found errors on device %s but could not correct them: %s."
,
source
,
string
(
out
))
case
isExitError
&&
ee
.
ExitStatus
()
>
fsckErrorsUncorrected
:
glog
.
Infof
(
"`fsck` error %s"
,
string
(
out
))
if
!
readOnly
{
// Run fsck on the disk to fix repairable issues, only do this for volumes requested as rw.
glog
.
V
(
4
)
.
Infof
(
"Checking for issues with fsck on disk: %s"
,
source
)
args
:=
[]
string
{
"-a"
,
source
}
out
,
err
:=
mounter
.
Exec
.
Run
(
"fsck"
,
args
...
)
if
err
!=
nil
{
ee
,
isExitError
:=
err
.
(
utilexec
.
ExitError
)
switch
{
case
err
==
utilexec
.
ErrExecutableNotFound
:
glog
.
Warningf
(
"'fsck' not found on system; continuing mount without running 'fsck'."
)
case
isExitError
&&
ee
.
ExitStatus
()
==
fsckErrorsCorrected
:
glog
.
Infof
(
"Device %s has errors which were corrected by fsck."
,
source
)
case
isExitError
&&
ee
.
ExitStatus
()
==
fsckErrorsUncorrected
:
return
fmt
.
Errorf
(
"'fsck' found errors on device %s but could not correct them: %s."
,
source
,
string
(
out
))
case
isExitError
&&
ee
.
ExitStatus
()
>
fsckErrorsUncorrected
:
glog
.
Infof
(
"`fsck` error %s"
,
string
(
out
))
}
}
}
...
...
@@ -503,8 +514,13 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string,
return
err
}
if
existingFormat
==
""
{
if
readOnly
{
// Don't attempt to format if mounting as readonly, return an error to reflect this.
return
errors
.
New
(
"failed to mount unformatted volume as read only"
)
}
// Disk is unformatted so format it.
args
=
[]
string
{
source
}
args
:
=
[]
string
{
source
}
// Use 'ext4' as the default
if
len
(
fstype
)
==
0
{
fstype
=
"ext4"
...
...
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