@@ -344,6 +344,22 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
344
344
return nil , status .Error (codes .InvalidArgument , err .Error ())
345
345
}
346
346
347
+ // Check does devicepath already contain a filesystem?
348
+ existingFsType , err := determineFilesystemType (device .Path )
349
+ if err != nil {
350
+ return nil , status .Error (codes .Internal , err .Error ())
351
+ }
352
+
353
+ // what to do if existing file system is detected;
354
+ if existingFsType != "" {
355
+ // Is existing filesystem type same as requested?
356
+ if existingFsType == requestedFsType {
357
+ klog .V (4 ).Infof ("Skip mkfs as %v file system already exists on %v" , existingFsType , device .Path )
358
+ } else {
359
+ return nil , status .Error (codes .AlreadyExists , "File system with different type exists" )
360
+ }
361
+ }
362
+
347
363
if err = ns .provisionDevice (device , requestedFsType ); err != nil {
348
364
return nil , status .Error (codes .Internal , err .Error ())
349
365
}
@@ -478,44 +494,25 @@ func (ns *nodeServer) createEphemeralDevice(ctx context.Context, req *csi.NodePu
478
494
// and mounts at given targetPath.
479
495
func (ns * nodeServer ) provisionDevice (device * pmdmanager.PmemDeviceInfo , fsType string ) error {
480
496
if fsType == "" {
481
- // Default to ext4 filesystem
497
+ // Empty FsType means "unspecified" and we pick default, currently hard-coded to ext4
482
498
fsType = defaultFilesystem
483
499
}
484
500
485
- // Check does devicepath already contain a filesystem?
486
- existingFsType , err := determineFilesystemType (device .Path )
487
- if err != nil {
488
- return err
489
- }
490
-
491
- // what to do if existing file system is detected and is different from request;
492
- // forced re-format would lead to loss of previous data, so we refuse.
493
- if existingFsType != "" {
494
- // Is existing filesystem type same as requested?
495
- if existingFsType == fsType {
496
- klog .V (4 ).Infof ("Skip mkfs as %v file system already exists on %v" , existingFsType , device .Path )
497
- } else {
498
- return fmt .Errorf ("File system with different type(%s) exists, whereas requested type is '%s'" , existingFsType , fsType )
499
- }
501
+ cmd := ""
502
+ var args []string
503
+ // hard-code block size to 4k to avoid smaller values and trouble to dax mount option
504
+ if fsType == "ext4" {
505
+ cmd = "mkfs.ext4"
506
+ args = []string {"-b 4096" , "-F" , device .Path }
507
+ } else if fsType == "xfs" {
508
+ cmd = "mkfs.xfs"
509
+ args = []string {"-b" , "size=4096" , "-f" , device .Path }
500
510
} else {
501
- // no existing file system, make fs
502
- // Empty FsType means "unspecified" and we pick default, currently hard-codes to ext4
503
- cmd := ""
504
- var args []string
505
- // hard-code block size to 4k to avoid smaller values and trouble to dax mount option
506
- if fsType == "ext4" {
507
- cmd = "mkfs.ext4"
508
- args = []string {"-b 4096" , "-F" , device .Path }
509
- } else if fsType == "xfs" {
510
- cmd = "mkfs.xfs"
511
- args = []string {"-b" , "size=4096" , "-f" , device .Path }
512
- } else {
513
- return fmt .Errorf ("Unsupported filesystem '%s'. Supported filesystems types: 'xfs', 'ext4'" , fsType )
514
- }
515
- output , err := pmemexec .RunCommand (cmd , args ... )
516
- if err != nil {
517
- return fmt .Errorf ("mkfs failed: %s" , output )
518
- }
511
+ return fmt .Errorf ("Unsupported filesystem '%s'. Supported filesystems types: 'xfs', 'ext4'" , fsType )
512
+ }
513
+ output , err := pmemexec .RunCommand (cmd , args ... )
514
+ if err != nil {
515
+ return fmt .Errorf ("mkfs failed: %s" , output )
519
516
}
520
517
521
518
return nil
0 commit comments