1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright (c) 2020 by Delphix. All rights reserved. 25# 26 27. $STF_SUITE/include/libtest.shlib 28 29# 30# DESCRIPTION: Identify the objset id and the object id of a file in a 31# filesystem, and verify that zfs_ids_to_path behaves correctly with them. 32# 33# STRATEGY: 34# 1. Create a dataset 35# 2. Makes files in the dataset 36# 3. Verify that zfs_ids_to_path outputs the correct format for each one 37# 38 39verify_runnable "both" 40 41function cleanup 42{ 43 destroy_dataset $TESTPOOL/$TESTFS 44 zfs create -o mountpoint=$TESTDIR $TESTPOOL/$TESTFS 45} 46 47function test_one 48{ 49 typeset ds_id="$1" 50 typeset ds_path="$2" 51 typeset file_path="$3" 52 53 typeset mntpnt=$(get_prop mountpoint $ds_path) 54 typeset file_id=$(ls -i /$mntpnt/$file_path | sed 's/ .*//') 55 typeset output=$(zfs_ids_to_path $TESTPOOL $ds_id $file_id) 56 [[ "$output" == "$mntpnt/$file_path" ]] || \ 57 log_fail "Incorrect output for non-verbose while mounted: $output" 58 output=$(zfs_ids_to_path -v $TESTPOOL $ds_id $file_id) 59 [[ "$output" == "$ds_path:/$file_path" ]] || \ 60 log_fail "Incorrect output for verbose while mounted: $output" 61 log_must zfs unmount $ds_path 62 output=$(zfs_ids_to_path $TESTPOOL $ds_id $file_id) 63 [[ "$output" == "$ds_path:/$file_path" ]] || \ 64 log_fail "Incorrect output for non-verbose while unmounted: $output" 65 output=$(zfs_ids_to_path -v $TESTPOOL $ds_id $file_id) 66 [[ "$output" == "$ds_path:/$file_path" ]] || \ 67 log_fail "Incorrect output for verbose while unmounted: $output" 68 log_must zfs mount $ds_path 69} 70 71log_onexit cleanup 72 73typeset BASE=$TESTPOOL/$TESTFS 74typeset TESTFILE1=f1 75typeset TESTDIR1=d1 76typeset TESTFILE2=d1/f2 77typeset TESTDIR2=d1/d2 78typeset TESTFILE3=d1/d2/f3 79typeset TESTFILE4=d1/d2/f4 80 81typeset mntpnt=$(get_prop mountpoint $BASE) 82 83log_must touch /$mntpnt/$TESTFILE1 84log_must mkdir /$mntpnt/$TESTDIR1 85log_must touch /$mntpnt/$TESTFILE2 86log_must mkdir /$mntpnt/$TESTDIR2 87log_must touch /$mntpnt/$TESTFILE3 88log_must touch /$mntpnt/$TESTFILE4 89 90typeset ds_id=$(zdb $BASE | grep "^Dataset" | sed 's/.* ID \([0-9]*\).*/\1/') 91test_one $ds_id $BASE $TESTFILE1 92test_one $ds_id $BASE $TESTFILE2 93test_one $ds_id $BASE $TESTFILE3 94test_one $ds_id $BASE $TESTFILE4 95 96log_pass "zfs_ids_to_path displayed correctly" 97