Skip to content

Remove basename(1). Clean up/shorten/eliminate some pipelines #12652

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

Merged
merged 1 commit into from
Nov 11, 2021

Conversation

nabijaczleweli
Copy link
Contributor

Motivation and Context

Basename has a very narrow window of usefulness. For the others, well, they're smaller, and faster.

Basenames that remain:

cmd/zed/zed.d/statechange-led.sh:		dev=$(basename "$(echo "$therest" | awk '{print $(NF-1)}')")
cmd/zed/zed.d/statechange-led.sh:	vdev=$(basename "$ZEVENT_VDEV_PATH")

I don't wanna interfere with #11988

scripts/zfs-tests.sh:	SINGLETESTFILE=$(basename "$SINGLETEST")
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib:		ACTUAL=$(basename $dataset)
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib:		ACTUAL=$(basename $dataset)
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_-c_homedir.ksh:typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_-c_searchpath.ksh:typeset CMD_1=$(basename "$SCRIPT_1")
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/zpool_iostat_-c_searchpath.ksh:typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/cli_user/zpool_status/zpool_status_-c_homedir.ksh:typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_status/zpool_status_-c_searchpath.ksh:typeset CMD_1=$(basename "$SCRIPT_1")
tests/zfs-tests/tests/functional/cli_user/zpool_status/zpool_status_-c_searchpath.ksh:typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/migration/migration.cfg:export BNAME=`basename $TESTFILE`
tests/zfs-tests/tests/perf/perf.shlib:	typeset logbase="$(get_perf_output_dir)/$(basename \
tests/zfs-tests/tests/perf/perf.shlib:		typeset logbase="$(get_perf_output_dir)/$(basename \

These are potentially Of Directories, where basename is actually useful

Description

Case-by-case basis, I grepped for cut, awk, and sed.

How Has This Been Tested?

Ex situ.

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 should apply
  • I have run the ZFS Test Suite with this change applied. ‒ CI take my hand
  • All commit messages are properly formatted and contain Signed-off-by.

@@ -105,8 +105,7 @@ find_rootfs()
find_pools()
{
pools=$("$@" 2> /dev/null | \
grep -E "pool:|^[a-zA-Z0-9]" | \
sed 's@.*: @@' | \
sed -Ee '/pool:|^[a-zA-Z0-9]/!d' -e 's@.*: @@' | \
Copy link
Contributor Author

@nabijaczleweli nabijaczleweli Oct 17, 2021

Choose a reason for hiding this comment

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

BTW, this also catches status: lines. zpool import returns

   pool: zoot
     id: 2006131424514547921
  state: ONLINE
status: The pool was last accessed by another system.
 action: The pool can be imported using its name or numeric identifier and
        the '-f' flag.
   see: https://openzfs.github.io/openzfs-docs/msg/ZFS-8000-EY
 config:

        zoot             ONLINE
          tzpfmest-zoot  ONLINE

for me, which gets filtered down to

zoot
The pool was last accessed by another system.

I don't think this realistically changes anything (well, not for me, anyway, since this lives on my root pool), but I wonder why not just /^pool:? Protection against old (ancient?) ZFS binaries, or?

@@ -11,7 +11,7 @@ fault_led: Show value of the disk enclosure slot fault LED.
locate_led: Show value of the disk enclosure slot locate LED.
ses: Show disk's enc, enc device, slot, and fault/locate LED values."

script=$(basename "$0")
script="${0##*/}"
if [ "$1" = "-h" ] ; then
echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2-
exit
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't comment on the relevant bit so commenting here. Below, in

	case $i in
	enc)
		val=$(ls "$VDEV_ENC_SYSFS_PATH/../../" 2>/dev/null)
		;;
	slot)
		val=$(cat "$VDEV_ENC_SYSFS_PATH/slot" 2>/dev/null)
		;;
	encdev)
		val=$(ls "$VDEV_ENC_SYSFS_PATH/../device/scsi_generic" 2>/dev/null)
		;;
	fault_led)
		val=$(cat "$VDEV_ENC_SYSFS_PATH/fault" 2>/dev/null)
		;;
	locate_led)
		val=$(cat "$VDEV_ENC_SYSFS_PATH/locate" 2>/dev/null)
		;;
esac

The cat ones cold just be read -r val 2>/dev/null < path, but I'm not sure if any of them can be multiline?

@nabijaczleweli nabijaczleweli force-pushed the anti-basename-aktion branch 3 times, most recently from 2248de3 to 81ea874 Compare October 18, 2021 21:00
@nabijaczleweli nabijaczleweli changed the title Remove basename(1). Clean up/shorten some pipelines Remove basename(1). Clean up/shorten/eliminate some pipelines Oct 18, 2021
@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Oct 18, 2021
@behlendorf behlendorf requested a review from tonyhutter October 20, 2021 22:51
@tonyhutter
Copy link
Contributor

How Has This Been Tested?
Ex situ.

Did you run all the scripts and verify everything still works?

@nabijaczleweli
Copy link
Contributor Author

Not all of them, because some of them require hardware I don't have, but for those I ran the relevant bits in vitro.

Also, are we sure parted prints partXXX? Bullseye parted (3.4-1) gives me this on MBR and GPT tables:

nabijaczleweli@tarta:~/store/code/zfs$ sudo parted -s /dev/zd128 -- unit cyl print
Model: Unknown (unknown)
Disk /dev/zd128: 65793cyl
Sector size (logical/physical): 512B/8192B
BIOS cylinder,head,sector geometry: 65793,255,2.  Each cylinder is 261kB.
Partition Table: msdos
Disk Flags:

Number  Start  End       Size      Type     File system  Flags
 1      4cyl   65788cyl  65784cyl  primary  ext4

nabijaczleweli@tarta:~/store/code/zfs$ sudo parted -s /dev/sda -- unit cyl print
Model: ATA SanDisk SD7SN3Q0 (scsi)
Disk /dev/sda: 245187cyl
Sector size (logical/physical): 512B/512B
BIOS cylinder,head,sector geometry: 245187,255,2.  Each cylinder is 261kB.
Partition Table: gpt
Disk Flags:

Number  Start    End        Size       File system  Name             Flags
 1      4cyl     8cyl       4cyl                    tarta-BIOS-boot  bios_grub
 2      8cyl     1036cyl    1028cyl    fat16        tarta-boot       bls_boot
 3      1036cyl  231311cyl  230275cyl  zfs          tarta-zoot

Basenames that remain, in cmd/zed/zed.d/statechange-led.sh:
	dev=$(basename "$(echo "$therest" | awk '{print $(NF-1)}')")
	vdev=$(basename "$ZEVENT_VDEV_PATH")
I don't wanna interfere with openzfs#11988

scripts/zfs-tests.sh:
	SINGLETESTFILE=$(basename "$SINGLETEST")
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib:
	ACTUAL=$(basename $dataset)
	ACTUAL=$(basename $dataset)
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_searchpath.ksh:
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_searchpath.ksh
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/migration/migration.cfg:
	export BNAME=`basename $TESTFILE`
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \
These are potentially Of Directories, where basename is actually useful

Signed-off-by: Ahelenia Ziemiańska <[email protected]>
@nabijaczleweli
Copy link
Contributor Author

Bump. Looks like CI just fails due to unrelated configuration errors?

@jwk404 jwk404 merged commit 420b444 into openzfs:master Nov 11, 2021
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Feb 15, 2022
Basenames that remain, in cmd/zed/zed.d/statechange-led.sh:
	dev=$(basename "$(echo "$therest" | awk '{print $(NF-1)}')")
	vdev=$(basename "$ZEVENT_VDEV_PATH")
I don't wanna interfere with openzfs#11988

scripts/zfs-tests.sh:
	SINGLETESTFILE=$(basename "$SINGLETEST")
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib:
	ACTUAL=$(basename $dataset)
	ACTUAL=$(basename $dataset)
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_searchpath.ksh:
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_searchpath.ksh
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/migration/migration.cfg:
	export BNAME=`basename $TESTFILE`
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \

These are potentially Of Directories, where basename is actually
useful

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12652
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Feb 16, 2022
Basenames that remain, in cmd/zed/zed.d/statechange-led.sh:
	dev=$(basename "$(echo "$therest" | awk '{print $(NF-1)}')")
	vdev=$(basename "$ZEVENT_VDEV_PATH")
I don't wanna interfere with openzfs#11988

scripts/zfs-tests.sh:
	SINGLETESTFILE=$(basename "$SINGLETEST")
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib:
	ACTUAL=$(basename $dataset)
	ACTUAL=$(basename $dataset)
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_searchpath.ksh:
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_searchpath.ksh
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/migration/migration.cfg:
	export BNAME=`basename $TESTFILE`
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \

These are potentially Of Directories, where basename is actually
useful

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12652
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Feb 17, 2022
Basenames that remain, in cmd/zed/zed.d/statechange-led.sh:
	dev=$(basename "$(echo "$therest" | awk '{print $(NF-1)}')")
	vdev=$(basename "$ZEVENT_VDEV_PATH")
I don't wanna interfere with openzfs#11988

scripts/zfs-tests.sh:
	SINGLETESTFILE=$(basename "$SINGLETEST")
tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib:
	ACTUAL=$(basename $dataset)
	ACTUAL=$(basename $dataset)
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_iostat/
	zpool_iostat_-c_searchpath.ksh:
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_homedir.ksh:
	typeset USER_SCRIPT=$(basename "$USER_SCRIPT_FULL")
tests/zfs-tests/tests/functional/cli_user/zpool_status/
	zpool_status_-c_searchpath.ksh
	typeset CMD_1=$(basename "$SCRIPT_1")
	typeset CMD_2=$(basename "$SCRIPT_2")
tests/zfs-tests/tests/functional/migration/migration.cfg:
	export BNAME=`basename $TESTFILE`
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \
tests/zfs-tests/tests/perf/perf.shlib:
	typeset logbase="$(get_perf_output_dir)/$(basename \

These are potentially Of Directories, where basename is actually
useful

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants