Author: aschnell Date: Wed Jul 23 17:35:16 2008 New Revision: 49369 URL: http://svn.opensuse.org/viewcvs/yast?rev=49369&view=rev Log: - show correct size when creating raids Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Md.cc branches/tmp/aschnell/part-redesign/libstorage/src/Md.h branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h branches/tmp/aschnell/part-redesign/storage/src/include/ep-raid-dialogs.ycp branches/tmp/aschnell/part-redesign/storage/src/modules/DevicesSelectionBox.ycp branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Md.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Md.cc?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/libstorage/src/Md.cc (original) +++ branches/tmp/aschnell/part-redesign/libstorage/src/Md.cc Wed Jul 23 17:35:16 2008 @@ -245,57 +245,12 @@ return( ret ); } - -// TODO: make this function available in StorageInterface.h -unsigned long long -Md::computeSizeK(storage::MdType md_type, list<string> devices) const -{ - unsigned long long sumK = 0; - unsigned long long smallestK = 0; - - for (list<string>::const_iterator i = devices.begin(); i != devices.end(); i++) - { - const Volume* v = getContainer()->getStorage()->getVolume(*i); - sumK += v->sizeK(); - if (smallestK == 0) - smallestK = v->sizeK(); - else - smallestK = min(smallestK, v->sizeK()); - } - - unsigned long long sizeK = 0; - switch (md_type) - { - case RAID0: - sizeK = sumK; - break; - case RAID1: - case MULTIPATH: - sizeK = smallestK; - break; - case RAID5: - sizeK = devices.size()==0 ? 0 : smallestK*(devices.size()-1); - break; - case RAID6: - sizeK = devices.size()<2 ? 0 : smallestK*(devices.size()-2); - break; - case RAID10: - sizeK = smallestK*devices.size()/2; - break; - default: - sizeK = 0; - break; - } - y2milestone ("type:%d smallest:%llu sum:%llu size:%llu", md_type, - smallestK, sumK, sizeK); - return sizeK; -} - - void Md::computeSize() { - setSize(computeSizeK(md_type, devs)); + unsigned long long size_k; + getContainer()->getStorage()->computeMdSize(md_type, devs, size_k); + setSize(size_k); } void Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Md.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Md.h?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/libstorage/src/Md.h (original) +++ branches/tmp/aschnell/part-redesign/libstorage/src/Md.h Wed Jul 23 17:35:16 2008 @@ -55,8 +55,6 @@ bool equalContent( const Md& rhs ) const; void logDifference( const Md& d ) const; - unsigned long long computeSizeK(storage::MdType md_type, std::list<string> devices) const; - protected: void init(); void computeSize(); Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc (original) +++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.cc Wed Jul 23 17:35:16 2008 @@ -3582,6 +3582,60 @@ return( ret ); } + +int +Storage::computeMdSize(MdType md_type, list<string> devices, unsigned long long& sizeK) +{ + int ret = 0; + + unsigned long long sumK = 0; + unsigned long long smallestK = 0; + + for (list<string>::const_iterator i = devices.begin(); i != devices.end(); i++) + { + const Volume* v = getVolume(*i); + if (!v) + { + ret = STORAGE_VOLUME_NOT_FOUND; + break; + } + + sumK += v->sizeK(); + if (smallestK == 0) + smallestK = v->sizeK(); + else + smallestK = min(smallestK, v->sizeK()); + } + + switch (md_type) + { + case RAID0: + sizeK = sumK; + break; + case RAID1: + case MULTIPATH: + sizeK = smallestK; + break; + case RAID5: + sizeK = devices.size()<1 ? 0 : smallestK*(devices.size()-1); + break; + case RAID6: + sizeK = devices.size()<2 ? 0 : smallestK*(devices.size()-2); + break; + case RAID10: + sizeK = smallestK*devices.size()/2; + break; + default: + break; + } + + y2milestone ("type:%d smallest:%llu sum:%llu size:%llu", md_type, + smallestK, sumK, sizeK); + + return ret; +} + + bool Storage::haveMd( MdCo*& md ) { md = NULL; Modified: branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h (original) +++ branches/tmp/aschnell/part-redesign/libstorage/src/Storage.h Wed Jul 23 17:35:16 2008 @@ -433,6 +433,8 @@ int changeMdChunk( const string& name, unsigned long chunk ); int changeMdParity( const string& name, storage::MdParity ptype ); int checkMd( const string& name ); + int computeMdSize(MdType md_type, list<string> devices, + unsigned long long& sizeK); int addNfsDevice( const string& nfsDev, const string& opts, unsigned long long sizeK, const string& mp ); Modified: branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h (original) +++ branches/tmp/aschnell/part-redesign/libstorage/src/StorageInterface.h Wed Jul 23 17:35:16 2008 @@ -4,10 +4,12 @@ #include <string> #include <deque> +#include <list> #include <ostream> using std::string; using std::deque; +using std::list; /*! @@ -1779,6 +1781,16 @@ virtual int checkMd( const string& name ) = 0; /** + * Compute the size of a raid device. + * + * @param md_type raid type of the software raid + * @param devices list with physical devices for the software raid + * @return zero if all is ok, a negative number to indicate an error + */ + virtual int computeMdSize(MdType md_type, list<string> devices, + unsigned long long& sizeK) = 0; + + /** * Add knowledge about existence of nfs device. * * @param nfsDev name of nfs device Modified: branches/tmp/aschnell/part-redesign/storage/src/include/ep-raid-dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/include/ep-raid-dialogs.ycp?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/storage/src/include/ep-raid-dialogs.ycp (original) +++ branches/tmp/aschnell/part-redesign/storage/src/include/ep-raid-dialogs.ycp Wed Jul 23 17:35:16 2008 @@ -64,15 +64,15 @@ `VBox( // Translators, 'Striping' is a technical term here. Translate only if // you are sure!! If in doubt, leave it in English. - `LeftRadioButton(`id(`raid0), _("RAID &0 (Striping)"), + `LeftRadioButton(`id(`raid0), `opt(`notify), _("RAID &0 (Striping)"), raid_type == "raid0"), // Translators, 'Mirroring' is a technical term here. Translate only if // you are sure!! If in doubt, leave it in English. - `LeftRadioButton(`id(`raid1), _("RAID &1 (Mirroring)"), + `LeftRadioButton(`id(`raid1), `opt(`notify), _("RAID &1 (Mirroring)"), raid_type == "raid1"), // Translators, 'Redundant Striping' is a technical term here. Translate // only if you are sure!! If in doubt, leave it in English. - `LeftRadioButton(`id(`raid5), _("RAID &5 (Redundant Striping)"), + `LeftRadioButton(`id(`raid5), `opt(`notify), _("RAID &5 (Redundant Striping)"), raid_type == "raid5") ) )))) @@ -85,6 +85,8 @@ MiniWorkflow::SetContents(Greasemonkey::Transform(contents), "TODO help"); MiniWorkflow::SetLastStep(false); + DevicesSelectionBox::SetSizeAlgorithm(symbolof(toterm(raid_type))); + symbol widget = nil; repeat @@ -94,10 +96,15 @@ switch (widget) { - case `next: - { + case `raid0: + case `raid1: + case `raid5: raid_type = substring(tostring((symbol) UI::QueryWidget(`id(`raid_type), `Value)), 1); + DevicesSelectionBox::SetSizeAlgorithm(symbolof(toterm(raid_type))); + break; + case `next: + { devices = maplist(map device, DevicesSelectionBox::GetSelectedDevices(), { return device["device"]:""; }); Modified: branches/tmp/aschnell/part-redesign/storage/src/modules/DevicesSelectionBox.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/modules/DevicesSelectionBox.ycp?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/storage/src/modules/DevicesSelectionBox.ycp (original) +++ branches/tmp/aschnell/part-redesign/storage/src/modules/DevicesSelectionBox.ycp Wed Jul 23 17:35:16 2008 @@ -18,6 +18,8 @@ list<map> devices = []; + symbol size_algorithm = `sum; + /** * Returns list with the maps of the unselected devices. @@ -45,13 +47,38 @@ } - term SizeTerm(list<map> tmp) + term UnselectedSizeTerm() { - integer size_k = Integer::Sum(maplist(map device, tmp, { return device["size_k"]:0; })); + list<map> unselected_devices = GetUnselectedDevices(); + integer size_k = Integer::Sum(maplist(map device, unselected_devices, { return device["size_k"]:0; })); return `Left(`Label(sformat(_("Total size: %1"), Storage::KByteToHumanString(size_k)))); } + term SelectedSizeTerm() + { + list<map> selected_devices = GetSelectedDevices(); + + integer size_k = 0; + if (contains([ `raid0, `raid1, `raid5, `raid6, `raid10 ], size_algorithm)) + Storage::ComputeMdSize(size_algorithm, maplist(map device, selected_devices, + { return device["device"]:"error"; }), size_k); + else + size_k = Integer::Sum(maplist(map device, selected_devices, { return device["size_k"]:0; })); + + return `Left(`Label(sformat(_("Resulting size: %1"), Storage::KByteToHumanString(size_k)))); + } + + + global void SetSizeAlgorithm(symbol new_size_algorithm) + { + size_algorithm = new_size_algorithm; + + UI::ReplaceWidget(`id(`unselected_rp), UnselectedSizeTerm()); + UI::ReplaceWidget(`id(`selected_rp), SelectedSizeTerm()); + } + + /** * The maps for the devices must contain the entries "device" and "size_k". * @@ -77,7 +104,7 @@ list<string> selected = maplist(map device, selected_devices, { return device["device"]:""; }); term ret = DualMultiSelectionBox::Create(header, content, selected, unselected_label, selected_label, - SizeTerm(unselected_devices), SizeTerm(selected_devices)); + UnselectedSizeTerm(), SelectedSizeTerm()); return ret; } @@ -89,8 +116,8 @@ if (contains([`unselected, `selected, `add, `add_all, `remove, `remove_all], widget)) { - UI::ReplaceWidget(`id(`unselected_rp), SizeTerm(GetUnselectedDevices())); - UI::ReplaceWidget(`id(`selected_rp), SizeTerm(GetSelectedDevices())); + UI::ReplaceWidget(`id(`unselected_rp), UnselectedSizeTerm()); + UI::ReplaceWidget(`id(`selected_rp), SelectedSizeTerm()); } } } Modified: branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp?rev=49369&r1=49368&r2=49369&view=diff ============================================================================== --- branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp (original) +++ branches/tmp/aschnell/part-redesign/storage/src/modules/Storage.ycp Wed Jul 23 17:35:16 2008 @@ -3280,6 +3280,22 @@ return( ret ); } +global integer ComputeMdSize(symbol md_type, list<string> devices, integer& sizeK) +{ + integer ret = 0; + + integer tmp = LibStorage::RAID_UNK(); + foreach(integer k, symbol v, conv_mdtype["m"]:$[], { + if (v == md_type) + tmp = k; + }); + + ret = LibStorage::StorageInterface::computeMdSize(sint, tmp, devices, sizeK); + if( ret!=0 ) + y2milestone( "ComputeMdSize sint ret:%1", ret ); + return ret; +} + global string CreateLoop( string file, boolean create, integer sizeK, string mp ) { -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org