[yast-commit] r64176 - in /branches/SuSE-Code-11-SP2-Branch/storage: libstorage/src/Btrfs.cc libstorage/src/StorageInterface.h libstorage/src/Volume.cc libstorage/src/Volume.h package/yast2-storage.changes
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<const Btrfs*>(this); + list<string> li = l->getDevices(); + y2mil( "devices:" << li ); + if( li.size()>1 ) + { + cmd = BTRFSBIN " device add "; + bool needUmount; + string m; + ret = prepareTmpMount( m, needUmount ); + if( ret==0 ) + { + for( list<string>::const_iterator i=li.begin(); i!=li.end(); ++i ) + { + if( *i!=device() && *i!=mountDevice() ) + { + c.execute( cmd + quote(*i) + " " + m ); + if( c.retcode()!=0 ) + ret = VOLUME_BTRFS_ADD_FAILED; + } + } + } + if( needUmount ) + ret = umountTmpMount( ret ); + } + } + y2mil( "ret:" << ret ); + return( ret ); + } + int Volume::doFormat() { static int fcount=1000; @@ -858,9 +924,6 @@ params = "-t ext4 -v"; progressbar = new Mke2fsProgressBar( cb ); break; - case BTRFS: - cmd = "/sbin/mkfs.btrfs"; - break; case REISERFS: cmd = "/sbin/mkreiserfs"; params = "-f -f"; @@ -891,7 +954,9 @@ ret = VOLUME_FORMAT_UNKNOWN_FS; break; } - if( ret==0 ) + if( ret==VOLUME_FORMAT_UNKNOWN_FS && fs==BTRFS ) + ret = doFormatBtrfs(); + if( ret==0 && fs!=BTRFS ) { cmd += " "; if( !mkfs_opt.empty() ) @@ -902,18 +967,7 @@ { cmd += params + " "; } - if( fs==BTRFS && cType()==BTRFSC && getEncryption()==ENC_NONE ) - { - const Btrfs* l = static_cast<const Btrfs*>(this); - list<string> li = l->getDevices(); - for( list<string>::const_iterator i=li.begin(); i!=li.end(); ++i ) - { - cmd += ' '; - cmd += quote(*i ); - } - } - else - cmd += quote(mountDevice()); + cmd += quote(mountDevice()); SystemCmd c; c.setOutputProcessor(progressbar); c.execute( cmd ); Modified: branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.h URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.h?rev=64176&r1=64175&r2=64176&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.h (original) +++ branches/SuSE-Code-11-SP2-Branch/storage/libstorage/src/Volume.h Tue May 31 15:12:50 2011 @@ -234,6 +234,9 @@ bool pwdLengthOk( storage::EncryptType typ, const string& val, bool format ) const; bool noFreqPassno() const; + int prepareTmpMount( string& m, bool& needUmount ); + int umountTmpMount( int ret ); + int doFormatBtrfs(); string getLosetupCmd( storage::EncryptType, const string& pwdfile ) const; string getCryptsetupCmd( storage::EncryptType e, const string& dmdev, Modified: branches/SuSE-Code-11-SP2-Branch/storage/package/yast2-storage.changes URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/storage/package/yast2-storage.changes?rev=64176&r1=64175&r2=64176&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/storage/package/yast2-storage.changes (original) +++ branches/SuSE-Code-11-SP2-Branch/storage/package/yast2-storage.changes Tue May 31 15:12:50 2011 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Tue May 31 15:12:18 CEST 2011 - fehr@suse.de + +- format multi volume btrfs with mkfs.btrfs and subssequent calls to + "btrfs device add ..." + +------------------------------------------------------------------- Mon May 30 18:32:40 CEST 2011 - fehr@suse.de - add default subvol list to root fs -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
fehr@svn2.opensuse.org