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: add option for forcible unmounting dataset while receiving snapshot. #9904

Merged
merged 3 commits into from
Mar 17, 2020

Conversation

oshogbo
Copy link
Contributor

@oshogbo oshogbo commented Jan 28, 2020

Motivation and Context

Currently on FreeBSD when the dataset is in use we can't receive snapshot.

zfs send test/1@asd | zfs recv -F test/2
cannot unmount '/test/2': Device busy

The same goes for the Linux version:

oshogbo@u-wing:/test$ sudo sudo zfs send test/1@b | sudo zfs recv -F test/2
umount: /test/2: target is busy.
cannot unmount '/test/2': umount failed
oshogbo@u-wing:/test$ uname -a
Linux u-wing 4.18.0-25-generic #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Description

This commits add option 'M' which forcible unmounting the dataset.
Thanks to to that we can enforce receiving snapshot in single step.

Discussed with: pjd
Reviowed by: AllanJude (FreeBSD version), bcr (man page)
FreeBSD review: https://reviews.freebsd.org/D22306

How Has This Been Tested?

root@w1:~ # zfs create ztest/a
root@w1:~ # zfs create ztest/b
root@w1:~ # zfs snapshot ztest/a@a
root@w1:~ # cd /ztest/b/
root@w1:/ztest/b # zfs send ztest/a@a | zfs recv -F ztest/b
cannot unmount '/ztest/b': Device busy
root@w1:/ztest/b # zfs send ztest/a@a | zfs recv -FM ztest/b
root@w1:/ztest/b # 

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:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

@codecov
Copy link

codecov bot commented Jan 28, 2020

Codecov Report

Merging #9904 into master will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9904      +/-   ##
==========================================
+ Coverage   79.56%   79.61%   +0.05%     
==========================================
  Files         384      384              
  Lines      121788   121793       +5     
==========================================
+ Hits        96900    96968      +68     
+ Misses      24888    24825      -63     
Flag Coverage Δ
#kernel 79.73% <ø> (-0.11%) ⬇️
#user 67.45% <87.50%> (+0.39%) ⬆️
Impacted Files Coverage Δ
module/zfs/arc.c 85.20% <0.00%> (-3.42%) ⬇️
module/os/linux/zfs/arc_os.c 59.50% <0.00%> (-2.48%) ⬇️
module/zfs/aggsum.c 93.02% <0.00%> (-2.33%) ⬇️
module/os/linux/zfs/zvol_os.c 87.36% <0.00%> (-1.34%) ⬇️
cmd/zed/agents/fmd_serd.c 78.21% <0.00%> (-1.00%) ⬇️
module/zfs/vdev_indirect.c 85.00% <0.00%> (-0.84%) ⬇️
module/os/linux/zfs/zfs_dir.c 82.83% <0.00%> (-0.70%) ⬇️
module/zfs/zvol.c 85.02% <0.00%> (-0.67%) ⬇️
module/zfs/vdev_indirect_mapping.c 98.55% <0.00%> (-0.49%) ⬇️
module/zfs/zap_leaf.c 87.76% <0.00%> (-0.48%) ⬇️
... and 56 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a340316...54a60ec. Read the comment docs.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Jan 28, 2020
Copy link
Contributor

@allanjude allanjude left a comment

Choose a reason for hiding this comment

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

Reviewed By: Allan Jude allanjude@freebsd.org

@behlendorf behlendorf added the Component: Send/Recv "zfs send/recv" feature label Feb 11, 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.

Thanks for opening this PR. I'd suggest we add a test case for this, you've already almost written in the PR comments. The only slightly tricky bit is that we should expect the test to fail on Linux and pass on FreeBSD. See the inline comment about this.

man/man8/zfs-receive.8 Show resolved Hide resolved
@behlendorf behlendorf requested a review from ahrens February 11, 2020 01:06
@oshogbo
Copy link
Contributor Author

oshogbo commented Feb 11, 2020

@behlendorf That's very interesting.
I will try to install this version of ZFS on linux or verify (I only build it on it).
Those this mean zfs unmount -f doesn't work as well?
I'm just asking to maybe add this to man page as well.

@ahrens ahrens added the Type: Feature Feature request or new feature label Feb 11, 2020
@behlendorf
Copy link
Contributor

Those this mean zfs unmount -f doesn't work as well?

That's right. I thought we had updated the man page to mention this, but looking at it now that's clearly not the case. It would be great if you could update it in this PR.

@oshogbo
Copy link
Contributor Author

oshogbo commented Feb 12, 2020

Ok will do, thanks!

@bghira
Copy link

bghira commented Feb 18, 2020

force unmount on Linux is useful only for NFS, as i understand.

@behlendorf behlendorf requested a review from a user February 26, 2020 00:03
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. Just a couple minor nits.

# STRATEGY:
# 1. Create snapshot of file system
# 2. Make a zfs filesystem mountpoint busy
# 3. Recife filesystem with force flag.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Recife -> Receive


for snap in $init_snap $rst_snap; do
snapexists $snap && \
log_must zfs destroy -f $snap
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use destroy_snapshot here.

done

datasetexists $rst_root && \
log_must zfs destroy -Rf $rst_root
Copy link
Contributor

Choose a reason for hiding this comment

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

And destroy_dataset here.

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.

Looks good, zfs_recieve tests passed on FreeBSD with the commits cherry-picked on top of ZoF.

Comment on lines +46 to +53
for file in $full_bkup
do
[[ -e $file ]] && \
log_must rm -f $file
done

[[ -d $TESTDIR1 ]] && \
log_must rm -rf $TESTDIR1
Copy link

Choose a reason for hiding this comment

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

rm -rf $full_bkup $TESTDIR1 is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hym I'm not sure. The purpose is not to know what exactly went wrong?

Copy link

Choose a reason for hiding this comment

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

If something fails in cleanup we still want to finish cleaning up. There will be error messages in the logs to know what went wrong.

The purpose of cleanup is to put the system back the way it was when the test started. If there is something that should be tested that is relevant to the test, it can happen in the test rather than in cleanup. Cleanup should make a best effort to clean up as much as possible. It is potentially being invoked halfway through the test because something already went wrong.

@behlendorf behlendorf added Status: Revision Needed Changes are required for the PR to be accepted and removed Status: Code Review Needed Ready for review and testing labels Feb 28, 2020
oshogbo added 2 commits March 11, 2020 05:37
…hot.

Currently when the dataset is in use we can't receive snapshot.
zfs send test/1@asd | zfs recv -FM test/2
cannot unmount '/test/2': Device busy

The same goes for the Linux version:
oshogbo@u-wing:/test$ sudo sudo zfs send test/1@b | sudo zfs recv -F test/2
umount: /test/2: target is busy.
cannot unmount '/test/2': umount failed
oshogbo@u-wing:/test$ uname -a
Linux u-wing 4.18.0-25-generic openzfs#26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

This commits add option 'M' which forcible unmounting the dataset.
Thanks to to that we can enforce receiving snapshot in single step.

Discussed with: pjd
Reviewed by:	AllanJude (FreeBSD version)
FreeBSD review:	https://reviews.freebsd.org/D22306

Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
As pointed out by behlendorf, Linux does not support forcible
unmount. Document this behavior.

Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
Signed-off-by: Mariusz Zaborski <oshogbo@vexillium.org>
@codecov-io
Copy link

codecov-io commented Mar 11, 2020

Codecov Report

Merging #9904 into master will decrease coverage by <1%.
The diff coverage is 88%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #9904    +/-   ##
========================================
- Coverage      79%      79%   -<1%     
========================================
  Files         385      385            
  Lines      122389   122394     +5     
========================================
- Hits        97266    97168    -98     
- Misses      25123    25226   +103
Flag Coverage Δ
#kernel 80% <ø> (ø) ⬇️
#user 67% <88%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ddd9ef3...7eceb06. Read the comment docs.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Revision Needed Changes are required for the PR to be accepted labels Mar 16, 2020
@behlendorf
Copy link
Contributor

Sorry about the delay. This looks ready to go. The only minor concern raised is the cleanup in the test case which could result in files being left around on error. Which is unlikely at best, @oshogbo if you're happy with the current version of the PR please post as much and I'll get this merged.

@oshogbo
Copy link
Contributor Author

oshogbo commented Mar 17, 2020

I'm happy to go. I fixed (I think) everything you mention. I'm not good in the zfs test framework so I'm not sure if something else still there.

@behlendorf behlendorf merged commit a57d3d4 into openzfs:master Mar 17, 2020
@behlendorf
Copy link
Contributor

Sounds good. I've gone ahead and merged this PR. If we encounter any issues with the new tests we can tackle them as a followup PR, though I don't expect any.

jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
Currently when the dataset is in use we can't receive snapshots.

    zfs send test/1@asd | zfs recv -FM test/2
    cannot unmount '/test/2': Device busy

This commits add option 'M' which attempts to forcibly unmount the
dataset.  Thanks to this we can enforce receiving snapshots in a
single step.

Note that this functionality is not supported on Linux because the
VFS will prevent active mounted filesystems from being unmounted,
even with the force option.  This is the intended VFS behavior.

Test cases were added to verify the expected behavior based on
the platform.

Discussed-with: Pawel Jakub Dawidek <pjd@FreeBSD.org>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Allan Jude <allanjude@freebsd.org>
External-issue: https://reviews.freebsd.org/D22306
Closes openzfs#9904
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Send/Recv "zfs send/recv" feature Status: Accepted Ready to integrate (reviewed, tested) Type: Feature Feature request or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants