From: Igor Fedotov Date: Tue, 18 Feb 2025 17:20:53 +0000 (+0300) Subject: tool/ceph-bluestore-tool: Make bluefs-bdev-expand command output nicer. X-Git-Tag: testing/wip-pdonnell-testing-20250429.182310-reef-debug~26^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=fd5394eaf88ee7d9f407505ebaf03851dd579e26;p=ceph-ci.git tool/ceph-bluestore-tool: Make bluefs-bdev-expand command output nicer. Here is a sample output: inferring bluefs devices from bluestore path 0 : device size 0x4049c000(1.0 GiB) : using 0x1801000(24 MiB) 1 : device size 0x140000000(5 GiB) : using 0x1502000(21 MiB) 2 : device size 0x8c0000000(35 GiB) : using 0x40014000(1.0 GiB) Expanding DB/WAL... 0 : nothing to do, skipped 1 : Expanding to 0x140000000(5 GiB) 1 : size updated to 0x140000000(5 GiB) 2 : Expanding to 0x8c0000000(35 GiB) 2 : size updated to 0x8c0000000(35 GiB) Fixes: https://tracker.ceph.com/issues/67966 Signed-off-by: Igor Fedotov (cherry picked from commit ac7789139e3d4ba3bfd69ddcd4fe504c35b42bc3) --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 666a38b6b29..f38d78947f9 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -574,16 +574,17 @@ void BlueFS::dump_perf_counters(Formatter *f) void BlueFS::dump_block_extents(ostream& out) { for (unsigned i = 0; i < MAX_BDEV; ++i) { - if (!bdev[i]) { + if (!bdev[i] || !alloc[i]) { continue; } - auto total = get_total(i); + auto total = get_total(i) + block_reserved[i]; auto free = get_free(i); out << i << " : device size 0x" << std::hex << total + << "(" << byte_u_t(total) << ")" << " : using 0x" << total - free - << std::dec << "(" << byte_u_t(total - free) << ")"; - out << "\n"; + << "(" << byte_u_t(total - free) << ")" + << std::dec << std::endl; } } diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 97f65f215c7..a952ecfa7ff 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -7644,32 +7644,15 @@ string BlueStore::get_device_path(unsigned id) return res; } -int BlueStore::_set_bdev_label_size(const string& path, uint64_t size) -{ - bluestore_bdev_label_t label; - int r = _read_bdev_label(cct, path, &label); - if (r < 0) { - derr << "unable to read label for " << path << ": " - << cpp_strerror(r) << dendl; - } else { - label.size = size; - r = _write_bdev_label(cct, path, label); - if (r < 0) { - derr << "unable to write label for " << path << ": " - << cpp_strerror(r) << dendl; - } - } - return r; -} - int BlueStore::expand_devices(ostream& out) { int r = _open_db_and_around(true); ceph_assert(r == 0); bluefs->dump_block_extents(out); out << "Expanding DB/WAL..." << std::endl; + // updating dedicated devices first for (auto devid : { BlueFS::BDEV_WAL, BlueFS::BDEV_DB}) { - if (devid == bluefs_layout.shared_bdev ) { + if (devid == bluefs_layout.shared_bdev) { continue; } uint64_t size = bluefs->get_block_device_size(devid); @@ -7677,53 +7660,105 @@ int BlueStore::expand_devices(ostream& out) // no bdev continue; } - - out << devid - <<" : expanding " << " to 0x" << size << std::dec << std::endl; - string p = get_device_path(devid); - const char* path = p.c_str(); - if (path == nullptr) { - derr << devid - <<": can't find device path " << dendl; - continue; - } if (bluefs->bdev_support_label(devid)) { - if (_set_bdev_label_size(p, size) >= 0) { - out << devid - << " : size label updated to " << size - << std::endl; + string my_path = get_device_path(devid); + bluestore_bdev_label_t my_label; + int r = _read_bdev_label(cct, my_path, &my_label); + if (r < 0) { + derr << "unable to read label for " << my_path << ": " + << cpp_strerror(r) << dendl; + continue; + } else { + if (size == my_label.size) { + // no need to expand + out << devid + << " : nothing to do, skipped" + << std::endl; + continue; + } else if (size < my_label.size) { + // something weird in bdev label + out << devid + <<" : ERROR: bdev label is above device size, skipped" + << std::endl; + continue; + } else { + my_label.size = size; + out << devid + << " : Expanding to 0x" << std::hex << size + << std::dec << "(" << byte_u_t(size) << ")" + << std::endl; + r = _write_bdev_label(cct, my_path, my_label); + if (r < 0) { + derr << "unable to write label for " << my_path << ": " + << cpp_strerror(r) << dendl; + } else { + out << devid + << " : size updated to 0x" << std::hex << size + << std::dec << "(" << byte_u_t(size) << ")" + << std::endl; + } + } } } } + // now proceed with a shared device uint64_t size0 = fm->get_size(); uint64_t size = bdev->get_size(); - if (size0 < size) { - out << bluefs_layout.shared_bdev - << " : expanding " << " from 0x" << std::hex - << size0 << " to 0x" << size << std::dec << std::endl; - _write_out_fm_meta(size); - string p = get_device_path(bluefs_layout.shared_bdev); - if (bdev->supported_bdev_label()) { - if (_set_bdev_label_size(p, size) >= 0) { - out << bluefs_layout.shared_bdev - << " : size label updated to " << size - << std::endl; + auto devid = bluefs_layout.shared_bdev; + auto aligned_size = p2align(size, min_alloc_size); + if (aligned_size == size0) { + // no need to expand + out << devid + << " : nothing to do, skipped" + << std::endl; + } else if (aligned_size < size0) { + // something weird in bdev label + out << devid + << " : ERROR: previous device size is above the current one, skipped" + << std::endl; + } else { + auto my_path = get_device_path(devid); + out << devid + <<" : Expanding to 0x" << std::hex << size + << std::dec << "(" << byte_u_t(size) << ")" + << std::endl; + r = _write_out_fm_meta(size); + if (r != 0) { + derr << "unable to write out fm meta for " << my_path << ": " + << cpp_strerror(r) << dendl; + } else if (bdev->supported_bdev_label()) { + bluestore_bdev_label_t my_label; + int r = _read_bdev_label(cct, my_path, &my_label); + if (r < 0) { + derr << "unable to read label for " << my_path << ": " + << cpp_strerror(r) << dendl; + } else { + my_label.size = size; + r = _write_bdev_label(cct, my_path, my_label); + if (r < 0) { + derr << "unable to write label(s) for " << my_path << ": " + << cpp_strerror(r) << dendl; + } } } - _close_db_and_around(); + if (r == 0) { + out << devid + << " : size updated to 0x" << std::hex << size + << std::dec << "(" << byte_u_t(size) << ")" + << std::endl; + _close_db_and_around(); - // mount in read/write to sync expansion changes - r = _mount(); - ceph_assert(r == 0); - if (fm && fm->is_null_manager()) { - // we grow the allocation range, must reflect it in the allocation file - alloc->init_add_free(size0, size - size0); - need_to_destage_allocation_file = true; + // mount in read/write to sync expansion changes + r = _open_db_and_around(false); + ceph_assert(r == 0); + if (fm && fm->is_null_manager()) { + // we grow the allocation range, must reflect it in the allocation file + alloc->init_add_free(size0, size - size0); + need_to_destage_allocation_file = true; + } } - umount(); - } else { - _close_db_and_around(); } + _close_db_and_around(); return r; } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index ca792a0a855..fbd54d2a10a 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2702,8 +2702,6 @@ public: private: int _check_or_set_bdev_label(std::string path, uint64_t size, std::string desc, bool create); - int _set_bdev_label_size(const std::string& path, uint64_t size); - int _open_super_meta(); void _open_statfs();