2004-05-12 01:56:20 +04:00
|
|
|
/* $NetBSD: bufcache.c,v 1.17 2004/05/11 21:56:20 martin Exp $ */
|
1999-11-15 09:16:56 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Simon Burge.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2004-05-12 01:56:20 +04:00
|
|
|
__RCSID("$NetBSD: bufcache.c,v 1.17 2004/05/11 21:56:20 martin Exp $");
|
1999-11-15 09:16:56 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/mount.h>
|
2000-11-30 15:08:13 +03:00
|
|
|
#include <sys/sysctl.h>
|
1999-11-15 09:16:56 +03:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
2000-11-30 15:08:13 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1999-11-15 09:16:56 +03:00
|
|
|
#include <err.h>
|
2000-11-30 15:08:13 +03:00
|
|
|
#include <errno.h>
|
1999-11-15 09:16:56 +03:00
|
|
|
#include <kvm.h>
|
2001-03-09 06:05:20 +03:00
|
|
|
#include <math.h>
|
1999-11-15 09:16:56 +03:00
|
|
|
#include <nlist.h>
|
|
|
|
#include <stdlib.h>
|
2000-11-30 15:08:13 +03:00
|
|
|
#include <string.h>
|
1999-11-15 13:54:40 +03:00
|
|
|
#include <unistd.h>
|
1999-11-15 09:16:56 +03:00
|
|
|
|
2003-12-30 15:52:48 +03:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
1999-11-15 09:16:56 +03:00
|
|
|
#include "systat.h"
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
#define VCACHE_SIZE 50
|
|
|
|
|
|
|
|
struct vcache {
|
|
|
|
int vc_age;
|
|
|
|
struct vnode *vc_addr;
|
|
|
|
struct vnode vc_node;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ml_entry {
|
2003-12-30 15:52:48 +03:00
|
|
|
u_int ml_count;
|
|
|
|
u_long ml_size;
|
|
|
|
u_long ml_valid;
|
1999-11-15 09:16:56 +03:00
|
|
|
struct mount *ml_addr;
|
|
|
|
LIST_ENTRY(ml_entry) ml_entries;
|
2003-12-30 15:52:48 +03:00
|
|
|
struct mount ml_mount;
|
1999-11-15 09:16:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct nlist namelist[] = {
|
2003-12-30 15:52:48 +03:00
|
|
|
#define X_BUFMEM 0
|
|
|
|
{ "_bufmem" },
|
1999-11-15 09:16:56 +03:00
|
|
|
{ "" },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct vcache vcache[VCACHE_SIZE];
|
|
|
|
static LIST_HEAD(mount_list, ml_entry) mount_list;
|
|
|
|
|
2004-05-12 01:56:20 +04:00
|
|
|
static u_long bufmem;
|
|
|
|
static u_int nbuf, pgwidth, kbwidth;
|
2000-11-30 15:08:13 +03:00
|
|
|
static struct uvmexp_sysctl uvmexp;
|
1999-11-15 09:16:56 +03:00
|
|
|
|
2000-07-05 15:03:20 +04:00
|
|
|
static void vc_init(void);
|
|
|
|
static void ml_init(void);
|
|
|
|
static struct vnode *vc_lookup(struct vnode *);
|
|
|
|
static struct mount *ml_lookup(struct mount *, int, int);
|
2001-03-09 06:05:20 +03:00
|
|
|
static void fetchuvmexp(void);
|
1999-11-15 09:16:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
WINDOW *
|
2000-07-05 15:03:20 +04:00
|
|
|
openbufcache(void)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
|
2003-02-24 13:10:00 +03:00
|
|
|
return (subwin(stdscr, -1, 0, 5, 0));
|
1999-11-15 09:16:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
closebufcache(WINDOW *w)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
if (w == NULL)
|
|
|
|
return;
|
|
|
|
wclear(w);
|
|
|
|
wrefresh(w);
|
|
|
|
delwin(w);
|
|
|
|
ml_init(); /* Clear out mount list */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
labelbufcache(void)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
wmove(wnd, 1, 0);
|
2001-03-09 06:05:20 +03:00
|
|
|
wclrtoeol(wnd);
|
2000-11-30 15:08:13 +03:00
|
|
|
wmove(wnd, 2, 0);
|
1999-11-15 09:16:56 +03:00
|
|
|
wclrtoeol(wnd);
|
2001-03-09 06:05:20 +03:00
|
|
|
wmove(wnd, 3, 0);
|
|
|
|
wclrtoeol(wnd);
|
|
|
|
mvwaddstr(wnd, 4, 0,
|
1999-11-27 08:58:04 +03:00
|
|
|
"File System Bufs used % kB in use % Bufsize kB % Util %");
|
1999-11-15 09:16:56 +03:00
|
|
|
wclrtoeol(wnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-05 15:03:20 +04:00
|
|
|
showbufcache(void)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
int tbuf, i, lastrow;
|
2003-12-30 15:52:48 +03:00
|
|
|
double tvalid, tsize;
|
1999-11-15 09:16:56 +03:00
|
|
|
struct ml_entry *ml;
|
|
|
|
|
2003-12-30 15:52:48 +03:00
|
|
|
NREAD(X_BUFMEM, &bufmem, sizeof(bufmem));
|
|
|
|
|
|
|
|
mvwprintw(wnd, 0, 0,
|
2004-05-12 01:56:20 +04:00
|
|
|
"There are %*d metadata buffers using %*ld kBytes of memory.",
|
2003-12-30 15:52:48 +03:00
|
|
|
pgwidth, nbuf, kbwidth, bufmem/1024);
|
|
|
|
wclrtoeol(wnd);
|
2000-11-30 15:08:13 +03:00
|
|
|
mvwprintw(wnd, 1, 0,
|
2001-12-09 06:07:43 +03:00
|
|
|
"There are %*llu pages for cached file data using %*llu kBytes of memory.",
|
|
|
|
pgwidth, (long long)uvmexp.filepages,
|
|
|
|
kbwidth, (long long) uvmexp.filepages * getpagesize() / 1024);
|
2001-03-09 06:05:20 +03:00
|
|
|
wclrtoeol(wnd);
|
|
|
|
mvwprintw(wnd, 2, 0,
|
|
|
|
"There are %*llu pages for executables using %*llu kBytes of memory.",
|
2001-12-09 06:07:43 +03:00
|
|
|
pgwidth, (long long)uvmexp.execpages,
|
|
|
|
kbwidth, (long long) uvmexp.execpages * getpagesize() / 1024);
|
2000-11-30 15:08:13 +03:00
|
|
|
wclrtoeol(wnd);
|
|
|
|
|
2003-12-30 15:52:48 +03:00
|
|
|
if (nbuf == 0 || bufmem == 0) {
|
|
|
|
wclrtobot(wnd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tbuf = 0;
|
|
|
|
tvalid = tsize = 0;
|
2001-03-09 06:05:20 +03:00
|
|
|
lastrow = 5; /* Leave room for header. */
|
1999-11-15 09:16:56 +03:00
|
|
|
for (i = lastrow, ml = LIST_FIRST(&mount_list); ml != NULL;
|
|
|
|
i++, ml = LIST_NEXT(ml, ml_entries)) {
|
|
|
|
|
2003-12-30 15:52:48 +03:00
|
|
|
int c = ml->ml_count;
|
|
|
|
double v = ml->ml_valid;
|
|
|
|
double s = ml->ml_size;
|
|
|
|
|
1999-11-15 09:16:56 +03:00
|
|
|
/* Display in window if enough room. */
|
|
|
|
if (i < getmaxy(wnd) - 2) {
|
|
|
|
mvwprintw(wnd, i, 0, "%-20.20s", ml->ml_addr == NULL ?
|
|
|
|
"NULL" : ml->ml_mount.mnt_stat.f_mntonname);
|
1999-11-27 08:58:04 +03:00
|
|
|
wprintw(wnd,
|
2003-12-30 15:52:48 +03:00
|
|
|
" %6d %3d %8ld %3.0f %8ld %3.0f %3.0f",
|
|
|
|
c, (100 * c) / nbuf,
|
|
|
|
(long)(v/1024), 100 * v / bufmem,
|
|
|
|
(long)(s/1024), 100 * s / bufmem,
|
|
|
|
100 * v / s);
|
1999-11-15 09:16:56 +03:00
|
|
|
wclrtoeol(wnd);
|
|
|
|
lastrow = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update statistics. */
|
2003-12-30 15:52:48 +03:00
|
|
|
tbuf += c;
|
|
|
|
tvalid += v;
|
|
|
|
tsize += s;
|
1999-11-15 09:16:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
wclrtobot(wnd);
|
1999-11-27 08:58:04 +03:00
|
|
|
mvwprintw(wnd, lastrow + 2, 0,
|
2003-12-30 15:52:48 +03:00
|
|
|
"%-20s %6d %3d %8ld %3.0f %8ld %3.0f %3.0f",
|
1999-11-27 08:58:04 +03:00
|
|
|
"Total:", tbuf, (100 * tbuf) / nbuf,
|
2003-12-30 15:52:48 +03:00
|
|
|
(long)(tvalid/1024), 100 * tvalid / bufmem,
|
|
|
|
(long)(tsize/1024), 100 * tsize / bufmem,
|
|
|
|
tsize != 0 ? ((100 * tvalid) / tsize) : 0);
|
1999-11-15 09:16:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-07-05 15:03:20 +04:00
|
|
|
initbufcache(void)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
2003-12-30 15:52:48 +03:00
|
|
|
if (namelist[0].n_type == 0) {
|
1999-11-15 09:16:56 +03:00
|
|
|
if (kvm_nlist(kd, namelist)) {
|
|
|
|
nlisterr(namelist);
|
|
|
|
return(0);
|
|
|
|
}
|
1999-12-21 02:11:50 +03:00
|
|
|
}
|
1999-11-15 09:16:56 +03:00
|
|
|
|
2001-03-09 06:05:20 +03:00
|
|
|
fetchuvmexp();
|
|
|
|
pgwidth = (int)(floor(log10((double)uvmexp.npages)) + 1);
|
|
|
|
kbwidth = (int)(floor(log10(uvmexp.npages * getpagesize() / 1024.0)) + 1);
|
|
|
|
|
1999-11-15 09:16:56 +03:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2001-03-09 06:05:20 +03:00
|
|
|
static void
|
|
|
|
fetchuvmexp(void)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
2001-03-09 06:05:20 +03:00
|
|
|
int mib[2];
|
2000-11-30 15:08:13 +03:00
|
|
|
size_t size;
|
1999-11-15 09:16:56 +03:00
|
|
|
|
2001-03-09 06:05:20 +03:00
|
|
|
/* Re-read pages used for vnodes & executables */
|
2000-11-30 15:08:13 +03:00
|
|
|
size = sizeof(uvmexp);
|
|
|
|
mib[0] = CTL_VM;
|
|
|
|
mib[1] = VM_UVMEXP2;
|
|
|
|
if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) < 0) {
|
|
|
|
error("can't get uvmexp: %s\n", strerror(errno));
|
|
|
|
memset(&uvmexp, 0, sizeof(uvmexp));
|
|
|
|
}
|
2001-03-09 06:05:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fetchbufcache(void)
|
|
|
|
{
|
2003-12-30 15:52:48 +03:00
|
|
|
int count;
|
2004-02-19 06:56:30 +03:00
|
|
|
struct buf_sysctl *bp, *buffers;
|
2001-03-09 06:05:20 +03:00
|
|
|
struct vnode *vn;
|
|
|
|
struct mount *mt;
|
|
|
|
struct ml_entry *ml;
|
2004-02-19 06:56:30 +03:00
|
|
|
int mib[6];
|
2003-12-30 15:52:48 +03:00
|
|
|
size_t size;
|
|
|
|
int extraslop = 0;
|
2000-11-30 15:08:13 +03:00
|
|
|
|
2003-12-30 15:52:48 +03:00
|
|
|
/* Re-read pages used for vnodes & executables */
|
2001-03-09 06:05:20 +03:00
|
|
|
fetchuvmexp();
|
1999-11-15 09:16:56 +03:00
|
|
|
|
|
|
|
/* Initialise vnode cache and mount list. */
|
|
|
|
vc_init();
|
|
|
|
ml_init();
|
2003-12-30 15:52:48 +03:00
|
|
|
|
|
|
|
/* Get metadata buffers */
|
|
|
|
size = 0;
|
|
|
|
buffers = NULL;
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_BUF;
|
2004-02-19 06:56:30 +03:00
|
|
|
mib[2] = KERN_BUF_ALL;
|
|
|
|
mib[3] = KERN_BUF_ALL;
|
|
|
|
mib[4] = (int)sizeof(struct buf_sysctl);
|
|
|
|
mib[5] = INT_MAX; /* we want them all */
|
|
|
|
again:
|
|
|
|
if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) {
|
2003-12-30 15:52:48 +03:00
|
|
|
error("can't get buffers size: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
2004-02-19 06:56:30 +03:00
|
|
|
size += extraslop * sizeof(struct buf_sysctl);
|
2003-12-30 15:52:48 +03:00
|
|
|
buffers = malloc(size);
|
|
|
|
if (buffers == NULL) {
|
|
|
|
error("can't allocate buffers: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2004-02-19 06:56:30 +03:00
|
|
|
if (sysctl(mib, 6, buffers, &size, NULL, 0) < 0) {
|
2003-12-30 15:52:48 +03:00
|
|
|
free(buffers);
|
|
|
|
if (extraslop == 0) {
|
|
|
|
extraslop = 100;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
error("can't get buffers: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-02-19 06:56:30 +03:00
|
|
|
nbuf = size / sizeof(struct buf_sysctl);
|
2003-12-30 15:52:48 +03:00
|
|
|
for (bp = buffers; bp < buffers + nbuf; bp++) {
|
2004-02-19 06:56:30 +03:00
|
|
|
if (UINT64TOPTR(bp->b_vp) != NULL) {
|
2003-12-30 15:52:48 +03:00
|
|
|
struct mount *mp;
|
2004-02-19 06:56:30 +03:00
|
|
|
vn = vc_lookup(UINT64TOPTR(bp->b_vp));
|
2003-12-30 15:52:48 +03:00
|
|
|
if (vn == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
mp = vn->v_mount;
|
|
|
|
/*
|
|
|
|
* References to mounted-on vnodes should be
|
|
|
|
* counted towards the mounted filesystem.
|
|
|
|
*/
|
|
|
|
if (vn->v_type == VBLK && vn->v_specinfo != NULL) {
|
|
|
|
struct specinfo sp;
|
|
|
|
if (!KREAD(vn->v_specinfo, &sp, sizeof(sp)))
|
|
|
|
continue;
|
|
|
|
if (sp.si_mountpoint)
|
|
|
|
mp = sp.si_mountpoint;
|
1999-11-15 09:16:56 +03:00
|
|
|
}
|
2003-12-30 15:52:48 +03:00
|
|
|
if (mp != NULL)
|
|
|
|
mt = ml_lookup(mp,
|
|
|
|
bp->b_bufsize,
|
|
|
|
bp->b_bcount);
|
1999-11-15 09:16:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* simple sort - there's not that many entries */
|
|
|
|
do {
|
|
|
|
if ((ml = LIST_FIRST(&mount_list)) == NULL ||
|
|
|
|
LIST_NEXT(ml, ml_entries) == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (ml = LIST_FIRST(&mount_list); ml != NULL;
|
|
|
|
ml = LIST_NEXT(ml, ml_entries)) {
|
|
|
|
if (LIST_NEXT(ml, ml_entries) == NULL)
|
|
|
|
break;
|
|
|
|
if (ml->ml_count < LIST_NEXT(ml, ml_entries)->ml_count) {
|
|
|
|
ml = LIST_NEXT(ml, ml_entries);
|
|
|
|
LIST_REMOVE(ml, ml_entries);
|
|
|
|
LIST_INSERT_HEAD(&mount_list, ml, ml_entries);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (count != 0);
|
2003-12-30 15:52:48 +03:00
|
|
|
|
|
|
|
free(buffers);
|
1999-11-15 09:16:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-05 15:03:20 +04:00
|
|
|
vc_init(void)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* vc_addr == NULL for unused cache entry. */
|
|
|
|
for (i = 0; i < VCACHE_SIZE; i++)
|
|
|
|
vcache[i].vc_addr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-07-05 15:03:20 +04:00
|
|
|
ml_init(void)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
struct ml_entry *ml;
|
|
|
|
|
|
|
|
/* Throw out the current mount list and start again. */
|
|
|
|
while ((ml = LIST_FIRST(&mount_list)) != NULL) {
|
|
|
|
LIST_REMOVE(ml, ml_entries);
|
|
|
|
free(ml);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct vnode *
|
2000-07-05 15:03:20 +04:00
|
|
|
vc_lookup(struct vnode *vaddr)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
struct vnode *ret;
|
2003-12-07 10:28:05 +03:00
|
|
|
size_t i, oldest;
|
1999-11-15 09:16:56 +03:00
|
|
|
|
|
|
|
ret = NULL;
|
2003-12-07 10:28:05 +03:00
|
|
|
oldest = 0;
|
2004-05-12 01:56:20 +04:00
|
|
|
for (i = 0; i < VCACHE_SIZE; i++) {
|
1999-11-15 09:16:56 +03:00
|
|
|
if (vcache[i].vc_addr == NULL)
|
|
|
|
break;
|
2004-05-12 01:56:20 +04:00
|
|
|
vcache[i].vc_age++;
|
1999-11-15 09:16:56 +03:00
|
|
|
if (vcache[i].vc_age < vcache[oldest].vc_age)
|
|
|
|
oldest = i;
|
|
|
|
if (vcache[i].vc_addr == vaddr) {
|
|
|
|
vcache[i].vc_age = 0;
|
|
|
|
ret = &vcache[i].vc_node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find an entry in the cache? */
|
|
|
|
if (ret != NULL)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
/* Go past the end of the cache? */
|
|
|
|
if (i >= VCACHE_SIZE)
|
|
|
|
i = oldest;
|
|
|
|
|
|
|
|
/* Read in new vnode and reset age counter. */
|
2003-12-07 10:28:05 +03:00
|
|
|
if (KREAD(vaddr, &vcache[i].vc_node, sizeof(struct vnode)) == 0)
|
|
|
|
return NULL;
|
1999-11-15 09:16:56 +03:00
|
|
|
vcache[i].vc_addr = vaddr;
|
|
|
|
vcache[i].vc_age = 0;
|
|
|
|
|
|
|
|
return(&vcache[i].vc_node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct mount *
|
2000-07-05 15:03:20 +04:00
|
|
|
ml_lookup(struct mount *maddr, int size, int valid)
|
1999-11-15 09:16:56 +03:00
|
|
|
{
|
|
|
|
struct ml_entry *ml;
|
|
|
|
|
|
|
|
for (ml = LIST_FIRST(&mount_list); ml != NULL;
|
|
|
|
ml = LIST_NEXT(ml, ml_entries))
|
|
|
|
if (ml->ml_addr == maddr) {
|
|
|
|
ml->ml_count++;
|
2003-12-30 15:52:48 +03:00
|
|
|
ml->ml_size += size;
|
|
|
|
ml->ml_valid += valid;
|
1999-11-15 09:16:56 +03:00
|
|
|
if (ml->ml_addr == NULL)
|
|
|
|
return(NULL);
|
|
|
|
else
|
|
|
|
return(&ml->ml_mount);
|
|
|
|
}
|
|
|
|
|
1999-12-21 02:11:50 +03:00
|
|
|
if ((ml = malloc(sizeof(struct ml_entry))) == NULL) {
|
|
|
|
error("out of memory");
|
|
|
|
die(0);
|
|
|
|
}
|
1999-11-15 09:16:56 +03:00
|
|
|
LIST_INSERT_HEAD(&mount_list, ml, ml_entries);
|
|
|
|
ml->ml_count = 1;
|
2003-12-30 15:52:48 +03:00
|
|
|
ml->ml_size = size;
|
|
|
|
ml->ml_valid = valid;
|
1999-11-15 09:16:56 +03:00
|
|
|
ml->ml_addr = maddr;
|
|
|
|
if (maddr == NULL)
|
|
|
|
return(NULL);
|
|
|
|
|
|
|
|
KREAD(maddr, &ml->ml_mount, sizeof(struct mount));
|
|
|
|
return(&ml->ml_mount);
|
|
|
|
}
|