@@ -174,7 +174,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
174
174
return nil , err
175
175
}
176
176
srcPath = device .Path
177
- mountFlags = append (mountFlags , "dax" )
177
+ mountFlags = append (mountFlags , "dax=always " )
178
178
} else {
179
179
// Validate parameters.
180
180
v , err := parameters .Parse (parameters .PersistentVolumeOrigin , req .GetVolumeContext ())
@@ -526,7 +526,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
526
526
}
527
527
}
528
528
529
- mountOptions = append (mountOptions , "dax" )
529
+ mountOptions = append (mountOptions , "dax=always " )
530
530
531
531
if err = ns .mount (device .Path , stagingtargetPath , mountOptions , false /* raw block */ ); err != nil {
532
532
return nil , status .Error (codes .Internal , err .Error ())
@@ -630,6 +630,19 @@ func (ns *nodeServer) provisionDevice(device *pmdmanager.PmemDeviceInfo, fsType
630
630
fsType = defaultFilesystem
631
631
}
632
632
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
+ }
633
646
cmd := ""
634
647
var args []string
635
648
// 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
646
659
}
647
660
output , err := pmemexec .RunCommand (cmd , args ... )
648
661
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 )
658
663
}
659
664
660
665
return nil
@@ -664,7 +669,7 @@ func (ns *nodeServer) provisionDevice(device *pmdmanager.PmemDeviceInfo, fsType
664
669
func (ns * nodeServer ) mount (sourcePath , targetPath string , mountOptions []string , rawBlock bool ) error {
665
670
notMnt , err := ns .mounter .IsLikelyNotMountPoint (targetPath )
666
671
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 ())
668
673
}
669
674
if ! notMnt {
670
675
return nil
@@ -798,7 +803,9 @@ func findMountFlags(flags []string, findIn []string) bool {
798
803
}
799
804
found := false
800
805
for _ , fIn := range findIn {
801
- if f == fIn {
806
+ if f == "dax=always" && fIn == "dax" ||
807
+ f == "dax" && fIn == "dax=always" ||
808
+ f == fIn {
802
809
found = true
803
810
break
804
811
}
0 commit comments