mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 04:50:31 -04:00
metadata_v2: implement get_chunks
This commit is contained in:
parent
6dad327913
commit
9af2fb078f
@ -32,6 +32,7 @@
|
|||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
#include <boost/range/irange.hpp>
|
#include <boost/range/irange.hpp>
|
||||||
|
|
||||||
#include <folly/Expected.h>
|
#include <folly/Expected.h>
|
||||||
@ -84,6 +85,77 @@ class directory_view
|
|||||||
meta_;
|
meta_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using chunk_view = ::apache::thrift::frozen::View<thrift::metadata::chunk>;
|
||||||
|
|
||||||
|
class chunk_range {
|
||||||
|
public:
|
||||||
|
class iterator
|
||||||
|
: public boost::iterator_facade<iterator, chunk_view const,
|
||||||
|
boost::random_access_traversal_tag> {
|
||||||
|
public:
|
||||||
|
iterator() = default;
|
||||||
|
|
||||||
|
iterator(::apache::thrift::frozen::MappedFrozen<
|
||||||
|
thrift::metadata::metadata> const* meta,
|
||||||
|
uint32_t it)
|
||||||
|
: meta_(meta)
|
||||||
|
, it_(it) {}
|
||||||
|
|
||||||
|
iterator(iterator const& other)
|
||||||
|
: meta_(other.meta_)
|
||||||
|
, it_(other.it_) {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class boost::iterator_core_access;
|
||||||
|
|
||||||
|
bool equal(iterator const& other) const {
|
||||||
|
return meta_ == other.meta_ && it_ == other.it_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void increment() { ++it_; }
|
||||||
|
|
||||||
|
void decrement() { --it_; }
|
||||||
|
|
||||||
|
void advance(difference_type n) { it_ += n; }
|
||||||
|
|
||||||
|
difference_type distance_to(iterator const& other) const {
|
||||||
|
return static_cast<difference_type>(other.it_) -
|
||||||
|
static_cast<difference_type>(it_);
|
||||||
|
}
|
||||||
|
|
||||||
|
chunk_view const& dereference() const {
|
||||||
|
view_ = meta_->chunks()[it_];
|
||||||
|
return view_;
|
||||||
|
}
|
||||||
|
|
||||||
|
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata> const*
|
||||||
|
meta_;
|
||||||
|
uint32_t it_{0};
|
||||||
|
mutable chunk_view view_;
|
||||||
|
};
|
||||||
|
|
||||||
|
chunk_range(::apache::thrift::frozen::MappedFrozen<
|
||||||
|
thrift::metadata::metadata> const* meta,
|
||||||
|
uint32_t begin, uint32_t end)
|
||||||
|
: meta_(meta)
|
||||||
|
, begin_(begin)
|
||||||
|
, end_(end) {}
|
||||||
|
|
||||||
|
iterator begin() const { return iterator(meta_, begin_); }
|
||||||
|
|
||||||
|
iterator end() const { return iterator(meta_, end_); }
|
||||||
|
|
||||||
|
size_t size() const { return end_ - begin_; }
|
||||||
|
|
||||||
|
bool empty() const { return end_ == begin_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata> const*
|
||||||
|
meta_;
|
||||||
|
uint32_t begin_{0};
|
||||||
|
uint32_t end_{0};
|
||||||
|
};
|
||||||
|
|
||||||
class metadata_v2 {
|
class metadata_v2 {
|
||||||
public:
|
public:
|
||||||
metadata_v2() = default;
|
metadata_v2() = default;
|
||||||
@ -150,15 +222,9 @@ class metadata_v2 {
|
|||||||
|
|
||||||
int statvfs(struct ::statvfs* stbuf) const { return impl_->statvfs(stbuf); }
|
int statvfs(struct ::statvfs* stbuf) const { return impl_->statvfs(stbuf); }
|
||||||
|
|
||||||
#if 0
|
std::optional<chunk_range> get_chunks(int inode) const {
|
||||||
size_t block_size() const { return impl_->block_size(); }
|
return impl_->get_chunks(inode);
|
||||||
|
|
||||||
unsigned block_size_bits() const { return impl_->block_size_bits(); }
|
|
||||||
|
|
||||||
const chunk_type* get_chunks(int inode, size_t& num) const {
|
|
||||||
return impl_->get_chunks(inode, num);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
class impl {
|
class impl {
|
||||||
public:
|
public:
|
||||||
@ -199,11 +265,7 @@ class metadata_v2 {
|
|||||||
|
|
||||||
virtual int statvfs(struct ::statvfs* stbuf) const = 0;
|
virtual int statvfs(struct ::statvfs* stbuf) const = 0;
|
||||||
|
|
||||||
#if 0
|
virtual std::optional<chunk_range> get_chunks(int inode) const = 0;
|
||||||
virtual size_t block_size() const = 0;
|
|
||||||
virtual unsigned block_size_bits() const = 0;
|
|
||||||
virtual const chunk_type* get_chunks(int inode, size_t& num) const = 0;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include <folly/Format.h>
|
#include <folly/Format.h>
|
||||||
|
#include <folly/container/Enumerate.h>
|
||||||
|
|
||||||
#include "dwarfs/block_cache.h"
|
#include "dwarfs/block_cache.h"
|
||||||
#include "dwarfs/config.h"
|
#include "dwarfs/config.h"
|
||||||
@ -199,11 +200,17 @@ void filesystem_<LoggerPolicy>::dump(std::ostream& os) const {
|
|||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
void filesystem_<LoggerPolicy>::dump_v2(std::ostream& os) const {
|
void filesystem_<LoggerPolicy>::dump_v2(std::ostream& os) const {
|
||||||
meta_v2_.dump(os, [&](const std::string& indent, uint32_t inode) {
|
meta_v2_.dump(os, [&](const std::string& indent, uint32_t inode) {
|
||||||
size_t num = 0;
|
auto chunks = meta_v2_.get_chunks(inode);
|
||||||
const chunk_type* chunk = meta_.get_chunks(inode, num); // TODO
|
|
||||||
|
|
||||||
os << indent << num << " chunks in inode " << inode << "\n";
|
if (chunks) {
|
||||||
ir_.dump(os, indent + " ", chunk, num);
|
os << indent << chunks->size() << " chunks in inode " << inode << "\n";
|
||||||
|
for (auto chunk : folly::enumerate(*chunks)) {
|
||||||
|
os << indent << " [" << chunk.index << "] -> (" << chunk->block()
|
||||||
|
<< ", " << chunk->offset() << ", " << chunk->size() << ")\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ir_.dump(os, indent + " ", chunk, num); // TODO
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,15 +125,7 @@ class metadata_v2_ : public metadata_v2::impl {
|
|||||||
|
|
||||||
int statvfs(struct ::statvfs* stbuf) const override;
|
int statvfs(struct ::statvfs* stbuf) const override;
|
||||||
|
|
||||||
#if 0
|
std::optional<chunk_range> get_chunks(int inode) const override;
|
||||||
size_t block_size() const override {
|
|
||||||
return static_cast<size_t>(1) << cfg_->block_size_bits;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned block_size_bits() const override { return cfg_->block_size_bits; }
|
|
||||||
|
|
||||||
const chunk_type* get_chunks(int inode, size_t& num) const override;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
entry_view make_entry_view(size_t index) const {
|
entry_view make_entry_view(size_t index) const {
|
||||||
@ -189,7 +181,7 @@ class metadata_v2_ : public metadata_v2::impl {
|
|||||||
std::optional<entry_view> get_entry(int inode) const {
|
std::optional<entry_view> get_entry(int inode) const {
|
||||||
inode -= inode_offset_;
|
inode -= inode_offset_;
|
||||||
std::optional<entry_view> rv;
|
std::optional<entry_view> rv;
|
||||||
if (inode >= 0 && inode < int(meta_.entry_index().size())) {
|
if (inode >= 0 && inode < static_cast<int>(meta_.entry_index().size())) {
|
||||||
rv = make_entry_view_from_inode(inode);
|
rv = make_entry_view_from_inode(inode);
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
@ -200,12 +192,6 @@ class metadata_v2_ : public metadata_v2::impl {
|
|||||||
.links()[meta_.link_index()[entry.inode()] - meta_.link_index_offset()];
|
.links()[meta_.link_index()[entry.inode()] - meta_.link_index_offset()];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
const char* linkptr(entry_view entry) const {
|
|
||||||
return as<char>(entry->u.offset + sizeof(uint16_t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::vector<uint8_t> data_;
|
std::vector<uint8_t> data_;
|
||||||
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata> meta_;
|
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata> meta_;
|
||||||
entry_view root_;
|
entry_view root_;
|
||||||
@ -249,7 +235,7 @@ void metadata_v2_<LoggerPolicy>::dump(
|
|||||||
auto count = dir.entry_count();
|
auto count = dir.entry_count();
|
||||||
auto first = dir.first_entry();
|
auto first = dir.first_entry();
|
||||||
|
|
||||||
os << indent << "(" << count << ") entries [" << dir.self_inode() << ":"
|
os << "(" << count << " entries) [" << dir.self_inode() << ", "
|
||||||
<< dir.parent_inode() << "]\n";
|
<< dir.parent_inode() << "]\n";
|
||||||
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
@ -505,22 +491,20 @@ int metadata_v2_<LoggerPolicy>::statvfs(struct ::statvfs* stbuf) const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
const chunk_type*
|
std::optional<chunk_range>
|
||||||
metadata_v2_<LoggerPolicy>::get_chunks(int inode, size_t& num) const {
|
metadata_v2_<LoggerPolicy>::get_chunks(int inode) const {
|
||||||
inode -= inode_offset_;
|
std::optional<chunk_range> rv;
|
||||||
if (inode < static_cast<int>(cfg_->chunk_index_offset) ||
|
inode -= inode_offset_ + meta_.chunk_index_offset();
|
||||||
inode >= static_cast<int>(cfg_->inode_count)) {
|
if (inode >= 0 &&
|
||||||
return nullptr;
|
inode < (static_cast<int>(meta_.chunk_index().size()) - 1)) {
|
||||||
|
uint32_t begin = meta_.chunk_index()[inode];
|
||||||
|
uint32_t end = meta_.chunk_index()[inode + 1];
|
||||||
|
rv = chunk_range(&meta_, begin, end);
|
||||||
}
|
}
|
||||||
uint32_t off = chunk_index_[inode];
|
return rv;
|
||||||
num = (chunk_index_[inode + 1] - off) / sizeof(chunk_type);
|
|
||||||
return as<chunk_type>(off);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void metadata_v2::get_stat_defaults(struct ::stat* defaults) {
|
void metadata_v2::get_stat_defaults(struct ::stat* defaults) {
|
||||||
::memset(defaults, 0, sizeof(struct ::stat));
|
::memset(defaults, 0, sizeof(struct ::stat));
|
||||||
defaults->st_uid = ::geteuid();
|
defaults->st_uid = ::geteuid();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user