home *** CD-ROM | disk | FTP | other *** search
- /**
- * File: modules/AutoinstRAID.ycp
- * Module: Auto-Installation
- * Summary: RAID
- * Authors: Anas Nashif <nashif@suse.de>
- *
- * $Id: AutoinstRAID.ycp 27288 2006-01-24 14:29:15Z ug $
- */
- {
-
- module "AutoinstRAID";
- textdomain "autoinst";
-
- import "Storage";
- import "Partitions";
- import "AutoinstStorage";
-
- include "partitioning/partition_defines.ycp";
- include "partitioning/raid_lib.ycp";
-
-
- global map<string, map> ExistingRAID = $[];
-
- global boolean old_available = false;
-
-
-
- map raid = $[];
-
- // Local variables
- list region = [0,0];
-
- // Temporary copy of variable from Storage
- map<string, map> targetMap = $[];
-
-
- /**
- * Constructor
- * @return void
- */
- global define void AutoinstRAID () {
- return;
- }
-
- /**
- * Initialize
- */
- global boolean Init ()
- {
- raid = filter(string k, map v,
- AutoinstStorage::AutoTargetMap, ``(k == "/dev/md"));
-
- if (size(raid) == 0)
- {
- return false;
- }
-
- ExistingRAID = filter(string k,map v, Storage::GetTargetMap(), ``(k == "/dev/md"));
- y2milestone("Existing RAID: %1", ExistingRAID );
-
- if (size(ExistingRAID) > 0 )
- old_available = true;
-
- return true;
- }
-
- /**
- * Return existing MDs
- * @return list list of existing MDs
- */
- global define list ExistingMDs ( string md ) {
- return(filter( map part, get_possible_rds( Storage::GetTargetMap() ),
- ``( part["raid_name"]:"-1" == md )));
- }
-
-
- /**
- * Return deleted MDs
- * @return list list of deleted MDs
- */
- global define list DeletedMDs ( string md ) {
- list<list<map> > ret = [];
- foreach( string dev, map devmap, Storage::GetTargetMap(),
- ``{
- ret = add( ret,
- filter( map part, devmap["partitions"]:[],
- ``(
- part["raid_name"]:"" == md
- &&
- part["delete"]:false
- &&
- part["fsid"]:0 == Partitions::fsid_raid
- )
- )
- );
- });
-
- return( flatten(ret) );
- }
-
-
- /**
- * Delete MDs
- * @return list list of deleted MDs
- */
- global define list DeleteMDs () {
- list to_bo_deleted = [];
- foreach( string dev, map devmap, Storage::GetTargetMap(), ``{
- foreach( map part, devmap["partitions"]:[], ``{
- if (part["old_raid_name"]:"" != "" && part["delete"]:false)
- {
- to_bo_deleted= add(to_bo_deleted, part["old_raid_name"]:"");
- }
- });
- });
-
- y2milestone("mds to delete: %1", to_bo_deleted);
-
- if (old_available)
- {
- list<map> mds = Storage::GetTargetMap()["/dev/md","partitions"]:[];
- list<map> new_mds = maplist( map md, mds ,``{
- if ( contains(to_bo_deleted, md["device"]:""))
- {
- md["delete"] = true;
- }
- return (md);
- });
- y2milestone("new_mds: %1", new_mds );
- map allmds = targetMap["/dev/md"]:$[];
- allmds["partitions"] = new_mds;
- targetMap["/dev/md"] = allmds;
- Storage::SetTargetMap(targetMap);
- }
- }
-
-
-
- define boolean remove_possible_mds () {
-
- boolean prefer_remove = raid["/dev/md", "prefer_remove"]:false;
- if (old_available && prefer_remove)
- {
- list<map> existing_mds = ExistingRAID["/dev/md","partitions"]:[];
- list<map> modified_mds = maplist( map md, existing_mds ,``{
- md["delete"] = true;
- return (md);
- });
- map<string, any> allmds = (map<string, any>)ExistingRAID["/dev/md"]:$[];
- allmds["partitions"] = modified_mds;
- map<string,map> tg = Storage::GetTargetMap();
- tg["/dev/md"] = allmds;
- Storage::SetTargetMap(tg);
- // update our variable
- ExistingRAID["/dev/md"] = allmds;
- }
- return true;
- }
-
- /**
- * Create RAID Configuration
- * @return boolean
- */
- global define boolean Write() {
-
- remove_possible_mds ();
- list<map> raid_partitions = raid["/dev/md", "partitions"]:[];
-
- list<map> RaidList = maplist ( map md, raid_partitions, ``{
- string use = raid["/dev/md","use"]:"none";
- string dev = sformat("/dev/md%1", md["partition_nr"]:0);
- md["device"] = dev;
-
-
- if (md["enc_type"]:`none!=`none )
- {
- Storage::SetCryptPwd( dev, md["crypt_key"]:"" );
- }
- y2milestone("Working on %1", md);
-
-
- integer chunk_size = 4;
- map options = md["raid_options"]:$[];
- string raid_type = options["raid_type"]:"raid1";
-
- if ( raid_type == "raid5" )
- {
- chunk_size = 128;
- }
- if ( raid_type == "raid0" )
- {
- chunk_size = 32;
- }
-
-
- if (!haskey(options, "raid_type"))
- {
- options["raid_type"] = raid_type;
- }
-
- integer sel_chunksize = tointeger(options["chunk_size"]:"0");
-
- if ( sel_chunksize != 0 )
- {
- chunk_size = sel_chunksize;
- options["chunk_size"] = chunk_size;
- }
-
-
- if( raid_type == "raid5" && options["parity_algorithm"]:"" == "" )
- {
- options["parity_algorithm"] = "left_symmetric";
- }
-
- md["nr"] = md["partition_nr"]:0;
-
-
- if (!haskey(md, "create"))
- {
- md["create"] = true;
- md["status"] = "create";
- }
-
- if (!haskey(md, "format"))
- {
- md["format"] = false;
- }
-
- if (md["format"]:false)
- {
- md["used_fs"] = md["filesystem"]:`ext2;
- }
-
- md["type"] = `sw_raid;
- if (haskey(md, "raid_options"))
- md=remove(md, "raid_options");
- md["devices"] = AutoinstStorage::raid2device[md["device"]:""]:[];
- return (union(md, options));
- });
-
- list allraid = [];
- if (size (ExistingRAID["/dev/md","partitions"]:[]) > 0 )
- {
- allraid = union (ExistingRAID["/dev/md", "partitions"]:[], RaidList );
- }
- else
- {
- allraid = RaidList;
- }
- y2milestone("All RAID: %1", allraid);
-
-
- map<string, any> RaidMap =
- $[
- "partitions" : allraid,
- "type" : `CT_MD
- ];
- y2milestone("RaidMap: %1", RaidMap);
-
- map<string,map> tg = Storage::GetTargetMap();
- tg["/dev/md"] = RaidMap;
- Storage::SetTargetMap(tg);
- y2milestone("Targets: %1", Storage::GetTargetMap());
- return true;
- }
-
-
- }
-
-