8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / rcm_daemon / common / SUNW,vdevices.pl
blob0c5d4d9ca74c69110df1c5198616f5ba4ee1f0f0
1 #!/usr/bin/perl -w
3 # CDDL HEADER START
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.
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.
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]
20 # CDDL HEADER END
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
31 # RCM script to allow/deny removal of miscellaneous virtual devices
32 # from an LDoms domain.
34 # Currently, the only device in this category is vcc
35 # (virtual-console-concentrator).
38 use strict;
40 my $vcc_path_prefix = "/devices/virtual-devices\@100/channel-devices\@200/";
41 my $vcc_leaf_node = "virtual-console-concentrator";
43 my $cmd;
44 my %dispatch;
47 sub do_scriptinfo
49 print "rcm_log_debug=do_scriptinfo\n";
51 print "rcm_script_version=1\n";
52 print "rcm_script_func_info=VIO DR (VCC)\n";
54 exit (0);
57 sub do_resourceinfo
59 print "rcm_log_debug=do_resourceinfo\n";
60 print "rcm_resource_usage_info=" .
61 "in use by virtual console service (vntsd)\n";
63 exit (0);
66 sub do_register
68 print "rcm_log_debug=do_register\n";
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.
75 my $path = $vcc_path_prefix . $vcc_leaf_node . "\*ctl";
76 my @devs = glob $path;
77 my $consdev;
80 # Tell the RCM framework to notify us if there is a request to
81 # remove a vcc device.
83 printf "rcm_log_debug=do_register: %d devices\n", scalar(@devs);
84 foreach $consdev(@devs) {
85 print "rcm_resource_name=$consdev\n";
88 exit (0);
91 sub do_queryremove
93 my $rsrc = shift(@ARGV);
95 print "rcm_log_debug=do_queryremove: '$rsrc'\n";
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.
102 my $str = `/usr/sbin/fuser $rsrc 2>/dev/null`;
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);
111 my @words = split(/ /, $str);
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);
121 exit (0);
124 $cmd = shift(@ARGV);
126 # dispatch table for RCM commands
127 %dispatch = (
128 "scriptinfo" => \&do_scriptinfo,
129 "resourceinfo" => \&do_resourceinfo,
130 "register" => \&do_register,
131 "queryremove" => \&do_queryremove
134 if (defined($dispatch{$cmd})) {
135 &{$dispatch{$cmd}};
136 } else {
137 exit (2);