home *** CD-ROM | disk | FTP | other *** search
- /**
- * File:
- * lvm_config_ui.ycp
- *
- * Module:
- * configuration of lvm in installed system
- * Summary:
- *
- * Authors:
- * mike <mike@suse.de>
- *
- * $Id: lvm_config_ui.ycp 33002 2006-09-20 10:28:09Z fehr $
- *
- *
- *----------------------------------------------------
- * IMPORTANT: when you read this code notice:
- *
- * vg = volume group
- * vgs = volume groups
- *
- * pv = physical volume
- * pvs = physical volumes
- *
- * lv = logical volume
- * lvs = logical volumes
- *----------------------------------------------------
- *
- */
- {
- import "Arch";
- import "Storage";
- import "FileSystems";
- import "Partitions";
- import "Mode";
-
- textdomain "storage";
-
- import "Popup";
- include "partitioning/partition_defines.ycp";
- include "partitioning/custom_part_dialogs.ycp";
- include "partitioning/custom_part_lib.ycp";
- include "partitioning/custom_part_helptexts.ycp";
- include "partitioning/custom_part_dialogs.ycp";
- include "partitioning/lvm_ui_dialogs.ycp";
- include "partitioning/lvm_ui_lib.ycp";
- include "partitioning/lvm_lib.ycp";
- include "partitioning/lvm_lv_lib.ycp";
- include "partitioning/lvm_pv_lib.ycp";
-
-
-
- define boolean CheckItemIsNotMounted( string id )
- ``{
- y2milestone( "CheckItemIsNotMounted id:%1", id );
- boolean ret = true;
- if( size(id)>0 )
- {
- string device = id;
- string cmd = "mount | grep \"^" + device + " \"";
- y2milestone( "mounts cmd=%1", cmd );
- map bo = (map)SCR::Execute(.target.bash_output, cmd);
- string line = bo["stdout"]:"";
- y2milestone( "mounts line=%1", line );
- ret = size(line)<size(device);
- if( !ret )
- {
- line = substring( line, search( line, "on " )+3 );
- y2milestone( "mounts line=%1", line );
- line = substring( line, 0, findfirstof( line, " " ) );
- y2milestone( "mounts line=%1", line );
- // popup text, %1 is device name. %2 is mount point.
- Popup::Message(sformat(_("Device %1 is already mounted at %2.
- A mounted file system cannot be added to a volume group."),
- device, line ));
- }
- }
- y2milestone( "mounts ret=%1", ret );
- return( ret );
- }
-
- string current_vg = "none";
- string vg_key = "";
- integer pesize = 4*1024*1024;
-
-
-
- boolean test_mode = Mode::test ();
- boolean view_all_mnts = Storage::GetLvmViewAllMnt();
- map<string,map> targetMap = Storage::GetTargetMap();
-
-
- ////////////////////////////////////////////////
- // Testmode, should be commented in release
- // test_mode = true;
- // test_mode = false;
- // architecture = "ppc";
- // system_type = "prep";
- // architecture = "axp";
- ////////////////////////////////////////////////
-
- list lvm_vgs = get_vgs( targetMap );
- list<map> parts_lv = get_lvs_and_mounted_partitions( targetMap, view_all_mnts, current_vg );
- list table_lv = get_lv_widget_table( parts_lv );
- list<map> parts_pv = get_possible_pvs( targetMap );
- list table_pv = get_pv_widget_table( parts_pv );
-
- //////////////////////////////////////////////////////////////////////
- // First we typically have to create a volumegroup
- // check if there is already a lvm group
- //////////////////////////////////////////////////////////////////////
-
- if( size( lvm_vgs ) == 0 )
- {
- map vg = DlgCreateVolumeGroup( lvm_vgs );
- map addVG = addVolumeGroup( vg, targetMap, lvm_vgs );
-
- // has the user cancelled the dialog?
- if( !addVG["cancelled"]:false )
- {
- targetMap = Storage::GetTargetMap();
- lvm_vgs = get_vgs( targetMap );
- current_vg = addVG["vg"]:"";
- }
- else
- {
- return( `back );
- }
- }
- else
- {
- // there are already vgs ... select the first one
- current_vg = lvm_vgs[0]:"";
- }
-
- vg_key = "/dev/" + current_vg;
- pesize = targetMap[vg_key,"cyl_size"]:(4*1024*1024);
-
-
- // Display current vg:
- new_vg_list( lvm_vgs );
- UI::ChangeWidget( `id(`vg), `Value, current_vg);
-
-
- //////////////////////////////////////////////////////////////////////
- // mainloop
- //////////////////////////////////////////////////////////////////////
-
- string id = "";
- symbol ret = `next;
- integer max_size = 0;
- integer used_size = 0;
- list size_list = [];
- string vg_size_str = "";
-
- repeat
- {
- /////////////////////////////////////////////////////////////////
- // Show the current state:
- parts_pv = get_possible_pvs( targetMap );
- table_pv = get_pv_widget_table( parts_pv );
- string ti = (string)UI::QueryWidget(`id(`pv_table), `CurrentItem );
- UI::ChangeWidget( `id(`pv_table), `Items, table_pv );
- if( ti != nil )
- UI::ChangeWidget( `id(`pv_table), `CurrentItem, ti );
-
- parts_lv = get_lvs_and_mounted_partitions( targetMap, view_all_mnts,
- current_vg );
- table_lv = get_lv_widget_table( parts_lv );
- ti = (string)UI::QueryWidget(`id(`lv_table), `CurrentItem );
- UI::ChangeWidget( `id(`lv_table), `Items, table_lv );
- if( ti != nil )
- UI::ChangeWidget( `id(`lv_table), `CurrentItem, ti );
-
- integer s = targetMap["/dev/"+current_vg,"size_k"]:0*1024;
- string vg_size_str = ByteToHumanStringWithZero( s );
- y2debug( "**** %1", vg_size_str );
- UI::ChangeWidget( `id(`pv_size), `Value, vg_size_str);
-
- UI::SetFocus( `id(`pv_table));
-
-
-
- /////////////////////////////////////////////////////////////////
- // Size for BarGraph
-
- size_list = get_lv_size_info( targetMap, current_vg );
- max_size = size_list[1]:0;
- used_size = size_list[0]:0;
- y2debug( "list=%3, max_size=%1 used_size=%2", max_size, used_size,
- size_list );
- vg_size_str = ByteToHumanStringWithZero( max_size );
-
- if( UI::HasSpecialWidget( `BarGraph ))
- {
- UI::ChangeWidget( `id(`vg_size), `Labels,
- [
- sformat( "used\n%1",
- ByteToHumanStringWithZero(used_size)),
- sformat( "free\n%1",
- ByteToHumanStringWithZero(max_size))
- ] );
- UI::ChangeWidget( `id(`vg_size), `Values,
- [ used_size / 1048576, max_size / 1048576 ] );
- }
- else
- {
- UI::ChangeWidget( `id(`vg_size), `Value, vg_size_str);
- }
-
- /////////////////////////////////////////////////////////////////
- // Wait for User input
-
- ret= (symbol)UI::UserInput();
-
- y2milestone( "USERINPUT %1", ret );
-
-
- ////////////////////////////////////////
- // user has changed "view all mountpoints" checkbox
- ////////////////////////////////////////
-
- if( ret == `viewmnt )
- {
- view_all_mnts = (boolean)UI::QueryWidget(`id(`viewmnt), `Value );
- }
-
-
- ////////////////////////////////////////
- // user has changed the current volume group
- ////////////////////////////////////////
-
- if( ret == `vg )
- {
- current_vg = (string)UI::QueryWidget( `id(`vg), `Value);
- vg_key = "/dev/" + current_vg;
- pesize = targetMap[vg_key,"cyl_size"]:(4*1024*1024);
- y2debug("TTT %1", current_vg );
- }
-
-
- ////////////////////////////////////////
- // Add a new volume group:
- ////////////////////////////////////////
-
- if( ret == `vg_add_vg )
- {
- map vg = DlgCreateVolumeGroup( lvm_vgs );
- map addVG = addVolumeGroup( vg, targetMap, lvm_vgs );
-
- // has the user cancelled the dialog?
- if( !addVG["cancelled"]:false )
- {
- targetMap = Storage::GetTargetMap();
- lvm_vgs = get_vgs( targetMap );
- current_vg = addVG["vg"]:"";
- y2milestone( "new current_vg %1", current_vg );
- }
- }
-
-
- ////////////////////////////////////////
- // Remove volume group:
- ////////////////////////////////////////
-
- if( ret == `vg_remove_vg && current_vg != nil )
- {
- if( HandleRemoveVg( targetMap, current_vg ))
- {
- targetMap = Storage::GetTargetMap();
- lvm_vgs = get_vgs( targetMap );
- current_vg = lvm_vgs[0]:"";
- new_vg_list( lvm_vgs );
- UI::ChangeWidget( `id(`vg), `Value, current_vg);
- y2milestone( " current_vg %1" , current_vg );
- }
- }
-
-
- ////////////////////////////////////////
- // Add a new physical volume:
- ////////////////////////////////////////
-
-
- if( ret == `pv_add && current_vg != nil )
- {
- id = (string)UI::QueryWidget(`id(`pv_table), `CurrentItem );
- y2debug( "WWW ID ADD GROUP %1", id);
-
- if( id!=nil && CheckItemIsNotPv(targetMap,id) &&
- CheckItemIsNotMounted(id) )
- {
- addPhysicalVolume( targetMap, id, current_vg );
- targetMap = Storage::GetTargetMap();
- }
- }
-
- ////////////////////////////////////////
- // Delete a new physical volume:
- ////////////////////////////////////////
-
- if( ret == `pv_delete && current_vg != nil )
- {
- id = (string)UI::QueryWidget(`id(`pv_table), `CurrentItem );
- y2milestone( "id:%1", id );
-
- if( id!=nil && CheckItemIsPv(targetMap,id) )
- {
- string vg = "";
- if( haskey( targetMap, id ))
- vg = targetMap[id,"used_by"]:"";
- else
- vg = Storage::GetPartition( targetMap, id )["used_by"]:"";
- vg = lvmVg(vg);
- y2milestone( "vg=%1", vg );
- if( !check_pv_delete( targetMap, id, vg ) )
- {
- ret = `again;
- continue;
- }
-
- removePhysicalVolume( targetMap, id, vg );
- targetMap = Storage::GetTargetMap();
- }
- }
-
-
- ////////////////////////////////////////
- // Add a new logical volume:
- ////////////////////////////////////////
-
- if( ret == `lv_add )
- {
- if( max_size<pesize )
- {
- //rwalter: add example VG for translators
- // popup text, %1 is volume group, such as ???
- Popup::Message(sformat(_("No space available in the current volume group %1."), current_vg ));
- }
- else
- {
- map<string,any> Lv = $[
- "create" : true,
- "used_fs" : Partitions::DefaultFs(),
- "size_k" : max_size/4/pesize*pesize/1024,
- "stripes" : 1,
- "format" : true,
- "type" : `lvm,
- "mount" : GetMountPointProposal(targetMap, [Partitions::BootMount()] )
- ];
-
- if( Lv["size_k"]:0 == 0 )
- {
- Lv["size_k"] = max_size/pesize*pesize/1024;
- }
-
- map createLv = DlgCreateEditLogicaVolume( `create, Lv,
- max_size, current_vg,
- get_lv_names(targetMap,current_vg),
- FileSystems::GetAllFileSystems(true,true),
- "", pesize );
-
- // has an error occured
- if( size(createLv)>0 )
- {
- addLogicalVolume( createLv, current_vg );
- targetMap = Storage::GetTargetMap();
- }
- }
- }
-
- ////////////////////////////////////////
- // Edit/Resize a new logical volume:
- ////////////////////////////////////////
-
-
- if( ret == `lv_edit )
- {
- id = (string)UI::QueryWidget(`id(`lv_table), `CurrentItem );
- y2milestone("id %1", id);
-
- if ( id == nil )
- {
- // Popup text
- Popup::Error(_("No device selected.
- Select the device to edit.
- "));
-
- }
- else
- {
- HandleEditLv( targetMap, id );
- targetMap = Storage::GetTargetMap();
- }
- }
-
- ////////////////////////////////////////
- // Delete a new logical volume:
- ////////////////////////////////////////
-
- if( ret == `lv_delete )
- {
- id = (string)UI::QueryWidget(`id(`lv_table), `CurrentItem );
- if( id == nil )
- {
- // Popup text
- Popup::Error(_("No device selected.
- Select the device to remove.
- "));
- }
- else
- {
- HandleRemoveLv( targetMap, id );
- targetMap = Storage::GetTargetMap();
- }
- }
-
- if( ret == `help )
- {
- // LVM Helptext headline
- Popup::LongText( _("LVM Configuration"), `RichText( getLvmHelptext()),
- 70, 20 );
- }
-
- ////////////////////////////////////////
- // Finish this step
- ////////////////////////////////////////
-
- if( ret == `finish || ret == `apply )
- {
- y2milestone( "END___ %1", ret);
- Storage::SetLvmViewAllMnt( view_all_mnts );
- }
-
- } until (ret == `finish || ret == `apply || ret == `abort);
-
- y2milestone( "END_ %1", ret);
-
- return ret;
- }
-
- // end
-