1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 1994-2002 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate * raid operations
31*0Sstevel@tonic-gate */
32*0Sstevel@tonic-gate
33*0Sstevel@tonic-gate #include <meta.h>
34*0Sstevel@tonic-gate #include <sys/lvm/md_mirror.h>
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gate /*
37*0Sstevel@tonic-gate * resync raid
38*0Sstevel@tonic-gate */
39*0Sstevel@tonic-gate int
meta_raid_resync(mdsetname_t * sp,mdname_t * raidnp,daddr_t size,md_error_t * ep)40*0Sstevel@tonic-gate meta_raid_resync(
41*0Sstevel@tonic-gate mdsetname_t *sp,
42*0Sstevel@tonic-gate mdname_t *raidnp,
43*0Sstevel@tonic-gate daddr_t size,
44*0Sstevel@tonic-gate md_error_t *ep
45*0Sstevel@tonic-gate )
46*0Sstevel@tonic-gate {
47*0Sstevel@tonic-gate char *miscname;
48*0Sstevel@tonic-gate md_resync_ioctl_t ri;
49*0Sstevel@tonic-gate
50*0Sstevel@tonic-gate /* should have a set */
51*0Sstevel@tonic-gate assert(sp != NULL);
52*0Sstevel@tonic-gate assert(sp->setno == MD_MIN2SET(meta_getminor(raidnp->dev)));
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate /* make sure we have a raid */
55*0Sstevel@tonic-gate if ((miscname = metagetmiscname(raidnp, ep)) == NULL)
56*0Sstevel@tonic-gate return (-1);
57*0Sstevel@tonic-gate if (strcmp(miscname, MD_RAID) != 0) {
58*0Sstevel@tonic-gate return (mdmderror(ep, MDE_NOT_RAID, meta_getminor(raidnp->dev),
59*0Sstevel@tonic-gate raidnp->cname));
60*0Sstevel@tonic-gate }
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate /* start resync */
63*0Sstevel@tonic-gate (void) memset(&ri, 0, sizeof (ri));
64*0Sstevel@tonic-gate MD_SETDRIVERNAME(&ri, MD_RAID, sp->setno);
65*0Sstevel@tonic-gate ri.ri_mnum = meta_getminor(raidnp->dev);
66*0Sstevel@tonic-gate ri.ri_copysize = size;
67*0Sstevel@tonic-gate if (metaioctl(MD_IOCSETSYNC, &ri, &ri.mde, raidnp->cname) != 0)
68*0Sstevel@tonic-gate return (mdstealerror(ep, &ri.mde));
69*0Sstevel@tonic-gate
70*0Sstevel@tonic-gate /* return success */
71*0Sstevel@tonic-gate return (0);
72*0Sstevel@tonic-gate }
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate /*
75*0Sstevel@tonic-gate * NAME: meta_raid_resync_all
76*0Sstevel@tonic-gate * DESCRIPTION: loop through the RAID devices synch'ing all
77*0Sstevel@tonic-gate * PARAMETERS: char *sp - the set to synch
78*0Sstevel@tonic-gate * daddr_t size - resync size
79*0Sstevel@tonic-gate * md_error_t *ep - return error info
80*0Sstevel@tonic-gate *
81*0Sstevel@tonic-gate */
82*0Sstevel@tonic-gate int
meta_raid_resync_all(mdsetname_t * sp,daddr_t size,md_error_t * ep)83*0Sstevel@tonic-gate meta_raid_resync_all(
84*0Sstevel@tonic-gate mdsetname_t *sp,
85*0Sstevel@tonic-gate daddr_t size,
86*0Sstevel@tonic-gate md_error_t *ep
87*0Sstevel@tonic-gate )
88*0Sstevel@tonic-gate {
89*0Sstevel@tonic-gate mdnamelist_t *nlp = NULL;
90*0Sstevel@tonic-gate mdnamelist_t *p;
91*0Sstevel@tonic-gate int rval = 0, fval;
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gate /* should have a set */
94*0Sstevel@tonic-gate assert(sp != NULL);
95*0Sstevel@tonic-gate
96*0Sstevel@tonic-gate /* get raids */
97*0Sstevel@tonic-gate if (meta_get_raid_names(sp, &nlp, 0, ep) < 0)
98*0Sstevel@tonic-gate return (-1);
99*0Sstevel@tonic-gate
100*0Sstevel@tonic-gate /* fork a process */
101*0Sstevel@tonic-gate if ((fval = md_daemonize(sp, ep)) != 0) {
102*0Sstevel@tonic-gate /*
103*0Sstevel@tonic-gate * md_daemonize forks off a process to do the work. This
104*0Sstevel@tonic-gate * is the parent or errror.
105*0Sstevel@tonic-gate */
106*0Sstevel@tonic-gate if (fval > 0) {
107*0Sstevel@tonic-gate if (nlp != NULL)
108*0Sstevel@tonic-gate metafreenamelist(nlp);
109*0Sstevel@tonic-gate return (0);
110*0Sstevel@tonic-gate }
111*0Sstevel@tonic-gate mdclrerror(ep);
112*0Sstevel@tonic-gate }
113*0Sstevel@tonic-gate
114*0Sstevel@tonic-gate assert((fval == 0) || (fval == -1));
115*0Sstevel@tonic-gate
116*0Sstevel@tonic-gate /* resync each raid */
117*0Sstevel@tonic-gate for (p = nlp; (p != NULL); p = p->next) {
118*0Sstevel@tonic-gate mdname_t *raidnp = p->namep;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate if (meta_raid_resync(sp, raidnp, size, ep) != 0)
121*0Sstevel@tonic-gate rval = -1;
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate
124*0Sstevel@tonic-gate /* cleanup, return success */
125*0Sstevel@tonic-gate if (nlp != NULL)
126*0Sstevel@tonic-gate metafreenamelist(nlp);
127*0Sstevel@tonic-gate if (fval == 0)
128*0Sstevel@tonic-gate exit(0);
129*0Sstevel@tonic-gate return (rval);
130*0Sstevel@tonic-gate }
131