Skip to content

Commit

Permalink
fix(expand): expand volume over maximum size
Browse files Browse the repository at this point in the history
Get the storage class of the pvc to check if the new volume size is
bigger than the maximum size of the file system in the storage
class.

File system "ext4": 16TiB
File system "xfs":   8EiB

Ref: 7423

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz authored and David Ko committed Dec 28, 2023
1 parent a09d8e5 commit 9cb537d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions controller/node_controller.go
Expand Up @@ -720,7 +720,7 @@ func (nc *NodeController) syncDiskStatus(node *longhorn.Node, collectedDataInfo

for _, diskInfoMap := range readyDiskInfoMap {
nc.updateReadyDiskStatusReadyCondition(node, diskInfoMap)
nc.updateReadyDiskStatusFileSystemType(node, diskInfoMap)
nc.updateDiskStatusFileSystemType(node, diskInfoMap)
}

return nc.updateDiskStatusSchedulableCondition(node)
Expand Down Expand Up @@ -843,7 +843,7 @@ func (nc *NodeController) updateReadyDiskStatusReadyCondition(node *longhorn.Nod
}
}

func (nc *NodeController) updateReadyDiskStatusFileSystemType(node *longhorn.Node, diskInfoMap map[string]*monitor.CollectedDiskInfo) {
func (nc *NodeController) updateDiskStatusFileSystemType(node *longhorn.Node, diskInfoMap map[string]*monitor.CollectedDiskInfo) {
diskStatusMap := node.Status.DiskStatus
for diskName, info := range diskInfoMap {
diskStatus := diskStatusMap[diskName]
Expand Down
12 changes: 12 additions & 0 deletions datastore/longhorn.go
Expand Up @@ -4881,3 +4881,15 @@ func IsBackendStoreDriverV1(backendstoreDriver longhorn.BackendStoreDriverType)
func IsBackendStoreDriverV2(backendstoreDriver longhorn.BackendStoreDriverType) bool {
return backendstoreDriver == longhorn.BackendStoreDriverTypeV2
}

// IsSupportedVolumeSize returns turn if the v1 volume size is supported by the given fsType file system.
func IsSupportedVolumeSize(backendstoreDriver longhorn.BackendStoreDriverType, fsType string, volumeSize int64) bool {
// TODO: check the logical volume maximum size limit
if IsBackendStoreDriverV1(backendstoreDriver) {
// unix.Statfs can not differentiate the ext2/ext3/ext4 file systems.
if (strings.HasPrefix(fsType, "ext") && volumeSize >= util.MaxExt4VolumeSize) || (fsType == "xfs" && volumeSize >= util.MaxXfsVolumeSize) {
return false
}
}
return true
}
5 changes: 1 addition & 4 deletions scheduler/replica_scheduler.go
Expand Up @@ -2,7 +2,6 @@ package scheduler

import (
"fmt"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -321,9 +320,7 @@ func (rcs *ReplicaScheduler) filterNodeDisksForReplica(node *longhorn.Node, disk
continue
}

volumeSize := volume.Spec.Size
// unix.Statfs can not differentiate the ext2/ext3/ext4 file systems.
if (strings.HasPrefix(diskStatus.FSType, "ext") && volumeSize >= util.MaxExt4VolumeSize) || (diskStatus.FSType == "xfs" && volumeSize >= util.MaxXfsVolumeSize) {
if !datastore.IsSupportedVolumeSize(volume.Spec.BackendStoreDriver, diskStatus.FSType, volume.Spec.Size) {
logrus.Debugf("Volume %v size %v is not compatible with the file system %v of the disk %v", volume.Name, volume.Spec.Size, diskStatus.Type, diskName)
continue
}
Expand Down
17 changes: 17 additions & 0 deletions webhook/resources/volume/validator.go
Expand Up @@ -341,6 +341,23 @@ func (v *volumeValidator) validateExpansionSize(oldVolume *longhorn.Volume, newV
return fmt.Errorf("shrinking volume %v size from %v to %v is not supported", newVolume.Name, oldSize, newSize)
}

replicas, err := v.ds.ListVolumeReplicasRO(newVolume.Name)
if err != nil {
return err
}
for _, replica := range replicas {
diskUUID := replica.Spec.DiskID
node, diskName, err := v.ds.GetReadyDiskNode(diskUUID)
if err != nil {
return err
}
diskStatus := node.Status.DiskStatus[diskName]
if !datastore.IsSupportedVolumeSize(replica.Spec.BackendStoreDriver, diskStatus.FSType, newSize) {
return fmt.Errorf("file system %s does not support volume size %v", diskStatus.Type, newSize)
}
break
}

newKubernetesStatus := &newVolume.Status.KubernetesStatus
namespace := newKubernetesStatus.Namespace
pvcName := newKubernetesStatus.PVCName
Expand Down

0 comments on commit 9cb537d

Please sign in to comment.