00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 shrinkMd(unsigned num, const list<string>& devs, const list<string>& spares);
00052 int changeMdType( unsigned num, storage::MdType ptype );
00053 int changeMdChunk( unsigned num, unsigned long chunk );
00054 int changeMdParity( unsigned num, storage::MdParity ptype );
00055 int checkMd( unsigned num );
00056 int getMdState(unsigned num, MdStateInfo& info);
00057 bool equalContent( const Container& rhs ) const;
00058
00059 virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
00060
00061 void syncMdadm(EtcMdadm* mdadm) const;
00062
00063 void changeDeviceName( const string& old, const string& nw );
00064
00065 static void activate(bool val, const string& tmpDir);
00066 int removeVolume( Volume* v );
00067
00068
00069 list<unsigned> usedNumbers() const;
00070
00071 protected:
00072
00073
00074 typedef CastIterator<VIter, Md *> MdInter;
00075 typedef CastIterator<CVIter, const Md *> MdCInter;
00076 template< class Pred >
00077 struct MdPI { typedef ContainerIter<Pred, MdInter> type; };
00078 template< class Pred >
00079 struct MdCPI { typedef ContainerIter<Pred, MdCInter> type; };
00080 typedef CheckFnc<const Md> CheckFncMd;
00081 typedef CheckerIterator< CheckFncMd, MdPI<CheckFncMd>::type,
00082 MdInter, Md > MdPIterator;
00083 typedef CheckerIterator< CheckFncMd, MdCPI<CheckFncMd>::type,
00084 MdCInter, const Md > MdCPIterator;
00085 typedef DerefIterator<MdPIterator,Md> MdIter;
00086 typedef DerefIterator<MdCPIterator,const Md> ConstMdIter;
00087 typedef IterPair<MdIter> MdPair;
00088 typedef IterPair<ConstMdIter> ConstMdPair;
00089
00090 MdPair mdPair( bool (* Check)( const Md& )=NULL)
00091 {
00092 return( MdPair( mdBegin( Check ), mdEnd( Check ) ));
00093 }
00094 MdIter mdBegin( bool (* Check)( const Md& )=NULL)
00095 {
00096 IterPair<MdInter> p( (MdInter(begin())), (MdInter(end())) );
00097 return( MdIter( MdPIterator( p, Check )) );
00098 }
00099 MdIter mdEnd( bool (* Check)( const Md& )=NULL)
00100 {
00101 IterPair<MdInter> p( (MdInter(begin())), (MdInter(end())) );
00102 return( MdIter( MdPIterator( p, Check, true )) );
00103 }
00104
00105 ConstMdPair mdPair( bool (* Check)( const Md& )=NULL) const
00106 {
00107 return( ConstMdPair( mdBegin( Check ), mdEnd( Check ) ));
00108 }
00109 ConstMdIter mdBegin( bool (* Check)( const Md& )=NULL) const
00110 {
00111 IterPair<MdCInter> p( (MdCInter(begin())), (MdCInter(end())) );
00112 return( ConstMdIter( MdCPIterator( p, Check )) );
00113 }
00114 ConstMdIter mdEnd( bool (* Check)( const Md& )=NULL) const
00115 {
00116 IterPair<MdCInter> p( (MdCInter(begin())), (MdCInter(end())) );
00117 return( ConstMdIter( MdCPIterator( p, Check, true )) );
00118 }
00119
00120 bool findMd( unsigned num, MdIter& i );
00121 bool findMd( unsigned num );
00122 bool findMd( const string& dev, MdIter& i );
00123 bool findMd( const string& dev );
00124 int checkUse(const list<string>& dev, const list<string>& spares) const;
00125 void addMd( Md* m );
00126
00127 virtual void print( std::ostream& s ) const { s << *this; }
00128 virtual Container* getCopy() const { return( new MdCo( *this ) ); }
00129
00130 int doCreate( Volume* v );
00131 int doRemove( Volume* v );
00132
00133
00134 bool isHandledByMdPart(const string& name) const;
00135
00136 static bool active;
00137
00138 private:
00139
00140 MdCo& operator=(const MdCo&);
00141
00142 };
00143
00144 }
00145
00146 #endif