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 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 /*
30 * mirror operations
31 */
32
33 #include <meta.h>
34 #include <sdssc.h>
35
36 /*
37 * resync named device
38 */
39 int
meta_resync_byname(mdsetname_t * sp,mdname_t * np,daddr_t size,md_error_t * ep,md_resync_cmd_t cmd)40 meta_resync_byname(
41 mdsetname_t *sp,
42 mdname_t *np,
43 daddr_t size,
44 md_error_t *ep,
45 md_resync_cmd_t cmd /* action to perform */
46 )
47 {
48 char *miscname;
49
50 /* should have a set */
51 assert(sp != NULL);
52 assert(sp->setno == MD_MIN2SET(meta_getminor(np->dev)));
53
54 /* get type */
55 if (metachkmeta(np, ep) != 0)
56 return (-1);
57 if ((miscname = metagetmiscname(np, ep)) == NULL)
58 return (-1);
59
60 /* dispatch */
61 if (strcmp(miscname, MD_RAID) == 0) {
62 return (meta_raid_resync(sp, np, size, ep));
63 } else if (strcmp(miscname, MD_MIRROR) == 0) {
64 return (meta_mirror_resync(sp, np, size, ep, cmd));
65 } else {
66 return (mdmderror(ep, MDE_UNKNOWN_TYPE, meta_getminor(np->dev),
67 np->cname));
68 }
69 }
70
71 /*
72 * resync all devices
73 */
74 int
meta_resync_all(mdsetname_t * sp,daddr_t size,md_error_t * ep)75 meta_resync_all(
76 mdsetname_t *sp,
77 daddr_t size,
78 md_error_t *ep
79 )
80 {
81 int rval = 0;
82 md_set_desc *sd;
83
84 /* see if we have any databases */
85 if (meta_setup_db_locations(ep) != 0) {
86 if (mdismddberror(ep, MDE_DB_NODB)) {
87 mdclrerror(ep);
88 return (0);
89 }
90 rval = -1;
91 }
92
93 if (!(metaislocalset(sp))) {
94 if ((sd = metaget_setdesc(sp, ep)) == NULL)
95 return (-1);
96
97 /* MN disksets don't use DCS clustering services. */
98 if (!(MD_MNSET_DESC(sd)))
99 sdssc_notify_service(NULL, Shutdown_Services);
100 }
101
102 /* resync units */
103 if (meta_mirror_resync_all(sp, size, ep) != 0)
104 rval = -1;
105 if (meta_raid_resync_all(sp, size, ep) != 0)
106 rval = -1;
107 return (rval);
108 }
109