00001 #ifndef PE_CONTAINER_H
00002 #define PE_CONTAINER_H
00003
00004 #include "y2storage/Container.h"
00005 #include "y2storage/Dm.h"
00006
00007 class PeContainer : public Container
00008 {
00009 friend class Storage;
00010
00011 public:
00012 PeContainer( Storage * const s, storage::CType t );
00013 PeContainer( const PeContainer& c );
00014 PeContainer& operator= ( const PeContainer& rhs );
00015 virtual ~PeContainer();
00016
00017 unsigned long long peSize() const { return pe_size; }
00018 unsigned long long sizeK() const { return pe_size*num_pe; }
00019 unsigned long peCount() const { return num_pe; }
00020 unsigned long peFree() const { return free_pe; }
00021 unsigned numPv() const { return pv.size(); }
00022 friend std::ostream& operator<< (std::ostream&, const PeContainer& );
00023
00024 int setPeSize( long long unsigned, bool lvm1 );
00025 bool equalContent( const PeContainer& rhs, bool comp_vol=true ) const;
00026 string logDifference( const PeContainer& d ) const;
00027
00028 protected:
00029 struct Pv
00030 {
00031 string device;
00032 string uuid;
00033 string status;
00034 unsigned long num_pe;
00035 unsigned long free_pe;
00036
00037 static bool comp_le( const Pv& a, const Pv& b )
00038 { return( a.free_pe<b.free_pe ); }
00039 static bool no_free( const Pv& a )
00040 { return( a.free_pe==0 ); }
00041
00042 bool operator== ( const Pv& rhs ) const
00043 { return( device==rhs.device ); }
00044 bool operator== ( const string& dev ) const
00045 { return( device==dev); }
00046 bool equalContent( const Pv& rhs ) const
00047 { return( device==rhs.device && uuid==rhs.uuid &&
00048 status==rhs.status && num_pe==rhs.num_pe &&
00049 free_pe==rhs.free_pe ); }
00050 Pv() { num_pe = free_pe = 0; }
00051 };
00052
00053 friend std::ostream& operator<< (std::ostream&, const Pv& );
00054
00055 void init();
00056 unsigned long long capacityInKb() const {return pe_size*num_pe;}
00057 virtual void print( std::ostream& s ) const { s << *this; }
00058 virtual Container* getCopy() const { return( new PeContainer( *this ) ); }
00059
00060 unsigned long leByLvRemove() const;
00061 int tryUnusePe( const string& dev, std::list<Pv>& pl, std::list<Pv>& pladd,
00062 std::list<Pv>& plrem, unsigned long& removed_pe );
00063 static int addLvPeDistribution( unsigned long le, unsigned stripe,
00064 std::list<Pv>& pl, std::list<Pv>& pladd,
00065 std::map<string,unsigned long>& pe_map );
00066 static int remLvPeDistribution( unsigned long le, std::map<string,unsigned long>& pe_map,
00067 std::list<Pv>& pl, std::list<Pv>& pladd );
00068 virtual bool checkConsistency() const;
00069
00070 void addPv( const Pv* p );
00071
00072 unsigned long long pe_size;
00073 unsigned long num_pe;
00074 unsigned long free_pe;
00075 std::list<Pv> pv;
00076 std::list<Pv> pv_add;
00077 std::list<Pv> pv_remove;
00078 };
00079
00080 #endif