home *** CD-ROM | disk | FTP | other *** search
- /**
- * File:
- * lvm_lv_lib.ycp
- *
- * Module:
- *
- * Summary: lib for lvm-configs logical volume management
- *
- * Authors:
- * mike <mike@suse.de>
- *
- * $Id: lvm_lv_lib.ycp 29983 2006-04-11 13:12:27Z 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
- *----------------------------------------------------
- *
- */
- {
-
- textdomain "storage";
- import "Storage";
- import "Partitions";
-
- include "partitioning/lvm_lib.ycp";
- include "partitioning/lvm_pv_lib.ycp";
-
- //////////////////////////////////////////////////////////////////////
- // add a logical volume to the modify_targets stack
- //
- // 1: $[ "use_module" : "lvm_ll"
- // "type" : "create_lv",
- // "name" : "usr"
- // "size" : 12121
- // "vgname" : "system"
- // "stripes" : 1 ]
- //
- // !!!!!!! changes targetMap by reference !!!!!!
- //
- //////////////////////////////////////////////////////////////////////
-
- define boolean addLogicalVolume( map Lv, string current_vg )
- ``{
- boolean ret=true;
- if( !Storage::CreateLvmLv( current_vg, Lv["name"]:"", Lv["size_k"]:0,
- Lv["stripes"]:1 ))
- {
- string txt = _("A logical volume with the requested size could
- not be created.
- ");
- if( Lv["stripes"]:1 > 1 )
- txt = txt + _("Try reducing the stripe count of the volume.");
- Popup::Error( txt );
- ret = false;
- }
- else
- {
- ret = Storage::ChangeVolumeProperties( Lv );
- if( Lv["stripes"]:1>1 && Lv["stripesize"]:0>0 )
- ret = Storage::ChangeLvStripeSize( current_vg, Lv["name"]:"",
- Lv["stripesize"]:0 ) && ret;
- }
- return( ret );
- };
-
- define boolean editLogicalVolume( map Lv, string current_vg)
- ``{
- y2milestone( "editLogicalVolume Lv:%1", Lv );
- boolean ret = Storage::ChangeVolumeProperties( Lv );
- ret = Storage::ResizeVolume( Lv["device"]:"", "/dev/"+current_vg,
- Lv["size_k"]:0 ) && ret;
- return( ret );
- };
-
- define boolean removeLogicalVolume( string disk, string device )
- ``{
- return( Storage::DeleteDevice( disk, device ));
- };
-
-
- //////////////////////////////////////////////////////////////////////
- //
- // !!!! input: partition_list: must be aready those lvs that belong to current_vg
- //
- // [ $["fsid":Partitions::fsid_lvm,
- // "fstype":"LVM",
- // "nr":"var",
- // "region":[255, 16],
- // "type":`primary],
- // $[
- // "fsid":131,
- // "fstype":"Linux native",
- // "nr":4, "region":[271, 844],
- // ...
- //
- // out: [ 10344343, 2223333 ] [ used, avail ]
-
- define list get_lv_size_info( map<string,map> targetMap, string current_vg )
- ``{
- list ret = [];
- integer sum_byte_vg = targetMap["/dev/"+current_vg,"size_k"]:0*1024;
- integer free_byte_vg = targetMap["/dev/"+current_vg,"pe_free"]:0*
- targetMap["/dev/"+current_vg,"cyl_size"]:0;
- ret = [ sum_byte_vg-free_byte_vg, free_byte_vg ];
-
- y2milestone( "get_lv_size_info vg=%1 ret=%2", current_vg, ret );
- return( ret );
- };
-
-
- ////////////////////////////////////////////////////////////////////////////////
- // Get all logical volumes and mounted partitions
-
- define list<map> get_lvs_and_mounted_partitions( map<string,map> targetMap,
- boolean view_all_mnts,
- string current_vg )
- ``{
- list<map> ret = [];
- integer pesize = targetMap["/dev/"+current_vg,"cyl_size"]:(4096*1024);
- y2milestone( "current_vg=%2 pesize=%1", pesize, current_vg );
-
- //////////////////////////////////////////////////////////////////////
- // add the devicename i.e /dev/hda1 or /dev/system/usr to partition list
- // and the device key <subdevice>/<maindevice> i.e. 1//dev/hda
-
- targetMap = mapmap( string dev, map devmap, targetMap,
- ``{
- boolean is_lvm_vg = devmap["type"]:`CT_UNKNOWN==`CT_LVM;
- integer cyl_size = devmap["cyl_size"]:0;
-
- list partitions = maplist( map part, devmap["partitions"]:[],
- ``{
- if( is_lvm_vg )
- {
- part["lvm_name"] = devmap["name"]:"";
- }
- part["size_str"] = ByteToHumanStringWithZero(part["size_k"]:0*1024);
-
- part["maindev"] = dev;
- y2debug("devname %1 size %2 pe %3", part["device"]:"",
- part["size_k"]:0*1024, pesize );
- return( part );
- });
-
- devmap["partitions"] = partitions;
- return( $[ dev: devmap ] );
- });
-
- ////////////////////////////////////////////////////////////
- // Look for all partitions:
- //
- // normal partition with mountpoint
- // logical volume
-
- if( !view_all_mnts )
- {
- string f = "/" + current_vg + "/";
- // only to current vg depending vgs ...
- foreach( string dev, map devmap, targetMap,
- ``{
- ret = (list<map>)union( ret, filter( map part, devmap["partitions"]:[],
- ``( part["type"]:`none == `lvm &&
- search( part["device"]:"", f )==4 )));
- });
- }
- else
- {
- foreach( string dev, map devmap, targetMap,
- ``{
- ret = (list<map>)merge( ret, filter( map part, devmap["partitions"]:[],
- ``( size(part["mount"]:"")>0 ||
- part["type"]:`none == `lvm )));
- });
- }
- return( ret );
- };
-
- ////////////////////////////////////////////////////////////////////////////////
- // Get all existing lv names of a volume group
-
- define list get_lv_names( map<string,map> targetMap, string current_vg )
- ``{
- list<map> part = targetMap["/dev/"+current_vg,"partitions"]:[];
- list ret = maplist( map e, part, ``(e["name"]:"") );
- return( ret );
- };
-
- //////////////////////////////////////////////////////////////////////
- // partition list to widget table
- // in:
- // [ $["fsid":Partitions::fsid_lvm,
- // "fstype":"LVM",
- // "nr":"var",
- // "region":[255, 16],
- // "type":`primary],
- // $[
- // "fsid":131,
- // "fstype":"Linux native",
- // "nr":4, "region":[271, 844],
- // ...
- //
- // out:
- // [
- // `item(`id(1//dev/hda), "/dev/hda1 ", " /var ", "system", " 1G ", " LVM "),
- // `item(`id(2//dev/hda), "/dev/hda2 ", " /usr ", "system", " 2G ", " Linux ")
- // ];
-
- define list get_lv_widget_table( list<map> possPvList )
- ``{
- list ret = [];
-
- possPvList =
- sort( map x, map y, possPvList,
- ``{
- if( x["maindev"]:"" == y["maindev"]:"" )
- {
- return( x["nr"]:(any)"" < y["nr"]:(any)"" );
- }
- else
- {
- return( x["maindev"]:"" < y["maindev"]:"" );
- }
- });
-
-
- return( maplist( map partition, possPvList,
- ``{
- return(`item( `id(partition["device"]:"--"),
- partition["device"]:"--",
- partition["mount"]:"",
- partition["lvm_name"]:"",
- partition["size_str"]:"--",
- partition["fstype"]:"--"
- ));
- }
- ));
- };
-
-
-
- }
-