"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/SWRaid_Info.cc" between
gparted-1.0.0.tar.gz and gparted-1.1.0.tar.gz

About: GParted is a graphical partition editor for creating, reorganizing, and deleting disk partitions (using GNU libparted).

SWRaid_Info.cc  (gparted-1.0.0):SWRaid_Info.cc  (gparted-1.1.0)
skipping to change at line 38 skipping to change at line 38
// Data model: // Data model:
// cache_initialised - Has the cache been loaded? // cache_initialised - Has the cache been loaded?
// mdadm_found - Is the "mdadm" command available? // mdadm_found - Is the "mdadm" command available?
// swraid_info_cache - Vector of member information in Linux Software RAID array s. // swraid_info_cache - Vector of member information in Linux Software RAID array s.
// Only active arrays have /dev entries. // Only active arrays have /dev entries.
// Notes: // Notes:
// * BS(member) is short hand for constructor BlockSpecial (member). // * BS(member) is short hand for constructor BlockSpecial (member).
// * Array is only displayed as the mount point to the use r and // * Array is only displayed as the mount point to the use r and
// never compared so not constructing BlockSpecial objec t for it. // never compared so not constructing BlockSpecial objec t for it.
// E.g. // E.g.
// //member , array , uuid // //member , fstype , array , uuid
, label , active , label , active
// [{BS("/dev/sda1)", "/dev/md1", "15224a42-c25b-bcd9-15db-6 // [{BS("/dev/sda1"), FS_LINUX_SWRAID, "/dev/md1" , "15224a
0004e5fe53a", "chimney:1", true }, 42-c25b-bcd9-15db-60004e5fe53a", "chimney:1", true },
// {BS("/dev/sda2"), "/dev/md1", "15224a42-c25b-bcd9-15db-6 // {BS("/dev/sdb1"), FS_LINUX_SWRAID, "/dev/md1" , "15224a
0004e5fe53a", "chimney:1", true }, 42-c25b-bcd9-15db-60004e5fe53a", "chimney:1", true },
// {BS("/dev/sda6"), "" , "8dc7483c-d74e-e0a8-b6a8-d // {BS("/dev/sda2"), FS_LINUX_SWRAID, "" , "8dc748
c3ca57e43f8", "" , false}, 3c-d74e-e0a8-b6a8-dc3ca57e43f8", "" , false},
// {BS("/dev/sdb6"), "" , "8dc7483c-d74e-e0a8-b6a8-d // {BS("/dev/sdb2"), FS_LINUX_SWRAID, "" , "8dc748
c3ca57e43f8", "" , false} 3c-d74e-e0a8-b6a8-dc3ca57e43f8", "" , false},
// {BS("/dev/sdc") , FS_ATARAID , "/dev/md126", "43060c
4c-b0c0-c371-60bf-d43082e97d3c", "" , true },
// {BS("/dev/sdd") , FS_ATARAID , "/dev/md126", "43060c
4c-b0c0-c371-60bf-d43082e97d3c", "" , true }
// ] // ]
// Initialise static data elements // Initialise static data elements
bool SWRaid_Info::cache_initialised = false; bool SWRaid_Info::cache_initialised = false;
bool SWRaid_Info::mdadm_found = false; bool SWRaid_Info::mdadm_found = false;
std::vector<SWRaid_Member> SWRaid_Info::swraid_info_cache; std::vector<SWRaid_Member> SWRaid_Info::swraid_info_cache;
void SWRaid_Info::load_cache() void SWRaid_Info::load_cache()
{ {
set_command_found(); set_command_found();
skipping to change at line 75 skipping to change at line 77
} }
// Return member/array active status, or false when there is no such member. // Return member/array active status, or false when there is no such member.
bool SWRaid_Info::is_member_active( const Glib::ustring & member_path ) bool SWRaid_Info::is_member_active( const Glib::ustring & member_path )
{ {
initialise_if_required(); initialise_if_required();
const SWRaid_Member & memb = get_cache_entry_by_member( member_path ); const SWRaid_Member & memb = get_cache_entry_by_member( member_path );
return memb.active; return memb.active;
} }
// Return "file system" type of the member, or FS_UNKNOWN if there is no such me
mber.
FSType SWRaid_Info::get_fstype(const Glib::ustring& member_path)
{
initialise_if_required();
const SWRaid_Member& memb = get_cache_entry_by_member(member_path);
return memb.fstype;
}
// Return array /dev entry (e.g. "/dev/md1") containing the specified member, or "" if the // 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. // array is not running or there is no such member.
Glib::ustring SWRaid_Info::get_array( const Glib::ustring & member_path ) Glib::ustring SWRaid_Info::get_array( const Glib::ustring & member_path )
{ {
initialise_if_required(); initialise_if_required();
const SWRaid_Member & memb = get_cache_entry_by_member( member_path ); const SWRaid_Member & memb = get_cache_entry_by_member( member_path );
return memb.array; return memb.array;
} }
// Return array UUID for the specified member, or "" when failed to parse the UU ID or // Return array UUID for the specified member, or "" when failed to parse the UU ID or
skipping to change at line 132 skipping to change at line 142
{ {
Glib::ustring output, error; Glib::ustring output, error;
swraid_info_cache.clear(); swraid_info_cache.clear();
// Load SWRaid members into the cache. Load member device, array UUID an d array // Load SWRaid members into the cache. Load member device, array UUID an d array
// label (array name in mdadm terminology). // label (array name in mdadm terminology).
if ( mdadm_found && if ( mdadm_found &&
! Utils::execute_command( "mdadm --examine --scan --verbose", output , error, true ) ) ! Utils::execute_command( "mdadm --examine --scan --verbose", output , error, true ) )
{ {
// Extract information from Linux Software RAID arrays only, excl // Extract information about all array members. Example output:
uding
// IMSM and DDF arrays. Example output:
// ARRAY metadata=imsm UUID=9a5e3477:e1e668ea:12066a1b:d37086 08 // ARRAY metadata=imsm UUID=9a5e3477:e1e668ea:12066a1b:d37086 08
// devices=/dev/sdd,/dev/sdc,/dev/md/imsm0 // devices=/dev/sdd,/dev/sdc,/dev/md/imsm0
// ARRAY /dev/md/MyRaid container=9a5e3477:e1e668ea:12066a1b: d3708608 member=0 UUID=47518beb:cc6ef9e7:c80cd1c7:5f6ecb28 // ARRAY /dev/md/MyRaid container=9a5e3477:e1e668ea:12066a1b: d3708608 member=0 UUID=47518beb:cc6ef9e7:c80cd1c7:5f6ecb28
// //
// ARRAY /dev/md/1 level=raid1 metadata=1.0 num-devices=2 UU ID=15224a42:c25bbcd9:15db6000:4e5fe53a name=chimney:1 // ARRAY /dev/md/1 level=raid1 metadata=1.0 num-devices=2 UU ID=15224a42:c25bbcd9:15db6000:4e5fe53a name=chimney:1
// devices=/dev/sda1,/dev/sdb1 // devices=/dev/sda1,/dev/sdb1
// ARRAY /dev/md5 level=raid1 num-devices=2 UUID=8dc7483c:d74 ee0a8:b6a8dc3c:a57e43f8 // ARRAY /dev/md5 level=raid1 num-devices=2 UUID=8dc7483c:d74 ee0a8:b6a8dc3c:a57e43f8
// devices=/dev/sda6,/dev/sdb6 // devices=/dev/sda6,/dev/sdb6
std::vector<Glib::ustring> lines; std::vector<Glib::ustring> lines;
Utils::split( output, lines, "\n" ); Utils::split( output, lines, "\n" );
enum MDADM_LINE_TYPE enum MDADM_LINE_TYPE
{ {
MDADM_LT_OTHER = 0, MDADM_LT_OTHER = 0,
MDADM_LT_ARRAY = 1, MDADM_LT_ARRAY = 1,
MDADM_LT_DEVICES = 2 MDADM_LT_DEVICES = 2
}; };
MDADM_LINE_TYPE mdadm_line_type = MDADM_LT_OTHER; MDADM_LINE_TYPE mdadm_line_type = MDADM_LT_OTHER;
FSType fstype = FS_UNKNOWN;
Glib::ustring uuid; Glib::ustring uuid;
Glib::ustring label; Glib::ustring label;
for ( unsigned int i = 0 ; i < lines.size() ; i ++ ) for ( unsigned int i = 0 ; i < lines.size() ; i ++ )
{ {
Glib::ustring metadata_type;
if ( lines[i].substr( 0, 6 ) == "ARRAY " ) if ( lines[i].substr( 0, 6 ) == "ARRAY " )
{ {
mdadm_line_type = MDADM_LT_ARRAY; mdadm_line_type = MDADM_LT_ARRAY;
Glib::ustring metadata_type = Utils::regexp_label
( lines[i], if (lines[i].find("container=") != Glib::ustring:
:npos)
"metadata=([[:graph:]]+)" ); {
// Mdadm with these flags doesn't seem to print t // Skip mdadm array containers which don'
he t have
// metadata tag for 0.90 version arrays. Accept // any members.
no tag mdadm_line_type = MDADM_LT_OTHER;
// (or empty version) as well as "0.90". continue;
if ( metadata_type != "" && metadata_type != " }
0.90" &&
metadata_type != "1.0" && metadata_type != " fstype = FS_UNKNOWN;
1.1" && Glib::ustring metadata = Utils::regexp_label(line
metadata_type != "1.2" s[i],
) "met
adata=([[:graph:]]+)");
// Mdadm doesn't print a metadata tag for 0.90 ve
rsion
// arrays, so accept empty.
if (metadata == "" || metadata == "1.0" ||
metadata == "1.1" || metadata == "1.2" )
{
fstype = FS_LINUX_SWRAID;
}
else if (metadata == "imsm" || metadata == "ddf")
{
fstype = FS_ATARAID;
}
else
{ {
// Skip mdadm reported non-Linux Software RAID arrays // Skip unexpected mdadm array line.
mdadm_line_type = MDADM_LT_OTHER; mdadm_line_type = MDADM_LT_OTHER;
continue; continue;
} }
uuid = mdadm_to_canonical_uuid( uuid = mdadm_to_canonical_uuid(
Utils::regexp_label( lines[i], "U UID=([[:graph:]]+)" ) ); Utils::regexp_label( lines[i], "U UID=([[:graph:]]+)" ) );
label = Utils::regexp_label( lines[i], "name=(.*) $" ); label = Utils::regexp_label( lines[i], "name=(.*) $" );
} }
else if ( mdadm_line_type == MDADM_LT_ARRAY && else if ( mdadm_line_type == MDADM_LT_ARRAY &&
lines[i].find( "devices=" ) != Glib::ustring::n pos ) lines[i].find( "devices=" ) != Glib::ustring::n pos )
{ {
mdadm_line_type = MDADM_LT_DEVICES; mdadm_line_type = MDADM_LT_DEVICES;
Glib::ustring devices_str = Utils::regexp_label( lines[i], Glib::ustring devices_str = Utils::regexp_label( lines[i],
"devices=([[:graph:]]+)" ); "devices=([[:graph:]]+)" );
std::vector<Glib::ustring> devices; std::vector<Glib::ustring> devices;
Utils::split( devices_str, devices, "," ); Utils::split( devices_str, devices, "," );
for ( unsigned int j = 0 ; j < devices.size() ; j ++ ) for ( unsigned int j = 0 ; j < devices.size() ; j ++ )
{ {
SWRaid_Member memb; SWRaid_Member memb;
memb.member = BlockSpecial( devices[j] ); memb.member = BlockSpecial( devices[j] );
memb.fstype = fstype;
memb.array = ""; memb.array = "";
memb.uuid = uuid; memb.uuid = uuid;
memb.label = label; memb.label = label;
memb.active = false; memb.active = false;
swraid_info_cache.push_back( memb ); swraid_info_cache.push_back( memb );
} }
uuid.clear(); uuid.clear();
label.clear(); label.clear();
} }
else else
{ {
mdadm_line_type = MDADM_LT_OTHER; mdadm_line_type = MDADM_LT_OTHER;
} }
} }
} }
// For active SWRaid members, set array and active flag. // For active array members, set array and active flag.
std::string line; std::string line;
std::ifstream input( "/proc/mdstat" ); std::ifstream input( "/proc/mdstat" );
if ( input ) if ( input )
{ {
// Read /proc/mdstat extracting information for Linux Software RA // Read /proc/mdstat extracting information about all active arra
ID arrays y
// only, excluding external IMSM and DDF arrays. Example /proc/m // members. Example /proc/mdstat:
dstat:
// Personalities : [raid1] // Personalities : [raid1]
// md127 : inactive sdd[1](S) sdc[0](S) // md127 : inactive sdd[1](S) sdc[0](S)
// 6306 blocks super external:imsm // 6306 blocks super external:imsm
// //
// md126 : active raid1 sdc[1] sdd[0] // md126 : active raid1 sdc[1] sdd[0]
// 8383831 blocks super external:/md127/0 [2/2] [UU] // 8383831 blocks super external:/md127/0 [2/2] [UU]
// //
// md1 : active raid1 sdb1[3] sda1[2] // md1 : active raid1 sdb1[3] sda1[2]
// 524224 blocks super 1.0 [2/2] [UU] // 524224 blocks super 1.0 [2/2] [UU]
// //
skipping to change at line 233 skipping to change at line 260
// 524224 blocks [2/2] [UU] // 524224 blocks [2/2] [UU]
// //
// unused devices: <none> // unused devices: <none>
enum MDSTAT_LINE_TYPE enum MDSTAT_LINE_TYPE
{ {
MDSTAT_LT_OTHER = 0, MDSTAT_LT_OTHER = 0,
MDSTAT_LT_ACTIVE = 1, MDSTAT_LT_ACTIVE = 1,
MDSTAT_LT_BLOCKS = 2 MDSTAT_LT_BLOCKS = 2
}; };
MDSTAT_LINE_TYPE mdstat_line_type = MDSTAT_LT_OTHER; MDSTAT_LINE_TYPE mdstat_line_type = MDSTAT_LT_OTHER;
FSType fstype = FS_UNKNOWN;
Glib::ustring array; Glib::ustring array;
std::vector<Glib::ustring> members; std::vector<Glib::ustring> members;
while ( getline( input, line ) ) while ( getline( input, line ) )
{ {
if ( line.find( " : active " ) != std::string::npos ) if ( line.find( " : active " ) != std::string::npos )
{ {
mdstat_line_type = MDSTAT_LT_ACTIVE; mdstat_line_type = MDSTAT_LT_ACTIVE;
// Found a line for an active array. Split into space // Found a line for an active array. Split into space
// separated fields. // separated fields.
std::vector<Glib::ustring> fields; std::vector<Glib::ustring> fields;
skipping to change at line 262 skipping to change at line 290
// kernel device name of a member . // kernel device name of a member .
members.push_back( "/dev/" + fiel ds[i].substr( 0, index ) ); members.push_back( "/dev/" + fiel ds[i].substr( 0, index ) );
} }
} }
} }
else if ( mdstat_line_type == MDSTAT_LT_ACTIVE && else if ( mdstat_line_type == MDSTAT_LT_ACTIVE &&
line.find( " blocks " ) != std::string::npos ) line.find( " blocks " ) != std::string::npos )
{ {
mdstat_line_type = MDSTAT_LT_BLOCKS; mdstat_line_type = MDSTAT_LT_BLOCKS;
// Found a blocks line for an array. // Found a blocks line for an array.
Glib::ustring super_type = Utils::regexp_label( l fstype = FS_UNKNOWN;
ine, "super ([[:graph:]]+)" ); Glib::ustring super = Utils::regexp_label(line, "
super ([[:graph:]]+)");
// Kernel doesn't seem to print the super block t // Kernel doesn't print the super type for 0.90 v
ype for ersion
// 0.90 version arrays. Accept no tag (or empty // arrays, so accept empty.
version) if (super == "" || super == "1.0" ||
// as well as "0.90". super == "1.1" || super == "1.2" )
if ( super_type != "" && super_type != "0.90" {
&& fstype = FS_LINUX_SWRAID;
super_type != "1.0" && super_type != "1.1" }
&& else if (super.compare(0, 9, "external:") == 0)
super_type != "1.2" {
) fstype = FS_ATARAID;
}
else
{ {
// Skip /proc/mdstat reported non-Linux S oftware RAID arrays // Skip unrecognised super type.
mdstat_line_type = MDSTAT_LT_OTHER; mdstat_line_type = MDSTAT_LT_OTHER;
continue; continue;
} }
for ( unsigned int i = 0 ; i < members.size() ; i ++ ) for ( unsigned int i = 0 ; i < members.size() ; i ++ )
{ {
SWRaid_Member & memb = get_cache_entry_by _member( members[i] ); SWRaid_Member & memb = get_cache_entry_by _member( members[i] );
if ( memb.member.m_name.length() > 0 ) if ( memb.member.m_name.length() > 0 )
{ {
// Update existing cache entry, s etting // Update existing cache entry, s etting
skipping to change at line 293 skipping to change at line 328
memb.array = array; memb.array = array;
memb.active = true; memb.active = true;
} }
else else
{ {
// Member not already found in th e cache. // Member not already found in th e cache.
// (Mdadm command possibly missin g). // (Mdadm command possibly missin g).
// Insert cache entry. // Insert cache entry.
SWRaid_Member new_memb; SWRaid_Member new_memb;
new_memb.member = BlockSpecial( m embers[i] ); new_memb.member = BlockSpecial( m embers[i] );
new_memb.fstype = fstype;
new_memb.array = array; new_memb.array = array;
new_memb.uuid = ""; new_memb.uuid = "";
new_memb.label = ""; new_memb.label = "";
new_memb.active = true; new_memb.active = true;
swraid_info_cache.push_back( new_ memb ); swraid_info_cache.push_back( new_ memb );
} }
} }
array.clear(); array.clear();
members.clear(); members.clear();
} }
skipping to change at line 322 skipping to change at line 358
// Perform linear search of the cache to find the matching member. // Perform linear search of the cache to find the matching member.
// Returns found cache entry or not found substitute. // Returns found cache entry or not found substitute.
SWRaid_Member & SWRaid_Info::get_cache_entry_by_member( const Glib::ustring & me mber_path ) SWRaid_Member & SWRaid_Info::get_cache_entry_by_member( const Glib::ustring & me mber_path )
{ {
BlockSpecial bs = BlockSpecial( member_path ); BlockSpecial bs = BlockSpecial( member_path );
for ( unsigned int i = 0 ; i < swraid_info_cache.size() ; i ++ ) for ( unsigned int i = 0 ; i < swraid_info_cache.size() ; i ++ )
{ {
if ( bs == swraid_info_cache[i].member ) if ( bs == swraid_info_cache[i].member )
return swraid_info_cache[i]; return swraid_info_cache[i];
} }
static SWRaid_Member memb = {BlockSpecial(), "", "", "", false}; static SWRaid_Member memb = {BlockSpecial(), FS_UNKNOWN, "", "", "", fals e};
return memb; return memb;
} }
// Reformat mdadm printed UUID into canonical format. Returns "" if source not correctly // Reformat mdadm printed UUID into canonical format. Returns "" if source not correctly
// formatted. // formatted.
// E.g. "15224a42:c25bbcd9:15db6000:4e5fe53a" -> "15224a42-c25b-bcd9-15db-60004e 5fe53a" // E.g. "15224a42:c25bbcd9:15db6000:4e5fe53a" -> "15224a42-c25b-bcd9-15db-60004e 5fe53a"
Glib::ustring SWRaid_Info::mdadm_to_canonical_uuid( const Glib::ustring & mdadm_ uuid ) Glib::ustring SWRaid_Info::mdadm_to_canonical_uuid( const Glib::ustring & mdadm_ uuid )
{ {
Glib::ustring verified_uuid = Utils::regexp_label( mdadm_uuid, Glib::ustring verified_uuid = Utils::regexp_label( mdadm_uuid,
"^([[:xdigit:]]{8}:[[:xdigit:]]{8}:[[:xdigit:]]{8}:[[:xdi git:]]{8})$" ); "^([[:xdigit:]]{8}:[[:xdigit:]]{8}:[[:xdigit:]]{8}:[[:xdi git:]]{8})$" );
 End of changes. 16 change blocks. 
50 lines changed or deleted 81 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)