Beginning to work

This commit is contained in:
Joe Thornber
2014-07-25 16:14:24 +01:00
parent 7e870ea5a6
commit 11469a2fda
5 changed files with 79 additions and 268 deletions

View File

@@ -10,6 +10,7 @@
#include <unistd.h>
#include <iostream>
#include <stdexcept>
//----------------------------------------------------------------
@@ -176,7 +177,6 @@ namespace bcache {
int
block_cache::issue_read(block &b)
{
std::cerr << "issuing read - that's a shame: " << b.index_ << "\n";
assert(!test_flags(b, IO_PENDING));
return issue_low_level(b, IO_CMD_PREAD, "read");
}
@@ -359,7 +359,7 @@ namespace bcache {
if (!b) {
if (list_empty(&clean_)) {
if (list_empty(&io_pending_))
writeback(9000);
writeback(16);
wait_io();
}
@@ -566,7 +566,6 @@ namespace bcache {
{
block *b, *tmp;
std::cerr << "in flush\n";
list_for_each_entry_safe (b, tmp, &dirty_, list_) {
if (b->ref_count_ || test_flags(*b, IO_PENDING))
// The superblock may well be still locked.
@@ -575,9 +574,7 @@ namespace bcache {
issue_write(*b);
}
std::cerr << "issued all writes\n";
wait_all();
std::cerr << "wait all returned\n";
return list_empty(&errored_) ? 0 : -EIO;
}

View File

@@ -1,7 +1,6 @@
#ifndef BLOCK_CACHE_H
#define BLOCK_CACHE_H
#include "block-cache/buffer.h"
#include "block-cache/list.h"
#include <boost/shared_ptr.hpp>

View File

@@ -1,94 +0,0 @@
// Copyright (C) 2013 Red Hat, Inc. All rights reserved.
//
// This file is part of the thin-provisioning-tools source.
//
// thin-provisioning-tools is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// thin-provisioning-tools is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>.
#ifndef BUFFER_H
#define BUFFER_H
#include <stdint.h>
#include <malloc.h>
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/static_assert.hpp>
#include <stdexcept>
//----------------------------------------------------------------
namespace bcache {
uint32_t const DEFAULT_BUFFER_SIZE = 4096;
template <uint32_t Size = DEFAULT_BUFFER_SIZE>
class buffer {
public:
buffer(void *data, bool writeable = true)
: data_(static_cast<unsigned char *>(data)),
writeable_(writeable) {
}
typedef boost::shared_ptr<buffer> ptr;
typedef boost::shared_ptr<buffer const> const_ptr;
size_t size() const {
return Size;
}
unsigned char &operator[](unsigned index) {
check_writeable();
check_index(index);
return data_[index];
}
unsigned char const &operator[](unsigned index) const {
check_index(index);
return data_[index];
}
unsigned char *raw() {
return data_;
}
unsigned char const *raw() const {
return data_;
}
void set_data(void *data) {
data_ = static_cast<unsigned char *>(data);
}
private:
static void check_index(unsigned index) {
if (index >= Size)
throw std::range_error("buffer index out of bounds");
}
void check_writeable() const {
if (!writeable_)
throw std::runtime_error("buffer isn't writeable");
}
unsigned char *data_;
bool writeable_;
};
}
//----------------------------------------------------------------
#endif