2012-01-28 07:25:31 -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
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../include/LVM2_PV_Info.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
enum PV_ATTRIBUTE
|
|
|
|
{
|
|
|
|
PVATTR_PV_NAME = 0,
|
2012-02-09 07:30:29 -07:00
|
|
|
PVATTR_PV_FREE = 1,
|
|
|
|
PVATTR_VG_NAME = 2,
|
2012-02-12 06:41:41 -07:00
|
|
|
PVATTR_VG_BITS = 3,
|
|
|
|
PVATTR_LV_NAME = 4,
|
|
|
|
PVATTR_LV_BITS = 5
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
} ;
|
|
|
|
|
2012-01-28 07:25:31 -07:00
|
|
|
//Data model:
|
|
|
|
// lvm2_pv_info_cache_initialized
|
|
|
|
// - Has the cache been loaded let?
|
|
|
|
// lvm_found - Is the "lvm" command available?
|
|
|
|
// lvm2_pv_cache - String vector storing attributes of a PV.
|
2012-02-09 07:30:29 -07:00
|
|
|
// Attributes are: pv_name,pv_free,vg_name,
|
2012-02-12 06:41:41 -07:00
|
|
|
// vg_attr,lv_name,lv_attr. Pv_free is the
|
|
|
|
// number of free bytes, see vgs(8) and lvs(8)
|
|
|
|
// for details of vg_attr and lv_attr
|
|
|
|
// respectively.
|
2012-01-28 07:25:31 -07:00
|
|
|
// E.g.
|
2012-02-12 06:41:41 -07:00
|
|
|
// ["/dev/sda10,2147483648,,r-----,,",
|
|
|
|
// "/dev/sda11,2143289344,GParted-VG1,wz--n-,,",
|
|
|
|
// "/dev/sda12,1619001344,GParted-VG2,wz--n-,lvol0,-wi---",
|
|
|
|
// "/dev/sda12,1619001344,GParted-VG2,wz--n-,,",
|
|
|
|
// "/dev/sda13,830472192,GParted_VG3,wz--n-,lvol0,-wi-a-",
|
|
|
|
// "/dev/sda13,830472192,GParted_VG3,wz--n-,lvol1,-wi-a-",
|
|
|
|
// "/dev/sda13,830472192,GParted_VG3,wz--n-,,",
|
|
|
|
// "/dev/sda14,1828716544,GParted-VG4,wzx-n-,lvol0,-wi---",
|
|
|
|
// "/dev/sda14,1828716544,GParted-VG4,wzx-n-,,"]
|
2012-02-09 13:58:55 -07:00
|
|
|
// error_messages - String vector storing error messsages.
|
2012-02-09 07:30:29 -07:00
|
|
|
|
2012-01-28 07:25:31 -07:00
|
|
|
|
|
|
|
//Initialize static data elements
|
|
|
|
bool LVM2_PV_Info::lvm2_pv_info_cache_initialized = false ;
|
|
|
|
bool LVM2_PV_Info::lvm_found = false ;
|
|
|
|
std::vector<Glib::ustring> LVM2_PV_Info::lvm2_pv_cache ;
|
2012-02-09 13:58:55 -07:00
|
|
|
std::vector<Glib::ustring> LVM2_PV_Info::error_messages ;
|
2012-01-28 07:25:31 -07:00
|
|
|
|
|
|
|
LVM2_PV_Info::LVM2_PV_Info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LVM2_PV_Info::LVM2_PV_Info( bool do_refresh )
|
|
|
|
{
|
2011-12-11 16:17:52 -07:00
|
|
|
if ( do_refresh )
|
2012-01-28 07:25:31 -07:00
|
|
|
{
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
set_command_found() ;
|
2012-01-28 07:25:31 -07:00
|
|
|
load_lvm2_pv_info_cache() ;
|
2011-12-11 16:17:52 -07:00
|
|
|
lvm2_pv_info_cache_initialized = true ;
|
|
|
|
}
|
2012-01-28 07:25:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
LVM2_PV_Info::~LVM2_PV_Info()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LVM2_PV_Info::is_lvm2_pv_supported()
|
|
|
|
{
|
2011-12-11 16:17:52 -07:00
|
|
|
if ( ! lvm2_pv_info_cache_initialized )
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
set_command_found() ;
|
|
|
|
return ( lvm_found ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Glib::ustring LVM2_PV_Info::get_vg_name( const Glib::ustring & path )
|
|
|
|
{
|
2011-12-11 16:17:52 -07:00
|
|
|
initialize_if_required() ;
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
return get_pv_attr_by_path( path, PVATTR_VG_NAME ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//Return number of free bytes in the PV, or -1 for error.
|
|
|
|
Byte_Value LVM2_PV_Info::get_free_bytes( const Glib::ustring & path )
|
|
|
|
{
|
2011-12-11 16:17:52 -07:00
|
|
|
initialize_if_required() ;
|
2012-01-28 07:25:31 -07:00
|
|
|
Byte_Value free_bytes = -1 ;
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
Glib::ustring fb_str = get_pv_attr_by_path( path, PVATTR_PV_FREE ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
if ( fb_str != "" )
|
|
|
|
{
|
|
|
|
gchar * suffix ;
|
|
|
|
free_bytes = (Byte_Value) g_ascii_strtoll( fb_str .c_str(), & suffix, 10 ) ;
|
|
|
|
if ( free_bytes < 0 || ( free_bytes == 0 && suffix == fb_str ) )
|
|
|
|
//Negative number or conversion failed
|
|
|
|
free_bytes = -1 ;
|
|
|
|
}
|
|
|
|
return free_bytes ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Report if any LVs are active in the VG stored in the PV.
|
|
|
|
bool LVM2_PV_Info::has_active_lvs( const Glib::ustring & path )
|
|
|
|
{
|
2011-12-11 16:17:52 -07:00
|
|
|
initialize_if_required() ;
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
Glib::ustring vgname = get_pv_attr_by_path( path, PVATTR_VG_NAME ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
if ( vgname == "" )
|
|
|
|
//PV not yet included in any VG
|
|
|
|
return false ;
|
|
|
|
|
2012-02-09 07:30:29 -07:00
|
|
|
for ( unsigned int i = 0 ; i < lvm2_pv_cache .size() ; i ++ )
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
{
|
2012-02-09 07:30:29 -07:00
|
|
|
std::vector<Glib::ustring> pv_attrs ;
|
|
|
|
Utils::split( lvm2_pv_cache [i], pv_attrs, "," ) ;
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
if ( vgname == get_pv_attr_by_row( i, PVATTR_VG_NAME ) )
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
{
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
Glib::ustring lv_bits = get_pv_attr_by_row( i, PVATTR_LV_BITS ) ;
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
//5th "bit" is active status. E.g.
|
|
|
|
// "-wi---" inactive, "-wi-a-" active, ...
|
|
|
|
// Treat any non-hyphen character as active.
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
if ( lv_bits .length() >= 5 && lv_bits [4] != '-' )
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
//LV in VG is active
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false ;
|
2012-01-28 07:25:31 -07:00
|
|
|
}
|
|
|
|
|
2012-02-12 06:41:41 -07:00
|
|
|
//Report if the VG is exported.
|
|
|
|
bool LVM2_PV_Info::is_vg_exported( const Glib::ustring & vgname )
|
|
|
|
{
|
|
|
|
initialize_if_required() ;
|
|
|
|
|
|
|
|
for ( unsigned int i = 0 ; i < lvm2_pv_cache .size() ; i ++ )
|
|
|
|
{
|
|
|
|
std::vector<Glib::ustring> pv_attrs ;
|
|
|
|
Utils::split( lvm2_pv_cache [i], pv_attrs, "," ) ;
|
|
|
|
if ( vgname == get_pv_attr_by_row( i, PVATTR_VG_NAME ) )
|
|
|
|
{
|
|
|
|
Glib::ustring vg_bits = get_pv_attr_by_row( i, PVATTR_VG_BITS ) ;
|
|
|
|
//3rd "bit" is export status. E.g.
|
|
|
|
// "wz--n-" imported, "wzx-n-" exported.
|
|
|
|
// Treat any non-hyphen character as exported.
|
|
|
|
if ( vg_bits .length() >= 3 && vg_bits [2] != '-' )
|
|
|
|
//VG is exported
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
2012-02-09 13:58:55 -07:00
|
|
|
std::vector<Glib::ustring> LVM2_PV_Info::get_error_messages()
|
|
|
|
{
|
|
|
|
initialize_if_required() ;
|
|
|
|
return error_messages ;
|
|
|
|
}
|
|
|
|
|
2012-01-28 07:25:31 -07:00
|
|
|
//Private methods
|
|
|
|
|
2011-12-11 16:17:52 -07:00
|
|
|
void LVM2_PV_Info::initialize_if_required()
|
|
|
|
{
|
|
|
|
if ( ! lvm2_pv_info_cache_initialized )
|
|
|
|
{
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
set_command_found() ;
|
2011-12-11 16:17:52 -07:00
|
|
|
load_lvm2_pv_info_cache() ;
|
|
|
|
lvm2_pv_info_cache_initialized = true ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
void LVM2_PV_Info::set_command_found()
|
2012-01-28 07:25:31 -07:00
|
|
|
{
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
//Set status of command found
|
2012-01-28 07:25:31 -07:00
|
|
|
lvm_found = ( ! Glib::find_program_in_path( "lvm" ) .empty() ) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LVM2_PV_Info::load_lvm2_pv_info_cache()
|
|
|
|
{
|
|
|
|
Glib::ustring output, error ;
|
|
|
|
|
|
|
|
lvm2_pv_cache .clear() ;
|
2012-02-09 13:58:55 -07:00
|
|
|
error_messages .clear() ;
|
2012-01-28 07:25:31 -07:00
|
|
|
if ( lvm_found )
|
|
|
|
{
|
|
|
|
//The OS is expected to fully enable LVM, this scan does
|
|
|
|
// not do the full job. It is included incase anything
|
|
|
|
// is changed not using lvm commands.
|
|
|
|
Utils::execute_command( "lvm vgscan", output, error, true ) ;
|
Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes. However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.
To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.
# dmsetup info --columns --noheadings --separator , -o name
GParted_VG1-lvol_00
GParted--VG2-lvol--00
# lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
lvol_00,GParted_VG1,-wi-a-
lvol-00,GParted-VG2,-wi-a-
lvol-01,GParted-VG3,-wi---
.^.
(-) not active, (a) or any other character considered active. Reference
lvs(8).
Bug #160787 - lvm support
2012-02-02 06:22:46 -07:00
|
|
|
|
|
|
|
//Load LVM2 PV attribute cache. Output PV attributes in
|
|
|
|
// PV_ATTRIBUTE order
|
2012-02-12 06:41:41 -07:00
|
|
|
Glib::ustring cmd = "lvm pvs --config \"log{command_names=0}\" --nosuffix --noheadings --separator , --units b -o pv_name,pv_free,vg_name,vg_attr,lv_name,lv_attr" ;
|
2012-02-09 13:58:55 -07:00
|
|
|
if ( ! Utils::execute_command( cmd, output, error, true ) )
|
2012-01-28 07:25:31 -07:00
|
|
|
{
|
|
|
|
if ( output != "" )
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
{
|
|
|
|
Utils::tokenize( output, lvm2_pv_cache, "\n" ) ;
|
|
|
|
for ( unsigned int i = 0 ; i < lvm2_pv_cache .size() ; i ++ )
|
|
|
|
lvm2_pv_cache [i] = Utils::trim( lvm2_pv_cache [i] ) ;
|
|
|
|
}
|
2012-01-28 07:25:31 -07:00
|
|
|
}
|
2012-02-09 13:58:55 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error_messages .push_back( cmd ) ;
|
|
|
|
if ( ! output .empty() )
|
|
|
|
error_messages .push_back ( output ) ;
|
|
|
|
if ( ! error .empty() )
|
|
|
|
error_messages .push_back ( error ) ;
|
|
|
|
Glib::ustring temp ;
|
|
|
|
temp = _("An error occurred reading LVM2 configuration!") ;
|
|
|
|
temp += "\n" ;
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
temp += _("Some or all of the details might be missing or incorrect.") ;
|
2012-02-09 13:58:55 -07:00
|
|
|
temp += "\n" ;
|
|
|
|
temp += _("You should NOT modify any LVM2 PV partitions.") ;
|
|
|
|
temp += "\n" ;
|
|
|
|
error_messages .push_back( temp ) ;
|
|
|
|
}
|
2012-01-28 07:25:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-09 07:30:29 -07:00
|
|
|
//Return PV's nth attribute. Performs linear search of the cache and
|
|
|
|
// uses the first matching PV entry. Attributes are numbered 0 upward
|
|
|
|
// using PV_ATTRIBUTE enumeration.
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
Glib::ustring LVM2_PV_Info::get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry )
|
2012-01-28 07:25:31 -07:00
|
|
|
{
|
|
|
|
for ( unsigned int i = 0 ; i < lvm2_pv_cache .size() ; i ++ )
|
|
|
|
{
|
|
|
|
std::vector<Glib::ustring> pv_attrs ;
|
|
|
|
Utils::split( lvm2_pv_cache [i], pv_attrs, "," ) ;
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
if ( PVATTR_PV_NAME < pv_attrs .size() && path == pv_attrs [PVATTR_PV_NAME] )
|
2012-01-28 07:25:31 -07:00
|
|
|
{
|
|
|
|
if ( entry < pv_attrs .size() )
|
|
|
|
return pv_attrs [entry] ;
|
|
|
|
else
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "" ;
|
|
|
|
}
|
|
|
|
|
Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs. There aren't normally any embeded
spaces, but they can occur in certain degrated situations. For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:
# lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
PV,PFree,VG,LV,Attr
/dev/sda11,2143289344,GParted-VG1,,
unknown device,1619001344,GParted-VG1,lvol0,-wi---
unknown device,1619001344,GParted-VG1,,
This was loaded into the cache as:
["/dev/sda11,2143289344,GParted-VG1,,",
"unknown",
"device,1619001344,GParted-VG1,lvol0,-wi---",
"unknown",
"device,1619001344,GParted-VG1,,"]
The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.
Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces. Don't crash on lines without without enough comma
separated fields.
Bug #160787 - lvm support
2012-02-11 07:09:22 -07:00
|
|
|
//Return PV's nth attribute from specified cache row. Row is numbered
|
|
|
|
// 0 upwards and attributes are numbers numbered 0 upwards using
|
|
|
|
// PV_ATTRIBUTE enumeration.
|
|
|
|
Glib::ustring LVM2_PV_Info::get_pv_attr_by_row( unsigned int row, unsigned int entry )
|
|
|
|
{
|
|
|
|
if ( row >= lvm2_pv_cache .size() )
|
|
|
|
return "" ;
|
|
|
|
std::vector<Glib::ustring> pv_attrs ;
|
|
|
|
Utils::split( lvm2_pv_cache [row], pv_attrs, "," ) ;
|
|
|
|
if ( entry < pv_attrs .size() )
|
|
|
|
return pv_attrs [entry] ;
|
|
|
|
return "" ;
|
|
|
|
}
|
|
|
|
|
2012-01-28 07:25:31 -07:00
|
|
|
}//GParted
|