xref: /titanic_41/usr/src/uts/common/sys/lvm/md_convert.h (revision c037192b037119c9fd354732fc29b38ce097d356)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS__MD_CONVERT_H
27 #define	_SYS__MD_CONVERT_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/lvm/md_stripe.h>
32 #include <sys/lvm/md_mirror.h>
33 #include <sys/lvm/md_raid.h>
34 #include <sys/lvm/md_hotspares.h>
35 #include <sys/lvm/md_sp.h>
36 #include <sys/lvm/md_trans.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 size_t get_big_stripe_req_size(ms_unit32_od_t *, int);
43 size_t get_small_stripe_req_size(ms_unit_t *, int);
44 
45 void stripe_convert(caddr_t, caddr_t, int);
46 void mirror_convert(caddr_t, caddr_t, int);
47 void raid_convert(caddr_t, caddr_t, int);
48 void hs_convert(caddr_t, caddr_t, int);
49 void hsp_convert(caddr_t, caddr_t, int);
50 void softpart_convert(caddr_t, caddr_t, int);
51 void trans_master_convert(caddr_t, caddr_t, int);
52 void trans_log_convert(caddr_t, caddr_t, int);
53 
54 extern void dump_mdc_unit(mdc_unit_t *);
55 extern void dump_mdc_unit32_od(mdc_unit32_od_t *);
56 
57 extern void dump_mm_unit(mm_unit_t *);
58 extern void dump_mm_unit32_od(mm_unit32_od_t *);
59 
60 extern void dump_ms_unit(ms_unit_t *);
61 extern void dump_ms_unit32_od(ms_unit32_od_t *);
62 
63 extern void dump_mr_unit(mr_unit_t *);
64 extern void dump_mr_unit32_od(mr_unit32_od_t *);
65 
66 
67 /*
68  * Nice debug printing macro:
69  * eg: HBDBG(stripe_convert, 0x%llx, msp->c.un_revision);
70  */
71 #define	HBDBG(r, f, v) printf(#r "," #v ":[" #f "]\n", v)
72 
73 /* Compacting a timeval64 to a timeval32 */
74 #define	CMPLTV(dest, source)				\
75 	{						\
76 	(dest).tv_sec  = (int32_t)(source).tv_sec;	\
77 	(dest).tv_usec = (int32_t)(source).tv_usec;	\
78 	}
79 
80 /* Expanding a timeval32 to a timeval64 */
81 #define	EXPLTV(dest, source)				\
82 	{						\
83 	(dest).tv_sec  = (long)(source).tv_sec;	\
84 	(dest).tv_usec = (long)(source).tv_usec;	\
85 	}
86 
87 #define	COMPLETE_STRUCTURE 0
88 #define	FIRST_COMP_OFFSET 1
89 
90 #define	SMALL_2_BIG 1
91 #define	BIG_2_SMALL 2
92 
93 /* Used by different types */
94 
95 /* mdc_unit -> mdc_unit32_od */
96 #define	MDC_UNIT_BIG2SMALL(big_un, small_un) \
97 	small_un->c.un_revision		= big_un->c.un_revision;\
98 	small_un->c.un_type		= big_un->c.un_type;\
99 	small_un->c.un_status		= big_un->c.un_status;\
100 	small_un->c.un_parent_res 	= big_un->c.un_parent_res;\
101 	small_un->c.un_child_res	= big_un->c.un_child_res;\
102 	small_un->c.un_self_id		= big_un->c.un_self_id;\
103 	small_un->c.un_record_id	= big_un->c.un_record_id;\
104 	small_un->c.un_flag		= big_un->c.un_flag;\
105 	small_un->c.un_total_blocks	= (daddr32_t)big_un->c.un_total_blocks;\
106 	small_un->c.un_actual_tb	= (daddr32_t)big_un->c.un_actual_tb;\
107 	small_un->c.un_nhead		= (ushort_t)big_un->c.un_nhead;\
108 	small_un->c.un_nsect		= (ushort_t)big_un->c.un_nsect;\
109 	small_un->c.un_rpm		= big_un->c.un_rpm;\
110 	small_un->c.un_wr_reinstruct	= big_un->c.un_wr_reinstruct;\
111 	small_un->c.un_rd_reinstruct	= big_un->c.un_rd_reinstruct;\
112 	small_un->c.un_vtoc_id		= big_un->c.un_vtoc_id;\
113 	small_un->c.un_capabilities	= big_un->c.un_capabilities;\
114 	small_un->c.un_parent		= big_un->c.un_parent;\
115 	small_un->c.un_user_flags	= big_un->c.un_user_flags;
116 
117 #define	MDC_UNIT_SMALL2BIG(small_un, big_un) \
118 	big_un->c.un_revision	   = small_un->c.un_revision;\
119 	big_un->c.un_type	   = small_un->c.un_type;\
120 	big_un->c.un_status	   = small_un->c.un_status;\
121 	big_un->c.un_parent_res    = small_un->c.un_parent_res;\
122 	big_un->c.un_child_res	   = small_un->c.un_child_res;\
123 	big_un->c.un_self_id	   = small_un->c.un_self_id;\
124 	big_un->c.un_record_id	   = small_un->c.un_record_id;\
125 	big_un->c.un_flag	   = small_un->c.un_flag;\
126 	big_un->c.un_total_blocks  = (diskaddr_t)small_un->c.un_total_blocks;\
127 	big_un->c.un_actual_tb	   = (diskaddr_t)small_un->c.un_actual_tb;\
128 	big_un->c.un_nhead	   = (uint_t)small_un->c.un_nhead;\
129 	big_un->c.un_nsect	   = (uint_t)small_un->c.un_nsect;\
130 	big_un->c.un_rpm	   = small_un->c.un_rpm;\
131 	big_un->c.un_wr_reinstruct = small_un->c.un_wr_reinstruct;\
132 	big_un->c.un_rd_reinstruct = small_un->c.un_rd_reinstruct;\
133 	big_un->c.un_vtoc_id	   = small_un->c.un_vtoc_id;\
134 	big_un->c.un_capabilities  = small_un->c.un_capabilities;\
135 	big_un->c.un_parent	   = small_un->c.un_parent;\
136 	big_un->c.un_user_flags	   = small_un->c.un_user_flags;
137 
138 /* md_m_shared -> md_m_shared32_od */
139 #define	MMSH_BIG2SMALL(big_mdms, small_mdms) \
140 	small_mdms->ms_flags		= big_mdms->ms_flags; \
141 	small_mdms->xms_mx[0]		= 0; \
142 	small_mdms->xms_mx[1]		= 0; \
143 	small_mdms->ms_state		= big_mdms->ms_state; \
144 	small_mdms->ms_lasterrcnt	= big_mdms->ms_lasterrcnt; \
145 	small_mdms->ms_orig_dev		= md_cmpldev(big_mdms->ms_orig_dev); \
146 	small_mdms->ms_orig_blk		= (daddr32_t)big_mdms->ms_orig_blk; \
147 	small_mdms->ms_hs_key		= big_mdms->ms_hs_key; \
148 	small_mdms->ms_hs_id		= big_mdms->ms_hs_id; \
149 	CMPLTV(small_mdms->ms_timestamp, big_mdms->ms_timestamp);
150 
151 /* mdc_unit32_od -> mdc_unit */
152 /* md_m_shared32_od -> md_m_shared */
153 #define	MMSH_SMALL2BIG(small_mdms, big_mdms) \
154 	big_mdms->ms_flags		= small_mdms->ms_flags; \
155 	big_mdms->ms_state		= small_mdms->ms_state; \
156 	big_mdms->ms_lasterrcnt	= small_mdms->ms_lasterrcnt; \
157 	big_mdms->ms_orig_dev		= md_expldev(small_mdms->ms_orig_dev); \
158 	big_mdms->ms_orig_blk		= (diskaddr_t)small_mdms->ms_orig_blk; \
159 	big_mdms->ms_hs_key		= small_mdms->ms_hs_key; \
160 	big_mdms->ms_hs_id		= small_mdms->ms_hs_id; \
161 	CMPLTV(big_mdms->ms_timestamp, small_mdms->ms_timestamp);
162 
163 
164 /* Used by Stripes */
165 
166 /* ms_comp -> ms_comp32_od */
167 #define	MSCOMP_BIG2SMALL(big_mdcp, small_mdcp) \
168 	small_mdcp->un_key		= big_mdcp->un_key; \
169 	small_mdcp->un_dev		= md_cmpldev(big_mdcp->un_dev); \
170 	small_mdcp->un_start_block	= (daddr32_t)big_mdcp->un_start_block; \
171 	MMSH_BIG2SMALL((&(big_mdcp->un_mirror)), (&(small_mdcp->un_mirror)));
172 
173 /* ms_comp32_od -> ms_comp */
174 #define	MSCOMP_SMALL2BIG(small_mdcp, big_mdcp)				   \
175 	big_mdcp->un_key	 = small_mdcp->un_key;			   \
176 	big_mdcp->un_dev	 = md_expldev(small_mdcp->un_dev);	   \
177 	big_mdcp->un_start_block = (diskaddr_t)small_mdcp->un_start_block; \
178 	MMSH_SMALL2BIG((&(small_mdcp->un_mirror)), (&(big_mdcp->un_mirror)));
179 
180 
181 /* ms_row -> ms_row32_od */
182 #define	MSROW_BIG2SMALL(big_mdr, small_mdr)				\
183 	small_mdr->un_icomp	 = big_mdr->un_icomp;			\
184 	small_mdr->un_ncomp	 = big_mdr->un_ncomp;			\
185 	small_mdr->un_blocks	 = (daddr32_t)big_mdr->un_blocks;	\
186 	small_mdr->un_cum_blocks = (daddr32_t)big_mdr->un_cum_blocks;	\
187 	small_mdr->un_interlace	 = (daddr32_t)big_mdr->un_interlace;
188 
189 /* ms_row -> ms_row32_od */
190 #define	MSROW_SMALL2BIG(small_mdr, big_mdr)				\
191 	big_mdr->un_icomp	= small_mdr->un_icomp;			\
192 	big_mdr->un_ncomp	= small_mdr->un_ncomp;			\
193 	big_mdr->un_blocks	= (diskaddr_t)small_mdr->un_blocks;	\
194 	big_mdr->un_cum_blocks	= (diskaddr_t)small_mdr->un_cum_blocks;	\
195 	big_mdr->un_interlace	= (diskaddr_t)small_mdr->un_interlace;
196 
197 
198 
199 /* Used by Mirrors */
200 
201 /* mm_submirror -> mm_submirror32_od */
202 #define	MMSM_BIG2SMALL(big_sm, small_sm)				\
203 	small_sm->sm_key	= big_sm->sm_key; \
204 	small_sm->sm_dev	= md_cmpldev(big_sm->sm_dev); \
205 	small_sm->sm_state	= big_sm->sm_state; \
206 	small_sm->sm_flags	= big_sm->sm_flags; \
207 	small_sm->sm_hsp_id	= big_sm->sm_hsp_id; \
208 	CMPLTV(small_sm->sm_timestamp, big_sm->sm_timestamp); \
209 	MMSH_BIG2SMALL((&(big_sm->sm_shared)), (&(small_sm->sm_shared)));
210 
211 /* mm_submirror32_od -> mm_submirror */
212 #define	MMSM_SMALL2BIG(small_sm, big_sm) \
213 	big_sm->sm_key	  = small_sm->sm_key; \
214 	big_sm->sm_dev    = md_expldev(small_sm->sm_dev); \
215 	big_sm->sm_state  = small_sm->sm_state; \
216 	big_sm->sm_flags  = small_sm->sm_flags; \
217 	big_sm->sm_hsp_id = small_sm->sm_hsp_id; \
218 	CMPLTV(big_sm->sm_timestamp, small_sm->sm_timestamp); \
219 	MMSH_SMALL2BIG((&(small_sm->sm_shared)), (&(big_sm->sm_shared)));
220 
221 
222 /* Used by Raid */
223 /* mr_column -> mr_column32_od */
224 #define	MRCOL_BIG2SMALL(big_rcol, small_rcol)				\
225 	small_rcol->un_devstate		= big_rcol->un_devstate;	\
226 	small_rcol->un_devflags		= big_rcol->un_devflags;	\
227 	CMPLTV(small_rcol->un_devtimestamp, big_rcol->un_devtimestamp); \
228 	small_rcol->un_hs_id		= big_rcol->un_hs_id; 		\
229 	small_rcol->un_hs_pwstart	= (daddr32_t)big_rcol->un_hs_pwstart; \
230 	small_rcol->un_hs_devstart	= (daddr32_t)big_rcol->un_hs_devstart; \
231 	small_rcol->un_hs_key		= big_rcol->un_hs_key; 		\
232 	small_rcol->un_orig_dev		= md_cmpldev(big_rcol->un_orig_dev); \
233 	small_rcol->un_orig_key		= big_rcol->un_orig_key;	\
234 	small_rcol->un_orig_pwstart	= (daddr32_t)big_rcol->un_orig_pwstart;\
235 	small_rcol->un_orig_devstart  = (daddr32_t)big_rcol->un_orig_devstart;\
236 	small_rcol->un_dev		= md_cmpldev(big_rcol->un_dev);	\
237 	small_rcol->un_pwstart		= (daddr32_t)big_rcol->un_pwstart; \
238 	small_rcol->un_devstart		= (daddr32_t)big_rcol->un_devstart; \
239 	small_rcol->un_alt_dev		= md_cmpldev(big_rcol->un_alt_dev); \
240 	small_rcol->un_alt_pwstart	= (daddr32_t)big_rcol->un_alt_pwstart; \
241 	small_rcol->un_alt_devstart	= (daddr32_t)big_rcol->un_alt_devstart;
242 
243 /* mr_column32_od -> mr_column */
244 #define	MRCOL_SMALL2BIG(small_rcol, big_rcol)				\
245 	big_rcol->un_devstate	   = small_rcol->un_devstate; 	\
246 	big_rcol->un_devflags	   = small_rcol->un_devflags; 	\
247 	CMPLTV(big_rcol->un_devtimestamp, small_rcol->un_devtimestamp); \
248 	big_rcol->un_hs_id	   = small_rcol->un_hs_id;		\
249 	big_rcol->un_hs_pwstart	   = (diskaddr_t)small_rcol->un_hs_pwstart; \
250 	big_rcol->un_hs_devstart   = (diskaddr_t)small_rcol->un_hs_devstart; \
251 	big_rcol->un_hs_key	   = small_rcol->un_hs_key;	\
252 	big_rcol->un_orig_dev	   = md_expldev(small_rcol->un_orig_dev); \
253 	big_rcol->un_orig_key	   = small_rcol->un_orig_key; 	\
254 	big_rcol->un_orig_pwstart  = (diskaddr_t)small_rcol->un_orig_pwstart; \
255 	big_rcol->un_orig_devstart = (diskaddr_t)small_rcol->un_orig_devstart;\
256 	big_rcol->un_dev	   = md_expldev(small_rcol->un_dev);	\
257 	big_rcol->un_pwstart	   = (diskaddr_t)small_rcol->un_pwstart; \
258 	big_rcol->un_devstart	   = (diskaddr_t)small_rcol->un_devstart; \
259 	big_rcol->un_alt_dev	   = md_expldev(small_rcol->un_alt_dev); \
260 	big_rcol->un_alt_pwstart   = (diskaddr_t)small_rcol->un_alt_pwstart; \
261 	big_rcol->un_alt_devstart  = (diskaddr_t)small_rcol->un_alt_devstart;
262 
263 /* mr_unit -> mr_unit32_od */
264 #define	MRUNIT_BIG2SMALL(big_un, small_un)				\
265 	MDC_UNIT_BIG2SMALL(big_un, small_un);				\
266 	CMPLTV(small_un->un_timestamp, big_un->un_timestamp);		\
267 	small_un->un_magic		= big_un->un_magic;		\
268 	small_un->un_state		= big_un->un_state;		\
269 	small_un->un_origcolumncnt	= big_un->un_origcolumncnt;	\
270 	small_un->un_totalcolumncnt	= big_un->un_totalcolumncnt;	\
271 	small_un->un_rflags		= big_un->un_rflags;		\
272 	small_un->un_segsize		= big_un->un_segsize;		\
273 	small_un->un_segsincolumn	= (uint_t)big_un->un_segsincolumn;\
274 	small_un->un_maxio		= big_un->un_maxio;		\
275 	small_un->un_iosize		= big_un->un_iosize;		\
276 	small_un->un_linlck_flg		= big_un->un_linlck_flg;	\
277 	small_un->un_pwcnt		= big_un->un_pwcnt;		\
278 	small_un->un_pwsize		= big_un->un_pwsize;		\
279 	small_un->un_pwid		= big_un->un_pwid;		\
280 	small_un->un_percent_done	= big_un->un_percent_done;	\
281 	small_un->un_resync_copysize	= big_un->un_resync_copysize;	\
282 	small_un->un_hsp_id		= big_un->un_hsp_id;
283 
284 /* mr_unit32_od -> mr_unit */
285 #define	MRUNIT_SMALL2BIG(small_un, big_un)				\
286 	MDC_UNIT_SMALL2BIG(small_un, big_un);				\
287 	CMPLTV(big_un->un_timestamp, small_un->un_timestamp);		\
288 	big_un->un_magic	   = small_un->un_magic;		\
289 	big_un->un_state	   = small_un->un_state;		\
290 	big_un->un_origcolumncnt   = small_un->un_origcolumncnt;	\
291 	big_un->un_totalcolumncnt  = small_un->un_totalcolumncnt;	\
292 	big_un->un_rflags	   = small_un->un_rflags;		\
293 	big_un->un_segsize	   = small_un->un_segsize;		\
294 	big_un->un_segsincolumn	   = (diskaddr_t)small_un->un_segsincolumn;\
295 	big_un->un_maxio	   = small_un->un_maxio;		\
296 	big_un->un_iosize	   = small_un->un_iosize;		\
297 	big_un->un_linlck_flg	   = small_un->un_linlck_flg;		\
298 	big_un->un_pwcnt	   = small_un->un_pwcnt;		\
299 	big_un->un_pwsize	   = small_un->un_pwsize;		\
300 	big_un->un_pwid		   = small_un->un_pwid;			\
301 	big_un->un_percent_done	   = small_un->un_percent_done;		\
302 	big_un->un_resync_copysize = small_un->un_resync_copysize;	\
303 	big_un->un_hsp_id	   = small_un->un_hsp_id;
304 
305 
306 /* Used by Softpartitions */
307 /* mp_unit -> mp_unit32_od */
308 #define	MPUNIT_BIG2SMALL(big_un, small_un) { 				\
309 	uint_t __i;							\
310 	MDC_UNIT_BIG2SMALL(big_un, small_un);				\
311 	small_un->un_key = big_un->un_key;				\
312 	small_un->un_dev = md_cmpldev(big_un->un_dev);			\
313 	small_un->un_start_blk = big_un->un_start_blk;			\
314 	small_un->un_status = big_un->un_status;			\
315 	small_un->un_numexts = big_un->un_numexts;			\
316 	small_un->un_length = big_un->un_length;			\
317 	for (__i = 0; __i < big_un->un_numexts; __i++) {		\
318 		small_un->un_ext[__i].un_voff = big_un->un_ext[__i].un_voff; \
319 		small_un->un_ext[__i].un_poff = big_un->un_ext[__i].un_poff; \
320 		small_un->un_ext[__i].un_len  = big_un->un_ext[__i].un_len; \
321 	} \
322 }
323 
324 /* mp_unit32_od -> mp_unit */
325 #define	MPUNIT_SMALL2BIG(small_un, big_un) {				\
326 	uint_t __j;							\
327 	MDC_UNIT_BIG2SMALL(small_un, big_un);				\
328 	big_un->un_key = small_un->un_key;				\
329 	big_un->un_dev = md_expldev(small_un->un_dev);			\
330 	big_un->un_start_blk = small_un->un_start_blk;			\
331 	big_un->un_status = small_un->un_status;			\
332 	big_un->un_numexts = small_un->un_numexts;			\
333 	big_un->un_length = small_un->un_length;			\
334 	for (__j = 0; __j < small_un->un_numexts; __j++) {		\
335 		big_un->un_ext[__j].un_voff = small_un->un_ext[__j].un_voff; \
336 		big_un->un_ext[__j].un_poff = small_un->un_ext[__j].un_poff; \
337 		big_un->un_ext[__j].un_len  = small_un->un_ext[__j].un_len; \
338 	} \
339 }
340 
341 
342 /* Used by Hotspares */
343 /* hot_spare -> hot_spare32_od */
344 #define	MHS_BIG2SMALL(big, small)					\
345 	small->hs_revision = big->hs_revision;				\
346 	small->hs_record_id = big->hs_record_id;			\
347 	small->xx_hs_next = 0;						\
348 	small->hs_devnum = md_cmpldev(big->hs_devnum);			\
349 	small->hs_key = big->hs_key;					\
350 	small->hs_start_blk = (daddr32_t)big->hs_start_blk;		\
351 	small->hs_has_label = big->hs_has_label;			\
352 	small->hs_number_blks = (daddr32_t)big->hs_number_blks;		\
353 	small->hs_state = big->hs_state;				\
354 	small->hs_refcount = big->hs_refcount;				\
355 	small->hs_isopen = big->hs_isopen;				\
356 	CMPLTV(small->hs_timestamp, big->hs_timestamp);
357 
358 /* hot_spare -> hot_spare32_od */
359 #define	MHS_SMALL2BIG(small, big)					\
360 	big->hs_revision = small->hs_revision;				\
361 	big->hs_record_id = small->hs_record_id;			\
362 	big->hs_devnum = md_expldev(small->hs_devnum);			\
363 	big->hs_key = small->hs_key;					\
364 	big->hs_start_blk = (diskaddr_t)small->hs_start_blk;		\
365 	big->hs_has_label = small->hs_has_label;			\
366 	big->hs_number_blks = (diskaddr_t)small->hs_number_blks;	\
367 	big->hs_state = small->hs_state;				\
368 	big->hs_refcount = small->hs_refcount;				\
369 	big->hs_isopen = small->hs_isopen;				\
370 	CMPLTV(big->hs_timestamp, small->hs_timestamp);
371 
372 /* hot_spare_pool_ond -> hot_spare_pool_ond32 */
373 #define	MHSP_BIG2SMALL(big, small) {					\
374 	int __i;							\
375 	small->hsp_revision = big->hsp_revision;			\
376 	small->hsp_self_id = big->hsp_self_id;				\
377 	small->hsp_record_id = big->hsp_record_id;			\
378 	small->hsp_refcount = big->hsp_refcount;			\
379 	small->hsp_nhotspares = big->hsp_nhotspares;			\
380 	for (__i = 0; __i < big->hsp_nhotspares; __i++) 		\
381 		small->hsp_hotspares[__i] = big->hsp_hotspares[__i];	\
382 }
383 
384 /* hot_spare_pool_ond32 -> hot_spare_pool_ond */
385 #define	MHSP_SMALL2BIG(small, big) {					\
386 	int __i;							\
387 	big->hsp_revision = small->hsp_revision;			\
388 	big->hsp_self_id = small->hsp_self_id;				\
389 	big->hsp_record_id = small->hsp_record_id;			\
390 	big->hsp_refcount = small->hsp_refcount;			\
391 	big->hsp_nhotspares = small->hsp_nhotspares;			\
392 	for (__i = 0; __i < small->hsp_nhotspares; __i++) 		\
393 		big->hsp_hotspares[__i] = small->hsp_hotspares[__i];	\
394 }
395 
396 #ifdef	__cplusplus
397 }
398 #endif
399 
400 #endif /* _SYS__MD_CONVERT_H */
401