summaryrefslogtreecommitdiffstats
path: root/src/os/bluestore/BlueStore.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/bluestore/BlueStore.cc')
-rw-r--r--src/os/bluestore/BlueStore.cc72
1 files changed, 61 insertions, 11 deletions
diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc
index 23633638672..535cf166f0a 100644
--- a/src/os/bluestore/BlueStore.cc
+++ b/src/os/bluestore/BlueStore.cc
@@ -6794,9 +6794,8 @@ void BlueStore::_main_bdev_label_try_reserve()
vector<uint64_t> candidate_positions;
vector<uint64_t> accepted_positions;
uint64_t lsize = std::max(BDEV_LABEL_BLOCK_SIZE, min_alloc_size);
- for (size_t i = 1; i < bdev_label_positions.size(); i++) {
- uint64_t location = bdev_label_positions[i];
- if (location + lsize <= bdev->get_size()) {
+ for (uint64_t location : bdev_label_valid_locations) {
+ if (location != BDEV_FIRST_LABEL_POSITION) {
candidate_positions.push_back(location);
}
}
@@ -6928,6 +6927,10 @@ int BlueStore::read_bdev_label(
{
unique_ptr<BlockDevice> bdev(BlockDevice::create(
cct, path, nullptr, nullptr, nullptr, nullptr));
+ if (!bdev) {
+ return -EIO;
+ }
+ bdev->set_no_exclusive_lock();
int r = bdev->open(path);
if (r < 0)
return r;
@@ -6990,7 +6993,7 @@ int BlueStore::_open_bdev(bool create)
{
ceph_assert(bdev == NULL);
string p = path + "/block";
- bdev = BlockDevice::create(cct, p, aio_cb, static_cast<void*>(this), discard_cb, static_cast<void*>(this));
+ bdev = BlockDevice::create(cct, p, aio_cb, static_cast<void*>(this), discard_cb, static_cast<void*>(this), "bluestore");
int r = bdev->open(p);
if (r < 0)
goto fail;
@@ -7724,6 +7727,10 @@ int BlueStore::_open_db_and_around(bool read_only, bool to_repair)
if (r < 0)
goto out_fm;
+ if (bdev_label_multi) {
+ _main_bdev_label_try_reserve();
+ }
+
// Re-open in the proper mode(s).
// Can't simply bypass second open for read-only mode as we need to
@@ -7740,10 +7747,6 @@ int BlueStore::_open_db_and_around(bool read_only, bool to_repair)
_post_init_alloc();
}
- if (bdev_label_multi) {
- _main_bdev_label_try_reserve();
- }
-
// when function is called in repair mode (to_repair=true) we skip db->open()/create()
// we can't change bluestore allocation so no need to invlidate allocation-file
if (fm->is_null_manager() && !read_only && !to_repair) {
@@ -8988,6 +8991,47 @@ void BlueStore::trim_free_space(const string& type, std::ostream& outss)
}
}
+int BlueStore::zap_device(CephContext* cct, const string& dev)
+{
+ string path = dev; // dummy var for dout
+ uint64_t brush_size;
+ dout(5) << __func__ << " " << dev << dendl;
+ unique_ptr<BlockDevice>
+ _bdev(BlockDevice::create(cct, dev, nullptr, nullptr, nullptr, nullptr));
+ int r = _bdev->open(dev);
+ if (r < 0)
+ goto fail;
+ brush_size = std::max(_bdev->get_block_size(), BDEV_LABEL_BLOCK_SIZE);
+
+ for (auto off : bdev_label_positions) {
+ uint64_t end = std::min(off + brush_size, _bdev->get_size());
+ if (end > off) {
+ uint64_t l = end - off;
+ bufferlist bl;
+ bl.append_zero(l);
+ dout(10) << __func__ << " writing 0x"
+ << std::hex << off << "~" << l
+ << std::dec << " to " << dev
+ << dendl;
+ r = _bdev->write(off, bl, false);
+ if (r < 0) {
+ derr << __func__ << " error writing 0x"
+ << std::hex << off << "~" << l
+ << std::dec << " to " << dev
+ << " : " << cpp_strerror(r) << dendl;
+ break;
+ }
+ } else {
+ break;
+ }
+ }
+
+ _bdev->close();
+
+fail:
+ return r;
+}
+
void BlueStore::set_cache_shards(unsigned num)
{
dout(10) << __func__ << " " << num << dendl;
@@ -11452,9 +11496,7 @@ int BlueStore::_fsck_on_open(BlueStore::FSCKDepth depth, bool repair)
string p = path + "/block";
_write_bdev_label(cct, bdev, p, bdev_label, bdev_labels_in_repair);
for (uint64_t pos : bdev_labels_in_repair) {
- if (pos != BDEV_FIRST_LABEL_POSITION) {
- bdev_label_valid_locations.push_back(pos);
- }
+ bdev_label_valid_locations.push_back(pos);
}
repaired += bdev_labels_in_repair.size();
}
@@ -20527,6 +20569,14 @@ int BlueStore::read_allocation_from_drive_for_bluestore_tool()
if (ret < 0) {
return ret;
}
+ if (bdev_label_multi) {
+ uint64_t lsize = std::max(BDEV_LABEL_BLOCK_SIZE, min_alloc_size);
+ for (uint64_t p : bdev_label_valid_locations) {
+ if (p != BDEV_FIRST_LABEL_POSITION) {
+ allocator->init_rm_free(p, lsize);
+ }
+ }
+ }
duration = ceph_clock_now() - start;
stats.insert_count = 0;