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