diff --git a/pkg/iscsi/v1alpha1/iscsi_util.go b/pkg/iscsi/v1alpha1/iscsi_util.go index 96241ece8..57f99c29b 100644 --- a/pkg/iscsi/v1alpha1/iscsi_util.go +++ b/pkg/iscsi/v1alpha1/iscsi_util.go @@ -698,9 +698,9 @@ func (util *ISCSIUtil) ReScan() error { return nil } -// ReSizeFS can be used to run a resize command on the filesystem to expand the -// filesystem to the actual size of the device -func (util *ISCSIUtil) ReSizeFS(path string) error { +// ResizeExt4 can be used to run a resize command on the ext4 filesystem +// to expand the filesystem to the actual size of the device +func (util *ISCSIUtil) ResizeExt4(path string) error { b := &iscsiDiskMounter{ exec: mount.NewOsExec(), } @@ -711,3 +711,17 @@ func (util *ISCSIUtil) ReSizeFS(path string) error { } return nil } + +// ResizeXFS can be used to run a resize command on the xfs filesystem +// to expand the filesystem to the actual size of the device +func (util *ISCSIUtil) ResizeXFS(path string) error { + b := &iscsiDiskMounter{ + exec: mount.NewOsExec(), + } + out, err := b.exec.Run("xfs_growfs", path) + if err != nil { + glog.Errorf("iscsi: resize failed error: %s", string(out)) + return err + } + return nil +} diff --git a/pkg/iscsi/v1alpha1/mount.go b/pkg/iscsi/v1alpha1/mount.go index 48d9cdf3f..1e6fb9197 100644 --- a/pkg/iscsi/v1alpha1/mount.go +++ b/pkg/iscsi/v1alpha1/mount.go @@ -37,7 +37,8 @@ func Unmount(path string) error { // ResizeVolume rescans the iSCSI session and runs the resize to filesystem // command on that particular device -func ResizeVolume(volumePath string) error { +func ResizeVolume(volumePath string, fsType string) error { + var err error mounter := mount.New("") list, _ := mounter.List() for _, mpt := range list { @@ -46,7 +47,13 @@ func ResizeVolume(volumePath string) error { if err := util.ReScan(); err != nil { return err } - if err := util.ReSizeFS(mpt.Device); err != nil { + switch fsType { + case "ext4": + err = util.ResizeExt4(mpt.Device) + case "xfs": + err = util.ResizeXFS(volumePath) + } + if err != nil { return err } break diff --git a/pkg/service/v1alpha1/controller_utils.go b/pkg/service/v1alpha1/controller_utils.go index b27932d76..49c94eb96 100644 --- a/pkg/service/v1alpha1/controller_utils.go +++ b/pkg/service/v1alpha1/controller_utils.go @@ -138,6 +138,18 @@ func (cs *controller) validateVolumeCreateReq(req *csi.CreateVolumeRequest) erro "failed to handle create volume request: missing volume capabilities", ) } + for _, volcap := range volCapabilities { + mount := volcap.GetMount() + if mount != nil { + if !isValidFStype(mount.GetFsType()) { + return status.Errorf( + codes.InvalidArgument, + "failed to handle create volume request, invalid fsType : %s", + req.GetParameters()["fsType"], + ) + } + } + } return nil } diff --git a/pkg/service/v1alpha1/node.go b/pkg/service/v1alpha1/node.go index 02bcd6d63..1ec8cdcb7 100644 --- a/pkg/service/v1alpha1/node.go +++ b/pkg/service/v1alpha1/node.go @@ -336,7 +336,12 @@ func (ns *node) NodeExpandVolume( } defer removeVolumeFromTransitionList(volumeID) - if err = iscsiutils.ResizeVolume(req.GetVolumePath()); err != nil { + vol, err := utils.GetCSIVolume(volumeID + "-" + utils.NodeIDENV) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + + if err = iscsiutils.ResizeVolume(req.GetVolumePath(), vol.Spec.Volume.FSType); err != nil { return nil, status.Errorf( codes.Internal, "failed to handle NodeExpandVolumeRequest for %s, {%s}", diff --git a/pkg/service/v1alpha1/utils.go b/pkg/service/v1alpha1/utils.go index 3fae781f1..460ef09eb 100644 --- a/pkg/service/v1alpha1/utils.go +++ b/pkg/service/v1alpha1/utils.go @@ -26,9 +26,18 @@ const ( ) var ( - ValidFSTypes = []string{FSTypeExt2, FSTypeExt3, FSTypeExt4, FSTypeXfs} + ValidFSTypes = []string{FSTypeExt4, FSTypeXfs} ) +func isValidFStype(fstype string) bool { + for _, fs := range ValidFSTypes { + if fs == fstype { + return true + } + } + return false +} + func removeVolumeFromTransitionList(volumeID string) { utils.TransitionVolListLock.Lock() defer utils.TransitionVolListLock.Unlock()