home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / root / usr / share / YaST2 / include / partitioning / lvm_lv_lib.ycp < prev    next >
Encoding:
Text File  |  2006-11-29  |  6.9 KB  |  252 lines

  1. /**
  2.  * File:
  3.  *   lvm_lv_lib.ycp
  4.  *
  5.  * Module:
  6.  *
  7.  * Summary:  lib for lvm-configs logical volume management
  8.  *
  9.  * Authors:
  10.  *   mike <mike@suse.de>
  11.  *
  12.  * $Id: lvm_lv_lib.ycp 29983 2006-04-11 13:12:27Z fehr $
  13.  *
  14.  *
  15.  *----------------------------------------------------
  16.  * IMPORTANT: when you read this code notice:
  17.  *
  18.  * vg  = volume group
  19.  * vgs = volume groups
  20.  *
  21.  * pv  = physical volume
  22.  * pvs = physical volumes
  23.  *
  24.  * lv  = logical volume
  25.  * lvs = logical volumes
  26.  *----------------------------------------------------
  27.  *
  28.  */
  29. {
  30.  
  31. textdomain "storage";
  32. import "Storage";
  33. import "Partitions";
  34.  
  35. include "partitioning/lvm_lib.ycp";
  36. include "partitioning/lvm_pv_lib.ycp";
  37.       
  38.     //////////////////////////////////////////////////////////////////////
  39.     // add a logical volume to the modify_targets stack
  40.     //
  41.     // 1:  $[  "use_module" : "lvm_ll"
  42.     //         "type"       : "create_lv", 
  43.     //         "name"       : "usr"
  44.     //         "size"       : 12121
  45.     //         "vgname"     : "system"
  46.     //         "stripes"    : 1 ]           
  47.     //
  48.     //   !!!!!!! changes targetMap by reference !!!!!!
  49.     //     
  50.     //////////////////////////////////////////////////////////////////////
  51.  
  52. define boolean addLogicalVolume( map Lv, string current_vg )
  53.     ``{
  54.     boolean ret=true;
  55.     if( !Storage::CreateLvmLv( current_vg, Lv["name"]:"", Lv["size_k"]:0,
  56.                                Lv["stripes"]:1 ))
  57.     {
  58.     string txt = _("A logical volume with the requested size could 
  59. not be created.
  60. ");
  61.     if( Lv["stripes"]:1 > 1 )
  62.         txt = txt + _("Try reducing the stripe count of the volume.");
  63.     Popup::Error( txt );
  64.     ret = false;
  65.     }
  66.     else 
  67.     {
  68.     ret = Storage::ChangeVolumeProperties( Lv );
  69.     if( Lv["stripes"]:1>1 && Lv["stripesize"]:0>0 )
  70.         ret = Storage::ChangeLvStripeSize( current_vg, Lv["name"]:"", 
  71.                            Lv["stripesize"]:0 ) && ret;
  72.     }
  73.     return( ret );
  74.     };
  75.     
  76. define boolean editLogicalVolume( map Lv, string current_vg)
  77.     ``{
  78.     y2milestone( "editLogicalVolume Lv:%1", Lv );
  79.     boolean ret = Storage::ChangeVolumeProperties( Lv );
  80.     ret = Storage::ResizeVolume( Lv["device"]:"", "/dev/"+current_vg,
  81.                                  Lv["size_k"]:0 ) && ret;
  82.     return( ret );
  83.     };
  84.  
  85. define boolean removeLogicalVolume( string disk, string device )
  86.     ``{
  87.     return( Storage::DeleteDevice( disk, device ));
  88.     };
  89.  
  90.   
  91.     //////////////////////////////////////////////////////////////////////
  92.     //      
  93.     // !!!! input: partition_list: must be aready those lvs that belong to current_vg
  94.     // 
  95.     // [  $["fsid":Partitions::fsid_lvm,
  96.     //      "fstype":"LVM",
  97.     //      "nr":"var",
  98.     //      "region":[255, 16],
  99.     //      "type":`primary],
  100.     //      $[
  101.     //       "fsid":131,
  102.     //       "fstype":"Linux native",
  103.     //       "nr":4, "region":[271, 844],
  104.     //    ...
  105.     //
  106.     //  out: [ 10344343, 2223333 ]   [ used, avail ]
  107.      
  108. define list get_lv_size_info( map<string,map> targetMap, string current_vg )
  109.     ``{
  110.     list ret = [];
  111.     integer sum_byte_vg = targetMap["/dev/"+current_vg,"size_k"]:0*1024;
  112.     integer free_byte_vg = targetMap["/dev/"+current_vg,"pe_free"]:0*
  113.                            targetMap["/dev/"+current_vg,"cyl_size"]:0;
  114.     ret = [ sum_byte_vg-free_byte_vg, free_byte_vg ];
  115.  
  116.     y2milestone( "get_lv_size_info vg=%1 ret=%2", current_vg, ret );
  117.     return( ret );
  118.     };
  119.         
  120.  
  121.     ////////////////////////////////////////////////////////////////////////////////
  122.     // Get all logical volumes and mounted partitions
  123.     
  124. define list<map> get_lvs_and_mounted_partitions( map<string,map> targetMap, 
  125.                          boolean view_all_mnts,
  126.                          string current_vg )
  127.     ``{
  128.     list<map> ret = [];
  129.     integer pesize = targetMap["/dev/"+current_vg,"cyl_size"]:(4096*1024);
  130.     y2milestone( "current_vg=%2 pesize=%1", pesize, current_vg );
  131.     
  132.     //////////////////////////////////////////////////////////////////////
  133.     // add the devicename i.e /dev/hda1 or /dev/system/usr to partition list
  134.     // and the device key  <subdevice>/<maindevice> i.e. 1//dev/hda
  135.     
  136.     targetMap = mapmap( string dev, map devmap, targetMap,
  137.     ``{
  138.     boolean is_lvm_vg  = devmap["type"]:`CT_UNKNOWN==`CT_LVM;
  139.     integer cyl_size   = devmap["cyl_size"]:0;
  140.                     
  141.     list partitions = maplist( map part, devmap["partitions"]:[],
  142.         ``{
  143.         if( is_lvm_vg )
  144.         {
  145.         part["lvm_name"] = devmap["name"]:"";
  146.         }
  147.         part["size_str"] = ByteToHumanStringWithZero(part["size_k"]:0*1024);
  148.         
  149.         part["maindev"] = dev;
  150.         y2debug("devname %1 size %2 pe %3", part["device"]:"",
  151.                 part["size_k"]:0*1024, pesize );
  152.         return( part );
  153.         });
  154.  
  155.     devmap["partitions"] = partitions;
  156.     return( $[ dev: devmap ] );
  157.     });
  158.  
  159.     ////////////////////////////////////////////////////////////
  160.     // Look for all partitions:
  161.     //
  162.     // normal partition with mountpoint
  163.     // logical volume
  164.  
  165.     if( !view_all_mnts )
  166.     {
  167.     string f = "/" + current_vg + "/";
  168.     // only to current vg depending vgs ...
  169.     foreach( string dev, map devmap, targetMap,
  170.         ``{
  171.         ret = (list<map>)union( ret, filter( map part, devmap["partitions"]:[],
  172.                       ``( part["type"]:`none == `lvm &&
  173.                       search( part["device"]:"", f )==4 )));
  174.         });
  175.     }
  176.     else
  177.     {
  178.     foreach( string dev, map devmap, targetMap,
  179.         ``{
  180.         ret = (list<map>)merge( ret, filter( map part, devmap["partitions"]:[],
  181.                       ``( size(part["mount"]:"")>0 ||
  182.                           part["type"]:`none == `lvm )));
  183.         });
  184.     }
  185.     return( ret );
  186.     };
  187.  
  188.     ////////////////////////////////////////////////////////////////////////////////
  189.     // Get all existing lv names of a volume group
  190.     
  191. define list get_lv_names( map<string,map> targetMap, string current_vg )
  192.     ``{
  193.     list<map> part = targetMap["/dev/"+current_vg,"partitions"]:[];
  194.     list ret = maplist( map e, part, ``(e["name"]:"") );
  195.     return( ret );
  196.     };
  197.  
  198.     //////////////////////////////////////////////////////////////////////
  199.     // partition list to widget table
  200.     // in:
  201.     // [  $["fsid":Partitions::fsid_lvm,
  202.     //      "fstype":"LVM",
  203.     //      "nr":"var",
  204.     //      "region":[255, 16],
  205.     //      "type":`primary],
  206.     //      $[
  207.     //       "fsid":131,
  208.     //       "fstype":"Linux native",
  209.     //       "nr":4, "region":[271, 844],
  210.     //    ...
  211.     //
  212.     // out:
  213.     // [
  214.     //    `item(`id(1//dev/hda), "/dev/hda1 ",   " /var ",  "system", " 1G ", " LVM "),
  215.     //      `item(`id(2//dev/hda), "/dev/hda2 ",   " /usr ",  "system", " 2G ", " Linux ")
  216.     //     ];
  217.  
  218. define list get_lv_widget_table( list<map> possPvList )
  219.     ``{
  220.     list    ret = [];
  221.  
  222.     possPvList = 
  223.     sort( map x, map y, possPvList,
  224.         ``{
  225.         if( x["maindev"]:"" == y["maindev"]:"" )
  226.         {
  227.         return( x["nr"]:(any)"" < y["nr"]:(any)"" );
  228.         }
  229.         else
  230.         {
  231.         return( x["maindev"]:"" < y["maindev"]:"" );
  232.         }
  233.         });
  234.     
  235.     
  236.     return( maplist( map partition, possPvList,
  237.          ``{
  238.          return(`item( `id(partition["device"]:"--"),
  239.                    partition["device"]:"--",
  240.                    partition["mount"]:"",
  241.                    partition["lvm_name"]:"",
  242.                    partition["size_str"]:"--",
  243.                    partition["fstype"]:"--"
  244.                    ));
  245.         }
  246.          ));
  247.     };
  248.  
  249.  
  250.  
  251. }
  252.