Skip to content

Commit

Permalink
add code for detection and handling of thin provisioning in LVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Fehr committed Aug 23, 2012
1 parent 7b6513c commit 01f102c
Show file tree
Hide file tree
Showing 21 changed files with 979 additions and 253 deletions.
12 changes: 10 additions & 2 deletions libstorage/examples/Makefile.am
Expand Up @@ -9,7 +9,9 @@ LDADD = ../src/liby2storage.la

AM_CXXFLAGS =

noinst_PROGRAMS = TestDisk TestDiskLog TestStorage TestProbing TestLvm TestMd TestLoop TestLock SaveGraph ShowBytes
noinst_PROGRAMS = TestDisk TestDiskLog TestStorage TestProbing TestLvm TestMd TestLoop TestLock \
SaveGraph ShowBytes \
TestLvmSnap TestLvmStripe TestLvmThin

TestDisk_SOURCES = TestDisk.cc

Expand All @@ -21,6 +23,12 @@ TestProbing_SOURCES = TestProbing.cc

TestLvm_SOURCES = TestLvm.cc

TestLvmSnap_SOURCES = TestLvmSnap.cc

TestLvmThin_SOURCES = TestLvmThin.cc

TestLvmStripe_SOURCES = TestLvmStripe.cc

TestMd_SOURCES = TestMd.cc

TestLoop_SOURCES = TestLoop.cc
Expand All @@ -33,7 +41,7 @@ ShowBytes_SOURCES = ShowBytes.cc

exampledir = $(docdir)/examples/libstorage

example_DATA = TestDisk.cc TestDiskLog.cc TestProbing.cc TestLvm.cc TestMd.cc TestLoop.cc SaveGraph.cc ShowBytes.cc
example_DATA = TestDisk.cc TestDiskLog.cc TestProbing.cc TestLvm.cc TestLvmSnap.cc TestLvmStripe.cc TestLvmThin.cc TestMd.cc TestLoop.cc SaveGraph.cc ShowBytes.cc

EXTRA_DIST = $(example_DATA) Makefile.example

Expand Down
122 changes: 122 additions & 0 deletions libstorage/examples/TestLvmSnap.cc
@@ -0,0 +1,122 @@

#include <getopt.h>
#include <iostream>

#include <storage/StorageInterface.h>

using namespace storage;
using namespace std;

void progressbarCb( const string& id, unsigned cur, unsigned max )
{
cout << "PROGRESSBAR id:" << id << " cur:" << cur << " max:" << max << endl;
}

void installInfoCb( const string& info )
{
cout << "INFO " << info << endl;
}

void
printCommitActions(StorageInterface* s)
{
list<CommitInfo> l;
s->getCommitInfos(l);
for (list<CommitInfo>::iterator i=l.begin(); i!=l.end(); ++i)
cout << i->text << endl;
}

int doCommit( StorageInterface* s )
{
static int cnt = 1;

//printCommitActions( s );
int ret = s->commit();
if( ret ) cerr << "retcode:" << ret << endl;
if( ret==0 )
{
printCommitActions( s );
}
cnt++;
return( ret );
}

struct option long_options[] = {
{ "keep", 0, 0, 'k' },
{ 0, 0, 0, 0 }
};

#define VOL_NAME "zzz_volume"
#define SNAP_NAME "s_snapshot"

int
main( int argc, char** argv )
{
int ret = 0;
int c;
bool keep = false;
while( (c=getopt_long(argc, argv, "k", long_options, 0))!=EOF )
{
switch(c)
{
case 'k':
keep = true;
break;
default:
break;
}
}
StorageInterface* s = createStorageInterface(Environment(false));
s->setCallbackProgressBar( progressbarCb );
s->setCallbackShowInstallInfo( installInfoCb );
string device;
deque<string> devs;
devs.push_back("/dev/sdb8");
devs.push_back("/dev/sdb9");
if( ret==0 )
{
ret = s->createLvmVg( "testvg", 4*1024, false, devs );
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
ret = s->createLvmLv( "testvg", VOL_NAME, 1024*1024, 1, device );
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
ret = s->createLvmLvSnapshot( "testvg", VOL_NAME, SNAP_NAME, 300*1024, device );
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
ret = doCommit( s );
}
if( !keep )
{
if( ret==0 )
{
ret = s->removeLvmLv( "testvg", SNAP_NAME );
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
ret = s->removeLvmLv( "testvg", VOL_NAME );
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
ret = doCommit( s );
}
if( ret==0 )
{
ret = s->removeLvmVg( "testvg" );
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
ret = doCommit( s );
}
}
delete(s);
}
119 changes: 119 additions & 0 deletions libstorage/examples/TestLvmStripe.cc
@@ -0,0 +1,119 @@

#include <getopt.h>
#include <iostream>

#include <storage/StorageInterface.h>

using namespace storage;
using namespace std;

void progressbarCb( const string& id, unsigned cur, unsigned max )
{
cout << "PROGRESSBAR id:" << id << " cur:" << cur << " max:" << max << endl;
}

void installInfoCb( const string& info )
{
cout << "INFO " << info << endl;
}

void
printCommitActions(StorageInterface* s)
{
list<CommitInfo> l;
s->getCommitInfos(l);
for (list<CommitInfo>::iterator i=l.begin(); i!=l.end(); ++i)
cout << i->text << endl;
}

int doCommit( StorageInterface* s )
{
static int cnt = 1;

//printCommitActions( s );
int ret = s->commit();
if( ret ) cerr << "retcode:" << ret << endl;
if( ret==0 )
{
printCommitActions( s );
}
cnt++;
return( ret );
}

struct option long_options[] = {
{ "keep", 0, 0, 'k' },
{ 0, 0, 0, 0 }
};

int
main( int argc, char** argv )
{
int ret = 0;
int c;
bool keep = false;
while( (c=getopt_long(argc, argv, "k", long_options, 0))!=EOF )
{
switch(c)
{
case 'k':
keep = true;
break;
default:
break;
}
}
StorageInterface* s = createStorageInterface(Environment(false));
s->setCallbackProgressBar( progressbarCb );
s->setCallbackShowInstallInfo( installInfoCb );
string device;
deque<string> devs;
devs.push_back("/dev/sdb5");
devs.push_back("/dev/sdb6");
devs.push_back("/dev/sdb7");
devs.push_back("/dev/sdb8");
devs.push_back("/dev/sdb9");
if( ret==0 )
{
ret = s->createLvmVg( "testvg", 4*1024, false, devs );
if( ret ) cerr << "retcode:" << ret << endl;
}
const char * lvnames[] = { "aa", "bb", "cc", "dd", "ee" };
for( int i=0; i<5; ++i )
{
if( ret==0 )
{
ret = s->createLvmLv( "testvg", lvnames[i], 1024*1024, i+1, device );
if( ret ) cerr << "retcode:" << ret << endl;
}
}
if( ret==0 )
{
ret = doCommit( s );
}
if( !keep )
{
for( int i=0; i<5; ++i )
{
if( ret==0 )
{
ret = s->removeLvmLv( "testvg", lvnames[i] );
if( ret ) cerr << "retcode:" << ret << endl;
}
}
if( ret==0 )
{
ret = doCommit( s );
}
if( ret==0 )
{
ret = s->removeLvmVg( "testvg" );
if( ret ) cerr << "retcode:" << ret << endl;
}
if( ret==0 )
{
ret = doCommit( s );
}
}
delete(s);
}

0 comments on commit 01f102c

Please sign in to comment.