libds.c revision 49b225e1cfa7bbf7738d4df0a03f18e3283426eb
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * CDDL HEADER START
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * The contents of this file are subject to the terms of the
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Common Development and Distribution License (the "License").
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * You may not use this file except in compliance with the License.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * or http://www.opensolaris.org/os/licensing.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * See the License for the specific language governing permissions
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * and limitations under the License.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * When distributing Covered Code, include this CDDL HEADER in each
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * If applicable, add the following below this CDDL HEADER, with the
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * fields enclosed by brackets "[]" replaced with your own identifying
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * information: Portions Copyright [yyyy] [name of copyright owner]
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * CDDL HEADER END
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
49b225e1cfa7bbf7738d4df0a03f18e3283426ebGavin Maltby * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Use is subject to license terms.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <stdio.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <fcntl.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <unistd.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <stdlib.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <strings.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <errno.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <sys/types.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <sys/sysevent.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <libsysevent.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include <sys/vlds.h>
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#include "libds.h"
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#define PTRTOUINT64(ptr) ((uint64_t)((uintptr_t)(ptr)))
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic char vlds_device[] =
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen "/devices/virtual-devices@100/channel-devices@200/"
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen "virtual-domain-service@0:vlds";
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensentypedef struct dslibentry {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_hdl_t dsl_hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint32_t dsl_flags;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen uint32_t dsl_tflags;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen char *dsl_service;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_ops_t dsl_ops;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen} dslibentry_t;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen/* dsl_tflags */
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen#define DSL_ENTRY_INUSE 0x0001 /* handle is currently active */
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen#define MIN_DSLIB_ENTRIES 64
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *dslibtab;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic int ndslib;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Lock to protect the dslibtab table. We only need to protect this
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * table for those functions which actually look at or modify the table:
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * service registration (ds_svc_reg/ds_clnt_reg), service unregistration
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * (ds_hdl_unreg) or during callbacks (ds_recv)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic mutex_t dslib_lock;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic int ds_fd = -1;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic char *ds_sid_name = "vlds";
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic evchan_t *ds_evchan;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Static functions internal to dslib.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *ds_hdl_to_dslibentry(ds_hdl_t hdl);
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensenstatic dslibentry_t *ds_new_dslibentry(void);
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensenstatic uint_t ds_service_count(char *service, boolean_t is_client);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *ds_lookup_dslibentry(char *service, boolean_t is_client);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *ds_register_dslibentry(ds_hdl_t hdl, char *service,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen boolean_t is_client);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic void ds_free_dslibentry(dslibentry_t *dsp, int force_unreg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic int ds_recv(sysevent_t *sep, void *arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic void ds_string_arg(vlds_string_t *dsp, char *str);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic int ds_register(ds_capability_t *cap, ds_ops_t *ops, uint_t flags);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_hdl_to_dslibentry(ds_hdl_t hdl)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen int i;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen for (i = 0, dsp = dslibtab; i < ndslib; i++, dsp++) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (hdl == dsp->dsl_hdl)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (dsp);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (NULL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_new_dslibentry(void)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen int newndslib;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((dsp = ds_hdl_to_dslibentry(NULL)) != NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (dsp);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /* double the size */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen newndslib = ndslib << 1;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((dslibtab = realloc(dslibtab, newndslib * sizeof (dslibentry_t)))
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen == NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (NULL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp = &dslibtab[ndslib];
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) memset(dsp, 0, (newndslib - ndslib) * sizeof (dslibentry_t));
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ndslib = newndslib;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (dsp);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensenstatic uint_t
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensends_service_count(char *service, boolean_t is_client)
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen{
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen int i;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen dslibentry_t *dsp;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen uint_t is_client_flag = is_client ? VLDS_REG_CLIENT : 0;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen uint_t count = 0;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen for (i = 0, dsp = dslibtab; i < ndslib; i++, dsp++) {
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen if (dsp->dsl_hdl != NULL &&
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen strcmp(dsp->dsl_service, service) == 0 &&
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen (dsp->dsl_flags & VLDS_REG_CLIENT) == is_client_flag) {
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen count++;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen }
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen }
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen return (count);
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen}
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_lookup_dslibentry(char *service, boolean_t is_client)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen int i;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint_t is_client_flag = is_client ? VLDS_REG_CLIENT : 0;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen for (i = 0, dsp = dslibtab; i < ndslib; i++, dsp++) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (dsp->dsl_hdl != NULL &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen strcmp(dsp->dsl_service, service) == 0 &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (dsp->dsl_flags & VLDS_REG_CLIENT) == is_client_flag) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (dsp);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (NULL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic dslibentry_t *
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_register_dslibentry(ds_hdl_t hdl, char *service, boolean_t is_client)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp, *orig_dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen if ((dsp = ds_hdl_to_dslibentry(hdl)) != NULL) {
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen dsp->dsl_tflags |= DSL_ENTRY_INUSE;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (dsp);
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((orig_dsp = ds_lookup_dslibentry(service, is_client)) == NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (NULL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen if ((orig_dsp->dsl_tflags & DSL_ENTRY_INUSE) == 0) {
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen /* use the original structure entry */
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen orig_dsp->dsl_tflags |= DSL_ENTRY_INUSE;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen orig_dsp->dsl_hdl = hdl;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen return (orig_dsp);
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen /* allocate a new structure entry */
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen if ((dsp = ds_new_dslibentry()) == NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (NULL);
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen *dsp = *orig_dsp;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen dsp->dsl_service = strdup(orig_dsp->dsl_service);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->dsl_hdl = hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (dsp);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Want to leave an entry in the dslib table even though all the
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * handles may have been unregistered for it.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic void
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_free_dslibentry(dslibentry_t *dsp, int force_unreg)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint_t nhdls;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /*
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen * Find out if we have 1 or 2 or more handles for the given
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen * service. Having one implies that we want to leave the entry
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen * intact but marked as not in use unless this is a ds_unreg_hdl
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * (force_unreg is true).
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen nhdls = ds_service_count(dsp->dsl_service,
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen (dsp->dsl_flags & VLDS_REG_CLIENT) != 0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen if ((nhdls == 1 && force_unreg) || nhdls >= 2) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->dsl_hdl = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (dsp->dsl_service) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen free(dsp->dsl_service);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) memset(dsp, 0, sizeof (dslibentry_t));
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen } else if (nhdls == 1) {
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen dsp->dsl_tflags &= ~DSL_ENTRY_INUSE;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*ARGSUSED*/
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic int
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_recv(sysevent_t *sep, void *arg)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nvlist_t *nvl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint64_t hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_ver_t ver;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_domain_hdl_t dhdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uchar_t *bufp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen boolean_t is_client;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint_t buflen;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen char *subclass;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen char *servicep;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_cb_arg_t cb_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen subclass = sysevent_get_subclass_name(sep);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (sysevent_get_attr_list(sep, &nvl) != 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (nvlist_lookup_uint64(nvl, VLDS_HDL, &hdl) == 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (strcmp(subclass, ESC_VLDS_REGISTER) == 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen void (*reg_cb)(ds_hdl_t, ds_cb_arg_t, ds_ver_t *,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_domain_hdl_t) = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (nvlist_lookup_string(nvl, VLDS_SERVICE_ID,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen &servicep) == 0 &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nvlist_lookup_boolean_value(nvl, VLDS_ISCLIENT,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen &is_client) == 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_lock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((dsp = ds_register_dslibentry(hdl,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen servicep, is_client)) != NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen reg_cb = dsp->dsl_ops.ds_reg_cb;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen cb_arg = dsp->dsl_ops.cb_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (reg_cb != NULL &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nvlist_lookup_uint64(nvl, VLDS_DOMAIN_HDL,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen &dhdl) == 0 &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nvlist_lookup_uint16(nvl, VLDS_VER_MAJOR,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen &ver.major) == 0 &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nvlist_lookup_uint16(nvl, VLDS_VER_MINOR,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen &ver.minor) == 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (reg_cb)((ds_hdl_t)hdl, cb_arg, &ver,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dhdl);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen } else if (strcmp(subclass, ESC_VLDS_UNREGISTER) == 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen void (*unreg_cb)(ds_hdl_t, ds_cb_arg_t) = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_lock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((dsp = ds_hdl_to_dslibentry(hdl)) != NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen unreg_cb = dsp->dsl_ops.ds_unreg_cb;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen cb_arg = dsp->dsl_ops.cb_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_free_dslibentry(dsp, 0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (unreg_cb != NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (unreg_cb)((ds_hdl_t)hdl, cb_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen } else if (strcmp(subclass, ESC_VLDS_DATA) == 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen void (*data_cb)(ds_hdl_t, ds_cb_arg_t, void *,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen size_t) = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_lock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((dsp = ds_hdl_to_dslibentry(hdl)) != NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen data_cb = dsp->dsl_ops.ds_data_cb;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen cb_arg = dsp->dsl_ops.cb_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (data_cb != NULL &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nvlist_lookup_byte_array(nvl, VLDS_DATA, &bufp,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen &buflen) == 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (data_cb)((ds_hdl_t)hdl, cb_arg, bufp, buflen);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nvlist_free(nvl);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic void
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_string_arg(vlds_string_t *dsp, char *str)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (str == NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->vlds_strp = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->vlds_strlen = 0;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen } else {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->vlds_strp = PTRTOUINT64(str);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->vlds_strlen = strlen(str) + 1;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic int
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_init_sysev(void)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen char evchan_name[MAX_CHNAME_LEN];
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) sprintf(evchan_name, VLDS_SYSEV_CHAN_FMT, (int)getpid());
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (sysevent_evc_bind(evchan_name, &ds_evchan, 0) != 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (sysevent_evc_subscribe(ds_evchan, ds_sid_name, EC_VLDS,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_recv, NULL, 0) != 0) {
49b225e1cfa7bbf7738d4df0a03f18e3283426ebGavin Maltby (void) sysevent_evc_unbind(ds_evchan);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_evchan = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_init(void)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd >= 0)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((ds_fd = open(vlds_device, 0)) < 0)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (dslibtab == NULL) {
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen dslibtab = malloc(sizeof (dslibentry_t) * MIN_DSLIB_ENTRIES);
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen if (dslibtab == NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = ENOMEM);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ndslib = MIN_DSLIB_ENTRIES;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) memset(dslibtab, 0, sizeof (dslibentry_t) * ndslib);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_init(&dslib_lock, USYNC_THREAD, NULL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenstatic int
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_register(ds_capability_t *cap, ds_ops_t *ops, uint_t flags)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_svc_reg_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_cap_t vlds_cap;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_ver_t vlds_vers[VLDS_MAX_VERS];
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint64_t hdl_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_hdl_t hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint_t nhdls;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen int i;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (cap == NULL || ops == NULL || cap->svc_id == NULL ||
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen cap->vers == NULL || (flags & (~VLDS_REG_CLIENT)) != 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EINVAL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (cap->nvers > VLDS_MAX_VERS) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EINVAL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0 && (errno = ds_init()) != 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_hdl_lookup(cap->svc_id, (flags & VLDS_REG_CLIENT), NULL, 1,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen &nhdls) == 0 && nhdls == 1) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EALREADY);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_lock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((dsp = ds_new_dslibentry()) == NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = ENOMEM);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /* Setup device driver capability structure. */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /* service string */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_string_arg(&vlds_cap.vlds_service, cap->svc_id);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /* version array */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen for (i = 0; i < cap->nvers; i++) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_vers[i].vlds_major = cap->vers[i].major;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_vers[i].vlds_minor = cap->vers[i].minor;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_cap.vlds_versp = PTRTOUINT64(vlds_vers);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_cap.vlds_nver = cap->nvers;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Format args for VLDS_SVC_REG ioctl.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_capp = PTRTOUINT64(&vlds_cap);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /* op flags */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ops->ds_reg_cb != NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen flags |= VLDS_REGCB_VALID;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ops->ds_unreg_cb != NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen flags |= VLDS_UNREGCB_VALID;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ops->ds_data_cb != NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen flags |= VLDS_DATACB_VALID;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_reg_flags = flags;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /* returned handle */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_hdlp = PTRTOUINT64(&hdl_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_SVC_REG, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Setup user callback sysevent channel.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((flags & VLDS_ANYCB_VALID) != 0 && ds_evchan == NULL &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_init_sysev() != 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) ioctl(ds_fd, VLDS_UNREG_HDL, &vlds_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen hdl = hdl_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen /*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Set entry values in dslibtab.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->dsl_hdl = hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->dsl_flags = flags;
ba9236fbcb49a99c7d71c0c25d1e45cb2a75ac78Mike Christensen dsp->dsl_tflags = 0;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->dsl_service = strdup(cap->svc_id);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dsp->dsl_ops = *ops;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Registers a service provider. Kicks off the handshake with other
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * domain(s) to announce servce. Callback events are as described above.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_svc_reg(ds_capability_t *cap, ds_ops_t *ops)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (ds_register(cap, ops, 0));
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Registers interest in a service from a specific domain. When that
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * service is registered, the register callback is invoked. When that
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * service is unregistered, the unregister callback is invoked. When
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * data is received, the receive data callback is invoked.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_clnt_reg(ds_capability_t *cap, ds_ops_t *ops)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (ds_register(cap, ops, VLDS_REG_CLIENT));
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Given a service name and type, returns the existing handle(s), if
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * one or more exist. This could be used to poll for the connection being
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * registered or unregistered, rather than using the register/unregister
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * callbacks.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_hdl_lookup(char *service, boolean_t is_client, ds_hdl_t *hdlsp,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint_t maxhdls, uint_t *nhdlsp)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_hdl_lookup_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint64_t nhdls_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen errno = 0;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EBADF);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (service == NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EINVAL);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_string_arg(&vlds_arg.vlds_service, service);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_isclient = is_client ? VLDS_REG_CLIENT : 0;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_hdlsp = PTRTOUINT64(hdlsp);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_maxhdls = maxhdls;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_nhdlsp = PTRTOUINT64(&nhdls_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_HDL_LOOKUP, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *nhdlsp = nhdls_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Given a handle, return its associated domain.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_domain_lookup(ds_hdl_t hdl, ds_domain_hdl_t *dhdlp)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_dmn_lookup_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint64_t dhdl_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EBADF);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_hdl = hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_dhdlp = PTRTOUINT64(&dhdl_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_DMN_LOOKUP, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (dhdlp) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *dhdlp = dhdl_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Unregisters either a service or an interest in that service
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * indicated by the supplied handle.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_unreg_hdl(ds_hdl_t hdl)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_unreg_hdl_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_lock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if ((dsp = ds_hdl_to_dslibentry(hdl)) != NULL) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_free_dslibentry(dsp, 1);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd >= 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_hdl = hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) ioctl(ds_fd, VLDS_UNREG_HDL, &vlds_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Send data to the appropriate service provider or client
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * indicated by the provided handle. The sender will block
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * until the message has been sent. There is no guarantee
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * that multiple calls to ds_send_msg by the same thread
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * will result in the data showing up at the receiver in
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * the same order as sent. If multiple messages are required,
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * it will be up to the sender and receiver to implement a
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * protocol.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_send_msg(ds_hdl_t hdl, void *buf, size_t buflen)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_send_msg_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EBADF);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_hdl = hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_bufp = PTRTOUINT64(buf);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_buflen = buflen;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_SEND_MSG, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Receive data from the appropriate service provider or client
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * indicated by the provided handle. The sender will block
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * until a message has been received.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_recv_msg(ds_hdl_t hdl, void *buf, size_t buflen, size_t *msglen)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_recv_msg_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint64_t msglen_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EBADF);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_hdl = hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_bufp = PTRTOUINT64(buf);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_buflen = buflen;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_msglenp = PTRTOUINT64(&msglen_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_RECV_MSG, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (errno == EFBIG && msglen) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *msglen = msglen_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (msglen) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *msglen = msglen_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_isready(ds_hdl_t hdl, boolean_t *is_ready)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_hdl_isready_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint64_t is_ready_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EBADF);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_hdl = hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_isreadyp = PTRTOUINT64(&is_ready_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_HDL_ISREADY, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *is_ready = (is_ready_arg != 0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Given a domain name, return its associated domain handle.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_dom_name_to_hdl(char *domain_name, ds_domain_hdl_t *dhdlp)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_dom_nam2hdl_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint64_t dhdl_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EBADF);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_string_arg(&vlds_arg.vlds_domain_name, domain_name);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_dhdlp = PTRTOUINT64(&dhdl_arg);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_DOM_NAM2HDL, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (dhdlp) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen *dhdlp = dhdl_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen/*
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen * Given a domain handle, return its associated domain name.
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen */
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenint
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_dom_hdl_to_name(ds_domain_hdl_t dhdl, char *domain_name, uint_t maxnamlen)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_dom_hdl2nam_arg_t vlds_arg;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno = EBADF);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_dhdl = dhdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_domain_name.vlds_strp = PTRTOUINT64(domain_name);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen vlds_arg.vlds_domain_name.vlds_strlen = maxnamlen;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ioctl(ds_fd, VLDS_DOM_HDL2NAM, &vlds_arg) < 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (errno);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen return (0);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenvoid
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_unreg_svc(char *service, boolean_t is_client)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_hdl_t hdl;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen uint_t nhdls;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen while (ds_hdl_lookup(service, is_client, &hdl, 1, &nhdls) == 0 &&
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen nhdls == 1) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) ds_unreg_hdl(hdl);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensenvoid
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensends_fini(void)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen{
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen int i;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibentry_t *dsp;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_fd >= 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) close(ds_fd);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_fd = -1;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ds_evchan) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) sysevent_evc_unsubscribe(ds_evchan, ds_sid_name);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) sysevent_evc_unbind(ds_evchan);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ds_evchan = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (ndslib > 0) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_lock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen for (i = 0, dsp = dslibtab; i < ndslib; i++, dsp++) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (dsp->dsl_hdl == NULL)
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen continue;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen if (dsp->dsl_service) {
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen free(dsp->dsl_service);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen free(dslibtab);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen ndslib = 0;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen dslibtab = NULL;
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_unlock(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen (void) mutex_destroy(&dslib_lock);
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen }
30588217a56ff2c9137248fb2e5065c4f0101459Mike Christensen}