xref: /titanic_41/usr/src/lib/lvm/libmeta/common/meta_replace.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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 2003 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  * replace components in metadevices
31  */
32 
33 #include <meta.h>
34 #include <sys/lvm/md_stripe.h>
35 
36 int
37 meta_replace(mdsetname_t *sp, mdname_t *metanp, mdname_t *oldnp,
38     mdname_t *newnp, char *uname, mdcmdopts_t options, md_error_t *ep)
39 {
40 	char			*miscname;
41 
42 	assert(sp != NULL);
43 
44 	if (is_hspname(uname)) {
45 		mdhspname_t	*hspnp;
46 
47 		if ((hspnp = metahspname(&sp, uname, ep)) == NULL)
48 			return (-1);
49 		assert(sp != NULL);
50 		(void) meta_hs_replace(sp, hspnp, oldnp, newnp, options, ep);
51 		return (0);
52 	}
53 	assert(sp->setno == MD_MIN2SET(meta_getminor(metanp->dev)));
54 	if (metachkmeta(metanp, ep) != 0)
55 		return (-1);
56 
57 
58 	if ((miscname = metagetmiscname(metanp, ep)) == NULL)
59 		return (-1);
60 
61 	if (strcmp(miscname, MD_RAID) == 0) {
62 		return (meta_raid_replace(sp, metanp, oldnp, newnp,
63 		    options, ep));
64 	} else if (strcmp(miscname, MD_TRANS) == 0) {
65 		return (meta_trans_replace(sp, metanp, oldnp, newnp,
66 		    options, ep));
67 	} else if (strcmp(miscname, MD_STRIPE) == 0) {
68 		return (meta_stripe_replace(sp, metanp, oldnp, newnp,
69 		    options, ep));
70 	}
71 
72 	return (mdmderror(ep, MDE_UNKNOWN_TYPE, meta_getminor(metanp->dev),
73 	    metanp->cname));
74 }
75 /*
76  * replace named device
77  */
78 int
79 meta_replace_byname(
80 	mdsetname_t	*sp,
81 	mdname_t	*np,
82 	mdname_t	*oldnp,
83 	mdname_t	*newnp,
84 	mdcmdopts_t	options,
85 	md_error_t	*ep
86 )
87 {
88 	char		*miscname;
89 
90 	/* should have a set */
91 	assert(sp != NULL);
92 	assert(sp->setno == MD_MIN2SET(meta_getminor(np->dev)));
93 
94 	/* get type */
95 	if (metachkmeta(np, ep) != 0)
96 		return (-1);
97 	if ((miscname = metagetmiscname(np, ep)) == NULL)
98 		return (-1);
99 
100 	/* dispatch */
101 	if (strcmp(miscname, MD_RAID) == 0) {
102 		return (meta_raid_replace(sp, np, oldnp, newnp, options, ep));
103 	} else if (strcmp(miscname, MD_MIRROR) == 0) {
104 		return (meta_mirror_replace(sp, np, oldnp, newnp, options, ep));
105 	} else {
106 		return (mdmderror(ep, MDE_UNKNOWN_TYPE, meta_getminor(np->dev),
107 		    np->cname));
108 	}
109 }
110 
111 /*
112  * enable named device
113  */
114 int
115 meta_enable_byname(
116 	mdsetname_t	*sp,
117 	mdname_t	*np,
118 	mdname_t	*compnp,
119 	mdcmdopts_t	options,
120 	md_error_t	*ep
121 )
122 {
123 	char		*miscname;
124 
125 	/* should have a set */
126 	assert(sp != NULL);
127 	assert(sp->setno == MD_MIN2SET(meta_getminor(np->dev)));
128 
129 	/* get type */
130 	if (metachkmeta(np, ep) != 0)
131 		return (-1);
132 	if ((miscname = metagetmiscname(np, ep)) == NULL)
133 		return (-1);
134 
135 	/* dispatch */
136 	if (strcmp(miscname, MD_RAID) == 0) {
137 		return (meta_raid_enable(sp, np, compnp, options, ep));
138 	} else if (strcmp(miscname, MD_MIRROR) == 0) {
139 		return (meta_mirror_enable(sp, np, compnp, options, ep));
140 	} else {
141 		return (mdmderror(ep, MDE_UNKNOWN_TYPE, meta_getminor(np->dev),
142 		    np->cname));
143 	}
144 }
145