EvmsCo.h

Go to the documentation of this file.
00001 #ifndef EVMS_CO_H
00002 #define EVMS_CO_H
00003 
00004 #include <list>
00005 #include <map>
00006 
00007 #include "y2storage/PeContainer.h"
00008 #include "y2storage/Evms.h"
00009 
00010 namespace storage
00011 {
00012 
00013 struct EvmsObj
00014     {
00015     EvmsObj( unsigned i=0, const string& n="", unsigned v=0 ) : id(i), vol(v), name(n) {}
00016     unsigned id;
00017     unsigned vol;
00018     string name;
00019     inline bool operator== ( const EvmsObj& rhs ) const
00020         { return( id==rhs.id && name==rhs.name && vol==rhs.vol ); }
00021     };
00022 
00023 struct EvmsVol
00024     {
00025     EvmsVol( unsigned i=0, const string& n="", unsigned s=0 ) : id(i),  sizeK(s), name(n) {native=false; uses=0;}
00026     unsigned id;
00027     unsigned long long sizeK;
00028     bool native;
00029     string name;
00030     string device;
00031     unsigned uses;
00032     inline bool operator==( const EvmsVol& rhs ) const
00033         { return( id==rhs.id && name==rhs.name && sizeK==rhs.sizeK && 
00034                   device==rhs.device ); }
00035     };
00036 
00037 struct EvmsCont
00038     {
00039     struct peinfo
00040         {
00041         peinfo() { id=size=free=0; }
00042         unsigned id;
00043         unsigned long long size;
00044         unsigned long long free;
00045         string uuid;
00046         inline bool operator==( const peinfo& rhs ) const
00047             { return( id==rhs.id && size==rhs.size && free==rhs.free && 
00048                       uuid==rhs.uuid ); }
00049         };
00050         
00051     EvmsCont( const string& n="" ) : name(n) 
00052         {lvm1=true; peSize=free=sizeK=0; }
00053     string name;
00054     string uuid;
00055     bool lvm1;
00056     unsigned long long peSize;
00057     unsigned long long free;
00058     unsigned long long sizeK;
00059     std::list<peinfo> consumes;
00060     std::list<unsigned> creates;
00061     inline bool operator==( const EvmsCont& rhs ) const
00062         { return( peSize==rhs.peSize && name==rhs.name && lvm1==rhs.lvm1 &&
00063                   sizeK==rhs.sizeK && consumes==rhs.consumes &&
00064                   creates==rhs.creates ); }
00065     };
00066 
00067 struct EvmsTree
00068     {
00069     EvmsTree() {}
00070     std::map<unsigned,EvmsObj> objects;
00071     std::map<unsigned,EvmsVol> volumes;
00072     std::list<EvmsCont> cont;
00073     inline bool operator==( const EvmsTree& rhs ) const
00074         { return( objects==rhs.objects && volumes==rhs.volumes && cont==rhs.cont ); }
00075     };
00076 
00077 std::ostream& operator<< (std::ostream&, const EvmsTree& );
00078 std::ostream& operator<< (std::ostream&, const EvmsCont& );
00079 std::ostream& operator<< (std::ostream&, const EvmsVol& );
00080 std::ostream& operator<< (std::ostream&, const EvmsObj& );
00081 
00082 class EvmsCo : public PeContainer
00083     {
00084     friend class Storage;
00085 
00086     public:
00087         EvmsCo( Storage * const s, const EvmsTree& data );
00088         EvmsCo( Storage * const s, const EvmsCont& cont, const EvmsTree& data );
00089         EvmsCo( Storage * const s, const string& name, bool lvm1 );
00090         EvmsCo( const EvmsCo& c );
00091         virtual ~EvmsCo();
00092         unsigned numVol() const { return vols.size(); }
00093         bool lvm2() const { return( !lvm1 ); }
00094         bool isContainer() const { return( container ); } 
00095         bool isValid() const { return( valid ); }
00096         static storage::CType staticType() { return storage::EVMS; }
00097         friend std::ostream& operator<< (std::ostream&, const EvmsCo& );
00098 
00099         int removeCo();
00100         int extendCo( const std::list<string>& dl );
00101         int extendCo( const string& device );
00102         int reduceCo( const std::list<string>& dl );
00103         int reduceCo( const string& device );
00104         int modifyCo( const string& name, long long unsigned peSizeK, 
00105                       bool lvm1 );
00106         int createVol( const string& name, unsigned long long sizeK, 
00107                        unsigned stripe, string& device );
00108         int removeVol( const string& name );
00109         int changeStripe( const string& name, unsigned long stripe );
00110         int changeStripeSize( const string& name,  
00111                               unsigned long long stripeSize );
00112 
00113         int setPeSize( long long unsigned peSizeK );
00114 
00115         void getCommitActions( std::list<storage::commitAction*>& l ) const;
00116         int commitChanges( storage::CommitStage stage );
00117         int getToCommit( storage::CommitStage stage, std::list<Container*>& col,
00118                          std::list<Volume*>& vol );
00119         int resizeVolume( Volume* v, unsigned long long newSize );
00120         int removeVolume( Volume* v );
00121         void addVolume( Evms* v );
00122         void getInfo( storage::EvmsCoInfo& info ) const;
00123         bool equalContent( const Container& rhs ) const;
00124         void logDifference( const Container& d ) const;
00125         bool checkConsistency() const;
00126         void updateMd();
00127         void changeDeviceName( const string& old, const string& nw );
00128 
00129         static void activate( bool val=true );
00130         static int activateDevices();
00131         static bool canDoEvms();
00132         static void getEvmsList( EvmsTree& data );
00133         static bool lvNotDeleted( const Evms& l ) { return( !l.deleted() ); }
00134         
00135     protected:
00136         // iterators over EVMS Volumes
00137         // protected typedefs for iterators over EVMS Volumes
00138         typedef CastIterator<VIter, Evms *> EvmsInter;
00139         typedef CastIterator<CVIter, const Evms *> EvmsCInter;
00140         template< class Pred >
00141             struct EvmsPI { typedef ContainerIter<Pred, EvmsInter> type; };
00142         template< class Pred >
00143             struct EvmsCPI { typedef ContainerIter<Pred, EvmsCInter> type; };
00144         typedef CheckFnc<const Evms> CheckFncEvms;
00145         typedef CheckerIterator< CheckFncEvms, EvmsPI<CheckFncEvms>::type,
00146                                  EvmsInter, Evms > EvmsPIterator;
00147         typedef CheckerIterator< CheckFncEvms, EvmsCPI<CheckFncEvms>::type,
00148                                  EvmsCInter, const Evms > EvmsCPIterator;
00149         typedef DerefIterator<EvmsPIterator,Evms> EvmsIter;
00150         typedef DerefIterator<EvmsCPIterator,const Evms> ConstEvmsIter;
00151         typedef IterPair<EvmsIter> EvmsPair;
00152         typedef IterPair<ConstEvmsIter> ConstEvmsPair;
00153 
00154         EvmsPair evmsPair( bool (* Check)( const Evms& )=NULL)
00155             {
00156             return( EvmsPair( evmsBegin( Check ), evmsEnd( Check ) ));
00157             }
00158         EvmsIter evmsBegin( bool (* Check)( const Evms& )=NULL)
00159             {
00160             IterPair<EvmsInter> p( (EvmsInter(begin())), (EvmsInter(end())) );
00161             return( EvmsIter( EvmsPIterator( p, Check )) );
00162             }
00163         EvmsIter evmsEnd( bool (* Check)( const Evms& )=NULL)
00164             {
00165             IterPair<EvmsInter> p( (EvmsInter(begin())), (EvmsInter(end())) );
00166             return( EvmsIter( EvmsPIterator( p, Check, true )) );
00167             }
00168 
00169         ConstEvmsPair evmsPair( bool (* Check)( const Evms& )=NULL) const
00170             {
00171             return( ConstEvmsPair( evmsBegin( Check ), evmsEnd( Check ) ));
00172             }
00173         ConstEvmsIter evmsBegin( bool (* Check)( const Evms& )=NULL) const
00174             {
00175             IterPair<EvmsCInter> p( (EvmsCInter(begin())), (EvmsCInter(end())) );
00176             return( ConstEvmsIter( EvmsCPIterator( p, Check )) );
00177             }
00178         ConstEvmsIter evmsEnd( bool (* Check)( const Evms& )=NULL) const
00179             {
00180             IterPair<EvmsCInter> p( (EvmsCInter(begin())), (EvmsCInter(end())) );
00181             return( ConstEvmsIter( EvmsCPIterator( p, Check, true )) );
00182             }
00183 
00184         EvmsCo( Storage * const s, const string& File, int );
00185 
00186         bool getCoData( const string& name, const EvmsTree& data, 
00187                         bool check=false );
00188         void getNormalVolumes( const EvmsTree& data );
00189         void setUsed( const string& device, storage::UsedByType typ,
00190                       const string& name );
00191         void init();
00192         virtual void print( std::ostream& s ) const { s << *this; }
00193         virtual Container* getCopy() const { return( new EvmsCo( *this ) ); }
00194 
00195         string createCoText( bool doing ) const;
00196         string removeCoText( bool doing ) const;
00197         string extendCoText( bool doing, const string& dev ) const;
00198         string reduceCoText( bool doing, const string& dev ) const;
00199 
00200         int doCreateCo();
00201         int doRemoveCo();
00202         int doExtendCo();
00203         int doReduceCo();
00204         int doCreate( Volume* v );
00205         int doRemove( Volume* v );
00206         int doResize( Volume* v );
00207 
00208         void logData( const string& Dir );
00209         void addLv( unsigned long le, const string& name, bool native );
00210         void addPv( const Pv* p );
00211         string evmsNormalizeDevice( const string& dev ) const;
00212         static bool attachToSocket( bool attach=true );
00213         static bool sendCommand( const string& cmd, bool one_line, 
00214                                  std::list<string>& lines );
00215         static int getSocketFd();
00216         static bool startHelper( bool retry=false );
00217         static int executeCmd( const string& cmd );
00218         static string devToEvms( const string& dev );
00219         static string evmsToDev( const string& edev );
00220 
00221         string uuid;
00222         bool lvm1;
00223         bool container;
00224         bool valid;
00225         static bool active;
00226         static int sockfd;
00227         mutable storage::EvmsCoInfo info;
00228     };
00229 
00230 }
00231 
00232 #endif

Generated on Wed Apr 30 15:02:08 2008 for yast2-storage by  doxygen 1.4.6