{
assert(bdev == NULL);
string p = path + "/block";
- uint64_t dev_size;
bdev = BlockDevice::create(cct, p, aio_cb, static_cast<void*>(this), discard_cb, static_cast<void*>(this));
int r = bdev->open(p);
if (r < 0)
goto fail;
- dev_size = bdev->get_size();
if (create && cct->_conf->bdev_enable_discard) {
- bdev->discard(0, dev_size);
+ bdev->discard(0, bdev->get_size());
}
if (bdev->supported_bdev_label()) {
if (r < 0) {
goto fail_close;
}
- if (dev_size < cct->_conf->bluestore_bluefs_min) {
- dout(1) << __func__ << " main device size " << byte_u_t(dev_size)
- << " is too small, disable bluestore_bluefs_min for now"
- << dendl;
- int r = cct->_conf.set_val("bluestore_bluefs_min", "0");
- assert(r == 0);
- }
return 0;
fail_close:
return r;
}
+void BlueStore::_validate_bdev()
+{
+ assert(bdev);
+ assert(min_alloc_size); // _get_odisk_reserved depends on that
+ uint64_t dev_size = bdev->get_size();
+ if (dev_size <
+ _get_ondisk_reserved() + cct->_conf->bluestore_bluefs_min) {
+ dout(1) << __func__ << " main device size " << byte_u_t(dev_size)
+ << " is too small, disable bluestore_bluefs_min for now"
+ << dendl;
+ assert(dev_size >= _get_ondisk_reserved());
+
+ int r = cct->_conf.set_val("bluestore_bluefs_min", "0");
+ assert(r == 0);
+ }
+}
+
void BlueStore::_close_bdev()
{
assert(bdev);
// allocate superblock reserved space. note that we do not mark
// bluefs space as allocated in the freelist; we instead rely on
// bluefs_extents.
- uint64_t reserved = round_up_to(
- std::max<uint64_t>(SUPER_RESERVED, min_alloc_size),
- min_alloc_size);
+ auto reserved = _get_ondisk_reserved();
fm->allocate(0, reserved, t);
if (cct->_conf->bluestore_bluefs) {
min_alloc_size = cct->_conf->bluestore_min_alloc_size_ssd;
}
}
+ _validate_bdev();
// make sure min_alloc_size is power of 2 aligned.
if (!isp2(min_alloc_size)) {
// -----------------
// write helpers
+uint64_t BlueStore::_get_ondisk_reserved() const {
+ return round_up_to(
+ std::max<uint64_t>(SUPER_RESERVED, min_alloc_size), min_alloc_size);
+}
+
void BlueStore::_prepare_ondisk_format_super(KeyValueDB::Transaction& t)
{
dout(10) << __func__ << " ondisk_format " << ondisk_format
_set_finisher_num();
+ _validate_bdev();
return 0;
}
void _set_finisher_num();
int _open_bdev(bool create);
+ // Verifies if disk space is enough for reserved + min bluefs
+ // and alters the latter if needed.
+ // Depends on min_alloc_size hence should be called after
+ // its initialization (and outside of _open_bdev)
+ void _validate_bdev();
void _close_bdev();
/*
* @warning to_repair_db means that we open this db to repair it, will not
int32_t ondisk_format = 0; ///< value detected on mount
int _upgrade_super(); ///< upgrade (called during open_super)
+ uint64_t _get_ondisk_reserved() const;
void _prepare_ondisk_format_super(KeyValueDB::Transaction& t);
// --- public interface ---