mirror of
https://github.com/mhx/dwarfs.git
synced 2025-08-04 02:06:22 -04:00
feat: add filesystem_v2::cache_blocks_by_category()
This commit is contained in:
parent
b04a9fd19a
commit
85ce5380b5
@ -357,6 +357,10 @@ class filesystem_v2 {
|
|||||||
return impl_->get_block_category(block_number);
|
return impl_->get_block_category(block_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cache_blocks_by_category(std::string_view category) const {
|
||||||
|
return impl_->cache_blocks_by_category(category);
|
||||||
|
}
|
||||||
|
|
||||||
class impl {
|
class impl {
|
||||||
public:
|
public:
|
||||||
virtual ~impl() = default;
|
virtual ~impl() = default;
|
||||||
@ -452,6 +456,7 @@ class filesystem_v2 {
|
|||||||
virtual std::shared_ptr<internal::filesystem_parser> get_parser() const = 0;
|
virtual std::shared_ptr<internal::filesystem_parser> get_parser() const = 0;
|
||||||
virtual std::optional<std::string>
|
virtual std::optional<std::string>
|
||||||
get_block_category(size_t block_number) const = 0;
|
get_block_category(size_t block_number) const = 0;
|
||||||
|
virtual void cache_blocks_by_category(std::string_view category) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -100,6 +101,10 @@ class inode_reader_v2 {
|
|||||||
|
|
||||||
size_t num_blocks() const { return impl_->num_blocks(); }
|
size_t num_blocks() const { return impl_->num_blocks(); }
|
||||||
|
|
||||||
|
void cache_blocks(std::span<size_t const> blocks) const {
|
||||||
|
impl_->cache_blocks(blocks);
|
||||||
|
}
|
||||||
|
|
||||||
class impl {
|
class impl {
|
||||||
public:
|
public:
|
||||||
virtual ~impl() = default;
|
virtual ~impl() = default;
|
||||||
@ -121,6 +126,7 @@ class inode_reader_v2 {
|
|||||||
virtual void set_num_workers(size_t num) = 0;
|
virtual void set_num_workers(size_t num) = 0;
|
||||||
virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0;
|
virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0;
|
||||||
virtual size_t num_blocks() const = 0;
|
virtual size_t num_blocks() const = 0;
|
||||||
|
virtual void cache_blocks(std::span<size_t const> blocks) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -184,6 +184,11 @@ class metadata_v2 {
|
|||||||
return impl_->get_all_gids();
|
return impl_->get_all_gids();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<size_t>
|
||||||
|
get_block_numbers_by_category(std::string_view category) const {
|
||||||
|
return impl_->get_block_numbers_by_category(category);
|
||||||
|
}
|
||||||
|
|
||||||
class impl {
|
class impl {
|
||||||
public:
|
public:
|
||||||
virtual ~impl() = default;
|
virtual ~impl() = default;
|
||||||
@ -255,6 +260,9 @@ class metadata_v2 {
|
|||||||
virtual std::vector<file_stat::uid_type> get_all_uids() const = 0;
|
virtual std::vector<file_stat::uid_type> get_all_uids() const = 0;
|
||||||
|
|
||||||
virtual std::vector<file_stat::gid_type> get_all_gids() const = 0;
|
virtual std::vector<file_stat::gid_type> get_all_gids() const = 0;
|
||||||
|
|
||||||
|
virtual std::vector<size_t>
|
||||||
|
get_block_numbers_by_category(std::string_view category) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -312,6 +312,10 @@ class filesystem_ final : public filesystem_v2::impl {
|
|||||||
return meta_.get_block_category(block_no);
|
return meta_.get_block_category(block_no);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cache_blocks_by_category(std::string_view category) const override {
|
||||||
|
ir_.cache_blocks(meta_.get_block_numbers_by_category(category));
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
filesystem_info const* get_info(fsinfo_options const& opts) const;
|
filesystem_info const* get_info(fsinfo_options const& opts) const;
|
||||||
void check_section(fs_section const& section) const;
|
void check_section(fs_section const& section) const;
|
||||||
|
@ -722,6 +722,8 @@ class block_cache_ final : public block_cache::impl {
|
|||||||
block->touch();
|
block->touch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_VERBOSE << "inserting block " << block_no << " into cache";
|
||||||
|
|
||||||
cache_.set(block_no, std::move(block));
|
cache_.set(block_no, std::move(block));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +152,12 @@ class inode_reader_ final : public inode_reader_v2::impl {
|
|||||||
}
|
}
|
||||||
size_t num_blocks() const override { return cache_.block_count(); }
|
size_t num_blocks() const override { return cache_.block_count(); }
|
||||||
|
|
||||||
|
void cache_blocks(std::span<size_t const> blocks) const override {
|
||||||
|
for (auto b : blocks) {
|
||||||
|
cache_.get(b, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using offset_cache_type =
|
using offset_cache_type =
|
||||||
basic_offset_cache<uint32_t, file_off_t, size_t,
|
basic_offset_cache<uint32_t, file_off_t, size_t,
|
||||||
|
@ -563,6 +563,9 @@ class metadata_ final : public metadata_v2::impl {
|
|||||||
std::vector<file_stat::uid_type> get_all_uids() const override;
|
std::vector<file_stat::uid_type> get_all_uids() const override;
|
||||||
std::vector<file_stat::gid_type> get_all_gids() const override;
|
std::vector<file_stat::gid_type> get_all_gids() const override;
|
||||||
|
|
||||||
|
std::vector<size_t>
|
||||||
|
get_block_numbers_by_category(std::string_view category) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename K>
|
template <typename K>
|
||||||
using set_type = folly::F14ValueSet<K>;
|
using set_type = folly::F14ValueSet<K>;
|
||||||
@ -2203,6 +2206,35 @@ std::vector<file_stat::gid_type> metadata_<LoggerPolicy>::get_all_gids() const {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename LoggerPolicy>
|
||||||
|
std::vector<size_t> metadata_<LoggerPolicy>::get_block_numbers_by_category(
|
||||||
|
std::string_view category) const {
|
||||||
|
std::vector<size_t> rv;
|
||||||
|
|
||||||
|
if (auto catnames = meta_.category_names()) {
|
||||||
|
if (auto categories = meta_.block_categories()) {
|
||||||
|
std::optional<size_t> category_num;
|
||||||
|
|
||||||
|
for (size_t catnum = 0; catnum < catnames.value().size(); ++catnum) {
|
||||||
|
if (catnames.value()[catnum] == category) {
|
||||||
|
category_num = catnum;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category_num) {
|
||||||
|
for (size_t blknum = 0; blknum < categories.value().size(); ++blknum) {
|
||||||
|
if (categories.value()[blknum] == *category_num) {
|
||||||
|
rv.push_back(blknum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
metadata_v2::metadata_v2(
|
metadata_v2::metadata_v2(
|
||||||
logger& lgr, std::span<uint8_t const> schema, std::span<uint8_t const> data,
|
logger& lgr, std::span<uint8_t const> schema, std::span<uint8_t const> data,
|
||||||
metadata_options const& options, int inode_offset,
|
metadata_options const& options, int inode_offset,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user