Skip to content

Add fstat to OsSysCalls#24298

Merged
alyssawilk merged 18 commits intoenvoyproxy:mainfrom
ravenblackx:fstat
Dec 9, 2022
Merged

Add fstat to OsSysCalls#24298
alyssawilk merged 18 commits intoenvoyproxy:mainfrom
ravenblackx:fstat

Conversation

@ravenblackx
Copy link
Contributor

@ravenblackx ravenblackx commented Dec 1, 2022

Commit Message: Add fstat to OsSysCalls
Additional Description: Just another os call wrapper. This functionality will be useful in file system cache implementation.
Risk Level: Very low, not changing any production code paths.
Testing: Added a unit test covering the new function and several others.
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: Identical implementation for Posix and Windows.

Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
(.circleci yaml CI failure)

Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
@ravenblackx ravenblackx changed the title Add fstat to OsSysCalls Add fstat to OsSysCalls, and pread and pwrite for Windows Dec 2, 2022
@ravenblackx ravenblackx changed the title Add fstat to OsSysCalls, and pread and pwrite for Windows Add fstat to OsSysCalls Dec 2, 2022
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

nice. lgtm with one nit.

@@ -1,9 +1,65 @@
#include <fcntl.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need this? Aren't we working entirely with the OSSysCalls abstraction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it won't build on Windows without it because O_CREAT and O_READWR aren't defined without that header.

Copy link
Contributor

Choose a reason for hiding this comment

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

that makes sense. The completist in me makes me want to contemplate having an enum layer in OSSysCalls, but I don't want to burden you with that one here and maybe it's overkill; not sure.

In the meantime can you just add a line-comment like // needed for O_CREAT and O_READRW or similar to this include-line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. (And I agree - also a real cleanup would do something with unifying this and Alyssa's file abstraction, which has an enum mapping but only for some of the options and in a way that precludes reusing it here. Probably the right solution would be to add all the file operation functionality to the file abstraction, and migrate AsyncFileManager to using that abstraction - that way the Windows side could use HANDLE objects and the functions that work with them, which would mean supporting pwrite and pread style operations would become possible like it currently is not - Windows doesn't have thread-safe read-at-position functions that work on file descriptors.)

@jmarantz
Copy link
Contributor

jmarantz commented Dec 5, 2022

format issues also

/wait

Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
@ravenblackx
Copy link
Contributor Author

/retest

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Check envoy-presubmit isn't fully completed, but will still attempt retrying.
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #24298 (comment) was created by @ravenblackx.

see: more, trace.

Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
@ravenblackx ravenblackx requested a review from jmarantz December 7, 2022 15:26
jmarantz
jmarantz previously approved these changes Dec 7, 2022
Copy link
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

thanks!

const int rc = ::closesocket(fd);
return {rc, rc != -1 ? 0 : ::WSAGetLastError()};
int rc = ::closesocket(fd);
const int socket_err = ::WSAGetLastError();
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't appear to be called out in the release note. is it tested in the new test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed in Slack; in existing code close is only called where closesocket behavior is fine. My hope is to later change this back and make it explicitly closesocket (for all platforms), and remove everything I've done here after implementing [fstat, pread, pwrite, tmpfiles] in Envoy::Filesystem::File and migrating AsyncFileManager to using that. But getting it in here allows me to make progress elsewhere while that chain of changes is in flight.

namespace Envoy {

// Test happy path for `open`, `pwrite`, `pread`, `fstat`, `close`, `stat` and `unlink`.
TEST(OsSyscallsTest, OpenPwritePreadFstatCloseStatUnlink) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ugh I really want to break these out but you can't really fully test read without write/open, ditto fstat. so yeah can leave as is but if fully testing close requires tweaking anything let's at least add line breaks between the different sections. if close is tested we can merge as-is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Close is [kind of] tested, in that this new test tests the new path, and existing tests implicitly cover the old path. But it turns out Windows doesn't like to unlink a file that was created without explicit windows-specific permissions flags, so that shot the auto-merge. :(

@alyssawilk alyssawilk enabled auto-merge (squash) December 7, 2022 17:14
Mostly just to trigger CI to retry

Signed-off-by: Raven Black <ravenblack@dropbox.com>
Signed-off-by: Raven Black <ravenblack@dropbox.com>
auto-merge was automatically disabled December 8, 2022 20:39

Head branch was pushed to by a user without write access

@alyssawilk alyssawilk enabled auto-merge (squash) December 8, 2022 21:00
@ravenblackx
Copy link
Contributor Author

/retest
(unrelated flakes)

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #24298 (comment) was created by @ravenblackx.

see: more, trace.

@ravenblackx
Copy link
Contributor Author

/retest
(Different unrelated flakes.)

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #24298 (comment) was created by @ravenblackx.

see: more, trace.

@ravenblackx
Copy link
Contributor Author

/retest
Hoping to get luckier on that first flake. #24469 should land eventually if not!

@repokitteh-read-only
Copy link

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #24298 (comment) was created by @ravenblackx.

see: more, trace.

@alyssawilk alyssawilk merged commit ceca213 into envoyproxy:main Dec 9, 2022
@ravenblackx ravenblackx deleted the fstat branch December 12, 2022 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants