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

zfs_vnops: make zfs_get_data OS-independent #10979

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

problame
Copy link
Contributor

@problame problame commented Sep 25, 2020

zfs_vnops: refactor + make zfs_get_data OS-independent

- include/sys/zfs_vnops.h contains declarations of vnop functions
  that implement the same behavior on every platform.
  Function definitions are in
    - module/zfs/zfs_vnops.c for OS-independent code
    - module/os/*/zfs_vnops.c for OS-specific code

  In order to share the zfs_symlink declaration, the FreeBSD variant had
  to lose it's constness on the `char*` parameters.

- As a PoC, move zfs_get_data to zfs_vnops.c
    - This required creating a compatible zfs_zrele_async for FreeBSD.

Motivation

  • zfs_get_data is almost platform-independent
    • it's sibling zvol_get_data already is platform-independent
  • the only platform-specific aspect of it is the way we release an inode (Linux) / vnode_t (FreeBSD)
  • I am not aware of a platform that could be supported by ZFS that couldn't implement zfs_rele_async itself.

Future work: evaluate whether we could make all interactions with inode / vnode lifecycle management C-style virtual function calls (i.e. store function pointers to the platform-specific lifecycle functions in the znode).

How Has This Been Tested?

Straight-forward refactor -> rely on ZFS test suite in OpenZFS CI.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

@problame
Copy link
Contributor Author

Requesting @mattmacy for review.

@problame problame changed the title os independent zfs get data zfs_vnops: move zfs_get_data to OS-independent code Sep 25, 2020
@problame problame force-pushed the os-independent-zfs_get_data branch 4 times, most recently from e7968c2 to c449627 Compare September 25, 2020 14:59
@darkfiberiru
Copy link

@problame Seems to be small typo in commit message 's/zfs_rele_async/zfs_zrele_async/'

@ghost ghost added the Status: Work in Progress Not yet ready for general review label Sep 25, 2020
@ghost ghost self-requested a review September 25, 2020 17:09
@problame
Copy link
Contributor Author

http://build.zfsonlinux.org/builders/FreeBSD%20stable%2F12%20amd64%20%28TEST%29/builds/2432/steps/shell_6/logs/stdio

kldload: an error occurred while loading module openzfs. Please check dmesg(8) for more details.

This is the ztest stage.

I'm afraid I don't understand why the module builds on FreeBSD (but doesn't load?).
Also, it would be helfpul if buildbot captured dmesg somewhere in that stage.

@problame
Copy link
Contributor Author

problame commented Sep 25, 2020

@ghost
Copy link

ghost commented Sep 25, 2020

http://build.zfsonlinux.org/builders/FreeBSD%20stable%2F12%20amd64%20%28TEST%29/builds/2432/steps/shell_6/logs/stdio

kldload: an error occurred while loading module openzfs. Please check dmesg(8) for more details.

This is the ztest stage.

I'm afraid I don't understand why the module builds on FreeBSD (but doesn't load?).
Also, it would be helfpul if buildbot captured dmesg somewhere in that stage.

Dmesg is captured as console

You'll need to add the new file to module/Makefile.bsd for the FreeBSD build.

@ghost
Copy link

ghost commented Sep 25, 2020

Welcome to the jungle... 😅

@problame
Copy link
Contributor Author

I'll set up a FreeBSD dev system.

@problame
Copy link
Contributor Author

How do you feel about this refactor in general?
I feel like there are a bunch of more functions in zfs_vnops that are almost platform-independent.
Look at zfs_write for example.

Is this duplication intentional and intended to stay long-term or was it just easier to initially duplicate code for a faster FreeBSD port?

@ghost
Copy link

ghost commented Sep 25, 2020

It was easier and faster to keep the the ZPL bits in vnops/vfsops separate. There is indeed a lot of refactoring that should be done to share more of the code, and I see that as a worthwhile effort.

I haven't closely audited your changes yet, but at a glance there is one suggestion I have, apart from setting yourself up with a FreeBSD VM and getting it to build on FreeBSD. Rather than *_common.c, the convention has been to name the platform-dependent files *_os.c where there is a name collision between files in common and platform code.

@problame problame force-pushed the os-independent-zfs_get_data branch 3 times, most recently from a35dc5e to 86d8a78 Compare September 26, 2020 13:07
@problame
Copy link
Contributor Author

I haven't closely audited your changes yet, but at a glance there is one suggestion I have, apart from setting yourself up with a FreeBSD VM and getting it to build on FreeBSD. Rather than *_common.c, the convention has been to name the platform-dependent files *_os.c where there is a name collision between files in common and platform code.

I restructured the PR to follow this pattern and updated the commit message accordingly.
It should be usable for future refactorings of the ZPL.

I set up a test VM with FreeBSD 12.1 release and found that my version of master didn't compile there.
I added the missing includes in a separate commit included in this PR.

@problame problame changed the title zfs_vnops: move zfs_get_data to OS-independent code zfs_vnops: refactor + make zfs_get_data OS-independent Sep 26, 2020
@ghost ghost added Status: Code Review Needed Ready for review and testing and removed Status: Work in Progress Not yet ready for general review labels Sep 26, 2020
@ghost
Copy link

ghost commented Sep 26, 2020

The build errors appear to be all 32-bit platforms, except Fedora. Not sure what happened to that one.

module/os/linux/zfs/zfs_ctldir.c Outdated Show resolved Hide resolved
module/zfs/zfs_vnops.c Outdated Show resolved Hide resolved
@problame
Copy link
Contributor Author

problame commented Oct 7, 2020

@freqlabs I addressed the issues mentioned in the review and rebased onto master. Your Throw const on some strings forced me to move most of the functions in the shared zfs_vnops.h back into zfs_vnops_os.h since the const-ness is only on FreeBSD.

@ghost
Copy link

ghost commented Oct 7, 2020

@freqlabs I addressed the issues mentioned in the review and rebased onto master. Your Throw const on some strings forced me to move most of the functions in the shared zfs_vnops.h back into zfs_vnops_os.h since the const-ness is only on FreeBSD.

There seemed to be some differences after all in how those functions are implemented. I don't fully understand why, but as I recall the Linux code passes around ownership of some strings instead of merely borrowing the strings from the caller. The eventual call to free forces that the strings not be const in a number of functions.

It would be good to investigate further if it is really necessary to pass around the string ownership like that.

@problame
Copy link
Contributor Author

problame commented Oct 7, 2020

Agreed, although that won't be part of this PR.

@mattmacy
Copy link
Contributor

I wasn't aware of this PR and just re-did the bulk of the re-factoring. I need to share some common code for the async I/O rework. zfs_fsync is a simpler place to start BTW.

@problame
Copy link
Contributor Author

@mattmacy certainly. Could you please link to the commits where you did this refactoring?

@mattmacy
Copy link
Contributor

@mattmacy
Copy link
Contributor

Please see also #11078

@mattmacy
Copy link
Contributor

@problame It looks like the core of your changes should be just drop in on top of mine

@problame
Copy link
Contributor Author

I guess this PR is obsolete, then. Close at your discretion.

@behlendorf
Copy link
Contributor

These changes nicely complement the work done in #11078. Let's get that PR in first then this work can be applied on top.

@behlendorf
Copy link
Contributor

@problame with #11078 merged we should be all set to move zfs_get_data in to the common code.

@behlendorf behlendorf added Status: Work in Progress Not yet ready for general review and removed Status: Code Review Needed Ready for review and testing labels Oct 22, 2020
@mattmacy
Copy link
Contributor

@problame if you just keep your vnops changes we can get that merged

@problame
Copy link
Contributor Author

Sry, I've been awfully busy in the last few days. I'll try to get it done until the end of the week!

closes openzfs#10979

Signed-off-by: Christian Schwarz <me@cschwarz.com>
@problame
Copy link
Contributor Author

problame commented Nov 1, 2020

Rebase is done and it builds on my test VMs.

@ghost ghost added Status: Code Review Needed Ready for review and testing and removed Status: Work in Progress Not yet ready for general review labels Nov 2, 2020
Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Nov 2, 2020
@problame problame changed the title zfs_vnops: refactor + make zfs_get_data OS-independent zfs_vnops: make zfs_get_data OS-independent Nov 2, 2020
@behlendorf behlendorf merged commit ab8c935 into openzfs:master Nov 2, 2020
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
Move zfs_get_data() in to platform-independent code. The only
platform-specific aspect of it is the way we release an inode 
(Linux) / vnode_t (FreeBSD). I am not aware of a platform that
could be supported by ZFS that couldn't implement zfs_rele_async 
itself. It's sibling zvol_get_data already is platform-independent.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christian Schwarz <me@cschwarz.com>
Closes openzfs#10979
sempervictus pushed a commit to sempervictus/zfs that referenced this pull request May 31, 2021
Move zfs_get_data() in to platform-independent code. The only
platform-specific aspect of it is the way we release an inode 
(Linux) / vnode_t (FreeBSD). I am not aware of a platform that
could be supported by ZFS that couldn't implement zfs_rele_async 
itself. It's sibling zvol_get_data already is platform-independent.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christian Schwarz <me@cschwarz.com>
Closes openzfs#10979
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Jun 10, 2021
Move zfs_get_data() in to platform-independent code. The only
platform-specific aspect of it is the way we release an inode
(Linux) / vnode_t (FreeBSD). I am not aware of a platform that
could be supported by ZFS that couldn't implement zfs_rele_async
itself. It's sibling zvol_get_data already is platform-independent.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christian Schwarz <me@cschwarz.com>
Closes openzfs#10979
tonyhutter pushed a commit that referenced this pull request Jun 23, 2021
Move zfs_get_data() in to platform-independent code. The only
platform-specific aspect of it is the way we release an inode
(Linux) / vnode_t (FreeBSD). I am not aware of a platform that
could be supported by ZFS that couldn't implement zfs_rele_async
itself. It's sibling zvol_get_data already is platform-independent.

Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Christian Schwarz <me@cschwarz.com>
Closes #10979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants