Skip to content

Commit

Permalink
improve handling of udev by-id links for dm devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fehr committed Mar 6, 2013
1 parent 84aefa2 commit 023811f
Show file tree
Hide file tree
Showing 23 changed files with 228 additions and 45 deletions.
7 changes: 6 additions & 1 deletion libstorage/src/AppUtil.cc
Expand Up @@ -605,7 +605,12 @@ readlink(const string& path, string& buf)

string::size_type pos = tmp.find_first_not_of("./");
if (pos != string::npos)
links[udevDecode(entry->d_name)] = tmp.substr(pos);
{
tmp.erase(0,pos);
if( boost::starts_with(tmp, "dev/"))
tmp.erase(0,4);
links[udevDecode(entry->d_name)] = tmp;
}
}
closedir(dir);
}
Expand Down
22 changes: 21 additions & 1 deletion libstorage/src/Dm.cc
Expand Up @@ -28,6 +28,7 @@
#include "storage/Dm.h"
#include "storage/PeContainer.h"
#include "storage/SystemCmd.h"
#include "storage/SystemInfo.h"
#include "storage/AppUtil.h"
#include "storage/Regex.h"
#include "storage/Storage.h"
Expand Down Expand Up @@ -218,11 +219,30 @@ void Dm::init()
pe_larger = false;
}

void Dm::setUdevData(SystemInfo& si)
{
const UdevMap& by_id = si.getUdevMap("/dev/disk/by-id");
alt_names.remove_if(string_starts_with("/dev/disk/by-id/"));
UdevMap::const_iterator it = by_id.find(procName());
if (it != by_id.end())
{
list<string> sl = it->second;
partition(sl.begin(), sl.end(), string_starts_with("dm-name-"));
y2mil("dev:" << dev << " udev_id:" << sl);
for (list<string>::const_iterator i = sl.begin(); i != sl.end(); ++i)
alt_names.push_back("/dev/disk/by-id/" + *i);
}
}

void Dm::updateMajorMinor()
{
getMajorMinor();
if( majorNr()==Dm::dmMajor() )
addDmNames(minorNr());
{
string d = "/dev/dm-" + decString(minorNr());
if( d!=dev )
replaceAltName( "/dev/dm-", d );
}
num = mnr;
}

Expand Down
1 change: 1 addition & 0 deletions libstorage/src/Dm.h
Expand Up @@ -70,6 +70,7 @@ class Dm : public Volume

virtual string procName() const { return "dm-" + decString(mnr); }
virtual string sysfsPath() const;
void setUdevData(SystemInfo& systeminfo);

void updateMajorMinor();

Expand Down
30 changes: 22 additions & 8 deletions libstorage/src/DmPart.cc
Expand Up @@ -42,8 +42,7 @@ namespace storage
Partition* pa)
: Dm(c, name, device, name), p(pa)
{
Dm::init();

Dm::init();
numeric = true;
num = nr;
getTableInfo();
Expand All @@ -52,6 +51,20 @@ namespace storage
y2mil("constructed DmPart " << dev << " on " << cont->device());
}

DmPart::DmPart(const DmPartCo& c, const string& name, const string& device, unsigned nr,
Partition* pa, SystemInfo& si)
: Dm(c, name, device, name), p(pa)
{
Dm::init();
numeric = true;
num = nr;
getTableInfo();
if( pa )
setSize( pa->sizeK() );
Dm::setUdevData(si);
y2mil("constructed DmPart " << dev << " on " << cont->device());
}


DmPart::DmPart(const DmPartCo& c, const DmPart& v)
: Dm(c, v)
Expand Down Expand Up @@ -87,8 +100,8 @@ void DmPart::updateMinor()
getMajorMinor();
if (mjr != old_mjr || mnr != old_mnr)
{
addDmNames(mnr);
getTableInfo();
replaceAltName("/dev/dm-", "/dev/dm-" + decString(mnr));
}
}

Expand All @@ -107,7 +120,7 @@ void DmPart::updateSize()
{
unsigned long long si = 0;
updateSize();
if (mjr > 0 && parts.getSize("/dev/dm-" + decString(mnr), si))
if (mjr > 0 && parts.getSize("/dev/dm-" + decString(mnr), si))
setSize( si );
}

Expand All @@ -121,12 +134,13 @@ void DmPart::addUdevData()
void
DmPart::addAltUdevId(unsigned num)
{
alt_names.remove_if(string_contains("/by-id/"));

const list<string> tmp = co()->udevId();
for (list<string>::const_iterator i = tmp.begin(); i != tmp.end(); ++i)
alt_names.push_back("/dev/disk/by-id/" + udevAppendPart(*i, num));

{
string s = "/dev/disk/by-id/"+udevAppendPart(*i, num);
if( find( alt_names.begin(), alt_names.end(), s )==alt_names.end() )
alt_names.push_back(s);
}
mount_by = orig_mount_by = defaultMountBy();
}

Expand Down
2 changes: 2 additions & 0 deletions libstorage/src/DmPart.h
Expand Up @@ -37,6 +37,8 @@ class DmPart : public Dm
{
public:

DmPart(const DmPartCo& c, const string& name, const string& device, unsigned nr,
Partition* p, SystemInfo& si);
DmPart(const DmPartCo& c, const string& name, const string& device, unsigned nr,
Partition* p);
DmPart(const DmPartCo& c, const DmPart& v);
Expand Down
40 changes: 35 additions & 5 deletions libstorage/src/DmPartCo.cc
Expand Up @@ -320,7 +320,7 @@ void
if (tmp.empty())
activate_part(true);
}
getVolumes(systeminfo.getProcParts());
getVolumes(systeminfo);
active = true;
}
}
Expand All @@ -347,22 +347,29 @@ DmPartCo::newP( DmPart*& dm, unsigned num, Partition* p )
dm = new DmPart( *this, getPartName(num), getPartDevice(num), num, p );
}

void
DmPartCo::newP( DmPart*& dm, unsigned num, Partition* p, SystemInfo& si )
{
y2mil( "num:" << num );
dm = new DmPart( *this, getPartName(num), getPartDevice(num), num, p, si );
}


void
DmPartCo::getVolumes(const ProcParts& parts)
DmPartCo::getVolumes(SystemInfo& si)
{
clearPointerList(vols);
Disk::PartPair pp = disk->partPair();
Disk::PartIter i = pp.begin();
DmPart * p = NULL;
while( i!=pp.end() )
{
newP( p, i->nr(), &(*i) );
p->updateSize(parts);
newP( p, i->nr(), &(*i), si );
p->updateSize(si.getProcParts());
addToList( p );
++i;
}
handleWholeDevice();
handleWholeDevice(si);
}

void DmPartCo::handleWholeDevice()
Expand All @@ -388,6 +395,29 @@ void DmPartCo::handleWholeDevice()
}
}

void DmPartCo::handleWholeDevice(SystemInfo& si)
{
Disk::PartPair pp = disk->partPair( Partition::notDeleted );
y2mil("empty:" << pp.empty());
if( pp.empty() )
{
DmPart * p = NULL;
newP( p, 0, NULL, si );
p->setSize( size_k );
addToList( p );
}
else
{
DmPartIter i;
if( findDm( 0, i ))
{
DmPart* dm = &(*i);
if( !removeFromList( dm ))
y2err( "not found:" << *i );
}
}
}

Partition*
DmPartCo::getPartition( unsigned nr, bool del )
{
Expand Down
4 changes: 3 additions & 1 deletion libstorage/src/DmPartCo.h
Expand Up @@ -169,13 +169,15 @@ class DmPartCo : public PeContainer
void activate_part( bool val );
void init(SystemInfo& systeminfo);
void createDisk(SystemInfo& systeminfo);
void getVolumes(const ProcParts& parts);
void getVolumes(SystemInfo& si);
void updatePointers( bool invalid=false );
void updateMinor();
virtual void newP( DmPart*& dm, unsigned num, Partition* p, SystemInfo& si );
virtual void newP( DmPart*& dm, unsigned num, Partition* p );
int addNewDev( string& device );
int updateDelDev();
void handleWholeDevice();
void handleWholeDevice(SystemInfo& si);
void removeFromMemory();
void removePresentPartitions();
bool validPartition( const Partition* p );
Expand Down
7 changes: 7 additions & 0 deletions libstorage/src/Dmmultipath.cc
Expand Up @@ -44,6 +44,13 @@ namespace storage
y2mil("constructed Dmmultipath " << dev << " on " << cont->device());
}

Dmmultipath::Dmmultipath(const DmmultipathCo& c, const string& name, const string& device,
unsigned nr, Partition* p, SystemInfo& si)
: DmPart(c, name, device, nr, p, si)
{
y2mil("constructed Dmmultipath " << dev << " on " << cont->device());
}


Dmmultipath::Dmmultipath(const DmmultipathCo& c, const Dmmultipath& v)
: DmPart(c, v)
Expand Down
2 changes: 2 additions & 0 deletions libstorage/src/Dmmultipath.h
Expand Up @@ -37,6 +37,8 @@ class Dmmultipath : public DmPart

Dmmultipath(const DmmultipathCo& c, const string& name, const string& device, unsigned nr,
Partition* p);
Dmmultipath(const DmmultipathCo& c, const string& name, const string& device, unsigned nr,
Partition* p, SystemInfo& si);
Dmmultipath(const DmmultipathCo& c, const Dmmultipath& v);
virtual ~Dmmultipath();

Expand Down
6 changes: 6 additions & 0 deletions libstorage/src/DmmultipathCo.cc
Expand Up @@ -216,6 +216,12 @@ DmmultipathCo::newP( DmPart*& dm, unsigned num, Partition* p )
dm = new Dmmultipath( *this, getPartName(num), getPartDevice(num), num, p );
}

void
DmmultipathCo::newP( DmPart*& dm, unsigned num, Partition* p, SystemInfo& si )
{
y2mil( "num:" << num );
dm = new Dmmultipath( *this, getPartName(num), getPartDevice(num), num, p, si );
}

void
DmmultipathCo::addPv(const Pv& p)
Expand Down
1 change: 1 addition & 0 deletions libstorage/src/DmmultipathCo.h
Expand Up @@ -139,6 +139,7 @@ class DmmultipathCo : public DmPartCo
void getMultipathData(const string& name, SystemInfo& systeminfo);
void addPv(const Pv& pv);
void newP( DmPart*& dm, unsigned num, Partition* p );
void newP( DmPart*& dm, unsigned num, Partition* p, SystemInfo& si );

static void activate(bool val);
static bool isActive() { return active; }
Expand Down
7 changes: 7 additions & 0 deletions libstorage/src/Dmraid.cc
Expand Up @@ -44,6 +44,13 @@ namespace storage
y2mil("constructed Dmraid " << dev << " on " << cont->device());
}

Dmraid::Dmraid(const DmraidCo& c, const string& name, const string& device, unsigned nr,
Partition* p, SystemInfo& si)
: DmPart(c, name, device, nr, p, si)
{
y2mil("constructed Dmraid " << dev << " on " << cont->device());
}


Dmraid::Dmraid(const DmraidCo& c, const Dmraid& v)
: DmPart(c, v)
Expand Down
2 changes: 2 additions & 0 deletions libstorage/src/Dmraid.h
Expand Up @@ -37,6 +37,8 @@ class Dmraid : public DmPart

Dmraid(const DmraidCo& c, const string& name, const string& device, unsigned nr,
Partition* p);
Dmraid(const DmraidCo& c, const string& name, const string& device, unsigned nr,
Partition* p, SystemInfo& si);
Dmraid(const DmraidCo& c, const Dmraid& v);
virtual ~Dmraid();

Expand Down
7 changes: 7 additions & 0 deletions libstorage/src/DmraidCo.cc
Expand Up @@ -179,6 +179,13 @@ DmraidCo::newP( DmPart*& dm, unsigned num, Partition* p )
dm = new Dmraid( *this, getPartName(num), getPartDevice(num), num, p );
}

void
DmraidCo::newP( DmPart*& dm, unsigned num, Partition* p, SystemInfo& si )
{
y2mil( "num:" << num );
dm = new Dmraid( *this, getPartName(num), getPartDevice(num), num, p, si );
}


void
DmraidCo::addPv(const Pv& pv)
Expand Down
1 change: 1 addition & 0 deletions libstorage/src/DmraidCo.h
Expand Up @@ -137,6 +137,7 @@ class DmraidCo : public DmPartCo
void getRaidData(const string& name, SystemInfo& systeminfo);
void addPv(const Pv& pv);
void newP( DmPart*& dm, unsigned num, Partition* p );
void newP( DmPart*& dm, unsigned num, Partition* p, SystemInfo& si );

Text removeText( bool doing ) const;

Expand Down
6 changes: 4 additions & 2 deletions libstorage/src/LvmLv.cc
Expand Up @@ -40,11 +40,13 @@ namespace storage


LvmLv::LvmLv(const LvmVg& c, const string& name, const string& device, const string& origi,
unsigned long le, const string& uuid, const string& stat, const string& alloc)
unsigned long le, const string& uuid, const string& stat, const string& alloc,
SystemInfo& si)
: Dm(c, name, device, makeDmTableName(c.name(), name)), origin(origi),
chunk_size(0), pool(false)
{
Dm::init();
Dm::init();
setUdevData(si);
setUuid( uuid );
setStatus( stat );
setAlloc( alloc );
Expand Down
5 changes: 3 additions & 2 deletions libstorage/src/LvmLv.h
Expand Up @@ -36,9 +36,10 @@ class LvmLv : public Dm
public:

LvmLv(const LvmVg& c, const string& name, const string& device, const string& origin,
unsigned long le, const string& uuid, const string& status, const string& alloc);
unsigned long le, const string& uuid, const string& status, const string& alloc,
SystemInfo& si);
LvmLv(const LvmVg& c, const string& name, const string& device, const string& origin,
unsigned long le, unsigned stripe);
unsigned long le, unsigned stripe );
LvmLv(const LvmVg& c, const xmlNode* node);
LvmLv(const LvmVg& c, const LvmLv& v);
virtual ~LvmLv();
Expand Down
10 changes: 6 additions & 4 deletions libstorage/src/LvmVg.cc
Expand Up @@ -31,6 +31,7 @@
#include "storage/SystemCmd.h"
#include "storage/AppUtil.h"
#include "storage/Storage.h"
#include "storage/SystemInfo.h"
#include "storage/StorageDefines.h"


Expand Down Expand Up @@ -795,6 +796,7 @@ void LvmVg::getVgData( const string& name, bool exists )
string line;
string tmp;
string::size_type pos;
SystemInfo si;
while( i<cnt )
{
line = c.getLine( i++ );
Expand Down Expand Up @@ -869,7 +871,7 @@ void LvmVg::getVgData( const string& name, bool exists )
{
addLv(origin.empty() ? num_le : num_cow_le, vname,
origin, uuid, status, allocation,
readOnly, pool, used_pool, pool_chunk);
readOnly, pool, used_pool, pool_chunk, si);
}
vname = extractNthWord( 2, line );
if( (pos=vname.rfind( "/" ))!=string::npos )
Expand Down Expand Up @@ -927,7 +929,7 @@ void LvmVg::getVgData( const string& name, bool exists )
{
addLv(origin.empty() ? num_le : num_cow_le, vname, origin,
uuid, status, allocation, readOnly, pool,
used_pool, pool_chunk);
used_pool, pool_chunk, si);
}
Pv *p = new Pv;
while( i<cnt )
Expand Down Expand Up @@ -1019,7 +1021,7 @@ void LvmVg::getVgData( const string& name, bool exists )
void
LvmVg::addLv(unsigned long& le, string& name, string& origin, string& uuid,
string& status, string& alloc, bool& ro, bool& pool,
string& used_pool, unsigned long long& pchunk )
string& used_pool, unsigned long long& pchunk, SystemInfo& si )
{
y2mil("addLv:" << name);
LvmLvPair p=lvmLvPair(lvNotDeletedCreated);
Expand Down Expand Up @@ -1063,7 +1065,7 @@ LvmVg::addLv(unsigned long& le, string& name, string& origin, string& uuid,
if( i==p.end() )
{
LvmLv *n = new LvmLv( *this, name, dev + "/" + name, origin,
le, uuid, status, alloc );
le, uuid, status, alloc, si );
if( ro )
n->setReadonly();
if( pool )
Expand Down

0 comments on commit 023811f

Please sign in to comment.