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

Unlitter /var/lock from all-debug.sh and history_event-zfs-list-cacher.sh.in. Allow history_event-zfs-list-cacher.sh.in per pool #12042

Closed
wants to merge 3 commits into from

Conversation

nabijaczleweli
Copy link
Contributor

@nabijaczleweli nabijaczleweli commented May 14, 2021

Motivation and Context

Pessimistic locks and needless litter in /var/lock.

Description

See commit messages.

How Has This Been Tested?

Ran all-debug.sh – it's okay. Haven't run history_event-zfs-list-cacher.sh.in enough (it should be fine, but what do you know; will dedraft when I've done so).

Ran it, I guess?

Also: is there some better way to mark the latter two patches as critically dependent on the former than what I've done to the messages?

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)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the OpenZFS code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes. – none apply(?)
  • I have run the ZFS Test Suite with this change applied. – as above
  • All commit messages are properly formatted and contain Signed-off-by.

@nabijaczleweli nabijaczleweli force-pushed the lockpsko branch 5 times, most recently from 5517014 to ee55b01 Compare May 14, 2021 10:13
@nabijaczleweli nabijaczleweli force-pushed the lockpsko branch 2 times, most recently from 36b161b to ccf35c6 Compare May 14, 2021 12:15
@nabijaczleweli nabijaczleweli changed the title Detrashify /var/lock from all-debug.sh and history_event-zfs-list-cacher.sh.in. Paralellise history_event-zfs-list-cacher.sh.in Detrashify /var/lock from all-debug.sh and history_event-zfs-list-cacher.sh.in. Parallelise history_event-zfs-list-cacher.sh.in May 14, 2021
@nabijaczleweli nabijaczleweli force-pushed the lockpsko branch 2 times, most recently from e724424 to 5d952af Compare May 14, 2021 12:22
@nabijaczleweli nabijaczleweli marked this pull request as ready for review May 14, 2021 15:55
@nabijaczleweli nabijaczleweli force-pushed the lockpsko branch 2 times, most recently from 278d92c to f421eef Compare May 14, 2021 20:00
@nabijaczleweli nabijaczleweli changed the title Detrashify /var/lock from all-debug.sh and history_event-zfs-list-cacher.sh.in. Parallelise history_event-zfs-list-cacher.sh.in Unlitter /var/lock from all-debug.sh and history_event-zfs-list-cacher.sh.in. Parallelise history_event-zfs-list-cacher.sh.in May 17, 2021
@nabijaczleweli nabijaczleweli changed the title Unlitter /var/lock from all-debug.sh and history_event-zfs-list-cacher.sh.in. Parallelise history_event-zfs-list-cacher.sh.in Unlitter /var/lock from all-debug.sh and history_event-zfs-list-cacher.sh.in. Allow history_event-zfs-list-cacher.sh.in per pool May 20, 2021
behlendorf pushed a commit that referenced this pull request May 20, 2021
Before, make shellcheck checked
  scripts/{commitcheck,make_gitrev,man-dates,paxcheck,zfs-helpers,zfs,
           zfs-tests,zimport,zloop}.sh
  cmd/zed/zed.d/{{all-debug,all-syslog,data-notify,generic-notify,
                 resilver_finish-start-scrub,scrub_finish-notify,
                 statechange-led,statechange-notify,trim_finish-notify,
                 zed-functions}.sh,history_event-zfs-list-cacher.sh.in}
  cmd/zpool/zpool.d/{dm-deps,iostat,lsblk,media,ses,smart,upath}
now it also checks
  contrib/dracut/{02zfsexpandknowledge/module-setup,
                  90zfs/{export-zfs,parse-zfs,zfs-needshutdown,
                         zfs-load-key,zfs-lib,module-setup,
                         mount-zfs,zfs-generator}}.sh.in
  cmd/zed/zed.d/{pool_import-led,vdev_attach-led,
                 resilver_finish-notify,vdev_clear-led}.sh
  contrib/initramfs/{zfsunlock,hooks/zfs.in,scripts/local-top/zfs}
  tests/zfs-tests/tests/perf/scripts/prefetch_io.sh
  scripts/common.sh.in
  contrib/bpftrace/zfs-trace.sh
  autogen.sh

Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12042
behlendorf pushed a commit that referenced this pull request May 20, 2021
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12042
behlendorf pushed a commit that referenced this pull request May 20, 2021
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12042
behlendorf pushed a commit that referenced this pull request May 20, 2021
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12042
@behlendorf
Copy link
Contributor

My mistake, I added the wrong PR number to the recently merged comments and accidentally closed this. Re-opening.

@behlendorf behlendorf reopened this May 20, 2021
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label May 20, 2021
@nabijaczleweli
Copy link
Contributor Author

Rebased

@tonyhutter
Copy link
Contributor

Unfortunately, using /tmp/zed.debug.log as a lock would violate LSB:

"Lock files should be stored within the /var/lock directory structure."
https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html#varlockLockFiles

@tonyhutter
Copy link
Contributor

Also: is there some better way to mark the latter two patches as critically dependent on the former than what I've done to the messages?

In this particular case, I would get rid of the middle "lock zed.debug.log" commit, and squash the other two. That way the dependency wont be missed when other people backport this PR to the release branch.

@tonyhutter tonyhutter added the Component: ZED ZFS Event Daemon label May 21, 2021
@nabijaczleweli
Copy link
Contributor Author

nabijaczleweli commented May 21, 2021

/tmp/zed.debug.log is not a lock file. If you read down the paragraph you linked, it describes both the format (HDB UUCP) and the naming (LCK..ttys0) for accessing shared resources, and what they would be, for lock files.

/tmp/zed.debug.log is just the output file, which we lock on, purely cooperatively, from this one script. Likewise for /etc/zfs/zfs-list.cache/poolname. Neither of them are shared resources, and we're definitely not writing the locks in that insane format (mainly because we're... blocking on flock, and not using open(O_CREAT|O_EXCL) or whatever it would be to use the filesystem for "locking" like in the bad old days). You could say that using /var/lock for it is an abuse of the FHS, but that'd be pedantic.

In both cases locking purely on the output file makes more sense. I'd also say that the FHS directs our use of /etc/exports.d/zfs.exports.lock to be moved to /var/lock on Linux instead of keeping the lock permanently in /etc, but.

As for squashing all of these, I'm moderately apprehensive about it, since, well, they all do logically disparate things, and especially the cacher patch is non-trivial.

@tonyhutter
Copy link
Contributor

I'd also say that the FHS directs our use of /etc/exports.d/zfs.exports.lock to be moved to /var/lock on Linux instead of keeping the lock permanently in /etc, but.

Ah, fair point

As for squashing all of these, I'm moderately apprehensive about it, since, well, they all do logically disparate things, and especially the cacher patch is non-trivial.

Yea, after looking at your code in more detail, I see what you're getting at. Why don't you leave the three commits as-is, and we'll just try to keep it in the back of our minds that there's a dependency when we backport.

@@ -126,7 +126,7 @@ zed_lock()

# Obtain a lock on the file bound to the given file descriptor.
#
eval "exec ${fd}> '${lockfile}'"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just so I understand correctly, you use the append (>>) instead of the truncate (>) is to keep us from needlessly recreating the lockfile if it already exists? Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In so many words, yeah. It allows us to lock on any file (that we have write permissions for) instead of only dedicated lock files, since the locking process itself no longer alters the file in any way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, could you add that to the commit message, or add it as a comment to the code, just so future generations know what's happening:

zed-functions.sh: zed_lock(): don't truncate lock

Use append (>>) instead of truncate (>) to let us lock on any file
(that we have write permissions for) instead of only dedicated lock
files, since the locking process itself no longer alters the file in
any way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, updated

By appending instead of truncating, we can lock on any file (with write
permissions) instead of only dedicated lock files, since the locking
process itself no longer alters the file in any way

Signed-off-by: Ahelenia Ziemiańska <[email protected]>
By locking the log file itself, we can omit arduous rebinding and
explicit umask setting, but, perhaps more importantly, avoid permanently
littering /var/lock/ with zed.debug.log.lock we will never delete

It is imperative that the previous commit
("zed-functions.sh: zed_lock(): don't truncate lock")
be included in any series that contains this one

Signed-off-by: Ahelenia Ziemiańska <[email protected]>
This:
  (a) improves the error log message,
  (b) locks per pool instead of globally,
  (c) locks the actual output file instead of /var/lock/zfs-list,
      which would otherwise linger there forever (well, still will,
      but you can remove it and it won't come back), and
  (d) preserves attributes of the output file
      instead of reverting them to 0:0 644

It is imperative that the previous commit
("zed-functions.sh: zed_lock(): don't truncate lock")
be included in any series that contains this one

Signed-off-by: Ahelenia Ziemiańska <[email protected]>
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 8, 2021
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 8, 2021
Before, make shellcheck checked
  scripts/{commitcheck,make_gitrev,man-dates,paxcheck,zfs-helpers,zfs,
           zfs-tests,zimport,zloop}.sh
  cmd/zed/zed.d/{{all-debug,all-syslog,data-notify,generic-notify,
                 resilver_finish-start-scrub,scrub_finish-notify,
                 statechange-led,statechange-notify,trim_finish-notify,
                 zed-functions}.sh,history_event-zfs-list-cacher.sh.in}
  cmd/zpool/zpool.d/{dm-deps,iostat,lsblk,media,ses,smart,upath}
now it also checks
  contrib/dracut/{02zfsexpandknowledge/module-setup,
                  90zfs/{export-zfs,parse-zfs,zfs-needshutdown,
                         zfs-load-key,zfs-lib,module-setup,
                         mount-zfs,zfs-generator}}.sh.in
  cmd/zed/zed.d/{pool_import-led,vdev_attach-led,
                 resilver_finish-notify,vdev_clear-led}.sh
  contrib/initramfs/{zfsunlock,hooks/zfs.in,scripts/local-top/zfs}
  tests/zfs-tests/tests/perf/scripts/prefetch_io.sh
  scripts/common.sh.in
  contrib/bpftrace/zfs-trace.sh
  autogen.sh

Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 8, 2021
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 8, 2021
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 8, 2021
Reviewed-by: John Kennedy <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Jun 8, 2021
@behlendorf behlendorf closed this in b828cf1 Jun 8, 2021
behlendorf pushed a commit that referenced this pull request Jun 8, 2021
By locking the log file itself, we can omit arduous rebinding and
explicit umask setting, but, perhaps more importantly, avoid permanently
littering /var/lock/ with zed.debug.log.lock we will never delete

It is imperative that the previous commit
("zed-functions.sh: zed_lock(): don't truncate lock")
be included in any series that contains this one

Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12042
behlendorf pushed a commit that referenced this pull request Jun 8, 2021
This:
  (a) improves the error log message,
  (b) locks per pool instead of globally,
  (c) locks the actual output file instead of /var/lock/zfs-list,
      which would otherwise linger there forever (well, still will,
      but you can remove it and it won't come back), and
  (d) preserves attributes of the output file
      instead of reverting them to 0:0 644

It is imperative that the previous commit
("zed-functions.sh: zed_lock(): don't truncate lock")
be included in any series that contains this one

Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12042
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 9, 2021
By appending instead of truncating, we can lock on any file (with write
permissions) instead of only dedicated lock files, since the locking
process itself no longer alters the file in any way

Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 9, 2021
By locking the log file itself, we can omit arduous rebinding and
explicit umask setting, but, perhaps more importantly, avoid permanently
littering /var/lock/ with zed.debug.log.lock we will never delete

It is imperative that the previous commit
("zed-functions.sh: zed_lock(): don't truncate lock")
be included in any series that contains this one

Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
behlendorf pushed a commit to behlendorf/zfs that referenced this pull request Jun 9, 2021
This:
  (a) improves the error log message,
  (b) locks per pool instead of globally,
  (c) locks the actual output file instead of /var/lock/zfs-list,
      which would otherwise linger there forever (well, still will,
      but you can remove it and it won't come back), and
  (d) preserves attributes of the output file
      instead of reverting them to 0:0 644

It is imperative that the previous commit
("zed-functions.sh: zed_lock(): don't truncate lock")
be included in any series that contains this one

Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: ZED ZFS Event Daemon Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants