@@ -285,9 +285,11 @@ int main(int argc, char **argv)
285285 string dest_file;
286286 string key, value;
287287 vector<string> allocs_name;
288+ vector<string> bdev_type;
288289 string empty_sharding (1 , ' \0 ' );
289290 string new_sharding = empty_sharding;
290291 string resharding_ctrl;
292+ string really;
291293 int log_level = 30 ;
292294 bool fsck_deep = false ;
293295 po::options_description po_options (" Options" );
@@ -309,6 +311,8 @@ int main(int argc, char **argv)
309311 (" key,k" , po::value<string>(&key), " label metadata key name" )
310312 (" value,v" , po::value<string>(&value), " label metadata value" )
311313 (" allocator" , po::value<vector<string>>(&allocs_name), " allocator to inspect: 'block'/'bluefs-wal'/'bluefs-db'" )
314+ (" 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" )
312316 (" sharding" , po::value<string>(&new_sharding), " new sharding to apply" )
313317 (" resharding-ctrl" , po::value<string>(&resharding_ctrl), " gives control over resharding procedure details" )
314318 (" op" , po::value<string>(&action_aux),
@@ -340,7 +344,8 @@ int main(int argc, char **argv)
340344 " free-fragmentation, "
341345 " bluefs-stats, "
342346 " reshard, "
343- " show-sharding" )
347+ " show-sharding, "
348+ " trim" )
344349 ;
345350 po::options_description po_all (" All options" );
346351 po_all.add (po_options).add (po_positional);
@@ -572,6 +577,29 @@ int main(int argc, char **argv)
572577 exit (EXIT_FAILURE);
573578 }
574579 }
580+ if (action == " trim" ) {
581+ if (path.empty ()) {
582+ cerr << " must specify bluestore path" << std::endl;
583+ exit (EXIT_FAILURE);
584+ }
585+ if (really.empty () || strcmp (really.c_str (), " --yes-i-really-really-mean-it" ) != 0 ) {
586+ cerr << " Trimming a non healthy bluestore is a dangerous operation which could cause data loss, "
587+ << " please run fsck and confirm with --yes-i-really-really-mean-it option"
588+ << std::endl;
589+ exit (EXIT_FAILURE);
590+ }
591+ for (auto type : bdev_type) {
592+ if (!type.empty () &&
593+ type != " bdev-block" &&
594+ type != " bdev-db" &&
595+ type != " bdev-wal" ) {
596+ cerr << " unknown bdev type '" << type << " '" << std::endl;
597+ exit (EXIT_FAILURE);
598+ }
599+ }
600+ if (bdev_type.empty ())
601+ bdev_type = vector<string>{" bdev-block" , " bdev-db" , " bdev-wal" };
602+ }
575603
576604 if (action == " restore_cfb" ) {
577605#ifndef CEPH_BLUESTORE_TOOL_RESTORE_ALLOCATION
@@ -1175,6 +1203,20 @@ int main(int argc, char **argv)
11751203 exit (EXIT_FAILURE);
11761204 }
11771205 cout << sharding << std::endl;
1206+ } else if (action == " trim" ) {
1207+ BlueStore bluestore (cct.get (), path);
1208+ int r = bluestore.cold_open ();
1209+ if (r < 0 ) {
1210+ cerr << " error from cold_open: " << cpp_strerror (r) << std::endl;
1211+ exit (EXIT_FAILURE);
1212+ }
1213+ for (auto type : bdev_type) {
1214+ cout << " trimming: " << type << std::endl;
1215+ ostringstream outss;
1216+ bluestore.trim_free_space (type, outss);
1217+ cout << " status: " << outss.str () << std::endl;
1218+ }
1219+ bluestore.cold_close ();
11781220 } else {
11791221 cerr << " unrecognized action " << action << std::endl;
11801222 return 1 ;
0 commit comments