in gce-containers-startup/volumes/volumes.go [314:361]
func (env Env) processGcePersistentDiskVolume(volume *api.GcePersistentDiskVolume, volumeMountWantsReadWrite bool, diskMetadataReadOnlyMap map[string]bool) (VolumeHostPathAndMode, error) {
if volume.FsType != "" && volume.FsType != ext4FsType {
return VolumeHostPathAndMode{}, fmt.Errorf("Unsupported filesystem type: %s", volume.FsType)
}
chosenFsType := ext4FsType
if volume.PdName == "" {
return VolumeHostPathAndMode{}, fmt.Errorf("Empty GCE Persistent Disk name!")
}
attachedReadOnly, diskMetadataFound := diskMetadataReadOnlyMap[volume.PdName]
if !diskMetadataFound {
return VolumeHostPathAndMode{}, fmt.Errorf("Could not determine if the GCE Persistent Disk %s is attached read-only or read-write.", volume.PdName)
}
if attachedReadOnly && volumeMountWantsReadWrite {
return VolumeHostPathAndMode{}, fmt.Errorf("Volume mount requires read-write access, but the GCE Persistent Disk %s is attached read-only.", volume.PdName)
}
devicePath, err := resolveGcePersistentDiskDevicePath(volume.PdName)
if err != nil {
return VolumeHostPathAndMode{}, fmt.Errorf("Could not resolve GCE Persistent Disk device path: %s", err)
}
if volume.Partition > 0 {
devicePath = fmt.Sprintf("%s-part%d", devicePath, volume.Partition)
}
if err := env.checkDeviceReadable(devicePath); err != nil {
return VolumeHostPathAndMode{}, err
}
if err := env.checkDeviceNotMounted(devicePath); err != nil {
return VolumeHostPathAndMode{}, err
}
if !attachedReadOnly {
if err := env.checkFilesystemAndFormatIfNeeded(devicePath, chosenFsType); err != nil {
return VolumeHostPathAndMode{}, err
}
}
mountReadOnly := attachedReadOnly || !volumeMountWantsReadWrite
deviceMountPoint, err := env.createNewMountPath("gce-persistent-disk", volume.PdName)
if err != nil {
return VolumeHostPathAndMode{}, err
}
mnt := newMount(devicePath, deviceMountPoint, chosenFsType, readOnly(mountReadOnly))
if err := env.mountDevice(mnt); err != nil {
return VolumeHostPathAndMode{}, err
}
// Success!
return VolumeHostPathAndMode{deviceMountPoint, mountReadOnly}, nil
}