@@ -8949,30 +8949,6 @@ string BlueStore::get_device_path(unsigned id)
89498949 return res;
89508950}
89518951
8952- int BlueStore::_set_bdev_label_size(unsigned id, uint64_t size)
8953- {
8954- ceph_assert(bluefs);
8955- BlockDevice* my_bdev = bluefs->get_block_device(id);
8956- int r = -1;
8957- if (my_bdev != nullptr) {
8958- string my_path = get_device_path(id);
8959- bluestore_bdev_label_t label;
8960- r = _read_bdev_label(cct, my_bdev, my_path, &label);
8961- if (r < 0) {
8962- derr << "unable to read label for " << my_path << ": "
8963- << cpp_strerror(r) << dendl;
8964- } else {
8965- label.size = size;
8966- r = _write_bdev_label(cct, my_bdev, my_path, label);
8967- if (r < 0) {
8968- derr << "unable to write label for " << my_path << ": "
8969- << cpp_strerror(r) << dendl;
8970- }
8971- }
8972- }
8973- return r;
8974- }
8975-
89768952int BlueStore::expand_devices(ostream& out)
89778953{
89788954 // let's open in read-only mode first to be able to recover
@@ -8983,38 +8959,85 @@ int BlueStore::expand_devices(ostream& out)
89838959 ceph_assert(r == 0);
89848960 bluefs->dump_block_extents(out);
89858961 out << "Expanding DB/WAL..." << std::endl;
8962+ // updating dedicated devices first
89868963 for (auto devid : { BlueFS::BDEV_WAL, BlueFS::BDEV_DB}) {
8987- if (devid == bluefs_layout.shared_bdev ) {
8964+ if (devid == bluefs_layout.shared_bdev) {
89888965 continue;
89898966 }
8990- uint64_t size = bluefs->get_block_device_size(devid);
8967+ auto my_bdev = bluefs->get_block_device(devid);
8968+ uint64_t size = my_bdev ? my_bdev->get_size() : 0;
89918969 if (size == 0) {
89928970 // no bdev
89938971 continue;
89948972 }
8995- out << devid
8996- <<" : expanding " << " to 0x" << size << std::dec << std::endl;
8997- if (bluefs->bdev_support_label(devid)) {
8998- if (_set_bdev_label_size(devid, size) >= 0) {
8999- out << devid
9000- << " : size label updated to " << size
9001- << std::endl;
8973+ if (my_bdev->supported_bdev_label()) {
8974+ string my_path = get_device_path(devid);
8975+ bluestore_bdev_label_t my_label;
8976+ int r = _read_bdev_label(cct, my_bdev, my_path, &my_label);
8977+ if (r < 0) {
8978+ derr << "unable to read label for " << my_path << ": "
8979+ << cpp_strerror(r) << dendl;
8980+ continue;
8981+ } else {
8982+ if (size == my_label.size) {
8983+ // no need to expand
8984+ out << devid
8985+ << " : nothing to do, skipped"
8986+ << std::endl;
8987+ continue;
8988+ } else if (size < my_label.size) {
8989+ // something weird in bdev label
8990+ out << devid
8991+ <<" : ERROR: bdev label is above device size, skipped"
8992+ << std::endl;
8993+ continue;
8994+ } else {
8995+ my_label.size = size;
8996+ out << devid
8997+ << " : Expanding to 0x" << std::hex << size
8998+ << std::dec << "(" << byte_u_t(size) << ")"
8999+ << std::endl;
9000+ r = _write_bdev_label(cct, my_bdev, my_path, my_label);
9001+ if (r < 0) {
9002+ derr << "unable to write label for " << my_path << ": "
9003+ << cpp_strerror(r) << dendl;
9004+ } else {
9005+ out << devid
9006+ << " : size updated to 0x" << std::hex << size
9007+ << std::dec << "(" << byte_u_t(size) << ")"
9008+ << std::endl;
9009+ }
9010+ }
90029011 }
90039012 }
90049013 }
9014+ // now proceed with a shared device
90059015 uint64_t size0 = fm->get_size();
90069016 uint64_t size = bdev->get_size();
9007- if (size0 < size) {
9008- out << bluefs_layout.shared_bdev
9009- << " : expanding " << " from 0x" << std::hex
9010- << size0 << " to 0x" << size << std::dec << std::endl;
9011- _write_out_fm_meta(size);
9012- if (bdev->supported_bdev_label()) {
9013- out << bluefs_layout.shared_bdev
9014- << " : size label updated to " << size
9015- << std::endl;
9017+ auto devid = bluefs_layout.shared_bdev;
9018+ auto aligned_size = p2align(size, min_alloc_size);
9019+ if (aligned_size == size0) {
9020+ // no need to expand
9021+ out << devid
9022+ << " : nothing to do, skipped"
9023+ << std::endl;
9024+ } else if (aligned_size < size0) {
9025+ // something weird in bdev label
9026+ out << devid
9027+ << " : ERROR: previous device size is above the current one, skipped"
9028+ << std::endl;
9029+ } else {
9030+ auto my_path = get_device_path(devid);
9031+ out << devid
9032+ <<" : Expanding to 0x" << std::hex << size
9033+ << std::dec << "(" << byte_u_t(size) << ")"
9034+ << std::endl;
9035+ r = _write_out_fm_meta(size);
9036+ if (r != 0) {
9037+ derr << "unable to write out fm meta for " << my_path << ": "
9038+ << cpp_strerror(r) << dendl;
9039+ } else if (bdev->supported_bdev_label()) {
90169040 bdev_label.size = size;
9017-
90189041 uint64_t lsize = std::max(BDEV_LABEL_BLOCK_SIZE, min_alloc_size);
90199042 for (uint64_t loc : bdev_label_positions) {
90209043 if ((loc >= size0) && (loc + lsize <= size)) {
@@ -9024,22 +9047,32 @@ int BlueStore::expand_devices(ostream& out)
90249047 }
90259048 }
90269049 }
9027- _write_bdev_label(cct, bdev,
9028- get_device_path(bluefs_layout.shared_bdev),
9029- bdev_label, bdev_label_valid_locations);
9050+ r = _write_bdev_label(cct, bdev, my_path,
9051+ bdev_label, bdev_label_valid_locations);
9052+ if (r != 0) {
9053+ derr << "unable to write label(s) for " << my_path << ": "
9054+ << cpp_strerror(r) << dendl;
9055+ }
90309056 }
9031- _close_db_and_around();
9057+ if (r == 0) {
9058+ out << devid
9059+ << " : size updated to 0x" << std::hex << size
9060+ << std::dec << "(" << byte_u_t(size) << ")"
9061+ << std::endl;
9062+ _close_db_and_around();
90329063
9033- //
9034- // Mount in read/write to sync expansion changes
9035- // and make sure everything is all right.
9036- //
9037- before_expansion_bdev_size = size0; //preserve orignal size to permit following
9038- // _db_open_and_around() do some post-init stuff
9039- // on opened allocator
9064+ //
9065+ // Mount in read/write to sync expansion changes
9066+ // and make sure everything is all right.
9067+ //
9068+ before_expansion_bdev_size = size0; // preserve orignal size to permit
9069+ // following _db_open_and_around()
9070+ // do some post-init stuff on opened
9071+ // allocator.
90409072
9041- r = _open_db_and_around(false);
9042- ceph_assert(r == 0);
9073+ r = _open_db_and_around(false);
9074+ ceph_assert(r == 0);
9075+ }
90439076 }
90449077 _close_db_and_around();
90459078 return r;
0 commit comments