Class: Yast::KdumpClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Kdump.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



196
197
198
199
# File '../../src/modules/Kdump.rb', line 196

def Abort
  return @AbortFunction.call == true if @AbortFunction != nil
  false
end

- (Object) AddDeviceVgamode(section)



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File '../../src/modules/Kdump.rb', line 249

def AddDeviceVgamode(section)
  section = deep_copy(section)
  tmp_boot_section = Builtins.tostring(Ops.get(section, "append"))
  # adding root device
  tmp_boot_section = Ops.add(
    Ops.add(tmp_boot_section, " root="),
    Builtins.tostring(Ops.get(section, "root"))
  )
  tmp_boot_section = Ops.add(
    Ops.add(tmp_boot_section, " vga="),
    Builtins.tostring(Ops.get(section, "vgamode"))
  )

  Builtins.splitstring(tmp_boot_section, " ")
end

- (Object) AddPackages

Adding necessary packages for installation



1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File '../../src/modules/Kdump.rb', line 1065

def AddPackages
  if Mode.installation
    @kdump_packages = Builtins.add(@kdump_packages, "kexec-tools")
    @kdump_packages = Builtins.add(@kdump_packages, "yast2-kdump")
    if Arch.ppc64
      @kdump_packages = Builtins.add(@kdump_packages, "kernel-kdump")
    else
      @kdump_packages = Builtins.add(@kdump_packages, "kdump")
    end
  end

  nil
end

- (Object) BuildCrashkernelValue

Build crashkernel value from alocated memory

@return [String] value of crashkernel



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
# File '../../src/modules/Kdump.rb', line 497

def BuildCrashkernelValue
  # if user doesn't modified or select don't modify
  # return readed value
  return @crashkernel_param_value if @crashkernel_list_ranges

  crash_value = ""
  crash_value = Ops.add(@alocated_memory, "M")

  # bnc#563905 problem with offset in crashkernel
  if Arch.i386 || Arch.x86_64 || Arch.ia64 || Arch.ppc64
    Builtins.y2milestone(
      "i386, x86_64, ia64 and ppc64 platforms are without offset"
    )
  else
    if Mode.normal
      Popup.Error(
        _("Unsupported architecture, \"crashkernel\" was not added")
      )
    end
    Builtins.y2error("Unsupported platform/architecture...")
  end

  reserved_memory = Builtins.tostring(
    Ops.multiply(2, Builtins.tointeger(@alocated_memory))
  )


  crash_value = Ops.add(Ops.add(reserved_memory, "M-:"), crash_value)
  Builtins.y2milestone("builded crashkernel value is %1", crash_value)
  crash_value
end

- (Object) CheckPackages

Check if user enabled kdump if no deselect packages for installing if yes add necessary packages for installation



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
# File '../../src/modules/Kdump.rb', line 1104

def CheckPackages
  # remove duplicates
  @kdump_packages = Builtins.toset(@kdump_packages)
  if !@add_crashkernel_param
    Builtins.y2milestone(
      "deselect packages for installation: %1",
      @kdump_packages
    )
    pkg_deselect = false
    Builtins.foreach(@kdump_packages) do |p|
      PackagesProposal.RemoveResolvables("yast2-kdump", :package, [p])
      pkg_deselect = true
    end
    if pkg_deselect
      Builtins.y2milestone(
        "Deselected kdump packages for installation: %1",
        @kdump_packages
      )
    end
  else
    Builtins.y2milestone(
      "select packages for installation: %1",
      @kdump_packages
    )
    pkg_added = false
    Builtins.foreach(@kdump_packages) do |p|
      PackagesProposal.AddResolvables("yast2-kdump", :package, [p])
      pkg_added = true
    end
    if pkg_added
      Builtins.y2milestone(
        "Selected kdump packages for installation: %1",
        @kdump_packages
      )
    end
  end

  nil
end

- (Boolean) checkPassword

Function check if KDUMP_SAVEDIR or KDUMP_SMTP_PASSWORD include password

Returns:

  • (Boolean)

    true if inlude password



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
# File '../../src/modules/Kdump.rb', line 431

def checkPassword
  return true if Ops.get(@KDUMP_SETTINGS, "KDUMP_SMTP_PASSWORD", "") != ""

  if Builtins.search(Ops.get(@KDUMP_SETTINGS, "KDUMP_SAVEDIR", ""), "file") != nil ||
      Builtins.search(Ops.get(@KDUMP_SETTINGS, "KDUMP_SAVEDIR", ""), "nfs") != nil ||
      Ops.get(@KDUMP_SETTINGS, "KDUMP_SAVEDIR", "") == ""
    return false
  end

  if Builtins.search(Ops.get(@KDUMP_SETTINGS, "KDUMP_SAVEDIR", ""), "@") == nil
    return false
  end

  temp = Builtins.splitstring(
    Ops.get(@KDUMP_SETTINGS, "KDUMP_SAVEDIR", ""),
    "@"
  )
  temp_1 = Ops.get(temp, 0, "")
  position = Builtins.findlastof(temp_1, ":")
  return false if position == nil

  # if there is 2 times ":" -> it means that password is defined
  # for example cifs://login:password@server....
  if Ops.greater_than(position, 6)
    return true
  else
    return false
  end
end

- (Object) CheckXenDefault(act_boot_secion)

Check if default boot section is Xen section remember position of section (important for saving to xen_append)

Parameters:

  • string

    name of section



558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File '../../src/modules/Kdump.rb', line 558

def CheckXenDefault(act_boot_secion)
  if act_boot_secion != "" && act_boot_secion != nil
    section_position = -1
    Builtins.foreach(BootCommon.sections) do |section|
      section_position = Ops.add(section_position, 1)
      name = Builtins.tostring(Ops.get(section, "name"))
      type = Builtins.tostring(Ops.get(section, "type"))
      if name == act_boot_secion && type == "xen"
        @section_pos = section_position
        Builtins.y2milestone("default boot section is Xen...")
      end
    end
    if @section_pos == -1
      Builtins.y2milestone("default boot section is NOT Xen...")
    end
  end

  nil
end

- (Boolean) Chmod(target, permissions)

Function set permission for file.

FileUtils::Chmod (“/etc/sysconfig/kdump”, “600”) -> true FileUtils::Chmod ("/tmp/doesnt_exist", "644") -> false

Parameters:

  • string

    file name

  • permissions (String)

Returns:

  • (Boolean)

    true on success



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File '../../src/modules/Kdump.rb', line 274

def Chmod(target, permissions)
  if !FileUtils.Exists(target)
    Builtins.y2error("Target %1 doesn't exist", target)
    return false
  end

  if !FileUtils.Exists("/bin/chmod")
    Builtins.y2error("tool: /bin/chmod not found")
    return false
  end

  cmd = Builtins.sformat("/bin/chmod %1 %2", permissions, target)
  cmd_out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))

  if Ops.get_integer(cmd_out, "exit", -1) != 0
    Builtins.y2error("Command >%1< returned %2", cmd, cmd_out)
    return false
  end
  Builtins.y2milestone("Command: %1 finish successful.", cmd)
  true
end

- (Object) CmpKernelAndBootOptions(kernel_option, boot_options)

Compare boot section options with

options from running kernel @return [Fixnum] return number of differences



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File '../../src/modules/Kdump.rb', line 223

def CmpKernelAndBootOptions(kernel_option, boot_options)
  kernel_option = deep_copy(kernel_option)
  boot_options = deep_copy(boot_options)
  result = Builtins.size(kernel_option)
  dif_size = Ops.subtract(
    Builtins.size(boot_options),
    Builtins.size(kernel_option)
  )
  dif_size = Ops.multiply(dif_size, -1) if Ops.less_than(dif_size, 0)
  Builtins.foreach(kernel_option) do |option|
    if Builtins.contains(boot_options, option)
      result = Ops.subtract(result, 1)
    end
  end

  result = Ops.add(result, dif_size)
  result
end

- (Object) convertCrashkernelForXEN(crash)



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File '../../src/modules/Kdump.rb', line 536

def convertCrashkernelForXEN(crash)
  crash_value = ""
  if crash != ""
    crash_value = Ops.add(getAlocatedMemory(crash), "M") 
    # bnc#563905 problem with offset in crashkernel
    #if ((Arch::i386()) ||(Arch::x86_64()) || Arch::ppc64())
    #	crash_value = crash_value + "@16M";
  end
  Builtins.y2milestone(
    "Converting crashkernel value from: (%1) to :(%2)",
    crash,
    crash_value
  )
  crash_value
end

- (Object) Export

Export kdump settings to a map

Returns:

  • kdump settings



1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
# File '../../src/modules/Kdump.rb', line 1229

def Export
  out = {
    "crash_kernel"     => BuildCrashkernelValue(),
    "add_crash_kernel" => @add_crashkernel_param,
    "general"          => filterExport(@KDUMP_SETTINGS)
  }

  Builtins.y2milestone("Kdump exporting settings: %1", out)
  deep_copy(out)
end

- (Hash{String => String}) filterExport(settings)

bnc# 480466 - fix problem with validation autoyast profil Function filters keys for autoyast profil

Parameters:

  • map (string, string)

    KDUMP_SETTINGS

Returns:

  • (Hash{String => String})

    filtered KDUMP_SETTINGS by DEFAULT_CONFIG



1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
# File '../../src/modules/Kdump.rb', line 1212

def filterExport(settings)
  settings = deep_copy(settings)
  ret = {}
  keys = Convert.convert(
    Map.Keys(@DEFAULT_CONFIG),
    :from => "list",
    :to   => "list <string>"
  )
  ret = Builtins.filter(settings) do |key, value|
    next true if Builtins.contains(keys, key)
  end

  deep_copy(ret)
end

- (Object) GetActualBootSection



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
# File '../../src/modules/Kdump.rb', line 302

def GetActualBootSection
  # read option from bootlaoder

  result = ""
  kernel_boot_options = ""
  min_dif_size = 1000
  if Mode.update
    result = Bootloader.getDefaultSection
    section_position = -1
    Builtins.foreach(BootCommon.sections) do |section|
      section_position = Ops.add(section_position, 1)
      name = Builtins.tostring(Ops.get(section, "name"))
      if name == result && Ops.get(section, "xen_append") != nil
        @section_pos = section_position
        @kernel_version = "xen"
      end
    end
    return result
  end

  # reading bootloader settings
  old_progress = Progress.set(false)
  Bootloader.Read
  Progress.set(old_progress)

  # reading kernel options
  command = "cat /proc/cmdline"
  options = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), command)
  )
  Builtins.y2milestone(
    "[kdump] (GetActualBootSection) command read boot options from kernel:  %1  output: %2",
    command,
    options
  )

  return "" if Ops.get(options, "exit") != 0

  kernel_boot_options = Builtins.tostring(Ops.get(options, "stdout"))

  # reading version of kernel
  command = "uname -r"
  options = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), command)
  )
  Builtins.y2milestone(
    "[kdump] (GetActualBootSection) command read kernel version:  %1  output: %2",
    command,
    options
  )

  return "" if Ops.get(options, "exit") != 0

  @kernel_version = Builtins.tostring(Ops.get(options, "stdout"))
  Builtins.y2milestone(
    "[kdump] (GetActualBootSection) kerne version: %1",
    @kernel_version
  )

  # boot sections from bootloader
  sects = deep_copy(BootCommon.sections)

  # deleting non linux sections
  sects = Builtins.filter(sects) { |s| !Builtins.haskey(s, "chainloader") }

  Builtins.y2milestone(
    "[kdump] (GetActualBootSection) BootCommon::sections only linux sections:  %1",
    sects
  )

  # find probably boot section, what was used during start-up
  Builtins.foreach(sects) do |section|
    image = Builtins.tostring(Ops.get(section, "image"))
    if image != nil
      command = Ops.add("/sbin/get_kernel_version ", image)
      options = Convert.to_map(
        SCR.Execute(path(".target.bash_output"), command)
      )

      if Ops.get(options, "exit") == 0
        ret = Builtins.tostring(Ops.get(options, "stdout"))

        if ret == @kernel_version
          #Popup::Message("hura!");
          value = CmpKernelAndBootOptions(
            Builtins.splitstring(kernel_boot_options, " "),
            AddDeviceVgamode(section)
          )
          if Ops.less_than(value, min_dif_size)
            min_dif_size = value
            result = Builtins.tostring(Ops.get(section, "name"))
          end
        end # end if (ret == kernel_version)
      end # end if (options["exit"]:nil ==  0)
    end # end of if (image != nil)
  end # end of foreach(map section, sects, {

  Builtins.y2milestone(
    "[kdump] (GetActualBootSection) selected boot section :  %1",
    result
  )
  result
end

- (Object) getAlocatedMemory(crash_value)

get alocated memory from value of crashkernel option there can be several ranges -> take the first range @param string 64M@16M or 128M-:64M@16M [(reserved_memory*2)-:reserved_memory] @return [String] value of alocated memory (64M)



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
# File '../../src/modules/Kdump.rb', line 467

def getAlocatedMemory(crash_value)
  result = ""
  allocated = ""
  range = ""
  if Builtins.search(crash_value, ",") != nil
    ranges = Builtins.splitstring(crash_value, ",")
    @crashkernel_list_ranges = true
    range = Ops.get(ranges, 0, "")
  else
    range = crash_value
  end
  Builtins.y2milestone("The 1st range from crashkernel is %1", range)
  position = Builtins.search(range, ":")

  if position != nil
    allocated = Builtins.substring(range, Ops.add(position, 1))
  else
    allocated = range
  end

  result = Builtins.substring(allocated, 0, Builtins.search(allocated, "M"))

  Builtins.y2milestone("Allocated memory is %1", result)
  result
end

- (Object) getCrashKernelValue(crash)

get value of crashkernel option from XEN boot section @param string crashkernel=64M@16M @return [String] value of carshkernel option



411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File '../../src/modules/Kdump.rb', line 411

def getCrashKernelValue(crash)
  Builtins.y2milestone("crashkernel option %1", crash)
  result = ""
  if crash != "" || crash != nil
    position = Builtins.search(crash, "=")
    if position != nil
      result = Builtins.substring(crash, Ops.add(position, 1))
    else
      Builtins.y2error("Wrong crashkernel option!")
    end
  end
  Builtins.y2milestone("crashkernel value is %1", result)
  result
end

- (Object) GetModified

Data was modified?

Returns:

  • true if modified



203
204
205
206
# File '../../src/modules/Kdump.rb', line 203

def GetModified
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Boolean) Import(settings)

Import settings from a map

Parameters:

  • settings (Hash)

    map of kdump settings

Returns:

  • (Boolean)

    true on success



1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
# File '../../src/modules/Kdump.rb', line 1243

def Import(settings)
  settings = deep_copy(settings)
  Builtins.y2milestone("Importing settings for kdump")
  @crashkernel_param_value = Ops.get_string(settings, "crash_kernel", "")
  @add_crashkernel_param = Ops.get_boolean(
    settings,
    "add_crash_kernel",
    false
  )
  result = true
  my_import_map = Ops.get_map(settings, "general", {})
  Builtins.foreach(Map.Keys(@DEFAULT_CONFIG)) do |key|
    str_key = Builtins.tostring(key)
    val = Ops.get(my_import_map, str_key)
    Ops.set(@KDUMP_SETTINGS, str_key, val) if val != nil
    if val == nil
      Ops.set(@KDUMP_SETTINGS, str_key, Ops.get(@DEFAULT_CONFIG, str_key))
    end
  end
  if Builtins.haskey(settings, "crash_kernel") ||
      Builtins.haskey(settings, "add_crash_kernel") ||
      Ops.greater_than(Builtins.size(my_import_map), 0)
    @import_called = true
  end
  result
end

- (Object) main



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
# File '../../src/modules/Kdump.rb', line 35

def main
  textdomain "kdump"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "BootCommon"
  #import "Storage";
  Yast.import "Map"
  Yast.import "Bootloader"
  Yast.import "Service"
  Yast.import "Popup"
  Yast.import "Arch"
  Yast.import "Mode"
  Yast.import "ProductControl"
  Yast.import "ProductFeatures"
  Yast.import "PackagesProposal"
  Yast.import "FileUtils"

  # Data was modified?
  @modified = false

  # kdump config file

  @kdump_file = "/etc/sysconfig/kdump"



  @proposal_valid = false

  # List of available partiotions
  # with known partition
  #
  # list <string>
  @available_partitions = []

  # true if propose was called
  @propose_called = false

  # List of available partiotions
  # without filesystem or with uknown
  #
  # list <string>
  @uknown_fs_partitions = []

  # Total available memory [MB]
  #
  #
  # integer
  @total_memory = 0

  # Boolean option indicates that "crashkernel" includes
  #  several ranges
  #
  # boolean true if there are several ranges (>1)
  @crashkernel_list_ranges = false


  #  list of packages for installation
  @kdump_packages = []

  # Number of cpus
  #
  # integer
  @number_of_cpus = 1

  # kernel version (uname -r)
  #
  # string
  @kernel_version = ""


  # Position actual boot section in BootCommon::sections list
  # it is relevant only if XEN boot section is used
  #
  # integer
  @section_pos = -1


  # Boolean option indicates kernel parameter
  # "crashkernel"
  #
  # boolean true if kernel parameter is set
  @crashkernel_param = false

  # String option indicates value of kernel parameter
  # "crashkernel"
  #
  # string value of kernel parameter
  @crashkernel_param_value = ""

  # Boolean option indicates add kernel param
  # "crashkernel"
  #
  # boolean true if kernel parameter will be add
  @add_crashkernel_param = false


  # String option for alocate of memory for boot param
  # "crashkernel"
  #
  # string value number of alocate memory
  @alocated_memory = "0"

  # Boolean option indicates that Import()
  # was called and data was proposed
  #
  # boolean true if import was called with data

  @import_called = false


  # String option identify which boot section was used
  # during boot process
  #
  # string value actual boot section

  @actual_boot_section = ""


  # Write only, used during autoinstallation.
  # Don't run services and SuSEconfig, it's all done at one place.
  @write_only = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = nil

  # map of deafult values for options in UI
  #
  # global map <string, string >

  @DEFAULT_CONFIG = {
    "KDUMP_KERNELVER"          => "",
    "KDUMP_COMMANDLINE"        => "",
    "KDUMP_COMMANDLINE_APPEND" => "",
    "KEXEC_OPTIONS"            => "",
    "KDUMP_IMMEDIATE_REBOOT"   => "yes",
    "KDUMP_COPY_KERNEL"        => "yes",
    "KDUMP_TRANSFER"           => "",
    "KDUMP_SAVEDIR"            => "file:///var/crash",
    "KDUMP_KEEP_OLD_DUMPS"     => "5",
    "KDUMP_FREE_DISK_SIZE"     => "64",
    "KDUMP_VERBOSE"            => "3",
    "KDUMP_DUMPLEVEL"          => "0",
    "KDUMP_DUMPFORMAT"         => "compressed", #or "ELF"
    "KDUMP_SMTP_SERVER"        => "",
    "KDUMP_SMTP_USER"          => "",
    "KDUMP_SMTP_PASSWORD"      => "",
    "KDUMP_NOTIFICATION_TO"    => "",
    "KDUMP_NOTIFICATION_CC"    => ""
  }

  # map <string, string > of kdump settings
  #
  @KDUMP_SETTINGS = {}
end

- (Object) Propose

Propose all kdump settings



1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
# File '../../src/modules/Kdump.rb', line 1146

def Propose
  Builtins.y2milestone("Proposing new settings of kdump")
  # read available memory
  ReadAvailableMemory()
  # set default values for global variables
  ProposeGlobalVars()

  # add packages for installation
  AddPackages()

  # select packages for installation
  CheckPackages()

  nil
end

- (Object) ProposeAlocatedMemory

Propose reserved/allocated memory

@return [Boolean] successfull



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
# File '../../src/modules/Kdump.rb', line 670

def ProposeAlocatedMemory
  if @alocated_memory == "0"
    if Ops.greater_or_equal(@total_memory, 512) &&
        Ops.less_than(Ops.divide(@total_memory, 1024), 2)
      @alocated_memory = "64"
    elsif Ops.greater_or_equal(Ops.divide(@total_memory, 1024), 2)
      @alocated_memory = "128"
    end

    # bnc #431492 - UPT-LTE: /proc/vmcore is empty in kdump kerne
    if Arch.ppc64 && @alocated_memory != ""
      al_mem = Builtins.tointeger(@alocated_memory)
      al_mem = Ops.multiply(al_mem, 2)
      @alocated_memory = Builtins.tostring(al_mem)
    end
    # bnc #446480 - Fine-tune kdump memory proposal
    if Arch.ia64 && Ops.greater_or_equal(@total_memory, 1024)
      total_memory_gigabyte = Ops.divide(@total_memory, 1024)
      if Ops.greater_or_equal(total_memory_gigabyte, 1) &&
          Ops.less_than(total_memory_gigabyte, 8)
        @alocated_memory = "256"
      elsif Ops.greater_or_equal(total_memory_gigabyte, 8) &&
          Ops.less_than(total_memory_gigabyte, 128)
        @alocated_memory = "512"
      elsif Ops.greater_or_equal(total_memory_gigabyte, 128) &&
          Ops.less_than(total_memory_gigabyte, 256)
        @alocated_memory = "768"
      elsif Ops.greater_or_equal(total_memory_gigabyte, 256) &&
          Ops.less_than(total_memory_gigabyte, 378)
        @alocated_memory = "1024"
      elsif Ops.greater_or_equal(total_memory_gigabyte, 378) &&
          Ops.less_than(total_memory_gigabyte, 512)
        @alocated_memory = "1536"
      elsif Ops.greater_or_equal(total_memory_gigabyte, 512) &&
          Ops.less_than(total_memory_gigabyte, 768)
        @alocated_memory = "2048"
      elsif Ops.greater_or_equal(total_memory_gigabyte, 768)
        @alocated_memory = "3072"
      end
    end
  end
  Builtins.y2milestone(
    "[kdump] allocated memory if not set in \"crashkernel\" param: %1",
    @alocated_memory
  )
  true
end

- (Object) ProposeGlobalVars

Propose global variables once… after that remember user settings



1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File '../../src/modules/Kdump.rb', line 1082

def ProposeGlobalVars
  if !@propose_called
    # propose disable kdump if PC has less than 1024MB RAM
    if Ops.less_than(@total_memory, 1024)
      @add_crashkernel_param = false
    else
      @add_crashkernel_param = true
    end

    @crashkernel_param = false
    # added defualt settings
    @KDUMP_SETTINGS = deep_copy(@DEFAULT_CONFIG)
  end
  @propose_called = true

  nil
end

- (Object) Read

Read all kdump settings

Returns:

  • true on success



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
# File '../../src/modules/Kdump.rb', line 920

def Read
  # Kdump read dialog caption
  caption = _("Initializing kdump Configuration")
  steps = 4

  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/4
      _("Reading the config file..."),
      # Progress stage 3/4
      _("Reading kernel boot options..."),
      # Progress stage 4/4
      _("Reading available memory...")
    ],
    [
      # Progress step 1/4
      _("Reading the config file..."),
      # Progress step 2/4
      _("Reading partitions of disks..."),
      # Progress finished 3/4
      _("Reading available memory..."),
      # Progress finished 4/4
      Message.Finished
    ],
    ""
  )

  # read database
  return false if Abort()
  Progress.NextStage
  # Error message
  if !ReadKdumpSettings()
    Report.Error(_("Cannot read config file /etc/sysconfig/kdump"))
  end

  # read another database
  return false if Abort()
  Progress.NextStep
  # Error message
  if !ReadKdumpKernelParam()
    Report.Error(_("Cannot read kernel boot options."))
  end

  # read another database
  return false if Abort()
  Progress.NextStep
  # Error message
  Report.Error(_("Cannot read available memory.")) if !ReadAvailableMemory()

  return false if Abort()
  # Progress finished
  Progress.NextStage

  return false if Abort()
  @modified = false
  true
end

- (Object) ReadAvailableMemory

Read available memory

@return [Boolean] successfull



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
# File '../../src/modules/Kdump.rb', line 723

def ReadAvailableMemory
  output = Convert.convert(
    SCR.Read(path(".probe.memory")),
    :from => "any",
    :to   => "list <map>"
  )
  Builtins.y2milestone(
    "[kdump] (ReadAvailableMemory) SCR::Read(.probe.memory): %1",
    output
  )

  resor = {}
  temp = Builtins.maplist(output) { |mem| Ops.get(mem, "resource") }
  #y2milestone("[kdump] (ReadAvailableMemory) temp: %1", temp);
  resor = Builtins.tomap(Ops.get(temp, 0))

  output = Convert.convert(
    Ops.get(resor, "phys_mem"),
    :from => "any",
    :to   => "list <map>"
  )
  temp = Builtins.maplist(output) { |mem| Ops.get(mem, "range") }
  #list <any> range = maplist(map resor["phys_mem"]:nil);

  #resor = (map)range;
  @total_memory = Ops.divide(Builtins.tointeger(Ops.get(temp, 0)), 1048576)
  Builtins.y2milestone(
    "[kdump] (ReadAvailableMemory) total phys. memory [MB]: %1",
    Builtins.tostring(@total_memory)
  )
  ProposeAlocatedMemory()
  true
end

- (Object) ReadKdumpKernelParam

Read current kdump configuration

read kernel parameter “crashkernel” @return [Boolean] successfull



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
# File '../../src/modules/Kdump.rb', line 634

def ReadKdumpKernelParam
  @actual_boot_section = GetActualBootSection()

  if Builtins.search(@kernel_version, "xen") != nil
    return ReadXenKdumpKernelParam(@actual_boot_section)
  end


  if @actual_boot_section == ""
    @actual_boot_section = Bootloader.getDefaultSection
  end

  result = Bootloader.getKernelParam(@actual_boot_section, "crashkernel")

  #Popup::Message(result);
  if result == "false"
    @crashkernel_param = false
    @add_crashkernel_param = false
  else
    @crashkernel_param = true
    @add_crashkernel_param = true
  end

  @crashkernel_param_value = result
  if result != "false"
    @alocated_memory = getAlocatedMemory(@crashkernel_param_value)
  end

  true
end

- (Object) ReadKdumpSettings

Read current kdump configuration

@return [Boolean] successfull



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
# File '../../src/modules/Kdump.rb', line 762

def ReadKdumpSettings
  @KDUMP_SETTINGS = deep_copy(@DEFAULT_CONFIG)
  Builtins.foreach(SCR.Dir(path(".sysconfig.kdump"))) do |key|
    val = Convert.to_string(
      SCR.Read(Builtins.add(path(".sysconfig.kdump"), key))
    )
    Ops.set(@KDUMP_SETTINGS, key, val) if val != nil
  end

  debug_KDUMP_SETTINGS = deep_copy(@KDUMP_SETTINGS)

  # delete KDUMP_SAVEDIR - it can include password
  Ops.set(debug_KDUMP_SETTINGS, "KDUMP_SAVEDIR", "********")
  Ops.set(debug_KDUMP_SETTINGS, "KDUMP_SMTP_PASSWORD", "********")
  Builtins.y2milestone("-------------KDUMP_SETTINGS-------------------")
  Builtins.y2milestone(
    "kdump configuration has been read without value \"KDUMP_SAVEDIR\" and \"KDUMP_SMTP_PASSWORD\": %1",
    debug_KDUMP_SETTINGS
  )
  Builtins.y2milestone("---------------------------------------------")

  true
end

- (Object) ReadXenKdumpKernelParam(act_boot_secion)



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
# File '../../src/modules/Kdump.rb', line 584

def ReadXenKdumpKernelParam(act_boot_secion)
  crash = ""
  if @actual_boot_section == ""
    Builtins.y2milestone("Actual boot section was not found")
    @crashkernel_param = false
    @add_crashkernel_param = false
  else
    section_position = -1
    Builtins.foreach(BootCommon.sections) do |section|
      section_position = Ops.add(section_position, 1)
      name = Builtins.tostring(Ops.get(section, "name"))
      if name == act_boot_secion
        crash = Ops.get_string(section, "xen_append", "")
        @section_pos = section_position
      end
    end
  end

  if crash != ""
    xen_append = Builtins.splitstring(crash, " ")
    crash_arg = ""

    if Ops.greater_than(Builtins.size(xen_append), 1)
      Builtins.foreach(xen_append) do |key|
        crash_arg = key if Builtins.search(key, "crashkernel") != nil
      end
    else
      crash_arg = crash
    end

    if crash_arg != ""
      @crashkernel_param = true
      @add_crashkernel_param = true
      @crashkernel_param_value = getCrashKernelValue(crash_arg)
      @alocated_memory = getAlocatedMemory(@crashkernel_param_value)
    else
      @crashkernel_param = false
      @add_crashkernel_param = false
    end
  end

  true
end

- (Object) SetModified

Set data was modified



210
211
212
213
214
215
# File '../../src/modules/Kdump.rb', line 210

def SetModified
  @modified = true
  Builtins.y2debug("modified=%1", @modified)

  nil
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
# File '../../src/modules/Kdump.rb', line 1164

def Summary
  result = []
  result = Builtins.add(
    result,
    Builtins.sformat(
      _("Kdump status: %1"),
      @add_crashkernel_param ? _("enabled") : _("disabled")
    )
  )
  if @add_crashkernel_param
    result = Builtins.add(
      result,
      Builtins.sformat(
        _("Value of crashkernel option: %1"),
        BuildCrashkernelValue()
      )
    )
    result = Builtins.add(
      result,
      Builtins.sformat(
        _("Dump format: %1"),
        Ops.get(@KDUMP_SETTINGS, "KDUMP_DUMPFORMAT", "")
      )
    )
    result = Builtins.add(
      result,
      Builtins.sformat(
        _("Target of dumps: %1"),
        Ops.get(@KDUMP_SETTINGS, "KDUMP_SAVEDIR", "")
      )
    )
    result = Builtins.add(
      result,
      Builtins.sformat(
        _("Number of dumps: %1"),
        Ops.get(@KDUMP_SETTINGS, "KDUMP_KEEP_OLD_DUMPS", "")
      )
    )
  end
  deep_copy(result)
end

- (Object) Update

Update crashkernel argument during update of OS

Returns:

  • true on success



984
985
986
987
988
989
# File '../../src/modules/Kdump.rb', line 984

def Update
  Builtins.y2milestone("Update kdump settings")
  ReadKdumpKernelParam()
  WriteKdumpBootParameter()
  true
end

- (Object) Write

Write all kdump settings

Returns:

  • true on success



994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
# File '../../src/modules/Kdump.rb', line 994

def Write
  # Kdump read dialog caption
  caption = _("Saving kdump Configuration")

  #number of stages
  steps = 2
  if Mode.installation
    write_kdump = ProductFeatures.GetBooleanFeature(
      "globals",
      "enable_kdump"
    )
    if write_kdump == nil || !write_kdump
      Builtins.y2milestone("Installation doesn't support kdump.")
      return true
    end
  end

  if (Mode.installation || Mode.autoinst) && !@add_crashkernel_param
    Builtins.y2milestone(
      "Skip writing of configuration for kdump during installation"
    )
    return true
  end

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Write the settings"),
      # Progress stage 2/2
      _("Update boot options")
    ],
    [
      # Progress step 1/2
      _("Writing the settings..."),
      # Progress step 2/2
      _("Updating boot options..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # write settings
  return false if Abort()
  Progress.NextStage
  # Error message
  Report.Error(_("Cannot write settings.")) if !WriteKdumpSettings()

  # write/delete bootloader option for kernel "crashkernel"
  return false if Abort()
  Progress.NextStage
  # Error message
  if !WriteKdumpBootParameter()
    Report.Error(_("Adding crashkernel parameter to bootloader fault."))
  end

  return false if Abort()
  # Progress finished
  Progress.NextStage

  return false if Abort()
  true
end

- (Object) WriteKdumpBootParameter

Write kdump boot argument crashkernel set kernel-kdump start at boot

@return [Boolean] successfull



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
# File '../../src/modules/Kdump.rb', line 825

def WriteKdumpBootParameter
  result = true
  old_progress = false
  if Mode.installation
    Bootloader.Read
    @actual_boot_section = Bootloader.getDefaultSection
    CheckXenDefault(@actual_boot_section)
  end

  Builtins.y2milestone("Default boot section is %1", @actual_boot_section)
  if @add_crashkernel_param
    crash_value = ""
    crash_value = BuildCrashkernelValue() if !Mode.autoinst

    if !@crashkernel_param || crash_value != @crashkernel_param_value
      crash_value = @crashkernel_param_value if Mode.autoinst

      if Mode.update
        if Builtins.search(crash_value, "@") != nil
          tmp_crash_value = Builtins.splitstring(crash_value, "@")
          crash_value = Ops.get(tmp_crash_value, 0, "")
          Builtins.y2milestone(
            "Delete offset crashkernel value: %1",
            crash_value
          )
        end
      end

      # write crashkernel option to boot section
      if @section_pos == -1
        result = Bootloader.setKernelParam(
          @actual_boot_section,
          "crashkernel",
          crash_value
        )
      else
        Ops.set(
          BootCommon.sections,
          [@section_pos, "xen_append"],
          Ops.add("crashkernel=", convertCrashkernelForXEN(crash_value))
        )
        # added flag which means that section was changed bnc #432651
        Ops.set(BootCommon.sections, [@section_pos, "__changed"], true)
        result = true
        Builtins.y2milestone(
          "Write boot section to XEN boot section %1",
          Ops.get(BootCommon.sections, @section_pos)
        )
      end
      old_progress = Progress.set(false)
      Bootloader.Write
      Progress.set(old_progress)
      # Popup::Message(crash_value);
      Builtins.y2milestone(
        "[kdump] (WriteKdumpBootParameter) adding chrashkernel option with value : %1",
        crash_value
      )
      if Mode.normal
        Popup.Message(_("To apply changes a reboot is necessary."))
      end

      Service.Enable("boot.kdump")
      return result
    end

    # start kernel-kdump at boot
    Service.Enable("boot.kdump")

    Service.Restart("boot.kdump") if Service.Status("boot.kdump") == 0
  else
    if @crashkernel_param
      #delete crashkernel paramter from bootloader
      result = Bootloader.setKernelParam(
        @actual_boot_section,
        "crashkernel",
        "false"
      )
      old_progress = Progress.set(false)
      Bootloader.Write
      Progress.set(old_progress)
      if Mode.normal
        Popup.Message(_("To apply changes a reboot is necessary."))
      end
    end
    Service.Disable("boot.kdump")
    Service.Stop("boot.kdump") if Service.Status("boot.kdump") == 0
    return result
  end
  true
end

- (Object) WriteKdumpSettings

Write current kdump configuration

@return [Boolean] successfull



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
# File '../../src/modules/Kdump.rb', line 791

def WriteKdumpSettings
  debug_KDUMP_SETTINGS = deep_copy(@KDUMP_SETTINGS)
  # delete KDUMP_SAVEDIR - it can include password
  Ops.set(debug_KDUMP_SETTINGS, "KDUMP_SAVEDIR", "********")
  Ops.set(debug_KDUMP_SETTINGS, "KDUMP_SMTP_PASSWORD", "********")
  Builtins.y2milestone("-------------KDUMP_SETTINGS-------------------")
  Builtins.y2milestone(
    "kdump configuration for writing without value \"KDUMP_SAVEDIR\" and \"KDUMP_SMTP_PASSWORD\": %1",
    debug_KDUMP_SETTINGS
  )
  Builtins.y2milestone("---------------------------------------------")

  Builtins.foreach(@KDUMP_SETTINGS) do |option_key, option_val|
    SCR.Write(
      Builtins.add(path(".sysconfig.kdump"), option_key),
      option_val
    )
  end
  SCR.Write(path(".sysconfig.kdump"), nil)


  if checkPassword
    Chmod(@kdump_file, "600")
  else
    Chmod(@kdump_file, "644")
  end
  true
end