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

reorganize code and add an unit test #354

Merged
merged 3 commits into from
Nov 20, 2024
Merged

reorganize code and add an unit test #354

merged 3 commits into from
Nov 20, 2024

Conversation

salvete
Copy link
Contributor

@salvete salvete commented Nov 19, 2024

What this PR does / why we need it:

Reorganize the code to make the structure clearer. And also add an unit test for the internal ErofsCache.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Please check the following list:

  • Does the affected code have corresponding tests, e.g. unit test, E2E test?
  • Does this change require a documentation update?
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have an appropriate license header?

Reorganize the code to make the structure clearer. Specifically:

- erofs_common.*: contains some common content used internally
  by EROFS, such as I/O controllers and constants;

- liberofs.*: contains the content for creating EROFS filesystem
  images;

- erofs_fs.*: contains the content for building the EROFS filesystem
  from EROFS filesystem images and performing operations on the filesystem.

Additional changes:
- rename `min` to `erofs_min` to avoid conflicts with `std::min`;
- declare erofs_check_fs() and erofs_create_fs() as extern in comm_func.cpp,
  as including erofs_fs.h at this point leads to conflicts. Subsequent patches
  will clean up erofs_fs.h to allow it to be included by third parties (hide content
  related to liberofs to avoid conflicts).

No other changes were made.

Signed-off-by: Hongzhen Luo <[email protected]>
struct erofs_fs_private {
struct erofs_sb_info sbi;
struct liberofs_file target_file;
unsigned long magic = LIBEROFS_MAGIC;
Copy link
Contributor

@hsiangkao hsiangkao Nov 19, 2024

Choose a reason for hiding this comment

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

what's the exact use of this field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what's the exact use of this fields?

The ErofsFileSystem needs to be associated with the erofs_superblock and the I/O controller, so this information has been packaged here. The same goes for ErofsFile. The reason for this approach is to avoid including items like erofs_superblock in erofs_fs.h.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean what's the uses of magic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a double check for pointer conversion using reinterpret_cast.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's useful

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. This field is removed.


class ErofsFileSystem: public photon::fs::IFileSystem {
public:
struct erofs_sb_info sbi;
struct liberofs_file target_file;
void *fs_private;
Copy link
Contributor

@hsiangkao hsiangkao Nov 19, 2024

Choose a reason for hiding this comment

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

I think you could just

..
private:
struct ErofsFileSystemInt;
ErofsFileSystemInt *private;

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.

@@ -61,7 +58,7 @@ class ErofsFileSystem: public photon::fs::IFileSystem {
class ErofsFile: public photon::fs::VirtualReadOnlyFile {
public:
ErofsFileSystem *fs;
struct erofs_inode inode;
void *file_private;
Copy link
Contributor

@hsiangkao hsiangkao Nov 19, 2024

Choose a reason for hiding this comment

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

I think you could just

...
private:
struct ErofsFileInt;
ErofsFileInt *private;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I will give it a try.

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.

Hide the parts related to liberofs in erofs_fs.h
so that erofs_fs.h can be included.

Signed-off-by: Hongzhen Luo <[email protected]>
Add an unit test for the internal ErofsCache.

Signed-off-by: Hongzhen Luo <[email protected]>
@BigVan
Copy link
Member

BigVan commented Nov 20, 2024

LGTM

@BigVan BigVan merged commit 7566f30 into containerd:main Nov 20, 2024
2 checks passed
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