2011-11-28 05:33:51 -07:00
|
|
|
/* Copyright (C) 2012 Mike Fleetwood
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2011-11-28 05:33:51 -07:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2011-11-28 05:33:51 -07:00
|
|
|
*/
|
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "LVM2_PV_Info.h"
|
|
|
|
#include "lvm2_pv.h"
|
|
|
|
#include "Partition.h"
|
2011-11-28 05:33:51 -07:00
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2015-05-16 02:38:22 -06:00
|
|
|
const Glib::ustring lvm2_pv::get_custom_text( CUSTOM_TEXT ttype, int index ) const
|
2012-02-13 05:44:45 -07:00
|
|
|
{
|
|
|
|
/*TO TRANSLATORS: these labels will be used in the partition menu */
|
|
|
|
static const Glib::ustring activate_text = _( "Ac_tivate" ) ;
|
|
|
|
static const Glib::ustring deactivate_text = _( "Deac_tivate" ) ;
|
|
|
|
|
2012-08-25 15:25:23 -06:00
|
|
|
static const Glib::ustring resize_warning =
|
|
|
|
_( "The LVM2 Physical Volume can not currently be resized because it is a member of an exported "
|
|
|
|
"Volume Group." ) ;
|
|
|
|
|
2012-02-13 05:44:45 -07:00
|
|
|
switch ( ttype )
|
|
|
|
{
|
|
|
|
case CTEXT_ACTIVATE_FILESYSTEM:
|
|
|
|
return index == 0 ? activate_text : "" ;
|
|
|
|
case CTEXT_DEACTIVATE_FILESYSTEM:
|
|
|
|
return index == 0 ? deactivate_text : "" ;
|
2012-08-25 15:25:23 -06:00
|
|
|
case CTEXT_RESIZE_DISALLOWED_WARNING:
|
|
|
|
return index == 0 ? resize_warning : "" ;
|
2012-02-13 05:44:45 -07:00
|
|
|
default:
|
|
|
|
return "" ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 05:33:51 -07:00
|
|
|
FS lvm2_pv::get_filesystem_support()
|
|
|
|
{
|
2015-11-13 14:46:57 -07:00
|
|
|
FS fs( FS_LVM2_PV );
|
2011-11-28 05:33:51 -07:00
|
|
|
|
2015-06-05 13:54:37 -06:00
|
|
|
if ( LVM2_PV_Info::is_lvm2_pv_supported() )
|
2011-11-28 05:33:51 -07:00
|
|
|
{
|
2014-02-14 18:26:32 -07:00
|
|
|
fs .busy = FS::EXTERNAL ;
|
2012-01-12 06:15:26 -07:00
|
|
|
fs .read = FS::EXTERNAL ;
|
|
|
|
fs .create = FS::EXTERNAL ;
|
2012-01-15 12:41:28 -07:00
|
|
|
fs .grow = FS::EXTERNAL ;
|
|
|
|
fs .shrink = FS::EXTERNAL ;
|
|
|
|
fs .move = FS::GPARTED ;
|
|
|
|
fs .check = FS::EXTERNAL ;
|
2012-07-25 14:45:02 -06:00
|
|
|
fs .remove = FS::EXTERNAL ;
|
2012-09-10 09:41:58 -06:00
|
|
|
fs .online_read = FS::EXTERNAL ;
|
2013-11-15 09:27:12 -07:00
|
|
|
#ifdef ENABLE_ONLINE_RESIZE
|
|
|
|
if ( Utils::kernel_version_at_least( 3, 6, 0 ) )
|
|
|
|
{
|
|
|
|
fs .online_grow = fs .grow ;
|
|
|
|
fs .online_shrink = fs.shrink ;
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
2014-02-14 18:26:32 -07:00
|
|
|
bool lvm2_pv::is_busy( const Glib::ustring & path )
|
|
|
|
{
|
2015-06-05 13:54:37 -06:00
|
|
|
return LVM2_PV_Info::has_active_lvs( path );
|
2014-02-14 18:26:32 -07:00
|
|
|
}
|
|
|
|
|
2011-11-28 05:33:51 -07:00
|
|
|
void lvm2_pv::set_used_sectors( Partition & partition )
|
|
|
|
{
|
2015-06-05 13:54:37 -06:00
|
|
|
T = (Sector) LVM2_PV_Info::get_size_bytes( partition.get_path() );
|
|
|
|
N = (Sector) LVM2_PV_Info::get_free_bytes( partition.get_path() );
|
2012-03-08 08:37:31 -07:00
|
|
|
if ( T > -1 && N > -1 )
|
|
|
|
{
|
|
|
|
T = Utils::round( T / double(partition .sector_size) ) ;
|
|
|
|
N = Utils::round( N / double(partition .sector_size) ) ;
|
|
|
|
partition .set_sector_usage( T, N ) ;
|
|
|
|
}
|
2012-02-09 13:58:55 -07:00
|
|
|
|
2015-06-05 13:54:37 -06:00
|
|
|
std::vector<Glib::ustring> error_messages = LVM2_PV_Info::get_error_messages( partition.get_path() );
|
2015-12-31 09:32:08 -07:00
|
|
|
partition.append_messages( error_messages );
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operationdetail )
|
|
|
|
{
|
Time and check nearly all file system action commands (#754684)
There has been an undocumented rule that external commands displayed in
the operation details, as part of file system manipulations, only get a
time and check mark displayed when multiple commands are needed, and not
otherwise. (GParted checks whether all commands are successful or not
regardless of whether a check mark is displayed in the operation details
or not).
EXCEPTION 1: btrfs resize
Since the following commit [1] from 2013-02-22, GParted stopped
displaying the timing for the btrfs resize command in the operation
details. It being part of a multi-command sequence to perform the step.
This is because FileSystem::execute_command() since the commit can only
check the exit status for zero / non-zero while timing and checking the
command status but btrfs resize needs to consider some non-zero statuses
as successful.
[1] 52a2a9b00a32996921ace055e71d0e09fb33c5fe
Reduce threading (#685740)
EXCEPTION 2: ext2/3/4 move and copy using e2image
When use of e2image was added [2] the single command steps were timed
and check.
[2] 86111fe12a26d23d9fc2a9e2d19281290ecaf985
Use e2image to move/copy ext[234] file systems (#721516)
EXCEPTION 3: fat16/32 write label and UUID
Uses Utils::execute_command() rather than FileSystem::execute_command()
so can be separately changed. See the following commit for resolution
of the final commands not yet timed and check mark displayed.
CHANGE:
Lets make a simpler rule of always displaying the time and a check mark
for all external commands displayed in the operation details. However
this makes several of the other single command actions need special exit
status handling because zero success, non-zero failure is not correct
for every case. Specifically affects resizing of reiserfs and check
repair of ext2/3/4, fat16/32, jfs and reiserfs.
After this change all external commands run as file system actions must
follow one of these two patterns of using the EXEC_CHECK_STATUS flag or
separately calling FileSystem::set_status() to register success or
failure of the command:
exit_status = execute_command(cmd, od, EXEC_CHECK_STATUS...);
or:
exit_status = execute_command(cmd, od, ...);
bool success = (exit_status == 0 || exit_status == OTHER_SUCCESS_VALUE...);
set_status(od, success );
Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
functions
2015-09-05 02:31:16 -06:00
|
|
|
return ! execute_command( "lvm pvcreate -M 2 " + new_partition.get_path(), operationdetail, EXEC_CHECK_STATUS );
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
|
|
|
|
{
|
2012-01-15 12:41:28 -07:00
|
|
|
Glib::ustring size = "" ;
|
|
|
|
if ( ! fill_partition )
|
|
|
|
size = " --setphysicalvolumesize " +
|
|
|
|
Utils::num_to_str( floor( Utils::sector_to_unit(
|
|
|
|
partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K " ;
|
Time and check nearly all file system action commands (#754684)
There has been an undocumented rule that external commands displayed in
the operation details, as part of file system manipulations, only get a
time and check mark displayed when multiple commands are needed, and not
otherwise. (GParted checks whether all commands are successful or not
regardless of whether a check mark is displayed in the operation details
or not).
EXCEPTION 1: btrfs resize
Since the following commit [1] from 2013-02-22, GParted stopped
displaying the timing for the btrfs resize command in the operation
details. It being part of a multi-command sequence to perform the step.
This is because FileSystem::execute_command() since the commit can only
check the exit status for zero / non-zero while timing and checking the
command status but btrfs resize needs to consider some non-zero statuses
as successful.
[1] 52a2a9b00a32996921ace055e71d0e09fb33c5fe
Reduce threading (#685740)
EXCEPTION 2: ext2/3/4 move and copy using e2image
When use of e2image was added [2] the single command steps were timed
and check.
[2] 86111fe12a26d23d9fc2a9e2d19281290ecaf985
Use e2image to move/copy ext[234] file systems (#721516)
EXCEPTION 3: fat16/32 write label and UUID
Uses Utils::execute_command() rather than FileSystem::execute_command()
so can be separately changed. See the following commit for resolution
of the final commands not yet timed and check mark displayed.
CHANGE:
Lets make a simpler rule of always displaying the time and a check mark
for all external commands displayed in the operation details. However
this makes several of the other single command actions need special exit
status handling because zero success, non-zero failure is not correct
for every case. Specifically affects resizing of reiserfs and check
repair of ext2/3/4, fat16/32, jfs and reiserfs.
After this change all external commands run as file system actions must
follow one of these two patterns of using the EXEC_CHECK_STATUS flag or
separately calling FileSystem::set_status() to register success or
failure of the command:
exit_status = execute_command(cmd, od, EXEC_CHECK_STATUS...);
or:
exit_status = execute_command(cmd, od, ...);
bool success = (exit_status == 0 || exit_status == OTHER_SUCCESS_VALUE...);
set_status(od, success );
Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
functions
2015-09-05 02:31:16 -06:00
|
|
|
return ! execute_command( "lvm pvresize -v " + size + partition_new.get_path(),
|
|
|
|
operationdetail, EXEC_CHECK_STATUS );
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
Time and check nearly all file system action commands (#754684)
There has been an undocumented rule that external commands displayed in
the operation details, as part of file system manipulations, only get a
time and check mark displayed when multiple commands are needed, and not
otherwise. (GParted checks whether all commands are successful or not
regardless of whether a check mark is displayed in the operation details
or not).
EXCEPTION 1: btrfs resize
Since the following commit [1] from 2013-02-22, GParted stopped
displaying the timing for the btrfs resize command in the operation
details. It being part of a multi-command sequence to perform the step.
This is because FileSystem::execute_command() since the commit can only
check the exit status for zero / non-zero while timing and checking the
command status but btrfs resize needs to consider some non-zero statuses
as successful.
[1] 52a2a9b00a32996921ace055e71d0e09fb33c5fe
Reduce threading (#685740)
EXCEPTION 2: ext2/3/4 move and copy using e2image
When use of e2image was added [2] the single command steps were timed
and check.
[2] 86111fe12a26d23d9fc2a9e2d19281290ecaf985
Use e2image to move/copy ext[234] file systems (#721516)
EXCEPTION 3: fat16/32 write label and UUID
Uses Utils::execute_command() rather than FileSystem::execute_command()
so can be separately changed. See the following commit for resolution
of the final commands not yet timed and check mark displayed.
CHANGE:
Lets make a simpler rule of always displaying the time and a check mark
for all external commands displayed in the operation details. However
this makes several of the other single command actions need special exit
status handling because zero success, non-zero failure is not correct
for every case. Specifically affects resizing of reiserfs and check
repair of ext2/3/4, fat16/32, jfs and reiserfs.
After this change all external commands run as file system actions must
follow one of these two patterns of using the EXEC_CHECK_STATUS flag or
separately calling FileSystem::set_status() to register success or
failure of the command:
exit_status = execute_command(cmd, od, EXEC_CHECK_STATUS...);
or:
exit_status = execute_command(cmd, od, ...);
bool success = (exit_status == 0 || exit_status == OTHER_SUCCESS_VALUE...);
set_status(od, success );
Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
functions
2015-09-05 02:31:16 -06:00
|
|
|
return ! execute_command( "lvm pvck -v " + partition.get_path(), operationdetail, EXEC_CHECK_STATUS );
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
2012-07-25 14:05:33 -06:00
|
|
|
bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
2015-06-05 13:54:37 -06:00
|
|
|
Glib::ustring vgname = LVM2_PV_Info::get_vg_name( partition.get_path() );
|
2012-07-25 14:45:02 -06:00
|
|
|
Glib::ustring cmd ;
|
|
|
|
if ( vgname .empty() )
|
|
|
|
cmd = "lvm pvremove " + partition .get_path() ;
|
|
|
|
else
|
|
|
|
//Must force the removal of a PV which is a member of a VG
|
2013-02-21 17:57:33 -07:00
|
|
|
cmd = "lvm pvremove --force --force --yes " + partition .get_path() ;
|
Time and check nearly all file system action commands (#754684)
There has been an undocumented rule that external commands displayed in
the operation details, as part of file system manipulations, only get a
time and check mark displayed when multiple commands are needed, and not
otherwise. (GParted checks whether all commands are successful or not
regardless of whether a check mark is displayed in the operation details
or not).
EXCEPTION 1: btrfs resize
Since the following commit [1] from 2013-02-22, GParted stopped
displaying the timing for the btrfs resize command in the operation
details. It being part of a multi-command sequence to perform the step.
This is because FileSystem::execute_command() since the commit can only
check the exit status for zero / non-zero while timing and checking the
command status but btrfs resize needs to consider some non-zero statuses
as successful.
[1] 52a2a9b00a32996921ace055e71d0e09fb33c5fe
Reduce threading (#685740)
EXCEPTION 2: ext2/3/4 move and copy using e2image
When use of e2image was added [2] the single command steps were timed
and check.
[2] 86111fe12a26d23d9fc2a9e2d19281290ecaf985
Use e2image to move/copy ext[234] file systems (#721516)
EXCEPTION 3: fat16/32 write label and UUID
Uses Utils::execute_command() rather than FileSystem::execute_command()
so can be separately changed. See the following commit for resolution
of the final commands not yet timed and check mark displayed.
CHANGE:
Lets make a simpler rule of always displaying the time and a check mark
for all external commands displayed in the operation details. However
this makes several of the other single command actions need special exit
status handling because zero success, non-zero failure is not correct
for every case. Specifically affects resizing of reiserfs and check
repair of ext2/3/4, fat16/32, jfs and reiserfs.
After this change all external commands run as file system actions must
follow one of these two patterns of using the EXEC_CHECK_STATUS flag or
separately calling FileSystem::set_status() to register success or
failure of the command:
exit_status = execute_command(cmd, od, EXEC_CHECK_STATUS...);
or:
exit_status = execute_command(cmd, od, ...);
bool success = (exit_status == 0 || exit_status == OTHER_SUCCESS_VALUE...);
set_status(od, success );
Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
functions
2015-09-05 02:31:16 -06:00
|
|
|
return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS );
|
2012-07-25 14:05:33 -06:00
|
|
|
}
|
|
|
|
|
2011-11-28 05:33:51 -07:00
|
|
|
} //GParted
|