Skip to content

Commit

Permalink
Fixes after rebase and more review
Browse files Browse the repository at this point in the history
Raw send now uses '-w' instead of '-r'
Bug fixes discovered after the rebase uncovered some code paths.

Signed-off-by: Tom Caputi <tcaputi@datto.com>
  • Loading branch information
Tom Caputi authored and lundman committed Jun 13, 2017
1 parent 0cbdbc9 commit 25a3b51
Show file tree
Hide file tree
Showing 23 changed files with 354 additions and 131 deletions.
14 changes: 6 additions & 8 deletions usr/src/cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3737,11 +3737,12 @@ zfs_do_send(int argc, char **argv)
{"embed", no_argument, NULL, 'e'},
{"resume", required_argument, NULL, 't'},
{"compressed", no_argument, NULL, 'c'},
{"raw", no_argument, NULL, 'w'},
{0, 0, 0, 0}
};

/* check options */
while ((c = getopt_long(argc, argv, ":i:I:RbDpvnPLet:cr", long_options,
while ((c = getopt_long(argc, argv, ":i:I:RbDpvnPLet:cw", long_options,
NULL)) != -1) {
switch (c) {
case 'i':
Expand Down Expand Up @@ -3789,8 +3790,11 @@ zfs_do_send(int argc, char **argv)
case 'c':
flags.compress = B_TRUE;
break;
case 'r':
case 'w':
flags.raw = B_TRUE;
flags.compress = B_TRUE;
flags.embed_data = B_TRUE;
flags.largeblock = B_TRUE;
break;
case ':':
/*
Expand Down Expand Up @@ -3860,12 +3864,6 @@ zfs_do_send(int argc, char **argv)
}
}

if (flags.raw && flags.compress) {
(void) fprintf(stderr,
gettext("raw and compress flags are mutually exclusive\n"));
return (1);
}

if (!flags.dryrun && isatty(STDOUT_FILENO)) {
(void) fprintf(stderr,
gettext("Error: Stream can not be written to a terminal.\n"
Expand Down
76 changes: 67 additions & 9 deletions usr/src/cmd/zstreamdump/zstreamdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,31 @@ print_block(char *buf, int length)
}
}

/*
* Print an array of bytes to stdout as hexidecimal characters. str must
* have buf_len * 2 + 1 bytes of space.
*/
static void
sprintf_bytes(char *str, uint8_t *buf, uint_t buf_len)
{
int i, n;

for (i = 0; i < buf_len; i++) {
n = sprintf(str, "%02x", buf[i] & 0xff);
str += n;
}

str[0] = '\0';
}

int
main(int argc, char *argv[])
{
char *buf = safe_malloc(SPA_MAXBLOCKSIZE);
uint64_t drr_record_count[DRR_NUMTYPES] = { 0 };
char salt[ZIO_DATA_SALT_LEN * 2 + 1];
char iv[ZIO_DATA_IV_LEN * 2 + 1];
char mac[ZIO_DATA_MAC_LEN * 2 + 1];
uint64_t total_records = 0;
uint64_t payload_size;
dmu_replay_record_t thedrr;
Expand Down Expand Up @@ -424,14 +444,19 @@ main(int argc, char *argv[])
if (verbose) {
(void) printf("OBJECT object = %llu type = %u "
"bonustype = %u blksz = %u bonuslen = %u "
"raw_bonuslen = %u flags = %u\n",
"raw_bonuslen = %u flags = %u "
"indblkshift = %u nlevels = %u "
"nblkptr = %u\n",
(u_longlong_t)drro->drr_object,
drro->drr_type,
drro->drr_bonustype,
drro->drr_blksz,
drro->drr_bonuslen,
drro->drr_raw_bonuslen,
drro->drr_flags);
drro->drr_flags,
drro->drr_indblkshift,
drro->drr_nlevels,
drro->drr_nblkptr);
}
if (drro->drr_bonuslen > 0) {
(void) ssread(buf, payload_size, &zc);
Expand Down Expand Up @@ -477,13 +502,20 @@ main(int argc, char *argv[])
* print info on the modified block
*/
if (verbose) {
sprintf_bytes(salt, drrw->drr_salt,
ZIO_DATA_SALT_LEN);
sprintf_bytes(iv, drrw->drr_iv,
ZIO_DATA_IV_LEN);
sprintf_bytes(mac, drrw->drr_mac,
ZIO_DATA_MAC_LEN);

(void) printf("WRITE object = %llu type = %u "
"checksum type = %u compression type = %u\n"
" flags = %u offset = %llu "
"logical_size = %llu "
"compressed_size = %llu "
"payload_size = %llu "
"props = %llx\n",
"payload_size = %llu props = %llx "
"salt = %s iv = %s mac = %s\n",
(u_longlong_t)drrw->drr_object,
drrw->drr_type,
drrw->drr_checksumtype,
Expand All @@ -493,7 +525,10 @@ main(int argc, char *argv[])
(u_longlong_t)drrw->drr_logical_size,
(u_longlong_t)drrw->drr_compressed_size,
(u_longlong_t)payload_size,
(u_longlong_t)drrw->drr_key.ddk_prop);
(u_longlong_t)drrw->drr_key.ddk_prop,
salt,
iv,
mac);
}

/*
Expand Down Expand Up @@ -564,12 +599,31 @@ main(int argc, char *argv[])
if (do_byteswap) {
drrs->drr_object = BSWAP_64(drrs->drr_object);
drrs->drr_length = BSWAP_64(drrs->drr_length);
drrs->drr_compressed_size =
BSWAP_64(drrs->drr_compressed_size);
drrs->drr_type = BSWAP_32(drrs->drr_type);
}
if (verbose) {
sprintf_bytes(salt, drrs->drr_salt,
ZIO_DATA_SALT_LEN);
sprintf_bytes(iv, drrs->drr_iv,
ZIO_DATA_IV_LEN);
sprintf_bytes(mac, drrs->drr_mac,
ZIO_DATA_MAC_LEN);

(void) printf("SPILL block for object = %llu "
"length = %llu\n", drrs->drr_object,
drrs->drr_length);
"length = %llu flags = %u "
"compression type = %u "
"compressed_size = %llu "
"salt = %s iv = %s mac = %s\n",
(u_longlong_t)drrs->drr_object,
(u_longlong_t)drrs->drr_length,
drrs->drr_flags,
drrs->drr_compressiontype,
(u_longlong_t)drrs->drr_compressed_size,
salt,
iv,
mac);
}
(void) ssread(buf, drrs->drr_length, &zc);
if (dump) {
Expand Down Expand Up @@ -618,10 +672,14 @@ main(int argc, char *argv[])
}
if (verbose) {
(void) printf("OBJECT_RANGE firstobj = %llu "
"numslots = %llu flags = %u\n",
"numslots = %llu flags = %u "
"salt = %s iv = %s mac = %s\n",
(u_longlong_t)drror->drr_firstobj,
(u_longlong_t)drror->drr_numslots,
drror->drr_flags);
drror->drr_flags,
salt,
iv,
mac);
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion usr/src/lib/libzfs/common/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ typedef struct sendflags {
/* compressed WRITE records are permitted */
boolean_t compress;

/* raw WRITE records are permitted, mutually exclusive with compress */
/* raw encrypted records are permitted */
boolean_t raw;
} sendflags_t;

Expand Down
10 changes: 5 additions & 5 deletions usr/src/lib/libzfs/common/libzfs_sendrecv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3367,7 +3367,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
char *snapname = NULL;
nvlist_t *props = NULL;
char tmp_keylocation[MAXNAMELEN];

begin_time = time(NULL);
bzero(tmp_keylocation, MAXNAMELEN);

Expand Down Expand Up @@ -3397,11 +3397,11 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
* the keylocation for now to avoid any errors from the receive
* ioctl.
*/
err = nvlist_lookup_string(rcvprops,
err = nvlist_lookup_string(props,
zfs_prop_to_name(ZFS_PROP_KEYLOCATION), &keylocation);
if (err == 0) {
strcpy(tmp_keylocation, keylocation);
(void) nvlist_remove_all(rcvprops,
(void) strcpy(tmp_keylocation, keylocation);
(void) nvlist_remove_all(props,
zfs_prop_to_name(ZFS_PROP_KEYLOCATION));
}

Expand Down Expand Up @@ -3984,7 +3984,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap,
}

if (tmp_keylocation[0] != '\0') {
VERIFY(0 == nvlist_add_string(rcvprops,
VERIFY(0 == nvlist_add_string(props,
zfs_prop_to_name(ZFS_PROP_KEYLOCATION), tmp_keylocation));
}

Expand Down
10 changes: 5 additions & 5 deletions usr/src/man/man1m/zfs.1m
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
.Ar snapshot bookmark
.Nm
.Cm send
.Op Fl DLPRcenprv
.Op Fl DLPRcenpvw
.Op Oo Fl I Ns | Ns Fl i Oc Ar snapshot
.Ar snapshot
.Nm
Expand Down Expand Up @@ -2642,7 +2642,7 @@ feature.
.It Xo
.Nm
.Cm send
.Op Fl DLPRcenprv
.Op Fl DLPRcenpvw
.Op Oo Fl I Ns | Ns Fl i Oc Ar snapshot
.Ar snapshot
.Xc
Expand Down Expand Up @@ -2775,7 +2775,7 @@ and the verbose output goes to standard error
Include the dataset's properties in the stream. This flag is implicit when
.Fl R
is specified. The receiving system must also support this feature.
.It Fl r, -raw
.It Fl w, -raw
For encrypted datasets send data exactly as it exists on disk. This allows
backups to be taken even if encryption keys are not currently loaded. The
backup may then be received on an untrusted machine since that machine will
Expand All @@ -2787,7 +2787,7 @@ property will be defaulted to
.Sy prompt
if not otherwise provided. For unencrypted datasets, this flag will be
equivalent to
.Fl c .
.Fl Lec .
Note that if you do not use this flag for sending encrypted datasets,
data will be sent unencrypted and may be re-encrypted with a different
encryption key on the receiving system, which will disable the ability
Expand Down Expand Up @@ -2880,7 +2880,7 @@ property will be defaulted to
.Sy prompt
if not otherwise provided. For unencrypted datasets, this flag will be
equivalent to
.Fl c .
.Fl Lec .
Note that if you do not use this flag for sending encrypted datasets,
data will be sent unencrypted and may be re-encrypted with a different
encryption key on the receiving system, which will disable the ability
Expand Down
7 changes: 5 additions & 2 deletions usr/src/pkg/manifests/system-test-zfstest.mf
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,9 @@ file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos \
mode=0555
file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted \
mode=0555
file \
path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted_unloaded \
mode=0555
file path=opt/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_raw \
mode=0555
file path=opt/zfs-tests/tests/functional/cli_root/zfs_set/cache_001_pos \
Expand Down Expand Up @@ -2193,8 +2196,6 @@ file path=opt/zfs-tests/tests/functional/rsend/rsend_020_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/rsend_021_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/rsend_022_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/rsend_024_pos mode=0555
file path=opt/zfs-tests/tests/functional/rsend/send_encrypted_heirarchy \
mode=0555
file path=opt/zfs-tests/tests/functional/rsend/send-cD mode=0555
file path=opt/zfs-tests/tests/functional/rsend/send-c_embedded_blocks \
mode=0555
Expand All @@ -2216,6 +2217,8 @@ file path=opt/zfs-tests/tests/functional/rsend/send-c_volume mode=0555
file path=opt/zfs-tests/tests/functional/rsend/send-c_zstreamdump mode=0555
file path=opt/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize \
mode=0555
file path=opt/zfs-tests/tests/functional/rsend/send_encrypted_heirarchy \
mode=0555
file path=opt/zfs-tests/tests/functional/rsend/setup mode=0555
file path=opt/zfs-tests/tests/functional/scrub_mirror/cleanup mode=0555
file path=opt/zfs-tests/tests/functional/scrub_mirror/default.cfg mode=0444
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/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 (c) 2017 Datto, Inc. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib

#
# DESCRIPTION:
# ZFS must promote clones of an encryption root.
#
# STRATEGY:
# 1. Create an encrypted dataset
# 2. Clone the encryption root
# 3. Clone the clone
# 4. Verify the encryption root of all three datasets is the origin
# 5. Promote the clone of the clone
# 6. Verify the encryption root of all three datasets is still the origin
# 7. Promote the clone of the original encryption root
# 8. Verify the encryption root of all three datasets is the promoted dataset
#

verify_runnable "both"

function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -Rf $TESTPOOL/$TESTFS1
datasetexists $TESTPOOL/clone1 && \
log_must zfs destroy -Rf $TESTPOOL/clone1
datasetexists $TESTPOOL/clone2 && \
log_must zfs destroy -Rf $TESTPOOL/clone2
}
log_onexit cleanup

log_assert "ZFS must promote clones of an encryption root"

passphrase="password"
snaproot="$TESTPOOL/$TESTFS1@snap1"
snapclone="$TESTPOOL/clone1@snap2"

log_must eval "echo $passphrase | zfs create -o encryption=on" \
"-o keyformat=passphrase $TESTPOOL/$TESTFS1"

log_must zfs snap $snaproot
log_must zfs clone $snaproot $TESTPOOL/clone1
log_must zfs snap $snapclone
log_must zfs clone $snapclone $TESTPOOL/clone2

log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1
log_must verify_encryption_root $TESTPOOL/clone1 $TESTPOOL/$TESTFS1
log_must verify_encryption_root $TESTPOOL/clone2 $TESTPOOL/$TESTFS1

log_must zfs promote $TESTPOOL/clone2
log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1
log_must verify_encryption_root $TESTPOOL/clone1 $TESTPOOL/$TESTFS1
log_must verify_encryption_root $TESTPOOL/clone2 $TESTPOOL/$TESTFS1

log_must zfs promote $TESTPOOL/clone2
log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/clone2
log_must verify_encryption_root $TESTPOOL/clone1 $TESTPOOL/clone2
log_must verify_encryption_root $TESTPOOL/clone2 $TESTPOOL/clone2

log_pass "ZFS promotes clones of an encryption root"
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typeset checksum=$(md5sum /$TESTPOOL/$TESTFS1/$TESTFILE0 | \
log_must zfs snapshot $snap

log_note "Verify ZFS can receive a raw send stream from an encrypted dataset"
log_must eval "zfs send -r $snap | zfs receive $TESTPOOL/$TESTFS2"
log_must eval "zfs send -w $snap | zfs receive $TESTPOOL/$TESTFS2"

keystatus=$(get_prop keystatus $TESTPOOL/$TESTFS2)
[[ "$keystatus" == "unavailable" ]] || \
Expand All @@ -78,7 +78,7 @@ typeset cksum1=$(md5sum /$TESTPOOL/$TESTFS2/$TESTFILE0 | awk '{ print $1 }')
[[ "$cksum1" == "$checksum" ]] || \
log_fail "Checksums differ ($cksum1 != $checksum)"

log_must eval "zfs send -r $snap | zfs receive $TESTPOOL/$TESTFS1/c1"
log_must eval "zfs send -w $snap | zfs receive $TESTPOOL/$TESTFS1/c1"

keystatus=$(get_prop keystatus $TESTPOOL/$TESTFS1/c1)
[[ "$keystatus" == "unavailable" ]] || \
Expand Down
Loading

0 comments on commit 25a3b51

Please sign in to comment.