Skip to content

Commit

Permalink
Changes to handle NodeExpandVolume() API correctly for raw-block volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
akankshapanse committed Jan 30, 2023
1 parent c4a4c15 commit 6d6d90b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/csi/service/node.go
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions pkg/csi/service/osutils/linux_os_utils.go
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions pkg/csi/service/osutils/windows_os_utils.go
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions pkg/csi/service/vanilla/controller.go
Expand Up @@ -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,
Expand Down

0 comments on commit 6d6d90b

Please sign in to comment.