self.background_procs.append(rproc)
return rproc
- def create_n_files(self, fs_path, count, sync=False, dirsync=False, unlink=False, finaldirsync=False):
+ def create_n_files(self, fs_path, count, sync=False, dirsync=False,
+ unlink=False, finaldirsync=False, hard_links=0):
"""
Create n files.
:param dirsync: sync the containing directory after closing the file
:param unlink: unlink the file after closing
:param finaldirsync: sync the containing directory after closing the last file
+ :param hard_links: create given number of hard link(s) for each file
"""
assert(self.is_mounted())
pyscript = dedent(f"""
import os
+ import uuid
n = {count}
+ create_hard_links = False
+ if {hard_links} > 0:
+ create_hard_links = True
path = "{abs_path}"
dpath = os.path.dirname(path)
os.unlink(fpath)
if {dirsync}:
os.fsync(dirfd)
+ if create_hard_links:
+ for j in range({hard_links}):
+ os.system(f"ln {{fpath}} {{dpath}}/{{fnameprefix}}_{{i}}_{{uuid.uuid4()}}")
if {finaldirsync}:
os.fsync(dirfd)
finally:
command = "flush_path /"
self.asok_command(mds_rank, command, success_validator)
+ def scrub_with_stray_evaluation(self, fs, mnt, path, flag, files=2000,
+ _hard_links=3):
+ fs.set_allow_new_snaps(True)
+
+ test_dir = "stray_eval_dir"
+ mnt.run_shell(["mkdir", test_dir])
+ client_path = os.path.join(mnt.mountpoint, test_dir)
+ mnt.create_n_files(fs_path=f"{test_dir}/file", count=files,
+ hard_links=_hard_links)
+ mnt.run_shell(["mkdir", f"{client_path}/.snap/snap1-{test_dir}"])
+ mnt.run_shell(f"find {client_path}/ -type f -delete")
+ mnt.run_shell(["rmdir", f"{client_path}/.snap/snap1-{test_dir}"])
+ perf_dump = fs.rank_tell(["perf", "dump"], 0)
+ self.assertNotEqual(perf_dump.get('mds_cache').get('num_strays'),
+ 0, "mdcache.num_strays is zero")
+
+ log.info(
+ f"num of strays: {perf_dump.get('mds_cache').get('num_strays')}")
+
+ out_json = fs.run_scrub(["start", path, flag])
+ self.assertNotEqual(out_json, None)
+ self.assertEqual(out_json["return_code"], 0)
+
+ self.assertEqual(
+ fs.wait_until_scrub_complete(tag=out_json["scrub_tag"]), True)
+
+ perf_dump = fs.rank_tell(["perf", "dump"], 0)
+ self.assertEqual(int(perf_dump.get('mds_cache').get('num_strays')),
+ 0, "mdcache.num_strays is non-zero")
+
def test_scrub_repair(self):
mds_rank = 0
test_dir = "scrub_repair_path"
# fragstat should be fixed
self.mount_a.run_shell(["rmdir", test_dir])
+ def test_stray_evaluation_with_scrub(self):
+ """
+ test that scrub can iterate over ~mdsdir and evaluate strays
+ """
+ self.scrub_with_stray_evaluation(self.fs, self.mount_a, "~mdsdir",
+ "recursive")
+
+ def test_flag_scrub_mdsdir(self):
+ """
+ test flag scrub_mdsdir
+ """
+ self.scrub_with_stray_evaluation(self.fs, self.mount_a, "/",
+ "scrub_mdsdir")
+
@staticmethod
def json_validator(json_out, rc, element, expected_value):
if rc != 0: