1# vim: filetype=sh
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 http://www.opensolaris.org/os/licensing.
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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)iscsi_common.kshlib	1.2	07/03/14 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34#
35# Check if a volume is a valide iscsi target
36# $1 volume name
37# return 0 if suceeds, otherwise, return 1
38#
39function is_iscsi_target
40{
41	typeset dataset=$1
42	typeset target targets
43
44	[[ -z $dataset ]] && return 1
45
46	targets=$($ISCSITADM list target | $GREP "Target:" | $AWK '{print $2}')
47	[[ -z $targets ]] && return 1
48
49	for target in $targets; do
50		[[ $dataset == $target ]] && return 0
51	done
52
53	return 1
54}
55
56#
57# Get the iSCSI name of a target
58# $1 target name
59#
60function iscsi_name
61{
62	typeset target=$1
63	typeset name
64
65	[[ -z $target ]] && log_fail "No parameter."
66
67	if ! is_iscsi_target $target ; then
68		log_fail "Not a target."
69	fi
70
71	name=$($ISCSITADM list target $target | $GREP "iSCSI Name:" \
72		| $AWK '{print $2}')
73
74	return $name
75}
76
77#
78# Check shareiscsi option is supported or not
79# return 0 if it is supported, otherwise return 1
80#
81function check_shareiscsi
82{
83	$ZFS set 2>&1 | $GREP shareiscsi
84	[[ $? -ne 0 ]] && return 1
85
86	return 0
87}
88