}
};
-BlueFS::BlueFS(CephContext* cct,
- bluefs_shared_alloc_context_t* _shared_alloc)
+BlueFS::BlueFS(CephContext* cct)
: cct(cct),
bdev(MAX_BDEV),
ioc(MAX_BDEV),
block_reserved(MAX_BDEV),
alloc(MAX_BDEV),
alloc_size(MAX_BDEV, 0),
- pending_release(MAX_BDEV),
- shared_alloc(_shared_alloc)
+ pending_release(MAX_BDEV)
{
discard_cb[BDEV_WAL] = wal_discard_cb;
discard_cb[BDEV_DB] = db_discard_cb;
int BlueFS::add_block_device(unsigned id, const string& path, bool trim,
uint64_t reserved,
- bool shared_with_bluestore)
+ bluefs_shared_alloc_context_t* _shared_alloc)
{
dout(10) << __func__ << " bdev " << id << " path " << path << " "
<< reserved << dendl;
BlockDevice *b = BlockDevice::create(cct, path, NULL, NULL,
discard_cb[id], static_cast<void*>(this));
block_reserved[id] = reserved;
- if (shared_with_bluestore) {
+ if (_shared_alloc) {
b->set_no_exclusive_lock();
}
int r = b->open(path);
<< " size " << byte_u_t(b->get_size()) << dendl;
bdev[id] = b;
ioc[id] = new IOContext(cct, NULL);
- if (shared_with_bluestore) {
- ceph_assert(shared_alloc); // to be set in ctor before
+ if (_shared_alloc) {
+ ceph_assert(!shared_alloc);
+ shared_alloc = _shared_alloc;
alloc[id] = shared_alloc->a;
shared_alloc_id = id;
}
{
std::lock_guard l(lock);
dout(10) << __func__ << " bdev " << id << dendl;
- if (id >= alloc.size())
- return -EINVAL;
+ ceph_assert(id < alloc.size());
for (auto& p : file_map) {
for (auto& q : p.second->fnode.extents) {
- if (q.bdev == id && alloc[q.bdev] == shared_alloc->a) {
+ if (q.bdev == id) {
extents->insert(q.offset, q.length);
}
}
{
dout(1) << __func__ << dendl;
- bool shared_alloc_ready = shared_alloc && shared_alloc->a;
int r = _open_super();
if (r < 0) {
derr << __func__ << " failed to open super: " << cpp_strerror(r) << dendl;
for (auto& p : file_map) {
dout(30) << __func__ << " noting alloc for " << p.second->fnode << dendl;
for (auto& q : p.second->fnode.extents) {
- if (is_shared_alloc(q.bdev)) {
- // we might have still uninitialized shared_alloc at this point
- // just bypass initialization then
- if (shared_alloc_ready && shared_alloc->need_init) {
- ceph_assert(shared_alloc->a);
- alloc[q.bdev]->init_rm_free(q.offset, q.length);
- shared_alloc->bluefs_used += q.length;
- }
- } else {
+ bool is_shared = is_shared_alloc(q.bdev);
+ ceph_assert(!is_shared || (is_shared && shared_alloc));
+ if (is_shared && shared_alloc->need_init && shared_alloc->a) {
+ shared_alloc->bluefs_used += q.length;
+ alloc[q.bdev]->init_rm_free(q.offset, q.length);
+ } else if (!is_shared) {
alloc[q.bdev]->init_rm_free(q.offset, q.length);
}
}
}
- if (shared_alloc_ready) {
+ if (shared_alloc) {
shared_alloc->need_init = false;
+ dout(1) << __func__ << " shared_bdev_used = "
+ << shared_alloc->bluefs_used << dendl;
+ } else {
+ dout(1) << __func__ << " shared bdev not used"
+ << dendl;
}
- dout(1) << __func__ << " shared_bdev_used = "
- << (shared_alloc_ready ? (int64_t)shared_alloc->bluefs_used : -1)
- << dendl;
// set up the log for future writes
log_writer = _create_writer(_get_file(1));
BlockDevice::aio_callback_t discard_cb[3]; //discard callbacks for each dev
std::unique_ptr<BlueFSVolumeSelector> vselector;
+
bluefs_shared_alloc_context_t* shared_alloc = nullptr;
unsigned shared_alloc_id = unsigned(-1);
inline bool is_shared_alloc(unsigned id) const {
}
public:
- BlueFS(CephContext* cct, bluefs_shared_alloc_context_t* _shared_alloc);
+ BlueFS(CephContext* cct);
~BlueFS();
// the super is always stored on bdev 0
int add_block_device(unsigned bdev, const std::string& path, bool trim,
uint64_t reserved,
- bool shared_with_bluestore = false);
+ bluefs_shared_alloc_context_t* _shared_alloc = nullptr);
bool bdev_support_label(unsigned id);
uint64_t get_block_device_size(unsigned bdev) const;
return r;
}
-int BlueStore::_open_alloc()
+int BlueStore::_create_alloc()
{
ceph_assert(shared_alloc.a == NULL);
ceph_assert(bdev->get_size());
}
shared_alloc.set(Allocator::create(cct, cct->_conf->bluestore_allocator,
- bdev->get_size(),
- alloc_size, "block"));
+ bdev->get_size(),
+ alloc_size, "block"));
if (!shared_alloc.a) {
- lderr(cct) << __func__ << " Allocator::unknown alloc type "
- << cct->_conf->bluestore_allocator
- << dendl;
+ lderr(cct) << __func__ << "Failed to create allocator:: "
+ << cct->_conf->bluestore_allocator
+ << dendl;
return -EINVAL;
}
+ return 0;
+}
+
+int BlueStore::_init_alloc()
+{
+ int r = _create_alloc();
+ if (r < 0) {
+ return r;
+ }
+ ceph_assert(shared_alloc.a != NULL);
if (bdev->is_smr()) {
shared_alloc.a->set_zone_states(fm->get_zone_states(db));
int BlueStore::_minimal_open_bluefs(bool create)
{
int r;
- bluefs = new BlueFS(cct, &shared_alloc);
+ bluefs = new BlueFS(cct);
string bfn;
struct stat st;
// never trim here
r = bluefs->add_block_device(bluefs_layout.shared_bdev, bfn, false,
0, // no need to provide valid 'reserved' for shared dev
- true);
+ &shared_alloc);
if (r < 0) {
derr << __func__ << " add block device(" << bfn << ") returned: "
<< cpp_strerror(r) << dendl;
// open in read-only first to read FM list and init allocator
// as they might be needed for some BlueFS procedures
-
r = _open_db(false, false, true);
if (r < 0)
goto out_bdev;
if (r < 0)
goto out_db;
- r = _open_alloc();
+ r = _init_alloc();
if (r < 0)
goto out_fm;
r = _open_db(false, to_repair, read_only);
if (r < 0) {
- goto out_fm;
+ goto out_alloc;
}
return 0;
- out_fm:
+out_alloc:
+ _close_alloc();
+out_fm:
_close_fm();
out_db:
_close_db(read_only);
void BlueStore::_close_db_and_around(bool read_only)
{
_close_db(read_only);
- _close_alloc();
_close_fm();
+ _close_alloc();
_close_bdev();
_close_fsid();
_close_path();
goto out_close_bdev;
}
- uint64_t alloc_size;
- alloc_size = min_alloc_size;
- if (bdev->is_smr()) {
- int r = _zoned_check_config_settings();
- if (r < 0)
- return r;
- alloc_size = _zoned_piggyback_device_parameters_onto(alloc_size);
- }
- shared_alloc.set(Allocator::create(cct, cct->_conf->bluestore_allocator,
- bdev->get_size(),
- alloc_size, "block"));
- if (!shared_alloc.a) {
- r = -EINVAL;
+ r = _create_alloc();
+ if (r < 0) {
goto out_close_bdev;
}
+
reserved = _get_ondisk_reserved();
shared_alloc.a->init_add_free(reserved,
p2align(bdev->get_size(), min_alloc_size) - reserved);
r = _open_db(true);
if (r < 0)
- goto out_close_bdev;
+ goto out_close_alloc;
{
KeyValueDB::Transaction t = db->get_transaction();
_close_fm();
out_close_db:
_close_db(false);
+ out_close_alloc:
+ _close_alloc();
out_close_bdev:
- delete shared_alloc.a;
- shared_alloc.reset();
_close_bdev();
out_close_fsid:
_close_fsid();
int _open_fm(KeyValueDB::Transaction t, bool read_only);
void _close_fm();
int _write_out_fm_meta(uint64_t target_size);
- int _open_alloc();
+ int _create_alloc();
+ int _init_alloc();
void _close_alloc();
int _open_collections();
void _fsck_collections(int64_t* errors);
cout << " -> " << target_path;
}
cout << std::endl;
+
+ // We provide no shared allocator which prevents bluefs to operate in R/W mode.
+ // Read-only mode isn't strictly enforced though
int r = fs->add_block_device(e.second, e.first, false, 0); // 'reserved' is fake
if (r < 0) {
cerr << "unable to open " << e.first << ": " << cpp_strerror(r) << std::endl;
const vector<string>& devs)
{
validate_path(cct, path, true);
- // We provide no shared allocator which prevents bluefs to operate in R/W mode.
- // Read-only mode isn't strictly enforced though
- BlueFS *fs = new BlueFS(cct, nullptr);
+ BlueFS *fs = new BlueFS(cct);
add_devices(fs, cct, devs);
const vector<string>& devs)
{
validate_path(cct, path, true);
- // We provide no shared allocator which prevents bluefs to operate in R/W mode.
- // Read-only mode isn't strictly enforced though
- BlueFS *fs = new BlueFS(cct, nullptr);
+ BlueFS *fs = new BlueFS(cct);
add_devices(fs, cct, devs);
int r = fs->log_dump();
uint64_t size = 1048576 * 128;
TempBdev bdev{size};
uuid_d fsid;
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
}
TEST(BlueFS, mkfs_mount) {
uint64_t size = 1048576 * 128;
TempBdev bdev{size};
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
TEST(BlueFS, write_read) {
uint64_t size = 1048576 * 128;
TempBdev bdev{size};
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
TEST(BlueFS, small_appends) {
uint64_t size = 1048576 * 128;
TempBdev bdev{size};
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
// we'll write a ~5G file, so allocate more than that for the whole fs
uint64_t size = 1048576 * 1024 * 8ull;
TempBdev bdev{size};
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
bool old = g_ceph_context->_conf.get_val<bool>("bluefs_buffered_io");
g_ceph_context->_conf.set_val("bluefs_buffered_io", "false");
"65536");
g_ceph_context->_conf.apply_changes(nullptr);
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
"65536");
g_ceph_context->_conf.apply_changes(nullptr);
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
"65536");
g_ceph_context->_conf.apply_changes(nullptr);
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
uint64_t size = 1048576 * 128;
TempBdev bdev{size};
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
uint64_t size = 1048576 * 128;
TempBdev bdev{size};
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
"bluefs_compact_log_sync",
"true");
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
"bluefs_compact_log_sync",
"false");
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
"bluefs_compact_log_sync",
"false");
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));
conf.SetVal("bluefs_sync_write", "true");
conf.ApplyChanges();
- BlueFS fs(g_ceph_context, nullptr);
+ BlueFS fs(g_ceph_context);
ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, bdev.path, false, 1048576));
uuid_d fsid;
ASSERT_EQ(0, fs.mkfs(fsid, { BlueFS::BDEV_DB, false, false }));