Class: Yast::ModuleLoadingClass

Inherits:
Module
  • Object
show all
Defined in:
library/system/src/modules/ModuleLoading.rb

Instance Method Summary collapse

Instance Method Details

#Load(modulename, moduleargs, vendorname, devicename, ask_before_loading, with_modprobe) ⇒ Symbol

load a module if not already loaded by linuxrc

Parameters:

  • modulename (String)
  • moduleargs (String)
  • vendorname (String)
  • devicename (String)
  • ask_before_loading (Boolean)
  • with_modprobe (Boolean)

Returns:

  • (Symbol)

    : dont user choose *not* to load module ok module loaded ok `fail module loading failed



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
# File 'library/system/src/modules/ModuleLoading.rb', line 126

def Load(modulename, moduleargs, vendorname, devicename, ask_before_loading, with_modprobe)
  if modulename != "" &&
      # there is no reason for checking initrd, if I need the module to get loaded, I just  need to
      # check if it isn't already loaded
      #      && (!contains (Initrd::ListModules (), modulename))
      !Mode.test
    # always look whether the module is already loaded
    loaded_modules = Convert.to_map(SCR.Read(path(".proc.modules")))
    if Ops.greater_than(
      Builtins.size(Ops.get_map(loaded_modules, modulename, {})),
      0
    )
      # already loaded
      return :ok
    end

    # sformat( _("Loading module %1"), modulename);

    # #97655
    if MarkedAsBroken(modulename)
      Builtins.y2milestone("In BrokenModules, skipping: %1", modulename)
      return :dont
    end

    if ask_before_loading && !Mode.autoinst && !Mode.autoupgrade
      UI.OpenDialog(
        Opt(:decorated, :centered),
        HBox(
          HSpacing(1),
          HCenter(
            HSquash(
              VBox(
                HCenter(
                  HSquash(
                    VBox(
                      # Popup-Box for manual driver installation.
                      # If the user selects 'manual installation' when
                      # booting from CD, YaST2 does not load any modules
                      # automatically, but asks the user for confirmation
                      # about every module.
                      # The popup box informs the user about the detected
                      # hardware and suggests a module to load.
                      # The user can confirm the module or change
                      # the suggested load command
                      #
                      # This is the heading of the popup box
                      HBox(
                        # bnc #421002
                        Icon.Simple("question"),
                        Heading(_("Confirm driver activation")),
                        HStretch()
                      ),
                      VSpacing(0.2),
                      # This is in information message. Next come the
                      # vendor and device information strings as stored
                      # in the hardware-probing database.
                      Left(Label(_("YaST2 detected the following device"))),
                      Left(Label(vendorname)),
                      Left(Label(devicename)),
                      VSpacing(0.1),
                      Left(
                        # Caption for Textentry with module information
                        InputField(
                          Id(:mod_name),
                          Opt(:hstretch),
                          _("&Driver/Module to load"),
                          Ops.add(Ops.add(modulename, " "), moduleargs)
                        )
                      )
                    )
                  )
                ),
                ButtonBox(
                  PushButton(
                    Id(:ok_msg),
                    Opt(:default, :okButton, :key_F10),
                    Label.OKButton
                  ),
                  PushButton(
                    Id(:cancel_msg),
                    Opt(:cancelButton, :key_F9),
                    Label.CancelButton
                  )
                ),
                VSpacing(0.2)
              )
            )
          ),
          HSpacing(1)
        )
      )
      UI.SetFocus(Id(:ok_msg))
      ret = Convert.to_symbol(UI.UserInput)
      if ret == :ok_msg
        module_data = Convert.to_string(
          UI.QueryWidget(Id(:mod_name), :Value)
        )
        if Ops.greater_than(Builtins.size(module_data), 0)
          # skip leading spaces
          firstspace = Builtins.findfirstnotof(module_data, " ")
          module_data = Builtins.substring(module_data, firstspace) if !firstspace.nil?

          # split name and args
          firstspace = Builtins.findfirstof(module_data, " ")

          if firstspace.nil?
            modulename = module_data
            moduleargs = ""
          else
            modulename = Builtins.substring(module_data, 0, firstspace)
            moduleargs = Builtins.substring(
              module_data,
              Ops.add(firstspace, 1)
            )
          end
        end
      end
      UI.CloseDialog

      if ret == :cancel_msg
        Builtins.y2milestone(
          "NOT loaded module %1 %2",
          modulename,
          moduleargs
        )
        return :dont
      end
    end
  end

  load_success = if with_modprobe
    Convert.to_boolean(
      SCR.Execute(path(".target.modprobe"), modulename, moduleargs)
    )
  else
    Convert.to_boolean(
      SCR.Execute(path(".target.insmod"), modulename, moduleargs)
    )
  end
  load_success = false if load_success.nil?

  Builtins.y2milestone(
    "Loaded module %1 %2 %3",
    modulename,
    moduleargs,
    load_success ? "Ok" : "Failed"
  )

  load_success ? :ok : :fail
end

#mainObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'library/system/src/modules/ModuleLoading.rb', line 34

def main
  Yast.import "UI"

  textdomain "base"

  Yast.import "Mode"
  Yast.import "Label"
  Yast.import "Icon"

  @vendor_name = ""
  @device_name = ""

  # Cache for MarkedAsBroken
  @broken_modules = nil
end

#MarkedAsBroken(mod) ⇒ Object

Is the module marked as broken in install.inf? (BrokenModules)

97655

Parameters:

Returns:

  • broken?



101
102
103
104
105
106
107
108
109
110
111
# File 'library/system/src/modules/ModuleLoading.rb', line 101

def MarkedAsBroken(mod)
  if @broken_modules.nil?
    bms = Convert.to_string(
      SCR.Read(path(".etc.install_inf.BrokenModules"))
    )
    bms = "" if bms.nil?
    @broken_modules = Builtins.splitstring(bms, " ")
  end

  Builtins.contains(@broken_modules, mod)
end

#prepareVendorDeviceInfo(controller) ⇒ Array

Convert internal probing data to user readable string for module loading.

Parameters:

  • controller (Hash)

Returns:

  • (Array)

    [string vendor, string device]

See Also:

  • Yast::ModuleLoadingClass#ModuleLoading#ModuleLoading::Load


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
# File 'library/system/src/modules/ModuleLoading.rb', line 56

def prepareVendorDeviceInfo(controller)
  controller = deep_copy(controller)
  # build up vendor/device information

  # if vendor not given, try sub_vendor

  controller_vendor = Ops.get_string(
    controller,
    "vendor",
    Ops.get_string(controller, "sub_vendor", "")
  )
  if controller_vendor != ""
    controller_sub_vendor = Ops.get_string(controller, "sub_vendor", "")
    if controller_sub_vendor != ""
      controller_vendor = Ops.add(
        Ops.add(Ops.add(controller_vendor, "\n("), controller_sub_vendor),
        ")"
      )
    end
  end

  # if device not given, try sub_device

  controller_device = Ops.get_string(
    controller,
    "device",
    Ops.get_string(controller, "sub_device", "")
  )
  if controller_device != ""
    controller_sub_device = Ops.get_string(controller, "sub_device", "")
    if controller_sub_device != ""
      controller_device = Ops.add(
        Ops.add(Ops.add(controller_device, "\n("), controller_sub_device),
        ")"
      )
    end
  end

  [controller_vendor, controller_device]
end