Factor out block_range and iovec_read_buf types

This commit is contained in:
Marcus Holland-Moritz 2023-07-12 15:09:31 +02:00
parent 0a34cf943b
commit 9915b3e1f4
9 changed files with 93 additions and 34 deletions

View File

@ -28,6 +28,7 @@
#include <memory>
#include "dwarfs/block_compressor.h"
#include "dwarfs/block_range.h"
#include "dwarfs/fstypes.h"
namespace dwarfs {
@ -35,7 +36,6 @@ namespace dwarfs {
struct block_cache_options;
struct cache_tidy_config;
class block_range;
class fs_section;
class logger;
class mmif;

View File

@ -0,0 +1,48 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz (github@mhxnet.de)
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs 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.
*
* dwarfs 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 dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <cstdint>
#include <memory>
namespace dwarfs {
class cached_block;
class block_range {
public:
block_range(uint8_t const* data, size_t offset, size_t size);
block_range(std::shared_ptr<cached_block const> block, size_t offset,
size_t size);
uint8_t const* data() const { return begin_; }
uint8_t const* begin() const { return begin_; }
uint8_t const* end() const { return end_; }
size_t size() const { return end_ - begin_; }
private:
uint8_t const* const begin_;
uint8_t const* const end_;
std::shared_ptr<cached_block const> block_;
};
} // namespace dwarfs

View File

@ -35,6 +35,7 @@
#include <folly/Expected.h>
#include <folly/dynamic.h>
#include "dwarfs/block_range.h"
#include "dwarfs/fstypes.h"
#include "dwarfs/metadata_types.h"
#include "dwarfs/types.h"

View File

@ -24,46 +24,13 @@
#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <memory>
#include <string>
#include <folly/portability/IOVec.h>
#include <folly/small_vector.h>
#include "dwarfs/block_compressor.h" // TODO: or the other way round?
#include "dwarfs/checksum.h"
namespace dwarfs {
class cached_block;
// TODO: move elsewhere
class block_range {
public:
block_range(uint8_t const* data, size_t offset, size_t size);
block_range(std::shared_ptr<cached_block const> block, size_t offset,
size_t size);
uint8_t const* data() const { return begin_; }
uint8_t const* begin() const { return begin_; }
uint8_t const* end() const { return end_; }
size_t size() const { return end_ - begin_; }
private:
uint8_t const* const begin_;
uint8_t const* const end_;
std::shared_ptr<cached_block const> block_;
};
// TODO: move elsewhere
struct iovec_read_buf {
// This covers more than 95% of reads
static constexpr size_t inline_storage = 16;
folly::small_vector<struct ::iovec, inline_storage> buf;
folly::small_vector<block_range, inline_storage> ranges;
};
constexpr uint8_t MAJOR_VERSION = 2;
constexpr uint8_t MINOR_VERSION = 5;

View File

@ -28,6 +28,7 @@
#include <folly/Expected.h>
#include "dwarfs/block_range.h"
#include "dwarfs/metadata_types.h"
#include "dwarfs/types.h"

View File

@ -0,0 +1,39 @@
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz (github@mhxnet.de)
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs 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.
*
* dwarfs 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 dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <folly/portability/IOVec.h>
#include <folly/small_vector.h>
#include "dwarfs/block_range.h"
namespace dwarfs {
struct iovec_read_buf {
// This covers more than 95% of reads
static constexpr size_t inline_storage = 16;
folly::small_vector<struct ::iovec, inline_storage> buf;
folly::small_vector<block_range, inline_storage> ranges;
};
} // namespace dwarfs

View File

@ -36,6 +36,7 @@
#include "dwarfs/block_cache.h"
#include "dwarfs/fstypes.h"
#include "dwarfs/inode_reader_v2.h"
#include "dwarfs/iovec_read_buf.h"
#include "dwarfs/logger.h"
#include "dwarfs/offset_cache.h"
#include "dwarfs/performance_monitor.h"

View File

@ -66,6 +66,7 @@
#include "dwarfs/file_stat.h"
#include "dwarfs/filesystem_v2.h"
#include "dwarfs/fstypes.h"
#include "dwarfs/iovec_read_buf.h"
#include "dwarfs/logger.h"
#include "dwarfs/metadata_v2.h"
#include "dwarfs/mmap.h"

View File

@ -31,6 +31,7 @@
#include "dwarfs/file_stat.h"
#include "dwarfs/filesystem_v2.h"
#include "dwarfs/filesystem_writer.h"
#include "dwarfs/iovec_read_buf.h"
#include "dwarfs/logger.h"
#include "dwarfs/options.h"
#include "dwarfs/progress.h"