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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* LVM2_PV_Info
|
|
|
|
*
|
|
|
|
* A persistent cache of information about LVM2 PVs that helps to
|
|
|
|
* minimize the number of executions of lvm commands used to query
|
|
|
|
* their attributes.
|
|
|
|
*/
|
|
|
|
|
2013-05-27 05:20:16 -06:00
|
|
|
#ifndef GPARTED_LVM2_PV_INFO_H
|
|
|
|
#define GPARTED_LVM2_PV_INFO_H
|
2012-01-28 07:25:31 -07:00
|
|
|
|
|
|
|
#include "../include/Utils.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
class LVM2_PV_Info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LVM2_PV_Info() ;
|
|
|
|
LVM2_PV_Info( bool do_refresh ) ;
|
|
|
|
~LVM2_PV_Info() ;
|
|
|
|
bool is_lvm2_pv_supported() ;
|
|
|
|
Glib::ustring get_vg_name( const Glib::ustring & path ) ;
|
2012-03-08 08:37:31 -07:00
|
|
|
Byte_Value get_size_bytes( const Glib::ustring & path ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
Byte_Value get_free_bytes( const Glib::ustring & path ) ;
|
|
|
|
bool has_active_lvs( const Glib::ustring & path ) ;
|
2012-02-12 06:41:41 -07:00
|
|
|
bool is_vg_exported( const Glib::ustring & vgname ) ;
|
2012-07-01 02:57:52 -06:00
|
|
|
std::vector<Glib::ustring> get_vg_members( const Glib::ustring & vgname ) ;
|
2012-02-12 07:44:50 -07:00
|
|
|
std::vector<Glib::ustring> get_error_messages( const Glib::ustring & path ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
private:
|
2011-12-11 16:17:52 -07:00
|
|
|
void initialize_if_required() ;
|
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 set_command_found() ;
|
2012-01-28 07:25:31 -07:00
|
|
|
void load_lvm2_pv_info_cache() ;
|
2012-07-07 05:14:25 -06:00
|
|
|
Glib::ustring get_pv_attr_by_path( const Glib::ustring & path, unsigned int entry ) const ;
|
|
|
|
Glib::ustring get_pv_attr_by_row( unsigned int row, unsigned int entry ) const ;
|
Correctly show multiple "unknown device" LVM2 VG members (#670171)
If an LVM2 Volume Group has two or more missing Physical Volumes, the VG
is displayed as only having one "unknown device" because
get_vg_members() only adds unique names to the list of members.
# lvm pvcreate /dev/sda11 /dev/sda12 /dev/sda13
# lvm vgcreate Test-VG1 /dev/sda11 /dev/sda12 /dev/sda13
# wipefs -a /dev/sda12
# wipefs -a /dev/sda13
View partition information in GParted
The simplest fix would be to include the PV's UUID in the cache of LVM2
information and add PV names based on unique UUIDs being a member of the
relevant VG. Unfortunately "lvm pvs" seems to have a bug when
displaying Logical Volume attributes, and there are two or more missing
PVs, which causes one of the PVs to be displayed multiple times, rather
than displaying each PV once.
Without LV attributes, every PV is listed:
# lvm pvs --nosuffix --separator , --units b -o pv_name,pv_uuid,vg_name,vg_attr 2> /dev/null
PV,PV UUID,VG,Attr
/dev/sda11,pJ3R51-AOPP-rKlr-CKCT-nfPS-G5FP-B5Vyjm,Test-VG1,wz-pn-
unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-
unknown device,1ESORF-7wlR-0tnO-fy2z-nOL1-MrnJ-2O5yjK,Test-VG1,wz-pn-
With LV attributes, one missing PV is repeated:
# lvm pvs --nosuffix --separator , --units b -o pv_name,pv_uuid,vg_name,vg_attr,lv_name,lv_attr 2> /dev/null
PV,PV UUID,VG,Attr,LV,Attr
/dev/sda11,pJ3R51-AOPP-rKlr-CKCT-nfPS-G5FP-B5Vyjm,Test-VG1,wz-pn-,,
unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-,,
unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-,,
Also "lvm vgs" and "lvm lvs" don't display anything when including both
VG and LV attributes.
Instead query the LVM2 information in two separate commands, one
querying PV attributes and one querying VG and LV attributes, saving the
results in lvm_pv_cache and lvm_vg_cache respectively.
Bug #670171 - Add LVM PV read-write support
2012-08-18 02:12:47 -06:00
|
|
|
Glib::ustring get_vg_attr_by_name( const Glib::ustring & vgname, unsigned int entry ) const ;
|
|
|
|
Glib::ustring get_vg_attr_by_row( unsigned int row, unsigned int entry ) const ;
|
2012-08-18 03:35:21 -06:00
|
|
|
static Glib::ustring get_attr_by_name( const std::vector<Glib::ustring> cache,
|
|
|
|
const Glib::ustring name, unsigned int entry ) ;
|
|
|
|
static Glib::ustring get_attr_by_row( const std::vector<Glib::ustring> cache,
|
|
|
|
unsigned int row, unsigned int entry ) ;
|
2012-07-07 05:14:25 -06:00
|
|
|
static Byte_Value lvm2_pv_attr_to_num( const Glib::ustring str ) ;
|
2012-07-09 07:19:14 -06:00
|
|
|
static bool bit_set( const Glib::ustring & attr, unsigned int bit ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
static bool lvm2_pv_info_cache_initialized ;
|
|
|
|
static bool lvm_found ;
|
|
|
|
static std::vector<Glib::ustring> lvm2_pv_cache ;
|
Correctly show multiple "unknown device" LVM2 VG members (#670171)
If an LVM2 Volume Group has two or more missing Physical Volumes, the VG
is displayed as only having one "unknown device" because
get_vg_members() only adds unique names to the list of members.
# lvm pvcreate /dev/sda11 /dev/sda12 /dev/sda13
# lvm vgcreate Test-VG1 /dev/sda11 /dev/sda12 /dev/sda13
# wipefs -a /dev/sda12
# wipefs -a /dev/sda13
View partition information in GParted
The simplest fix would be to include the PV's UUID in the cache of LVM2
information and add PV names based on unique UUIDs being a member of the
relevant VG. Unfortunately "lvm pvs" seems to have a bug when
displaying Logical Volume attributes, and there are two or more missing
PVs, which causes one of the PVs to be displayed multiple times, rather
than displaying each PV once.
Without LV attributes, every PV is listed:
# lvm pvs --nosuffix --separator , --units b -o pv_name,pv_uuid,vg_name,vg_attr 2> /dev/null
PV,PV UUID,VG,Attr
/dev/sda11,pJ3R51-AOPP-rKlr-CKCT-nfPS-G5FP-B5Vyjm,Test-VG1,wz-pn-
unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-
unknown device,1ESORF-7wlR-0tnO-fy2z-nOL1-MrnJ-2O5yjK,Test-VG1,wz-pn-
With LV attributes, one missing PV is repeated:
# lvm pvs --nosuffix --separator , --units b -o pv_name,pv_uuid,vg_name,vg_attr,lv_name,lv_attr 2> /dev/null
PV,PV UUID,VG,Attr,LV,Attr
/dev/sda11,pJ3R51-AOPP-rKlr-CKCT-nfPS-G5FP-B5Vyjm,Test-VG1,wz-pn-,,
unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-,,
unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-,,
Also "lvm vgs" and "lvm lvs" don't display anything when including both
VG and LV attributes.
Instead query the LVM2 information in two separate commands, one
querying PV attributes and one querying VG and LV attributes, saving the
results in lvm_pv_cache and lvm_vg_cache respectively.
Bug #670171 - Add LVM PV read-write support
2012-08-18 02:12:47 -06:00
|
|
|
static std::vector<Glib::ustring> lvm2_vg_cache ;
|
2012-02-09 13:58:55 -07:00
|
|
|
static std::vector<Glib::ustring> error_messages ;
|
2012-01-28 07:25:31 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}//GParted
|
|
|
|
|
2013-05-27 05:20:16 -06:00
|
|
|
#endif /* GPARTED_LVM2_PV_INFO_H */
|