Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openstack: Use common SafeFormatAndMount() for mounting. #17650

Merged
merged 1 commit into from
Jan 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,9 +624,8 @@ type RBDVolumeSource struct {
type CinderVolumeSource struct {
// Unique id of the volume used to identify the cinder volume
VolumeID string `json:"volumeID"`
// Required: Filesystem type to mount.
// Filesystem type to mount.
// Must be a filesystem type supported by the host operating system.
// Only ext3 and ext4 are allowed
FSType string `json:"fsType,omitempty"`
// Optional: Defaults to false (read/write). ReadOnly here will force
// the ReadOnly setting in VolumeMounts.
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ func validateCinderVolumeSource(cd *api.CinderVolumeSource, fldPath *field.Path)
if len(cd.VolumeID) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("volumeID"), ""))
}
if len(cd.FSType) == 0 || (cd.FSType != "ext3" && cd.FSType != "ext4") {
if len(cd.FSType) == 0 {
allErrs = append(allErrs, field.Required(fldPath.Child("fsType"), ""))
}
return allErrs
Expand Down
4 changes: 2 additions & 2 deletions pkg/volume/cinder/cinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (plugin *cinderPlugin) newBuilderInternal(spec *volume.Spec, podUID types.U
},
fsType: fsType,
readOnly: readOnly,
blockDeviceMounter: &cinderSafeFormatAndMount{mounter, exec.New()}}, nil
blockDeviceMounter: &mount.SafeFormatAndMount{mounter, exec.New()}}, nil
}

func (plugin *cinderPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cleaner, error) {
Expand Down Expand Up @@ -181,7 +181,7 @@ type cinderVolumeBuilder struct {
*cinderVolume
fsType string
readOnly bool
blockDeviceMounter mount.Interface
blockDeviceMounter *mount.SafeFormatAndMount
}

// cinderPersistentDisk volumes are disk resources provided by C3
Expand Down
71 changes: 1 addition & 70 deletions pkg/volume/cinder/cinder_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cinder

import (
"errors"
"fmt"
"io/ioutil"
"os"
"path"
Expand All @@ -27,7 +26,6 @@ import (

"github.com/golang/glog"
"k8s.io/kubernetes/pkg/util/exec"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume"
)

Expand Down Expand Up @@ -69,7 +67,6 @@ func (util *CinderDiskUtil) AttachDisk(b *cinderVolumeBuilder, globalPDPath stri
}
time.Sleep(time.Second * 6)
}

notmnt, err := b.mounter.IsLikelyNotMountPoint(globalPDPath)
if err != nil {
if os.IsNotExist(err) {
Expand All @@ -82,7 +79,7 @@ func (util *CinderDiskUtil) AttachDisk(b *cinderVolumeBuilder, globalPDPath stri
}
}
if notmnt {
err = b.blockDeviceMounter.Mount(devicePath, globalPDPath, b.fsType, options)
err = b.blockDeviceMounter.FormatAndMount(devicePath, globalPDPath, b.fsType, options)
if err != nil {
os.Remove(globalPDPath)
return err
Expand Down Expand Up @@ -162,72 +159,6 @@ func (util *CinderDiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID s
return name, volSizeGB, nil
}

type cinderSafeFormatAndMount struct {
mount.Interface
runner exec.Interface
}

/*
The functions below depend on the following executables; This will have to be ported to more generic implementations
/bin/lsblk
/sbin/mkfs.ext3 or /sbin/mkfs.ext4
/usr/bin/udevadm
*/
func (diskmounter *cinderSafeFormatAndMount) Mount(device string, target string, fstype string, options []string) error {
fmtRequired, err := isFormatRequired(device, fstype, diskmounter)
if err != nil {
glog.Warningf("Failed to determine if formating is required: %v\n", err)
//return err
}
if fmtRequired {
glog.V(2).Infof("Formatting of the vol required")
if _, err := formatVolume(device, fstype, diskmounter); err != nil {
glog.Warningf("Failed to format volume: %v\n", err)
return err
}
}
return diskmounter.Interface.Mount(device, target, fstype, options)
}

func isFormatRequired(devicePath string, fstype string, exec *cinderSafeFormatAndMount) (bool, error) {
args := []string{"-f", devicePath}
glog.V(4).Infof("exec-ing: /bin/lsblk %v\n", args)
cmd := exec.runner.Command("/bin/lsblk", args...)
dataOut, err := cmd.CombinedOutput()
if err != nil {
glog.Warningf("error running /bin/lsblk\n%s", string(dataOut))
return false, err
}
if len(string(dataOut)) > 0 {
if strings.Contains(string(dataOut), fstype) {
return false, nil
} else {
return true, nil
}
} else {
glog.Warningf("Failed to get any response from /bin/lsblk")
return false, errors.New("Failed to get reponse from /bin/lsblk")
}
glog.Warningf("Unknown error occured executing /bin/lsblk")
return false, errors.New("Unknown error occured executing /bin/lsblk")
}

func formatVolume(devicePath string, fstype string, exec *cinderSafeFormatAndMount) (bool, error) {
if "ext4" != fstype && "ext3" != fstype {
glog.Warningf("Unsupported format type: %q\n", fstype)
return false, errors.New(fmt.Sprint("Unsupported format type: %q\n", fstype))
}
args := []string{devicePath}
cmd := exec.runner.Command(fmt.Sprintf("/sbin/mkfs.%s", fstype), args...)
dataOut, err := cmd.CombinedOutput()
if err != nil {
glog.Warningf("error running /sbin/mkfs for fstype: %q \n%s", fstype, string(dataOut))
return false, err
}
glog.V(2).Infof("Successfully formated device: %q with fstype %q; output:\n %q\n,", devicePath, fstype, string(dataOut))
return true, err
}

func probeAttachedVolume() error {
executor := exec.New()
args := []string{"trigger"}
Expand Down
82 changes: 0 additions & 82 deletions pkg/volume/cinder/cinder_util_test.go

This file was deleted.