xref: /onnv-gate/usr/src/lib/librdc/common/rdcpersist.c (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM  * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM  *
4*7836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM  *
8*7836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM  * and limitations under the License.
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM  *
19*7836SJohn.Forte@Sun.COM  * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM  */
21*7836SJohn.Forte@Sun.COM /*
22*7836SJohn.Forte@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7836SJohn.Forte@Sun.COM  * Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM  */
25*7836SJohn.Forte@Sun.COM 
26*7836SJohn.Forte@Sun.COM #include <sys/types.h>
27*7836SJohn.Forte@Sun.COM #include <sys/stat.h>
28*7836SJohn.Forte@Sun.COM #include <sys/mkdev.h>
29*7836SJohn.Forte@Sun.COM #include <fcntl.h>
30*7836SJohn.Forte@Sun.COM #include <unistd.h>
31*7836SJohn.Forte@Sun.COM #include <stropts.h>
32*7836SJohn.Forte@Sun.COM #include <stdio.h>
33*7836SJohn.Forte@Sun.COM #include <errno.h>
34*7836SJohn.Forte@Sun.COM #include <libintl.h>
35*7836SJohn.Forte@Sun.COM #include <locale.h>
36*7836SJohn.Forte@Sun.COM #include <stdlib.h>
37*7836SJohn.Forte@Sun.COM 
38*7836SJohn.Forte@Sun.COM #include <sys/nsctl/rdcerr.h>
39*7836SJohn.Forte@Sun.COM #include <sys/nsctl/rdc_ioctl.h>
40*7836SJohn.Forte@Sun.COM #include <sys/nsctl/librdc.h>
41*7836SJohn.Forte@Sun.COM #include <sys/nsctl/cfg.h>
42*7836SJohn.Forte@Sun.COM #include <sys/nsctl/nsc_hash.h>
43*7836SJohn.Forte@Sun.COM #include <sys/nsctl/sv.h>
44*7836SJohn.Forte@Sun.COM 
45*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_dtrinkets.h>
46*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_etrinkets.h>
47*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s.h>
48*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s_u.h>
49*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_s_impl.h>
50*7836SJohn.Forte@Sun.COM #include <sys/unistat/spcs_errors.h>
51*7836SJohn.Forte@Sun.COM 
52*7836SJohn.Forte@Sun.COM typedef struct volcount_s {
53*7836SJohn.Forte@Sun.COM 	int count;
54*7836SJohn.Forte@Sun.COM } volcount_t;
55*7836SJohn.Forte@Sun.COM 
56*7836SJohn.Forte@Sun.COM hash_node_t **volhash = NULL;
57*7836SJohn.Forte@Sun.COM 
58*7836SJohn.Forte@Sun.COM char *
config2buf(char * buf,rdcconfig_t * rdc)59*7836SJohn.Forte@Sun.COM config2buf(char *buf, rdcconfig_t *rdc)
60*7836SJohn.Forte@Sun.COM {
61*7836SJohn.Forte@Sun.COM 	snprintf(buf, CFG_MAX_BUF, "%s %s %s %s %s %s %s %s %s %s %s",
62*7836SJohn.Forte@Sun.COM 	    rdc->phost, rdc->pfile, rdc->pbmp, rdc->shost, rdc->sfile,
63*7836SJohn.Forte@Sun.COM 	    rdc->sbmp, rdc->direct, rdc->mode, rdc->group ? rdc->group : "",
64*7836SJohn.Forte@Sun.COM 	    rdc->ctag ? rdc->ctag : "", rdc->options ? rdc->options : "");
65*7836SJohn.Forte@Sun.COM 	return (buf);
66*7836SJohn.Forte@Sun.COM 
67*7836SJohn.Forte@Sun.COM }
68*7836SJohn.Forte@Sun.COM 
69*7836SJohn.Forte@Sun.COM /*
70*7836SJohn.Forte@Sun.COM  * SV type functions.
71*7836SJohn.Forte@Sun.COM  */
72*7836SJohn.Forte@Sun.COM 
73*7836SJohn.Forte@Sun.COM static void
load_rdc_vols(CFGFILE * cfg)74*7836SJohn.Forte@Sun.COM load_rdc_vols(CFGFILE *cfg)
75*7836SJohn.Forte@Sun.COM {
76*7836SJohn.Forte@Sun.COM 	int set;
77*7836SJohn.Forte@Sun.COM 	char key[ CFG_MAX_KEY ];
78*7836SJohn.Forte@Sun.COM 	char buf[ CFG_MAX_BUF ];
79*7836SJohn.Forte@Sun.COM 	char *vol, *bmp, *host1, *host2;
80*7836SJohn.Forte@Sun.COM 	volcount_t *volcount;
81*7836SJohn.Forte@Sun.COM 
82*7836SJohn.Forte@Sun.COM 	if (volhash) {
83*7836SJohn.Forte@Sun.COM 		return;
84*7836SJohn.Forte@Sun.COM 	}
85*7836SJohn.Forte@Sun.COM 
86*7836SJohn.Forte@Sun.COM 	cfg_rewind(cfg, CFG_SEC_CONF);
87*7836SJohn.Forte@Sun.COM 	volhash = nsc_create_hash();
88*7836SJohn.Forte@Sun.COM 	for (set = 1; /*CSTYLED*/; set++) {
89*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d", set);
90*7836SJohn.Forte@Sun.COM 		if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF)) {
91*7836SJohn.Forte@Sun.COM 			break;
92*7836SJohn.Forte@Sun.COM 		}
93*7836SJohn.Forte@Sun.COM 
94*7836SJohn.Forte@Sun.COM 		host1 = strtok(buf, " ");
95*7836SJohn.Forte@Sun.COM 		vol = strtok(NULL, " ");
96*7836SJohn.Forte@Sun.COM 		bmp = strtok(NULL, " ");
97*7836SJohn.Forte@Sun.COM 
98*7836SJohn.Forte@Sun.COM 		if (!self_check(host1)) {
99*7836SJohn.Forte@Sun.COM 			/* next one had better be ours */
100*7836SJohn.Forte@Sun.COM 			host2 = strtok(NULL, " ");
101*7836SJohn.Forte@Sun.COM 			vol = strtok(NULL, " ");
102*7836SJohn.Forte@Sun.COM 			bmp = strtok(NULL, " ");
103*7836SJohn.Forte@Sun.COM 
104*7836SJohn.Forte@Sun.COM 			if (!self_check(host2)) {
105*7836SJohn.Forte@Sun.COM 				continue;
106*7836SJohn.Forte@Sun.COM 			}
107*7836SJohn.Forte@Sun.COM 		}
108*7836SJohn.Forte@Sun.COM 
109*7836SJohn.Forte@Sun.COM 		/* primary vol may be used more than once */
110*7836SJohn.Forte@Sun.COM 		volcount = (volcount_t *)nsc_lookup(volhash, vol);
111*7836SJohn.Forte@Sun.COM 		if (volcount) {
112*7836SJohn.Forte@Sun.COM 			volcount->count++;
113*7836SJohn.Forte@Sun.COM 		} else {
114*7836SJohn.Forte@Sun.COM 			volcount = (volcount_t *)malloc(sizeof (volcount_t));
115*7836SJohn.Forte@Sun.COM 			volcount->count = 1;
116*7836SJohn.Forte@Sun.COM 			nsc_insert_node(volhash, volcount, vol);
117*7836SJohn.Forte@Sun.COM 		}
118*7836SJohn.Forte@Sun.COM 
119*7836SJohn.Forte@Sun.COM 		/* bitmap ought to be only used once */
120*7836SJohn.Forte@Sun.COM 		volcount = (volcount_t *)nsc_lookup(volhash, bmp);
121*7836SJohn.Forte@Sun.COM 		if (volcount) {
122*7836SJohn.Forte@Sun.COM 			/* argh */
123*7836SJohn.Forte@Sun.COM 			volcount->count++;
124*7836SJohn.Forte@Sun.COM 		} else {
125*7836SJohn.Forte@Sun.COM 			volcount = (volcount_t *)malloc(sizeof (volcount_t));
126*7836SJohn.Forte@Sun.COM 			volcount->count = 1;
127*7836SJohn.Forte@Sun.COM 			nsc_insert_node(volhash, volcount, bmp);
128*7836SJohn.Forte@Sun.COM 		}
129*7836SJohn.Forte@Sun.COM 	}
130*7836SJohn.Forte@Sun.COM }
131*7836SJohn.Forte@Sun.COM 
132*7836SJohn.Forte@Sun.COM int
sv_enable_one_nocfg(char * vol)133*7836SJohn.Forte@Sun.COM sv_enable_one_nocfg(char *vol)
134*7836SJohn.Forte@Sun.COM {
135*7836SJohn.Forte@Sun.COM 	struct stat sb;
136*7836SJohn.Forte@Sun.COM 	sv_conf_t svc;
137*7836SJohn.Forte@Sun.COM 	int fd;
138*7836SJohn.Forte@Sun.COM 
139*7836SJohn.Forte@Sun.COM 	bzero(&svc, sizeof (svc));
140*7836SJohn.Forte@Sun.COM 	if (stat(vol, &sb) != 0) {
141*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_OS, 0, "unable to stat %s", vol);
142*7836SJohn.Forte@Sun.COM 		return (-1);
143*7836SJohn.Forte@Sun.COM 	}
144*7836SJohn.Forte@Sun.COM 	if (!S_ISCHR(sb.st_mode)) {
145*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL, "%s is not"
146*7836SJohn.Forte@Sun.COM 		    " a character device", vol);
147*7836SJohn.Forte@Sun.COM 		return (-1);
148*7836SJohn.Forte@Sun.COM 	}
149*7836SJohn.Forte@Sun.COM 
150*7836SJohn.Forte@Sun.COM 	svc.svc_major = major(sb.st_rdev);
151*7836SJohn.Forte@Sun.COM 	svc.svc_minor = minor(sb.st_rdev);
152*7836SJohn.Forte@Sun.COM 	strncpy(svc.svc_path, vol, sizeof (svc.svc_path));
153*7836SJohn.Forte@Sun.COM 
154*7836SJohn.Forte@Sun.COM 	fd = open(SV_DEVICE, O_RDONLY);
155*7836SJohn.Forte@Sun.COM 	if (fd < 0) {
156*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_OS, 0, 0);
157*7836SJohn.Forte@Sun.COM 		return (-1);
158*7836SJohn.Forte@Sun.COM 	}
159*7836SJohn.Forte@Sun.COM 
160*7836SJohn.Forte@Sun.COM 	svc.svc_flag = (NSC_DEVICE | NSC_CACHE);
161*7836SJohn.Forte@Sun.COM 	svc.svc_error = spcs_s_ucreate();
162*7836SJohn.Forte@Sun.COM 
163*7836SJohn.Forte@Sun.COM 	if (ioctl(fd, SVIOC_ENABLE, &svc) < 0) {
164*7836SJohn.Forte@Sun.COM 		if (errno != SV_EENABLED) {
165*7836SJohn.Forte@Sun.COM 			rdc_set_error(&svc.svc_error, RDC_INTERNAL,
166*7836SJohn.Forte@Sun.COM 			    RDC_NONFATAL, 0);
167*7836SJohn.Forte@Sun.COM 			return (-1);
168*7836SJohn.Forte@Sun.COM 		}
169*7836SJohn.Forte@Sun.COM 	}
170*7836SJohn.Forte@Sun.COM 
171*7836SJohn.Forte@Sun.COM 	spcs_log("sv", NULL, gettext("enabled %s"), svc.svc_path);
172*7836SJohn.Forte@Sun.COM 
173*7836SJohn.Forte@Sun.COM 	close(fd);
174*7836SJohn.Forte@Sun.COM 	return (1);
175*7836SJohn.Forte@Sun.COM }
176*7836SJohn.Forte@Sun.COM 
177*7836SJohn.Forte@Sun.COM int
sv_enable_nocfg(rdcconfig_t * rdc)178*7836SJohn.Forte@Sun.COM sv_enable_nocfg(rdcconfig_t *rdc)
179*7836SJohn.Forte@Sun.COM {
180*7836SJohn.Forte@Sun.COM 	struct stat stbv;
181*7836SJohn.Forte@Sun.COM 	struct stat stbb;
182*7836SJohn.Forte@Sun.COM 	sv_conf_t svcv;
183*7836SJohn.Forte@Sun.COM 	sv_conf_t svcb;
184*7836SJohn.Forte@Sun.COM 	char	vol[NSC_MAXPATH];
185*7836SJohn.Forte@Sun.COM 	char	bmp[NSC_MAXPATH];
186*7836SJohn.Forte@Sun.COM 	int fd = -1;
187*7836SJohn.Forte@Sun.COM 
188*7836SJohn.Forte@Sun.COM 
189*7836SJohn.Forte@Sun.COM 	if (self_check(rdc->phost)) {
190*7836SJohn.Forte@Sun.COM 		strncpy(vol, rdc->pfile, NSC_MAXPATH);
191*7836SJohn.Forte@Sun.COM 		strncpy(bmp, rdc->pbmp, NSC_MAXPATH);
192*7836SJohn.Forte@Sun.COM 	} else {
193*7836SJohn.Forte@Sun.COM 		strncpy(vol, rdc->sfile, NSC_MAXPATH);
194*7836SJohn.Forte@Sun.COM 		strncpy(bmp, rdc->sbmp, NSC_MAXPATH);
195*7836SJohn.Forte@Sun.COM 	}
196*7836SJohn.Forte@Sun.COM 
197*7836SJohn.Forte@Sun.COM 	bzero(&svcv, sizeof (svcv));
198*7836SJohn.Forte@Sun.COM 	bzero(&svcb, sizeof (svcb));
199*7836SJohn.Forte@Sun.COM 
200*7836SJohn.Forte@Sun.COM 	if ((stat(vol, &stbv) != 0) || (stat(bmp, &stbb) != 0))
201*7836SJohn.Forte@Sun.COM 		return (-1);
202*7836SJohn.Forte@Sun.COM 
203*7836SJohn.Forte@Sun.COM 	if ((!S_ISCHR(stbv.st_mode)) || (!S_ISCHR(stbb.st_mode)))
204*7836SJohn.Forte@Sun.COM 		return (-1);
205*7836SJohn.Forte@Sun.COM 
206*7836SJohn.Forte@Sun.COM 	svcv.svc_major = major(stbv.st_rdev);
207*7836SJohn.Forte@Sun.COM 	svcb.svc_minor = minor(stbb.st_rdev);
208*7836SJohn.Forte@Sun.COM 
209*7836SJohn.Forte@Sun.COM 	strncpy(svcv.svc_path, vol, sizeof (svcv.svc_path));
210*7836SJohn.Forte@Sun.COM 	strncpy(svcb.svc_path, bmp, sizeof (svcb.svc_path));
211*7836SJohn.Forte@Sun.COM 
212*7836SJohn.Forte@Sun.COM 	fd = open(SV_DEVICE, O_RDONLY);
213*7836SJohn.Forte@Sun.COM 	if (fd < 0)
214*7836SJohn.Forte@Sun.COM 		return (-1);
215*7836SJohn.Forte@Sun.COM 
216*7836SJohn.Forte@Sun.COM 	/* SV enable the volume */
217*7836SJohn.Forte@Sun.COM 	svcv.svc_flag = (NSC_DEVICE | NSC_CACHE);
218*7836SJohn.Forte@Sun.COM 	svcv.svc_error = spcs_s_ucreate();
219*7836SJohn.Forte@Sun.COM 
220*7836SJohn.Forte@Sun.COM 	if (ioctl(fd, SVIOC_ENABLE, &svcv) < 0) {
221*7836SJohn.Forte@Sun.COM 		if (errno != SV_EENABLED) {
222*7836SJohn.Forte@Sun.COM 			spcs_log("sv", &svcv.svc_error,
223*7836SJohn.Forte@Sun.COM 			    gettext("unable to enable %s"),
224*7836SJohn.Forte@Sun.COM 			    svcv.svc_path);
225*7836SJohn.Forte@Sun.COM 			spcs_s_ufree(&svcv.svc_error);
226*7836SJohn.Forte@Sun.COM 			return (-1);
227*7836SJohn.Forte@Sun.COM 		}
228*7836SJohn.Forte@Sun.COM 	}
229*7836SJohn.Forte@Sun.COM 
230*7836SJohn.Forte@Sun.COM 	/* SV enable the bitmap disable the vol on error */
231*7836SJohn.Forte@Sun.COM 	svcb.svc_flag = (NSC_DEVICE | NSC_CACHE);
232*7836SJohn.Forte@Sun.COM 	svcb.svc_error = spcs_s_ucreate();
233*7836SJohn.Forte@Sun.COM 
234*7836SJohn.Forte@Sun.COM 	if (ioctl(fd, SVIOC_ENABLE, &svcb) < 0) {
235*7836SJohn.Forte@Sun.COM 		if (errno != SV_EENABLED) {
236*7836SJohn.Forte@Sun.COM 			spcs_log("sv", &svcb.svc_error,
237*7836SJohn.Forte@Sun.COM 			    gettext("unable to enable %s"),
238*7836SJohn.Forte@Sun.COM 			    svcb.svc_path);
239*7836SJohn.Forte@Sun.COM 			if (ioctl(fd, SVIOC_DISABLE, &svcv) < 0)
240*7836SJohn.Forte@Sun.COM 				spcs_log("sv", &svcv.svc_error,
241*7836SJohn.Forte@Sun.COM 				    gettext("unable to disable %s"),
242*7836SJohn.Forte@Sun.COM 				    svcv.svc_path);
243*7836SJohn.Forte@Sun.COM 
244*7836SJohn.Forte@Sun.COM 			spcs_s_ufree(&svcv.svc_error);
245*7836SJohn.Forte@Sun.COM 			spcs_s_ufree(&svcb.svc_error);
246*7836SJohn.Forte@Sun.COM 			return (-1);
247*7836SJohn.Forte@Sun.COM 		}
248*7836SJohn.Forte@Sun.COM 	}
249*7836SJohn.Forte@Sun.COM 
250*7836SJohn.Forte@Sun.COM 
251*7836SJohn.Forte@Sun.COM 	spcs_log("sv", NULL, gettext("enabled %s"), svcv.svc_path);
252*7836SJohn.Forte@Sun.COM 	spcs_log("sv", NULL, gettext("enabled %s"), svcb.svc_path);
253*7836SJohn.Forte@Sun.COM 	spcs_s_ufree(&svcv.svc_error);
254*7836SJohn.Forte@Sun.COM 	spcs_s_ufree(&svcb.svc_error);
255*7836SJohn.Forte@Sun.COM 
256*7836SJohn.Forte@Sun.COM 
257*7836SJohn.Forte@Sun.COM 	if (fd >= 0)
258*7836SJohn.Forte@Sun.COM 		(void) close(fd);
259*7836SJohn.Forte@Sun.COM 
260*7836SJohn.Forte@Sun.COM 	return (1);
261*7836SJohn.Forte@Sun.COM }
262*7836SJohn.Forte@Sun.COM 
263*7836SJohn.Forte@Sun.COM int
do_autosv_enable(CFGFILE * cfg,rdcconfig_t * rdc)264*7836SJohn.Forte@Sun.COM do_autosv_enable(CFGFILE *cfg, rdcconfig_t *rdc)
265*7836SJohn.Forte@Sun.COM {
266*7836SJohn.Forte@Sun.COM 	char vol[NSC_MAXPATH];
267*7836SJohn.Forte@Sun.COM 	char bmp[NSC_MAXPATH];
268*7836SJohn.Forte@Sun.COM 
269*7836SJohn.Forte@Sun.COM 	cfg_load_svols(cfg);
270*7836SJohn.Forte@Sun.COM 	cfg_load_dsvols(cfg);
271*7836SJohn.Forte@Sun.COM 	cfg_load_shadows(cfg);
272*7836SJohn.Forte@Sun.COM 	load_rdc_vols(cfg);
273*7836SJohn.Forte@Sun.COM 
274*7836SJohn.Forte@Sun.COM 	if (self_check(rdc->phost)) {
275*7836SJohn.Forte@Sun.COM 		strncpy(vol, rdc->pfile, NSC_MAXPATH);
276*7836SJohn.Forte@Sun.COM 		strncpy(bmp, rdc->pbmp, NSC_MAXPATH);
277*7836SJohn.Forte@Sun.COM 	} else {
278*7836SJohn.Forte@Sun.COM 		strncpy(vol, rdc->sfile, NSC_MAXPATH);
279*7836SJohn.Forte@Sun.COM 		strncpy(bmp, rdc->sbmp, NSC_MAXPATH);
280*7836SJohn.Forte@Sun.COM 	}
281*7836SJohn.Forte@Sun.COM 	if (nsc_lookup(volhash, vol) == NULL) {
282*7836SJohn.Forte@Sun.COM 		if (cfg_vol_enable(cfg, vol, rdc->ctag, "sndr") < 0) {
283*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
284*7836SJohn.Forte@Sun.COM 			    "auto sv enable failed for %s", vol);
285*7836SJohn.Forte@Sun.COM 			return (-1);
286*7836SJohn.Forte@Sun.COM 		}
287*7836SJohn.Forte@Sun.COM 	}
288*7836SJohn.Forte@Sun.COM 	if (nsc_lookup(volhash, bmp) == NULL) {
289*7836SJohn.Forte@Sun.COM 		if (cfg_vol_enable(cfg, bmp, rdc->ctag, "sndr") < 0) {
290*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
291*7836SJohn.Forte@Sun.COM 			    "auto sv enable failed for %s", vol);
292*7836SJohn.Forte@Sun.COM 			return (-1);
293*7836SJohn.Forte@Sun.COM 		}
294*7836SJohn.Forte@Sun.COM 	}
295*7836SJohn.Forte@Sun.COM 
296*7836SJohn.Forte@Sun.COM 	nsc_remove_all(volhash, free);
297*7836SJohn.Forte@Sun.COM 	volhash = NULL;
298*7836SJohn.Forte@Sun.COM 
299*7836SJohn.Forte@Sun.COM 	cfg_unload_shadows();
300*7836SJohn.Forte@Sun.COM 	cfg_unload_dsvols();
301*7836SJohn.Forte@Sun.COM 	cfg_unload_svols();
302*7836SJohn.Forte@Sun.COM 
303*7836SJohn.Forte@Sun.COM 	return (1);
304*7836SJohn.Forte@Sun.COM }
305*7836SJohn.Forte@Sun.COM 
306*7836SJohn.Forte@Sun.COM int
do_autosv_disable(CFGFILE * cfg,rdcconfig_t * rdc)307*7836SJohn.Forte@Sun.COM do_autosv_disable(CFGFILE *cfg, rdcconfig_t *rdc)
308*7836SJohn.Forte@Sun.COM {
309*7836SJohn.Forte@Sun.COM 	char vol[NSC_MAXPATH];
310*7836SJohn.Forte@Sun.COM 	char bmp[NSC_MAXPATH];
311*7836SJohn.Forte@Sun.COM 	volcount_t *vc;
312*7836SJohn.Forte@Sun.COM 
313*7836SJohn.Forte@Sun.COM 	cfg_load_svols(cfg);
314*7836SJohn.Forte@Sun.COM 	cfg_load_dsvols(cfg);
315*7836SJohn.Forte@Sun.COM 	cfg_load_shadows(cfg);
316*7836SJohn.Forte@Sun.COM 	load_rdc_vols(cfg);
317*7836SJohn.Forte@Sun.COM 
318*7836SJohn.Forte@Sun.COM 	if (self_check(rdc->phost)) {
319*7836SJohn.Forte@Sun.COM 		strncpy(vol, rdc->pfile, NSC_MAXPATH);
320*7836SJohn.Forte@Sun.COM 		strncpy(bmp, rdc->pbmp, NSC_MAXPATH);
321*7836SJohn.Forte@Sun.COM 	} else {
322*7836SJohn.Forte@Sun.COM 		strncpy(vol, rdc->sfile, NSC_MAXPATH);
323*7836SJohn.Forte@Sun.COM 		strncpy(bmp, rdc->sbmp, NSC_MAXPATH);
324*7836SJohn.Forte@Sun.COM 	}
325*7836SJohn.Forte@Sun.COM 
326*7836SJohn.Forte@Sun.COM 	vc = nsc_lookup(volhash, vol);
327*7836SJohn.Forte@Sun.COM 	if (vc && (vc->count == 1)) {
328*7836SJohn.Forte@Sun.COM 		if (cfg_vol_disable(cfg, vol, rdc->ctag, "sndr") < 0)
329*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
330*7836SJohn.Forte@Sun.COM 				"auto sv disable failed for %s", vol);
331*7836SJohn.Forte@Sun.COM 	} else if (!vc) {
332*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
333*7836SJohn.Forte@Sun.COM 		    "Unable to find %s in config", vol);
334*7836SJohn.Forte@Sun.COM 	}
335*7836SJohn.Forte@Sun.COM 	vc = nsc_lookup(volhash, bmp);
336*7836SJohn.Forte@Sun.COM 	if (vc && (vc->count == 1)) {
337*7836SJohn.Forte@Sun.COM 		if (cfg_vol_disable(cfg, bmp, rdc->ctag, "sndr") < 0)
338*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
339*7836SJohn.Forte@Sun.COM 				"auto sv disable failed for %s", bmp);
340*7836SJohn.Forte@Sun.COM 
341*7836SJohn.Forte@Sun.COM 	} else if (!vc) {
342*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
343*7836SJohn.Forte@Sun.COM 		    "Unable to find %s in config", bmp);
344*7836SJohn.Forte@Sun.COM 	}
345*7836SJohn.Forte@Sun.COM 
346*7836SJohn.Forte@Sun.COM 	return (1);
347*7836SJohn.Forte@Sun.COM 
348*7836SJohn.Forte@Sun.COM }
349*7836SJohn.Forte@Sun.COM 
350*7836SJohn.Forte@Sun.COM /*
351*7836SJohn.Forte@Sun.COM  * do sv enables for the appropriate vol
352*7836SJohn.Forte@Sun.COM  * and bitmap. If called without persistance
353*7836SJohn.Forte@Sun.COM  * it will follow a chain and sv enable all
354*7836SJohn.Forte@Sun.COM  * otherwise, it will enable only the one
355*7836SJohn.Forte@Sun.COM  * set.
356*7836SJohn.Forte@Sun.COM  */
357*7836SJohn.Forte@Sun.COM int
sv_enable(CFGFILE * cfg,rdcconfig_t * rdcs)358*7836SJohn.Forte@Sun.COM sv_enable(CFGFILE *cfg, rdcconfig_t *rdcs)
359*7836SJohn.Forte@Sun.COM {
360*7836SJohn.Forte@Sun.COM 	rdcconfig_t *rdcp = NULL;
361*7836SJohn.Forte@Sun.COM 
362*7836SJohn.Forte@Sun.COM 	rdcp = rdcs;
363*7836SJohn.Forte@Sun.COM 	if (!rdcp->persist) {
364*7836SJohn.Forte@Sun.COM 
365*7836SJohn.Forte@Sun.COM 		return (sv_enable_nocfg(rdcp));
366*7836SJohn.Forte@Sun.COM 
367*7836SJohn.Forte@Sun.COM 	} else if (cfg == NULL) {
368*7836SJohn.Forte@Sun.COM 
369*7836SJohn.Forte@Sun.COM 		return (-1);
370*7836SJohn.Forte@Sun.COM 
371*7836SJohn.Forte@Sun.COM 	}
372*7836SJohn.Forte@Sun.COM 
373*7836SJohn.Forte@Sun.COM 	do_autosv_enable(cfg, rdcp);
374*7836SJohn.Forte@Sun.COM 
375*7836SJohn.Forte@Sun.COM 	return (1);
376*7836SJohn.Forte@Sun.COM }
377*7836SJohn.Forte@Sun.COM 
378*7836SJohn.Forte@Sun.COM int
sv_disable(CFGFILE * cfg,rdcconfig_t * rdcs)379*7836SJohn.Forte@Sun.COM sv_disable(CFGFILE *cfg, rdcconfig_t *rdcs)
380*7836SJohn.Forte@Sun.COM {
381*7836SJohn.Forte@Sun.COM 	rdcconfig_t *rdcp;
382*7836SJohn.Forte@Sun.COM 
383*7836SJohn.Forte@Sun.COM 	rdcp = rdcs;
384*7836SJohn.Forte@Sun.COM 	if (!rdcp->persist) { /* don't disable */
385*7836SJohn.Forte@Sun.COM 
386*7836SJohn.Forte@Sun.COM 		return (1);
387*7836SJohn.Forte@Sun.COM 
388*7836SJohn.Forte@Sun.COM 	} else if (cfg == NULL) {
389*7836SJohn.Forte@Sun.COM 
390*7836SJohn.Forte@Sun.COM 		return (-1);
391*7836SJohn.Forte@Sun.COM 
392*7836SJohn.Forte@Sun.COM 	}
393*7836SJohn.Forte@Sun.COM 
394*7836SJohn.Forte@Sun.COM 	do_autosv_disable(cfg, rdcp);
395*7836SJohn.Forte@Sun.COM 
396*7836SJohn.Forte@Sun.COM 	return (1);
397*7836SJohn.Forte@Sun.COM 
398*7836SJohn.Forte@Sun.COM }
399*7836SJohn.Forte@Sun.COM 
400*7836SJohn.Forte@Sun.COM /*
401*7836SJohn.Forte@Sun.COM  * disable the appropriate bitmap in rdc
402*7836SJohn.Forte@Sun.COM  * and replace it with bitmap
403*7836SJohn.Forte@Sun.COM  */
404*7836SJohn.Forte@Sun.COM int
sv_reconfig(CFGFILE * cfg,rdcconfig_t * rdc,char * oldbmp,char * newbmp)405*7836SJohn.Forte@Sun.COM sv_reconfig(CFGFILE *cfg, rdcconfig_t *rdc, char *oldbmp, char *newbmp)
406*7836SJohn.Forte@Sun.COM {
407*7836SJohn.Forte@Sun.COM 	rdcconfig_t *rdcp;
408*7836SJohn.Forte@Sun.COM 	int fail = 0;
409*7836SJohn.Forte@Sun.COM 
410*7836SJohn.Forte@Sun.COM 	rdcp = rdc;
411*7836SJohn.Forte@Sun.COM 	if (!rdcp->persist) { /* just enable, don't disable */
412*7836SJohn.Forte@Sun.COM 
413*7836SJohn.Forte@Sun.COM 		sv_enable_one_nocfg(newbmp);
414*7836SJohn.Forte@Sun.COM 
415*7836SJohn.Forte@Sun.COM 	} else if (rdcp->persist) { /* do sv disable and enable */
416*7836SJohn.Forte@Sun.COM 		volcount_t *vc;
417*7836SJohn.Forte@Sun.COM 
418*7836SJohn.Forte@Sun.COM 		cfg_load_svols(cfg);
419*7836SJohn.Forte@Sun.COM 		cfg_load_dsvols(cfg);
420*7836SJohn.Forte@Sun.COM 		cfg_load_shadows(cfg);
421*7836SJohn.Forte@Sun.COM 		load_rdc_vols(cfg);
422*7836SJohn.Forte@Sun.COM 
423*7836SJohn.Forte@Sun.COM 		vc = (volcount_t *)nsc_lookup(volhash, oldbmp);
424*7836SJohn.Forte@Sun.COM 		if (vc && (vc->count == 1)) {
425*7836SJohn.Forte@Sun.COM 			if (cfg_vol_disable(cfg, oldbmp, rdc->ctag, "sndr") < 0)
426*7836SJohn.Forte@Sun.COM 				rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
427*7836SJohn.Forte@Sun.COM 				    "auto sv disable failed for %s", oldbmp);
428*7836SJohn.Forte@Sun.COM 
429*7836SJohn.Forte@Sun.COM 		}
430*7836SJohn.Forte@Sun.COM 		if (nsc_lookup(volhash, newbmp) == NULL) {
431*7836SJohn.Forte@Sun.COM 			if (cfg_vol_enable(cfg,
432*7836SJohn.Forte@Sun.COM 			    newbmp, rdc->ctag, "sndr") < 0) {
433*7836SJohn.Forte@Sun.COM 
434*7836SJohn.Forte@Sun.COM 				rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
435*7836SJohn.Forte@Sun.COM 				    "auto sv enable failed for %s", newbmp);
436*7836SJohn.Forte@Sun.COM 				fail++;
437*7836SJohn.Forte@Sun.COM 			}
438*7836SJohn.Forte@Sun.COM 		}
439*7836SJohn.Forte@Sun.COM 		nsc_remove_all(volhash, free);
440*7836SJohn.Forte@Sun.COM 		volhash = NULL;
441*7836SJohn.Forte@Sun.COM 
442*7836SJohn.Forte@Sun.COM 		cfg_unload_shadows();
443*7836SJohn.Forte@Sun.COM 		cfg_unload_dsvols();
444*7836SJohn.Forte@Sun.COM 		cfg_unload_svols();
445*7836SJohn.Forte@Sun.COM 		if (fail)
446*7836SJohn.Forte@Sun.COM 			return (-1);
447*7836SJohn.Forte@Sun.COM 
448*7836SJohn.Forte@Sun.COM 	}
449*7836SJohn.Forte@Sun.COM 	return (1);
450*7836SJohn.Forte@Sun.COM 
451*7836SJohn.Forte@Sun.COM }
452*7836SJohn.Forte@Sun.COM 
453*7836SJohn.Forte@Sun.COM /*
454*7836SJohn.Forte@Sun.COM  * SNDR functions
455*7836SJohn.Forte@Sun.COM  */
456*7836SJohn.Forte@Sun.COM 
457*7836SJohn.Forte@Sun.COM /*
458*7836SJohn.Forte@Sun.COM  * add_to_rdc_cfg
459*7836SJohn.Forte@Sun.COM  * this adds the successfully created rdc sets to libdscfg,
460*7836SJohn.Forte@Sun.COM  * also, as auto_sv stuff is part of libdscfg, it does the
461*7836SJohn.Forte@Sun.COM  * auto_sv stuff and enables the correct volumes
462*7836SJohn.Forte@Sun.COM  */
463*7836SJohn.Forte@Sun.COM int
add_to_rdc_cfg(rdcconfig_t * rdcs)464*7836SJohn.Forte@Sun.COM add_to_rdc_cfg(rdcconfig_t *rdcs)
465*7836SJohn.Forte@Sun.COM {
466*7836SJohn.Forte@Sun.COM 	CFGFILE *cfg;
467*7836SJohn.Forte@Sun.COM 	rdcconfig_t *rdcp;
468*7836SJohn.Forte@Sun.COM 	char *buf;
469*7836SJohn.Forte@Sun.COM 
470*7836SJohn.Forte@Sun.COM 
471*7836SJohn.Forte@Sun.COM 	buf = calloc(CFG_MAX_BUF, sizeof (char));
472*7836SJohn.Forte@Sun.COM 	if (!buf) {
473*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_OS, RDC_FATAL, NULL);
474*7836SJohn.Forte@Sun.COM 		return (NULL);
475*7836SJohn.Forte@Sun.COM 	}
476*7836SJohn.Forte@Sun.COM 
477*7836SJohn.Forte@Sun.COM 	if ((cfg = cfg_open(NULL)) == NULL) {
478*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_DSCFG, 0, 0);
479*7836SJohn.Forte@Sun.COM 		return (-1);
480*7836SJohn.Forte@Sun.COM 	}
481*7836SJohn.Forte@Sun.COM 	if ((cfg_lock(cfg, CFG_WRLOCK)) < 0) {
482*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_DSCFG, 0, 0);
483*7836SJohn.Forte@Sun.COM 		return (-1);
484*7836SJohn.Forte@Sun.COM 	}
485*7836SJohn.Forte@Sun.COM 
486*7836SJohn.Forte@Sun.COM 	rdcp = rdcs;
487*7836SJohn.Forte@Sun.COM 	while (rdcp)  {
488*7836SJohn.Forte@Sun.COM 		buf = config2buf(buf, rdcp);
489*7836SJohn.Forte@Sun.COM 		if ((sv_enable(cfg, rdcp) < 0) ||
490*7836SJohn.Forte@Sun.COM 		    (cfg_put_cstring(cfg, "sndr", buf, CFG_MAX_BUF) < 0)) {
491*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
492*7836SJohn.Forte@Sun.COM 			free(buf);
493*7836SJohn.Forte@Sun.COM 			return (-1);
494*7836SJohn.Forte@Sun.COM 		}
495*7836SJohn.Forte@Sun.COM 		rdcp = rdcp->next;
496*7836SJohn.Forte@Sun.COM 	}
497*7836SJohn.Forte@Sun.COM 	if (!cfg_commit(cfg)) {
498*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_DSCFG, 0, NULL);
499*7836SJohn.Forte@Sun.COM 		return (-1);
500*7836SJohn.Forte@Sun.COM 	}
501*7836SJohn.Forte@Sun.COM 
502*7836SJohn.Forte@Sun.COM 	cfg_close(cfg);
503*7836SJohn.Forte@Sun.COM 
504*7836SJohn.Forte@Sun.COM 	return (0);
505*7836SJohn.Forte@Sun.COM }
506*7836SJohn.Forte@Sun.COM 
507*7836SJohn.Forte@Sun.COM int
cfg_lookup(CFGFILE * cfg,char * shost,char * sfile)508*7836SJohn.Forte@Sun.COM cfg_lookup(CFGFILE *cfg, char *shost, char *sfile)
509*7836SJohn.Forte@Sun.COM {
510*7836SJohn.Forte@Sun.COM 	char buf[CFG_MAX_BUF];
511*7836SJohn.Forte@Sun.COM 	char key[CFG_MAX_KEY];
512*7836SJohn.Forte@Sun.COM 	int setnum;
513*7836SJohn.Forte@Sun.COM 	int numsets = 0;
514*7836SJohn.Forte@Sun.COM 
515*7836SJohn.Forte@Sun.COM 	numsets = cfg_get_num_entries(cfg, "sndr");
516*7836SJohn.Forte@Sun.COM 	for (setnum = 1; setnum <= numsets; setnum++) {
517*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
518*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.shost", setnum);
519*7836SJohn.Forte@Sun.COM 		if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) < 0) {
520*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
521*7836SJohn.Forte@Sun.COM 			return (-1);
522*7836SJohn.Forte@Sun.COM 		}
523*7836SJohn.Forte@Sun.COM 		if (strncmp(buf, shost, strlen(shost)))
524*7836SJohn.Forte@Sun.COM 			continue;
525*7836SJohn.Forte@Sun.COM 
526*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
527*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.secondary", setnum);
528*7836SJohn.Forte@Sun.COM 		if (cfg_get_cstring(cfg, key, buf, CFG_MAX_BUF) < 0) {
529*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
530*7836SJohn.Forte@Sun.COM 			return (-1);
531*7836SJohn.Forte@Sun.COM 		}
532*7836SJohn.Forte@Sun.COM 		if (strncmp(buf, sfile, strlen(sfile)))
533*7836SJohn.Forte@Sun.COM 			continue;
534*7836SJohn.Forte@Sun.COM 		break;
535*7836SJohn.Forte@Sun.COM 	}
536*7836SJohn.Forte@Sun.COM 	return (setnum);
537*7836SJohn.Forte@Sun.COM }
538*7836SJohn.Forte@Sun.COM 
539*7836SJohn.Forte@Sun.COM void
remove_from_rdc_cfg(rdcconfig_t * rdcs)540*7836SJohn.Forte@Sun.COM remove_from_rdc_cfg(rdcconfig_t *rdcs)
541*7836SJohn.Forte@Sun.COM {
542*7836SJohn.Forte@Sun.COM 	CFGFILE *cfg;
543*7836SJohn.Forte@Sun.COM 	rdcconfig_t *rdcp;
544*7836SJohn.Forte@Sun.COM 	char key[CFG_MAX_KEY];
545*7836SJohn.Forte@Sun.COM 
546*7836SJohn.Forte@Sun.COM 	rdcp = rdcs;
547*7836SJohn.Forte@Sun.COM 	cfg = cfg_open(NULL);
548*7836SJohn.Forte@Sun.COM 	cfg_lock(cfg, CFG_WRLOCK);
549*7836SJohn.Forte@Sun.COM 
550*7836SJohn.Forte@Sun.COM 	while (rdcp) {
551*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d",
552*7836SJohn.Forte@Sun.COM 		    cfg_lookup(cfg, rdcp->shost, rdcp->sfile));
553*7836SJohn.Forte@Sun.COM 		if ((sv_disable(cfg, rdcp) < 0) ||
554*7836SJohn.Forte@Sun.COM 		    (cfg_put_cstring(cfg, key, NULL, 0)) < 0) {
555*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
556*7836SJohn.Forte@Sun.COM 		}
557*7836SJohn.Forte@Sun.COM 
558*7836SJohn.Forte@Sun.COM 		rdcp = rdcp->next;
559*7836SJohn.Forte@Sun.COM 	}
560*7836SJohn.Forte@Sun.COM 	cfg_commit(cfg);
561*7836SJohn.Forte@Sun.COM 	cfg_close(cfg);
562*7836SJohn.Forte@Sun.COM }
563*7836SJohn.Forte@Sun.COM /*ARGSUSED*/
564*7836SJohn.Forte@Sun.COM int
replace_entry(int offset,char * entry)565*7836SJohn.Forte@Sun.COM replace_entry(int offset, char *entry)
566*7836SJohn.Forte@Sun.COM {
567*7836SJohn.Forte@Sun.COM 	return (1);
568*7836SJohn.Forte@Sun.COM }
569*7836SJohn.Forte@Sun.COM 
570*7836SJohn.Forte@Sun.COM /*
571*7836SJohn.Forte@Sun.COM  * this will set the value at "field" in dscfg to the
572*7836SJohn.Forte@Sun.COM  * value contained in entry.
573*7836SJohn.Forte@Sun.COM  * for things like bitmap reconfigs, only pass one rdc
574*7836SJohn.Forte@Sun.COM  * not a chain
575*7836SJohn.Forte@Sun.COM  */
576*7836SJohn.Forte@Sun.COM int
replace_cfgfield(rdcconfig_t * rdc,char * field,char * entry)577*7836SJohn.Forte@Sun.COM replace_cfgfield(rdcconfig_t *rdc, char *field, char *entry)
578*7836SJohn.Forte@Sun.COM {
579*7836SJohn.Forte@Sun.COM 	CFGFILE *cfg;
580*7836SJohn.Forte@Sun.COM 	rdcconfig_t *rdcp;
581*7836SJohn.Forte@Sun.COM 	char key[CFG_MAX_KEY];
582*7836SJohn.Forte@Sun.COM 	char newentry[CFG_MAX_BUF];
583*7836SJohn.Forte@Sun.COM 	char oldbmp[CFG_MAX_BUF];
584*7836SJohn.Forte@Sun.COM 	int setnum;
585*7836SJohn.Forte@Sun.COM 	int ispbmp = 0;
586*7836SJohn.Forte@Sun.COM 	int issbmp = 0;
587*7836SJohn.Forte@Sun.COM 
588*7836SJohn.Forte@Sun.COM 	if (strncmp(field, "pbitmap", NSC_MAXPATH) == 0)
589*7836SJohn.Forte@Sun.COM 		ispbmp++;
590*7836SJohn.Forte@Sun.COM 	if (strncmp(field, "sbitmap", NSC_MAXPATH) == 0)
591*7836SJohn.Forte@Sun.COM 		issbmp++;
592*7836SJohn.Forte@Sun.COM 
593*7836SJohn.Forte@Sun.COM 	bzero(newentry, sizeof (newentry));
594*7836SJohn.Forte@Sun.COM 	if (!entry || strlen(entry) == 0)
595*7836SJohn.Forte@Sun.COM 		*newentry = '-';
596*7836SJohn.Forte@Sun.COM 	else
597*7836SJohn.Forte@Sun.COM 		strncpy(newentry, entry, CFG_MAX_BUF);
598*7836SJohn.Forte@Sun.COM 
599*7836SJohn.Forte@Sun.COM 
600*7836SJohn.Forte@Sun.COM 	if ((cfg = cfg_open(NULL)) == NULL) {
601*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_DSCFG, 0, 0);
602*7836SJohn.Forte@Sun.COM 		return (-1);
603*7836SJohn.Forte@Sun.COM 	}
604*7836SJohn.Forte@Sun.COM 	if ((cfg_lock(cfg, CFG_WRLOCK)) < 0) {
605*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_DSCFG, 0, 0);
606*7836SJohn.Forte@Sun.COM 		return (-1);
607*7836SJohn.Forte@Sun.COM 	}
608*7836SJohn.Forte@Sun.COM 
609*7836SJohn.Forte@Sun.COM 	rdcp = rdc;
610*7836SJohn.Forte@Sun.COM 	while (rdcp) {
611*7836SJohn.Forte@Sun.COM 		if ((setnum = cfg_lookup(cfg, rdcp->shost, rdcp->sfile)) < 0) {
612*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
613*7836SJohn.Forte@Sun.COM 			return (-1);
614*7836SJohn.Forte@Sun.COM 		}
615*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.%s", setnum, field);
616*7836SJohn.Forte@Sun.COM 		if (!((ispbmp || issbmp) &&
617*7836SJohn.Forte@Sun.COM 		    (cfg_get_cstring(cfg, key, oldbmp, CFG_MAX_BUF)) == 0)) {
618*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, "unable to get %s",
619*7836SJohn.Forte@Sun.COM 			    key);
620*7836SJohn.Forte@Sun.COM 		}
621*7836SJohn.Forte@Sun.COM 		if (((ispbmp && self_check(rdcp->phost)) ||
622*7836SJohn.Forte@Sun.COM 		    (issbmp && self_check(rdcp->shost))) &&
623*7836SJohn.Forte@Sun.COM 		    (sv_reconfig(cfg, rdcp, oldbmp, newentry) < 0)) {
624*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_INTERNAL, RDC_NONFATAL,
625*7836SJohn.Forte@Sun.COM 			    "unable to sv reconfig %s to %s", oldbmp, newentry);
626*7836SJohn.Forte@Sun.COM 			return (-1);
627*7836SJohn.Forte@Sun.COM 		}
628*7836SJohn.Forte@Sun.COM 
629*7836SJohn.Forte@Sun.COM 		if ((cfg_put_cstring(cfg, key, newentry, CFG_MAX_BUF)) < 0) {
630*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
631*7836SJohn.Forte@Sun.COM 			return (-1);
632*7836SJohn.Forte@Sun.COM 		}
633*7836SJohn.Forte@Sun.COM 		rdcp = rdcp->next;
634*7836SJohn.Forte@Sun.COM 	}
635*7836SJohn.Forte@Sun.COM 	cfg_commit(cfg);
636*7836SJohn.Forte@Sun.COM 	cfg_close(cfg);
637*7836SJohn.Forte@Sun.COM 	return (1);
638*7836SJohn.Forte@Sun.COM }
639*7836SJohn.Forte@Sun.COM 
640*7836SJohn.Forte@Sun.COM /*
641*7836SJohn.Forte@Sun.COM  * reverse_in_cfg
642*7836SJohn.Forte@Sun.COM  * used by RDC_OPT_REVERSE_ROLE
643*7836SJohn.Forte@Sun.COM  * swaps primary info and secondary info
644*7836SJohn.Forte@Sun.COM  */
645*7836SJohn.Forte@Sun.COM int
reverse_in_cfg(rdcconfig_t * rdc)646*7836SJohn.Forte@Sun.COM reverse_in_cfg(rdcconfig_t *rdc)
647*7836SJohn.Forte@Sun.COM {
648*7836SJohn.Forte@Sun.COM 	CFGFILE *cfg;
649*7836SJohn.Forte@Sun.COM 	rdcconfig_t *rdcp = NULL;
650*7836SJohn.Forte@Sun.COM 	char key[CFG_MAX_KEY];
651*7836SJohn.Forte@Sun.COM 	int setnum;
652*7836SJohn.Forte@Sun.COM 
653*7836SJohn.Forte@Sun.COM 	if ((cfg = cfg_open(NULL)) == NULL) {
654*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_DSCFG, 0, 0);
655*7836SJohn.Forte@Sun.COM 		return (-1);
656*7836SJohn.Forte@Sun.COM 	}
657*7836SJohn.Forte@Sun.COM 	if ((cfg_lock(cfg, CFG_WRLOCK)) < 0) {
658*7836SJohn.Forte@Sun.COM 		rdc_set_error(NULL, RDC_DSCFG, 0, 0);
659*7836SJohn.Forte@Sun.COM 		return (-1);
660*7836SJohn.Forte@Sun.COM 	}
661*7836SJohn.Forte@Sun.COM 
662*7836SJohn.Forte@Sun.COM 	rdcp = rdc;
663*7836SJohn.Forte@Sun.COM 	while (rdcp) {
664*7836SJohn.Forte@Sun.COM 		if ((setnum = cfg_lookup(cfg, rdcp->shost, rdcp->sfile)) < 0) {
665*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
666*7836SJohn.Forte@Sun.COM 			goto badconfig;
667*7836SJohn.Forte@Sun.COM 		}
668*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
669*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.phost", setnum);
670*7836SJohn.Forte@Sun.COM 		if ((cfg_put_cstring(cfg, key, rdcp->shost, CFG_MAX_BUF)) < 0) {
671*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
672*7836SJohn.Forte@Sun.COM 			goto badconfig;
673*7836SJohn.Forte@Sun.COM 		}
674*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
675*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.primary", setnum);
676*7836SJohn.Forte@Sun.COM 		if ((cfg_put_cstring(cfg, key, rdcp->sfile, CFG_MAX_BUF)) < 0) {
677*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
678*7836SJohn.Forte@Sun.COM 			goto badconfig;
679*7836SJohn.Forte@Sun.COM 		}
680*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
681*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.pbitmap", setnum);
682*7836SJohn.Forte@Sun.COM 		if ((cfg_put_cstring(cfg, key, rdcp->sbmp, CFG_MAX_BUF)) < 0) {
683*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
684*7836SJohn.Forte@Sun.COM 			goto badconfig;
685*7836SJohn.Forte@Sun.COM 		}
686*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
687*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.shost", setnum);
688*7836SJohn.Forte@Sun.COM 		if ((cfg_put_cstring(cfg, key, rdcp->phost, CFG_MAX_BUF)) < 0) {
689*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
690*7836SJohn.Forte@Sun.COM 			goto badconfig;
691*7836SJohn.Forte@Sun.COM 		}
692*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
693*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.secondary", setnum);
694*7836SJohn.Forte@Sun.COM 		if ((cfg_put_cstring(cfg, key, rdcp->pfile, CFG_MAX_BUF)) < 0) {
695*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
696*7836SJohn.Forte@Sun.COM 			goto badconfig;
697*7836SJohn.Forte@Sun.COM 		}
698*7836SJohn.Forte@Sun.COM 		bzero(key, CFG_MAX_KEY);
699*7836SJohn.Forte@Sun.COM 		snprintf(key, CFG_MAX_KEY, "sndr.set%d.sbitmap", setnum);
700*7836SJohn.Forte@Sun.COM 		if ((cfg_put_cstring(cfg, key, rdcp->pbmp, CFG_MAX_BUF)) < 0) {
701*7836SJohn.Forte@Sun.COM 			rdc_set_error(NULL, RDC_DSCFG, 0, 0);
702*7836SJohn.Forte@Sun.COM 			goto badconfig;
703*7836SJohn.Forte@Sun.COM 		}
704*7836SJohn.Forte@Sun.COM 		rdcp = rdcp->next;
705*7836SJohn.Forte@Sun.COM 	}
706*7836SJohn.Forte@Sun.COM 	if (!cfg_commit(cfg)) {
707*7836SJohn.Forte@Sun.COM 		cfg_close(cfg);
708*7836SJohn.Forte@Sun.COM 		return (-1);
709*7836SJohn.Forte@Sun.COM 	}
710*7836SJohn.Forte@Sun.COM 	cfg_close(cfg);
711*7836SJohn.Forte@Sun.COM 	return (0);
712*7836SJohn.Forte@Sun.COM 
713*7836SJohn.Forte@Sun.COM badconfig:
714*7836SJohn.Forte@Sun.COM 	cfg_close(cfg);
715*7836SJohn.Forte@Sun.COM 	return (-1);
716*7836SJohn.Forte@Sun.COM }
717