[cache_restore] --debug-override-metadata-version
A flag that deliberately causes the wrong metadata version to be written. Useful for testing the kernel module.
This commit is contained in:
parent
c92aff63e2
commit
f8633da296
@ -5,12 +5,14 @@
|
||||
#include "caching/xml_format.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <fstream>
|
||||
#include <getopt.h>
|
||||
#include <iostream>
|
||||
#include <libgen.h>
|
||||
#include <string>
|
||||
|
||||
using namespace boost;
|
||||
using namespace caching;
|
||||
using namespace persistent_data;
|
||||
using namespace std;
|
||||
@ -18,14 +20,31 @@ using namespace std;
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
int restore(string const &xml_file, string const &dev) {
|
||||
struct flags {
|
||||
flags()
|
||||
: metadata_version(1),
|
||||
override_metadata_version(false) {
|
||||
}
|
||||
|
||||
optional<string> input;
|
||||
optional<string> output;
|
||||
uint32_t metadata_version;
|
||||
bool override_metadata_version;
|
||||
};
|
||||
|
||||
int restore(flags const &fs) {
|
||||
try {
|
||||
block_manager<>::ptr bm = open_bm(dev, block_io<>::READ_WRITE);
|
||||
block_manager<>::ptr bm = open_bm(*fs.output, block_io<>::READ_WRITE);
|
||||
metadata::ptr md(new metadata(bm, metadata::CREATE));
|
||||
emitter::ptr restorer = create_restore_emitter(md);
|
||||
|
||||
check_file_exists(xml_file);
|
||||
ifstream in(xml_file.c_str(), ifstream::in);
|
||||
if (fs.override_metadata_version) {
|
||||
cerr << "overriding" << endl;
|
||||
md->sb_.version = fs.metadata_version;
|
||||
}
|
||||
|
||||
check_file_exists(*fs.input);
|
||||
ifstream in(fs.input->c_str(), ifstream::in);
|
||||
parse_xml(in, restorer);
|
||||
|
||||
} catch (std::exception &e) {
|
||||
@ -42,17 +61,21 @@ namespace {
|
||||
<< " {-h|--help}" << endl
|
||||
<< " {-i|--input} <input xml file>" << endl
|
||||
<< " {-o|--output} <output device or file>" << endl
|
||||
<< " {-V|--version}" << endl;
|
||||
<< " {-V|--version}" << endl
|
||||
<< endl
|
||||
<< " {--debug-override-metadata-version} <integer>" << endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c;
|
||||
string input, output;
|
||||
flags fs;
|
||||
char const *prog_name = basename(argv[0]);
|
||||
char const *short_opts = "hi:o:V";
|
||||
option const long_opts[] = {
|
||||
{ "debug-override-metadata-version", required_argument, NULL, 0 },
|
||||
{ "help", no_argument, NULL, 'h'},
|
||||
{ "input", required_argument, NULL, 'i' },
|
||||
{ "output", required_argument, NULL, 'o'},
|
||||
@ -62,16 +85,21 @@ int main(int argc, char **argv)
|
||||
|
||||
while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
|
||||
switch(c) {
|
||||
case 0:
|
||||
fs.metadata_version = lexical_cast<uint32_t>(optarg);
|
||||
fs.override_metadata_version = true;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
usage(cout, prog_name);
|
||||
return 0;
|
||||
|
||||
case 'i':
|
||||
input = optarg;
|
||||
fs.input = optional<string>(string(optarg));
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
output = optarg;
|
||||
fs.output = optional<string>(string(optarg));
|
||||
break;
|
||||
|
||||
case 'V':
|
||||
@ -89,20 +117,19 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (input.empty()) {
|
||||
if (!fs.input) {
|
||||
cerr << "No input file provided." << endl << endl;
|
||||
usage(cerr, prog_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (output.empty()) {
|
||||
if (!fs.output) {
|
||||
cerr << "No output file provided." << endl << endl;
|
||||
usage(cerr, prog_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return restore(input, output);
|
||||
return restore(fs);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace {
|
||||
|
||||
uint32_t const SUPERBLOCK_MAGIC = 06142003;
|
||||
uint32_t const VERSION_BEGIN = 1;
|
||||
uint32_t const VERSION_END = 3;
|
||||
uint32_t const VERSION_END = 2;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
@ -86,3 +86,9 @@ Feature: cache_check
|
||||
When I run `cache_check metadata.bin`
|
||||
Then it should pass
|
||||
|
||||
Scenario: Invalid metadata version causes a fail
|
||||
Given a small xml file
|
||||
And input file
|
||||
And I run cache_restore with -i metadata.xml -o input --debug-override-metadata-version 12345
|
||||
When I run `cache_check input`
|
||||
Then it should fail
|
||||
|
@ -9,7 +9,8 @@ Feature: thin_restore
|
||||
|
||||
Scenario: print help (-h)
|
||||
When I run cache_restore with -h
|
||||
Then it should pass with:
|
||||
Then it should pass
|
||||
And the output should contain exactly:
|
||||
|
||||
"""
|
||||
Usage: cache_restore [options]
|
||||
@ -18,11 +19,15 @@ Feature: thin_restore
|
||||
{-i|--input} <input xml file>
|
||||
{-o|--output} <output device or file>
|
||||
{-V|--version}
|
||||
|
||||
{--debug-override-metadata-version} <integer>
|
||||
|
||||
"""
|
||||
|
||||
Scenario: print help (--help)
|
||||
When I run cache_restore with -h
|
||||
Then it should pass with:
|
||||
Then it should pass
|
||||
And the output should contain exactly:
|
||||
|
||||
"""
|
||||
Usage: cache_restore [options]
|
||||
@ -31,6 +36,9 @@ Feature: thin_restore
|
||||
{-i|--input} <input xml file>
|
||||
{-o|--output} <output device or file>
|
||||
{-V|--version}
|
||||
|
||||
{--debug-override-metadata-version} <integer>
|
||||
|
||||
"""
|
||||
|
||||
Scenario: missing input file
|
||||
@ -53,9 +61,14 @@ Feature: thin_restore
|
||||
No output file provided.
|
||||
"""
|
||||
|
||||
@announce
|
||||
Scenario: successfully restores a valid xml file
|
||||
Given a small xml file
|
||||
And an empty dev file
|
||||
When I run cache_restore with -i metadata.xml -o metadata.bin
|
||||
Then it should pass
|
||||
|
||||
Scenario: accepts --debug-override-metadata-version
|
||||
Given a small xml file
|
||||
And an empty dev file
|
||||
When I run cache_restore with -i metadata.xml -o metadata.bin --debug-override-metadata-version 10298
|
||||
Then it should pass
|
||||
|
Loading…
Reference in New Issue
Block a user