Skip to content

Commit

Permalink
DAOS-16863 dfs: disallow force removal of entries with caching (#15570)
Browse files Browse the repository at this point in the history
if a dfs sys mount has caching enabled, disable force removal of dir that does not check for child entries. DFS sys does not evict them from the cache in that case and that can cause namespace corruptions.

Signed-off-by: Mohamad Chaarawi <[email protected]>
  • Loading branch information
mchaarawi authored Dec 12, 2024
1 parent 30065cb commit eff5def
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/client/dfs/dfs_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,12 @@ dfs_sys_remove_type(dfs_sys_t *dfs_sys, const char *path, bool force,
return EINVAL;
if (path == NULL)
return EINVAL;
/*
* since we are not evicting child entries from the dfs sys cache in case of force removal
* of a dir, just disallow force removal if cache is enabled on the dfs sys mount.
*/
if (dfs_sys->hash && force)
return ENOTSUP;

rc = sys_path_parse(dfs_sys, &sys_path, path);
if (rc != 0)
Expand Down
49 changes: 33 additions & 16 deletions src/tests/suite/dfs_sys_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ dfs_sys_test_create_remove(void **state)
rc = dfs_sys_symlink(dfs_sys_mt, sym1_target, sym1);
assert_int_equal(rc, 0);

/** remove should return ENOTSUP with force since caching is enabled */
rc = dfs_sys_remove(dfs_sys_mt, dir1, true, NULL);
assert_int_equal(rc, ENOTSUP);
rc = dfs_sys_remove_type(dfs_sys_mt, dir1, true, S_IFDIR, NULL);
assert_int_equal(rc, ENOTSUP);

/** Remove dirs, links with remove */
rc = dfs_sys_remove(dfs_sys_mt, sym1, 0, 0);
assert_int_equal(rc, 0);
Expand Down Expand Up @@ -212,20 +218,18 @@ dfs_sys_test_create_remove(void **state)
rc = dfs_sys_close(obj);
assert_int_equal(rc, 0);

/** Remove files with remove */
rc = dfs_sys_remove(dfs_sys_mt, file2, 0, 0);
assert_int_equal(rc, 0);

/** Remove dirs, files, links with remove_type */
rc = dfs_sys_remove_type(dfs_sys_mt, file1, false, S_IFREG, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove_type(dfs_sys_mt, file2, false, S_IFREG, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove_type(dfs_sys_mt, sym1, false, S_IFLNK, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove_type(dfs_sys_mt, dir3, false, S_IFDIR, NULL);
assert_int_equal(rc, 0);

/** Remove dirs with remove_type(force) */
rc = dfs_sys_remove_type(dfs_sys_mt, dir1, true, S_IFDIR, NULL);
rc = dfs_sys_remove_type(dfs_sys_mt, dir2, false, S_IFDIR, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove_type(dfs_sys_mt, dir1, false, S_IFDIR, NULL);
assert_int_equal(rc, 0);

/** Create dirs, files with mknod */
Expand All @@ -242,8 +246,14 @@ dfs_sys_test_create_remove(void **state)
0, 0);
assert_int_equal(rc, 0);

/** Remove tree (dir) with remove(force) */
rc = dfs_sys_remove(dfs_sys_mt, dir1, true, NULL);
/** Remove tree with remove */
rc = dfs_sys_remove(dfs_sys_mt, file1, false, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove(dfs_sys_mt, dir3, false, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove(dfs_sys_mt, dir2, false, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove(dfs_sys_mt, dir1, false, NULL);
assert_int_equal(rc, 0);
}

Expand Down Expand Up @@ -640,7 +650,14 @@ dfs_sys_test_open_readdir(void **state)
rc = dfs_sys_closedir(dirp);
assert_int_equal(rc, 0);

rc = dfs_sys_remove(dfs_sys_mt, dir1, true, NULL);
for (i = 0; i < num_dirs; i++) {
rc = snprintf(buf, buf_size, "%s/sub%u", dir1, i);
assert_true(rc > 0);
rc = dfs_sys_remove(dfs_sys_mt, buf, false, 0);
assert_int_equal(rc, 0);
}
rc = dfs_sys_remove(dfs_sys_mt, dir1, false, NULL);
assert_int_equal(rc, 0);
}

/**
Expand Down Expand Up @@ -848,11 +865,11 @@ dfs_sys_test_mkdir(void **state)
rc = dfs_sys_mkdir(dfs_sys_mt, file, S_IWUSR | S_IRUSR, 0);
assert_int_equal(rc, EEXIST);

rc = dfs_sys_remove(dfs_sys_mt, file, true, NULL);
rc = dfs_sys_remove(dfs_sys_mt, file, false, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove(dfs_sys_mt, child, true, NULL);
rc = dfs_sys_remove(dfs_sys_mt, child, false, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove(dfs_sys_mt, parent, true, NULL);
rc = dfs_sys_remove(dfs_sys_mt, parent, false, NULL);
assert_int_equal(rc, 0);
}

Expand Down Expand Up @@ -885,11 +902,11 @@ dfs_sys_test_mkdir_p(void **state)
rc = dfs_sys_mkdir_p(dfs_sys_mt, file, S_IWUSR | S_IRUSR, 0);
assert_int_equal(rc, EEXIST);

rc = dfs_sys_remove(dfs_sys_mt, file, true, NULL);
rc = dfs_sys_remove(dfs_sys_mt, file, false, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove(dfs_sys_mt, child, true, NULL);
rc = dfs_sys_remove(dfs_sys_mt, child, false, NULL);
assert_int_equal(rc, 0);
rc = dfs_sys_remove(dfs_sys_mt, parent, true, NULL);
rc = dfs_sys_remove(dfs_sys_mt, parent, false, NULL);
assert_int_equal(rc, 0);
}

Expand Down

0 comments on commit eff5def

Please sign in to comment.