1*045b72beSjm22469#!/usr/bin/perl -w 2*045b72beSjm22469# 3*045b72beSjm22469# CDDL HEADER START 4*045b72beSjm22469# 5*045b72beSjm22469# The contents of this file are subject to the terms of the 6*045b72beSjm22469# Common Development and Distribution License (the "License"). 7*045b72beSjm22469# You may not use this file except in compliance with the License. 8*045b72beSjm22469# 9*045b72beSjm22469# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*045b72beSjm22469# or http://www.opensolaris.org/os/licensing. 11*045b72beSjm22469# See the License for the specific language governing permissions 12*045b72beSjm22469# and limitations under the License. 13*045b72beSjm22469# 14*045b72beSjm22469# When distributing Covered Code, include this CDDL HEADER in each 15*045b72beSjm22469# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*045b72beSjm22469# If applicable, add the following below this CDDL HEADER, with the 17*045b72beSjm22469# fields enclosed by brackets "[]" replaced with your own identifying 18*045b72beSjm22469# information: Portions Copyright [yyyy] [name of copyright owner] 19*045b72beSjm22469# 20*045b72beSjm22469# CDDL HEADER END 21*045b72beSjm22469# 22*045b72beSjm22469 23*045b72beSjm22469# 24*045b72beSjm22469# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 25*045b72beSjm22469# Use is subject to license terms. 26*045b72beSjm22469# 27*045b72beSjm22469#pragma ident "%Z%%M% %I% %E% SMI" 28*045b72beSjm22469# 29*045b72beSjm22469 30*045b72beSjm22469# 31*045b72beSjm22469# RCM script to allow/deny removal of miscellaneous virtual devices 32*045b72beSjm22469# from an LDoms domain. 33*045b72beSjm22469# 34*045b72beSjm22469# Currently, the only device in this category is vcc 35*045b72beSjm22469# (virtual-console-concentrator). 36*045b72beSjm22469# 37*045b72beSjm22469 38*045b72beSjm22469use strict; 39*045b72beSjm22469 40*045b72beSjm22469my $vcc_path_prefix = "/devices/virtual-devices\@100/channel-devices\@200/"; 41*045b72beSjm22469my $vcc_leaf_node = "virtual-console-concentrator"; 42*045b72beSjm22469 43*045b72beSjm22469my $cmd; 44*045b72beSjm22469my %dispatch; 45*045b72beSjm22469 46*045b72beSjm22469 47*045b72beSjm22469sub do_scriptinfo 48*045b72beSjm22469{ 49*045b72beSjm22469 print "rcm_log_debug=do_scriptinfo\n"; 50*045b72beSjm22469 51*045b72beSjm22469 print "rcm_script_version=1\n"; 52*045b72beSjm22469 print "rcm_script_func_info=VIO DR (VCC)\n"; 53*045b72beSjm22469 54*045b72beSjm22469 exit (0); 55*045b72beSjm22469} 56*045b72beSjm22469 57*045b72beSjm22469sub do_resourceinfo 58*045b72beSjm22469{ 59*045b72beSjm22469 print "rcm_log_debug=do_resourceinfo\n"; 60*045b72beSjm22469 print "rcm_resource_usage_info=" . 61*045b72beSjm22469 "in use by virtual console service (vntsd)\n"; 62*045b72beSjm22469 63*045b72beSjm22469 exit (0); 64*045b72beSjm22469} 65*045b72beSjm22469 66*045b72beSjm22469sub do_register 67*045b72beSjm22469{ 68*045b72beSjm22469 print "rcm_log_debug=do_register\n"; 69*045b72beSjm22469 70*045b72beSjm22469 # 71*045b72beSjm22469 # Identify any vcc devices in the system. Vntsd always keeps the 72*045b72beSjm22469 # ":ctl" node open as a way to create or remove console ports, so 73*045b72beSjm22469 # use that as a proxy for the entire device. 74*045b72beSjm22469 # 75*045b72beSjm22469 my $path = $vcc_path_prefix . $vcc_leaf_node . "\*ctl"; 76*045b72beSjm22469 my @devs = glob $path; 77*045b72beSjm22469 my $consdev; 78*045b72beSjm22469 79*045b72beSjm22469 # 80*045b72beSjm22469 # Tell the RCM framework to notify us if there is a request to 81*045b72beSjm22469 # remove a vcc device. 82*045b72beSjm22469 # 83*045b72beSjm22469 printf "rcm_log_debug=do_register: %d devices\n", scalar(@devs); 84*045b72beSjm22469 foreach $consdev(@devs) { 85*045b72beSjm22469 print "rcm_resource_name=$consdev\n"; 86*045b72beSjm22469 } 87*045b72beSjm22469 88*045b72beSjm22469 exit (0); 89*045b72beSjm22469} 90*045b72beSjm22469 91*045b72beSjm22469sub do_queryremove 92*045b72beSjm22469{ 93*045b72beSjm22469 my $rsrc = shift(@ARGV); 94*045b72beSjm22469 95*045b72beSjm22469 print "rcm_log_debug=do_queryremove: '$rsrc'\n"; 96*045b72beSjm22469 97*045b72beSjm22469 # 98*045b72beSjm22469 # fuser(1M) sends to stdout the pids of any processes using the 99*045b72beSjm22469 # device. Some other information always appears on stderr and 100*045b72beSjm22469 # must be discarded to avoid invalidating the test. 101*045b72beSjm22469 # 102*045b72beSjm22469 my $str = `/usr/sbin/fuser $rsrc 2>/dev/null`; 103*045b72beSjm22469 104*045b72beSjm22469 if ($? != 0) { 105*045b72beSjm22469 printf "rcm_log_err=do_queryremove: " . 106*045b72beSjm22469 "fuser failed (status %d)\n", $?; 107*045b72beSjm22469 print "rcm_failure_reason=helper command (fuser) failed\n"; 108*045b72beSjm22469 exit (1); 109*045b72beSjm22469 } 110*045b72beSjm22469 111*045b72beSjm22469 my @words = split(/ /, $str); 112*045b72beSjm22469 113*045b72beSjm22469 # Allow the operation if device not opened by any processes. 114*045b72beSjm22469 if (scalar(@words) != 0) { 115*045b72beSjm22469 print "rcm_log_debug=BLOCKED\n"; 116*045b72beSjm22469 print "rcm_failure_reason=device " . 117*045b72beSjm22469 "in use by virtual console service (vntsd)\n"; 118*045b72beSjm22469 exit (3); 119*045b72beSjm22469 } 120*045b72beSjm22469 121*045b72beSjm22469 exit (0); 122*045b72beSjm22469} 123*045b72beSjm22469 124*045b72beSjm22469$cmd = shift(@ARGV); 125*045b72beSjm22469 126*045b72beSjm22469# dispatch table for RCM commands 127*045b72beSjm22469%dispatch = ( 128*045b72beSjm22469 "scriptinfo" => \&do_scriptinfo, 129*045b72beSjm22469 "resourceinfo" => \&do_resourceinfo, 130*045b72beSjm22469 "register" => \&do_register, 131*045b72beSjm22469 "queryremove" => \&do_queryremove 132*045b72beSjm22469); 133*045b72beSjm22469 134*045b72beSjm22469if (defined($dispatch{$cmd})) { 135*045b72beSjm22469 &{$dispatch{$cmd}}; 136*045b72beSjm22469} else { 137*045b72beSjm22469 exit (2); 138*045b72beSjm22469} 139