-
Notifications
You must be signed in to change notification settings - Fork 14
/
StorageControllers.ycp
389 lines (323 loc) · 10.3 KB
/
StorageControllers.ycp
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
/*
* Copyright (c) 2012 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.
*/
/**
* Module: StorageControllers.ycp
*
* Authors: Klaus Kaempf <kkaempf@suse.de> (initial)
*
* Purpose:
* This module does all floppy disk related stuff:
* - Detect the floppy devices
*
* SCR: Read(.probe.storage)
*
* $Id$
*/
{
module "StorageControllers";
import "Arch";
import "ModuleLoading";
import "HwStatus";
import "Initrd";
import "Storage";
import "StorageDevices";
import "StorageClients";
import "Linuxrc";
textdomain "storage";
// list of loaded modules and arguments
// needed for modules.conf writing
// must be kept in order (-> no map !)
// must be searchable (-> separate lists for names and args)
list<string> moduleNames = [];
list<string> moduleArgs = [];
list<list> ModToInitrdLx = [];
list<list> ModToInitrd = [];
list<map> controllers = []; // set by "Probe"
/**
* Probe storage controllers
* probing, loading modules
*
* @returns integer number of controllers, 0 = none found
*/
global integer Probe()
{
y2milestone( "StorageControllers::Probe()" );
// probe 'storage' list
controllers = (list<map>)SCR::Read (.probe.storage);
if (!Arch::s390 () && size (controllers) == 0)
{
y2milestone("no controllers");
}
return size (controllers);
}
// start a controller (by loading its module)
// return true if all necessary modules were actually loaded
// return false if loading failed or was not necessary at all
boolean StartController(map controller)
{
// check module information
// skip controller if no module info available
list<map> module_drivers = controller["drivers"]:[];
if (size (module_drivers) == 0)
return false;
// get list of modules from /proc/modules
SCR::UnmountAgent (.proc.modules);
map loaded_modules = (map)SCR::Read(.proc.modules);
// loop through all drivers checking if one is already active
// or if one is already listed in /proc/modules
boolean already_active = false;
foreach (map modulemap, module_drivers,
``{
if( modulemap["active"]:true ||
size( loaded_modules[modulemap["modules",0,0]:""]:$[] ) > 0 )
{
already_active = true;
if( modulemap["active"]:true )
{
ModToInitrdLx = add( ModToInitrdLx,
[ modulemap["modules",0,0]:"",
modulemap["modules",0,1]:"" ] );
y2milestone( "startController ModToInitrdLx %1", ModToInitrdLx );
y2milestone( "startController ModToInitrd %1", ModToInitrd );
}
}
});
// save unique key for HwStatus::Set()
string unique_key = controller["unique_key"]:"";
if (already_active)
{
HwStatus::Set (unique_key, `yes);
return false;
}
boolean stop_loading = false;
boolean one_module_failed = false;
// loop through all drivers defined for this controller
// break after first successful load
// no need to check "active", already done before !
foreach (map modulemap, module_drivers,
``{
y2milestone ("startController modulemap: %1", modulemap);
boolean module_modprobe = modulemap["modprobe"]:false;
boolean all_modules_loaded = true;
if (!stop_loading)
{
foreach (list module_entry, modulemap["modules"]:[],
``{
string module_name = module_entry[0]:"";
string module_args = module_entry[1]:"";
// load module if not yet loaded
if( !contains (moduleNames, module_name) )
{
symbol load_result = `ok;
if( Linuxrc::manual () )
{
list vendor_device =
ModuleLoading::prepareVendorDeviceInfo(controller);
load_result =
ModuleLoading::Load( module_name, module_args,
vendor_device[0]:"",
vendor_device[1]:"", true,
module_modprobe );
}
else
{
load_result =
ModuleLoading::Load( module_name, module_args,
"", "", false,
module_modprobe );
}
y2milestone( "startController load_result %1", load_result );
if (load_result == `fail)
{
all_modules_loaded = false;
}
else if (load_result == `dont)
{
all_modules_loaded = true;
}
else // load ok
{
// save data for modules.conf writing
moduleNames = add (moduleNames, module_name);
moduleArgs = add (moduleArgs, module_args);
y2milestone( "startController moduleNames %1", moduleNames );
y2milestone( "startController moduleArgs %1", moduleArgs );
ModToInitrd = add( ModToInitrd, [ module_name,
module_args ] );
y2milestone( "startController ModToInitrd %1", ModToInitrd );
y2milestone( "startController ModToInitrdLx %1", ModToInitrdLx );
}
} // not yet loaded
// break out of module load loop if one module failed
if (!all_modules_loaded)
{
one_module_failed = true;
}
}); // foreach module of current driver info
} // stop_loading
// break out of driver load loop if all modules of
// the current driver loaded successfully
if (all_modules_loaded)
{
stop_loading = true;
}
}); // foreach driver
HwStatus::Set (unique_key, one_module_failed?`no:`yes);
return !one_module_failed;
}
// local function to go through list of resources (list of maps)
// checking if '"active":true' is set.
boolean AnyActive(list<map> resources)
{
boolean active = size(resources)==0;
foreach (map res, resources,
``{
if (res["active"]:false)
active = true;
});
return active;
}
/**
* Start storage related USB and FireWire stuff
*
*/
global void StartHotplugStorage()
{
import "Hotplug";
// If USB capable, there might be an usb storage device (i.e. ZIP)
// activate the module _last_ since it might interfere with other
// controllers (i.e. having usb-storage first might result in
// /dev/sda == zip which is bad if the zip drive is removed :-}).
if (Hotplug::haveUSB)
{
// if loading of usb-storage is successful, re-probe for floppies
// again since USB ZIP drives are regarded as floppies.
if (ModuleLoading::Load ("usb-storage", "", "", "USB Storage", Linuxrc::manual (), true) == `ok)
{
StorageDevices::FloppyReady();
}
}
if (Hotplug::haveFireWire)
{
// load sbp2
ModuleLoading::Load ("sbp2", "", "", "SBP2 Protocol", Linuxrc::manual (), true);
}
}
/**
* @param none
* @returns void
* Init storage controllers (module loading)
* Must have called StorageControllers::probe() before !
// O: list of [ loaded modules, module argument ]
*/
global void Initialize()
{
moduleNames = [];
moduleArgs = [];
integer cindex = 0;
boolean module_loaded = false;
ModToInitrd = [];
ModToInitrdLx = [];
y2milestone("Initialize controllers: %1", controllers);
// loop through all controller descriptions from hwprobe
// use while(), continue not allowed in foreach()
while( !Arch::s390() && cindex < size(controllers) )
{
map controller = controllers[cindex]:$[];
y2milestone( "Initialize controller %1", controller );
if( !isempty(controller["requires"]:[]) )
{
Storage::AddHwPackages( controller["requires"]:[] );
}
cindex = cindex + 1;
// check BIOS resources on 'wintel' compatible systems
if (Arch::board_wintel ())
{
// for every controller it is checked whether
// the controller is disabled in BIOS
// this is done by checking for an active IO or memory resource
if( !(AnyActive (controller["resource", "io"]:[])
|| AnyActive (controller["resource", "mem"]:[])))
{
y2milestone( "Initialize controller %1 disabled in BIOS",
controller["device"]:"" );
// continue if disabled in BIOS
continue;
}
}
module_loaded = StartController(controller) || module_loaded;
} // while (controller)
y2milestone( "Initialize module_loaded %1", module_loaded );
y2milestone( "Initialize ModToInitrdLx %1 ModToInitrd %2 ", ModToInitrdLx,
ModToInitrd );
ModToInitrd = (list<list>)union( ModToInitrdLx, ModToInitrd );
y2milestone( "Initialize ModToInitrd %1", ModToInitrd );
if( size(ModToInitrd)>1 )
{
list<string> ls = filter( string s,
splitstring( (string)SCR::Read( .etc.install_inf.InitrdModules ),
" " ),
``(size(s)>0) );
y2milestone( "Initialize ls=%1", ls );
integer i = 0;
map lrmods = listmap( string s, ls, ``{i=i+1; return( $[ s : i ] );});
y2milestone( "Initialize lrmods=%1", lrmods );
i = 0;
while( i<size(ModToInitrd) )
{
integer j=i+1;
while( j<size(ModToInitrd) )
{
if( haskey( lrmods, ModToInitrd[i,0]:"" ) &&
haskey( lrmods, ModToInitrd[j,0]:"" ) &&
lrmods[ModToInitrd[i,0]:""]:0 >
lrmods[ModToInitrd[j,0]:""]:0 )
{
list tmp = ModToInitrd[i]:[];
ModToInitrd[i] = ModToInitrd[j]:[];
ModToInitrd[j] = tmp;
}
j = j+1;
}
i=i+1;
}
y2milestone( "Initialize ModToInitrd %1", ModToInitrd );
}
foreach( list s, ModToInitrd,
``{
Initrd::AddModule( s[0]:"", s[1]:"" );
});
// load all raid personalities
SCR::Execute(.target.modprobe, "raid0", "" );
SCR::Execute(.target.modprobe, "raid1", "" );
SCR::Execute(.target.modprobe, "raid5", "");
SCR::Execute(.target.modprobe, "raid6", "");
SCR::Execute(.target.modprobe, "raid10", "");
SCR::Execute(.target.modprobe, "multipath", "" );
StartHotplugStorage();
y2milestone("Initialize all controllers initialized module_loaded:%1", module_loaded);
StorageDevices::InitDone();
if( module_loaded )
Storage::ReReadTargetMap();
y2milestone( "Initialize calling EnablePopup()" );
StorageClients::EnablePopup();
};
}