Merge pull request #16942 from swagiaal/distinguish-format-and-mount

Auto commit by PR queue bot
pull/6/head
k8s-merge-robot 2015-12-03 10:51:26 -08:00
commit 13b0fd3cda
12 changed files with 42 additions and 32 deletions

View File

@ -49,16 +49,20 @@ type MountPoint struct {
Pass int
}
// SafeFormatAndMount probes a device to see if it is formatted. If
// so it mounts it otherwise it formats it and mounts it
// SafeFormatAndMount probes a device to see if it is formatted.
// Namely it checks to see if a file system is present. If so it
// mounts it otherwise the device is formatted first then mounted.
type SafeFormatAndMount struct {
Interface
Runner exec.Interface
}
// Mount mounts the given disk. If the disk is not formatted and the disk is not being mounted as read only
// it will format the disk first then mount it.
func (mounter *SafeFormatAndMount) Mount(source string, target string, fstype string, options []string) error {
// FormatAndMount formats the given disk, if needed, and mounts it.
// That is if the disk is not formatted and it is not being mounted as
// read-only it will format it first then mount it. Otherwise, if the
// 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" {

View File

@ -156,7 +156,7 @@ func TestSafeFormatAndMount(t *testing.T) {
device := "/dev/foo"
dest := "/mnt/bar"
err := mounter.Mount(device, dest, test.fstype, test.mountOptions)
err := mounter.FormatAndMount(device, dest, test.fstype, test.mountOptions)
if test.expectedError == nil {
if err != nil {
t.Errorf("unexpected non-error: %v", err)

View File

@ -172,7 +172,7 @@ type awsElasticBlockStoreBuilder struct {
// Specifies whether the disk will be attached as read-only.
readOnly bool
// diskMounter provides the interface that is used to mount the actual block device.
diskMounter mount.Interface
diskMounter *mount.SafeFormatAndMount
}
var _ volume.Builder = &awsElasticBlockStoreBuilder{}

View File

@ -74,7 +74,7 @@ func (util *AWSDiskUtil) AttachAndMountDisk(b *awsElasticBlockStoreBuilder, glob
options = append(options, "ro")
}
if notMnt {
err = b.diskMounter.Mount(devicePath, globalPDPath, b.fsType, options)
err = b.diskMounter.FormatAndMount(devicePath, globalPDPath, b.fsType, options)
if err != nil {
os.Remove(globalPDPath)
return err

View File

@ -107,11 +107,11 @@ func (plugin *fcPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID,
wwns: fc.TargetWWNs,
lun: lun,
manager: manager,
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
io: &osIOHandler{},
plugin: plugin},
fsType: fc.FSType,
readOnly: readOnly,
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
}, nil
}
@ -121,14 +121,16 @@ func (plugin *fcPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cle
}
func (plugin *fcPlugin) newCleanerInternal(volName string, podUID types.UID, manager diskManager, mounter mount.Interface) (volume.Cleaner, error) {
return &fcDiskCleaner{&fcDisk{
podUID: podUID,
volName: volName,
manager: manager,
return &fcDiskCleaner{
fcDisk: &fcDisk{
podUID: podUID,
volName: volName,
manager: manager,
plugin: plugin,
io: &osIOHandler{},
},
mounter: mounter,
plugin: plugin,
io: &osIOHandler{},
}}, nil
}, nil
}
func (plugin *fcPlugin) execCommand(command string, args []string) ([]byte, error) {
@ -143,7 +145,6 @@ type fcDisk struct {
wwns []string
lun string
plugin *fcPlugin
mounter mount.Interface
// Utility interface that provides API calls to the provider to attach/detach disks.
manager diskManager
// io handler interface
@ -160,6 +161,7 @@ type fcDiskBuilder struct {
*fcDisk
readOnly bool
fsType string
mounter *mount.SafeFormatAndMount
}
var _ volume.Builder = &fcDiskBuilder{}
@ -187,6 +189,7 @@ func (b *fcDiskBuilder) SetUpAt(dir string) error {
type fcDiskCleaner struct {
*fcDisk
mounter mount.Interface
}
var _ volume.Cleaner = &fcDiskCleaner{}

View File

@ -184,7 +184,7 @@ func (util *FCUtil) AttachDisk(b fcDiskBuilder) error {
return fmt.Errorf("fc: failed to mkdir %s, error", globalPDPath)
}
err = b.mounter.Mount(devicePath, globalPDPath, b.fsType, nil)
err = b.mounter.FormatAndMount(devicePath, globalPDPath, b.fsType, nil)
if err != nil {
return fmt.Errorf("fc: failed to mount fc volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
}

View File

@ -160,7 +160,7 @@ type gcePersistentDiskBuilder struct {
// Specifies whether the disk will be attached as read-only.
readOnly bool
// diskMounter provides the interface that is used to mount the actual block device.
diskMounter mount.Interface
diskMounter *mount.SafeFormatAndMount
}
var _ volume.Builder = &gcePersistentDiskBuilder{}

View File

@ -90,7 +90,7 @@ func (diskUtil *GCEDiskUtil) AttachAndMountDisk(b *gcePersistentDiskBuilder, glo
options = append(options, "ro")
}
if notMnt {
err = b.diskMounter.Mount(devicePath, globalPDPath, b.fsType, options)
err = b.diskMounter.FormatAndMount(devicePath, globalPDPath, b.fsType, options)
if err != nil {
os.Remove(globalPDPath)
return err

View File

@ -105,10 +105,10 @@ func (plugin *iscsiPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UI
iqn: iscsi.IQN,
lun: lun,
manager: manager,
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
plugin: plugin},
fsType: iscsi.FSType,
readOnly: readOnly,
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
}, nil
}
@ -118,13 +118,15 @@ func (plugin *iscsiPlugin) NewCleaner(volName string, podUID types.UID) (volume.
}
func (plugin *iscsiPlugin) newCleanerInternal(volName string, podUID types.UID, manager diskManager, mounter mount.Interface) (volume.Cleaner, error) {
return &iscsiDiskCleaner{&iscsiDisk{
podUID: podUID,
volName: volName,
manager: manager,
return &iscsiDiskCleaner{
iscsiDisk: &iscsiDisk{
podUID: podUID,
volName: volName,
manager: manager,
plugin: plugin,
},
mounter: mounter,
plugin: plugin,
}}, nil
}, nil
}
func (plugin *iscsiPlugin) execCommand(command string, args []string) ([]byte, error) {
@ -139,7 +141,6 @@ type iscsiDisk struct {
iqn string
lun string
plugin *iscsiPlugin
mounter mount.Interface
// Utility interface that provides API calls to the provider to attach/detach disks.
manager diskManager
}
@ -154,6 +155,7 @@ type iscsiDiskBuilder struct {
*iscsiDisk
readOnly bool
fsType string
mounter *mount.SafeFormatAndMount
}
var _ volume.Builder = &iscsiDiskBuilder{}
@ -182,6 +184,7 @@ func (b *iscsiDiskBuilder) SetUpAt(dir string) error {
type iscsiDiskCleaner struct {
*iscsiDisk
mounter mount.Interface
}
var _ volume.Cleaner = &iscsiDiskCleaner{}

View File

@ -113,7 +113,7 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskBuilder) error {
return err
}
err = b.mounter.Mount(devicePath, globalPDPath, b.fsType, nil)
err = b.mounter.FormatAndMount(devicePath, globalPDPath, b.fsType, nil)
if err != nil {
glog.Errorf("iscsi: failed to mount iscsi volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
}

View File

@ -154,7 +154,7 @@ func (plugin *rbdPlugin) newCleanerInternal(volName string, podUID types.UID, ma
podUID: podUID,
volName: volName,
manager: manager,
mounter: mounter,
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
plugin: plugin,
},
Mon: make([]string, 0),
@ -169,7 +169,7 @@ type rbd struct {
Image string
ReadOnly bool
plugin *rbdPlugin
mounter mount.Interface
mounter *mount.SafeFormatAndMount
// Utility interface that provides API calls to the provider to attach/detach disks.
manager diskManager
}

View File

@ -273,7 +273,7 @@ func (util *RBDUtil) AttachDisk(b rbdBuilder) error {
// the json file remains invisible during rbd mount and thus won't be removed accidentally.
util.persistRBD(b, globalPDPath)
if err = b.mounter.Mount(devicePath, globalPDPath, b.fsType, nil); err != nil {
if err = b.mounter.FormatAndMount(devicePath, globalPDPath, b.fsType, nil); err != nil {
err = fmt.Errorf("rbd: failed to mount rbd volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
}
return err