[yast-commit] r60278 - in /branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src: MdCo.cc MdCo.h MdPartCo.cc MdPartCo.h Storage.cc Storage.h
Author: mpatelcz Date: Thu Jan 7 16:10:03 2010 New Revision: 60278 URL: http://svn.opensuse.org/viewcvs/yast?rev=60278&view=rev Log: Bug 567662 - wrong number for new software raid Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.cc branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.h branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.cc branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.h branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.cc branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.h Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.cc?rev=60278&r1=60277&r2=60278&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.cc (original) +++ branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.cc Thu Jan 7 16:10:03 2010 @@ -277,6 +277,19 @@ return( i ); } +int +MdCo::usedNumbers(list<int>& nums) +{ + MdPair p=mdPair(Md::notDeleted); + MdIter i; + nums.clear(); + for(i=p.begin(); i!=p.end(); i++ ) + { + nums.push_back(i->nr()); + } + return 0; +} + int MdCo::createMd( unsigned num, MdType type, const list<string>& devs ) { Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.h?rev=60278&r1=60277&r2=60278&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.h (original) +++ branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdCo.h Thu Jan 7 16:10:03 2010 @@ -56,6 +56,10 @@ bool equalContent( const Container& rhs ) const; void logDifference( const Container& d ) const; + /* This function is deprecated and should not be used. + * It returns first free 'md' number for Non-partitionable MD RAIDs + * Regardless from Partitionable RAIDs and this can lead to errors. + */ unsigned unusedNumber(); void syncRaidtab(); void changeDeviceName( const string& old, const string& nw ); @@ -63,6 +67,9 @@ static void activate( bool val, const string& tmpDir ); int removeVolume( Volume* v ); + /* returns in 'nums' numbers that are used by Md */ + int usedNumbers(list<int>& nums); + protected: // iterators over MD volumes // protected typedefs for iterators over MD volumes Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.cc?rev=60278&r1=60277&r2=60278&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.cc (original) +++ branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.cc Thu Jan 7 16:10:03 2010 @@ -502,6 +502,11 @@ return n; } +int MdPartCo::nr() +{ + return mnr; +} + // // Assumption is that we're using /dev not /dev/md Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.h?rev=60278&r1=60277&r2=60278&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.h (original) +++ branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/MdPartCo.h Thu Jan 7 16:10:03 2010 @@ -131,7 +131,10 @@ void syncRaidtab(); + /* Returns number from MD name */ int nr(const string& name); + /* Returns Md number. */ + int nr(); /* RAID Related functionality */ unsigned long chunkSize() const { return chunk_size; } Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.cc?rev=60278&r1=60277&r2=60278&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.cc (original) +++ branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.cc Thu Jan 7 16:10:03 2010 @@ -3382,14 +3382,87 @@ int ret = 0; assertInit(); MdCo *md = NULL; - nr = 0; + list<int> mdNums; + list<int> mdPartNums; + + nr = -1; + mdNums.clear(); + mdPartNums.clear(); if (haveMd(md)) - nr = md->unusedNumber(); - device = "/dev/md" + decString(nr); - y2milestone("ret:%d nr:%d device:%s", ret, nr, device.c_str()); + (void)md->usedNumbers(mdNums); + + getMdPartMdNums(mdPartNums); + + mdPartNums.merge(mdNums); + mdPartNums.sort(); + mdPartNums.unique(); + + if(mdPartNums.size() > 0 ) + { + int found; + //FIXME: magic number + for(int i=0; i<1000; i++) + { + found=0; + for(list<int>::iterator it=mdPartNums.begin(); + it!=mdPartNums.end(); it++) + { + if (i == *it ) + found = 1; + } + if(found == 0) + { + // Number not found on the list. + nr = i; + break; + } + } + } + else + { + nr = 0; + } + if( nr != -1 ) + { + device = "/dev/md" + decString(nr); + y2milestone("ret:%d nr:%d device:%s", ret, nr, device.c_str()); + } + else + ret = MD_UNKNOWN_NUMBER; return ret; } +bool Storage::checkMdNumber(int num) +{ + assertInit(); + MdCo *md = NULL; + list<int> mdNums; + list<int> mdPartNums; + + mdNums.clear(); + mdPartNums.clear(); + if (haveMd(md)) + (void)md->usedNumbers(mdNums); + + getMdPartMdNums(mdPartNums); + + mdPartNums.merge(mdNums); + mdPartNums.sort(); + mdPartNums.unique(); + + if(mdPartNums.size() == 0 ) + return false; + + for(list<int>::iterator it=mdPartNums.begin(); + it!=mdPartNums.end(); + it++) + { + if (num == *it ) + return true; + } + return false; +} + int Storage::createMd( const string& name, MdType rtype, const deque<string>& devs ) @@ -3407,6 +3480,10 @@ { ret = STORAGE_MD_INVALID_NAME; } + if( ret==0 && checkMdNumber(num)==true ) + { + ret = MD_DUPLICATE_NUMBER; + } MdCo *md = NULL; bool have_md = true; if( ret==0 ) @@ -3450,16 +3527,22 @@ } MdCo *md = NULL; bool have_md = true; + int mdNum=0; unsigned num = 0; + string tmpStr; if( ret==0 ) { have_md = haveMd(md); if( !have_md ) md = new MdCo( this, false ); - else - num = md->unusedNumber(); if( md==NULL ) ret = STORAGE_MEMORY_EXHAUSTED; + if( ret == 0 ) + { + ret = nextFreeMd(mdNum,tmpStr); + if( ret == 0 ) + num = (unsigned)mdNum; + } } if( ret==0 ) { @@ -3795,6 +3878,21 @@ return( i != p.end() ); } +int Storage::getMdPartMdNums(list<int>& mdPartNums) + { + mdPartNums.clear(); + CPair p = cPair(); + ContIterator i; + for(i=p.begin(); i!=p.end(); i++ ) + { + if( i->type()==MDPART ) + { + MdPartCo *mdpart = static_cast<MdPartCo*>(&(*i)); + mdPartNums.push_back(mdpart->nr()); + } + } + return 0; + } bool Storage::haveDm(DmCo*& dm) @@ -5840,7 +5938,7 @@ break; case UB_MDPART: y2war(device << " used by MD PART"); - // ret = removeMdPartCo( name ); + //ret = removeMdPartCo( uby.device() ); break; case UB_DMMULTIPATH: break; Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.h?rev=60278&r1=60277&r2=60278&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.h (original) +++ branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/Storage.h Thu Jan 7 16:10:03 2010 @@ -460,6 +460,7 @@ LvmLvSnapshotStateInfo& info); int nextFreeMd(int &nr, string &device); + bool checkMdNumber(int num); int createMd( const string& name, storage::MdType rtype, const deque<string>& devs ); int createMdAny( storage::MdType rtype, const deque<string>& devs, @@ -1880,6 +1881,7 @@ void checkPwdBuf( const string& device ); bool haveMd( MdCo*& md ); + int getMdPartMdNums(list<int>& mdPartNums); bool haveDm(DmCo*& dm); bool haveNfs( NfsCo*& co ); bool haveLoop( LoopCo*& loop ); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
mpatelcz@svn.opensuse.org