Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit a01c1d8

Browse files
committed
nodeserver: Improve idempotency in ephemeral volume creation
The check for existing file system before mkfs was made on one call path only, but ephemeral took another path when creating an inline volume. Due to 2 additional side effects: incomplete idempotency testing, and issue in kubelet that caused repeated publishVolume requests, it was exposed that nodeserver attempts to mkfs a device with existing file system, which fails, and there is no useful error information. dax flag gets reported as "dax=always" which means we have to use special handling for comparing.
1 parent ff531cb commit a01c1d8

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

pkg/pmem-csi-driver/nodeserver.go

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
174174
return nil, err
175175
}
176176
srcPath = device.Path
177-
mountFlags = append(mountFlags, "dax")
177+
mountFlags = append(mountFlags, "dax=always")
178178
} else {
179179
// Validate parameters.
180180
v, err := parameters.Parse(parameters.PersistentVolumeOrigin, req.GetVolumeContext())
@@ -526,7 +526,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
526526
}
527527
}
528528

529-
mountOptions = append(mountOptions, "dax")
529+
mountOptions = append(mountOptions, "dax=always")
530530

531531
if err = ns.mount(device.Path, stagingtargetPath, mountOptions, false /* raw block */); err != nil {
532532
return nil, status.Error(codes.Internal, err.Error())
@@ -630,6 +630,19 @@ func (ns *nodeServer) provisionDevice(device *pmdmanager.PmemDeviceInfo, fsType
630630
fsType = defaultFilesystem
631631
}
632632

633+
// Check does devicepath already contain a filesystem?
634+
existingFsType, err := determineFilesystemType(device.Path)
635+
if err != nil {
636+
return status.Error(codes.Internal, err.Error())
637+
}
638+
if existingFsType != "" {
639+
// Is existing filesystem type same as requested?
640+
if existingFsType == fsType {
641+
klog.V(4).Infof("Skip mkfs as %v file system already exists on %v", existingFsType, device.Path)
642+
return nil
643+
}
644+
return status.Error(codes.AlreadyExists, "File system with different type exists")
645+
}
633646
cmd := ""
634647
var args []string
635648
// hard-code block size to 4k to avoid smaller values and trouble to dax mount option
@@ -646,15 +659,7 @@ func (ns *nodeServer) provisionDevice(device *pmdmanager.PmemDeviceInfo, fsType
646659
}
647660
output, err := pmemexec.RunCommand(cmd, args...)
648661
if err != nil {
649-
// If the filesystem is already mounted, then
650-
// formatting it fails. In that case we don't need to
651-
// format and can ignore that error. We could check
652-
// for that ourselves in advance, but that would be
653-
// extra code.
654-
if strings.Contains(output, "contains a mounted filesystem") {
655-
return nil
656-
}
657-
return fmt.Errorf("mkfs failed: %s", output)
662+
return fmt.Errorf("mkfs failed: output:[%s] err:[%v]", output, err)
658663
}
659664

660665
return nil
@@ -664,7 +669,7 @@ func (ns *nodeServer) provisionDevice(device *pmdmanager.PmemDeviceInfo, fsType
664669
func (ns *nodeServer) mount(sourcePath, targetPath string, mountOptions []string, rawBlock bool) error {
665670
notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath)
666671
if err != nil && !os.IsNotExist(err) {
667-
return fmt.Errorf("failed to determain if '%s' is a valid mount point: %s", targetPath, err.Error())
672+
return fmt.Errorf("failed to determine if '%s' is a valid mount point: %s", targetPath, err.Error())
668673
}
669674
if !notMnt {
670675
return nil
@@ -798,7 +803,9 @@ func findMountFlags(flags []string, findIn []string) bool {
798803
}
799804
found := false
800805
for _, fIn := range findIn {
801-
if f == fIn {
806+
if f == "dax=always" && fIn == "dax" ||
807+
f == "dax" && fIn == "dax=always" ||
808+
f == fIn {
802809
found = true
803810
break
804811
}

0 commit comments

Comments
 (0)