Skip to content

FreeBSD: Intialize zlog in zvol_first_open, this prevents a NULL reference later. #11152

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

Merged
merged 1 commit into from
Nov 6, 2020

Conversation

oshogbo
Copy link
Contributor

@oshogbo oshogbo commented Nov 4, 2020

Motivation and Context

In the past the zilog was initialized in the zvol_first_open (https://svnweb.freebsd.org/base/stable/12/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c?revision=365689&view=markup#l842).
While the openzfs upgrade this was dropped.
This cause an page fault in the zvol_cdev_open function while accessing the ZVOL.

https://drive.google.com/file/d/1-dvj8eoUNqRWL5mcVtH5Px4NbrhLfzML/view?usp=sharing

Description

Initialize zlog in the zvol_first_open like in old version of ZFS.

How Has This Been Tested?

Tested on FreeBSD box.

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:

@oshogbo oshogbo changed the title Intialize zlog in zvol_first_open, this prevents a NULL reference later. FreeBSD: Intialize zlog in zvol_first_open, this prevents a NULL reference later. Nov 4, 2020
@ghost
Copy link

ghost commented Nov 4, 2020

The zil is opened on first write. It looks like the correct fix here is to check that the zvol has been written to before calling zil_async_to_sync in zvol_cdev_open:

--- a/module/os/freebsd/zfs/zvol_os.c
+++ b/module/os/freebsd/zfs/zvol_os.c
@@ -891,7 +891,8 @@ zvol_cdev_open(struct cdev *dev, int flags, int fmt, struct thread *td)
        if (flags & (FSYNC | FDSYNC)) {
                zsd = &zv->zv_zso->zso_dev;
                zsd->zsd_sync_cnt++;
-               if (zsd->zsd_sync_cnt == 1)
+               if (zsd->zsd_sync_cnt == 1 &&
+                   (zv->zv_flags & ZVOL_WRITTEN_TO) != 0)
                        zil_async_to_sync(zv->zv_zilog, ZVOL_OBJ);
        }

@ghost ghost added the Status: Revision Needed Changes are required for the PR to be accepted label Nov 4, 2020
@behlendorf
Copy link
Contributor

It looks like the correct fix here is to check that the zvol has been written to before calling zil_async_to_sync in zvol_cdev_open:

That's right, for additional context see 1eacf2b which added the ZVOL_WRITTEN_TO flag.

@oshogbo
Copy link
Contributor Author

oshogbo commented Nov 5, 2020

Thank you for pointing out that to me.
I fixed the patch.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@ghost ghost added Status: Code Review Needed Ready for review and testing and removed Status: Revision Needed Changes are required for the PR to be accepted labels Nov 5, 2020
@behlendorf
Copy link
Contributor

@oshogbo can you rebase this on the latest commits from the master branch and force update the PR. This will resolve the Fedora and FreeBSD build failures and let is get a proper test run with the change.

@oshogbo
Copy link
Contributor Author

oshogbo commented Nov 5, 2020

Done.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Nov 5, 2020
Check if the ZVOL has been written before calling zil_async_to_sync.
The ZIL will be opened on the first write, not earlier.

Signed-off-by: Mariusz Zaborski <[email protected]>
@behlendorf behlendorf merged commit ae37cea into openzfs:master Nov 6, 2020
uqs pushed a commit to freebsd/freebsd-src that referenced this pull request Nov 8, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934


git-svn-id: svn+ssh://svn.freebsd.org/base/head@367487 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
uqs pushed a commit to freebsd/freebsd-src that referenced this pull request Nov 8, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934
markjdb pushed a commit to markjdb/freebsd that referenced this pull request Nov 10, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934
behlendorf pushed a commit that referenced this pull request Nov 11, 2020
Check if the ZVOL has been written before calling zil_async_to_sync.
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
Closes #11152
brooksdavis pushed a commit to CTSRD-CHERI/cheribsd that referenced this pull request Nov 24, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934
mat813 pushed a commit to mat813/freebsd that referenced this pull request Nov 28, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934


git-svn-id: https://svn.freebsd.org/base/head@367487 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
qwattash pushed a commit to CTSRD-CHERI/cheribsd that referenced this pull request Dec 3, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934
markjdb pushed a commit to markjdb/freebsd that referenced this pull request Dec 10, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934
bsd-hacker pushed a commit to bsd-hacker/freebsd that referenced this pull request Dec 30, 2020
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934
bdrewery pushed a commit to bdrewery/freebsd that referenced this pull request Jan 7, 2021
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934


git-svn-id: svn+ssh://svn.freebsd.org/base/head@367487 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
Check if the ZVOL has been written before calling zil_async_to_sync.
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
Closes openzfs#11152
zxombie pushed a commit to CTSRD-CHERI/freebsd-morello that referenced this pull request Apr 15, 2021
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
OpenZFS Pull Request: openzfs/zfs#11152
PR:		250934
sempervictus pushed a commit to sempervictus/zfs that referenced this pull request May 31, 2021
Check if the ZVOL has been written before calling zil_async_to_sync.
The ZIL will be opened on the first write, not earlier.

Reviewed-by: Ryan Moeller <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Mariusz Zaborski <[email protected]>
Closes openzfs#11152
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.

2 participants