Class: Yast::KdumpClass

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

Constant Summary

FADUMP_KEY =
"KDUMP_FADUMP"
TEMPORARY_CONFIG_FILE =
"/var/lib/YaST2/kdump.sysconfig"
PROPOSE_ALLOCATED_MEMORY_MB_COMMAND =
"kdumptool --configfile #{TEMPORARY_CONFIG_FILE} calibrate"
PROPOSE_ALLOCATED_MEMORY_MB_FALLBACK =

if the command fails

"128"

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



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

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

- (Object) AddDeviceVgamode(section)



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File '../../src/modules/Kdump.rb', line 255

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



1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
# File '../../src/modules/Kdump.rb', line 1087

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 allocated memory

@return [String] value of crashkernel



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

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(@allocated_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(@allocated_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



1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
# File '../../src/modules/Kdump.rb', line 1126

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



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

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



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File '../../src/modules/Kdump.rb', line 564

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



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File '../../src/modules/Kdump.rb', line 280

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



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File '../../src/modules/Kdump.rb', line 229

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)



542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File '../../src/modules/Kdump.rb', line 542

def convertCrashkernelForXEN(crash)
  crash_value = ""
  if crash != ""
    crash_value = Ops.add(getAllocatedMemory(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



1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
# File '../../src/modules/Kdump.rb', line 1251

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

- (Boolean) fadump_supported?

Returns whether FADump (Firmware assisted dump) is supported by the current system

Returns:

  • (Boolean)

    is supported



1296
1297
1298
# File '../../src/modules/Kdump.rb', line 1296

def fadump_supported?
  Arch.ppc64
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



1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
# File '../../src/modules/Kdump.rb', line 1234

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



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

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) getAllocatedMemory(crash_value)

get allocated 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 allocated memory (64M)



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

def getAllocatedMemory(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



417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File '../../src/modules/Kdump.rb', line 417

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



209
210
211
212
# File '../../src/modules/Kdump.rb', line 209

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



1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
# File '../../src/modules/Kdump.rb', line 1265

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



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

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"
  Yast.import "Directory"

  # 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
  @allocated_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 = {}

  # initial kdump settings replaced in Read function
  @initial_kdump_settings = deep_copy(@KDUMP_SETTINGS)
end

- (Object) Propose

Propose all kdump settings



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
# File '../../src/modules/Kdump.rb', line 1168

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

- (Boolean) ProposeAllocatedMemory

Propose reserved/allocated memory Store the result as a string! to @allocated_memory

Returns:

  • (Boolean)

    true, always successful



689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File '../../src/modules/Kdump.rb', line 689

def ProposeAllocatedMemory
  # only propose once
  return true if @allocated_memory != "0"

  write_temporary_config_file
  out = SCR.Execute(path(".target.bash_output"), PROPOSE_ALLOCATED_MEMORY_MB_COMMAND)
  @allocated_memory = out["stdout"].chomp
  if out["exit"] != 0 or @allocated_memory.empty?
    # stderr has been already logged
    Builtins.y2error("failed to propose allocated memory")
    @allocated_memory = PROPOSE_ALLOCATED_MEMORY_MB_FALLBACK
  end
  Builtins.y2milestone(
    "[kdump] allocated memory if not set in \"crashkernel\" param: %1",
    @allocated_memory
  )
  true
end

- (Object) ProposeGlobalVars

Propose global variables once… after that remember user settings



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
# File '../../src/modules/Kdump.rb', line 1104

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



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

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



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

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)
  )
  ProposeAllocatedMemory()
  true
end

- (Object) ReadKdumpKernelParam

Read current kdump configuration

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



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

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"
    @allocated_memory = getAllocatedMemory(@crashkernel_param_value)
  end

  true
end

- (Object) ReadKdumpSettings

Read current kdump configuration

@return [Boolean] successfull



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

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("---------------------------------------------")

  @initial_kdump_settings = deep_copy(@KDUMP_SETTINGS)

  true
end

- (Object) ReadXenKdumpKernelParam(act_boot_secion)



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

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)
      @allocated_memory = getAllocatedMemory(@crashkernel_param_value)
    else
      @crashkernel_param = false
      @add_crashkernel_param = false
    end
  end

  true
end

- (Object) SetModified

Set data was modified



216
217
218
219
220
221
# File '../../src/modules/Kdump.rb', line 216

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



1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
# File '../../src/modules/Kdump.rb', line 1186

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



1003
1004
1005
1006
1007
1008
# File '../../src/modules/Kdump.rb', line 1003

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

- (Boolean) update_initrd

Updates initrd and reports whether it was successful. Failed update is reported using Report library.

Returns:

  • (Boolean)

    whether successful



782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# File '../../src/modules/Kdump.rb', line 782

def update_initrd
  # See FATE#315780
  # See https://www.suse.com/support/kb/doc.php?id=7012786
  update_command = (using_fadump? ? "mkdumprd -f" : "mkinitrd")
  update_logfile = File.join(Directory.vardir, "y2logmkinitrd")

  run_command = update_command + " >> #{update_logfile} 2>&1"
  y2milestone("Running command: #{run_command}")
  ret = SCR.Execute(path(".target.bash"), run_command)

  if ret != 0
    y2error("Error updating initrd, see #{update_logfile} or call {update_command} manually")
    Report.Error(_(
      "Error updating initrd while calling '%{cmd}'.\n" +
      "See %{log} for details."
    ) % { :cmd => update_command, :log => update_logfile })
    return false
  end

  true
end

- (Boolean) use_fadump(new_value)

Sets whether to use FADump (Firmware assisted dump)

Parameters:

  • new (Boolean)

    state

Returns:

  • (Boolean)

    whether successfully set



1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
# File '../../src/modules/Kdump.rb', line 1304

def use_fadump(new_value)
  # Trying to use fadump on unsupported hardware
  if !fadump_supported? && new_value
    Builtins.y2milestone("FADump is not supported on this hardware")
    Report.Error(_("Cannot use Firmware-assisted dump.\nIt is not supported on this hardware."))
    return false
  end

  @KDUMP_SETTINGS[FADUMP_KEY] = (new_value ? "yes" : "no")
  true
end

- (Boolean) using_fadump?

Returns whether FADump (Firmware assisted dump) is currently in use

Returns:

  • (Boolean)

    currently in use



1319
1320
1321
# File '../../src/modules/Kdump.rb', line 1319

def using_fadump?
  @KDUMP_SETTINGS[FADUMP_KEY] == "yes"
end

- (Boolean) using_fadump_changed?

Has the using_fadump? been changed?

Returns:

  • (Boolean)

    whether changed



1326
1327
1328
# File '../../src/modules/Kdump.rb', line 1326

def using_fadump_changed?
  @initial_kdump_settings[FADUMP_KEY] != @KDUMP_SETTINGS[FADUMP_KEY]
end

- (Object) Write

Write all kdump settings

Returns:

  • true on success



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
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
# File '../../src/modules/Kdump.rb', line 1013

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
  if ! WriteKdumpSettings()
    Report.Error(_("Cannot write settings."))
    return false
  end

  # 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) write_temporary_config_file



673
674
675
676
677
678
679
680
# File '../../src/modules/Kdump.rb', line 673

def write_temporary_config_file
  # FIXME parameterize Write instead of copying the old config
  # NOTE make sure we do not lose 600 mode (cp is ok)
  command = "cp #{@kdump_file} #{TEMPORARY_CONFIG_FILE}"
  retcode = SCR.Execute(path(".target.bash"), command)
  # if this fails the system is broken; SCR has logged the details
  raise "cannot copy files" if retcode != 0
end

- (Object) WriteKdumpBootParameter

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

@return [Boolean] successfull



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

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



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

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 using_fadump_changed? && ! update_initrd
    return false
  end

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