Skip to content

Commit

Permalink
FIXUP: fs: exported changes in unit headers to a separate PR
Browse files Browse the repository at this point in the history
  • Loading branch information
varqox committed Feb 26, 2020
1 parent 4e43664 commit 0612764
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 100 deletions.
10 changes: 5 additions & 5 deletions include/seastar/fs/block_device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public:
explicit operator bool() const noexcept { return bool(_block_device_impl); }

template <typename CharType>
future<size_t> read(uint64_t aligned_offset, CharType* aligned_buffer, size_t aligned_len, const io_priority_class& pc = default_priority_class()) {
return _block_device_impl->read(aligned_offset, aligned_buffer, aligned_len, pc);
future<size_t> read(uint64_t aligned_pos, CharType* aligned_buffer, size_t aligned_len, const io_priority_class& pc = default_priority_class()) {
return _block_device_impl->read(aligned_pos, aligned_buffer, aligned_len, pc);
}

template <typename CharType>
future<size_t> write(uint64_t aligned_offset, const CharType* aligned_buffer, size_t aligned_len, const io_priority_class& pc = default_priority_class()) {
return _block_device_impl->write(aligned_offset, aligned_buffer, aligned_len, pc);
future<size_t> write(uint64_t aligned_pos, const CharType* aligned_buffer, size_t aligned_len, const io_priority_class& pc = default_priority_class()) {
return _block_device_impl->write(aligned_pos, aligned_buffer, aligned_len, pc);
}

future<> flush() {
Expand Down Expand Up @@ -93,7 +93,7 @@ public:
}
};

inline future<block_device> open_block_device(std::string name) {
inline future<block_device> open_block_device(sstring name) {
return open_file_dma(std::move(name), open_flags::rw).then([](file f) {
return block_device(make_shared<file_block_device_impl>(std::move(f)));
});
Expand Down
7 changes: 4 additions & 3 deletions include/seastar/fs/temporary_file.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
#pragma once

#include <seastar/core/posix.hh>
#include <seastar/core/sstring.hh>

namespace seastar::fs {

class temporary_file {
std::string _path;
sstring _path;
public:
explicit temporary_file(std::string path) : _path(std::move(path) + ".XXXXXX") {
explicit temporary_file(sstring path) : _path(std::move(path) + ".XXXXXX") {
int fd = mkstemp(_path.data());
throw_system_error_on(fd == -1);
close(fd);
Expand All @@ -43,7 +44,7 @@ public:
temporary_file(temporary_file&&) noexcept = delete;
temporary_file& operator=(temporary_file&&) noexcept = delete;

const std::string& path() const noexcept {
const sstring& path() const noexcept {
return _path;
}
};
Expand Down
53 changes: 0 additions & 53 deletions src/fs/bitwise.hh
Original file line number Diff line number Diff line change
Expand Up @@ -69,57 +69,4 @@ constexpr inline T mul_by_power_of_2(T a, U b) noexcept {
static_assert(mul_by_power_of_2(3u, 1u) == 3);
static_assert(mul_by_power_of_2(3u, 4u) == 12);

template<class T, class U, std::enable_if_t<std::is_unsigned_v<T>, int> = 0, std::enable_if_t<std::is_unsigned_v<U>, int> = 0>
constexpr inline T round_down_to_multiple_of_power_of_2(T a, U b) noexcept {
return a - mod_by_power_of_2(a, b);
}

static_assert(round_down_to_multiple_of_power_of_2(0u, 1u) == 0);
static_assert(round_down_to_multiple_of_power_of_2(1u, 1u) == 1);
static_assert(round_down_to_multiple_of_power_of_2(19u, 1u) == 19);

static_assert(round_down_to_multiple_of_power_of_2(0u, 2u) == 0);
static_assert(round_down_to_multiple_of_power_of_2(1u, 2u) == 0);
static_assert(round_down_to_multiple_of_power_of_2(2u, 2u) == 2);
static_assert(round_down_to_multiple_of_power_of_2(3u, 2u) == 2);
static_assert(round_down_to_multiple_of_power_of_2(4u, 2u) == 4);
static_assert(round_down_to_multiple_of_power_of_2(5u, 2u) == 4);

static_assert(round_down_to_multiple_of_power_of_2(31u, 16u) == 16);
static_assert(round_down_to_multiple_of_power_of_2(32u, 16u) == 32);
static_assert(round_down_to_multiple_of_power_of_2(33u, 16u) == 32);
static_assert(round_down_to_multiple_of_power_of_2(37u, 16u) == 32);
static_assert(round_down_to_multiple_of_power_of_2(39u, 16u) == 32);
static_assert(round_down_to_multiple_of_power_of_2(45u, 16u) == 32);
static_assert(round_down_to_multiple_of_power_of_2(47u, 16u) == 32);
static_assert(round_down_to_multiple_of_power_of_2(48u, 16u) == 48);
static_assert(round_down_to_multiple_of_power_of_2(49u, 16u) == 48);

template<class T, class U, std::enable_if_t<std::is_unsigned_v<T>, int> = 0, std::enable_if_t<std::is_unsigned_v<U>, int> = 0>
constexpr inline T round_up_to_multiple_of_power_of_2(T a, U b) noexcept {
auto mod = mod_by_power_of_2(a, b);
return (mod == 0 ? a : a - mod + b);
}

static_assert(round_up_to_multiple_of_power_of_2(0u, 1u) == 0);
static_assert(round_up_to_multiple_of_power_of_2(1u, 1u) == 1);
static_assert(round_up_to_multiple_of_power_of_2(19u, 1u) == 19);

static_assert(round_up_to_multiple_of_power_of_2(0u, 2u) == 0);
static_assert(round_up_to_multiple_of_power_of_2(1u, 2u) == 2);
static_assert(round_up_to_multiple_of_power_of_2(2u, 2u) == 2);
static_assert(round_up_to_multiple_of_power_of_2(3u, 2u) == 4);
static_assert(round_up_to_multiple_of_power_of_2(4u, 2u) == 4);
static_assert(round_up_to_multiple_of_power_of_2(5u, 2u) == 6);

static_assert(round_up_to_multiple_of_power_of_2(31u, 16u) == 32);
static_assert(round_up_to_multiple_of_power_of_2(32u, 16u) == 32);
static_assert(round_up_to_multiple_of_power_of_2(33u, 16u) == 48);
static_assert(round_up_to_multiple_of_power_of_2(37u, 16u) == 48);
static_assert(round_up_to_multiple_of_power_of_2(39u, 16u) == 48);
static_assert(round_up_to_multiple_of_power_of_2(45u, 16u) == 48);
static_assert(round_up_to_multiple_of_power_of_2(47u, 16u) == 48);
static_assert(round_up_to_multiple_of_power_of_2(48u, 16u) == 48);
static_assert(round_up_to_multiple_of_power_of_2(49u, 16u) == 64);

} // namespace seastar::fs
4 changes: 2 additions & 2 deletions src/fs/cluster.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#pragma once

#include "fs/bitwise.hh"
#include "fs/units.hh"
#include "bitwise.hh"
#include "units.hh"

namespace seastar::fs {

Expand Down
40 changes: 6 additions & 34 deletions src/fs/inode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

#pragma once

#include "fs/bitwise.hh"
#include "fs/units.hh"
#include "bitwise.hh"

#include <cstdint>
#include <optional>

namespace seastar::fs {

Expand All @@ -34,47 +32,21 @@ using inode_t = uint64_t;

// Obtains shard id of the shard owning @p inode.
//@p fs_shards_pool_size is the number of file system shards rounded up to a power of 2
inline fs_shard_id_t inode_to_shard_no(inode_t inode, fs_shard_id_t fs_shards_pool_size) noexcept {
inline unsigned inode_to_shard_no(inode_t inode, unsigned fs_shards_pool_size) noexcept {
assert(is_power_of_2(fs_shards_pool_size));
return mod_by_power_of_2(inode, fs_shards_pool_size);
}

// Returns inode belonging to the shard owning @p shard_previous_inode that is next after @p shard_previous_inode
// (i.e. the lowest inode greater than @p shard_previous_inode belonging to the same shard)
//@p fs_shards_pool_size is the number of file system shards rounded up to a power of 2
inline inode_t shard_next_inode(inode_t shard_previous_inode, fs_shard_id_t fs_shards_pool_size) noexcept {
inline unsigned shard_next_inode(inode_t shard_previous_inode, unsigned fs_shards_pool_size) noexcept {
return shard_previous_inode + fs_shards_pool_size;
}

// Returns first inode (lowest by value) belonging to the shard @p fs_shard_id
inline inode_t shard_first_inode(fs_shard_id_t fs_shard_id) noexcept {
return fs_shard_id;
// Returns first inode (lowest by value) belonging to the shard @p shard_id
inline unsigned shard_first_inode(unsigned shard_id) noexcept {
return shard_id;
}

class shard_inode_allocator {
fs_shard_id_t _fs_shards_pool_size;
fs_shard_id_t _fs_shard_id;
std::optional<inode_t> _latest_allocated_inode;

public:
shard_inode_allocator(fs_shard_id_t fs_shards_pool_size, fs_shard_id_t fs_shard_id, std::optional<inode_t> latest_allocated_inode = std::nullopt)
: _fs_shards_pool_size(fs_shards_pool_size)
, _fs_shard_id(fs_shard_id)
, _latest_allocated_inode(latest_allocated_inode) {}

inode_t alloc() noexcept {
if (not _latest_allocated_inode) {
_latest_allocated_inode = shard_first_inode(_fs_shard_id);
return *_latest_allocated_inode;
}

_latest_allocated_inode = shard_next_inode(*_latest_allocated_inode, _fs_shards_pool_size);
return *_latest_allocated_inode;
}

void reset(std::optional<inode_t> latest_allocated_inode = std::nullopt) noexcept {
_latest_allocated_inode = latest_allocated_inode;
}
};

} // namespace seastar::fs
4 changes: 1 addition & 3 deletions src/fs/units.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

#include "fs/range.hh"
#include "range.hh"

#include <cstdint>

Expand All @@ -35,6 +35,4 @@ using disk_range = range<disk_offset_t>;
using file_offset_t = uint64_t;
using file_range = range<file_offset_t>;

using fs_shard_id_t = uint32_t;

} // namespace seastar::fs

0 comments on commit 0612764

Please sign in to comment.