mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #58912 from mlmhl/volume_mount
Automatic merge from submit-queue (batch tested with PRs 59466, 58912, 59605, 59548). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. return a more human readable error message if mount an unformatted vo… **What this PR does / why we need it**: If an unformatted volume is requested as read only mode, according device mount operation will fail, and the message is verbose and obscure. We should check this scenario and return a more human readable message. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #58911 **Release note**: ```release-note NONE ``` /sig storage
This commit is contained in:
commit
3ee818c259
@ -126,12 +126,6 @@ type SafeFormatAndMount struct {
|
|||||||
// disk is already formatted or it is being mounted as read-only, it
|
// disk is already formatted or it is being mounted as read-only, it
|
||||||
// will be mounted without formatting.
|
// will be mounted without formatting.
|
||||||
func (mounter *SafeFormatAndMount) FormatAndMount(source string, target string, fstype string, options []string) error {
|
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)
|
return mounter.formatAndMount(source, target, fstype, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ limitations under the License.
|
|||||||
package mount
|
package mount
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -472,9 +473,18 @@ func (mounter *Mounter) ExistsPath(pathname string) bool {
|
|||||||
|
|
||||||
// formatAndMount uses unix utils to format and mount the given disk
|
// formatAndMount uses unix utils to format and mount the given disk
|
||||||
func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, fstype string, options []string) error {
|
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")
|
options = append(options, "defaults")
|
||||||
|
|
||||||
// Run fsck on the disk to fix repairable issues
|
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)
|
glog.V(4).Infof("Checking for issues with fsck on disk: %s", source)
|
||||||
args := []string{"-a", source}
|
args := []string{"-a", source}
|
||||||
out, err := mounter.Exec.Run("fsck", args...)
|
out, err := mounter.Exec.Run("fsck", args...)
|
||||||
@ -491,6 +501,7 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string,
|
|||||||
glog.Infof("`fsck` error %s", string(out))
|
glog.Infof("`fsck` error %s", string(out))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Try to mount the disk
|
// Try to mount the disk
|
||||||
glog.V(4).Infof("Attempting to mount disk: %s %s %s", fstype, source, target)
|
glog.V(4).Infof("Attempting to mount disk: %s %s %s", fstype, source, target)
|
||||||
@ -503,8 +514,13 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if existingFormat == "" {
|
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.
|
// Disk is unformatted so format it.
|
||||||
args = []string{source}
|
args := []string{source}
|
||||||
// Use 'ext4' as the default
|
// Use 'ext4' as the default
|
||||||
if len(fstype) == 0 {
|
if len(fstype) == 0 {
|
||||||
fstype = "ext4"
|
fstype = "ext4"
|
||||||
|
Loading…
Reference in New Issue
Block a user