8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / avs / sdbc / sdbc_ioctl.c
blobbaa0858236708b95c4fd7f8961618eeb890a09a5
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * SDBC user level ioctl interface
30 #include <stdio.h>
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include <sys/types.h>
34 #include <fcntl.h>
35 #include <strings.h>
37 #include <sys/nsctl/sd_cache.h>
38 #include <sys/nsctl/sd_conf.h>
39 #include <sys/nsctl/sdbc_ioctl.h>
40 #include <sys/unistat/spcs_s.h>
41 #include <sys/unistat/spcs_s_u.h>
43 #include <sys/nsctl/sv.h>
44 #include <sys/nsctl/sv_impl.h>
47 const char *__sdbc_dev = "/dev/sdbc";
48 static int __sdbc_fd;
51 static int
52 __sdbc_open(void)
54 int fd;
56 fd = open("/dev/nsctl", O_RDONLY);
57 if (fd >= 0)
58 (void) close(fd);
60 fd = open(__sdbc_dev, O_RDONLY);
61 if (fd < 0)
62 return (-1);
64 return (__sdbc_fd = fd);
68 static void
69 sv_list()
71 sv_name_t svn[1];
72 sv_name_t *svn_system;
73 sv_list_t svl;
74 static int fd = -1;
76 if (fd < 0)
77 fd = open(SV_DEVICE, O_RDONLY);
78 if (fd < 0)
79 return;
81 bzero(&svl, sizeof (svl));
82 bzero(&svn[0], sizeof (svn));
84 svl.svl_names = &svn[0];
85 svl.svl_error = spcs_s_ucreate();
87 if (ioctl(fd, SVIOC_LIST, &svl) < 0)
88 return;
90 svn_system = calloc(svl.svl_maxdevs, sizeof (*svn));
91 if (svn_system == NULL)
92 return;
94 /* Grab the system list from the driver */
95 svl.svl_count = svl.svl_maxdevs;
96 svl.svl_names = svn_system;
98 (void) ioctl(fd, SVIOC_LIST, &svl);
100 free(svn_system);
101 spcs_s_ufree(&svl.svl_error);
106 sdbc_ioctl(long cmd, long a0, long a1, long a2, long a3, long a4,
107 spcs_s_info_t *ustatus)
109 _sdbc_ioctl_t args;
110 int rc;
112 *ustatus = NULL;
114 if (!__sdbc_fd && __sdbc_open() < 0)
115 return (-1);
117 switch (cmd) {
119 * These ioctls work on open cache descriptors. The sv_list() function
120 * has the side-effect of re-opening all configured descriptors.
121 * Without this call, devices seem to "disappear" from the system when
122 * certain reconfiguration operations, for example II or SNDR disable,
123 * are done.
124 * It does rely on SV being configured, so in an STE-only environment
125 * the disappearing will still seem to happen.
127 case SDBC_SET_CD_HINT:
128 case SDBC_GET_CD_HINT:
129 case SDBC_STATS:
130 case SDBC_GET_CD_BLK:
131 case SDBC_INJ_IOERR:
132 case SDBC_CLR_IOERR:
133 sv_list();
134 break;
136 default:
137 break;
140 args.arg0 = a0;
141 args.arg1 = a1;
142 args.arg2 = a2;
143 args.arg3 = a3;
144 args.arg4 = a4;
145 args.magic = _SD_MAGIC; /* for versioning */
146 args.sdbc_ustatus = spcs_s_ucreate();
148 if ((rc = ioctl(__sdbc_fd, cmd, &args)) < 0) {
149 *ustatus = args.sdbc_ustatus;
150 } else {
151 spcs_s_ufree(&args.sdbc_ustatus);
152 *ustatus = NULL;
155 return (rc);