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

Commit 9e405a2

Browse files
authored
Merge pull request #956 from okartau/improve-ephemeral-idemp
nodeserver: Improve idempotency in ephemeral volume creation
2 parents 8581b52 + a01c1d8 commit 9e405a2

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
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
}

test/e2e/storage/sanity.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,11 @@ fi
762762
v.remove(vol, volName)
763763
})
764764

765-
Context("ephemeral volumes", func() {
766-
doit := func(withFlag bool, repeatCalls int) {
765+
Context("CSI ephemeral volumes", func() {
766+
doit := func(withFlag bool, repeatCalls int, fsType string) {
767767
targetPath := sc.TargetPath + "/ephemeral"
768768
params := map[string]string{
769-
"size": "1Mi",
769+
"size": "100Mi",
770770
}
771771
if withFlag {
772772
params["csi.storage.k8s.io/ephemeral"] = "true"
@@ -776,7 +776,9 @@ fi
776776
VolumeContext: params,
777777
VolumeCapability: &csi.VolumeCapability{
778778
AccessType: &csi.VolumeCapability_Mount{
779-
Mount: &csi.VolumeCapability_MountVolume{},
779+
Mount: &csi.VolumeCapability_MountVolume{
780+
FsType: fsType,
781+
},
780782
},
781783
AccessMode: &csi.VolumeCapability_AccessMode{
782784
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
@@ -790,7 +792,6 @@ fi
790792
_, err := nc.NodePublishVolume(ctx, &req)
791793
if err == nil {
792794
published = true
793-
break
794795
} else if failedPublish == nil {
795796
failedPublish = fmt.Errorf("NodePublishVolume for ephemeral volume, attempt #%d: %v", i, err)
796797
}
@@ -812,13 +813,21 @@ fi
812813
}
813814

814815
doall := func(withFlag bool) {
815-
It("work", func() {
816-
doit(withFlag, 1)
817-
})
816+
for _, fs := range []string{"default", "ext4", "xfs"} {
817+
fsType := fs
818+
if fsType == "default" {
819+
fsType = ""
820+
}
821+
Context(fs+" FS", func() {
822+
It("work", func() {
823+
doit(withFlag, 1, fsType)
824+
})
818825

819-
It("are idempotent", func() {
820-
doit(withFlag, 10)
821-
})
826+
It("are idempotent", func() {
827+
doit(withFlag, 10, fsType)
828+
})
829+
})
830+
}
822831
}
823832

824833
Context("with csi.storage.k8s.io/ephemeral", func() {

0 commit comments

Comments
 (0)