diff --git a/pkg/csi/service/node.go b/pkg/csi/service/node.go index f68d66edee..16c280a549 100644 --- a/pkg/csi/service/node.go +++ b/pkg/csi/service/node.go @@ -528,6 +528,34 @@ func (driver *vsphereCSIDriver) NodeExpandVolume( } } + // Check the volume capability and handle accordingly. + // NOTE: VolumeCapability is optional field, if specified, use it for validation. + // Otherwise, use volume_path to determine access_type and handle accordingly. + volCap := req.GetVolumeCapability() + if volCap != nil { + caps := []*csi.VolumeCapability{volCap} + if err := common.IsValidVolumeCapabilities(ctx, caps); err != nil { + return nil, logger.LogNewErrorCodef(log, codes.InvalidArgument, + "volume capability not supported. Err: %+v", err) + } + // No need to expand file system for raw block volumes, hence return. + if volCap.GetBlock() != nil { + log.Infof("NodeExpandVolume: called for raw block volume %s, ignoring..", volumeID) + return &csi.NodeExpandVolumeResponse{}, nil + } + } else { + isBlock, err := driver.osUtils.IsBlockDevice(ctx, volumePath) + if err != nil { + return nil, logger.LogNewErrorCodef(log, codes.Internal, "failed to determine device path for volpath [%v]: %v", volumePath, err) + } + if isBlock { + log.Infof("NodeExpandVolume: called for raw block volume %s at volumePath %s, ignoring..", volumeID, volumePath) + return &csi.NodeExpandVolumeResponse{ + CapacityBytes: int64(units.FileSize(reqVolSizeMB * common.MbInBytes)), + }, nil + } + } + // Resize file system. if err = driver.osUtils.ResizeVolume(ctx, dev.RealDev, volumePath, reqVolSizeBytes); err != nil { return nil, logger.LogNewErrorCodef(log, codes.Internal, diff --git a/pkg/csi/service/osutils/linux_os_utils.go b/pkg/csi/service/osutils/linux_os_utils.go index 10f96b0ab9..60d353ff3e 100644 --- a/pkg/csi/service/osutils/linux_os_utils.go +++ b/pkg/csi/service/osutils/linux_os_utils.go @@ -1097,3 +1097,14 @@ func unescape(ctx context.Context, in string) string { } return string(out) } + +// Check if device at given path is block device or not +func (osUtils *OsUtils) IsBlockDevice(ctx context.Context, volumePath string) (bool, error) { + log := logger.GetLogger(ctx) + + deviceInfo, err := os.Stat(volumePath) + if err != nil { + return false, logger.LogNewErrorf(log, "IsBlockDevice: could not get device info for path %s", volumePath) + } + return deviceInfo.Mode()&os.ModeDevice == os.ModeDevice, nil +} diff --git a/pkg/csi/service/osutils/windows_os_utils.go b/pkg/csi/service/osutils/windows_os_utils.go index 9bd60b3664..1b6e2cd512 100644 --- a/pkg/csi/service/osutils/windows_os_utils.go +++ b/pkg/csi/service/osutils/windows_os_utils.go @@ -511,3 +511,8 @@ func (osUtils *OsUtils) ShouldContinue(ctx context.Context) { } return } + +// Check if device at given path is block device or not +func (osUtils *OsUtils) IsBlockDevice(ctx context.Context, volumePath string) (bool, error) { + return false, nil +} diff --git a/pkg/csi/service/vanilla/controller.go b/pkg/csi/service/vanilla/controller.go index 7f4de51d78..d99538a23d 100644 --- a/pkg/csi/service/vanilla/controller.go +++ b/pkg/csi/service/vanilla/controller.go @@ -2495,6 +2495,8 @@ func (c *controller) ControllerExpandVolume(ctx context.Context, req *csi.Contro if _, ok := req.GetVolumeCapability().GetAccessType().(*csi.VolumeCapability_Block); ok { nodeExpansionRequired = false } + log.Debugf("ControllerExpandVolumeInternal: returns %v as capacity and %v as NodeExpansionRequired", + int64(units.FileSize(volSizeMB*common.MbInBytes)), nodeExpansionRequired) resp := &csi.ControllerExpandVolumeResponse{ CapacityBytes: int64(units.FileSize(volSizeMB * common.MbInBytes)), NodeExpansionRequired: nodeExpansionRequired,