Skip to content

Commit 274413f

Browse files
authored
Merge pull request ceph#59762 from aclamk/wip-aclamk-cbt-combined
ceph-bluestore-tool: Fixes for multilple bdev label
2 parents 4ebcd01 + afeaeb7 commit 274413f

File tree

4 files changed

+89
-8
lines changed

4 files changed

+89
-8
lines changed

doc/man/8/ceph-bluestore-tool.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Synopsis
3030
| **ceph-bluestore-tool** reshard --path *osd path* --sharding *new sharding* [ --sharding-ctrl *control string* ]
3131
| **ceph-bluestore-tool** show-sharding --path *osd path*
3232
| **ceph-bluestore-tool** trim --path *osd path*
33+
| **ceph-bluestore-tool** zap-device --dev *dev path*
3334
3435

3536
Description
@@ -108,7 +109,8 @@ Commands
108109

109110
:command:`show-label` --dev *device* [...]
110111

111-
Show device label(s).
112+
Show device label(s).
113+
The label may be printed while an OSD is running.
112114

113115
:command:`free-dump` --path *osd path* [ --allocator block/bluefs-wal/bluefs-db/bluefs-slow ]
114116

@@ -141,6 +143,10 @@ Commands
141143
and allows the drive to perform more efficient internal housekeeping.
142144
If BlueStore runs with discard enabled, this option may not be useful.
143145

146+
:command: `zap-device` --dev *dev path*
147+
148+
Zeros all device label locations. This effectively makes device appear empty.
149+
144150
Options
145151
=======
146152

@@ -202,15 +208,19 @@ Useful to provide necessary configuration options when access to monitor/ceph.co
202208
Device labels
203209
=============
204210

205-
Every BlueStore block device has a single block label at the beginning of the
206-
device. You can dump the contents of the label with::
211+
Every BlueStore block device has a block label at the beginning of the device.
212+
You can dump the contents of the label with::
207213

208214
ceph-bluestore-tool show-label --dev *device*
209215

210216
The main device will have a lot of metadata, including information
211217
that used to be stored in small files in the OSD data directory. The
212218
auxiliary devices (db and wal) will only have the minimum required
213219
fields (OSD UUID, size, device type, birth time).
220+
The main device contains additional label copies at offsets: 1G, 10G, 100G and 1000G.
221+
Corrupted labels are fixed as part of repair::
222+
223+
ceph-bluestore-tool repair --dev *device*
214224

215225
OSD directory priming
216226
=====================

src/os/bluestore/BlueStore.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6928,6 +6928,10 @@ int BlueStore::read_bdev_label(
69286928
{
69296929
unique_ptr<BlockDevice> bdev(BlockDevice::create(
69306930
cct, path, nullptr, nullptr, nullptr, nullptr));
6931+
if (!bdev) {
6932+
return -EIO;
6933+
}
6934+
bdev->set_no_exclusive_lock();
69316935
int r = bdev->open(path);
69326936
if (r < 0)
69336937
return r;
@@ -8988,6 +8992,47 @@ void BlueStore::trim_free_space(const string& type, std::ostream& outss)
89888992
}
89898993
}
89908994

8995+
int BlueStore::zap_device(CephContext* cct, const string& dev)
8996+
{
8997+
string path = dev; // dummy var for dout
8998+
uint64_t brush_size;
8999+
dout(5) << __func__ << " " << dev << dendl;
9000+
unique_ptr<BlockDevice>
9001+
_bdev(BlockDevice::create(cct, dev, nullptr, nullptr, nullptr, nullptr));
9002+
int r = _bdev->open(dev);
9003+
if (r < 0)
9004+
goto fail;
9005+
brush_size = std::max(_bdev->get_block_size(), BDEV_LABEL_BLOCK_SIZE);
9006+
9007+
for (auto off : bdev_label_positions) {
9008+
uint64_t end = std::min(off + brush_size, _bdev->get_size());
9009+
if (end > off) {
9010+
uint64_t l = end - off;
9011+
bufferlist bl;
9012+
bl.append_zero(l);
9013+
dout(10) << __func__ << " writing 0x"
9014+
<< std::hex << off << "~" << l
9015+
<< std::dec << " to " << dev
9016+
<< dendl;
9017+
r = _bdev->write(off, bl, false);
9018+
if (r < 0) {
9019+
derr << __func__ << " error writing 0x"
9020+
<< std::hex << off << "~" << l
9021+
<< std::dec << " to " << dev
9022+
<< " : " << cpp_strerror(r) << dendl;
9023+
break;
9024+
}
9025+
} else {
9026+
break;
9027+
}
9028+
}
9029+
9030+
_bdev->close();
9031+
9032+
fail:
9033+
return r;
9034+
}
9035+
89919036
void BlueStore::set_cache_shards(unsigned num)
89929037
{
89939038
dout(10) << __func__ << " " << num << dendl;

src/os/bluestore/BlueStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,7 @@ class BlueStore : public ObjectStore,
31923192

31933193
int dump_bluefs_sizes(std::ostream& out);
31943194
void trim_free_space(const std::string& type, std::ostream& outss);
3195+
static int zap_device(CephContext* cct, const std::string& dev);
31953196

31963197
public:
31973198
int statfs(struct store_statfs_t *buf,

src/os/bluestore/bluestore_tool.cc

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ int main(int argc, char **argv)
289289
string empty_sharding(1, '\0');
290290
string new_sharding = empty_sharding;
291291
string resharding_ctrl;
292-
string really;
293292
int log_level = 30;
294293
bool fsck_deep = false;
295294
po::options_description po_options("Options");
@@ -312,7 +311,7 @@ int main(int argc, char **argv)
312311
("value,v", po::value<string>(&value), "label metadata value")
313312
("allocator", po::value<vector<string>>(&allocs_name), "allocator to inspect: 'block'/'bluefs-wal'/'bluefs-db'")
314313
("bdev-type", po::value<vector<string>>(&bdev_type), "bdev type to inspect: 'bdev-block'/'bdev-wal'/'bdev-db'")
315-
("really", po::value<string>(&really), "--yes-i-really-really-mean-it")
314+
("yes-i-really-really-mean-it", "additional confirmation for dangerous commands")
316315
("sharding", po::value<string>(&new_sharding), "new sharding to apply")
317316
("resharding-ctrl", po::value<string>(&resharding_ctrl), "gives control over resharding procedure details")
318317
("op", po::value<string>(&action_aux),
@@ -345,7 +344,9 @@ int main(int argc, char **argv)
345344
"bluefs-stats, "
346345
"reshard, "
347346
"show-sharding, "
348-
"trim")
347+
"trim, "
348+
"zap-device"
349+
)
349350
;
350351
po::options_description po_all("All options");
351352
po_all.add(po_options).add(po_positional);
@@ -354,7 +355,11 @@ int main(int argc, char **argv)
354355
po::variables_map vm;
355356
try {
356357
po::parsed_options parsed =
357-
po::command_line_parser(argc, argv).options(po_all).allow_unregistered().run();
358+
po::command_line_parser(argc, argv).options(po_all)
359+
.allow_unregistered()
360+
.style(po::command_line_style::default_style &
361+
~po::command_line_style::allow_guessing)
362+
.run();
358363
po::store( parsed, vm);
359364
po::notify(vm);
360365
ceph_option_strings = po::collect_unrecognized(parsed.options,
@@ -582,7 +587,7 @@ int main(int argc, char **argv)
582587
cerr << "must specify bluestore path" << std::endl;
583588
exit(EXIT_FAILURE);
584589
}
585-
if (really.empty() || strcmp(really.c_str(), "--yes-i-really-really-mean-it") != 0) {
590+
if (!vm.count("yes-i-really-really-mean-it")) {
586591
cerr << "Trimming a non healthy bluestore is a dangerous operation which could cause data loss, "
587592
<< "please run fsck and confirm with --yes-i-really-really-mean-it option"
588593
<< std::endl;
@@ -600,6 +605,18 @@ int main(int argc, char **argv)
600605
if (bdev_type.empty())
601606
bdev_type = vector<string>{"bdev-block", "bdev-db", "bdev-wal"};
602607
}
608+
if (action == "zap-device") {
609+
if (devs.empty()) {
610+
cerr << "must specify device(s) with --dev option" << std::endl;
611+
exit(EXIT_FAILURE);
612+
}
613+
if (!vm.count("yes-i-really-really-mean-it")) {
614+
cerr << "zap-osd is a DESTRUCTIVE operation, it causes OSD data loss, "
615+
<< "please confirm with --yes-i-really-really-mean-it option"
616+
<< std::endl;
617+
exit(EXIT_FAILURE);
618+
}
619+
}
603620

604621
if (action == "restore_cfb") {
605622
#ifndef CEPH_BLUESTORE_TOOL_RESTORE_ALLOCATION
@@ -1249,6 +1266,14 @@ int main(int argc, char **argv)
12491266
cout << "status: " << outss.str() << std::endl;
12501267
}
12511268
bluestore.cold_close();
1269+
} else if (action == "zap-device") {
1270+
for(auto& dev : devs) {
1271+
int r = BlueStore::zap_device(cct.get(), dev);
1272+
if (r < 0) {
1273+
cerr << "error from zap: " << cpp_strerror(r) << std::endl;
1274+
exit(EXIT_FAILURE);
1275+
}
1276+
}
12521277
} else {
12531278
cerr << "unrecognized action " << action << std::endl;
12541279
return 1;

0 commit comments

Comments
 (0)