xref: /illumos-gate/usr/src/cmd/sendmail/db/mp/mp_bh.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*-
2*7c478bd9Sstevel@tonic-gate  * See the file LICENSE for redistribution information.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1996, 1997, 1998
5*7c478bd9Sstevel@tonic-gate  *	Sleepycat Software.  All rights reserved.
6*7c478bd9Sstevel@tonic-gate  */
7*7c478bd9Sstevel@tonic-gate #include "config.h"
8*7c478bd9Sstevel@tonic-gate 
9*7c478bd9Sstevel@tonic-gate #ifndef lint
10*7c478bd9Sstevel@tonic-gate static const char sccsid[] = "@(#)mp_bh.c	10.45 (Sleepycat) 11/25/98";
11*7c478bd9Sstevel@tonic-gate #endif /* not lint */
12*7c478bd9Sstevel@tonic-gate 
13*7c478bd9Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES
14*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
15*7c478bd9Sstevel@tonic-gate 
16*7c478bd9Sstevel@tonic-gate #include <errno.h>
17*7c478bd9Sstevel@tonic-gate #include <string.h>
18*7c478bd9Sstevel@tonic-gate #include <unistd.h>
19*7c478bd9Sstevel@tonic-gate #endif
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate #include "db_int.h"
22*7c478bd9Sstevel@tonic-gate #include "shqueue.h"
23*7c478bd9Sstevel@tonic-gate #include "db_shash.h"
24*7c478bd9Sstevel@tonic-gate #include "mp.h"
25*7c478bd9Sstevel@tonic-gate #include "common_ext.h"
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate static int __memp_upgrade __P((DB_MPOOL *, DB_MPOOLFILE *, MPOOLFILE *));
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * __memp_bhwrite --
31*7c478bd9Sstevel@tonic-gate  *	Write the page associated with a given bucket header.
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __memp_bhwrite
34*7c478bd9Sstevel@tonic-gate  * PUBLIC:     __P((DB_MPOOL *, MPOOLFILE *, BH *, int *, int *));
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate int
__memp_bhwrite(dbmp,mfp,bhp,restartp,wrotep)37*7c478bd9Sstevel@tonic-gate __memp_bhwrite(dbmp, mfp, bhp, restartp, wrotep)
38*7c478bd9Sstevel@tonic-gate 	DB_MPOOL *dbmp;
39*7c478bd9Sstevel@tonic-gate 	MPOOLFILE *mfp;
40*7c478bd9Sstevel@tonic-gate 	BH *bhp;
41*7c478bd9Sstevel@tonic-gate 	int *restartp, *wrotep;
42*7c478bd9Sstevel@tonic-gate {
43*7c478bd9Sstevel@tonic-gate 	DB_MPOOLFILE *dbmfp;
44*7c478bd9Sstevel@tonic-gate 	DB_MPREG *mpreg;
45*7c478bd9Sstevel@tonic-gate 	int incremented, ret;
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate 	if (restartp != NULL)
48*7c478bd9Sstevel@tonic-gate 		*restartp = 0;
49*7c478bd9Sstevel@tonic-gate 	if (wrotep != NULL)
50*7c478bd9Sstevel@tonic-gate 		*wrotep = 0;
51*7c478bd9Sstevel@tonic-gate 	incremented = 0;
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate 	/*
54*7c478bd9Sstevel@tonic-gate 	 * Walk the process' DB_MPOOLFILE list and find a file descriptor for
55*7c478bd9Sstevel@tonic-gate 	 * the file.  We also check that the descriptor is open for writing.
56*7c478bd9Sstevel@tonic-gate 	 * If we find a descriptor on the file that's not open for writing, we
57*7c478bd9Sstevel@tonic-gate 	 * try and upgrade it to make it writeable.  If that fails, we're done.
58*7c478bd9Sstevel@tonic-gate 	 */
59*7c478bd9Sstevel@tonic-gate 	LOCKHANDLE(dbmp, dbmp->mutexp);
60*7c478bd9Sstevel@tonic-gate 	for (dbmfp = TAILQ_FIRST(&dbmp->dbmfq);
61*7c478bd9Sstevel@tonic-gate 	    dbmfp != NULL; dbmfp = TAILQ_NEXT(dbmfp, q))
62*7c478bd9Sstevel@tonic-gate 		if (dbmfp->mfp == mfp) {
63*7c478bd9Sstevel@tonic-gate 			if (F_ISSET(dbmfp, MP_READONLY) &&
64*7c478bd9Sstevel@tonic-gate 			    __memp_upgrade(dbmp, dbmfp, mfp)) {
65*7c478bd9Sstevel@tonic-gate 				UNLOCKHANDLE(dbmp, dbmp->mutexp);
66*7c478bd9Sstevel@tonic-gate 				return (0);
67*7c478bd9Sstevel@tonic-gate 			}
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate 			/*
70*7c478bd9Sstevel@tonic-gate 			 * Increment the reference count -- see the comment in
71*7c478bd9Sstevel@tonic-gate 			 * memp_fclose().
72*7c478bd9Sstevel@tonic-gate 			 */
73*7c478bd9Sstevel@tonic-gate 			++dbmfp->ref;
74*7c478bd9Sstevel@tonic-gate 			incremented = 1;
75*7c478bd9Sstevel@tonic-gate 			break;
76*7c478bd9Sstevel@tonic-gate 		}
77*7c478bd9Sstevel@tonic-gate 	UNLOCKHANDLE(dbmp, dbmp->mutexp);
78*7c478bd9Sstevel@tonic-gate 	if (dbmfp != NULL)
79*7c478bd9Sstevel@tonic-gate 		goto found;
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 	/*
82*7c478bd9Sstevel@tonic-gate 	 * It's not a page from a file we've opened.  If the file requires
83*7c478bd9Sstevel@tonic-gate 	 * input/output processing, see if this process has ever registered
84*7c478bd9Sstevel@tonic-gate 	 * information as to how to write this type of file.  If not, there's
85*7c478bd9Sstevel@tonic-gate 	 * nothing we can do.
86*7c478bd9Sstevel@tonic-gate 	 */
87*7c478bd9Sstevel@tonic-gate 	if (mfp->ftype != 0) {
88*7c478bd9Sstevel@tonic-gate 		LOCKHANDLE(dbmp, dbmp->mutexp);
89*7c478bd9Sstevel@tonic-gate 		for (mpreg = LIST_FIRST(&dbmp->dbregq);
90*7c478bd9Sstevel@tonic-gate 		    mpreg != NULL; mpreg = LIST_NEXT(mpreg, q))
91*7c478bd9Sstevel@tonic-gate 			if (mpreg->ftype == mfp->ftype)
92*7c478bd9Sstevel@tonic-gate 				break;
93*7c478bd9Sstevel@tonic-gate 		UNLOCKHANDLE(dbmp, dbmp->mutexp);
94*7c478bd9Sstevel@tonic-gate 		if (mpreg == NULL)
95*7c478bd9Sstevel@tonic-gate 			return (0);
96*7c478bd9Sstevel@tonic-gate 	}
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate 	/*
99*7c478bd9Sstevel@tonic-gate 	 * Try and open the file, attaching to the underlying shared area.
100*7c478bd9Sstevel@tonic-gate 	 *
101*7c478bd9Sstevel@tonic-gate 	 * XXX
102*7c478bd9Sstevel@tonic-gate 	 * Don't try to attach to temporary files.  There are two problems in
103*7c478bd9Sstevel@tonic-gate 	 * trying to do that.  First, if we have different privileges than the
104*7c478bd9Sstevel@tonic-gate 	 * process that "owns" the temporary file, we might create the backing
105*7c478bd9Sstevel@tonic-gate 	 * disk file such that the owning process couldn't read/write its own
106*7c478bd9Sstevel@tonic-gate 	 * buffers, e.g., memp_trickle() running as root creating a file owned
107*7c478bd9Sstevel@tonic-gate 	 * as root, mode 600.  Second, if the temporary file has already been
108*7c478bd9Sstevel@tonic-gate 	 * created, we don't have any way of finding out what its real name is,
109*7c478bd9Sstevel@tonic-gate 	 * and, even if we did, it was already unlinked (so that it won't be
110*7c478bd9Sstevel@tonic-gate 	 * left if the process dies horribly).  This decision causes a problem,
111*7c478bd9Sstevel@tonic-gate 	 * however: if the temporary file consumes the entire buffer cache,
112*7c478bd9Sstevel@tonic-gate 	 * and the owner doesn't flush the buffers to disk, we could end up
113*7c478bd9Sstevel@tonic-gate 	 * with resource starvation, and the memp_trickle() thread couldn't do
114*7c478bd9Sstevel@tonic-gate 	 * anything about it.  That's a pretty unlikely scenario, though.
115*7c478bd9Sstevel@tonic-gate 	 *
116*7c478bd9Sstevel@tonic-gate 	 * XXX
117*7c478bd9Sstevel@tonic-gate 	 * There's no negative cache, so we may repeatedly try and open files
118*7c478bd9Sstevel@tonic-gate 	 * that we have previously tried (and failed) to open.
119*7c478bd9Sstevel@tonic-gate 	 *
120*7c478bd9Sstevel@tonic-gate 	 * Ignore any error, assume it's a permissions problem.
121*7c478bd9Sstevel@tonic-gate 	 */
122*7c478bd9Sstevel@tonic-gate 	if (F_ISSET(mfp, MP_TEMP))
123*7c478bd9Sstevel@tonic-gate 		return (0);
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (__memp_fopen(dbmp, mfp, R_ADDR(dbmp, mfp->path_off),
126*7c478bd9Sstevel@tonic-gate 	    0, 0, mfp->stat.st_pagesize, 0, NULL, &dbmfp) != 0)
127*7c478bd9Sstevel@tonic-gate 		return (0);
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate found:	ret = __memp_pgwrite(dbmfp, bhp, restartp, wrotep);
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	if (incremented) {
132*7c478bd9Sstevel@tonic-gate 		LOCKHANDLE(dbmp, dbmp->mutexp);
133*7c478bd9Sstevel@tonic-gate 		--dbmfp->ref;
134*7c478bd9Sstevel@tonic-gate 		UNLOCKHANDLE(dbmp, dbmp->mutexp);
135*7c478bd9Sstevel@tonic-gate 	}
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	return (ret);
138*7c478bd9Sstevel@tonic-gate }
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate /*
141*7c478bd9Sstevel@tonic-gate  * __memp_pgread --
142*7c478bd9Sstevel@tonic-gate  *	Read a page from a file.
143*7c478bd9Sstevel@tonic-gate  *
144*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __memp_pgread __P((DB_MPOOLFILE *, BH *, int));
145*7c478bd9Sstevel@tonic-gate  */
146*7c478bd9Sstevel@tonic-gate int
__memp_pgread(dbmfp,bhp,can_create)147*7c478bd9Sstevel@tonic-gate __memp_pgread(dbmfp, bhp, can_create)
148*7c478bd9Sstevel@tonic-gate 	DB_MPOOLFILE *dbmfp;
149*7c478bd9Sstevel@tonic-gate 	BH *bhp;
150*7c478bd9Sstevel@tonic-gate 	int can_create;
151*7c478bd9Sstevel@tonic-gate {
152*7c478bd9Sstevel@tonic-gate 	DB_IO db_io;
153*7c478bd9Sstevel@tonic-gate 	DB_MPOOL *dbmp;
154*7c478bd9Sstevel@tonic-gate 	MPOOLFILE *mfp;
155*7c478bd9Sstevel@tonic-gate 	size_t len, pagesize;
156*7c478bd9Sstevel@tonic-gate 	ssize_t nr;
157*7c478bd9Sstevel@tonic-gate 	int created, ret;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 	dbmp = dbmfp->dbmp;
160*7c478bd9Sstevel@tonic-gate 	mfp = dbmfp->mfp;
161*7c478bd9Sstevel@tonic-gate 	pagesize = mfp->stat.st_pagesize;
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 	F_SET(bhp, BH_LOCKED | BH_TRASH);
164*7c478bd9Sstevel@tonic-gate 	LOCKBUFFER(dbmp, bhp);
165*7c478bd9Sstevel@tonic-gate 	UNLOCKREGION(dbmp);
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate 	/*
168*7c478bd9Sstevel@tonic-gate 	 * Temporary files may not yet have been created.  We don't create
169*7c478bd9Sstevel@tonic-gate 	 * them now, we create them when the pages have to be flushed.
170*7c478bd9Sstevel@tonic-gate 	 */
171*7c478bd9Sstevel@tonic-gate 	nr = 0;
172*7c478bd9Sstevel@tonic-gate 	if (dbmfp->fd == -1)
173*7c478bd9Sstevel@tonic-gate 		ret = 0;
174*7c478bd9Sstevel@tonic-gate 	else {
175*7c478bd9Sstevel@tonic-gate 		/*
176*7c478bd9Sstevel@tonic-gate 		 * Ignore read errors if we have permission to create the page.
177*7c478bd9Sstevel@tonic-gate 		 * Assume that the page doesn't exist, and that we'll create it
178*7c478bd9Sstevel@tonic-gate 		 * when we write it out.
179*7c478bd9Sstevel@tonic-gate 		 */
180*7c478bd9Sstevel@tonic-gate 		db_io.fd_io = dbmfp->fd;
181*7c478bd9Sstevel@tonic-gate 		db_io.fd_lock = dbmp->reginfo.fd;
182*7c478bd9Sstevel@tonic-gate 		db_io.mutexp =
183*7c478bd9Sstevel@tonic-gate 		    F_ISSET(dbmp, MP_LOCKHANDLE) ? dbmfp->mutexp : NULL;
184*7c478bd9Sstevel@tonic-gate 		db_io.pagesize = db_io.bytes = pagesize;
185*7c478bd9Sstevel@tonic-gate 		db_io.pgno = bhp->pgno;
186*7c478bd9Sstevel@tonic-gate 		db_io.buf = bhp->buf;
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 		ret = __os_io(&db_io, DB_IO_READ, &nr);
189*7c478bd9Sstevel@tonic-gate 	}
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	created = 0;
192*7c478bd9Sstevel@tonic-gate 	if (nr < (ssize_t)pagesize)
193*7c478bd9Sstevel@tonic-gate 		if (can_create)
194*7c478bd9Sstevel@tonic-gate 			created = 1;
195*7c478bd9Sstevel@tonic-gate 		else {
196*7c478bd9Sstevel@tonic-gate 			/* If we had a short read, ret may be 0. */
197*7c478bd9Sstevel@tonic-gate 			if (ret == 0)
198*7c478bd9Sstevel@tonic-gate 				ret = EIO;
199*7c478bd9Sstevel@tonic-gate 			__db_err(dbmp->dbenv,
200*7c478bd9Sstevel@tonic-gate 			    "%s: page %lu doesn't exist, create flag not set",
201*7c478bd9Sstevel@tonic-gate 			    __memp_fn(dbmfp), (u_long)bhp->pgno);
202*7c478bd9Sstevel@tonic-gate 			goto err;
203*7c478bd9Sstevel@tonic-gate 		}
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	/*
206*7c478bd9Sstevel@tonic-gate 	 * Clear any bytes we didn't read that need to be cleared.  If we're
207*7c478bd9Sstevel@tonic-gate 	 * running in diagnostic mode, smash any bytes on the page that are
208*7c478bd9Sstevel@tonic-gate 	 * unknown quantities for the caller.
209*7c478bd9Sstevel@tonic-gate 	 */
210*7c478bd9Sstevel@tonic-gate 	if (nr != (ssize_t)pagesize) {
211*7c478bd9Sstevel@tonic-gate 		len = mfp->clear_len == 0 ? pagesize : mfp->clear_len;
212*7c478bd9Sstevel@tonic-gate 		if (nr < (ssize_t)len)
213*7c478bd9Sstevel@tonic-gate 			memset(bhp->buf + nr, 0, len - nr);
214*7c478bd9Sstevel@tonic-gate #ifdef DIAGNOSTIC
215*7c478bd9Sstevel@tonic-gate 		if (nr > (ssize_t)len)
216*7c478bd9Sstevel@tonic-gate 			len = nr;
217*7c478bd9Sstevel@tonic-gate 		if (len < pagesize)
218*7c478bd9Sstevel@tonic-gate 			memset(bhp->buf + len, 0xdb, pagesize - len);
219*7c478bd9Sstevel@tonic-gate #endif
220*7c478bd9Sstevel@tonic-gate 	}
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	/* Call any pgin function. */
223*7c478bd9Sstevel@tonic-gate 	ret = mfp->ftype == 0 ? 0 : __memp_pg(dbmfp, bhp, 1);
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate 	/* Unlock the buffer and reacquire the region lock. */
226*7c478bd9Sstevel@tonic-gate err:	UNLOCKBUFFER(dbmp, bhp);
227*7c478bd9Sstevel@tonic-gate 	LOCKREGION(dbmp);
228*7c478bd9Sstevel@tonic-gate 
229*7c478bd9Sstevel@tonic-gate 	/*
230*7c478bd9Sstevel@tonic-gate 	 * If no errors occurred, the data is now valid, clear the BH_TRASH
231*7c478bd9Sstevel@tonic-gate 	 * flag; regardless, clear the lock bit and let other threads proceed.
232*7c478bd9Sstevel@tonic-gate 	 */
233*7c478bd9Sstevel@tonic-gate 	F_CLR(bhp, BH_LOCKED);
234*7c478bd9Sstevel@tonic-gate 	if (ret == 0) {
235*7c478bd9Sstevel@tonic-gate 		F_CLR(bhp, BH_TRASH);
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate 		/* Update the statistics. */
238*7c478bd9Sstevel@tonic-gate 		if (created) {
239*7c478bd9Sstevel@tonic-gate 			++dbmp->mp->stat.st_page_create;
240*7c478bd9Sstevel@tonic-gate 			++mfp->stat.st_page_create;
241*7c478bd9Sstevel@tonic-gate 		} else {
242*7c478bd9Sstevel@tonic-gate 			++dbmp->mp->stat.st_page_in;
243*7c478bd9Sstevel@tonic-gate 			++mfp->stat.st_page_in;
244*7c478bd9Sstevel@tonic-gate 		}
245*7c478bd9Sstevel@tonic-gate 	}
246*7c478bd9Sstevel@tonic-gate 
247*7c478bd9Sstevel@tonic-gate 	return (ret);
248*7c478bd9Sstevel@tonic-gate }
249*7c478bd9Sstevel@tonic-gate 
250*7c478bd9Sstevel@tonic-gate /*
251*7c478bd9Sstevel@tonic-gate  * __memp_pgwrite --
252*7c478bd9Sstevel@tonic-gate  *	Write a page to a file.
253*7c478bd9Sstevel@tonic-gate  *
254*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __memp_pgwrite __P((DB_MPOOLFILE *, BH *, int *, int *));
255*7c478bd9Sstevel@tonic-gate  */
256*7c478bd9Sstevel@tonic-gate int
__memp_pgwrite(dbmfp,bhp,restartp,wrotep)257*7c478bd9Sstevel@tonic-gate __memp_pgwrite(dbmfp, bhp, restartp, wrotep)
258*7c478bd9Sstevel@tonic-gate 	DB_MPOOLFILE *dbmfp;
259*7c478bd9Sstevel@tonic-gate 	BH *bhp;
260*7c478bd9Sstevel@tonic-gate 	int *restartp, *wrotep;
261*7c478bd9Sstevel@tonic-gate {
262*7c478bd9Sstevel@tonic-gate 	DB_ENV *dbenv;
263*7c478bd9Sstevel@tonic-gate 	DB_IO db_io;
264*7c478bd9Sstevel@tonic-gate 	DB_LOG *lg_info;
265*7c478bd9Sstevel@tonic-gate 	DB_LSN lsn;
266*7c478bd9Sstevel@tonic-gate 	DB_MPOOL *dbmp;
267*7c478bd9Sstevel@tonic-gate 	MPOOL *mp;
268*7c478bd9Sstevel@tonic-gate 	MPOOLFILE *mfp;
269*7c478bd9Sstevel@tonic-gate 	ssize_t nw;
270*7c478bd9Sstevel@tonic-gate 	int callpgin, dosync, ret, syncfail;
271*7c478bd9Sstevel@tonic-gate 	const char *fail;
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate 	dbmp = dbmfp->dbmp;
274*7c478bd9Sstevel@tonic-gate 	dbenv = dbmp->dbenv;
275*7c478bd9Sstevel@tonic-gate 	mp = dbmp->mp;
276*7c478bd9Sstevel@tonic-gate 	mfp = dbmfp->mfp;
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 	if (restartp != NULL)
279*7c478bd9Sstevel@tonic-gate 		*restartp = 0;
280*7c478bd9Sstevel@tonic-gate 	if (wrotep != NULL)
281*7c478bd9Sstevel@tonic-gate 		*wrotep = 0;
282*7c478bd9Sstevel@tonic-gate 	callpgin = 0;
283*7c478bd9Sstevel@tonic-gate 
284*7c478bd9Sstevel@tonic-gate 	/*
285*7c478bd9Sstevel@tonic-gate 	 * Check the dirty bit -- this buffer may have been written since we
286*7c478bd9Sstevel@tonic-gate 	 * decided to write it.
287*7c478bd9Sstevel@tonic-gate 	 */
288*7c478bd9Sstevel@tonic-gate 	if (!F_ISSET(bhp, BH_DIRTY)) {
289*7c478bd9Sstevel@tonic-gate 		if (wrotep != NULL)
290*7c478bd9Sstevel@tonic-gate 			*wrotep = 1;
291*7c478bd9Sstevel@tonic-gate 		return (0);
292*7c478bd9Sstevel@tonic-gate 	}
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate 	LOCKBUFFER(dbmp, bhp);
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	/*
297*7c478bd9Sstevel@tonic-gate 	 * If there were two writers, we may have just been waiting while the
298*7c478bd9Sstevel@tonic-gate 	 * other writer completed I/O on this buffer.  Check the dirty bit one
299*7c478bd9Sstevel@tonic-gate 	 * more time.
300*7c478bd9Sstevel@tonic-gate 	 */
301*7c478bd9Sstevel@tonic-gate 	if (!F_ISSET(bhp, BH_DIRTY)) {
302*7c478bd9Sstevel@tonic-gate 		UNLOCKBUFFER(dbmp, bhp);
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 		if (wrotep != NULL)
305*7c478bd9Sstevel@tonic-gate 			*wrotep = 1;
306*7c478bd9Sstevel@tonic-gate 		return (0);
307*7c478bd9Sstevel@tonic-gate 	}
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate 	F_SET(bhp, BH_LOCKED);
310*7c478bd9Sstevel@tonic-gate 	UNLOCKREGION(dbmp);
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 	if (restartp != NULL)
313*7c478bd9Sstevel@tonic-gate 		*restartp = 1;
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate 	/* Copy the LSN off the page if we're going to need it. */
316*7c478bd9Sstevel@tonic-gate 	lg_info = dbenv->lg_info;
317*7c478bd9Sstevel@tonic-gate 	if (lg_info != NULL || F_ISSET(bhp, BH_WRITE))
318*7c478bd9Sstevel@tonic-gate 		memcpy(&lsn, bhp->buf + mfp->lsn_off, sizeof(DB_LSN));
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate 	/* Ensure the appropriate log records are on disk. */
321*7c478bd9Sstevel@tonic-gate 	if (lg_info != NULL && (ret = log_flush(lg_info, &lsn)) != 0)
322*7c478bd9Sstevel@tonic-gate 		goto err;
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate 	/*
325*7c478bd9Sstevel@tonic-gate 	 * Call any pgout function.  We set the callpgin flag so that we flag
326*7c478bd9Sstevel@tonic-gate 	 * that the contents of the buffer will need to be passed through pgin
327*7c478bd9Sstevel@tonic-gate 	 * before they are reused.
328*7c478bd9Sstevel@tonic-gate 	 */
329*7c478bd9Sstevel@tonic-gate 	if (mfp->ftype == 0)
330*7c478bd9Sstevel@tonic-gate 		ret = 0;
331*7c478bd9Sstevel@tonic-gate 	else {
332*7c478bd9Sstevel@tonic-gate 		callpgin = 1;
333*7c478bd9Sstevel@tonic-gate 		if ((ret = __memp_pg(dbmfp, bhp, 0)) != 0)
334*7c478bd9Sstevel@tonic-gate 			goto err;
335*7c478bd9Sstevel@tonic-gate 	}
336*7c478bd9Sstevel@tonic-gate 
337*7c478bd9Sstevel@tonic-gate 	/* Temporary files may not yet have been created. */
338*7c478bd9Sstevel@tonic-gate 	if (dbmfp->fd == -1) {
339*7c478bd9Sstevel@tonic-gate 		LOCKHANDLE(dbmp, dbmfp->mutexp);
340*7c478bd9Sstevel@tonic-gate 		if (dbmfp->fd == -1 && ((ret = __db_appname(dbenv,
341*7c478bd9Sstevel@tonic-gate 		    DB_APP_TMP, NULL, NULL, DB_CREATE | DB_EXCL | DB_TEMPORARY,
342*7c478bd9Sstevel@tonic-gate 		    &dbmfp->fd, NULL)) != 0 || dbmfp->fd == -1)) {
343*7c478bd9Sstevel@tonic-gate 			UNLOCKHANDLE(dbmp, dbmfp->mutexp);
344*7c478bd9Sstevel@tonic-gate 			__db_err(dbenv,
345*7c478bd9Sstevel@tonic-gate 			    "unable to create temporary backing file");
346*7c478bd9Sstevel@tonic-gate 			goto err;
347*7c478bd9Sstevel@tonic-gate 		}
348*7c478bd9Sstevel@tonic-gate 		UNLOCKHANDLE(dbmp, dbmfp->mutexp);
349*7c478bd9Sstevel@tonic-gate 	}
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 	/* Write the page. */
352*7c478bd9Sstevel@tonic-gate 	db_io.fd_io = dbmfp->fd;
353*7c478bd9Sstevel@tonic-gate 	db_io.fd_lock = dbmp->reginfo.fd;
354*7c478bd9Sstevel@tonic-gate 	db_io.mutexp = F_ISSET(dbmp, MP_LOCKHANDLE) ? dbmfp->mutexp : NULL;
355*7c478bd9Sstevel@tonic-gate 	db_io.pagesize = db_io.bytes = mfp->stat.st_pagesize;
356*7c478bd9Sstevel@tonic-gate 	db_io.pgno = bhp->pgno;
357*7c478bd9Sstevel@tonic-gate 	db_io.buf = bhp->buf;
358*7c478bd9Sstevel@tonic-gate 	if ((ret = __os_io(&db_io, DB_IO_WRITE, &nw)) != 0) {
359*7c478bd9Sstevel@tonic-gate 		__db_panic(dbenv, ret);
360*7c478bd9Sstevel@tonic-gate 		fail = "write";
361*7c478bd9Sstevel@tonic-gate 		goto syserr;
362*7c478bd9Sstevel@tonic-gate 	}
363*7c478bd9Sstevel@tonic-gate 	if (nw != (ssize_t)mfp->stat.st_pagesize) {
364*7c478bd9Sstevel@tonic-gate 		ret = EIO;
365*7c478bd9Sstevel@tonic-gate 		fail = "write";
366*7c478bd9Sstevel@tonic-gate 		goto syserr;
367*7c478bd9Sstevel@tonic-gate 	}
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate 	if (wrotep != NULL)
370*7c478bd9Sstevel@tonic-gate 		*wrotep = 1;
371*7c478bd9Sstevel@tonic-gate 
372*7c478bd9Sstevel@tonic-gate 	/* Unlock the buffer and reacquire the region lock. */
373*7c478bd9Sstevel@tonic-gate 	UNLOCKBUFFER(dbmp, bhp);
374*7c478bd9Sstevel@tonic-gate 	LOCKREGION(dbmp);
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate 	/*
377*7c478bd9Sstevel@tonic-gate 	 * Clean up the flags based on a successful write.
378*7c478bd9Sstevel@tonic-gate 	 *
379*7c478bd9Sstevel@tonic-gate 	 * If we rewrote the page, it will need processing by the pgin
380*7c478bd9Sstevel@tonic-gate 	 * routine before reuse.
381*7c478bd9Sstevel@tonic-gate 	 */
382*7c478bd9Sstevel@tonic-gate 	if (callpgin)
383*7c478bd9Sstevel@tonic-gate 		F_SET(bhp, BH_CALLPGIN);
384*7c478bd9Sstevel@tonic-gate 	F_CLR(bhp, BH_DIRTY | BH_LOCKED);
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate 	/*
387*7c478bd9Sstevel@tonic-gate 	 * If we write a buffer for which a checkpoint is waiting, update
388*7c478bd9Sstevel@tonic-gate 	 * the count of pending buffers (both in the mpool as a whole and
389*7c478bd9Sstevel@tonic-gate 	 * for this file).  If the count for this file goes to zero, set a
390*7c478bd9Sstevel@tonic-gate 	 * flag so we flush the writes.
391*7c478bd9Sstevel@tonic-gate 	 */
392*7c478bd9Sstevel@tonic-gate 	if (F_ISSET(bhp, BH_WRITE)) {
393*7c478bd9Sstevel@tonic-gate 		F_CLR(bhp, BH_WRITE);
394*7c478bd9Sstevel@tonic-gate 
395*7c478bd9Sstevel@tonic-gate 		--mp->lsn_cnt;
396*7c478bd9Sstevel@tonic-gate 		dosync = --mfp->lsn_cnt == 0 ? 1 : 0;
397*7c478bd9Sstevel@tonic-gate 	} else
398*7c478bd9Sstevel@tonic-gate 		dosync = 0;
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate 	/* Update the page clean/dirty statistics. */
401*7c478bd9Sstevel@tonic-gate 	++mp->stat.st_page_clean;
402*7c478bd9Sstevel@tonic-gate 	--mp->stat.st_page_dirty;
403*7c478bd9Sstevel@tonic-gate 
404*7c478bd9Sstevel@tonic-gate 	/* Update I/O statistics. */
405*7c478bd9Sstevel@tonic-gate 	++mp->stat.st_page_out;
406*7c478bd9Sstevel@tonic-gate 	++mfp->stat.st_page_out;
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	/*
409*7c478bd9Sstevel@tonic-gate 	 * Do the sync after everything else has been updated, so any incoming
410*7c478bd9Sstevel@tonic-gate 	 * checkpoint doesn't see inconsistent information.
411*7c478bd9Sstevel@tonic-gate 	 *
412*7c478bd9Sstevel@tonic-gate 	 * XXX:
413*7c478bd9Sstevel@tonic-gate 	 * Don't lock the region around the sync, fsync(2) has no atomicity
414*7c478bd9Sstevel@tonic-gate 	 * issues.
415*7c478bd9Sstevel@tonic-gate 	 *
416*7c478bd9Sstevel@tonic-gate 	 * XXX:
417*7c478bd9Sstevel@tonic-gate 	 * We ignore errors from the sync -- it makes no sense to return an
418*7c478bd9Sstevel@tonic-gate 	 * error to the calling process, so set a flag causing the checkpoint
419*7c478bd9Sstevel@tonic-gate 	 * to be retried later.  There is a possibility, of course, that a
420*7c478bd9Sstevel@tonic-gate 	 * subsequent checkpoint was started and that we're going to force it
421*7c478bd9Sstevel@tonic-gate 	 * to fail.  That should be unlikely, and fixing it would be difficult.
422*7c478bd9Sstevel@tonic-gate 	 */
423*7c478bd9Sstevel@tonic-gate 	if (dosync) {
424*7c478bd9Sstevel@tonic-gate 		UNLOCKREGION(dbmp);
425*7c478bd9Sstevel@tonic-gate 		syncfail = __os_fsync(dbmfp->fd) != 0;
426*7c478bd9Sstevel@tonic-gate 		LOCKREGION(dbmp);
427*7c478bd9Sstevel@tonic-gate 		if (syncfail)
428*7c478bd9Sstevel@tonic-gate 			F_SET(mp, MP_LSN_RETRY);
429*7c478bd9Sstevel@tonic-gate 	}
430*7c478bd9Sstevel@tonic-gate 
431*7c478bd9Sstevel@tonic-gate 	return (0);
432*7c478bd9Sstevel@tonic-gate 
433*7c478bd9Sstevel@tonic-gate syserr:	__db_err(dbenv, "%s: %s failed for page %lu",
434*7c478bd9Sstevel@tonic-gate 	    __memp_fn(dbmfp), fail, (u_long)bhp->pgno);
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate err:	/* Unlock the buffer and reacquire the region lock. */
437*7c478bd9Sstevel@tonic-gate 	UNLOCKBUFFER(dbmp, bhp);
438*7c478bd9Sstevel@tonic-gate 	LOCKREGION(dbmp);
439*7c478bd9Sstevel@tonic-gate 
440*7c478bd9Sstevel@tonic-gate 	/*
441*7c478bd9Sstevel@tonic-gate 	 * Clean up the flags based on a failure.
442*7c478bd9Sstevel@tonic-gate 	 *
443*7c478bd9Sstevel@tonic-gate 	 * The page remains dirty but we remove our lock.  If we rewrote the
444*7c478bd9Sstevel@tonic-gate 	 * page, it will need processing by the pgin routine before reuse.
445*7c478bd9Sstevel@tonic-gate 	 */
446*7c478bd9Sstevel@tonic-gate 	if (callpgin)
447*7c478bd9Sstevel@tonic-gate 		F_SET(bhp, BH_CALLPGIN);
448*7c478bd9Sstevel@tonic-gate 	F_CLR(bhp, BH_LOCKED);
449*7c478bd9Sstevel@tonic-gate 
450*7c478bd9Sstevel@tonic-gate 	return (ret);
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate /*
454*7c478bd9Sstevel@tonic-gate  * __memp_pg --
455*7c478bd9Sstevel@tonic-gate  *	Call the pgin/pgout routine.
456*7c478bd9Sstevel@tonic-gate  *
457*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __memp_pg __P((DB_MPOOLFILE *, BH *, int));
458*7c478bd9Sstevel@tonic-gate  */
459*7c478bd9Sstevel@tonic-gate int
__memp_pg(dbmfp,bhp,is_pgin)460*7c478bd9Sstevel@tonic-gate __memp_pg(dbmfp, bhp, is_pgin)
461*7c478bd9Sstevel@tonic-gate 	DB_MPOOLFILE *dbmfp;
462*7c478bd9Sstevel@tonic-gate 	BH *bhp;
463*7c478bd9Sstevel@tonic-gate 	int is_pgin;
464*7c478bd9Sstevel@tonic-gate {
465*7c478bd9Sstevel@tonic-gate 	DBT dbt, *dbtp;
466*7c478bd9Sstevel@tonic-gate 	DB_MPOOL *dbmp;
467*7c478bd9Sstevel@tonic-gate 	DB_MPREG *mpreg;
468*7c478bd9Sstevel@tonic-gate 	MPOOLFILE *mfp;
469*7c478bd9Sstevel@tonic-gate 	int ftype, ret;
470*7c478bd9Sstevel@tonic-gate 
471*7c478bd9Sstevel@tonic-gate 	dbmp = dbmfp->dbmp;
472*7c478bd9Sstevel@tonic-gate 	mfp = dbmfp->mfp;
473*7c478bd9Sstevel@tonic-gate 
474*7c478bd9Sstevel@tonic-gate 	LOCKHANDLE(dbmp, dbmp->mutexp);
475*7c478bd9Sstevel@tonic-gate 
476*7c478bd9Sstevel@tonic-gate 	ftype = mfp->ftype;
477*7c478bd9Sstevel@tonic-gate 	for (mpreg = LIST_FIRST(&dbmp->dbregq);
478*7c478bd9Sstevel@tonic-gate 	    mpreg != NULL; mpreg = LIST_NEXT(mpreg, q)) {
479*7c478bd9Sstevel@tonic-gate 		if (ftype != mpreg->ftype)
480*7c478bd9Sstevel@tonic-gate 			continue;
481*7c478bd9Sstevel@tonic-gate 		if (mfp->pgcookie_len == 0)
482*7c478bd9Sstevel@tonic-gate 			dbtp = NULL;
483*7c478bd9Sstevel@tonic-gate 		else {
484*7c478bd9Sstevel@tonic-gate 			dbt.size = mfp->pgcookie_len;
485*7c478bd9Sstevel@tonic-gate 			dbt.data = R_ADDR(dbmp, mfp->pgcookie_off);
486*7c478bd9Sstevel@tonic-gate 			dbtp = &dbt;
487*7c478bd9Sstevel@tonic-gate 		}
488*7c478bd9Sstevel@tonic-gate 		UNLOCKHANDLE(dbmp, dbmp->mutexp);
489*7c478bd9Sstevel@tonic-gate 
490*7c478bd9Sstevel@tonic-gate 		if (is_pgin) {
491*7c478bd9Sstevel@tonic-gate 			if (mpreg->pgin != NULL && (ret =
492*7c478bd9Sstevel@tonic-gate 			    mpreg->pgin(bhp->pgno, bhp->buf, dbtp)) != 0)
493*7c478bd9Sstevel@tonic-gate 				goto err;
494*7c478bd9Sstevel@tonic-gate 		} else
495*7c478bd9Sstevel@tonic-gate 			if (mpreg->pgout != NULL && (ret =
496*7c478bd9Sstevel@tonic-gate 			    mpreg->pgout(bhp->pgno, bhp->buf, dbtp)) != 0)
497*7c478bd9Sstevel@tonic-gate 				goto err;
498*7c478bd9Sstevel@tonic-gate 		break;
499*7c478bd9Sstevel@tonic-gate 	}
500*7c478bd9Sstevel@tonic-gate 
501*7c478bd9Sstevel@tonic-gate 	if (mpreg == NULL)
502*7c478bd9Sstevel@tonic-gate 		UNLOCKHANDLE(dbmp, dbmp->mutexp);
503*7c478bd9Sstevel@tonic-gate 
504*7c478bd9Sstevel@tonic-gate 	return (0);
505*7c478bd9Sstevel@tonic-gate 
506*7c478bd9Sstevel@tonic-gate err:	UNLOCKHANDLE(dbmp, dbmp->mutexp);
507*7c478bd9Sstevel@tonic-gate 	__db_err(dbmp->dbenv, "%s: %s failed for page %lu",
508*7c478bd9Sstevel@tonic-gate 	    __memp_fn(dbmfp), is_pgin ? "pgin" : "pgout", (u_long)bhp->pgno);
509*7c478bd9Sstevel@tonic-gate 	return (ret);
510*7c478bd9Sstevel@tonic-gate }
511*7c478bd9Sstevel@tonic-gate 
512*7c478bd9Sstevel@tonic-gate /*
513*7c478bd9Sstevel@tonic-gate  * __memp_bhfree --
514*7c478bd9Sstevel@tonic-gate  *	Free a bucket header and its referenced data.
515*7c478bd9Sstevel@tonic-gate  *
516*7c478bd9Sstevel@tonic-gate  * PUBLIC: void __memp_bhfree __P((DB_MPOOL *, MPOOLFILE *, BH *, int));
517*7c478bd9Sstevel@tonic-gate  */
518*7c478bd9Sstevel@tonic-gate void
__memp_bhfree(dbmp,mfp,bhp,free_mem)519*7c478bd9Sstevel@tonic-gate __memp_bhfree(dbmp, mfp, bhp, free_mem)
520*7c478bd9Sstevel@tonic-gate 	DB_MPOOL *dbmp;
521*7c478bd9Sstevel@tonic-gate 	MPOOLFILE *mfp;
522*7c478bd9Sstevel@tonic-gate 	BH *bhp;
523*7c478bd9Sstevel@tonic-gate 	int free_mem;
524*7c478bd9Sstevel@tonic-gate {
525*7c478bd9Sstevel@tonic-gate 	size_t off;
526*7c478bd9Sstevel@tonic-gate 
527*7c478bd9Sstevel@tonic-gate 	/* Delete the buffer header from the hash bucket queue. */
528*7c478bd9Sstevel@tonic-gate 	off = BUCKET(dbmp->mp, R_OFFSET(dbmp, mfp), bhp->pgno);
529*7c478bd9Sstevel@tonic-gate 	SH_TAILQ_REMOVE(&dbmp->htab[off], bhp, hq, __bh);
530*7c478bd9Sstevel@tonic-gate 
531*7c478bd9Sstevel@tonic-gate 	/* Delete the buffer header from the LRU queue. */
532*7c478bd9Sstevel@tonic-gate 	SH_TAILQ_REMOVE(&dbmp->mp->bhq, bhp, q, __bh);
533*7c478bd9Sstevel@tonic-gate 
534*7c478bd9Sstevel@tonic-gate 	/*
535*7c478bd9Sstevel@tonic-gate 	 * If we're not reusing it immediately, free the buffer header
536*7c478bd9Sstevel@tonic-gate 	 * and data for real.
537*7c478bd9Sstevel@tonic-gate 	 */
538*7c478bd9Sstevel@tonic-gate 	if (free_mem) {
539*7c478bd9Sstevel@tonic-gate 		__db_shalloc_free(dbmp->addr, bhp);
540*7c478bd9Sstevel@tonic-gate 		--dbmp->mp->stat.st_page_clean;
541*7c478bd9Sstevel@tonic-gate 	}
542*7c478bd9Sstevel@tonic-gate }
543*7c478bd9Sstevel@tonic-gate 
544*7c478bd9Sstevel@tonic-gate /*
545*7c478bd9Sstevel@tonic-gate  * __memp_upgrade --
546*7c478bd9Sstevel@tonic-gate  *	Upgrade a file descriptor from readonly to readwrite.
547*7c478bd9Sstevel@tonic-gate  */
548*7c478bd9Sstevel@tonic-gate static int
__memp_upgrade(dbmp,dbmfp,mfp)549*7c478bd9Sstevel@tonic-gate __memp_upgrade(dbmp, dbmfp, mfp)
550*7c478bd9Sstevel@tonic-gate 	DB_MPOOL *dbmp;
551*7c478bd9Sstevel@tonic-gate 	DB_MPOOLFILE *dbmfp;
552*7c478bd9Sstevel@tonic-gate 	MPOOLFILE *mfp;
553*7c478bd9Sstevel@tonic-gate {
554*7c478bd9Sstevel@tonic-gate 	int fd, ret;
555*7c478bd9Sstevel@tonic-gate 	char *rpath;
556*7c478bd9Sstevel@tonic-gate 
557*7c478bd9Sstevel@tonic-gate 	/*
558*7c478bd9Sstevel@tonic-gate 	 * !!!
559*7c478bd9Sstevel@tonic-gate 	 * We expect the handle to already be locked.
560*7c478bd9Sstevel@tonic-gate 	 */
561*7c478bd9Sstevel@tonic-gate 
562*7c478bd9Sstevel@tonic-gate 	/* Check to see if we've already upgraded. */
563*7c478bd9Sstevel@tonic-gate 	if (F_ISSET(dbmfp, MP_UPGRADE))
564*7c478bd9Sstevel@tonic-gate 		return (0);
565*7c478bd9Sstevel@tonic-gate 
566*7c478bd9Sstevel@tonic-gate 	/* Check to see if we've already failed. */
567*7c478bd9Sstevel@tonic-gate 	if (F_ISSET(dbmfp, MP_UPGRADE_FAIL))
568*7c478bd9Sstevel@tonic-gate 		return (1);
569*7c478bd9Sstevel@tonic-gate 
570*7c478bd9Sstevel@tonic-gate 	/*
571*7c478bd9Sstevel@tonic-gate 	 * Calculate the real name for this file and try to open it read/write.
572*7c478bd9Sstevel@tonic-gate 	 * We know we have a valid pathname for the file because it's the only
573*7c478bd9Sstevel@tonic-gate 	 * way we could have gotten a file descriptor of any kind.
574*7c478bd9Sstevel@tonic-gate 	 */
575*7c478bd9Sstevel@tonic-gate 	if ((ret = __db_appname(dbmp->dbenv, DB_APP_DATA,
576*7c478bd9Sstevel@tonic-gate 	    NULL, R_ADDR(dbmp, mfp->path_off), 0, NULL, &rpath)) != 0)
577*7c478bd9Sstevel@tonic-gate 		return (ret);
578*7c478bd9Sstevel@tonic-gate 	if (__db_open(rpath, 0, 0, 0, &fd) != 0) {
579*7c478bd9Sstevel@tonic-gate 		F_SET(dbmfp, MP_UPGRADE_FAIL);
580*7c478bd9Sstevel@tonic-gate 		ret = 1;
581*7c478bd9Sstevel@tonic-gate 	} else {
582*7c478bd9Sstevel@tonic-gate 		/* Swap the descriptors and set the upgrade flag. */
583*7c478bd9Sstevel@tonic-gate 		(void)__os_close(dbmfp->fd);
584*7c478bd9Sstevel@tonic-gate 		dbmfp->fd = fd;
585*7c478bd9Sstevel@tonic-gate 		F_SET(dbmfp, MP_UPGRADE);
586*7c478bd9Sstevel@tonic-gate 		ret = 0;
587*7c478bd9Sstevel@tonic-gate 	}
588*7c478bd9Sstevel@tonic-gate 	__os_freestr(rpath);
589*7c478bd9Sstevel@tonic-gate 	return (ret);
590*7c478bd9Sstevel@tonic-gate }
591