Skip to content

Commit

Permalink
Storable options is almost done
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad1mir-D committed Jan 18, 2015
1 parent 414dfcd commit 2f73676
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 160 deletions.
4 changes: 2 additions & 2 deletions backup_collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class BundleCollector: public IndexProcessor
}

ZCollector::ZCollector( string const & storageDir, string const & password,
Config & inConfig ):
ZBackupBase( storageDir, password, inConfig ),
Config & configIn ):
ZBackupBase( storageDir, password, configIn ),
chunkStorageReader( storageInfo, encryptionkey, chunkIndex, getBundlesPath(),
config.runtime.cacheSize )
{
Expand Down
2 changes: 1 addition & 1 deletion backup_collector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ZCollector : public ZBackupBase

public:
ZCollector( std::string const & storageDir, std::string const & password,
Config & inConfig );
Config & configIn );

void gc();
};
Expand Down
1 change: 0 additions & 1 deletion backup_exchanger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <string>
#include <vector>
#include "sptr.hh"
#include "tmp_mgr.hh"

namespace BackupExchanger {
Expand Down
2 changes: 1 addition & 1 deletion bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void Creator::write( std::string const & fileName, EncryptionKey const & key )

BundleFileHeader header;

const_sptr<Compression::CompressionMethod> compression = Compression::CompressionMethod::defaultCompression;
const_sptr<Compression::CompressionMethod> compression = Compression::CompressionMethod::selectedCompression;
header.set_compression_method( compression->getName() );

// The old code only support lzma, so we will bump up the version, if we're
Expand Down
2 changes: 1 addition & 1 deletion compression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ static const_sptr<CompressionMethod> const compressions[] = {
NULL
};

const_sptr<CompressionMethod> CompressionMethod::defaultCompression = compressions[0];
const_sptr<CompressionMethod> CompressionMethod::selectedCompression = compressions[0];

const_sptr<CompressionMethod> CompressionMethod::findCompression( const std::string& name, bool optional )
{
Expand Down
2 changes: 1 addition & 1 deletion compression.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public:
static const_sptr<CompressionMethod> findCompression(
const std::string& name, bool optional = false );

static const_sptr<CompressionMethod> defaultCompression;
static const_sptr<CompressionMethod> selectedCompression;

class iterator
{
Expand Down
88 changes: 85 additions & 3 deletions config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ex.hh"
#include "debug.hh"
#include "utils.hh"
#include "compression.hh"

#define VALID_SUFFIXES "Valid suffixes:\n" \
"B - multiply by 1 (bytes)\n" \
Expand Down Expand Up @@ -46,7 +47,8 @@ static struct
"Maximum number of bytes a bundle can hold. Only real chunk bytes are\n"
"counted, not metadata. Any bundle should be able to contain at least\n"
"one arbitrary single chunk, so this should not be smaller than\n"
"chunk.max_size" },
"chunk.max_size"
},
{
"bundle.compression_method",
Config::oBundle_compression_method,
Expand Down Expand Up @@ -81,6 +83,18 @@ static struct
"Default is %sMiB",
Utils::numberToString( defaultConfig.runtime.cacheSize / 1024 / 1024 )
},
{
"exchange",
Config::oRuntime_exchange,
Config::Runtime,
"Data to exchange between repositories in import/export process\n"
"Can be specified multiple times\n"
"Valid values:\n"
"backups - exchange backup instructions (files in backups/ directory)\n"
"bundles - exchange bundles with data (files in bunles/ directory)\n"
"index - exchange indicies of chunks (files in index/ directory)\n"
"No default value, you should specify it explicitly"
},

{ NULL, Config::oBadOption, Config::None }
};
Expand Down Expand Up @@ -138,6 +152,48 @@ bool Config::parseOption( const char * option, const OptionType type )

switch ( opcode )
{
case oBundle_compression_method:
if ( !hasValue )
return false;

if ( strcmp( optionValue, "lzma" ) == 0 )
{
const_sptr< Compression::CompressionMethod > lzma =
Compression::CompressionMethod::findCompression( "lzma" );
if ( !lzma )
{
fprintf( stderr, "zbackup is compiled without LZMA support, but the code "
"would support it. If you install liblzma (including development files) "
"and recompile zbackup, you can use LZMA.\n" );
return false;
}
Compression::CompressionMethod::selectedCompression = lzma;
}
else
if ( strcmp( optionValue, "lzo" ) == 0 )
{
const_sptr< Compression::CompressionMethod > lzo =
Compression::CompressionMethod::findCompression( "lzo1x_1" );
if ( !lzo )
{
fprintf( stderr, "zbackup is compiled without LZO support, but the code "
"would support it. If you install liblzo2 (including development files) "
"and recompile zbackup, you can use LZO.\n" );
return false;
}
Compression::CompressionMethod::selectedCompression = lzo;
}
else
{
fprintf( stderr, "zbackup doesn't support compression method '%s'. You may need a newer version.\n",
optionValue );
return false;
}

return true;
/* NOTREACHED */
break;

case oRuntime_threads:
if ( !hasValue )
return false;
Expand All @@ -148,7 +204,7 @@ bool Config::parseOption( const char * option, const OptionType type )
throw exInvalidThreadsValue( optionValue );
runtime.threads = sizeValue;

dPrintf( "runtime[threads]: %zu\n", runtime.threads );
dPrintf( "runtime[threads] = %zu\n", runtime.threads );

return true;
/* NOTREACHED */
Expand Down Expand Up @@ -216,14 +272,40 @@ bool Config::parseOption( const char * option, const OptionType type )
}
runtime.cacheSize = sizeValue * scale;

dPrintf( "runtime[cacheSize]: %zu\n", runtime.cacheSize );
dPrintf( "runtime[cacheSize] = %zu\n", runtime.cacheSize );

return true;
}
return false;
/* NOTREACHED */
break;

case oRuntime_exchange:
if ( !hasValue )
return false;

if ( strcmp( optionValue, "backups" ) == 0 )
runtime.exchange.set( BackupExchanger::backups );
else
if ( strcmp( optionValue, "bundles" ) == 0 )
runtime.exchange.set( BackupExchanger::bundles );
else
if ( strcmp( optionValue, "index" ) == 0 )
runtime.exchange.set( BackupExchanger::index );
else
{
fprintf( stderr, "Invalid exchange value specified: %s\n"
"Must be one of the following: backups, bundles, index\n",
optionValue );
return false;
}

dPrintf( "runtime[exchange] = %s\n", runtime.exchange.to_string().c_str() );

return true;
/* NOTREACHED */
break;

case oBadOption:
default:
return false;
Expand Down
5 changes: 5 additions & 0 deletions config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#define CONFIG_HH_INCLUDED__

#include <string>
#include <bitset>
#include <google/protobuf/text_format.h>
#include "zbackup.pb.h"
#include "mt.hh"
#include "backup_exchanger.hh"

using std::string;
using std::bitset;

class Config
{
Expand All @@ -18,6 +21,7 @@ public:
{
size_t threads;
size_t cacheSize;
bitset< BackupExchanger::Flags > exchange;

// Default runtime config
RuntimeConfig():
Expand Down Expand Up @@ -47,6 +51,7 @@ public:

oRuntime_threads,
oRuntime_cacheSize,
oRuntime_exchange,

oDeprecated, oUnsupported
} OpCodes;
Expand Down
Loading

0 comments on commit 2f73676

Please sign in to comment.