]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Fix ASSERT in zfs_receive_one()
authorLOLi <loli10K@users.noreply.github.com>
Tue, 4 Dec 2018 17:38:55 +0000 (18:38 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 4 Dec 2018 17:38:55 +0000 (09:38 -0800)
This commit fixes the following ASSERT in zfs_receive_one() when
receiving a send stream from a root dataset with the "-e" option:

    $ sudo zfs snap source@snap
    $ sudo zfs send source@snap | sudo zfs recv -e destination/recv
    chopprefix > drrb->drr_toname
    ASSERT at libzfs_sendrecv.c:3804:zfs_receive_one()

Reviewed-by: Tom Caputi <tcaputi@datto.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Paul Dagnelie <pcd@delphix.com>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #8121

cmd/zfs/zfs_main.c
lib/libzfs/libzfs_sendrecv.c
tests/runfiles/linux.run
tests/zfs-tests/tests/functional/cli_root/zfs_receive/Makefile.am
tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_-e.ksh [new file with mode: 0755]

index 2b7fe93038b37f44bb7be2ca552ab370cd00846c..6b08bb115e078d6f2cf2be6eb37a9db43b0979a5 100644 (file)
@@ -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"));
index 4a620a9da1579a392564ad7268266f6f4e085d9b..710bc191287a3a7232b5093bb36567bdef78c291 100644 (file)
@@ -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');
 
index 3dd9656f05f35bc4d457b4d44c63d60c4a6fee2e..f33a9164940d29fa16d4f46d81999b415688447d 100644 (file)
@@ -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]
index 2d9f0e5ff5e162591846a09aab852d0e335e276e..bf112a77e6a2adaf9d0cf0a2f722ea56dac7a4f3 100644 (file)
@@ -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 (executable)
index 0000000..0c535b4
--- /dev/null
@@ -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 <ezomori.nozomu@gmail.com>. 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"