1734Smw145384 /*
2734Smw145384 * CDDL HEADER START
3734Smw145384 *
4734Smw145384 * The contents of this file are subject to the terms of the
5*6901Sjkennedy * Common Development and Distribution License (the "License").
6*6901Sjkennedy * You may not use this file except in compliance with the License.
7734Smw145384 *
8734Smw145384 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9734Smw145384 * or http://www.opensolaris.org/os/licensing.
10734Smw145384 * See the License for the specific language governing permissions
11734Smw145384 * and limitations under the License.
12734Smw145384 *
13734Smw145384 * When distributing Covered Code, include this CDDL HEADER in each
14734Smw145384 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15734Smw145384 * If applicable, add the following below this CDDL HEADER, with the
16734Smw145384 * fields enclosed by brackets "[]" replaced with your own identifying
17734Smw145384 * information: Portions Copyright [yyyy] [name of copyright owner]
18734Smw145384 *
19734Smw145384 * CDDL HEADER END
20734Smw145384 */
21734Smw145384 /*
22*6901Sjkennedy * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23734Smw145384 * Use is subject to license terms.
24734Smw145384 */
25734Smw145384
26734Smw145384 #pragma ident "%Z%%M% %I% %E% SMI"
27734Smw145384
28734Smw145384 /*
29734Smw145384 * md_convert.c
30734Smw145384 *
31734Smw145384 * As the size of a metadevice used to be stored in 32 bit signed variables,
32734Smw145384 * there was a limit of 1 TB for the size (2^31 * 512 byte).
33734Smw145384 * In order to be able to create larger metadevices, a 2nd set of structures
34734Smw145384 * with wider variables for the size has been created.
35734Smw145384 * There's one structure being shared by all types (mdc_unit_t) and one
36734Smw145384 * for each type of metadevice (mm_unit_t, ms_unit_t, mr_unit_t, ...).
37734Smw145384 * the wide structures are named like mdc_unit_t, mm_unit_t,..
38734Smw145384 * The narrow structures are named like mdc_unit32_od_t, mm_unit32_od_t,...
39734Smw145384 *
40734Smw145384 * The wide structures are used for md's >= 1TB, the narrow structures
41734Smw145384 * are used for md's < 1TB.
42734Smw145384 * Once a metadevice grows from < 1TB to >= 1TB the record has to be
43734Smw145384 * converted from a narrow one to a wide one.
44734Smw145384 *
45734Smw145384 * Incore (commands, libs and drivers) we only use the wide structures,
46734Smw145384 * in order to keep it simple.
47734Smw145384 * This means when we snarf a narrow struct, we have to convert it to a
48734Smw145384 * wide incore instance before we can use the md.
49734Smw145384 *
50734Smw145384 *
51734Smw145384 * This file contains conversion routines for the various metadevices.
52734Smw145384 * All the conversion routines take as input two pointers to memory areas
53734Smw145384 * and a direction. The directions specifies which memory area is the
54734Smw145384 * source and which is the destination.
55734Smw145384 */
56734Smw145384
57734Smw145384
58734Smw145384 #include <sys/sysmacros.h>
59734Smw145384 #include <sys/types.h>
60734Smw145384 #include <sys/cmn_err.h>
61734Smw145384 #include <sys/lvm/mdvar.h>
62734Smw145384 #ifdef _KERNEL
63734Smw145384 #include <sys/lvm/md_basic.h>
64734Smw145384 #else /* !_KERNEL */
65734Smw145384 #include <meta_basic.h>
66734Smw145384 #endif /* _KERNEL */
67734Smw145384 #include <sys/lvm/md_convert.h>
68734Smw145384
69734Smw145384
70734Smw145384 /*
71734Smw145384 * SVM private devt expansion routine
72734Smw145384 * INPUT: dev a 64 bit container holding either a 32 bit or a 64 bit device
73734Smw145384 * OUTPUT: always an expanded 64 bit device, even if we are running in a
74734Smw145384 * 32 bit Kernel.
75734Smw145384 */
76734Smw145384 md_dev64_t
md_expldev(md_dev64_t dev)77734Smw145384 md_expldev(md_dev64_t dev)
78734Smw145384 {
79734Smw145384 minor_t minor;
80734Smw145384 major_t major = (major_t)(dev >> NBITSMINOR64) & MAXMAJ64;
81734Smw145384
82734Smw145384 /* Here we were given a 64bit dev, return unchanged */
83734Smw145384 if (major != (major_t)0)
84734Smw145384 return (dev);
85734Smw145384 /* otherwise we were given a 32 bit dev */
86734Smw145384 major = (major_t)dev >> NBITSMINOR32 & MAXMAJ32;
87734Smw145384 minor = (minor_t)dev & MAXMIN32;
88734Smw145384 return (((md_dev64_t)major << NBITSMINOR64) | minor);
89734Smw145384 }
90734Smw145384
91734Smw145384 /*
92734Smw145384 * SVM private devt compact routine
93734Smw145384 * INPUT: dev a 64 bit container holding either a 32 bit or a 64 bit device
94734Smw145384 * OUTPUT: always a compacted 32 bit device, even if we are running in a
95734Smw145384 * 64 bit Kernel.
96734Smw145384 */
97734Smw145384 dev32_t
md_cmpldev(md_dev64_t dev)98734Smw145384 md_cmpldev(md_dev64_t dev)
99734Smw145384 {
100734Smw145384 minor_t minor;
101734Smw145384 major_t major = (major_t)(dev >> NBITSMINOR64) & MAXMAJ64;
102734Smw145384
103734Smw145384 /* Here we were given a 32bit dev, return unchanged */
104734Smw145384 if (major == 0) {
105734Smw145384 return ((dev32_t)dev);
106734Smw145384 }
107734Smw145384 /* otherwise we were given a 64 bit dev */
108734Smw145384 minor = (minor_t)dev & MAXMIN32;
109734Smw145384 return (((dev32_t)major << NBITSMINOR32) | minor);
110734Smw145384 }
111734Smw145384
112734Smw145384
113734Smw145384 /*
114734Smw145384 * given a small stripe unit, compute the size of an appropriate
115734Smw145384 * big stripe unit.
116734Smw145384 * if first_comp_only is set just return the offset of the first component
117734Smw145384 * in the new big unit.
118734Smw145384 *
119734Smw145384 * The function:
120734Smw145384 * usr/src/lib/lvm/libmeta/common/meta_statconcise.c:get_stripe_req_size()
121734Smw145384 * contains code derived from this function and thus if any changes are made to
122734Smw145384 * this function get_stripe_req_size() should be evaluated to determine whether
123734Smw145384 * or not code changes will also be necessary there.
124734Smw145384 *
125734Smw145384 */
126734Smw145384 size_t
get_big_stripe_req_size(ms_unit32_od_t * un,int first_comp_only)127734Smw145384 get_big_stripe_req_size(ms_unit32_od_t *un, int first_comp_only)
128734Smw145384 {
129734Smw145384 struct ms_row32_od *mdr;
130734Smw145384 uint_t row;
131734Smw145384 uint_t ncomps = 0;
132734Smw145384 size_t mdsize = 0;
133734Smw145384 size_t first_comp = 0;
134734Smw145384
135734Smw145384
136734Smw145384 /* Compute the offset of the first component */
137734Smw145384 first_comp = sizeof (ms_unit_t) +
138*6901Sjkennedy sizeof (struct ms_row) * (un->un_nrows - 1);
139734Smw145384 first_comp = roundup(first_comp, sizeof (long long));
140734Smw145384 if (first_comp_only == FIRST_COMP_OFFSET)
141734Smw145384 return (first_comp);
142734Smw145384
143734Smw145384 /*
144734Smw145384 * Requestor wants to have the total size, add the sizes of
145734Smw145384 * all components
146734Smw145384 */
147734Smw145384 mdr = &un->un_row[0];
148734Smw145384 for (row = 0; (row < un->un_nrows); row++)
149734Smw145384 ncomps += mdr[row].un_ncomp;
150734Smw145384 mdsize = first_comp + sizeof (ms_comp_t) * ncomps;
151734Smw145384 return (mdsize);
152734Smw145384 }
153734Smw145384
154734Smw145384 /*
155734Smw145384 * given a big stripe unit, compute the size of an appropriate
156734Smw145384 * small stripe unit.
157734Smw145384 * if first_comp_only is set just return the offset of the first component
158734Smw145384 * in the new small unit.
159734Smw145384 */
160734Smw145384 size_t
get_small_stripe_req_size(ms_unit_t * un,int first_comp_only)161734Smw145384 get_small_stripe_req_size(ms_unit_t *un, int first_comp_only)
162734Smw145384 {
163734Smw145384 struct ms_row *mdr;
164734Smw145384 uint_t row;
165734Smw145384 uint_t ncomps = 0;
166734Smw145384 size_t mdsize;
167734Smw145384 size_t first_comp;
168734Smw145384
169734Smw145384 /* Compute the size of the new small ms_unit */
170734Smw145384 first_comp = sizeof (ms_unit32_od_t) +
171*6901Sjkennedy sizeof (struct ms_row32_od) * (un->un_nrows - 1);
172734Smw145384 first_comp = roundup(first_comp, sizeof (long long));
173734Smw145384 if (first_comp_only == FIRST_COMP_OFFSET)
174734Smw145384 return (first_comp);
175734Smw145384
176734Smw145384 /*
177734Smw145384 * Requestor wants to have the total size, add the sizes of
178734Smw145384 * all components
179734Smw145384 */
180734Smw145384 mdr = &un->un_row[0];
181734Smw145384 for (row = 0; (row < un->un_nrows); row++)
182734Smw145384 ncomps += mdr[row].un_ncomp;
183734Smw145384 mdsize = first_comp + sizeof (ms_comp32_od_t) * ncomps;
184734Smw145384 return (mdsize);
185734Smw145384 }
186734Smw145384
187734Smw145384
188734Smw145384 /*
189734Smw145384 * stripe_convert(small, big, dir)
190734Smw145384 *
191734Smw145384 * Parameters:
192734Smw145384 * small is the address of a ms_unit32_od_t structure
193734Smw145384 * big is the address of a ms_unit_t structure
194734Smw145384 * dir is either BIG2SMALL or SMALL2BIG
195734Smw145384 * Return value is void
196734Smw145384 *
197734Smw145384 * what it does:
198734Smw145384 * if dir is BIG2SMALL, convert from big to small (updating old records)
199734Smw145384 * if dir is SMALL2BIG, convert from small to big (snarfing old records)
200734Smw145384 *
201734Smw145384 * Caveat emptor: big and small must be well allocated memory areas.
202734Smw145384 */
203734Smw145384
204734Smw145384 void
stripe_convert(caddr_t small,caddr_t big,int direction)205734Smw145384 stripe_convert(caddr_t small, caddr_t big, int direction)
206734Smw145384 {
207734Smw145384 /*LINTED*/
208734Smw145384 ms_unit32_od_t *small_un = (ms_unit32_od_t *)small;
209734Smw145384 /*LINTED*/
210734Smw145384 ms_unit_t *big_un = (ms_unit_t *)big;
211734Smw145384
212734Smw145384 struct ms_row32_od *small_mdr;
213734Smw145384 struct ms_row *big_mdr;
214734Smw145384 uint_t row, comp, ncomps = 0;
215734Smw145384 ms_comp_t *big_mdcomp;
216734Smw145384 ms_comp32_od_t *small_mdcomp;
217734Smw145384
218734Smw145384 if (direction == BIG_2_SMALL) {
219734Smw145384 MDC_UNIT_BIG2SMALL(big_un, small_un);
220734Smw145384
221734Smw145384 small_un->un_hsp_id = big_un->un_hsp_id;
222734Smw145384 small_un->un_nrows = big_un->un_nrows;
223734Smw145384 small_un->c.un_size =
224*6901Sjkennedy get_small_stripe_req_size(big_un, COMPLETE_STRUCTURE);
225734Smw145384 small_un->un_ocomp =
226*6901Sjkennedy get_small_stripe_req_size(big_un, FIRST_COMP_OFFSET);
227734Smw145384
228734Smw145384 /* walk through all rows */
229734Smw145384 big_mdr = &big_un->un_row[0];
230734Smw145384 small_mdr = &small_un->un_row[0];
231734Smw145384
232734Smw145384 for (row = 0; (row < big_un->un_nrows); row++) {
233734Smw145384 ncomps += big_mdr[row].un_ncomp;
234734Smw145384 MSROW_BIG2SMALL((&(big_mdr[row])), (&(small_mdr[row])));
235734Smw145384 }
236734Smw145384
237734Smw145384 /* Now copy the components */
238*6901Sjkennedy big_mdcomp = (ms_comp_t *)(void *)&((char *)big_un)
239*6901Sjkennedy [big_un->un_ocomp];
240734Smw145384 small_mdcomp = (ms_comp32_od_t *)(void *)&((char *)small_un)
241*6901Sjkennedy [small_un->un_ocomp];
242734Smw145384 for (comp = 0; (comp < ncomps); ++comp) {
243734Smw145384 ms_comp_t *big_mdcp = &big_mdcomp[comp];
244734Smw145384 ms_comp32_od_t *small_mdcp = &small_mdcomp[comp];
245734Smw145384
246734Smw145384 MSCOMP_BIG2SMALL(big_mdcp, small_mdcp);
247734Smw145384
248734Smw145384 }
249734Smw145384 }
250734Smw145384
251734Smw145384 if (direction == SMALL_2_BIG) {
252734Smw145384 MDC_UNIT_SMALL2BIG(small_un, big_un);
253734Smw145384
254734Smw145384 big_un->un_hsp_id = small_un->un_hsp_id;
255734Smw145384 big_un->un_nrows = small_un->un_nrows;
256734Smw145384 big_un->c.un_size =
257*6901Sjkennedy get_big_stripe_req_size(small_un, COMPLETE_STRUCTURE);
258734Smw145384 big_un->un_ocomp =
259*6901Sjkennedy get_big_stripe_req_size(small_un, FIRST_COMP_OFFSET);
260734Smw145384
261734Smw145384
262734Smw145384 /* walk through all rows */
263734Smw145384 small_mdr = &small_un->un_row[0];
264734Smw145384 big_mdr = &big_un->un_row[0];
265734Smw145384
266734Smw145384 for (row = 0; (row < small_un->un_nrows); row++) {
267734Smw145384 ncomps += small_mdr[row].un_ncomp;
268734Smw145384 MSROW_SMALL2BIG((&(small_mdr[row])), (&(big_mdr[row])));
269734Smw145384 }
270734Smw145384 /* Now copy the components */
271734Smw145384 big_mdcomp = (ms_comp_t *)(void *)&((char *)big_un)
272*6901Sjkennedy [big_un->un_ocomp];
273734Smw145384 small_mdcomp = (ms_comp32_od_t *)(void *)&((char *)small_un)
274*6901Sjkennedy [small_un->un_ocomp];
275734Smw145384 for (comp = 0; (comp < ncomps); ++comp) {
276734Smw145384 ms_comp_t *big_mdcp = &big_mdcomp[comp];
277734Smw145384 ms_comp32_od_t *small_mdcp = &small_mdcomp[comp];
278734Smw145384
279734Smw145384 MSCOMP_SMALL2BIG(small_mdcp, big_mdcp);
280734Smw145384
281734Smw145384 }
282734Smw145384 }
283734Smw145384 }
284734Smw145384
285734Smw145384 /*
286734Smw145384 * mirror_convert(small, big, dir)
287734Smw145384 *
288734Smw145384 * Parameters:
289734Smw145384 * small is the address of a mm_unit32_od_t structure
290734Smw145384 * big is the address of a mm_unit_t structure
291734Smw145384 * dir is either BIG2SMALL or SMALL2BIG
292734Smw145384 * Return value is void
293734Smw145384 *
294734Smw145384 * what it does:
295734Smw145384 * if dir is BIG2SMALL, convert from big to small (updating old records)
296734Smw145384 * if dir is SMALL2BIG, convert from small to big (snarfing old records)
297734Smw145384 *
298734Smw145384 * Caveat emptor: big and small must be well allocated memory areas.
299734Smw145384 */
300734Smw145384 void
mirror_convert(caddr_t small,caddr_t big,int direction)301734Smw145384 mirror_convert(caddr_t small, caddr_t big, int direction)
302734Smw145384 {
303734Smw145384 /*LINTED*/
304734Smw145384 mm_unit32_od_t *small_un = (mm_unit32_od_t *)small;
305734Smw145384 /*LINTED*/
306734Smw145384 mm_unit_t *big_un = (mm_unit_t *)big;
307734Smw145384 int i;
308734Smw145384
309734Smw145384
310734Smw145384 if (direction == BIG_2_SMALL) {
311734Smw145384 MDC_UNIT_BIG2SMALL(big_un, small_un);
312734Smw145384
313734Smw145384 small_un->c.un_size =
314734Smw145384 roundup(sizeof (mm_unit32_od_t), sizeof (long long));
315734Smw145384 small_un->un_last_read = big_un->un_last_read;
316734Smw145384 small_un->un_changecnt = big_un->un_changecnt;
317734Smw145384 small_un->un_nsm = big_un->un_nsm;
318734Smw145384 for (i = 0; i < NMIRROR; i++) {
319734Smw145384 MMSM_BIG2SMALL((&(big_un->un_sm[i])),
320734Smw145384 (&(small_un->un_sm[i])));
321734Smw145384 }
322*6901Sjkennedy small_un->un_overlap_tree_flag = big_un->un_overlap_tree_flag;
323734Smw145384 small_un->un_read_option = big_un->un_read_option;
324734Smw145384 small_un->un_write_option = big_un->un_write_option;
325734Smw145384 small_un->un_pass_num = big_un->un_pass_num;
326734Smw145384 small_un->un_rrd_blksize = big_un->un_rrd_blksize;
327734Smw145384 small_un->un_rrd_num = big_un->un_rrd_num;
328734Smw145384 small_un->un_rr_dirty_recid = big_un->un_rr_dirty_recid;
329734Smw145384 small_un->un_rs_copysize = big_un->un_rs_copysize;
330734Smw145384 small_un->un_rs_dests = big_un->un_rs_dests;
331734Smw145384 small_un->un_rs_resync_done =
332734Smw145384 (daddr32_t)big_un->un_rs_resync_done;
333734Smw145384 small_un->un_rs_resync_2_do =
334734Smw145384 (daddr32_t)big_un->un_rs_resync_2_do;
335734Smw145384 small_un->un_rs_dropped_lock = big_un->un_rs_dropped_lock;
336734Smw145384 small_un->un_rs_type = big_un->un_rs_type;
337734Smw145384 }
338734Smw145384
339734Smw145384 if (direction == SMALL_2_BIG) {
340734Smw145384 MDC_UNIT_SMALL2BIG(small_un, big_un);
341734Smw145384 big_un->c.un_size =
342734Smw145384 roundup(sizeof (mm_unit_t), sizeof (long long));
343734Smw145384 big_un->un_last_read = small_un->un_last_read;
344734Smw145384 big_un->un_changecnt = small_un->un_changecnt;
345734Smw145384 big_un->un_nsm = small_un->un_nsm;
346734Smw145384
347734Smw145384
348734Smw145384 for (i = 0; i < NMIRROR; i++) {
349734Smw145384 MMSM_SMALL2BIG((&(small_un->un_sm[i])),
350734Smw145384 (&(big_un->un_sm[i])));
351734Smw145384 }
352734Smw145384
353734Smw145384
354734Smw145384 /* Now back to the simple things again */
355*6901Sjkennedy big_un->un_overlap_tree_flag = small_un->un_overlap_tree_flag;
356734Smw145384 big_un->un_read_option = small_un->un_read_option;
357734Smw145384 big_un->un_write_option = small_un->un_write_option;
358734Smw145384 big_un->un_pass_num = small_un->un_pass_num;
359734Smw145384 big_un->un_rrd_blksize = small_un->un_rrd_blksize;
360734Smw145384 big_un->un_rrd_num = small_un->un_rrd_num;
361734Smw145384 big_un->un_rr_dirty_recid = small_un->un_rr_dirty_recid;
362734Smw145384 big_un->un_rs_copysize = small_un->un_rs_copysize;
363734Smw145384 big_un->un_rs_dests = small_un->un_rs_dests;
364734Smw145384 big_un->un_rs_resync_done =
365734Smw145384 (diskaddr_t)small_un->un_rs_resync_done;
366734Smw145384 big_un->un_rs_resync_2_do =
367734Smw145384 (diskaddr_t)small_un->un_rs_resync_2_do;
368734Smw145384 big_un->un_rs_dropped_lock = small_un->un_rs_dropped_lock;
369734Smw145384 big_un->un_rs_type = small_un->un_rs_type;
370734Smw145384 }
371734Smw145384 }
372734Smw145384
373734Smw145384 /*
374734Smw145384 * raid_convert(small, big, dir)
375734Smw145384 *
376734Smw145384 * Parameters:
377734Smw145384 * small is the address of a mr_unit32_od_t structure
378734Smw145384 * big is the address of a mr_unit_t structure
379734Smw145384 * dir is either BIG2SMALL or SMALL2BIG
380734Smw145384 * Return value is void
381734Smw145384 *
382734Smw145384 * what it does:
383734Smw145384 * if dir is BIG2SMALL, convert from big to small (updating old records)
384734Smw145384 * if dir is SMALL2BIG, convert from small to big (snarfing old records)
385734Smw145384 *
386734Smw145384 * Caveat emptor: big and small must be well allocated memory areas.
387734Smw145384 */
388734Smw145384 void
raid_convert(caddr_t small,caddr_t big,int direction)389734Smw145384 raid_convert(caddr_t small, caddr_t big, int direction)
390734Smw145384
391734Smw145384 {
392734Smw145384 /*LINTED*/
393734Smw145384 mr_unit32_od_t *small_un = (mr_unit32_od_t *)small;
394734Smw145384 /*LINTED*/
395734Smw145384 mr_unit_t *big_un = (mr_unit_t *)big;
396734Smw145384
397734Smw145384 int i;
398734Smw145384 uint_t ncol;
399734Smw145384
400734Smw145384 if (direction == BIG_2_SMALL) {
401734Smw145384 MRUNIT_BIG2SMALL(big_un, small_un);
402734Smw145384
403734Smw145384 ncol = small_un->un_totalcolumncnt;
404734Smw145384 small_un->c.un_size = sizeof (mr_unit32_od_t);
405734Smw145384 small_un->c.un_size += (ncol - 1) * sizeof (mr_column32_od_t);
406734Smw145384 for (i = 0; i < ncol; i++) {
407734Smw145384 MRCOL_BIG2SMALL((&(big_un->un_column[i])),
408734Smw145384 (&(small_un->un_column[i])));
409734Smw145384 }
410734Smw145384 }
411734Smw145384
412734Smw145384 if (direction == SMALL_2_BIG) {
413734Smw145384 MRUNIT_SMALL2BIG(small_un, big_un);
414734Smw145384
415734Smw145384 ncol = big_un->un_totalcolumncnt;
416734Smw145384 big_un->c.un_size = sizeof (mr_unit_t);
417734Smw145384 big_un->c.un_size += (ncol - 1) * sizeof (mr_column_t);
418734Smw145384 for (i = 0; i < ncol; i++) {
419734Smw145384 MRCOL_SMALL2BIG((&(small_un->un_column[i])),
420734Smw145384 (&(big_un->un_column[i])));
421734Smw145384 }
422734Smw145384 }
423734Smw145384 }
424734Smw145384
425734Smw145384
426734Smw145384
427734Smw145384
428734Smw145384
429734Smw145384 /*
430734Smw145384 * softpart_convert(small, big, dir)
431734Smw145384 *
432734Smw145384 * Parameters:
433734Smw145384 * small is the address of a mp_unit32_od_t structure
434734Smw145384 * big is the address of a mp_unit_t structure
435734Smw145384 * dir is either BIG2SMALL or SMALL2BIG
436734Smw145384 * Return value is void
437734Smw145384 *
438734Smw145384 * what it does:
439734Smw145384 * if dir is BIG2SMALL, convert from big to small (updating old records)
440734Smw145384 * if dir is SMALL2BIG, convert from small to big (snarfing old records)
441734Smw145384 *
442734Smw145384 * Caveat emptor: big and small must be well allocated memory areas.
443734Smw145384 */
444734Smw145384 void
softpart_convert(caddr_t small,caddr_t big,int direction)445734Smw145384 softpart_convert(caddr_t small, caddr_t big, int direction)
446734Smw145384
447734Smw145384 {
448734Smw145384 /*LINTED*/
449734Smw145384 mp_unit32_od_t *small_un = (mp_unit32_od_t *)small;
450734Smw145384 /*LINTED*/
451734Smw145384 mp_unit_t *big_un = (mp_unit_t *)big;
452734Smw145384
453734Smw145384 if (direction == BIG_2_SMALL) {
454734Smw145384 MPUNIT_BIG2SMALL(big_un, small_un);
455734Smw145384 /*
456734Smw145384 * Note that there isn't a mp_ext32_od_t, it's right to use
457734Smw145384 * mp_ext_t here, too.
458734Smw145384 */
459734Smw145384 small_un->c.un_size = sizeof (mp_unit32_od_t) +
460734Smw145384 (small_un->un_numexts - 1) * sizeof (mp_ext_t);
461734Smw145384 }
462734Smw145384
463734Smw145384 if (direction == SMALL_2_BIG) {
464734Smw145384 MPUNIT_SMALL2BIG(small_un, big_un);
465734Smw145384 big_un->c.un_size = sizeof (mp_unit_t) +
466734Smw145384 (big_un->un_numexts - 1) * sizeof (mp_ext_t);
467734Smw145384 }
468734Smw145384 }
469734Smw145384
470734Smw145384
471734Smw145384 /*
472734Smw145384 * trans_master_convert(smallp, bigp, dir)
473734Smw145384 *
474734Smw145384 * Parameters:
475734Smw145384 * smallp is the address of a mt_unit32_od_t structure
476734Smw145384 * bigp is the address of a mt_unit_t structure
477734Smw145384 * dir is either BIG2SMALL or SMALL2BIG
478734Smw145384 * Return value is void
479734Smw145384 *
480734Smw145384 * what it does:
481734Smw145384 * if dir is BIG2SMALL, convert from big to small (updating old records)
482734Smw145384 * if dir is SMALL2BIG, convert from small to big (snarfing old records)
483734Smw145384 *
484734Smw145384 * Caveat emptor: bigp and smallp must be well allocated memory areas.
485734Smw145384 */
486734Smw145384 void
trans_master_convert(caddr_t smallp,caddr_t bigp,int direction)487734Smw145384 trans_master_convert(caddr_t smallp, caddr_t bigp, int direction)
488734Smw145384 {
489734Smw145384 /*LINTED*/
490734Smw145384 mt_unit32_od_t *small = (mt_unit32_od_t *)smallp;
491734Smw145384 /*LINTED*/
492734Smw145384 mt_unit_t *big = (mt_unit_t *)bigp;
493734Smw145384
494734Smw145384 if (direction == SMALL_2_BIG) {
495734Smw145384 MDC_UNIT_SMALL2BIG(small, big);
496734Smw145384 big->c.un_size =
497734Smw145384 roundup(sizeof (mt_unit_t), sizeof (long long));
498734Smw145384 big->un_flags = small->un_flags;
499734Smw145384 big->un_m_key = small->un_m_key;
500734Smw145384 big->un_m_dev = md_expldev(small->un_m_dev);
501734Smw145384 big->un_l_key = small->un_l_key;
502734Smw145384 big->un_l_dev = md_expldev(small->un_l_dev);
503734Smw145384 big->un_l_sblk = small->un_l_sblk;
504734Smw145384 big->un_l_pwsblk = small->un_l_pwsblk;
505734Smw145384 big->un_l_nblks = small->un_l_nblks;
506734Smw145384 big->un_l_tblks = small->un_l_tblks;
507734Smw145384 big->un_l_head = small->un_l_head;
508734Smw145384 big->un_l_tail = small->un_l_tail;
509734Smw145384 big->un_l_resv = small->un_l_resv;
510734Smw145384 big->un_l_maxresv = small->un_l_maxresv;
511734Smw145384 big->un_l_recid = small->un_l_recid;
512734Smw145384 big->un_l_error = small->un_l_error;
513734Smw145384 big->un_s_dev = md_expldev(small->un_s_dev);
514734Smw145384 big->un_debug = small->un_debug;
515734Smw145384 big->un_dev = md_expldev(small->un_dev);
516734Smw145384 big->un_logreset = small->un_logreset;
517734Smw145384 big->un_l_maxtransfer = small->un_l_maxtransfer;
518734Smw145384 big->un_timestamp.tv_sec = small->un_timestamp.tv_sec;
519734Smw145384 big->un_timestamp.tv_usec = small->un_timestamp.tv_usec;
520734Smw145384 big->un_l_timestamp.tv_sec = small->un_l_timestamp.tv_sec;
521734Smw145384 big->un_l_timestamp.tv_usec = small->un_l_timestamp.tv_usec;
522734Smw145384 }
523734Smw145384 if (direction == BIG_2_SMALL) {
524734Smw145384 MDC_UNIT_BIG2SMALL(big, small);
525734Smw145384 small->c.un_size =
526734Smw145384 roundup(sizeof (mt_unit32_od_t), sizeof (long long));
527734Smw145384 small->un_flags = big->un_flags;
528734Smw145384 small->un_m_key = big->un_m_key;
529734Smw145384 small->un_m_dev = md_cmpldev(big->un_m_dev);
530734Smw145384 small->un_l_key = big->un_l_key;
531734Smw145384 small->un_l_dev = md_cmpldev(big->un_l_dev);
532734Smw145384 small->un_l_sblk = big->un_l_sblk;
533734Smw145384 small->un_l_pwsblk = big->un_l_pwsblk;
534734Smw145384 small->un_l_nblks = big->un_l_nblks;
535734Smw145384 small->un_l_tblks = big->un_l_tblks;
536734Smw145384 small->un_l_head = big->un_l_head;
537734Smw145384 small->un_l_tail = big->un_l_tail;
538734Smw145384 small->un_l_resv = big->un_l_resv;
539734Smw145384 small->un_l_maxresv = big->un_l_maxresv;
540734Smw145384 small->un_l_maxtransfer = big->un_l_maxtransfer;
541734Smw145384 small->un_l_recid = big->un_l_recid;
542734Smw145384 small->un_l_error = big->un_l_error;
543734Smw145384 small->un_s_dev = md_cmpldev(big->un_s_dev);
544734Smw145384 small->un_debug = big->un_debug;
545734Smw145384 small->un_dev = md_cmpldev(big->un_dev);
546734Smw145384 small->un_logreset = big->un_logreset;
547734Smw145384 small->un_timestamp.tv_sec = big->un_timestamp.tv_sec;
548734Smw145384 small->un_timestamp.tv_usec = big->un_timestamp.tv_usec;
549734Smw145384 small->un_l_timestamp.tv_sec = big->un_l_timestamp.tv_sec;
550734Smw145384 small->un_l_timestamp.tv_usec = big->un_l_timestamp.tv_usec;
551734Smw145384 }
552734Smw145384
553734Smw145384 }
554734Smw145384
555734Smw145384
556734Smw145384 /*
557734Smw145384 * trans_log_convert(smallp, bigp, dir)
558734Smw145384 *
559734Smw145384 * Parameters:
560734Smw145384 * smallp is the address of a ml_unit32_od_t structure
561734Smw145384 * bigp is the address of a ml_unit_t structure
562734Smw145384 * dir is either BIG2SMALL or SMALL2BIG
563734Smw145384 * Return value is void
564734Smw145384 *
565734Smw145384 * what it does:
566734Smw145384 * if dir is BIG2SMALL, convert from big to small (updating old records)
567734Smw145384 * if dir is SMALL2BIG, convert from small to big (snarfing old records)
568734Smw145384 *
569734Smw145384 * Caveat emptor: bigp and smallp must be well allocated memory areas.
570734Smw145384 */
571734Smw145384 void
trans_log_convert(caddr_t smallp,caddr_t bigp,int direction)572734Smw145384 trans_log_convert(caddr_t smallp, caddr_t bigp, int direction)
573734Smw145384 {
574734Smw145384 /*LINTED*/
575734Smw145384 ml_unit32_od_t *small = (ml_unit32_od_t *)smallp;
576734Smw145384 /*LINTED*/
577734Smw145384 ml_unit_t *big = (ml_unit_t *)bigp;
578734Smw145384
579734Smw145384 if (direction == SMALL_2_BIG) {
580734Smw145384 big->un_revision = small->un_revision;
581734Smw145384 big->un_recid = small->un_recid;
582734Smw145384 big->un_key = small->un_key;
583734Smw145384 big->un_dev = md_expldev(small->un_dev);
584734Smw145384 big->un_opencnt = small->un_opencnt;
585734Smw145384 big->un_transcnt = small->un_transcnt;
586734Smw145384 big->un_head_lof = small->un_head_lof;
587734Smw145384 big->un_head_ident = small->un_head_ident;
588734Smw145384 big->un_tail_lof = small->un_tail_lof;
589734Smw145384 big->un_tail_ident = small->un_tail_ident;
590734Smw145384 big->un_bol_lof = small->un_bol_lof;
591734Smw145384 big->un_eol_lof = small->un_eol_lof;
592734Smw145384 big->un_nblks = small->un_nblks;
593734Smw145384 big->un_tblks = small->un_tblks;
594734Smw145384 big->un_maxtransfer = small->un_maxtransfer;
595734Smw145384 big->un_status = small->un_status;
596734Smw145384 big->un_maxresv = small->un_maxresv;
597734Smw145384 big->un_pwsblk = small->un_pwsblk;
598734Smw145384 big->un_devbsize = small->un_devbsize;
599734Smw145384 big->un_resv = small->un_resv;
600734Smw145384 big->un_resv_wantin = small->un_resv_wantin;
601734Smw145384 big->un_error = small->un_error;
602734Smw145384 big->un_tid = small->un_tid;
603734Smw145384 big->un_head_tid = small->un_head_tid;
604734Smw145384 big->un_timestamp.tv_sec = small->un_timestamp.tv_sec;
605734Smw145384 big->un_timestamp.tv_usec = small->un_timestamp.tv_usec;
606734Smw145384 }
607734Smw145384 if (direction == BIG_2_SMALL) {
608734Smw145384 small->un_revision = big->un_revision;
609734Smw145384 small->un_recid = big->un_recid;
610734Smw145384 small->un_key = big->un_key;
611734Smw145384 small->un_dev = md_cmpldev(big->un_dev);
612734Smw145384 small->un_opencnt = big->un_opencnt;
613734Smw145384 small->un_transcnt = big->un_transcnt;
614734Smw145384 small->un_head_lof = big->un_head_lof;
615734Smw145384 small->un_head_ident = big->un_head_ident;
616734Smw145384 small->un_tail_lof = big->un_tail_lof;
617734Smw145384 small->un_tail_ident = big->un_tail_ident;
618734Smw145384 small->un_bol_lof = big->un_bol_lof;
619734Smw145384 small->un_eol_lof = big->un_eol_lof;
620734Smw145384 small->un_nblks = big->un_nblks;
621734Smw145384 small->un_tblks = big->un_tblks;
622734Smw145384 small->un_maxtransfer = big->un_maxtransfer;
623734Smw145384 small->un_status = big->un_status;
624734Smw145384 small->un_maxresv = big->un_maxresv;
625734Smw145384 small->un_pwsblk = big->un_pwsblk;
626734Smw145384 small->un_devbsize = big->un_devbsize;
627734Smw145384 small->un_resv = big->un_resv;
628734Smw145384 small->un_resv_wantin = big->un_resv_wantin;
629734Smw145384 small->un_error = big->un_error;
630734Smw145384 small->un_tid = big->un_tid;
631734Smw145384 small->un_head_tid = big->un_head_tid;
632734Smw145384 small->un_timestamp.tv_sec = big->un_timestamp.tv_sec;
633734Smw145384 small->un_timestamp.tv_usec = big->un_timestamp.tv_usec;
634734Smw145384 }
635734Smw145384 }
636734Smw145384
637734Smw145384 /*
638734Smw145384 * hs_convert(small, big, dir)
639734Smw145384 *
640734Smw145384 * Parameters:
641734Smw145384 * small is the address of a hot_spare32_od_t structure
642734Smw145384 * big is the address of a hot_spare_t structure
643734Smw145384 * dir is either BIG2SMALL or SMALL2BIG
644734Smw145384 * Return value is void
645734Smw145384 *
646734Smw145384 * what it does:
647734Smw145384 * if dir is BIG2SMALL, convert from big to small (updating old records)
648734Smw145384 * if dir is SMALL2BIG, convert from small to big (snarfing old records)
649734Smw145384 *
650734Smw145384 * Caveat emptor: big and small must be well allocated memory areas.
651734Smw145384 */
652734Smw145384 void
hs_convert(caddr_t small,caddr_t big,int direction)653734Smw145384 hs_convert(caddr_t small, caddr_t big, int direction)
654734Smw145384
655734Smw145384 {
656734Smw145384 /*LINTED*/
657734Smw145384 hot_spare32_od_t *small_un = (hot_spare32_od_t *)small;
658734Smw145384 /*LINTED*/
659734Smw145384 hot_spare_t *big_un = (hot_spare_t *)big;
660734Smw145384
661734Smw145384 if (direction == BIG_2_SMALL) {
662734Smw145384 MHS_BIG2SMALL(big_un, small_un);
663734Smw145384 }
664734Smw145384
665734Smw145384 if (direction == SMALL_2_BIG) {
666734Smw145384 MHS_SMALL2BIG(small_un, big_un);
667734Smw145384 }
668734Smw145384 }
669