yast2-storage

MdCo.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) [2004-2010] Novell, Inc.
00003  *
00004  * All Rights Reserved.
00005  *
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of version 2 of the GNU General Public License as published
00008  * by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but WITHOUT
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013  * more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, contact Novell, Inc.
00017  *
00018  * To contact Novell about this file by physical or electronic mail, you may
00019  * find current contact information at www.novell.com.
00020  */
00021 
00022 
00023 #ifndef MD_CO_H
00024 #define MD_CO_H
00025 
00026 #include "storage/Container.h"
00027 #include "storage/Md.h"
00028 
00029 namespace storage
00030 {
00031 
00032     class EtcMdadm;
00033 
00034 class MdCo : public Container
00035     {
00036     friend class Storage;
00037 
00038     public:
00039 
00040         MdCo(Storage * const s);
00041         MdCo(Storage * const s, SystemInfo& systeminfo);
00042         MdCo(const MdCo& c);    
00043         virtual ~MdCo();
00044 
00045         static storage::CType staticType() { return storage::MD; }
00046         friend std::ostream& operator<< (std::ostream&, const MdCo& );
00047 
00048         int createMd(unsigned num, MdType type, const list<string>& devs, const list<string>& spares);
00049         int removeMd( unsigned num, bool destroySb=true );
00050         int extendMd(unsigned num, const list<string>& devs, const list<string>& spares);
00051         int updateMd(unsigned num, const list<string>& devs, const list<string>& spares);
00052         int shrinkMd(unsigned num, const list<string>& devs, const list<string>& spares);
00053         int changeMdType( unsigned num, storage::MdType ptype );
00054         int changeMdChunk( unsigned num, unsigned long chunk );
00055         int changeMdParity( unsigned num, storage::MdParity ptype );
00056         int checkMd( unsigned num );
00057         int getMdState(unsigned num, MdStateInfo& info);
00058         bool equalContent( const Container& rhs ) const;
00059 
00060         virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
00061 
00062         void syncMdadm(EtcMdadm* mdadm) const;
00063 
00064         void changeDeviceName( const string& old, const string& nw );
00065 
00066         static void activate(bool val, const string& tmpDir);
00067         int removeVolume( Volume* v );
00068         
00069         /* returns in 'nums' numbers that are used by Md */
00070         list<unsigned> usedNumbers() const;
00071 
00072     protected:
00073         // iterators over MD volumes
00074         // protected typedefs for iterators over MD volumes
00075         typedef CastIterator<VIter, Md *> MdInter;
00076         typedef CastIterator<CVIter, const Md *> MdCInter;
00077         template< class Pred >
00078             struct MdPI { typedef ContainerIter<Pred, MdInter> type; };
00079         template< class Pred >
00080             struct MdCPI { typedef ContainerIter<Pred, MdCInter> type; };
00081         typedef CheckFnc<const Md> CheckFncMd;
00082         typedef CheckerIterator< CheckFncMd, MdPI<CheckFncMd>::type,
00083                                  MdInter, Md > MdPIterator;
00084         typedef CheckerIterator< CheckFncMd, MdCPI<CheckFncMd>::type,
00085                                  MdCInter, const Md > MdCPIterator;
00086         typedef DerefIterator<MdPIterator,Md> MdIter;
00087         typedef DerefIterator<MdCPIterator,const Md> ConstMdIter;
00088         typedef IterPair<MdIter> MdPair;
00089         typedef IterPair<ConstMdIter> ConstMdPair;
00090 
00091         MdPair mdPair( bool (* Check)( const Md& )=NULL)
00092             {
00093             return( MdPair( mdBegin( Check ), mdEnd( Check ) ));
00094             }
00095         MdIter mdBegin( bool (* Check)( const Md& )=NULL)
00096             {
00097             IterPair<MdInter> p( (MdInter(begin())), (MdInter(end())) );
00098             return( MdIter( MdPIterator( p, Check )) );
00099             }
00100         MdIter mdEnd( bool (* Check)( const Md& )=NULL)
00101             {
00102             IterPair<MdInter> p( (MdInter(begin())), (MdInter(end())) );
00103             return( MdIter( MdPIterator( p, Check, true )) );
00104             }
00105 
00106         ConstMdPair mdPair( bool (* Check)( const Md& )=NULL) const
00107             {
00108             return( ConstMdPair( mdBegin( Check ), mdEnd( Check ) ));
00109             }
00110         ConstMdIter mdBegin( bool (* Check)( const Md& )=NULL) const
00111             {
00112             IterPair<MdCInter> p( (MdCInter(begin())), (MdCInter(end())) );
00113             return( ConstMdIter( MdCPIterator( p, Check )) );
00114             }
00115         ConstMdIter mdEnd( bool (* Check)( const Md& )=NULL) const
00116             {
00117             IterPair<MdCInter> p( (MdCInter(begin())), (MdCInter(end())) );
00118             return( ConstMdIter( MdCPIterator( p, Check, true )) );
00119             }
00120 
00121         bool findMd( unsigned num, MdIter& i );
00122         bool findMd( unsigned num ); 
00123         bool findMd( const string& dev, MdIter& i );
00124         bool findMd( const string& dev ); 
00125         int checkUse(const list<string>& dev, const list<string>& spares) const;
00126         void addMd( Md* m );
00127 
00128         virtual void print( std::ostream& s ) const { s << *this; }
00129         virtual Container* getCopy() const { return( new MdCo( *this ) ); }
00130 
00131         int doCreate( Volume* v );
00132         int doRemove( Volume* v );
00133 
00134         /* Return true if given device is alredy handled by MdPartCo. */
00135         bool isHandledByMdPart(const string& name) const;
00136 
00137         static bool active;  
00138 
00139     private:
00140 
00141         MdCo& operator=(const MdCo&); // disallow
00142 
00143     };
00144 
00145 }
00146 
00147 #endif