Author: aschnell
Date: Wed Aug 13 23:18:32 2008
New Revision: 50050
URL: http://svn.opensuse.org/viewcvs/yast?rev=50050&view=rev
Log:
- backup commit
Modified:
branches/tmp/aschnell/snapshots/libstorage/src/Dm.h
branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.cc
branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.h
branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.cc
branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.h
branches/tmp/aschnell/snapshots/libstorage/src/Storage.cc
branches/tmp/aschnell/snapshots/libstorage/src/Storage.h
branches/tmp/aschnell/snapshots/libstorage/src/StorageInterface.h
Modified: branches/tmp/aschnell/snapshots/libstorage/src/Dm.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/Dm.h?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/Dm.h (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/Dm.h Wed Aug 13 23:18:32 2008
@@ -27,7 +27,7 @@
void setLe( unsigned long long le );
void modifyPeSize( unsigned long long old, unsigned long long neww );
bool removeTable();
- void calcSize();
+ virtual void calcSize();
const std::map& getPeMap() const { return( pe_map ); }
void setPeMap( const std::map& m );
unsigned long long usingPe( const string& dev ) const;
Modified: branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.cc?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.cc (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.cc Wed Aug 13 23:18:32 2008
@@ -13,10 +13,13 @@
using namespace storage;
using namespace std;
-LvmLv::LvmLv( const LvmVg& d, const string& name, unsigned long le,
- const string& uuid, const string& stat, const string& alloc ) :
- Dm( d, dupDash(d.name())+"-"+dupDash(name) )
- {
+
+LvmLv::LvmLv(const LvmVg& d, const string& name, const string& origi,
+ unsigned long le, const string& uuid, const string& stat,
+ const string& alloc)
+ : Dm( d, dupDash(d.name())+"-"+dupDash(name) ),
+ origin(origi)
+{
init( name );
setUuid( uuid );
setStatus( stat );
@@ -24,28 +27,32 @@
setLe( le );
calcSize();
getTableInfo();
- y2debug( "constructed lvm lv %s on vg %s", dev.c_str(),
- cont->name().c_str() );
- }
-LvmLv::LvmLv( const LvmVg& d, const string& name, unsigned long le,
- unsigned str ) :
- Dm( d, dupDash(d.name())+"-"+dupDash(name) )
- {
+ y2deb("constructed lvm lv dev:" << dev << " vg:" << cont->name() << " origin:" << origin);
+}
+
+
+LvmLv::LvmLv(const LvmVg& d, const string& name, const string& origi,
+ unsigned long le, unsigned str)
+ : Dm( d, dupDash(d.name())+"-"+dupDash(name) ),
+ origin(origi)
+{
init( name );
setLe( le );
calcSize();
stripe = str;
fs = detected_fs = FSNONE;
alt_names.push_back( "/dev/mapper/" + dupDash(cont->name()) + "-" + dupDash(name) );
- y2debug( "constructed lvm lv %s on vg %s", dev.c_str(),
- cont->name().c_str() );
- }
+
+ y2deb("constructed lvm lv dev:" << dev << " vg:" << cont->name() << " origin:" << origin);
+}
+
LvmLv::~LvmLv()
- {
- y2debug( "destructed lvm lv %s", dev.c_str() );
- }
+{
+ y2deb("destructed lvm lv dev:" << dev);
+}
+
void LvmLv::init( const string& name )
{
@@ -54,6 +61,23 @@
Dm::init();
}
+
+void LvmLv::calcSize()
+{
+ if (origin.empty())
+ {
+ Dm::calcSize();
+ }
+ else
+ {
+ const Container* cont = getContainer();
+
+ // TODO: take size from origin
+ Dm::calcSize();
+ }
+}
+
+
string LvmLv::removeText( bool doing ) const
{
string txt;
@@ -219,6 +243,10 @@
info.allocation = allocation;
info.dm_table = tname;
info.dm_target = target;
+
+ info.sizeK = num_le * pec()->peSize();
+ info.origin = origin;
+
tinfo = info;
}
Modified: branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.h?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.h (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/LvmLv.h Wed Aug 13 23:18:32 2008
@@ -13,13 +13,19 @@
class LvmLv : public Dm
{
public:
- LvmLv( const LvmVg& d, const string& name, unsigned long le,
- const string& uuid, const string& status, const string& alloc );
- LvmLv( const LvmVg& d, const string& name, unsigned long le,
- unsigned stripe );
- LvmLv( const LvmVg& d, const LvmLv& l );
+ LvmLv(const LvmVg& d, const string& name, const string& origin, unsigned long le,
+ const string& uuid, const string& status, const string& alloc);
+ LvmLv(const LvmVg& d, const string& name, const string& origin, unsigned long le,
+ unsigned stripe);
+ LvmLv(const LvmVg& d, const LvmLv& l);
virtual ~LvmLv();
+
+ void calcSize();
+
+ void setOrigin( const string& o ) { origin=o; }
+ string getOrigin() const { return origin; }
+
void setUuid( const string& uuid ) { vol_uuid=uuid; }
void setStatus( const string& s ) { status=s; }
void setAlloc( const string& a ) { allocation=a; }
@@ -38,6 +44,8 @@
virtual const string shortPrintedName() const { return( "Lv" ); }
LvmLv& operator=( const LvmLv& );
+ string origin; // only for snapshots, empty otherwise
+
string vol_uuid;
string status;
string allocation;
Modified: branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.cc?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.cc (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.cc Wed Aug 13 23:18:32 2008
@@ -279,7 +279,7 @@
ret = addLvPeDistribution( num_le, stripe, pv, pv_add, pe_map );
if( ret==0 )
{
- LvmLv* l = new LvmLv( *this, name, num_le, stripe );
+ LvmLv* l = new LvmLv( *this, name, "", num_le, stripe );
l->setCreated( true );
l->setPeMap( pe_map );
device = l->device();
@@ -292,6 +292,7 @@
return( ret );
}
+// TODO: disallow for lv with snapshots and for snapshots
int LvmVg::resizeVolume( Volume* v, unsigned long long newSize )
{
int ret = 0;
@@ -359,6 +360,7 @@
return( removeLv( v->name() ));
}
+// TODO: disallow for lv with snapshots
int
LvmVg::removeLv( const string& name )
{
@@ -494,6 +496,84 @@
return( ret );
}
+
+int
+LvmVg::createLvSnapshot(const string& origin, const string& name,
+ unsigned long long cowSizeK, string& device)
+{
+ int ret = 0;
+ device.erase();
+ y2mil("origin:" << origin << " name:" << name << " cowSizeK:" << cowSizeK );
+ checkConsistency();
+ if (readonly())
+ {
+ ret = LVM_CHANGE_READONLY;
+ }
+ if (ret == 0 && name.find("\"\' /\n\t:*?") != string::npos)
+ {
+ ret = LVM_LV_INVALID_NAME;
+ }
+ int stripe = 1;
+ if (ret == 0)
+ {
+ LvmLvPair p = lvmLvPair(lvNotDeleted);
+ LvmLvIter i = p.begin();
+ while (i != p.end() && i->name() != origin)
+ ++i;
+ if (i == p.end())
+ ret = LVM_LV_UNKNOWN_ORIGIN;
+ else
+ stripe = i->stripes();
+ }
+ if (ret == 0)
+ {
+ LvmLvPair p = lvmLvPair(lvNotDeleted);
+ LvmLvIter i = p.begin();
+ while (i != p.end() && i->name() != name)
+ ++i;
+ if (i != p.end())
+ ret = LVM_LV_DUPLICATE_NAME;
+ }
+ unsigned long num_le = sizeToLe(cowSizeK);
+ if( stripe>1 )
+ num_le = ((num_le+stripe-1)/stripe)*stripe;
+ if (ret == 0 && free_pe < num_le)
+ {
+ ret = LVM_LV_NO_SPACE;
+ }
+ map pe_map;
+ if (ret == 0)
+ ret = addLvPeDistribution(num_le, stripe, pv, pv_add, pe_map);
+ if (ret == 0)
+ {
+ LvmLv* l = new LvmLv(*this, name, origin, num_le, stripe);
+ l->setCreated(true);
+ l->setPeMap(pe_map);
+ device = l->device();
+ free_pe -= num_le;
+ addToList(l);
+ }
+ if (ret == 0)
+ checkConsistency();
+ y2mil("ret:" << ret << " device:" << device);
+ return ret;
+}
+
+
+int
+LvmVg::removeLvSnapshot(const string& name)
+{
+ // TODO
+}
+
+
+int
+LvmVg::getLvSnapshotState(const string& name, LvmLvSnapshotStateInfo& info)
+{
+ // TODO
+}
+
+
void LvmVg::getVgData( const string& name, bool exists )
{
y2milestone( "name:%s", name.c_str() );
@@ -559,10 +639,12 @@
line = *c.getLine( i++ );
}
string vname;
+ string origin;
string uuid;
string status;
string allocation;
unsigned long num_le = 0;
+ unsigned long num_cow_le = 0;
bool readOnly = false;
while( line.find( "Physical volume" )==string::npos && i> num_le;
}
+ else if (line.find( "COW-table LE" ) == 0)
+ {
+ extractNthWord( 2, line ) >> num_cow_le;
+ }
else if( line.find( "Allocation" ) == 0 )
{
allocation = extractNthWord( 1, line );
@@ -601,9 +694,9 @@
line = *c.getLine( i++ );
}
if( !vname.empty() )
- {
- addLv( num_le, vname, uuid, status, allocation, readOnly );
- }
+ {
+ addLv(origin.empty() ? num_le : num_cow_le, vname, origin, uuid, status, allocation, readOnly);
+ }
Pv *p = new Pv;
while( isetLe( le );
if( i->created() )
@@ -705,6 +798,7 @@
}
i->setUuid( uuid );
i->setStatus( status );
+ i->setOrigin( origin );
i->setAlloc( alloc );
i->getTableInfo();
i->updateMajorMinor();
@@ -722,7 +816,7 @@
if( i==p.end() )
{
num_lv++;
- LvmLv *n = new LvmLv( *this, name, le, uuid, status, alloc );
+ LvmLv *n = new LvmLv( *this, name, origin, le, uuid, status, alloc );
if( ro )
n->setReadonly();
if( !n->inactive() )
@@ -734,11 +828,12 @@
}
}
}
- name = uuid = status = alloc = "";
+ name = origin = uuid = status = alloc = "";
le = 0;
ro = false;
}
+
void LvmVg::addPv( Pv*& p )
{
PeContainer::addPv( p );
@@ -1177,14 +1272,23 @@
}
checkConsistency();
string cmd = LVCREATEBIN " " + instSysString() + " -l " + decString(l->getLe());
- if( l->stripes()>1 )
+ if (l->getOrigin().empty())
+ {
+ if( l->stripes()>1 )
{
- cmd += " -i " + decString(l->stripes());
- if( l->stripeSize()>0 )
- cmd += " -I " + decString(l->stripeSize());
+ cmd += " -i " + decString(l->stripes());
+ if( l->stripeSize()>0 )
+ cmd += " -I " + decString(l->stripeSize());
}
- cmd += " -n " + quote(l->name());
- cmd += " " + quote(name());
+ cmd += " --name " + quote(l->name());
+ cmd += " " + quote(name());
+ }
+ else
+ {
+ cmd += " --snapshot";
+ cmd += " --name " + quote(l->name());
+ cmd += " " + quote(name() + "/" + l->getOrigin());
+ }
SystemCmd c( cmd );
if( c.retcode()!=0 )
{
Modified: branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.h?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.h (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/LvmVg.h Wed Aug 13 23:18:32 2008
@@ -34,6 +34,11 @@
int changeStripeSize( const string& name,
unsigned long long stripeSize );
+ int createLvSnapshot(const string& origin, const string& name,
+ unsigned long long cowSizeK, string& device);
+ int removeLvSnapshot(const string& name);
+ int getLvSnapshotState(const string& name, LvmLvSnapshotStateInfo& info);
+
int setPeSize( long long unsigned peSizeK );
void normalizeDmDevices();
void getCommitActions( std::liststorage::commitAction*& l ) const;
@@ -124,8 +129,8 @@
string instSysString();
void logData( const string& Dir );
- void addLv( unsigned long& le, string& name, string& uuid,
- string& status, string& alloc, bool& ro );
+ void addLv(unsigned long& le, string& name, string& origin, string& uuid,
+ string& status, string& alloc, bool& ro);
void addPv( Pv*& p );
string status;
Modified: branches/tmp/aschnell/snapshots/libstorage/src/Storage.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/Storage.cc?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/Storage.cc (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/Storage.cc Wed Aug 13 23:18:32 2008
@@ -2741,6 +2741,90 @@
int
+Storage::createLvmLvSnapshot(const string& vg, const string& origin,
+ const string& name, unsigned long long cowSizeK,
+ string& device)
+{
+ int ret = 0;
+ device.erase();
+ assertInit();
+ y2mil("vg:" << vg << " origin:" << origin << " name:" << name << " cowSizeK:" << cowSizeK);
+ LvmVgIterator i = findLvmVg(vg);
+ if (readonly)
+ {
+ ret = STORAGE_CHANGE_READONLY;
+ }
+ else if (i != lvgEnd())
+ {
+ ret = i->createLvSnapshot(origin, name, cowSizeK, device);
+ }
+ else
+ {
+ ret = STORAGE_LVM_VG_NOT_FOUND;
+ }
+ if (ret == 0)
+ {
+ ret = checkCache();
+ }
+ y2mil("ret:" << ret << " device:" << device);
+ return ret;
+}
+
+
+int
+Storage::removeLvmLvSnapshot(const string& vg, const string& name)
+{
+ int ret = 0;
+ assertInit();
+ y2mil("vg:" << vg << " name:" << name);
+ LvmVgIterator i = findLvmVg(vg);
+ if (readonly)
+ {
+ ret = STORAGE_CHANGE_READONLY;
+ }
+ else if (i != lvgEnd())
+ {
+ ret = i->removeLvSnapshot(name);
+ }
+ else
+ {
+ ret = STORAGE_LVM_VG_NOT_FOUND;
+ }
+ if (ret == 0)
+ {
+ ret = checkCache();
+ }
+ y2mil("ret:" << ret);
+ return ret;
+}
+
+
+int
+Storage::getLvmLvSnapshotStateInfo(const string& vg, const string& name,
+ LvmLvSnapshotStateInfo& info)
+{
+ int ret = 0;
+ assertInit();
+ y2mil("vg:" << vg << " name:" << name);
+ LvmVgIterator i = findLvmVg(vg);
+ if (i != lvgEnd())
+ {
+ ret = i->getLvSnapshotState(name, info);
+ }
+ else
+ {
+ ret = STORAGE_LVM_VG_NOT_FOUND;
+ }
+ if (ret == 0)
+ {
+ ret = checkCache();
+ }
+ y2mil("ret:" << ret);
+ return ret;
+}
+
+
+int
Storage::nextFreeMd(int &nr, string &device)
{
int ret = 0;
Modified: branches/tmp/aschnell/snapshots/libstorage/src/Storage.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/Storage.h?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/Storage.h (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/Storage.h Wed Aug 13 23:18:32 2008
@@ -396,6 +396,13 @@
int changeLvStripeSize( const string& vg, const string& name,
unsigned long long stripeSize );
+ int createLvmLvSnapshot(const string& vg, const string& origin,
+ const string& name, unsigned long long cowSizeK,
+ string& device);
+ int removeLvmLvSnapshot(const string& vg, const string& name);
+ int getLvmLvSnapshotStateInfo(const string& vg, const string& name,
+ LvmLvSnapshotStateInfo& info);
+
int nextFreeMd(int &nr, string &device);
int createMd( const string& name, storage::MdType rtype,
const deque<string>& devs );
Modified: branches/tmp/aschnell/snapshots/libstorage/src/StorageInterface.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/snapshots/libstorage/src/StorageInterface.h?rev=50050&r1=50049&r2=50050&view=diff
==============================================================================
--- branches/tmp/aschnell/snapshots/libstorage/src/StorageInterface.h (original)
+++ branches/tmp/aschnell/snapshots/libstorage/src/StorageInterface.h Wed Aug 13 23:18:32 2008
@@ -310,6 +310,18 @@
string allocation;
string dm_table;
string dm_target;
+ string origin; // only for snapshots, otherwise empty
+ unsigned long long sizeK;
+ };
+
+ /**
+ *
+ */
+ struct LvmLvSnapshotStateInfo
+ {
+ LvmLvSnapshotStateInfo() {}
+ bool active;
+ double allocated;
};
/**
@@ -554,6 +566,7 @@
LVM_LV_REMOVE_USED_BY = -4025,
LVM_LV_ALREADY_ON_DISK = -4026,
LVM_LV_NO_STRIPE_SIZE = -4027,
+ LVM_LV_UNKNOWN_ORIGIN = -4028,
FSTAB_ENTRY_NOT_FOUND = -5000,
FSTAB_CHANGE_PREFIX_IMPOSSIBLE = -5001,
@@ -1481,6 +1494,24 @@
unsigned long long stripeSize ) = 0;
/**
+ *
+ */
+ virtual int createLvmLvSnapshot(const string& vg, const string& origin,
+ const string& name, unsigned long long cowSizeK,
+ string& device) = 0;
+
+ /**
+ *
+ */
+ virtual int removeLvmLvSnapshot(const string& vg, const string& name) = 0;
+
+ /**
+ *
+ */
+ virtual int getLvmLvSnapshotStateInfo(const string& vg, const string& name,
+ LvmLvSnapshotStateInfo& info) = 0;
+
+ /**
* Determine the device name of the next created software raid device
*
* @param nr is set to the number of the next created software raid device
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org