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

Generated on Fri May 18 11:48:28 2007 for yast2-storage by  doxygen 1.4.6