|
yast2-storage
|
00001 /* 00002 * Copyright (c) [2004-2011] Novell, Inc. 00003 * 00004 * All Rights Reserved. 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of version 2 of the GNU General Public License as published 00008 * by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 * more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, contact Novell, Inc. 00017 * 00018 * To contact Novell about this file by physical or electronic mail, you may 00019 * find current contact information at www.novell.com. 00020 */ 00021 00022 00023 #ifndef BTRFS_CO_H 00024 #define BTRFS_CO_H 00025 00026 #include "storage/Container.h" 00027 #include "storage/Btrfs.h" 00028 00029 00030 namespace storage 00031 { 00032 class SystemInfo; 00033 00034 00035 class BtrfsCo : public Container 00036 { 00037 friend class Storage; 00038 00039 public: 00040 00041 BtrfsCo(Storage * const s); 00042 BtrfsCo(Storage * const s, SystemInfo& systeminfo); 00043 BtrfsCo(const BtrfsCo& c); 00044 virtual ~BtrfsCo(); 00045 00046 void addFromVolume( const Volume& v, string& uuid ); 00047 void eraseVolume( Volume* v ); 00048 00049 bool existSubvolume( const string& device, const string& name ); 00050 int createSubvolume( const string& device, const string& name ); 00051 int removeSubvolume( const string& device, const string& name ); 00052 int extendVolume( const string& device, const string& dev ); 00053 int extendVolume( const string& device, const list<string>& devs ); 00054 int shrinkVolume( const string& device, const string& dev ); 00055 int shrinkVolume( const string& device, const list<string>& devs ); 00056 bool deviceToUuid( const string& device, string& uuid ); 00057 00058 int doRemove( Volume* v ); 00059 00060 void changeDeviceName( const string& old, const string& nw ); 00061 00062 static storage::CType staticType() { return storage::BTRFSC; } 00063 friend std::ostream& operator<< (std::ostream&, const BtrfsCo& ); 00064 00065 int commitChanges( CommitStage stage, Volume* vol ); 00066 void getToCommit( storage::CommitStage stage, list<const Container*>& col, 00067 list<const Volume*>& vo ) const; 00068 00069 int resizeVolume( Volume* v, Container* r_co, Volume* r_v, 00070 unsigned long long newSize ); 00071 int removeVolume( Volume* v ); 00072 int removeVolume( Volume* v, bool quiet ); 00073 int removeUuid( const string& uuid ); 00074 bool equalContent( const Container& rhs ) const; 00075 void saveData(xmlNode* node) const; 00076 string fakeUuid(); 00077 00078 virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const; 00079 virtual void logData(const string& Dir) const; 00080 00081 00082 protected: 00083 // iterators over BTRFS volumes 00084 // protected typedefs for iterators over BTRFS volumes 00085 typedef CastIterator<VIter, Btrfs *> BtrfsInter; 00086 typedef CastIterator<CVIter, const Btrfs *> BtrfsCInter; 00087 template< class Pred > 00088 struct BtrfsPI { typedef ContainerIter<Pred, BtrfsInter> type; }; 00089 template< class Pred > 00090 struct BtrfsCPI { typedef ContainerIter<Pred, BtrfsCInter> type; }; 00091 typedef CheckFnc<const Btrfs> CheckFncBtrfs; 00092 typedef CheckerIterator< CheckFncBtrfs, BtrfsPI<CheckFncBtrfs>::type, 00093 BtrfsInter, Btrfs > BtrfsPIterator; 00094 typedef CheckerIterator< CheckFncBtrfs, BtrfsCPI<CheckFncBtrfs>::type, 00095 BtrfsCInter, const Btrfs > BtrfsCPIterator; 00096 typedef DerefIterator<BtrfsPIterator,Btrfs> BtrfsIter; 00097 typedef DerefIterator<BtrfsCPIterator,const Btrfs> ConstBtrfsIter; 00098 typedef IterPair<BtrfsIter> BtrfsPair; 00099 typedef IterPair<ConstBtrfsIter> ConstBtrfsPair; 00100 00101 BtrfsPair btrfsPair( bool (* Check)( const Btrfs& )=NULL) 00102 { 00103 return( BtrfsPair( btrfsBegin( Check ), btrfsEnd( Check ) )); 00104 } 00105 BtrfsIter btrfsBegin( bool (* Check)( const Btrfs& )=NULL) 00106 { 00107 IterPair<BtrfsInter> p( (BtrfsInter(begin())), (BtrfsInter(end())) ); 00108 return( BtrfsIter( BtrfsPIterator( p, Check )) ); 00109 } 00110 BtrfsIter btrfsEnd( bool (* Check)( const Btrfs& )=NULL) 00111 { 00112 IterPair<BtrfsInter> p( (BtrfsInter(begin())), (BtrfsInter(end())) ); 00113 return( BtrfsIter( BtrfsPIterator( p, Check, true )) ); 00114 } 00115 00116 ConstBtrfsPair btrfsPair( bool (* Check)( const Btrfs& )=NULL) const 00117 { 00118 return( ConstBtrfsPair( btrfsBegin( Check ), btrfsEnd( Check ) )); 00119 } 00120 ConstBtrfsIter btrfsBegin( bool (* Check)( const Btrfs& )=NULL) const 00121 { 00122 IterPair<BtrfsCInter> p( (BtrfsCInter(begin())), (BtrfsCInter(end())) ); 00123 return( ConstBtrfsIter( BtrfsCPIterator( p, Check )) ); 00124 } 00125 ConstBtrfsIter btrfsEnd( bool (* Check)( const Btrfs& )=NULL) const 00126 { 00127 IterPair<BtrfsCInter> p( (BtrfsCInter(begin())), (BtrfsCInter(end())) ); 00128 return( ConstBtrfsIter( BtrfsCPIterator( p, Check, true )) ); 00129 } 00130 00131 void getBtrfsData(SystemInfo& systeminfo); 00132 bool findBtrfs( const string& uuid, BtrfsIter& i ); 00133 void addBtrfs( Btrfs* m ); 00134 00135 virtual void print( std::ostream& s ) const { s << *this; } 00136 virtual Container* getCopy() const { return( new BtrfsCo( *this ) ); } 00137 00138 private: 00139 00140 BtrfsCo& operator=(const BtrfsCo&); // disallow 00141 00142 }; 00143 00144 } 00145 00146 #endif
1.7.3