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