2015-08-24 21:25:53 +05:30
|
|
|
#ifndef THIN_PROVISIONING_CACHE_STREAM_H
|
|
|
|
#define THIN_PROVISIONING_CACHE_STREAM_H
|
|
|
|
|
|
|
|
#include "thin-provisioning/chunk_stream.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace thin_provisioning {
|
|
|
|
using namespace bcache;
|
|
|
|
|
|
|
|
class cache_stream : public chunk_stream {
|
|
|
|
public:
|
|
|
|
cache_stream(std::string const &path,
|
|
|
|
block_address block_size,
|
|
|
|
size_t cache_mem);
|
|
|
|
|
2015-09-04 19:46:49 +05:30
|
|
|
block_address size() const;
|
2015-09-03 17:32:29 +05:30
|
|
|
|
2015-08-24 21:25:53 +05:30
|
|
|
virtual void rewind();
|
2015-09-03 17:32:29 +05:30
|
|
|
|
|
|
|
virtual bool next(block_address count = 1ull);
|
|
|
|
virtual bool eof() const;
|
|
|
|
|
|
|
|
virtual chunk const &get();
|
|
|
|
virtual void put(chunk const &c);
|
2015-08-24 21:25:53 +05:30
|
|
|
|
|
|
|
private:
|
2015-09-03 17:32:29 +05:30
|
|
|
struct chunk_wrapper {
|
|
|
|
chunk_wrapper(cache_stream &parent);
|
|
|
|
|
|
|
|
block_cache::auto_block block_;
|
|
|
|
chunk c_;
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class chunk_wrapper;
|
2015-08-24 21:25:53 +05:30
|
|
|
|
|
|
|
block_address block_size_;
|
|
|
|
block_address nr_blocks_;
|
|
|
|
block_address cache_blocks_;
|
2015-09-03 17:32:29 +05:30
|
|
|
|
2015-08-24 21:25:53 +05:30
|
|
|
int fd_;
|
|
|
|
validator::ptr v_;
|
2017-03-13 18:50:52 +05:30
|
|
|
std::unique_ptr<block_cache> cache_;
|
2015-08-24 21:25:53 +05:30
|
|
|
|
|
|
|
block_address current_index_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|