xref: /titanic_51/usr/src/uts/common/avs/ns/sv/sv_impl.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SV_IMPL_H
27 #define	_SV_IMPL_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * Storage Volume Character and Block Driver (SV)
35  * Private header file.
36  */
37 
38 #if defined(_KERNEL)
39 
40 /*
41  * Locking.
42  * Define SV_SLEEP_LOCK to get full sleep lock semantics (ie. mutex not
43  * held across calls to sdctl functions.
44  *
45  * #define SV_SLEEP_LOCK
46  */
47 
48 
49 /*
50  * Misc defines, enums.
51  */
52 
53 enum { SV_DISABLE = 0, SV_PENDING, SV_ENABLE };
54 
55 
56 /*
57  * Guard device clients
58  */
59 
60 typedef int64_t sv_gid_t;		/* bitmask */
61 
62 typedef struct sv_gclient_s {
63 	struct sv_gclient_s *sg_next;	/* linked list */
64 	char		*sg_name;	/* name of client */
65 	sv_gid_t	sg_id;		/* id (bitmask) of client */
66 } sv_gclient_t;
67 
68 
69 /*
70  * Hashing.
71  *
72  * SV_MAJOR_HASH_CNT & SV_MINOR_HASH_CNT should be prime.
73  *
74  * In a given system, there is likely to be one or two major devices in use.
75  *
76  * Examples are:
77  *	SD	- Direct Attached Storage (SCSI-2/3)
78  *	SSD	- SAN Direct Attached Storage FC SCSI-2/3
79  *	SVM	- Solaris Volume Manager
80  *	VxVM	- Veritas Volume Manager
81  *	Global	- Sun Cluster  Global Devices
82  *
83  * For a typical system, there may be a 10s to 100s of minor devices configured
84  * per major device, but most are likely to be configured under a single major
85  * number. SV_MINOR_HASH_CNT has been chosen to ensure that the hash chains are
86  * not too long (one or two devices), for the worst case.
87  */
88 
89 #define	SV_MAJOR_HASH_CNT	3	/* # hash buckets per system */
90 #define	SV_MAJOR_HASH(min)	((min) % SV_MAJOR_HASH_CNT)
91 
92 #define	SV_MINOR_HASH_CNT	37	/* # hash buckets per major */
93 #define	SV_MINOR_HASH(min)	((min) % SV_MINOR_HASH_CNT)
94 
95 /*
96  * Per major device structure.
97  *
98  */
99 
100 typedef struct sv_maj_s {
101 	struct dev_ops	*sm_dev_ops;
102 	int		(*sm_strategy)();
103 	int		(*sm_awrite)();
104 	int		(*sm_write)();
105 	int		(*sm_ioctl)();
106 	int		(*sm_close)();
107 	int		(*sm_aread)();
108 	int		(*sm_read)();
109 	int		(*sm_open)();
110 	major_t		sm_major;			/* Major device # */
111 	int		sm_flag;
112 	volatile int	sm_inuse;
113 	volatile int	sm_seq;
114 	struct sv_dev_s	*sm_hash[SV_MINOR_HASH_CNT];	/* Minor Hash Table */
115 	struct sv_maj_s *sm_next;			/* Major Hash Chain */
116 } sv_maj_t;
117 
118 /*
119  * Per configured sv structure.
120  */
121 
122 typedef struct sv_dev_s {
123 	struct sv_dev_s	*sv_hash;	/* Minor hash chain */
124 	krwlock_t	sv_lock;	/* mutual exclusion */
125 	kmutex_t	sv_olock;	/* mutual exclusion for otyp flags */
126 	dev_t		sv_dev;		/* underlying dev_t */
127 	nsc_fd_t	*sv_fd;		/* underlying fd */
128 	nsc_size_t	sv_maxfbas;	/* maxfbas accepted by I/O module */
129 	nsc_size_t	sv_nblocks;	/* size of device */
130 	int		sv_state;	/* state */
131 	int		sv_flag;	/* internal flags */
132 	sv_gid_t	sv_gclients;	/* bitmask of all guard clients */
133 	sv_gid_t	sv_gkernel;	/* bitmask of kernel guard clients */
134 	int		sv_openlcnt;	/* # of OTYP_LYR opens whilst failed */
135 	clock_t		sv_timestamp;	/* time of successful {en,dis}able */
136 	ldi_handle_t	sv_lh;		/* layered open handle */
137 	void		*sv_pending;	/* the thread setting SV_PENDING */
138 } sv_dev_t;
139 
140 /*
141  * private functions exported from nskern to sv.
142  */
143 extern int nskern_partition(dev_t, int *);
144 extern int nskernd_isdaemon(void);
145 
146 #endif  /* _KERNEL */
147 
148 #ifdef	__cplusplus
149 }
150 #endif
151 
152 #endif	/* _SV_IMPL_H */
153