Skip to content

Commit

Permalink
recognize /dev/disk-by-id/dm-name-<nm> as alias to /dev/mapper/<dm>
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fehr committed Feb 20, 2013
1 parent d8af296 commit a527741
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 23 deletions.
8 changes: 8 additions & 0 deletions libstorage/src/AppUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ logStreamClose(LogLevel level, const char* file, unsigned line, const char* func
return s + "-part" + decString(num);
}

string afterLast(const string& s, const string& pat )
{
string ret(s);
string::size_type pos = s.find_last_of(pat);
if( pos!=string::npos )
ret.erase( 0, pos+pat.length() );
return( ret );
}

string
udevEncode(const string& s)
Expand Down
1 change: 1 addition & 0 deletions libstorage/src/AppUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ std::map<string,string> makeMap( const std::list<string>& l,
const string& removeSur = " \t\n" );

string udevAppendPart(const string&, unsigned num);
string afterLast(const string& s, const string& pat );

string udevEncode(const string&);
string udevDecode(const string&);
Expand Down
6 changes: 1 addition & 5 deletions libstorage/src/Dm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,7 @@ void Dm::updateMajorMinor()
{
getMajorMinor();
if( majorNr()==Dm::dmMajor() )
{
string d = "/dev/dm-" + decString(minorNr());
if( d!=dev )
replaceAltName( "/dev/dm-", d );
}
addDmNames(minorNr());
num = mnr;
}

Expand Down
2 changes: 1 addition & 1 deletion libstorage/src/DmPart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void DmPart::updateMinor()
getMajorMinor();
if (mjr != old_mjr || mnr != old_mnr)
{
replaceAltName("/dev/dm-", "/dev/dm-" + decString(mnr));
addDmNames(mnr);
getTableInfo();
}
}
Expand Down
1 change: 0 additions & 1 deletion libstorage/src/Loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ Loop::setDmcryptDev( const string& dm_dev, bool active )
if( active )
{
getMajorMinor();
replaceAltName( "/dev/dm-", "/dev/dm-"+decString(mnr) );
}
Volume::setDmcryptDev( dm_dev, active );
}
Expand Down
2 changes: 1 addition & 1 deletion libstorage/src/Storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6719,7 +6719,7 @@ bool Storage::setDmcryptData( const string& dev, const string& dm,
findVolume( dev, v ) )
{
v->setDmcryptDevEnc( dm, typ, siz!=0 );
v->replaceAltName( "/dev/dm-", Dm::dmDeviceName(dmnum) );
v->addDmNames(dmnum);
v->setSize( siz );
ret = true;
}
Expand Down
41 changes: 26 additions & 15 deletions libstorage/src/Volume.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,34 @@ void Volume::setDmcryptDev( const string& dm, bool active )
y2mil( "dev:" << dev << " dm:" << dm << " active:" << active );
dmcrypt_dev = dm;
dmcrypt_active = active;
if( active )
{
unsigned long dummy, minor;
storage::getMajorMinor( dmcrypt_dev, dummy, minor );
addDmNames(minor);
}
else
removeDmNames();
y2mil( "this:" << *this );
}

void Volume::setDmcryptDevEnc( const string& dm, storage::EncryptType typ, bool active )
{
y2mil("dev:" << dev << " dm:" << dm << " enc_type:" << toString(typ) << " active:" << active);
dmcrypt_dev = dm;
encryption = orig_encryption = typ;
dmcrypt_active = active;
y2mil( "this:" << *this );
y2mil("enc_type:" << toString(typ));
setDmcryptDev(dm,active);
}

void Volume::addDmNames( unsigned long minor )
{
replaceAltName( "/dev/dm-", Dm::dmDeviceName(minor) );
replaceAltName( "/dev/disk/by-id/dm-name-",
"/dev/disk/by-id/dm-name-"+afterLast(dmcrypt_dev,"/"));
}

void Volume::removeDmNames()
{
replaceAltName( "/dev/dm-", "" );
replaceAltName( "/dev/disk/by-id/dm-name-", "" );
}

const string& Volume::mountDevice() const
Expand Down Expand Up @@ -1306,6 +1324,7 @@ int Volume::cryptUnsetup( bool force )
ret = VOLUME_CRYPTUNSETUP_FAILED;
dmcrypt_active = false;
}
removeDmNames();
}
return( ret );
}
Expand Down Expand Up @@ -2301,17 +2320,9 @@ int Volume::doCryptsetup()
dmcrypt_active = true;
unsigned long dummy, minor;
if (cType() == LOOP)
{
getMajorMinor();
minor = mnr;
replaceAltName( "/dev/dm-", Dm::dmDeviceName(mnr) );
}
else
{
storage::getMajorMinor( dmcrypt_dev, dummy, minor );
replaceAltName("/dev/dm-", Dm::dmDeviceName(minor));
}

storage::getMajorMinor( dmcrypt_dev, dummy, minor );
addDmNames(minor);
ProcParts parts;
unsigned long long sz;
if (parts.getSize( Dm::dmDeviceName(minor), sz))
Expand Down
2 changes: 2 additions & 0 deletions libstorage/src/Volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ class Storage;
bool getLoopFile( string& fname ) const;
void setExtError( const SystemCmd& cmd, bool serr=true );
string getDmcryptName() const;
void addDmNames(unsigned long minor);
void removeDmNames();
bool needLosetup( bool urgent ) const;
bool needCryptsetup() const;
int doLosetup();
Expand Down

0 comments on commit a527741

Please sign in to comment.