From 2a9c572059e9401001bd168465aa521d83e16b32 Mon Sep 17 00:00:00 2001 From: Fedor Uporov <60701163+fuporovvStack@users.noreply.github.com> Date: Wed, 10 Nov 2021 11:22:00 -0800 Subject: [PATCH 01/12] zdb: Report bad label checksum In case if all label checksums will be invalid on any vdev, the pool will become unimportable. From other side zdb with -l option will not provide any useful information why it happened. Add notifications about corrupted label checksums. Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Signed-off-by: Fedor Uporov Closes #2509 Closes #12685 --- cmd/zdb/zdb.c | 52 ++++++++++++- tests/runfiles/common.run | 5 +- tests/zfs-tests/include/blkdev.shlib | 13 ++++ .../tests/functional/cli_root/zdb/Makefile.am | 1 + .../cli_root/zdb/zdb_label_checksum.ksh | 78 +++++++++++++++++++ 5 files changed, 143 insertions(+), 6 deletions(-) create mode 100755 tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 8bbb77479b24..dff61b7bae8b 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -4221,11 +4221,13 @@ print_label_numbers(char *prefix, cksum_record_t *rec) typedef struct zdb_label { vdev_label_t label; + uint64_t label_offset; nvlist_t *config_nv; cksum_record_t *config; cksum_record_t *uberblocks[MAX_UBERBLOCK_COUNT]; boolean_t header_printed; boolean_t read_failed; + boolean_t cksum_valid; } zdb_label_t; static void @@ -4239,7 +4241,8 @@ print_label_header(zdb_label_t *label, int l) return; (void) printf("------------------------------------\n"); - (void) printf("LABEL %d\n", l); + (void) printf("LABEL %d %s\n", l, + label->cksum_valid ? "" : "(Bad label cksum)"); (void) printf("------------------------------------\n"); label->header_printed = B_TRUE; @@ -4751,6 +4754,42 @@ zdb_copy_object(objset_t *os, uint64_t srcobj, char *destfile) return (err); } +static boolean_t +label_cksum_valid(vdev_label_t *label, uint64_t offset) +{ + zio_checksum_info_t *ci = &zio_checksum_table[ZIO_CHECKSUM_LABEL]; + zio_cksum_t expected_cksum; + zio_cksum_t actual_cksum; + zio_cksum_t verifier; + zio_eck_t *eck; + int byteswap; + + void *data = (char *)label + offsetof(vdev_label_t, vl_vdev_phys); + eck = (zio_eck_t *)((char *)(data) + VDEV_PHYS_SIZE) - 1; + + offset += offsetof(vdev_label_t, vl_vdev_phys); + ZIO_SET_CHECKSUM(&verifier, offset, 0, 0, 0); + + byteswap = (eck->zec_magic == BSWAP_64(ZEC_MAGIC)); + if (byteswap) + byteswap_uint64_array(&verifier, sizeof (zio_cksum_t)); + + expected_cksum = eck->zec_cksum; + eck->zec_cksum = verifier; + + abd_t *abd = abd_get_from_buf(data, VDEV_PHYS_SIZE); + ci->ci_func[byteswap](abd, VDEV_PHYS_SIZE, NULL, &actual_cksum); + abd_free(abd); + + if (byteswap) + byteswap_uint64_array(&expected_cksum, sizeof (zio_cksum_t)); + + if (ZIO_CHECKSUM_EQUAL(actual_cksum, expected_cksum)) + return (B_TRUE); + + return (B_FALSE); +} + static int dump_label(const char *dev) { @@ -4817,8 +4856,9 @@ dump_label(const char *dev) /* * 1. Read the label from disk - * 2. Unpack the configuration and insert in config tree. - * 3. Traverse all uberblocks and insert in uberblock tree. + * 2. Verify label cksum + * 3. Unpack the configuration and insert in config tree. + * 4. Traverse all uberblocks and insert in uberblock tree. */ for (int l = 0; l < VDEV_LABELS; l++) { zdb_label_t *label = &labels[l]; @@ -4829,8 +4869,10 @@ dump_label(const char *dev) zio_cksum_t cksum; vdev_t vd; + label->label_offset = vdev_label_offset(psize, l, 0); + if (pread64(fd, &label->label, sizeof (label->label), - vdev_label_offset(psize, l, 0)) != sizeof (label->label)) { + label->label_offset) != sizeof (label->label)) { if (!dump_opt['q']) (void) printf("failed to read label %d\n", l); label->read_failed = B_TRUE; @@ -4839,6 +4881,8 @@ dump_label(const char *dev) } label->read_failed = B_FALSE; + label->cksum_valid = label_cksum_valid(&label->label, + label->label_offset); if (nvlist_unpack(buf, buflen, &config, 0) == 0) { nvlist_t *vdev_tree = NULL; diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index 9f181b53e157..220710548393 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -122,8 +122,9 @@ tags = ['functional', 'clean_mirror'] tests = ['zdb_002_pos', 'zdb_003_pos', 'zdb_004_pos', 'zdb_005_pos', 'zdb_006_pos', 'zdb_args_neg', 'zdb_args_pos', 'zdb_block_size_histogram', 'zdb_checksum', 'zdb_decompress', - 'zdb_display_block', 'zdb_object_range_neg', 'zdb_object_range_pos', - 'zdb_objset_id', 'zdb_decompress_zstd', 'zdb_recover', 'zdb_recover_2'] + 'zdb_display_block', 'zdb_label_checksum', 'zdb_object_range_neg', + 'zdb_object_range_pos', 'zdb_objset_id', 'zdb_decompress_zstd', + 'zdb_recover', 'zdb_recover_2'] pre = post = tags = ['functional', 'cli_root', 'zdb'] diff --git a/tests/zfs-tests/include/blkdev.shlib b/tests/zfs-tests/include/blkdev.shlib index bf70952904bb..18fc6b3524a0 100644 --- a/tests/zfs-tests/include/blkdev.shlib +++ b/tests/zfs-tests/include/blkdev.shlib @@ -652,3 +652,16 @@ function corrupt_blocks_at_level # input_file corrupt_level # This is necessary for pools made of loop devices. sync } + +function corrupt_label_checksum # label_number vdev_path +{ + typeset label_size=$((256*1024)) + typeset vdev_size=$(stat_size ${2}) + typeset -a offsets=("$((128*1024 - 32))" \ + "$(($label_size + (128*1024 - 32)))" \ + "$(($vdev_size - $label_size - (128*1024 + 32)))" \ + "$(($vdev_size - (128*1024 + 32)))") + + dd if=/dev/urandom of=${2} seek=${offsets[$1]} bs=1 count=32 \ + conv=notrunc +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am index d84a3dfc72a2..c1d4bf5a47ba 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/Makefile.am @@ -14,6 +14,7 @@ dist_pkgdata_SCRIPTS = \ zdb_object_range_neg.ksh \ zdb_object_range_pos.ksh \ zdb_display_block.ksh \ + zdb_label_checksum.ksh \ zdb_objset_id.ksh \ zdb_recover.ksh \ zdb_recover_2.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh new file mode 100755 index 000000000000..6cc1560418bc --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_label_checksum.ksh @@ -0,0 +1,78 @@ +#!/bin/ksh + +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2021 by vStack. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/include/blkdev.shlib + +# +# Description: +# zdb -l will report corrupted labels checksums +# +# Strategy: +# 1. Create pool with some number of vdevs and export it +# 2. Corrupt label 0 and label 1, check that corrupted labels are reported +# 3. Check that pool still be imported correctly +# 4. Corrupt all labels, check that all corrupted labels are reported +# 5. Check that pool cannot be imported +# + +log_assert "Verify zdb -l will report corrupted labels checksums" +log_onexit cleanup + +VIRTUAL_DISK=$TEST_BASE_DIR/disk + +function cleanup +{ + poolexists $TESTPOOL && log_must destroy_pool $TESTPOOL + [[ -f $VIRTUAL_DISK ]] && log_must rm $VIRTUAL_DISK +} + +verify_runnable "global" + +log_must truncate -s $(($MINVDEVSIZE * 8)) $VIRTUAL_DISK + +log_must zpool create $TESTPOOL $VIRTUAL_DISK +log_must zpool export $TESTPOOL + +corrupt_label_checksum 0 $VIRTUAL_DISK +corrupt_label_checksum 1 $VIRTUAL_DISK + +msg_count=$(zdb -l $VIRTUAL_DISK | grep -c '(Bad label cksum)') +[ $msg_count -ne 1 ] && \ + log_fail "zdb -l produces an incorrect number of corrupted labels." + +msg_count=$(zdb -lll $VIRTUAL_DISK | grep -c '(Bad label cksum)') +[ $msg_count -ne 2 ] && \ + log_fail "zdb -l produces an incorrect number of corrupted labels." + +log_must zpool import $TESTPOOL -d $TEST_BASE_DIR +log_must zpool export $TESTPOOL + +corrupt_label_checksum 0 $VIRTUAL_DISK +corrupt_label_checksum 1 $VIRTUAL_DISK +corrupt_label_checksum 2 $VIRTUAL_DISK +corrupt_label_checksum 3 $VIRTUAL_DISK + +msg_count=$(zdb -lll $VIRTUAL_DISK | grep -c '(Bad label cksum)') +[ $msg_count -ne 4 ] && \ + log_fail "zdb -l produces an incorrect number of corrupted labels." + +log_mustnot zpool import $TESTPOOL -d $TEST_BASE_DIR + +cleanup + +log_pass "zdb -l bad cksum report is correct." From 371e0f7754746f2b2574006ec5dd58059cf165cd Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 10 Nov 2021 12:56:01 -0800 Subject: [PATCH 02/12] Exclude zfs_copies_003_pos on Linux This test case may fail on 5.13 and newer Linux kernels if the /dev/zvol/ device is not created by udev. Reviewed-by: Rich Ercolani Reviewed-by: John Kennedy Reviewed-by: George Melikov Signed-off-by: Brian Behlendorf Issue #12301 Closes #12738 --- tests/test-runner/bin/zts-report.py.in | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test-runner/bin/zts-report.py.in b/tests/test-runner/bin/zts-report.py.in index ce43d204fc9d..d04663705309 100755 --- a/tests/test-runner/bin/zts-report.py.in +++ b/tests/test-runner/bin/zts-report.py.in @@ -293,6 +293,7 @@ elif sys.platform.startswith('linux'): 'alloc_class/alloc_class_011_neg': ['FAIL', known_reason], 'alloc_class/alloc_class_012_pos': ['FAIL', known_reason], 'alloc_class/alloc_class_013_pos': ['FAIL', '11888'], + 'cli_root/zfs_copies/zfs_copies_003_pos': ['FAIL', '12301'], 'cli_root/zfs_rename/zfs_rename_002_pos': ['FAIL', known_reason], 'cli_root/zpool_expand/zpool_expand_001_pos': ['FAIL', known_reason], 'cli_root/zpool_expand/zpool_expand_005_pos': ['FAIL', known_reason], From c23803be84cb5cc9d98186221f4106a9962dfc45 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 10 Nov 2021 16:14:32 -0800 Subject: [PATCH 03/12] Restore dirty dnode detection logic In addition to flushing memory mapped regions when checking holes, commit de198f2d95 modified the dirty dnode detection logic to check the dn->dn_dirty_records instead of the dn->dn_dirty_link. Relying on the dirty record has not be reliable, switch back to the previous method. Signed-off-by: Brian Behlendorf Issue #11900 Closes #12745 --- module/zfs/dnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/zfs/dnode.c b/module/zfs/dnode.c index 6f87f49f89f3..db1a5d71df3c 100644 --- a/module/zfs/dnode.c +++ b/module/zfs/dnode.c @@ -1657,7 +1657,7 @@ dnode_is_dirty(dnode_t *dn) mutex_enter(&dn->dn_mtx); for (int i = 0; i < TXG_SIZE; i++) { - if (list_head(&dn->dn_dirty_records[i]) != NULL) { + if (multilist_link_active(&dn->dn_dirty_link[i])) { mutex_exit(&dn->dn_mtx); return (B_TRUE); } From 637771a066ba10083e818eb52d299e0d448f149b Mon Sep 17 00:00:00 2001 From: Palash Gandhi Date: Thu, 11 Nov 2021 07:46:44 -0800 Subject: [PATCH 04/12] ZTS: zfs_list_004_neg should not check paths that belong to ZFS When ZFS is on root, /tmp is a ZFS. This causes zfs_list_004_neg to fail since `zfs list` on /tmp passes when the test expects it not to. The fix is to exclude paths that belong to ZFS. Reviewed-by: John Kennedy Reviewed-by: Brian Behlendorf Signed-off-by: Palash Gandhi Closes #12744 --- .../cli_user/zfs_list/zfs_list.kshlib | 19 +++++++++++++++++++ .../cli_user/zfs_list/zfs_list_004_neg.ksh | 10 +++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib index 03c9d1f07a87..889ae46fb932 100644 --- a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib +++ b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list.kshlib @@ -116,3 +116,22 @@ function verify_reverse_sort { # command list name "unexpected number of filesystems found in list output!" fi } + +function is_fs_type_zfs { + + typeset dirname=$1 + typeset fs="$(df $dirname | tail -1 | awk '{print $NF}')" + + if is_freebsd; then + fs_type=$(mount | awk -v fs=$fs '{if ($3 == fs) print $4}' \ + | sed -n 's/(\(.*\),/\1/p') + elif is_linux; then + fs_type=$(mount | awk -v fs=$fs '{if ($3 == fs) print $5}') + fi + + if [[ $fs_type == "zfs" ]]; then + true + else + false + fi +} diff --git a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh index 5d1114dacfa1..727c0aef0883 100755 --- a/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_user/zfs_list/zfs_list_004_neg.ksh @@ -29,7 +29,7 @@ # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # -. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_user/zfs_list/zfs_list.kshlib # # DESCRIPTION: @@ -55,8 +55,12 @@ paths="$TESTPOOL/NONEXISTFS $TESTPOOL/$TESTFS/NONEXISTFS \ cd /tmp for fs in $paths ; do - log_mustnot zfs list $fs - log_mustnot zfs list -r $fs + # In cases when ZFS is on root, /tmp will belong to ZFS and hence must be + # skipped + if ! is_fs_type_zfs $fs; then + log_mustnot zfs list $fs + log_mustnot zfs list -r $fs + fi done log_pass "'zfs list [-r]' fails while the given dataset/path does not exist " \ From d04b5c9e877a4d4b2337e6b2b453c7650aed433d Mon Sep 17 00:00:00 2001 From: Fedor Uporov <60701163+fuporovvStack@users.noreply.github.com> Date: Thu, 11 Nov 2021 11:26:18 -0800 Subject: [PATCH 05/12] zhack: Add repair label option In case if all label checksums will be invalid on any vdev, the pool will become unimportable. The zhack with newly added cli options could be used to restore label checksums and make pool importable again. Reviewed-by: Brian Behlendorf Signed-off-by: Fedor Uporov Closes #2510 Closes #12686 --- cmd/zhack/zhack.c | 171 +++++++++++++++++- configure.ac | 1 + man/man1/zhack.1 | 7 + tests/runfiles/common.run | 6 + .../tests/functional/cli_root/Makefile.am | 1 + .../functional/cli_root/zhack/Makefile.am | 3 + .../cli_root/zhack/zhack_label_checksum.ksh | 64 +++++++ 7 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 tests/zfs-tests/tests/functional/cli_root/zhack/Makefile.am create mode 100755 tests/zfs-tests/tests/functional/cli_root/zhack/zhack_label_checksum.ksh diff --git a/cmd/zhack/zhack.c b/cmd/zhack/zhack.c index b27423f538e7..bae242712a75 100644 --- a/cmd/zhack/zhack.c +++ b/cmd/zhack/zhack.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -76,7 +78,12 @@ usage(void) " -d decrease instead of increase the refcount\n" " -m add the feature to the label if increasing refcount\n" "\n" - " : should be a feature guid\n"); + " : should be a feature guid\n" + "\n" + " label repair \n" + " repair corrupted label checksums\n" + "\n" + " : path to vdev\n"); exit(1); } @@ -471,6 +478,166 @@ zhack_do_feature(int argc, char **argv) return (0); } +static int +zhack_repair_label_cksum(int argc, char **argv) +{ + zio_checksum_info_t *ci = &zio_checksum_table[ZIO_CHECKSUM_LABEL]; + const char *cfg_keys[] = { ZPOOL_CONFIG_VERSION, + ZPOOL_CONFIG_POOL_STATE, ZPOOL_CONFIG_GUID }; + boolean_t labels_repaired[VDEV_LABELS]; + boolean_t repaired = B_FALSE; + vdev_label_t labels[VDEV_LABELS]; + struct stat st; + int fd; + + bzero(labels_repaired, sizeof (labels_repaired)); + bzero(labels, sizeof (labels)); + + abd_init(); + + argc -= 1; + argv += 1; + + if (argc < 1) { + (void) fprintf(stderr, "error: missing device\n"); + usage(); + } + + if ((fd = open(argv[0], O_RDWR)) == -1) + fatal(NULL, FTAG, "cannot open '%s': %s", argv[0], + strerror(errno)); + + if (stat(argv[0], &st) != 0) + fatal(NULL, FTAG, "cannot stat '%s': %s", argv[0], + strerror(errno)); + + for (int l = 0; l < VDEV_LABELS; l++) { + uint64_t label_offset, offset; + zio_cksum_t expected_cksum; + zio_cksum_t actual_cksum; + zio_cksum_t verifier; + zio_eck_t *eck; + nvlist_t *cfg; + int byteswap; + uint64_t val; + ssize_t err; + + vdev_label_t *vl = &labels[l]; + + label_offset = vdev_label_offset(st.st_size, l, 0); + err = pread64(fd, vl, sizeof (vdev_label_t), label_offset); + if (err == -1) { + (void) fprintf(stderr, "error: cannot read " + "label %d: %s\n", l, strerror(errno)); + continue; + } else if (err != sizeof (vdev_label_t)) { + (void) fprintf(stderr, "error: bad label %d read size " + "\n", l); + continue; + } + + err = nvlist_unpack(vl->vl_vdev_phys.vp_nvlist, + VDEV_PHYS_SIZE - sizeof (zio_eck_t), &cfg, 0); + if (err) { + (void) fprintf(stderr, "error: cannot unpack nvlist " + "label %d\n", l); + continue; + } + + for (int i = 0; i < ARRAY_SIZE(cfg_keys); i++) { + err = nvlist_lookup_uint64(cfg, cfg_keys[i], &val); + if (err) { + (void) fprintf(stderr, "error: label %d: " + "cannot find nvlist key %s\n", + l, cfg_keys[i]); + continue; + } + } + + void *data = (char *)vl + offsetof(vdev_label_t, vl_vdev_phys); + eck = (zio_eck_t *)((char *)(data) + VDEV_PHYS_SIZE) - 1; + + offset = label_offset + offsetof(vdev_label_t, vl_vdev_phys); + ZIO_SET_CHECKSUM(&verifier, offset, 0, 0, 0); + + byteswap = (eck->zec_magic == BSWAP_64(ZEC_MAGIC)); + if (byteswap) + byteswap_uint64_array(&verifier, sizeof (zio_cksum_t)); + + expected_cksum = eck->zec_cksum; + eck->zec_cksum = verifier; + + abd_t *abd = abd_get_from_buf(data, VDEV_PHYS_SIZE); + ci->ci_func[byteswap](abd, VDEV_PHYS_SIZE, NULL, &actual_cksum); + abd_free(abd); + + if (byteswap) + byteswap_uint64_array(&expected_cksum, + sizeof (zio_cksum_t)); + + if (ZIO_CHECKSUM_EQUAL(actual_cksum, expected_cksum)) + continue; + + eck->zec_cksum = actual_cksum; + + err = pwrite64(fd, data, VDEV_PHYS_SIZE, offset); + if (err == -1) { + (void) fprintf(stderr, "error: cannot write " + "label %d: %s\n", l, strerror(errno)); + continue; + } else if (err != VDEV_PHYS_SIZE) { + (void) fprintf(stderr, "error: bad write size " + "label %d\n", l); + continue; + } + + fsync(fd); + + labels_repaired[l] = B_TRUE; + } + + close(fd); + + abd_fini(); + + for (int l = 0; l < VDEV_LABELS; l++) { + (void) printf("label %d: %s\n", l, + labels_repaired[l] ? "repaired" : "skipped"); + repaired |= labels_repaired[l]; + } + + if (repaired) + return (0); + + return (1); +} + +static int +zhack_do_label(int argc, char **argv) +{ + char *subcommand; + int err; + + argc--; + argv++; + if (argc == 0) { + (void) fprintf(stderr, + "error: no label operation specified\n"); + usage(); + } + + subcommand = argv[0]; + if (strcmp(subcommand, "repair") == 0) { + err = zhack_repair_label_cksum(argc, argv); + } else { + (void) fprintf(stderr, "error: unknown subcommand: %s\n", + subcommand); + usage(); + } + + return (err); +} + #define MAX_NUM_PATHS 1024 int @@ -516,6 +683,8 @@ main(int argc, char **argv) if (strcmp(subcommand, "feature") == 0) { rv = zhack_do_feature(argc, argv); + } else if (strcmp(subcommand, "label") == 0) { + return (zhack_do_label(argc, argv)); } else { (void) fprintf(stderr, "error: unknown subcommand: %s\n", subcommand); diff --git a/configure.ac b/configure.ac index ebc7b276a640..4ff902cdc289 100644 --- a/configure.ac +++ b/configure.ac @@ -288,6 +288,7 @@ AC_CONFIG_FILES([ tests/zfs-tests/tests/functional/cli_root/zfs_unshare/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/Makefile tests/zfs-tests/tests/functional/cli_root/zfs_wait/Makefile + tests/zfs-tests/tests/functional/cli_root/zhack/Makefile tests/zfs-tests/tests/functional/cli_root/zpool/Makefile tests/zfs-tests/tests/functional/cli_root/zpool_add/Makefile tests/zfs-tests/tests/functional/cli_root/zpool_attach/Makefile diff --git a/man/man1/zhack.1 b/man/man1/zhack.1 index 83046ee8f515..b03b87a1bdab 100644 --- a/man/man1/zhack.1 +++ b/man/man1/zhack.1 @@ -94,6 +94,13 @@ The flag indicates that the .Ar guid feature is now required to read the pool MOS. +. +.It Xo +.Nm zhack +.Cm label repair +.Ar device +.Xc +Repair corrupted labels by rewriting the checksum using the presumed valid contents of the label. .El . .Sh GLOBAL OPTIONS diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index 220710548393..980e25958f7f 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -317,6 +317,12 @@ tags = ['functional', 'cli_root', 'zfs_upgrade'] tests = ['zfs_wait_deleteq'] tags = ['functional', 'cli_root', 'zfs_wait'] +[tests/functional/cli_root/zhack] +tests = ['zhack_label_checksum'] +pre = +post = +tags = ['functional', 'cli_root', 'zhack'] + [tests/functional/cli_root/zpool] tests = ['zpool_001_neg', 'zpool_002_pos', 'zpool_003_pos', 'zpool_colors'] tags = ['functional', 'cli_root', 'zpool'] diff --git a/tests/zfs-tests/tests/functional/cli_root/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/Makefile.am index c01ecee89640..9951f96f31ef 100644 --- a/tests/zfs-tests/tests/functional/cli_root/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/Makefile.am @@ -35,6 +35,7 @@ SUBDIRS = \ zfs_unshare \ zfs_upgrade \ zfs_wait \ + zhack \ zpool \ zpool_add \ zpool_attach \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zhack/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zhack/Makefile.am new file mode 100644 index 000000000000..931dacde6beb --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zhack/Makefile.am @@ -0,0 +1,3 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zhack +dist_pkgdata_SCRIPTS = \ + zhack_label_checksum.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zhack/zhack_label_checksum.ksh b/tests/zfs-tests/tests/functional/cli_root/zhack/zhack_label_checksum.ksh new file mode 100755 index 000000000000..67c7e7c4487d --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zhack/zhack_label_checksum.ksh @@ -0,0 +1,64 @@ +#!/bin/ksh + +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2021 by vStack. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/include/blkdev.shlib + +# +# Description: +# zhack label repair will calculate and rewrite label checksum if invalid +# +# Strategy: +# 1. Create pool with some number of vdevs and export it +# 2. Corrupt all labels checksums +# 3. Check that pool cannot be imported +# 4. Use zhack to repair labels checksums +# 5. Check that pool can be imported +# + +log_assert "Verify zhack label repair will repair labels checksums" +log_onexit cleanup + +VIRTUAL_DISK=$TEST_BASE_DIR/disk + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + [[ -f $VIRTUAL_DISK ]] && log_must rm $VIRTUAL_DISK +} + +log_must truncate -s $(($MINVDEVSIZE * 8)) $VIRTUAL_DISK + +log_must zpool create $TESTPOOL $VIRTUAL_DISK +log_must zpool export $TESTPOOL + +log_mustnot zhack label repair $VIRTUAL_DISK + +corrupt_label_checksum 0 $VIRTUAL_DISK +corrupt_label_checksum 1 $VIRTUAL_DISK +corrupt_label_checksum 2 $VIRTUAL_DISK +corrupt_label_checksum 3 $VIRTUAL_DISK + +log_mustnot zpool import $TESTPOOL -d $TEST_BASE_DIR + +log_must zhack label repair $VIRTUAL_DISK + +log_must zpool import $TESTPOOL -d $TEST_BASE_DIR + +cleanup + +log_pass "zhack label repair works correctly." From 49d42425d6dc9b55c8e83aa1b920fd0e08f7a142 Mon Sep 17 00:00:00 2001 From: Fedor Uporov <60701163+fuporovvStack@users.noreply.github.com> Date: Thu, 11 Nov 2021 11:54:15 -0800 Subject: [PATCH 06/12] Check l2cache vdevs pending list inside the vdev_inuse() The l2cache device could be added twice because vdev_inuse() does not check spa_l2cache for added devices. Make l2cache vdevs inuse checking logic more closer to spare vdevs. Reviewed-by: George Amanakis Reviewed-by: Brian Behlendorf Signed-off-by: Fedor Uporov Closes #9153 Closes #12689 --- include/sys/spa.h | 1 + module/zfs/spa.c | 21 +++++++++++++---- module/zfs/vdev_label.c | 23 +++++++++++++++---- .../cli_root/zpool_add/zpool_add_009_neg.ksh | 12 +++++++--- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/include/sys/spa.h b/include/sys/spa.h index 2ae467877ddf..a55dbd66d8d7 100644 --- a/include/sys/spa.h +++ b/include/sys/spa.h @@ -1075,6 +1075,7 @@ extern void spa_upgrade(spa_t *spa, uint64_t version); extern void spa_evict_all(void); extern vdev_t *spa_lookup_by_guid(spa_t *spa, uint64_t guid, boolean_t l2cache); +extern boolean_t spa_has_l2cache(spa_t *, uint64_t guid); extern boolean_t spa_has_spare(spa_t *, uint64_t guid); extern uint64_t dva_get_dsize_sync(spa_t *spa, const dva_t *dva); extern uint64_t bp_get_dsize_sync(spa_t *spa, const blkptr_t *bp); diff --git a/module/zfs/spa.c b/module/zfs/spa.c index 1083b5a90da9..7546e3e414f1 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -9451,12 +9451,11 @@ spa_upgrade(spa_t *spa, uint64_t version) txg_wait_synced(spa_get_dsl(spa), 0); } -boolean_t -spa_has_spare(spa_t *spa, uint64_t guid) +static boolean_t +spa_has_aux_vdev(spa_t *spa, uint64_t guid, spa_aux_vdev_t *sav) { int i; - uint64_t spareguid; - spa_aux_vdev_t *sav = &spa->spa_spares; + uint64_t vdev_guid; for (i = 0; i < sav->sav_count; i++) if (sav->sav_vdevs[i]->vdev_guid == guid) @@ -9464,13 +9463,25 @@ spa_has_spare(spa_t *spa, uint64_t guid) for (i = 0; i < sav->sav_npending; i++) { if (nvlist_lookup_uint64(sav->sav_pending[i], ZPOOL_CONFIG_GUID, - &spareguid) == 0 && spareguid == guid) + &vdev_guid) == 0 && vdev_guid == guid) return (B_TRUE); } return (B_FALSE); } +boolean_t +spa_has_l2cache(spa_t *spa, uint64_t guid) +{ + return (spa_has_aux_vdev(spa, guid, &spa->spa_l2cache)); +} + +boolean_t +spa_has_spare(spa_t *spa, uint64_t guid) +{ + return (spa_has_aux_vdev(spa, guid, &spa->spa_spares)); +} + /* * Check if a pool has an active shared spare device. * Note: reference count of an active spare is 2, as a spare and as a replace diff --git a/module/zfs/vdev_label.c b/module/zfs/vdev_label.c index f03ae0873f6c..daf53f0a0c8b 100644 --- a/module/zfs/vdev_label.c +++ b/module/zfs/vdev_label.c @@ -933,7 +933,7 @@ vdev_inuse(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason, /* * Check to see if this is a spare device. We do an explicit check for * spa_has_spare() here because it may be on our pending list of spares - * to add. We also check if it is an l2cache device. + * to add. */ if (spa_spare_exists(device_guid, &spare_pool, NULL) || spa_has_spare(spa, device_guid)) { @@ -942,7 +942,6 @@ vdev_inuse(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason, switch (reason) { case VDEV_LABEL_CREATE: - case VDEV_LABEL_L2CACHE: return (B_TRUE); case VDEV_LABEL_REPLACE: @@ -959,8 +958,24 @@ vdev_inuse(vdev_t *vd, uint64_t crtxg, vdev_labeltype_t reason, /* * Check to see if this is an l2cache device. */ - if (spa_l2cache_exists(device_guid, NULL)) - return (B_TRUE); + if (spa_l2cache_exists(device_guid, NULL) || + spa_has_l2cache(spa, device_guid)) { + if (l2cache_guid) + *l2cache_guid = device_guid; + + switch (reason) { + case VDEV_LABEL_CREATE: + return (B_TRUE); + + case VDEV_LABEL_REPLACE: + return (!spa_has_l2cache(spa, device_guid)); + + case VDEV_LABEL_L2CACHE: + return (spa_has_l2cache(spa, device_guid)); + default: + break; + } + } /* * We can't rely on a pool's state if it's been imported diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh index 7ffe9512afea..0a9fa868cb81 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_009_neg.ksh @@ -39,8 +39,9 @@ # # STRATEGY: # 1. Create a storage pool -# 2. Add the two same devices to pool A -# 3. Add the device in pool A to pool A again +# 2. Add the device in pool A to pool A again +# 3. Add the two devices to pool A in the loop, one of them already +# added or same device added multiple times # verify_runnable "global" @@ -58,8 +59,13 @@ log_onexit cleanup create_pool $TESTPOOL $DISK0 log_must poolexists $TESTPOOL -log_mustnot zpool add -f $TESTPOOL $DISK1 $DISK1 log_mustnot zpool add -f $TESTPOOL $DISK0 +for type in "" "mirror" "raidz" "draid" "spare" "log" "dedup" "special" "cache" +do + log_mustnot zpool add -f $TESTPOOL $type $DISK0 $DISK1 + log_mustnot zpool add -f $TESTPOOL $type $DISK1 $DISK1 +done + log_pass "'zpool add' get fail as expected if vdevs are the same or vdev is " \ "contained in the given pool." From 420b44488ff91dc0f67c24faae5d580122b08cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 11 Nov 2021 21:27:37 +0100 Subject: [PATCH 07/12] Remove basename(1). Clean up/shorten some coreutils pipelines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 #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 Reviewed-by: John Kennedy Signed-off-by: Ahelenia ZiemiaƄska Closes #12652 --- cmd/vdev_id/vdev_id | 11 +++++++---- cmd/zed/zed.d/all-syslog.sh | 2 +- cmd/zed/zed.d/generic-notify.sh | 2 +- cmd/zed/zed.d/zed-functions.sh | 6 +++--- cmd/zpool/zpool.d/dm-deps | 10 ++++------ cmd/zpool/zpool.d/iostat | 6 +++--- cmd/zpool/zpool.d/lsblk | 2 +- cmd/zpool/zpool.d/media | 15 ++++++--------- cmd/zpool/zpool.d/ses | 2 +- config/always-python.m4 | 2 +- config/always-pyzfs.m4 | 2 +- config/zfs-meta.m4 | 4 ++-- contrib/bpftrace/zfs-trace.sh | 3 ++- .../02zfsexpandknowledge/module-setup.sh.in | 16 ++++++---------- contrib/dracut/90zfs/module-setup.sh.in | 2 +- contrib/dracut/90zfs/parse-zfs.sh.in | 2 +- contrib/dracut/90zfs/zfs-generator.sh.in | 2 +- contrib/initramfs/scripts/zfs | 5 ++--- etc/init.d/zfs-import.in | 3 +-- etc/zfs/zfs-functions.in | 14 ++++++-------- rpm/generic/zfs-dkms.spec.in | 2 +- scripts/kmodtool | 2 +- scripts/zfs-tests.sh | 4 ++-- scripts/zfs.sh | 11 +++++++---- scripts/zimport.sh | 2 +- tests/zfs-tests/include/libtest.shlib | 8 +++----- .../reservation/reservation_021_neg.ksh | 2 +- 27 files changed, 67 insertions(+), 75 deletions(-) diff --git a/cmd/vdev_id/vdev_id b/cmd/vdev_id/vdev_id index 8cc4399a5668..7b5aab141997 100755 --- a/cmd/vdev_id/vdev_id +++ b/cmd/vdev_id/vdev_id @@ -596,7 +596,9 @@ enclosure_handler () { # DEVPATH=/sys/devices/pci0000:00/0000:00:03.0/0000:05:00.0/host0/subsystem/devices/0:0:0:0/scsi_generic/sg0 # Get the enclosure ID ("0:0:0:0") - ENC=$(basename $(readlink -m "/sys/$DEVPATH/../..")) + ENC="${DEVPATH%/*}" + ENC="${ENC%/*}" + ENC="${ENC##*/}" if [ ! -d "/sys/class/enclosure/$ENC" ] ; then # Not an enclosure, bail out return @@ -616,10 +618,11 @@ enclosure_handler () { # The PCI directory is two directories up from the port directory # /sys/devices/pci0000:00/0000:00:03.0/0000:05:00.0 - PCI_ID_LONG=$(basename $(readlink -m "/sys/$PORT_DIR/../..")) + PCI_ID_LONG="$(readlink -m "/sys/$PORT_DIR/../..")" + PCI_ID_LONG="${PCI_ID_LONG##*/}" # Strip down the PCI address from 0000:05:00.0 to 05:00.0 - PCI_ID=$(echo "$PCI_ID_LONG" | sed -r 's/^[0-9]+://g') + PCI_ID="${PCI_ID_LONG#[0-9]*:}" # Name our device according to vdev_id.conf (like "L0" or "U1"). NAME=$(awk "/channel/{if (\$1 == \"channel\" && \$2 == \"$PCI_ID\" && \ @@ -674,7 +677,7 @@ alias_handler () { link=$(echo "$link" | sed 's/p[0-9][0-9]*$//') fi # Check both the fully qualified and the base name of link. - for l in $link $(basename "$link") ; do + for l in $link ${link##*/} ; do if [ ! -z "$l" ]; then alias=$(awk -v var="$l" '($1 == "alias") && \ ($3 == var) \ diff --git a/cmd/zed/zed.d/all-syslog.sh b/cmd/zed/zed.d/all-syslog.sh index b07cf0f295ad..ea108c47b779 100755 --- a/cmd/zed/zed.d/all-syslog.sh +++ b/cmd/zed/zed.d/all-syslog.sh @@ -21,7 +21,7 @@ if [ "${ZED_SYSLOG_DISPLAY_GUIDS}" = "1" ]; then [ -n "${ZEVENT_VDEV_GUID}" ] && msg="${msg} vdev_guid=${ZEVENT_VDEV_GUID}" else [ -n "${ZEVENT_POOL}" ] && msg="${msg} pool='${ZEVENT_POOL}'" - [ -n "${ZEVENT_VDEV_PATH}" ] && msg="${msg} vdev=$(basename "${ZEVENT_VDEV_PATH}")" + [ -n "${ZEVENT_VDEV_PATH}" ] && msg="${msg} vdev=${ZEVENT_VDEV_PATH##*/}" fi # log pool state if state is anything other than 'ACTIVE' diff --git a/cmd/zed/zed.d/generic-notify.sh b/cmd/zed/zed.d/generic-notify.sh index 1db26980c1a0..9cf657e39970 100755 --- a/cmd/zed/zed.d/generic-notify.sh +++ b/cmd/zed/zed.d/generic-notify.sh @@ -23,7 +23,7 @@ # Rate-limit the notification based in part on the filename. # -rate_limit_tag="${ZEVENT_POOL};${ZEVENT_SUBCLASS};$(basename -- "$0")" +rate_limit_tag="${ZEVENT_POOL};${ZEVENT_SUBCLASS};${0##*/}" rate_limit_interval="${ZED_NOTIFY_INTERVAL_SECS}" zed_rate_limit "${rate_limit_tag}" "${rate_limit_interval}" || exit 3 diff --git a/cmd/zed/zed.d/zed-functions.sh b/cmd/zed/zed.d/zed-functions.sh index 2ec0ea6948d8..eb59036cf4d8 100644 --- a/cmd/zed/zed.d/zed-functions.sh +++ b/cmd/zed/zed.d/zed-functions.sh @@ -77,7 +77,7 @@ zed_log_msg() zed_log_err() { logger -p "${ZED_SYSLOG_PRIORITY}" -t "${ZED_SYSLOG_TAG}" -- "error:" \ - "$(basename -- "$0"):""${ZEVENT_EID:+" eid=${ZEVENT_EID}:"}" "$@" + "${0##*/}:""${ZEVENT_EID:+" eid=${ZEVENT_EID}:"}" "$@" } @@ -258,7 +258,7 @@ zed_notify_email() [ -n "${subject}" ] || return 1 if [ ! -r "${pathname}" ]; then zed_log_err \ - "$(basename "${ZED_EMAIL_PROG}") cannot read \"${pathname}\"" + "${ZED_EMAIL_PROG##*/} cannot read \"${pathname}\"" return 1 fi @@ -270,7 +270,7 @@ zed_notify_email() eval ${ZED_EMAIL_PROG} ${ZED_EMAIL_OPTS} < "${pathname}" >/dev/null 2>&1 rv=$? if [ "${rv}" -ne 0 ]; then - zed_log_err "$(basename "${ZED_EMAIL_PROG}") exit=${rv}" + zed_log_err "${ZED_EMAIL_PROG##*/} exit=${rv}" return 1 fi return 0 diff --git a/cmd/zpool/zpool.d/dm-deps b/cmd/zpool/zpool.d/dm-deps index ee39514e4d92..42af6a8d63cd 100755 --- a/cmd/zpool/zpool.d/dm-deps +++ b/cmd/zpool/zpool.d/dm-deps @@ -16,14 +16,12 @@ if [ -L "$dev" ] ; then dev=$(readlink "$dev") fi -dev=$(basename "$dev") +dev="${dev##*/}" val="" if [ -d "/sys/class/block/$dev/slaves" ] ; then - # ls -C: output in columns, no newlines - val=$(ls -C "/sys/class/block/$dev/slaves") - - # ls -C will print two spaces between files; change to one space. - val=$(echo "$val" | sed -r 's/[[:blank:]]+/ /g') + # ls -C: output in columns, no newlines, two spaces (change to one) + # shellcheck disable=SC2012 + val=$(ls -C "/sys/class/block/$dev/slaves" | tr -s '[:space:]' ' ') fi echo "dm-deps=$val" diff --git a/cmd/zpool/zpool.d/iostat b/cmd/zpool/zpool.d/iostat index 41a3acfae7a4..19be475e9b27 100755 --- a/cmd/zpool/zpool.d/iostat +++ b/cmd/zpool/zpool.d/iostat @@ -9,7 +9,7 @@ iostat: Show iostat values since boot (summary page). iostat-1s: Do a single 1-second iostat sample and show values. iostat-10s: Do a single 10-second iostat sample and show values." -script=$(basename "$0") +script="${0##*/}" if [ "$1" = "-h" ] ; then echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2- exit @@ -42,7 +42,7 @@ else ${brief:+"-y"} \ ${interval:+"$interval"} \ ${interval:+"1"} \ - "$VDEV_UPATH" | awk NF | tail -n 2) + "$VDEV_UPATH" | grep -v '^$' | tail -n 2) fi @@ -61,7 +61,7 @@ fi cols=$(echo "$out" | head -n 1) # Get the values and tab separate them to make them cut-able. -vals=$(echo "$out" | tail -n 1 | sed -r 's/[[:blank:]]+/\t/g') +vals=$(echo "$out" | tail -n 1 | tr -s '[:space:]' '\t') i=0 for col in $cols ; do diff --git a/cmd/zpool/zpool.d/lsblk b/cmd/zpool/zpool.d/lsblk index 1cdef40494fe..919783a1c1bf 100755 --- a/cmd/zpool/zpool.d/lsblk +++ b/cmd/zpool/zpool.d/lsblk @@ -48,7 +48,7 @@ size: Show the disk capacity. vendor: Show the disk vendor. lsblk: Show the disk size, vendor, and model number." -script=$(basename "$0") +script="${0##*/}" if [ "$1" = "-h" ] ; then echo "$helpstr" | grep "$script:" | tr -s '\t' | cut -f 2- diff --git a/cmd/zpool/zpool.d/media b/cmd/zpool/zpool.d/media index 5683cdc3c023..660f78b743fc 100755 --- a/cmd/zpool/zpool.d/media +++ b/cmd/zpool/zpool.d/media @@ -9,15 +9,12 @@ if [ "$1" = "-h" ] ; then fi if [ -b "$VDEV_UPATH" ]; then - device=$(basename "$VDEV_UPATH") - val=$(cat "/sys/block/$device/queue/rotational" 2>/dev/null) - if [ "$val" = "0" ]; then - MEDIA="ssd" - fi - - if [ "$val" = "1" ]; then - MEDIA="hdd" - fi + device="${VDEV_UPATH##*/}" + read -r val 2>/dev/null < "/sys/block/$device/queue/rotational" + case "$val" in + 0) MEDIA="ssd" ;; + 1) MEDIA="hdd" ;; + esac vpd_pg83="/sys/block/$device/device/vpd_pg83" if [ -f "$vpd_pg83" ]; then diff --git a/cmd/zpool/zpool.d/ses b/cmd/zpool/zpool.d/ses index b1836d676528..b51fe31894ab 100755 --- a/cmd/zpool/zpool.d/ses +++ b/cmd/zpool/zpool.d/ses @@ -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 diff --git a/config/always-python.m4 b/config/always-python.m4 index 76b06fcd8488..5f47df424c27 100644 --- a/config/always-python.m4 +++ b/config/always-python.m4 @@ -28,7 +28,7 @@ AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_PYTHON], [ dnl # AM_PATH_PYTHON([], [], [:]) AS_IF([test -z "$PYTHON_VERSION"], [ - PYTHON_VERSION=$(basename $PYTHON | tr -cd 0-9.) + PYTHON_VERSION=$(echo ${PYTHON##*/} | tr -cd 0-9.) ]) PYTHON_MINOR=${PYTHON_VERSION#*\.} diff --git a/config/always-pyzfs.m4 b/config/always-pyzfs.m4 index fa39fd88519c..00e5d0e2cbbd 100644 --- a/config/always-pyzfs.m4 +++ b/config/always-pyzfs.m4 @@ -6,7 +6,7 @@ dnl # https://www.gnu.org/software/autoconf-archive/ax_python_module.html dnl # Required by ZFS_AC_CONFIG_ALWAYS_PYZFS. dnl # AC_DEFUN([ZFS_AC_PYTHON_MODULE], [ - PYTHON_NAME=$(basename $PYTHON) + PYTHON_NAME=${PYTHON##*/} AC_MSG_CHECKING([for $PYTHON_NAME module: $1]) AS_IF([$PYTHON -c "import $1" 2>/dev/null], [ AC_MSG_RESULT(yes) diff --git a/config/zfs-meta.m4 b/config/zfs-meta.m4 index 1c9d246124d1..20064a0fb595 100644 --- a/config/zfs-meta.m4 +++ b/config/zfs-meta.m4 @@ -73,14 +73,14 @@ AC_DEFUN([ZFS_AC_META], [ if test ! -f ".nogitrelease" && git rev-parse --git-dir > /dev/null 2>&1; then _match="${ZFS_META_NAME}-${ZFS_META_VERSION}" _alias=$(git describe --match=${_match} 2>/dev/null) - _release=$(echo ${_alias}|sed "s/${ZFS_META_NAME}//"|cut -f3- -d'-'|sed 's/-/_/g') + _release=$(echo ${_alias}|sed "s/${ZFS_META_NAME}//"|cut -f3- -d'-'|tr - _) if test -n "${_release}"; then ZFS_META_RELEASE=${_release} _zfs_ac_meta_type="git describe" else _match="${ZFS_META_NAME}-${ZFS_META_VERSION}-${ZFS_META_RELEASE}" _alias=$(git describe --match=${_match} 2>/dev/null) - _release=$(echo ${_alias}|sed 's/${ZFS_META_NAME}//'|cut -f3- -d'-'|sed 's/-/_/g') + _release=$(echo ${_alias}|sed 's/${ZFS_META_NAME}//'|cut -f3- -d'-'|tr - _) if test -n "${_release}"; then ZFS_META_RELEASE=${_release} _zfs_ac_meta_type="git describe" diff --git a/contrib/bpftrace/zfs-trace.sh b/contrib/bpftrace/zfs-trace.sh index 54f66f3ba3fd..0165335c474b 100755 --- a/contrib/bpftrace/zfs-trace.sh +++ b/contrib/bpftrace/zfs-trace.sh @@ -1,6 +1,7 @@ #!/bin/sh -ZVER=$(cut -f 1 -d '-' /sys/module/zfs/version) +read -r ZVER < /sys/module/zfs/version +ZVER="${ZVER%%-*}" KVER=$(uname -r) exec bpftrace \ diff --git a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in index d21ab74cc0d0..a161fbf6f113 100755 --- a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in +++ b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in @@ -2,8 +2,8 @@ get_devtype() { local typ - typ=$(udevadm info --query=property --name="$1" | grep "^ID_FS_TYPE=" | sed 's|^ID_FS_TYPE=||') - if [ "$typ" = "" ] ; then + typ=$(udevadm info --query=property --name="$1" | sed -n 's|^ID_FS_TYPE=||p') + if [ -z "$typ" ] ; then typ=$(blkid -c /dev/null "$1" -o value -s TYPE) fi echo "$typ" @@ -36,7 +36,6 @@ find_zfs_block_devices() { local dev local mp local fstype - local pool local _ numfields="$(awk '{print NF; exit}' /proc/self/mountinfo)" if [ "$numfields" = "10" ] ; then @@ -47,10 +46,7 @@ find_zfs_block_devices() { # shellcheck disable=SC2086 while read -r ${fields?} ; do [ "$fstype" = "zfs" ] || continue - if [ "$mp" = "$1" ]; then - pool=$(echo "$dev" | cut -d / -f 1) - get_pool_devices "$pool" - fi + [ "$mp" = "$1" ] && get_pool_devices "${dev%%/*}" done < /proc/self/mountinfo } @@ -100,9 +96,9 @@ if [ -n "$hostonly" ]; then majmin=$(get_maj_min "$dev") if [ -d "/sys/dev/block/$majmin/slaves" ] ; then for _depdev in "/sys/dev/block/$majmin/slaves"/*; do - [[ -f $_depdev/dev ]] || continue - _depdev=/dev/$(basename "$_depdev") - _depdevname=$(udevadm info --query=property --name="$_depdev" | grep "^DEVNAME=" | sed 's|^DEVNAME=||') + [ -f "$_depdev/dev" ] || continue + _depdev="/dev/${_depdev##*/}" + _depdevname=$(udevadm info --query=property --name="$_depdev" | sed -n 's|^DEVNAME=||p') _depdevtype=$(get_devtype "$_depdevname") dinfo "zfsexpandknowledge: underlying block device backing ZFS dataset $mp: ${_depdevname//$'\n'/ }" array_contains "$_depdevname" "${host_devs[@]}" || host_devs+=("$_depdevname") diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in index a4b62da1f742..c27f905bfa8c 100755 --- a/contrib/dracut/90zfs/module-setup.sh.in +++ b/contrib/dracut/90zfs/module-setup.sh.in @@ -69,8 +69,8 @@ install() { dracut_install @mounthelperdir@/mount.zfs dracut_install @udevdir@/vdev_id dracut_install awk - dracut_install basename dracut_install cut + dracut_install tr dracut_install head dracut_install @udevdir@/zvol_id inst_hook cmdline 95 "${moddir}/parse-zfs.sh" diff --git a/contrib/dracut/90zfs/parse-zfs.sh.in b/contrib/dracut/90zfs/parse-zfs.sh.in index fe786a880699..0f92f5c80cce 100755 --- a/contrib/dracut/90zfs/parse-zfs.sh.in +++ b/contrib/dracut/90zfs/parse-zfs.sh.in @@ -43,7 +43,7 @@ case "${root}" in root="${root#FILESYSTEM=}" root="zfs:${root#ZFS=}" # switch + with spaces because kernel cmdline does not allow us to quote parameters - root=$(printf '%s\n' "$root" | sed "s/+/ /g") + root=$(echo "$root" | tr '+' ' ') rootok=1 wait_for_zfs=1 diff --git a/contrib/dracut/90zfs/zfs-generator.sh.in b/contrib/dracut/90zfs/zfs-generator.sh.in index b57c64c688b1..e50b9530c4f0 100755 --- a/contrib/dracut/90zfs/zfs-generator.sh.in +++ b/contrib/dracut/90zfs/zfs-generator.sh.in @@ -89,7 +89,7 @@ else _zfs_generator_cb() { dset="${1}" mpnt="${2}" - unit="sysroot$(echo "$mpnt" | sed 's;/;-;g').mount" + unit="sysroot$(echo "$mpnt" | tr '/' '-').mount" { echo "[Unit]" diff --git a/contrib/initramfs/scripts/zfs b/contrib/initramfs/scripts/zfs index 35502291e6f2..ad20eeb4948e 100644 --- a/contrib/initramfs/scripts/zfs +++ b/contrib/initramfs/scripts/zfs @@ -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@.*: @@' | \ tr '\n' ';') echo "${pools%%;}" # Return without the last ';'. @@ -428,7 +427,7 @@ decrypt_fs() else # Temporarily setting "printk" to "7" allows the prompt to appear even when the "quiet" kernel option has been used echo "load-key" > /run/zfs_console_askpwd_cmd - storeprintk="$(awk '{print $1}' /proc/sys/kernel/printk)" + read -r storeprintk _ < /proc/sys/kernel/printk echo 7 > /proc/sys/kernel/printk $ZFS load-key "${ENCRYPTIONROOT}" echo "$storeprintk" > /proc/sys/kernel/printk diff --git a/etc/init.d/zfs-import.in b/etc/init.d/zfs-import.in index e4bc7b8339fc..130174f74d06 100755 --- a/etc/init.d/zfs-import.in +++ b/etc/init.d/zfs-import.in @@ -57,8 +57,7 @@ find_pools() local pools pools=$("$@" 2> /dev/null | \ - grep -E "pool:|^[a-zA-Z0-9]" | \ - sed 's@.*: @@' | \ + sed -Ee '/pool:|^[a-zA-Z0-9]/!d' -e 's@.*: @@' | \ sort | \ tr '\n' ';') diff --git a/etc/zfs/zfs-functions.in b/etc/zfs/zfs-functions.in index 2fb065afdb9a..a27d4c6cb073 100644 --- a/etc/zfs/zfs-functions.in +++ b/etc/zfs/zfs-functions.in @@ -345,7 +345,7 @@ read_mtab() # Unset all MTAB_* variables # shellcheck disable=SC2046 - unset $(env | grep ^MTAB_ | sed 's,=.*,,') + unset $(env | sed -e '/^MTAB_/!d' -e 's,=.*,,') while read -r fs mntpnt fstype opts rest; do if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then @@ -360,9 +360,8 @@ read_mtab() fs=$(/bin/echo "$fs" | sed 's,\\0,\\00,') # Remove 'unwanted' characters. - mntpnt=$(printf '%b\n' "$mntpnt" | sed -e 's,/,,g' \ - -e 's,-,,g' -e 's,\.,,g' -e 's, ,,g') - fs=$(printf '%b\n' "$fs") + mntpnt=$(printf '%b' "$mntpnt" | tr -d '/. -') + fs=$(printf '%b' "$fs") # Set the variable. eval export "MTAB_$mntpnt=\"$fs\"" @@ -374,8 +373,7 @@ in_mtab() { local mntpnt="$1" # Remove 'unwanted' characters. - mntpnt=$(printf '%b\n' "$mntpnt" | sed -e 's,/,,g' \ - -e 's,-,,g' -e 's,\.,,g' -e 's, ,,g') + mntpnt=$(printf '%b' "$mntpnt" | tr -d '/. -') local var var="$(eval echo "MTAB_$mntpnt")" @@ -391,7 +389,7 @@ read_fstab() # Unset all FSTAB_* variables # shellcheck disable=SC2046 - unset $(env | grep ^FSTAB_ | sed 's,=.*,,') + unset $(env | sed -e '/^FSTAB_/!d' -e 's,=.*,,') i=0 while read -r fs mntpnt fstype opts; do @@ -401,7 +399,7 @@ read_fstab() if echo "$fs $mntpnt $fstype $opts" | grep -qE "$match"; then eval export "FSTAB_dev_$i=$fs" - fs=$(printf '%b\n' "$fs" | sed 's,/,_,g') + fs=$(printf '%b' "$fs" | tr '/' '_') eval export "FSTAB_$i=$mntpnt" i=$((i + 1)) diff --git a/rpm/generic/zfs-dkms.spec.in b/rpm/generic/zfs-dkms.spec.in index e0c410c680c2..e0e0efe2a1de 100644 --- a/rpm/generic/zfs-dkms.spec.in +++ b/rpm/generic/zfs-dkms.spec.in @@ -82,7 +82,7 @@ exit 1 # Are we doing an upgrade? if [ "$1" = "1" -o "$1" = "upgrade" ] ; then # Yes we are. Are we upgrading to a new ZFS version? - NEWEST_VER=$(dkms status zfs | sed 's/,//g' | sort -r -V | awk '/installed/{print $2; exit}') + NEWEST_VER=$(dkms status zfs | tr -d , | sort -r -V | awk '/installed/{print $2; exit}') if [ "$NEWEST_VER" != "%{version}" ] ; then # Yes, it's a new ZFS version. We'll uninstall the old module # later on in this script. diff --git a/scripts/kmodtool b/scripts/kmodtool index 26bacf5991d2..b1021596997e 100755 --- a/scripts/kmodtool +++ b/scripts/kmodtool @@ -446,7 +446,7 @@ print_rpmtemplate () myprog_help () { - echo "Usage: $(basename ${0}) [OPTIONS]" + echo "Usage: ${0##*/} [OPTIONS]" echo $'\n'"Creates a template to be used during kmod building" echo $'\n'"Available options:" echo " --filterfile -- filter the results with grep --file " diff --git a/scripts/zfs-tests.sh b/scripts/zfs-tests.sh index ac28788582f9..797d08706338 100755 --- a/scripts/zfs-tests.sh +++ b/scripts/zfs-tests.sh @@ -90,7 +90,7 @@ cleanup_freebsd_loopback() { cleanup_linux_loopback() { for TEST_LOOPBACK in ${LOOPBACKS}; do - LOOP_DEV=$(basename "$TEST_LOOPBACK") + LOOP_DEV="${TEST_LOOPBACK##*/}" DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \ grep "${LOOP_DEV}" | cut -f1) @@ -606,7 +606,7 @@ if [ -z "${DISKS}" ]; then TEST_LOOPBACK=$(sudo "${LOSETUP}" -f) sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" || fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}" - BASELOOPBACK=$(basename "$TEST_LOOPBACK") + BASELOOPBACK="${TEST_LOOPBACK##*/}" DISKS="$DISKS $BASELOOPBACK" LOOPBACKS="$LOOPBACKS $TEST_LOOPBACK" fi diff --git a/scripts/zfs.sh b/scripts/zfs.sh index 7870b8930cab..940c83ffa28f 100755 --- a/scripts/zfs.sh +++ b/scripts/zfs.sh @@ -91,7 +91,8 @@ check_modules_linux() { for KMOD in $KMOD_SPL $KMOD_ZAVL $KMOD_ZNVPAIR $KMOD_ZUNICODE $KMOD_ZCOMMON \ $KMOD_ZLUA $KMOD_ZZSTD $KMOD_ICP $KMOD_ZFS; do - NAME=$(basename "$KMOD" .ko) + NAME="${KMOD##*/}" + NAME="${NAME%.ko}" if lsmod | grep -E -q "^${NAME}"; then LOADED_MODULES="$LOADED_MODULES\t$NAME\n" @@ -172,7 +173,8 @@ load_modules_linux() { unload_module_linux() { KMOD=$1 - NAME=$(basename "$KMOD" .ko) + NAME="${KMOD##*/}" + NAME="${NAME%.ko}" FILE=$(modinfo "$KMOD" | awk '/^filename:/ {print $2}') VERSION=$(modinfo "$KMOD" | awk '/^version:/ {print $2}') @@ -198,8 +200,9 @@ unload_modules_freebsd() { unload_modules_linux() { for KMOD in $KMOD_ZFS $KMOD_ICP $KMOD_ZZSTD $KMOD_ZLUA $KMOD_ZCOMMON \ $KMOD_ZUNICODE $KMOD_ZNVPAIR $KMOD_ZAVL $KMOD_SPL; do - NAME=$(basename "$KMOD" .ko) - USE_COUNT=$(lsmod | grep -E "^${NAME} " | awk '{print $3}') + NAME="${KMOD##*/}" + NAME="${NAME%.ko}" + USE_COUNT=$(lsmod | awk '/^'"${NAME}"'/ {print $3}') if [ "$USE_COUNT" = "0" ] ; then unload_module_linux "$KMOD" || return 1 diff --git a/scripts/zimport.sh b/scripts/zimport.sh index 0e9c01182b8b..03c766cf36c2 100755 --- a/scripts/zimport.sh +++ b/scripts/zimport.sh @@ -486,7 +486,7 @@ for TAG in $POOL_TAGS; do "$POOL_DIR_COPY" || \ fail "Failed to copy $POOL_DIR_PRISTINE to $POOL_DIR_COPY" POOL_NAME=$($ZPOOL_CMD import -d "$POOL_DIR_COPY" | \ - awk '/pool:/ { print $2; exit 0 }') + awk '/pool:/ { print $2; exit }') if ! $ZPOOL_CMD import -N -d "$POOL_DIR_COPY" "$POOL_NAME" &>/dev/null; then diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index ab0cd5270c99..2e6ec7601db3 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -252,7 +252,7 @@ function unmounted function splitline { - echo $1 | sed "s/,/ /g" + echo $1 | tr ',' ' ' } function default_setup @@ -1092,9 +1092,7 @@ function get_endslice # case "$(uname)" in Linux) endcyl=$(parted -s $DEV_DSKDIR/$disk -- unit cyl print | \ - grep "part${slice}" | \ - awk '{print $3}' | \ - sed 's,cyl,,') + awk "/part${slice}/"' {sub(/cyl/, "", $3); print $3}') ((endcyl = (endcyl + 1))) ;; FreeBSD) @@ -1461,7 +1459,7 @@ function is_shared_smb if datasetnonexists "$fs" ; then return 1 else - fs=$(echo $fs | sed 's@/@_@g') + fs=$(echo $fs | tr / _) fi if is_linux; then diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_021_neg.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_021_neg.ksh index c99a82c5db71..07da7e96306e 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_021_neg.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_021_neg.ksh @@ -34,7 +34,7 @@ verify_runnable "both" -fs=$TESTPOOL/$TESTFS/$(basename $0).$$ +fs=$TESTPOOL/$TESTFS/${0##*/}.$$ function cleanup { From c9d62d1356380669a8cd7ca1979d2d38e5e9777f Mon Sep 17 00:00:00 2001 From: George Amanakis Date: Thu, 11 Nov 2021 21:52:16 +0100 Subject: [PATCH 08/12] Introduce a tunable to exclude special class buffers from L2ARC Special allocation class or dedup vdevs may have roughly the same performance as L2ARC vdevs. Introduce a new tunable to exclude those buffers from being cacheable on L2ARC. Reviewed-by: Don Brady Reviewed-by: Brian Behlendorf Signed-off-by: George Amanakis Closes #11761 Closes #12285 --- include/sys/arc.h | 1 + include/sys/dbuf.h | 11 +------ include/sys/dmu_objset.h | 4 --- man/man4/zfs.4 | 5 +++ module/zfs/arc.c | 12 +++++++ module/zfs/dbuf.c | 71 +++++++++++++++++++++++++++++++++++++--- module/zfs/dmu.c | 2 +- module/zfs/dmu_objset.c | 34 +++++++++++++++++-- 8 files changed, 119 insertions(+), 21 deletions(-) diff --git a/include/sys/arc.h b/include/sys/arc.h index afbe65bb1c97..9041939e5b78 100644 --- a/include/sys/arc.h +++ b/include/sys/arc.h @@ -85,6 +85,7 @@ typedef void arc_prune_func_t(int64_t bytes, void *priv); /* Shared module parameters */ extern int zfs_arc_average_blocksize; +extern int l2arc_exclude_special; /* generic arc_done_func_t's which you can use */ arc_read_done_func_t arc_bcopy_func; diff --git a/include/sys/dbuf.h b/include/sys/dbuf.h index 89422659d05a..9017cf345724 100644 --- a/include/sys/dbuf.h +++ b/include/sys/dbuf.h @@ -442,16 +442,7 @@ dbuf_find_dirty_eq(dmu_buf_impl_t *db, uint64_t txg) (dbuf_is_metadata(_db) && \ ((_db)->db_objset->os_primary_cache == ZFS_CACHE_METADATA))) -#define DBUF_IS_L2CACHEABLE(_db) \ - ((_db)->db_objset->os_secondary_cache == ZFS_CACHE_ALL || \ - (dbuf_is_metadata(_db) && \ - ((_db)->db_objset->os_secondary_cache == ZFS_CACHE_METADATA))) - -#define DNODE_LEVEL_IS_L2CACHEABLE(_dn, _level) \ - ((_dn)->dn_objset->os_secondary_cache == ZFS_CACHE_ALL || \ - (((_level) > 0 || \ - DMU_OT_IS_METADATA((_dn)->dn_handle->dnh_dnode->dn_type)) && \ - ((_dn)->dn_objset->os_secondary_cache == ZFS_CACHE_METADATA))) +boolean_t dbuf_is_l2cacheable(dmu_buf_impl_t *db); #ifdef ZFS_DEBUG diff --git a/include/sys/dmu_objset.h b/include/sys/dmu_objset.h index e89ee64ea686..7ade2dc91247 100644 --- a/include/sys/dmu_objset.h +++ b/include/sys/dmu_objset.h @@ -200,10 +200,6 @@ struct objset { #define DMU_GROUPUSED_DNODE(os) ((os)->os_groupused_dnode.dnh_dnode) #define DMU_PROJECTUSED_DNODE(os) ((os)->os_projectused_dnode.dnh_dnode) -#define DMU_OS_IS_L2CACHEABLE(os) \ - ((os)->os_secondary_cache == ZFS_CACHE_ALL || \ - (os)->os_secondary_cache == ZFS_CACHE_METADATA) - /* called from zpl */ int dmu_objset_hold(const char *name, void *tag, objset_t **osp); int dmu_objset_hold_flags(const char *name, boolean_t decrypt, void *tag, diff --git a/man/man4/zfs.4 b/man/man4/zfs.4 index a136690c76e0..9c21688705b8 100644 --- a/man/man4/zfs.4 +++ b/man/man4/zfs.4 @@ -109,6 +109,11 @@ A value of .Sy 100 disables this feature. . +.It Sy l2arc_exclude_special Ns = Ns Sy 0 Ns | Ns 1 Pq int +Controls whether buffers present on special vdevs are eligibile for caching +into L2ARC. +If set to 1, exclude dbufs on special vdevs from being cached to L2ARC. +. .It Sy l2arc_mfuonly Ns = Ns Sy 0 Ns | Ns 1 Pq int Controls whether only MFU metadata and data are cached from ARC into L2ARC. This may be desired to avoid wasting space on L2ARC when reading/writing large diff --git a/module/zfs/arc.c b/module/zfs/arc.c index f0330150f986..79e2d4381830 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -869,6 +869,14 @@ static void l2arc_hdr_arcstats_update(arc_buf_hdr_t *hdr, boolean_t incr, #define l2arc_hdr_arcstats_decrement_state(hdr) \ l2arc_hdr_arcstats_update((hdr), B_FALSE, B_TRUE) +/* + * l2arc_exclude_special : A zfs module parameter that controls whether buffers + * present on special vdevs are eligibile for caching in L2ARC. If + * set to 1, exclude dbufs on special vdevs from being cached to + * L2ARC. + */ +int l2arc_exclude_special = 0; + /* * l2arc_mfuonly : A ZFS module parameter that controls whether only MFU * metadata and data are cached from ARC into L2ARC. @@ -11097,6 +11105,10 @@ ZFS_MODULE_PARAM(zfs_l2arc, l2arc_, rebuild_blocks_min_l2size, ULONG, ZMOD_RW, ZFS_MODULE_PARAM(zfs_l2arc, l2arc_, mfuonly, INT, ZMOD_RW, "Cache only MFU data from ARC into L2ARC"); +ZFS_MODULE_PARAM(zfs_l2arc, l2arc_, exclude_special, INT, ZMOD_RW, + "If set to 1 exclude dbufs on special vdevs from being cached to " + "L2ARC."); + ZFS_MODULE_PARAM_CALL(zfs_arc, zfs_arc_, lotsfree_percent, param_set_arc_int, param_get_int, ZMOD_RW, "System free memory I/O throttle in bytes"); diff --git a/module/zfs/dbuf.c b/module/zfs/dbuf.c index 289247c6ed65..fe54da425286 100644 --- a/module/zfs/dbuf.c +++ b/module/zfs/dbuf.c @@ -53,6 +53,7 @@ #include #include #include +#include kstat_t *dbuf_ksp; @@ -599,6 +600,68 @@ dbuf_is_metadata(dmu_buf_impl_t *db) } } +/* + * We want to exclude buffers that are on a special allocation class from + * L2ARC. + */ +boolean_t +dbuf_is_l2cacheable(dmu_buf_impl_t *db) +{ + vdev_t *vd = NULL; + zfs_cache_type_t cache = db->db_objset->os_secondary_cache; + blkptr_t *bp = db->db_blkptr; + + if (bp != NULL && !BP_IS_HOLE(bp)) { + uint64_t vdev = DVA_GET_VDEV(bp->blk_dva); + vdev_t *rvd = db->db_objset->os_spa->spa_root_vdev; + + if (vdev < rvd->vdev_children) + vd = rvd->vdev_child[vdev]; + + if (cache == ZFS_CACHE_ALL || + (dbuf_is_metadata(db) && cache == ZFS_CACHE_METADATA)) { + if (vd == NULL) + return (B_TRUE); + + if ((vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && + vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) || + l2arc_exclude_special == 0) + return (B_TRUE); + } + } + + return (B_FALSE); +} + +static inline boolean_t +dnode_level_is_l2cacheable(blkptr_t *bp, dnode_t *dn, int64_t level) +{ + vdev_t *vd = NULL; + zfs_cache_type_t cache = dn->dn_objset->os_secondary_cache; + + if (bp != NULL && !BP_IS_HOLE(bp)) { + uint64_t vdev = DVA_GET_VDEV(bp->blk_dva); + vdev_t *rvd = dn->dn_objset->os_spa->spa_root_vdev; + + if (vdev < rvd->vdev_children) + vd = rvd->vdev_child[vdev]; + + if (cache == ZFS_CACHE_ALL || ((level > 0 || + DMU_OT_IS_METADATA(dn->dn_handle->dnh_dnode->dn_type)) && + cache == ZFS_CACHE_METADATA)) { + if (vd == NULL) + return (B_TRUE); + + if ((vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && + vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) || + l2arc_exclude_special == 0) + return (B_TRUE); + } + } + + return (B_FALSE); +} + /* * This function *must* return indices evenly distributed between all @@ -1527,7 +1590,7 @@ dbuf_read_impl(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags, DTRACE_SET_STATE(db, "read issued"); mutex_exit(&db->db_mtx); - if (DBUF_IS_L2CACHEABLE(db)) + if (dbuf_is_l2cacheable(db)) aflags |= ARC_FLAG_L2CACHE; dbuf_add_ref(db, NULL); @@ -3370,7 +3433,7 @@ dbuf_prefetch_impl(dnode_t *dn, int64_t level, uint64_t blkid, dpa->dpa_arg = arg; /* flag if L2ARC eligible, l2arc_noprefetch then decides */ - if (DNODE_LEVEL_IS_L2CACHEABLE(dn, level)) + if (dnode_level_is_l2cacheable(&bp, dn, level)) dpa->dpa_aflags |= ARC_FLAG_L2CACHE; /* @@ -3388,7 +3451,7 @@ dbuf_prefetch_impl(dnode_t *dn, int64_t level, uint64_t blkid, zbookmark_phys_t zb; /* flag if L2ARC eligible, l2arc_noprefetch then decides */ - if (DNODE_LEVEL_IS_L2CACHEABLE(dn, level)) + if (dnode_level_is_l2cacheable(&bp, dn, level)) iter_aflags |= ARC_FLAG_L2CACHE; SET_BOOKMARK(&zb, ds != NULL ? ds->ds_object : DMU_META_OBJSET, @@ -4986,7 +5049,7 @@ dbuf_write(dbuf_dirty_record_t *dr, arc_buf_t *data, dmu_tx_t *tx) children_ready_cb = dbuf_write_children_ready; dr->dr_zio = arc_write(pio, os->os_spa, txg, - &dr->dr_bp_copy, data, DBUF_IS_L2CACHEABLE(db), + &dr->dr_bp_copy, data, dbuf_is_l2cacheable(db), &zp, dbuf_write_ready, children_ready_cb, dbuf_write_physdone, dbuf_write_done, db, ZIO_PRIORITY_ASYNC_WRITE, diff --git a/module/zfs/dmu.c b/module/zfs/dmu.c index f12c5eda8b59..eee3e70bbc95 100644 --- a/module/zfs/dmu.c +++ b/module/zfs/dmu.c @@ -1839,7 +1839,7 @@ dmu_sync(zio_t *pio, uint64_t txg, dmu_sync_cb_t *done, zgd_t *zgd) dsa->dsa_tx = NULL; zio_nowait(arc_write(pio, os->os_spa, txg, - zgd->zgd_bp, dr->dt.dl.dr_data, DBUF_IS_L2CACHEABLE(db), + zgd->zgd_bp, dr->dt.dl.dr_data, dbuf_is_l2cacheable(db), &zp, dmu_sync_ready, NULL, NULL, dmu_sync_done, dsa, ZIO_PRIORITY_SYNC_WRITE, ZIO_FLAG_CANFAIL, &zb)); diff --git a/module/zfs/dmu_objset.c b/module/zfs/dmu_objset.c index af107fb8ad63..b30a9d619034 100644 --- a/module/zfs/dmu_objset.c +++ b/module/zfs/dmu_objset.c @@ -63,6 +63,8 @@ #include #include #include "zfs_namecheck.h" +#include +#include /* * Needed to close a window in dnode_move() that allows the objset to be freed @@ -411,6 +413,34 @@ dnode_multilist_index_func(multilist_t *ml, void *obj) multilist_get_num_sublists(ml)); } +static inline boolean_t +dmu_os_is_l2cacheable(objset_t *os) +{ + vdev_t *vd = NULL; + zfs_cache_type_t cache = os->os_secondary_cache; + blkptr_t *bp = os->os_rootbp; + + if (bp != NULL && !BP_IS_HOLE(bp)) { + uint64_t vdev = DVA_GET_VDEV(bp->blk_dva); + vdev_t *rvd = os->os_spa->spa_root_vdev; + + if (vdev < rvd->vdev_children) + vd = rvd->vdev_child[vdev]; + + if (cache == ZFS_CACHE_ALL || cache == ZFS_CACHE_METADATA) { + if (vd == NULL) + return (B_TRUE); + + if ((vd->vdev_alloc_bias != VDEV_BIAS_SPECIAL && + vd->vdev_alloc_bias != VDEV_BIAS_DEDUP) || + l2arc_exclude_special == 0) + return (B_TRUE); + } + } + + return (B_FALSE); +} + /* * Instantiates the objset_t in-memory structure corresponding to the * objset_phys_t that's pointed to by the specified blkptr_t. @@ -453,7 +483,7 @@ dmu_objset_open_impl(spa_t *spa, dsl_dataset_t *ds, blkptr_t *bp, SET_BOOKMARK(&zb, ds ? ds->ds_object : DMU_META_OBJSET, ZB_ROOT_OBJECT, ZB_ROOT_LEVEL, ZB_ROOT_BLKID); - if (DMU_OS_IS_L2CACHEABLE(os)) + if (dmu_os_is_l2cacheable(os)) aflags |= ARC_FLAG_L2CACHE; if (ds != NULL && ds->ds_dir->dd_crypto_obj != 0) { @@ -1663,7 +1693,7 @@ dmu_objset_sync(objset_t *os, zio_t *pio, dmu_tx_t *tx) } zio = arc_write(pio, os->os_spa, tx->tx_txg, - blkptr_copy, os->os_phys_buf, DMU_OS_IS_L2CACHEABLE(os), + blkptr_copy, os->os_phys_buf, dmu_os_is_l2cacheable(os), &zp, dmu_objset_write_ready, NULL, NULL, dmu_objset_write_done, os, ZIO_PRIORITY_ASYNC_WRITE, ZIO_FLAG_MUSTSUCCEED, &zb); From ac32854a6eef468441ad5c46100af38bc101e088 Mon Sep 17 00:00:00 2001 From: Pawel Jakub Dawidek Date: Fri, 12 Nov 2021 17:06:44 -0800 Subject: [PATCH 09/12] Remove (now unused) td argument from zfs_lookup() Reviewed-by: Brian Behlendorf Reviewed-by: Ryan Moeller Signed-off-by: Pawel Jakub Dawidek Closes #12748 --- module/os/freebsd/zfs/zfs_vnops_os.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/module/os/freebsd/zfs/zfs_vnops_os.c b/module/os/freebsd/zfs/zfs_vnops_os.c index 6f63fb9db5bf..2886eef0a2c5 100644 --- a/module/os/freebsd/zfs/zfs_vnops_os.c +++ b/module/os/freebsd/zfs/zfs_vnops_os.c @@ -761,8 +761,8 @@ zfs_lookup_lock(vnode_t *dvp, vnode_t *vp, const char *name, int lkflags) /* ARGSUSED */ static int zfs_lookup(vnode_t *dvp, const char *nm, vnode_t **vpp, - struct componentname *cnp, int nameiop, cred_t *cr, kthread_t *td, - int flags, boolean_t cached) + struct componentname *cnp, int nameiop, cred_t *cr, int flags, + boolean_t cached) { znode_t *zdp = VTOZ(dvp); znode_t *zp; @@ -1337,8 +1337,8 @@ zfs_lookup_internal(znode_t *dzp, const char *name, vnode_t **vpp, a.a_cnp = cnp; error = vfs_cache_lookup(&a); } else { - error = zfs_lookup(ZTOV(dzp), name, vpp, cnp, nameiop, kcred, - curthread, 0, B_FALSE); + error = zfs_lookup(ZTOV(dzp), name, vpp, cnp, nameiop, kcred, 0, + B_FALSE); } #ifdef ZFS_DEBUG if (error) { @@ -4582,7 +4582,7 @@ zfs_freebsd_lookup(struct vop_lookup_args *ap, boolean_t cached) strlcpy(nm, cnp->cn_nameptr, MIN(cnp->cn_namelen + 1, sizeof (nm))); return (zfs_lookup(ap->a_dvp, nm, ap->a_vpp, cnp, cnp->cn_nameiop, - cnp->cn_cred, curthread, 0, cached)); + cnp->cn_cred, 0, cached)); } static int @@ -5339,7 +5339,7 @@ zfs_getextattr_dir(struct vop_getextattr_args *ap, const char *attrname) vnode_t *xvp = NULL, *vp; int error, flags; - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, + error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, LOOKUP_XATTR, B_FALSE); if (error != 0) return (error); @@ -5450,18 +5450,17 @@ struct vop_deleteextattr { static int zfs_deleteextattr_dir(struct vop_deleteextattr_args *ap, const char *attrname) { - struct thread *td = ap->a_td; struct nameidata nd; vnode_t *xvp = NULL, *vp; int error; - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, + error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, LOOKUP_XATTR, B_FALSE); if (error != 0) return (error); NDINIT_ATVP(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF, - UIO_SYSSPACE, attrname, xvp, td); + UIO_SYSSPACE, attrname, xvp, ap->a_td); error = namei(&nd); vp = nd.ni_vp; if (error != 0) { @@ -5583,7 +5582,7 @@ zfs_setextattr_dir(struct vop_setextattr_args *ap, const char *attrname) vnode_t *xvp = NULL, *vp; int error, flags; - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, + error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, LOOKUP_XATTR | CREATE_XATTR_DIR, B_FALSE); if (error != 0) return (error); @@ -5732,7 +5731,7 @@ zfs_listextattr_dir(struct vop_listextattr_args *ap, const char *attrprefix) vnode_t *xvp = NULL, *vp; int error, eof; - error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, td, + error = zfs_lookup(ap->a_vp, NULL, &xvp, NULL, 0, ap->a_cred, LOOKUP_XATTR, B_FALSE); if (error != 0) { /* From 8ac58c3f567a87cc9b69d89cd18754b5dcf20cfc Mon Sep 17 00:00:00 2001 From: Damian Szuberski <30863496+szubersk@users.noreply.github.com> Date: Sat, 13 Nov 2021 16:02:50 +0100 Subject: [PATCH 10/12] Fix `zfs:AUTO` autodetection in initramfs scripts Don't exit early in find_rootfs() when zpool.bootfs is set to `zfs:AUTO`. Reviewed-by: Richard Laager Reviewed-by: Tony Nguyen Signed-off-by: szubersk Closes #12658 --- contrib/initramfs/scripts/zfs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/initramfs/scripts/zfs b/contrib/initramfs/scripts/zfs index ad20eeb4948e..ccb42ce103b9 100644 --- a/contrib/initramfs/scripts/zfs +++ b/contrib/initramfs/scripts/zfs @@ -79,7 +79,9 @@ find_rootfs() # If it's already specified, just keep it mounted and exit # User (kernel command line) must be correct. - [ -n "${ZFS_BOOTFS}" ] && return 0 + if [ -n "${ZFS_BOOTFS}" ] && [ "${ZFS_BOOTFS}" != "zfs:AUTO" ]; then + return 0 + fi # Not set, try to find it in the 'bootfs' property of the pool. # NOTE: zpool does not support 'get -H -ovalue bootfs'... @@ -756,7 +758,7 @@ mountroot() # rpool=rpool (default if none of the above is used) # root=/ (uses this for rpool - first part) # root=ZFS=/ (uses this for rpool - first part, without 'ZFS=') - # root=zfs:AUTO (tries to detect both pool and rootfs + # root=zfs:AUTO (tries to detect both pool and rootfs) # root=zfs:/ (uses this for rpool - first part, without 'zfs:') # # Option could also be From b8dcfb2c9ff35fabcfe9dffa58278c7e14b18088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Matu=C5=A1ka?= Date: Mon, 15 Nov 2021 17:07:39 +0100 Subject: [PATCH 11/12] FreeBSD: fix world build after de198f2d9 The inline function vn_flush_cached_data() in vnode.h must not be compiled when building BASE. Reviewed-by: Brian Behlendorf Reviewed-by: Ryan Moeller Reviewed-by: Allan Jude Signed-off-by: Martin Matuska Closes #12743 --- include/os/freebsd/spl/sys/vnode.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/os/freebsd/spl/sys/vnode.h b/include/os/freebsd/spl/sys/vnode.h index 3bc8a18eeb72..1ac595aa15dd 100644 --- a/include/os/freebsd/spl/sys/vnode.h +++ b/include/os/freebsd/spl/sys/vnode.h @@ -86,6 +86,7 @@ vn_is_readonly(vnode_t *vp) ((vp)->v_object != NULL && \ (vp)->v_object->resident_page_count > 0) +#ifndef IN_BASE static __inline void vn_flush_cached_data(vnode_t *vp, boolean_t sync) { @@ -100,6 +101,7 @@ vn_flush_cached_data(vnode_t *vp, boolean_t sync) zfs_vmobject_wunlock(vp->v_object); } } +#endif #define vn_exists(vp) do { } while (0) #define vn_invalid(vp) do { } while (0) From 269b5dadcfd1d5732cf763dddcd46009a332eae4 Mon Sep 17 00:00:00 2001 From: Rich Ercolani <214141+rincebrain@users.noreply.github.com> Date: Tue, 16 Nov 2021 14:40:10 -0500 Subject: [PATCH 12/12] Enable edonr in FreeBSD The code is integrated, builds fine, runs fine, there's not really any reason not to. Reviewed-by: Brian Behlendorf Reviewed-by: Ryan Moeller Reviewed-by: Allan Jude Reviewed-by: Tony Nguyen Signed-off-by: Rich Ercolani Closes #12735 --- include/sys/zio.h | 2 -- man/man7/zfsprops.7 | 4 ---- man/man7/zpool-features.7 | 4 ---- module/Makefile.bsd | 6 ++++++ module/zcommon/zfeature_common.c | 8 ++------ module/zcommon/zfs_prop.c | 14 -------------- module/zfs/zio_checksum.c | 4 ---- tests/runfiles/common.run | 2 +- tests/runfiles/linux.run | 4 ---- .../tests/functional/checksum/Makefile.am | 4 +--- .../tests/functional/checksum/default.cfg | 5 +---- .../cli_root/zfs_set/checksum_001_pos.ksh | 5 +---- .../functional/cli_root/zpool_get/zpool_get.cfg | 9 ++------- 13 files changed, 14 insertions(+), 57 deletions(-) diff --git a/include/sys/zio.h b/include/sys/zio.h index b3589e9b0312..121b58dea58e 100644 --- a/include/sys/zio.h +++ b/include/sys/zio.h @@ -88,9 +88,7 @@ enum zio_checksum { ZIO_CHECKSUM_NOPARITY, ZIO_CHECKSUM_SHA512, ZIO_CHECKSUM_SKEIN, -#if !defined(__FreeBSD__) ZIO_CHECKSUM_EDONR, -#endif ZIO_CHECKSUM_FUNCTIONS }; diff --git a/man/man7/zfsprops.7 b/man/man7/zfsprops.7 index 78721f2df9fa..55bcde3dca41 100644 --- a/man/man7/zfsprops.7 +++ b/man/man7/zfsprops.7 @@ -771,10 +771,6 @@ The and .Sy edonr checksum algorithms require enabling the appropriate features on the pool. -.Fx -does not support the -.Sy edonr -algorithm. .Pp Please see .Xr zpool-features 7 diff --git a/man/man7/zpool-features.7 b/man/man7/zpool-features.7 index 83ca91175370..d10ca7f441f6 100644 --- a/man/man7/zpool-features.7 +++ b/man/man7/zpool-features.7 @@ -436,10 +436,6 @@ in ZFS, which means that the checksum is pre-seeded with a secret to be checksummed. Thus the produced checksums are unique to a given pool, preventing hash collision attacks on systems with dedup. -.Pp -.checksum-spiel edonr -.Pp -.Fx does not support the Sy edonr No feature. . .feature com.delphix embedded_data no This feature improves the performance and compression ratio of diff --git a/module/Makefile.bsd b/module/Makefile.bsd index 8aa4ed22275e..63aacb04b35b 100644 --- a/module/Makefile.bsd +++ b/module/Makefile.bsd @@ -12,6 +12,7 @@ KMOD= openzfs .PATH: ${SRCDIR}/avl \ ${SRCDIR}/lua \ ${SRCDIR}/nvpair \ + ${SRCDIR}/icp/algs/edonr \ ${SRCDIR}/os/freebsd/spl \ ${SRCDIR}/os/freebsd/zfs \ ${SRCDIR}/unicode \ @@ -73,6 +74,9 @@ SRCS= vnode_if.h device_if.h bus_if.h # avl SRCS+= avl.c +# icp +SRCS+= edonr.c + #lua SRCS+= lapi.c \ lauxlib.c \ @@ -219,6 +223,7 @@ SRCS+= abd.c \ dsl_scan.c \ dsl_synctask.c \ dsl_userhold.c \ + edonr_zfs.c \ fm.c \ gzip.c \ lzjb.c \ @@ -345,6 +350,7 @@ CFLAGS.dmu_traverse.c= -Wno-cast-qual CFLAGS.dsl_dir.c= -Wno-cast-qual CFLAGS.dsl_deadlist.c= -Wno-cast-qual CFLAGS.dsl_prop.c= -Wno-cast-qual +CFLAGS.edonr.c=-Wno-cast-qual CFLAGS.fm.c= -Wno-cast-qual CFLAGS.lz4.c= -Wno-cast-qual CFLAGS.spa.c= -Wno-cast-qual diff --git a/module/zcommon/zfeature_common.c b/module/zcommon/zfeature_common.c index fc0e09605eef..da7454c118d7 100644 --- a/module/zcommon/zfeature_common.c +++ b/module/zcommon/zfeature_common.c @@ -227,12 +227,8 @@ zfs_mod_supported_feature(const char *name) * tree, but this has not been done yet. Therefore, we return * that all features except edonr are supported. */ -#if defined(__FreeBSD__) - if (strcmp(name, "org.illumos:edonr") == 0) - return (B_FALSE); - else - return (B_TRUE); -#elif defined(_KERNEL) || defined(LIB_ZPOOL_BUILD) + +#if defined(_KERNEL) || defined(LIB_ZPOOL_BUILD) || defined(__FreeBSD__) return (B_TRUE); #else return (zfs_mod_supported(ZFS_SYSFS_POOL_FEATURES, name)); diff --git a/module/zcommon/zfs_prop.c b/module/zcommon/zfs_prop.c index d17321990809..260bf185a3f8 100644 --- a/module/zcommon/zfs_prop.c +++ b/module/zcommon/zfs_prop.c @@ -83,10 +83,7 @@ zfs_prop_init(void) { "noparity", ZIO_CHECKSUM_NOPARITY }, { "sha512", ZIO_CHECKSUM_SHA512 }, { "skein", ZIO_CHECKSUM_SKEIN }, -#if !defined(__FreeBSD__) - { "edonr", ZIO_CHECKSUM_EDONR }, -#endif { NULL } }; @@ -103,11 +100,8 @@ zfs_prop_init(void) { "skein", ZIO_CHECKSUM_SKEIN }, { "skein,verify", ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY }, -#if !defined(__FreeBSD__) - { "edonr,verify", ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY }, -#endif { NULL } }; @@ -396,21 +390,13 @@ zfs_prop_init(void) zprop_register_index(ZFS_PROP_CHECKSUM, "checksum", ZIO_CHECKSUM_DEFAULT, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, -#if !defined(__FreeBSD__) "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein" " | edonr", -#else - "on | off | fletcher2 | fletcher4 | sha256 | sha512 | skein", -#endif "CHECKSUM", checksum_table); zprop_register_index(ZFS_PROP_DEDUP, "dedup", ZIO_CHECKSUM_OFF, PROP_INHERIT, ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME, "on | off | verify | sha256[,verify] | sha512[,verify] | " -#if !defined(__FreeBSD__) "skein[,verify] | edonr,verify", -#else - "skein[,verify]", -#endif "DEDUP", dedup_table); zprop_register_index(ZFS_PROP_COMPRESSION, "compression", ZIO_COMPRESS_DEFAULT, PROP_INHERIT, diff --git a/module/zfs/zio_checksum.c b/module/zfs/zio_checksum.c index f8fee78c6068..e6b5c9588939 100644 --- a/module/zfs/zio_checksum.c +++ b/module/zfs/zio_checksum.c @@ -191,12 +191,10 @@ zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = { abd_checksum_skein_tmpl_init, abd_checksum_skein_tmpl_free, ZCHECKSUM_FLAG_METADATA | ZCHECKSUM_FLAG_DEDUP | ZCHECKSUM_FLAG_SALTED | ZCHECKSUM_FLAG_NOPWRITE, "skein"}, -#if !defined(__FreeBSD__) {{abd_checksum_edonr_native, abd_checksum_edonr_byteswap}, abd_checksum_edonr_tmpl_init, abd_checksum_edonr_tmpl_free, ZCHECKSUM_FLAG_METADATA | ZCHECKSUM_FLAG_SALTED | ZCHECKSUM_FLAG_NOPWRITE, "edonr"}, -#endif }; /* @@ -213,10 +211,8 @@ zio_checksum_to_feature(enum zio_checksum cksum) return (SPA_FEATURE_SHA512); case ZIO_CHECKSUM_SKEIN: return (SPA_FEATURE_SKEIN); -#if !defined(__FreeBSD__) case ZIO_CHECKSUM_EDONR: return (SPA_FEATURE_EDONR); -#endif default: return (SPA_FEATURE_NONE); } diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index 980e25958f7f..89cd58c2aa32 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -109,7 +109,7 @@ tests = ['tst.destroy_fs', 'tst.destroy_snap', 'tst.get_count_and_limit', tags = ['functional', 'channel_program', 'synctask_core'] [tests/functional/checksum] -tests = ['run_sha2_test', 'run_skein_test', 'filetest_001_pos', +tests = ['run_edonr_test', 'run_sha2_test', 'run_skein_test', 'filetest_001_pos', 'filetest_002_pos'] tags = ['functional', 'checksum'] diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 01e1f79e5852..eab9c5dc7743 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -38,10 +38,6 @@ tags = ['functional', 'atime'] tests = ['chattr_001_pos', 'chattr_002_neg'] tags = ['functional', 'chattr'] -[tests/functional/checksum:Linux] -tests = ['run_edonr_test'] -tags = ['functional', 'checksum'] - [tests/functional/cli_root/zfs:Linux] tests = ['zfs_003_neg'] tags = ['functional', 'cli_root', 'zfs'] diff --git a/tests/zfs-tests/tests/functional/checksum/Makefile.am b/tests/zfs-tests/tests/functional/checksum/Makefile.am index ddabc0302010..717098aa0723 100644 --- a/tests/zfs-tests/tests/functional/checksum/Makefile.am +++ b/tests/zfs-tests/tests/functional/checksum/Makefile.am @@ -21,13 +21,11 @@ dist_pkgdata_DATA = \ pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/checksum pkgexec_PROGRAMS = \ + edonr_test \ skein_test \ sha2_test skein_test_SOURCES = skein_test.c sha2_test_SOURCES = sha2_test.c -if BUILD_LINUX -pkgexec_PROGRAMS += edonr_test edonr_test_SOURCES = edonr_test.c -endif diff --git a/tests/zfs-tests/tests/functional/checksum/default.cfg b/tests/zfs-tests/tests/functional/checksum/default.cfg index bc2f6e261b73..afb956093d8a 100644 --- a/tests/zfs-tests/tests/functional/checksum/default.cfg +++ b/tests/zfs-tests/tests/functional/checksum/default.cfg @@ -30,7 +30,4 @@ . $STF_SUITE/include/libtest.shlib -set -A CHECKSUM_TYPES "fletcher2" "fletcher4" "sha256" "sha512" "skein" -if ! is_freebsd; then - CHECKSUM_TYPES+=("edonr") -fi +set -A CHECKSUM_TYPES "fletcher2" "fletcher4" "sha256" "sha512" "skein" "edonr" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh index f30d0052240e..27003b21b556 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh @@ -46,10 +46,7 @@ verify_runnable "both" set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL" -set -A values "on" "off" "fletcher2" "fletcher4" "sha256" "sha512" "skein" "noparity" -if is_linux; then - values+=("edonr") -fi +set -A values "on" "off" "fletcher2" "fletcher4" "sha256" "sha512" "skein" "edonr" "noparity" log_assert "Setting a valid checksum on a file system, volume," \ "it should be successful." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg index 6075e1f1abbd..accbf69cf9c8 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg @@ -72,6 +72,7 @@ typeset -a properties=( "feature@large_blocks" "feature@sha512" "feature@skein" + "feature@edonr" "feature@device_removal" "feature@obsolete_counts" "feature@zpool_checkpoint" @@ -97,10 +98,4 @@ if is_linux || is_freebsd; then "feature@livelist" "feature@zstd_compress" ) -fi - -if ! is_freebsd; then - properties+=( - "feature@edonr" - ) -fi +fi \ No newline at end of file