xref: /illumos-gate/usr/src/cmd/allocate/svc-allocate (revision 6a634c9d)
1*269f47deSThuy Fettig#! /bin/sh
2*269f47deSThuy Fettig#
3*269f47deSThuy Fettig#
4*269f47deSThuy Fettig# CDDL HEADER START
5*269f47deSThuy Fettig#
6*269f47deSThuy Fettig# The contents of this file are subject to the terms of the
7*269f47deSThuy Fettig# Common Development and Distribution License (the "License").
8*269f47deSThuy Fettig# You may not use this file except in compliance with the License.
9*269f47deSThuy Fettig#
10*269f47deSThuy Fettig# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*269f47deSThuy Fettig# or http://www.opensolaris.org/os/licensing.
12*269f47deSThuy Fettig# See the License for the specific language governing permissions
13*269f47deSThuy Fettig# and limitations under the License.
14*269f47deSThuy Fettig#
15*269f47deSThuy Fettig# When distributing Covered Code, include this CDDL HEADER in each
16*269f47deSThuy Fettig# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*269f47deSThuy Fettig# If applicable, add the following below this CDDL HEADER, with the
18*269f47deSThuy Fettig# fields enclosed by brackets "[]" replaced with your own identifying
19*269f47deSThuy Fettig# information: Portions Copyright [yyyy] [name of copyright owner]
20*269f47deSThuy Fettig#
21*269f47deSThuy Fettig# CDDL HEADER END
22*269f47deSThuy Fettig#
23*269f47deSThuy Fettig# Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
24*269f47deSThuy Fettig#
25*269f47deSThuy Fettig
26*269f47deSThuy Fettig. /lib/svc/share/smf_include.sh
27*269f47deSThuy Fettig
28*269f47deSThuy FettigDEVALLOC=/etc/security/device_allocate
29*269f47deSThuy FettigDEVMAPS=/etc/security/device_maps
30*269f47deSThuy FettigDEVFSADM=/usr/sbin/devfsadm
31*269f47deSThuy FettigMKDEVALLOC=/usr/sbin/mkdevalloc
32*269f47deSThuy FettigMKDEVMAPS=/usr/sbin/mkdevmaps
33*269f47deSThuy FettigHALFDI=/etc/hal/fdi/policy/30user/90-solaris-device-allocation.fdi
34*269f47deSThuy Fettig
35*269f47deSThuy Fettig# dev_allocation_convert
36*269f47deSThuy Fettig#	All the real work gets done in this function
37*269f47deSThuy Fettig
38*269f47deSThuy Fettigdev_allocation_convert()
39*269f47deSThuy Fettig{
40*269f47deSThuy Fettig#
41*269f47deSThuy Fettig# If allocation already configured, just return
42*269f47deSThuy Fettig#
43*269f47deSThuy Fettigif [ -f ${HALFDI} -a -f ${DEVALLOC} -a -f ${DEVMAPS} ]; then
44*269f47deSThuy Fettig    return
45*269f47deSThuy Fettigfi
46*269f47deSThuy Fettig
47*269f47deSThuy Fettig# Prevent automount of removable and hotpluggable volume
48*269f47deSThuy Fettig# by forcing volume.ignore HAL property on all such volumes.
49*269f47deSThuy Fettigif [ ! -f ${HALFDI} ]; then
50*269f47deSThuy Fettig	cat > ${HALFDI} <<FDI
51*269f47deSThuy Fettig<?xml version="1.0" encoding="UTF-8"?>
52*269f47deSThuy Fettig<deviceinfo version="0.2">
53*269f47deSThuy Fettig  <device>
54*269f47deSThuy Fettig    <match key="info.capabilities" contains="volume">
55*269f47deSThuy Fettig      <match key="@block.storage_device:storage.removable" bool="true">
56*269f47deSThuy Fettig        <merge key="volume.ignore" type="bool">true</merge>
57*269f47deSThuy Fettig      </match>
58*269f47deSThuy Fettig      <match key="@block.storage_device:storage.hotpluggable" bool="true">
59*269f47deSThuy Fettig        <merge key="volume.ignore" type="bool">true</merge>
60*269f47deSThuy Fettig      </match>
61*269f47deSThuy Fettig    </match>
62*269f47deSThuy Fettig  </device>
63*269f47deSThuy Fettig</deviceinfo>
64*269f47deSThuy FettigFDI
65*269f47deSThuy Fettigfi
66*269f47deSThuy Fettig
67*269f47deSThuy Fettig# Initialize device allocation
68*269f47deSThuy Fettig
69*269f47deSThuy Fettig
70*269f47deSThuy Fettig# Need to determine if Trusted Extensions is enabled.
71*269f47deSThuy Fettig# Check the setting in etc/system (other methods won't work
72*269f47deSThuy Fettig# because TX is likely not yet fully active.)
73*269f47deSThuy Fettig#
74*269f47deSThuy Fettiggrep "^[ 	]*set[ 	][ 	]*sys_labeling[ 	]*=[ 	]*1" \
75*269f47deSThuy Fettig    /etc/system > /dev/null 2>&1
76*269f47deSThuy Fettig
77*269f47deSThuy Fettigif [ $? = 0 ]; then
78*269f47deSThuy Fettig	# Trusted Extensions is enabled (but possibly not yet booted).
79*269f47deSThuy Fettig	${DEVFSADM} -e
80*269f47deSThuy Fettigelse
81*269f47deSThuy Fettig	if [ ! -f ${DEVALLOC} ]; then
82*269f47deSThuy Fettig		echo "DEVICE_ALLOCATION=ON" > $DEVALLOC
83*269f47deSThuy Fettig		${MKDEVALLOC} >> $DEVALLOC
84*269f47deSThuy Fettig	fi
85*269f47deSThuy Fettig	if [ ! -f ${DEVMAPS} ]; then
86*269f47deSThuy Fettig		${MKDEVMAPS} > $DEVMAPS
87*269f47deSThuy Fettig	fi
88*269f47deSThuy Fettigfi
89*269f47deSThuy Fettig}
90*269f47deSThuy Fettig
91*269f47deSThuy Fettigdev_allocation_unconvert()
92*269f47deSThuy Fettig{
93*269f47deSThuy Fettig	# Turn off device allocation.
94*269f47deSThuy Fettig	${DEVFSADM} -d
95*269f47deSThuy Fettig	/usr/bin/rm -f $DEVALLOC $DEVMAPS
96*269f47deSThuy Fettig	# Restore default policy for removable and hotpluggable volumes
97*269f47deSThuy Fettig	/usr/bin/rm -f $HALFDI
98*269f47deSThuy Fettig}
99*269f47deSThuy Fettig
100*269f47deSThuy Fettigcase "$1" in
101*269f47deSThuy Fettig'start')
102*269f47deSThuy Fettig	dev_allocation_convert
103*269f47deSThuy Fettig	deallocate -Is
104*269f47deSThuy Fettig	;;
105*269f47deSThuy Fettig'stop')
106*269f47deSThuy Fettig	state=`/usr/bin/svcprop -c -p general/enabled $SMF_FMRI 2>/dev/null`
107*269f47deSThuy Fettig	if [ "$state" = "true" ] ; then
108*269f47deSThuy Fettig		exit $SMF_EXIT_OK
109*269f47deSThuy Fettig	fi
110*269f47deSThuy Fettig	dev_allocation_unconvert
111*269f47deSThuy Fettig	;;
112*269f47deSThuy Fettigesac
113*269f47deSThuy Fettig
114*269f47deSThuy Fettigexit $SMF_EXIT_OK
115