Class: Yast::AutoinstLVMClass
- Inherits:
-
Module
- Object
- Module
- Yast::AutoinstLVMClass
- Includes:
- Logger
- Defined in:
- ../../src/modules/AutoinstLVM.rb
Instance Method Summary (collapse)
-
- (Object) AutoinstLVM
Constructer.
-
- (Array) get_existing_pvs(vgname)
Return only those PVs on disks touched by the control file, dont add PVs of unconfigured disks.
-
- (void) Init
Initialize.
- - (Object) main
-
- (Object) remove_possible_volumes(vgname)
Delete possible partitions.
-
- (Boolean) Write
Write LVM Configuration.
Instance Method Details
- (Object) AutoinstLVM
Constructer
53 54 55 |
# File '../../src/modules/AutoinstLVM.rb', line 53 def AutoinstLVM nil end |
- (Array) get_existing_pvs(vgname)
Return only those PVs on disks touched by the control file, dont add PVs of unconfigured disks.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File '../../src/modules/AutoinstLVM.rb', line 256 def get_existing_pvs(vgname) Builtins.y2milestone("entering get_existing_pvs with %1", vgname) usedBy = :UB_LVM # all possible PVs on all available devices all_possible_pvs = Builtins.filter(get_possible_pvs(Storage.GetTargetMap)) do |part| (Ops.get_string(part, "used_by_device", "") == Ops.add("/dev/", vgname) && Ops.get_symbol(part, "used_by_type", :UB_NONE) == usedBy || Ops.get_symbol(part, "used_by_type", :UB_NONE) == :UB_NONE) && !Ops.get_boolean(part, "delete", false) end Builtins.y2milestone("all pvs= %1", all_possible_pvs) # FIXME deep_copy(all_possible_pvs) end |
- (void) Init
This method returns an undefined value.
Initialize
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File '../../src/modules/AutoinstLVM.rb', line 60 def Init Builtins.y2milestone("entering Init") Builtins.y2milestone("AutoTargetMap is %1", AutoinstStorage.AutoTargetMap) @lvm = Builtins.filter(AutoinstStorage.AutoTargetMap) do |k, v| Ops.get_symbol(v, "type", :CT_UNKNOWN) == :CT_LVM end # check for existing VM @targetMap = Storage.GetTargetMap Builtins.y2milestone("GetTargetMap returns %1", @targetMap) @ExistingLVM = Builtins.filter(Storage.GetTargetMap) do |k, v| Ops.get_symbol(v, "type", :CT_UNKNOWN) == :CT_LVM end if Builtins.haskey(@ExistingLVM, "/dev/evms") @ExistingLVM = Builtins.remove(@ExistingLVM, "/dev/evms") end @ExistingVGs = Builtins.maplist(@ExistingLVM) do |d, g| Builtins.substring(d, 5) end # we say keep all LVs where the keep_unknown_lv is set Builtins.foreach(@ExistingLVM) do |k, v| vgname = Ops.get_string(v, "name", "") Builtins.foreach(Ops.get_list(v, "partitions", [])) do |p| if Ops.get_boolean( @lvm, [Ops.add("/dev/", vgname), "keep_unknown_lv"], false ) == true Ops.set( @keepLVM, vgname, Builtins.add( Ops.get(@keepLVM, vgname, []), Ops.get_string(p, "lv_name", "") ) ) end end end # look for VGs to reuse Builtins.foreach(AutoinstStorage.AutoTargetMap) do |k, v| Builtins.foreach(Ops.get_list(v, "partitions", [])) do |p| if Builtins.haskey(p, "lvm_group") && Ops.get_boolean(p, "create", true) == false && Ops.get_boolean(p, "format", true) == false if !Builtins.contains( @ExistingVGs, Ops.get_string(p, "lvm_group", "x") ) Report.Error( Builtins.sformat( _( "Cannot reuse volume group %1. The volume group does not exist." ), Ops.get_string(p, "lvm_group", "x") ) ) end atm = deep_copy(AutoinstStorage.AutoTargetMap) Builtins.foreach( Ops.get_list( atm, [ Ops.add("/dev/", Ops.get_string(p, "lvm_group", "x")), "partitions" ], [] ) ) do |vg_p| lvm_group = Ops.get_string(p, "lvm_group", "x") # we know the LV now. So remove it from the keep-list for now Ops.set( @keepLVM, lvm_group, Builtins.filter(Ops.get(@keepLVM, lvm_group, [])) do |v2| v2 != Ops.get_string(vg_p, "lv_name", "") end ) if Ops.get_boolean(vg_p, "create", true) == false Ops.set( @keepLVM, lvm_group, Builtins.add( Ops.get(@keepLVM, lvm_group, []), Ops.get_string(vg_p, "lv_name", "") ) ) end end end end end Builtins.y2milestone("Existing VGs: %1", @ExistingVGs) Builtins.y2milestone("Existing LVM: %1", @ExistingLVM) Builtins.y2milestone("keep LVM: %1", @keepLVM) # FIXME Builtins.foreach(@ExistingVGs) do |v| dev = Builtins.sformat("/dev/%1", v) if Ops.greater_than( Builtins.size(Ops.get_list(@ExistingLVM, [dev, "partitions"], [])), 0 ) @old_available = true end end # Process data @lvm = Builtins.mapmap(@lvm) do |device, disk| Ops.set( disk, "pesize", AutoinstStorage.humanStringToByte( Ops.get_string(disk, "pesize", "4M"), true ) ) vgname = Builtins.substring(device, 5) Ops.set( disk, "partitions", Builtins.maplist(Ops.get_list(disk, "partitions", [])) do |lv| lvsize_str = Ops.get_string(lv, "size", "") mount_point = Ops.get_string(lv, "mount", "") lvsize = 0 vgsize = Ops.multiply( Ops.get_integer(@targetMap, [device, "size_k"], 0), 1024 ) if (lvsize_str == "auto" || lvsize_str == "suspend") && mount_point == "swap" Builtins.y2milestone( "swap slot size: %1", Ops.multiply(Ops.divide(vgsize, 1024), 1024) ) lvsize = Ops.multiply( 1024 * 1024, Partitions.SwapSizeMb( Ops.divide(vgsize, 1024 * 1024), lvsize_str == "suspend" ) ) elsif lvsize_str != "" lvsize = AutoinstStorage.humanStringToByte(lvsize_str, true) end Ops.set(lv, "size_k", Ops.divide(lvsize, 1024)) Ops.set(lv, "type", :lvm) Ops.set(lv, "name", Ops.get_string(lv, "lv_name", "")) deep_copy(lv) end ) { device => disk } end true end |
- (Object) main
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File '../../src/modules/AutoinstLVM.rb', line 15 def main textdomain "autoinst" Yast.import "Storage" Yast.import "Report" Yast.import "Partitions" Yast.import "FileSystems" Yast.import "AutoinstStorage" Yast.import "Label" Yast.include self, "partitioning/lvm_lv_lib.rb" @ExistingLVM = {} @ExistingVGs = [] @keepLVM = {} # LVM map as imported from Profile @lvm = {} # useless # boolean pvs_on_unconfigured = false; # temporary copy of variable from Storage # map <string, map> targetMap = $[]; # temporary copy of variable from Storage @targetMap = {} @old_available = false AutoinstLVM() end |
- (Object) remove_possible_volumes(vgname)
Delete possible partitions
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File '../../src/modules/AutoinstLVM.rb', line 222 def remove_possible_volumes(vgname) Builtins.y2milestone("Deleting possible VGs and LVs") return true if @ExistingLVM == {} vg = Ops.get(@ExistingLVM, Ops.add("/dev/", vgname), {}) lvs = Ops.get_list(vg, "partitions", []) Builtins.y2milestone("Existing LVs: %1", lvs) Builtins.foreach(lvs) do |lv| if !Builtins.contains( Ops.get(@keepLVM, vgname, []), Ops.get_string(lv, "name", "") ) Storage.DeleteDevice( Ops.add( Ops.add(Ops.add("/dev/", vgname), "/"), Ops.get_string(lv, "name", "") ) ) end end if !Builtins.haskey(@keepLVM, vgname) && Ops.get(@ExistingLVM, Ops.add("/dev/", vgname), {}) != {} Storage.DeleteLvmVg(vgname) end true end |
- (Boolean) Write
Write LVM Configuration
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File '../../src/modules/AutoinstLVM.rb', line 277 def Write Builtins.y2milestone("entering Write") Storage.SetZeroNewPartitions(AutoinstStorage.ZeroNewPartitions) lvm_vgs = get_vgs(@targetMap) current_vg = "" error = false Builtins.foreach(@lvm) do |device, volume_group| Builtins.y2milestone("volume_group is %1", volume_group) use = Ops.get_string(volume_group, "use", "none") lvm2 = Ops.get_boolean(volume_group, "lvm2", true) lvm_string = lvm2 ? "lvm2" : "lvm" vgname = Builtins.substring(device, 5) current_vg = vgname new_pvs = get_existing_pvs(vgname) pesize = Ops.get_integer(volume_group, "pesize", 1) if Ops.get_boolean(volume_group, "prefer_remove", false) remove_possible_volumes(vgname) end if Builtins.size(Ops.get_list(volume_group, "keep_lv", [])) == 0 ret = Storage.CreateLvmVg( vgname, Ops.get_integer(volume_group, "pesize", 4194304), lvm2 ) current_vg = vgname Builtins.y2milestone("CreateLvmVg returns %1", ret) @targetMap = Storage.GetTargetMap Builtins.y2milestone("Storage::GetTargetMap returns %1", @targetMap) lvm_vgs = get_vgs(@targetMap) end new_pvs_devices = Builtins.maplist(new_pvs) do |pv| Ops.get_string(pv, "device", "") end Builtins.y2milestone("Existing PVs: %1", new_pvs) atm = deep_copy(AutoinstStorage.AutoTargetMap) smallest_physical = 0 Builtins.foreach(new_pvs) do |pv| to_add = false if Ops.get_boolean(pv, "create", false) to_add = true # exclude partitions that are NOT supposed to be in the LVM Builtins.foreach( Ops.get_list( atm, [Ops.get_string(pv, "maindev", ""), "partitions"], [] ) ) do |atm_vol| if Ops.get_integer(pv, "nr", 0) == Ops.get_integer(atm_vol, "partition_nr", -1) if Ops.get_string(atm_vol, "lvm_group", "") != current_vg Builtins.y2milestone("do not add %1", atm_vol) to_add = false end end end else to_add = false # exclude partitions that are NOT supposed to be in the LVM Builtins.foreach( Ops.get_list( atm, [Ops.get_string(pv, "maindev", ""), "partitions"], [] ) ) do |atm_vol| if Ops.get_integer(pv, "nr", 0) == Ops.get_integer(atm_vol, "partition_nr", -1) if Ops.get_string(atm_vol, "lvm_group", "") == current_vg Builtins.y2milestone("add %1", atm_vol) to_add = true end end end end if to_add Builtins.y2milestone( "addPhysicalVolume %1 , %2", Ops.get_string(pv, "device", ""), current_vg ) if smallest_physical == 0 || Ops.less_than( Ops.get_integer(pv, "size_k", 0), smallest_physical ) smallest_physical = Ops.get_integer(pv, "size_k", 0) end addPhysicalVolume( @targetMap, Ops.get_string(pv, "device", ""), current_vg ) end end # calculating the "max" for logical volume tmp_tm = Storage.GetTargetMap freeSpace = 0 buffer = 0 freeSpace = Ops.get_integer(tmp_tm, [device, "size_k"], 0) buffer = Ops.get_integer(tmp_tm, [device, "cyl_size"], 0) buffer = Ops.divide(Ops.multiply(buffer, 2), 1024) max_counter = 0 Ops.set( volume_group, "partitions", Builtins.maplist(Ops.get_list(volume_group, "partitions", [])) do |lv| s = AutoinstStorage.humanStringToByte( Ops.get_string(lv, "size", "10000"), true ) if Ops.less_or_equal(s, 100) && Ops.greater_than(s, 0) # we assume percentage for this lv integer_k = Ops.divide( Ops.multiply( freeSpace, Builtins.tointeger(Ops.get_string(lv, "size", "0")) ), 100 ) Ops.set(lv, "size_k", integer_k) Builtins.y2milestone( "percentage for lv %1. Size_k is %2", lv, integer_k ) elsif (Ops.get_string(lv, "size", "") == "max" || Ops.get_string(lv, "size", "") == "auto") && Ops.less_or_equal(Ops.get_integer(lv, "stripes", 0), 1) # "auto" size does not make sense here. But we are switching to the "max" behaviour in order # not to produce an error and to evaluate other useable settings. (bnc#962034) Report.Warning( "Option \"auto\" is not supported with LVM. Taking \"max\" option instead.") if lv["size"] == "auto" max_counter = Ops.add(max_counter, 1) end deep_copy(lv) end ) Builtins.foreach(Ops.get_list(volume_group, "partitions", [])) do |lv| freeSpace = Ops.subtract(freeSpace, Ops.get_integer(lv, "size_k", 0)) Builtins.y2milestone("freeSpace = %1", freeSpace) end freeSpace = Ops.subtract(freeSpace, buffer) # that's a buffer for rounding errors with cylinder boundaries Builtins.foreach(Ops.get_list(volume_group, "partitions", [])) do |lv| if Ops.get_integer(lv, "size_k", 0) == 0 && Ops.greater_than(freeSpace, 0) # if "max" calculation is turned on for the LV if Ops.greater_than(Ops.get_integer(lv, "stripes", 0), 1) Ops.set( lv, "size_k", Ops.multiply( smallest_physical, Ops.get_integer(lv, "stripes", 1) ) ) Ops.set( lv, "size", Builtins.sformat( "%1K", Ops.multiply( smallest_physical, Ops.get_integer(lv, "stripes", 1) ) ) ) freeSpace = Ops.subtract( freeSpace, Ops.get_integer(lv, "size_k", 0) ) smallest_physical = 0 Builtins.y2milestone( "max-config for striped LV found. Setting size to %1", Ops.get_string(lv, "size", "0") ) else Ops.set(lv, "size_k", Ops.divide(freeSpace, max_counter)) Ops.set(lv, "size", Builtins.sformat("%1K", freeSpace)) end end Builtins.y2milestone( "size_k before rounding %1", Ops.get_integer(lv, "size_k", 0) ) Ops.set( lv, "size_k", Ops.divide( Ops.multiply( Ops.divide( Ops.multiply(Ops.get_integer(lv, "size_k", 0), 1024), pesize ), pesize ), 1024 ) ) # rounding Builtins.y2milestone( "size_k after rounding %1", Ops.get_integer(lv, "size_k", 0) ) lvlist = Ops.get_list(@ExistingLVM, [device, "partitions"], []) if Builtins.contains( Ops.get(@keepLVM, vgname, []), Ops.get_string(lv, "lv_name", "") ) lvtokeep = Builtins.filter(lvlist) do |p| Ops.get_string(p, "nr", "") == Ops.get_string(lv, "lv_name", "") end this_lv = Ops.get(lvtokeep, 0, {}) Builtins.y2milestone("Keeping LV: %1", this_lv) Builtins.y2milestone("lv = %1", lv) Ops.set( lv, "device", Ops.add( Ops.add(Ops.add("/dev/", vgname), "/"), Ops.get_string(lv, "lv_name", "") ) ) Ops.set(lv, "used_fs", Ops.get_symbol(this_lv, "used_fs") do Partitions.DefaultFs end) lvret = {} if Ops.get_boolean(lv, "resize", false) reslv = { "create" => false, "region" => Ops.get_list(lv, "region", []), "fsid" => 142, "lv_size" => Ops.get_integer(lv, "lv_size", 0), "fstype" => "LV", "nr" => Ops.get_string(lv, "nr", ""), "mount" => Ops.get_string(lv, "mount", ""), "used_fs" => Ops.get_symbol(this_lv, "used_fs") do Partitions.DefaultFs end, "format" => Ops.get_boolean(lv, "format", false), "device" => Ops.get_string(lv, "device", "") } Ops.set(reslv, "changed_size", true) Storage.ResizeVolume( Ops.add( Ops.add(Ops.add("/dev/", current_vg), "/"), Ops.get_string(lv, "name", "") ), Ops.add("/dev/", current_vg), Ops.divide(Ops.get_integer(lv, "lv_size", 0), 1024) ) else Storage.ChangeVolumeProperties(lv) end @targetMap = Convert.convert( Ops.get(lvret, "targets", @targetMap), :from => "any", :to => "map <string, map>" ) elsif Ops.get_boolean(lv, "create", true) Ops.set(lv, "used_fs", Ops.get_symbol(lv, "filesystem") do Partitions.DefaultFs end) lv = AutoinstStorage.AddFilesysData(lv, lv) Ops.set(lv, "create", true) Ops.set(lv, "format", Ops.get_boolean(lv, "format", true)) Ops.set( lv, "device", Ops.add( Ops.add(Ops.add("/dev/", current_vg), "/"), Ops.get_string(lv, "name", "") ) ) Builtins.y2milestone( "calling addLogicalVolume with lv = %1 and current_vg = %2", lv, current_vg ) addLogicalVolume(lv, current_vg) @targetMap = Storage.GetTargetMap Builtins.y2milestone("Storage::GetTargetMap returns %1", @targetMap) end end end Builtins.y2milestone("targetmap: %1", @targetMap) AutoinstStorage.AutoTargetMap.each do |device, data| target_map = Storage.GetTargetMap() if target_map.has_key?(device) && data["type"] == :CT_LVM if data["enable_snapshots"] && target_map[device].has_key?("partitions") root_partition = target_map[device]["partitions"].find do |p| p["mount"] == "/" && p["used_fs"] == :btrfs end if root_partition log.info("Enabling snapshots for \"/\"; root_partition #{root_partition}") Storage.SetUserdata(root_partition["device"], { "/" => "snapshots" }) end end end end true end |