Author: fehr
Date: Tue May 31 15:12:50 2011
New Revision: 64176
URL: http://svn.opensuse.org/viewcvs/yast?rev=64176&view=rev
Log:
format multi volume btrfs with mkfs.btrfs and subssequent calls to "btrfs device add ..."
Modified:
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageInterface.h
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.cc
branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.h
branches/SuSE-Code-11-SP2-Branch/storage/package/yast2-storage.changes
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc?rev=64176&r1=64175&r2=64176&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Btrfs.cc Tue May 31 15:12:50 2011
@@ -263,18 +263,9 @@
int Btrfs::doExtend()
{
y2mil( "this:" << *this );
- int ret = 0;
- bool needUmount = false;
- Storage* st = NULL;
- string m = getMount();
- if( !isMounted() )
- {
- st = getContainer()->getStorage();
- if( st->mountTmp( this, m ) )
- needUmount = true;
- else
- ret = BTRFS_CANNOT_TMP_MOUNT;
- }
+ bool needUmount;
+ string m;
+ int ret = prepareTmpMount( m, needUmount );
list<string> devs = dev_add;
list<string>::const_iterator d = devs.begin();
SystemCmd c;
@@ -294,12 +285,7 @@
++d;
}
if( needUmount )
- {
- if( !st->umountDev( device() ) && ret==0 )
- {
- ret = BTRFS_CANNOT_TMP_UMOUNT;
- }
- }
+ ret = umountTmpMount( ret );
y2mil( "this:" << *this );
y2mil("ret:" << ret);
return( ret );
@@ -308,18 +294,9 @@
int Btrfs::doReduce()
{
y2mil( "this:" << *this );
- int ret = 0;
- bool needUmount = false;
- Storage* st = NULL;
- string m = getMount();
- if( !isMounted() )
- {
- st = getContainer()->getStorage();
- if( st->mountTmp( this, m ) )
- needUmount = true;
- else
- ret = BTRFS_CANNOT_TMP_MOUNT;
- }
+ bool needUmount;
+ string m;
+ int ret = prepareTmpMount( m, needUmount );
list<string> devs = dev_rem;
list<string>::const_iterator d = devs.begin();
SystemCmd c;
@@ -339,12 +316,7 @@
++d;
}
if( needUmount )
- {
- if( !st->umountDev( device() ) && ret==0 )
- {
- ret = BTRFS_CANNOT_TMP_UMOUNT;
- }
- }
+ ret = umountTmpMount( ret );
y2mil( "this:" << *this );
y2mil("ret:" << ret);
return( ret );
@@ -352,18 +324,9 @@
int Btrfs::doDeleteSubvol()
{
- int ret = 0;
- bool needUmount = false;
- Storage* st = NULL;
- string m = getMount();
- if( !isMounted() )
- {
- st = getContainer()->getStorage();
- if( st->mountTmp( this, m ) )
- needUmount = true;
- else
- ret = BTRFS_CANNOT_TMP_MOUNT;
- }
+ bool needUmount;
+ string m;
+ int ret = prepareTmpMount( m, needUmount );
if( ret==0 )
{
SystemCmd c;
@@ -383,30 +346,16 @@
}
}
if( needUmount )
- {
- if( !st->umountDev( device() ) && ret==0 )
- {
- ret = BTRFS_CANNOT_TMP_UMOUNT;
- }
- }
+ ret = umountTmpMount( ret );
y2mil( "ret:" << ret );
return( ret );
}
int Btrfs::doCreateSubvol()
{
- int ret = 0;
- bool needUmount = false;
- Storage* st = NULL;
- string m = getStorage()->prependRoot(getMount());
- if( !isMounted() )
- {
- st = getContainer()->getStorage();
- if( st->mountTmp( this, m ) )
- needUmount = true;
- else
- ret = BTRFS_CANNOT_TMP_MOUNT;
- }
+ bool needUmount;
+ string m;
+ int ret = prepareTmpMount( m, needUmount );
if( ret==0 )
{
SystemCmd c;
@@ -435,12 +384,7 @@
}
}
if( needUmount )
- {
- if( !st->umountDev( device() ) && ret==0 )
- {
- ret = BTRFS_CANNOT_TMP_UMOUNT;
- }
- }
+ ret = umountTmpMount( ret );
y2mil( "ret:" << ret );
return( ret );
}
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageInterface.h?rev=64176&r1=64175&r2=64176&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageInterface.h (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/StorageInterface.h Tue May 31 15:12:50 2011
@@ -746,6 +746,9 @@
VOLUME_REMOUNT_FAILED = -3039,
VOLUME_TUNEREISERFS_FAILED = -3040,
VOLUME_UMOUNT_NOT_MOUNTED = -3041,
+ VOLUME_BTRFS_ADD_FAILED = -3042,
+ VOLUME_CANNOT_TMP_MOUNT = -3043,
+ VOLUME_CANNOT_TMP_UMOUNT = -3044,
LVM_CREATE_PV_FAILED = -4000,
LVM_PV_ALREADY_CONTAINED = -4001,
Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.cc?rev=64176&r1=64175&r2=64176&view=diff
==============================================================================
--- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.cc (original)
+++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.cc Tue May 31 15:12:50 2011
@@ -707,6 +707,30 @@
return( ret );
}
+int Volume::prepareTmpMount( string& m, bool& needUmount )
+ {
+ int ret = 0;
+ needUmount=false;
+ m = getMount();
+ if( !isMounted() )
+ {
+ if( getStorage()->mountTmp( this, m ) )
+ needUmount = true;
+ else
+ ret = VOLUME_CANNOT_TMP_MOUNT;
+ }
+ y2mil( "ret:" << " mp:" << m << " needUmount:" << needUmount );
+ return( ret );
+ }
+
+int Volume::umountTmpMount( int ret )
+ {
+ int r = ret;
+ if( !getStorage()->umountDev( mountDevice() ) && r==0 )
+ r = VOLUME_CANNOT_TMP_UMOUNT;
+ return( r );
+ }
+
Text Volume::formatText( bool doing ) const
{
Text txt;
@@ -794,6 +818,48 @@
return( ret );
}
+int Volume::doFormatBtrfs()
+ {
+ int ret = 0;
+ SystemCmd c;
+ string cmd = "/sbin/mkfs.btrfs " + quote(mountDevice());
+ c.execute( cmd );
+ if( c.retcode()!=0 )
+ {
+ ret = VOLUME_FORMAT_FAILED;
+ setExtError( c );
+ }
+ if( ret==0 && cType()==BTRFSC && getEncryption()==ENC_NONE )
+ {
+ const Btrfs* l = static_cast