}
string p = path + "/block";
if (bdev_label_valid_locations.empty()) {
- _read_main_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
+ _read_multi_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
&bdev_label_multi, &bdev_label_epoch);
}
if (!bdev_label_valid_locations.empty()) {
}
string p = path + "/block";
if (bdev_label_valid_locations.empty()) {
- _read_main_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
+ _read_multi_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
&bdev_label_multi, &bdev_label_epoch);
}
if (!bdev_label_valid_locations.empty()) {
unique_ptr<BlockDevice> bdev(BlockDevice::create(cct, bdev_path, nullptr, nullptr, nullptr, nullptr));
int r = bdev->open(bdev_path);
if (r == 0) {
- r = _read_main_bdev_label(cct, bdev.get(), bdev_path, uuid_d(), &label);
+ r = _read_multi_bdev_label(cct, bdev.get(), bdev_path, uuid_d(), &label);
}
if (r == 0) {
*fsid = label.osd_uuid;
1 When some, but not all labels are read
-ENOENT Otherwise
*/
-int BlueStore::_read_main_bdev_label(
+int BlueStore::_read_multi_bdev_label(
CephContext* cct,
BlockDevice* bdev,
const string& path,
}
} else {
derr << __func__ << " label at 0x" << std::hex << position << std::dec
- << " is multi=yes but no epoch=" << dendl;
+ << " is multi=yes but no epoch" << dendl;
}
} else if (r == 0) {
derr << __func__ << " label at 0x" << std::hex << position << std::dec
int BlueStore::_check_main_bdev_label()
{
string block_path = path + "/block";
- int r = _read_main_bdev_label(cct, bdev, block_path, fsid, &bdev_label,
+ int r = _read_multi_bdev_label(cct, bdev, block_path, fsid, &bdev_label,
&bdev_label_valid_locations, &bdev_label_multi, &bdev_label_epoch);
if (r < 0)
return r;
}
int BlueStore::read_bdev_label(
- CephContext* cct, const std::string &path,
- bluestore_bdev_label_t *label, uint64_t disk_position)
+ CephContext* cct,
+ const std::string &path,
+ bluestore_bdev_label_t* out_label,
+ std::vector<uint64_t>* out_valid_positions,
+ bool* out_is_multi,
+ int64_t* out_epoch)
{
unique_ptr<BlockDevice> bdev(BlockDevice::create(
cct, path, nullptr, nullptr, nullptr, nullptr));
int r = bdev->open(path);
if (r < 0)
return r;
- r = BlueStore::_read_bdev_label(
- cct, bdev.get(), path, label, disk_position);
+ uuid_d fsid;
+ r = BlueStore::_read_multi_bdev_label(
+ cct, bdev.get(), path, fsid, out_label, out_valid_positions, out_is_multi, out_epoch);
bdev->close();
return r;
}
const std::string& desc, bool create);
int _set_main_bdev_label();
int _check_main_bdev_label();
- static int _read_main_bdev_label(
+ static int _read_multi_bdev_label(
CephContext* cct,
BlockDevice* bdev,
const std::string& path,
uuid_d fsid,
bluestore_bdev_label_t *out_label,
std::vector<uint64_t>* out_valid_positions = nullptr,
- bool* out_is_cloned = nullptr,
+ bool* out_is_multi = nullptr,
int64_t* out_epoch = nullptr);
int _set_bdev_label_size(const std::string& path, uint64_t size);
void _main_bdev_label_try_reserve();
std::vector<uint64_t>({disk_position}));
}
static int read_bdev_label(
- CephContext* cct, const std::string &path,
- bluestore_bdev_label_t *label, uint64_t disk_position = 0);
+ CephContext* cct,
+ const std::string &path,
+ bluestore_bdev_label_t *out_label,
+ std::vector<uint64_t>* out_valid_positions = nullptr,
+ bool* out_is_cloned = nullptr,
+ int64_t* out_epoch = nullptr);
static int write_bdev_label(
CephContext* cct, const std::string &path,
const bluestore_bdev_label_t& label, uint64_t disk_position = 0);
}
else if (action == "set-label-key") {
bluestore_bdev_label_t label;
- int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label);
+ std::vector<uint64_t> valid_positions;
+ bool is_multi = false;
+ int64_t epoch = -1;
+ int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label,
+ &valid_positions, &is_multi, &epoch);
if (r < 0) {
cerr << "unable to read label for " << devs.front() << ": "
<< cpp_strerror(r) << std::endl;
} else {
label.meta[key] = value;
}
- r = BlueStore::write_bdev_label(cct.get(), devs.front(), label);
- if (r < 0) {
- cerr << "unable to write label for " << devs.front() << ": "
- << cpp_strerror(r) << std::endl;
- exit(EXIT_FAILURE);
+ if (is_multi) {
+ epoch++;
+ label.meta["epoch"] = std::to_string(epoch);
+ }
+ bool wrote_at_least_one = false;
+ for (uint64_t position : valid_positions) {
+ r = BlueStore::write_bdev_label(cct.get(), devs.front(), label, position);
+ if (r < 0) {
+ cerr << "unable to write label for " << devs.front()
+ << " at 0x" << std::hex << position << std::dec
+ << ": " << cpp_strerror(r) << std::endl;
+ } else {
+ wrote_at_least_one = true;
+ }
+ }
+ if (!wrote_at_least_one) {
+ exit(EXIT_FAILURE);
}
}
else if (action == "rm-label-key") {
bluestore_bdev_label_t label;
- int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label);
+ std::vector<uint64_t> valid_positions;
+ bool is_multi = false;
+ int64_t epoch = -1;
+ int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label,
+ &valid_positions, &is_multi, &epoch);
if (r < 0) {
cerr << "unable to read label for " << devs.front() << ": "
<< cpp_strerror(r) << std::endl;
exit(EXIT_FAILURE);
}
label.meta.erase(key);
- r = BlueStore::write_bdev_label(cct.get(), devs.front(), label);
- if (r < 0) {
- cerr << "unable to write label for " << devs.front() << ": "
- << cpp_strerror(r) << std::endl;
- exit(EXIT_FAILURE);
+ if (is_multi) {
+ epoch++;
+ label.meta["epoch"] = std::to_string(epoch);
+ }
+ bool wrote_at_least_one = false;
+ for (uint64_t position : valid_positions) {
+ r = BlueStore::write_bdev_label(cct.get(), devs.front(), label, position);
+ if (r < 0) {
+ cerr << "unable to write label for " << devs.front()
+ << " at 0x" << std::hex << position << std::dec
+ << ": " << cpp_strerror(r) << std::endl;
+ } else {
+ wrote_at_least_one = true;
+ }
+ }
+ if (!wrote_at_least_one) {
+ exit(EXIT_FAILURE);
}
}
else if (action == "bluefs-bdev-sizes") {
}
bool read_bdev_label(bluestore_bdev_label_t* label, uint64_t position) {
string bdev_path = get_data_dir() + "/block";
- int r = BlueStore::read_bdev_label(g_ceph_context, bdev_path, label, position);
+ unique_ptr<BlockDevice> bdev(BlockDevice::create(
+ g_ceph_context, bdev_path, nullptr, nullptr, nullptr, nullptr));
+ int r = bdev->open(bdev_path);
+ if (r < 0)
+ return r;
+ r = BlueStore::debug_read_bdev_label(g_ceph_context, bdev.get(), bdev_path, label, position);
+ bdev->close();
return r;
}
bool write_bdev_label(const bluestore_bdev_label_t& label, uint64_t position) {
string bdev_path = get_data_dir() + "/block";
- int r = BlueStore::write_bdev_label(g_ceph_context, bdev_path, label, position);
+ unique_ptr<BlockDevice> bdev(BlockDevice::create(
+ g_ceph_context, bdev_path, nullptr, nullptr, nullptr, nullptr));
+ int r = bdev->open(bdev_path);
+ if (r < 0)
+ return r;
+ r = BlueStore::debug_write_bdev_label(g_ceph_context, bdev.get(), bdev_path, label, position);
+ bdev->close();
return r;
}
protected: