17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 59acbbeafSnn35248 * Common Development and Distribution License (the "License"). 69acbbeafSnn35248 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*d4204c85Sraf 227c478bd9Sstevel@tonic-gate /* 23*d4204c85Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/systm.h> 317c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 327c478bd9Sstevel@tonic-gate #include <sys/class.h> 337c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 347c478bd9Sstevel@tonic-gate #include <sys/cred.h> 357c478bd9Sstevel@tonic-gate #include <sys/proc.h> 367c478bd9Sstevel@tonic-gate #include <sys/procset.h> 377c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 387c478bd9Sstevel@tonic-gate #include <sys/disp.h> 397c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 40*d4204c85Sraf #include <sys/schedctl.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate static int getcidbyname_locked(char *, id_t *); 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * Allocate a cid given a class name if one is not already allocated. 467c478bd9Sstevel@tonic-gate * Returns 0 if the cid was already exists or if the allocation of a new 477c478bd9Sstevel@tonic-gate * cid was successful. Nonzero return indicates error. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate int 507c478bd9Sstevel@tonic-gate alloc_cid(char *clname, id_t *cidp) 517c478bd9Sstevel@tonic-gate { 527c478bd9Sstevel@tonic-gate sclass_t *clp; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&class_lock)); 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* 577c478bd9Sstevel@tonic-gate * If the clname doesn't already have a cid, allocate one. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate if (getcidbyname_locked(clname, cidp) != 0) { 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * Allocate a class entry and a lock for it. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate for (clp = sclass; clp < &sclass[nclass]; clp++) 647c478bd9Sstevel@tonic-gate if (clp->cl_name[0] == '\0' && clp->cl_lock == NULL) 657c478bd9Sstevel@tonic-gate break; 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate if (clp == &sclass[nclass]) { 687c478bd9Sstevel@tonic-gate return (ENOSPC); 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate *cidp = clp - &sclass[0]; 717c478bd9Sstevel@tonic-gate clp->cl_lock = kmem_alloc(sizeof (krwlock_t), KM_SLEEP); 727c478bd9Sstevel@tonic-gate clp->cl_name = kmem_alloc(strlen(clname) + 1, KM_SLEEP); 737c478bd9Sstevel@tonic-gate (void) strcpy(clp->cl_name, clname); 747c478bd9Sstevel@tonic-gate rw_init(clp->cl_lock, NULL, RW_DEFAULT, NULL); 757c478bd9Sstevel@tonic-gate } 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* 787c478bd9Sstevel@tonic-gate * At this point, *cidp will contain the index into the class 797c478bd9Sstevel@tonic-gate * array for the given class name. 807c478bd9Sstevel@tonic-gate */ 817c478bd9Sstevel@tonic-gate return (0); 827c478bd9Sstevel@tonic-gate } 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate int 857c478bd9Sstevel@tonic-gate scheduler_load(char *clname, sclass_t *clp) 867c478bd9Sstevel@tonic-gate { 877c478bd9Sstevel@tonic-gate int rv = 0; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate if (LOADABLE_SCHED(clp)) { 907c478bd9Sstevel@tonic-gate rw_enter(clp->cl_lock, RW_READER); 917c478bd9Sstevel@tonic-gate if (!SCHED_INSTALLED(clp)) { 927c478bd9Sstevel@tonic-gate rw_exit(clp->cl_lock); 937c478bd9Sstevel@tonic-gate if (modload("sched", clname) == -1) 947c478bd9Sstevel@tonic-gate return (EINVAL); 957c478bd9Sstevel@tonic-gate rw_enter(clp->cl_lock, RW_READER); 967c478bd9Sstevel@tonic-gate /* did we really load a scheduling class? */ 977c478bd9Sstevel@tonic-gate if (!SCHED_INSTALLED(clp)) 987c478bd9Sstevel@tonic-gate rv = EINVAL; 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate rw_exit(clp->cl_lock); 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate return (rv); 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * Get class ID given class name. 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate int 1097c478bd9Sstevel@tonic-gate getcid(char *clname, id_t *cidp) 1107c478bd9Sstevel@tonic-gate { 1117c478bd9Sstevel@tonic-gate sclass_t *clp; 1127c478bd9Sstevel@tonic-gate int retval; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate mutex_enter(&class_lock); 1157c478bd9Sstevel@tonic-gate if ((retval = alloc_cid(clname, cidp)) == 0) { 1167c478bd9Sstevel@tonic-gate clp = &sclass[*cidp]; 1177c478bd9Sstevel@tonic-gate clp->cl_count++; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * If it returns zero, it's loaded & locked 1217c478bd9Sstevel@tonic-gate * or we found a statically installed scheduler 1227c478bd9Sstevel@tonic-gate * module. 1237c478bd9Sstevel@tonic-gate * If it returns EINVAL, modload() failed when 1247c478bd9Sstevel@tonic-gate * it tried to load the module. 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate mutex_exit(&class_lock); 1277c478bd9Sstevel@tonic-gate retval = scheduler_load(clname, clp); 1287c478bd9Sstevel@tonic-gate mutex_enter(&class_lock); 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate clp->cl_count--; 1317c478bd9Sstevel@tonic-gate if (retval != 0 && clp->cl_count == 0) { 1327c478bd9Sstevel@tonic-gate /* last guy out of scheduler_load frees the storage */ 1337c478bd9Sstevel@tonic-gate kmem_free(clp->cl_name, strlen(clname) + 1); 1347c478bd9Sstevel@tonic-gate kmem_free(clp->cl_lock, sizeof (krwlock_t)); 1357c478bd9Sstevel@tonic-gate clp->cl_name = ""; 1367c478bd9Sstevel@tonic-gate clp->cl_lock = (krwlock_t *)NULL; 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate mutex_exit(&class_lock); 1407c478bd9Sstevel@tonic-gate return (retval); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate static int 1457c478bd9Sstevel@tonic-gate getcidbyname_locked(char *clname, id_t *cidp) 1467c478bd9Sstevel@tonic-gate { 1477c478bd9Sstevel@tonic-gate sclass_t *clp; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&class_lock)); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate if (*clname == NULL) 1527c478bd9Sstevel@tonic-gate return (EINVAL); 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate for (clp = &sclass[0]; clp < &sclass[nclass]; clp++) { 1557c478bd9Sstevel@tonic-gate if (strcmp(clp->cl_name, clname) == 0) { 1567c478bd9Sstevel@tonic-gate *cidp = clp - &sclass[0]; 1577c478bd9Sstevel@tonic-gate return (0); 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate return (EINVAL); 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * Lookup a module by name. 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate int 1677c478bd9Sstevel@tonic-gate getcidbyname(char *clname, id_t *cidp) 1687c478bd9Sstevel@tonic-gate { 1697c478bd9Sstevel@tonic-gate int retval; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate mutex_enter(&class_lock); 1727c478bd9Sstevel@tonic-gate retval = getcidbyname_locked(clname, cidp); 1737c478bd9Sstevel@tonic-gate mutex_exit(&class_lock); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate return (retval); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate /* 1797c478bd9Sstevel@tonic-gate * Get the scheduling parameters of the thread pointed to by 1807c478bd9Sstevel@tonic-gate * tp into the buffer pointed to by parmsp. 1817c478bd9Sstevel@tonic-gate */ 1827c478bd9Sstevel@tonic-gate void 183*d4204c85Sraf parmsget(kthread_t *tp, pcparms_t *parmsp) 1847c478bd9Sstevel@tonic-gate { 1857c478bd9Sstevel@tonic-gate parmsp->pc_cid = tp->t_cid; 1867c478bd9Sstevel@tonic-gate CL_PARMSGET(tp, parmsp->pc_clparms); 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate /* 1917c478bd9Sstevel@tonic-gate * Check the validity of the scheduling parameters in the buffer 1927c478bd9Sstevel@tonic-gate * pointed to by parmsp. 1937c478bd9Sstevel@tonic-gate * Note that the format of the parameters may be changed by class 1947c478bd9Sstevel@tonic-gate * specific code which we call. 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate int 1977c478bd9Sstevel@tonic-gate parmsin(pcparms_t *parmsp, pc_vaparms_t *vaparmsp) 1987c478bd9Sstevel@tonic-gate { 1997c478bd9Sstevel@tonic-gate if (parmsp->pc_cid >= loaded_classes || parmsp->pc_cid < 1) 2007c478bd9Sstevel@tonic-gate return (EINVAL); 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * Call the class specific routine to validate class 2047c478bd9Sstevel@tonic-gate * specific parameters. 2057c478bd9Sstevel@tonic-gate * The input parameters are either in a pcparms structure (PC_SETPARMS) 2067c478bd9Sstevel@tonic-gate * or in a variable parameter structure (PC_SETXPARMS). In the 2077c478bd9Sstevel@tonic-gate * 'PC_SETPARMS' case vaparmsp is a NULL pointer and a CL_PARMSIN() 2087c478bd9Sstevel@tonic-gate * routine gets the parameter. Otherwise vaparmsp points to a variable 2097c478bd9Sstevel@tonic-gate * parameter structure and a CL_VAPARMSIN() routine gets the parameter. 2107c478bd9Sstevel@tonic-gate */ 2117c478bd9Sstevel@tonic-gate if (vaparmsp != NULL) 2127c478bd9Sstevel@tonic-gate return (CL_VAPARMSIN(&sclass[parmsp->pc_cid], 2137c478bd9Sstevel@tonic-gate parmsp->pc_clparms, vaparmsp)); 2147c478bd9Sstevel@tonic-gate else 2157c478bd9Sstevel@tonic-gate return (CL_PARMSIN(&sclass[parmsp->pc_cid], 2167c478bd9Sstevel@tonic-gate parmsp->pc_clparms)); 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* 2217c478bd9Sstevel@tonic-gate * Call the class specific code to do the required processing 2227c478bd9Sstevel@tonic-gate * before the scheduling parameters are copied out to the user. 2237c478bd9Sstevel@tonic-gate * Note that the format of the parameters may be changed by the 2247c478bd9Sstevel@tonic-gate * class specific code. 2257c478bd9Sstevel@tonic-gate */ 2267c478bd9Sstevel@tonic-gate int 2277c478bd9Sstevel@tonic-gate parmsout(pcparms_t *parmsp, pc_vaparms_t *vaparmsp) 2287c478bd9Sstevel@tonic-gate { 2297c478bd9Sstevel@tonic-gate return (CL_PARMSOUT(&sclass[parmsp->pc_cid], parmsp->pc_clparms, 2307c478bd9Sstevel@tonic-gate vaparmsp)); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate /* 2357c478bd9Sstevel@tonic-gate * Set the scheduling parameters of the thread pointed to by 2367c478bd9Sstevel@tonic-gate * targtp to those specified in the pcparms structure pointed 2377c478bd9Sstevel@tonic-gate * to by parmsp. If reqtp is non-NULL it points to the thread 2387c478bd9Sstevel@tonic-gate * that initiated the request for the parameter change and indicates 2397c478bd9Sstevel@tonic-gate * that our caller wants us to verify that the requesting thread 2407c478bd9Sstevel@tonic-gate * has the appropriate permissions. 2417c478bd9Sstevel@tonic-gate */ 2427c478bd9Sstevel@tonic-gate int 243*d4204c85Sraf parmsset(pcparms_t *parmsp, kthread_t *targtp) 2447c478bd9Sstevel@tonic-gate { 2457c478bd9Sstevel@tonic-gate caddr_t clprocp; 2467c478bd9Sstevel@tonic-gate int error; 2477c478bd9Sstevel@tonic-gate cred_t *reqpcredp; 2487c478bd9Sstevel@tonic-gate proc_t *reqpp = ttoproc(curthread); 2497c478bd9Sstevel@tonic-gate proc_t *targpp = ttoproc(targtp); 2507c478bd9Sstevel@tonic-gate id_t oldcid; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&pidlock)); 2537c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&targpp->p_lock)); 2547c478bd9Sstevel@tonic-gate if (reqpp != NULL) { 2557c478bd9Sstevel@tonic-gate mutex_enter(&reqpp->p_crlock); 2567c478bd9Sstevel@tonic-gate crhold(reqpcredp = reqpp->p_cred); 2577c478bd9Sstevel@tonic-gate mutex_exit(&reqpp->p_crlock); 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* 2607c478bd9Sstevel@tonic-gate * Check basic permissions. 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate if (!prochasprocperm(targpp, reqpp, reqpcredp)) { 2637c478bd9Sstevel@tonic-gate crfree(reqpcredp); 2647c478bd9Sstevel@tonic-gate return (EPERM); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate } else { 2677c478bd9Sstevel@tonic-gate reqpcredp = NULL; 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate if (parmsp->pc_cid != targtp->t_cid) { 2717c478bd9Sstevel@tonic-gate void *bufp = NULL; 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * Target thread must change to new class. 2747c478bd9Sstevel@tonic-gate */ 2757c478bd9Sstevel@tonic-gate clprocp = (caddr_t)targtp->t_cldata; 2767c478bd9Sstevel@tonic-gate oldcid = targtp->t_cid; 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* 2797c478bd9Sstevel@tonic-gate * Purpose: allow scheduling class to veto moves 2807c478bd9Sstevel@tonic-gate * to other classes. All the classes, except FSS, 2817c478bd9Sstevel@tonic-gate * do nothing except returning 0. 2827c478bd9Sstevel@tonic-gate */ 2837c478bd9Sstevel@tonic-gate error = CL_CANEXIT(targtp, reqpcredp); 2847c478bd9Sstevel@tonic-gate if (error) { 2857c478bd9Sstevel@tonic-gate /* 2867c478bd9Sstevel@tonic-gate * Not allowed to leave the class, so return error. 2877c478bd9Sstevel@tonic-gate */ 2887c478bd9Sstevel@tonic-gate crfree(reqpcredp); 2897c478bd9Sstevel@tonic-gate return (error); 2907c478bd9Sstevel@tonic-gate } else { 2917c478bd9Sstevel@tonic-gate /* 2927c478bd9Sstevel@tonic-gate * Pre-allocate scheduling class data. 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate if (CL_ALLOC(&bufp, parmsp->pc_cid, KM_NOSLEEP) != 0) { 2957c478bd9Sstevel@tonic-gate error = ENOMEM; /* no memory available */ 2967c478bd9Sstevel@tonic-gate crfree(reqpcredp); 2977c478bd9Sstevel@tonic-gate return (error); 2987c478bd9Sstevel@tonic-gate } else { 2997c478bd9Sstevel@tonic-gate error = CL_ENTERCLASS(targtp, parmsp->pc_cid, 3007c478bd9Sstevel@tonic-gate parmsp->pc_clparms, reqpcredp, bufp); 3017c478bd9Sstevel@tonic-gate crfree(reqpcredp); 3027c478bd9Sstevel@tonic-gate if (error) { 3037c478bd9Sstevel@tonic-gate CL_FREE(parmsp->pc_cid, bufp); 3047c478bd9Sstevel@tonic-gate return (error); 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate CL_EXITCLASS(oldcid, clprocp); 3097c478bd9Sstevel@tonic-gate } else { 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate /* 3127c478bd9Sstevel@tonic-gate * Not changing class 3137c478bd9Sstevel@tonic-gate */ 3147c478bd9Sstevel@tonic-gate error = CL_PARMSSET(targtp, parmsp->pc_clparms, 3157c478bd9Sstevel@tonic-gate curthread->t_cid, reqpcredp); 3167c478bd9Sstevel@tonic-gate crfree(reqpcredp); 3177c478bd9Sstevel@tonic-gate if (error) 3187c478bd9Sstevel@tonic-gate return (error); 3197c478bd9Sstevel@tonic-gate } 320*d4204c85Sraf schedctl_set_cidpri(targtp); 3217c478bd9Sstevel@tonic-gate return (0); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate /* 3267c478bd9Sstevel@tonic-gate * Copy all selected class parameters to the user. 3277c478bd9Sstevel@tonic-gate * The parameters are specified by a key. 3287c478bd9Sstevel@tonic-gate */ 3297c478bd9Sstevel@tonic-gate int 3309acbbeafSnn35248 vaparmsout(char *classp, pcparms_t *prmsp, pc_vaparms_t *vaparmsp, 3319acbbeafSnn35248 uio_seg_t seg) 3327c478bd9Sstevel@tonic-gate { 3337c478bd9Sstevel@tonic-gate char *clname; 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate ASSERT(MUTEX_NOT_HELD(&curproc->p_lock)); 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate if (classp != NULL) 3387c478bd9Sstevel@tonic-gate return (CL_VAPARMSOUT(&sclass[prmsp->pc_cid], 3397c478bd9Sstevel@tonic-gate prmsp->pc_clparms, vaparmsp)); 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate switch (vaparmsp->pc_vaparmscnt) { 3427c478bd9Sstevel@tonic-gate case 0: 3437c478bd9Sstevel@tonic-gate return (0); 3447c478bd9Sstevel@tonic-gate case 1: 3457c478bd9Sstevel@tonic-gate break; 3467c478bd9Sstevel@tonic-gate default: 3477c478bd9Sstevel@tonic-gate return (EINVAL); 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate if (vaparmsp->pc_parms[0].pc_key != PC_KY_CLNAME) 3517c478bd9Sstevel@tonic-gate return (EINVAL); 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate clname = sclass[prmsp->pc_cid].cl_name; 3549acbbeafSnn35248 if ((seg == UIO_USERSPACE ? copyout : kcopy)(clname, 3559acbbeafSnn35248 (void *)(uintptr_t)vaparmsp->pc_parms[0].pc_parm, 3567c478bd9Sstevel@tonic-gate MIN(strlen(clname) + 1, PC_CLNMSZ))) 3577c478bd9Sstevel@tonic-gate return (EFAULT); 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate return (0); 3607c478bd9Sstevel@tonic-gate } 361