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

Add flags when open file #7445

Merged
merged 1 commit into from
Aug 2, 2019
Merged

Conversation

scw00
Copy link
Contributor

@scw00 scw00 commented Jul 2, 2019

Add flags for open method. So user can use it with read only mode or write only mode.

  • Risk Level: Low
  • Testing: unit_tests (under linux platform)
  • Docs Changes: no docs change
  • Release Notes:
    [Optional Fixes #Issue] no issue
    [Optional Deprecated:]

@scw00 scw00 force-pushed the open_reconstruct branch 4 times, most recently from 94d066a to 72e0a14 Compare July 2, 2019 06:51
@scw00
Copy link
Contributor Author

scw00 commented Jul 2, 2019

Hi, it seems the clang_tidy check run win32 implementation under linux platform. And I am not sure how to fix that.

/source/source/common/filesystem/win32/filesystem_impl.cc:2:10: error: 'io.h' file not found [clang-diagnostic-error]
#include <io.h>
         ^
Suppressed 2 warnings (1 in non-user code, 1 due to line filter).

@mattklein123
Copy link
Member

@scw00 thanks for the contribution. Can you describe the purpose of this change? AFAICT the new functionality is not used? Are you planning on a follow up change?

@scw00
Copy link
Contributor Author

scw00 commented Jul 4, 2019

Hi @mattklein123 . I am trying to implement the static file filter which return static file from local fs. But I didn't found any appropriate structure for reading a file. It is the first step to implement the opening method with reading only flag.

@scw00 scw00 force-pushed the open_reconstruct branch 3 times, most recently from 6c4d30f to f86d9b4 Compare July 7, 2019 01:24
@scw00
Copy link
Contributor Author

scw00 commented Jul 7, 2019

Updated. For using std::bitset and set default value to open method.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks, a few high level comments to get started. Please also check clang-tidy and format.

/wait

include/envoy/filesystem/filesystem.h Outdated Show resolved Hide resolved
source/common/filesystem/file_shared_impl.cc Outdated Show resolved Hide resolved
ci/run_clang_tidy.sh Outdated Show resolved Hide resolved
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Cool, thanks for working on this. A few small comments otherwise LGTM.

/wait

source/common/filesystem/file_shared_impl.cc Outdated Show resolved Hide resolved
source/common/filesystem/posix/filesystem_impl.cc Outdated Show resolved Hide resolved
test/common/filesystem/filesystem_impl_test.cc Outdated Show resolved Hide resolved
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM with some nits, thanks.

/wait

source/common/access_log/access_log_manager_impl.cc Outdated Show resolved Hide resolved
source/common/filesystem/posix/filesystem_impl.cc Outdated Show resolved Hide resolved
source/common/filesystem/win32/filesystem_impl.cc Outdated Show resolved Hide resolved
@@ -12,6 +12,10 @@
namespace Envoy {
namespace Filesystem {

static constexpr FlagSet DEFAULT_FLAGS{
Copy link
Member

Choose a reason for hiding this comment

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

Please use the default flags function that is already defined, same elsewhere (I already commented on this I think).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I can use the default function which is defined in access_log_manager_impl.h. file_system_test should not dependent on other implementations .

mattklein123
mattklein123 previously approved these changes Jul 31, 2019
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM. @jmarantz any further comments?

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.

sorry I should've chimed in earlier; I do have some questions.

@@ -83,6 +83,9 @@ class AccessLogFileImpl : public AccessLogFile {
void open();
void createFlushStructures();

// return default flags set which used by open
Filesystem::FlagSet defaultFlags();
Copy link
Contributor

Choose a reason for hiding this comment

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

Declare this method static; it does not appear to require this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks and will do.


fd_ = ::open(path_.c_str(), flags, mode);
void FileImplPosix::openFile(FlagSet in) {
const auto flags_and_perm = translateFlag(in);
Copy link
Contributor

Choose a reason for hiding this comment

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

You reference 'perm' in this PR a few times; can we spell that out? I think it might mean "permanent" but I'm not sure.

Copy link
Contributor Author

@scw00 scw00 Aug 1, 2019

Choose a reason for hiding this comment

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

You mean move this into shared interface . It seems contradictory to previous changes, see
#7445 (comment)

This is also why I make the PermAndFlags into platform implementation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh it's hard to see exactly what Matt had an issue with because you squashed commits. In general please try to avoid that because we lose the comment history.

I still don't understand the meaning of 'perm'. But looking at how it's used here I retract my "make part of the interface" suggestion, and instead suggest using the correct type and name in posix for the 3rd arg to open: mode_t mode

@@ -16,8 +16,14 @@ class FileImplPosix : public FileSharedImpl {
~FileImplPosix() override;

protected:
struct FlagsAndPerm {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to put FlagsAndPerm in a shared interface, rather than repeating it from win32 and posix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the translateFlags method is platform specified function ( the translateFlags is in the platform class not in shared interface). So the implementation should have their own flags and perm or other something more than this two flags.

But currently we only care about the perm and flags, so I'm ok with that . And will change.

Copy link
Contributor

Choose a reason for hiding this comment

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

s/perm/mode/ and s/int/mode_t/ for the mode arg?

fd_ = ::_open(path_.c_str(), flags, mode);
void FileImplWin32::openFile(FlagSet in) {
const auto flags_and_perm = translateFlag(in);
fd_ = ::open(path_.c_str(), flags_and_perm.flags, flags_and_perm.perm);
Copy link
Contributor

Choose a reason for hiding this comment

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

ah I finally figured out what 'perm' meant by reading the MS docs: https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/open-wopen?view=vs-2019 -- it means "permissions".

but there it's called pmode, not perm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks and will change

@@ -14,8 +14,14 @@ class FileImplWin32 : public FileSharedImpl {
~FileImplWin32();

protected:
struct FlagsAndPerm {
int flags = 0;
int perm = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

pmode

jmarantz
jmarantz previously approved these changes Aug 1, 2019
@@ -16,8 +16,14 @@ class FileImplPosix : public FileSharedImpl {
~FileImplPosix() override;

protected:
struct FlagsAndMode {
int flags = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Signed-off-by: cwsong <cwsong@iflytek.com>
@scw00
Copy link
Contributor Author

scw00 commented Aug 1, 2019

/retest

@repokitteh-read-only
Copy link

🤷‍♀️ nothing to rebuild.

🐱

Caused by: a #7445 (comment) was created by @scw00.

see: more, trace.

@dio
Copy link
Member

dio commented Aug 1, 2019

/azp run envoy-macos

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@scw00
Copy link
Contributor Author

scw00 commented Aug 1, 2019

Thanks @dio

@scw00
Copy link
Contributor Author

scw00 commented Aug 2, 2019

Hi @mattklein123 @jmarantz thanks for your comments. And Can I get another approve ?

@jmarantz jmarantz merged commit dd50110 into envoyproxy:master Aug 2, 2019
@scw00
Copy link
Contributor Author

scw00 commented Aug 2, 2019

Thanks

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.

None yet

4 participants