d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER START
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# This file and its contents are supplied under the terms of the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Common Development and Distribution License ("CDDL"), version 1.0.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# You may only use this file in accordance with the terms of version
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 1.0 of the CDDL.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# A full copy of the text of the CDDL should have accompanied this
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# source. A copy of the CDDL is also available via the Internet at
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER END
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Verify 'zfs list -t all -o name,origin,clones' prints the correct
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# clone information
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 1. Create datasets
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 2. Create recursive snapshots and their clones
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 3. Verify zfs clones property displays right information for different
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy typeset -i i=1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs destroy -rf $ds/$TESTCLONE.$i
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy datasetexists $ds && log_must zfs destroy -Rf $ds
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Set up filesystem with clones
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy typeset -i i=1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy datasetexists $ds || log_fail "Create $ds dataset fail."
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs snapshot -r $TESTPOOL/$TESTFS1@snap
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs clone $ds@snap $fs/$TESTCLONE.$i
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Verify clone list
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy typeset -i i=1
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ -n $clone_snap ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy snapshot=$(echo "$names" | grep $ds$clone_snap@snap)
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy actual_clone=$(zfs list -t all -o clones $snapshot | tail -1)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_fail "$snapshot has unexpected number of clones" \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $unexpected -eq 1 ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $fs == $ds ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ -z $clone_snap ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy [[ $match == $expected_clone ]] && exit 0; \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedydatasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_note "Verify zfs clone propery for multiple clones"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedynames=$(zfs list -rt all -o name $TESTPOOL)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_note "verfify clone property for clone deletion"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedynames=$(zfs list -rt all -o name $TESTPOOL)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_note "verify zfs deferred destroy on clones property"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedynames=$(zfs list -rt all -o name $TESTPOOL)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy deferred_snaps=( "${deferred_snaps[@]}" "$ds@snap" )
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_note "verify zfs deferred destroy by destroying clones on clones property"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy d_clones=( "${d_clones[@]}" "$fs/$TESTCLONE.$i" )
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_fail "$snap exist after deferred destroy"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_fail "$dclone exist after deferred destroy"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_note "verify clone property for zfs promote"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedynames=$(zfs list -rt all -o name,clones $TESTPOOL)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_note "verify clone list truncated correctly"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedytypeset -i j=200
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs clone $fs@snap $fs/$TESTCLONE$(python -c 'print "x" * 200').$i
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedychar_count=$(echo "$clone_list" | tail -1 | wc | awk '{print $3}')
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_fail "Clone list not truncated correctly. Unexpected character count" \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_pass "'zfs list -o name,origin,clones prints the correct clone information."