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

mount: use the mount syscall directly #10294

Merged
merged 1 commit into from
May 21, 2020

Conversation

felixdoerre
Copy link
Contributor

@felixdoerre felixdoerre commented May 6, 2020

This is just a draft change to understand if/how using mount directly breaks any test cases.

Motivation and Context

The motivation behind this PR is to be able to mount zfs datasets without the invocation of external processes. This allows the mounting to be used from inside a pam module. Spawning processes from within a pam module is highly discouraged as the application might be confused by the additional child processes.

Description

How Has This Been Tested?

For now some mount-related unit tests have been executed locally and they passed.

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)

I am not sure, how I would classify this PR. It can be seen both as a new feature but also as a cleanup/bugfix kind of change.

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-io
Copy link

codecov-io commented May 7, 2020

Codecov Report

Merging #10294 into master will decrease coverage by 0.01%.
The diff coverage is 88.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10294      +/-   ##
==========================================
- Coverage   79.46%   79.44%   -0.02%     
==========================================
  Files         389      389              
  Lines      123120   123137      +17     
==========================================
- Hits        97834    97831       -3     
- Misses      25286    25306      +20     
Flag Coverage Δ
#kernel 79.92% <ø> (+0.04%) ⬆️
#user 65.84% <88.23%> (-0.04%) ⬇️
Impacted Files Coverage Δ
cmd/zfs/zfs_main.c 82.56% <ø> (+0.02%) ⬆️
lib/libzfs/os/linux/libzfs_mount_os.c 63.40% <87.80%> (-0.32%) ⬇️
cmd/mount_zfs/mount_zfs.c 42.85% <100.00%> (-16.20%) ⬇️
lib/libzfs/libzfs_mount.c 84.21% <100.00%> (ø)
module/zfs/vdev_indirect.c 73.50% <0.00%> (-7.84%) ⬇️
module/zfs/zio_compress.c 89.74% <0.00%> (-2.57%) ⬇️
module/icp/api/kcf_mac.c 37.14% <0.00%> (-1.72%) ⬇️
module/zfs/vdev_raidz.c 90.95% <0.00%> (-1.53%) ⬇️
... 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 3e5d41d...e6bc6db. Read the comment docs.

@behlendorf behlendorf self-requested a review May 7, 2020 23:29
@felixdoerre felixdoerre force-pushed the zfs_raw_mount branch 2 times, most recently from 91eaf6c to a92131c Compare May 8, 2020 12:54
@behlendorf behlendorf added the Status: Design Review Needed Architecture or design is under discussion label May 9, 2020
@felixdoerre felixdoerre changed the title mount: try to use the mount syscall directly mount: use the mount syscall directly May 11, 2020
@felixdoerre felixdoerre marked this pull request as ready for review May 11, 2020 23:32
@behlendorf
Copy link
Contributor

@grwilson @tuxoko would you mind taking a look at this PR. It tackles some work you've both looked at in the past regarding having libzfs directly call mount(2). The short version is that a lot of the issues which originally prevented us from doing this are no longer relevant for current Linux systems. The major one being the need to update an /etc/mtab file since it was converted to a symlink.

There is still a legitimate concern around possible problems when not using a mount helper on systems with selinux enabled. But in that case I think it's reasonable to fall back to the mount helper if needed. @prometheanfire as a selinux user would it be possible for you to try out the PR and see if there are any issues? Testing was done on CentOS 8 with it enforcing and everything seemed to work, but it would be nice to know that's the case for other environments. Thanks in advance!

cmd/mount_zfs/mount_zfs.c Outdated Show resolved Hide resolved
lib/libzfs/os/linux/libzfs_mount_os.c Show resolved Hide resolved
lib/libzfs/os/linux/libzfs_mount_os.c Show resolved Hide resolved
lib/libzfs/os/linux/libzfs_mount_os.c Show resolved Hide resolved
lib/libzfs/os/linux/libzfs_mount_os.c Outdated Show resolved Hide resolved
lib/libzfs/os/linux/libzfs_mount_os.c Outdated Show resolved Hide resolved
*/
int
zfs_parse_mount_options(char *mntopts, unsigned long *mntflags,
unsigned long *zfsflags, int sloppy, char *badopt, char *mtabopt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that there are multiple callers it would be nice to allow NULL to be passed for badopt and mtabopt, in which case those values simply aren't set.

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 have let badopt be as it is, as the option that caused parsing to fail should probably printed as an error. Can I just copy something like this:

return (zfs_error_fmt(hdl, ENXIO
		    dgettext(TEXT_DOMAIN, "cannot mount: option '%s' unknown"),
		    badopt)

Would I need to extend do_mount with an additional libzfs_handle_t parameter, or can I somehow use the already give zfs_handle_t parameter?

Copy link
Contributor

Choose a reason for hiding this comment

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

The way this is structured we'd want to add the special error message to the error handling block at the end of zfs_mount_at(). While it'd be nice to provide a more useful error message with the bad argument I don't think it's critical. But what we do need to do is update do_mount() so it returns EINVAL and not ENXIO in this case. This way we'll at least print a meaningful generic error, instead of a misleading errno and message.

lib/libzfs/os/linux/libzfs_mount_os.c Outdated Show resolved Hide resolved
lib/libzfs/os/linux/libzfs_mount_os.c Outdated Show resolved Hide resolved
cmd/mount_zfs/mount_zfs.c Outdated Show resolved Hide resolved
@prometheanfire
Copy link
Contributor

my systemd env is kinda defunct, but if it worked on cent-8 it should work anywhere else, the policies are more or less central across distros.

@felixdoerre felixdoerre force-pushed the zfs_raw_mount branch 2 times, most recently from cb1cbb4 to 1115a1f Compare May 19, 2020 08:29
@codecov-commenter
Copy link

codecov-commenter commented May 19, 2020

Codecov Report

Merging #10294 into master will increase coverage by 0.32%.
The diff coverage is 77.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10294      +/-   ##
==========================================
+ Coverage   79.57%   79.90%   +0.32%     
==========================================
  Files         390      390              
  Lines      123350   123364      +14     
==========================================
+ Hits        98153    98571     +418     
+ Misses      25197    24793     -404     
Flag Coverage Δ
#kernel 80.03% <ø> (+0.06%) ⬆️
#user 67.27% <77.17%> (+1.00%) ⬆️
Impacted Files Coverage Δ
cmd/zfs/zfs_main.c 82.67% <ø> (+0.13%) ⬆️
lib/libzfs/os/linux/libzfs_mount_os.c 62.30% <76.40%> (-1.42%) ⬇️
cmd/mount_zfs/mount_zfs.c 42.85% <100.00%> (-16.20%) ⬇️
lib/libzfs/libzfs_mount.c 84.21% <100.00%> (ø)
module/icp/api/kcf_mac.c 38.28% <0.00%> (-1.72%) ⬇️
module/zfs/vdev_initialize.c 97.46% <0.00%> (-0.64%) ⬇️
module/zfs/vdev_queue.c 95.41% <0.00%> (-0.62%) ⬇️
module/icp/api/kcf_cipher.c 15.76% <0.00%> (-0.42%) ⬇️
... and 58 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 5b090d5...f0aed99. Read the comment docs.

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.

Aside from the small requested change to do_mount() this LGTM.

*/
int
zfs_parse_mount_options(char *mntopts, unsigned long *mntflags,
unsigned long *zfsflags, int sloppy, char *badopt, char *mtabopt)
Copy link
Contributor

Choose a reason for hiding this comment

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

The way this is structured we'd want to add the special error message to the error handling block at the end of zfs_mount_at(). While it'd be nice to provide a more useful error message with the bad argument I don't think it's critical. But what we do need to do is update do_mount() so it returns EINVAL and not ENXIO in this case. This way we'll at least print a meaningful generic error, instead of a misleading errno and message.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Design Review Needed Architecture or design is under discussion labels May 20, 2020
@behlendorf behlendorf merged commit 501a151 into openzfs:master May 21, 2020
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
Allow zfs datasets to be mounted on Linux without relying on the
invocation of an external processes.  This is the same behavior
which is implemented for FreeBSD.

Use of the libmount library was originally considered because it 
provides functionality to properly lock and update the /etc/mtab 
file.  However, these days /etc/mtab is typically a symlink to 
/proc/self/mounts so there's nothing to updated.  Therefore, we
call mount(2) directly and avoid any additional dependencies. 

If required the legacy behavior can be enabled by setting the 
ZFS_MOUNT_HELPER environment variable.  This may be needed in
environments where SELinux in enabled and the zfs binary does  
not have mount permission.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Felix Dörre <felix@dogcraft.de>
openzfs#10294
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.

5 participants