Improve dmraid device detection with checking udev if needed

Some distros appear to display /dev/dm-# device names with
libparted.  Since this fails a pattern match with the dmraid
device name, check with udev to see if a pattern match is
possible with the name returned from udevinfo or udevadm info.

For example:
     /dev/mapper/isw_cjbdddajhi_Vol0 is the device name
     /dev/dm-0 is a symbolic link pointing to the above device name
This commit is contained in:
Curtis Gedak 2009-04-26 16:45:53 -06:00
parent 5112e41815
commit ce4de8b51e
2 changed files with 28 additions and 0 deletions

View file

@ -71,6 +71,8 @@ private:
static bool dmraid_found ;
static bool dmsetup_found ;
static bool kpartx_found ;
static bool udevinfo_found ;
static bool udevadm_found ;
static std::vector<Glib::ustring> dmraid_devices ;
};

View file

@ -27,6 +27,8 @@ bool DMRaid::dmraid_cache_initialized = false ;
bool DMRaid::dmraid_found = false ;
bool DMRaid::dmsetup_found = false ;
bool DMRaid::kpartx_found = false ;
bool DMRaid::udevinfo_found = false ;
bool DMRaid::udevadm_found = false ;
std::vector<Glib::ustring> DMRaid::dmraid_devices ;
DMRaid::DMRaid()
@ -82,6 +84,8 @@ void DMRaid::set_commands_found()
dmraid_found = (! Glib::find_program_in_path( "dmraid" ) .empty() ) ;
dmsetup_found = (! Glib::find_program_in_path( "dmsetup" ) .empty() ) ;
kpartx_found = (! Glib::find_program_in_path( "kpartx" ) .empty() ) ;
udevinfo_found = (! Glib::find_program_in_path( "udevinfo" ) .empty() ) ;
udevadm_found = (! Glib::find_program_in_path( "udevadm" ) .empty() ) ;
}
bool DMRaid::is_dmraid_supported()
@ -102,6 +106,28 @@ bool DMRaid::is_dmraid_device( const Glib::ustring & dev_path )
device_found = true ;
}
//Some distros appear to default to /dev/dm-# for device names, so
// also check with udev to see if they are in fact dmraid devices
if ( ! device_found && ( dev_path .find( "/dev/dm" ) != Glib::ustring::npos ) )
{
Glib::ustring output = "" ;
Glib::ustring error = "" ;
Glib::ustring alt_udev_path = "" ;
if ( udevinfo_found )
if ( ! Utils::execute_command( "udevinfo --query=name --name=" + dev_path, output, error, true ) )
alt_udev_path = output ;
else if ( udevadm_found )
if ( ! Utils::execute_command( "udevadm info --query=name --name=" + DEV_MAP_PATH + dev_path, output, error, true ) )
alt_udev_path = output ;
if ( ! alt_udev_path .empty() )
{
for ( unsigned int k=0; k < dmraid_devices .size(); k++ )
if ( alt_udev_path .find( dmraid_devices[k] ) != Glib::ustring::npos )
device_found = true ;
}
}
return device_found ;
}