-
Notifications
You must be signed in to change notification settings - Fork 305
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
Conversation
- 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]>
Bug-tracker data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@@ -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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/client/dfs/dfs.c
Outdated
strncpy(dirs[key_nr].d_name, ptr, kds[i].kd_key_len); | ||
dirs[key_nr].d_name[kds[i].kd_key_len] = '\0'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]>
@@ -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); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
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 |
- 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]>
- 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]>
…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]>
Features: dfs
Required-githooks: true
Before requesting gatekeeper:
Features:
(orTest-tag*
) commit pragma was used or there is a reason documented that there are no appropriate tags for this PR.Gatekeeper: