00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LOOP_CO_H
00024 #define LOOP_CO_H
00025
00026 #include "storage/Container.h"
00027 #include "storage/Loop.h"
00028
00029
00030 namespace storage
00031 {
00032 class SystemInfo;
00033
00034
00035 class LoopCo : public Container
00036 {
00037 friend class Storage;
00038
00039 public:
00040
00041 LoopCo(Storage * const s);
00042 LoopCo(Storage * const s, SystemInfo& systeminfo);
00043 LoopCo(const LoopCo& c);
00044 virtual ~LoopCo();
00045
00046 static storage::CType staticType() { return storage::LOOP; }
00047 friend std::ostream& operator<< (std::ostream&, const LoopCo& );
00048
00049 int createLoop( const string& file, bool reuseExisting,
00050 unsigned long long sizeK, bool dmcr, string& device );
00051 int updateLoop( const string& device, const string& file,
00052 bool reuseExisting, unsigned long long sizeK );
00053 int removeLoop( const string& file, bool removeFile = false );
00054
00055 list<unsigned> usedNumbers() const;
00056
00057 int removeVolume( Volume* v );
00058 bool equalContent( const Container& rhs ) const;
00059
00060 virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
00061
00062 protected:
00063
00064
00065 typedef CastIterator<VIter, Loop *> LoopInter;
00066 typedef CastIterator<CVIter, const Loop *> LoopCInter;
00067 template< class Pred >
00068 struct LoopPI { typedef ContainerIter<Pred, LoopInter> type; };
00069 template< class Pred >
00070 struct LoopCPI { typedef ContainerIter<Pred, LoopCInter> type; };
00071 typedef CheckFnc<const Loop> CheckFncLoop;
00072 typedef CheckerIterator< CheckFncLoop, LoopPI<CheckFncLoop>::type,
00073 LoopInter, Loop > LoopPIterator;
00074 typedef CheckerIterator< CheckFncLoop, LoopCPI<CheckFncLoop>::type,
00075 LoopCInter, const Loop > LoopCPIterator;
00076 typedef DerefIterator<LoopPIterator,Loop> LoopIter;
00077 typedef DerefIterator<LoopCPIterator,const Loop> ConstLoopIter;
00078 typedef IterPair<LoopIter> LoopPair;
00079 typedef IterPair<ConstLoopIter> ConstLoopPair;
00080
00081 LoopPair loopPair( bool (* Check)( const Loop& )=NULL)
00082 {
00083 return( LoopPair( loopBegin( Check ), loopEnd( Check ) ));
00084 }
00085 LoopIter loopBegin( bool (* Check)( const Loop& )=NULL)
00086 {
00087 IterPair<LoopInter> p( (LoopInter(begin())), (LoopInter(end())) );
00088 return( LoopIter( LoopPIterator( p, Check )) );
00089 }
00090 LoopIter loopEnd( bool (* Check)( const Loop& )=NULL)
00091 {
00092 IterPair<LoopInter> p( (LoopInter(begin())), (LoopInter(end())) );
00093 return( LoopIter( LoopPIterator( p, Check, true )) );
00094 }
00095
00096 ConstLoopPair loopPair( bool (* Check)( const Loop& )=NULL) const
00097 {
00098 return( ConstLoopPair( loopBegin( Check ), loopEnd( Check ) ));
00099 }
00100 ConstLoopIter loopBegin( bool (* Check)( const Loop& )=NULL) const
00101 {
00102 IterPair<LoopCInter> p( (LoopCInter(begin())), (LoopCInter(end())) );
00103 return( ConstLoopIter( LoopCPIterator( p, Check )) );
00104 }
00105 ConstLoopIter loopEnd( bool (* Check)( const Loop& )=NULL) const
00106 {
00107 IterPair<LoopCInter> p( (LoopCInter(begin())), (LoopCInter(end())) );
00108 return( ConstLoopIter( LoopCPIterator( p, Check, true )) );
00109 }
00110
00111 void getLoopData(SystemInfo& systeminfo);
00112 bool findLoop( unsigned num, LoopIter& i );
00113 bool findLoop( unsigned num );
00114 bool findLoop( const string& file, LoopIter& i );
00115 bool findLoop( const string& file );
00116 bool findLoopDev( const string& dev, LoopIter& i );
00117 void addLoop( Loop* m );
00118
00119 virtual void print( std::ostream& s ) const { s << *this; }
00120 virtual Container* getCopy() const { return( new LoopCo( *this ) ); }
00121
00122 int doCreate( Volume* v );
00123 int doRemove( Volume* v );
00124
00125 private:
00126
00127 LoopCo& operator=(const LoopCo&);
00128
00129 };
00130
00131 }
00132
00133 #endif