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

Avoid here-documents in systemd mount generator #9802

Merged
merged 1 commit into from
Jan 8, 2020
Merged

Avoid here-documents in systemd mount generator #9802

merged 1 commit into from
Jan 8, 2020

Conversation

lhuedepohl
Copy link
Contributor

Motivation and Context

The systemd zfs-mount-generator script fails on my openSUSE systems, as there is not yet a writeable temporary file system available at the time it runs. Thus bash bails out with an error,

'cannot create temp file for here-document: Read-only file system',

on the here documents in zfs-mount-generator.

Description

The simple fix is to change these into many individual echo statements.

How Has This Been Tested?

I use it myself since a few weeks on several machines. The (backported) patch is also active on my project on the openSUSE Build Service where I build zfs packages for openSUSE and which is used by several other people.

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.

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Jan 2, 2020
@behlendorf behlendorf requested a review from rlaager January 2, 2020 21:04
@behlendorf
Copy link
Contributor

@aerusso would you mind commenting on this.

@codecov
Copy link

codecov bot commented Jan 3, 2020

Codecov Report

Merging #9802 into master will decrease coverage by <1%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #9802    +/-   ##
========================================
- Coverage      79%      79%   -<1%     
========================================
  Files         385      385            
  Lines      121492   121492            
========================================
- Hits        96511    96376   -135     
- Misses      24981    25116   +135
Flag Coverage Δ
#kernel 80% <ø> (ø) ⬇️
#user 67% <ø> (ø) ⬇️

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 c24fa4b...dcae3f5. Read the comment docs.

@InsanePrawn
Copy link
Contributor

InsanePrawn commented Jan 3, 2020

Well here's something I didn't know about - bash uses temp files for heredocs?!

While the echo solution looks okayish to me, my limited sense of shell script aesthetics tells me to write it 'at once' instead of appending multiple echoes to the file repeatedly, so maybe something like this?

( echo "abc"
...
echo "last line") > "${dest_norm}/${keyloadunit}"

saves us a couple syscalls at least.

Alternatively we could could escape the newlines to merge it into one long multi-line echo.

@aerusso
Copy link
Contributor

aerusso commented Jan 3, 2020

Wow, I bumped into this in my first version of this, but somehow wasn't able to reproduce the issue. We can avoid the multiple calls with something like

printf "# Automatically generated by zfs-mount-generator\n"\
"\n"\
"[Unit]\n"\
... > ...

@lhuedepohl
Copy link
Contributor Author

I guess one could also do

echo "First line
second line
third line" > file

@mschilli87
Copy link
Contributor

mschilli87 commented Jan 3, 2020

@lhuedepohl:

I guess one could also do

echo "First line
second line
third line" > file

I think especially when planning to support more than just Linux, printf is the safer bet.


Also, IMHO this whole change might be worth documenting inline to avoid future more elegant refactors using here-docs. 😉


edit: Just realized this is symstemd-specific anyways. So portability is likely not really an issue here. Sorry for the noise.

InsanePrawn added a commit to InsanePrawn/zfs that referenced this pull request Jan 3, 2020
This commit makes the following changes:
- the systemd mount generator now generates units for
datasets marked canmount=noauto too. Unlike canmount=on,
these units are NOT WantedBy local-fs.target.

- introduces handling of the user property org.openzfs.systemd:noauto,
which is now included in the zfs-list.cache files and will cause a
canmount=on dataset to be treated like noauto by the generator.

- replaces the heredocs with redirected echo statements to avoid
problems with creating tempfiles for them. (resolves openzfs#9802)

- suppresses shellcheck warnings for an intentionally unquoted variable
and some confusion that arises from the nested quoting for the keyload
commands.

Signed-off-by: InsanePrawn <[email protected]>
@behlendorf
Copy link
Contributor

@lhuedepohl I'd suggest we go with either the printf or single echo command approach you mentioned above. It agree we should also add a comment that here-docs were intentionally avoided and shouldn't be used. Please go ahead and refresh this PR when you get a chance.

@rlaager
Copy link
Member

rlaager commented Jan 6, 2020

Portability is only important in the sense that /bin/sh is not always bash. So as long as it works in a POSIX she’ll, we should be good. We may need to rewrite this in C anyway, but fixing this now is still valuable.

@lhuedepohl
Copy link
Contributor Author

lhuedepohl commented Jan 6, 2020

Rewrote as requested with single echo and multi-line strings. I ran the checkbashisms tool on a little test script with such a construction and it was fine with it - for what it's worth.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jan 6, 2020
Copy link
Member

@gmelikov gmelikov left a comment

Choose a reason for hiding this comment

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

LGTM

On some systems - openSUSE, for example - there is not yet a writeable
temporary file system available, so bash bails out with an error,

  'cannot create temp file for here-document: Read-only file system',

on the here documents in zfs-mount-generator. The simple fix is to
change these into a multi-line echo statement.

Signed-off-by: Lorenz Hüdepohl <[email protected]>
Copy link
Member

@rlaager rlaager left a comment

Choose a reason for hiding this comment

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

LGTM

@behlendorf behlendorf merged commit 028e3b3 into openzfs:master Jan 8, 2020
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Apr 22, 2020
On some systems - openSUSE, for example - there is not yet a writeable
temporary file system available, so bash bails out with an error,

  'cannot create temp file for here-document: Read-only file system',

on the here documents in zfs-mount-generator. The simple fix is to
change these into a multi-line echo statement.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-By: Richard Laager <[email protected]>
Reviewed-by: George Melikov <[email protected]>
Signed-off-by: Lorenz Hüdepohl <[email protected]>
Closes openzfs#9802
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Apr 22, 2020
On some systems - openSUSE, for example - there is not yet a writeable
temporary file system available, so bash bails out with an error,

  'cannot create temp file for here-document: Read-only file system',

on the here documents in zfs-mount-generator. The simple fix is to
change these into a multi-line echo statement.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-By: Richard Laager <[email protected]>
Reviewed-by: George Melikov <[email protected]>
Signed-off-by: Lorenz Hüdepohl <[email protected]>
Closes openzfs#9802
tonyhutter pushed a commit that referenced this pull request May 12, 2020
On some systems - openSUSE, for example - there is not yet a writeable
temporary file system available, so bash bails out with an error,

  'cannot create temp file for here-document: Read-only file system',

on the here documents in zfs-mount-generator. The simple fix is to
change these into a multi-line echo statement.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-By: Richard Laager <[email protected]>
Reviewed-by: George Melikov <[email protected]>
Signed-off-by: Lorenz Hüdepohl <[email protected]>
Closes #9802
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.

7 participants