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