00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MD_PART_CO_H
00025 #define MD_PART_CO_H
00026
00027 #include <list>
00028
00029 #include "storage/Container.h"
00030 #include "storage/Disk.h"
00031 #include "storage/Md.h"
00032 #include "storage/MdPart.h"
00033
00034 namespace storage
00035 {
00036 class Storage;
00037 class SystemInfo;
00038 class Region;
00039
00040
00047 class MdPartCo : public Container
00048 {
00049 friend class Storage;
00050 friend class Md;
00051
00052 public:
00053
00054 MdPartCo(Storage* s, const string& name, const string& device, SystemInfo& systeminfo);
00055 MdPartCo(const MdPartCo& c);
00056 virtual ~MdPartCo();
00057
00058 const string& labelName() const { return disk->labelName(); }
00059 virtual list<string> udevId() const { return udev_id; }
00060 unsigned numPartitions() const { return disk->numPartitions(); }
00061 static storage::CType staticType() { return storage::MDPART; }
00062 friend std::ostream& operator<< (std::ostream&, const MdPartCo& );
00063
00064 void setUdevData(SystemInfo& systeminfo);
00065
00066 virtual string procName() const { return nm; }
00067 virtual string sysfsPath() const;
00068
00069 static bool notDeleted(const MdPartCo& c) { return !c.deleted(); }
00070
00071 int getMdPartCoState(MdPartCoStateInfo& info) const;
00072
00073 int createPartition( storage::PartitionType type, long unsigned start,
00074 long unsigned len, string& device,
00075 bool checkRelaxed=false );
00076 int createPartition( long unsigned len, string& device,
00077 bool checkRelaxed=false );
00078 int createPartition( storage::PartitionType type, string& device );
00079 int removePartition( unsigned nr );
00080 int changePartitionId( unsigned nr, unsigned id );
00081 int forgetChangePartitionId( unsigned nr );
00082 int changePartitionArea(unsigned nr, const Region& cylRegion, bool checkRelaxed = false);
00083 int nextFreePartition(storage::PartitionType type, unsigned& nr,
00084 string& device) const;
00085 int destroyPartitionTable( const string& new_label );
00086 int freeCylindersAroundPartition(const MdPart* p, unsigned long& freeCylsBefore,
00087 unsigned long& freeCylsAfter) const;
00088 int resizePartition( MdPart* p, unsigned long newCyl );
00089 int resizeVolume( Volume* v, unsigned long long newSize );
00090 int removeVolume( Volume* v );
00091 int removeMdPart();
00092
00093 unsigned maxPrimary() const { return disk->maxPrimary(); }
00094 bool extendedPossible() const { return disk->extendedPossible(); }
00095 unsigned maxLogical() const { return disk->maxLogical(); }
00096
00097 unsigned int numPrimary() const { return disk->numPrimary(); }
00098 bool hasExtended() const { return disk->hasExtended(); }
00099 unsigned int numLogical() const { return disk->numLogical(); }
00100
00101 void getUnusedSpace(std::list<Region>& free, bool all = true, bool logical = false) const
00102 { disk->getUnusedSpace(free, all, logical); }
00103
00104 unsigned long long cylinderToKb( unsigned long val ) const
00105 { return disk->cylinderToKb( val ); }
00106 unsigned long kbToCylinder( unsigned long long val ) const
00107 { return disk->kbToCylinder( val ); }
00108
00109 string getPartName(unsigned nr) const;
00110 string getPartDevice(unsigned nr) const;
00111
00112 virtual void getCommitActions(list<commitAction>& l) const;
00113 virtual void getToCommit(CommitStage stage, list<const Container*>& col,
00114 list<const Volume*>& vol) const;
00115 virtual int commitChanges( storage::CommitStage stage );
00116 int commitChanges( storage::CommitStage stage, Volume* vol );
00117
00118 Partition* getPartition( unsigned nr, bool del );
00119
00120 virtual list<string> getUsing() const;
00121
00122 void getInfo( storage::MdPartCoInfo& info ) const;
00123 bool equalContent( const Container& rhs ) const;
00124
00125 void logDifference(std::ostream& log, const MdPartCo& rhs) const;
00126 virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
00127
00128 MdPartCo& operator= ( const MdPartCo& rhs );
00129 static string undevName( const string& name );
00130
00131 static list<string> getMdRaids(SystemInfo& systeminfo);
00132
00133 void syncMdadm(EtcMdadm* mdadm) const;
00134
00135
00136 unsigned nr() const { return mnr; }
00137
00138 unsigned long chunkSizeK() const { return chunk_k; }
00139
00140 storage::MdType personality() const { return md_type; }
00141
00142 const string& getMdUuid() const { return md_uuid; }
00143
00144
00145 list<string> getDevs(bool all = true, bool spare = false) const;
00146
00147 static void activate( bool val, const string& tmpDir );
00148
00149 static bool isActive() { return active; }
00150
00151 static bool hasPartitionTable(const string& name, SystemInfo& systeminfo);
00152 static bool hasFileSystem(const string& name, SystemInfo& systeminfo);
00153
00154 static bool matchRegex( const string& dev );
00155 static bool mdStringNum( const string& name, unsigned& num );
00156
00157
00158
00159 static bool scanForRaid(list<string>& raidNames);
00160
00161
00162
00163
00164
00165 static list<string> filterMdPartCo(const list<string>& raidList, SystemInfo& systeminfo,
00166 bool instsys);
00167
00168 protected:
00169
00170
00171 typedef CastIterator<VIter, MdPart *> MdPartInter;
00172 typedef CastIterator<CVIter, const MdPart *> MdPartCInter;
00173 template< class Pred >
00174 struct MdPartPI { typedef ContainerIter<Pred, MdPartInter> type; };
00175 template< class Pred >
00176 struct MdPartCPI { typedef ContainerIter<Pred, MdPartCInter> type; };
00177 typedef CheckFnc<const MdPart> CheckFncMdPart;
00178 typedef CheckerIterator< CheckFncMdPart, MdPartPI<CheckFncMdPart>::type,
00179 MdPartInter, MdPart > MdPartPIterator;
00180 typedef CheckerIterator< CheckFncMdPart, MdPartCPI<CheckFncMdPart>::type,
00181 MdPartCInter, const MdPart > MdPartCPIterator;
00182 typedef DerefIterator<MdPartPIterator,MdPart> MdPartIter;
00183 typedef DerefIterator<MdPartCPIterator,const MdPart> ConstMdPartIter;
00184 typedef IterPair<MdPartIter> MdPartPair;
00185 typedef IterPair<ConstMdPartIter> ConstMdPartPair;
00186
00187 MdPartPair mdpartPair( bool (* CheckMdPart)( const MdPart& )=NULL)
00188 {
00189 return( MdPartPair( mdpartBegin( CheckMdPart ), mdpartEnd( CheckMdPart ) ));
00190 }
00191 MdPartIter mdpartBegin( bool (* CheckMdPart)( const MdPart& )=NULL)
00192 {
00193 IterPair<MdPartInter> p( (MdPartInter(begin())), (MdPartInter(end())) );
00194 return( MdPartIter( MdPartPIterator( p, CheckMdPart )) );
00195 }
00196 MdPartIter mdpartEnd( bool (* CheckMdPart)( const MdPart& )=NULL)
00197 {
00198 IterPair<MdPartInter> p( (MdPartInter(begin())), (MdPartInter(end())) );
00199 return( MdPartIter( MdPartPIterator( p, CheckMdPart, true )) );
00200 }
00201
00202 ConstMdPartPair mdpartPair( bool (* CheckMdPart)( const MdPart& )=NULL) const
00203 {
00204 return( ConstMdPartPair( mdpartBegin( CheckMdPart ), mdpartEnd( CheckMdPart ) ));
00205 }
00206 ConstMdPartIter mdpartBegin( bool (* CheckMdPart)( const MdPart& )=NULL) const
00207 {
00208 IterPair<MdPartCInter> p( (MdPartCInter(begin())), (MdPartCInter(end())) );
00209 return( ConstMdPartIter( MdPartCPIterator( p, CheckMdPart )) );
00210 }
00211 ConstMdPartIter mdpartEnd( bool (* CheckMdPart)( const MdPart& )=NULL) const
00212 {
00213 IterPair<MdPartCInter> p( (MdPartCInter(begin())), (MdPartCInter(end())) );
00214 return( ConstMdPartIter( MdPartCPIterator( p, CheckMdPart, true )) );
00215 }
00216
00217 virtual void print( std::ostream& s ) const { s << *this; }
00218 virtual Container* getCopy() const { return( new MdPartCo( *this ) ); }
00219 void activate_part( bool val );
00220 void init(SystemInfo& systeminfo);
00221 void createDisk(SystemInfo& systeminfo);
00222 void getVolumes(const ProcParts& ppart);
00223 void updatePointers( bool invalid=false );
00224 void updateMinor();
00225 virtual void newP( MdPart*& dm, unsigned num, Partition* p );
00226 int addNewDev( string& device );
00227 int updateDelDev();
00228 void handleWholeDevice();
00229 void removeFromMemory();
00230 void removePresentPartitions();
00231 bool validPartition( const Partition* p );
00232 bool findMdPart( unsigned nr, MdPartIter& i );
00233
00234 bool updateEntry(EtcMdadm* mdadm) const;
00235
00236 int doCreate( Volume* v );
00237 int doRemove( Volume* v );
00238 int doResize( Volume* v );
00239 int doSetType( MdPart* v );
00240 int doCreateLabel();
00241 virtual int doRemove();
00242 virtual Text removeText( bool doing ) const;
00243 virtual Text setDiskLabelText( bool doing ) const;
00244
00245
00246 void initMd(SystemInfo& systeminfo);
00247
00248 void setSize(unsigned long long size );
00249
00250 bool isMdPart(const string& name) const;
00251
00252 void getPartNum(const string& device, unsigned& num) const;
00253
00254 void unuseDevs() const;
00255
00256 Disk* disk;
00257
00258
00259 static CType envSelection(const string& name);
00260 static bool havePartsInProc(const string& name, SystemInfo& systeminfo);
00261
00262 MdType md_type;
00263 MdParity md_parity;
00264 unsigned long chunk_k;
00265 string md_uuid;
00266 string md_name;
00267 string sb_ver;
00268 bool destrSb;
00269 list<string> devs;
00270 list<string> spare;
00271
00272 list<string> udev_id;
00273
00274
00275 bool has_container;
00276 string parent_container;
00277 string parent_uuid;
00278 string parent_md_name;
00279 string parent_metadata;
00280 string parent_member;
00281
00282 mutable storage::MdPartCoInfo info;
00283
00284 static bool active;
00285
00286 };
00287 }
00288
00289 #endif