Author: mpatelcz
Date: Wed Sep 23 13:57:53 2009
New Revision: 58716
URL: http://svn.opensuse.org/viewcvs/yast?rev=58716&view=rev
Log:
Branch creation
Added:
branches/tmp/mpatelcz/
branches/tmp/mpatelcz/SLE-11-SP1-Stash/
- copied from r58702, branches/tmp/SLE-11-SP1-Stash/storage/
Modified:
branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.cc
branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.h
branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/MdCo.cc
branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Storage.cc
branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/StorageInterface.h
branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Volume.cc
Modified: branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.cc?rev=58716&r1=58702&r2=58716&view=diff
==============================================================================
--- branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.cc (original)
+++ branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.cc Wed Sep 23 13:57:53 2009
@@ -6,6 +6,13 @@
#include
#include
+#include
+#include <string>
+#include
+#include
+#include
+
+
#include "y2storage/Md.h"
#include "y2storage/StorageTypes.h"
#include "y2storage/Storage.h"
@@ -31,6 +38,115 @@
computeSize();
}
+
+Md::Md( const MdCo& d, const string& dev_name) : Volume(d,0,0)
+{
+ //
+ y2mil("Md new constructor.");
+ if( d.type() != MD )
+ {
+ y2err("constructed md with wrong container");
+ }
+ init();
+ /* Get first part */
+ if( mdStringNum( dev_name, num ))
+ {
+ y2mil("num is " << num);
+ nm.clear();
+ y2mil("seNameDev.");
+ setNameDev();
+ y2mil("nm = " << nm);
+ y2mil("num after is " << num << ", dev is " << dev << ", arg="<> tmpSize;
+ setSize(tmpSize);
+ y2mil("component size :" << tmpSize);
+ }
+
+ property.clear();
+ if( !readProp(CHUNK_SIZE, property) )
+ {
+ y2mil("Failed to read chunk_size");
+ chunk = 0;
+ }
+ else
+ {
+ property >> chunk;
+ /* From 'B' in file to 'Kb' here. */
+ chunk /= 1024;
+ y2mil("chunk size :" << chunk);
+ }
+
+ property.clear();
+ if( !readProp(ARRAY_STATE, property) )
+ {
+ md_state = storage::UNKNOWN;
+ y2mil("array state unknown ");
+ }
+ else
+ {
+ if( property == "readonly" )
+ {
+ setReadonly();
+ }
+ md_state = toMdArrayState(property);
+ y2mil("Array state : " << property << "(" << md_state << ")");
+
+ }
+
+ if( md_type != CONTAINER)
+ {
+ y2mil("Not container ");
+ // read raid level.
+ if( !readProp(LEVEL, property) )
+ {
+ y2mil("RAID type unknown");
+ md_type = storage::RAID_UNK;
+ }
+ else
+ {
+ md_type = toMdType(property);
+ y2mil("RAID type '" << property << "'(" << md_type << ")");
+ }
+ }
+ else
+ {
+ y2mil("RAID type 'container'(" << md_type << ")");
+ }
+
+ y2mil("Getting Parity - only for raid 5 and... ");
+ setMdParity();
+ y2mil("Getting Devs");
+ setMdDevs();
+ y2mil("reading 'map' file.");
+ readMdMap();
+
+ y2mil("Done");
+}
+
Md::Md( const MdCo& d, const string& line1, const string& line2 )
: Volume( d, 0, 0 )
{
@@ -508,7 +624,7 @@
MdType
Md::toMdType( const string& val )
{
- enum MdType ret = MULTIPATH;
+ enum MdType ret = CONTAINER;
while( ret!=RAID_UNK && val!=md_names[ret] )
{
ret = MdType(ret-1);
@@ -527,6 +643,21 @@
return( ret );
}
+
+
+storage::MdArrayState
+Md::toMdArrayState( const string& val )
+{
+ enum storage::MdArrayState ret = storage::ACTIVE_IDLE;
+ while( ret!=storage::UNKNOWN && val!=md_states[ret] )
+ {
+ ret = storage::MdArrayState(ret-1);
+ }
+ return( ret );
+}
+
+
+
bool Md::matchRegex( const string& dev )
{
static Regex md( "^md[0123456789]+$" );
@@ -567,23 +698,40 @@
void Md::getInfo( MdInfo& tinfo ) const
{
+
+ y2mil("Called");
((Volume*)this)->getInfo( info.v );
+ y2mil("info.nr = " << num);
info.nr = num;
+ y2mil("info.type = " << md_type);
info.type = md_type;
+ y2mil("info.uuid = " << md_uuid);
info.uuid = md_uuid;
+ y2mil("info.sb_ver = " << sb_ver);
info.sb_ver = sb_ver;
+ y2mil("info.chunk = " << chunk);
info.chunk = chunk;
+ y2mil("info.parity = " << md_parity);
info.parity = md_parity;
+
info.devices.clear();
+
list<string>::const_iterator i=devs.begin();
while( i!=devs.end() )
{
+ y2mil("dev = " << *i);
if( !info.devices.empty() )
+ {
+ y2mil("devices not empy, adding ' '");
info.devices += ' ';
+ }
info.devices += *i;
+ y2mil("info.devices = " << info.devices);
++i;
}
+
tinfo = info;
+ y2mil("Done");
}
namespace storage
@@ -679,9 +827,188 @@
*this = rhs;
}
+
+/* metadata can be:
+ * external:name - external metadata as imsm,
+ * external:/dev/xxxx - volume
+ * name - internal volume.
+ * */
+void Md::checkMetaData()
+{
+ y2mil("Checking metadata");
+ if( sb_ver.find("external:")!=string::npos )
+ {
+ if( sb_ver.find('/')!=string::npos )
+ {
+ // if '/' then this is volume
+ md_type = RAID_UNK;
+ y2mil("External volume: " << sb_ver);
+ }
+ else
+ {
+ // found external: but no '/'. this is external metadata.
+ md_type = CONTAINER;
+ y2mil("External container: " << sb_ver);
+ }
+ }
+ else
+ {
+ // If no 'external:' then this is volume
+ md_type = RAID_UNK;
+ y2mil("Internal volume: " << sb_ver);
+ }
+}
+
+
+
+
+bool Md::readProp(enum MdProperty prop, string& val)
+{
+ string path = sysfs_path + nm + "/md/" + md_props[prop];
+
+ y2mil("Path : " << path);
+ std::ifstream file( path.c_str() );
+ classic(file);
+
+ if( file.good() )
+ {
+ getline(file,val);
+ }
+ else
+ {
+ y2mil("File: " << sysfs_path << md_props[prop] << " = FAILED");
+ return false;
+ }
+ file.close();
+ file.clear();
+ y2mil("File: " << sysfs_path << md_props[prop] << " = " << val);
+ return true;
+}
+
+
+void Md::setMdDevs()
+{
+ /* /sys/devices/virtual/block/mdX/slaves contains devices (links)*/
+ string path = sysfs_path + nm + "/slaves";
+ DIR* dir;
+
+ y2mil("called, path=" << path);
+
+ if ((dir = opendir(path.c_str())) != NULL)
+ {
+ struct dirent* entry;
+ while ((entry = readdir(dir)) != NULL)
+ {
+ string tmpS(entry->d_name);
+ y2mil("Entry : " << tmpS);
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
+ continue;
+ y2mil("Adding disk : " << tmpS);
+ devs.push_back( ("/dev/"+tmpS) );
+
+ /* Get disk and mark it as used by MD. */
+ }
+ closedir(dir);
+ }
+ y2mil("Exiting");
+}
+
+
+void Md::setMdParity()
+{
+ //TBD:
+}
+
+void Md::setMdUUID()
+{
+ //FIXME: from 'map' file.
+}
+
+
+bool Md::findMdMap(std::ifstream& file)
+{
+ const char* mdadm_map[] = {"/var/run/mdadm/map",
+ "/var/run/mdadm.map",
+ "/dev/.mdadm.map",
+ 0};
+ classic(file);
+ int i=0;
+ while( mdadm_map[i] )
+ {
+ y2mil("Looking for file: " << mdadm_map[i]);
+ file.open( mdadm_map[i] );
+ if( file.is_open() )
+ {
+ y2mil("Found");
+ return true;
+ }
+ else
+ {
+ i++;
+ }
+ }
+ y2mil("File not found");
+ return false;
+}
+
+/* Will try to set: UUID, Name.*/
+/* Format: mdX metadata uuid /dev/md/md_name */
+bool Md::readMdMap()
+{
+ std::ifstream file;
+ string line;
+ classic(file);
+
+ y2mil("Reading 'map' file");
+ /* Got file, now parse output. */
+ if( findMdMap(file) )
+ {
+ y2mil("map file found.");
+ while( !file.eof() )
+ {
+ string val;
+ getline(file,line);
+ y2mil("Line: " << line);
+ val = extractNthWord( MAP_DEV, line );
+ if( val == nm )
+ {
+ size_t found;
+ y2mil("Found good line, paring");
+ md_uuid = extractNthWord( MAP_UUID, line );
+ y2mil("UUID: " << md_uuid);
+
+ val = extractNthWord( MAP_NAME, line );
+ found = val.find_last_of("/");
+ md_name = val.substr(found+1);
+
+ y2mil("md name is: " << md_name);
+ file.close();
+ return true;
+ }
+ else
+ {
+ y2mil("getting another line.");
+ }
+ }
+ file.close();
+ }
+ return true;
+}
+
+
string Md::md_names[] = { "unknown", "raid0", "raid1", "raid5", "raid6",
- "raid10", "multipath" };
+ "raid10", "multipath", "container" };
string Md::par_names[] = { "none", "left-asymmetric", "left-symmetric",
"right-asymmetric", "right-symmetric" };
+/* */
+string Md::md_states[] = {"clear", "inactive", "suspended", "readonly",
+ "read-auto", "clean", "active", "write-pending",
+ "active-idle"};
+
+string Md::md_props[] = {"metadata_version", "component_size", "chunk_size",
+ "array_state", "level" };
+/* */
+string Md::sysfs_path = "/sys/devices/virtual/block/";
+
unsigned Md::md_major = 0;
Modified: branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.h?rev=58716&r1=58702&r2=58716&view=diff
==============================================================================
--- branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.h (original)
+++ branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Md.h Wed Sep 23 13:57:53 2009
@@ -17,11 +17,18 @@
Md( const MdCo& d, const string& line, const string& line2 );
Md( const MdCo& d, const Md& m );
+ Md( const MdCo& d, const string& dev_name);
+
virtual ~Md();
storage::MdType personality() const { return md_type; }
void setPersonality( storage::MdType val );
storage::MdParity parity() const { return md_parity; }
void setParity( storage::MdParity val ) { md_parity=val; }
+ /* */
+ storage::MdArrayState getArrayState() { return md_state; };
+ void setArrayState( storage::MdArrayState val ) { md_state = val; }
+ /* */
+
unsigned long chunkSize() const { return chunk; }
void setChunkSize( unsigned long val ) { chunk=val; }
void setMdUuid( const string&val ) { md_uuid=val; }
@@ -61,22 +68,58 @@
void computeSize();
Md& operator=( const Md& );
+
+ void checkMetaData();
+
+ void setMdDevs();
+ void setMdParity();
+ void setMdUUID();
+
+ /* fields in 'map' file */
+ enum mdMap { MAP_DEV=0, MAP_META, MAP_UUID, MAP_NAME, };
+ bool findMdMap(std::ifstream& file);
+ bool readMdMap();
+
+
static void getMdMajor();
static storage::MdType toMdType( const string& val );
static storage::MdParity toMdParity( const string& val );
+ static storage::MdArrayState toMdArrayState( const string& val );
storage::MdType md_type;
storage::MdParity md_parity;
+ storage::MdArrayState md_state;
unsigned long chunk;
string md_uuid;
string sb_ver;
bool destrSb;
std::list<string> devs;
std::list<string> spare;
- static string md_names[storage::MULTIPATH+1];
+ static string md_names[storage::CONTAINER+1];
static string par_names[storage::RIGHT_SYMMETRIC+1];
+ static string md_states[storage::ACTIVE_IDLE+1];
static unsigned md_major;
mutable storage::MdInfo info;
+
+ /* Name that is present in /dev/md directory.*/
+ string md_name;
+
+ static string sysfs_path;
+
+ enum MdProperty
+ {
+ METADATA=0,
+ COMPONENT_SIZE,
+ CHUNK_SIZE,
+ ARRAY_STATE,
+ LEVEL,
+ /* ... */
+ MDPROP_LAST,
+ };
+ static string md_props[MDPROP_LAST];
+
+ bool readProp(enum MdProperty prop, string& val);
+
};
}
Modified: branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/MdCo.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/MdCo.cc?rev=58716&r1=58702&r2=58716&view=diff
==============================================================================
--- branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/MdCo.cc (original)
+++ branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/MdCo.cc Wed Sep 23 13:57:53 2009
@@ -86,6 +86,7 @@
{
y2milestone( "begin" );
string line;
+ string dev_name;
std::ifstream file( "/proc/mdstat" );
classic(file);
unsigned dummy;
@@ -93,14 +94,18 @@
while( file.good() )
{
y2mil( "mdstat line:" << line );
- if( Md::mdStringNum(extractNthWord( 0, line ),dummy) )
- {
+ string dev_name = extractNthWord( 0, line );
+ /* If this first word is device name (like md126) */
+ if( Md::mdStringNum(dev_name,dummy) )
+ {
+ y2mil("MD Device: " << dev_name << ", dummy="<http://svn.opensuse.org/viewcvs/yast/branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Storage.cc?rev=58716&r1=58702&r2=58716&view=diff
==============================================================================
--- branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Storage.cc (original)
+++ branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Storage.cc Wed Sep 23 13:57:53 2009
@@ -4036,6 +4036,8 @@
VolIterator v;
info.type = CUNKNOWN;
assertInit();
+
+ y2mil("Called for device : " << device);
if( findVolume( dev, c, v ))
{
info.type = c->type();
Modified: branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/StorageInterface.h?rev=58716&r1=58702&r2=58716&view=diff
==============================================================================
--- branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/StorageInterface.h (original)
+++ branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/StorageInterface.h Wed Sep 23 13:57:53 2009
@@ -107,11 +107,15 @@
enum EncryptType { ENC_NONE, ENC_TWOFISH, ENC_TWOFISH_OLD,
ENC_TWOFISH256_OLD, ENC_LUKS, ENC_UNKNOWN };
- enum MdType { RAID_UNK, RAID0, RAID1, RAID5, RAID6, RAID10, MULTIPATH };
+ enum MdType { RAID_UNK, RAID0, RAID1, RAID5, RAID6, RAID10, MULTIPATH,
+ CONTAINER };
enum MdParity { PAR_NONE, LEFT_ASYMMETRIC, LEFT_SYMMETRIC,
RIGHT_ASYMMETRIC, RIGHT_SYMMETRIC };
+ enum MdArrayState {UNKNOWN, CLEAR, INACTIVE, SUSPENDED, READONLY, READ_AUTO,
+ CLEAN, ACTIVE, WRITE_PENDING, ACTIVE_IDLE };
+
enum UsedByType { UB_NONE, UB_LVM, UB_MD, UB_DM, UB_DMRAID, UB_DMMULTIPATH };
enum CType { CUNKNOWN, DISK, MD, LOOP, LVM, DM, DMRAID, NFSC, DMMULTIPATH,
@@ -356,6 +360,7 @@
MdStateInfo() {}
bool active;
bool degraded;
+ enum MdArrayState state;
};
/**
Modified: branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Volume.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Volume.cc?rev=58716&r1=58702&r2=58716&view=diff
==============================================================================
--- branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Volume.cc (original)
+++ branches/tmp/mpatelcz/SLE-11-SP1-Stash/libstorage/src/Volume.cc Wed Sep 23 13:57:53 2009
@@ -2703,6 +2703,8 @@
void Volume::getInfo( VolumeInfo& tinfo ) const
{
+ y2mil("called");
+ y2mil("info.sizeK = " << size_k);
info.sizeK = size_k;
info.major = mjr;
info.minor = mnr;
@@ -2733,6 +2735,7 @@
else
info.OrigSizeK = 0;
tinfo = info;
+ y2mil("Done");
}
void Volume::mergeFstabInfo( VolumeInfo& tinfo, const FstabEntry& fste ) const
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org