Skip to content

Commit

Permalink
csi/controller: make the volme expand really work
Browse files Browse the repository at this point in the history
    - Execute lvextend multiple times will get EIO if
      size not change. We need to add pre-check for
      avoiding that.

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
  • Loading branch information
Vicente-Cheng committed Jul 11, 2024
1 parent 59b1b46 commit f2f2def
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkg/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,18 +554,36 @@ func extendLVS(name string, size uint64, isBlock bool) (string, error) {
return "", fmt.Errorf("logical volume %s does not exist", name)
}

// TODO: check available capacity, fail if request doesn't fit

executor := cmd.NewExecutor()
args := []string{"-L", fmt.Sprintf("%db", size)}
targetLVName := fmt.Sprintf("%s/%s", vgName, name)
// check current lv size
args := []string{"--noheadings", "--unit", "b", "-o", "Size"}
args = append(args, targetLVName)
out, err := executor.Execute("lvs", args)
if err != nil {
return "", fmt.Errorf("unable to get size of lv %s: %w", name, err)
}
lvSizeStr := strings.TrimSpace(out)
lvSizeStr = strings.TrimSuffix(lvSizeStr, "B")
klog.Infof("current size of lv %s is %s", name, lvSizeStr)
lvSize, err := strconv.ParseUint(lvSizeStr, 10, 64)
if err != nil {
return "", fmt.Errorf("unable to parse size of lv %s: %w", name, err)
}
if lvSize == size {
klog.Infof("logical volume %s already has the requested size %d", name, size)
return "", nil
}

args = []string{"-L", fmt.Sprintf("%db", size)}
if isBlock {
args = append(args, "-n")
} else {
args = append(args, "-r")
}
args = append(args, fmt.Sprintf("%s/%s", vgName, name))
klog.Infof("lvextend %s", args)
out, err := executor.Execute("lvextend", args)
out, err = executor.Execute("lvextend", args)
return out, err
}

Expand Down
1 change: 1 addition & 0 deletions pkg/lvm/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func (ns *nodeServer) NodeGetVolumeStats(ctx context.Context, in *csi.NodeGetVol

func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {

klog.Infof("NodeExpandVolume: %s", req)
// Check arguments
if req.GetCapacityRange() == nil {
return nil, status.Error(codes.InvalidArgument, "Volume capability missing in request")
Expand Down

0 comments on commit f2f2def

Please sign in to comment.