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