nsc_proc.c revision fcf3ce441efd61da9bb2884968af01cb7c1452cc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*fn)(void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int ready;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&nsc_proc_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create a daemon (server) proc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If 'rt' is TRUE, then increase the scheduling priority of the lwp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Exactly how, if at all, this feature is implemented is at the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * discretion of nskernd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns 0 or errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_create_process(void (*func)(void *), void *arg, boolean_t rt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* user level returns error in nsk->data1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait for the child to start and check in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove from list of outstanding requests.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (nlwpp = &nsc_nlwp_top; (*nlwpp); nlwpp = &((*nlwpp)->next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Child lwp calls this function when it returns to the kernel.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if the args are still on the pending list. If they are, then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * run the required function. If they are not, then something went
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wrong, so just return back to userland and die.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*fn)(void *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check that the request is still on the list of work to do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (nlwp = nsc_nlwp_top; nlwp; nlwp = nlwp->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nlwp == (struct nsc_nlwp *)(unsigned long)arg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mark as ready */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create a thread that acquires an inter-node lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * mode - 0 (read), 1 (write).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lockp - used to return the opaque address of a sync structure, which
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * must be passed to nsc_do_unlock() later.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns 0 or errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* user level returns error in nsk->data1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait for the child to start and check in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* retrieve errno from child's lock operation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * error - remove from list of outstanding requests as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * child will not be checking in (nskernd_get() failed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or user thread create failed) or will not be waiting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (child thread lock failure).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* success, return argument for nsc_do_unlock() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find child on work list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (nlwp = nsc_nlwp_top; nlwp; nlwp = nlwp->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* signal unlock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Lock child thread calls this function when it returns to the kernel.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if the args are still on the pending list. If they are, then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * post the lock results and wait for the unlock. If they are not,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then something went wrong, so just return back to userland and die.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check that the request is still on the list of work to do
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (nlwp = nsc_nlwp_top; nlwp; nlwp = nlwp->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nlwp == (struct nsc_nlwp *)(unsigned long)arg) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* mark as ready */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Error - either this request is no longer on the work
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queue, or there was an error in the userland lock code
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in which case the lock caller (currently blocked in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_do_lock() will do the cleanup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no errors, so wait for an unlock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove self from list of outstanding requests.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (nlwpp = &nsc_nlwp_top; (*nlwpp); nlwpp = &((*nlwpp)->next)) {