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 "y2storage/Container.h"
00030 #include "y2storage/Disk.h"
00031 #include "y2storage/MdPart.h"
00032
00033 namespace storage
00034 {
00035
00036 class Storage;
00037 class SystemCmd;
00038 class ProcPart;
00039 class Region;
00040 class EtcRaidtab;
00041
00048 class MdPartCo : public Container
00049 {
00050 friend class Storage;
00051
00052 public:
00053 MdPartCo( Storage * const s,
00054 const string& Name,
00055 ProcPart* ppart = NULL);
00056
00057 MdPartCo( const MdPartCo& rhs );
00058
00059 virtual ~MdPartCo();
00060
00061 unsigned long long sizeK() const { return size_k; }
00062 const string& labelName() const { return disk->labelName(); }
00063 const string& udevPath() const { return udev_path; }
00064 const std::list<string>& udevId() const { return udev_id; }
00065 unsigned numPartitions() const { return disk->numPartitions(); }
00066 static storage::CType staticType() { return storage::MDPART; }
00067 friend std::ostream& operator<< (std::ostream&, const MdPartCo& );
00068 void setUdevData(const list<string>& id);
00069
00070
00071 bool matchMdName(const string& name ) { return (name==nm); }
00072
00073 void getMdPartCoState(storage::MdPartCoStateInfo& info);
00074
00075 int createPartition( storage::PartitionType type, long unsigned start,
00076 long unsigned len, string& device,
00077 bool checkRelaxed=false );
00078 int createPartition( long unsigned len, string& device,
00079 bool checkRelaxed=false );
00080 int createPartition( storage::PartitionType type, string& device );
00081 int removePartition( unsigned nr );
00082 int changePartitionId( unsigned nr, unsigned id );
00083 int forgetChangePartitionId( unsigned nr );
00084 int changePartitionArea( unsigned nr, unsigned long start,
00085 unsigned long size, bool checkRelaxed=false );
00086 int nextFreePartition(storage::PartitionType type, unsigned& nr,
00087 string& device) const;
00088 int destroyPartitionTable( const string& new_label );
00089 int freeCylindersAfterPartition(const MdPart* p, unsigned long& freeCyls) const;
00090 int resizePartition( MdPart* p, unsigned long newCyl );
00091 int resizeVolume( Volume* v, unsigned long long newSize );
00092 int removeVolume( Volume* v );
00093 int removeMdPart();
00094
00095 unsigned maxPrimary() const { return disk->maxPrimary(); }
00096 bool extendedPossible() const { return disk->extendedPossible(); }
00097 unsigned maxLogical() const { return disk->maxLogical(); }
00098
00099 unsigned int numPrimary() const { return disk->numPrimary(); }
00100 bool hasExtended() const { return disk->hasExtended(); }
00101 unsigned int numLogical() const { return disk->numLogical(); }
00102
00103 void getUnusedSpace(std::list<Region>& free, bool all = true, bool logical = false) const
00104 { disk->getUnusedSpace(free, all, logical); }
00105
00106 unsigned long long cylinderToKb( unsigned long val ) const
00107 { return disk->cylinderToKb( val ); }
00108 unsigned long kbToCylinder( unsigned long long val ) const
00109 { return disk->kbToCylinder( val ); }
00110 string getPartName( unsigned nr ) const;
00111
00112 virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00113 virtual int getToCommit( storage::CommitStage stage,
00114 std::list<Container*>& col,
00115 std::list<Volume*>& vol );
00116 virtual int commitChanges( storage::CommitStage stage );
00117 int commitChanges( storage::CommitStage stage, Volume* vol );
00118
00119 Partition* getPartition( unsigned nr, bool del );
00120 int getPartitionInfo(deque<storage::PartitionInfo>& plist);
00121 void getInfo( storage::MdPartCoInfo& info ) const;
00122 bool equalContent( const Container& rhs ) const;
00123 virtual string getDiffString( const Container& d ) const;
00124 void logDifference( const MdPartCo& d ) const;
00125 MdPartCo& operator= ( const MdPartCo& rhs );
00126 static string undevName( const string& name );
00127 string numToName( unsigned mdNum ) const;
00128
00129 static list<string> getMdRaids();
00130
00131 void syncRaidtab();
00132
00133
00134 int nr(const string& name);
00135
00136 int nr();
00137
00138 unsigned long chunkSize() const { return chunk_size; }
00139
00140 storage::MdType personality() const { return md_type; }
00141
00142 storage::MdArrayState getArrayState() { return md_state; };
00143
00144 void getMdUuid( string&val ) { val=md_uuid; }
00145
00146
00147 const string& pName() const { return md_names[md_type]; }
00148
00149 const string& ptName() const { return par_names[md_parity]; }
00150
00151 void getDevs( std::list<string>& devices, bool all=true, bool spare=false ) const;
00152
00153
00154 void getSpareDevs(std::list<string>& devices );
00155
00156
00157 static bool matchMdRegex( const string& dev );
00158
00159 static unsigned mdMajor();
00160
00161
00162 static const string& pName( storage::MdType t ) { return md_names[t]; }
00163
00164 static void activate( bool val, const string& tmpDir );
00165
00166 static bool isActive( void ) { return active; }
00167
00168
00169 static bool hasPartitionTable(const string& name );
00170
00171 static bool hasFileSystem(const string& name);
00172
00173 static bool isImsmPlatform();
00174
00175 static bool matchRegex( const string& dev );
00176 static bool mdStringNum( const string& name, unsigned& num );
00177
00178
00179
00180 static int scanForRaid(list<string>& raidNames);
00181
00182
00183
00184
00185
00186 static list<string> filterMdPartCo(list<string>& raidList,
00187 ProcPart& ppart,
00188 bool isInst);
00189
00190
00191
00192 static bool getUuidName(const string dev,string& uuid, string& mdName);
00193
00194 protected:
00195
00196
00197 typedef CastIterator<VIter, MdPart *> MdPartInter;
00198 typedef CastIterator<CVIter, const MdPart *> MdPartCInter;
00199 template< class Pred >
00200 struct MdPartPI { typedef ContainerIter<Pred, MdPartInter> type; };
00201 template< class Pred >
00202 struct MdPartCPI { typedef ContainerIter<Pred, MdPartCInter> type; };
00203 typedef CheckFnc<const MdPart> CheckFncMdPart;
00204 typedef CheckerIterator< CheckFncMdPart, MdPartPI<CheckFncMdPart>::type,
00205 MdPartInter, MdPart > MdPartPIterator;
00206 typedef CheckerIterator< CheckFncMdPart, MdPartCPI<CheckFncMdPart>::type,
00207 MdPartCInter, const MdPart > MdPartCPIterator;
00208 typedef DerefIterator<MdPartPIterator,MdPart> MdPartIter;
00209 typedef DerefIterator<MdPartCPIterator,const MdPart> ConstMdPartIter;
00210 typedef IterPair<MdPartIter> MdPartPair;
00211 typedef IterPair<ConstMdPartIter> ConstMdPartPair;
00212
00213 MdPartPair mdpartPair( bool (* CheckMdPart)( const MdPart& )=NULL)
00214 {
00215 return( MdPartPair( mdpartBegin( CheckMdPart ), mdpartEnd( CheckMdPart ) ));
00216 }
00217 MdPartIter mdpartBegin( bool (* CheckMdPart)( const MdPart& )=NULL)
00218 {
00219 IterPair<MdPartInter> p( (MdPartInter(begin())), (MdPartInter(end())) );
00220 return( MdPartIter( MdPartPIterator( p, CheckMdPart )) );
00221 }
00222 MdPartIter mdpartEnd( bool (* CheckMdPart)( const MdPart& )=NULL)
00223 {
00224 IterPair<MdPartInter> p( (MdPartInter(begin())), (MdPartInter(end())) );
00225 return( MdPartIter( MdPartPIterator( p, CheckMdPart, true )) );
00226 }
00227
00228 ConstMdPartPair mdpartPair( bool (* CheckMdPart)( const MdPart& )=NULL) const
00229 {
00230 return( ConstMdPartPair( mdpartBegin( CheckMdPart ), mdpartEnd( CheckMdPart ) ));
00231 }
00232 ConstMdPartIter mdpartBegin( bool (* CheckMdPart)( const MdPart& )=NULL) const
00233 {
00234 IterPair<MdPartCInter> p( (MdPartCInter(begin())), (MdPartCInter(end())) );
00235 return( ConstMdPartIter( MdPartCPIterator( p, CheckMdPart )) );
00236 }
00237 ConstMdPartIter mdpartEnd( bool (* CheckMdPart)( const MdPart& )=NULL) const
00238 {
00239 IterPair<MdPartCInter> p( (MdPartCInter(begin())), (MdPartCInter(end())) );
00240 return( ConstMdPartIter( MdPartCPIterator( p, CheckMdPart, true )) );
00241 }
00242
00243 MdPartCo( Storage * const s, const string& File );
00244 virtual void print( std::ostream& s ) const { s << *this; }
00245 virtual Container* getCopy() const { return( new MdPartCo( *this ) ); }
00246 void activate_part( bool val );
00247 void init( ProcPart* ppart );
00248 void createDisk( ProcPart* ppart );
00249 void getVolumes( ProcPart* ppart );
00250 void updatePointers( bool invalid=false );
00251 void updateMinor();
00252 virtual void newP( MdPart*& dm, unsigned num, Partition* p );
00253 int addNewDev( string& device );
00254 int updateDelDev();
00255 void handleWholeDevice();
00256 void removeFromMemory();
00257 void removePresentPartitions();
00258 bool validPartition( const Partition* p );
00259 bool findMdPart( unsigned nr, MdPartIter& i );
00260
00261 void updateEntry();
00262 string mdadmLine() const;
00263 void raidtabLines( list<string>& lines ) const;
00264
00265
00266 static bool partNotDeleted( const MdPart&d ) { return( !d.deleted() ); }
00267
00268 int doCreate( Volume* v );
00269 int doRemove( Volume* v );
00270 int doResize( Volume* v );
00271 int doSetType( MdPart* v );
00272 int doCreateLabel();
00273 virtual int doRemove();
00274 virtual string removeText( bool doing ) const;
00275 virtual string setDiskLabelText( bool doing ) const;
00276
00277 void getMajorMinor(void);
00278
00279
00280 void makeDevName(const string& name );
00281
00282 void initMd(void);
00283
00284 void setSize(unsigned long long size );
00285
00286 static bool isMdName(const string& name);
00287
00288 bool isMdPart(const string& name);
00289
00290 void getPartNum(const string& device, unsigned& num);
00291
00292 void getMdProps(void);
00293
00294 void setSpares(void);
00295
00296 int unuseDevs(void);
00297
00298 void logData( const string& Dir );
00299 string udev_path;
00300 std::list<string> udev_id;
00301 string logfile_name;
00302
00303 Disk* disk;
00304 bool del_ptable;
00305 unsigned num_part;
00306
00307
00308
00309
00310 void getParent();
00311
00312 void setMetaData();
00313
00314 void setMdDevs();
00315
00316 void setMdParity();
00317
00318
00319 void getSlaves(const string name, std::list<string>& devs_list );
00320
00321
00322 enum mdMap { MAP_DEV=0, MAP_META, MAP_UUID, MAP_NAME, };
00323 static bool findMdMap(std::ifstream& file);
00324
00325 string getContMember() const;
00326
00327
00328 static storage::CType envSelection(const string& name);
00329 static bool havePartsInProc(const string& name, ProcPart& ppart);
00330
00331 static void getMdMajor();
00332 static storage::MdType toMdType( const string& val );
00333 static storage::MdParity toMdParity( const string& val );
00334 static storage::MdArrayState toMdArrayState( const string& val );
00335
00336
00337
00338 unsigned long chunk_size;
00339 storage::MdType md_type;
00340 storage::MdParity md_parity;
00341 storage::MdArrayState md_state;
00342
00343
00344 bool has_container;
00345 string parent_container;
00346 string parent_uuid;
00347 string parent_metadata;
00348 string parent_md_name;
00349 string md_metadata;
00350 string md_uuid;
00351 string sb_ver;
00352 bool destrSb;
00353 std::list<string> devs;
00354 std::list<string> spare;
00355 static string md_names[storage::MULTIPATH+1];
00356 static string par_names[storage::RIGHT_SYMMETRIC+1];
00357 static string md_states[storage::ACTIVE_IDLE+1];
00358 static unsigned md_major;
00359
00360
00361 string md_name;
00362
00363 static string sysfs_path;
00364
00365 enum MdProperty
00366 {
00367 METADATA=0,
00368 COMPONENT_SIZE,
00369 CHUNK_SIZE,
00370 ARRAY_STATE,
00371 LEVEL,
00372 LAYOUT,
00373
00374 MDPROP_LAST,
00375 };
00376 static string md_props[MDPROP_LAST];
00377
00378 bool readProp(enum MdProperty prop, string& val);
00379
00380
00381 bool hasParity() const
00382 { return md_type == RAID5 || md_type == RAID6 || md_type == RAID10; }
00383
00384 mutable storage::MdPartCoInfo info;
00385
00386 static bool active;
00387
00388 };
00389 }
00390
00391 #endif