From de4f06c275430937026e328f48438cc799eba987 Mon Sep 17 00:00:00 2001 From: Paul Dagnelie Date: Wed, 20 May 2020 10:05:33 -0700 Subject: Small program that converts a dataset id and an object id to a path Small program that converts a dataset id and an object id to a path Reviewed-by: Prakash Surya Reviewed-by: Brian Behlendorf Reviewed-by: Matthew Ahrens Signed-off-by: Paul Dagnelie Closes #10204 --- tests/runfiles/common.run | 4 + tests/zfs-tests/include/commands.cfg | 3 +- .../tests/functional/cli_root/Makefile.am | 1 + .../cli_root/zfs_ids_to_path/Makefile.am | 5 ++ .../cli_root/zfs_ids_to_path/cleanup.ksh | 29 +++++++ .../functional/cli_root/zfs_ids_to_path/setup.ksh | 31 +++++++ .../zfs_ids_to_path/zfs_ids_to_path_001_pos.ksh | 96 ++++++++++++++++++++++ 7 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/Makefile.am create mode 100755 tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/cleanup.ksh create mode 100755 tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/setup.ksh create mode 100755 tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/zfs_ids_to_path_001_pos.ksh (limited to 'tests') diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run index a9bede475..01bab0870 100644 --- a/tests/runfiles/common.run +++ b/tests/runfiles/common.run @@ -169,6 +169,10 @@ tests = ['zfs_get_001_pos', 'zfs_get_002_pos', 'zfs_get_003_pos', 'zfs_get_008_pos', 'zfs_get_009_pos', 'zfs_get_010_neg'] tags = ['functional', 'cli_root', 'zfs_get'] +[tests/functional/cli_root/zfs_ids_to_path] +tests = ['zfs_ids_to_path_001_pos'] +tags = ['functional', 'cli_root', 'zfs_ids_to_path'] + [tests/functional/cli_root/zfs_inherit] tests = ['zfs_inherit_001_neg', 'zfs_inherit_002_neg', 'zfs_inherit_003_pos', 'zfs_inherit_mountpoint'] diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index cf65313ac..7bd691e25 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -183,7 +183,8 @@ export ZFS_FILES='zdb zed zgenhostid zstream - zstreamdump' + zstreamdump + zfs_ids_to_path' export ZFSTEST_FILES='btree_test chg_usr_exec diff --git a/tests/zfs-tests/tests/functional/cli_root/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/Makefile.am index 8d99df09f..2595ed8c1 100644 --- a/tests/zfs-tests/tests/functional/cli_root/Makefile.am +++ b/tests/zfs-tests/tests/functional/cli_root/Makefile.am @@ -13,6 +13,7 @@ SUBDIRS = \ zfs_destroy \ zfs_diff \ zfs_get \ + zfs_ids_to_path \ zfs_inherit \ zfs_load-key \ zfs_mount \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/Makefile.am new file mode 100644 index 000000000..5f5e38587 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/Makefile.am @@ -0,0 +1,5 @@ +pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_ids_to_path +dist_pkgdata_SCRIPTS = \ + setup.ksh \ + cleanup.ksh \ + zfs_ids_to_path_001_pos.ksh diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/cleanup.ksh new file mode 100755 index 000000000..b5ff02217 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/cleanup.ksh @@ -0,0 +1,29 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (c) 2020 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +default_cleanup diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/setup.ksh new file mode 100755 index 000000000..fd6f8f8bb --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/setup.ksh @@ -0,0 +1,31 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (c) 2020 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +verify_runnable "global" + +default_setup $DISKS diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/zfs_ids_to_path_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/zfs_ids_to_path_001_pos.ksh new file mode 100755 index 000000000..4968e1507 --- /dev/null +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_ids_to_path/zfs_ids_to_path_001_pos.ksh @@ -0,0 +1,96 @@ +#!/bin/ksh -p +# +# CDDL HEADER START +# +# The contents of this file are subject to the terms of the +# Common Development and Distribution License (the "License"). +# You may not use this file except in compliance with the License. +# +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +# or http://www.opensolaris.org/os/licensing. +# See the License for the specific language governing permissions +# and limitations under the License. +# +# When distributing Covered Code, include this CDDL HEADER in each +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. +# If applicable, add the following below this CDDL HEADER, with the +# fields enclosed by brackets "[]" replaced with your own identifying +# information: Portions Copyright [yyyy] [name of copyright owner] +# +# CDDL HEADER END +# + +# +# Copyright (c) 2020 by Delphix. All rights reserved. +# + +. $STF_SUITE/include/libtest.shlib + +# +# DESCRIPTION: Identify the objset id and the object id of a file in a +# filesystem, and verify that zfs_ids_to_path behaves correctly with them. +# +# STRATEGY: +# 1. Create a dateset +# 2. Makes files in the dataset +# 3. Verify that zfs_ids_to_path outputs the correct format for each one +# + +verify_runnable "both" + +function cleanup +{ + destroy_dataset $TESTPOOL/$TESTFS + zfs create -o mountpoint=$TESTDIR $TESTPOOL/$TESTFS +} + +function test_one +{ + typeset ds_id="$1" + typeset ds_path="$2" + typeset file_path="$3" + + typeset mntpnt=$(get_prop mountpoint $ds_path) + typeset file_id=$(ls -i /$mntpnt/$file_path | sed 's/ .*//') + typeset output=$(zfs_ids_to_path $TESTPOOL $ds_id $file_id) + [[ "$output" == "$mntpnt/$file_path" ]] || \ + log_fail "Incorrect output for non-verbose while mounted: $output" + output=$(zfs_ids_to_path -v $TESTPOOL $ds_id $file_id) + [[ "$output" == "$ds_path:/$file_path" ]] || \ + log_fail "Incorrect output for verbose while mounted: $output" + log_must zfs unmount $ds_path + output=$(zfs_ids_to_path $TESTPOOL $ds_id $file_id) + [[ "$output" == "$ds_path:/$file_path" ]] || \ + log_fail "Incorrect output for non-verbose while unmounted: $output" + output=$(zfs_ids_to_path -v $TESTPOOL $ds_id $file_id) + [[ "$output" == "$ds_path:/$file_path" ]] || \ + log_fail "Incorrect output for verbose while unmounted: $output" + log_must zfs mount $ds_path +} + +log_onexit cleanup + +typeset BASE=$TESTPOOL/$TESTFS +typeset TESTFILE1=f1 +typeset TESTDIR1=d1 +typeset TESTFILE2=d1/f2 +typeset TESTDIR2=d1/d2 +typeset TESTFILE3=d1/d2/f3 +typeset TESTFILE4=d1/d2/f4 + +typeset mntpnt=$(get_prop mountpoint $BASE) + +log_must touch /$mntpnt/$TESTFILE1 +log_must mkdir /$mntpnt/$TESTDIR1 +log_must touch /$mntpnt/$TESTFILE2 +log_must mkdir /$mntpnt/$TESTDIR2 +log_must touch /$mntpnt/$TESTFILE3 +log_must touch /$mntpnt/$TESTFILE4 + +typeset ds_id=$(zdb $BASE | grep "^Dataset" | sed 's/.* ID \([0-9]*\).*/\1/') +test_one $ds_id $BASE $TESTFILE1 +test_one $ds_id $BASE $TESTFILE2 +test_one $ds_id $BASE $TESTFILE3 +test_one $ds_id $BASE $TESTFILE4 + +log_pass "zfs_ids_to_path displayed correctly" -- cgit v1.2.3