xref: /illumos-gate/usr/src/cmd/rcm_daemon/common/SUNW,vdevices.pl (revision fc910014e8a32a65612105835a10995f2c13d942)
1#!/usr/bin/perl -w
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#
24# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# RCM script to allow/deny removal of miscellaneous virtual devices
30# from an LDoms domain.
31#
32# Currently, the only device in this category is vcc
33# (virtual-console-concentrator).
34#
35
36use strict;
37
38my $vcc_path_prefix = "/devices/virtual-devices\@100/channel-devices\@200/";
39my $vcc_leaf_node = "virtual-console-concentrator";
40
41my $cmd;
42my %dispatch;
43
44
45sub do_scriptinfo
46{
47	print "rcm_log_debug=do_scriptinfo\n";
48
49	print "rcm_script_version=1\n";
50	print "rcm_script_func_info=VIO DR (VCC)\n";
51
52	exit (0);
53}
54
55sub do_resourceinfo
56{
57	print "rcm_log_debug=do_resourceinfo\n";
58	print "rcm_resource_usage_info=" .
59		"in use by virtual console service (vntsd)\n";
60
61	exit (0);
62}
63
64sub do_register
65{
66	print "rcm_log_debug=do_register\n";
67
68	#
69	# Identify any vcc devices in the system.  Vntsd always keeps the
70	# ":ctl" node open as a way to create or remove console ports, so
71	# use that as a proxy for the entire device.
72	#
73	my $path = $vcc_path_prefix . $vcc_leaf_node . "\*ctl";
74	my @devs = glob $path;
75	my $consdev;
76
77	#
78	# Tell the RCM framework to notify us if there is a request to
79	# remove a vcc device.
80	#
81	printf "rcm_log_debug=do_register: %d devices\n", scalar(@devs);
82	foreach $consdev(@devs) {
83		print "rcm_resource_name=$consdev\n";
84	}
85
86	exit (0);
87}
88
89sub do_queryremove
90{
91	my $rsrc = shift(@ARGV);
92
93	print "rcm_log_debug=do_queryremove: '$rsrc'\n";
94
95	#
96	# fuser(8) sends to stdout the pids of any processes using the
97	# device.  Some other information always appears on stderr and
98	# must be discarded to avoid invalidating the test.
99	#
100	my $str = `/usr/sbin/fuser $rsrc 2>/dev/null`;
101
102	if ($? != 0) {
103		printf "rcm_log_err=do_queryremove: " .
104		    "fuser failed (status %d)\n", $?;
105		print "rcm_failure_reason=helper command (fuser) failed\n";
106		exit (1);
107	}
108
109	my @words = split(/ /, $str);
110
111	# Allow the operation if device not opened by any processes.
112	if (scalar(@words) != 0) {
113		print "rcm_log_debug=BLOCKED\n";
114		print "rcm_failure_reason=device " .
115		    "in use by virtual console service (vntsd)\n";
116		exit (3);
117	}
118
119	exit (0);
120}
121
122$cmd = shift(@ARGV);
123
124# dispatch table for RCM commands
125%dispatch = (
126	"scriptinfo"	=>	\&do_scriptinfo,
127	"resourceinfo"	=>	\&do_resourceinfo,
128	"register"	=>	\&do_register,
129	"queryremove"	=>	\&do_queryremove
130);
131
132if (defined($dispatch{$cmd})) {
133	&{$dispatch{$cmd}};
134} else {
135	exit (2);
136}
137