-
Notifications
You must be signed in to change notification settings - Fork 14
/
Storage.rb
7386 lines (6629 loc) · 234 KB
/
Storage.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
51
52
53
54
55
56
57
58
59
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
220
221
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# encoding: utf-8
# Copyright (c) [2012-2015] Novell, Inc.
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may
# find current contact information at www.novell.com.
require "yast"
require "dbus"
require "storage"
require "storage/target_map_formatter"
require "storage/used_storage_features"
require "storage/shadowed_vol_helper"
module Yast
class StorageClass < Module
include Yast::Logger
include Yast::StorageHelpers::TargetMapFormatter
def main
Yast.import "Pkg"
Yast.import "UI"
textdomain "storage"
Yast.import "Arch"
Yast.import "Directory"
Yast.import "FileSystems"
Yast.import "FileUtils"
Yast.import "Installation"
Yast.import "Label"
Yast.import "Icon"
Yast.import "Mode"
Yast.import "Partitions"
Yast.import "Popup"
Yast.import "Report"
Yast.import "Misc"
Yast.import "HTML"
Yast.import "StorageInit"
Yast.import "StorageDevices"
Yast.import "StorageClients"
Yast.import "StorageSnapper"
Yast.import "Stage"
Yast.import "String"
Yast.import "Hotplug"
Yast.import "ProductFeatures"
Yast.import "Service"
Yast.import "Package"
# simple resize functionality - dialog to set size of Linux and Windows before proposal
@resize_partition = nil
@resize_partition_data = nil
@resize_cyl_size = nil
@default_multipathing = false
# end of resizing functions
@conv_ctype = {
"def_sym" => :CT_UNKNOWN,
"def_int" => ::Storage::CUNKNOWN,
"m" => {
::Storage::DISK => :CT_DISK,
::Storage::MD => :CT_MD,
::Storage::LOOP => :CT_LOOP,
::Storage::LVM => :CT_LVM,
::Storage::DMRAID => :CT_DMRAID,
::Storage::DMMULTIPATH => :CT_DMMULTIPATH,
::Storage::DM => :CT_DM,
::Storage::MDPART => :CT_MDPART,
::Storage::NFSC => :CT_NFS,
::Storage::BTRFSC => :CT_BTRFS,
::Storage::TMPFSC => :CT_TMPFS
}
}
@conv_usedby = {
"def_sym" => :UB_NONE,
"def_int" => ::Storage::UB_NONE,
"m" => {
::Storage::UB_LVM => :UB_LVM,
::Storage::UB_MD => :UB_MD,
::Storage::UB_DMRAID => :UB_DMRAID,
::Storage::UB_DMMULTIPATH => :UB_DMMULTIPATH,
::Storage::UB_MDPART => :UB_MDPART,
::Storage::UB_DM => :UB_DM,
::Storage::UB_BTRFS => :UB_BTRFS
}
}
@conv_ptype = {
"def_sym" => :primary,
"def_int" => ::Storage::PRIMARY,
"m" => {
::Storage::LOGICAL => :logical,
::Storage::EXTENDED => :extended
}
}
@conv_mountby = {
"def_sym" => :device,
"def_int" => ::Storage::MOUNTBY_DEVICE,
"m" => {
::Storage::MOUNTBY_UUID => :uuid,
::Storage::MOUNTBY_LABEL => :label,
::Storage::MOUNTBY_ID => :id,
::Storage::MOUNTBY_PATH => :path
}
}
@conv_encryption = {
"def_sym" => :none,
"def_int" => ::Storage::ENC_NONE,
"m" => {
::Storage::ENC_TWOFISH => :twofish,
::Storage::ENC_TWOFISH_OLD => :twofish_old,
::Storage::ENC_TWOFISH256_OLD => :twofish_256_old,
::Storage::ENC_LUKS => :luks,
::Storage::ENC_UNKNOWN => :unknown
}
}
@conv_mdtype = {
"def_sym" => :raid_unknown,
"def_int" => ::Storage::RAID_UNK,
"m" => {
::Storage::RAID0 => :raid0,
::Storage::RAID1 => :raid1,
::Storage::RAID5 => :raid5,
::Storage::RAID6 => :raid6,
::Storage::RAID10 => :raid10,
::Storage::MULTIPATH => :multipath
}
}
@conv_mdstring = {
"raid0" => ::Storage::RAID0,
"raid1" => ::Storage::RAID1,
"raid5" => ::Storage::RAID5,
"raid6" => ::Storage::RAID6,
"raid10" => ::Storage::RAID10,
"multipath" => ::Storage::MULTIPATH
}
@conv_mdparity = {
"def_sym" => :par_default,
"def_int" => ::Storage::PAR_DEFAULT,
"m" => {
::Storage::LEFT_ASYMMETRIC => :left_asymmetric,
::Storage::LEFT_SYMMETRIC => :left_symmetric,
::Storage::RIGHT_ASYMMETRIC => :right_asymmetric,
::Storage::RIGHT_SYMMETRIC => :right_symmetric,
::Storage::PAR_FIRST => :par_first,
::Storage::PAR_LAST => :par_last,
::Storage::LEFT_ASYMMETRIC_6 => :left_asymmetric_6,
::Storage::LEFT_SYMMETRIC_6 => :left_symmetric_6,
::Storage::RIGHT_ASYMMETRIC_6 => :right_asymmetric_6,
::Storage::RIGHT_SYMMETRIC_6 => :right_symmetric_6,
::Storage::PAR_FIRST_6 => :par_first_6,
::Storage::PAR_NEAR_2 => :par_near_2,
::Storage::PAR_OFFSET_2 => :par_offset_2,
::Storage::PAR_FAR_2 => :par_far_2,
::Storage::PAR_NEAR_3 => :par_near_3,
::Storage::PAR_OFFSET_3 => :par_offset_3,
::Storage::PAR_FAR_3 => :par_far_3
}
}
@conv_parstring = {
"default" => ::Storage::PAR_DEFAULT,
"left_asymmetric" => ::Storage::LEFT_ASYMMETRIC,
"left_symmetric" => ::Storage::LEFT_SYMMETRIC,
"right_asymmetric" => ::Storage::RIGHT_ASYMMETRIC,
"right_symmetric" => ::Storage::RIGHT_SYMMETRIC,
"parity_first" => ::Storage::PAR_FIRST,
"parity_last" => ::Storage::PAR_LAST,
"left_asymmetric_6" => ::Storage::LEFT_ASYMMETRIC_6,
"left_symmetric_6" => ::Storage::LEFT_SYMMETRIC_6,
"right_asymmetric_6" => ::Storage::RIGHT_ASYMMETRIC_6,
"right_symmetric_6" => ::Storage::RIGHT_SYMMETRIC_6,
"parity_first_6" => ::Storage::PAR_FIRST_6,
"n2" => ::Storage::PAR_NEAR_2,
"o2" => ::Storage::PAR_OFFSET_2,
"f2" => ::Storage::PAR_FAR_2,
"n3" => ::Storage::PAR_NEAR_3,
"o3" => ::Storage::PAR_OFFSET_3,
"f3" => ::Storage::PAR_FAR_3
}
@rev_conv_parstring = Builtins.mapmap(@conv_parstring) do |s, i|
{ i => s }
end
@conv_partalign = {
"def_sym" => :align_optimal,
"def_int" => ::Storage::ALIGN_OPTIMAL,
"m" => {
::Storage::ALIGN_OPTIMAL => :align_optimal,
::Storage::ALIGN_CYLINDER => :align_cylinder
}
}
@conv_transport = {
"def_sym" => :unknown,
"def_int" => ::Storage::TUNKNOWN,
"m" => {
::Storage::SBP => :sbp,
::Storage::ATA => :ata,
::Storage::FC => :fc,
::Storage::ISCSI => :iscsi,
::Storage::SAS => :sas,
::Storage::SATA => :sata,
::Storage::SPI => :spi,
::Storage::USB => :usb,
::Storage::FCOE => :fcoe
}
}
@DiskMapVersion = {}
@DiskMap = {}
@type_order = {
:CT_DISK => 0,
:CT_DMRAID => 1,
:CT_DMMULTIPATH => 2,
:CT_MDPART => 3,
:CT_MD => 4,
:CT_DM => 5,
:CT_LVM => 6,
:CT_LOOP => 7,
:CT_NFS => 8,
:CT_BTRFS => 9,
:CT_TMPFS => 10
}
@hw_packages = []
@part_insts = nil
# Storage = TargetMap
# /* Storage = $[ "targets" : $[],
# "must_reread_partitions" : false,
# "win_device" : false,
# "testsuite" : false,
# "do_resize" : "",
# "part_proposal_mode" : "",
# "part_proposal_first" : true,
# "focus" : key
# ]
@StorageMap = {}
# stringkeys for access to the Storage map
@targets_key = "targets"
@part_mode_key = "part_mode"
@part_disk_key = "part_disk"
@testsuite_key = "testsuite"
@do_resize_key = "do_resize"
@win_device_key = "win_device"
@custom_display_key = "custom_display"
@part_proposal_mode_key = "part_proposal_mode"
@part_proposal_first_key = "part_proposal_first"
@part_proposal_active_key = "part_proposal_active"
@probe_done = false
@exit_key = :next
@sint = nil
@conts = []
@count = 0
@save_chtxt = ""
@dbus_cookie = nil
Storage()
end
def IsKernelDeviceName(device)
Builtins.substring(device, 0, 6) != "LABEL=" &&
Builtins.substring(device, 0, 5) != "UUID=" &&
Builtins.substring(device, 0, 13) != "/dev/disk/by-"
end
def DeviceNameMightNeedAdaption(device)
if IsKernelDeviceName(device)
return true
end
if device.start_with?("/dev/disk/by-id/raid-") ||
device.start_with?("/dev/disk/by-id/dm-name-") ||
device.start_with?("/dev/disk/by-id/dm-uuid-DMRAID-")
return true
end
return false
end
def InitLibstorage(readonly)
return true if @sint != nil
log.info("InitLibstorage")
@sint = StorageInit.CreateInterface(readonly)
if @sint == nil
log.error("StorageInit::CreateInterface failed")
return false
end
StorageClients.InstallCallbacks(@sint)
btrfs_default_subvolume = ProductFeatures.GetStringFeature("partitioning",
"btrfs_default_subvolume")
@sint.setDefaultSubvolName(btrfs_default_subvolume) if btrfs_default_subvolume
if Stage.initial
@sint.setDetectMountedVolumes(false)
@sint.setRootPrefix(Installation.destdir)
if skip_activation_popup?
val = @default_multipathing ? ::Storage::MPAS_ON : ::Storage::MPAS_OFF
@sint.setMultipathAutostart(val)
end
end
@conts = getContainers
log.info("InitLibstorage conts:#{@conts}")
FileSystems.InitSlib(@sint)
Partitions.InitSlib(@sint)
true
end
def FinishLibstorage
return if @sint == nil
log.info("FinishLibstorage")
::Storage::destroyStorageInterface(@sint)
@sint = nil
nil
end
def default_subvolume_name()
return @sint.getDefaultSubvolName()
end
def ClassicStringToByte(str)
ret, bytes = ::Storage::humanStringToByte(str,true)
if( !ret )
ts = Ops.add(str, "b")
ret, bytes = ::Storage::humanStringToByte(ts,true)
if( !ret )
bytes = 0
Builtins.y2error("cannot parse %1 or %2", str, ts)
end
end
bytes
end
def ByteToHumanString(bytes)
return ::Storage::byteToHumanString(bytes, false, 2, false).force_encoding("UTF-8")
end
def KByteToHumanString(bytes_k)
return ::Storage::byteToHumanString(bytes_k*1024, false, 2, false).force_encoding("UTF-8")
end
def ByteToHumanStringOmitZeroes(bytes)
return ::Storage::byteToHumanString(bytes, false, 2, true).force_encoding("UTF-8")
end
def KByteToHumanStringOmitZeroes(bytes_k)
return ::Storage::byteToHumanString(bytes_k*1024, false, 2, true).force_encoding("UTF-8")
end
def HumanStringToByte(str, bytes)
i = 0
bytes.value = i # bnc #408829 and #408891
ret, bytes.value = ::Storage::humanStringToByte( str, false )
Builtins.y2milestone(
"HumanStringToByte ret: %1 str: %2 bytes: %3",
ret,
str,
bytes.value
)
ret
end
def HumanStringToKByte(str, bytes_k)
ret, bytes = ::Storage::humanStringToByte( str, false )
bytes = 0 if !ret # bnc #408829
bytes_k.value = bytes.div(1024)
Builtins.y2milestone(
"HumanStringToKByte ret: %1 str: %2 bytes_k: %3",
ret,
str,
bytes_k.value
)
ret
end
# Converts a string into a integer and checks the allowed range for the
# integer. The range check is a bit sloppy to compensate rounding issues but
# it's guaranteed that the result lies within the allowed range.
def HumanStringToKByteWithRangeCheck(str, bytes_k, min_k, max_k)
if !(
bytes_k_ref = arg_ref(bytes_k.value);
_HumanStringToKByte_result = HumanStringToKByte(str, bytes_k_ref);
bytes_k.value = bytes_k_ref.value;
_HumanStringToKByte_result
)
return false
end
if min_k != nil && Ops.less_than(bytes_k.value, min_k)
if KByteToHumanString(bytes_k.value) != KByteToHumanString(min_k)
return false
end
bytes_k.value = min_k
end
if max_k != nil && Ops.greater_than(bytes_k.value, max_k)
if KByteToHumanString(bytes_k.value) != KByteToHumanString(max_k)
return false
end
bytes_k.value = max_k
end
true
end
# Returns Device Name
#
# @param string Disk
# @param [Object] partition
# @return [String] device name
#
# @example Storage::GetDeviceName("/dev/md", 1)
# @example Storage::GetDeviceName("/dev/system", "root")
def GetDeviceName(disk, partition)
ret = disk
if Ops.is_integer?(partition)
ret = @sint.getPartitionName(disk, Convert.to_integer(partition));
elsif !Builtins.isempty(Convert.to_string(partition))
ret = Ops.add(Ops.add(ret, "/"), Convert.to_string(partition))
end
ret
end
def SetIgnoreFstab(device, val)
@sint.setIgnoreFstab(device, val)==0
end
def GetIgnoreFstab(device, val)
ret, val.value = @sint.getIgnoreFstab(device);
ret == 0
end
def toSymbol(conv, val)
conv = deep_copy(conv)
Ops.get_symbol(
conv,
["m", val],
Ops.get_symbol(conv, "def_sym", :invalid_conv_map)
)
end
def fromSymbol(conv, val)
conv = deep_copy(conv)
ret = Ops.get_integer(conv, "def_int", -1)
Builtins.foreach(Ops.get_map(conv, "m", {})) { |i, s| ret = i if s == val }
ret
end
def GetContVolInfo(device, info)
tmp = ::Storage::ContVolInfo.new()
if @sint.getContVolInfo(device, tmp) != 0
return false
end
info.value = {
"ctype" => toSymbol(@conv_ctype, tmp.ctype),
"cname" => tmp.cname,
"cdevice" => tmp.cdevice,
"vname" => tmp.vname,
"vdevice" => tmp.vdevice,
"num" => tmp.num
}
Builtins.y2milestone(
"GetContVolInfo device: %1 info: %2",
device,
info.value
)
true
end
def GetDiskPartitionTg(inpdev, tg)
tg = deep_copy(tg)
device = inpdev
ret = []
dlen = 0
as_string = false
ls = Builtins.filter(Builtins.splitstring(device, "/")) do |s|
!Builtins.isempty(s)
end
if Builtins.search(device, "LABEL=") == 0 ||
Builtins.search(device, "UUID=") == 0
tl = Builtins.splitstring(device, "=")
ls = ["dev", "disk", "", Ops.get(tl, 1, "")]
Ops.set(
ls,
2,
Builtins.search(device, "LABEL=") == 0 ? "by-label" : "by-uuid"
)
Builtins.y2milestone("GetDiskPartitionTg ls: %1", ls)
end
Builtins.y2debug(
"GetDiskPartitionTg size: %1 ls: %2",
Builtins.size(ls),
ls
)
if device == "/dev/tmpfs"
ret = [ { "disk" => "/dev/tmpfs", "nr" => "" } ]
elsif device == "tmpfs"
# TODO multiple mount points issues unfixable
ret = [ { "disk" => "/dev/tmpfs", "nr" => "tmpfs" } ]
elsif Ops.greater_or_equal(Builtins.size(ls), 4) &&
Ops.get(ls, 1, "") == "disk" &&
Builtins.contains(
["by-id", "by-path", "by-uuid", "by-label"],
Ops.get(ls, 2, "")
)
part = {}
regex = "-part[0-9]+$"
if Ops.get(ls, 2, "") == "by-label"
Builtins.foreach(tg) do |dev, disk|
part = Builtins.find(Ops.get_list(disk, "partitions", [])) do |p|
Ops.get_string(p, "label", "") == Ops.get(ls, 3, "")
end
if part != nil
tmp = {}
Ops.set(tmp, "disk", dev)
if Builtins.haskey(part, "nr")
Ops.set(tmp, "nr", Ops.get(part, "nr", 0))
else
Ops.set(tmp, "nr", Ops.get_string(part, "name", ""))
end
ret = Builtins.add(ret, tmp)
end
end
elsif Ops.get(ls, 2, "") == "by-uuid"
Builtins.foreach(tg) do |dev, disk|
part = Builtins.find(Ops.get_list(disk, "partitions", [])) do |p|
Ops.get_string(p, "uuid", "") == Ops.get(ls, 3, "")
end
if part != nil
tmp = {}
Ops.set(tmp, "disk", dev)
if Builtins.haskey(part, "nr")
Ops.set(tmp, "nr", Ops.get(part, "nr", 0))
else
Ops.set(tmp, "nr", Ops.get_string(part, "name", ""))
end
ret = Builtins.add(ret, tmp)
end
end
elsif Ops.get(ls, 2, "") == "by-id"
id = Ops.get(ls, 3, "")
num = 0
l = Builtins.regexppos(id, regex)
if Ops.greater_than(Builtins.size(l), 0)
num = Builtins.tointeger(
Builtins.substring(id, Ops.add(Ops.get_integer(l, 0, 0), 5))
)
id = Builtins.substring(id, 0, Ops.get_integer(l, 0, 0))
Builtins.y2debug("GetDiskPartitionTg id: %1 num: %2", id, num)
end
Builtins.foreach(tg) do |dev, disk|
if Builtins.size(ret) == 0 &&
Builtins.find(Ops.get_list(disk, "udev_id", [])) { |s| s == id } != nil
part = Builtins.find(Ops.get_list(disk, "partitions", [])) do |p|
Ops.get_integer(p, "nr", 0) == num
end
if num == 0 || part != nil
tmp = {}
Ops.set(tmp, "disk", dev)
if Ops.greater_than(num, 0)
Ops.set(tmp, "nr", num)
else
Ops.set(tmp, "nr", "")
end
ret = [tmp]
end
end
end
elsif Ops.get(ls, 2, "") == "by-path"
id = Ops.get(ls, 3, "")
num = 0
l = Builtins.regexppos(id, regex)
if Ops.greater_than(Builtins.size(l), 0)
num = Builtins.tointeger(
Builtins.substring(id, Ops.add(Ops.get_integer(l, 0, 0), 5))
)
id = Builtins.substring(id, 0, Ops.get_integer(l, 0, 0))
Builtins.y2debug("GetDiskPartitionTg id: %1 num: %2", id, num)
end
Builtins.foreach(tg) do |dev, disk|
if Builtins.size(ret) == 0 &&
Ops.get_string(disk, "udev_path", "") == id
part = Builtins.find(Ops.get_list(disk, "partitions", [])) do |p|
Ops.get_integer(p, "nr", 0) == num
end
if num == 0 || part != nil
tmp = {}
Ops.set(tmp, "disk", dev)
if Ops.greater_than(num, 0)
Ops.set(tmp, "nr", num)
else
Ops.set(tmp, "nr", "")
end
ret = [tmp]
end
end
end
end
elsif Builtins.search(device, "/") == 0
if Builtins.search(device, "/dev/hd") == 0 ||
Builtins.search(device, "/dev/sd") == 0 ||
Builtins.search(device, "/dev/ed") == 0 ||
Builtins.search(device, "/dev/iseries/vd") == 0
dlen = Builtins.findfirstof(device, "0123456789")
dlen = Builtins.size(device) if dlen == nil
elsif Builtins.search(device, "/dev/md") == 0 && Builtins.size(ls) == 2
pos = Builtins.search(device, "p")
if pos != nil
dlen = pos
else
dlen = 7
end
elsif Builtins.search(device, "/dev/loop") == 0
dlen = 9
elsif Builtins.search(device, "/dev/i2o/hd") == 0
dlen = 12
elsif @sint.getPartitionPrefix(device)=="p"
pos = Builtins.findlastof(device, "p")
dlen = Builtins.size(device)
dlen = pos if pos != nil
elsif Builtins.search(device, "/dev/dasd") == 0
dlen = Builtins.size(device)
if Builtins.findfirstof(device, "0123456789") != nil
dlen = Ops.subtract(dlen, 1)
end
elsif Builtins.search(device, "/dev/mapper/") == 0
regex = "[_-]part[0-9]+$"
l = Builtins.regexppos(device, regex)
if Ops.greater_than(Builtins.size(l), 0)
dlen = Ops.get_integer(l, 0, 0)
else
dlen = Builtins.size(device)
end
else
as_string = true
if Ops.greater_or_equal(Builtins.size(ls), 3)
pos = Builtins.findlastof(device, "/")
dlen = pos if pos != nil
else
dlen = Builtins.size(device)
nonzero = Builtins.findlastnotof(device, "0123456789")
if nonzero != nil && Ops.less_than(nonzero, Ops.subtract(dlen, 1))
dlen = Ops.add(nonzero, 1)
as_string = false
end
end
end
tmp = {}
Ops.set(tmp, "disk", Builtins.substring(device, 0, dlen))
device = Builtins.substring(device, dlen)
if Builtins.search(device, "-part") == 0
device = Builtins.substring(device, 5)
end
if Ops.greater_than(Builtins.size(device), 0) &&
Builtins.findfirstof(device, "/p") == 0
device = Builtins.substring(device, 1)
end
Ops.set(tmp, "nr", -1)
if as_string
Ops.set(tmp, "nr", device)
else
if Ops.greater_than(Builtins.size(device), 0)
Ops.set(tmp, "nr", Builtins.tointeger(device))
end
end
if Ops.greater_than(Builtins.size(Ops.get_string(tmp, "disk", "")), 0) &&
Ops.get(tmp, "nr", 1) == -1
Ops.set(tmp, "nr", "")
end
if Ops.greater_than(Builtins.size(tg), 0) &&
!Builtins.haskey(tg, Ops.get_string(tmp, "disk", ""))
Builtins.y2milestone("GetDiskPartitionTg tmp: %1", tmp)
r = {}
if (
r_ref = arg_ref(r);
_GetContVolInfo_result = GetContVolInfo(inpdev, r_ref);
r = r_ref.value;
_GetContVolInfo_result
)
Builtins.y2milestone("GetDiskPartitionTg rtmp: %1", r)
if Builtins.haskey(tg, Ops.get_string(r, "cdevice", ""))
Ops.set(tmp, "disk", Ops.get_string(r, "cdevice", ""))
if Ops.get_integer(r, "num", -1) != -1
Ops.set(tmp, "nr", Ops.get_integer(r, "num", -1))
else
Ops.set(tmp, "nr", Ops.get_string(r, "vname", ""))
end
end
end
end
ret = [tmp]
else
ret = [{ "disk" => "/dev/nfs", "nr" => device }]
end
Builtins.y2debug("GetDiskPartitionTg device: %1 ret: %2", device, ret)
deep_copy(ret)
end
# Returns map describing the disk partition
#
# @param [String] device
# @return [Hash] DiskPartition
#
# Examples:
# "/dev/sda" -> $[ "disk" : "/dev/sda", "nr" : "" ]
# "/dev/sda2" -> $[ "disk" : "/dev/sda", "nr" : 2 ]
# "/dev/system" -> $[ "disk" : "/dev/system", "nr" : "" ]
# "/dev/system/abuild" -> $[ "disk" : "/dev/system", "nr" : "abuild" ]
def GetDiskPartition(device)
Ops.get(GetDiskPartitionTg(device, GetTargetMap()), 0, {})
end
def UpdateChangeTime
change_time = ::Time.now.to_i
Builtins.y2milestone("UpdateChangeTime time %1", change_time)
Ops.set(@StorageMap, "targets_time", change_time)
nil
end
# return list of partitions of map <tg>
def GetPartitionLst(tg, device)
tg = deep_copy(tg)
ret = []
tmp = GetDiskPartitionTg(device, tg)
Builtins.y2milestone("GetPartitionLst tmp: %1", tmp)
Builtins.foreach(tmp) do |m|
disk = Ops.get_string(m, "disk", "")
if Builtins.search(device, "/dev/evms") == 0 &&
!Builtins.haskey(tg, disk)
disk = "/dev/evms"
end
Builtins.y2debug("GetPartitionLst device=%1 disk=%2", device, disk)
part = Builtins.filter(Ops.get_list(tg, [disk, "partitions"], [])) do |p|
Ops.get_string(p, "device", "") == device
end
part = Builtins.filter(part) { |p| !Ops.get_boolean(p, "delete", false) }
if Builtins.size(part) == 0 && Ops.is_integer?(Ops.get(m, "nr", 0))
part = Builtins.filter(Ops.get_list(tg, [disk, "partitions"], [])) do |p|
Ops.get_integer(p, "nr", -1) == Ops.get_integer(m, "nr", 0)
end
part = Builtins.filter(part) do |p|
!Ops.get_boolean(p, "delete", false)
end
end
if Builtins.size(part) == 0
part = Builtins.filter(Ops.get_list(tg, [disk, "partitions"], [])) do |p|
Ops.get_string(p, "name", "") == Ops.get_string(m, "nr", "")
end
part = Builtins.filter(part) do |p|
!Ops.get_boolean(p, "delete", false)
end
end
pa = Ops.get(part, 0, {})
if Builtins.size(pa) == 0 &&
Builtins.search(device, "/dev/mapper/") == 0
part = Builtins.filter(
Ops.get_list(tg, ["/dev/mapper", "partitions"], [])
) { |p| Ops.get_string(p, "device", "") == device }
pa = Ops.get(part, 0, {})
end
if Builtins.size(pa) == 0 &&
Builtins.search(device, "/dev/mapper/") == 0
part = Builtins.filter(
Ops.get_list(tg, ["/dev/loop", "partitions"], [])
) { |p| Ops.get_string(p, "device", "") == device }
pa = Ops.get(part, 0, {})
end
ret = Builtins.add(ret, pa) if Ops.greater_than(Builtins.size(pa), 0)
end
Builtins.y2debug("GetPartitionLst ret=%1", ret)
deep_copy(ret)
end
def GetPartition(tg, device)
tg = deep_copy(tg)
Convert.convert(
Ops.get(GetPartitionLst(tg, device), 0, {}),
:from => "map",
:to => "map <string, any>"
)
end
# Returns disk identified by 'device' taken from the 'tg' (target) map
#
# @param [Hash{String => map}] tg (target map)
# @param [String] device
def GetDisk(tg, device)
tg = deep_copy(tg)
ret = {}
tmp = Ops.get(GetDiskPartitionTg(device, tg), 0, {})
disk = Ops.get_string(tmp, "disk", "")
if Builtins.search(device, "/dev/evms") == 0 && !Builtins.haskey(tg, disk)
disk = "/dev/evms"
end
Builtins.y2debug("GetDisk disk=%1", disk)
Convert.convert(
Ops.get(tg, disk, {}),
:from => "map",
:to => "map <string, any>"
)
end
# Get List of swap partitions
# @return [Array] List of swap partitions
def SwappingPartitions
SCR.UnmountAgent(path(".proc.swaps"))
swaps = Convert.convert(
SCR.Read(path(".proc.swaps")),
:from => "any",
:to => "list <map>"
)
if swaps == nil
Builtins.y2error("SCR::Read(.proc.swaps) returned nil")
Builtins.y2milestone(
"/proc/swaps is %1",
SCR.Execute(path(".target.bash_output"), "cat /proc/swaps")
)
swaps = []
end
swaps = Builtins.filter(swaps) do |e|
Ops.get_string(e, "type", "") == "partition"
end
ret = Builtins.maplist(swaps) do |e|
Partitions.TranslateMapperName(Ops.get_string(e, "file", ""))
end
Builtins.y2milestone("SwappingPartitions %1", ret)
deep_copy(ret)
end
def GetFreeInfo(device, get_resize, resize_info, get_content, content_info, use_cache)
resize_info.value = {}
content_info.value = {}
tmp1 = ::Storage::ResizeInfo.new()
tmp2 = ::Storage::ContentInfo.new()
ret = @sint.getFreeInfo(device, get_resize, tmp1, get_content,
tmp2, use_cache)
if ret
if get_resize
resize_info.value = {
:df_free_k => tmp1.df_freeK,
:resize_free_k => tmp1.resize_freeK,
:used_k => tmp1.usedK,
:resize_ok => tmp1.resize_ok
}
end
if get_content
content_info.value = {
:windows => tmp2.windows,
:efi => tmp2.efi,
:homes => tmp2.homes
}
end
end
Builtins.y2milestone("GetFreeInfo device: %1 ret: %2", device, ret)
ret
end
# Returns map of free space per partition
#
# @param [String] device
# @param integer testsize
# @param [Symbol] used_fs
# @param [Boolean] verbose
def GetFreeSpace(device, used_fs, verbose)
resize_info = {}
content_info = {}
r = (
resize_info_ref = arg_ref(resize_info);
content_info_ref = arg_ref(content_info);
_GetFreeInfo_result = GetFreeInfo(
device,
true,
resize_info_ref,
true,
content_info_ref,
used_fs == :ntfs
);
resize_info = resize_info_ref.value;
content_info = content_info_ref.value;
_GetFreeInfo_result
)
used = 1024*Ops.get_integer(resize_info, :used_k, 0)
resize_free = 1024*Ops.get_integer(resize_info, :resize_free_k, 0)
df_free = 1024*Ops.get_integer(resize_info, :df_free_k, 0)
resize_ok = Ops.get_boolean(resize_info, :resize_ok, false)
win_disk = Ops.get_boolean(content_info, :windows, false)
efi = Ops.get_boolean(content_info, :efi, false)
if used_fs == :ntfs && (!r || !resize_ok) && verbose
cmd = Builtins.sformat("/usr/sbin/ntfsresize -f -i '%1'", device)
Builtins.y2milestone("GetFreeSpace Executing cmd: %1", cmd)
bcall = Convert.to_map(
SCR.Execute(
path(".target.bash_output"),
cmd,
{ "LC_MESSAGES" => "POSIX" }
)
)
Builtins.y2milestone("GetFreeSpace Executing ret: %1", bcall)
tmp = _("Resize Not Possible:") + "\n\n"
tmp = Ops.add(
Ops.add(tmp, Ops.get_string(bcall, "stdout", "")),
Ops.get_string(bcall, "stderr", "")
)
Popup.Error(tmp)
return {}
end