Merge branch 'resize-polishing'

This commit is contained in:
Adriaan de Groot 2018-10-01 04:22:54 -04:00
commit af392105b8
3 changed files with 58 additions and 37 deletions

View File

@ -33,6 +33,7 @@
#include "JobQueue.h" #include "JobQueue.h"
#include "GlobalStorage.h" #include "GlobalStorage.h"
#include "utils/CalamaresUtils.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/Units.h" #include "utils/Units.h"
@ -48,11 +49,11 @@ ResizeFSJob::RelativeSize::RelativeSize()
template<int N> template<int N>
void matchUnitSuffix( void matchUnitSuffix(
const QString& s, const QString& s,
const char (&suffix)[N], const char ( &suffix )[N],
ResizeFSJob::RelativeSize::Unit matchedUnit, ResizeFSJob::RelativeSize::Unit matchedUnit,
int& value, int& value,
ResizeFSJob::RelativeSize::Unit& unit ResizeFSJob::RelativeSize::Unit& unit
) )
{ {
if ( s.endsWith( suffix ) ) if ( s.endsWith( suffix ) )
{ {
@ -62,7 +63,7 @@ void matchUnitSuffix(
} }
ResizeFSJob::RelativeSize::RelativeSize( const QString& s) ResizeFSJob::RelativeSize::RelativeSize( const QString& s )
: m_value( 0 ) : m_value( 0 )
, m_unit( None ) , m_unit( None )
{ {
@ -81,14 +82,14 @@ ResizeFSJob::RelativeSize::RelativeSize( const QString& s)
} }
qint64 qint64
ResizeFSJob::RelativeSize::apply( qint64 totalSectors , qint64 sectorSize ) ResizeFSJob::RelativeSize::apply( qint64 totalSectors, qint64 sectorSize )
{ {
if ( !isValid() ) if ( !isValid() )
return -1; return -1;
if ( sectorSize < 1 ) if ( sectorSize < 1 )
return -1; return -1;
switch( m_unit ) switch ( m_unit )
{ {
case None: case None:
return -1; return -1;
@ -113,6 +114,7 @@ ResizeFSJob::RelativeSize::apply( Device* d )
ResizeFSJob::ResizeFSJob( QObject* parent ) ResizeFSJob::ResizeFSJob( QObject* parent )
: Calamares::CppJob( parent ) : Calamares::CppJob( parent )
, m_required( false )
{ {
} }
@ -136,7 +138,7 @@ ResizeFSJob::findPartition( CoreBackend* backend )
cDebug() << "ResizeFSJob found" << devices.count() << "devices."; cDebug() << "ResizeFSJob found" << devices.count() << "devices.";
for ( DeviceList::iterator dev_it = devices.begin(); dev_it != devices.end(); ++dev_it ) for ( DeviceList::iterator dev_it = devices.begin(); dev_it != devices.end(); ++dev_it )
{ {
if ( ! (*dev_it) ) if ( ! ( *dev_it ) )
continue; continue;
cDebug() << "ResizeFSJob found" << ( *dev_it )->deviceNode(); cDebug() << "ResizeFSJob found" << ( *dev_it )->deviceNode();
for ( auto part_it = PartitionIterator::begin( *dev_it ); part_it != PartitionIterator::end( *dev_it ); ++part_it ) for ( auto part_it = PartitionIterator::begin( *dev_it ); part_it != PartitionIterator::end( *dev_it ); ++part_it )
@ -164,7 +166,7 @@ ResizeFSJob::findPartition( CoreBackend* backend )
* by occupied space after it). * by occupied space after it).
*/ */
qint64 qint64
ResizeFSJob::findGrownEnd(ResizeFSJob::PartitionMatch m) ResizeFSJob::findGrownEnd( ResizeFSJob::PartitionMatch m )
{ {
if ( !m.first || !m.second ) if ( !m.first || !m.second )
return -1; // Missing device data return -1; // Missing device data
@ -193,7 +195,7 @@ ResizeFSJob::findGrownEnd(ResizeFSJob::PartitionMatch m)
continue; continue;
} }
cDebug() << ".. comparing" << next_start << '-' << next_end; cDebug() << ".. comparing" << next_start << '-' << next_end;
if ( (next_start > last_currently) && (next_start < last_available) ) if ( ( next_start > last_currently ) && ( next_start < last_available ) )
{ {
cDebug() << " .. shrunk last available to" << next_start; cDebug() << " .. shrunk last available to" << next_start;
last_available = next_start - 1; // Before that one starts last_available = next_start - 1; // Before that one starts
@ -202,7 +204,7 @@ ResizeFSJob::findGrownEnd(ResizeFSJob::PartitionMatch m)
if ( !( last_available > last_currently ) ) if ( !( last_available > last_currently ) )
{ {
cDebug() << "Partition can not grow larger."; cDebug() << "Partition cannot grow larger.";
return 0; return 0;
} }
@ -234,13 +236,12 @@ ResizeFSJob::exec()
if ( !isValid() ) if ( !isValid() )
return Calamares::JobResult::error( return Calamares::JobResult::error(
tr( "Invalid configuration" ), tr( "Invalid configuration" ),
tr( "The file-system resize job has an invalid configuration " tr( "The file-system resize job has an invalid configuration and will not run." ) );
"and will not run." ) );
// Get KPMCore // Get KPMCore
auto backend_p = CoreBackendManager::self()->backend(); auto backend_p = CoreBackendManager::self()->backend();
if ( backend_p ) if ( backend_p )
cDebug() << "KPMCore backend @" << (void *)backend_p << backend_p->id() << backend_p->version(); cDebug() << "KPMCore backend @" << ( void* )backend_p << backend_p->id() << backend_p->version();
else else
{ {
cDebug() << "No KPMCore backend loaded yet"; cDebug() << "No KPMCore backend loaded yet";
@ -269,8 +270,8 @@ ResizeFSJob::exec()
if ( !m.first || !m.second ) if ( !m.first || !m.second )
return Calamares::JobResult::error( return Calamares::JobResult::error(
tr( "Resize Failed" ), tr( "Resize Failed" ),
!m_fsname.isEmpty() ? tr( "The filesystem %1 could not be found in this system, and can not be resized." ).arg(m_fsname) !m_fsname.isEmpty() ? tr( "The filesystem %1 could not be found in this system, and cannot be resized." ).arg( m_fsname )
: tr( "The device %1 could not be found in this system, and can not be resized." ).arg(m_devicename) ); : tr( "The device %1 could not be found in this system, and cannot be resized." ).arg( m_devicename ) );
m.second->fileSystem().init(); // Initialize support for specific FS m.second->fileSystem().init(); // Initialize support for specific FS
if ( !ResizeOperation::canGrow( m.second ) ) if ( !ResizeOperation::canGrow( m.second ) )
@ -278,8 +279,8 @@ ResizeFSJob::exec()
cDebug() << "canGrow() returned false."; cDebug() << "canGrow() returned false.";
return Calamares::JobResult::error( return Calamares::JobResult::error(
tr( "Resize Failed" ), tr( "Resize Failed" ),
!m_fsname.isEmpty() ? tr( "The filesystem %1 can not be resized." ).arg(m_fsname) !m_fsname.isEmpty() ? tr( "The filesystem %1 cannot be resized." ).arg( m_fsname )
: tr( "The device %1 can not be resized." ).arg(m_devicename) ); : tr( "The device %1 cannot be resized." ).arg( m_devicename ) );
} }
qint64 new_end = findGrownEnd( m ); qint64 new_end = findGrownEnd( m );
@ -291,13 +292,18 @@ ResizeFSJob::exec()
if ( new_end < 0 ) if ( new_end < 0 )
return Calamares::JobResult::error( return Calamares::JobResult::error(
tr( "Resize Failed" ), tr( "Resize Failed" ),
!m_fsname.isEmpty() ? tr( "The filesystem %1 can not be resized." ).arg(m_fsname) !m_fsname.isEmpty() ? tr( "The filesystem %1 cannot be resized." ).arg( m_fsname )
: tr( "The device %1 can not be resized." ).arg(m_devicename) ); : tr( "The device %1 cannot be resized." ).arg( m_devicename ) );
if ( new_end == 0 ) if ( new_end == 0 )
{ {
// TODO: is that a bad thing? is the resize required?
cWarning() << "Resize operation on" << m_fsname << m_devicename cWarning() << "Resize operation on" << m_fsname << m_devicename
<< "skipped as not-useful."; << "skipped as not-useful.";
if ( m_required )
return Calamares::JobResult::error(
tr( "Resize Failed" ),
!m_fsname.isEmpty() ? tr( "The filesystem %1 must be resized, but cannot." ).arg( m_fsname )
: tr( "The device %11 must be resized, but cannot" ).arg( m_fsname ) );
return Calamares::JobResult::ok(); return Calamares::JobResult::ok();
} }
@ -334,6 +340,8 @@ ResizeFSJob::setConfigurationMap( const QVariantMap& configurationMap )
m_size = RelativeSize( configurationMap["size"].toString() ); m_size = RelativeSize( configurationMap["size"].toString() );
m_atleast = RelativeSize( configurationMap["atleast"].toString() ); m_atleast = RelativeSize( configurationMap["atleast"].toString() );
m_required = CalamaresUtils::getBool( configurationMap, "required", false );
} }
CALAMARES_PLUGIN_FACTORY_DEFINITION( ResizeFSJobFactory, registerPlugin<ResizeFSJob>(); ) CALAMARES_PLUGIN_FACTORY_DEFINITION( ResizeFSJobFactory, registerPlugin<ResizeFSJob>(); )

View File

@ -107,6 +107,7 @@ private:
RelativeSize m_atleast; RelativeSize m_atleast;
QString m_fsname; // Either this, or devicename, is set, not both QString m_fsname; // Either this, or devicename, is set, not both
QString m_devicename; QString m_devicename;
bool m_required;
using PartitionMatch = QPair<Device*, Partition*>; using PartitionMatch = QPair<Device*, Partition*>;
/** @brief Find the configured FS using KPMCore @p backend */ /** @brief Find the configured FS using KPMCore @p backend */

View File

@ -33,5 +33,17 @@ size: 100%
# size, as above. If missing, then it's assumed to be 0, # size, as above. If missing, then it's assumed to be 0,
# which means resizing is always worthwhile. # which means resizing is always worthwhile.
# #
# If *atleast* is not zero, then the setting *required*,
# below, becomes relevant.
#
# Percentages apply to **total device size**. # Percentages apply to **total device size**.
atleast: 1000MiB #atleast: 1000MiB
# When *atleast* is not zero, then the resize may be
# recommended (the default) or **required**. If the
# resize is required and cannot be carried out (because
# there's not enough space), then that is a fatal
# error for the installer. By default, resize is only
# recommended and it is not an error for no resize to be
# carried out.
required: false