Skip to content

Commit

Permalink
fix(resize): Add command to resize xfs volumes (#61)
Browse files Browse the repository at this point in the history
Signed-off-by: Payes <payes.anand@mayadata.io>
payes authored and prateekpandey14 committed Dec 11, 2019
1 parent 2653bac commit a4cded0
Showing 5 changed files with 54 additions and 7 deletions.
20 changes: 17 additions & 3 deletions pkg/iscsi/v1alpha1/iscsi_util.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 9 additions & 2 deletions pkg/iscsi/v1alpha1/mount.go
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions pkg/service/v1alpha1/controller_utils.go
Original file line number Diff line number Diff line change
@@ -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
}

7 changes: 6 additions & 1 deletion pkg/service/v1alpha1/node.go
Original file line number Diff line number Diff line change
@@ -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}",
11 changes: 10 additions & 1 deletion pkg/service/v1alpha1/utils.go
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a4cded0

Please sign in to comment.