Skip to content

Commit

Permalink
DAOS-15069 dfs: use memcpy instead of snprintf for readdir (#13654)
Browse files Browse the repository at this point in the history
- memcpy is more efficient to avoid scanning the entire kds string.
- remove an assert and replace with error when looking up "."


#Pragmas from previous commit message:
Skip-checkpatch: true
Skip-python-bandit: true
Skip-build: true
Quick-build: true
Quick-Functional: true
Allow-unstable-test: true
#RPM-test-version: version[-release]
#RPM-test-version: 2.5.100
# VM1-label: ci_vm1
# Ubuntu-VM9-label: ci_vm9
# Leap15-VM9-label: ci_vm9
# EL8-VM9-label: ci_vm9
# HW-medium-label: ci_nvme5
# HW-large-label: ci_nvme9
Signed-off-by: Mohamad Chaarawi <[email protected]>
  • Loading branch information
mchaarawi authored and brianjmurrell committed Jan 31, 2024
1 parent e9a8ca3 commit ca82635
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/client/dfs/dfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ fetch_entry(dfs_layout_ver_t ver, daos_handle_t oh, daos_handle_t th, const char

/** TODO - not supported yet */
if (strcmp(name, ".") == 0)
D_ASSERT(0);
return ENOTSUP;

if (xnr) {
D_ALLOC_ARRAY(pxnames, xnr);
Expand Down Expand Up @@ -3790,11 +3790,8 @@ readdir_int(dfs_t *dfs, dfs_obj_t *obj, daos_anchor_t *anchor, uint32_t *nr,
D_GOTO(out, rc = daos_der2errno(rc));

for (ptr = enum_buf, i = 0; i < number; i++) {
int len;

len = snprintf(dirs[key_nr].d_name,
kds[i].kd_key_len + 1, "%s", ptr);
D_ASSERT(len >= kds[i].kd_key_len);
memcpy(dirs[key_nr].d_name, ptr, kds[i].kd_key_len);
dirs[key_nr].d_name[kds[i].kd_key_len] = '\0';
ptr += kds[i].kd_key_len;

/** stat the entry if requested */
Expand Down Expand Up @@ -6542,8 +6539,6 @@ dfs_listxattr(dfs_t *dfs, dfs_obj_t *obj, char *list, daos_size_t *size)
continue;

for (ptr = enum_buf, i = 0; i < number; i++) {
int len;

if (strncmp("x:", ptr, 2) != 0) {
ptr += kds[i].kd_key_len;
continue;
Expand All @@ -6556,10 +6551,8 @@ dfs_listxattr(dfs_t *dfs, dfs_obj_t *obj, char *list, daos_size_t *size)
if (list_size < kds[i].kd_key_len - 2)
continue;

len = snprintf(ptr_list, kds[i].kd_key_len - 1, "%s",
ptr + 2);
D_ASSERT(len >= kds[i].kd_key_len - 2);

memcpy(ptr_list, ptr + 2, kds[i].kd_key_len - 2);
ptr_list[kds[i].kd_key_len - 2] = '\0';
list_size -= kds[i].kd_key_len - 1;
ptr_list += kds[i].kd_key_len - 1;
ptr += kds[i].kd_key_len;
Expand Down

0 comments on commit ca82635

Please sign in to comment.