@@ -345,6 +345,13 @@ func CreateVolume(ctx context.Context, vol *apis.LVMVolume) error {
345345 klog .Errorf (
346346 "lvm: could not create volume %v cmd %v error: %s" , volume , args , string (out ),
347347 )
348+ // remove lvm volume if creation failed
349+ if cleanupErr := DestroyVolume (ctx , vol ); cleanupErr != nil {
350+ klog .Warningf ("lvm: failed to cleanup volume %s: %v" , volume , cleanupErr )
351+ } else {
352+ klog .Infof ("lvm: successfully cleaned up failed volume %s" , volume )
353+ }
354+
348355 return err
349356 }
350357 klog .Infof ("lvm: created volume %s" , volume )
@@ -743,8 +750,11 @@ func getLvDeviceName(path string) (string, error) {
743750 klog .Errorf ("failed to resolve device mapper from lv path %v: %v" , path , err )
744751 return "" , err
745752 }
746- deviceName := strings .Split (dmPath , "/" )
747- return deviceName [len (deviceName )- 1 ], nil
753+ _ , file := filepath .Split (dmPath )
754+ if file == "" {
755+ return "" , fmt .Errorf ("invalid device path: %s" , dmPath )
756+ }
757+ return file , nil
748758}
749759
750760// To parse the output of lvs command and store it in LogicalVolume
@@ -899,12 +909,13 @@ func decodeLvsJSON(raw []byte) ([]LogicalVolume, error) {
899909 for _ , item := range items {
900910 var lv LogicalVolume
901911 if lv , err = parseLogicalVolume (item ); err != nil {
902- return lvs , err
912+ klog .Warningf ("failed to parse LV %s, skipping: %v" , lv .Name , err )
913+ continue
903914 }
904915 deviceName , err := getLvDeviceName (lv .Path )
905916 if err != nil {
906- klog .Error ( err )
907- return nil , err
917+ klog .Warningf ( "failed to get device name for LV %s, skipping: %v" , lv . Name , err )
918+ continue
908919 }
909920 lv .Device = deviceName
910921 lvs = append (lvs , lv )
0 commit comments