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