Skip to content

Commit 0a0f703

Browse files
committed
csi/controller: make the volme expand really work
- 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>
1 parent 449062c commit 0a0f703

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

pkg/lvm/lvm.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,18 +554,36 @@ func extendLVS(name string, size uint64, isBlock bool) (string, error) {
554554
return "", fmt.Errorf("logical volume %s does not exist", name)
555555
}
556556

557-
// TODO: check available capacity, fail if request doesn't fit
558-
559557
executor := cmd.NewExecutor()
560-
args := []string{"-L", fmt.Sprintf("%db", size)}
558+
targetLVName := fmt.Sprintf("%s/%s", vgName, name)
559+
// check current lv size
560+
args := []string{"--noheadings", "--unit", "b", "-o", "Size"}
561+
args = append(args, targetLVName)
562+
out, err := executor.Execute("lvs", args)
563+
if err != nil {
564+
return "", fmt.Errorf("unable to get size of lv %s: %w", name, err)
565+
}
566+
lvSizeStr := strings.TrimSpace(out)
567+
lvSizeStr = strings.TrimSuffix(lvSizeStr, "B")
568+
klog.Infof("current size of lv %s is %s", name, lvSizeStr)
569+
lvSize, err := strconv.ParseUint(lvSizeStr, 10, 64)
570+
if err != nil {
571+
return "", fmt.Errorf("unable to parse size of lv %s: %w", name, err)
572+
}
573+
if lvSize == size {
574+
klog.Infof("logical volume %s already has the requested size %d", name, size)
575+
return "", nil
576+
}
577+
578+
args = []string{"-L", fmt.Sprintf("%db", size)}
561579
if isBlock {
562580
args = append(args, "-n")
563581
} else {
564582
args = append(args, "-r")
565583
}
566584
args = append(args, fmt.Sprintf("%s/%s", vgName, name))
567585
klog.Infof("lvextend %s", args)
568-
out, err := executor.Execute("lvextend", args)
586+
out, err = executor.Execute("lvextend", args)
569587
return out, err
570588
}
571589

pkg/lvm/nodeserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ func (ns *nodeServer) NodeGetVolumeStats(ctx context.Context, in *csi.NodeGetVol
230230

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

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

0 commit comments

Comments
 (0)