Author: mpatelcz
Date: Fri Jan 15 14:09:48 2010
New Revision: 60399
URL: http://svn.opensuse.org/viewcvs/yast?rev=60399&view=rev
Log:
BZ568325 - Storage::removeUsing not handling MDPART
Modified:
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
branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/StorageInterface.h
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=60399&r1=60398&r2=60399&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 Fri Jan 15 14:09:48 2010
@@ -669,27 +669,39 @@
y2mil("begin");
if( readonly() )
{
+ y2war("Read-Only RAID.");
ret = MDPART_CHANGE_READONLY;
}
if( ret==0 && !created() )
{
+ list<string> rdevs;
+ getDevs( rdevs );
+ for( list<string>::const_iterator s=rdevs.begin();
+ s!=rdevs.end(); ++s )
+ {
+ getStorage()->clearUsedBy(*s);
+ }
+ //Remove partitions
MdPartPair p=mdpartPair(MdPart::notDeleted);
for( MdPartIter i=p.begin(); i!=p.end(); ++i )
{
if( i->nr()>0 )
+ {
ret = removePartition( i->nr() );
+ }
}
+ //Remove 'whole device' it was created when last partition was deleted.
p=mdpartPair(MdPart::notDeleted);
if( p.begin()!=p.end() && p.begin()->nr()==0 )
{
if( !removeFromList( &(*p.begin()) ))
+ {
y2err( "not found:" << *p.begin() );
+ }
}
setDeleted( true );
- }
- if( ret==0 )
- {
- //unuseDev(); - In PeContainer.
+ destrSb = true;
+ del_ptable = true;
}
y2mil("ret:" << ret);
return( ret );
@@ -867,16 +879,90 @@
return( ret );
}
+//Remove MDPART unless:
+//1. It's IMSM or DDF SW RAID
+//2. It contains partitions.
int MdPartCo::doRemove()
{
- return( MDPART_NO_REMOVE );
+ y2mil("begin");
+ // 1. Check Metadata.
+ if( sb_ver == "imsm" || sb_ver == "ddf" )
+ {
+ if( !silent )
+ {
+ getStorage()->showInfoCb( noRemoveTextFormat(true) );
+ }
+ y2error("Cannot remove IMSM or DDF SW RAIDs.");
+ return (MDPART_NO_REMOVE);
+ }
+ // 2. Check for partitions.
+ if( disk!=NULL && disk->numPartitions()>0 )
+ {
+ int permitRemove=1;
+ //handleWholeDevice: partition 0.
+ if( disk->numPartitions() == 1 )
+ {
+ //Find partition '0' if it exists then this 'whole device'
+ MdPartIter i;
+ if( findMdPart( 0, i ) == true)
+ {
+ //Single case when removal is allowed.
+ permitRemove = 0;
+ }
+ }
+ if( permitRemove == 1 )
+ {
+ if( !silent )
+ {
+ getStorage()->showInfoCb( noRemoveTextPartitions(true) );
+ }
+ y2error("Cannot remove RAID with partitions.");
+ return (MDPART_NO_REMOVE);
+ }
+ }
+ /* Try to remove this. */
+ y2milestone( "Raid:%s is going to be removed permanently.", name().c_str() );
+ int ret = 0;
+ if( deleted() )
+ {
+ string cmd = MDADMBIN " --stop " + quote(device());
+ SystemCmd c( cmd );
+ if( c.retcode()!=0 )
+ {
+ ret = MD_REMOVE_FAILED;
+ setExtError( c );
+ }
+ if( !silent )
+ {
+ getStorage()->showInfoCb( removeText(true) );
+ }
+ if( ret==0 && destrSb )
+ {
+ SystemCmd c;
+ list<string> d;
+ getDevs( d );
+ for( list<string>::const_iterator i=d.begin(); i!=d.end(); ++i )
+ {
+ c.execute(MDADMBIN " --zero-superblock " + quote(*i));
+ }
+ }
+ if( ret==0 )
+ {
+ EtcRaidtab* tab = getStorage()->getRaidtab();
+ if( tab!=NULL )
+ {
+ tab->removeEntry( nr() );
+ }
+ }
+ }
+ y2mil("Done, ret:" << ret);
+ return( ret );
}
int MdPartCo::doRemove( Volume* v )
{
y2mil("name:" << name() << " v->name:" << v->name());
MdPart * l = dynamic_cast(v);
- bool save_act = false;
int ret = disk ? 0 : MDPART_INTERNAL_ERR;
if( ret==0 && l == NULL )
ret = MDPART_INVALID_VOLUME;
@@ -890,28 +976,28 @@
}
if( ret==0 )
{
- save_act = active;
- if( active )
- activate_part(false);
Partition *p = l->getPtr();
if( p==NULL )
+ {
+ y2error("Partition not found");
ret = MDPART_PARTITION_NOT_FOUND;
- else if( !deleted() )
- ret = disk->doRemove( p );
+ }
+ else
+ {
+ ret = disk->doRemove( p );
+ }
}
if( ret==0 )
{
if( !removeFromList( l ) )
+ {
+ y2warning("Couldn't remove parititon from list.");
ret = MDPART_REMOVE_PARTITION_LIST_ERASE;
- }
- if( save_act && !deleted() )
- {
- activate_part(true);
- updateMinor();
+ }
}
if( ret==0 )
getStorage()->waitForDevice();
- y2mil("ret:" << ret);
+ y2mil("Done, ret:" << ret);
return( ret );
}
@@ -1004,8 +1090,36 @@
}
return( txt );
}
-
-
+string MdPartCo::noRemoveTextFormat( bool doing ) const
+ {
+ string txt;
+ if( doing )
+ {
+ // displayed text during action, %1$s is replaced by a name (e.g. pdc_igeeeadj),
+ txt = sformat( _("Cannot remove %1$s. It is IMSM or DDF RAID."), name().c_str() );
+ }
+ else
+ {
+ // displayed text before action, %1$s is replaced by a name (e.g. pdc_igeeeadj),
+ txt = sformat( _("Couldn't remove %1$s. It is IMSM or DDF RAID."), name().c_str() );
+ }
+ return( txt );
+ }
+string MdPartCo::noRemoveTextPartitions( bool doing ) const
+ {
+ string txt;
+ if( doing )
+ {
+ // displayed text during action, %1$s is replaced by a name (e.g. pdc_igeeeadj),
+ txt = sformat( _("Cannot remove %1$s because it contains at least 1 partition."), name().c_str() );
+ }
+ else
+ {
+ // displayed text before action, %1$s is replaced by a name (e.g. pdc_igeeeadj),
+ txt = sformat( _("Couldn't remove %1$s because it contains at least 1 partition."), name().c_str() );
+ }
+ return( txt );
+ }
void
MdPartCo::setUdevData(const list<string>& id)
{
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=60399&r1=60398&r2=60399&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 Fri Jan 15 14:09:48 2010
@@ -277,6 +277,8 @@
int doCreateLabel();
virtual int doRemove();
virtual string removeText( bool doing ) const;
+ virtual string noRemoveTextFormat( bool doing ) const;
+ virtual string noRemoveTextPartitions( bool doing ) const;
virtual string setDiskLabelText( bool doing ) const;
void getMajorMinor(void);
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=60399&r1=60398&r2=60399&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 Fri Jan 15 14:09:48 2010
@@ -3865,6 +3865,37 @@
return ret;
}
+//
+// Removes Software RAIDs that are not IMSM RAIDs.
+//
+int Storage::removeMdPartCo(const string& devName, bool destroySb)
+{
+ y2mil("Called");
+ int ret;
+ MdPartCoIterator mdp;
+
+ mdp = findMdPartCo(devName);
+ if( mdp == mdpCoEnd() )
+ {
+ y2war("Not found device: " + devName);
+ return MDPART_DEVICE_NOT_FOUND;
+ }
+ MdPartCoInfo mdpInfo;
+ mdp->getInfo(mdpInfo);
+ if( mdpInfo.sb_ver == "imsm" || mdpInfo.sb_ver == "ddf" )
+ {
+ y2war("IMSM or DDF RAID cannot be removed");
+ return MDPART_NO_REMOVE;
+ }
+ //Remove all: Md Partitions and RAID itself.
+ ret = mdp->removeMdPart();
+ if( ret==0 )
+ {
+ ret = checkCache();
+ }
+ y2mil("Done, ret=" << ret);
+ return ret;
+}
bool Storage::haveMd( MdCo*& md )
{
@@ -4465,7 +4496,7 @@
const_cast((*ac)->vol()->getContainer());
if( cont )
{
- bool cont_removed = co->deleted() && type==LVM;
+ bool cont_removed = co->deleted() && (type==LVM || type==MDPART);
ret = co->commitChanges( *pt );
cont_removed = cont_removed && ret==0;
if( cont_removed )
@@ -5937,8 +5968,7 @@
//ret = removeDmraidCo( name );
break;
case UB_MDPART:
- y2war(device << " used by MD PART");
- //ret = removeMdPartCo( uby.device() );
+ ret = removeMdPartCo( uby.device(), true );
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=60399&r1=60398&r2=60399&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 Fri Jan 15 14:09:48 2010
@@ -481,6 +481,7 @@
MdPartCoInfo& info);
int getMdPartCoStateInfo(const string& name, MdPartCoStateInfo& info);
bool useMdForImsm() { return MdPartCo::isHandlingDev(); }
+ int removeMdPartCo(const string& devName, bool destroySb);
int addNfsDevice( const string& nfsDev, const string& opts,
unsigned long long sizeK, const string& mp );
Modified: branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/StorageInterface.h?rev=60399&r1=60398&r2=60399&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/StorageInterface.h (original)
+++ branches/SuSE-Code-11-SP1-Branch/storage/libstorage/src/StorageInterface.h Fri Jan 15 14:09:48 2010
@@ -712,6 +712,7 @@
MDPART_REMOVE_PARTITION_LIST_ERASE = -6104,
MDPART_COMMIT_NOTHING_TODO = -6105,
MDPART_NO_REMOVE = -6106,
+ MDPART_DEVICE_NOT_FOUND = -6107,
LOOP_CHANGE_READONLY = -7000,
LOOP_DUPLICATE_FILE = -7001,
@@ -1908,6 +1909,18 @@
virtual int computeMdSize(MdType md_type, list<string> devices,
unsigned long long& sizeK) = 0;
+ /**
+ * Remove a Partitionable Software raid device.
+ *
+ * Only RAID with persistent superblock can be removed. IMSM and DDF
+ * RAIDs cannot be removed.
+ * @param name name of software raid device to remove (e.g. /dev/md0)
+ * @param destroySb flag if the MD superblocks on the physical devices
+ * should be destroyed after md device is deleted
+ * @return zero if all is ok, a negative number to indicate an error
+ */
+ virtual int removeMdPartCo(const string& name, bool destroySb ) = 0;
+
/**
* Add knowledge about existence of nfs device.
*
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org