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

create /proc/sys/kernel/spl/gitrev with git hash #7965

Merged
merged 8 commits into from
Oct 9, 2018

Conversation

ahrens
Copy link
Member

@ahrens ahrens commented Sep 27, 2018

Motivation and Context

The existing mechanisms for determining what code is running in the kernel do not always correctly report the git hash. The versions reported there do not reflect changes made since configure was run (i.e. incremental builds do not update the version) and they are misleading if git tags are not set up properly. This applies to modinfo zfs, dmesg, and /sys/module/zfs/version.

This is related to #7931. It doesn't directly fix it (existing version info can still be stale), but it provides an alternative which decreases the need for a fix.

Description

There are complicated requirements on how the existing version is generated. Therefore we are leaving that alone, and adding a new mechanism to record and retrieve the git hash: cat /proc/sys/kernel/spl/gitrev

The gitrev is re-generated at compile time, when running make (including for incremental builds). The value is the output of git describe (or "unknown" if not in a git repo or there are uncommitted changes).

We're also removing /proc/sys/kernel/spl/version, which was never very useful.

How Has This Been Tested?

Check the contents of /proc/sys/kernel/spl/gitrev after full and incremental builds, and when there are uncommitted changes.

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.
  • All new and existing tests passed.
  • All commit messages are properly formatted and contain Signed-off-by.
  • Change has been approved by a ZFS on Linux member.

Copy link
Contributor

@pzakha pzakha left a comment

Choose a reason for hiding this comment

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

LGTM, few nits

scripts/make_gitrev.sh Outdated Show resolved Hide resolved
#
# Check if there are uncommitted changes
#
git diff-index --quiet HEAD -- || exit
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we perhaps still generate a hash with "(modified)" appended to it, just so that people aren't too confused why it's suddenly "unknown"?
Also nit: -- looks unnecessary

Copy link
Member Author

Choose a reason for hiding this comment

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

For simplicity, I'm going to drop this (adding (modified)) if that's OK with you.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's up to you. That should be very easy to implement though.

scripts/make_gitrev.sh Outdated Show resolved Hide resolved
module/spl/spl-generic.c Outdated Show resolved Hide resolved
scripts/make_gitrev.sh Outdated Show resolved Hide resolved
scripts/make_gitrev.sh Outdated Show resolved Hide resolved
scripts/make_gitrev.sh Outdated Show resolved Hide resolved
scripts/make_gitrev.sh Outdated Show resolved Hide resolved
@ahrens ahrens added the Status: Revision Needed Changes are required for the PR to be accepted label Sep 28, 2018
@ahrens ahrens 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 Sep 28, 2018
@dweeezil
Copy link
Contributor

dweeezil commented Oct 2, 2018

How about adding spl_gitrev to the string logged in spa_history_log_version()?

gitrev:
-${top_srcdir}/scripts/make_gitrev.sh

BUILT_SOURCES = gitrev
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should add a call to -${top_srcdir}/scripts/make_gitrev.sh in dist-hook:. This target is run at the end of make dist and it let's you add additional files prior to the tar. Right now it's used to ensure an updated META file is included in the the final tarball. This would ensure that tarball also includes the git hash if available, and a valid version of sys/zfs_gitrev.h.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a dependency on gitrev, which I think will do the same thing without duplicating code. Let me know if you see a problem with this (I'm not a makefile expert).

Copy link
Contributor

Choose a reason for hiding this comment

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

If it works, that sounds good to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, it does the same thing as what you suggested. However, zfs_gitrev.h doesn't end up in the tarball. I suspect that we would need to tell it to generate the file in an alternate location.

Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out we copy the .c/.h files before doing dist-hook. So I had to also add a line to dist-hook to copy zfs_gitrev.h into the distdir. Now I have:

$ make dist
...
make[2]: Entering directory '/export/home/delphix/zfs'
./scripts/make_gitrev.sh
cp ./include/zfs_gitrev.h zfs-0.8.0/include; \
sed -i 's/Release:[[:print:]]*/Release:      rc1/' \
	zfs-0.8.0/META
...
$ tar -tzf zfs-0.8.0.tar.gz |grep git
zfs-0.8.0/scripts/make_gitrev.sh
zfs-0.8.0/include/zfs_gitrev.h

@ahrens
Copy link
Member Author

ahrens commented Oct 2, 2018

How about adding spl_gitrev to the string logged in spa_history_log_version()?

Great idea. What would you think about replacing "software version 5000/5" with software version <gitrev>? I would argue that the 5000/5 is basically useless. It's been the same for years despite numerous software changes.

@ahrens
Copy link
Member Author

ahrens commented Oct 3, 2018

@behlendorf I'm getting the following errors, do you know how I should address them? I think I'm not using POSIX sh's echo, I'm using /bin/echo.

./scripts/make_gitrev.sh:37:11: warning: In POSIX sh, echo flags are undefined. [SC2039]
./scripts/make_gitrev.sh:52:11: warning: In POSIX sh, echo flags are undefined. [SC2039]
Makefile:1536: recipe for target 'shellcheck' failed

Incidentally, I don't get these errors when running make checkstyle locally, because I don't have shellcheck installed. I don't think it's a good idea to have this silently pass. We could at least print a warning if shellcheck is not installed.

@dweeezil
Copy link
Contributor

dweeezil commented Oct 3, 2018

@ahrens Yes, that's exactly what I was thinking. The existing "software version" thing doesn't seem very useful at all.

@ahrens
Copy link
Member Author

ahrens commented Oct 3, 2018

Regarding the shellcheck errors, I noticed that several other scripts use echo -e but they are bash scripts. Should I change the new script to be a bash script, rather than sh?

@ahrens
Copy link
Member Author

ahrens commented Oct 3, 2018

I also see that the kernel.org build is not working, it seems that it isn't generating the new header or it's being put in the wrong place.

fs/zfs/spl/spl-generic.c:48:10: fatal error: zfs_gitrev.h: No such file or directory
 #include "zfs_gitrev.h"
          ^~~~~~~~~~~~~~
compilation terminated.

ahrens added 8 commits October 5, 2018 11:46
The existing mechanisms for determining what code is running in the
kernel do not always correctly report the git hash.  The versions
reported there do not reflect changes made since `configure` was run
(i.e. incremental builds do not update the version) and they are
misleading if git tags are not set up properly.  This applies to
`modinfo zfs`, `dmesg`, and `/sys/module/zfs/version`.

There are complicated requirements on how the existing version is
generated.  Therefore we are leaving that alone, and adding a new
mechanism to record and retrieve the git hash:
`cat /proc/sys/kernel/spl/gitrev`

The gitrev is re-generated at compile time, when running `make`
(including for incremental builds).  The value is the output of `git
describe` (or "unknown" if not in a git repo or there are uncommitted
changes).

We're also removing /proc/sys/kernel/spl/version, which was never very
useful.

Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
@codecov
Copy link

codecov bot commented Oct 5, 2018

Codecov Report

Merging #7965 into master will decrease coverage by 0.17%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7965      +/-   ##
==========================================
- Coverage   78.65%   78.48%   -0.18%     
==========================================
  Files         377      377              
  Lines      114213   114213              
==========================================
- Hits        89837    89642     -195     
- Misses      24376    24571     +195
Flag Coverage Δ
#kernel 78.76% <100%> (-0.09%) ⬇️
#user 67.81% <100%> (-0.14%) ⬇️

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 dfbe267...dd560b1. Read the comment docs.

@ahrens
Copy link
Member Author

ahrens commented Oct 5, 2018

I believe I've addressed all the review feedback and this is now ready for final review and integration. Note that I moved the location of the new (generated) header to include/zfs_gitrev.h. This was needed so that the zfs kernel module could also use it (in spa_history_log_version).

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Oct 7, 2018
@behlendorf behlendorf merged commit 4cbde2e into openzfs:master Oct 9, 2018
GregorKopka pushed a commit to GregorKopka/zfs that referenced this pull request Jan 7, 2019
The existing mechanisms for determining what code is running in the
kernel do not always correctly report the git hash.  The versions
reported there do not reflect changes made since `configure` was run
(i.e. incremental builds do not update the version) and they are
misleading if git tags are not set up properly.  This applies to
`modinfo zfs`, `dmesg`, and `/sys/module/zfs/version`.

There are complicated requirements on how the existing version is
generated.  Therefore we are leaving that alone, and adding a new
mechanism to record and retrieve the git hash:
`cat /proc/sys/kernel/spl/gitrev`

The gitrev is re-generated at compile time, when running `make`
(including for incremental builds).  The value is the output of `git
describe` (or "unknown" if not in a git repo or there are uncommitted
changes).

We're also removing /proc/sys/kernel/spl/version, which was never very
useful.

Reviewed by: Pavel Zakharov <pavel.zakharov@delphix.com>
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Tim Chase <tim@chase2k.com>
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Closes openzfs#7931 
Closes openzfs#7965
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