Home | History | Annotate | Line # | Download | only in dump
rcache.c revision 1.2
      1  1.2  perseant /*      $NetBSD: rcache.c,v 1.2 1999/09/29 04:57:49 perseant Exp $       */
      2  1.1    bouyer 
      3  1.1    bouyer /*-
      4  1.1    bouyer  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  1.1    bouyer  * All rights reserved.
      6  1.1    bouyer  *
      7  1.1    bouyer  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1    bouyer  * by Martin J. Laubach <mjl (at) emsi.priv.at> and
      9  1.1    bouyer  *    Manuel Bouyer <Manuel.Bouyer (at) lip6.fr>.
     10  1.1    bouyer  *
     11  1.1    bouyer  * Redistribution and use in source and binary forms, with or without
     12  1.1    bouyer  * modification, are permitted provided that the following conditions
     13  1.1    bouyer  * are met:
     14  1.1    bouyer  * 1. Redistributions of source code must retain the above copyright
     15  1.1    bouyer  *    notice, this list of conditions and the following disclaimer.
     16  1.1    bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1    bouyer  *    notice, this list of conditions and the following disclaimer in the
     18  1.1    bouyer  *    documentation and/or other materials provided with the distribution.
     19  1.1    bouyer  * 3. All advertising materials mentioning features or use of this software
     20  1.1    bouyer  *    must display the following acknowledgement:
     21  1.1    bouyer  *      This product includes software developed by the NetBSD
     22  1.1    bouyer  *      Foundation, Inc. and its contributors.
     23  1.1    bouyer  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1    bouyer  *    contributors may be used to endorse or promote products derived
     25  1.1    bouyer  *    from this software without specific prior written permission.
     26  1.1    bouyer  *
     27  1.1    bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1    bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1    bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1    bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1    bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1    bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1    bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1    bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1    bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1    bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1    bouyer  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1    bouyer  */
     39  1.1    bouyer /*-----------------------------------------------------------------------*/
     40  1.1    bouyer #include <sys/types.h>
     41  1.1    bouyer #include <sys/uio.h>
     42  1.1    bouyer #include <sys/mman.h>
     43  1.1    bouyer #include <sys/param.h>
     44  1.1    bouyer #include <sys/sysctl.h>
     45  1.1    bouyer #include <ufs/ufs/dinode.h>
     46  1.1    bouyer 
     47  1.1    bouyer #include <stdio.h>
     48  1.1    bouyer #include <stdlib.h>
     49  1.1    bouyer #include <unistd.h>
     50  1.1    bouyer #include <fcntl.h>
     51  1.1    bouyer #include <errno.h>
     52  1.1    bouyer #include <string.h>
     53  1.1    bouyer 
     54  1.1    bouyer #include "dump.h"
     55  1.1    bouyer 
     56  1.1    bouyer /*-----------------------------------------------------------------------*/
     57  1.1    bouyer #define MAXCACHEBUFS	512	/* max 512 buffers */
     58  1.1    bouyer #define MAXMEMPART	6	/* max 15% of the user mem */
     59  1.1    bouyer 
     60  1.1    bouyer /*-----------------------------------------------------------------------*/
     61  1.1    bouyer struct cheader {
     62  1.1    bouyer 	volatile size_t count;
     63  1.1    bouyer };
     64  1.1    bouyer 
     65  1.1    bouyer struct cdesc {
     66  1.1    bouyer 	volatile daddr_t blkstart;
     67  1.1    bouyer 	volatile daddr_t blkend;/* start + nblksread */
     68  1.1    bouyer 	volatile daddr_t blocksRead;
     69  1.1    bouyer 	volatile size_t time;
     70  1.1    bouyer #ifdef DIAGNOSTICS
     71  1.1    bouyer 	volatile pid_t owner;
     72  1.1    bouyer #endif
     73  1.1    bouyer };
     74  1.1    bouyer 
     75  1.1    bouyer static int findlru __P((void));
     76  1.1    bouyer 
     77  1.1    bouyer static void *shareBuffer = NULL;
     78  1.1    bouyer static struct cheader *cheader;
     79  1.1    bouyer static struct cdesc *cdesc;
     80  1.1    bouyer static char *cdata;
     81  1.1    bouyer static int cachebufs;
     82  1.1    bouyer static int nblksread;
     83  1.1    bouyer 
     84  1.1    bouyer #ifdef STATS
     85  1.1    bouyer static int nreads;
     86  1.1    bouyer static int nphysread;
     87  1.1    bouyer static int64_t readsize;
     88  1.1    bouyer static int64_t physreadsize;
     89  1.1    bouyer #endif
     90  1.1    bouyer 
     91  1.1    bouyer #define CDATA(i)	(cdata + ((i) * nblksread * dev_bsize))
     92  1.1    bouyer 
     93  1.1    bouyer /*-----------------------------------------------------------------------*/
     94  1.1    bouyer void
     95  1.1    bouyer initcache(cachesize, readblksize)
     96  1.1    bouyer 	int cachesize;
     97  1.1    bouyer 	int readblksize;
     98  1.1    bouyer {
     99  1.1    bouyer 	size_t len;
    100  1.1    bouyer 	size_t  sharedSize;
    101  1.1    bouyer 
    102  1.2  perseant 	nblksread = (readblksize + ufsib->ufs_bsize - 1) / ufsib->ufs_bsize;
    103  1.1    bouyer 	if(cachesize == -1) {	/* Compute from memory available */
    104  1.1    bouyer 		int usermem;
    105  1.1    bouyer 		int mib[2] = { CTL_HW, HW_USERMEM };
    106  1.1    bouyer 
    107  1.1    bouyer 		len = sizeof(usermem);
    108  1.1    bouyer 		if (sysctl(mib, 2, &usermem, &len, NULL, 0) < 0) {
    109  1.1    bouyer 			msg("sysctl(hw.usermem) failed: %s\n", strerror(errno));
    110  1.1    bouyer 			return;
    111  1.1    bouyer 		}
    112  1.1    bouyer 		cachebufs = (usermem / MAXMEMPART) / (nblksread * dev_bsize);
    113  1.1    bouyer 	} else {		/* User specified */
    114  1.1    bouyer 		cachebufs = cachesize;
    115  1.1    bouyer 	}
    116  1.1    bouyer 
    117  1.1    bouyer 	if(cachebufs) {	/* Don't allocate if zero --> no caching */
    118  1.1    bouyer 		if (cachebufs > MAXCACHEBUFS)
    119  1.1    bouyer 			cachebufs = MAXCACHEBUFS;
    120  1.1    bouyer 
    121  1.1    bouyer 		sharedSize = sizeof(struct cheader) +
    122  1.1    bouyer 	   	    sizeof(struct cdesc) * cachebufs +
    123  1.1    bouyer 	   	    nblksread * cachebufs * dev_bsize;
    124  1.1    bouyer #ifdef STATS
    125  1.1    bouyer 		fprintf(stderr, "Using %d buffers (%d bytes)\n", cachebufs,
    126  1.1    bouyer 	   	    sharedSize);
    127  1.1    bouyer #endif
    128  1.1    bouyer 		shareBuffer = mmap(NULL, sharedSize, PROT_READ | PROT_WRITE,
    129  1.1    bouyer 	   	    MAP_ANON | MAP_SHARED, -1, 0);
    130  1.1    bouyer 		if (shareBuffer == (void *)-1) {
    131  1.1    bouyer 			msg("can't mmap shared memory for buffer: %s\n",
    132  1.1    bouyer 			    strerror(errno));
    133  1.1    bouyer 			return;
    134  1.1    bouyer 		}
    135  1.1    bouyer 		cheader = shareBuffer;
    136  1.1    bouyer 		cdesc = (struct cdesc *) (((char *) shareBuffer) +
    137  1.1    bouyer 		    sizeof(struct cheader));
    138  1.1    bouyer 		cdata = ((char *) shareBuffer) + sizeof(struct cheader) +
    139  1.1    bouyer 	   	    sizeof(struct cdesc) * cachebufs;
    140  1.1    bouyer 
    141  1.1    bouyer 		memset(shareBuffer, '\0', sharedSize);
    142  1.1    bouyer 	}
    143  1.1    bouyer }
    144  1.1    bouyer /*-----------------------------------------------------------------------*/
    145  1.1    bouyer /* Find the cache buffer descriptor that shows the minimal access time */
    146  1.1    bouyer 
    147  1.1    bouyer static int
    148  1.1    bouyer findlru()
    149  1.1    bouyer {
    150  1.1    bouyer 	int     i;
    151  1.1    bouyer 	int     minTime = cdesc[0].time;
    152  1.1    bouyer 	int     minIdx = 0;
    153  1.1    bouyer 
    154  1.1    bouyer 	for (i = 0; i < cachebufs; i++) {
    155  1.1    bouyer 		if (cdesc[i].time < minTime) {
    156  1.1    bouyer 			minIdx = i;
    157  1.1    bouyer 			minTime = cdesc[i].time;
    158  1.1    bouyer 		}
    159  1.1    bouyer 	}
    160  1.1    bouyer 
    161  1.1    bouyer 	return minIdx;
    162  1.1    bouyer }
    163  1.1    bouyer /*-----------------------------------------------------------------------*/
    164  1.1    bouyer /*
    165  1.1    bouyer  * Read data directly from disk, with smart error handling.
    166  1.1    bouyer  * Try to recover from hard errors by reading in sector sized pieces.
    167  1.1    bouyer  * Error recovery is attempted at most BREADEMAX times before seeking
    168  1.1    bouyer  * consent from the operator to continue.
    169  1.1    bouyer  */
    170  1.1    bouyer 
    171  1.1    bouyer 
    172  1.1    bouyer static int breaderrors = 0;
    173  1.1    bouyer #define BREADEMAX 32
    174  1.1    bouyer 
    175  1.1    bouyer void
    176  1.1    bouyer rawread(blkno, buf, size)
    177  1.1    bouyer 	daddr_t blkno;
    178  1.1    bouyer 	char *buf;
    179  1.1    bouyer 	int size;
    180  1.1    bouyer {
    181  1.1    bouyer 	int cnt, i;
    182  1.1    bouyer #ifdef STATS
    183  1.1    bouyer 	nphysread++;
    184  1.1    bouyer 	physreadsize += size;
    185  1.1    bouyer #endif
    186  1.1    bouyer 
    187  1.1    bouyer 	if (lseek(diskfd, ((off_t) blkno << dev_bshift), 0) < 0) {
    188  1.1    bouyer 		msg("rawread: lseek fails\n");
    189  1.1    bouyer 		goto err;
    190  1.1    bouyer 	}
    191  1.1    bouyer 	if ((cnt =  read(diskfd, buf, size)) == size)
    192  1.1    bouyer 		return;
    193  1.1    bouyer 	if (cnt == -1)
    194  1.1    bouyer 		msg("read error from %s: %s: [block %d]: count=%d\n",
    195  1.1    bouyer 			disk, strerror(errno), blkno, size);
    196  1.1    bouyer 	else
    197  1.1    bouyer 		msg("short read error from %s: [block %d]: count=%d, got=%d\n",
    198  1.1    bouyer 			disk, blkno, size, cnt);
    199  1.1    bouyer err:
    200  1.1    bouyer 	if (++breaderrors > BREADEMAX) {
    201  1.1    bouyer 		msg("More than %d block read errors from %d\n",
    202  1.1    bouyer 			BREADEMAX, disk);
    203  1.1    bouyer 		broadcast("DUMP IS AILING!\n");
    204  1.1    bouyer 		msg("This is an unrecoverable error.\n");
    205  1.1    bouyer 		if (!query("Do you want to attempt to continue?")){
    206  1.1    bouyer 			dumpabort(0);
    207  1.1    bouyer 			/*NOTREACHED*/
    208  1.1    bouyer 		} else
    209  1.1    bouyer 			breaderrors = 0;
    210  1.1    bouyer 	}
    211  1.1    bouyer 	/*
    212  1.1    bouyer 	 * Zero buffer, then try to read each sector of buffer separately.
    213  1.1    bouyer 	 */
    214  1.1    bouyer 	memset(buf, 0, size);
    215  1.1    bouyer 	for (i = 0; i < size; i += dev_bsize, buf += dev_bsize, blkno++) {
    216  1.1    bouyer 		if (lseek(diskfd, ((off_t)blkno << dev_bshift), 0) < 0) {
    217  1.1    bouyer 			msg("rawread: lseek2 fails: %s!\n",
    218  1.1    bouyer 			    strerror(errno));
    219  1.1    bouyer 			continue;
    220  1.1    bouyer 		}
    221  1.1    bouyer 		if ((cnt = read(diskfd, buf, (int)dev_bsize)) == dev_bsize)
    222  1.1    bouyer 			continue;
    223  1.1    bouyer 		if (cnt == -1) {
    224  1.1    bouyer 			msg("read error from %s: %s: [sector %d]: count=%d: "
    225  1.1    bouyer 			    "%s\n", disk, strerror(errno), blkno, dev_bsize,
    226  1.1    bouyer 			    strerror(errno));
    227  1.1    bouyer 			continue;
    228  1.1    bouyer 		}
    229  1.1    bouyer 		msg("short read error from %s: [sector %d]: count=%d, got=%d\n",
    230  1.1    bouyer 		    disk, blkno, dev_bsize, cnt);
    231  1.1    bouyer 	}
    232  1.1    bouyer }
    233  1.1    bouyer 
    234  1.1    bouyer /*-----------------------------------------------------------------------*/
    235  1.1    bouyer #define min(a,b)	(((a) < (b)) ? (a) : (b))
    236  1.1    bouyer 
    237  1.1    bouyer void
    238  1.1    bouyer bread(blkno, buf, size)
    239  1.1    bouyer 	daddr_t blkno;
    240  1.1    bouyer 	char *buf;
    241  1.1    bouyer 	int size;
    242  1.1    bouyer {
    243  1.1    bouyer 	int     osize = size;
    244  1.1    bouyer 	daddr_t oblkno = blkno;
    245  1.1    bouyer 	char   *obuf = buf;
    246  1.1    bouyer 	daddr_t numBlocks = (size + dev_bsize -1) / dev_bsize;
    247  1.1    bouyer 
    248  1.1    bouyer #ifdef STATS
    249  1.1    bouyer 	nreads++;
    250  1.1    bouyer 	readsize += size;
    251  1.1    bouyer #endif
    252  1.1    bouyer 
    253  1.1    bouyer 	if (!shareBuffer) {
    254  1.1    bouyer 		rawread(blkno, buf, size);
    255  1.1    bouyer 		return;
    256  1.1    bouyer 	}
    257  1.1    bouyer 
    258  1.1    bouyer 	if (flock(diskfd, LOCK_EX)) {
    259  1.1    bouyer 		msg("flock(LOCK_EX) failed: %s\n",
    260  1.1    bouyer 		    strerror(errno));
    261  1.1    bouyer 		rawread(blkno, buf, size);
    262  1.1    bouyer 		return;
    263  1.1    bouyer 	}
    264  1.1    bouyer 
    265  1.1    bouyer 
    266  1.1    bouyer retry:
    267  1.1    bouyer 	while(size > 0) {
    268  1.1    bouyer 		int     i;
    269  1.1    bouyer 
    270  1.1    bouyer 		for (i = 0; i < cachebufs; i++) {
    271  1.1    bouyer 			struct cdesc *curr = &cdesc[i];
    272  1.1    bouyer 
    273  1.1    bouyer #ifdef DIAGNOSTICS
    274  1.1    bouyer 			if (curr->owner) {
    275  1.1    bouyer 				fprintf(stderr, "Owner is set (%d, me=%d), can"
    276  1.1    bouyer 				    "not happen.\n", curr->owner, getpid());
    277  1.1    bouyer 			}
    278  1.1    bouyer #endif
    279  1.1    bouyer 
    280  1.1    bouyer 			if (curr->blkend == 0)
    281  1.1    bouyer 				continue;
    282  1.1    bouyer 			/*
    283  1.1    bouyer 			 * If we find a bit of the read in the buffers,
    284  1.1    bouyer 			 * now compute how many blocks we can copy,
    285  1.1    bouyer 			 * copy them out, adjust blkno, buf and size,
    286  1.1    bouyer 			 * and restart
    287  1.1    bouyer 			 */
    288  1.1    bouyer 			if (curr->blkstart <= blkno &&
    289  1.1    bouyer 			    blkno < curr->blkend) {
    290  1.1    bouyer 				/* Number of data blocks to be copied */
    291  1.1    bouyer 				int toCopy = min(size,
    292  1.1    bouyer 				    (curr->blkend - blkno) * dev_bsize);
    293  1.1    bouyer #ifdef DIAGNOSTICS
    294  1.1    bouyer 				if (toCopy <= 0 ||
    295  1.1    bouyer 				    toCopy > nblksread * dev_bsize) {
    296  1.1    bouyer 					fprintf(stderr, "toCopy %d !\n",
    297  1.1    bouyer 					    toCopy);
    298  1.1    bouyer 					dumpabort(0);
    299  1.1    bouyer 				}
    300  1.1    bouyer 				if (CDATA(i) + (blkno - curr->blkstart) *
    301  1.1    bouyer 			   	    dev_bsize < CDATA(i) ||
    302  1.1    bouyer 			   	    CDATA(i) + (blkno - curr->blkstart) *
    303  1.1    bouyer 			   	    dev_bsize >
    304  1.1    bouyer 				    CDATA(i) + nblksread * dev_bsize) {
    305  1.1    bouyer 					fprintf(stderr, "%p < %p !!!\n",
    306  1.1    bouyer 				   	   CDATA(i) + (blkno -
    307  1.1    bouyer 						curr->blkstart) * dev_bsize,
    308  1.1    bouyer 					   CDATA(i));
    309  1.1    bouyer 					fprintf(stderr, "cdesc[i].blkstart %d "
    310  1.1    bouyer 					    "blkno %d dev_bsize %ld\n",
    311  1.1    bouyer 				   	    curr->blkstart, blkno, dev_bsize);
    312  1.1    bouyer 					dumpabort(0);
    313  1.1    bouyer 				}
    314  1.1    bouyer #endif
    315  1.1    bouyer 				memcpy(buf, CDATA(i) +
    316  1.1    bouyer 				    (blkno - curr->blkstart) * dev_bsize,
    317  1.1    bouyer 			   	    toCopy);
    318  1.1    bouyer 
    319  1.1    bouyer 				buf 	+= toCopy;
    320  1.1    bouyer 				size 	-= toCopy;
    321  1.1    bouyer 				blkno 	+= (toCopy + dev_bsize - 1) / dev_bsize;
    322  1.1    bouyer 				numBlocks -=
    323  1.1    bouyer 				    (toCopy  + dev_bsize - 1) / dev_bsize;
    324  1.1    bouyer 
    325  1.1    bouyer 				curr->time = cheader->count++;
    326  1.1    bouyer 
    327  1.1    bouyer 				/*
    328  1.1    bouyer 				 * If all data of a cache block have been
    329  1.1    bouyer 				 * read, chances are good no more reads
    330  1.1    bouyer 				 * will occur, so expire the cache immediately
    331  1.1    bouyer 				 */
    332  1.1    bouyer 
    333  1.1    bouyer 				curr->blocksRead +=
    334  1.1    bouyer 				    (toCopy + dev_bsize -1) / dev_bsize;
    335  1.1    bouyer 				if (curr->blocksRead >= nblksread)
    336  1.1    bouyer 					curr->time = 0;
    337  1.1    bouyer 
    338  1.1    bouyer 				goto retry;
    339  1.1    bouyer 			}
    340  1.1    bouyer 		}
    341  1.1    bouyer 
    342  1.1    bouyer 		/* No more to do? */
    343  1.1    bouyer 		if (size == 0)
    344  1.1    bouyer 			break;
    345  1.1    bouyer 
    346  1.1    bouyer 		/*
    347  1.1    bouyer 		 * This does actually not happen if fs blocks are not greater
    348  1.1    bouyer 		 * than nblksread.
    349  1.1    bouyer 		 */
    350  1.1    bouyer 		if (numBlocks > nblksread) {
    351  1.1    bouyer 			rawread(oblkno, obuf, osize);
    352  1.1    bouyer 			break;
    353  1.1    bouyer 		} else {
    354  1.1    bouyer 			int     idx;
    355  1.1    bouyer 			ssize_t rsize;
    356  1.1    bouyer 			daddr_t blockBlkNo;
    357  1.1    bouyer 
    358  1.1    bouyer 			blockBlkNo = (blkno / nblksread) * nblksread;
    359  1.1    bouyer 			idx = findlru();
    360  1.1    bouyer 			rsize = min(nblksread,
    361  1.2  perseant 			    ufsib->ufs_dsize - blockBlkNo) *
    362  1.1    bouyer 			    dev_bsize;
    363  1.2  perseant 			if(rsize < 0)
    364  1.2  perseant 				fprintf(stderr,"blk %d, rsize=%d (dsize=%d)\n",
    365  1.2  perseant 					blockBlkNo, rsize, ufsib->ufs_dsize);
    366  1.1    bouyer #ifdef DIAGNOSTICS
    367  1.1    bouyer 			if (cdesc[idx].owner)
    368  1.1    bouyer 				fprintf(stderr, "Owner is set (%d, me=%d), can"
    369  1.1    bouyer 				    "not happen(2).\n", cdesc[idx].owner,
    370  1.1    bouyer 				    getpid());
    371  1.1    bouyer 			cdesc[idx].owner = getpid();
    372  1.1    bouyer #endif
    373  1.1    bouyer 			cdesc[idx].time = cheader->count++;
    374  1.1    bouyer 			cdesc[idx].blkstart = blockBlkNo;
    375  1.1    bouyer 			cdesc[idx].blocksRead = 0;
    376  1.1    bouyer 
    377  1.1    bouyer 			if (lseek(diskfd,
    378  1.1    bouyer 			    ((off_t) (blockBlkNo) << dev_bshift), 0) < 0) {
    379  1.1    bouyer 				msg("readBlocks: lseek fails: %s\n",
    380  1.1    bouyer 				    strerror(errno));
    381  1.1    bouyer 				rsize = -1;
    382  1.1    bouyer 			} else {
    383  1.1    bouyer 				rsize = read(diskfd, CDATA(idx), rsize);
    384  1.1    bouyer 				if (rsize < 0) {
    385  1.1    bouyer 					msg("readBlocks: read fails: %s\n",
    386  1.1    bouyer 					    strerror(errno));
    387  1.1    bouyer 				}
    388  1.1    bouyer 			}
    389  1.1    bouyer 
    390  1.1    bouyer 			/* On errors, panic, punt, try to read without
    391  1.1    bouyer 			 * cache and let raw read routine do the rest.
    392  1.1    bouyer 			 */
    393  1.1    bouyer 
    394  1.1    bouyer 			if (rsize <= 0) {
    395  1.1    bouyer 				rawread(oblkno, obuf, osize);
    396  1.1    bouyer #ifdef DIAGNOSTICS
    397  1.1    bouyer 				if (cdesc[idx].owner != getpid())
    398  1.1    bouyer 					fprintf(stderr, "Owner changed from "
    399  1.1    bouyer 					    "%d to %d, can't happen\n",
    400  1.1    bouyer 					    getpid(), cdesc[idx].owner);
    401  1.1    bouyer 				cdesc[idx].owner = 0;
    402  1.1    bouyer #endif
    403  1.1    bouyer 				break;
    404  1.1    bouyer 			}
    405  1.1    bouyer 
    406  1.1    bouyer 			/* On short read, just note the fact and go on */
    407  1.1    bouyer 			cdesc[idx].blkend = blockBlkNo + rsize / dev_bsize;
    408  1.1    bouyer 
    409  1.1    bouyer #ifdef STATS
    410  1.1    bouyer 			nphysread++;
    411  1.1    bouyer 			physreadsize += rsize;
    412  1.1    bouyer #endif
    413  1.1    bouyer #ifdef DIAGNOSTICS
    414  1.1    bouyer 			if (cdesc[idx].owner != getpid())
    415  1.1    bouyer 				fprintf(stderr, "Owner changed from "
    416  1.1    bouyer 				    "%d to %d, can't happen\n",
    417  1.1    bouyer 				    getpid(), cdesc[idx].owner);
    418  1.1    bouyer 			cdesc[idx].owner = 0;
    419  1.1    bouyer #endif
    420  1.1    bouyer 			/*
    421  1.1    bouyer 			 * We swapped some of data in, let the loop fetch
    422  1.1    bouyer 			 * them from cache
    423  1.1    bouyer 			 */
    424  1.1    bouyer 		}
    425  1.1    bouyer 	}
    426  1.1    bouyer 
    427  1.1    bouyer 	if (flock(diskfd, LOCK_UN))
    428  1.1    bouyer 		msg("flock(LOCK_UN) failed: %s\n",
    429  1.1    bouyer 		    strerror(errno));
    430  1.1    bouyer 	return;
    431  1.1    bouyer }
    432  1.1    bouyer 
    433  1.1    bouyer /*-----------------------------------------------------------------------*/
    434  1.1    bouyer void
    435  1.1    bouyer printcachestats()
    436  1.1    bouyer {
    437  1.1    bouyer #ifdef STATS
    438  1.1    bouyer 	fprintf(stderr, "Pid %d: %d reads (%u bytes) "
    439  1.1    bouyer 	    "%d physical reads (%u bytes) %d%% hits, %d%% overhead\n",
    440  1.1    bouyer 	    getpid(), nreads, (u_int) readsize, nphysread,
    441  1.1    bouyer 	    (u_int) physreadsize, (nreads - nphysread) * 100 / nreads,
    442  1.1    bouyer 	    (int) (((physreadsize - readsize) * 100) / readsize));
    443  1.1    bouyer #endif
    444  1.1    bouyer }
    445  1.1    bouyer 
    446  1.1    bouyer /*-----------------------------------------------------------------------*/
    447