diff options
-rw-r--r-- | cmd/zfs/zfs_main.c | 17 | ||||
-rw-r--r-- | lib/libzfs/libzfs_sendrecv.c | 5 | ||||
-rw-r--r-- | tests/runfiles/linux.run | 2 | ||||
-rw-r--r-- | tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am | 3 | ||||
-rwxr-xr-x | tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_-e.ksh | 106 |
5 files changed, 128 insertions, 5 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 2b7fe9303..6b08bb115 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -4240,10 +4240,21 @@ zfs_do_receive(int argc, char **argv) } break; case 'd': + if (flags.istail) { + (void) fprintf(stderr, gettext("invalid option " + "combination: -d and -e are mutually " + "exclusive\n")); + usage(B_FALSE); + } flags.isprefix = B_TRUE; break; case 'e': - flags.isprefix = B_TRUE; + if (flags.isprefix) { + (void) fprintf(stderr, gettext("invalid option " + "combination: -d and -e are mutually " + "exclusive\n")); + usage(B_FALSE); + } flags.istail = B_TRUE; break; case 'n': @@ -4279,6 +4290,10 @@ zfs_do_receive(int argc, char **argv) argc -= optind; argv += optind; + /* zfs recv -e (use "tail" name) implies -d (remove dataset "head") */ + if (flags.istail) + flags.isprefix = B_TRUE; + /* check number of arguments */ if (argc < 1) { (void) fprintf(stderr, gettext("missing snapshot argument\n")); diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index 4a620a9da..710bc1912 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -3801,8 +3801,9 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, } ASSERT(strstr(drrb->drr_toname, sendfs) == drrb->drr_toname); - ASSERT(chopprefix > drrb->drr_toname); - ASSERT(chopprefix <= drrb->drr_toname + strlen(drrb->drr_toname)); + ASSERT(chopprefix > drrb->drr_toname || strchr(sendfs, '/') == NULL); + ASSERT(chopprefix <= drrb->drr_toname + strlen(drrb->drr_toname) || + strchr(sendfs, '/') == NULL); ASSERT(chopprefix[0] == '/' || chopprefix[0] == '@' || chopprefix[0] == '\0'); diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 3dd9656f0..f33a91649 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -206,7 +206,7 @@ tests = ['zfs_receive_001_pos', 'zfs_receive_002_pos', 'zfs_receive_003_pos', 'zfs_receive_013_pos', 'zfs_receive_014_pos', 'zfs_receive_015_pos', 'receive-o-x_props_override', 'zfs_receive_from_encrypted', 'zfs_receive_to_encrypted', 'zfs_receive_raw', - 'zfs_receive_raw_incremental'] + 'zfs_receive_raw_incremental', 'zfs_receive_-e'] tags = ['functional', 'cli_root', 'zfs_receive'] [tests/functional/cli_root/zfs_remap] diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am index 2d9f0e5ff..bf112a77e 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am @@ -21,4 +21,5 @@ dist_pkgdata_SCRIPTS = \ zfs_receive_from_encrypted.ksh \ zfs_receive_to_encrypted.ksh \ zfs_receive_raw.ksh \ - zfs_receive_raw_incremental.ksh + zfs_receive_raw_incremental.ksh \ + zfs_receive_-e.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_-e.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_-e.ksh new file mode 100755 index 000000000..0c535b469 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_-e.ksh @@ -0,0 +1,106 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# 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. +# +# CDDL HEADER END +# + +# +# Copyright 2018, loli10K <[email protected]>. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +# +# DESCRIPTION: +# ZFS receive '-e' option can be used to discard all but the last element of +# the sent snapshot's file system name +# +# STRATEGY: +# 1. Create a filesystem with children and snapshots +# 2. Verify 'zfs receive -e' rejects invalid options +# 3. Verify 'zfs receive -e' can receive the root dataset +# 4. Verify 'zfs receive -e' can receive a replication stream +# 5. Verify 'zfs receive -e' can receive an incremental replication stream +# + +verify_runnable "both" + +function cleanup +{ + destroy_pool "$poolname" + log_must rm -f "$vdevfile" + log_must rm -f "$streamfile" +} + +log_assert "ZFS receive '-e' option can be used to discard all but the last"\ + "element of the sent snapshot's file system name" +log_onexit cleanup + +poolname="$TESTPOOL-zfsrecv" +recvfs="$poolname/recv" +vdevfile="$TEST_BASE_DIR/vdevfile.$$" +streamfile="$TEST_BASE_DIR/streamfile.$$" + +# +# 1. Create a filesystem with children and snapshots +# NOTE: set "mountpoint=none" just to speed up the test process +# +log_must truncate -s $MINVDEVSIZE "$vdevfile" +log_must zpool create -O mountpoint=none "$poolname" "$vdevfile" +log_must zfs create -p "$poolname/fs/a/b" +log_must zfs create "$recvfs" +log_must zfs snapshot -r "$poolname@full" +log_must zfs snapshot -r "$poolname@incr" + +# +# 2. Verify 'zfs receive -e' rejects invalid options +# +log_must eval "zfs send $poolname/fs@full > $streamfile" +log_mustnot eval "zfs receive -e < $streamfile" +log_mustnot eval "zfs receive -e $recvfs@snap < $streamfile" +log_mustnot eval "zfs receive -e $recvfs/1/2/3 < $streamfile" +log_mustnot eval "zfs receive -A -e $recvfs < $streamfile" +log_mustnot eval "zfs receive -e -d $recvfs < $streamfile" + +# +# 3. 'zfs receive -e' can receive the root dataset +# +recvfs_rootds="$recvfs/rootds" +log_must zfs create "$recvfs_rootds" +log_must eval "zfs send $poolname@full > $streamfile" +log_must eval "zfs receive -e $recvfs_rootds < $streamfile" +log_must datasetexists "$recvfs_rootds/$poolname" +log_must snapexists "$recvfs_rootds/$poolname@full" + +# +# 4. 'zfs receive -e' can receive a replication stream +# +recvfs_fs="$recvfs/fs" +log_must zfs create "$recvfs_fs" +log_must eval "zfs send -R $poolname/fs/a@full > $streamfile" +log_must eval "zfs receive -e $recvfs_fs < $streamfile" +log_must datasetexists "$recvfs_fs/a" +log_must datasetexists "$recvfs_fs/a/b" +log_must snapexists "$recvfs_fs/a@full" +log_must snapexists "$recvfs_fs/a/b@full" + +# +# 5. 'zfs receive -e' can receive an incremental replication stream +# +log_must eval "zfs send -R -i full $poolname/fs/a@incr > $streamfile" +log_must eval "zfs receive -e $recvfs_fs < $streamfile" +log_must snapexists "$recvfs_fs/a@incr" +log_must snapexists "$recvfs_fs/a/b@incr" + +log_pass "ZFS receive '-e' discards all but the last element of the sent"\ + "snapshot's file system name as expected" |