From: Adam Kupczyk Date: Thu, 5 Jun 2025 19:31:56 +0000 (+0000) Subject: test/test_bluefs.cc: Fix valgrind reported memleaks X-Git-Tag: v20.1.0~196^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=233ff38fd83290f988f4d8008efbbaae1df2bffa;p=ceph.git test/test_bluefs.cc: Fix valgrind reported memleaks 1. Moved BlueFS::FileWriter iovs cleanup from _drain_writer to destructor 2. Add missing umount()s, close_writer()s, delete writers Signed-off-by: Adam Kupczyk (cherry picked from commit 41c7e05be4eeacaaea87cab4addef7535f6bbcb7) --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 4972518d4b6d..12a0d6725202 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -4693,7 +4693,6 @@ void BlueFS::_drain_writer(FileWriter *h) if (bdev[i]) { if (h->iocv[i]) { h->iocv[i]->aio_wait(); - delete h->iocv[i]; } } } diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 8011292ebdc8..fd5af65f321b 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -434,6 +434,9 @@ public: // NOTE: caller must call BlueFS::close_writer() ~FileWriter() { --file->num_writers; + for (unsigned i = 0; i < MAX_BDEV; ++i) { + delete iocv[i]; + } } // note: BlueRocksEnv uses this append exclusively, so it's safe diff --git a/src/test/objectstore/test_bluefs.cc b/src/test/objectstore/test_bluefs.cc index 2193157cc8a2..b588839997ed 100644 --- a/src/test/objectstore/test_bluefs.cc +++ b/src/test/objectstore/test_bluefs.cc @@ -1137,7 +1137,7 @@ TEST(BlueFS, test_wal_migrate) { gen_debugable(70000, bl1); fs.append_try_flush(writer, bl1.c_str(), bl1.length()); fs.fsync(writer); - + fs.close_writer(writer); // WAL files don't update internal extents while writing to save memory, only on _replay fs.umount(); fs.mount(); @@ -1392,6 +1392,7 @@ TEST(BlueFS, test_wal_read_after_rollback_to_v1) { gen_debugable(70000, bl1); fs.append_try_flush(writer, bl1.c_str(), bl1.length()); fs.fsync(writer); + fs.close_writer(writer); g_ceph_context->_conf.set_val("bluefs_wal_envelope_mode", "false"); fs.umount(); @@ -1411,6 +1412,7 @@ TEST(BlueFS, test_wal_read_after_rollback_to_v1) { ASSERT_EQ(0, fs.open_for_write(dir_db, wal_file, &writer, false)); ASSERT_NE(nullptr, writer); ASSERT_EQ(writer->file->fnode.encoding, bluefs_node_encoding::PLAIN); + fs.close_writer(writer); } fs.umount(); } @@ -1628,6 +1630,7 @@ TEST(BlueFS, truncate_fsync) { fs.fsync(h); fs.close_writer(h); } + fs.umount(); } { //this was broken due to https://tracker.ceph.com/issues/55307 @@ -2082,6 +2085,7 @@ TEST(BlueFS, test_log_runway) { utime_t mtime; fs.stat("dir", "file", &file_size, &mtime); ASSERT_EQ(file_size, 9); + fs.umount(); } TEST(BlueFS, test_log_runway_2) { @@ -2139,6 +2143,7 @@ TEST(BlueFS, test_log_runway_2) { std::vector ls_longdir; fs.readdir(longdir, &ls_longdir); ASSERT_EQ(ls_longdir.front(), longfile); + fs.umount(); } TEST(BlueFS, test_log_runway_3) { @@ -2199,6 +2204,7 @@ TEST(BlueFS, test_log_runway_3) { fs.stat(longdir, longfile, &file_size, &mtime); ASSERT_EQ(file_size, 6); } + fs.umount(); } TEST(BlueFS, test_log_runway_advance_seq) { @@ -2223,6 +2229,7 @@ TEST(BlueFS, test_log_runway_advance_seq) { std::string longdir(max_log_runway*2, 'A'); ASSERT_EQ(fs.mkdir(longdir), 0); fs.compact_log(); + fs.umount(); } TEST(BlueFS, test_69481_truncate_corrupts_log) {