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 "y2storage/PeContainer.h"
00027 #include "y2storage/LvmLv.h"
00028
00029 namespace storage
00030 {
00031
00032 class LvmVg : public PeContainer
00033 {
00034 friend class Storage;
00035 friend class LvmLv;
00036
00037 public:
00038 LvmVg( Storage * const s, const string& Name );
00039 LvmVg( Storage * const s, const string& Name, bool lvm1 );
00040 LvmVg( const LvmVg& c );
00041 virtual ~LvmVg();
00042 unsigned numLv() const { return vols.size(); }
00043 bool lvm2() const { return( !lvm1 ); }
00044 bool inactive() const { return( inactiv ); }
00045 static storage::CType staticType() { return storage::LVM; }
00046 friend std::ostream& operator<< (std::ostream&, const LvmVg& );
00047
00048 int removeVg();
00049 int extendVg( const std::list<string>& dl );
00050 int extendVg( const string& device );
00051 int reduceVg( const std::list<string>& dl );
00052 int reduceVg( const string& device );
00053 int createLv( const string& name, unsigned long long sizeK,
00054 unsigned stripe, string& device );
00055 int removeLv( const string& name );
00056 int changeStripe( const string& name, unsigned long stripe );
00057 int changeStripeSize( const string& name,
00058 unsigned long long stripeSize );
00059
00060 int createLvSnapshot(const string& origin, const string& name,
00061 unsigned long long cowSizeK, string& device);
00062 int removeLvSnapshot(const string& name);
00063 int getLvSnapshotState(const string& name, LvmLvSnapshotStateInfo& info);
00064
00065 int setPeSize( long long unsigned peSizeK );
00066 void normalizeDmDevices();
00067 void getCommitActions( std::list<storage::commitAction*>& l ) const;
00068 int commitChanges( storage::CommitStage stage );
00069 int getToCommit( storage::CommitStage stage, std::list<Container*>& col,
00070 std::list<Volume*>& vol );
00071 int resizeVolume( Volume* v, unsigned long long newSize );
00072 int removeVolume( Volume* v );
00073 void getInfo( storage::LvmVgInfo& info ) const;
00074 bool equalContent( const Container& rhs ) const;
00075 void logDifference( const Container& rhs ) const;
00076
00077 static void activate( bool val=true );
00078 static bool isActive() { return active; }
00079
00080 static void getVgs( std::list<string>& l );
00081 static bool lvNotDeleted( const LvmLv& l ) { return( !l.deleted() ); }
00082
00083 protected:
00084
00085
00086 typedef CastIterator<VIter, LvmLv *> LvmLvInter;
00087 typedef CastIterator<CVIter, const LvmLv *> LvmLvCInter;
00088 template< class Pred >
00089 struct LvmLvPI { typedef ContainerIter<Pred, LvmLvInter> type; };
00090 template< class Pred >
00091 struct LvmLvCPI { typedef ContainerIter<Pred, LvmLvCInter> type; };
00092 typedef CheckFnc<const LvmLv> CheckFncLvmLv;
00093 typedef CheckerIterator< CheckFncLvmLv, LvmLvPI<CheckFncLvmLv>::type,
00094 LvmLvInter, LvmLv > LvmLvPIterator;
00095 typedef CheckerIterator< CheckFncLvmLv, LvmLvCPI<CheckFncLvmLv>::type,
00096 LvmLvCInter, const LvmLv > LvmLvCPIterator;
00097 typedef DerefIterator<LvmLvPIterator,LvmLv> LvmLvIter;
00098 typedef DerefIterator<LvmLvCPIterator,const LvmLv> ConstLvmLvIter;
00099 typedef IterPair<LvmLvIter> LvmLvPair;
00100 typedef IterPair<ConstLvmLvIter> ConstLvmLvPair;
00101
00102 LvmLvPair lvmLvPair( bool (* Check)( const LvmLv& )=NULL)
00103 {
00104 return( LvmLvPair( lvmLvBegin( Check ), lvmLvEnd( Check ) ));
00105 }
00106 LvmLvIter lvmLvBegin( bool (* Check)( const LvmLv& )=NULL)
00107 {
00108 IterPair<LvmLvInter> p( (LvmLvInter(begin())), (LvmLvInter(end())) );
00109 return( LvmLvIter( LvmLvPIterator( p, Check )) );
00110 }
00111 LvmLvIter lvmLvEnd( bool (* Check)( const LvmLv& )=NULL)
00112 {
00113 IterPair<LvmLvInter> p( (LvmLvInter(begin())), (LvmLvInter(end())) );
00114 return( LvmLvIter( LvmLvPIterator( p, Check, true )) );
00115 }
00116
00117 ConstLvmLvPair lvmLvPair( bool (* Check)( const LvmLv& )=NULL) const
00118 {
00119 return( ConstLvmLvPair( lvmLvBegin( Check ), lvmLvEnd( Check ) ));
00120 }
00121 ConstLvmLvIter lvmLvBegin( bool (* Check)( const LvmLv& )=NULL) const
00122 {
00123 IterPair<LvmLvCInter> p( (LvmLvCInter(begin())), (LvmLvCInter(end())) );
00124 return( ConstLvmLvIter( LvmLvCPIterator( p, Check )) );
00125 }
00126 ConstLvmLvIter lvmLvEnd( bool (* Check)( const LvmLv& )=NULL) const
00127 {
00128 IterPair<LvmLvCInter> p( (LvmLvCInter(begin())), (LvmLvCInter(end())) );
00129 return( ConstLvmLvIter( LvmLvCPIterator( p, Check, true )) );
00130 }
00131
00132 LvmVg( Storage * const s, const string& File, int );
00133
00134 void getVgData( const string& name, bool exists=true );
00135 void init();
00136 virtual void print( std::ostream& s ) const { s << *this; }
00137 virtual Container* getCopy() const { return( new LvmVg( *this ) ); }
00138
00139 string createVgText( bool doing ) const;
00140 string removeVgText( bool doing ) const;
00141 string extendVgText( bool doing, const string& dev ) const;
00142 string reduceVgText( bool doing, const string& dev ) const;
00143
00144 int doCreateVg();
00145 int doRemoveVg();
00146 int doExtendVg();
00147 int doReduceVg();
00148 int doCreate( Volume* v );
00149 int doRemove( Volume* v );
00150 int doResize( Volume* v );
00151 int doCreatePv(const Pv& pv) const;
00152
00153 string metaString() const;
00154 string instSysString();
00155
00156 void logData( const string& Dir );
00157 void addLv(unsigned long& le, string& name, string& origin, string& uuid,
00158 string& status, string& alloc, bool& ro);
00159 void addPv( Pv*& p );
00160
00161 string status;
00162 string uuid;
00163 bool lvm1;
00164 bool inactiv;
00165 unsigned num_lv;
00166 static bool active;
00167 mutable storage::LvmVgInfo info;
00168 };
00169
00170 }
00171
00172 #endif