Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAOS-15069 dfs: use memcpy instead of snprintf for readdir #13654

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

mchaarawi
Copy link
Contributor

@mchaarawi mchaarawi commented Jan 23, 2024

  • memcpy is more efficient to avoid scanning the entire kds string.
  • remove an assert and replace with error when looking up "."

Features: dfs

Required-githooks: true

Before requesting gatekeeper:

  • Two review approvals and any prior change requests have been resolved.
  • Testing is complete and all tests passed or there is a reason documented in the PR why it should be force landed and forced-landing tag is set.
  • Features: (or Test-tag*) commit pragma was used or there is a reason documented that there are no appropriate tags for this PR.
  • Commit messages follows the guidelines outlined here.
  • Any tests skipped by the ticket being addressed have been run and passed in the PR.

Gatekeeper:

  • You are the appropriate gatekeeper to be landing the patch.
  • The PR has 2 reviews by people familiar with the code, including appropriate watchers.
  • Githooks were used. If not, request that user install them and check copyright dates.
  • Checkpatch issues are resolved. Pay particular attention to ones that will show up on future PRs.
  • All builds have passed. Check non-required builds for any new compiler warnings.
  • Sufficient testing is done. Check feature pragmas and test tags and that tests skipped for the ticket are run and now pass with the changes.
  • If applicable, the PR has addressed any potential version compatibility issues.
  • Check the target branch. If it is master branch, should the PR go to a feature branch? If it is a release branch, does it have merge approval in the JIRA ticket.
  • Extra checks if forced landing is requested
    • Review comments are sufficiently resolved, particularly by prior reviewers that requested changes.
    • No new NLT or valgrind warnings. Check the classic view.
    • Quick-build or Quick-functional is not used.
  • Fix the commit message upon landing. Check the standard here. Edit it to create a single commit. If necessary, ask submitter for a new summary.

- strncpy is more efficient to avoid scanning the entire kds string.
- remove an assert and replace with error when looking up "."

Features: dfs

Required-githooks: true

Signed-off-by: Mohamad Chaarawi <[email protected]>
Copy link

Bug-tracker data:
Ticket title is 'dfs_readdir complexity is quadratic in number of dirents'
Status is 'Open'
Labels: 'triaged'
https://daosio.atlassian.net/browse/DAOS-15069

@mchaarawi mchaarawi marked this pull request as ready for review January 23, 2024 21:22
@mchaarawi mchaarawi requested a review from a team as a code owner January 23, 2024 21:22
yuvale2
yuvale2 previously approved these changes Jan 23, 2024
Copy link
Collaborator

@yuvale2 yuvale2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

jolivier23
jolivier23 previously approved these changes Jan 24, 2024
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is progress but wasn't there a different ticket with a reprodyucer for this? Without seeing that ticket could dfs_lookup_rel() skip over entiries named "." when doing the path walk, then the rerroducer should pass rather than exit gracefully as presumably it does with this fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can leave that case for the ticket. this is fine for now

Comment on lines 3793 to 3794
strncpy(dirs[key_nr].d_name, ptr, kds[i].kd_key_len);
dirs[key_nr].d_name[kds[i].kd_key_len] = '\0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I'd been through daos and remove most of the places where snprintf() was used with "%s" but I must have missed this one. I think here though as dfs isn't ever doing anything with the entry names then it could just treat them as a memory region and use memcpy(). strncpy() will do two extra steps, check the length of the input string and pad the output buffer with \0, neither of which are of benefit in this case.

The same fix should also be applied to the dfs_listxattr code I assume?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, memcpy is better in this case.

Features: dfs
Required-githooks: true

Signed-off-by: Mohamad Chaarawi <[email protected]>
@mchaarawi mchaarawi dismissed stale reviews from jolivier23 and yuvale2 via f4c85e4 January 25, 2024 15:26
@mchaarawi mchaarawi changed the title DAOS-15069 dfs: use strncpy instead of snprintf for readdir DAOS-15069 dfs: use memcpy instead of snprintf for readdir Jan 25, 2024
@@ -3790,7 +3790,7 @@ 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++) {
strncpy(dirs[key_nr].d_name, ptr, kds[i].kd_key_len);
memcpy(dirs[key_nr].d_name, ptr, kds[i].kd_key_len);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check that kds[i].kd_key_len < sizeof(dirs[key_nr].d_name)? (I realize that this wasn't checked before, maybe it's guaranteed elsewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that condition would be false, then we have landed some data corruption in the container and this would be the least of the problems :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we don't detect it here, we'll have two data corruptions. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my point was we probably won't even get here if there is data corruption in the container.
but sure, i can add that check if needed to repush. otherwise can add it in another PR im working on.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding in another PR sounds good to me.

Copy link
Collaborator

@yuvale2 yuvale2 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, if the check is 100% redundant, a comment that explains this would help (it's not obvious unless you know the server side, I guess).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is an issue here but adding in another PR seems the way to go.

@daosbuild1
Copy link
Collaborator

Test stage Functional Hardware Large completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-13654/2/execution/node/1553/log

@mchaarawi mchaarawi merged commit 3732d42 into master Jan 30, 2024
50 checks passed
@mchaarawi mchaarawi deleted the mschaara/dfs_readdir_cpy branch January 30, 2024 15:07
mchaarawi added a commit that referenced this pull request Jan 30, 2024
- memcpy is more efficient to avoid scanning the entire kds string.
- remove an assert and replace with error when looking up "."

Signed-off-by: Mohamad Chaarawi <[email protected]>
brianjmurrell pushed a commit that referenced this pull request Jan 31, 2024
- 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]>
mchaarawi added a commit that referenced this pull request Feb 1, 2024
…13697)

- memcpy is more efficient to avoid scanning the entire kds string.
- remove an assert and replace with error when looking up "."

Signed-off-by: Mohamad Chaarawi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants