1045b72beSjm#!/usr/bin/perl -w
2045b72beSjm#
3045b72beSjm# CDDL HEADER START
4045b72beSjm#
5045b72beSjm# The contents of this file are subject to the terms of the
6045b72beSjm# Common Development and Distribution License (the "License").
7045b72beSjm# You may not use this file except in compliance with the License.
8045b72beSjm#
9045b72beSjm# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10045b72beSjm# or http://www.opensolaris.org/os/licensing.
11045b72beSjm# See the License for the specific language governing permissions
12045b72beSjm# and limitations under the License.
13045b72beSjm#
14045b72beSjm# When distributing Covered Code, include this CDDL HEADER in each
15045b72beSjm# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16045b72beSjm# If applicable, add the following below this CDDL HEADER, with the
17045b72beSjm# fields enclosed by brackets "[]" replaced with your own identifying
18045b72beSjm# information: Portions Copyright [yyyy] [name of copyright owner]
19045b72beSjm#
20045b72beSjm# CDDL HEADER END
21045b72beSjm#
22045b72beSjm
23045b72beSjm#
24045b72beSjm# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25045b72beSjm# Use is subject to license terms.
26045b72beSjm#
27045b72beSjm
28045b72beSjm#
29045b72beSjm# RCM script to allow/deny removal of miscellaneous virtual devices
30045b72beSjm# from an LDoms domain.
31045b72beSjm#
32045b72beSjm# Currently, the only device in this category is vcc
33045b72beSjm# (virtual-console-concentrator).
34045b72beSjm#
35045b72beSjm
36045b72beSjmuse strict;
37045b72beSjm
38045b72beSjmmy $vcc_path_prefix = "/devices/virtual-devices\@100/channel-devices\@200/";
39045b72beSjmmy $vcc_leaf_node = "virtual-console-concentrator";
40045b72beSjm
41045b72beSjmmy $cmd;
42045b72beSjmmy %dispatch;
43045b72beSjm
44045b72beSjm
45045b72beSjmsub do_scriptinfo
46045b72beSjm{
47045b72beSjm	print "rcm_log_debug=do_scriptinfo\n";
48045b72beSjm
49045b72beSjm	print "rcm_script_version=1\n";
50045b72beSjm	print "rcm_script_func_info=VIO DR (VCC)\n";
51045b72beSjm
52045b72beSjm	exit (0);
53045b72beSjm}
54045b72beSjm
55045b72beSjmsub do_resourceinfo
56045b72beSjm{
57045b72beSjm	print "rcm_log_debug=do_resourceinfo\n";
58045b72beSjm	print "rcm_resource_usage_info=" .
59045b72beSjm		"in use by virtual console service (vntsd)\n";
60045b72beSjm
61045b72beSjm	exit (0);
62045b72beSjm}
63045b72beSjm
64045b72beSjmsub do_register
65045b72beSjm{
66045b72beSjm	print "rcm_log_debug=do_register\n";
67045b72beSjm
68045b72beSjm	#
69045b72beSjm	# Identify any vcc devices in the system.  Vntsd always keeps the
70045b72beSjm	# ":ctl" node open as a way to create or remove console ports, so
71045b72beSjm	# use that as a proxy for the entire device.
72045b72beSjm	#
73045b72beSjm	my $path = $vcc_path_prefix . $vcc_leaf_node . "\*ctl";
74045b72beSjm	my @devs = glob $path;
75045b72beSjm	my $consdev;
76045b72beSjm
77045b72beSjm	#
78045b72beSjm	# Tell the RCM framework to notify us if there is a request to
79045b72beSjm	# remove a vcc device.
80045b72beSjm	#
81045b72beSjm	printf "rcm_log_debug=do_register: %d devices\n", scalar(@devs);
82045b72beSjm	foreach $consdev(@devs) {
83045b72beSjm		print "rcm_resource_name=$consdev\n";
84045b72beSjm	}
85045b72beSjm
86045b72beSjm	exit (0);
87045b72beSjm}
88045b72beSjm
89045b72beSjmsub do_queryremove
90045b72beSjm{
91045b72beSjm	my $rsrc = shift(@ARGV);
92045b72beSjm
93045b72beSjm	print "rcm_log_debug=do_queryremove: '$rsrc'\n";
94045b72beSjm
95045b72beSjm	#
96*bbf21555SRichard Lowe	# fuser(8) sends to stdout the pids of any processes using the
97045b72beSjm	# device.  Some other information always appears on stderr and
98045b72beSjm	# must be discarded to avoid invalidating the test.
99045b72beSjm	#
100045b72beSjm	my $str = `/usr/sbin/fuser $rsrc 2>/dev/null`;
101045b72beSjm
102045b72beSjm	if ($? != 0) {
103045b72beSjm		printf "rcm_log_err=do_queryremove: " .
104045b72beSjm		    "fuser failed (status %d)\n", $?;
105045b72beSjm		print "rcm_failure_reason=helper command (fuser) failed\n";
106045b72beSjm		exit (1);
107045b72beSjm	}
108045b72beSjm
109045b72beSjm	my @words = split(/ /, $str);
110045b72beSjm
111045b72beSjm	# Allow the operation if device not opened by any processes.
112045b72beSjm	if (scalar(@words) != 0) {
113045b72beSjm		print "rcm_log_debug=BLOCKED\n";
114045b72beSjm		print "rcm_failure_reason=device " .
115045b72beSjm		    "in use by virtual console service (vntsd)\n";
116045b72beSjm		exit (3);
117045b72beSjm	}
118045b72beSjm
119045b72beSjm	exit (0);
120045b72beSjm}
121045b72beSjm
122045b72beSjm$cmd = shift(@ARGV);
123045b72beSjm
124045b72beSjm# dispatch table for RCM commands
125045b72beSjm%dispatch = (
126045b72beSjm	"scriptinfo"	=>	\&do_scriptinfo,
127045b72beSjm	"resourceinfo"	=>	\&do_resourceinfo,
128045b72beSjm	"register"	=>	\&do_register,
129045b72beSjm	"queryremove"	=>	\&do_queryremove
130045b72beSjm);
131045b72beSjm
132045b72beSjmif (defined($dispatch{$cmd})) {
133045b72beSjm	&{$dispatch{$cmd}};
134045b72beSjm} else {
135045b72beSjm	exit (2);
136045b72beSjm}
137