gparted/include/LVM2_PV_Info.h

84 lines
2.6 KiB
C
Raw Normal View History

/* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
/* 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.
*/
#ifndef GPARTED_LVM2_PV_INFO_H
#define GPARTED_LVM2_PV_INFO_H
#include "BlockSpecial.h"
#include "Utils.h"
Create BlockSpecial class and use in LVM2_PV_Info (#767842) In some cases creating an LVM2 Physical Volume on top of a DMRaid array reports no usage information and this partition warning: Unable to read the contents of this file system! Because of this some operations may be unavailable. The cause might be a missing software package. The following list of software packages is required for lvm2 pv file system support: lvm2. For example on Ubuntu 14.04 LTS (with GParted built with --enable-libparted-dmraid) create an LVM2 PV in a DMRaid array partition. GParted uses this command: # lvm pvcreate -M 2 /dev/mapper/isw_bacdehijbd_MyArray0p2 But LVM reports the PV having a different name: # lvm pvs PV VG Fmt Attr PSize PFree /dev/disk/by-id/dm-name-isw_bacdehijbd_MyArray0p2 lvm2 a-- 1.00g 1.00g This alternate name is loaded into the LVM2_PV_Info module cache. Hence when GParted queries partition /dev/mapper/isw_bacdehijbd_MyArray0p2 it has no PV information against that name and reports unknown usage. However they are actually the same block special device; major 252, minor 2: # ls -l /dev/mapper/isw_bacdehijbd_MyArray0p2 brw-rw---- 1 root disk 252, 2 Jul 2 11:09 /dev/mapper/isw_bacdehijbd_MyArray0p2 # ls -l /dev/disk/by-id/dm-name-isw_bacdehijbd_MyArray0p2 lrwxrwxrwx 1 root root 10 Jul 2 11:09 /dev/disk/by-id/dm-name-isw_bacdehijbd_MyArray0p2 -> ../../dm-2 # ls -l /dev/dm-2 brw-rw---- 1 root disk 252, 2 Jul 2 11:09 /dev/dm-2 To determine if two names refer to the same block special device their major, minor numbers need to be compared, instead of string comparing their names. Implement class BlockSpecial which encapsulates the name and major, minor numbers for a block special device. Also performs comparison as needed. See bug 767842 comments 4 and 5 for further investigation and decision for choosing to implement a class. Replace name strings in the LVM2_PV_Info module with BlockSpecial objects performing correct block special device comparison. Bug 767842 - File system usage missing when tools report alternate block device names
2016-06-22 10:32:01 -06:00
#include <glibmm/ustring.h>
#include <vector>
namespace GParted
{
struct LVM2_PV
{
Create BlockSpecial class and use in LVM2_PV_Info (#767842) In some cases creating an LVM2 Physical Volume on top of a DMRaid array reports no usage information and this partition warning: Unable to read the contents of this file system! Because of this some operations may be unavailable. The cause might be a missing software package. The following list of software packages is required for lvm2 pv file system support: lvm2. For example on Ubuntu 14.04 LTS (with GParted built with --enable-libparted-dmraid) create an LVM2 PV in a DMRaid array partition. GParted uses this command: # lvm pvcreate -M 2 /dev/mapper/isw_bacdehijbd_MyArray0p2 But LVM reports the PV having a different name: # lvm pvs PV VG Fmt Attr PSize PFree /dev/disk/by-id/dm-name-isw_bacdehijbd_MyArray0p2 lvm2 a-- 1.00g 1.00g This alternate name is loaded into the LVM2_PV_Info module cache. Hence when GParted queries partition /dev/mapper/isw_bacdehijbd_MyArray0p2 it has no PV information against that name and reports unknown usage. However they are actually the same block special device; major 252, minor 2: # ls -l /dev/mapper/isw_bacdehijbd_MyArray0p2 brw-rw---- 1 root disk 252, 2 Jul 2 11:09 /dev/mapper/isw_bacdehijbd_MyArray0p2 # ls -l /dev/disk/by-id/dm-name-isw_bacdehijbd_MyArray0p2 lrwxrwxrwx 1 root root 10 Jul 2 11:09 /dev/disk/by-id/dm-name-isw_bacdehijbd_MyArray0p2 -> ../../dm-2 # ls -l /dev/dm-2 brw-rw---- 1 root disk 252, 2 Jul 2 11:09 /dev/dm-2 To determine if two names refer to the same block special device their major, minor numbers need to be compared, instead of string comparing their names. Implement class BlockSpecial which encapsulates the name and major, minor numbers for a block special device. Also performs comparison as needed. See bug 767842 comments 4 and 5 for further investigation and decision for choosing to implement a class. Replace name strings in the LVM2_PV_Info module with BlockSpecial objects performing correct block special device comparison. Bug 767842 - File system usage missing when tools report alternate block device names
2016-06-22 10:32:01 -06:00
BlockSpecial pv_name;
Byte_Value pv_size;
Byte_Value pv_free;
Glib::ustring vg_name;
};
struct LVM2_VG
{
Glib::ustring vg_name;
Glib::ustring vg_attr;
Glib::ustring lv_name;
Glib::ustring lv_attr;
};
class LVM2_PV_Info
{
public:
static bool is_lvm2_pv_supported();
static void clear_cache();
static Glib::ustring get_vg_name( const Glib::ustring & path );
static Byte_Value get_size_bytes( const Glib::ustring & path );
static Byte_Value get_free_bytes( const Glib::ustring & path );
static bool has_active_lvs( const Glib::ustring & path );
static bool is_vg_exported( const Glib::ustring & vgname );
static std::vector<Glib::ustring> get_vg_members( const Glib::ustring & vgname );
static std::vector<Glib::ustring> get_vg_lvs( const Glib::ustring & vgname );
static std::vector<Glib::ustring> get_error_messages( const Glib::ustring & path );
private:
static void initialize_if_required();
static void set_command_found();
static void load_lvm2_pv_info_cache();
static const LVM2_PV & get_pv_cache_entry_by_name( const Glib::ustring & pvname );
static const LVM2_VG & get_vg_cache_entry_by_name( const Glib::ustring & vgname );
static Byte_Value lvm2_pv_size_to_num(const Glib::ustring& str);
static bool bit_set( const Glib::ustring & attr, unsigned int bit ) ;
static bool lvm2_pv_info_cache_initialized ;
static bool lvm_found ;
static std::vector<LVM2_PV> lvm2_pv_cache;
static std::vector<LVM2_VG> lvm2_vg_cache;
static std::vector<Glib::ustring> error_messages ;
};
}//GParted
#endif /* GPARTED_LVM2_PV_INFO_H */