mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #16942 from swagiaal/distinguish-format-and-mount
Auto commit by PR queue bot
This commit is contained in:
commit
13b0fd3cda
@ -49,16 +49,20 @@ type MountPoint struct {
|
|||||||
Pass int
|
Pass int
|
||||||
}
|
}
|
||||||
|
|
||||||
// SafeFormatAndMount probes a device to see if it is formatted. If
|
// SafeFormatAndMount probes a device to see if it is formatted.
|
||||||
// so it mounts it otherwise it formats it and mounts it
|
// 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 {
|
type SafeFormatAndMount struct {
|
||||||
Interface
|
Interface
|
||||||
Runner exec.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
|
// FormatAndMount formats the given disk, if needed, and mounts it.
|
||||||
// it will format the disk first then mount it.
|
// That is if the disk is not formatted and it is not being mounted as
|
||||||
func (mounter *SafeFormatAndMount) Mount(source string, target string, fstype string, options []string) error {
|
// 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.
|
// Don't attempt to format if mounting as readonly. Go straight to mounting.
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if option == "ro" {
|
if option == "ro" {
|
||||||
|
@ -156,7 +156,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
|
|
||||||
device := "/dev/foo"
|
device := "/dev/foo"
|
||||||
dest := "/mnt/bar"
|
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 test.expectedError == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected non-error: %v", err)
|
t.Errorf("unexpected non-error: %v", err)
|
||||||
|
@ -172,7 +172,7 @@ type awsElasticBlockStoreBuilder struct {
|
|||||||
// Specifies whether the disk will be attached as read-only.
|
// Specifies whether the disk will be attached as read-only.
|
||||||
readOnly bool
|
readOnly bool
|
||||||
// diskMounter provides the interface that is used to mount the actual block device.
|
// diskMounter provides the interface that is used to mount the actual block device.
|
||||||
diskMounter mount.Interface
|
diskMounter *mount.SafeFormatAndMount
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.Builder = &awsElasticBlockStoreBuilder{}
|
var _ volume.Builder = &awsElasticBlockStoreBuilder{}
|
||||||
|
@ -74,7 +74,7 @@ func (util *AWSDiskUtil) AttachAndMountDisk(b *awsElasticBlockStoreBuilder, glob
|
|||||||
options = append(options, "ro")
|
options = append(options, "ro")
|
||||||
}
|
}
|
||||||
if notMnt {
|
if notMnt {
|
||||||
err = b.diskMounter.Mount(devicePath, globalPDPath, b.fsType, options)
|
err = b.diskMounter.FormatAndMount(devicePath, globalPDPath, b.fsType, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(globalPDPath)
|
os.Remove(globalPDPath)
|
||||||
return err
|
return err
|
||||||
|
@ -107,11 +107,11 @@ func (plugin *fcPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UID,
|
|||||||
wwns: fc.TargetWWNs,
|
wwns: fc.TargetWWNs,
|
||||||
lun: lun,
|
lun: lun,
|
||||||
manager: manager,
|
manager: manager,
|
||||||
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
|
|
||||||
io: &osIOHandler{},
|
io: &osIOHandler{},
|
||||||
plugin: plugin},
|
plugin: plugin},
|
||||||
fsType: fc.FSType,
|
fsType: fc.FSType,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
|
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
|
||||||
}, nil
|
}, 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) {
|
func (plugin *fcPlugin) newCleanerInternal(volName string, podUID types.UID, manager diskManager, mounter mount.Interface) (volume.Cleaner, error) {
|
||||||
return &fcDiskCleaner{&fcDisk{
|
return &fcDiskCleaner{
|
||||||
podUID: podUID,
|
fcDisk: &fcDisk{
|
||||||
volName: volName,
|
podUID: podUID,
|
||||||
manager: manager,
|
volName: volName,
|
||||||
|
manager: manager,
|
||||||
|
plugin: plugin,
|
||||||
|
io: &osIOHandler{},
|
||||||
|
},
|
||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
plugin: plugin,
|
}, nil
|
||||||
io: &osIOHandler{},
|
|
||||||
}}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *fcPlugin) execCommand(command string, args []string) ([]byte, error) {
|
func (plugin *fcPlugin) execCommand(command string, args []string) ([]byte, error) {
|
||||||
@ -143,7 +145,6 @@ type fcDisk struct {
|
|||||||
wwns []string
|
wwns []string
|
||||||
lun string
|
lun string
|
||||||
plugin *fcPlugin
|
plugin *fcPlugin
|
||||||
mounter mount.Interface
|
|
||||||
// Utility interface that provides API calls to the provider to attach/detach disks.
|
// Utility interface that provides API calls to the provider to attach/detach disks.
|
||||||
manager diskManager
|
manager diskManager
|
||||||
// io handler interface
|
// io handler interface
|
||||||
@ -160,6 +161,7 @@ type fcDiskBuilder struct {
|
|||||||
*fcDisk
|
*fcDisk
|
||||||
readOnly bool
|
readOnly bool
|
||||||
fsType string
|
fsType string
|
||||||
|
mounter *mount.SafeFormatAndMount
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.Builder = &fcDiskBuilder{}
|
var _ volume.Builder = &fcDiskBuilder{}
|
||||||
@ -187,6 +189,7 @@ func (b *fcDiskBuilder) SetUpAt(dir string) error {
|
|||||||
|
|
||||||
type fcDiskCleaner struct {
|
type fcDiskCleaner struct {
|
||||||
*fcDisk
|
*fcDisk
|
||||||
|
mounter mount.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.Cleaner = &fcDiskCleaner{}
|
var _ volume.Cleaner = &fcDiskCleaner{}
|
||||||
|
@ -184,7 +184,7 @@ func (util *FCUtil) AttachDisk(b fcDiskBuilder) error {
|
|||||||
return fmt.Errorf("fc: failed to mkdir %s, error", globalPDPath)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("fc: failed to mount fc volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
|
return fmt.Errorf("fc: failed to mount fc volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ type gcePersistentDiskBuilder struct {
|
|||||||
// Specifies whether the disk will be attached as read-only.
|
// Specifies whether the disk will be attached as read-only.
|
||||||
readOnly bool
|
readOnly bool
|
||||||
// diskMounter provides the interface that is used to mount the actual block device.
|
// diskMounter provides the interface that is used to mount the actual block device.
|
||||||
diskMounter mount.Interface
|
diskMounter *mount.SafeFormatAndMount
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.Builder = &gcePersistentDiskBuilder{}
|
var _ volume.Builder = &gcePersistentDiskBuilder{}
|
||||||
|
@ -90,7 +90,7 @@ func (diskUtil *GCEDiskUtil) AttachAndMountDisk(b *gcePersistentDiskBuilder, glo
|
|||||||
options = append(options, "ro")
|
options = append(options, "ro")
|
||||||
}
|
}
|
||||||
if notMnt {
|
if notMnt {
|
||||||
err = b.diskMounter.Mount(devicePath, globalPDPath, b.fsType, options)
|
err = b.diskMounter.FormatAndMount(devicePath, globalPDPath, b.fsType, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Remove(globalPDPath)
|
os.Remove(globalPDPath)
|
||||||
return err
|
return err
|
||||||
|
@ -105,10 +105,10 @@ func (plugin *iscsiPlugin) newBuilderInternal(spec *volume.Spec, podUID types.UI
|
|||||||
iqn: iscsi.IQN,
|
iqn: iscsi.IQN,
|
||||||
lun: lun,
|
lun: lun,
|
||||||
manager: manager,
|
manager: manager,
|
||||||
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
|
|
||||||
plugin: plugin},
|
plugin: plugin},
|
||||||
fsType: iscsi.FSType,
|
fsType: iscsi.FSType,
|
||||||
readOnly: readOnly,
|
readOnly: readOnly,
|
||||||
|
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
|
||||||
}, nil
|
}, 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) {
|
func (plugin *iscsiPlugin) newCleanerInternal(volName string, podUID types.UID, manager diskManager, mounter mount.Interface) (volume.Cleaner, error) {
|
||||||
return &iscsiDiskCleaner{&iscsiDisk{
|
return &iscsiDiskCleaner{
|
||||||
podUID: podUID,
|
iscsiDisk: &iscsiDisk{
|
||||||
volName: volName,
|
podUID: podUID,
|
||||||
manager: manager,
|
volName: volName,
|
||||||
|
manager: manager,
|
||||||
|
plugin: plugin,
|
||||||
|
},
|
||||||
mounter: mounter,
|
mounter: mounter,
|
||||||
plugin: plugin,
|
}, nil
|
||||||
}}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *iscsiPlugin) execCommand(command string, args []string) ([]byte, error) {
|
func (plugin *iscsiPlugin) execCommand(command string, args []string) ([]byte, error) {
|
||||||
@ -139,7 +141,6 @@ type iscsiDisk struct {
|
|||||||
iqn string
|
iqn string
|
||||||
lun string
|
lun string
|
||||||
plugin *iscsiPlugin
|
plugin *iscsiPlugin
|
||||||
mounter mount.Interface
|
|
||||||
// Utility interface that provides API calls to the provider to attach/detach disks.
|
// Utility interface that provides API calls to the provider to attach/detach disks.
|
||||||
manager diskManager
|
manager diskManager
|
||||||
}
|
}
|
||||||
@ -154,6 +155,7 @@ type iscsiDiskBuilder struct {
|
|||||||
*iscsiDisk
|
*iscsiDisk
|
||||||
readOnly bool
|
readOnly bool
|
||||||
fsType string
|
fsType string
|
||||||
|
mounter *mount.SafeFormatAndMount
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.Builder = &iscsiDiskBuilder{}
|
var _ volume.Builder = &iscsiDiskBuilder{}
|
||||||
@ -182,6 +184,7 @@ func (b *iscsiDiskBuilder) SetUpAt(dir string) error {
|
|||||||
|
|
||||||
type iscsiDiskCleaner struct {
|
type iscsiDiskCleaner struct {
|
||||||
*iscsiDisk
|
*iscsiDisk
|
||||||
|
mounter mount.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ volume.Cleaner = &iscsiDiskCleaner{}
|
var _ volume.Cleaner = &iscsiDiskCleaner{}
|
||||||
|
@ -113,7 +113,7 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskBuilder) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = b.mounter.Mount(devicePath, globalPDPath, b.fsType, nil)
|
err = b.mounter.FormatAndMount(devicePath, globalPDPath, b.fsType, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("iscsi: failed to mount iscsi volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
|
glog.Errorf("iscsi: failed to mount iscsi volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ func (plugin *rbdPlugin) newCleanerInternal(volName string, podUID types.UID, ma
|
|||||||
podUID: podUID,
|
podUID: podUID,
|
||||||
volName: volName,
|
volName: volName,
|
||||||
manager: manager,
|
manager: manager,
|
||||||
mounter: mounter,
|
mounter: &mount.SafeFormatAndMount{mounter, exec.New()},
|
||||||
plugin: plugin,
|
plugin: plugin,
|
||||||
},
|
},
|
||||||
Mon: make([]string, 0),
|
Mon: make([]string, 0),
|
||||||
@ -169,7 +169,7 @@ type rbd struct {
|
|||||||
Image string
|
Image string
|
||||||
ReadOnly bool
|
ReadOnly bool
|
||||||
plugin *rbdPlugin
|
plugin *rbdPlugin
|
||||||
mounter mount.Interface
|
mounter *mount.SafeFormatAndMount
|
||||||
// Utility interface that provides API calls to the provider to attach/detach disks.
|
// Utility interface that provides API calls to the provider to attach/detach disks.
|
||||||
manager diskManager
|
manager diskManager
|
||||||
}
|
}
|
||||||
|
@ -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.
|
// the json file remains invisible during rbd mount and thus won't be removed accidentally.
|
||||||
util.persistRBD(b, globalPDPath)
|
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)
|
err = fmt.Errorf("rbd: failed to mount rbd volume %s [%s] to %s, error %v", devicePath, b.fsType, globalPDPath, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user