00001 #ifndef MD_CO_H
00002 #define MD_CO_H
00003
00004 #include "y2storage/Container.h"
00005 #include "y2storage/Md.h"
00006
00007 namespace storage
00008 {
00009
00010 class EtcRaidtab;
00011
00012 class MdCo : public Container
00013 {
00014 friend class Storage;
00015
00016 public:
00017 MdCo( Storage * const s, bool detect );
00018 MdCo( const MdCo& rhs );
00019
00020 virtual ~MdCo();
00021 static storage::CType staticType() { return storage::MD; }
00022 friend std::ostream& operator<< (std::ostream&, const MdCo& );
00023
00024 int createMd( unsigned num, storage::MdType type,
00025 const std::list<string>& devs );
00026 int removeMd( unsigned num, bool destroySb=true );
00027 int extendMd( unsigned num, const string& dev );
00028 int shrinkMd( unsigned num, const string& dev );
00029 int changeMdType( unsigned num, storage::MdType ptype );
00030 int changeMdChunk( unsigned num, unsigned long chunk );
00031 int changeMdParity( unsigned num, storage::MdParity ptype );
00032 int checkMd( unsigned num );
00033 int getMdState(unsigned num, MdStateInfo& info);
00034 bool equalContent( const Container& rhs ) const;
00035 void logDifference( const Container& d ) const;
00036
00037 unsigned unusedNumber();
00038 void syncRaidtab();
00039 void changeDeviceName( const string& old, const string& nw );
00040
00041 static void activate( bool val, const string& tmpDir );
00042 int removeVolume( Volume* v );
00043
00044 protected:
00045
00046
00047 typedef CastIterator<VIter, Md *> MdInter;
00048 typedef CastIterator<CVIter, const Md *> MdCInter;
00049 template< class Pred >
00050 struct MdPI { typedef ContainerIter<Pred, MdInter> type; };
00051 template< class Pred >
00052 struct MdCPI { typedef ContainerIter<Pred, MdCInter> type; };
00053 typedef CheckFnc<const Md> CheckFncMd;
00054 typedef CheckerIterator< CheckFncMd, MdPI<CheckFncMd>::type,
00055 MdInter, Md > MdPIterator;
00056 typedef CheckerIterator< CheckFncMd, MdCPI<CheckFncMd>::type,
00057 MdCInter, const Md > MdCPIterator;
00058 typedef DerefIterator<MdPIterator,Md> MdIter;
00059 typedef DerefIterator<MdCPIterator,const Md> ConstMdIter;
00060 typedef IterPair<MdIter> MdPair;
00061 typedef IterPair<ConstMdIter> ConstMdPair;
00062
00063 MdPair mdPair( bool (* Check)( const Md& )=NULL)
00064 {
00065 return( MdPair( mdBegin( Check ), mdEnd( Check ) ));
00066 }
00067 MdIter mdBegin( bool (* Check)( const Md& )=NULL)
00068 {
00069 IterPair<MdInter> p( (MdInter(begin())), (MdInter(end())) );
00070 return( MdIter( MdPIterator( p, Check )) );
00071 }
00072 MdIter mdEnd( bool (* Check)( const Md& )=NULL)
00073 {
00074 IterPair<MdInter> p( (MdInter(begin())), (MdInter(end())) );
00075 return( MdIter( MdPIterator( p, Check, true )) );
00076 }
00077
00078 ConstMdPair mdPair( bool (* Check)( const Md& )=NULL) const
00079 {
00080 return( ConstMdPair( mdBegin( Check ), mdEnd( Check ) ));
00081 }
00082 ConstMdIter mdBegin( bool (* Check)( const Md& )=NULL) const
00083 {
00084 IterPair<MdCInter> p( (MdCInter(begin())), (MdCInter(end())) );
00085 return( ConstMdIter( MdCPIterator( p, Check )) );
00086 }
00087 ConstMdIter mdEnd( bool (* Check)( const Md& )=NULL) const
00088 {
00089 IterPair<MdCInter> p( (MdCInter(begin())), (MdCInter(end())) );
00090 return( ConstMdIter( MdCPIterator( p, Check, true )) );
00091 }
00092
00093 MdCo( Storage * const s, const string& File );
00094
00095 void getMdData();
00096 void getMdData( unsigned num );
00097 bool findMd( unsigned num, MdIter& i );
00098 bool findMd( unsigned num );
00099 bool findMd( const string& dev, MdIter& i );
00100 bool findMd( const string& dev );
00101 int checkUse( const string& dev );
00102 void addMd( Md* m );
00103 void checkMd( Md* m );
00104 void updateEntry( const Md* m );
00105 void initTab();
00106
00107 void init();
00108
00109 virtual void print( std::ostream& s ) const { s << *this; }
00110 virtual Container* getCopy() const { return( new MdCo( *this ) ); }
00111
00112 int doCreate( Volume* v );
00113 int doRemove( Volume* v );
00114
00115 void logData( const string& Dir );
00116
00117 EtcRaidtab *tab;
00118
00119 static bool active;
00120 };
00121
00122 }
00123
00124 #endif