Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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

Generated on Wed Sep 14 11:27:07 2005 for yast2-storage by  doxygen 1.4.4