|
4 | 4 | from tasks.cephfs.cephfs_test_case import CephFSTestCase |
5 | 5 | from teuthology.exceptions import CommandFailedError |
6 | 6 | from textwrap import dedent |
| 7 | +from threading import Thread |
7 | 8 | import errno |
8 | 9 | import platform |
9 | 10 | import time |
@@ -293,6 +294,71 @@ def test_file_sync_stuck_for_around_5s(self): |
293 | 294 | dir_path = "file_sync_do_not_wait_mdlog_testdir" |
294 | 295 | self._test_sync_stuck_for_around_5s(dir_path, True) |
295 | 296 |
|
| 297 | + def test_file_filesystem_sync_crash(self): |
| 298 | + """ |
| 299 | + To check whether the kernel crashes when doing the file/filesystem sync. |
| 300 | + """ |
| 301 | + |
| 302 | + stop_thread = False |
| 303 | + dir_path = "file_filesystem_sync_crash_testdir" |
| 304 | + self.mount_a.run_shell(["mkdir", dir_path]) |
| 305 | + |
| 306 | + def mkdir_rmdir_thread(mount, path): |
| 307 | + #global stop_thread |
| 308 | + |
| 309 | + log.info(" mkdir_rmdir_thread starting...") |
| 310 | + num = 0 |
| 311 | + while not stop_thread: |
| 312 | + n = num |
| 313 | + m = num |
| 314 | + for __ in range(10): |
| 315 | + mount.run_shell(["mkdir", os.path.join(path, f"{n}")]) |
| 316 | + n += 1 |
| 317 | + for __ in range(10): |
| 318 | + mount.run_shell(["rm", "-rf", os.path.join(path, f"{m}")]) |
| 319 | + m += 1 |
| 320 | + num += 10 |
| 321 | + log.info(" mkdir_rmdir_thread stopped") |
| 322 | + |
| 323 | + def filesystem_sync_thread(mount, path): |
| 324 | + #global stop_thread |
| 325 | + |
| 326 | + log.info(" filesystem_sync_thread starting...") |
| 327 | + while not stop_thread: |
| 328 | + mount.run_shell(["sync"]) |
| 329 | + log.info(" filesystem_sync_thread stopped") |
| 330 | + |
| 331 | + def file_sync_thread(mount, path): |
| 332 | + #global stop_thread |
| 333 | + |
| 334 | + log.info(" file_sync_thread starting...") |
| 335 | + pyscript = dedent(""" |
| 336 | + import os |
| 337 | +
|
| 338 | + path = "{path}" |
| 339 | + dfd = os.open(path, os.O_DIRECTORY) |
| 340 | + os.fsync(dfd) |
| 341 | + os.close(dfd) |
| 342 | + """.format(path=path)) |
| 343 | + |
| 344 | + while not stop_thread: |
| 345 | + mount.run_shell(['python3', '-c', pyscript]) |
| 346 | + log.info(" file_sync_thread stopped") |
| 347 | + |
| 348 | + td1 = Thread(target=mkdir_rmdir_thread, args=(self.mount_a, dir_path,)) |
| 349 | + td2 = Thread(target=filesystem_sync_thread, args=(self.mount_a, dir_path,)) |
| 350 | + td3 = Thread(target=file_sync_thread, args=(self.mount_a, dir_path,)) |
| 351 | + |
| 352 | + td1.start() |
| 353 | + td2.start() |
| 354 | + td3.start() |
| 355 | + time.sleep(1200) # run 20 minutes |
| 356 | + stop_thread = True |
| 357 | + td1.join() |
| 358 | + td2.join() |
| 359 | + td3.join() |
| 360 | + self.mount_a.run_shell(["rm", "-rf", dir_path]) |
| 361 | + |
296 | 362 |
|
297 | 363 | class TestCacheDrop(CephFSTestCase): |
298 | 364 | CLIENTS_REQUIRED = 1 |
|
0 commit comments