@@ -76,17 +76,29 @@ func buildLVMCreateArgs(vol *apis.LVMVolume) []string {
7676
7777 volume := vol .Name
7878 size := vol .Spec .Capacity + "b"
79+ // thinpool name required for thinProvision volumes
80+ pool := vol .Spec .VolGroup + "_thinpool"
7981
8082 if len (vol .Spec .Capacity ) != 0 {
81- LVMVolArg = append (LVMVolArg , "-L" , size )
83+ // check if thin pool exists for given volumegroup requested thin volume
84+ if strings .TrimSpace (vol .Spec .ThinProvision ) != "yes" || ! lvThinExists (vol .Spec .VolGroup , pool ) {
85+ LVMVolArg = append (LVMVolArg , "-L" , size )
86+ }
87+ }
88+
89+ // command to create thinpool and thin volume if thinProvision is enabled
90+ // `lvcreate -L 1G -T lvmvg/mythinpool -V 1G -n thinvol`
91+ if strings .TrimSpace (vol .Spec .ThinProvision ) == "yes" {
92+ LVMVolArg = append (LVMVolArg , "-T" , vol .Spec .VolGroup + "/" + pool , "-V" , size )
8293 }
8394
8495 if len (vol .Spec .VolGroup ) != 0 {
8596 LVMVolArg = append (LVMVolArg , "-n" , volume )
8697 }
8798
88- LVMVolArg = append (LVMVolArg , vol .Spec .VolGroup )
89-
99+ if strings .TrimSpace (vol .Spec .ThinProvision ) != "yes" {
100+ LVMVolArg = append (LVMVolArg , vol .Spec .VolGroup )
101+ }
90102 return LVMVolArg
91103}
92104
@@ -392,3 +404,14 @@ func ListLVMVolumeGroup() ([]apis.VolumeGroup, error) {
392404 }
393405 return decodeVgsJSON (output )
394406}
407+
408+ // lvThinExists verifies if thin pool/volume already exists for given volumegroup
409+ func lvThinExists (vg string , name string ) bool {
410+ cmd := exec .Command ("lvs" , vg + "/" + name , "--noheadings" , "-o" , "lv_name" )
411+ out , err := cmd .CombinedOutput ()
412+ if err != nil {
413+ klog .Infof ("unable to list existing volumes:%v" , err )
414+ return false
415+ }
416+ return name == strings .TrimSpace (string (out ))
417+ }
0 commit comments