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
00067 int createLvSnapshot(const string& origin, const string& name,
00068 unsigned long long cowSizeK, string& device);
00069 int removeLvSnapshot(const string& name);
00070 int getLvSnapshotState(const string& name, LvmLvSnapshotStateInfo& info);
00071
00072 int setPeSize( long long unsigned peSizeK );
00073 void normalizeDmDevices();
00074 void getCommitActions(list<commitAction>& l) const;
00075 void getToCommit(storage::CommitStage stage, list<const Container*>& col,
00076 list<const Volume*>& vol) const;
00077 int commitChanges( storage::CommitStage stage );
00078 int resizeVolume( Volume* v, unsigned long long newSize );
00079 int removeVolume( Volume* v );
00080 void getInfo( storage::LvmVgInfo& info ) const;
00081 bool equalContent( const Container& rhs ) const;
00082
00083 void logDifference(std::ostream& log, const LvmVg& rhs) const;
00084 virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
00085
00086 static void activate(bool val);
00087 static bool isActive() { return active; }
00088
00089 static list<string> getVgs();
00090
00091 protected:
00092
00093
00094 typedef CastIterator<VIter, LvmLv *> LvmLvInter;
00095 typedef CastIterator<CVIter, const LvmLv *> LvmLvCInter;
00096 template< class Pred >
00097 struct LvmLvPI { typedef ContainerIter<Pred, LvmLvInter> type; };
00098 template< class Pred >
00099 struct LvmLvCPI { typedef ContainerIter<Pred, LvmLvCInter> type; };
00100 typedef CheckFnc<const LvmLv> CheckFncLvmLv;
00101 typedef CheckerIterator< CheckFncLvmLv, LvmLvPI<CheckFncLvmLv>::type,
00102 LvmLvInter, LvmLv > LvmLvPIterator;
00103 typedef CheckerIterator< CheckFncLvmLv, LvmLvCPI<CheckFncLvmLv>::type,
00104 LvmLvCInter, const LvmLv > LvmLvCPIterator;
00105 typedef DerefIterator<LvmLvPIterator,LvmLv> LvmLvIter;
00106 typedef DerefIterator<LvmLvCPIterator,const LvmLv> ConstLvmLvIter;
00107 typedef IterPair<LvmLvIter> LvmLvPair;
00108 typedef IterPair<ConstLvmLvIter> ConstLvmLvPair;
00109
00110 LvmLvPair lvmLvPair( bool (* Check)( const LvmLv& )=NULL)
00111 {
00112 return( LvmLvPair( lvmLvBegin( Check ), lvmLvEnd( Check ) ));
00113 }
00114 LvmLvIter lvmLvBegin( bool (* Check)( const LvmLv& )=NULL)
00115 {
00116 IterPair<LvmLvInter> p( (LvmLvInter(begin())), (LvmLvInter(end())) );
00117 return( LvmLvIter( LvmLvPIterator( p, Check )) );
00118 }
00119 LvmLvIter lvmLvEnd( bool (* Check)( const LvmLv& )=NULL)
00120 {
00121 IterPair<LvmLvInter> p( (LvmLvInter(begin())), (LvmLvInter(end())) );
00122 return( LvmLvIter( LvmLvPIterator( p, Check, true )) );
00123 }
00124
00125 ConstLvmLvPair lvmLvPair( bool (* Check)( const LvmLv& )=NULL) const
00126 {
00127 return( ConstLvmLvPair( lvmLvBegin( Check ), lvmLvEnd( Check ) ));
00128 }
00129 ConstLvmLvIter lvmLvBegin( bool (* Check)( const LvmLv& )=NULL) const
00130 {
00131 IterPair<LvmLvCInter> p( (LvmLvCInter(begin())), (LvmLvCInter(end())) );
00132 return( ConstLvmLvIter( LvmLvCPIterator( p, Check )) );
00133 }
00134 ConstLvmLvIter lvmLvEnd( bool (* Check)( const LvmLv& )=NULL) const
00135 {
00136 IterPair<LvmLvCInter> p( (LvmLvCInter(begin())), (LvmLvCInter(end())) );
00137 return( ConstLvmLvIter( LvmLvCPIterator( p, Check, true )) );
00138 }
00139
00140 void getVgData( const string& name, bool exists=true );
00141
00142 virtual void print( std::ostream& s ) const { s << *this; }
00143 virtual Container* getCopy() const { return( new LvmVg( *this ) ); }
00144
00145 Text createText(bool doing) const;
00146 Text removeText(bool doing) const;
00147 Text extendText(bool doing, const string& dev) const;
00148 Text reduceText(bool doing, const string& dev) const;
00149
00150 int doCreateVg();
00151 int doRemoveVg();
00152 int doExtendVg();
00153 int doReduceVg();
00154 int doCreate( Volume* v );
00155 int doRemove( Volume* v );
00156 int doResize( Volume* v );
00157 int doCreatePv(const Pv& pv);
00158
00159 string metaString() const;
00160 string instSysString() const;
00161
00162 virtual void logData(const string& Dir) const;
00163
00164 void addLv(unsigned long& le, string& name, string& origin, string& uuid,
00165 string& status, string& alloc, bool& ro);
00166 void addPv( Pv*& p );
00167
00168 string status;
00169 string uuid;
00170 bool lvm1;
00171
00172 static bool active;
00173
00174 mutable storage::LvmVgInfo info;
00175
00176 private:
00177
00178 LvmVg& operator=(const LvmVg&);
00179
00180 };
00181
00182 }
00183
00184 #endif