fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/resource.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/priocntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/rtpriocntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/tspriocntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/wait.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <thread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <fcntl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <syslog.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/cfg.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsc_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nskernd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/mkdev.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/sv_efi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic const char *rdev = "/dev/nsctl";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Define a minimal user stack size in bytes over and above the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * libthread THR_STACK_MIN minimum value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This stack size needs to be sufficient to run _newlwp() and then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ioctl() down into the kernel.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define NSK_STACK_SIZE 512
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LWP scheduling control switches.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allow_pri - set to non-zero to enable priocntl() manipulations of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * created LWPs.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allow_rt - set to non-zero to use the RT rather than the TS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * scheduling class when manipulating the schduling
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters for an LWP. Only used if allow_pri is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int allow_pri = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int allow_rt = 0; /* disallow - bad interactions with timeout() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int nsctl_fd = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int sigterm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int nthreads; /* number of threads in the kernel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int exiting; /* shutdown in progress flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic mutex_t thr_mutex = DEFAULTMUTEX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic mutex_t cfg_mutex = DEFAULTMUTEX;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int cl_nodeid = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int display_msg = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int delay_time = 30;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusage(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("usage: nskernd\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesighand(int sig)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sig == SIGTERM) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sigterm++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns: 1 - can enter kernel; 0 - shutdown in progress, do not enter kernel
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenthread_inc(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_lock(&thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (exiting) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cannot enter kernel as nskernd is being shutdown - exit */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nthreads++;
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenthread_dec(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_lock(&thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nthreads--;
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns: 1 - can shutdown; 0 - unable to shutdown
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecanshutdown(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte time_t start_delay;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_lock(&thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nthreads > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (display_msg) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: unable to shutdown: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%d kernel threads in use\n"), nthreads);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte start_delay = time(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nthreads > 0 && (time(0) - start_delay) < delay_time) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&thr_mutex);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sleep(1);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_lock(&thr_mutex);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: delay shutdown: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%d kernel threads in use\n"), nthreads);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nthreads > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exiting = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flag shutdown in progress */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exiting = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&thr_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * returns: 1 - shutdown successful; 0 - unable to shutdown
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteshutdown(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nskernd data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsctl_fd < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&data, sizeof (data));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_STOP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!canshutdown()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ioctl(nsctl_fd, NSCIOC_NSKERND, &data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (errno != EINTR || !sigterm) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: NSKERND_STOP failed\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First function run by a NSKERND_NEWLWP thread.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determines if it needs to change the scheduling priority of the LWP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and then calls back into the kernel.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_newlwp(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nskernd nsk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pcparms_t pcparms;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pcinfo_t pcinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy arguments onto stack and free heap memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(arg, &nsk, sizeof (nsk));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsk.data2 && allow_pri) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* increase the scheduling priority of this LWP */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&pcinfo, sizeof (pcinfo));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(pcinfo.pc_clname, allow_rt ? "RT" : "TS");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (priocntl(0, 0, PC_GETCID, (char *)&pcinfo) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext(
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "nskernd: priocntl(PC_GETCID) failed: %s\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto pri_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&pcparms, sizeof (pcparms));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pcparms.pc_cid = pcinfo.pc_cid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (allow_rt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((rtparms_t *)pcparms.pc_clparms)->rt_pri =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (pri_t)0; /* minimum RT priority */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((rtparms_t *)pcparms.pc_clparms)->rt_tqsecs =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uint_t)RT_TQDEF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((rtparms_t *)pcparms.pc_clparms)->rt_tqnsecs =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RT_TQDEF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tsparms_t *)pcparms.pc_clparms)->ts_uprilim =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tsinfo_t *)&pcinfo.pc_clinfo)->ts_maxupri;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tsparms_t *)pcparms.pc_clparms)->ts_upri =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((tsinfo_t *)&pcinfo.pc_clinfo)->ts_maxupri;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (priocntl(P_LWPID, P_MYID,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte PC_SETPARMS, (char *)&pcparms) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext(
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "nskernd: priocntl(PC_SETPARMS) failed: %s\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortepri_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nthread_inc()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ioctl(nsctl_fd, NSCIOC_NSKERND, &nsk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nthread_dec();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Start a new thread bound to an LWP.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is the user level side of nsc_create_process().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenewlwp(struct nskernd *req)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nskernd *nskp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thread_t tid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nskp = malloc(sizeof (*nskp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!nskp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nskernd: malloc(%d) failed\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki sizeof (*nskp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->data1 = (uint64_t)ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy args for child */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(req, nskp, sizeof (*nskp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = thr_create(NULL, (THR_MIN_STACK + NSK_STACK_SIZE),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _newlwp, nskp, THR_BOUND|THR_DETACHED, &tid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* thr_create failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("nskernd: thr_create failed: %s\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->data1 = (uint64_t)errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nskp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* success - _newlwp() will free nskp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->data1 = (uint64_t)0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortelog_iibmp_err(char *set, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CFGFILE *cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char key[CFG_MAX_KEY];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char buf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char newflags[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char outbuf[CFG_MAX_BUF];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *mst, *shd, *bmp, *mode, *ovr, *cnode, *opt, *grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setno, found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int setlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pid_t pid = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (set && *set) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte setlen = strlen(set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_lock(&cfg_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg = cfg_open("");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&cfg_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENXIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg_lock(cfg, CFG_WRLOCK)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&cfg_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pid = fork();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pid == -1) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nskernd: Error forking\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (errno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (pid > 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stdout, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nskernd: Attempting deferred bitmap error\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_lock(&cfg_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg = cfg_open("");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!cfg) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&cfg_mutex);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nskernd: Failed cfg_open, deferred bitmap\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENXIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sooner or later, this lock will be free */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (!cfg_lock(cfg, CFG_WRLOCK))
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) sleep(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find the proper set number */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (setno = 1; !found; setno++) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) snprintf(key, CFG_MAX_KEY, "ii.set%d", setno);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mst = strtok(buf, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte shd = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(shd, set, setlen) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bmp = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ovr = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnode = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte opt = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp = strtok(NULL, " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (found) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* were there flags in the options field already? */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) snprintf(newflags, CFG_MAX_BUF, "%s=0x%x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSKERN_II_BMP_OPTION, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (opt && strcmp(opt, "-") != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(newflags, CFG_MAX_BUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte opt = strtok(opt, ";");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (opt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(opt, NSKERN_II_BMP_OPTION,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(NSKERN_II_BMP_OPTION)) != 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(newflags, ";");
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcat(newflags, opt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) snprintf(key, CFG_MAX_KEY, "ii.set%d", setno);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) snprintf(outbuf, CFG_MAX_BUF, "%s %s %s %s %s %s %s %s",
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki mst, shd, bmp, mode, ovr, cnode, newflags, grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_put_cstring(cfg, key, outbuf, CFG_MAX_BUF) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf("Failed to put [%s]\n", outbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENXIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) cfg_commit(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext(
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki "nskernd: Failed deferred bitmap [%s]\n"), set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_unlock(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&cfg_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we are the fork'ed client, just exit, if parent just return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*NOTREACHED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First function run by a NSKERND_LOCK thread.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Opens dscfg and locks it,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and then calls back into the kernel.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Incoming:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data1 is the kernel address of the sync structure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data2 is read(0)/write(1) lock mode.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data1 as incoming.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data2 errno.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_dolock(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nskernd nsk;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CFGFILE *cfg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int locked;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mode;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy arguments onto stack and free heap memory */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(arg, &nsk, sizeof (nsk));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_lock(&cfg_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg = cfg_open("");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("nskernd: cfg_open failed: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENXIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsk.data2 == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = CFG_RDLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode = CFG_WRLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg_lock(cfg, mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: cfg_lock failed: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return to kernel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsk.data2 = (uint64_t)rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nthread_inc()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ioctl(nsctl_fd, NSCIOC_NSKERND, &nsk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nthread_dec();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cleanup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (locked) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_unlock(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte locked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cfg != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg_close(cfg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cfg = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) mutex_unlock(&cfg_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Inter-node lock thread.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is the user level side of nsc_rmlock().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedolock(struct nskernd *req)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nskernd *nskp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thread_t tid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create a new thread to do the lock and return to kernel */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nskp = malloc(sizeof (*nskp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!nskp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("nskernd:dolock: malloc(%d) failed\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (*nskp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->data1 = (uint64_t)ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy args for child */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(req, nskp, sizeof (*nskp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = thr_create(NULL, (THR_MIN_STACK + NSK_STACK_SIZE),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _dolock, nskp, THR_BOUND|THR_DETACHED, &tid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* thr_create failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("nskernd: thr_create failed: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->data1 = (uint64_t)errno;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nskp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* success - _dolock() will free nskp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte req->data1 = (uint64_t)0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Convenience code for engineering test of multi-terabyte volumes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * zvol (part of zfs) does not support DKIOCPARTITION but does use EFI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * labels. This code allocates a simple efi label structure and ioctls
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to extract the size of a zvol. It only handles the minimal EFI ioctl
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * implementation in zvol.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortezvol_bsize(char *path, uint64_t *size, const int pnum)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat64 stb1, stb2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct dk_minfo dkm;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl_nodeid || pnum != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = open(path, O_RDONLY)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat64("/devices/pseudo/zfs@0:zfs", &stb1) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fstat64(fd, &stb2) != 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !S_ISCHR(stb1.st_mode) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !S_ISCHR(stb2.st_mode) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte major(stb1.st_rdev) != major(stb2.st_rdev)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ioctl(fd, DKIOCGMEDIAINFO, (void *)&dkm);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *size = LE_64(dkm.dki_capacity) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (dkm.dki_lbsize) / 512;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_bsize(uint64_t raw_fd, uint64_t *size, int *partitionp, char *path)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nscioc_bsize bsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DKIOCPARTITION
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct partition64 p64;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct dk_cinfo dki_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct vtoc vtoc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *partitionp = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *size = (uint64_t)0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dki_info.dki_partition = (ushort_t)-1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bsize.dki_info = (uint64_t)(unsigned long)&dki_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bsize.vtoc = (uint64_t)(unsigned long)&vtoc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bsize.raw_fd = raw_fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bsize.efi = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fd = open(rdev, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, NSCIOC_BSIZE, &bsize) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dki_info.dki_partition != (ushort_t)-1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* assume part# is ok and just the size failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *partitionp = (int)dki_info.dki_partition;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DKIOCPARTITION
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* see if this is an EFI label */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&p64, sizeof (p64));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p64.p_partno = (uint_t)*partitionp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ioctl(fd, DKIOCPARTITION, &p64)) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *size = (uint64_t)p64.p_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bsize.p64 = (uint64_t)(unsigned long)&p64;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bsize.efi = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(fd, NSCIOC_BSIZE, &bsize) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* see if this is a zvol */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte zvol_bsize(path, size, *partitionp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *size = (uint64_t)p64.p_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* DKIOCPARTITION */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *partitionp = (int)dki_info.dki_partition;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vtoc.v_sanity != VTOC_SANE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vtoc.v_version != V_VERSION && vtoc.v_version != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dki_info.dki_partition > V_NUMPAR)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *size = (uint64_t)vtoc.v_part[(int)dki_info.dki_partition].p_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscluster(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find out if we are running in a cluster
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_nodeid = cfg_iscluster();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl_nodeid > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cl_nodeid == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, "%s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: unable to ascertain environment"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* NOTREACHED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Runtime Solaris release checking - build release == runtime release
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is always considered success, so only keep entries in the map for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the special cases.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic nsc_release_t nskernd_rel_map[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* { "5.10", "5.10" }, */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { "5.11", "5.10" },
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte { NULL, NULL }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef lint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define main nskernd_main
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED1 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const char *dir = "/";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nskernd data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rlimit rl;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i, run, rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int partition;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *reqd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int syncpipe[2];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int startup;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) setlocale(LC_ALL, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) textdomain("nskernd");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_check_release(BUILD_REV_STR, nskernd_rel_map, &reqd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: unable to determine the current "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Solaris release: %s\n"), strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc == FALSE) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: incorrect Solaris release "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "(requires %s)\n"), reqd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Usage: <progname> [-g] [-d <seconds to delay>]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((i = getopt(argc, argv, "gd:")) != EOF) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (i) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'g':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte display_msg = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'd':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay_time = atoi(optarg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (delay_time <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay_time = 30;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Usage: nskernd [-g] [-d <seconds to delay>]");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (chroot(dir) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nskernd: chroot failed: %s\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (chdir(dir) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nskernd: chdir failed: %s\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determine if we are in a Sun Cluster or not, before fork'ing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscluster();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * create a pipe to synchronise the parent with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * child just before it enters its service loop.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pipe(syncpipe) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("nskernd: cannot create pipe: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Fork off a child that becomes the daemon.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = fork()) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(syncpipe[1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait for the close of the pipe.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we get a char back, indicates good
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * status from child, so exit 0.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we get a zero length read, then the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * child has failed, so we do too.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = read(syncpipe[0], &c, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit((n <= 0) ? 1 : 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nskernd: cannot fork: %s\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In child - become daemon.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* use closefrom(3C) from PSARC/2000/193 when possible */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < syncpipe[1]; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte closefrom(syncpipe[1] + 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) open("/dev/console", O_WRONLY|O_APPEND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) dup(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) dup(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) setpgrp();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Ignore all signals apart from SIGTERM.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 1; i < _sys_nsig; i++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sigset(i, SIG_IGN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) sigset(SIGTERM, sighand);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Increase the number of fd's that can be open.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rl.rlim_cur = RLIM_INFINITY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rl.rlim_max = RLIM_INFINITY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (setrlimit(RLIMIT_NOFILE, &rl) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: could not increase RLIMIT_NOFILE: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: the maximum number of nsctl open "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "devices may be reduced\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Open /dev/nsctl and startup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsctl_fd = open(rdev, O_RDONLY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsctl_fd < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nskernd: unable to open %s\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&data, sizeof (data));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_START;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.data1 = (uint64_t)cl_nodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte run = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte startup = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (run) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ioctl(nsctl_fd, NSCIOC_NSKERND, &data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try and do kernel cleanup and exit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (shutdown()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte run = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sigterm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: NSCIOC_NSKERND failed: %s\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strerror(errno));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (sigterm) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* SIGTERM received - terminate */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (data.command != NSKERND_START &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (data.command != NSKERND_STOP ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.data1 != (uint64_t)1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* need to do kernel cleanup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (shutdown()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte run = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sigterm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_START;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.data1 = (uint64_t)cl_nodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* just quit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (canshutdown()) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte run = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cannot shutdown - threads active */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sigterm = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_START;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.data1 = (uint64_t)cl_nodeid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (startup) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char c = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) write(syncpipe[1], &c, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(syncpipe[1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte startup = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (data.command) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSKERND_START: /* (re)start completion */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 1) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: already started\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte run = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc == 2) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: stopped by kernel\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte run = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_WAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSKERND_STOP: /* kernel telling daemon to stop */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (data.data1 != (uint64_t)1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) shutdown();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte run = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSKERND_BSIZE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kernel requesting partsize
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data1 - size return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * data2 - raw_fd (entry)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - partition number (return)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte partition = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte get_bsize(data.data2, &data.data1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &partition, data.char1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.data2 = (uint64_t)partition;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_WAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSKERND_NEWLWP: /* kernel requesting a new LWP */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte newlwp(&data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_WAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSKERND_LOCK: /* kernel requesting lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dolock(&data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_WAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSKERND_WAIT: /* kernel retrying wait */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the kernel thread can be woken by the dr config
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * utilities (ie cfgadm) therefore we just reissue
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the wait.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case NSKERND_IIBITMAP:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = log_iibmp_err(data.char1, (int)data.data1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.data1 = (uint64_t)rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_WAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte gettext("nskernd: unknown command %d"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data.command = NSKERND_WAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(nsctl_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}