Added auto detection of Linux software RAID devices

Auto detection of Linux software RAID devices was lost in GParted
0.3.8.  This was because device scanning by the libparted device
call ped_device_probe_all() was replaced with custom code within
GParted to scan /proc/partitions for devices.

The reason the libparted call was replaced was due to a long
scanning problem with ped_device_probe_all(), a non-existent
physical floppy device, and a BIOS setting indicating a floppy
drive existed.  See bug #351753:
https://bugzilla.gnome.org/show_bug.cgi?id=351753
This commit is contained in:
Curtis Gedak 2009-11-03 13:25:40 -07:00
parent c571fa47c4
commit 1607d13a06
5 changed files with 173 additions and 0 deletions

View File

@ -30,6 +30,7 @@ EXTRA_DIST = \
OperationResizeMove.h \ OperationResizeMove.h \
OperationLabelPartition.h \ OperationLabelPartition.h \
Partition.h \ Partition.h \
SWRaid.h \
TreeView_Detail.h \ TreeView_Detail.h \
Utils.h \ Utils.h \
Win_GParted.h \ Win_GParted.h \

55
include/SWRaid.h Normal file
View File

@ -0,0 +1,55 @@
/* Copyright (C) 2009 Curtis Gedak
*
* 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.
*/
/* READ THIS!
* This class was created in an effort to reduce the complexity of the
* GParted_Core class.
* This class provides support for Linux software RAID devices (mdadm).
* Static elements are used in order to reduce the disk accesses required to
* load the data structures upon each initialization of the class.
*/
#ifndef SWRAID_H_
#define SWRAID_H_
#include "../include/Utils.h"
#include <vector>
namespace GParted
{
class SWRaid
{
public:
SWRaid() ;
SWRaid( const bool & do_refresh ) ;
~SWRaid() ;
bool is_swraid_supported() ;
void get_devices( std::vector<Glib::ustring> & swraid_devices ) ;
private:
void load_swraid_cache() ;
void set_commands_found() ;
static bool swraid_cache_initialized ;
static bool mdadm_found ;
static std::vector<Glib::ustring> swraid_devices ;
};
}//GParted
#endif /* SWRAID_H_ */

View File

@ -18,6 +18,7 @@
#include "../include/Win_GParted.h" #include "../include/Win_GParted.h"
#include "../include/GParted_Core.h" #include "../include/GParted_Core.h"
#include "../include/DMRaid.h" #include "../include/DMRaid.h"
#include "../include/SWRaid.h"
#include "../include/FS_Info.h" #include "../include/FS_Info.h"
#include "../include/OperationCopy.h" #include "../include/OperationCopy.h"
#include "../include/OperationCreate.h" #include "../include/OperationCreate.h"
@ -160,6 +161,7 @@ void GParted_Core::set_devices( std::vector<Device> & devices )
Device temp_device ; Device temp_device ;
FS_Info fs_info( true ) ; //Refresh cache of file system information FS_Info fs_info( true ) ; //Refresh cache of file system information
DMRaid dmraid( true ) ; //Refresh cache of dmraid device information DMRaid dmraid( true ) ; //Refresh cache of dmraid device information
SWRaid swraid( true ) ; //Refresh cache of swraid device information
init_maps() ; init_maps() ;
@ -204,6 +206,16 @@ void GParted_Core::set_devices( std::vector<Device> & devices )
} }
proc_partitions .close() ; proc_partitions .close() ;
//Try to find all swraid devices
if (swraid .is_swraid_supported() ) {
std::vector<Glib::ustring> swraid_devices ;
swraid .get_devices( swraid_devices ) ;
for ( unsigned int k=0; k < swraid_devices .size(); k++ ) {
set_thread_status_message( String::ucompose ( _("Scanning %1"), swraid_devices[k] ) ) ;
ped_device_get( swraid_devices[k] .c_str() ) ;
}
}
//Try to find all dmraid devices //Try to find all dmraid devices
if (dmraid .is_dmraid_supported() ) { if (dmraid .is_dmraid_supported() ) {
std::vector<Glib::ustring> dmraid_devices ; std::vector<Glib::ustring> dmraid_devices ;

View File

@ -39,6 +39,7 @@ gpartedbin_SOURCES = \
OperationResizeMove.cc \ OperationResizeMove.cc \
OperationLabelPartition.cc \ OperationLabelPartition.cc \
Partition.cc \ Partition.cc \
SWRaid.cc \
TreeView_Detail.cc \ TreeView_Detail.cc \
Utils.cc \ Utils.cc \
Win_GParted.cc \ Win_GParted.cc \

104
src/SWRaid.cc Normal file
View File

@ -0,0 +1,104 @@
/* Copyright (C) 2009 Curtis Gedak
*
* 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/SWRaid.h"
namespace GParted
{
//Initialize static data elements
bool SWRaid::swraid_cache_initialized = false ;
bool SWRaid::mdadm_found = false ;
std::vector<Glib::ustring> SWRaid::swraid_devices ;
SWRaid::SWRaid()
{
//Ensure that cache has been loaded at least once
if ( ! swraid_cache_initialized )
{
swraid_cache_initialized = true ;
set_commands_found() ;
load_swraid_cache() ;
}
}
SWRaid::SWRaid( const bool & do_refresh )
{
//Ensure that cache has been loaded at least once
if ( ! swraid_cache_initialized )
{
swraid_cache_initialized = true ;
set_commands_found() ;
if ( do_refresh == false )
load_swraid_cache() ;
}
if ( do_refresh )
load_swraid_cache() ;
}
SWRaid::~SWRaid()
{
}
void SWRaid::load_swraid_cache()
{
//Load data into swraid structures
Glib::ustring output, error ;
swraid_devices .clear() ;
if ( mdadm_found )
{
if ( ! Utils::execute_command( "mdadm --examine --scan", output, error, true ) )
{
if ( output .size() > 0 )
{
std::vector<Glib::ustring> temp_arr ;
Utils::tokenize( output, temp_arr, "\n" ) ;
for ( unsigned int k = 0; k < temp_arr .size(); k++ )
{
Glib::ustring temp = Utils::regexp_label( output, "^[^/]*(/dev/[^\t ]*)" ) ;
if ( temp .size() > 0 )
swraid_devices .push_back( temp ) ;
}
}
}
}
}
void SWRaid::set_commands_found()
{
//Set status of commands found
mdadm_found = (! Glib::find_program_in_path( "mdadm" ) .empty() ) ;
}
bool SWRaid::is_swraid_supported()
{
//Determine if Linux software RAID is supported
return ( mdadm_found ) ;
}
void SWRaid::get_devices( std::vector<Glib::ustring> & device_list )
{
//Retrieve list of Linux software RAID devices
device_list .clear() ;
for ( unsigned int k=0; k < swraid_devices .size(); k++ )
device_list .push_back( swraid_devices[k] ) ;
}
}//GParted