Author: aschnell
Date: Fri Nov 7 12:32:31 2008
New Revision: 53051
URL: http://svn.opensuse.org/viewcvs/yast?rev=53051&view=rev
Log:
- fixed off-by-one error during resizing of partitions by moving FreeCylAfter to libstorage
Modified:
trunk/storage/libstorage/src/Disk.cc
trunk/storage/libstorage/src/Disk.h
trunk/storage/libstorage/src/DmPartCo.cc
trunk/storage/libstorage/src/DmPartCo.h
trunk/storage/libstorage/src/Storage.cc
trunk/storage/libstorage/src/Storage.h
trunk/storage/libstorage/src/StorageInterface.h
trunk/storage/package/yast2-storage.changes
trunk/storage/storage/src/include/ep-dialogs.ycp
trunk/storage/storage/src/inst_custom_part.ycp
trunk/storage/storage/src/modules/Storage.ycp
Modified: trunk/storage/libstorage/src/Disk.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Disk.cc?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Disk.cc (original)
+++ trunk/storage/libstorage/src/Disk.cc Fri Nov 7 12:32:31 2008
@@ -2394,64 +2394,83 @@
return( ret );
}
-int Disk::resizePartition( Partition* p, unsigned long newCyl )
- {
- y2mil( "newCyl:" << newCyl << " p:" << *p );
+
+int
+Disk::freeCylindersAfterPartition(const Partition* p, unsigned long& freeCyls)
+{
+ int ret = 0;
+ freeCyls = 0;
+ unsigned long start = p->cylEnd() + 1;
+ unsigned long end = cylinders();
+ if (p->type() == LOGICAL && hasExtended())
+ {
+ PartPair pp = partPair(notDeletedExt);
+ end = pp.begin()->cylEnd() + 1;
+ }
+ PartPair pp = partPair(notDeleted);
+ PartIter i = pp.begin();
+ while (i != pp.end())
+ {
+ if( (i->type()==p->type()||
+ (i->type()==EXTENDED&&p->type()==PRIMARY)) &&
+ i->cylStart()>=start && i->cylStart()cylStart();
+ ++i;
+ }
+ if (end > start)
+ freeCyls = end-start;
+ y2mil("ret:" << ret << " freeCyls:" << freeCyls);
+ return ret;
+}
+
+
+int
+Disk::resizePartition(Partition* p, unsigned long newCyl)
+{
+ y2mil("newCyl:" << newCyl << " p:" << *p);
int ret = 0;
if( readonly() )
- {
+ {
ret = DISK_CHANGE_READONLY;
- }
+ }
else
- {
+ {
unsigned long long newSize = cylinderToKb(newCyl);
if( newCyl!=p->cylSize() )
ret = p->canResize( newSize );
if( ret==0 && newCyl<p->cylSize() )
- {
+ {
if( p->created() )
p->changeRegion( p->cylStart(), newCyl, newSize );
else
p->setResizedSize( newSize );
- }
- y2mil( "newCyl:" << newCyl << " p->cylSize():" << p->cylSize() );
+ }
+ y2mil("newCyl:" << newCyl << " p->cylSize():" << p->cylSize());
if( ret==0 && newCyl>p->cylSize() )
+ {
+ unsigned long free_cyls = 0;
+ ret = freeCylindersAfterPartition(p, free_cyls);
+ if (ret == 0)
{
- unsigned long increase = newCyl - p->cylSize();
- PartPair pp = partPair(notDeletedExt);
- unsigned long start = p->cylEnd()+1;
- unsigned long end = cylinders();
- if( p->type()==LOGICAL && !pp.empty() )
- end = pp.begin()->cylEnd()+1;
- pp = partPair( notDeleted );
- PartIter i = pp.begin();
- while( i != pp.end() )
+ unsigned long increase = newCyl - p->cylSize();
+ if (free_cyls < increase)
{
- if( (i->type()==p->type()||
- (i->type()==EXTENDED&&p->type()==PRIMARY)) &&
- i->cylStart()>=start && i->cylStart()cylStart();
- ++i;
+ ret = DISK_RESIZE_NO_SPACE;
}
- unsigned long free = 0;
- if( end>start )
- free = end-start;
- y2milestone( "free cylinders after %lu SizeK:%llu Extend:%lu",
- free, cylinderToKb(free), increase );
- if( free < increase )
- ret = DISK_RESIZE_NO_SPACE;
- else
- {
- if( p->created() )
- p->changeRegion( p->cylStart(), newCyl, newSize );
else
- p->setResizedSize( newSize );
+ {
+ if( p->created() )
+ p->changeRegion( p->cylStart(), newCyl, newSize );
+ else
+ p->setResizedSize( newSize );
}
}
}
- y2milestone( "ret:%d", ret );
- return( ret );
}
+ y2mil("ret:" << ret);
+ return ret;
+}
+
int Disk::resizeVolume( Volume* v, unsigned long long newSize )
{
Modified: trunk/storage/libstorage/src/Disk.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Disk.h?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Disk.h (original)
+++ trunk/storage/libstorage/src/Disk.h Fri Nov 7 12:32:31 2008
@@ -83,6 +83,7 @@
std::list& vol );
virtual int commitChanges( storage::CommitStage stage );
int commitChanges( storage::CommitStage stage, Volume* vol );
+ int freeCylindersAfterPartition(const Partition* p, unsigned long& freeCyls);
virtual int resizePartition( Partition* p, unsigned long newCyl );
int resizeVolume( Volume* v, unsigned long long newSize );
int removeVolume( Volume* v );
Modified: trunk/storage/libstorage/src/DmPartCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/DmPartCo.cc?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/libstorage/src/DmPartCo.cc (original)
+++ trunk/storage/libstorage/src/DmPartCo.cc Fri Nov 7 12:32:31 2008
@@ -186,6 +186,21 @@
return( ret );
}
+
+int
+DmPartCo::freeCylindersAfterPartition(const DmPart* dm, unsigned long& freeCyls)
+{
+ const Partition* p = dm->getPtr();
+ int ret = p ? 0 : DMPART_PARTITION_NOT_FOUND;
+ if (ret == 0)
+ {
+ ret = disk->freeCylindersAfterPartition(p, freeCyls);
+ }
+ y2mil("ret:" << ret);
+ return ret;
+}
+
+
int DmPartCo::resizePartition( DmPart* dm, unsigned long newCyl )
{
Partition * p = dm->getPtr();
Modified: trunk/storage/libstorage/src/DmPartCo.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/DmPartCo.h?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/libstorage/src/DmPartCo.h (original)
+++ trunk/storage/libstorage/src/DmPartCo.h Fri Nov 7 12:32:31 2008
@@ -50,6 +50,7 @@
string& device );
int destroyPartitionTable( const string& new_label );
unsigned availablePartNumber( storage::PartitionType type=storage::PRIMARY );
+ int freeCylindersAfterPartition(const DmPart* p, unsigned long& freeCyls);
int resizePartition( DmPart* p, unsigned long newCyl );
int resizeVolume( Volume* v, unsigned long long newSize );
int removeVolume( Volume* v );
Modified: trunk/storage/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Storage.cc?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Storage.cc (original)
+++ trunk/storage/libstorage/src/Storage.cc Fri Nov 7 12:32:31 2008
@@ -1401,6 +1401,57 @@
return( ret );
}
+
+int
+Storage::freeCylindersAfterPartition(const string& partition, unsigned long& freeCyls)
+{
+ int ret = 0;
+ assertInit();
+ y2mil("partition:" << partition);
+ VolIterator vol;
+ ContIterator cont;
+ if( findVolume( partition, cont, vol ) )
+ {
+ if( cont->type()==DISK )
+ {
+ Disk* disk = dynamic_cast(&(*cont));
+ Partition* p = dynamic_cast(&(*vol));
+ if( disk!=NULL && p!=NULL )
+ {
+ ret = disk->freeCylindersAfterPartition(p, freeCyls);
+ }
+ else
+ {
+ ret = STORAGE_RESIZE_INVALID_CONTAINER;
+ }
+ }
+ else if( cont->type()==DMRAID || cont->type()==DMMULTIPATH )
+ {
+ DmPartCo* disk = dynamic_cast(&(*cont));
+ DmPart* p = dynamic_cast(&(*vol));
+ if( disk!=NULL && p!=NULL )
+ {
+ ret = disk->freeCylindersAfterPartition(p, freeCyls);
+ }
+ else
+ {
+ ret = STORAGE_RESIZE_INVALID_CONTAINER;
+ }
+ }
+ else
+ {
+ ret = STORAGE_RESIZE_INVALID_CONTAINER;
+ }
+ }
+ else
+ {
+ ret = STORAGE_VOLUME_NOT_FOUND;
+ }
+ y2mil("ret:" << ret);
+ return ret;
+}
+
+
int
Storage::changePartitionId( const string& partition, unsigned id )
{
Modified: trunk/storage/libstorage/src/Storage.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/Storage.h?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/libstorage/src/Storage.h (original)
+++ trunk/storage/libstorage/src/Storage.h Fri Nov 7 12:32:31 2008
@@ -305,6 +305,7 @@
unsigned &nr, string& device );
int updatePartitionArea( const string& device,
unsigned long start, unsigned long size );
+ int freeCylindersAfterPartition(const string& device, unsigned long& freeCyls);
int createPartitionKb( const string& disk, storage::PartitionType type,
unsigned long long start,
unsigned long long sizek, string& device );
Modified: trunk/storage/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/libstorage/src/StorageInterface.h?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/libstorage/src/StorageInterface.h (original)
+++ trunk/storage/libstorage/src/StorageInterface.h Fri Nov 7 12:32:31 2008
@@ -946,6 +946,14 @@
unsigned long start,
unsigned long sizeCyl ) = 0;
+ /**
+ * Return the number of free cylinders after a partition.
+ *
+ * @param device device name of partition, e.g. /dev/sda1
+ * @param freeCyls is set to the number of free cylinders
+ * @return zero if all is ok, a negative number to indicate an error
+ */
+ virtual int freeCylindersAfterPartition(const string& device, unsigned long& freeCyls) = 0;
/**
* Determine the device name of the next created partition
Modified: trunk/storage/package/yast2-storage.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/package/yast2-storage.changes?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/package/yast2-storage.changes (original)
+++ trunk/storage/package/yast2-storage.changes Fri Nov 7 12:32:31 2008
@@ -1,9 +1,15 @@
-------------------------------------------------------------------
+Fri Nov 07 12:30:59 CET 2008 - aschnell@suse.de
+
+- fixed off-by-one error during resizing of partitions (bnc
+ #442318)
+- 2.17.49
+
+-------------------------------------------------------------------
Thu Nov 06 19:58:25 CET 2008 - aschnell@suse.de
- added note that encrypted swap without password cannot be used
for suspend (bnc #441893)
-- 2.17.49
-------------------------------------------------------------------
Thu Nov 06 16:46:40 CET 2008 - aschnell@suse.de
Modified: trunk/storage/storage/src/include/ep-dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/storage/src/include/ep-dialogs.ycp?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/storage/src/include/ep-dialogs.ycp (original)
+++ trunk/storage/storage/src/include/ep-dialogs.ycp Fri Nov 7 12:32:31 2008
@@ -526,8 +526,8 @@
}
- integer cyl_size = disk["cyl_size"]:1;
- integer free_cyl_after = Storage::FreeCylAfter(disk, data);
+ integer cyl_size = 0;
+ integer free_cyl_after = 0;
string device = data["device"]:"error";
symbol used_fs = data["used_fs"]:`none;
@@ -633,6 +633,9 @@
// Heading for dialog
heading = sformat(_("Resize Partition %1"), device);
+ cyl_size = disk["cyl_size"]:1;
+ free_cyl_after = Storage::FreeCylindersAfterPartition(device);
+
min_size_k = Integer::Max([ min_size_k, cyl_size / 1024 ]);
max_size_k = size_k + (cyl_size * free_cyl_after) / 1024;
}
Modified: trunk/storage/storage/src/inst_custom_part.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/storage/src/inst_custom_part.ycp?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/storage/src/inst_custom_part.ycp (original)
+++ trunk/storage/storage/src/inst_custom_part.ycp Fri Nov 7 12:32:31 2008
@@ -1194,7 +1194,7 @@
integer cyl_after = 0;
if( possible["extend"]:false )
{
- cyl_after = Storage::FreeCylAfter( disk, cur_val );
+ // cyl_after = Storage::FreeCylAfter( disk, cur_val );
}
integer av_space = cyl_after*cyl_size;
Modified: trunk/storage/storage/src/modules/Storage.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/storage/storage/src/modules/Storage.ycp?rev=53051&r1=53050&r2=53051&view=diff
==============================================================================
--- trunk/storage/storage/src/modules/Storage.ycp (original)
+++ trunk/storage/storage/src/modules/Storage.ycp Fri Nov 7 12:32:31 2008
@@ -4591,30 +4591,12 @@
}
-global define integer FreeCylAfter(map disk, map partition)
+global integer FreeCylindersAfterPartition(string device)
{
integer ret = 0;
- integer end_cyl = Region::End(partition["region"]:[]);
- integer next_used_cyl = disk["cyl_count"]:0;
- if( partition["type"]:`primary == `logical )
- {
- map ext = filter( map part, disk["partitions"]:[],
- ``( part["type"]:`primary==`extended ))[0]:$[];
- next_used_cyl = Region::Length(ext["region"]:[]);
- }
- if( end_cyl < next_used_cyl )
- {
- foreach(map part, disk["partitions"]:[], ``{
- integer start = part["region",0]:0;
- if( start >= end_cyl && start < next_used_cyl )
- {
- next_used_cyl = start;
- }
- });
- }
- if( next_used_cyl >= end_cyl )
- ret = next_used_cyl - end_cyl;
- y2milestone("FreeCylAfter end_cyl:%1 ret:%2", end_cyl, ret);
+ if (LibStorage::StorageInterface::freeCylindersAfterPartition(sint, device, ret) != 0)
+ ret = 0;
+ y2milestone("FreeCylindersAfterPartition ret:%1", ret);
return ret;
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org