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

Fix bug in in_mtab() where the return value is always 1 #9168

Merged
merged 1 commit into from
Aug 20, 2019

Conversation

fling-
Copy link
Contributor

@fling- fling- commented Aug 15, 2019

$fs used with the wrong sed command where should be $mntpnt instead to match
a variable exported by read_mtab()

The fix is mostly to reuse the sed command found in read_mtab()

Signed-off-by: Alexey Smirnoff fling@member.fsf.org

Motivation and Context

I need the working in_mtab() function
to be able to implement rw remount in /etc/init.d/zfs-mount

Description

How Has This Been Tested?

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:

$fs used with the wrong sed command where should be $mntpnt instead
to match a variable exported by read_mtab()

The fix is mostly to reuse the sed command found in read_mtab()

Signed-off-by: Alexey Smirnoff <fling@member.fsf.org>
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Aug 15, 2019
@codecov
Copy link

codecov bot commented Aug 16, 2019

Codecov Report

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

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9168      +/-   ##
==========================================
+ Coverage   79.09%   79.13%   +0.04%     
==========================================
  Files         400      400              
  Lines      121831   121831              
==========================================
+ Hits        96361    96410      +49     
+ Misses      25470    25421      -49
Flag Coverage Δ
#kernel 79.7% <ø> (+0.01%) ⬆️
#user 66.72% <ø> (-0.1%) ⬇️

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 0e37a0f...95c81d3. Read the comment docs.

@behlendorf
Copy link
Contributor

@c0d3z3r0 would you mind reviewing this.

Copy link
Contributor

@c0d3z3r0 c0d3z3r0 left a comment

Choose a reason for hiding this comment

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

This fix is valid but I guess we should go another way here. While testing and verifying this PR I noticed that most the implementation of zfs-functions et al. generally has multiple problems. Main reasons for that are:

  • hardly readable because of too much unoptimized code
  • inconsistent coding style, e.g. [ "$(eval echo "$""$var")" != "" ] vs. var="$(eval echo FSTAB_$1)"; [ "${var}" != "" ]
  • use of eval where it is not needed at all, e.g. eval export FSTAB_dev_$i="$fs"
  • duplicated functionality: in_mtab vs. is_mounted
  • inconsistent use of mount and cat/read /proc/self/mounts (which both return the same results. the only differene is that mount does some formatting (insert on and type, put options in brackets, omitting freq and pass)
    ...

I vote for a complete reimplementation of zfs-functions by using (e)grep /proc/self/mounts or even zfs_mount (have to check this) and a proper, consistent coding style avoiding any use of eval, where possible. I will post a new PR for that in the next few days I guess

c0d3z3r0 added a commit to c0d3z3r0/zfs that referenced this pull request Aug 19, 2019
This fixes multiple issues with shell scripts:
- current shell code is hardly readable because of too much unoptimized
  code
- some bugs (like openzfs#9168)
- inconsistent coding style
- very much missing documentation
- use of eva... evil() where it is not needed at all, e.g.:
  `eval export FSTAB_dev_$i="$fs"`
- duplicated functionality: in_mtab vs. is_mounted
- inconsistent use of mount and cat/read /proc/self/mounts (which both
  return the same results. the only differene is that mount does some
  formatting (insert on and type, put options in brackets, omitting
  freq and pass)
- caching of fstab and mtab in env makes everything very, very
  complicated and is not needed at all (as far as I looked at the code;
  MAYBE this is really needed and I did not get this far, yet. we'll see)

This PR does a complete rework of all existing shell scripts to fix all
those problems.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
c0d3z3r0 added a commit to c0d3z3r0/zfs that referenced this pull request Aug 19, 2019
This fixes multiple issues with shell scripts:
- current shell code is hardly readable because of too much unoptimized
  code
- some bugs (like openzfs#9168)
- inconsistent coding style
- very much missing documentation
- use of eva... evil() where it is not needed at all, e.g.:
  `eval export FSTAB_dev_$i="$fs"`
- duplicated functionality: in_mtab vs. is_mounted
- inconsistent use of mount and cat/read /proc/self/mounts (which both
  return the same results. the only differene is that mount does some
  formatting (insert on and type, put options in brackets, omitting
  freq and pass)
- caching of fstab and mtab in env makes everything very, very
  complicated and is not needed at all; (as far as I looked at the
  code; MAYBE this is really needed and I did not get this far, yet.
  we'll see)
  IMHO it really does not matter if we call grep multiple times... the
  difference is negligible and should be in the range of some 10s or
  100s of milliseconds...

This PR does a complete rework of all existing shell scripts to fix all
those problems while keeping backwards compatibility.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
c0d3z3r0 added a commit to c0d3z3r0/zfs that referenced this pull request Aug 19, 2019
This fixes multiple issues with shell scripts:
- current shell code is hardly readable because of too much unoptimized
  code
- some bugs (like openzfs#9168, openzfs#9183)
- inconsistent coding style
- very much missing documentation
- use of eva... evil() where it is not needed at all, e.g.:
  `eval export FSTAB_dev_$i="$fs"`
- duplicated functionality: in_mtab vs. is_mounted
- inconsistent use of mount and cat/read /proc/self/mounts (which both
  return the same results. the only differene is that mount does some
  formatting (insert on and type, put options in brackets, omitting
  freq and pass)
- caching of fstab and mtab in env makes everything very, very
  complicated and is not needed at all; (as far as I looked at the
  code; MAYBE this is really needed and I did not get this far, yet.
  we'll see)
  IMHO it really does not matter if we call grep multiple times... the
  difference is negligible and should be in the range of some 10s or
  100s of milliseconds...

This PR does a complete rework of all existing shell scripts to fix all
those problems while keeping backwards compatibility.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
c0d3z3r0 added a commit to c0d3z3r0/zfs that referenced this pull request Aug 19, 2019
This fixes multiple issues with shell scripts:
- current shell code is hardly readable because of too much unoptimized
  code
- some bugs (like openzfs#9168, openzfs#9183)
- inconsistent coding style
- use of UPPER CASE variables (very confusing as only env vars or
  globals should be upper case...
- very much missing documentation
- use of eva... evil() where it is not needed at all, e.g.:
  `eval export FSTAB_dev_$i="$fs"`
- duplicated functionality: in_mtab vs. is_mounted
- inconsistent use of mount and cat/read /proc/self/mounts (which both
  return the same results. the only differene is that mount does some
  formatting (insert on and type, put options in brackets, omitting
  freq and pass)
- caching of fstab and mtab in env makes everything very, very
  complicated and is not needed at all; (as far as I looked at the
  code; MAYBE this is really needed and I did not get this far, yet.
  we'll see)
  IMHO it really does not matter if we call grep multiple times... the
  difference is negligible and should be in the range of some 10s or
  100s of milliseconds...

This PR does a complete rework of all existing shell scripts to fix all
those problems while keeping backwards compatibility.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
c0d3z3r0 added a commit to c0d3z3r0/zfs that referenced this pull request Aug 20, 2019
The shell scripts zfs-functions et al. have multiple problems:
- Current shell code is hard to read and debug because of too much
  unoptimized code
- Some bugs (like openzfs#9168, openzfs#9183, and I guess some more but I did not
  search in the issues, yet)
- Inconsistent code style
- Use of upper case variables (very confusing at least for me, as only
  env vars or globals should be upper case (isn't this (un)written
  convention?)
- Very much missing documentation which makes it hard for new devs to
  understand what SHOULD happen (which is not always what really
  happens)
- use of evi... eval() where it is not needed at all, e.g.:
  `eval export FSTAB_dev_$i="$fs"`
- duplicated functionality: `in_mtab` vs. `is_mounted`
- inconsistent use of `mount` and `cat/read /proc/self/mounts` (which
  both return the same results. The only differene is that mount does
  some formatting (insert `on` and `type`, put `options` in brackets,
  omitting `freq` and `pass`)
- Caching of fstab and mtab in env makes everything very, very
  complicated due to special character handling and (as far as I looked
  at the code, yet) is not needed at all. (MAYBE this is really needed
  and I did not get this far, yet. We'll see.) IMHO it really does not
  matter if we call grep multiple times but can completely drop any
  `eval`. The run time difference is negligible and should be in the
  range of some 10s or 100s of milliseconds.
- ... (more to follow)

This PR does a complete rework of all existing shell scripts to fix
all those problems while keeping backwards compatibility.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
@behlendorf
Copy link
Contributor

@c0d3z3r0 thanks for looking at this small fix, and your proposed refactoring in #9182.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Aug 20, 2019
@behlendorf behlendorf merged commit c759b33 into openzfs:master Aug 20, 2019
c0d3z3r0 added a commit to c0d3z3r0/zfs that referenced this pull request Aug 21, 2019
The shell scripts zfs-functions et al. have multiple problems:
- Current shell code is hard to read and debug because of too much
  unoptimized code
- Some bugs (like openzfs#9168, openzfs#9183, and I guess some more but I did not
  search in the issues, yet)
- Inconsistent code style
- Use of upper case variables (very confusing at least for me, as only
  env vars or globals should be upper case (isn't this (un)written
  convention?)
- Very much missing documentation which makes it hard for new devs to
  understand what SHOULD happen (which is not always what really
  happens)
- use of evi... eval() where it is not needed at all, e.g.:
  `eval export FSTAB_dev_$i="$fs"`
- duplicated functionality: `in_mtab` vs. `is_mounted`
- inconsistent use of `mount` and `cat/read /proc/self/mounts` (which
  both return the same results. The only differene is that mount does
  some formatting (insert `on` and `type`, put `options` in brackets,
  omitting `freq` and `pass`)
- Caching of fstab and mtab in env makes everything very, very
  complicated due to special character handling and (as far as I looked
  at the code, yet) is not needed at all. (MAYBE this is really needed
  and I did not get this far, yet. We'll see.) IMHO it really does not
  matter if we call grep multiple times but can completely drop any
  `eval`. The run time difference is negligible and should be in the
  range of some 10s or 100s of milliseconds.
- ... (more to follow)

This PR does a complete rework of all existing shell scripts to fix
all those problems while keeping backwards compatibility.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
c0d3z3r0 added a commit to c0d3z3r0/zfs that referenced this pull request Aug 21, 2019
The shell scripts zfs-functions et al. have multiple problems:
- Current shell code is hard to read and debug because of too much
  unoptimized code
- Some bugs (like openzfs#9168, openzfs#9183, and I guess some more but I did not
  search in the issues, yet)
- Inconsistent code style
- Use of upper case variables (very confusing at least for me, as only
  env vars or globals should be upper case (isn't this (un)written
  convention?)
- Very much missing documentation which makes it hard for new devs to
  understand what SHOULD happen (which is not always what really
  happens)
- use of evi... eval() where it is not needed at all, e.g.:
  `eval export FSTAB_dev_$i="$fs"`
- duplicated functionality: `in_mtab` vs. `is_mounted`
- inconsistent use of `mount` and `cat/read /proc/self/mounts` (which
  both return the same results. The only differene is that mount does
  some formatting (insert `on` and `type`, put `options` in brackets,
  omitting `freq` and `pass`)
- Caching of fstab and mtab in env makes everything very, very
  complicated due to special character handling and (as far as I looked
  at the code, yet) is not needed at all. (MAYBE this is really needed
  and I did not get this far, yet. We'll see.) IMHO it really does not
  matter if we call grep multiple times but can completely drop any
  `eval`. The run time difference is negligible and should be in the
  range of some 10s or 100s of milliseconds.
- ... (more to follow)

This PR does a complete rework of all existing shell scripts to fix
all those problems while keeping backwards compatibility.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Dec 24, 2019
$fs used with the wrong sed command where should be $mntpnt instead
to match a variable exported by read_mtab()

The fix is mostly to reuse the sed command found in read_mtab()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Michael Niewöhner <foss@mniewoehner.de>
Signed-off-by: Alexey Smirnoff <fling@member.fsf.org>
Closes openzfs#9168
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Dec 27, 2019
$fs used with the wrong sed command where should be $mntpnt instead
to match a variable exported by read_mtab()

The fix is mostly to reuse the sed command found in read_mtab()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Michael Niewöhner <foss@mniewoehner.de>
Signed-off-by: Alexey Smirnoff <fling@member.fsf.org>
Closes openzfs#9168
tonyhutter pushed a commit that referenced this pull request Jan 23, 2020
$fs used with the wrong sed command where should be $mntpnt instead
to match a variable exported by read_mtab()

The fix is mostly to reuse the sed command found in read_mtab()

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Michael Niewöhner <foss@mniewoehner.de>
Signed-off-by: Alexey Smirnoff <fling@member.fsf.org>
Closes #9168
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.

3 participants