Storage.h

Go to the documentation of this file.
00001 #ifndef STORAGE_H
00002 #define STORAGE_H
00003 
00004 #include <iostream>
00005 #include <list>
00006 #include <map>
00007 
00008 #include "y2storage/StorageInterface.h"
00009 #include "y2storage/StorageTypes.h"
00010 #include "y2storage/StorageTmpl.h"
00011 #include "y2storage/Container.h"
00012 #include "y2storage/Volume.h"
00013 #include "y2storage/Disk.h"
00014 #include "y2storage/Partition.h"
00015 #include "y2storage/LvmVg.h"
00016 #include "y2storage/LvmLv.h"
00017 #include "y2storage/EvmsCo.h"
00018 #include "y2storage/Evms.h"
00019 #include "y2storage/MdCo.h"
00020 #include "y2storage/Md.h"
00021 #include "y2storage/DmCo.h"
00022 #include "y2storage/LoopCo.h"
00023 #include "y2storage/Loop.h"
00024 #include "y2storage/FilterIterator.h"
00025 #include "y2storage/DerefIterator.h"
00026 #include "y2storage/ListListIterator.h"
00027 #include "y2storage/IterPair.h"
00028 
00029 namespace storage
00030 {
00031 template <int Value>
00032 class CheckType
00033     {
00034     public:
00035         bool operator()( const Container& d ) const
00036             {
00037             return( d.type()==Value );
00038             }
00039     };
00040 
00041 template< class Iter, int Value, class CastResult >
00042 class CastCheckIterator : public CheckType<Value>,
00043                           public FilterIterator< CheckType<Value>, Iter >
00044     {
00045     typedef FilterIterator<CheckType<Value>, Iter> _bclass;
00046     public:
00047         typedef CastResult value_type;
00048         typedef CastResult& reference;
00049         typedef CastResult* pointer;
00050 
00051         CastCheckIterator() : _bclass() {}
00052         CastCheckIterator( const Iter& b, const Iter& e, bool atend=false) :
00053             _bclass( b, e, *this, atend ) {}
00054         CastCheckIterator( const IterPair<Iter>& pair, bool atend=false) :
00055             _bclass( pair, *this, atend ) {}
00056         CastCheckIterator( const CastCheckIterator& i) { *this=i;}
00057         CastResult operator*() const
00058             {
00059             return( static_cast<CastResult>(_bclass::operator*()) );
00060             }
00061         CastResult* operator->() const
00062             {
00063             return( static_cast<CastResult*>(_bclass::operator->()) );
00064             }
00065         CastCheckIterator& operator++()
00066             {
00067             _bclass::operator++(); return(*this);
00068             }
00069         CastCheckIterator operator++(int)
00070             {
00071             y2warning( "Expensive ++ CastCheckIterator" );
00072             CastCheckIterator tmp(*this);
00073             _bclass::operator++();
00074             return(tmp);
00075             }
00076         CastCheckIterator& operator--()
00077             {
00078             _bclass::operator--(); return(*this);
00079             }
00080         CastCheckIterator operator--(int)
00081             {
00082             y2warning( "Expensive -- CastCheckIterator" );
00083             CastCheckIterator tmp(*this);
00084             _bclass::operator--();
00085             return(tmp);
00086             }
00087     };
00088 
00104 class EtcFstab;
00105 class DiskData;
00106 
00107 class Storage : public storage::StorageInterface
00108     {
00109     protected:
00110 
00111         typedef std::list<Container*> CCont;
00112         typedef CCont::iterator CIter;
00113         typedef CCont::const_iterator CCIter;
00114 
00115         static bool isMd( const Container&d )
00116             { return( d.type()==storage::MD ); }
00117         static bool isLoop( const Container&d )
00118             { return( d.type()==storage::LOOP ); }
00119         static bool isDm( const Container&d )
00120             { return( d.type()==storage::DM ); }
00121         struct FreeInfo
00122             {
00123             unsigned long long resize_free;
00124             unsigned long long df_free;
00125             unsigned long long used;
00126             bool win;
00127             FreeInfo() { resize_free=df_free=used=0; win=false; }
00128             FreeInfo( unsigned long long df,
00129                       unsigned long long resize,
00130                       unsigned long long usd, bool w=false )
00131                       { resize_free=resize; df_free=df; used=usd; win=w; }
00132             };
00133 
00134     public:
00135         struct SkipDeleted { bool operator()(const Container&d) const {return( !d.deleted());}};
00136         static SkipDeleted SkipDel;
00137         static bool notDeleted( const Container&d ) { return( !d.deleted() ); };
00138 
00139         static void initDefaultLogger ();
00140 
00141         Storage( bool ronly=false, bool testmode=false, bool autodetect=true );
00142         bool test() const { return( testmode ); }
00143         bool instsys() const { return( inst_sys ); }
00144         void setCacheChanges( bool val=true ) { cache = val; }
00145         bool isCacheChanges() const { return( cache ); }
00146         void assertInit() { if( !initialized ) initialize(); }
00147         void rescanEverything();
00148         int checkCache();
00149         const string& tDir() const { return( testdir ); }
00150         const string& root() const { return( rootprefix ); }
00151         const string& tmpDir() const;
00152         static const string& arch() { return( proc_arch ); }
00153         static const string& sysfsDir() { return( sysfs_dir ); }
00154         EtcFstab* getFstab() { return fstab; }
00155         void handleLogFile( const string& name );
00156         static bool testFilesEqual( const string& n1, const string& n2 );
00157         void printInfo( std::ostream& str );
00158         void logCo( Container* c );
00159         void logProcData( const string& l="" );
00160         storage::UsedByType usedBy( const string& dev );
00161         bool setUsedBy( const string& dev, storage::UsedByType typ,
00162                         const string& name );
00163         bool canUseDevice( const string& dev, bool disks_allowed=false );
00164         bool knownDevice( const string& dev, bool disks_allowed=false );
00165         bool isDisk( const string& dev );
00166         const Volume* getVolume( const string& dev );
00167         unsigned long long deviceSize( const string& dev );
00168         string deviceByNumber( const string& majmin );
00169         void rootMounted();
00170         bool isRootMounted() const { return( root_mounted ); }
00171         string findNormalDevice( const string& device );
00172         bool findVolume( const string& device, Volume const* &vol );
00173 
00174         virtual ~Storage();
00175 
00176         // functions for interface
00177 
00178         void getContainers( deque<storage::ContainerInfo>& infos );
00179         int getDiskInfo( const string& disk, storage::DiskInfo& info);
00180         int getLvmVgInfo( const string& name, storage::LvmVgInfo& info);
00181         int getEvmsCoInfo( const string& name, storage::EvmsCoInfo& info);
00182         int getContDiskInfo( const string& disk, storage::ContainerInfo& cinfo,
00183                              storage::DiskInfo& info);
00184         int getContLvmVgInfo( const string& name, storage::ContainerInfo& cinfo,
00185                               storage::LvmVgInfo& info);
00186         int getContEvmsCoInfo( const string& name,
00187                                storage::ContainerInfo& cinfo,
00188                                storage::EvmsCoInfo& info );
00189         void getVolumes (deque<storage::VolumeInfo>& vlist);
00190         int getVolume( const string& device, storage::VolumeInfo& info);
00191         int getPartitionInfo( const string& disk,
00192                               deque<storage::PartitionInfo>& plist );
00193         int getLvmLvInfo( const string& name,
00194                           deque<storage::LvmLvInfo>& plist );
00195         int getEvmsInfo( const string& name,
00196                          deque<storage::EvmsInfo>& plist );
00197         int getMdInfo( deque<storage::MdInfo>& plist );
00198         int getDmInfo( deque<storage::DmInfo>& plist );
00199         int getLoopInfo( deque<storage::LoopInfo>& plist );
00200 
00201         bool getFsCapabilities( storage::FsType fstype,
00202                                 storage::FsCapabilities& fscapabilities) const;
00203         void setExtError( const string& txt );
00204         int createPartition( const string& disk, storage::PartitionType type,
00205                              unsigned long start, unsigned long size,
00206                              string& device );
00207         int resizePartition( const string& device, unsigned long sizeCyl );
00208         int nextFreePartition( const string& disk, storage::PartitionType type,
00209                                unsigned &nr, string& device );
00210         int updatePartitionArea( const string& device,
00211                                  unsigned long start, unsigned long size );
00212         int createPartitionKb( const string& disk, storage::PartitionType type,
00213                                unsigned long long start,
00214                                unsigned long long sizek, string& device );
00215         int createPartitionAny( const string& disk, unsigned long long size,
00216                                 string& device );
00217         int createPartitionMax( const string& disk, storage::PartitionType type,
00218                                 string& device );
00219         unsigned long kbToCylinder( const string& disk, unsigned long long size );
00220         unsigned long long cylinderToKb( const string& disk, unsigned long size );
00221         int removePartition( const string& partition );
00222         int changePartitionId( const string& partition, unsigned id );
00223         int forgetChangePartitionId( const string& partition );
00224         int destroyPartitionTable( const string& disk, const string& label );
00225         int initializeDisk( const string& disk, bool value );
00226         string defaultDiskLabel() const;
00227 
00228         int changeFormatVolume( const string& device, bool format,
00229                                 storage::FsType fs );
00230         int changeLabelVolume( const string& device, const string& label );
00231         int changeMkfsOptVolume( const string& device, const string& opts );
00232         int changeMountPoint( const string& device, const string& mount );
00233         int getMountPoint( const string& device, string& mount );
00234         int changeMountBy( const string& device, storage::MountByType mby );
00235         int getMountBy( const string& device, storage::MountByType& mby );
00236         int changeFstabOptions( const string&, const string& options );
00237         int getFstabOptions( const string& device, string& options );
00238         int addFstabOptions( const string&, const string& options );
00239         int removeFstabOptions( const string&, const string& options );
00240         int setCryptPassword( const string& device, const string& pwd );
00241         int forgetCryptPassword( const string& device );
00242         int getCryptPassword( const string& device, string& pwd );
00243         int setCrypt( const string& device, bool val );
00244         int getCrypt( const string& device, bool& val );
00245         int setIgnoreFstab( const string& device, bool val );
00246         int getIgnoreFstab( const string& device, bool& val );
00247         int addFstabEntry( const string& device, const string& mount,
00248                            const string& vfs, const string& options,
00249                            unsigned freq, unsigned passno );
00250         int resizeVolume( const string& device, unsigned long long newSizeMb );
00251         int forgetResizeVolume( const string& device );
00252         void setRecursiveRemoval( bool val=true );
00253         bool getRecursiveRemoval() const { return recursiveRemove; }
00254         void setZeroNewPartitions( bool val=true );
00255         bool getZeroNewPartitions() const { return zeroNewPartitions; }
00256         void setDefaultMountBy (MountByType mby = MOUNTBY_DEVICE);
00257         MountByType getDefaultMountBy() const { return defaultMountBy; }
00258         void setDetectMountedVolumes( bool val=true );
00259         bool getDetectMountedVolumes() const { return detectMounted; }
00260         void setRootPrefix( const string& root );
00261         int removeVolume( const string& device );
00262         int removeUsing( const string& device, const storage::usedBy& uby );
00263         bool checkDeviceMounted( const string& device, string& mp );
00264         bool umountDevice( const string& device );
00265         bool mountDevice( const string& device, const string& mp );
00266         bool readFstab( const string& dir, deque<storage::VolumeInfo>& infos);
00267         bool getFreeInfo( const string& device, unsigned long long& resize_free,
00268                           unsigned long long& df_free,
00269                           unsigned long long& used, bool& win, bool use_cache );
00270         int createBackupState( const string& name );
00271         int removeBackupState( const string& name );
00272         int restoreBackupState( const string& name );
00273         bool checkBackupState( const string& name );
00274         bool equalBackupStates( const string& lhs, const string& rhs,
00275                                 bool verbose_log ) const;
00276 
00277         int createLvmVg( const string& name, unsigned long long peSizeK,
00278                          bool lvm1, const deque<string>& devs );
00279         int removeLvmVg( const string& name );
00280         int extendLvmVg( const string& name, const deque<string>& devs );
00281         int shrinkLvmVg( const string& name, const deque<string>& devs );
00282         int createLvmLv( const string& vg, const string& name,
00283                          unsigned long long sizeM, unsigned stripe,
00284                          string& device );
00285         int removeLvmLvByDevice( const string& device );
00286         int removeLvmLv( const string& vg, const string& name );
00287         int changeLvStripeSize( const string& vg, const string& name,
00288                                 unsigned long long stripeSize );
00289 
00290         int evmsActivate();
00291         int createEvmsContainer( const string& name, unsigned long long peSizeK,
00292                                  bool lvm1, const deque<string>& devs );
00293         int modifyEvmsContainer( const string& old_name, const string& new_name,
00294                                  unsigned long long peSizeK, bool lvm1 );
00295         int removeEvmsContainer( const string& name );
00296         int extendEvmsContainer( const string& name, const deque<string>& devs );
00297         int shrinkEvmsContainer( const string& name, const deque<string>& devs );
00298         int createEvmsVolume( const string& vg, const string& name,
00299                               unsigned long long sizeM, unsigned stripe,
00300                               string& device );
00301         int removeEvmsVolumeByDevice( const string& device );
00302         int removeEvmsVolume( const string& vg, const string& name );
00303         int changeEvmsStripeSize( const string& coname, const string& name,
00304                                   unsigned long long stripeSize );
00305 
00306         int createMd( const string& name, storage::MdType rtype,
00307                       const deque<string>& devs );
00308         int createMdAny( storage::MdType rtype, const deque<string>& devs,
00309                          string& device );
00310         int removeMd( const string& name, bool destroySb=true );
00311         int extendMd( const string& name, const string& dev );
00312         int shrinkMd( const string& name, const string& dev );
00313         int changeMdType( const string& name, storage::MdType rtype );
00314         int changeMdChunk( const string& name, unsigned long chunk );
00315         int changeMdParity( const string& name, storage::MdParity ptype );
00316         int checkMd( const string& name );
00317 
00318 
00319         int createFileLoop( const string& lname, bool reuseExisting,
00320                             unsigned long long sizeK, const string& mp,
00321                             const string& pwd, string& device );
00322         int modifyFileLoop( const string& device, const string& lname, 
00323                             bool reuseExisting, unsigned long long sizeK );
00324         int removeFileLoop( const string& lname, bool removeFile );
00325 
00326         deque<string> getCommitActions( bool mark_destructive );
00327         const string& getLastAction() const { return lastAction; }
00328         const string& getExtendedErrorMessage() const { return extendedError; }
00329         void eraseFreeInfo( const string& device );
00330         int waitForDevice() const;
00331         int waitForDevice( const string& device ) const;
00332         void checkDeviceExclusive( const string& device, unsigned secs );
00333         void getDiskList( bool (* CheckFnc)( const Disk& ),
00334                           std::list<Disk*>& dl );
00335 
00336         int commit();
00337         void activateHld( bool val=true );
00338         void removeDmTableTo( const Volume& vol );
00339         void removeDmTableTo( const string& device );
00340         bool removeDmTable( const string& table );
00341         bool removeDmMapsTo( const string& dev, bool also_evms=false );
00342         bool checkDmMapsTo( const string& dev );
00343         void updateDmEmptyPeMap();
00344         void dumpObjectList();
00345 
00346         void setCallbackProgressBar( storage::CallbackProgressBar pfnc )
00347             { progress_bar_cb=pfnc; }
00348         storage::CallbackProgressBar getCallbackProgressBar() const
00349             { return progress_bar_cb; }
00350         void setCallbackShowInstallInfo( storage::CallbackShowInstallInfo pfnc )
00351             { install_info_cb=pfnc; }
00352         storage::CallbackShowInstallInfo getCallbackShowInstallInfo() const
00353             { return install_info_cb; }
00354         void setCallbackInfoPopup( storage::CallbackInfoPopup pfnc )
00355             { info_popup_cb=pfnc; }
00356         storage::CallbackInfoPopup getCallbackInfoPopup() const
00357             { return info_popup_cb; }
00358         void setCallbackYesNoPopup( storage::CallbackYesNoPopup pfnc )
00359             { yesno_popup_cb=pfnc; }
00360         storage::CallbackYesNoPopup getCallbackYesNoPopup() const
00361             { return yesno_popup_cb; }
00362 
00363         static void setCallbackProgressBarYcp( storage::CallbackProgressBar pfnc )
00364             { progress_bar_cb_ycp=pfnc; }
00365         static storage::CallbackProgressBar getCallbackProgressBarYcp()
00366             { return progress_bar_cb_ycp; }
00367         static void setCallbackShowInstallInfoYcp( storage::CallbackShowInstallInfo pfnc )
00368             { install_info_cb_ycp=pfnc; }
00369         static storage::CallbackShowInstallInfo getCallbackShowInstallInfoYcp()
00370             { return install_info_cb_ycp; }
00371         static void setCallbackInfoPopupYcp( storage::CallbackInfoPopup pfnc )
00372             { info_popup_cb_ycp=pfnc; }
00373         static storage::CallbackInfoPopup getCallbackInfoPopupYcp()
00374             { return info_popup_cb_ycp; }
00375         static void setCallbackYesNoPopupYcp( storage::CallbackYesNoPopup pfnc )
00376             { yesno_popup_cb_ycp=pfnc; }
00377         static storage::CallbackYesNoPopup getCallbackYesNoPopupYcp()
00378             { return yesno_popup_cb_ycp; }
00379 
00380         storage::CallbackProgressBar getCallbackProgressBarTheOne() const
00381             { return progress_bar_cb ? progress_bar_cb : progress_bar_cb_ycp; }
00382         storage::CallbackShowInstallInfo getCallbackShowInstallInfoTheOne() const
00383             { return install_info_cb ? install_info_cb : install_info_cb_ycp; }
00384         storage::CallbackInfoPopup getCallbackInfoPopupTheOne() const
00385             { return info_popup_cb ? info_popup_cb : info_popup_cb_ycp; }
00386         storage::CallbackYesNoPopup getCallbackYesNoPopupTheOne() const
00387             { return yesno_popup_cb ? yesno_popup_cb : yesno_popup_cb_ycp; }
00388 
00389         void progressBarCb( const string& id, unsigned cur, unsigned max );
00390         void showInfoCb( const string& info );
00391         void infoPopupCb( const string& info );
00392         bool yesnoPopupCb( const string& info );
00393 
00394 // iterators over container
00395     protected:
00396         // protected typedefs for iterators over container
00397         template< class Pred >
00398             struct ConstContainerPI { typedef ContainerIter<Pred, CCIter> type; };
00399         typedef CheckFnc<const Container> CheckFncCont;
00400         typedef CheckerIterator< CheckFncCont, ConstContainerPI<CheckFncCont>::type,
00401                                  CCIter, Container > ConstContPIterator;
00402         template< class Pred >
00403             struct ContainerPI { typedef ContainerIter<Pred, CIter> type; };
00404         template< class Pred >
00405             struct ContainerI
00406                 { typedef ContainerDerIter<Pred, typename ContainerPI<Pred>::type,
00407                                            Container> type; };
00408         typedef CheckerIterator< CheckFncCont, ContainerPI<CheckFncCont>::type,
00409                                  CIter, Container > ContPIterator;
00410         typedef DerefIterator<ContPIterator,Container> ContIterator;
00411         typedef IterPair<ContIterator> CPair;
00412 
00413     public:
00414         // public typedefs for iterators over containers
00415         template< class Pred >
00416             struct ConstContainerI
00417                 { typedef ContainerDerIter<Pred, typename ConstContainerPI<Pred>::type,
00418                                            const Container> type; };
00419         template< class Pred >
00420             struct ContCondIPair { typedef MakeCondIterPair<Pred,
00421                                    typename ConstContainerI<Pred>::type> type;};
00422         typedef DerefIterator<ConstContPIterator,const Container> ConstContIterator;
00423         typedef IterPair<ConstContIterator> ConstContPair;
00424 
00425         // public member functions for iterators over containers
00426         ConstContPair contPair( bool (* CheckFnc)( const Container& )=NULL ) const
00427             {
00428             return( ConstContPair( contBegin( CheckFnc ), contEnd( CheckFnc ) ));
00429             }
00430         ConstContIterator contBegin( bool (* CheckFnc)( const Container& )=NULL ) const
00431             {
00432             return( ConstContIterator( ConstContPIterator( cont.begin(), cont.end(), CheckFnc )) );
00433             }
00434         ConstContIterator contEnd( bool (* CheckFnc)( const Container& )=NULL ) const
00435             {
00436             return( ConstContIterator( ConstContPIterator( cont.begin(), cont.end(), CheckFnc, true )) );
00437             }
00438         template< class Pred > typename ContCondIPair<Pred>::type contCondPair( const Pred& p ) const
00439             {
00440             return( typename ContCondIPair<Pred>::type( contCondBegin( p ), contCondEnd( p ) ) );
00441             }
00442         template< class Pred > typename ConstContainerI<Pred>::type contCondBegin( const Pred& p ) const
00443             {
00444             return( typename ConstContainerI<Pred>::type( typename ConstContainerPI<Pred>::type( cont.begin(), cont.end(), p )) );
00445             }
00446         template< class Pred > typename ConstContainerI<Pred>::type contCondEnd( const Pred& p ) const
00447             {
00448             return( typename ConstContainerI<Pred>::type( typename ConstContainerPI<Pred>::type( cont.begin(), cont.end(), p, true )) );
00449             }
00450     protected:
00451         // protected member functions for iterators over containers
00452         CPair cPair( bool (* CheckFnc)( const Container& )=NULL )
00453             {
00454             return( CPair( cBegin(CheckFnc), cEnd(CheckFnc) ));
00455             }
00456         ContIterator cBegin( bool (* CheckFnc)( const Container& )=NULL )
00457             {
00458             return( ContIterator( ContPIterator( cont.begin(), cont.end(), CheckFnc )) );
00459             }
00460         ContIterator cEnd( bool (* CheckFnc)( const Container& )=NULL )
00461             {
00462             return( ContIterator( ContPIterator( cont.begin(), cont.end(), CheckFnc, true )) );
00463             }
00464 
00465 // iterators over disks
00466     protected:
00467         // protected typedefs for iterators over disks
00468         typedef CastCheckIterator<CCIter, storage::DISK, const Disk *> ContainerCDiskIter;
00469         template< class Pred >
00470             struct ConstDiskPI { typedef ContainerIter<Pred, ContainerCDiskIter> type; };
00471         typedef CastCheckIterator<CIter, storage::DISK, Disk *> ContainerDiskIter;
00472         template< class Pred >
00473             struct DiskPI { typedef ContainerIter<Pred, ContainerDiskIter> type; };
00474         template< class Pred >
00475             struct DiskI { typedef ContainerDerIter<Pred, typename DiskPI<Pred>::type, Disk> type; };
00476         typedef CheckFnc<const Disk> CheckFncDisk;
00477         typedef CheckerIterator< CheckFncDisk, ConstDiskPI<CheckFncDisk>::type,
00478                                  ContainerCDiskIter, Disk > ConstDiskPIterator;
00479         typedef CheckerIterator< CheckFncDisk, DiskPI<CheckFncDisk>::type,
00480                                  ContainerDiskIter, Disk > DiskPIterator;
00481         typedef DerefIterator<DiskPIterator,Disk> DiskIterator;
00482         typedef IterPair<DiskIterator> DiskPair;
00483 
00484     public:
00485         // public typedefs for iterators over disks
00486         typedef DerefIterator<ConstDiskPIterator,const Disk> ConstDiskIterator;
00487         template< class Pred >
00488             struct ConstDiskI
00489                 { typedef ContainerDerIter<Pred, typename ConstDiskPI<Pred>::type,
00490                                            const Disk> type; };
00491         template< class Pred >
00492             struct DiskCondIPair { typedef MakeCondIterPair<Pred, typename ConstDiskI<Pred>::type> type; };
00493         typedef IterPair<ConstDiskIterator> ConstDiskPair;
00494 
00495         // public member functions for iterators over disks
00496         ConstDiskPair diskPair( bool (* CheckFnc)( const Disk& )=NULL ) const
00497             {
00498             return( ConstDiskPair( diskBegin( CheckFnc ), diskEnd( CheckFnc ) ));
00499             }
00500         ConstDiskIterator diskBegin( bool (* CheckFnc)( const Disk& )=NULL ) const
00501             {
00502             IterPair<ContainerCDiskIter> p( ContainerCDiskIter( cont.begin(), cont.end() ),
00503                                             ContainerCDiskIter( cont.begin(), cont.end(), true ));
00504             return( ConstDiskIterator( ConstDiskPIterator( p, CheckFnc )) );
00505             }
00506         ConstDiskIterator diskEnd( bool (* CheckFnc)( const Disk& )=NULL ) const
00507             {
00508             IterPair<ContainerCDiskIter> p( ContainerCDiskIter( cont.begin(), cont.end() ),
00509                                             ContainerCDiskIter( cont.begin(), cont.end(), true ));
00510             return( ConstDiskIterator( ConstDiskPIterator( p, CheckFnc, true )) );
00511             }
00512         template< class Pred > typename DiskCondIPair<Pred>::type diskCondPair( const Pred& p ) const
00513             {
00514             return( typename DiskCondIPair<Pred>::type( diskCondBegin( p ), diskCondEnd( p ) ) );
00515             }
00516         template< class Pred > typename ConstDiskI<Pred>::type diskCondBegin( const Pred& p ) const
00517             {
00518             IterPair<ContainerCDiskIter> pair( ContainerCDiskIter( cont.begin(), cont.end() ),
00519                                                ContainerCDiskIter( cont.begin(), cont.end(), true ));
00520             return( typename ConstDiskI<Pred>::type( typename ConstDiskPI<Pred>::type( pair, p )) );
00521             }
00522         template< class Pred > typename ConstDiskI<Pred>::type diskCondEnd( const Pred& p ) const
00523             {
00524             IterPair<ContainerCDiskIter> pair( ContainerCDiskIter( cont.begin(), cont.end() ),
00525                                                ContainerCDiskIter( cont.begin(), cont.end(), true ));
00526             return( typename ConstDiskI<Pred>::type( typename ConstDiskPI<Pred>::type( pair, p, true )) );
00527             }
00528     protected:
00529         // protected member functions for iterators over disks
00530         DiskPair dPair( bool (* CheckFnc)( const Disk& )=NULL )
00531             {
00532             return( DiskPair( dBegin( CheckFnc ), dEnd( CheckFnc ) ));
00533             }
00534         DiskIterator dBegin( bool (* CheckFnc)( const Disk& )=NULL )
00535             {
00536             IterPair<ContainerDiskIter> p( ContainerDiskIter( cont.begin(), cont.end() ),
00537                                            ContainerDiskIter( cont.begin(), cont.end(), true ));
00538             return( DiskIterator( DiskPIterator( p, CheckFnc )) );
00539             }
00540         DiskIterator dEnd( bool (* CheckFnc)( const Disk& )=NULL )
00541             {
00542             IterPair<ContainerDiskIter> p( ContainerDiskIter( cont.begin(), cont.end() ),
00543                                            ContainerDiskIter( cont.begin(), cont.end(), true ));
00544             return( DiskIterator( DiskPIterator( p, CheckFnc, true )) );
00545             }
00546 
00547 
00548 // iterators over LVM VGs
00549     protected:
00550         // protected typedefs for iterators over LVM VGs
00551         typedef CastCheckIterator<CCIter, storage::LVM, const LvmVg *> ContainerCLvmVgIter;
00552         template< class Pred >
00553             struct ConstLvmVgPI { typedef ContainerIter<Pred, ContainerCLvmVgIter> type; };
00554         typedef CastCheckIterator<CIter, storage::LVM, LvmVg *> ContainerLvmVgIter;
00555         template< class Pred >
00556             struct LvmVgPI { typedef ContainerIter<Pred, ContainerLvmVgIter> type; };
00557         template< class Pred >
00558             struct LvmVgI { typedef ContainerDerIter<Pred, typename LvmVgPI<Pred>::type, LvmVg> type; };
00559         typedef CheckFnc<const LvmVg> CheckFncLvmVg;
00560         typedef CheckerIterator< CheckFncLvmVg, ConstLvmVgPI<CheckFncLvmVg>::type,
00561                                  ContainerCLvmVgIter, LvmVg > ConstLvmVgPIterator;
00562         typedef CheckerIterator< CheckFncLvmVg, LvmVgPI<CheckFncLvmVg>::type,
00563                                  ContainerLvmVgIter, LvmVg > LvmVgPIterator;
00564         typedef DerefIterator<LvmVgPIterator,LvmVg> LvmVgIterator;
00565         typedef IterPair<LvmVgIterator> LvmVgPair;
00566 
00567     public:
00568         // public typedefs for iterators over LVM VGs
00569         typedef DerefIterator<ConstLvmVgPIterator,const LvmVg> ConstLvmVgIterator;
00570         template< class Pred >
00571             struct ConstLvmVgI
00572                 { typedef ContainerDerIter<Pred, typename ConstLvmVgPI<Pred>::type,
00573                                            const LvmVg> type; };
00574         template< class Pred >
00575             struct LvmVgCondIPair { typedef MakeCondIterPair<Pred, typename ConstLvmVgI<Pred>::type> type; };
00576         typedef IterPair<ConstLvmVgIterator> ConstLvmVgPair;
00577 
00578         // public member functions for iterators over LVM VGs
00579         ConstLvmVgPair lvmVgPair( bool (* CheckFnc)( const LvmVg& )=NULL ) const
00580             {
00581             return( ConstLvmVgPair( lvmVgBegin( CheckFnc ), lvmVgEnd( CheckFnc ) ));
00582             }
00583         ConstLvmVgIterator lvmVgBegin( bool (* CheckFnc)( const LvmVg& )=NULL ) const
00584             {
00585             IterPair<ContainerCLvmVgIter> p( ContainerCLvmVgIter( cont.begin(), cont.end() ),
00586                                              ContainerCLvmVgIter( cont.begin(), cont.end(), true ));
00587             return( ConstLvmVgIterator( ConstLvmVgPIterator( p, CheckFnc )) );
00588             }
00589         ConstLvmVgIterator lvmVgEnd( bool (* CheckFnc)( const LvmVg& )=NULL ) const
00590             {
00591             IterPair<ContainerCLvmVgIter> p( ContainerCLvmVgIter( cont.begin(), cont.end() ),
00592                                              ContainerCLvmVgIter( cont.begin(), cont.end(), true ));
00593             return( ConstLvmVgIterator( ConstLvmVgPIterator( p, CheckFnc, true )) );
00594             }
00595         template< class Pred > typename LvmVgCondIPair<Pred>::type lvmVgCondPair( const Pred& p ) const
00596             {
00597             return( typename LvmVgCondIPair<Pred>::type( lvmVgCondBegin( p ), lvmVgCondEnd( p ) ) );
00598             }
00599         template< class Pred > typename ConstLvmVgI<Pred>::type lvmVgCondBegin( const Pred& p ) const
00600             {
00601             IterPair<ContainerCLvmVgIter> pair( ContainerCLvmVgIter( cont.begin(), cont.end() ),
00602                                                 ContainerCLvmVgIter( cont.begin(), cont.end(), true ));
00603             return( typename ConstLvmVgI<Pred>::type( typename ConstLvmVgPI<Pred>::type( pair, p )) );
00604             }
00605         template< class Pred > typename ConstLvmVgI<Pred>::type lvmVgCondEnd( const Pred& p ) const
00606             {
00607             IterPair<ContainerCLvmVgIter> pair( ContainerCLvmVgIter( cont.begin(), cont.end() ),
00608                                                 ContainerCLvmVgIter( cont.begin(), cont.end(), true ));
00609             return( typename ConstLvmVgI<Pred>::type( typename ConstLvmVgPI<Pred>::type( pair, p, true )) );
00610             }
00611     protected:
00612         // protected member functions for iterators over LVM VGs
00613         LvmVgPair lvgPair( bool (* CheckFnc)( const LvmVg& )=NULL )
00614             {
00615             return( LvmVgPair( lvgBegin( CheckFnc ), lvgEnd( CheckFnc ) ));
00616             }
00617         LvmVgIterator lvgBegin( bool (* CheckFnc)( const LvmVg& )=NULL )
00618             {
00619             IterPair<ContainerLvmVgIter> p( ContainerLvmVgIter( cont.begin(), cont.end() ),
00620                                             ContainerLvmVgIter( cont.begin(), cont.end(), true ));
00621             return( LvmVgIterator( LvmVgPIterator( p, CheckFnc )) );
00622             }
00623         LvmVgIterator lvgEnd( bool (* CheckFnc)( const LvmVg& )=NULL )
00624             {
00625             IterPair<ContainerLvmVgIter> p( ContainerLvmVgIter( cont.begin(), cont.end() ),
00626                                             ContainerLvmVgIter( cont.begin(), cont.end(), true ));
00627             return( LvmVgIterator( LvmVgPIterator( p, CheckFnc, true )) );
00628             }
00629 
00630 // iterators over EVMS container
00631     protected:
00632         // protected typedefs for iterators over EVMS container
00633         typedef CastCheckIterator<CCIter, storage::EVMS, const EvmsCo *> ContainerCEvmsIter;
00634         template< class Pred >
00635             struct ConstEvmsCoPI { typedef ContainerIter<Pred, ContainerCEvmsIter> type; };
00636         typedef CastCheckIterator<CIter, storage::EVMS, EvmsCo *> ContainerEvmsIter;
00637         template< class Pred >
00638             struct EvmsCoPI { typedef ContainerIter<Pred, ContainerEvmsIter> type; };
00639         template< class Pred >
00640             struct EvmsCoI { typedef ContainerDerIter<Pred, typename EvmsCoPI<Pred>::type, EvmsCo> type; };
00641         typedef CheckFnc<const EvmsCo> CheckFncEvmsCo;
00642         typedef CheckerIterator< CheckFncEvmsCo, ConstEvmsCoPI<CheckFncEvmsCo>::type,
00643                                  ContainerCEvmsIter, EvmsCo > ConstEvmsCoPIterator;
00644         typedef CheckerIterator< CheckFncEvmsCo, EvmsCoPI<CheckFncEvmsCo>::type,
00645                                  ContainerEvmsIter, EvmsCo > EvmsCoPIterator;
00646         typedef DerefIterator<EvmsCoPIterator,EvmsCo> EvmsCoIterator;
00647         typedef IterPair<EvmsCoIterator> EvmsCoPair;
00648 
00649     public:
00650         // public typedefs for iterators over EVMS container
00651         typedef DerefIterator<ConstEvmsCoPIterator,const EvmsCo> ConstEvmsCoIterator;
00652         template< class Pred >
00653             struct ConstEvmsCoI
00654                 { typedef ContainerDerIter<Pred, typename ConstEvmsCoPI<Pred>::type,
00655                                            const EvmsCo> type; };
00656         template< class Pred >
00657             struct EvmsCoCondIPair { typedef MakeCondIterPair<Pred, typename ConstEvmsCoI<Pred>::type> type; };
00658         typedef IterPair<ConstEvmsCoIterator> ConstEvmsCoPair;
00659 
00660         // public member functions for iterators over EVMS container
00661         ConstEvmsCoPair evmsCoPair( bool (* CheckFnc)( const EvmsCo& )=NULL ) const
00662             {
00663             return( ConstEvmsCoPair( evmsCoBegin( CheckFnc ), evmsCoEnd( CheckFnc ) ));
00664             }
00665         ConstEvmsCoIterator evmsCoBegin( bool (* CheckFnc)( const EvmsCo& )=NULL ) const
00666             {
00667             IterPair<ContainerCEvmsIter> p( ContainerCEvmsIter( cont.begin(), cont.end() ),
00668                                             ContainerCEvmsIter( cont.begin(), cont.end(), true ));
00669             return( ConstEvmsCoIterator( ConstEvmsCoPIterator( p, CheckFnc )) );
00670             }
00671         ConstEvmsCoIterator evmsCoEnd( bool (* CheckFnc)( const EvmsCo& )=NULL ) const
00672             {
00673             IterPair<ContainerCEvmsIter> p( ContainerCEvmsIter( cont.begin(), cont.end() ),
00674                                             ContainerCEvmsIter( cont.begin(), cont.end(), true ));
00675             return( ConstEvmsCoIterator( ConstEvmsCoPIterator( p, CheckFnc, true )) );
00676             }
00677         template< class Pred > typename EvmsCoCondIPair<Pred>::type evmsCoCondPair( const Pred& p ) const
00678             {
00679             return( typename EvmsCoCondIPair<Pred>::type( evmsCoCondBegin( p ), evmsCoCondEnd( p ) ) );
00680             }
00681         template< class Pred > typename ConstEvmsCoI<Pred>::type evmsCoCondBegin( const Pred& p ) const
00682             {
00683             IterPair<ContainerCEvmsIter> pair( ContainerCEvmsIter( cont.begin(), cont.end() ),
00684                                                ContainerCEvmsIter( cont.begin(), cont.end(), true ));
00685             return( typename ConstEvmsCoI<Pred>::type( typename ConstEvmsCoPI<Pred>::type( pair, p )) );
00686             }
00687         template< class Pred > typename ConstEvmsCoI<Pred>::type evmsCoCondEnd( const Pred& p ) const
00688             {
00689             IterPair<ContainerCEvmsIter> pair( ContainerCEvmsIter( cont.begin(), cont.end() ),
00690                                                ContainerCEvmsIter( cont.begin(), cont.end(), true ));
00691             return( typename ConstEvmsCoI<Pred>::type( typename ConstEvmsCoPI<Pred>::type( pair, p, true )) );
00692             }
00693     protected:
00694         // protected member functions for iterators over EVMS container
00695         EvmsCoPair evCoPair( bool (* CheckFnc)( const EvmsCo& )=NULL )
00696             {
00697             return( EvmsCoPair( evCoBegin( CheckFnc ), evCoEnd( CheckFnc ) ));
00698             }
00699         EvmsCoIterator evCoBegin( bool (* CheckFnc)( const EvmsCo& )=NULL )
00700             {
00701             IterPair<ContainerEvmsIter> p( ContainerEvmsIter( cont.begin(), cont.end() ),
00702                                            ContainerEvmsIter( cont.begin(), cont.end(), true ));
00703             return( EvmsCoIterator( EvmsCoPIterator( p, CheckFnc )) );
00704             }
00705         EvmsCoIterator evCoEnd( bool (* CheckFnc)( const EvmsCo& )=NULL )
00706             {
00707             IterPair<ContainerEvmsIter> p( ContainerEvmsIter( cont.begin(), cont.end() ),
00708                                            ContainerEvmsIter( cont.begin(), cont.end(), true ));
00709             return( EvmsCoIterator( EvmsCoPIterator( p, CheckFnc, true )) );
00710             }
00711 
00712 // iterators over volumes
00713     protected:
00714         // protected typedefs for iterators over volumes
00715         typedef ListListIterator<Container::ConstPlainIterator, ConstContIterator> ConstVolInter;
00716         template< class Pred >
00717             struct ConstVolumePI { typedef ContainerIter<Pred, ConstVolInter> type; };
00718         typedef CheckFnc<const Volume> CheckFncVol;
00719         typedef CheckerIterator< CheckFncVol, ConstVolumePI<CheckFncVol>::type,
00720                                  ConstVolInter, Volume > ConstVolPIterator;
00721         typedef ListListIterator<Container::PlainIterator, ContIterator> VolPart;
00722         template< class Pred >
00723             struct VolumeI { typedef ContainerIter<Pred, VolPart> type; };
00724         typedef CheckerIterator< CheckFncVol, VolumeI<CheckFncVol>::type,
00725                                  VolPart, Volume > VolPIterator;
00726         typedef DerefIterator<VolPIterator,Volume> VolIterator;
00727         typedef IterPair<VolIterator> VPair;
00728 
00729     public:
00730         // public typedefs for iterators over volumes
00731         template< class Pred >
00732             struct ConstVolumeI { typedef ContainerDerIter<Pred, typename ConstVolumePI<Pred>::type, const Volume> type; };
00733         template< class Pred >
00734             struct VolCondIPair { typedef MakeCondIterPair<Pred, typename ConstVolumeI<Pred>::type> type;};
00735         typedef DerefIterator<ConstVolPIterator,const Volume> ConstVolIterator;
00736         typedef IterPair<ConstVolIterator> ConstVolPair;
00737 
00738         // public member functions for iterators over volumes
00739         ConstVolPair volPair( bool (* CheckCnt)( const Container& )) const
00740             {
00741             return( ConstVolPair( volBegin( CheckCnt ), volEnd( CheckCnt ) ));
00742             }
00743         ConstVolPair volPair( bool (* CheckVol)( const Volume& )=NULL,
00744                               bool (* CheckCnt)( const Container& )=NULL) const
00745             {
00746             return( ConstVolPair( volBegin( CheckVol, CheckCnt ),
00747                                   volEnd( CheckVol, CheckCnt ) ));
00748             }
00749         ConstVolIterator volBegin( bool (* CheckCnt)( const Container& )) const
00750             {
00751             return( volBegin( NULL, CheckCnt ) );
00752             }
00753         ConstVolIterator volBegin( bool (* CheckVol)( const Volume& )=NULL,
00754                                    bool (* CheckCnt)( const Container& )=NULL) const
00755             {
00756             IterPair<ConstVolInter> p( (ConstVolInter( contPair( CheckCnt ))),
00757                                        (ConstVolInter( contPair( CheckCnt ), true )));
00758             return( ConstVolIterator( ConstVolPIterator(p, CheckVol )));
00759             }
00760         ConstVolIterator volEnd( bool (* CheckCnt)( const Container& )) const
00761             {
00762             return( volEnd( NULL, CheckCnt ) );
00763             }
00764         ConstVolIterator volEnd( bool (* CheckVol)( const Volume& )=NULL,
00765                                  bool (* CheckCnt)( const Container& )=NULL) const
00766             {
00767             IterPair<ConstVolInter> p( (ConstVolInter( contPair( CheckCnt ))),
00768                                        (ConstVolInter( contPair( CheckCnt ), true )));
00769             return( ConstVolIterator( ConstVolPIterator(p, CheckVol, true )));
00770             }
00771         template< class Pred > typename VolCondIPair<Pred>::type volCondPair( const Pred& p ) const
00772             {
00773             return( typename VolCondIPair<Pred>::type( volCondBegin( p ), volCondEnd( p ) ) );
00774             }
00775         template< class Pred > typename ConstVolumeI<Pred>::type volCondBegin( const Pred& p ) const
00776             {
00777             IterPair<ConstVolInter> pair( (ConstVolInter( contPair())),
00778                                           (ConstVolInter( contPair(), true )));
00779             return( typename ConstVolumeI<Pred>::type( typename ConstVolumePI<Pred>::type(pair, p) ) );
00780             }
00781         template< class Pred > typename ConstVolumeI<Pred>::type volCondEnd( const Pred& p ) const
00782             {
00783             IterPair<ConstVolInter> pair( (ConstVolInter( contPair())),
00784                                           (ConstVolInter( contPair(), true )));
00785             return( typename ConstVolumeI<Pred>::type( typename ConstVolumePI<Pred>::type(pair, p, true )) );
00786             }
00787 
00788     protected:
00789         // protected member functions for iterators over volumes
00790         VPair vPair( bool (* CheckCnt)( const Container& ))
00791             {
00792             return( VPair( vBegin( CheckCnt ), vEnd( CheckCnt ) ));
00793             }
00794         VPair vPair( bool (* CheckVol)( const Volume& )=NULL,
00795                      bool (* CheckCnt)( const Container& )=NULL)
00796             {
00797             return( VPair( vBegin( CheckVol, CheckCnt ),
00798                            vEnd( CheckVol, CheckCnt ) ));
00799             }
00800         VolIterator vBegin( bool (* CheckCnt)( const Container& ))
00801             {
00802             return( vBegin( NULL, CheckCnt ) );
00803             }
00804         VolIterator vBegin( bool (* CheckVol)( const Volume& )=NULL,
00805                             bool (* CheckCnt)( const Container& )=NULL)
00806             {
00807             IterPair<VolPart> p( (VolPart( cPair( CheckCnt ))),
00808                                  (VolPart( cPair( CheckCnt ), true )));
00809             return( VolIterator( VolPIterator( p, CheckVol )));
00810             }
00811         VolIterator vEnd( bool (* CheckCnt)( const Container& ))
00812             {
00813             return( vEnd( NULL, CheckCnt ) );
00814             }
00815         VolIterator vEnd( bool (* CheckVol)( const Volume& )=NULL,
00816                           bool (* CheckCnt)( const Container& )=NULL)
00817             {
00818             IterPair<VolPart> p( (VolPart( cPair( CheckCnt ))),
00819                                  (VolPart( cPair( CheckCnt ), true )));
00820             return( VolIterator( VolPIterator( p, CheckVol, true )));
00821             }
00822 
00823 // iterators over partitions
00824     protected:
00825         // protected typedefs for iterators over partitions
00826         typedef ListListIterator<Container::ConstPlainIterator, ConstDiskIterator> ConstPartInter;
00827         typedef CastIterator<ConstPartInter, Partition *> ConstPartInter2;
00828         template< class Pred >
00829             struct ConstPartitionPI { typedef ContainerIter<Pred, ConstPartInter2> type; };
00830         typedef CheckFnc<const Partition> CheckFncPartition;
00831         typedef CheckerIterator< CheckFncPartition, ConstPartitionPI<CheckFncPartition>::type,
00832                                  ConstPartInter2, Partition > ConstPartPIterator;
00833     public:
00834         // public typedefs for iterators over partitions
00835         template< class Pred >
00836             struct ConstPartitionI
00837                 { typedef ContainerDerIter<Pred, typename ConstPartitionPI<Pred>::type,
00838                                            const Partition> type; };
00839         template< class Pred >
00840             struct PartCondIPair
00841                 { typedef MakeCondIterPair<Pred, typename ConstPartitionI<Pred>::type> type;};
00842         typedef DerefIterator<ConstPartPIterator, const Partition> ConstPartIterator;
00843         typedef IterPair<ConstPartIterator> ConstPartPair;
00844 
00845         // public member functions for iterators over partitions
00846         ConstPartPair partPair( bool (* CheckCnt)( const Disk& )) const
00847             {
00848             return( ConstPartPair( partBegin( CheckCnt ), partEnd( CheckCnt ) ));
00849             }
00850         ConstPartPair partPair( bool (* CheckPart)( const Partition& )=NULL,
00851                                 bool (* CheckCnt)( const Disk& )=NULL) const
00852             {
00853             return( ConstPartPair( partBegin( CheckPart, CheckCnt ),
00854                                    partEnd( CheckPart, CheckCnt ) ));
00855             }
00856         ConstPartIterator partBegin( bool (* CheckDisk)( const Disk& )) const
00857             {
00858             return( partBegin( NULL, CheckDisk ) );
00859             }
00860         ConstPartIterator partBegin( bool (* CheckPart)( const Partition& )=NULL,
00861                                      bool (* CheckDisk)( const Disk& )=NULL) const
00862             {
00863             IterPair<ConstPartInter2> p( (ConstPartInter(diskPair( CheckDisk ))),
00864                                          (ConstPartInter(diskPair( CheckDisk ), true )));
00865             return( ConstPartIterator( ConstPartPIterator(p, CheckPart )));
00866             }
00867         ConstPartIterator partEnd( bool (* CheckDisk)( const Disk& )) const
00868             {
00869             return( partEnd( NULL, CheckDisk ) );
00870             }
00871         ConstPartIterator partEnd( bool (* CheckPart)( const Partition& )=NULL,
00872                                    bool (* CheckDisk)( const Disk& )=NULL) const
00873             {
00874             IterPair<ConstPartInter2> p( (ConstPartInter(diskPair( CheckDisk ))),
00875                                          (ConstPartInter(diskPair( CheckDisk ), true )));
00876             return( ConstPartIterator( ConstPartPIterator(p, CheckPart, true )));
00877             }
00878         template< class Pred > typename PartCondIPair<Pred>::type partCondPair( const Pred& p ) const
00879             {
00880             return( typename PartCondIPair<Pred>::type( partCondBegin( p ), partCondEnd( p ) ) );
00881             }
00882         template< class Pred > typename ConstPartitionI<Pred>::type partCondBegin( const Pred& p ) const
00883             {
00884             IterPair<ConstPartInter2> pair( (ConstPartInter( diskPair())),
00885                                             (ConstPartInter( diskPair(), true )));
00886             return( typename ConstPartitionI<Pred>::type( typename ConstPartitionPI<Pred>::type(pair, p) ) );
00887             }
00888         template< class Pred > typename ConstPartitionI<Pred>::type partCondEnd( const Pred& p ) const
00889             {
00890             IterPair<ConstPartInter2> pair( (ConstPartInter( diskPair())),
00891                                             (ConstPartInter( diskPair(), true )));
00892             return( typename ConstPartitionI<Pred>::type( typename ConstPartitionPI<Pred>::type(pair, p, true )) );
00893             }
00894 
00895 // iterators over LVM LVs
00896     protected:
00897         // protected typedefs for iterators over LVM LVs
00898         typedef ListListIterator<Container::ConstPlainIterator, ConstLvmVgIterator> ConstLvmLvInter;
00899         typedef CastIterator<ConstLvmLvInter, LvmLv *> ConstLvmLvInter2;
00900         template< class Pred >
00901             struct ConstLvmLvPI { typedef ContainerIter<Pred, ConstLvmLvInter2> type; };
00902         typedef CheckFnc<const LvmLv> CheckFncLvmLv;
00903         typedef CheckerIterator< CheckFncLvmLv, ConstLvmLvPI<CheckFncLvmLv>::type,
00904                                  ConstLvmLvInter2, LvmLv > ConstLvmLvPIterator;
00905     public:
00906         // public typedefs for iterators over LVM LVs
00907         template< class Pred >
00908             struct ConstLvmLvI
00909                 { typedef ContainerDerIter<Pred, typename ConstLvmLvPI<Pred>::type,
00910                                            const LvmLv> type; };
00911         template< class Pred >
00912             struct LvmLvCondIPair
00913                 { typedef MakeCondIterPair<Pred, typename ConstLvmLvI<Pred>::type> type;};
00914         typedef DerefIterator<ConstLvmLvPIterator, const LvmLv> ConstLvmLvIterator;
00915         typedef IterPair<ConstLvmLvIterator> ConstLvmLvPair;
00916 
00917         // public member functions for iterators over LVM LVs
00918         ConstLvmLvPair lvmLvPair( bool (* CheckLvmVg)( const LvmVg& )) const
00919             {
00920             return( ConstLvmLvPair( lvmLvBegin( CheckLvmVg ), lvmLvEnd( CheckLvmVg ) ));
00921             }
00922         ConstLvmLvPair lvmLvPair( bool (* CheckLvmLv)( const LvmLv& )=NULL,
00923                                   bool (* CheckLvmVg)( const LvmVg& )=NULL) const
00924             {
00925             return( ConstLvmLvPair( lvmLvBegin( CheckLvmLv, CheckLvmVg ),
00926                                     lvmLvEnd( CheckLvmLv, CheckLvmVg ) ));
00927             }
00928         ConstLvmLvIterator lvmLvBegin( bool (* CheckLvmVg)( const LvmVg& )) const
00929             {
00930             return( lvmLvBegin( NULL, CheckLvmVg ) );
00931             }
00932         ConstLvmLvIterator lvmLvBegin( bool (* CheckLvmLv)( const LvmLv& )=NULL,
00933                                        bool (* CheckLvmVg)( const LvmVg& )=NULL) const
00934             {
00935             IterPair<ConstLvmLvInter2> p( (ConstLvmLvInter(lvmVgPair( CheckLvmVg ))),
00936                                           (ConstLvmLvInter(lvmVgPair( CheckLvmVg ), true )));
00937             return( ConstLvmLvIterator( ConstLvmLvPIterator(p, CheckLvmLv )));
00938             }
00939         ConstLvmLvIterator lvmLvEnd( bool (* CheckLvmVg)( const LvmVg& )) const
00940             {
00941             return( lvmLvEnd( NULL, CheckLvmVg ) );
00942             }
00943         ConstLvmLvIterator lvmLvEnd( bool (* CheckLvmLv)( const LvmLv& )=NULL,
00944                                      bool (* CheckLvmVg)( const LvmVg& )=NULL) const
00945             {
00946             IterPair<ConstLvmLvInter2> p( (ConstLvmLvInter(lvmVgPair( CheckLvmVg ))),
00947                                           (ConstLvmLvInter(lvmVgPair( CheckLvmVg ), true )));
00948             return( ConstLvmLvIterator( ConstLvmLvPIterator(p, CheckLvmLv, true )));
00949             }
00950         template< class Pred > typename LvmLvCondIPair<Pred>::type lvmLvCondPair( const Pred& p ) const
00951             {
00952             return( typename LvmLvCondIPair<Pred>::type( lvmLvCondBegin( p ), lvmLvCondEnd( p ) ) );
00953             }
00954         template< class Pred > typename ConstLvmLvI<Pred>::type lvmLvCondBegin( const Pred& p ) const
00955             {
00956             IterPair<ConstLvmLvInter2> pair( (ConstLvmLvInter( lvmVgPair())),
00957                                              (ConstLvmLvInter( lvmVgPair(), true )));
00958             return( typename ConstLvmLvI<Pred>::type( typename ConstLvmLvPI<Pred>::type(pair, p) ) );
00959             }
00960         template< class Pred > typename ConstLvmLvI<Pred>::type lvmLvCondEnd( const Pred& p ) const
00961             {
00962             IterPair<ConstLvmLvInter2> pair( (ConstLvmLvInter( lvmVgPair())),
00963                                              (ConstLvmLvInter( lvmVgPair(), true )));
00964             return( typename ConstLvmLvI<Pred>::type( typename ConstLvmLvPI<Pred>::type(pair, p, true )) );
00965             }
00966 
00967 // iterators over EVMS volumes
00968     protected:
00969         // protected typedefs for iterators over EVMS volumes
00970         typedef ListListIterator<Container::ConstPlainIterator, ConstEvmsCoIterator> ConstEvmsInter;
00971         typedef CastIterator<ConstEvmsInter, Evms *> ConstEvmsInter2;
00972         template< class Pred >
00973             struct ConstEvmsPI { typedef ContainerIter<Pred, ConstEvmsInter2> type; };
00974         typedef CheckFnc<const Evms> CheckFncEvms;
00975         typedef CheckerIterator< CheckFncEvms, ConstEvmsPI<CheckFncEvms>::type,
00976                                  ConstEvmsInter2, Evms > ConstEvmsPIterator;
00977     public:
00978         // public typedefs for iterators over EVMS volumes
00979         template< class Pred >
00980             struct ConstEvmsI
00981                 { typedef ContainerDerIter<Pred, typename ConstEvmsPI<Pred>::type,
00982                                            const Evms> type; };
00983         template< class Pred >
00984             struct EvmsCondIPair
00985                 { typedef MakeCondIterPair<Pred, typename ConstEvmsI<Pred>::type> type;};
00986         typedef DerefIterator<ConstEvmsPIterator, const Evms> ConstEvmsIterator;
00987         typedef IterPair<ConstEvmsIterator> ConstEvmsPair;
00988 
00989         // public member functions for iterators over EVMS volumes
00990         ConstEvmsPair evmsPair( bool (* CheckEvmsCo)( const EvmsCo& )) const
00991             {
00992             return( ConstEvmsPair( evmsBegin( CheckEvmsCo ), evmsEnd( CheckEvmsCo ) ));
00993             }
00994         ConstEvmsPair evmsPair( bool (* CheckEvms)( const Evms& )=NULL,
00995                                 bool (* CheckEvmsCo)( const EvmsCo& )=NULL) const
00996             {
00997             return( ConstEvmsPair( evmsBegin( CheckEvms, CheckEvmsCo ),
00998                                    evmsEnd( CheckEvms, CheckEvmsCo ) ));
00999             }
01000         ConstEvmsIterator evmsBegin( bool (* CheckEvmsCo)( const EvmsCo& )) const
01001             {
01002             return( evmsBegin( NULL, CheckEvmsCo ) );
01003             }
01004         ConstEvmsIterator evmsBegin( bool (* CheckEvms)( const Evms& )=NULL,
01005                                      bool (* CheckEvmsCo)( const EvmsCo& )=NULL) const
01006             {
01007             IterPair<ConstEvmsInter2> p( (ConstEvmsInter(evmsCoPair( CheckEvmsCo ))),
01008                                          (ConstEvmsInter(evmsCoPair( CheckEvmsCo ), true )));
01009             return( ConstEvmsIterator( ConstEvmsPIterator(p, CheckEvms )));
01010             }
01011         ConstEvmsIterator evmsEnd( bool (* CheckEvmsCo)( const EvmsCo& )) const
01012             {
01013             return( evmsEnd( NULL, CheckEvmsCo ) );
01014             }
01015         ConstEvmsIterator evmsEnd( bool (* CheckEvms)( const Evms& )=NULL,
01016                                    bool (* CheckEvmsCo)( const EvmsCo& )=NULL) const
01017             {
01018             IterPair<ConstEvmsInter2> p( (ConstEvmsInter(evmsCoPair( CheckEvmsCo ))),
01019                                          (ConstEvmsInter(evmsCoPair( CheckEvmsCo ), true )));
01020             return( ConstEvmsIterator( ConstEvmsPIterator(p, CheckEvms, true )));
01021             }
01022         template< class Pred > typename EvmsCondIPair<Pred>::type evmsCondPair( const Pred& p ) const
01023             {
01024             return( typename EvmsCondIPair<Pred>::type( evmsCondBegin( p ), evmsCondEnd( p ) ) );
01025             }
01026         template< class Pred > typename ConstEvmsI<Pred>::type evmsCondBegin( const Pred& p ) const
01027             {
01028             IterPair<ConstEvmsInter2> pair( (ConstEvmsInter( evmsCoPair())),
01029                                             (ConstEvmsInter( evmsCoPair(), true )));
01030             return( typename ConstEvmsI<Pred>::type( typename ConstEvmsPI<Pred>::type(pair, p) ) );
01031             }
01032         template< class Pred > typename ConstEvmsI<Pred>::type evmsCondEnd( const Pred& p ) const
01033             {
01034             IterPair<ConstEvmsInter2> pair( (ConstEvmsInter( evmsCoPair())),
01035                                             (ConstEvmsInter( evmsCoPair(), true )));
01036             return( typename ConstEvmsI<Pred>::type( typename ConstEvmsPI<Pred>::type(pair, p, true )) );
01037             }
01038 
01039 // iterators over software raid devices
01040     protected:
01041         // protected typedefs for iterators over software raid devices
01042         typedef CastIterator<ConstVolInter, Md *> ConstMdInter;
01043         template< class Pred >
01044             struct ConstMdPI { typedef ContainerIter<Pred,
01045                                                      ConstMdInter> type; };
01046         typedef CheckFnc<const Md> CheckFncMd;
01047         typedef CheckerIterator< CheckFncMd, ConstMdPI<CheckFncMd>::type,
01048                                  ConstMdInter, Md > ConstMdPIterator;
01049     public:
01050         // public typedefs for iterators over software raid devices
01051         template< class Pred >
01052             struct ConstMdI
01053                 { typedef ContainerDerIter<Pred, typename ConstMdPI<Pred>::type,
01054                                            const Md> type; };
01055         template< class Pred >
01056             struct MdCondIPair
01057                 { typedef MakeCondIterPair<Pred, typename ConstMdI<Pred>::type> type;};
01058         typedef DerefIterator<ConstMdPIterator, const Md> ConstMdIterator;
01059         typedef IterPair<ConstMdIterator> ConstMdPair;
01060 
01061         // public member functions for iterators over software raid devices
01062         ConstMdPair mdPair( bool (* CheckMd)( const Md& )=NULL ) const
01063             {
01064             return( ConstMdPair( mdBegin( CheckMd ), mdEnd( CheckMd ) ));
01065             }
01066         ConstMdIterator mdBegin( bool (* CheckMd)( const Md& )=NULL ) const
01067             {
01068             ConstVolInter b( contPair( isMd ) );
01069             ConstVolInter e( contPair( isMd ), true );
01070             IterPair<ConstMdInter> p( (ConstMdInter(b)), (ConstMdInter(e)) );
01071             return( ConstMdIterator( ConstMdPIterator(p, CheckMd )));
01072             }
01073         ConstMdIterator mdEnd( bool (* CheckMd)( const Md& )=NULL ) const
01074             {
01075             ConstVolInter b( contPair( isMd ) );
01076             ConstVolInter e( contPair( isMd ), true );
01077             IterPair<ConstMdInter> p( (ConstMdInter(b)), (ConstMdInter(e)) );
01078             return( ConstMdIterator( ConstMdPIterator(p, CheckMd, true )));
01079             }
01080         template< class Pred > typename MdCondIPair<Pred>::type mdCondPair( const Pred& p ) const
01081             {
01082             return( typename MdCondIPair<Pred>::type( mdCondBegin( p ), mdCondEnd( p ) ) );
01083             }
01084         template< class Pred > typename ConstMdI<Pred>::type mdCondBegin( const Pred& p ) const
01085             {
01086             ConstVolInter b( contPair( isMd ) );
01087             ConstVolInter e( contPair( isMd ), true );
01088             IterPair<ConstMdInter> pair( (ConstMdInter(b)), (ConstMdInter(e)) );
01089             return( typename ConstMdI<Pred>::type( typename ConstMdPI<Pred>::type(pair, p) ) );
01090             }
01091         template< class Pred > typename ConstMdI<Pred>::type mdCondEnd( const Pred& p ) const
01092             {
01093             ConstVolInter b( contPair( isMd ) );
01094             ConstVolInter e( contPair( isMd ), true );
01095             IterPair<ConstMdInter> pair( (ConstMdInter(b)), (ConstMdInter(e)) );
01096             return( typename ConstMdI<Pred>::type( typename ConstMdPI<Pred>::type(pair, p, true )) );
01097             }
01098 
01099 // iterators over file based loop devices
01100     protected:
01101         // protected typedefs for iterators over file based loop devices
01102         typedef CastIterator<ConstVolInter, Loop *> ConstLoopInter;
01103         template< class Pred >
01104             struct ConstLoopPI { typedef ContainerIter<Pred,
01105                                                      ConstLoopInter> type; };
01106         typedef CheckFnc<const Loop> CheckFncLoop;
01107         typedef CheckerIterator< CheckFncLoop, ConstLoopPI<CheckFncLoop>::type,
01108                                  ConstLoopInter, Loop > ConstLoopPIterator;
01109     public:
01110         // public typedefs for iterators over file based loop devices
01111         template< class Pred >
01112             struct ConstLoopI
01113                 { typedef ContainerDerIter<Pred, typename ConstLoopPI<Pred>::type,
01114                                            const Loop> type; };
01115         template< class Pred >
01116             struct LoopCondIPair
01117                 { typedef MakeCondIterPair<Pred, typename ConstLoopI<Pred>::type> type;};
01118         typedef DerefIterator<ConstLoopPIterator, const Loop> ConstLoopIterator;
01119         typedef IterPair<ConstLoopIterator> ConstLoopPair;
01120 
01121         // public member functions for iterators over file based loop devices
01122         ConstLoopPair loopPair( bool (* CheckLoop)( const Loop& )=NULL ) const
01123             {
01124             return( ConstLoopPair( loopBegin( CheckLoop ), loopEnd( CheckLoop ) ));
01125             }
01126         ConstLoopIterator loopBegin( bool (* CheckLoop)( const Loop& )=NULL ) const
01127             {
01128             ConstVolInter b( contPair( isLoop ) );
01129             ConstVolInter e( contPair( isLoop ), true );
01130             IterPair<ConstLoopInter> p( (ConstLoopInter(b)), (ConstLoopInter(e)) );
01131             return( ConstLoopIterator( ConstLoopPIterator(p, CheckLoop )));
01132             }
01133         ConstLoopIterator loopEnd( bool (* CheckLoop)( const Loop& )=NULL ) const
01134             {
01135             ConstVolInter b( contPair( isLoop ) );
01136             ConstVolInter e( contPair( isLoop ), true );
01137             IterPair<ConstLoopInter> p( (ConstLoopInter(b)), (ConstLoopInter(e)) );
01138             return( ConstLoopIterator( ConstLoopPIterator(p, CheckLoop, true )));
01139             }
01140         template< class Pred > typename LoopCondIPair<Pred>::type loopCondPair( const Pred& p ) const
01141             {
01142             return( typename LoopCondIPair<Pred>::type( loopCondBegin( p ), loopCondEnd( p ) ) );
01143             }
01144         template< class Pred > typename ConstLoopI<Pred>::type loopCondBegin( const Pred& p ) const
01145             {
01146             ConstVolInter b( contPair( isLoop ) );
01147             ConstVolInter e( contPair( isLoop ), true );
01148             IterPair<ConstLoopInter> pair( (ConstLoopInter(b)), (ConstLoopInter(e)) );
01149             return( typename ConstLoopI<Pred>::type( typename ConstLoopPI<Pred>::type(pair, p) ) );
01150             }
01151         template< class Pred > typename ConstLoopI<Pred>::type loopCondEnd( const Pred& p ) const
01152             {
01153             ConstVolInter b( contPair( isLoop ) );
01154             ConstVolInter e( contPair( isLoop ), true );
01155             IterPair<ConstLoopInter> pair( (ConstLoopInter(b)), (ConstLoopInter(e)) );
01156             return( typename ConstLoopI<Pred>::type( typename ConstLoopPI<Pred>::type(pair, p, true )) );
01157             }
01158 
01159 // iterators over device mapper devices
01160     protected:
01161         // protected typedefs for iterators over device mapper devices
01162         typedef CastIterator<ConstVolInter, Dm *> ConstDmInter;
01163         template< class Pred >
01164             struct ConstDmPI { typedef ContainerIter<Pred,
01165                                                      ConstDmInter> type; };
01166         typedef CheckFnc<const Dm> CheckFncDm;
01167         typedef CheckerIterator< CheckFncDm, ConstDmPI<CheckFncDm>::type,
01168                                  ConstDmInter, Dm > ConstDmPIterator;
01169     public:
01170         // public typedefs for iterators over device mapper devices
01171         template< class Pred >
01172             struct ConstDmI
01173                 { typedef ContainerDerIter<Pred, typename ConstDmPI<Pred>::type,
01174                                            const Dm> type; };
01175         template< class Pred >
01176             struct DmCondIPair
01177                 { typedef MakeCondIterPair<Pred, typename ConstDmI<Pred>::type> type;};
01178         typedef DerefIterator<ConstDmPIterator, const Dm> ConstDmIterator;
01179         typedef IterPair<ConstDmIterator> ConstDmPair;
01180 
01181         // public member functions for iterators over device mapper devices
01182         ConstDmPair dmPair( bool (* CheckDm)( const Dm& )=NULL ) const
01183             {
01184             return( ConstDmPair( dmBegin( CheckDm ), dmEnd( CheckDm ) ));
01185             }
01186         ConstDmIterator dmBegin( bool (* CheckDm)( const Dm& )=NULL ) const
01187             {
01188             ConstVolInter b( contPair( isDm ) );
01189             ConstVolInter e( contPair( isDm ), true );
01190             IterPair<ConstDmInter> p( (ConstDmInter(b)), (ConstDmInter(e)) );
01191             return( ConstDmIterator( ConstDmPIterator(p, CheckDm )));
01192             }
01193         ConstDmIterator dmEnd( bool (* CheckDm)( const Dm& )=NULL ) const
01194             {
01195             ConstVolInter b( contPair( isDm ) );
01196             ConstVolInter e( contPair( isDm ), true );
01197             IterPair<ConstDmInter> p( (ConstDmInter(b)), (ConstDmInter(e)) );
01198             return( ConstDmIterator( ConstDmPIterator(p, CheckDm, true )));
01199             }
01200         template< class Pred > typename DmCondIPair<Pred>::type dmCondPair( const Pred& p ) const
01201             {
01202             return( typename DmCondIPair<Pred>::type( dmCondBegin( p ), dmCondEnd( p ) ) );
01203             }
01204         template< class Pred > typename ConstDmI<Pred>::type dmCondBegin( const Pred& p ) const
01205             {
01206             ConstVolInter b( contPair( isDm ) );
01207             ConstVolInter e( contPair( isDm ), true );
01208             IterPair<ConstDmInter> pair( (ConstDmInter(b)), (ConstDmInter(e)) );
01209             return( typename ConstDmI<Pred>::type( typename ConstDmPI<Pred>::type(pair, p) ) );
01210             }
01211         template< class Pred > typename ConstDmI<Pred>::type dmCondEnd( const Pred& p ) const
01212             {
01213             ConstVolInter b( contPair( isDm ) );
01214             ConstVolInter e( contPair( isDm ), true );
01215             IterPair<ConstDmInter> pair( (ConstDmInter(b)), (ConstDmInter(e)) );
01216             return( typename ConstDmI<Pred>::type( typename ConstDmPI<Pred>::type(pair, p, true )) );
01217             }
01218 
01219     protected:
01220         // protected internal member functions
01221         void initialize();
01222         void detectDisks( ProcPart& ppart );
01223         void autodetectDisks( ProcPart& ppart );
01224         void detectMultipath();
01225         void detectMds();
01226         void detectLoops( ProcPart& ppart );
01227         void detectLvmVgs();
01228         void detectEvms();
01229         void detectDm( ProcPart& ppart );
01230         void initDisk( DiskData& data, ProcPart& pp );
01231         void detectFsData( const VolIterator& begin, const VolIterator& end );
01232         void detectFsDataTestMode( const string& file,
01233                                    const VolIterator& begin,
01234                                    const VolIterator& end );
01235         static void detectArch();
01236         void addToList( Container* e )
01237             { pointerIntoSortedList<Container>( cont, e ); }
01238         DiskIterator findDisk( const string& disk );
01239         LvmVgIterator findLvmVg( const string& name );
01240         EvmsCoIterator findEvmsCo( const string& name );
01241         bool findVolume( const string& device, ContIterator& c,
01242                          VolIterator& v  );
01243         bool findVolume( const string& device, VolIterator& v,
01244                          bool also_del=false );
01245         bool findContainer( const string& device, ContIterator& c );
01246 
01247         bool haveMd( MdCo*& md );
01248         bool haveLoop( LoopCo*& loop );
01249         bool haveEvms();
01250         void handleEvmsRemoveDevice( const Disk* disk, const string& d,
01251                                      bool rename );
01252         void handleEvmsCreateDevice( const string& disk, const string& dev, 
01253                                      bool extended=false );
01254 
01255         int removeContainer( Container* val, bool call_del=true );
01256         void logVolumes( const string& Dir );
01257         int commitPair( CPair& p, bool (* fnc)( const Container& ) );
01258         void sortCommitLists( storage::CommitStage stage,
01259                               std::list<Container*>& co,
01260                               std::list<Volume*>& vl,
01261                               std::list<storage::commitAction*>& todo );
01262         bool ignoreError( std::list<commitAction*>::iterator i,
01263                           std::list<commitAction*>& al );
01264         void evmsActivateDevices();
01265         string backupStates() const;
01266         void detectObjects();
01267         void deleteClist( CCont& co );
01268         void deleteBackups();
01269         void setFreeInfo( const string& device, unsigned long long df_free,
01270                           unsigned long long resize_free,
01271                           unsigned long long used, bool win );
01272         bool getFreeInfo( const string& device, unsigned long long& df_free,
01273                           unsigned long long& resize_free,
01274                           unsigned long long& used, bool& win );
01275 
01276         // protected internal member variables
01277         bool readonly;
01278         bool testmode;
01279         bool inst_sys;
01280         bool cache;
01281         bool initialized;
01282         bool autodetect;
01283         bool recursiveRemove;
01284         bool zeroNewPartitions;
01285         MountByType defaultMountBy;
01286         bool detectMounted;
01287         bool root_mounted;
01288         string testdir;
01289         string tempdir;
01290         string rootprefix;
01291         string logdir;
01292         static string proc_arch;
01293         static string sysfs_dir;
01294         CCont cont;
01295         EtcFstab *fstab;
01296 
01297         storage::CallbackProgressBar progress_bar_cb;
01298         storage::CallbackShowInstallInfo install_info_cb;
01299         storage::CallbackInfoPopup info_popup_cb;
01300         storage::CallbackYesNoPopup yesno_popup_cb;
01301         static storage::CallbackProgressBar progress_bar_cb_ycp;
01302         static storage::CallbackShowInstallInfo install_info_cb_ycp;
01303         static storage::CallbackInfoPopup info_popup_cb_ycp;
01304         static storage::CallbackYesNoPopup yesno_popup_cb_ycp;
01305         friend std::ostream& operator<< (std::ostream& s, Storage &v );
01306 
01307         unsigned max_log_num;
01308         string lastAction;
01309         string extendedError;
01310         std::map<string,CCont> backups;
01311         std::map<string,FreeInfo> freeInfo;
01312     };
01313 
01314 inline std::ostream& operator<< (std::ostream& s, commitAction &a )
01315     {
01316     s << "stage:" << a.stage
01317       << " type:" << a.type
01318       << " cont:" << a.container
01319       << " dest:" << a.destructive
01320       << " name:" << (a.container?a.co()->name():a.vol()->name());
01321     if( !a.descr.empty() )
01322       s << " desc:" << a.descr;
01323     return( s );
01324     };
01325 
01326 }
01327 
01328 #endif

Generated on Thu Jul 6 00:40:24 2006 for yast2-storage by  doxygen 1.4.6