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