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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _SV_IMPL_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _SV_IMPL_H
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern "C" {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Storage Volume Character and Block Driver (SV)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Private header file.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if defined(_KERNEL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Locking.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Define SV_SLEEP_LOCK to get full sleep lock semantics (ie. mutex not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * held across calls to sdctl functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * #define SV_SLEEP_LOCK
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Misc defines, enums.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteenum { SV_DISABLE = 0, SV_PENDING, SV_ENABLE };
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Guard device clients
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef int64_t sv_gid_t; /* bitmask */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct sv_gclient_s {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sv_gclient_s *sg_next; /* linked list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *sg_name; /* name of client */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_gid_t sg_id; /* id (bitmask) of client */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sv_gclient_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Hashing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SV_MAJOR_HASH_CNT & SV_MINOR_HASH_CNT should be prime.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In a given system, there is likely to be one or two major devices in use.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Examples are:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SD - Direct Attached Storage (SCSI-2/3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SSD - SAN Direct Attached Storage FC SCSI-2/3
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * SVM - Solaris Volume Manager
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * VxVM - Veritas Volume Manager
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Global - Sun Cluster Global Devices
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For a typical system, there may be a 10s to 100s of minor devices configured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * per major device, but most are likely to be configured under a single major
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * number. SV_MINOR_HASH_CNT has been chosen to ensure that the hash chains are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not too long (one or two devices), for the worst case.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SV_MAJOR_HASH_CNT 3 /* # hash buckets per system */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SV_MAJOR_HASH(min) ((min) % SV_MAJOR_HASH_CNT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SV_MINOR_HASH_CNT 37 /* # hash buckets per major */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SV_MINOR_HASH(min) ((min) % SV_MINOR_HASH_CNT)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Per major device structure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct sv_maj_s {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct dev_ops *sm_dev_ops;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_strategy)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_awrite)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_write)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_ioctl)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_close)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_aread)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_read)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*sm_open)();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte major_t sm_major; /* Major device # */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sm_flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int sm_inuse;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int sm_seq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sv_dev_s *sm_hash[SV_MINOR_HASH_CNT]; /* Minor Hash Table */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sv_maj_s *sm_next; /* Major Hash Chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sv_maj_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Per configured sv structure.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct sv_dev_s {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sv_dev_s *sv_hash; /* Minor hash chain */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krwlock_t sv_lock; /* mutual exclusion */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t sv_olock; /* mutual exclusion for otyp flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dev_t sv_dev; /* underlying dev_t */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_fd_t *sv_fd; /* underlying fd */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t sv_maxfbas; /* maxfbas accepted by I/O module */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t sv_nblocks; /* size of device */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sv_state; /* state */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sv_flag; /* internal flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_gid_t sv_gclients; /* bitmask of all guard clients */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sv_gid_t sv_gkernel; /* bitmask of kernel guard clients */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sv_openlcnt; /* # of OTYP_LYR opens whilst failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t sv_timestamp; /* time of successful {en,dis}able */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ldi_handle_t sv_lh; /* layered open handle */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *sv_pending; /* the thread setting SV_PENDING */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} sv_dev_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * private functions exported from nskern to sv.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int nskern_partition(dev_t, int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int nskernd_isdaemon(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _KERNEL */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef __cplusplus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* _SV_IMPL_H */