1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
12 #include "global/global_init.h"
13 #include "common/ceph_argparse.h"
14 #include "include/stringify.h"
15 #include "include/scope_guard.h"
16 #include "common/errno.h"
17 #include <gtest/gtest.h>
19 #include "os/bluestore/BlueFS.h"
21 std::unique_ptr
<char[]> gen_buffer(uint64_t size
)
23 std::unique_ptr
<char[]> buffer
= std::make_unique
<char[]>(size
);
24 std::independent_bits_engine
<std::default_random_engine
, CHAR_BIT
, unsigned char> e
;
25 std::generate(buffer
.get(), buffer
.get()+size
, std::ref(e
));
31 TempBdev(uint64_t size
)
32 : path
{get_temp_bdev(size
)}
37 const std::string path
;
39 static string
get_temp_bdev(uint64_t size
)
42 string fn
= "ceph_test_bluefs.tmp.block." + stringify(getpid())
43 + "." + stringify(++n
);
44 int fd
= ::open(fn
.c_str(), O_CREAT
|O_RDWR
|O_TRUNC
, 0644);
46 int r
= ::ftruncate(fd
, size
);
51 static void rm_temp_bdev(string f
)
58 uint64_t size
= 1048576 * 128;
61 BlueFS
fs(g_ceph_context
);
62 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
63 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
64 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
67 TEST(BlueFS
, mkfs_mount
) {
68 uint64_t size
= 1048576 * 128;
70 BlueFS
fs(g_ceph_context
);
71 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
72 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
74 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
75 ASSERT_EQ(0, fs
.mount());
76 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
77 ASSERT_EQ(fs
.get_total(BlueFS::BDEV_DB
), size
- 1048576);
78 ASSERT_LT(fs
.get_free(BlueFS::BDEV_DB
), size
- 1048576);
82 TEST(BlueFS
, mkfs_mount_duplicate_gift
) {
83 uint64_t size
= 1048576 * 128;
84 TempBdev bdev
{ size
};
85 bluefs_extent_t dup_ext
;
87 BlueFS
fs(g_ceph_context
);
88 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
89 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
91 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
92 ASSERT_EQ(0, fs
.mount());
95 BlueFS::FileWriter
*h
;
96 ASSERT_EQ(0, fs
.mkdir("dir"));
97 ASSERT_EQ(0, fs
.open_for_write("dir", "file1", &h
, false));
102 ceph_assert(h
->file
->fnode
.extents
.size() > 0);
103 dup_ext
= h
->file
->fnode
.extents
[0];
104 ceph_assert(dup_ext
.bdev
== BlueFS::BDEV_DB
);
112 BlueFS
fs(g_ceph_context
);
113 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
114 ASSERT_EQ(0, fs
.mount());
115 // free allocation presumably allocated for file1
116 std::cout
<< "duplicate extent: " << std::hex
117 << dup_ext
.offset
<< "~" << dup_ext
.length
118 << std::dec
<< std::endl
;
119 fs
.debug_inject_duplicate_gift(BlueFS::BDEV_DB
, dup_ext
.offset
, dup_ext
.length
);
121 // overwrite file1 with file2
122 BlueFS::FileWriter
*h
;
123 ASSERT_EQ(0, fs
.open_for_write("dir", "file2", &h
, false));
133 g_ceph_context
->_conf
.set_val_or_die("bluefs_log_replay_check_allocations", "true");
134 g_ceph_context
->_conf
.apply_changes(nullptr);
138 BlueFS
fs(g_ceph_context
);
139 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
140 ASSERT_NE(0, fs
.mount());
144 TEST(BlueFS
, write_read
) {
145 uint64_t size
= 1048576 * 128;
147 BlueFS
fs(g_ceph_context
);
148 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
149 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
151 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
152 ASSERT_EQ(0, fs
.mount());
153 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
155 BlueFS::FileWriter
*h
;
156 ASSERT_EQ(0, fs
.mkdir("dir"));
157 ASSERT_EQ(0, fs
.open_for_write("dir", "file", &h
, false));
165 BlueFS::FileReader
*h
;
166 ASSERT_EQ(0, fs
.open_for_read("dir", "file", &h
));
168 BlueFS::FileReaderBuffer
buf(4096);
169 ASSERT_EQ(9, fs
.read(h
, &buf
, 0, 1024, &bl
, NULL
));
170 ASSERT_EQ(0, strncmp("foobarbaz", bl
.c_str(), 9));
176 TEST(BlueFS
, small_appends
) {
177 uint64_t size
= 1048576 * 128;
179 BlueFS
fs(g_ceph_context
);
180 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
181 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
183 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
184 ASSERT_EQ(0, fs
.mount());
185 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
187 BlueFS::FileWriter
*h
;
188 ASSERT_EQ(0, fs
.mkdir("dir"));
189 ASSERT_EQ(0, fs
.open_for_write("dir", "file", &h
, false));
190 for (unsigned i
= 0; i
< 10000; ++i
) {
191 h
->append("abcdeabcdeabcdeabcdeabcdeabc", 23);
197 BlueFS::FileWriter
*h
;
198 ASSERT_EQ(0, fs
.open_for_write("dir", "file_sync", &h
, false));
199 for (unsigned i
= 0; i
< 1000; ++i
) {
200 h
->append("abcdeabcdeabcdeabcdeabcdeabc", 23);
201 ASSERT_EQ(0, fs
.fsync(h
));
208 TEST(BlueFS
, very_large_write
) {
209 // we'll write a ~3G file, so allocate more than that for the whole fs
210 uint64_t size
= 1048576 * 1024 * 8ull;
212 BlueFS
fs(g_ceph_context
);
214 bool old
= g_ceph_context
->_conf
.get_val
<bool>("bluefs_buffered_io");
215 g_ceph_context
->_conf
.set_val("bluefs_buffered_io", "false");
217 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
218 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
220 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
221 ASSERT_EQ(0, fs
.mount());
222 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
223 char buf
[1048571]; // this is biggish, but intentionally not evenly aligned
224 for (unsigned i
= 0; i
< sizeof(buf
); ++i
) {
228 BlueFS::FileWriter
*h
;
229 ASSERT_EQ(0, fs
.mkdir("dir"));
230 ASSERT_EQ(0, fs
.open_for_write("dir", "bigfile", &h
, false));
231 for (unsigned i
= 0; i
< 3*1024*1048576ull / sizeof(buf
); ++i
) {
232 h
->append(buf
, sizeof(buf
));
238 BlueFS::FileReader
*h
;
239 ASSERT_EQ(0, fs
.open_for_read("dir", "bigfile", &h
));
241 BlueFS::FileReaderBuffer
readbuf(10485760);
242 for (unsigned i
= 0; i
< 3*1024*1048576ull / sizeof(buf
); ++i
) {
244 fs
.read(h
, &readbuf
, i
* sizeof(buf
), sizeof(buf
), &bl
, NULL
);
245 int r
= memcmp(buf
, bl
.c_str(), sizeof(buf
));
247 cerr
<< "read got mismatch at offset " << i
*sizeof(buf
) << " r " << r
256 g_ceph_context
->_conf
.set_val("bluefs_buffered_io", stringify((int)old
));
259 #define ALLOC_SIZE 4096
261 void write_data(BlueFS
&fs
, uint64_t rationed_bytes
)
264 uint64_t written_bytes
= 0;
265 rationed_bytes
-= ALLOC_SIZE
;
268 ss
<< std::this_thread::get_id();
269 dir
.append(ss
.str());
271 dir
.append(to_string(j
));
272 ASSERT_EQ(0, fs
.mkdir(dir
));
274 string file
= "file.";
275 file
.append(to_string(j
));
276 BlueFS::FileWriter
*h
;
277 ASSERT_EQ(0, fs
.open_for_write(dir
, file
, &h
, false));
278 ASSERT_NE(nullptr, h
);
279 auto sg
= make_scope_guard([&fs
, h
] { fs
.close_writer(h
); });
281 std::unique_ptr
<char[]> buf
= gen_buffer(ALLOC_SIZE
);
282 bufferptr bp
= buffer::claim_char(ALLOC_SIZE
, buf
.get());
284 h
->append(bl
.c_str(), bl
.length());
289 written_bytes
+= g_conf()->bluefs_alloc_size
;
291 if ((rationed_bytes
- written_bytes
) <= g_conf()->bluefs_alloc_size
) {
297 void create_single_file(BlueFS
&fs
)
299 BlueFS::FileWriter
*h
;
301 string dir
= "dir.test";
302 ASSERT_EQ(0, fs
.mkdir(dir
));
303 string file
= "testfile";
304 ASSERT_EQ(0, fs
.open_for_write(dir
, file
, &h
, false));
306 std::unique_ptr
<char[]> buf
= gen_buffer(ALLOC_SIZE
);
307 bufferptr bp
= buffer::claim_char(ALLOC_SIZE
, buf
.get());
309 h
->append(bl
.c_str(), bl
.length());
314 void write_single_file(BlueFS
&fs
, uint64_t rationed_bytes
)
317 const string dir
= "dir.test";
318 const string file
= "testfile";
319 uint64_t written_bytes
= 0;
320 rationed_bytes
-= ALLOC_SIZE
;
322 BlueFS::FileWriter
*h
;
323 ASSERT_EQ(0, fs
.open_for_write(dir
, file
, &h
, false));
324 ASSERT_NE(nullptr, h
);
325 auto sg
= make_scope_guard([&fs
, h
] { fs
.close_writer(h
); });
327 std::unique_ptr
<char[]> buf
= gen_buffer(ALLOC_SIZE
);
328 bufferptr bp
= buffer::claim_char(ALLOC_SIZE
, buf
.get());
330 h
->append(bl
.c_str(), bl
.length());
335 written_bytes
+= g_conf()->bluefs_alloc_size
;
336 if ((rationed_bytes
- written_bytes
) <= g_conf()->bluefs_alloc_size
) {
342 bool writes_done
= false;
344 void sync_fs(BlueFS
&fs
)
347 if (writes_done
== true)
349 fs
.sync_metadata(false);
355 void do_join(std::thread
& t
)
360 void join_all(std::vector
<std::thread
>& v
)
362 std::for_each(v
.begin(),v
.end(),do_join
);
365 #define NUM_WRITERS 3
366 #define NUM_SYNC_THREADS 1
368 #define NUM_SINGLE_FILE_WRITERS 1
369 #define NUM_MULTIPLE_FILE_WRITERS 2
371 TEST(BlueFS
, test_flush_1
) {
372 uint64_t size
= 1048576 * 128;
374 g_ceph_context
->_conf
.set_val(
377 g_ceph_context
->_conf
.apply_changes(nullptr);
379 BlueFS
fs(g_ceph_context
);
380 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
381 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
383 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
384 ASSERT_EQ(0, fs
.mount());
385 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
387 std::vector
<std::thread
> write_thread_multiple
;
388 uint64_t effective_size
= size
- (32 * 1048576); // leaving the last 32 MB for log compaction
389 uint64_t per_thread_bytes
= (effective_size
/(NUM_MULTIPLE_FILE_WRITERS
+ NUM_SINGLE_FILE_WRITERS
));
390 for (int i
=0; i
<NUM_MULTIPLE_FILE_WRITERS
; i
++) {
391 write_thread_multiple
.push_back(std::thread(write_data
, std::ref(fs
), per_thread_bytes
));
394 create_single_file(fs
);
395 std::vector
<std::thread
> write_thread_single
;
396 for (int i
=0; i
<NUM_SINGLE_FILE_WRITERS
; i
++) {
397 write_thread_single
.push_back(std::thread(write_single_file
, std::ref(fs
), per_thread_bytes
));
400 join_all(write_thread_single
);
401 join_all(write_thread_multiple
);
406 TEST(BlueFS
, test_flush_2
) {
407 uint64_t size
= 1048576 * 256;
409 g_ceph_context
->_conf
.set_val(
412 g_ceph_context
->_conf
.apply_changes(nullptr);
414 BlueFS
fs(g_ceph_context
);
415 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
416 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
418 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
419 ASSERT_EQ(0, fs
.mount());
420 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
422 uint64_t effective_size
= size
- (128 * 1048576); // leaving the last 32 MB for log compaction
423 uint64_t per_thread_bytes
= (effective_size
/(NUM_WRITERS
));
424 std::vector
<std::thread
> write_thread_multiple
;
425 for (int i
=0; i
<NUM_WRITERS
; i
++) {
426 write_thread_multiple
.push_back(std::thread(write_data
, std::ref(fs
), per_thread_bytes
));
429 join_all(write_thread_multiple
);
434 TEST(BlueFS
, test_flush_3
) {
435 uint64_t size
= 1048576 * 256;
437 g_ceph_context
->_conf
.set_val(
440 g_ceph_context
->_conf
.apply_changes(nullptr);
442 BlueFS
fs(g_ceph_context
);
443 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
444 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
446 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
447 ASSERT_EQ(0, fs
.mount());
448 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
450 std::vector
<std::thread
> write_threads
;
451 uint64_t effective_size
= size
- (64 * 1048576); // leaving the last 11 MB for log compaction
452 uint64_t per_thread_bytes
= (effective_size
/(NUM_WRITERS
));
453 for (int i
=0; i
<NUM_WRITERS
; i
++) {
454 write_threads
.push_back(std::thread(write_data
, std::ref(fs
), per_thread_bytes
));
457 std::vector
<std::thread
> sync_threads
;
458 for (int i
=0; i
<NUM_SYNC_THREADS
; i
++) {
459 sync_threads
.push_back(std::thread(sync_fs
, std::ref(fs
)));
462 join_all(write_threads
);
464 join_all(sync_threads
);
469 TEST(BlueFS
, test_simple_compaction_sync
) {
470 g_ceph_context
->_conf
.set_val(
471 "bluefs_compact_log_sync",
473 uint64_t size
= 1048576 * 128;
476 BlueFS
fs(g_ceph_context
);
477 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
478 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
480 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
481 ASSERT_EQ(0, fs
.mount());
482 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
484 for (int i
=0; i
<10; i
++) {
486 dir
.append(to_string(i
));
487 ASSERT_EQ(0, fs
.mkdir(dir
));
488 for (int j
=0; j
<10; j
++) {
489 string file
= "file.";
490 file
.append(to_string(j
));
491 BlueFS::FileWriter
*h
;
492 ASSERT_EQ(0, fs
.open_for_write(dir
, file
, &h
, false));
493 ASSERT_NE(nullptr, h
);
494 auto sg
= make_scope_guard([&fs
, h
] { fs
.close_writer(h
); });
496 std::unique_ptr
<char[]> buf
= gen_buffer(4096);
497 bufferptr bp
= buffer::claim_char(4096, buf
.get());
499 h
->append(bl
.c_str(), bl
.length());
505 for (int i
=0; i
<10; i
+=2) {
507 dir
.append(to_string(i
));
508 for (int j
=0; j
<10; j
++) {
509 string file
= "file.";
510 file
.append(to_string(j
));
511 fs
.unlink(dir
, file
);
512 fs
.sync_metadata(false);
514 ASSERT_EQ(0, fs
.rmdir(dir
));
515 fs
.sync_metadata(false);
522 TEST(BlueFS
, test_simple_compaction_async
) {
523 g_ceph_context
->_conf
.set_val(
524 "bluefs_compact_log_sync",
526 uint64_t size
= 1048576 * 128;
529 BlueFS
fs(g_ceph_context
);
530 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
531 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
533 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
534 ASSERT_EQ(0, fs
.mount());
535 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
537 for (int i
=0; i
<10; i
++) {
539 dir
.append(to_string(i
));
540 ASSERT_EQ(0, fs
.mkdir(dir
));
541 for (int j
=0; j
<10; j
++) {
542 string file
= "file.";
543 file
.append(to_string(j
));
544 BlueFS::FileWriter
*h
;
545 ASSERT_EQ(0, fs
.open_for_write(dir
, file
, &h
, false));
546 ASSERT_NE(nullptr, h
);
547 auto sg
= make_scope_guard([&fs
, h
] { fs
.close_writer(h
); });
549 std::unique_ptr
<char[]> buf
= gen_buffer(4096);
550 bufferptr bp
= buffer::claim_char(4096, buf
.get());
552 h
->append(bl
.c_str(), bl
.length());
558 for (int i
=0; i
<10; i
+=2) {
560 dir
.append(to_string(i
));
561 for (int j
=0; j
<10; j
++) {
562 string file
= "file.";
563 file
.append(to_string(j
));
564 fs
.unlink(dir
, file
);
565 fs
.sync_metadata(false);
567 ASSERT_EQ(0, fs
.rmdir(dir
));
568 fs
.sync_metadata(false);
575 TEST(BlueFS
, test_compaction_sync
) {
576 uint64_t size
= 1048576 * 128;
578 g_ceph_context
->_conf
.set_val(
581 g_ceph_context
->_conf
.set_val(
582 "bluefs_compact_log_sync",
585 BlueFS
fs(g_ceph_context
);
586 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
587 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
589 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
590 ASSERT_EQ(0, fs
.mount());
591 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
593 std::vector
<std::thread
> write_threads
;
594 uint64_t effective_size
= size
- (32 * 1048576); // leaving the last 32 MB for log compaction
595 uint64_t per_thread_bytes
= (effective_size
/(NUM_WRITERS
));
596 for (int i
=0; i
<NUM_WRITERS
; i
++) {
597 write_threads
.push_back(std::thread(write_data
, std::ref(fs
), per_thread_bytes
));
600 std::vector
<std::thread
> sync_threads
;
601 for (int i
=0; i
<NUM_SYNC_THREADS
; i
++) {
602 sync_threads
.push_back(std::thread(sync_fs
, std::ref(fs
)));
605 join_all(write_threads
);
607 join_all(sync_threads
);
613 TEST(BlueFS
, test_compaction_async
) {
614 uint64_t size
= 1048576 * 128;
616 g_ceph_context
->_conf
.set_val(
619 g_ceph_context
->_conf
.set_val(
620 "bluefs_compact_log_sync",
623 BlueFS
fs(g_ceph_context
);
624 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
625 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
627 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
628 ASSERT_EQ(0, fs
.mount());
629 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
631 std::vector
<std::thread
> write_threads
;
632 uint64_t effective_size
= size
- (32 * 1048576); // leaving the last 32 MB for log compaction
633 uint64_t per_thread_bytes
= (effective_size
/(NUM_WRITERS
));
634 for (int i
=0; i
<NUM_WRITERS
; i
++) {
635 write_threads
.push_back(std::thread(write_data
, std::ref(fs
), per_thread_bytes
));
638 std::vector
<std::thread
> sync_threads
;
639 for (int i
=0; i
<NUM_SYNC_THREADS
; i
++) {
640 sync_threads
.push_back(std::thread(sync_fs
, std::ref(fs
)));
643 join_all(write_threads
);
645 join_all(sync_threads
);
651 TEST(BlueFS
, test_replay
) {
652 uint64_t size
= 1048576 * 128;
654 g_ceph_context
->_conf
.set_val(
657 g_ceph_context
->_conf
.set_val(
658 "bluefs_compact_log_sync",
661 BlueFS
fs(g_ceph_context
);
662 ASSERT_EQ(0, fs
.add_block_device(BlueFS::BDEV_DB
, bdev
.path
, false));
663 fs
.add_block_extent(BlueFS::BDEV_DB
, 1048576, size
- 1048576);
665 ASSERT_EQ(0, fs
.mkfs(fsid
, { BlueFS::BDEV_DB
, false, false }));
666 ASSERT_EQ(0, fs
.mount());
667 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
669 std::vector
<std::thread
> write_threads
;
670 uint64_t effective_size
= size
- (32 * 1048576); // leaving the last 32 MB for log compaction
671 uint64_t per_thread_bytes
= (effective_size
/(NUM_WRITERS
));
672 for (int i
=0; i
<NUM_WRITERS
; i
++) {
673 write_threads
.push_back(std::thread(write_data
, std::ref(fs
), per_thread_bytes
));
676 std::vector
<std::thread
> sync_threads
;
677 for (int i
=0; i
<NUM_SYNC_THREADS
; i
++) {
678 sync_threads
.push_back(std::thread(sync_fs
, std::ref(fs
)));
681 join_all(write_threads
);
683 join_all(sync_threads
);
687 // remount and check log can replay safe?
688 ASSERT_EQ(0, fs
.mount());
689 ASSERT_EQ(0, fs
.maybe_verify_layout({ BlueFS::BDEV_DB
, false, false }));
693 int main(int argc
, char **argv
) {
694 vector
<const char*> args
;
695 argv_to_vec(argc
, (const char **)argv
, args
);
697 map
<string
,string
> defaults
= {
698 { "debug_bluefs", "1/20" },
699 { "debug_bdev", "1/20" }
702 auto cct
= global_init(&defaults
, args
, CEPH_ENTITY_TYPE_CLIENT
,
703 CODE_ENVIRONMENT_UTILITY
,
704 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE
);
705 common_init_finish(g_ceph_context
);
706 g_ceph_context
->_conf
.set_val(
707 "enable_experimental_unrecoverable_data_corrupting_features",
709 g_ceph_context
->_conf
.apply_changes(nullptr);
711 ::testing::InitGoogleTest(&argc
, argv
);
712 return RUN_ALL_TESTS();