PeContainer.h

Go to the documentation of this file.
00001 #ifndef PE_CONTAINER_H
00002 #define PE_CONTAINER_H
00003 
00004 #include "y2storage/Container.h"
00005 #include "y2storage/Dm.h"
00006 
00007 namespace storage
00008 {
00009 
00010 class PeContainer : public Container
00011     {
00012     friend class Storage;
00013 
00014     public:
00015         PeContainer( Storage * const s, storage::CType t );
00016         PeContainer( const PeContainer& c );
00017         PeContainer& operator= ( const PeContainer& rhs );
00018         virtual ~PeContainer();
00019 
00020         unsigned long long peSize() const { return pe_size; }
00021         unsigned long long sizeK() const { return pe_size*num_pe; }
00022         unsigned long peCount() const { return num_pe; }
00023         unsigned long peFree() const { return free_pe; }
00024         unsigned numPv() const { return pv.size(); }
00025         friend std::ostream& operator<< (std::ostream&, const PeContainer& );
00026         bool addedPv( const string& dev ) const;
00027         unsigned long sizeToLe( unsigned long long sizeK ) const;
00028 
00029         int setPeSize( long long unsigned, bool lvm1 );
00030         void unuseDev();
00031         void changeDeviceName( const string& old, const string& nw );
00032         bool equalContent( const PeContainer& rhs, bool comp_vol=true ) const;
00033         virtual string getDiffString( const Container& d ) const;
00034         
00035     protected:
00036         struct Pv
00037             {
00038             string device;
00039             string uuid;
00040             string status;
00041             unsigned long num_pe;
00042             unsigned long free_pe;
00043 
00044             static bool comp_le( const Pv& a, const Pv& b )
00045                 { return( a.free_pe<b.free_pe ); }
00046             static bool no_free( const Pv& a )
00047                 { return( a.free_pe==0 ); }
00048 
00049             bool operator== ( const Pv& rhs ) const
00050                 { return( device==rhs.device ); }
00051             bool operator== ( const string& dev ) const
00052                 { return( device==dev); }
00053             bool equalContent( const Pv& rhs ) const
00054                 { return( device==rhs.device && uuid==rhs.uuid &&
00055                           status==rhs.status && num_pe==rhs.num_pe &&
00056                           free_pe==rhs.free_pe ); }
00057             Pv() { num_pe = free_pe = 0; }
00058             };
00059 
00060         // iterators over Dm volumes
00061         typedef CastIterator<VIter, Dm *> DmInter;
00062         typedef CastIterator<CVIter, const Dm *> DmCInter;
00063         template< class Pred >
00064             struct DmPI { typedef ContainerIter<Pred, DmInter> type; };
00065         template< class Pred >
00066             struct DmCPI { typedef ContainerIter<Pred, DmCInter> type; };
00067         typedef CheckFnc<const Dm> CheckFncDm;
00068         typedef CheckerIterator< CheckFncDm, DmPI<CheckFncDm>::type,
00069                                  DmInter, Dm > DmPIterator;
00070         typedef CheckerIterator< CheckFncDm, DmCPI<CheckFncDm>::type,
00071                                  DmCInter, const Dm > DmCPIterator;
00072         typedef DerefIterator<DmPIterator,Dm> DmIter;
00073         typedef DerefIterator<DmCPIterator,const Dm> ConstDmIter;
00074         typedef IterPair<DmIter> DmPair;
00075         typedef IterPair<ConstDmIter> ConstDmPair;
00076 
00077         DmPair dmPair( bool (* Check)( const Dm& )=NULL)
00078             {
00079             return( DmPair( dmBegin( Check ), dmEnd( Check ) ));
00080             }
00081         DmIter dmBegin( bool (* Check)( const Dm& )=NULL)
00082             {
00083             IterPair<DmInter> p( (DmInter(begin())), (DmInter(end())) );
00084             return( DmIter( DmPIterator( p, Check )) );
00085             }
00086         DmIter dmEnd( bool (* Check)( const Dm& )=NULL)
00087             {
00088             IterPair<DmInter> p( (DmInter(begin())), (DmInter(end())) );
00089             return( DmIter( DmPIterator( p, Check, true )) );
00090             }
00091 
00092         ConstDmPair dmPair( bool (* Check)( const Dm& )=NULL) const
00093             {
00094             return( ConstDmPair( dmBegin( Check ), dmEnd( Check ) ));
00095             }
00096         ConstDmIter dmBegin( bool (* Check)( const Dm& )=NULL) const
00097             {
00098             IterPair<DmCInter> p( (DmCInter(begin())), (DmCInter(end())) );
00099             return( ConstDmIter( DmCPIterator( p, Check )) );
00100             }
00101         ConstDmIter dmEnd( bool (* Check)( const Dm& )=NULL) const
00102             {
00103             IterPair<DmCInter> p( (DmCInter(begin())), (DmCInter(end())) );
00104             return( ConstDmIter( DmCPIterator( p, Check, true )) );
00105             }
00106 
00107 
00108         friend std::ostream& operator<< (std::ostream&, const Pv& );
00109         friend void printDevList (std::ostream&, const std::list<Pv>& );
00110 
00111         void init();
00112         unsigned long long capacityInKb() const {return pe_size*num_pe;}
00113         string addList() const;
00114         virtual void print( std::ostream& s ) const { s << *this; }
00115         virtual Container* getCopy() const { return( new PeContainer( *this ) ); }
00116         bool findPe( const string& dev, const std::list<Pv>& pl, 
00117                      std::list<Pv>::const_iterator& i ) const;
00118         bool findPe( const string& dev, std::list<Pv>& pl, 
00119                      std::list<Pv>::iterator& i );
00120         unsigned long leByLvRemove() const;
00121         int tryUnusePe( const string& dev, std::list<Pv>& pl, std::list<Pv>& pladd,
00122                         std::list<Pv>& plrem, unsigned long& removed_pe );
00123         bool checkCreateConstraints();
00124         static int addLvPeDistribution( unsigned long le, unsigned stripe,
00125                                         std::list<Pv>& pl, std::list<Pv>& pladd, 
00126                                         std::map<string,unsigned long>& pe_map );
00127         int remLvPeDistribution( unsigned long le, std::map<string,unsigned long>& pe_map,
00128                                  std::list<Pv>& pl, std::list<Pv>& pladd );
00129         virtual bool checkConsistency() const;
00130 
00131         void addPv( const Pv* p );
00132 
00133         unsigned long long pe_size;
00134         unsigned long num_pe;
00135         unsigned long free_pe;
00136         std::list<Pv> pv;
00137         std::list<Pv> pv_add;
00138         std::list<Pv> pv_remove;
00139     };
00140 
00141 }
00142 
00143 #endif

Generated on Wed Apr 30 14:58:40 2008 for yast2-storage by  doxygen 1.4.6