00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LVM_VG_H
00024 #define LVM_VG_H
00025
00026 #include "storage/PeContainer.h"
00027 #include "storage/LvmLv.h"
00028
00029
00030 namespace storage
00031 {
00032 using std::list;
00033
00034
00035 class LvmVg : public PeContainer
00036 {
00037 friend class Storage;
00038 friend class LvmLv;
00039
00040 public:
00041
00042 LvmVg(Storage* s, const string& name, const string& device, bool lvm1);
00043 LvmVg(Storage* s, const string& name, const string& device, SystemInfo& systeminfo);
00044 LvmVg(Storage* s, const xmlNode* node);
00045 LvmVg(const LvmVg& c);
00046 virtual ~LvmVg();
00047
00048 void saveData(xmlNode* node) const;
00049
00050 unsigned numLv() const;
00051 bool lvm2() const { return( !lvm1 ); }
00052 static storage::CType staticType() { return storage::LVM; }
00053 friend std::ostream& operator<< (std::ostream&, const LvmVg& );
00054
00055 int removeVg();
00056 int extendVg( const std::list<string>& dl );
00057 int extendVg( const string& device );
00058 int reduceVg( const std::list<string>& dl );
00059 int reduceVg( const string& device );
00060 int createLv( const string& name, unsigned long long sizeK,
00061 unsigned stripe, string& device );
00062 int removeLv( const string& name );
00063 int changeStripe( const string& name, unsigned long stripe );
00064 int changeStripeSize( const string& name,
00065 unsigned long long stripeSize );
00066 int changeChunkSize( const string& name,
00067 unsigned long long chunkSizeK );
00068
00069 int createLvSnapshot(const string& origin, const string& name,
00070 unsigned long long cowSizeK, string& device);
00071 int removeLvSnapshot(const string& name);
00072 int getLvSnapshotState(const string& name, LvmLvSnapshotStateInfo& info);
00073 int createPool( const string& name, unsigned long long sizeK,
00074 string& device );
00075 int createThin( const string& name, const string& pool,
00076 unsigned long long sizeK, string& device );
00077
00078 int setPeSize( long long unsigned peSizeK );
00079 void normalizeDmDevices();
00080 void getCommitActions(list<commitAction>& l) const;
00081 void getToCommit(storage::CommitStage stage, list<const Container*>& col,
00082 list<const Volume*>& vol) const;
00083 int commitChanges( storage::CommitStage stage );
00084 int resizeVolume( Volume* v, unsigned long long newSize );
00085 int removeVolume( Volume* v );
00086 void getInfo( storage::LvmVgInfo& info ) const;
00087 bool equalContent( const Container& rhs ) const;
00088
00089 void logDifference(std::ostream& log, const LvmVg& rhs) const;
00090 virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
00091
00092 static void activate(bool val);
00093 static bool isActive() { return active; }
00094
00095 static list<string> getVgs();
00096
00097 protected:
00098
00099
00100 typedef CastIterator<VIter, LvmLv *> LvmLvInter;
00101 typedef CastIterator<CVIter, const LvmLv *> LvmLvCInter;
00102 template< class Pred >
00103 struct LvmLvPI { typedef ContainerIter<Pred, LvmLvInter> type; };
00104 template< class Pred >
00105 struct LvmLvCPI { typedef ContainerIter<Pred, LvmLvCInter> type; };
00106 typedef CheckFnc<const LvmLv> CheckFncLvmLv;
00107 typedef CheckerIterator< CheckFncLvmLv, LvmLvPI<CheckFncLvmLv>::type,
00108 LvmLvInter, LvmLv > LvmLvPIterator;
00109 typedef CheckerIterator< CheckFncLvmLv, LvmLvCPI<CheckFncLvmLv>::type,
00110 LvmLvCInter, const LvmLv > LvmLvCPIterator;
00111 typedef DerefIterator<LvmLvPIterator,LvmLv> LvmLvIter;
00112 typedef DerefIterator<LvmLvCPIterator,const LvmLv> ConstLvmLvIter;
00113 typedef IterPair<LvmLvIter> LvmLvPair;
00114 typedef IterPair<ConstLvmLvIter> ConstLvmLvPair;
00115
00116 LvmLvPair lvmLvPair( bool (* Check)( const LvmLv& )=NULL)
00117 {
00118 return( LvmLvPair( lvmLvBegin( Check ), lvmLvEnd( Check ) ));
00119 }
00120 LvmLvIter lvmLvBegin( bool (* Check)( const LvmLv& )=NULL)
00121 {
00122 IterPair<LvmLvInter> p( (LvmLvInter(begin())), (LvmLvInter(end())) );
00123 return( LvmLvIter( LvmLvPIterator( p, Check )) );
00124 }
00125 LvmLvIter lvmLvEnd( bool (* Check)( const LvmLv& )=NULL)
00126 {
00127 IterPair<LvmLvInter> p( (LvmLvInter(begin())), (LvmLvInter(end())) );
00128 return( LvmLvIter( LvmLvPIterator( p, Check, true )) );
00129 }
00130
00131 ConstLvmLvPair lvmLvPair( bool (* Check)( const LvmLv& )=NULL) const
00132 {
00133 return( ConstLvmLvPair( lvmLvBegin( Check ), lvmLvEnd( Check ) ));
00134 }
00135 ConstLvmLvIter lvmLvBegin( bool (* Check)( const LvmLv& )=NULL) const
00136 {
00137 IterPair<LvmLvCInter> p( (LvmLvCInter(begin())), (LvmLvCInter(end())) );
00138 return( ConstLvmLvIter( LvmLvCPIterator( p, Check )) );
00139 }
00140 ConstLvmLvIter lvmLvEnd( bool (* Check)( const LvmLv& )=NULL) const
00141 {
00142 IterPair<LvmLvCInter> p( (LvmLvCInter(begin())), (LvmLvCInter(end())) );
00143 return( ConstLvmLvIter( LvmLvCPIterator( p, Check, true )) );
00144 }
00145
00146 void getVgData( const string& name, bool exists=true );
00147
00148 virtual void print( std::ostream& s ) const { s << *this; }
00149 virtual Container* getCopy() const { return( new LvmVg( *this ) ); }
00150
00151 Text createText(bool doing) const;
00152 Text removeText(bool doing) const;
00153 Text extendText(bool doing, const string& dev) const;
00154 Text reduceText(bool doing, const string& dev) const;
00155
00156 int doCreateVg();
00157 int doRemoveVg();
00158 int doExtendVg();
00159 int doReduceVg();
00160 int doCreate( Volume* v );
00161 int doRemove( Volume* v );
00162 int doResize( Volume* v );
00163 int doCreatePv(const Pv& pv);
00164
00165 string metaString() const;
00166 string instSysString() const;
00167
00168 virtual void logData(const string& Dir) const;
00169
00170 void addLv(unsigned long& le, string& name, string& origin, string& uuid,
00171 string& status, string& alloc, bool& ro, bool& pool,
00172 string& used_pool, unsigned long long& pchunk, SystemInfo& si );
00173 void addPv( Pv*& p );
00174 LvmLv* findLv(const string& name);
00175 bool checkChunk( unsigned long long val, unsigned long long mi=0,
00176 unsigned long long mx=0 );
00177
00178 string status;
00179 string uuid;
00180 bool lvm1;
00181
00182 static bool active;
00183
00184 mutable storage::LvmVgInfo info;
00185
00186 private:
00187
00188 LvmVg& operator=(const LvmVg&);
00189
00190 };
00191
00192 }
00193
00194 #endif