diff options
author | loli10K <ezomori.nozomu@gmail.com> | 2018-04-30 20:43:03 +0200 |
---|---|---|
committer | Prakash Surya <prakash.surya@delphix.com> | 2018-05-15 15:59:46 -0700 |
commit | 0b2e8253986c5c761129b58cfdac46d204903de1 (patch) | |
tree | 1a79a021e3f45245ef79ecc5fe001f770e972d89 /usr/src | |
parent | 591e0e133f9980083db5d64ac33a30bcc3382ff7 (diff) | |
download | illumos-joyent-0b2e8253986c5c761129b58cfdac46d204903de1.tar.gz |
9512 zfs remap poolname@snapname coredumps
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: John Wren Kennedy <john.kennedy@delphix.com>
Reviewed by: Sara Hartse <sara.hartse@delphix.com>
Approved by: Matt Ahrens <mahrens@delphix.com>
Diffstat (limited to 'usr/src')
11 files changed, 259 insertions, 2 deletions
diff --git a/usr/src/cmd/zfs/zfs_main.c b/usr/src/cmd/zfs/zfs_main.c index 821248f6bf..6abdaa892b 100644 --- a/usr/src/cmd/zfs/zfs_main.c +++ b/usr/src/cmd/zfs/zfs_main.c @@ -6951,11 +6951,28 @@ zfs_do_diff(int argc, char **argv) return (err != 0); } +/* + * zfs remap <filesystem | volume> + * + * Remap the indirect blocks in the given fileystem or volume. + */ static int zfs_do_remap(int argc, char **argv) { const char *fsname; int err = 0; + int c; + + /* check options */ + while ((c = getopt(argc, argv, "")) != -1) { + switch (c) { + case '?': + (void) fprintf(stderr, + gettext("invalid option '%c'\n"), optopt); + usage(B_FALSE); + } + } + if (argc != 2) { (void) fprintf(stderr, gettext("wrong number of arguments\n")); usage(B_FALSE); diff --git a/usr/src/lib/libzfs/common/libzfs_dataset.c b/usr/src/lib/libzfs/common/libzfs_dataset.c index 556538a440..f91b9ecf6a 100644 --- a/usr/src/lib/libzfs/common/libzfs_dataset.c +++ b/usr/src/lib/libzfs/common/libzfs_dataset.c @@ -3877,12 +3877,24 @@ zfs_remap_indirects(libzfs_handle_t *hdl, const char *fs) char errbuf[1024]; (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN, - "cannot remap filesystem '%s' "), fs); + "cannot remap dataset '%s'"), fs); err = lzc_remap(fs); if (err != 0) { - (void) zfs_standard_error(hdl, err, errbuf); + switch (err) { + case ENOTSUP: + zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, + "pool must be upgraded")); + (void) zfs_error(hdl, EZFS_BADVERSION, errbuf); + break; + case EINVAL: + (void) zfs_error(hdl, EZFS_BADTYPE, errbuf); + break; + default: + (void) zfs_standard_error(hdl, err, errbuf); + break; + } } return (err); diff --git a/usr/src/pkg/manifests/system-test-zfstest.mf b/usr/src/pkg/manifests/system-test-zfstest.mf index 3c779e7e9a..c10c421246 100644 --- a/usr/src/pkg/manifests/system-test-zfstest.mf +++ b/usr/src/pkg/manifests/system-test-zfstest.mf @@ -56,6 +56,7 @@ dir path=opt/zfs-tests/tests/functional/cli_root/zfs_mount dir path=opt/zfs-tests/tests/functional/cli_root/zfs_promote dir path=opt/zfs-tests/tests/functional/cli_root/zfs_property dir path=opt/zfs-tests/tests/functional/cli_root/zfs_receive +dir path=opt/zfs-tests/tests/functional/cli_root/zfs_remap dir path=opt/zfs-tests/tests/functional/cli_root/zfs_rename dir path=opt/zfs-tests/tests/functional/cli_root/zfs_reservation dir path=opt/zfs-tests/tests/functional/cli_root/zfs_rollback @@ -958,6 +959,13 @@ file \ file \ path=opt/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_014_pos \ mode=0555 +file path=opt/zfs-tests/tests/functional/cli_root/zfs_remap/cleanup mode=0555 +file path=opt/zfs-tests/tests/functional/cli_root/zfs_remap/setup mode=0555 +file path=opt/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_cliargs \ + mode=0555 +file \ + path=opt/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_obsolete_counts \ + mode=0555 file path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/cleanup mode=0555 file path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/setup mode=0555 file path=opt/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.cfg \ diff --git a/usr/src/test/zfs-tests/runfiles/delphix.run b/usr/src/test/zfs-tests/runfiles/delphix.run index d977a3a681..b5974f8476 100644 --- a/usr/src/test/zfs-tests/runfiles/delphix.run +++ b/usr/src/test/zfs-tests/runfiles/delphix.run @@ -162,6 +162,9 @@ tests = ['zfs_receive_001_pos', 'zfs_receive_002_pos', 'zfs_receive_003_pos', 'zfs_receive_010_pos', 'zfs_receive_011_pos', 'zfs_receive_012_pos', 'zfs_receive_013_pos', 'zfs_receive_014_pos'] +[/opt/zfs-tests/tests/functional/cli_root/zfs_remap] +tests = ['zfs_remap_cliargs', 'zfs_remap_obsolete_counts'] + [/opt/zfs-tests/tests/functional/cli_root/zfs_rename] tests = ['zfs_rename_001_pos', 'zfs_rename_002_pos', 'zfs_rename_003_pos', 'zfs_rename_004_neg', 'zfs_rename_005_neg', 'zfs_rename_006_pos', diff --git a/usr/src/test/zfs-tests/runfiles/omnios.run b/usr/src/test/zfs-tests/runfiles/omnios.run index ebf446f61a..57a828c86f 100644 --- a/usr/src/test/zfs-tests/runfiles/omnios.run +++ b/usr/src/test/zfs-tests/runfiles/omnios.run @@ -162,6 +162,9 @@ tests = ['zfs_rename_001_pos', 'zfs_rename_002_pos', 'zfs_rename_003_pos', 'zfs_rename_010_neg', 'zfs_rename_011_pos', 'zfs_rename_012_neg', 'zfs_rename_013_pos'] +[/opt/zfs-tests/tests/functional/cli_root/zfs_remap] +tests = ['zfs_remap_cliargs', 'zfs_remap_obsolete_counts'] + [/opt/zfs-tests/tests/functional/cli_root/zfs_reservation] tests = ['zfs_reservation_001_pos', 'zfs_reservation_002_pos'] diff --git a/usr/src/test/zfs-tests/runfiles/openindiana.run b/usr/src/test/zfs-tests/runfiles/openindiana.run index 2d8af0bf69..4cefe8f228 100644 --- a/usr/src/test/zfs-tests/runfiles/openindiana.run +++ b/usr/src/test/zfs-tests/runfiles/openindiana.run @@ -162,6 +162,9 @@ tests = ['zfs_rename_001_pos', 'zfs_rename_002_pos', 'zfs_rename_003_pos', 'zfs_rename_010_neg', 'zfs_rename_011_pos', 'zfs_rename_012_neg', 'zfs_rename_013_pos'] +[/opt/zfs-tests/tests/functional/cli_root/zfs_remap] +tests = ['zfs_remap_cliargs', 'zfs_remap_obsolete_counts'] + [/opt/zfs-tests/tests/functional/cli_root/zfs_reservation] tests = ['zfs_reservation_001_pos', 'zfs_reservation_002_pos'] diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/Makefile b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/Makefile new file mode 100644 index 0000000000..658776d0cd --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/Makefile @@ -0,0 +1,21 @@ +# +# 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) 2012, 2016 by Delphix. All rights reserved. +# + +include $(SRC)/Makefile.master + +ROOTOPTPKG = $(ROOT)/opt/zfs-tests +TARGETDIR = $(ROOTOPTPKG)/tests/functional/cli_root/zfs_remap + +include $(SRC)/test/zfs-tests/Makefile.com diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/cleanup.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/cleanup.ksh new file mode 100644 index 0000000000..e78deacd5b --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/cleanup.ksh @@ -0,0 +1,19 @@ +#!/bin/ksh -p +# +# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +default_cleanup diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/setup.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/setup.ksh new file mode 100644 index 0000000000..4497dbd746 --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/setup.ksh @@ -0,0 +1,17 @@ +#!/bin/ksh -p +# +# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_cliargs.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_cliargs.ksh new file mode 100644 index 0000000000..4e0d2bc442 --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_cliargs.ksh @@ -0,0 +1,78 @@ +#!/bin/ksh -p +# +# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/removal/removal.kshlib + +# +# DESCRIPTION: +# 'zfs remap' should only work with supported parameters. +# +# STRATEGY: +# 1. Prepare a pool where a top-level VDEV has been removed +# 2. Verify every supported parameter to 'zfs remap' is accepted +# 3. Verify other unsupported parameters raise an error +# + +verify_runnable "both" + +function cleanup +{ + destroy_pool $TESTPOOL + rm -f $DISK1 $DISK2 +} + +log_assert "'zfs remap' should only work with supported parameters" +log_onexit cleanup + +f="$TESTPOOL/fs" +v="$TESTPOOL/vol" +s="$TESTPOOL/fs@snap" +b="$TESTPOOL/fs#bmark" +c="$TESTPOOL/clone" + +typeset goodparams=("$f" "$v" "$c") +typeset badparams=("-H" "-p" "-?" "$s" "$b" "$f $f" "$f $v" "$f $s") + +DISK1="/var/tmp/zfs_remap-1" +DISK2="/var/tmp/zfs_remap-2" + +# 1. Prepare a pool where a top-level VDEV has been removed +log_must truncate -s $(($MINVDEVSIZE * 2)) $DISK1 +log_must zpool create $TESTPOOL $DISK1 +log_must zfs create $f +log_must zfs create -V 1M -s $v +log_must zfs snap $s +log_must zfs bookmark $s $b +log_must zfs clone $s $c +log_must truncate -s $(($MINVDEVSIZE * 2)) $DISK2 +log_must zpool add $TESTPOOL $DISK2 +log_must zpool remove $TESTPOOL $DISK1 +log_must wait_for_removal $TESTPOOL + +# 2. Verify every supported parameter to 'zfs remap' is accepted +for param in "${goodparams[@]}" +do + log_must zfs remap $param +done + +# 3. Verify other unsupported parameters raise an error +for param in "${badparams[@]}" +do + log_mustnot zfs remap $param +done + +log_pass "'zfs remap' only works with supported parameters" diff --git a/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_obsolete_counts.ksh b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_obsolete_counts.ksh new file mode 100644 index 0000000000..d8b52b091e --- /dev/null +++ b/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_remap/zfs_remap_obsolete_counts.ksh @@ -0,0 +1,76 @@ +#!/bin/ksh -p +# +# 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 2018, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/removal/removal.kshlib + +# +# DESCRIPTION: +# 'zfs remap' depends on 'feature@obsolete_counts' being active +# +# STRATEGY: +# 1. Prepare a pool where a top-level VDEV has been removed and with +# feature@obsolete_counts disabled +# 2. Verify any 'zfs remap' command cannot be executed +# 3. Verify the same commands complete successfully when +# feature@obsolete_counts is enabled +# + +verify_runnable "both" + +function cleanup +{ + destroy_pool $TESTPOOL + rm -f $DISK1 $DISK2 +} + +log_assert "'zfs remap' depends on feature@obsolete_counts being active" +log_onexit cleanup + +f="$TESTPOOL/fs" +v="$TESTPOOL/vol" +s="$TESTPOOL/fs@snap" +c="$TESTPOOL/clone" + +DISK1="/var/tmp/zfs_remap-1" +DISK2="/var/tmp/zfs_remap-2" + +# 1. Prepare a pool where a top-level VDEV has been removed with +# feature@obsolete_counts disabled +log_must truncate -s $(($MINVDEVSIZE * 2)) $DISK1 +log_must zpool create -d -o feature@device_removal=enabled $TESTPOOL $DISK1 +log_must zfs create $f +log_must zfs create -V 1M -s $v +log_must zfs snap $s +log_must zfs clone $s $c +log_must truncate -s $(($MINVDEVSIZE * 2)) $DISK2 +log_must zpool add $TESTPOOL $DISK2 +log_must zpool remove $TESTPOOL $DISK1 +log_must wait_for_removal $TESTPOOL + +# 2. Verify any 'zfs remap' command cannot be executed +log_mustnot zfs remap $f +log_mustnot zfs remap $v +log_mustnot zfs remap $c + +# 3. Verify the same commands complete successfully when +# feature@obsolete_counts is enabled +log_must zpool set feature@obsolete_counts=enabled $TESTPOOL +log_must zfs remap $f +log_must zfs remap $v +log_must zfs remap $c + +log_pass "'zfs remap' correctly depends on feature@obsolete_counts being active" |