Populate member mount point with SWRaid array device (#756829)

Busy file systems are accessed via a mount point, LVM Physical Volumes
are activated via the Volume Group name and busy SWRaid members are
accessed via the array device, /dev entry.  Therefore choose to show the
array device in the mount point field for busy SWRaid members.

The kernel device name for an SWRaid array (without leading "/dev/") is
the same as used in /proc/mdstat and /proc/partitions.  Therefore the
array device (with leading "/dev/") displayed in GParted will match
between the mount point for busy SWRaid members and the array itself as
used in the device combo box.

    # cat /proc/mdstat
    Personalities : [raid1]
    md1 : active raid1 sda1[2] sdb1[3]
          524224 blocks super 1.0 [2/2] [UU]
    ...
    # cat /proc/partitions
    major minor  #blocks  name

       8        0   33554432 sda
       8        1     524288 sda1
    ...
       8       16   33554432 sdb
       8       17     524288 sdb1
    ...
       9        1     524224 md1
    ...

Bug 756829 - SWRaid member detection enhancements
This commit is contained in:
Mike Fleetwood 2015-10-22 12:37:57 +01:00 committed by Curtis Gedak
parent 7255c8af40
commit f6c2f00df7
3 changed files with 30 additions and 9 deletions

View file

@ -33,6 +33,7 @@ namespace GParted
struct SWRaid_Member
{
Glib::ustring member;
Glib::ustring array;
Glib::ustring uuid;
Glib::ustring label;
bool active;
@ -44,6 +45,7 @@ public:
static void load_cache();
static bool is_member( const Glib::ustring & member_path );
static bool is_member_active( const Glib::ustring & member_path );
static Glib::ustring get_array( const Glib::ustring & member_path );
static Glib::ustring get_uuid( const Glib::ustring & member_path );
static Glib::ustring get_label( const Glib::ustring & member_path );

View file

@ -1817,6 +1817,12 @@ void GParted_Core::set_mountpoints( std::vector<Partition> & partitions )
if ( ! vgname .empty() )
partitions[ t ] .add_mountpoint( vgname ) ;
}
else if ( partitions[t].filesystem == FS_LINUX_SWRAID )
{
Glib::ustring array_path = SWRaid_Info::get_array( partitions[t].get_path() );
if ( ! array_path.empty() )
partitions[t].add_mountpoint( array_path );
}
}
}

View file

@ -27,12 +27,13 @@ namespace GParted
// Data model:
// mdadm_found - Is the "mdadm" command available?
// swraid_info_cache - Vector of member information in Linux Software RAID arrays.
// Only active arrays have /dev entries.
// E.g.
// //member , uuid , label , active
// [{"/dev/sda1", "15224a42-c25b-bcd9-15db-60004e5fe53a", "chimney:1", true },
// {"/dev/sda2", "15224a42-c25b-bcd9-15db-60004e5fe53a", "chimney:1", true },
// {"/dev/sda6", "8dc7483c-d74e-e0a8-b6a8-dc3ca57e43f8", "" , false},
// {"/dev/sdb6", "8dc7483c-d74e-e0a8-b6a8-dc3ca57e43f8", "" , false}
// //member , array , uuid , label , active
// [{"/dev/sda1", "/dev/md1", "15224a42-c25b-bcd9-15db-60004e5fe53a", "chimney:1", true },
// {"/dev/sda2", "/dev/md1", "15224a42-c25b-bcd9-15db-60004e5fe53a", "chimney:1", true },
// {"/dev/sda6", "" , "8dc7483c-d74e-e0a8-b6a8-dc3ca57e43f8", "" , false},
// {"/dev/sdb6", "" , "8dc7483c-d74e-e0a8-b6a8-dc3ca57e43f8", "" , false}
// ]
// Initialise static data elements
@ -63,6 +64,14 @@ bool SWRaid_Info::is_member_active( const Glib::ustring & member_path )
return false; // No such member
}
// Return array /dev entry (e.g. "/dev/md1") containing the specified member, or "" if the
// array is not running or there is no such member.
Glib::ustring SWRaid_Info::get_array( const Glib::ustring & member_path )
{
const SWRaid_Member & memb = get_cache_entry_by_member( member_path );
return memb.array;
}
// Return array UUID for the specified member, or "" when failed to parse the UUID or
// there is no such member.
Glib::ustring SWRaid_Info::get_uuid( const Glib::ustring & member_path )
@ -159,6 +168,7 @@ void SWRaid_Info::load_swraid_info_cache()
{
SWRaid_Member memb;
memb.member = devices[j];
memb.array = "";
memb.uuid = uuid;
memb.label = label;
memb.active = false;
@ -174,7 +184,7 @@ void SWRaid_Info::load_swraid_info_cache()
}
}
// Set which SWRaid members are active.
// For active SWRaid members, set array and active flag.
std::string line;
std::ifstream input( "/proc/mdstat" );
if ( input )
@ -197,13 +207,16 @@ void SWRaid_Info::load_swraid_info_cache()
if ( index != Glib::ustring::npos )
{
// Field contains an "[" so got a short
// kernel device name of a member. Mark
// as active.
// kernel device name of a member. Set
// array and active flag.
Glib::ustring mpath = "/dev/" +
fields[i].substr( 0, index );
SWRaid_Member & memb = get_cache_entry_by_member( mpath );
if ( memb.member == mpath )
{
memb.array = "/dev/" + fields[0];
memb.active = true;
}
}
}
}
@ -221,7 +234,7 @@ SWRaid_Member & SWRaid_Info::get_cache_entry_by_member( const Glib::ustring & me
if ( member_path == swraid_info_cache[i].member )
return swraid_info_cache[i];
}
static SWRaid_Member memb = {"", "", "", false};
static SWRaid_Member memb = {"", "", "", "", false};
return memb;
}