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         static storage::CType const staticType() { return storage::EVMS; }
00095         friend std::ostream& operator<< (std::ostream&, const EvmsCo& );
00096 
00097         int removeCo();
00098         int extendCo( const std::list<string>& dl );
00099         int extendCo( const string& device );
00100         int reduceCo( const std::list<string>& dl );
00101         int reduceCo( const string& device );
00102         int modifyCo( const string& name, long long unsigned peSizeK, 
00103                       bool lvm1 );
00104         int createVol( const string& name, unsigned long long sizeK, 
00105                        unsigned stripe, string& device );
00106         int removeVol( const string& name );
00107         int changeStripeSize( const string& name,  
00108                               unsigned long long stripeSize );
00109 
00110         int setPeSize( long long unsigned peSizeK );
00111 
00112         void getCommitActions( std::list<storage::commitAction*>& l ) const;
00113         int commitChanges( storage::CommitStage stage );
00114         int getToCommit( storage::CommitStage stage, std::list<Container*>& col,
00115                          std::list<Volume*>& vol );
00116         int resizeVolume( Volume* v, unsigned long long newSize );
00117         int removeVolume( Volume* v );
00118         void addVolume( Evms* v );
00119         void getInfo( storage::EvmsCoInfo& info ) const;
00120         bool equalContent( const EvmsCo& rhs ) const;
00121         void logDifference( const EvmsCo& d ) const;
00122         bool checkConsistency() const;
00123         void updateMd();
00124 
00125         static void activate( bool val=true );
00126         static int activateDevices();
00127         static bool canDoEvms();
00128         static void getEvmsList( EvmsTree& data );
00129         static bool lvNotDeleted( const Evms& l ) { return( !l.deleted() ); }
00130         
00131     protected:
00132         // iterators over EVMS Volumes
00133         // protected typedefs for iterators over EVMS Volumes
00134         typedef CastIterator<VIter, Evms *> EvmsInter;
00135         typedef CastIterator<CVIter, const Evms *> EvmsCInter;
00136         template< class Pred >
00137             struct EvmsPI { typedef ContainerIter<Pred, EvmsInter> type; };
00138         template< class Pred >
00139             struct EvmsCPI { typedef ContainerIter<Pred, EvmsCInter> type; };
00140         typedef CheckFnc<const Evms> CheckFncEvms;
00141         typedef CheckerIterator< CheckFncEvms, EvmsPI<CheckFncEvms>::type,
00142                                  EvmsInter, Evms > EvmsPIterator;
00143         typedef CheckerIterator< CheckFncEvms, EvmsCPI<CheckFncEvms>::type,
00144                                  EvmsCInter, const Evms > EvmsCPIterator;
00145         typedef DerefIterator<EvmsPIterator,Evms> EvmsIter;
00146         typedef DerefIterator<EvmsCPIterator,const Evms> ConstEvmsIter;
00147         typedef IterPair<EvmsIter> EvmsPair;
00148         typedef IterPair<ConstEvmsIter> ConstEvmsPair;
00149 
00150         EvmsPair evmsPair( bool (* Check)( const Evms& )=NULL)
00151             {
00152             return( EvmsPair( evmsBegin( Check ), evmsEnd( Check ) ));
00153             }
00154         EvmsIter evmsBegin( bool (* Check)( const Evms& )=NULL)
00155             {
00156             IterPair<EvmsInter> p( (EvmsInter(begin())), (EvmsInter(end())) );
00157             return( EvmsIter( EvmsPIterator( p, Check )) );
00158             }
00159         EvmsIter evmsEnd( bool (* Check)( const Evms& )=NULL)
00160             {
00161             IterPair<EvmsInter> p( (EvmsInter(begin())), (EvmsInter(end())) );
00162             return( EvmsIter( EvmsPIterator( p, Check, true )) );
00163             }
00164 
00165         ConstEvmsPair evmsPair( bool (* Check)( const Evms& )=NULL) const
00166             {
00167             return( ConstEvmsPair( evmsBegin( Check ), evmsEnd( Check ) ));
00168             }
00169         ConstEvmsIter evmsBegin( bool (* Check)( const Evms& )=NULL) const
00170             {
00171             IterPair<EvmsCInter> p( (EvmsCInter(begin())), (EvmsCInter(end())) );
00172             return( ConstEvmsIter( EvmsCPIterator( p, Check )) );
00173             }
00174         ConstEvmsIter evmsEnd( bool (* Check)( const Evms& )=NULL) const
00175             {
00176             IterPair<EvmsCInter> p( (EvmsCInter(begin())), (EvmsCInter(end())) );
00177             return( ConstEvmsIter( EvmsCPIterator( p, Check, true )) );
00178             }
00179 
00180         EvmsCo( Storage * const s, const string& File, int );
00181 
00182         void getCoData( const string& name, const EvmsTree& data, 
00183                         bool check=false );
00184         void getNormalVolumes( const EvmsTree& data );
00185         void setUsed( const string& device, storage::UsedByType typ,
00186                       const string& name );
00187         void init();
00188         virtual void print( std::ostream& s ) const { s << *this; }
00189         virtual Container* getCopy() const { return( new EvmsCo( *this ) ); }
00190 
00191         string createCoText( bool doing ) const;
00192         string removeCoText( bool doing ) const;
00193         string extendCoText( bool doing, const string& dev ) const;
00194         string reduceCoText( bool doing, const string& dev ) const;
00195 
00196         int doCreateCo();
00197         int doRemoveCo();
00198         int doExtendCo();
00199         int doReduceCo();
00200         int doCreate( Volume* v );
00201         int doRemove( Volume* v );
00202         int doResize( Volume* v );
00203 
00204         void logData( const string& Dir );
00205         void addLv( unsigned long le, const string& name, bool native );
00206         void addPv( const Pv* p );
00207         string evmsNormalizeDevice( const string& dev ) const;
00208         static bool attachToSocket( bool attach=true );
00209         static bool sendCommand( const string& cmd, bool one_line, 
00210                                  std::list<string>& lines );
00211         static int getSocketFd();
00212         static bool startHelper( bool retry=false );
00213         static int executeCmd( const string& cmd );
00214         static string devToEvms( const string& dev );
00215         static string evmsToDev( const string& edev );
00216 
00217         string uuid;
00218         bool lvm1;
00219         static bool active;
00220         static int sockfd;
00221         mutable storage::EvmsCoInfo info;
00222     };
00223 
00224 }
00225 
00226 #endif

Generated on Thu Jul 6 00:40:24 2006 for yast2-storage by  doxygen 1.4.6