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