thin_metadata_t now reproduces the recursive new_block() error.

This commit is contained in:
Joe Thornber 2013-04-11 13:41:43 +01:00
parent 3629e1e2b5
commit dde775ef52
4 changed files with 74 additions and 1 deletions

View File

@ -41,7 +41,7 @@ PDATA_SOURCE=\
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc
PDATA_OBJECTS=$(subst .cc,.o,$(PDATA_SOURCE))
#PDATA_OBJECTS=$(subst .cc,.o,$(PDATA_SOURCE))
SOURCE=\
$(PDATA_SOURCE) \
@ -56,6 +56,7 @@ SOURCE=\
thin-provisioning/restore_emitter.cc \
thin-provisioning/thin_pool.cc \
thin-provisioning/xml_format.cc
PDATA_OBJECTS=$(subst .cc,.o,$(SOURCE))
PROGRAM_SOURCE=\
cache/check.cc \

View File

@ -83,6 +83,7 @@ namespace {
::close(fd);
nr_blocks = div_down<block_address>(nr_blocks, MD_BLOCK_SIZE);
} else
// FIXME: needs a better message
throw runtime_error("bad path");
return nr_blocks;

View File

@ -50,6 +50,7 @@ TEST_SOURCE=\
unit-tests/cache_t.cc \
unit-tests/endian_t.cc \
unit-tests/space_map_t.cc \
unit-tests/thin_metadata_t.cc \
unit-tests/transaction_manager_t.cc
TEST_OBJECTS=$(subst .cc,.gmo,$(TEST_SOURCE))

View File

@ -0,0 +1,70 @@
#include "gmock/gmock.h"
#include "thin-provisioning/metadata.h"
#include <errno.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
using namespace std;
using namespace persistent_data;
using namespace testing;
using namespace thin_provisioning;
//----------------------------------------------------------------
namespace {
void rm_f(string path) {
struct stat info;
int r = ::stat(path.c_str(), &info);
if (r) {
if (errno == ENOENT)
return;
else {
cerr << "errno == " << errno << endl;
throw runtime_error("stat failed");
}
}
if (!S_ISREG(info.st_mode))
throw runtime_error("path isn't a file");
::unlink(path.c_str());
}
// FIXME: duplication with block.tcc, factor out a file_utils unit
void create_sized_file(string const &path, uint64_t file_size) {
int fd = ::open(path.c_str(), O_CREAT | O_TRUNC | O_RDWR, 0666);
if (fd < 0)
throw runtime_error("open_file failed");
int r = ::lseek(fd, file_size - 1, SEEK_SET);
if (r < 0)
throw runtime_error("lseek failed");
char c = '\0';
r = ::write(fd, &c, 1);
if (r < 0)
throw runtime_error("::write failed");
if (r != 1)
throw runtime_error("insufficient bytes written");
::close(fd);
}
}
//----------------------------------------------------------------
TEST(ThinMetadataTests, create)
{
string path("./metadata.bin");
rm_f(path);
create_sized_file(path, 4096 * 1024);
metadata::ptr md(new metadata(path, metadata::CREATE, 128, 102400));
}